diff options
Diffstat (limited to 'src/new_fields')
| -rw-r--r-- | src/new_fields/Doc.ts | 82 | ||||
| -rw-r--r-- | src/new_fields/RichTextUtils.ts | 2 | ||||
| -rw-r--r-- | src/new_fields/documentSchemas.ts | 13 | ||||
| -rw-r--r-- | src/new_fields/util.ts | 33 |
4 files changed, 63 insertions, 67 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 4b7f10f91..b30e84370 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -162,8 +162,8 @@ export class Doc extends RefField { private [Self] = this; private [SelfProxy]: any; - public [WidthSym] = () => NumCast(this[SelfProxy].width); - public [HeightSym] = () => NumCast(this[SelfProxy].height); + public [WidthSym] = () => NumCast(this[SelfProxy]._width); + public [HeightSym] = () => NumCast(this[SelfProxy]._height); [ToScriptString]() { return "invalid"; @@ -424,7 +424,7 @@ export namespace Doc { if (layout instanceof Doc && layout !== alias) { Doc.SetLayout(alias, Doc.MakeAlias(layout)); } - const aliasNumber = Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1; + const aliasNumber = 1;//Doc.GetProto(doc).aliasNumber = NumCast(Doc.GetProto(doc).aliasNumber) + 1; alias.title = ComputedField.MakeFunction(`renameAlias(this, ${aliasNumber})`); return alias; } @@ -447,19 +447,18 @@ export namespace Doc { if (!WillExpandTemplateLayout(templateLayoutDoc, dataDoc) || !dataDoc) return templateLayoutDoc; const templateField = StrCast(templateLayoutDoc.isTemplateForField); // the field that the template renders - const extensionDoc = fieldExtensionDoc(dataDoc, templateField); // an extension doc for the field that the template renders // First it checks if an expanded layout already exists -- if so it will be stored on the dataDoc // using the template layout doc's id as the field key. // If it doesn't find the expanded layout, then it makes a delegate of the template layout and // saves it on the data doc indexed by the template layout's id. // - const expandedLayoutFieldKey = "Layout[" + templateLayoutDoc[Id] + "]"; - const expandedTemplateLayout = extensionDoc?.[expandedLayoutFieldKey]; - if (expandedTemplateLayout === undefined && extensionDoc) { + const expandedLayoutFieldKey = templateField + "-layout[" + templateLayoutDoc[Id] + "]"; + const expandedTemplateLayout = dataDoc?.[expandedLayoutFieldKey]; + if (expandedTemplateLayout === undefined) { setTimeout(() => { - if (!extensionDoc[expandedLayoutFieldKey]) { + if (!dataDoc[expandedLayoutFieldKey]) { const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]"); - extensionDoc[expandedLayoutFieldKey] = newLayoutDoc; + dataDoc[expandedLayoutFieldKey] = newLayoutDoc; newLayoutDoc.resolvedDataDoc = dataDoc; } }, 0); @@ -473,26 +472,6 @@ export namespace Doc { const resolvedDataDoc = containerDataDoc === containerDoc || !containerDataDoc ? undefined : Doc.GetDataDoc(containerDataDoc); return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc), data: resolvedDataDoc }; } - - // - // Resolves a reference to a field by returning 'doc' if no field extension is specified, - // otherwise, it returns the extension document stored in doc.<fieldKey>_ext. - // This mechanism allows any fields to be extended with an extension document that can - // be used to capture field-specific metadata. For example, an image field can be extended - // to store annotations, ink, and other data. - // - export function fieldExtensionDoc(doc: Doc, fieldKey: string) { - if (!fieldKey) return undefined; - const extension = doc[fieldKey + "_ext"]; - if (doc instanceof Doc && extension === undefined) { - setTimeout(() => CreateDocumentExtensionForField(doc, fieldKey), 0); - } - return extension ? extension as Doc : undefined; - } - export function fieldExtensionDocSync(doc: Doc, fieldKey: string) { - return (doc[fieldKey + "_ext"] as Doc) || CreateDocumentExtensionForField(doc, fieldKey); - } - export function CreateDocumentExtensionForField(doc: Doc, fieldKey: string) { let proto: Doc | undefined = doc; while (proto && !Doc.IsPrototype(proto) && proto.proto) { @@ -586,8 +565,8 @@ export namespace Doc { export function ApplyTemplateTo(templateDoc: Doc, target: Doc, targetKey: string, titleTarget: string | undefined = undefined) { if (!templateDoc) { target.layout = undefined; - target.nativeWidth = undefined; - target.nativeHeight = undefined; + target._nativeWidth = undefined; + target._nativeHeight = undefined; target.onClick = undefined; target.type = undefined; return; @@ -600,7 +579,7 @@ export namespace Doc { Doc.GetProto(target).type = DocumentType.TEMPLATE; target.onClick = templateDoc.onClick instanceof ObjectField && templateDoc.onClick[Copy](); - Doc.GetProto(target)[targetKey] = layoutCustomLayout; + Doc.GetProto(target)[targetKey] = new PrefetchProxy(layoutCustomLayout); } target.layoutKey = targetKey; return target; @@ -648,12 +627,12 @@ export namespace Doc { const doc1Layout = Doc.Layout(doc1); const x2 = NumCast(doc2.x) - clusterDistance; const y2 = NumCast(doc2.y) - clusterDistance; - const w2 = NumCast(doc2Layout.width) + clusterDistance; - const h2 = NumCast(doc2Layout.height) + clusterDistance; + const w2 = NumCast(doc2Layout._width) + clusterDistance; + const h2 = NumCast(doc2Layout._height) + clusterDistance; const x = NumCast(doc1.x) - clusterDistance; const y = NumCast(doc1.y) - clusterDistance; - const w = NumCast(doc1Layout.width) + clusterDistance; - const h = NumCast(doc1Layout.height) + clusterDistance; + const w = NumCast(doc1Layout._width) + clusterDistance; + const h = NumCast(doc1Layout._height) + clusterDistance; return doc1.z === doc2.z && intersectRect({ left: x, top: y, width: w, height: h }, { left: x2, top: y2, width: w2, height: h2 }); } @@ -773,16 +752,14 @@ export namespace Doc { source && source.layout instanceof Doc && source.layout.isTemplateDoc ? source.layout : undefined; } - export function MakeDocFilter(docFilters: string[]) { - let docFilterText = ""; - for (let i = 0; i < docFilters.length; i += 3) { - const key = docFilters[i]; - const value = docFilters[i + 1]; - const modifiers = docFilters[i + 2]; - const scriptText = `${modifiers === "x" ? "!" : ""}matchFieldValue(doc, "${key}", "${value}")`; - docFilterText = docFilterText ? docFilterText + " || " + scriptText : scriptText; + export function matchFieldValue(doc: Doc, key: string, value: any): boolean { + const fieldVal = doc[key] ? doc[key] : doc[key + "_ext"]; + if (Cast(fieldVal, listSpec("string"), []).length) { + const vals = Cast(fieldVal, listSpec("string"), []); + return vals.some(v => v === value); } - return docFilterText ? "(" + docFilterText + ")" : ""; + const fieldStr = Field.toString(fieldVal as Field); + return fieldStr == value; } } @@ -802,17 +779,8 @@ Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: bo const docs = DocListCast(Doc.UserDoc().SelectedDocs).filter(d => !Doc.AreProtosEqual(d, container) && !d.annotationOn && d.type !== DocumentType.DOCUMENT && d.type !== DocumentType.KVP && (!excludeCollections || !Cast(d.data, listSpec(Doc), null))); return docs.length ? new List(docs) : prevValue; }); -Scripting.addGlobal(function matchFieldValue(doc: Doc, key: string, value: any) { - const fieldVal = doc[key] ? doc[key] : doc[key + "_ext"]; - if (Cast(fieldVal, listSpec("string"), []).length) { - const vals = Cast(fieldVal, listSpec("string"), []); - return vals.some(v => v === value); - } - const fieldStr = Field.toString(fieldVal as Field); - return fieldStr == value; -}); Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: string) { - const docFilters = Cast(container.docFilter, listSpec("string"), []); + const docFilters = Cast(container._docFilter, listSpec("string"), []); for (let i = 0; i < docFilters.length; i += 3) { if (docFilters[i] === key && docFilters[i + 1] === value) { docFilters.splice(i, 3); @@ -823,8 +791,6 @@ Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: an docFilters.push(key); docFilters.push(value) docFilters.push(modifiers); - container.docFilter = new List<string>(docFilters); + container._docFilter = new List<string>(docFilters); } - const docFilterText = Doc.MakeDocFilter(docFilters); - container.viewSpecScript = docFilterText ? ScriptField.MakeFunction(docFilterText, { doc: Doc.name }) : undefined; });
\ No newline at end of file diff --git a/src/new_fields/RichTextUtils.ts b/src/new_fields/RichTextUtils.ts index 682206aa2..6f34c82db 100644 --- a/src/new_fields/RichTextUtils.ts +++ b/src/new_fields/RichTextUtils.ts @@ -273,7 +273,7 @@ export namespace RichTextUtils { const guid = Utils.GenerateDeterministicGuid(src); const backingDocId = StrCast(textNote[guid]); if (!backingDocId) { - const backingDoc = Docs.Create.ImageDocument(src, { width: 300, height: 300 }); + const backingDoc = Docs.Create.ImageDocument(src, { _width: 300, _height: 300 }); DocumentView.makeCustomViewClicked(backingDoc, undefined); docid = backingDoc[Id]; textNote[guid] = docid; diff --git a/src/new_fields/documentSchemas.ts b/src/new_fields/documentSchemas.ts index 180c52b3d..44ba6d65c 100644 --- a/src/new_fields/documentSchemas.ts +++ b/src/new_fields/documentSchemas.ts @@ -8,16 +8,18 @@ export const documentSchema = createSchema({ layoutKey: "string", // holds the field key for the field that actually holds the current lyoat layoutCustom: Doc, // used to hold a custom layout (there's nothing special about this field .. any field could hold a custom layout that can be selected by setting 'layoutKey') title: "string", // document title (can be on either data document or layout) - nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set - nativeHeight: "number", // " - width: "number", // width of document in its container's coordinate system - height: "number", // " + _dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias" or "copy") + _nativeWidth: "number", // native width of document which determines how much document contents are scaled when the document's width is set + _nativeHeight: "number", // " + _width: "number", // width of document in its container's coordinate system + _height: "number", // " + _freeformLayoutEngine: "string",// the string ID for the layout engine to use to layout freeform view documents + _LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews color: "string", // foreground color of document backgroundColor: "string", // background color of document opacity: "number", // opacity of document creationDate: DateField, // when the document was created links: listSpec(Doc), // computed (readonly) list of links associated with this document - dropAction: "string", // override specifying what should happen when this document is dropped (can be "alias" or "copy") removeDropProperties: listSpec("string"), // properties that should be removed from the alias/copy/etc of this document when it is dropped onClick: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop) onPointerDown: ScriptField, // script to run when document is clicked (can be overriden by an onClick prop) @@ -56,7 +58,6 @@ export const documentSchema = createSchema({ xPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set yPadding: "number", // pixels of padding on left/right of collectionfreeformview contents when fitToBox is set LODarea: "number", // area (width*height) where CollectionFreeFormViews switch from a label to rendering contents - LODdisable: "boolean", // whether to disbale LOD switching for CollectionFreeFormViews letterSpacing: "string", textTransform: "string" }); diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 3255c6172..2cedda7a6 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -7,6 +7,7 @@ import { ObjectField } from "./ObjectField"; import { action, trace } from "mobx"; import { Parent, OnUpdate, Update, Id, SelfProxy, Self } from "./FieldSymbols"; import { DocServer } from "../client/DocServer"; +import { props } from "bluebird"; function _readOnlySetter(): never { throw new Error("Documents can't be modified in read-only mode"); @@ -35,6 +36,7 @@ const _setterImpl = action(function (target: any, prop: string | symbol | number target[prop] = value; return true; } + if (typeof prop === "symbol") { target[prop] = value; return true; @@ -98,11 +100,38 @@ export function makeEditable() { _setter = _setterImpl; } -export function setter(target: any, prop: string | symbol | number, value: any, receiver: any): boolean { +let layoutProps = ["panX", "panY", "width", "height", "nativeWidth", "nativeHeight", "fitWidth", "fitToBox", + "LODdisable", "dropAction", "chromeStatus", "viewType", "gridGap", "xMargin", "yMargin", "autoHeight"]; +export function setter(target: any, in_prop: string | symbol | number, value: any, receiver: any): boolean { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + resolvedLayout[prop] = value; + return true; + } + } return _setter(target, prop, value, receiver); } -export function getter(target: any, prop: string | symbol | number, receiver: any): any { +export function getter(target: any, in_prop: string | symbol | number, receiver: any): any { + let prop = in_prop; + if (typeof prop === "string" && prop !== "__id" && prop !== "__fields" && + ((prop as string).startsWith("_") || layoutProps.includes(prop))) { + if (!prop.startsWith("_")) { + console.log(prop + " is deprecated - switch to _" + prop); + prop = "_" + prop; + } + const resolvedLayout = getFieldImpl(target, getFieldImpl(target, "layoutKey", receiver), receiver); + if (resolvedLayout instanceof Doc) { + return resolvedLayout[prop]; + } + } if (prop === "then") {//If we're being awaited return undefined; } |
