aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2023-10-12 11:24:19 -0400
committerbobzel <zzzman@gmail.com>2023-10-12 11:24:19 -0400
commit53d456afb43b70cc240bc6a37094fa37cfe37436 (patch)
tree1c45b91992e766da36a92ae652aa7ebe122ff664 /src/fields/Doc.ts
parent54e80f26df04f1a031d1d7e4b840fe9426d4d2cf (diff)
performance fixes to reduce re-rendering : moved link brushing out of Doc's highlighting and into Annotation.tsx, stopped freeformview from rerendering whenever its invalidated by not always setting layoutElements to a new list.
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 7170be6cc..9e3eb28f9 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -50,8 +50,9 @@ import { listSpec } from './Schema';
import { ComputedField, ScriptField } from './ScriptField';
import { BoolCast, Cast, DocCast, FieldValue, NumCast, StrCast, ToConstructor } from './Types';
import { AudioField, CsvField, ImageField, PdfField, VideoField, WebField } from './URLField';
-import { containedFieldChangedHandler, deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, normalizeEmail, setter, SharingPermissions } from './util';
+import { containedFieldChangedHandler, deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, normalizeEmail, setter, SharingPermissions, TraceMobx } from './util';
import JSZip = require('jszip');
+export const LinkedTo = '-linkedTo';
export namespace Field {
export function toKeyValueString(doc: Doc, key: string): string {
const onDelegate = Object.keys(doc).includes(key.replace(/^_/, ''));
@@ -853,22 +854,22 @@ export namespace Doc {
export async function Zip(doc: Doc, zipFilename = 'dashExport.zip') {
const { clone, map, linkMap } = await Doc.MakeClone(doc);
const proms = new Set<string>();
- function replacer(key: any, value: any) {
+ function replacer(key: any, value: any) {
if (key && ['branchOf', 'cloneOf', 'cursors'].includes(key)) return undefined;
- if (value?.__type === 'image') {
+ if (value?.__type === 'image') {
const extension = value.url.replace(/.*\./, '');
proms.add(value.url.replace('.' + extension, '_o.' + extension));
return SerializationHelper.Serialize(new ImageField(value.url));
}
- if (value?.__type === 'pdf') {
+ if (value?.__type === 'pdf') {
proms.add(value.url);
return SerializationHelper.Serialize(new PdfField(value.url));
}
- if (value?.__type === 'audio') {
+ if (value?.__type === 'audio') {
proms.add(value.url);
return SerializationHelper.Serialize(new AudioField(value.url));
}
- if (value?.__type === 'video') {
+ if (value?.__type === 'video') {
proms.add(value.url);
return SerializationHelper.Serialize(new VideoField(value.url));
}
@@ -897,7 +898,9 @@ export namespace Doc {
const zip = new JSZip();
var count = 0;
- const promArr = Array.from(proms).filter(url => url?.startsWith("/files")).map(url => url.replace("/",""))// window.location.origin));
+ const promArr = Array.from(proms)
+ .filter(url => url?.startsWith('/files'))
+ .map(url => url.replace('/', '')); // window.location.origin));
console.log(promArr.length);
if (!promArr.length) {
zip.file('docs.json', jsonDocs);
@@ -905,7 +908,7 @@ export namespace Doc {
} else
promArr.forEach((url, i) => {
// loading a file and add it in a zip file
- JSZipUtils.getBinaryContent(window.location.origin+"/"+url, (err: any, data: any) => {
+ JSZipUtils.getBinaryContent(window.location.origin + '/' + url, (err: any, data: any) => {
if (err) throw err; // or handle the error
// // Generate a directory within the Zip file structure
// const assets = zip.folder("assets");
@@ -1343,24 +1346,11 @@ export namespace Doc {
protoBrushed = 1,
selfBrushed = 2,
highlighted = 3,
- linkHighlighted = 4,
}
// don't bother memoizing (caching) the result if called from a non-reactive context. (plus this avoids a warning message)
export function IsBrushedDegreeUnmemoized(doc: Doc) {
if (!doc || GetEffectiveAcl(doc) === AclPrivate || GetEffectiveAcl(Doc.GetProto(doc)) === AclPrivate || doc.opacity === 0) return DocBrushStatus.unbrushed;
const status = brushManager.BrushedDoc.has(doc) ? DocBrushStatus.selfBrushed : brushManager.BrushedDoc.has(Doc.GetProto(doc)) ? DocBrushStatus.protoBrushed : DocBrushStatus.unbrushed;
- if (status === DocBrushStatus.unbrushed) {
- const lastBrushed = Array.from(brushManager.BrushedDoc.keys()).lastElement();
- if (lastBrushed) {
- for (const link of LinkManager.Instance.getAllDirectLinks(lastBrushed)) {
- const a1 = Cast(link.link_anchor_1, Doc, null);
- const a2 = Cast(link.link_anchor_2, Doc, null);
- if (Doc.AreProtosEqual(a1, doc) || Doc.AreProtosEqual(a2, doc) || Doc.AreProtosEqual(Cast(a1.annotationOn, Doc, null), doc) || Doc.AreProtosEqual(Cast(a2.annotationOn, Doc, null), doc)) {
- return DocBrushStatus.linkHighlighted;
- }
- }
- }
- }
return status;
}
export function IsBrushedDegree(doc: Doc) {
@@ -1472,7 +1462,7 @@ export namespace Doc {
const isTransparent = (color: string) => color !== '' && DashColor(color).alpha() !== 1;
return isTransparent(StrCast(doc[key]));
}
- if (key === '-linkedTo') {
+ if (key === LinkedTo) {
// links are not a field value, so handled here. value is an expression of form ([field=]idToDoc("..."))
const allLinks = LinkManager.Instance.getAllRelatedLinks(doc);
const matchLink = (value: string, anchor: Doc) => {