aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-05-16 11:46:22 -0400
committerbobzel <zzzman@gmail.com>2025-05-16 11:46:22 -0400
commit2c26d7c96e56344a1a73a7c6f6dec3d6b0f0ee7e (patch)
tree711b88a3c257d3fc5e5e71fd87cf1c8cebdbcd23 /src/fields/Doc.ts
parent3741baee864a8bec757b4e50a58698a0064293be (diff)
changed isGroup to freeform_isGroup to fix issues with groups that are changed into other collection types. fixed toggleTarget links to work when opening in a light box (previously they flickered on, then off). fixed text boxes with a number field as data to act like a number input box.
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts54
1 files changed, 33 insertions, 21 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index 0d11b9743..e110550e6 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -536,23 +536,35 @@ export namespace Doc {
export function GetT<T extends FieldType>(doc: Doc, key: string, ctor: ToConstructor<T>, ignoreProto: boolean = false): FieldResult<T> {
return Cast(Get(doc, key, ignoreProto), ctor) as FieldResult<T>;
}
- export function isTemplateDoc(doc: Doc) {
- return GetT(doc, 'isTemplateDoc', 'boolean', true);
- }
- export function isTemplateForField(doc: Doc) {
- return GetT(doc, 'isTemplateForField', 'string', true);
- }
- export function IsDataProto(doc: Doc) {
- return GetT(doc, 'isDataDoc', 'boolean', true);
- }
- export function IsBaseProto(doc: Doc) {
- return GetT(doc, 'isBaseProto', 'boolean', true);
- }
- export function IsSystem(doc: Doc) {
- return GetT(doc, 'isSystem', 'boolean', true);
- }
- export function IsDelegateField(doc: Doc, fieldKey: string) {
- return doc && Get(doc, fieldKey, true) !== undefined;
+ /**
+ * Tests whether the Doc is flagged as being a template.
+ * Templates can be set as a layout for another target Doc. When rendered by the target Doc, the template
+ * creates an instance of itself that holds rendering data specific to the target
+ * @param doc
+ */
+ export function IsTemplateDoc(doc: Doc) { return GetT(doc, 'isTemplateDoc', 'boolean', true); } // prettier-ignore
+ /**
+ * Tests whether the Doc is flagged as being a template for rendering a specific field of a Doc
+ * When flagged as field template and rendered, the template will redirect its componentView to write to the
+ * specified template field. In general, a compound Doc template will contain multiple field templates, one for each of the
+ * data fields rendered by the compound template.
+ * @param doc
+ * @returns
+ */
+ export function IsTemplateForField(doc: Doc) { return GetT(doc, 'isTemplateForField', 'string', true); } // prettier-ignore
+ export function IsDataProto(doc: Doc) { return GetT(doc, 'isDataDoc', 'boolean', true); } // prettier-ignore
+ export function IsBaseProto(doc: Doc) { return GetT(doc, 'isBaseProto', 'boolean', true); } // prettier-ignore
+ export function IsSystem(doc: Doc) { return GetT(doc, 'isSystem', 'boolean', true); } // prettier-ignore
+ export function IsDelegateField(doc: Doc, fieldKey: string) { return doc && Get(doc, fieldKey, true) !== undefined; } // prettier-ignore
+ /**
+ * Tests whether a doc is a freeform collection that renders as a group.
+ * The group variant of a collection automatically resizes so that none of its contents
+ * are ever hidden.
+ * @param doc doc to test for being a freeform group
+ * @returns boolean
+ */
+ export function IsFreeformGroup(doc: Doc) {
+ return doc.freeform_isGroup && doc.type_collection === CollectionViewType.Freeform;
}
//
// this will write the value to the key on either the data doc or the embedding doc. The choice
@@ -734,7 +746,7 @@ export namespace Doc {
const FindDocsInRTF = new RegExp(/(audioId|textId|anchorId|docId)"\s*:\s*"(.*?)"/g);
export function makeClone(doc: Doc, cloneMap: Map<string, Doc>, linkMap: Map<string, Doc>, rtfs: { copy: Doc; key: string; field: RichTextField }[], exclusions: string[], pruneDocs: Doc[], cloneLinks: boolean, cloneTemplates: boolean): Doc {
- if (Doc.IsBaseProto(doc) || ((Doc.isTemplateDoc(doc) || Doc.isTemplateForField(doc)) && !cloneTemplates)) {
+ if (Doc.IsBaseProto(doc) || ((Doc.IsTemplateDoc(doc) || Doc.IsTemplateForField(doc)) && !cloneTemplates)) {
return doc;
}
if (cloneMap.get(doc[Id])) return cloneMap.get(doc[Id])!;
@@ -808,7 +820,7 @@ export namespace Doc {
const docAtKey = DocCast(clone[key]);
if (docAtKey && !Doc.IsSystem(docAtKey)) {
if (!Array.from(cloneMap.values()).includes(docAtKey)) {
- clone[key] = !cloneTemplates && (Doc.isTemplateDoc(docAtKey) || Doc.isTemplateForField(docAtKey)) ? docAtKey : cloneMap.get(docAtKey[Id]);
+ clone[key] = !cloneTemplates && (Doc.IsTemplateDoc(docAtKey) || Doc.IsTemplateForField(docAtKey)) ? docAtKey : cloneMap.get(docAtKey[Id]);
} else {
repairClone(docAtKey, cloneMap, cloneTemplates, visited);
}
@@ -859,7 +871,7 @@ export namespace Doc {
*/
export function expandTemplateLayout(templateLayoutDoc: Doc, targetDoc?: Doc, layoutFieldKey?: string) {
// nothing to do if the layout isn't a template or we don't have a target that's different than the template
- if (!targetDoc || templateLayoutDoc === targetDoc || (!Doc.isTemplateForField(templateLayoutDoc) && !Doc.isTemplateDoc(templateLayoutDoc))) {
+ if (!targetDoc || templateLayoutDoc === targetDoc || (!Doc.IsTemplateForField(templateLayoutDoc) && !Doc.IsTemplateDoc(templateLayoutDoc))) {
return templateLayoutDoc;
}
@@ -922,7 +934,7 @@ export namespace Doc {
console.log('Warning: GetLayoutDataDocPair childDoc not defined');
return { layout: childDoc, data: childDoc };
}
- const data = Doc.AreProtosEqual(containerDataDoc, containerDoc) || (!Doc.isTemplateDoc(childDoc) && !Doc.isTemplateForField(childDoc)) ? undefined : containerDataDoc;
+ const data = Doc.AreProtosEqual(containerDataDoc, containerDoc) || (!Doc.IsTemplateDoc(childDoc) && !Doc.IsTemplateForField(childDoc)) ? undefined : containerDataDoc;
const templateRoot = DocCast(containerDoc?.rootDocument);
return { layout: Doc.expandTemplateLayout(childDoc, templateRoot, layoutFieldKey), data };
}