From af94458be6620ae8a05730f17ee3fc4ec403cf09 Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Tue, 3 Dec 2024 19:44:25 -0500
Subject: bunch of changes related to rendering changes to template docs;
 trying to make it so docs don't need to rerender every time, and so that all
 attributes are accounted for.

---
 .../views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx     | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
index 890bc6f73..95f0da43d 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
@@ -20,4 +20,12 @@ export class TemplateManager {
     getValidTemplates = (cols: Col[]): Template[] => {
         return this.templates.filter(template => template.isValidTemplate(cols));
     }
+
+    addTemplate = (newTemplate: Template) =>{
+        this.templates.push(newTemplate);
+    }
+
+    removeTemplate = (template: Template) => {
+        this.templates.splice(this.templates.indexOf(template), 1);
+    }
 }
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 047bd02ea4f2a7f565ddfb5da9d1c0685d18e08e Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Sat, 7 Dec 2024 01:32:44 -0500
Subject: work started on field interface --> inheritcance structure

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 15 ++--
 .../DocCreatorMenu/FieldTypes/DynamicField.tsx     | 34 +++++++-
 .../DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx | 81 +++++++++++++++----
 .../DocCreatorMenu/FieldTypes/StaticField.tsx      | 94 +++++++++++++---------
 .../nodes/DataVizBox/DocCreatorMenu/Template.tsx   | 20 ++---
 .../DataVizBox/DocCreatorMenu/TemplateManager.tsx  |  4 +
 src/fields/Doc.ts                                  |  2 +-
 7 files changed, 175 insertions(+), 75 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index d45e11f95..079d222d3 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -399,16 +399,19 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
     testTemplate = async () => {
 
+        const obj = new DocumentOptions();
+        console.log(Object.entries(obj)[1][0]);
+
         //console.log(this.templateManager.templates)
 
-        const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+        // const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
         
-        this.templateManager.templates.forEach(template => {
-            const doc = template.mainField.renderedDoc();
-            mainCollection.addDocument(doc);
-        })
+        // this.templateManager.templates.forEach(template => {
+        //     const doc = template.mainField.renderedDoc();
+        //     mainCollection.addDocument(doc);
+        // })
 
-        this.forceUpdate();
+        // this.forceUpdate();
 
         // try {
         //     const res = await gptImageCall('Image of panda eating a cookie');
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
index c6f07d6c6..428f4a01c 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
@@ -1,12 +1,16 @@
-import { Doc } from "../../../../../../fields/Doc";
+import { makeAutoObservable, reaction } from "mobx";
+import { Doc, DocListCast } from "../../../../../../fields/Doc";
 import { Docs } from "../../../../../documents/Documents";
 import { Col } from "../DocCreatorMenu";
 import { TemplateLayouts } from "../TemplateBackend";
 import { Field, FieldContentType, FieldDimensions, FieldSettings, ViewType } from "./Field";
 import { FieldUtils } from "./FieldUtils";
 import { StaticField } from "./StaticField";
+import { IDisposer } from "mobx-utils";
+
+export class DynamicField extends Field {
+    private disposers: { [name: string]: IDisposer } = {};
 
-export class DynamicField implements Field {
     private subfields: Field[] = [];
 
     private id: number;
@@ -16,7 +20,11 @@ export class DynamicField implements Field {
     private parent: Field;
     private dimensions: FieldDimensions;
 
+    private renderedDocument: Doc;
+
     constructor(settings: FieldSettings, id: number, parent?: Field) {
+        super(settings, id);
+        makeAutoObservable(this);
         this.id = id;
         this.settings = settings;
         if (settings.title) { this.title = settings.title };
@@ -28,6 +36,13 @@ export class DynamicField implements Field {
             this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
         }
         this.subfields = this.setupSubfields();
+
+        // this.disposers.fieldList = reaction(
+        //     () => DocListCast(this.doc[Doc.LayoutFieldKey(this.doc)]),
+        //     docs => {
+        //         this.handleFieldUpdate(docs);
+        //     }
+        // );
     }
 
     setContent = (content: string, type?: FieldContentType) => { return };
@@ -59,6 +74,21 @@ export class DynamicField implements Field {
         return this.settings.description ?? '';
     }
 
+    // dispose = () => {
+    //     Object.values(this.disposers).forEach(disposer => disposer?.());
+    // }
+
+    // handleFieldUpdate = (newDocsList: Doc[]) => {
+    //     const currRenderedDocs: Set<Doc> = new Set();
+    //     this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc()));
+    //     newDocsList.forEach(doc => {
+    //         if (!currRenderedDocs.has(doc)) {
+    //             this.addField(doc);
+    //         }
+    //     });
+    //     currRenderedDocs.forEach();
+    // }
+
     matches = (cols: Col[]): Array<number> => {
         return [];
     }
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
index 5eaa7381c..14f7cb109 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
@@ -1,23 +1,72 @@
 import { Doc } from "../../../../../../fields/Doc";
 import { Col } from "../DocCreatorMenu";
 import { TemplateFieldSize, TemplateFieldType } from "../TemplateBackend";
+import { DynamicField } from "./DynamicField";
+import { FieldUtils } from "./FieldUtils";
+import { StaticField } from "./StaticField";
+
+export abstract class Field {
+    protected subfields: Field[] = [];
+
+    protected abstract renderedDocument: Doc;
+
+    protected id: number;
+    protected settings: FieldSettings;
+    protected title: string = '';
+
+    protected abstract dimensions: FieldDimensions;
+
+    constructor(settings: FieldSettings, id: number) {
+        this.id = id;
+        this.settings = settings;
+        this.title = settings.title ?? '';
+    }
+
+    get getSubfields(): Field[] { return this.subfields ?? []; };
+    get getAllSubfields() {
+        let fields: Field[] = [];
+        this.subfields?.forEach(field => {
+            fields.push(field);
+            fields = fields.concat(field.getAllSubfields)
+        });
+        return fields;
+    };
+
+    get renderedDoc() { return this.renderedDocument };
+    get getDimensions() { return this.dimensions };
+    get getID() { return this.id };
+    get getViewType() { return this.settings.viewType };
+
+    setTitle = (title: string) => { 
+        this.title = title;
+        this.renderedDocument.title = title;
+    };
+    getTitle = () => { return this.title };
+
+    abstract setContent(content: string, type?: FieldContentType): void;
+    abstract getContent(): string;
+
+    addField = () => {};
+    removeField = () => {};
+
+    setupSubfields = (): Field[] => {
+        return this.settings.subfields?.map((fieldSettings, index) => {
+            const id = Number(`${this.id}${index}`);
+            return fieldSettings.viewType === ViewType.FREEFORM || fieldSettings.viewType === ViewType.CAROUSEL3D
+                ? new DynamicField(fieldSettings, id, this)
+                : new StaticField(fieldSettings, this, id);
+        }) || [];
+    }
+
+    applyAttributes(field: Field) {
+        field.setTitle(this.title);
+        field.updateRenderedDoc(this.renderedDoc);
+    }
+
+    abstract updateRenderedDoc(oldDoc?: Doc): void;
+
+    abstract matches(cols: Col[]): Array<number>;
 
-export interface Field {
-    getContent: () => string;
-    setContent: (content: string, type?: FieldContentType) => void;
-    getDimensions: FieldDimensions;
-    getSubfields: Field[];
-    getAllSubfields: Field[];
-    getID: number;
-    getViewType: ViewType;
-    getDescription: string;
-    getTitle: () => string;
-    setTitle: (title: string) => void;
-    setupSubfields: () => Field[];
-    applyAttributes: (field: Field) => void;
-    renderedDoc: () => Doc;
-    matches: (cols: Col[]) => number[];
-    updateRenderedDoc: (oldDoc?: Doc) => void;
 }
 
 export type FieldSettings = {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
index f5d86f56e..88115c529 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
@@ -1,5 +1,5 @@
 import { TbHospital } from "react-icons/tb";
-import { Doc } from "../../../../../../fields/Doc";
+import { Doc, DocListCast } from "../../../../../../fields/Doc";
 import { FieldType } from "../../../../../../fields/ObjectField";
 import { Docs, DocumentOptions } from "../../../../../documents/Documents";
 import { Col } from "../DocCreatorMenu";
@@ -9,33 +9,38 @@ import { FieldUtils } from "./FieldUtils";
 import { Field, FieldContentType, FieldDimensions, FieldSettings, ViewType } from "./Field";
 import { indexOf } from "lodash";
 import { ScriptField } from "../../../../../../fields/ScriptField";
+import { StrCast } from "../../../../../../fields/Types";
+import { makeAutoObservable, reaction } from "mobx";
+import { IDisposer } from "mobx-utils";
+
+export class StaticField extends Field {
+    private disposers: { [name: string]: IDisposer } = {};
 
-export class StaticField {
     private content: string;
     private contentType: FieldContentType | undefined;
-    private subfields: Field[] = [];
-    private renderedDocument: Doc;
+    protected renderedDocument: Doc;
 
     private storedAttributes: Record<string, any>;
 
-    private id: number;
-    private title: string = '';
-
-    private settings: FieldSettings;
-
     private parent: Field;
-    private dimensions: FieldDimensions;
+    protected dimensions: FieldDimensions;
 
     constructor(settings: FieldSettings, parent: Field, id: number) {
-        this.settings = settings;
-        if (settings.title) { this.title = settings.title };
-        this.id = id;
+        super(settings, id);
+        makeAutoObservable(this);
         this.parent = parent;
         this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
         this.content = '';
         this.subfields = this.setupSubfields();
-        this.renderedDocument = this.updateRenderedDoc();
+        this.renderedDocument = this.setupRenderedDoc();
         this.storedAttributes = new DocumentOptions();
+
+        this.disposers.fieldList = reaction(
+            () => DocListCast(this.renderedDocument[Doc.LayoutFieldKey(this.renderedDocument)]),
+            docs => {
+                this.handleFieldUpdate(docs);
+            }
+        );
     };
 
     get getSubfields(): Field[] { return this.subfields ?? []; };
@@ -49,18 +54,10 @@ export class StaticField {
         return fields;
     };
 
-    get getDimensions() { return this.dimensions };
-    get getID() { return this.id };
-    get getViewType() { return this.settings.viewType };
-
     get getDescription(): string {
         return this.settings.description ?? '';
     }
 
-    renderedDoc = () => {
-        return this.renderedDocument;
-    }
-
     setContent = (newContent: string, type?: FieldContentType) => { 
         this.content = newContent;
         if (type) this.contentType = type;
@@ -68,16 +65,9 @@ export class StaticField {
     };
     getContent() { return this.content };
 
-    setTitle = (title: string) => { 
-        this.title = title;
-        this.renderedDocument.title = title;
-    };
-    getTitle = () => { return this.title };
-
     applyAttributes = (field: Field) => { //!!! can be updated later for more robust clonign; this is all ythat's needed now
-        field.setTitle(this.title);
+        super.applyAttributes(field);
         field.setContent('', this.contentType);
-        field.updateRenderedDoc(this.renderedDoc());
     }
 
     setupSubfields = (): Field[] => {
@@ -89,6 +79,26 @@ export class StaticField {
         }) || [];
     }
 
+    dispose = () => {
+        Object.values(this.disposers).forEach(disposer => disposer?.());
+    }
+
+    handleFieldUpdate = (newDocsList: Doc[]) => {
+        const currRenderedDocs: Set<Doc> = new Set();
+        this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc));
+        newDocsList.forEach(doc => {
+            if (!currRenderedDocs.has(doc)) {
+                this.addField(doc);
+            }
+        });
+        currRenderedDocs.forEach(doc => {
+            if (!newDocsList.includes(doc)){
+                const fields = this.subfields.filter(field => field.renderedDoc === doc);
+                fields.forEach(field => this.removeField(field));
+            }
+        });
+    }
+
     matches = (cols: Col[]): number[] => {
         const colMatchesField = (col: Col) => {
             const isMatch: boolean = (
@@ -150,8 +160,16 @@ export class StaticField {
 
         let doc: Doc;
 
-        if (this.shouldRerender() || forceRerender) {
-            this.updateStoredAttributes(this.renderedDocument);
+        // if (this.shouldRerender() || forceRerender) {
+        // } else {
+        //     this.updateStoredAttributes(this.renderedDocument);
+        // }
+
+        this.updateStoredAttributes(this.renderedDocument);
+
+        let list: string[] = Object.entries(this.storedAttributes).map(([key, value]) => `${key}: ${value}`);
+        console.log(list);
+
             switch (this.contentType) {
                 case FieldContentType.STRING:
                     const text = String(this.content);
@@ -164,16 +182,20 @@ export class StaticField {
                     break;
             } 
             doc._layout_hideScroll = true;  
+
+
+            console.log(StrCast(doc.backgroundColor), StrCast(doc._rotation));
+
             this.renderedDocument = doc;
-        } else {
-            this.updateStoredAttributes(this.renderedDocument);
-        }
+
+        //this.renderedDocument = doc;
     };
 
     private updateStoredAttributes = (currDoc?: Doc) => {
         const opts = this.settings.opts;
+        console.log("num atts", Object.entries(this.storedAttributes).length);
         Object.entries(this.storedAttributes).forEach(([key, value]) => {
-            key = String(key);
+            key = String(key); 
             if (currDoc && currDoc[key] !== undefined) {
                 this.storedAttributes[key] = currDoc[key];
             } else if (opts[key as keyof typeof opts] !== undefined) {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
index 94ef1d212..add588046 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
@@ -1,6 +1,6 @@
 
-import { makeAutoObservable } from "mobx";
-import { Doc, FieldType } from "../../../../../fields/Doc";
+import { makeAutoObservable, reaction } from "mobx";
+import { Doc, DocListCast, FieldType } from "../../../../../fields/Doc";
 import { Docs } from "../../../../documents/Documents";
 import { Col } from "./DocCreatorMenu";
 import { DynamicField } from "./FieldTypes/DynamicField";
@@ -8,32 +8,24 @@ import { Field, FieldSettings, ViewType } from "./FieldTypes/Field";
 import {  } from "./FieldTypes/FieldUtils";
 import { } from "./FieldTypes/StaticField";
 import { observer } from "mobx-react";
+import { IDisposer } from "mobx-utils";
 
 export class Template {
 
-    mainField: DynamicField;
-    settings: FieldSettings;
-    
+    private mainField: DynamicField;
+    private settings: FieldSettings;
 
     constructor(templateInfo: FieldSettings) {
         makeAutoObservable(this);
         this.mainField = this.setupMainField(templateInfo);
         this.settings = templateInfo;
-
     }
 
-
-
     get childFields(): Field[] { return this.mainField.getSubfields };
     get allFields(): Field[] { return this.mainField.getAllSubfields };
     get contentFields(): Field[] { return this.allFields.filter(field => field.getViewType === ViewType.STATIC) };
     get doc(){ return this.mainField.renderedDoc(); };
 
-    // addField = (type: FieldType, doc?: Doc): Field => {
-        
-    //     this.mainField.addField();
-    // }
-
     cloneBase = () => {
         const clone: Template = new Template(this.settings);
         clone.allFields.forEach(field => {
@@ -44,7 +36,7 @@ export class Template {
     }
 
     getRenderedDoc = () => {
-        const doc: Doc = this.mainField.renderedDoc();
+        const doc: Doc = this.doc;
         this.contentFields.forEach(field => {
             const title: string = field.getTitle();
             const val: FieldType = field.getContent() as FieldType;
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
index 95f0da43d..310b19890 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
@@ -1,3 +1,4 @@
+import { makeAutoObservable } from "mobx";
 import { Col } from "./DocCreatorMenu";
 import { FieldSettings } from "./FieldTypes/Field";
 import { Template } from "./Template";
@@ -6,8 +7,10 @@ import { TemplateLayouts } from "./TemplateBackend";
 export class TemplateManager {
 
     templates: Template[] = [];
+    //updateTrack
 
     constructor(templateSettings: FieldSettings[]) {
+        makeAutoObservable(this);
         this.templates = this.initializeTemplates(templateSettings);
     }
 
@@ -27,5 +30,6 @@ export class TemplateManager {
 
     removeTemplate = (template: Template) => {
         this.templates.splice(this.templates.indexOf(template), 1);
+        template.dispose();
     }
 }
\ No newline at end of file
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index a9bc5ee70..3f8de2988 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -576,7 +576,7 @@ export namespace Doc {
             if (!skipUndefineds || value !== undefined) {
                 // Do we want to filter out undefineds?
                 if (typeof value === 'object' && 'values' in value) {
-                    console.log(value);
+                    //console.log(value);
                 }
                 doc[key] = value;
             }
-- 
cgit v1.2.3-70-g09d2


From fe744903609e669c5f3048743ceba9268b8dfe0d Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Sat, 7 Dec 2024 19:46:07 -0500
Subject: field superclass

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 82 ++++++++-----------
 .../DocCreatorMenu/FieldTypes/DynamicField.tsx     | 91 ++--------------------
 .../DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx | 84 +++++++++++++++++---
 .../DocCreatorMenu/FieldTypes/StaticField.tsx      | 53 -------------
 .../nodes/DataVizBox/DocCreatorMenu/Template.tsx   | 11 ++-
 .../DataVizBox/DocCreatorMenu/TemplateManager.tsx  |  2 +-
 6 files changed, 121 insertions(+), 202 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index 079d222d3..d8a71a610 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -400,7 +400,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     testTemplate = async () => {
 
         const obj = new DocumentOptions();
-        console.log(Object.entries(obj)[1][0]);
 
         //console.log(this.templateManager.templates)
 
@@ -545,7 +544,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     compileFieldDescriptions = (templates: Template[]): string => {
         let descriptions: string = '';
         templates.forEach(template => {
-            descriptions += `----------  NEW TEMPLATE TO INCLUDE: The title is: ${template.mainField.getTitle()}. Its fields are: `;
+            descriptions += `----------  NEW TEMPLATE TO INCLUDE: The title is: ${template.title}. Its fields are: `;
             descriptions += template.descriptionSummary;
         });
 
@@ -585,7 +584,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                 const brokenDownAssignments: [Template, { [fieldID: number]: Col }][] = [];
 
                 Object.entries(assignments).forEach(([tempTitle, assignment]) => {
-                    const template = templates.filter(template => template.mainField.getTitle() === tempTitle)[0];
+                    const template = templates.filter(template => template.title === tempTitle)[0];
                     if (!template) return;
                     const toObj = Object.entries(assignment).reduce(
                         (a, [fieldID, colTitle]) => {
@@ -707,7 +706,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
     createDocsFromTemplate = async (template: Template) => {
         const dv = this._dataViz;
-        console.log('dataviz: ', dv);
+
         if (!dv) return;
 
         this._docsRendering = true;
@@ -781,7 +780,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     @action setExpandedView = (template: Template | undefined) => {
         if (template) {
             this._currEditingTemplate = template;
-            this._expandedPreview = template.mainField.renderedDoc(); //Docs.Create.FreeformDocument([doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''});
+            this._expandedPreview = template.doc; //Docs.Create.FreeformDocument([doc], { _height: NumListCast(doc._height)[0], _width: NumListCast(doc._width)[0], title: ''});
         } else {
             this._currEditingTemplate = undefined;
             this._expandedPreview = undefined;
@@ -839,6 +838,31 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
         const GPTOptions = <div></div>;
 
+        const previewDoc = (doc: Doc, template: Template) => 
+        <DocumentView
+        Document={doc}
+        isContentActive={emptyFunction} // !!! should be return false
+        addDocument={returnFalse}
+        moveDocument={returnFalse}
+        removeDocument={returnFalse}
+        PanelWidth={() => this._selectedTemplate === template ? 104 : 111}
+        PanelHeight={() => this._selectedTemplate === template ? 104 : 111}
+        ScreenToLocalTransform={() => new Transform(-this._pageX - 5,-this._pageY - 35, 1)}
+        renderDepth={1}
+        whenChildContentsActiveChanged={emptyFunction}
+        focus={emptyFunction}
+        styleProvider={DefaultStyleProvider}
+        addDocTab={this._props.addDocTab}
+        // eslint-disable-next-line no-use-before-define
+        pinToPres={() => undefined}
+        childFilters={returnEmptyFilter}
+        childFiltersByRanges={returnEmptyFilter}
+        searchFilterDocs={returnEmptyDoclist}
+        fitContentsToBox={returnFalse}
+        fitWidth={returnFalse}
+        hideDecorations={true}
+        />
+
         //<img className='docCreatorMenu-preview-image expanded' src={this._expandedPreview.icon!.url.href.replace(".png", "_o.png")} />
 
         return (
@@ -881,29 +905,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                                 <button className="option-button right" onPointerDown={e => this.setUpButtonClick(e, () => this.addUserTemplate(template))}>
                                                     <FontAwesomeIcon icon="plus" color="white" />
                                                 </button>
-                                                <DocumentView
-                                                    Document={doc}
-                                                    isContentActive={emptyFunction} // !!! should be return false
-                                                    addDocument={returnFalse}
-                                                    moveDocument={returnFalse}
-                                                    removeDocument={returnFalse}
-                                                    PanelWidth={() => this._selectedTemplate === template ? 104 : 111}
-                                                    PanelHeight={() => this._selectedTemplate === template ? 104 : 111}
-                                                    ScreenToLocalTransform={() => new Transform(-this._pageX - 5,-this._pageY - 35, 1)}
-                                                    renderDepth={1}
-                                                    whenChildContentsActiveChanged={emptyFunction}
-                                                    focus={emptyFunction}
-                                                    styleProvider={DefaultStyleProvider}
-                                                    addDocTab={this._props.addDocTab}
-                                                    // eslint-disable-next-line no-use-before-define
-                                                    pinToPres={() => undefined}
-                                                    childFilters={returnEmptyFilter}
-                                                    childFiltersByRanges={returnEmptyFilter}
-                                                    searchFilterDocs={returnEmptyDoclist}
-                                                    fitContentsToBox={returnFalse}
-                                                    fitWidth={returnFalse}
-                                                    hideDecorations={true}
-                                                    />
+                                                {previewDoc(doc, template)}
                                             </div>
                                         ))
                                 )}
@@ -950,29 +952,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                                             <button className="option-button right" onPointerDown={e => this.setUpButtonClick(e, () => this.removeUserTemplate(template))}>
                                                 <FontAwesomeIcon icon="minus" color="white" />
                                             </button>
-                                            <DocumentView
-                                                Document={doc}
-                                                isContentActive={emptyFunction} // !!! should be return false
-                                                addDocument={returnFalse}
-                                                moveDocument={returnFalse}
-                                                removeDocument={returnFalse}
-                                                PanelWidth={() => this._selectedTemplate === template ? 104 : 111}
-                                                PanelHeight={() => this._selectedTemplate === template ? 104 : 111}
-                                                ScreenToLocalTransform={() => new Transform(-this._pageX - 5, -this._pageY - 35, 1)}
-                                                renderDepth={1}
-                                                whenChildContentsActiveChanged={emptyFunction}
-                                                focus={emptyFunction}
-                                                styleProvider={DefaultStyleProvider}
-                                                addDocTab={this._props.addDocTab}
-                                                // eslint-disable-next-line no-use-before-define
-                                                pinToPres={() => undefined}
-                                                childFilters={returnEmptyFilter}
-                                                childFiltersByRanges={returnEmptyFilter}
-                                                searchFilterDocs={returnEmptyDoclist}
-                                                fitContentsToBox={returnFalse}
-                                                fitWidth={returnFalse}
-                                                hideDecorations={true}
-                                                />
+                                            {previewDoc(doc, template)}
                                         </div>
                                     ))}
                             </div>
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
index 428f4a01c..681e1d48c 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
@@ -9,25 +9,14 @@ import { StaticField } from "./StaticField";
 import { IDisposer } from "mobx-utils";
 
 export class DynamicField extends Field {
-    private disposers: { [name: string]: IDisposer } = {};
-
-    private subfields: Field[] = [];
-
-    private id: number;
-    private settings: FieldSettings;
-    private title: string = '';
-
     private parent: Field;
-    private dimensions: FieldDimensions;
+    protected dimensions: FieldDimensions;
 
-    private renderedDocument: Doc;
+    protected renderedDocument: Doc;
 
     constructor(settings: FieldSettings, id: number, parent?: Field) {
         super(settings, id);
         makeAutoObservable(this);
-        this.id = id;
-        this.settings = settings;
-        if (settings.title) { this.title = settings.title };
         if (!parent) {
             this.parent = this;
             this.dimensions = {width: this.settings.br[0] - this.settings.tl[0], height: this.settings.br[1] - this.settings.tl[1], coord: {x: this.settings.tl[0], y: this.settings.tl[1]}};
@@ -35,7 +24,7 @@ export class DynamicField extends Field {
             this.parent = parent;
             this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
         }
-        this.subfields = this.setupSubfields();
+        this.renderedDocument = new Doc(); //!!!
 
         // this.disposers.fieldList = reaction(
         //     () => DocListCast(this.doc[Doc.LayoutFieldKey(this.doc)]),
@@ -48,78 +37,10 @@ export class DynamicField extends Field {
     setContent = (content: string, type?: FieldContentType) => { return };
     getContent = () => { return '' };
 
-    setTitle = (title: string) => { this.title = title };
-    getTitle = () => { return this.title };
-
-    // addField = () => {
-    //     const newField: Field = new DynamicField();
-    //     //this.subfields.pu
-    // }
-
-    get getSubfields() { return this.subfields };
-    get getAllSubfields() {
-        let fields: Field[] = [];
-        this.subfields?.forEach(field => {
-            fields.push(field);
-            fields = fields.concat(field.getAllSubfields)
-        });
-        return fields;
-    };
-
-    get getDimensions() { return this.dimensions };
-    get getID() { return this.id };
-    get getViewType() { return this.settings.viewType };
-
-    get getDescription(): string {
-        return this.settings.description ?? '';
-    }
-
-    // dispose = () => {
-    //     Object.values(this.disposers).forEach(disposer => disposer?.());
-    // }
-
-    // handleFieldUpdate = (newDocsList: Doc[]) => {
-    //     const currRenderedDocs: Set<Doc> = new Set();
-    //     this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc()));
-    //     newDocsList.forEach(doc => {
-    //         if (!currRenderedDocs.has(doc)) {
-    //             this.addField(doc);
-    //         }
-    //     });
-    //     currRenderedDocs.forEach();
-    // }
-
     matches = (cols: Col[]): Array<number> => {
         return [];
     }
 
-    updateRenderedDoc = () => {
-        return new Doc();
-    }
-
-    setupSubfields = (): Field[] => {
-        const fields: Field[] = [];
-        this.settings.subfields?.forEach((fieldSettings, index) => {
-            let field: Field;
-            const type = fieldSettings.viewType;
-
-            const id = Number(String(this.id) + String(index));
-
-            if (type == ViewType.CAROUSEL3D || type === ViewType.FREEFORM) {
-                field = new DynamicField(fieldSettings, id, this); 
-            } else {  
-                field = new StaticField(fieldSettings, this, id);
-            }
-            fields.push(field);
-        });
-        return fields;
-    }
-
-    applyAttributes = (field: Field) => {
-        field.setTitle(this.title);
-        field.updateRenderedDoc(this.renderedDoc());
-    }
-
     getChildDimensions = (coords: { tl: [number, number]; br: [number, number] }): FieldDimensions => {
         const l = (coords.tl[0] * this.dimensions.height) / 2;
         const t = coords.tl[1] * this.dimensions.width / 2; //prettier-ignore
@@ -131,16 +52,16 @@ export class DynamicField extends Field {
         return { width, height, coord };
     };
 
-    renderedDoc = (): Doc => {
+    updateRenderedDoc = (): Doc => {
         switch (this.settings.viewType) {
             case ViewType.CAROUSEL3D:
-                const carouselDoc = Docs.Create.Carousel3DDocument(this.subfields.map(field => field.renderedDoc()), {
+                const carouselDoc = Docs.Create.Carousel3DDocument(this.subfields.map(field => field.renderedDoc), {
                     title: this.title,
                 });
                 FieldUtils.applyBasicOpts(carouselDoc, this.dimensions, this.settings);
                 return carouselDoc;
             case ViewType.FREEFORM:
-                const freeformDoc = Docs.Create.FreeformDocument(this.subfields.map(field => field.renderedDoc()), {
+                const freeformDoc = Docs.Create.FreeformDocument(this.subfields.map(field => field.renderedDoc), {
                     title: this.title,
                 });
                 FieldUtils.applyBasicOpts(freeformDoc, this.dimensions, this.settings);
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
index 14f7cb109..4d0aa10c8 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
@@ -1,12 +1,17 @@
-import { Doc } from "../../../../../../fields/Doc";
+import { makeAutoObservable, reaction } from "mobx";
+import { Doc, DocListCast } from "../../../../../../fields/Doc";
 import { Col } from "../DocCreatorMenu";
 import { TemplateFieldSize, TemplateFieldType } from "../TemplateBackend";
 import { DynamicField } from "./DynamicField";
 import { FieldUtils } from "./FieldUtils";
 import { StaticField } from "./StaticField";
+import { IDisposer } from "mobx-utils";
+import { DocumentType } from "../../../../../documents/DocumentTypes";
 
 export abstract class Field {
-    protected subfields: Field[] = [];
+    protected disposers: { [name: string]: IDisposer } = {};
+
+    protected subfields: Field[];
 
     protected abstract renderedDocument: Doc;
 
@@ -17,9 +22,19 @@ export abstract class Field {
     protected abstract dimensions: FieldDimensions;
 
     constructor(settings: FieldSettings, id: number) {
+        makeAutoObservable(this);
+        
         this.id = id;
         this.settings = settings;
         this.title = settings.title ?? '';
+        this.subfields = this.setupSubfields();
+
+        this.disposers.fieldList = reaction(
+            () => DocListCast(this.renderedDocument[Doc.LayoutFieldKey(this.renderedDocument)]),
+            docs => {
+                this.handleFieldUpdate(docs);
+            }
+        );
     }
 
     get getSubfields(): Field[] { return this.subfields ?? []; };
@@ -36,6 +51,7 @@ export abstract class Field {
     get getDimensions() { return this.dimensions };
     get getID() { return this.id };
     get getViewType() { return this.settings.viewType };
+    get getDescription(): string { return this.settings.description ?? '' };
 
     setTitle = (title: string) => { 
         this.title = title;
@@ -46,15 +62,41 @@ export abstract class Field {
     abstract setContent(content: string, type?: FieldContentType): void;
     abstract getContent(): string;
 
-    addField = () => {};
-    removeField = () => {};
+    addFieldFromDoc = (doc: Doc) => {
+        const settings: FieldSettings = {
+            tl: [Number(doc._x), Number(doc._y)],
+            br: [Number(doc._x) + Number(doc._width), Number(doc._y) + Number(doc._height)],
+            viewType: doc.type === DocumentType.COL ? ViewType.FREEFORM : ViewType.STATIC,
+            opts: {},
+        };
+
+        Object.getOwnPropertyNames(FieldOpts.prototype).forEach(([key, value]) => {
+            settings.opts[key as keyof FieldOpts] = StringCast(doc[key]);
+        });
+
+        const newField = this.setupField(settings, this.subfields.length)
+        this.subfields.push(newField);
+    };
+
+    addField = (type?: FieldContentType) => {
+
+    }
+
+    removeField = (field: Field) => {
+        this.subfields.splice(this.subfields.indexOf(field), 1);
+        field.dispose();
+    };
+
+    private setupField = (settings: FieldSettings, index: number): Field => { 
+        const id = Number(`${this.id}${index}`);
+        return settings.viewType === ViewType.FREEFORM || settings.viewType === ViewType.CAROUSEL3D
+        ? new DynamicField(settings, id, this)
+        : new StaticField(settings, this, id); 
+    }
 
     setupSubfields = (): Field[] => {
         return this.settings.subfields?.map((fieldSettings, index) => {
-            const id = Number(`${this.id}${index}`);
-            return fieldSettings.viewType === ViewType.FREEFORM || fieldSettings.viewType === ViewType.CAROUSEL3D
-                ? new DynamicField(fieldSettings, id, this)
-                : new StaticField(fieldSettings, this, id);
+            return this.setupField(fieldSettings, index);
         }) || [];
     }
 
@@ -67,6 +109,26 @@ export abstract class Field {
 
     abstract matches(cols: Col[]): Array<number>;
 
+    dispose = () => {
+        Object.values(this.disposers).forEach(disposer => disposer?.());
+    }
+
+    handleFieldUpdate = (newDocsList: Doc[]) => {
+        const currRenderedDocs: Set<Doc> = new Set();
+        this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc));
+        newDocsList.forEach(doc => {
+            if (!currRenderedDocs.has(doc)) {
+                this.addFieldFromDoc(doc);
+            }
+        });
+        currRenderedDocs.forEach(doc => {
+            if (!newDocsList.includes(doc)){
+                const fields = this.subfields.filter(field => field.renderedDoc === doc);
+                fields.forEach(field => this.removeField(field));
+            }
+        });
+    }
+
 }
 
 export type FieldSettings = {
@@ -99,7 +161,7 @@ export type FieldDimensions = {
     coord: {x: number, y: number};
 }
 
-export interface FieldOpts {
+export class FieldOpts {
     backgroundColor?: string;
     text_fontColor?: string;
     _layout_borderRounding?: number;
@@ -114,3 +176,7 @@ export interface FieldOpts {
     textTransform?: 'uppercase' | 'lowercase';
     fieldViewType?: 'freeform' | 'stacked';
 }
+function StringCast(arg0: unknown): undefined {
+    throw new Error("Function not implemented.");
+}
+
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
index 88115c529..94ff7b8e8 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
@@ -14,7 +14,6 @@ import { makeAutoObservable, reaction } from "mobx";
 import { IDisposer } from "mobx-utils";
 
 export class StaticField extends Field {
-    private disposers: { [name: string]: IDisposer } = {};
 
     private content: string;
     private contentType: FieldContentType | undefined;
@@ -31,33 +30,10 @@ export class StaticField extends Field {
         this.parent = parent;
         this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
         this.content = '';
-        this.subfields = this.setupSubfields();
         this.renderedDocument = this.setupRenderedDoc();
         this.storedAttributes = new DocumentOptions();
-
-        this.disposers.fieldList = reaction(
-            () => DocListCast(this.renderedDocument[Doc.LayoutFieldKey(this.renderedDocument)]),
-            docs => {
-                this.handleFieldUpdate(docs);
-            }
-        );
-    };
-
-    get getSubfields(): Field[] { return this.subfields ?? []; };
-
-    get getAllSubfields(): Field[] {
-        let fields: Field[] = [];
-        this.subfields?.forEach(field => {
-            fields.push(field);
-            fields = fields.concat(field.getAllSubfields);
-        });
-        return fields;
     };
 
-    get getDescription(): string {
-        return this.settings.description ?? '';
-    }
-
     setContent = (newContent: string, type?: FieldContentType) => { 
         this.content = newContent;
         if (type) this.contentType = type;
@@ -70,35 +46,6 @@ export class StaticField extends Field {
         field.setContent('', this.contentType);
     }
 
-    setupSubfields = (): Field[] => {
-        return this.settings.subfields?.map((fieldSettings, index) => {
-            const id = Number(`${this.id}${index}`);
-            return fieldSettings.viewType === ViewType.FREEFORM || fieldSettings.viewType === ViewType.CAROUSEL3D
-                ? new DynamicField(fieldSettings, id, this)
-                : new StaticField(fieldSettings, this, id);
-        }) || [];
-    }
-
-    dispose = () => {
-        Object.values(this.disposers).forEach(disposer => disposer?.());
-    }
-
-    handleFieldUpdate = (newDocsList: Doc[]) => {
-        const currRenderedDocs: Set<Doc> = new Set();
-        this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc));
-        newDocsList.forEach(doc => {
-            if (!currRenderedDocs.has(doc)) {
-                this.addField(doc);
-            }
-        });
-        currRenderedDocs.forEach(doc => {
-            if (!newDocsList.includes(doc)){
-                const fields = this.subfields.filter(field => field.renderedDoc === doc);
-                fields.forEach(field => this.removeField(field));
-            }
-        });
-    }
-
     matches = (cols: Col[]): number[] => {
         const colMatchesField = (col: Col) => {
             const isMatch: boolean = (
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
index add588046..e079af4de 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
@@ -12,7 +12,7 @@ import { IDisposer } from "mobx-utils";
 
 export class Template {
 
-    private mainField: DynamicField;
+    mainField: DynamicField;
     private settings: FieldSettings;
 
     constructor(templateInfo: FieldSettings) {
@@ -24,7 +24,12 @@ export class Template {
     get childFields(): Field[] { return this.mainField.getSubfields };
     get allFields(): Field[] { return this.mainField.getAllSubfields };
     get contentFields(): Field[] { return this.allFields.filter(field => field.getViewType === ViewType.STATIC) };
-    get doc(){ return this.mainField.renderedDoc(); };
+    get doc(){ return this.mainField.renderedDoc; };
+    get title() { return this.mainField.getTitle() };
+
+    cleanup = () => {
+        //dispose each subfields disposers, etc.
+    }
 
     cloneBase = () => {
         const clone: Template = new Template(this.settings);
@@ -76,7 +81,7 @@ export class Template {
 
     renderUpdates = () => {
         this.allFields.forEach(field => {
-            field.updateRenderedDoc(field.renderedDoc());
+            field.updateRenderedDoc(field.renderedDoc);
         });
     };
 
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
index 310b19890..413c3082e 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
@@ -30,6 +30,6 @@ export class TemplateManager {
 
     removeTemplate = (template: Template) => {
         this.templates.splice(this.templates.indexOf(template), 1);
-        template.dispose();
+        template.cleanup();
     }
 }
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2


From 6c5d7c2a4584e73e17593cb54071c91bcf153cca Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Sun, 22 Dec 2024 04:37:25 -0500
Subject: changes for testing without using GPT

---
 src/client/views/nodes/DataVizBox/DataVizBox.tsx   |  8 ++--
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   | 41 ++++++++++--------
 .../DocCreatorMenu/FieldTypes/DynamicField.tsx     |  4 --
 .../DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx |  4 +-
 .../DocCreatorMenu/FieldTypes/StaticField.tsx      | 14 ++----
 .../nodes/DataVizBox/DocCreatorMenu/Template.tsx   | 18 ++++----
 .../DataVizBox/DocCreatorMenu/TemplateBackend.tsx  | 50 ++++++++++++++--------
 .../DataVizBox/DocCreatorMenu/TemplateManager.tsx  |  1 -
 8 files changed, 74 insertions(+), 66 deletions(-)

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DataVizBox.tsx b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
index dececd1dc..117311b8c 100644
--- a/src/client/views/nodes/DataVizBox/DataVizBox.tsx
+++ b/src/client/views/nodes/DataVizBox/DataVizBox.tsx
@@ -411,10 +411,10 @@ export class DataVizBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
             },
             { fireImmediately: true }
         );
-        this._disposers.contentSummary = reaction(
-            () => this.records,
-            () => this.updateGPTSummary()
-        );
+        // this._disposers.contentSummary = reaction(
+        //     () => this.records,
+        //     () => this.updateGPTSummary()
+        // );
     }
 
     fetchData = () => {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index e1f53ec47..e8b80b7b5 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -115,14 +115,15 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         this._userTemplates.push(template);
     };
     @action removeUserTemplate = (template: Template) => {
-        this._userTemplates.splice(this._userTemplates.indexOf(t), 1);
+        this._userTemplates.splice(this._userTemplates.indexOf(template), 1);
     }
     @action setSuggestedTemplates = (templates: Template[]) => {
         this._suggestedTemplates = templates; //prettier-ignore
     };
 
     @computed get docsToRender() {
-        return this._selectedTemplate ? NumListCast(this._dataViz?.layoutDoc.dataViz_selectedRows) : [];
+        return [1, 2, 3, 4];
+        //this._selectedTemplate ? NumListCast(this._dataViz?.layoutDoc.dataViz_selectedRows) : []; !!! put this back for GPT rendering
     }
 
     @computed get rowsCount() {
@@ -357,6 +358,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
     @action updateRenderedPreviewCollection = async (template: Template) => {
         this._fullyRenderedDocs = await this.createDocsFromTemplate(template) ?? [];
+        console.log(this._fullyRenderedDocs);
         this.updateRenderedDocCollection();
     }
 
@@ -716,6 +718,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         });
     
         const processContent = async (content: {[title: string]: string}) => {
+
             const templateCopy = template.cloneBase(); 
 
             fields.filter(title => title).forEach(title => {
@@ -748,19 +751,23 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
     
             return templateCopy.getRenderedDoc();
         };
+
+        const rows = [1, 2, 3, 4];
     
-        const promises = rowContents.map(content => processContent(content));
+        //const promises = rowContents.map(content => processContent(content));
     
+        const promises = rows.map(row => processContent({}));
+
         const renderedDocs = await Promise.all(promises);
 
         this._docsRendering = false; // removes loading indicator
 
+        console.log('docs: ', renderedDocs);
+        console.log('first doc height: ', renderedDocs[0]._height);
+
         return renderedDocs;
     }
 
-    
-    
-
     addRenderedCollectionToMainview = () => {
         const collection = this._renderedDocCollection;
         if (!collection) return;
@@ -822,7 +829,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                         })}>
                         <FontAwesomeIcon icon="minimize" />
                     </button>
-                    <button className="docCreatorMenu-menu-button section-reveal-options top-right-lower" onPointerDown={e => this.setUpButtonClick(e, () => {this._currEditingTemplate?.resetToBase(); this.setExpandedView(this._currEditingTemplate);})}>
+                    <button className="docCreatorMenu-menu-button section-reveal-options top-right-lower" onPointerDown={e => this.setUpButtonClick(e, () => {this._currEditingTemplate?.printFieldInfo();/*this._currEditingTemplate?.resetToBase();*/ this.setExpandedView(this._currEditingTemplate);})}>
                         <FontAwesomeIcon icon="arrows-rotate" color="white" />
                     </button>
                 </div>
@@ -1012,11 +1019,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         collection._height = verticalSpan;
         collection._width = horizontalSpan;
 
-        const layout = this._layout;
-        const columns: number = layout.columns ?? this.columnsCount;
-        const xGap: number = layout.xMargin;
-        const yGap: number = layout.yMargin;
-        // const repeat: number = templateInfo.layout.repeat;
+        const columns: number = this._layout.columns ?? this.columnsCount;
+        const xGap: number = this._layout.xMargin;
+        const yGap: number = this._layout.yMargin;
         const startX: number = -Number(collection._width)/2;
         const startY: number = -Number(collection._height)/2;
         const docHeight: number = Number(docs[0]._height);
@@ -1066,7 +1071,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         console.log('called');
         if (!this._fullyRenderedDocs) return;
 
-        const { horizontalSpan, verticalSpan } = this.previewInfo;
         //const largerSpan: number = horizontalSpan > verticalSpan ? horizontalSpan : verticalSpan;
 
         const collectionFactory = (): (docs: Doc[], options: DocumentOptions) => Doc => {
@@ -1086,19 +1090,22 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
             }
         }
 
-        const collection: Doc = collectionFactory()(this._fullyRenderedDocs, {
+        const collection = collectionFactory()(this._fullyRenderedDocs, {
             isDefaultTemplateDoc: true,
-            _height: verticalSpan,
-            _width: horizontalSpan,
             title: 'title',
             backgroundColor: 'gray',
+            x: 200,
+            y: 200
         });
 
         this.applyLayout(collection, this._fullyRenderedDocs);
 
         this._renderedDocCollection = collection;
 
-        console.log('changed');
+        const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+        mainCollection.addDocument(collection);
+
+        console.log('changed to: ', collection);
     }
 
     layoutPreviewContents = (id?: number) => {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
index c751c91bd..c244dd57c 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
@@ -1,12 +1,8 @@
-import { makeAutoObservable, makeObservable, reaction } from "mobx";
 import { Doc, DocListCast } from "../../../../../../fields/Doc";
 import { Docs } from "../../../../../documents/Documents";
 import { Col } from "../DocCreatorMenu";
-import { TemplateLayouts } from "../TemplateBackend";
 import { Field, FieldContentType, FieldDimensions, FieldSettings, ViewType } from "./Field";
 import { FieldUtils } from "./FieldUtils";
-import { StaticField } from "./StaticField";
-import { IDisposer } from "mobx-utils";
 
 export class DynamicField extends Field {
     protected parent: Field;
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
index 1dd442c97..2aa9f9032 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
@@ -136,8 +136,8 @@ export abstract class Field {
         //this.updateRenderedDoc(this.renderedDoc);
         field.updateRenderedDoc(this.renderedDoc);
         field.subfields = this.subfields;
-        console.log('id:', this.id, 'set width to:', Number(this.renderedDoc.width));
-        console.log('set height to:', Number(this.renderedDoc.height));
+        //console.log('id:', this.id, 'set width to:', Number(this.renderedDoc.width));
+        //console.log('set height to:', Number(this.renderedDoc.height));
     }
 
     abstract updateRenderedDoc(oldDoc?: Doc): void;
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
index 0b2f437e8..df997c8c5 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
@@ -1,17 +1,8 @@
-import { TbHospital } from "react-icons/tb";
 import { Doc, DocListCast } from "../../../../../../fields/Doc";
-import { FieldType } from "../../../../../../fields/ObjectField";
 import { Docs, DocumentOptions } from "../../../../../documents/Documents";
 import { Col } from "../DocCreatorMenu";
-import { Template } from "../Template";
-import { DynamicField } from "./DynamicField";
 import { FieldUtils } from "./FieldUtils";
 import { Field, FieldContentType, FieldDimensions, FieldSettings, ViewType } from "./Field";
-import { indexOf } from "lodash";
-import { ScriptField } from "../../../../../../fields/ScriptField";
-import { StrCast } from "../../../../../../fields/Types";
-import { makeAutoObservable, makeObservable, reaction } from "mobx";
-import { IDisposer } from "mobx-utils";
 
 export class StaticField extends Field {
 
@@ -38,9 +29,10 @@ export class StaticField extends Field {
     setContent = (newContent: string, type?: FieldContentType) => { 
         this.content = newContent;
         if (type) this.contentType = type;
+
         this.updateRenderedDoc(this.renderedDocument /*, true*/);
     };
-    getContent() { return this.content };
+    getContent() { return this.content ?? 'Unset'};
 
     applyAttributes = (field: Field) => { //!!! can be updated later for more robust clonign; this is all ythat's needed now
         super.applyAttributes(field);
@@ -98,6 +90,8 @@ export class StaticField extends Field {
                 break;
         }   
 
+        //doc[this.title] = this.content; broken for some reason
+
         this.renderedDocument = doc;
 
         return doc;
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
index 7515a39be..16e70a47b 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
@@ -9,6 +9,7 @@ import {  } from "./FieldTypes/FieldUtils";
 import { } from "./FieldTypes/StaticField";
 import { observer } from "mobx-react";
 import { IDisposer } from "mobx-utils";
+import { Width } from "../../../../../fields/DocSymbols";
 
 export class Template {
 
@@ -44,16 +45,15 @@ export class Template {
         return clone;
     }
 
-    getRenderedDoc = () => {
-        console.log('called');
-        const doc: Doc = this.doc;
-        this.contentFields.forEach(field => {
-            const title: string = field.getTitle();
-            const val: FieldType = field.getContent() as FieldType;
-            if (!title || !val) return;
-            doc[title] = val;
+    printFieldInfo = () => {
+        this.allFields.forEach(field => {
+            const doc = field.renderedDoc;
+            console.log('title: ', field.getTitle(), ' width: ', doc.width);
         });
-        return doc;
+    }
+
+    getRenderedDoc = () => {
+        return this.doc;
     }
 
     getFieldByID = (id: number): Field => {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
index 4f1186320..bea5c2d5d 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
@@ -491,7 +491,7 @@ export class TemplateLayouts {
         tl:[0,0],
         br:[500, 600],
         opts: {
-            backgroundColor: '#DDD3A9',
+            backgroundColor: '#D7CBAB',
         },
         subfields: [
             {
@@ -502,63 +502,75 @@ export class TemplateLayouts {
                 sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
                 description: 'A small text field for a title that categorizes the rest of the content.',
                 opts: {
-                    borderColor: 'yellow',
-                    borderWidth: '8',
                     hCentering: "h-center",
                     backgroundColor: 'transparent',
+                    textTransform: 'uppercase',
                 },
             },
             {
                 viewType: ViewType.CAROUSEL3D,
-                tl: [-0.9, -.3],
-                br: [0.9, .9],
+                tl: [-0.9, -.5],
+                br: [0.9, .25],
                 opts: {
-                    borderColor: 'yellow',
+                    borderColor: '#847F69',
                     borderWidth: '8',
-                    backgroundColor: 'transparent',
+                    backgroundColor: '#C8BA94',
                 },
                 subfields: [
                     {
                         viewType: ViewType.STATIC,
-                        tl: [-.3, -.6],
-                        br: [.3, .6],
+                        tl: [-.4, -.6],
+                        br: [.4, .6],
                         types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
                         sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
                         description: 'A medium to large field for content that will share central focus with other content in the carousel.',
                         opts: {
-                            borderColor: 'yellow',
-                            borderWidth: '8',
+                            //borderColor: 'yellow',
+                            //borderWidth: '8',
                         },
                     },
                     {
                         viewType: ViewType.STATIC,
-                        tl: [-.3, -.6],
-                        br: [.3, .6],
+                        tl: [-.4, -.6],
+                        br: [.4, .6],
                         types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
                         sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
                         description: 'A medium to large field for content that will share central focus with other content in the carousel.',
                         opts: {
-                            borderColor: 'black',
-                            borderWidth: '8',
+                            //borderColor: 'black',
+                            //borderWidth: '8',
                         },
                     },
                     {
                         viewType: ViewType.STATIC,
-                        tl: [-.3, -.6],
-                        br: [.3, .6],
+                        tl: [-.4, -.6],
+                        br: [.4, .6],
                         types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
                         sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
                         description: 'A medium to large field for content that will share central focus with other content in the carousel.',
                         opts: {
-                            borderColor: 'yellow',
-                            borderWidth: '8',
+                            //borderColor: 'yellow',
+                            //borderWidth: '8',
                         },
                     },
                 ]
             },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.9, .35],
+                br: [0.9, .9],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium text field for a description of the content in the carousel.',
+                opts: {
+                    hCentering: "h-center",
+                    backgroundColor: 'transparent',
+                },
+            },
         ]
     }
 
+
     public static ThreeField001: FieldSettings = {
         title: 'threefield001',
         viewType: ViewType.FREEFORM,
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
index 413c3082e..6ab0a1774 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
@@ -2,7 +2,6 @@ import { makeAutoObservable } from "mobx";
 import { Col } from "./DocCreatorMenu";
 import { FieldSettings } from "./FieldTypes/Field";
 import { Template } from "./Template";
-import { TemplateLayouts } from "./TemplateBackend";
 
 export class TemplateManager {
 
-- 
cgit v1.2.3-70-g09d2


From 3b98831182a4d830cf577fa217a477b2cadcd7bc Mon Sep 17 00:00:00 2001
From: Nathan-SR <144961007+Nathan-SR@users.noreply.github.com>
Date: Wed, 26 Feb 2025 16:27:10 -0500
Subject: separated field content classes technically working

---
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   |  12 ++-
 .../DocCreatorMenu/FieldTypes/DecorationField.tsx  |  38 +++++++
 .../DocCreatorMenu/FieldTypes/DynamicField.tsx     |  11 ++-
 .../DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx |  19 ++--
 .../DocCreatorMenu/FieldTypes/FieldUtils.tsx       |  12 ++-
 .../DocCreatorMenu/FieldTypes/StaticContentField   |  98 ------------------
 .../FieldTypes/StaticContentField.tsx              | 109 +++++++++++++++++++++
 .../nodes/DataVizBox/DocCreatorMenu/Template.tsx   |   8 +-
 .../DataVizBox/DocCreatorMenu/TemplateManager.tsx  |   2 +-
 9 files changed, 183 insertions(+), 126 deletions(-)
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index b576aee82..6f3647133 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -568,13 +568,17 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
 
         let prompt: string = `(${origCount}) ${inputText}`;
 
+        console.log('prompt is: ', prompt)
+
         this._GPTLoading = true;
 
         try {
             const res = await gptAPICall(prompt, GPTCallType.TEMPLATE);
 
             if (res) {
+                console.log('res is: ', res)
                 const assignments: { [templateTitle: string]: { [fieldID: string]: string } } = JSON.parse(res);
+                console.log('assignments: ', assignments)
                 const brokenDownAssignments: [Template, { [fieldID: number]: Col }][] = [];
 
                 Object.entries(assignments).forEach(([tempTitle, assignment]) => {
@@ -583,7 +587,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                     const toObj = Object.entries(assignment).reduce(
                         (a, [fieldID, colTitle]) => {
                             const col = this.getColByTitle(colTitle);
-                            if (!this._userCreatedFields.includes(col)){ // do the following for any fields not added by the user; will change in the future, for now only GPT content works with user-added fields
+                            if (!this._userCreatedFields.includes(col)){ // do the following for any fields not added by the user; will change in the future, for now only GPT content works with user-added field
                                 const field = template.getFieldByID(Number(fieldID));
                                 field.setContent(col.defaultContent ?? '', col.type === TemplateFieldType.VISUAL ? ViewType.IMG : ViewType.TEXT);
                                 field.setTitle(col.title);
@@ -594,7 +598,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
                         },
                         {} as { [field: number]: Col }
                     );
+                    console.log('all assignments: ', toObj)
                     brokenDownAssignments.push([template, toObj]);
+                    console.log('brokendownassignments: ', brokenDownAssignments)
                 });
 
                 return brokenDownAssignments;
@@ -612,13 +618,15 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
         const cols = this.fieldsInfos;
         const templates = this.templateManager.getValidTemplates(cols);
 
+        console.log(templates)
+
         const assignments: [Template, { [field: number]: Col }][] = await this.assignColsToFields(templates, cols);
 
         const renderedTemplatePromises: Promise<Template | undefined>[] = assignments.map(([template, assignments]) => this.applyGPTContentToTemplate(template, assignments));
 
         const renderedTemplates: (Template | undefined)[] = await Promise.all(renderedTemplatePromises);
 
-        templates.forEach(template => template.mainField.updateRenderedDoc())
+        templates.forEach(template => template.mainField.initRenderedDoc())
 
         setTimeout(() => {
             this.setSuggestedTemplates(templates);
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
new file mode 100644
index 000000000..efe398aaa
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
@@ -0,0 +1,38 @@
+import { Doc, DocListCast } from "../../../../../../fields/Doc";
+import { Docs, DocumentOptions } from "../../../../../documents/Documents";
+import { FieldUtils } from "./FieldUtils";
+import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field";
+import { RichTextField } from "../../../../../../fields/RichTextField";
+import { DocData } from "../../../../../../fields/DocSymbols";
+import { ImageField } from "../../../../../../fields/URLField";
+
+export class DecorationField extends Field {
+
+    protected content: string = ''; 
+    protected subfields: Field[];
+
+    protected renderedDocument: Doc;
+
+    protected dimensions: FieldDimensions;
+
+    constructor(settings: FieldSettings, parent: Field, id: number) {
+        super(settings, id, FieldUtils.initField, parent);
+        this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
+        this.subfields = this.setupSubfields(this);
+        this.renderedDocument = this.initRenderedDoc();
+    };
+
+    setContent = (content: string, type?: ViewType) => { return }
+    getContent = () => { return 'none'};
+    get isContentField(): boolean { return false };
+
+    initRenderedDoc = (): Doc => {
+        const renderedSubfields: Doc[] = this.subfields.map(field => field.renderedDoc);
+        let doc: Doc = Docs.Create.FreeformDocument(renderedSubfields, { title: this.title, });
+        FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings);
+
+        this.renderedDocument = doc;
+
+        return doc;
+    };
+}
\ No newline at end of file
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
index 2d8328ed6..e5f080645 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
@@ -1,7 +1,7 @@
 import { Doc, DocListCast } from "../../../../../../fields/Doc";
 import { Docs } from "../../../../../documents/Documents";
 import { Col } from "../DocCreatorMenu";
-import { Field, FieldContentType, FieldDimensions, FieldSettings, ViewType } from "./Field";
+import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field";
 import { FieldUtils } from "./FieldUtils";
 
 export class DynamicField extends Field {
@@ -12,7 +12,7 @@ export class DynamicField extends Field {
     protected renderedDocument: Doc;
 
     constructor(settings: FieldSettings, id: number, parent?: Field) {
-        super(settings, id, FieldUtils.setupField, parent);
+        super(settings, id, FieldUtils.initField, parent);
         if (!parent) {
             this.parent = this;
             this.dimensions = {width: this.settings.br[0] - this.settings.tl[0], height: this.settings.br[1] - this.settings.tl[1], coord: {x: this.settings.tl[0], y: this.settings.tl[1]}};
@@ -22,7 +22,7 @@ export class DynamicField extends Field {
         }
         //console.log('new field dimensions: ', this.dimensions);
         this.subfields = this.setupSubfields(this);
-        this.renderedDocument = this.updateRenderedDoc(); //!!!
+        this.renderedDocument = this.initRenderedDoc(); //!!!
 
         // this.disposers.fieldList = reaction(
         //     () => DocListCast(this.doc[Doc.LayoutFieldKey(this.doc)]),
@@ -32,8 +32,9 @@ export class DynamicField extends Field {
         // );
     }
 
-    setContent = (content: string, type?: FieldContentType) => { return };
+    setContent = (content: string, type?: ViewType) => { return };
     getContent = () => { return '' };
+    get isContentField(): boolean { return false };
 
     matches = (cols: Col[]): Array<number> => {
         return [];
@@ -50,7 +51,7 @@ export class DynamicField extends Field {
         return { width, height, coord };
     };
 
-    updateRenderedDoc = (): Doc => {
+    initRenderedDoc = (): Doc => {
         console.log('dynamic field updated');
         let doc: Doc;
         const renderedSubfields: Doc[] = this.subfields.map(field => field.renderedDoc);
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
index d164053c3..9427d6c5c 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
@@ -8,13 +8,13 @@ import { DocumentType } from "../../../../../documents/DocumentTypes";
 export abstract class Field {
 
     protected disposers: { [name: string]: IDisposer } = {};
-    private setupField: (settings: FieldSettings, index: number, parent: Field) => Field;
+    private initField: (settings: FieldSettings, index: number, parent: Field) => Field;
 
     protected abstract subfields: Field[];
 
     protected abstract renderedDocument: Doc;
 
-    protected parent?: Field;
+    protected parent: Field;
     protected id: number;
     protected settings: FieldSettings;
     protected title: string = '';
@@ -22,7 +22,7 @@ export abstract class Field {
     protected abstract dimensions: FieldDimensions;
 
     constructor(settings: FieldSettings, id: number, fieldFactory: (settings: FieldSettings, index: number, parent: Field) => Field, parent?: Field) {
-        this.setupField = fieldFactory;
+        this.initField = fieldFactory;
         this.parent = parent ? parent : this;
         this.id = id;
         this.settings = settings;
@@ -57,6 +57,7 @@ export abstract class Field {
     };
     getTitle = () => { return this.title };
 
+    abstract get isContentField(): boolean;
     abstract setContent(content: string, type?: ViewType): void;
     abstract getContent(): string;
 
@@ -111,7 +112,7 @@ export abstract class Field {
             }
         });
         
-        const newField: Field = this.setupField(settings, this.subfields.length, this);
+        const newField: Field = this.initField(settings, this.subfields.length, this);
         this.subfields.push(newField);
     };
 
@@ -126,27 +127,23 @@ export abstract class Field {
 
     setupSubfields = (parent: Field): Field[] => {
         return this.settings.subfields?.map((fieldSettings, index) => {
-            return this.setupField(fieldSettings, index, parent);
+            return this.initField(fieldSettings, index, parent);
         }) || [];
     }
 
     applyAttributes(field: Field) {
         field.setTitle(this.title);
-        //this.updateRenderedDoc(this.renderedDoc);
-        field.updateRenderedDoc(this.renderedDoc);
+        field.initRenderedDoc(this.renderedDoc);
         field.subfields = this.subfields;
-        //console.log('id:', this.id, 'set width to:', Number(this.renderedDoc.width));
-        //console.log('set height to:', Number(this.renderedDoc.height));
     }
 
-    abstract updateRenderedDoc(oldDoc?: Doc): void;
+    abstract initRenderedDoc(oldDoc?: Doc): void;
 
     dispose = () => {
         Object.values(this.disposers).forEach(disposer => disposer?.());
     }
 
     handleFieldUpdate = (newDocsList: Doc[]) => {
-        console.log('handlefielduodate called');
         const currRenderedDocs: Set<Doc> = new Set();
         this.subfields.forEach(field => currRenderedDocs.add(field.renderedDoc));
         newDocsList.forEach(doc => {
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
index 6a800b8d1..d7cf24794 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
@@ -5,6 +5,7 @@ import { TemplateFieldSize, TemplateFieldType, TemplateLayouts } from "../Templa
 import { DynamicField } from "./DynamicField";
 import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field";
 import { TextTemplateField, ImageTemplateField } from "./StaticContentField";
+import { DecorationField } from "./DecorationField";
 
 export class FieldUtils {
     public static getLocalDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentDimensions: FieldDimensions): FieldDimensions => {
@@ -20,18 +21,19 @@ export class FieldUtils {
         return { width, height, coord };
     };
 
-    public static setupField = (settings: FieldSettings, index: number, parent: Field): Field => { 
-        //console.log('settings', settings);
+    public static initField = (settings: FieldSettings, index: number, parent: Field): Field => { 
         const id = Number(`${parent.getID}${index}`);
         switch (settings.viewType) {
             case ViewType.FREEFORM: case ViewType.CAROUSEL3D:
                 return new DynamicField(settings, id, parent);
             case ViewType.IMG:
-                return new ImageTemplateField(settings, id, parent);
+                return new ImageTemplateField(settings, parent, id);
             case ViewType.TEXT:
-                return new TextTemplateField(settings, id, parent);
+                return new TextTemplateField(settings, parent, id);
+            case ViewType.DEC:
+                return new DecorationField(settings, parent, id);
         }
-        return new TextTemplateField(settings, id, parent);
+        return new TextTemplateField(settings, parent, id);
     }
 
     public static textProperties: string[] = [
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField
deleted file mode 100644
index da2671f9c..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField
+++ /dev/null
@@ -1,98 +0,0 @@
-import { Doc, DocListCast } from "../../../../../../fields/Doc";
-import { Docs, DocumentOptions } from "../../../../../documents/Documents";
-import { FieldUtils } from "./FieldUtils";
-import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field";
-import { RichTextField } from "../../../../../../fields/RichTextField";
-import { DocData } from "../../../../../../fields/DocSymbols";
-import { ImageField } from "../../../../../../fields/URLField";
-
-export abstract class StaticContentField extends Field {
-
-    protected content: string; 
-    protected renderedDocument: Doc;
-    protected subfields: Field[];
-
-    protected parent: Field;
-    protected dimensions: FieldDimensions;
-
-    constructor(settings: FieldSettings, parent: Field, id: number) {
-        super(settings, id, FieldUtils.setupField, parent);
-        this.parent = parent;
-        this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
-        this.content = '';
-        this.subfields = this.setupSubfields(this);
-        this.renderedDocument = this.updateRenderedDoc();
-    };
-
-    abstract setContent(content: string): void;
-    getContent() { return this.content ?? 'unset'};
-
-    abstract updateRenderedDoc(): Doc;
-}
-
-export class ImageTemplateField extends StaticContentField {
-
-    setContent = (url: string) => { 
-        const imgField = new ImageField(url);
-        this.renderedDocument[DocData]['data'] = imgField;
-        this.content = url;
-    };
-
-    updateRenderedDoc = (): Doc => {
-        const url = String(this.content);
-        let doc: Doc = Docs.Create.ImageDocument(url, {
-            title: this.title,
-            _layout_fitWidth: false,
-        });
-        FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings);
-
-        this.renderedDocument = doc;
-
-        return doc;
-    };
-}
-
-export class TextTemplateField extends StaticContentField {
-
-    setContent = (text: string) => { 
-        const rtf = {
-            doc: {
-                type: 'doc',
-                content: [
-                    {
-                        type: 'paragraph',
-                        content: [
-                            {
-                                type: 'text',
-                                text,
-                            },
-                        ],
-                    },
-                ],
-            },
-            selection: { type: 'text', anchor: 1, head: 1 },
-            storedMarks: [],
-        };
-        this.content = text;
-        const field = new RichTextField(JSON.stringify(rtf), text);
-        this.renderedDocument[DocData]['text'] = field;
-    };
-
-    updateRenderedDoc = (): Doc => {
-        const opts = this.settings.opts;
-        const text = String(this.content);
-        let doc: Doc = Docs.Create.TextDocument(text, {
-            title: this.title,
-            text_fontColor: opts.text_fontColor,
-            contentBold: opts.contentBold,
-            textTransform: opts.textTransform,
-            color: opts.text_fontColor,
-            _text_fontSize: `${FieldUtils.calculateFontSize(this.dimensions.width, this.dimensions.height, text, true)}`
-        });
-        FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings);
-
-        this.renderedDocument = doc;
-
-        return doc;
-    };
-}
\ No newline at end of file
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx
new file mode 100644
index 000000000..baa5e71ec
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx
@@ -0,0 +1,109 @@
+import { Doc, DocListCast } from "../../../../../../fields/Doc";
+import { Docs, DocumentOptions } from "../../../../../documents/Documents";
+import { FieldUtils } from "./FieldUtils";
+import { Field, FieldDimensions, FieldSettings, ViewType } from "./Field";
+import { RichTextField } from "../../../../../../fields/RichTextField";
+import { DocData } from "../../../../../../fields/DocSymbols";
+import { ImageField } from "../../../../../../fields/URLField";
+
+export abstract class StaticContentField extends Field {
+
+    protected content: string = ''; 
+    protected subfields: Field[];
+
+    protected dimensions: FieldDimensions;
+
+    constructor(settings: FieldSettings, parent: Field, id: number) {
+        super(settings, id, FieldUtils.initField, parent);
+        this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions);
+        this.subfields = this.setupSubfields(this);
+    };
+
+    abstract setContent(content: string, type?: ViewType): void;
+    getContent = () => { return this.content ?? 'unset'};
+    get isContentField(): boolean { return true };
+
+    abstract initRenderedDoc(): Doc;
+}
+
+export class ImageTemplateField extends StaticContentField {
+
+    protected renderedDocument: Doc;
+
+    constructor(settings: FieldSettings, parent: Field, id: number){
+        super(settings, parent, id)
+        this.renderedDocument = this.initRenderedDoc();
+    }
+
+    setContent = (url: string, type?: ViewType) => { 
+        const imgField = new ImageField(url);
+        this.renderedDocument[DocData]['data'] = imgField;
+        this.content = url;
+    };
+
+    initRenderedDoc = (): Doc => {
+        const url = String(this.content);
+        let doc: Doc = Docs.Create.ImageDocument(url, {
+            title: this.title,
+            _layout_fitWidth: false,
+        });
+        FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings);
+
+        this.renderedDocument = doc;
+
+        return doc;
+    };
+}
+
+export class TextTemplateField extends StaticContentField {
+
+    protected renderedDocument: Doc;
+
+    constructor(settings: FieldSettings, parent: Field, id: number){
+        super(settings, parent, id)
+        this.renderedDocument = this.initRenderedDoc();
+    }
+
+    setContent = (text: string) => { 
+        console.log('content set to: ', text);
+        const rtf = {
+            doc: {
+                type: 'doc',
+                content: [
+                    {
+                        type: 'paragraph',
+                        content: [
+                            {
+                                type: 'text',
+                                text,
+                            },
+                        ],
+                    },
+                ],
+            },
+            selection: { type: 'text', anchor: 1, head: 1 },
+            storedMarks: [],
+        };
+        this.content = text;
+        const field = new RichTextField(JSON.stringify(rtf), text);
+        this.renderedDocument[DocData]['text'] = field;
+    };
+
+    initRenderedDoc = (): Doc => {
+        const opts = this.settings.opts;
+        const text = String(this.content);
+        let doc: Doc = Docs.Create.TextDocument(text, {
+            title: this.title,
+            text_fontColor: opts.text_fontColor,
+            contentBold: opts.contentBold,
+            textTransform: opts.textTransform,
+            color: opts.text_fontColor,
+            _text_fontSize: `${FieldUtils.calculateFontSize(this.dimensions.width, this.dimensions.height, text, true)}`
+        });
+        FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings);
+
+        this.renderedDocument = doc;
+
+        return doc;
+    };
+}
\ No newline at end of file
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
index 9d132d637..178af3df6 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
@@ -24,7 +24,7 @@ export class Template {
 
     get childFields(): Field[] { return this.mainField.getSubfields };
     get allFields(): Field[] { return this.mainField.getAllSubfields };
-    get contentFields(): Field[] { return this.allFields.filter(field => field !instanceof DynamicField) };
+    get contentFields(): Field[] { return this.allFields.filter(field => field.isContentField) };
     get doc(){ return this.mainField.renderedDoc; };
     get title() { return this.mainField.getTitle() };
 
@@ -36,11 +36,10 @@ export class Template {
         const clone: Template = new Template(this.settings);
         this.mainField.applyAttributes(clone.mainField);
         clone.allFields.filter(field => field !== clone.mainField).forEach(field => {
-            console.log('id:', field.getID);
             const matchingField: Field = this.allFields.filter(f => f.getID === field.getID)[0];
             matchingField.applyAttributes(field);
         })
-        clone.mainField.updateRenderedDoc();
+        clone.mainField.initRenderedDoc();
         return clone;
     }
 
@@ -85,13 +84,14 @@ export class Template {
 
     resetToBase = () => {
         this.allFields.forEach(field => {
-            field.updateRenderedDoc();
+            field.initRenderedDoc();
         })
     }
 
     isValidTemplate = (cols: Col[]) => {
         const matches: number[][] = this.getMatches(cols);
         const maxMatches: number = this.maxMatches(matches);
+        console.log('title: ', this.mainField.getTitle(), ' matches: ', matches, ' max: ', maxMatches, ' num content fields: ', this.contentFields.length)
         return maxMatches === this.contentFields.length;
     }
 
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
index 6ab0a1774..09b4ce029 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
@@ -6,7 +6,6 @@ import { Template } from "./Template";
 export class TemplateManager {
 
     templates: Template[] = [];
-    //updateTrack
 
     constructor(templateSettings: FieldSettings[]) {
         makeAutoObservable(this);
@@ -20,6 +19,7 @@ export class TemplateManager {
     }
 
     getValidTemplates = (cols: Col[]): Template[] => {
+        console.log('called in manager with templates: ', this.templates)
         return this.templates.filter(template => template.isValidTemplate(cols));
     }
 
-- 
cgit v1.2.3-70-g09d2


From 1ffa8a8fb3e16bd5a3338d18782ddda0c2ffca03 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Sun, 16 Mar 2025 21:15:00 -0400
Subject: a lot of code cleanup for doc creators templates

---
 src/client/views/Main.tsx                          |   6 +-
 .../DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx   |  89 ++-
 .../DocCreatorMenu/FieldTypes/DecorationField.tsx  |   3 -
 .../DocCreatorMenu/FieldTypes/DynamicField.tsx     | 189 -----
 .../DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx | 167 -----
 .../DocCreatorMenu/FieldTypes/FieldUtils.tsx       |  64 --
 .../FieldTypes/StaticContentField.tsx              |  90 ---
 .../nodes/DataVizBox/DocCreatorMenu/Template.ts    | 138 ++++
 .../nodes/DataVizBox/DocCreatorMenu/Template.tsx   | 139 ----
 .../DataVizBox/DocCreatorMenu/TemplateBackend.ts   | 768 ++++++++++++++++++++
 .../DataVizBox/DocCreatorMenu/TemplateBackend.tsx  | 771 ---------------------
 .../TemplateFieldTypes/DecorationField.ts          |  11 +
 .../TemplateFieldTypes/DynamicField.ts             | 164 +++++
 .../TemplateFieldTypes/StaticContentField.ts       |  72 ++
 .../TemplateFieldTypes/TemplateField.ts            | 159 +++++
 .../TemplateFieldTypes/TemplateFieldUtils.ts       |  71 ++
 .../DataVizBox/DocCreatorMenu/TemplateManager.ts   |  33 +
 .../DataVizBox/DocCreatorMenu/TemplateManager.tsx  |  34 -
 18 files changed, 1461 insertions(+), 1507 deletions(-)
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.ts
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.ts
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DecorationField.ts
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DynamicField.ts
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/StaticContentField.ts
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateField.ts
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateFieldUtils.ts
 create mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.ts
 delete mode 100644 src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx

(limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx')

diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index fc2d7f572..b335432c9 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -65,8 +65,8 @@ import { PresBox, PresElementBox } from './nodes/trails';
 import { FaceRecognitionHandler } from './search/FaceRecognitionHandler';
 import { SearchBox } from './search/SearchBox';
 import { StickerPalette } from './smartdraw/StickerPalette';
-import { Field } from './nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field';
-import { FieldUtils } from './nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils';
+import { TemplateField } from './nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateField';
+import { TemplateFieldUtils } from './nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateFieldUtils';
 
 dotenv.config();
 
@@ -102,7 +102,7 @@ FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' };
         new PingManager();
         new KeyManager();
         new FaceRecognitionHandler();
-        Field.initField = FieldUtils.initField; // set the init function for fields
+        TemplateField.initField = TemplateFieldUtils.initField; // set the init function for fields
 
         // initialize plugins and classes that require plugins
         CollectionDockingView.Init(TabDocView);
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index a702218b0..97faf01c2 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -27,7 +27,7 @@ import { DocumentView, DocumentViewInternal } from '../../DocumentView';
 import { OpenWhere } from '../../OpenWhere';
 import { DataVizBox } from '../DataVizBox';
 import './DocCreatorMenu.scss';
-import { Field, ViewType } from './FieldTypes/Field';
+import { TemplateField, ViewType } from './TemplateFieldTypes/TemplateField';
 import { Template } from './Template';
 import { TemplateFieldSize, TemplateFieldType, TemplateLayouts } from './TemplateBackend';
 import { TemplateManager } from './TemplateManager';
@@ -371,7 +371,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
     }
 
     @action updateRenderedPreviewCollection = async (template: Template) => {
-        this._fullyRenderedDocs = (await this.createDocsFromTemplate(template)) ?? [];
+        this._fullyRenderedDocs = ((await this.createDocsFromTemplate(template)) ?? []).filter(doc => doc).map(doc => doc!);
         console.log(this._fullyRenderedDocs);
         this.updateRenderedDocCollection();
     };
@@ -630,7 +630,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
             await Promise.all(renderedTemplatePromises);
         }
 
-        templates.forEach(template => template.mainField.initializeDocument({ subfields: [], title: template.title, opts: {}, viewType: ViewType.FREEFORM, tl: [0, 0], br: [900, 900] }));
+        templates.forEach(template => template.mainField.initializeDocument({ title: template.title, opts: {}, viewType: ViewType.FREEFORM, tl: [0, 0], br: [900, 900] }, []));
 
         setTimeout(() => {
             this.setSuggestedTemplates(templates);
@@ -638,10 +638,10 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
         });
     };
 
-    renderGPTImageCall = async (template: Template, col: Col, fieldNumber: number): Promise<boolean> => {
+    renderGPTImageCall = async (template: Template, col: Col, fieldNumber: number | undefined): Promise<boolean> => {
         const generateAndLoadImage = async (fieldNum: string, column: Col, prompt: string) => {
             const url = await this.generateGPTImage(prompt);
-            const field: Field = template.getFieldByID(Number(fieldNum));
+            const field: TemplateField = template.getFieldByID(Number(fieldNum));
 
             field.setContent(url ?? '', ViewType.IMG);
             field.setTitle(col.title);
@@ -665,7 +665,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
         return true;
     };
 
-    renderGPTTextCall = async (template: Template, col: Col, fieldNum: number): Promise<boolean> => {
+    renderGPTTextCall = async (template: Template, col: Col, fieldNum: number | undefined): Promise<boolean> => {
         const wordLimit = (size: TemplateFieldSize) => {
             switch (size) {
                 case TemplateFieldSize.TINY:
@@ -697,7 +697,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
             if (res) {
                 const assignments: { [title: string]: { number: string; content: string } } = JSON.parse(res);
                 Object.entries(assignments).forEach(([, /* title */ info]) => {
-                    const field: Field = template.getFieldByID(Number(info.number));
+                    const field: TemplateField = template.getFieldByID(Number(info.number));
                     // const column = this.getColByTitle(title);
 
                     field.setContent(info.content ?? '', ViewType.TEXT);
@@ -771,7 +771,7 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
             return templateCopy.mainField.renderedDoc;
         };
 
-        let docs: Promise<Doc>[];
+        let docs: Promise<Doc | undefined>[];
         if (this.DEBUG_MODE) {
             docs = [1, 2, 3, 4].map(() => processContent({}));
         } else {
@@ -868,30 +868,31 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
     get templatesPreviewContents() {
         const GPTOptions = <div></div>;
 
-        const previewDoc = (doc: Doc, template: Template) => (
-            <DocumentView
-                Document={doc}
-                isContentActive={emptyFunction} // !!! should be return false
-                addDocument={returnFalse}
-                moveDocument={returnFalse}
-                removeDocument={returnFalse}
-                PanelWidth={() => (this._selectedTemplate === template ? 104 : 111)}
-                PanelHeight={() => (this._selectedTemplate === template ? 104 : 111)}
-                ScreenToLocalTransform={() => new Transform(-this._pageX - 5, -this._pageY - 35, 1)}
-                renderDepth={1}
-                whenChildContentsActiveChanged={emptyFunction}
-                focus={emptyFunction}
-                styleProvider={DefaultStyleProvider}
-                addDocTab={this._props.addDocTab}
-                pinToPres={() => undefined}
-                childFilters={returnEmptyFilter}
-                childFiltersByRanges={returnEmptyFilter}
-                searchFilterDocs={returnEmptyDoclist}
-                fitContentsToBox={returnFalse}
-                fitWidth={returnFalse}
-                hideDecorations={true}
-            />
-        );
+        const previewDoc = (doc: Doc | undefined, template: Template) =>
+            !doc ? null : (
+                <DocumentView
+                    Document={doc}
+                    isContentActive={emptyFunction} // !!! should be return false
+                    addDocument={returnFalse}
+                    moveDocument={returnFalse}
+                    removeDocument={returnFalse}
+                    PanelWidth={() => (this._selectedTemplate === template ? 104 : 111)}
+                    PanelHeight={() => (this._selectedTemplate === template ? 104 : 111)}
+                    ScreenToLocalTransform={() => new Transform(-this._pageX - 5, -this._pageY - 35, 1)}
+                    renderDepth={1}
+                    whenChildContentsActiveChanged={emptyFunction}
+                    focus={emptyFunction}
+                    styleProvider={DefaultStyleProvider}
+                    addDocTab={this._props.addDocTab}
+                    pinToPres={() => undefined}
+                    childFilters={returnEmptyFilter}
+                    childFiltersByRanges={returnEmptyFilter}
+                    searchFilterDocs={returnEmptyDoclist}
+                    fitContentsToBox={returnFalse}
+                    fitWidth={returnFalse}
+                    hideDecorations={true}
+                />
+            );
 
         //<img className='docCreatorMenu-preview-image expanded' src={this._expandedPreview.icon!.url.href.replace(".png", "_o.png")} />
 
@@ -1096,19 +1097,13 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
 
         const collectionFactory = (): ((docs: Doc[], options: DocumentOptions) => Doc) => {
             switch (this._layout.type) {
-                case LayoutType.CAROUSEL3D:
-                    return Docs.Create.Carousel3DDocument;
-                case LayoutType.FREEFORM:
-                    return Docs.Create.FreeformDocument;
-                case LayoutType.CARD:
-                    return Docs.Create.CardDeckDocument;
-                case LayoutType.MASONRY:
-                    return Docs.Create.MasonryDocument;
-                case LayoutType.CAROUSEL:
-                    return Docs.Create.CarouselDocument;
-                default:
-                    return Docs.Create.FreeformDocument;
-            }
+                case LayoutType.CAROUSEL3D: return Docs.Create.Carousel3DDocument;
+                case LayoutType.FREEFORM:   return Docs.Create.FreeformDocument;
+                case LayoutType.CARD:       return Docs.Create.CardDeckDocument;
+                case LayoutType.MASONRY:    return Docs.Create.MasonryDocument;
+                case LayoutType.CAROUSEL:   return Docs.Create.CarouselDocument;
+                default:                    return Docs.Create.FreeformDocument;
+            } // prettier-ignore
         };
 
         const collection = collectionFactory()(this._fullyRenderedDocs, {
@@ -1241,9 +1236,9 @@ export class DocCreatorMenu extends ObservableReactComponent<DocCreateMenuProps>
                                 emptyFunction,
                                 undoable(clickEv => {
                                     clickEv.stopPropagation();
-                                    if (!this._selectedTemplate) return;
+                                    if (!this._selectedTemplate || !this._selectedTemplate.getRenderedDoc()) return;
                                     const layout: DataVizTemplateLayout = {
-                                        template: this._selectedTemplate.getRenderedDoc(),
+                                        template: this._selectedTemplate.getRenderedDoc()!,
                                         layout: { type: this._layout.type, xMargin: this._layout.xMargin, yMargin: this._layout.yMargin, repeat: 0 },
                                         columns: this.columnsCount,
                                         rows: this.rowsCount,
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
deleted file mode 100644
index 98a9dc7a6..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DecorationField.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import { DynamicField } from './DynamicField';
-
-export class DecorationField extends DynamicField {}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
deleted file mode 100644
index f100830d3..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ /dev/null
@@ -1,189 +0,0 @@
-import { Doc, DocListCast } from '../../../../../../fields/Doc';
-import { Docs } from '../../../../../documents/Documents';
-import { Field, FieldSettings, ViewType } from './Field';
-import { List } from '../../../../../../fields/List';
-import { DocData } from '../../../../../../fields/DocSymbols';
-import { DocumentType } from '../../../../../documents/DocumentTypes';
-import { reaction } from 'mobx';
-import { IDisposer } from 'mobx-utils';
-
-export class DynamicField extends Field {
-    protected subfields!: Field[];
-
-    protected disposers: { [name: string]: IDisposer } = {};
-    init(settings: FieldSettings, id: number, parent?: DynamicField) {
-        super.baseinit(undefined as unknown as Doc, settings, parent, id);
-        const { doc, subFields } = this.initializeDocument(settings);
-        this.Document = doc;
-        this.subfields = subFields;
-
-        this.disposers.fieldList = reaction(
-            () => DocListCast(this.Document[Doc.LayoutFieldKey(this.Document)]),
-            docs => {
-                console.log('updated');
-                this.handleFieldUpdate(docs);
-            }
-        );
-        return this;
-    }
-
-    static setupSubfields(subFieldSettings: FieldSettings[] | undefined, parent?: DynamicField): Field[] {
-        return subFieldSettings?.map((fieldSettings, index) => Field.initField!(fieldSettings, index, parent)) || [];
-    }
-
-    get getSubfields(): Field[] {
-        return this.subfields ?? [];
-    }
-    get getAllSubfields() {
-        let fields: Field[] = [];
-        this.subfields?.forEach(field => {
-            fields.push(field);
-            fields = fields.concat(field instanceof DynamicField ? field.getAllSubfields : ([] as Field[]));
-        });
-        return fields;
-    }
-
-    setSubFields = (fields: Field[]) => {
-        this.subfields = fields;
-    };
-    handleFieldUpdate = (newDocsList: Doc[]) => {
-        const currRenderedDocs: Set<Doc> = new Set();
-        this.subfields.forEach(field => currRenderedDocs.add(field.Document));
-        newDocsList.forEach(doc => {
-            if (!currRenderedDocs.has(doc)) {
-                this.addFieldFromDoc(doc);
-            }
-        });
-        currRenderedDocs.forEach(doc => {
-            if (!newDocsList.includes(doc)) {
-                const fields = this.subfields.filter(field => field.Document === doc);
-                fields.forEach(field => this.removeField(field));
-            }
-        });
-    };
-
-    addFieldFromDoc = (doc: Doc) => {
-        const par = this.Document;
-        const settings: FieldSettings = {
-            tl: [Number(doc._x) / Number(par._width), Number(doc._y) / Number(par._height)],
-            br: [(Number(doc._x) + Number(doc._width)) / Number(par._width), (Number(doc._y) + Number(doc._height)) / Number(par._height)],
-            viewType: doc.type === DocumentType.COL ? ViewType.FREEFORM : ViewType.STATIC,
-            opts: {},
-        };
-
-        const newField: Field = Field.initField!(settings, this.subfields.length, this);
-        this.subfields.push(newField);
-    };
-
-    addField = (field: Field) => {
-        if (!this.subfields.includes(field)) {
-            this.subfields.push(field);
-            console.log('field added');
-            // Doc.SetContainer(field.Document, this.Document);
-        }
-    };
-
-    dispose = () => {
-        Object.values(this.disposers).forEach(disposer => disposer?.());
-    };
-
-    removeField = (field: Field) => {
-        // var childDocs: Doc[] = DocListCast(this.Document[Doc.LayoutFieldKey(this.Document)]);
-        // this.Document[Doc.LayoutFieldKey(this.Document)] = new List<Doc>([...childDocs.splice(childDocs.indexOf(field.Document), 1)]);
-        this.subfields.splice(this.subfields.indexOf(field), 1);
-        field instanceof DynamicField && field.dispose();
-    };
-
-    exchangeFields = (newField: Field, oldField: Field) => {
-        this.subfields.splice(this.subfields.indexOf(oldField), 1, newField);
-        // this.renderedDoc.
-    };
-    // eslint-disable-next-line @typescript-eslint/no-unused-vars
-    setContent = (content: string, type: ViewType) => {
-        return;
-    };
-    getContent = () => {
-        return '';
-    };
-    get isContentField(): boolean {
-        return false;
-    }
-
-    addChildToDocument = (doc: Doc) => {
-        Doc.SetContainer(doc, this.Document);
-    };
-
-    matches = (): Array<number> => {
-        return [];
-    };
-
-    async makeClone(parent?: DynamicField): Promise<Field> {
-        const field = (await super.makeClone(parent)) as unknown as DynamicField;
-        field.subfields = await Promise.all(this.subfields.map(async cloneField => await cloneField.makeClone(field)));
-        field.Document[DocData].data = new List<Doc>(field.subfields.map(subfield => subfield.renderedDoc));
-        return field;
-    }
-    initializeDocument = (settings: FieldSettings) => {
-        const subFields = DynamicField.setupSubfields(settings.subfields, this);
-        const renderedSubfields = subFields.map(field => field.renderedDoc);
-        settings.opts.title = settings.title;
-        switch (settings.viewType) {
-            case ViewType.CAROUSEL3D:
-                return { doc: Docs.Create.Carousel3DDocument(renderedSubfields, settings.opts), subFields };
-            case ViewType.FREEFORM:
-                return { doc: Docs.Create.FreeformDocument(renderedSubfields, settings.opts), subFields };
-            default:
-                return { doc: Docs.Create.FreeformDocument(renderedSubfields, settings.opts), subFields };
-        }
-    };
-}
-
-// export class DynamicField extends Field {
-//     protected subfields: Field[];
-
-//     protected Document!: Doc;
-
-//     constructor(settings: FieldSettings, id: number, parent?: Field) {
-//         super(settings, id, parent);
-//         this.subfields = this.setupSubfields(this);
-//         this.initializeDocument();
-//     }
-
-//     setContent = (content: string, type: ViewType) => { return };
-//     getContent = () => { return '' };
-//     get isContentField(): boolean { return false };
-
-//     addChildToDocument = (doc: Doc) => {
-//         Doc.SetContainer(doc, this.Document);
-//     }
-
-//     matches = (cols: Col[]): Array<number> => {
-//         return [];
-//     }
-
-//     initializeDocument = (): Doc => {
-//         let doc: Doc;
-//         const renderedSubfields: Doc[] = this.subfields.map(field => field.renderedDoc);
-//         switch (this.settings.viewType) {
-//             case ViewType.CAROUSEL3D:
-//                 doc = Docs.Create.Carousel3DDocument(renderedSubfields, {
-//                     title: this.title,
-//                 });
-//                 break;
-//             case ViewType.FREEFORM:
-//                 doc = Docs.Create.FreeformDocument(renderedSubfields, {
-//                     title: this.title,
-//                 });
-//                 break;
-//             default:
-//                 doc = Docs.Create.FreeformDocument(renderedSubfields, {
-//                     title: this.title,
-//                 });
-//             break;
-//         }
-
-//         this.Document = doc;
-//         return doc;
-//     }
-
-// }
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
deleted file mode 100644
index 111ad8328..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ /dev/null
@@ -1,167 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-/* eslint-disable no-use-before-define */
-import { computed } from 'mobx';
-import { Doc } from '../../../../../../fields/Doc';
-import { DocData } from '../../../../../../fields/DocSymbols';
-import { Copy } from '../../../../../../fields/FieldSymbols';
-import { ObjectField } from '../../../../../../fields/ObjectField';
-import { ComputedField } from '../../../../../../fields/ScriptField';
-import { DocumentOptions } from '../../../../../documents/Documents';
-import { Col } from '../DocCreatorMenu';
-import { TemplateFieldSize, TemplateFieldType } from '../TemplateBackend';
-
-export abstract class Field {
-    Document!: Doc;
-
-    static initField?: (settings: FieldSettings, index: number, parent: any /* DynamicField */ | undefined, sameId?: boolean) => Field = undefined;
-
-    protected parent?: any;
-    protected id!: number;
-    settings!: FieldSettings;
-    protected title: string = '';
-    dimensions!: FieldDimensions;
-
-    constructor() {}
-
-    baseinit(doc: Doc, settings: FieldSettings, parent?: any, id: number = 1) {
-        this.id = id;
-        this.Document = doc;
-        this.parent = parent;
-        this.settings = settings;
-        this.title = settings.title ?? '';
-        this.dimensions = this.getLocalDimensions({ tl: this.settings.tl, br: this.settings.br }, this.parent?.getDimensions);
-        this.applyBasicOpts(this.dimensions, settings);
-        return this;
-    }
-
-    get renderedDoc() {
-        return this.Document;
-    }
-    get getDimensions() {
-        return this.dimensions;
-    }
-    get getID() {
-        return this.id;
-    }
-    get getDescription(): string {
-        return this.settings.description ?? '';
-    }
-    get viewType(): ViewType {
-        return this.settings.viewType;
-    }
-
-    setTitle = (title: string) => {
-        this.title = title;
-        this.Document.title = title;
-    };
-    getTitle = () => {
-        return this.title;
-    };
-
-    abstract get isContentField(): boolean;
-    abstract setContent(content: string, type: ViewType): void;
-    abstract getContent(): string;
-
-    async makeClone(parent?: any /* DynamicField*/): Promise<Field> {
-        const field = Field.initField!(this.settings, this.id, parent, true); // create a value for this.Document/subfields that we want to ignore
-        field.Document = (await Doc.MakeClone(this.Document)).clone;
-        field.title = this.title;
-        field.dimensions = this.dimensions;
-        return field;
-    }
-
-    @computed get documentOptions(): DocumentOptions {
-        const opts: DocumentOptions = {};
-        Object.assign(opts, this.Document[DocData]);
-        Object.entries(opts).forEach(([key, field]) => {
-            if (field instanceof ObjectField) {
-                Object.assign(opts, { [key]: ObjectField.MakeCopy(field) });
-            } else if (field instanceof ComputedField) {
-                Object.assign(opts, { [key]: field[Copy]() });
-            }
-        });
-        return opts;
-    }
-
-    // eslint-disable-next-line @typescript-eslint/no-unused-vars
-    changeFieldType = (newType: ViewType): Field => {
-        const newField = Field.initField!(this.settings, this.id, this.parent, true);
-        this.parent?.exchangeFields(newField, this);
-        return newField;
-    };
-
-    matches = (cols: Col[]): number[] => {
-        const colMatchesField = (col: Col) => {
-            const isMatch: boolean = (this.settings.sizes?.some(size => col.sizes?.includes(size)) && this.settings.types?.includes(col.type)) ?? false;
-            return isMatch;
-        };
-
-        const matches: Array<number> = [];
-
-        cols.forEach((col, v) => {
-            if (colMatchesField(col)) {
-                matches.push(v);
-            }
-        });
-
-        return matches;
-    };
-
-    private getLocalDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentDimensions?: FieldDimensions): FieldDimensions => {
-        if (!parentDimensions) {
-            return { width: coords.br[0] - coords.tl[0], height: coords.br[1] - coords.tl[1], coord: { x: coords.tl[0], y: coords.tl[1] } };
-        }
-        const l = (coords.tl[0] * parentDimensions.width) / 2;
-        const t = coords.tl[1] * parentDimensions.height / 2; //prettier-ignore
-        const r = (coords.br[0] * parentDimensions.width) / 2;
-        const b = coords.br[1] * parentDimensions.height / 2; //prettier-ignore
-        const width = r - l;
-        const height = b - t;
-        const coord = { x: l, y: t };
-        return { width, height, coord };
-    };
-
-    private applyBasicOpts = (dimensions: FieldDimensions, settings: FieldSettings) => {
-        const opts: DocumentOptions = settings.opts;
-        opts.isDefaultTemplateDoc ??= true;
-        opts._layout_hideScroll ??= true;
-        opts.x ??= dimensions.coord.x;
-        opts.y ??= dimensions.coord.y;
-        opts._height ??= dimensions.height;
-        opts._width ??= dimensions.width;
-        opts._nativeWidth ??= dimensions.width;
-        opts._nativeHeight ??= dimensions.height;
-        opts._layout_nativeDimEditable ??= true;
-    };
-}
-
-export type FieldSettings = {
-    tl: [number, number];
-    br: [number, number];
-    opts: DocumentOptions;
-    viewType: ViewType;
-    title?: string;
-    subfields?: FieldSettings[];
-    types?: TemplateFieldType[];
-    sizes?: TemplateFieldSize[];
-    description?: string;
-};
-
-export enum ViewType {
-    CAROUSEL3D = 'carousel3d',
-    FREEFORM = 'freeform',
-    STATIC = 'static',
-    DEC = 'decoration',
-    IMG = 'image',
-    TEXT = 'text',
-}
-
-export type FieldDimensions = {
-    width: number;
-    height: number;
-    coord: { x: number; y: number };
-};
-
-export type FieldTree = {
-    node: { field: Field; subfields: FieldTree[] };
-};
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
deleted file mode 100644
index 0582c9ed3..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import { Field, FieldSettings, ViewType } from './Field';
-import { TextTemplateField, ImageTemplateField } from './StaticContentField';
-import { DecorationField } from './DecorationField';
-import { DynamicField } from './DynamicField';
-
-export class FieldUtils {
-    public static initField = (settings: FieldSettings, index: number, parent: DynamicField | undefined, sameId: boolean = false): Field => {
-        const id = sameId ? index : parent ? Number(`${parent.getID}${index}`) : 1;
-        switch (settings.viewType) {
-            case ViewType.FREEFORM:
-            case ViewType.CAROUSEL3D:
-                return new DynamicField().init(settings, id, parent);
-            case ViewType.IMG:
-                return new ImageTemplateField().init(settings, id, parent);
-            case ViewType.TEXT:
-                return new TextTemplateField().init(settings, id, parent);
-            case ViewType.DEC:
-                return new DecorationField().init(settings, id, parent);
-        }
-        return new TextTemplateField().init(settings, id, parent);
-    };
-
-    // eslint-disable-next-line @typescript-eslint/no-unused-vars
-    public static calculateFontSize = (contWidth: number, contHeight: number, text: string, uppercase: boolean): number => {
-        const words: string[] = text.split(/\s+/).filter(Boolean);
-
-        let currFontSize = 1;
-        let rowsCount = 1;
-        let currTextHeight = currFontSize * rowsCount * 2;
-
-        while (currTextHeight <= contHeight) {
-            let wordIndex = 0;
-            let currentRowWidth = 0;
-            let wordsInCurrRow = 0;
-            rowsCount = 1;
-
-            while (wordIndex < words.length) {
-                const word = words[wordIndex];
-                const wordWidth = word.length * currFontSize * 0.7;
-
-                if (currentRowWidth + wordWidth <= contWidth) {
-                    currentRowWidth += wordWidth;
-                    ++wordsInCurrRow;
-                } else {
-                    if (words.length !== 1 && words.length > wordsInCurrRow) {
-                        rowsCount++;
-                        currentRowWidth = wordWidth;
-                        wordsInCurrRow = 1;
-                    } else {
-                        break;
-                    }
-                }
-
-                wordIndex++;
-            }
-
-            currTextHeight = rowsCount * currFontSize * 2;
-
-            currFontSize += 1;
-        }
-
-        return currFontSize - 1;
-    };
-}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx
deleted file mode 100644
index 75aea5440..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticContentField.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { DocData } from '../../../../../../fields/DocSymbols';
-import { RichTextField } from '../../../../../../fields/RichTextField';
-import { ImageField } from '../../../../../../fields/URLField';
-import { Docs } from '../../../../../documents/Documents';
-import { Field, FieldSettings, ViewType } from './Field';
-import { FieldUtils } from './FieldUtils';
-import { DynamicField } from './DynamicField';
-
-export abstract class StaticContentField extends Field {
-    protected content: string = '';
-
-    abstract setContent(content: string, type?: ViewType): void;
-    getContent = () => {
-        return this.content ?? 'unset';
-    };
-    get isContentField(): boolean {
-        return true;
-    }
-}
-
-export class ImageTemplateField extends StaticContentField {
-    init(settings: FieldSettings, id: number, parent: DynamicField | undefined) {
-        super.baseinit(this.initializeDocument(settings), settings, parent, id);
-        return this;
-    }
-
-    setContent = (url: string, type?: ViewType) => {
-        this.settings.viewType = type ?? this.settings.viewType;
-
-        if (type === ViewType.IMG || type === undefined) {
-            const imgField = new ImageField(url);
-            this.Document[DocData].data = imgField;
-            this.content = url;
-        } else {
-            const updatedField = this.changeFieldType(type);
-            updatedField.setContent(url, type);
-        }
-    };
-
-    initializeDocument = (settings: FieldSettings) => {
-        settings.opts.title = settings.title;
-        settings.opts._layout_fitWidth = false;
-
-        return Docs.Create.ImageDocument('', settings.opts);
-    };
-}
-
-export class TextTemplateField extends StaticContentField {
-    init(settings: FieldSettings, id: number, parent?: DynamicField) {
-        super.baseinit(this.initializeDocument(settings), settings, parent, id);
-        this.Document.text_fontSize = `${FieldUtils.calculateFontSize(this.dimensions.width, this.dimensions.height, '', true)}`;
-        return this;
-    }
-    setContent = (text: string, type?: ViewType) => {
-        this.settings.viewType = type ?? this.settings.viewType;
-
-        if (type === ViewType.TEXT || type === undefined) {
-            const rtf = {
-                doc: {
-                    type: 'doc',
-                    content: [
-                        {
-                            type: 'paragraph',
-                            content: [
-                                {
-                                    type: 'text',
-                                    text,
-                                },
-                            ],
-                        },
-                    ],
-                },
-                selection: { type: 'text', anchor: 1, head: 1 },
-                storedMarks: [],
-            };
-            this.content = text;
-            const field = new RichTextField(JSON.stringify(rtf), text);
-            this.Document[DocData]['text'] = field;
-        } else {
-            const updatedField = this.changeFieldType(type);
-            updatedField.setContent(text, type);
-        }
-    };
-
-    initializeDocument = (settings: FieldSettings) => {
-        const opts = settings.opts;
-        opts.title = settings.title;
-        return Docs.Create.TextDocument('', opts);
-    };
-}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.ts
new file mode 100644
index 000000000..ef6867e32
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.ts
@@ -0,0 +1,138 @@
+import { makeAutoObservable } from 'mobx';
+import { Col } from './DocCreatorMenu';
+import { DynamicField } from './TemplateFieldTypes/DynamicField';
+import { TemplateField, FieldSettings } from './TemplateFieldTypes/TemplateField';
+import { TemplateLayouts } from './TemplateBackend';
+
+export class Template {
+    mainField: DynamicField;
+    private settings: FieldSettings;
+
+    constructor(templateInfo: FieldSettings) {
+        makeAutoObservable(this);
+        this.settings = templateInfo;
+        this.mainField = this.setupMainField(templateInfo);
+    }
+
+    get childFields(): TemplateField[] {
+        return this.mainField.getSubfields;
+    }
+    get allFields(): TemplateField[] {
+        return this.mainField.getAllSubfields;
+    }
+    get contentFields(): TemplateField[] {
+        return this.allFields.filter(field => field.isContentField);
+    }
+    get doc() {
+        return this.mainField.renderedDoc;
+    }
+    get title() {
+        return this.mainField.getTitle();
+    }
+
+    cleanup = () => {
+        //dispose each subfields disposers, etc.
+    };
+
+    cloneBase = async (): Promise<Template> => {
+        const clone: Template = new Template(TemplateLayouts.BasicSettings);
+        clone.mainField = (await this.mainField.makeClone(undefined)) as unknown as DynamicField;
+        // clone.mainField.renderedDoc._width = this.mainField.renderedDoc._width;
+        // clone.mainField.renderedDoc._height = this.mainField.renderedDoc._height;
+        return clone;
+    };
+
+    printFieldInfo = () => {
+        this.allFields.forEach(field => {
+            const doc = field.renderedDoc;
+            console.log('title: ', field.getTitle(), ' width: ', doc?.width);
+        });
+    };
+
+    getRenderedDoc = () => {
+        return this.doc;
+    };
+
+    getFieldByID = (id: number): TemplateField => {
+        return this.allFields.filter(field => field.getID === id)[0];
+    };
+
+    getFieldByTitle = (title: string) => {
+        return this.allFields.filter(field => field.getTitle() === title)[0];
+    };
+
+    setupMainField = (templateInfo: FieldSettings) => {
+        return DynamicField.Create(templateInfo, 1);
+    };
+
+    get descriptionSummary(): string {
+        let summary: string = '';
+        this.contentFields.forEach(field => {
+            summary += `--- Field #${field.getID} (title: ${field.getTitle()}): ${field.getDescription ?? ''} ---`;
+        });
+        return summary;
+    }
+
+    get compiledContent(): string {
+        let summary: string = '';
+        this.contentFields.forEach(field => {
+            summary += `--- Field #${field.getID} (title: ${field.getTitle()}): ${field.getContent() ?? ''} ---`;
+        });
+        return summary;
+    }
+
+    isValidTemplate = (cols: Col[]) => {
+        const maxMatches = this.maxMatches(this.getMatches(cols));
+        return maxMatches === this.contentFields.length;
+    };
+
+    getMatches = (cols: Col[]): number[][] => {
+        const numFields = this.contentFields.length;
+
+        if (cols.length !== numFields) return [];
+
+        const matches: number[][] = Array(numFields)
+            .fill([])
+            .map(() => []);
+
+        this.contentFields.forEach((field, i) => {
+            matches[i] = field.matches(cols);
+        });
+
+        return matches;
+    };
+
+    maxMatches = (matches: number[][]) => {
+        if (matches.length === 0) return 0;
+
+        const fieldsCt = this.contentFields.length;
+        const used: boolean[] = Array(fieldsCt).fill(false);
+        const mt: number[] = Array(fieldsCt).fill(-1);
+
+        const augmentingPath = (v: number): boolean => {
+            if (used[v]) return false;
+            used[v] = true;
+
+            for (const to of matches[v]) {
+                if (mt[to] === -1 || augmentingPath(mt[to])) {
+                    mt[to] = v;
+                    return true;
+                }
+            }
+            return false;
+        };
+
+        for (let v = 0; v < fieldsCt; ++v) {
+            used.fill(false);
+            augmentingPath(v);
+        }
+
+        let count: number = 0;
+
+        for (let i = 0; i < fieldsCt; ++i) {
+            if (mt[i] !== -1) ++count;
+        }
+
+        return count;
+    };
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
deleted file mode 100644
index 3c610b36a..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx
+++ /dev/null
@@ -1,139 +0,0 @@
-import { makeAutoObservable } from 'mobx';
-import { Col } from './DocCreatorMenu';
-import { DynamicField } from './FieldTypes/DynamicField';
-import { Field, FieldSettings } from './FieldTypes/Field';
-import { TemplateLayouts } from './TemplateBackend';
-
-export class Template {
-    mainField: DynamicField;
-    private settings: FieldSettings;
-
-    constructor(templateInfo: FieldSettings) {
-        makeAutoObservable(this);
-        this.settings = templateInfo;
-        this.mainField = this.setupMainField(templateInfo);
-    }
-
-    get childFields(): Field[] {
-        return this.mainField.getSubfields;
-    }
-    get allFields(): Field[] {
-        return this.mainField.getAllSubfields;
-    }
-    get contentFields(): Field[] {
-        return this.allFields.filter(field => field.isContentField);
-    }
-    get doc() {
-        return this.mainField.renderedDoc;
-    }
-    get title() {
-        return this.mainField.getTitle();
-    }
-
-    cleanup = () => {
-        //dispose each subfields disposers, etc.
-    };
-
-    cloneBase = async (): Promise<Template> => {
-        const clone: Template = new Template(TemplateLayouts.BasicSettings);
-        clone.mainField = (await this.mainField.makeClone(undefined)) as unknown as DynamicField;
-        clone.mainField.renderedDoc._width = this.mainField.renderedDoc._width;
-        clone.mainField.renderedDoc._height = this.mainField.renderedDoc._height;
-        return clone;
-    };
-
-    printFieldInfo = () => {
-        this.allFields.forEach(field => {
-            const doc = field.renderedDoc;
-            console.log('title: ', field.getTitle(), ' width: ', doc.width);
-        });
-    };
-
-    getRenderedDoc = () => {
-        return this.doc;
-    };
-
-    getFieldByID = (id: number): Field => {
-        return this.allFields.filter(field => field.getID === id)[0];
-    };
-
-    getFieldByTitle = (title: string) => {
-        return this.allFields.filter(field => field.getTitle() === title)[0];
-    };
-
-    setupMainField = (templateInfo: FieldSettings) => {
-        return new DynamicField().init(templateInfo, 1);
-    };
-
-    get descriptionSummary(): string {
-        let summary: string = '';
-        this.contentFields.forEach(field => {
-            summary += `--- Field #${field.getID} (title: ${field.getTitle()}): ${field.getDescription ?? ''} ---`;
-        });
-        return summary;
-    }
-
-    get compiledContent(): string {
-        let summary: string = '';
-        this.contentFields.forEach(field => {
-            summary += `--- Field #${field.getID} (title: ${field.getTitle()}): ${field.getContent() ?? ''} ---`;
-        });
-        return summary;
-    }
-
-    isValidTemplate = (cols: Col[]) => {
-        const matches: number[][] = this.getMatches(cols);
-        const maxMatches: number = this.maxMatches(matches);
-        return maxMatches === this.contentFields.length;
-    };
-
-    getMatches = (cols: Col[]): number[][] => {
-        const numFields = this.contentFields.length;
-
-        if (cols.length !== numFields) return [];
-
-        const matches: number[][] = Array(numFields)
-            .fill([])
-            .map(() => []);
-
-        this.contentFields.forEach((field, i) => {
-            matches[i] = field.matches(cols);
-        });
-
-        return matches;
-    };
-
-    maxMatches = (matches: number[][]) => {
-        if (matches.length === 0) return 0;
-
-        const fieldsCt = this.contentFields.length;
-        const used: boolean[] = Array(fieldsCt).fill(false);
-        const mt: number[] = Array(fieldsCt).fill(-1);
-
-        const augmentingPath = (v: number): boolean => {
-            if (used[v]) return false;
-            used[v] = true;
-
-            for (const to of matches[v]) {
-                if (mt[to] === -1 || augmentingPath(mt[to])) {
-                    mt[to] = v;
-                    return true;
-                }
-            }
-            return false;
-        };
-
-        for (let v = 0; v < fieldsCt; ++v) {
-            used.fill(false);
-            augmentingPath(v);
-        }
-
-        let count: number = 0;
-
-        for (let i = 0; i < fieldsCt; ++i) {
-            if (mt[i] !== -1) ++count;
-        }
-
-        return count;
-    };
-}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.ts
new file mode 100644
index 000000000..9b0fac3a6
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.ts
@@ -0,0 +1,768 @@
+import { FieldSettings, ViewType } from './TemplateFieldTypes/TemplateField';
+
+export enum TemplateFieldType {
+    TEXT = 'text',
+    VISUAL = 'visual',
+    UNSET = 'unset',
+}
+
+export enum TemplateFieldSize {
+    TINY = 'tiny',
+    SMALL = 'small',
+    MEDIUM = 'medium',
+    LARGE = 'large',
+    HUGE = 'huge',
+}
+
+export class TemplateLayouts {
+    public static get allTemplates(): FieldSettings[] {
+        return Object.values(TemplateLayouts);
+    }
+
+    public static BasicSettings: FieldSettings = {
+        title: 'template_framework',
+        tl: [0, 0],
+        br: [400, 700],
+        viewType: ViewType.FREEFORM,
+        opts: {},
+    };
+
+    public static FourField001: FieldSettings = {
+        title: 'fourfield001',
+        tl: [0, 0],
+        br: [416, 700],
+        viewType: ViewType.FREEFORM,
+        opts: {
+            backgroundColor: '#C0B887',
+            _layout_borderRounding: '.05',
+            //borderColor: '#6B461F',
+            //borderWidth: '12',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.95, -1],
+                br: [0.95, -0.85],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY],
+                description: 'A title field for very short text that contextualizes the content.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: '#F1F0E9',
+                    hCentering: 'h-center',
+                    contentBold: true,
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.87, -0.83],
+                br: [0.87, 0.2],
+                types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                description: 'The main focus of the template; could be an image, long text, etc.',
+                opts: {
+                    _layout_borderRounding: '.05',
+                    borderColor: '#8F5B25',
+                    borderWidth: 6,
+                    backgroundColor: '#CECAB9',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.8, 0.2],
+                br: [0.8, 0.3],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A caption for field #2, very short text.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    hCentering: 'h-center',
+                    text_fontColor: '#F1F0E9',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.87, 0.37],
+                br: [0.87, 0.96],
+                types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                description: 'A medium-sized field for medium/long text.',
+                opts: {
+                    _layout_borderRounding: '.05',
+                    borderColor: '#8F5B25',
+                    borderWidth: 6,
+                    backgroundColor: '#CECAB9',
+                },
+            },
+        ],
+    };
+
+    public static FourField002: FieldSettings = {
+        title: 'fourfield002',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [425, 778],
+        opts: {
+            backgroundColor: '#242425',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.83, -0.95],
+                br: [0.83, -0.2],
+                types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus.',
+                opts: {
+                    borderWidth: 8,
+                    borderColor: '#F8E71C',
+                    backgroundColor: '#242425',
+                    text_fontColor: 'white',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.65, -0.2],
+                br: [0.65, -0.02],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY],
+                description: 'A tiny field for just a word or two of plain text.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: 'white',
+                    hCentering: 'h-center',
+                    text_transform: 'uppercase',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.65, 0],
+                br: [0.65, 0.18],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY],
+                description: 'A tiny field for just a word or two of plain text.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: 'white',
+                    hCentering: 'h-center',
+                    text_transform: 'uppercase',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.83, 0.2],
+                br: [0.83, 0.95],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                description: 'A medium to large-sized field suitable for longer text that should contextualize field 1.',
+                opts: {
+                    borderWidth: 8,
+                    borderColor: '#F8E71C',
+                    text_fontColor: 'white',
+                    backgroundColor: '#242425',
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.8, -0.075],
+                br: [-0.525, 0.075],
+                opts: {
+                    backgroundColor: '#F8E71C',
+                    _rotation: 45,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.3075, -0.0245],
+                br: [-0.2175, 0.0245],
+                opts: {
+                    backgroundColor: '#F8E71C',
+                    _rotation: 45,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.045, -0.0245],
+                br: [0.045, 0.0245],
+                opts: {
+                    backgroundColor: '#F8E71C',
+                    _rotation: 45,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [0.2175, -0.0245],
+                br: [0.3075, 0.0245],
+                opts: {
+                    backgroundColor: '#F8E71C',
+                    _rotation: 45,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [0.525, -0.075],
+                br: [0.8, 0.075],
+                opts: {
+                    backgroundColor: '#F8E71C',
+                    _rotation: 45,
+                },
+            },
+        ],
+    };
+
+    // public static FourField003: TemplateDocInfos = {
+    //     title: 'fourfield3',
+    //     width: 477,
+    //     height: 662,
+    //     opts: {
+    //         backgroundColor: '#9E9C95'
+    //     },
+    //     fields: [{
+    //         tl: [-.875, -.9],
+    //         br: [.875, .7],
+    //         types: [TemplateFieldType.VISUAL],
+    //         sizes: [TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+    //         description: '',
+    //         opts: {
+    //             borderWidth: '15',
+    //             borderColor: '#E0E0DA',
+    //         }
+    //     }, {
+    //         tl: [-.95, .8],
+    //         br: [-.1, .95],
+    //         types: [TemplateFieldType.TEXT],
+    //         sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+    //         description: '',
+    //         opts: {
+    //             backgroundColor: 'transparent',
+    //             color: 'white',
+    //             contentXCentering: 'h-right',
+    //         }
+    //     }, {
+    //         tl: [.1, .8],
+    //         br: [.95, .95],
+    //         types: [TemplateFieldType.TEXT],
+    //         sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+    //         description: '',
+    //         opts: {
+    //             backgroundColor: 'transparent',
+    //             color: 'red',
+    //             fontTransform: 'uppercase',
+    //             contentXCentering: 'h-left'
+    //         }
+    //     }, {
+    //         tl: [0, -.9],
+    //         br: [.85, -.66],
+    //         types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
+    //         sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+    //         description: '',
+    //         opts: {
+    //             backgroundColor: 'transparent',
+    //             contentXCentering: 'h-right'
+    //         }
+    //     }],
+    //     decorations: [{
+    //         tl: [-.025, .8],
+    //         br: [.025, .95],
+    //         opts: {
+    //             backgroundColor: '#E0E0DA',
+    //         }
+    //     }]
+    // };
+
+    public static FourField004: FieldSettings = {
+        title: 'fourfield04',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [414, 583],
+        opts: {
+            backgroundColor: '#6CCAF0',
+            //borderColor: '#1088C3',
+            //borderWidth: '10',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.86, -0.92],
+                br: [-0.075, -0.77],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY],
+                description: 'A tiny field for just a word or two of plain text.',
+                opts: {
+                    backgroundColor: '#E2B4F5',
+                    borderWidth: 9,
+                    borderColor: '#9222F1',
+                    hCentering: 'h-center',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [0.075, -0.92],
+                br: [0.86, -0.77],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY],
+                description: 'A tiny field for just a word or two of plain text.',
+                opts: {
+                    backgroundColor: '#F5B4DD',
+                    borderWidth: 9,
+                    borderColor: '#E260F3',
+                    hCentering: 'h-center',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.81, -0.64],
+                br: [0.81, 0.48],
+                types: [TemplateFieldType.VISUAL],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                description: 'A large to huge field for visual content that is the main content of the template.',
+                opts: {
+                    borderWidth: 16,
+                    borderColor: '#A2BD77',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.86, 0.6],
+                br: [0.86, 0.92],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium to large field for text that describes the visual content above',
+                opts: {
+                    borderWidth: 9,
+                    borderColor: '#F0D601',
+                    backgroundColor: '#F3F57D',
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.852, -0.67],
+                br: [0.852, 0.51],
+                opts: {
+                    backgroundColor: 'transparent',
+                    borderColor: '#007C0C',
+                    borderWidth: 10,
+                },
+            },
+        ],
+    };
+
+    public static FourField005: FieldSettings = {
+        title: 'fourfield05',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [400, 550],
+        opts: {
+            backgroundColor: '#95A575',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.9, -0.925],
+                br: [-0.075, -0.775],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A small text field for a title or word(s) that categorize the rest of the content.',
+                opts: {
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                    hCentering: 'h-center',
+                    backgroundColor: '#B8DC90',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [0.075, -0.925],
+                br: [0.9, -0.775],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A small text field for a title that categorizes the rest of the content.',
+                opts: {
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                    hCentering: 'h-center',
+                    backgroundColor: '#B8DC90',
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.82, -0.4],
+                br: [-0.5, -0.2],
+                opts: {
+                    backgroundColor: '#94B058',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.66, -0.65],
+                br: [0.66, 0.25],
+                types: [TemplateFieldType.VISUAL],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium to large field in the center of the template, for the main visual content.',
+                opts: {
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                    backgroundColor: '#B8DC90',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.875, 0.425],
+                br: [0.875, 0.925],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium to large field at the bottom of the template, for the main text content.',
+                opts: {
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                    hCentering: 'h-center',
+                    backgroundColor: '#B8DC90',
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-1.1, -0.62],
+                br: [-0.9, -0.5],
+                opts: {
+                    backgroundColor: '#7A9D31',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-1.1, 0],
+                br: [-0.9, 0.15],
+                opts: {
+                    backgroundColor: '#94B058',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.93, -0.265],
+                br: [-0.715, -0.125],
+                opts: {
+                    backgroundColor: '#728745',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [0.7, -0.45],
+                br: [0.85, -0.3],
+                opts: {
+                    backgroundColor: '#7A9D31',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [0.8, 0.03],
+                br: [1.2, 0.33],
+                opts: {
+                    backgroundColor: '#728745',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [0.875, -0.13],
+                br: [1.2, 0.12],
+                opts: {
+                    backgroundColor: '#94B058',
+                    borderColor: '#3B4A2C',
+                    borderWidth: 8,
+                },
+            },
+        ],
+    };
+
+    public static FourFieldCarousel: FieldSettings = {
+        title: 'title_fourfieldcarousel',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [500, 600],
+        opts: {
+            backgroundColor: '#D7CBAB',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.8, -0.9],
+                br: [0.8, -0.5],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A small text field for a title that categorizes the rest of the content.',
+                opts: {
+                    hCentering: 'h-center',
+                    backgroundColor: 'transparent',
+                    text_transform: 'uppercase',
+                },
+            },
+            {
+                viewType: ViewType.CAROUSEL3D,
+                tl: [-0.9, -0.5],
+                br: [0.9, 0.25],
+                opts: {
+                    borderColor: '#847F69',
+                    borderWidth: 8,
+                    backgroundColor: '#C8BA94',
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.STATIC,
+                        tl: [-0.4, -0.6],
+                        br: [0.4, 0.6],
+                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
+                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
+                        opts: {
+                            //borderColor: 'yellow',
+                            //borderWidth: '8',
+                        },
+                    },
+                    {
+                        viewType: ViewType.STATIC,
+                        tl: [-0.4, -0.6],
+                        br: [0.4, 0.6],
+                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
+                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
+                        opts: {
+                            //borderColor: 'black',
+                            //borderWidth: '8',
+                        },
+                    },
+                    {
+                        viewType: ViewType.STATIC,
+                        tl: [-0.4, -0.6],
+                        br: [0.4, 0.6],
+                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
+                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
+                        opts: {
+                            //borderColor: 'yellow',
+                            //borderWidth: '8',
+                        },
+                    },
+                ],
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.9, 0.35],
+                br: [0.9, 0.9],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium text field for a description of the content in the carousel.',
+                opts: {
+                    hCentering: 'h-center',
+                    backgroundColor: 'transparent',
+                },
+            },
+        ],
+    };
+
+    public static ThreeField001: FieldSettings = {
+        title: 'threefield001',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [575, 770],
+        opts: {
+            backgroundColor: '#DDD3A9',
+        },
+        subfields: [
+            {
+                viewType: ViewType.FREEFORM,
+                tl: [-0.66, -0.747],
+                br: [0.66, 0.247],
+                description: 'A medium to large field for visual content that is the central focus.',
+                opts: {
+                    borderColor: 'yellow',
+                    borderWidth: 8,
+                    backgroundColor: '#DDD3A9',
+                    _rotation: 45,
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.STATIC,
+                        tl: [-1.25, -1.25],
+                        br: [1.25, 1.25],
+                        types: [TemplateFieldType.VISUAL],
+                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                        description: 'A medium to large field for visual content that is the central focus.',
+                        opts: {
+                            _rotation: -45,
+                        },
+                    },
+                ],
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.7, 0.2],
+                br: [0.7, 0.46],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A very small text field for one to a few words. A good caption for the image.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    hCentering: 'h-center',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.95, 0.5],
+                br: [0.95, 0.95],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
+                description: 'A medium to large text field for a thorough description of the image. ',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: 'white',
+                },
+            },
+            {
+                viewType: ViewType.FREEFORM,
+                tl: [0.2, -1.32],
+                br: [1.8, -0.66],
+                opts: {
+                    backgroundColor: '#CEB155',
+                    _rotation: 45,
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.DEC,
+                        tl: [-1, -0.7],
+                        br: [1, -0.625],
+                        opts: {
+                            backgroundColor: 'yellow',
+                        },
+                    },
+                ],
+            },
+            {
+                viewType: ViewType.FREEFORM,
+                tl: [-1.8, -1.32],
+                br: [-0.2, -0.66],
+                opts: {
+                    backgroundColor: '#CEB155',
+                    _rotation: 135,
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.DEC,
+                        tl: [-1, -0.7],
+                        br: [1, -0.625],
+                        opts: {
+                            backgroundColor: 'yellow',
+                        },
+                    },
+                ],
+            },
+            {
+                viewType: ViewType.FREEFORM,
+                tl: [0.33, 0.75],
+                br: [1.66, 1.25],
+                opts: {
+                    backgroundColor: '#CEB155',
+                    _rotation: 135,
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.DEC,
+                        tl: [-1, -0.7],
+                        br: [1, -0.625],
+                        opts: {
+                            backgroundColor: 'yellow',
+                        },
+                    },
+                ],
+            },
+            {
+                viewType: ViewType.FREEFORM,
+                tl: [-1.66, 0.75],
+                br: [-0.33, 1.25],
+                opts: {
+                    backgroundColor: '#CEB155',
+                    _rotation: 45,
+                },
+                subfields: [
+                    {
+                        viewType: ViewType.DEC,
+                        tl: [-1, -0.7],
+                        br: [1, -0.625],
+                        opts: {
+                            backgroundColor: 'yellow',
+                        },
+                    },
+                ],
+            },
+        ],
+    };
+
+    public static ThreeField002: FieldSettings = {
+        title: 'threefield002',
+        viewType: ViewType.FREEFORM,
+        tl: [0, 0],
+        br: [477, 662],
+        opts: {
+            backgroundColor: '#9E9C95',
+        },
+        subfields: [
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.875, -0.9],
+                br: [0.875, 0.7],
+                types: [TemplateFieldType.VISUAL],
+                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
+                description: 'A medium to large visual field for the main content of the template',
+                opts: {
+                    borderWidth: 15,
+                    borderColor: '#E0E0DA',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [0.1, 0.775],
+                br: [0.95, 0.975],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A very small text field for one to a few words. The content should represent a general categorization of the image.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: '#AF0D0D',
+                    text_transform: 'uppercase',
+                    contentBold: true,
+                    hCentering: 'h-left',
+                },
+            },
+            {
+                viewType: ViewType.STATIC,
+                tl: [-0.95, 0.775],
+                br: [-0.1, 0.975],
+                types: [TemplateFieldType.TEXT],
+                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
+                description: 'A very small text field for one to a few words. The content should contextualize field 2.',
+                opts: {
+                    backgroundColor: 'transparent',
+                    text_fontColor: 'black',
+                    hCentering: 'h-right',
+                },
+            },
+            {
+                viewType: ViewType.DEC,
+                tl: [-0.025, 0.8],
+                br: [0.025, 0.95],
+                opts: {
+                    backgroundColor: '#E0E0DA',
+                },
+            },
+        ],
+    };
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
deleted file mode 100644
index 2b32d49aa..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateBackend.tsx
+++ /dev/null
@@ -1,771 +0,0 @@
-import { FieldSettings, ViewType } from "./FieldTypes/Field";
-
-export enum TemplateFieldType {
-    TEXT = 'text',
-    VISUAL = 'visual',
-    UNSET = 'unset',
-}
-
-export enum TemplateFieldSize {
-    TINY = 'tiny',
-    SMALL = 'small',
-    MEDIUM = 'medium',
-    LARGE = 'large',
-    HUGE = 'huge',
-}
-
-export class TemplateLayouts {
-    public static get allTemplates(): FieldSettings[] {
-        return Object.values(TemplateLayouts);
-    }
-
-    public static BasicSettings: FieldSettings = {
-        title: 'template_framework',
-        tl: [0, 0],
-        br: [400, 700],
-        viewType: ViewType.FREEFORM,
-        opts: {}
-    }
-
-    public static FourField001: FieldSettings = {
-        title: 'fourfield001',
-        tl: [0, 0],
-        br: [416, 700],
-        viewType: ViewType.FREEFORM,
-        opts: {
-            backgroundColor: '#C0B887',
-            _layout_borderRounding: '.05',
-            //borderColor: '#6B461F',
-            //borderWidth: '12',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.95, -1],
-                br: [0.95, -0.85],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY],
-                description: 'A title field for very short text that contextualizes the content.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: '#F1F0E9',
-                    hCentering: 'h-center',
-                    contentBold: true,
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.87, -0.83],
-                br: [0.87, 0.2],
-                types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                description: 'The main focus of the template; could be an image, long text, etc.',
-                opts: {
-                    _layout_borderRounding: '.05',
-                    borderColor: '#8F5B25',
-                    borderWidth: 6,
-                    backgroundColor: '#CECAB9',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.8, 0.2],
-                br: [0.8, 0.3],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A caption for field #2, very short text.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    hCentering: 'h-center',
-                    text_fontColor: '#F1F0E9',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.87, 0.37],
-                br: [0.87, 0.96],
-                types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                description: 'A medium-sized field for medium/long text.',
-                opts: {
-                    _layout_borderRounding: '.05',
-                    borderColor: '#8F5B25',
-                    borderWidth: 6,
-                    backgroundColor: '#CECAB9',
-                },
-            },
-        ],
-    };
-
-    public static FourField002: FieldSettings = {
-        title: 'fourfield002',
-        viewType: ViewType.FREEFORM,
-        tl: [0,0],
-        br: [425, 778],
-        opts: {
-            backgroundColor: '#242425',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.83, -0.95],
-                br: [0.83, -0.2],
-                types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium to large-sized field suitable for an image or longer text that should be the main focus.',
-                opts: {
-                    borderWidth: 8,
-                    borderColor: '#F8E71C',
-                    backgroundColor: '#242425',
-                    text_fontColor: 'white',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.65, -0.2],
-                br: [0.65, -0.02],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY],
-                description: 'A tiny field for just a word or two of plain text.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: 'white',
-                    hCentering: 'h-center',
-                    text_transform: 'uppercase',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.65, 0],
-                br: [0.65, 0.18],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY],
-                description: 'A tiny field for just a word or two of plain text.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: 'white',
-                    hCentering: 'h-center',
-                    text_transform: 'uppercase',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.83, 0.2],
-                br: [0.83, 0.95],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                description: 'A medium to large-sized field suitable for longer text that should contextualize field 1.',
-                opts: {
-                    borderWidth: 8,
-                    borderColor: '#F8E71C',
-                    text_fontColor: 'white',
-                    backgroundColor: '#242425',
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-0.8, -0.075],
-                br: [-0.525, 0.075],
-                opts: {
-                    backgroundColor: '#F8E71C',
-                    _rotation: 45,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-0.3075, -0.0245],
-                br: [-0.2175, 0.0245],
-                opts: {
-                    backgroundColor: '#F8E71C',
-                    _rotation: 45,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-0.045, -0.0245],
-                br: [0.045, 0.0245],
-                opts: {
-                    backgroundColor: '#F8E71C',
-                    _rotation: 45,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [0.2175, -0.0245],
-                br: [0.3075, 0.0245],
-                opts: {
-                    backgroundColor: '#F8E71C',
-                    _rotation: 45,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [0.525, -0.075],
-                br: [0.8, 0.075],
-                opts: {
-                    backgroundColor: '#F8E71C',
-                    _rotation: 45,
-                },
-            },
-        ],
-    };
-
-    // public static FourField003: TemplateDocInfos = {
-    //     title: 'fourfield3',
-    //     width: 477,
-    //     height: 662,
-    //     opts: {
-    //         backgroundColor: '#9E9C95'
-    //     },
-    //     fields: [{
-    //         tl: [-.875, -.9],
-    //         br: [.875, .7],
-    //         types: [TemplateFieldType.VISUAL],
-    //         sizes: [TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-    //         description: '',
-    //         opts: {
-    //             borderWidth: '15',
-    //             borderColor: '#E0E0DA',
-    //         }
-    //     }, {
-    //         tl: [-.95, .8],
-    //         br: [-.1, .95],
-    //         types: [TemplateFieldType.TEXT],
-    //         sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-    //         description: '',
-    //         opts: {
-    //             backgroundColor: 'transparent',
-    //             color: 'white',
-    //             contentXCentering: 'h-right',
-    //         }
-    //     }, {
-    //         tl: [.1, .8],
-    //         br: [.95, .95],
-    //         types: [TemplateFieldType.TEXT],
-    //         sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-    //         description: '',
-    //         opts: {
-    //             backgroundColor: 'transparent',
-    //             color: 'red',
-    //             fontTransform: 'uppercase',
-    //             contentXCentering: 'h-left'
-    //         }
-    //     }, {
-    //         tl: [0, -.9],
-    //         br: [.85, -.66],
-    //         types: [TemplateFieldType.TEXT, TemplateFieldType.VISUAL],
-    //         sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-    //         description: '',
-    //         opts: {
-    //             backgroundColor: 'transparent',
-    //             contentXCentering: 'h-right'
-    //         }
-    //     }],
-    //     decorations: [{
-    //         tl: [-.025, .8],
-    //         br: [.025, .95],
-    //         opts: {
-    //             backgroundColor: '#E0E0DA',
-    //         }
-    //     }]
-    // };
-
-    public static FourField004: FieldSettings = {
-        title: 'fourfield04',
-        viewType: ViewType.FREEFORM,
-        tl: [0,0],
-        br: [414,583],
-        opts: {
-            backgroundColor: '#6CCAF0',
-            //borderColor: '#1088C3',
-            //borderWidth: '10',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.86, -0.92],
-                br: [-0.075, -0.77],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY],
-                description: 'A tiny field for just a word or two of plain text.',
-                opts: {
-                    backgroundColor: '#E2B4F5',
-                    borderWidth: 9,
-                    borderColor: '#9222F1',
-                    hCentering: 'h-center',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [0.075, -0.92],
-                br: [0.86, -0.77],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY],
-                description: 'A tiny field for just a word or two of plain text.',
-                opts: {
-                    backgroundColor: '#F5B4DD',
-                    borderWidth: 9,
-                    borderColor: '#E260F3',
-                    hCentering: 'h-center',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.81, -0.64],
-                br: [0.81, 0.48],
-                types: [TemplateFieldType.VISUAL],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                description: 'A large to huge field for visual content that is the main content of the template.',
-                opts: {
-                    borderWidth: 16,
-                    borderColor: '#A2BD77',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.86, 0.6],
-                br: [0.86, 0.92],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium to large field for text that describes the visual content above',
-                opts: {
-                    borderWidth: 9,
-                    borderColor: '#F0D601',
-                    backgroundColor: '#F3F57D',
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-0.852, -0.67],
-                br: [0.852, 0.51],
-                opts: {
-                    backgroundColor: 'transparent',
-                    borderColor: '#007C0C',
-                    borderWidth: 10,
-                },
-            },
-        ],
-    };
-
-    public static FourField005: FieldSettings = {
-        title: 'fourfield05',
-        viewType: ViewType.FREEFORM,
-        tl: [0,0],
-        br: [400,550],
-        opts: {
-            backgroundColor: '#95A575',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.9, -.925],
-                br: [-.075, -.775],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A small text field for a title or word(s) that categorize the rest of the content.',
-                opts: {
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                    hCentering: "h-center",
-                    backgroundColor: '#B8DC90',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [.075, -.925],
-                br: [.9, -.775],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A small text field for a title that categorizes the rest of the content.',
-                opts: {
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                    hCentering: "h-center",
-                    backgroundColor: '#B8DC90',
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-.82, -.4],
-                br: [-.5, -.2],
-                opts: {
-                    backgroundColor: '#94B058',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.66, -.65],
-                br: [0.66, .25],
-                types: [TemplateFieldType.VISUAL],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium to large field in the center of the template, for the main visual content.',
-                opts: {
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                    backgroundColor: '#B8DC90',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-.875, .425],
-                br: [0.875, .925],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium to large field at the bottom of the template, for the main text content.',
-                opts: {
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                    hCentering: "h-center",
-                    backgroundColor: '#B8DC90',
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-1.1, -.62],
-                br: [-.9, -.5],
-                opts: {
-                    backgroundColor: '#7A9D31',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-1.1, 0],
-                br: [-.9, .15],
-                opts: {
-                    backgroundColor: '#94B058',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-.93, -.265],
-                br: [-.715, -.125],
-                opts: {
-                    backgroundColor: '#728745',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [.7, -.45],
-                br: [.85, -.3],
-                opts: {
-                    backgroundColor: '#7A9D31',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [.8, .03],
-                br: [1.2, .33],
-                opts: {
-                    backgroundColor: '#728745',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [.875, -.13],
-                br: [1.2, .12],
-                opts: {
-                    backgroundColor: '#94B058',
-                    borderColor: '#3B4A2C',
-                    borderWidth: 8,
-                },
-            },
-        ]
-    }
-
-    public static FourFieldCarousel: FieldSettings = {
-        title: 'title_fourfieldcarousel',
-        viewType: ViewType.FREEFORM,
-        tl:[0,0],
-        br:[500, 600],
-        opts: {
-            backgroundColor: '#D7CBAB',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.8, -.9],
-                br: [0.8, -.5],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A small text field for a title that categorizes the rest of the content.',
-                opts: {
-                    hCentering: "h-center",
-                    backgroundColor: 'transparent',
-                    text_transform: 'uppercase',
-                },
-            },
-            {
-                viewType: ViewType.CAROUSEL3D,
-                tl: [-0.9, -.5],
-                br: [0.9, .25],
-                opts: {
-                    borderColor: '#847F69',
-                    borderWidth: 8,
-                    backgroundColor: '#C8BA94',
-                },
-                subfields: [
-                    {
-                        viewType: ViewType.STATIC,
-                        tl: [-.4, -.6],
-                        br: [.4, .6],
-                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
-                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
-                        opts: {
-                            //borderColor: 'yellow',
-                            //borderWidth: '8',
-                        },
-                    },
-                    {
-                        viewType: ViewType.STATIC,
-                        tl: [-.4, -.6],
-                        br: [.4, .6],
-                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
-                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
-                        opts: {
-                            //borderColor: 'black',
-                            //borderWidth: '8',
-                        },
-                    },
-                    {
-                        viewType: ViewType.STATIC,
-                        tl: [-.4, -.6],
-                        br: [.4, .6],
-                        types: [TemplateFieldType.VISUAL, TemplateFieldType.TEXT],
-                        sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                        description: 'A medium to large field for content that will share central focus with other content in the carousel.',
-                        opts: {
-                            //borderColor: 'yellow',
-                            //borderWidth: '8',
-                        },
-                    },
-                ]
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.9, .35],
-                br: [0.9, .9],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium text field for a description of the content in the carousel.',
-                opts: {
-                    hCentering: "h-center",
-                    backgroundColor: 'transparent',
-                },
-            },
-        ]
-    }
-
-
-    public static ThreeField001: FieldSettings = {
-        title: 'threefield001',
-        viewType: ViewType.FREEFORM,
-        tl: [0,0],
-        br: [575, 770],
-        opts: {
-            backgroundColor: '#DDD3A9',
-        },
-        subfields: [
-            {
-                viewType: ViewType.FREEFORM,
-                tl: [-0.66, -0.747],
-                br: [0.66, 0.247],
-                description: 'A medium to large field for visual content that is the central focus.',
-                opts: {
-                    borderColor: 'yellow',
-                    borderWidth: 8,
-                    backgroundColor: '#DDD3A9',
-                    _rotation: 45,
-                },
-                subfields: [
-                    {
-                    viewType: ViewType.STATIC,
-                    tl: [-1.25, -1.25],
-                    br: [1.25, 1.25],
-                    types: [TemplateFieldType.VISUAL],
-                    sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                    description: 'A medium to large field for visual content that is the central focus.',
-                    opts: {
-                        _rotation: -45,
-                    },
-                },
-            ]
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.7, 0.2],
-                br: [0.7, 0.46],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A very small text field for one to a few words. A good caption for the image.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    hCentering: 'h-center',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.95, 0.5],
-                br: [0.95, 0.95],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE],
-                description: 'A medium to large text field for a thorough description of the image. ',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: 'white',
-                },
-            },
-            {
-                viewType: ViewType.FREEFORM,
-                tl: [0.2, -1.32],
-                br: [1.8, -0.66],
-                opts: {
-                    backgroundColor: '#CEB155',
-                    _rotation: 45,
-                },
-                subfields: [
-                    {
-                        viewType: ViewType.DEC,
-                        tl: [-1, -.7],
-                        br: [1, -.625],
-                        opts: {
-                            backgroundColor: 'yellow',
-                        },
-                    },
-                ]
-            },
-            {
-                viewType: ViewType.FREEFORM,
-                tl: [-1.8, -1.32],
-                br: [-0.2, -0.66],
-                opts: {
-                    backgroundColor: '#CEB155',
-                    _rotation: 135,
-                },
-                subfields: [
-                    {
-                        viewType: ViewType.DEC,
-                        tl: [-1, -.7],
-                        br: [1, -.625],
-                        opts: {
-                            backgroundColor: 'yellow',
-                        },
-                    },
-                ]
-            },
-            {
-                viewType: ViewType.FREEFORM,
-                tl: [0.33, 0.75],
-                br: [1.66, 1.25],
-                opts: {
-                    backgroundColor: '#CEB155',
-                    _rotation: 135,
-                },
-                subfields: [
-                    {
-                        viewType: ViewType.DEC,
-                        tl: [-1, -.7],
-                        br: [1, -.625],
-                        opts: {
-                            backgroundColor: 'yellow',
-                        },
-                    },
-                ]
-            },
-            {
-                viewType: ViewType.FREEFORM,
-                tl: [-1.66, 0.75],
-                br: [-0.33, 1.25],
-                opts: {
-                    backgroundColor: '#CEB155',
-                    _rotation: 45,
-                },
-                subfields: [
-                    {
-                        viewType: ViewType.DEC,
-                        tl: [-1, -.7],
-                        br: [1, -.625],
-                        opts: {
-                            backgroundColor: 'yellow',
-                        },
-                    },
-                ]
-            },
-        ],
-    };
-
-    public static ThreeField002: FieldSettings = {
-        title: 'threefield002',
-        viewType: ViewType.FREEFORM,
-        tl: [0,0],
-        br: [477, 662],
-        opts: {
-            backgroundColor: '#9E9C95',
-        },
-        subfields: [
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.875, -0.9],
-                br: [0.875, 0.7],
-                types: [TemplateFieldType.VISUAL],
-                sizes: [TemplateFieldSize.MEDIUM, TemplateFieldSize.LARGE, TemplateFieldSize.HUGE],
-                description: 'A medium to large visual field for the main content of the template',
-                opts: {
-                    borderWidth: 15,
-                    borderColor: '#E0E0DA',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [0.1, 0.775],
-                br: [0.95, 0.975],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A very small text field for one to a few words. The content should represent a general categorization of the image.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: '#AF0D0D',
-                    text_transform: 'uppercase',
-                    contentBold: true,
-                    hCentering: 'h-left',
-                },
-            },
-            {
-                viewType: ViewType.STATIC,
-                tl: [-0.95, 0.775],
-                br: [-0.1, 0.975],
-                types: [TemplateFieldType.TEXT],
-                sizes: [TemplateFieldSize.TINY, TemplateFieldSize.SMALL],
-                description: 'A very small text field for one to a few words. The content should contextualize field 2.',
-                opts: {
-                    backgroundColor: 'transparent',
-                    text_fontColor: 'black',
-                    hCentering: 'h-right',
-                },
-            },
-            {
-                viewType: ViewType.DEC,
-                tl: [-0.025, 0.8],
-                br: [0.025, 0.95],
-                opts: {
-                    backgroundColor: '#E0E0DA',
-                },
-            },
-        ],
-    };
-}
-
-
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DecorationField.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DecorationField.ts
new file mode 100644
index 000000000..4f5ad89b6
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DecorationField.ts
@@ -0,0 +1,11 @@
+import { DynamicField } from './DynamicField';
+import { FieldSettings, TemplateField } from './TemplateField';
+
+export class DecorationField extends DynamicField {
+    private constructor(settings: FieldSettings, parent?: TemplateField, id: number = 1) {
+        super(settings, parent, id);
+    }
+    static Create(settings: FieldSettings, id: number | undefined, parent?: TemplateField) {
+        return DynamicField.Create(settings, id, parent);
+    }
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DynamicField.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DynamicField.ts
new file mode 100644
index 000000000..0917093b1
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/DynamicField.ts
@@ -0,0 +1,164 @@
+import { reaction } from 'mobx';
+import { IDisposer } from 'mobx-utils';
+import { Doc, DocListCast } from '../../../../../../fields/Doc';
+import { DocData } from '../../../../../../fields/DocSymbols';
+import { List } from '../../../../../../fields/List';
+import { NumCast } from '../../../../../../fields/Types';
+import { Docs } from '../../../../../documents/Documents';
+import { DocumentType } from '../../../../../documents/DocumentTypes';
+import { FieldSettings, TemplateField, ViewType } from './TemplateField';
+
+export class DynamicField extends TemplateField {
+    protected _disposers: { [name: string]: IDisposer } = {};
+    protected _subfields: TemplateField[] | undefined;
+
+    protected constructor(settings: FieldSettings, parent?: TemplateField, id: number = 1) {
+        super(settings, parent, id);
+    }
+    static Create(settings: FieldSettings, id: number | undefined, parent?: TemplateField) {
+        const field = new DynamicField(settings, parent, id);
+        field._subfields = settings.subfields?.map((fieldSettings, index) => TemplateField.initField(fieldSettings, index, field)) || [];
+        field._renderDoc = field.initializeDocument(settings, field._subfields);
+        field._disposers.fieldList = reaction(() => DocListCast(field._renderDoc?.[Doc.LayoutFieldKey(field._renderDoc)]), field.handleFieldUpdate);
+        return field;
+    }
+
+    get getSubfields(): TemplateField[] {
+        return this._subfields ?? [];
+    }
+    get getAllSubfields() {
+        return (
+            this._subfields?.reduce((fields, field) => {
+                fields.push(field, ...((field as DynamicField).getAllSubfields ?? []));
+                return fields;
+            }, [] as TemplateField[]) ?? []
+        );
+    }
+
+    setSubFields = (fields: TemplateField[]) => (this._subfields = fields);
+
+    handleFieldUpdate = (newDocsList: Doc[]) => {
+        const currRenderedDocs = new Set(this._subfields?.filter(field => field.renderedDoc).map(field => field.renderedDoc!));
+        newDocsList.forEach(doc => !currRenderedDocs.has(doc) && this.addFieldFromDoc(doc));
+        currRenderedDocs.forEach(doc => {
+            if (!newDocsList.includes(doc)) {
+                this._subfields?.forEach(field => field.renderedDoc === doc && this.removeField(field));
+            }
+        });
+    };
+
+    addFieldFromDoc = (doc: Doc) => {
+        const par = this._renderDoc;
+        const settings: FieldSettings = {
+            tl: [Number(doc._x) / NumCast(par?._width, 1), Number(doc?._y) / NumCast(par?._height, 1)],
+            br: [(Number(doc._x) + Number(doc._width)) / NumCast(par?._width, 1), (Number(doc._y) + Number(doc._height)) / NumCast(par?._height, 1)],
+            viewType: doc.type === DocumentType.COL ? ViewType.FREEFORM : ViewType.STATIC,
+            opts: {},
+        };
+
+        this._subfields?.push(TemplateField.initField(settings, this._subfields?.length ?? 0, this));
+    };
+
+    addField = (field: TemplateField) => {
+        if (!this._subfields?.includes(field)) {
+            this._subfields?.push(field);
+            // Doc.SetContainer(field.Document, this.Document);
+        }
+    };
+
+    dispose = () => Object.values(this._disposers).forEach(disposer => disposer?.());
+
+    removeField = (field: TemplateField) => {
+        // var childDocs: Doc[] = DocListCast(this.Document[Doc.LayoutFieldKey(this.Document)]);
+        // this.Document[Doc.LayoutFieldKey(this.Document)] = new List<Doc>([...childDocs.splice(childDocs.indexOf(field.Document), 1)]);
+        this._subfields?.splice(this._subfields?.indexOf(field), 1);
+        (field as DynamicField).dispose?.();
+    };
+
+    // implement Field's abstract method for replacing a subfield with a new one
+    exchangeFields(newField: TemplateField, oldField: TemplateField) {
+        this._subfields?.splice(this._subfields?.indexOf(oldField), 1, newField);
+    }
+
+    get isContentField(): boolean {
+        return false;
+    }
+
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    setContent(content: string, type: ViewType) {}
+
+    getContent = () => '';
+
+    addChildToDocument = (doc: Doc) => this._renderDoc && Doc.SetContainer(doc, this._renderDoc);
+
+    matches = (): Array<number> => [];
+
+    async makeClone(parent?: DynamicField): Promise<TemplateField> {
+        const clone = (await super.makeClone(parent)) as unknown as DynamicField;
+        if (this._subfields) {
+            clone._subfields = await Promise.all(this._subfields.map(async cloneField => await cloneField.makeClone(clone)));
+        }
+        clone._renderDoc && (clone._renderDoc[DocData].data = new List<Doc>(clone._subfields?.filter(sub => sub.renderedDoc).map(sub => sub.renderedDoc!) ?? []));
+        return clone;
+    }
+
+    initializeDocument = (settings: FieldSettings, subFields: TemplateField[]) => {
+        const renderedSubfields = subFields?.filter(field => field.renderedDoc).map(field => field.renderedDoc!) ?? [];
+        settings.opts.title = settings.title;
+        switch (settings.viewType) {
+            case ViewType.CAROUSEL3D: return Docs.Create.Carousel3DDocument(renderedSubfields, settings.opts);
+            case ViewType.FREEFORM:   
+            default:                  return Docs.Create.FreeformDocument(renderedSubfields, settings.opts);
+        } // prettier-ignore
+    };
+}
+
+// export class DynamicField extends Field {
+//     protected subfields: Field[];
+
+//     protected Document!: Doc;
+
+//     constructor(settings: FieldSettings, id: number, parent?: Field) {
+//         super(settings, id, parent);
+//         this.subfields = this.setupSubfields(this);
+//         this.initializeDocument();
+//     }
+
+//     setContent = (content: string, type: ViewType) => { return };
+//     getContent = () => { return '' };
+//     get isContentField(): boolean { return false };
+
+//     addChildToDocument = (doc: Doc) => {
+//         Doc.SetContainer(doc, this.Document);
+//     }
+
+//     matches = (cols: Col[]): Array<number> => {
+//         return [];
+//     }
+
+//     initializeDocument = (): Doc => {
+//         let doc: Doc;
+//         const renderedSubfields: Doc[] = this.subfields.map(field => field.renderedDoc);
+//         switch (this.settings.viewType) {
+//             case ViewType.CAROUSEL3D:
+//                 doc = Docs.Create.Carousel3DDocument(renderedSubfields, {
+//                     title: this.title,
+//                 });
+//                 break;
+//             case ViewType.FREEFORM:
+//                 doc = Docs.Create.FreeformDocument(renderedSubfields, {
+//                     title: this.title,
+//                 });
+//                 break;
+//             default:
+//                 doc = Docs.Create.FreeformDocument(renderedSubfields, {
+//                     title: this.title,
+//                 });
+//             break;
+//         }
+
+//         this.Document = doc;
+//         return doc;
+//     }
+
+// }
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/StaticContentField.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/StaticContentField.ts
new file mode 100644
index 000000000..b8839efab
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/StaticContentField.ts
@@ -0,0 +1,72 @@
+import { DocData } from '../../../../../../fields/DocSymbols';
+import { RichTextField } from '../../../../../../fields/RichTextField';
+import { ImageField } from '../../../../../../fields/URLField';
+import { Docs } from '../../../../../documents/Documents';
+import { FieldSettings, TemplateField, ViewType } from './TemplateField';
+import { TemplateFieldUtils } from './TemplateFieldUtils';
+
+export abstract class StaticContentField extends TemplateField {
+    protected _content: string = '';
+
+    getContent = () => this._content ?? 'unset';
+    get isContentField(): boolean {
+        return true;
+    }
+}
+
+export class ImageTemplateField extends StaticContentField {
+    private constructor(settings: FieldSettings, parent?: TemplateField, id: number = 1) {
+        super(settings, parent, id);
+    }
+    static Create(settings: FieldSettings, id: number | undefined, parent: TemplateField | undefined) {
+        const field = new ImageTemplateField(settings, parent, id);
+        field._renderDoc = field.initializeDocument(settings);
+        return field;
+    }
+
+    setContent(url: string, type?: ViewType) {
+        super.setContent(url, type);
+
+        if (type === ViewType.IMG || type === undefined) {
+            this._renderDoc && (this._renderDoc[DocData].data = new ImageField(url));
+            this._content = url;
+        } else {
+            this.changeFieldType(type).setContent(url, type);
+        }
+    }
+
+    initializeDocument = (settings: FieldSettings) => {
+        settings.opts.title = settings.title;
+        settings.opts._layout_fitWidth = false;
+
+        return Docs.Create.ImageDocument('', settings.opts);
+    };
+}
+
+export class TextTemplateField extends StaticContentField {
+    private constructor(settings: FieldSettings, parent?: TemplateField, id: number = 1) {
+        super(settings, parent, id);
+    }
+    static Create(settings: FieldSettings, id: number, parent?: TemplateField) {
+        const field = new TextTemplateField(settings, parent, id);
+        field._renderDoc = field.initializeDocument(settings);
+        field._renderDoc.text_fontSize = `${TemplateFieldUtils.calculateFontSize(field._dimensions?.width ?? 10, field._dimensions?.height ?? 10, '', true)}`;
+        return field;
+    }
+    setContent(text: string, type?: ViewType) {
+        super.setContent(text, type);
+
+        if (type === ViewType.TEXT || type === undefined) {
+            this._content = text;
+            this._renderDoc && (this._renderDoc[DocData].text = RichTextField.textToRtf(text));
+        } else {
+            this.changeFieldType(type).setContent(text, type);
+        }
+    }
+
+    initializeDocument = (settings: FieldSettings | undefined) => {
+        const opts = settings?.opts;
+        opts && (opts.title = settings?.title ?? '');
+        return Docs.Create.TextDocument('', opts);
+    };
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateField.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateField.ts
new file mode 100644
index 000000000..318bffde5
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateField.ts
@@ -0,0 +1,159 @@
+/* eslint-disable no-use-before-define */
+import { computed } from 'mobx';
+import { Doc } from '../../../../../../fields/Doc';
+import { DocData } from '../../../../../../fields/DocSymbols';
+import { Copy } from '../../../../../../fields/FieldSymbols';
+import { ObjectField } from '../../../../../../fields/ObjectField';
+import { DocumentOptions } from '../../../../../documents/Documents';
+import { Col } from '../DocCreatorMenu';
+import { TemplateFieldSize, TemplateFieldType } from '../TemplateBackend';
+
+export abstract class TemplateField {
+    /**
+     * Creates and initializes a new TemplateField based on the settings and parameters
+     *
+     * implemented in FieldUtils and assigned in main (to avoid import cycles)
+     *
+     * @param settings - specification of the field type and other parameters
+     * @param index -
+     * @param parent - TemplateField that contains the new field
+     * @param sameId -
+     * @returns TemplateField
+     */
+    static initField: (settings: FieldSettings | undefined, index: number | undefined, parent: TemplateField | undefined, sameId?: boolean) => TemplateField;
+
+    protected _parent?: TemplateField;
+    protected _id: number;
+    protected _title: string = '';
+    protected _settings: FieldSettings;
+    protected _renderDoc: Doc | undefined;
+    protected _dimensions: FieldDimensions | undefined;
+
+    constructor(settings: FieldSettings, parent?: TemplateField, id: number = 1) {
+        this._id = id;
+        this._parent = parent;
+        this._settings = settings;
+        this._title = settings.title ?? '';
+        this._dimensions = this.getLocalDimensions(this._settings, this._parent?.getDimensions);
+        this.applyBasicOpts(this._dimensions, settings);
+        return this;
+    }
+
+    get renderedDoc() {
+        return this._renderDoc;
+    }
+    get getDimensions() {
+        return this._dimensions;
+    }
+    get getID() {
+        return this._id;
+    }
+    get getDescription(): string {
+        return this._settings?.description ?? '';
+    }
+    get viewType(): ViewType | undefined {
+        return this._settings?.viewType;
+    }
+
+    setTitle = (title: string) => {
+        this._title = title;
+        this._renderDoc && (this._renderDoc.title = title);
+    };
+    getTitle = () => this._title;
+
+    abstract get isContentField(): boolean;
+    setContent(content: string, type?: ViewType) {
+        this._settings && (this._settings.viewType = type ?? this._settings.viewType);
+    }
+
+    abstract getContent(): string;
+
+    async makeClone(parent?: TemplateField): Promise<TemplateField> {
+        const clone = TemplateField.initField(this._settings, this._id, parent, true); // create a value for this.Document/subfields that we want to ignore
+        clone._renderDoc = this._renderDoc ? (await Doc.MakeClone(this._renderDoc)).clone : undefined;
+        clone._title = this._title;
+        clone._dimensions = this._dimensions;
+        return clone;
+    }
+
+    @computed get documentOptions(): DocumentOptions {
+        const opts: DocumentOptions = {};
+        Object.assign(opts, this._renderDoc?.[DocData]);
+        Object.entries(opts).forEach(([key, field]) => {
+            Object.assign(opts, { [key]: field instanceof Object ? ObjectField.MakeCopy(field) : field[Copy]() });
+        });
+        return opts;
+    }
+    exchangeFields(newField: TemplateField, oldField: TemplateField) {
+        throw new Error('Only DynamicField can exchange fields.' + newField._title + ' ' + oldField._title);
+    }
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    changeFieldType = (newType: ViewType): TemplateField => {
+        const newField = TemplateField.initField(this._settings, this._id, this._parent, true);
+        this._parent?.exchangeFields(newField, this);
+        return newField;
+    };
+
+    matches = (cols: Col[]): number[] => {
+        const colMatchesField = (col: Col) => (this._settings?.sizes?.some(size => col.sizes?.includes(size)) && this._settings.types?.includes(col.type)) ?? false;
+
+        const matches: Array<number> = [];
+        cols.forEach((col, v) => colMatchesField(col) && matches.push(v));
+        return matches;
+    };
+
+    private getLocalDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentDimensions?: FieldDimensions): FieldDimensions => {
+        if (!parentDimensions) {
+            return { width: coords.br[0] - coords.tl[0], height: coords.br[1] - coords.tl[1], coord: { x: coords.tl[0], y: coords.tl[1] } };
+        }
+        const l = (coords.tl[0] * parentDimensions.width) / 2;
+        const t = coords.tl[1] * parentDimensions.height / 2; //prettier-ignore
+        const r = (coords.br[0] * parentDimensions.width) / 2;
+        const b = coords.br[1] * parentDimensions.height / 2; //prettier-ignore
+        return { width: r-l, height: b-t, coord: { x: l, y: t } }; //prettier-ignore
+    };
+
+    private applyBasicOpts = (dimensions: FieldDimensions, settings: FieldSettings | undefined) => {
+        const opts: DocumentOptions = settings?.opts ?? {};
+        opts.isDefaultTemplateDoc ??= true;
+        opts._layout_hideScroll ??= true;
+        opts.x ??= dimensions.coord.x;
+        opts.y ??= dimensions.coord.y;
+        opts._height ??= dimensions.height;
+        opts._width ??= dimensions.width;
+        opts._nativeWidth ??= dimensions.width;
+        opts._nativeHeight ??= dimensions.height;
+        opts._layout_nativeDimEditable ??= true;
+    };
+}
+
+export type FieldSettings = {
+    tl: [number, number];
+    br: [number, number];
+    opts: DocumentOptions;
+    viewType: ViewType;
+    title?: string;
+    subfields?: FieldSettings[];
+    types?: TemplateFieldType[];
+    sizes?: TemplateFieldSize[];
+    description?: string;
+};
+
+export enum ViewType {
+    CAROUSEL3D = 'carousel3d',
+    FREEFORM = 'freeform',
+    STATIC = 'static',
+    DEC = 'decoration',
+    IMG = 'image',
+    TEXT = 'text',
+}
+
+export type FieldDimensions = {
+    width: number;
+    height: number;
+    coord: { x: number; y: number };
+};
+
+export type FieldTree = {
+    node: { field: TemplateField; subfields: FieldTree[] };
+};
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateFieldUtils.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateFieldUtils.ts
new file mode 100644
index 000000000..c38d769cd
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateFieldTypes/TemplateFieldUtils.ts
@@ -0,0 +1,71 @@
+import { DecorationField } from './DecorationField';
+import { DynamicField } from './DynamicField';
+import { ImageTemplateField, TextTemplateField } from './StaticContentField';
+import { FieldSettings, TemplateField, ViewType } from './TemplateField';
+
+export class TemplateFieldUtils {
+    /**
+     * Creates and initializes a new TemplateField based on the settings and parameters
+     *
+     * implements Field.initField ... see main.tsx
+     *
+     * @param settings - specification of the field type and other parameters
+     * @param index -
+     * @param parent - TemplateField that contains the new field
+     * @param sameId -
+     * @returns TemplateField
+     */
+    public static initField = (settings: FieldSettings, index: number, parent: TemplateField | undefined, sameId: boolean = false): TemplateField => {
+        const id = sameId ? index : parent ? Number(`${parent.getID}${index}`) : 1;
+        switch (settings?.viewType) {
+            case ViewType.FREEFORM:
+            case ViewType.CAROUSEL3D: return DynamicField.Create(settings, id, parent);
+            case ViewType.IMG:        return ImageTemplateField.Create(settings, id, parent);
+            case ViewType.TEXT:       return TextTemplateField.Create(settings, id, parent);
+            case ViewType.DEC:        return DecorationField.Create(settings, id, parent);
+            default:                  return TextTemplateField.Create(settings, id, parent);
+        } // prettier-ignore
+    };
+
+    // eslint-disable-next-line @typescript-eslint/no-unused-vars
+    public static calculateFontSize = (contWidth: number, contHeight: number, text: string, uppercase: boolean): number => {
+        const words: string[] = text.split(/\s+/).filter(Boolean);
+
+        let currFontSize = 1;
+        let rowsCount = 1;
+        let currTextHeight = currFontSize * rowsCount * 2;
+
+        while (currTextHeight <= contHeight) {
+            let wordIndex = 0;
+            let currentRowWidth = 0;
+            let wordsInCurrRow = 0;
+            rowsCount = 1;
+
+            while (wordIndex < words.length) {
+                const word = words[wordIndex];
+                const wordWidth = word.length * currFontSize * 0.7;
+
+                if (currentRowWidth + wordWidth <= contWidth) {
+                    currentRowWidth += wordWidth;
+                    ++wordsInCurrRow;
+                } else {
+                    if (words.length !== 1 && words.length > wordsInCurrRow) {
+                        rowsCount++;
+                        currentRowWidth = wordWidth;
+                        wordsInCurrRow = 1;
+                    } else {
+                        break;
+                    }
+                }
+
+                wordIndex++;
+            }
+
+            currTextHeight = rowsCount * currFontSize * 2;
+
+            currFontSize += 1;
+        }
+
+        return currFontSize - 1;
+    };
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.ts
new file mode 100644
index 000000000..1959cf9d6
--- /dev/null
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.ts
@@ -0,0 +1,33 @@
+import { makeAutoObservable } from 'mobx';
+import { Col } from './DocCreatorMenu';
+import { FieldSettings } from './TemplateFieldTypes/TemplateField';
+import { Template } from './Template';
+
+export class TemplateManager {
+    templates: Template[] = [];
+
+    constructor(templateSettings: FieldSettings[]) {
+        makeAutoObservable(this);
+        this.templates = this.initializeTemplates(templateSettings);
+    }
+
+    initializeTemplates = (templateSettings: FieldSettings[]): Template[] => {
+        const initializedTemplates: Template[] = [];
+        templateSettings.forEach(settings => initializedTemplates.push(new Template(settings)));
+        return initializedTemplates;
+    };
+
+    getValidTemplates = (cols: Col[]): Template[] => {
+        console.log('called in manager with templates: ', this.templates);
+        return this.templates.filter(template => template.isValidTemplate(cols));
+    };
+
+    addTemplate = (newTemplate: Template) => {
+        this.templates.push(newTemplate);
+    };
+
+    removeTemplate = (template: Template) => {
+        this.templates.splice(this.templates.indexOf(template), 1);
+        template.cleanup();
+    };
+}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
deleted file mode 100644
index 09b4ce029..000000000
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/TemplateManager.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { makeAutoObservable } from "mobx";
-import { Col } from "./DocCreatorMenu";
-import { FieldSettings } from "./FieldTypes/Field";
-import { Template } from "./Template";
-
-export class TemplateManager {
-
-    templates: Template[] = [];
-
-    constructor(templateSettings: FieldSettings[]) {
-        makeAutoObservable(this);
-        this.templates = this.initializeTemplates(templateSettings);
-    }
-
-    initializeTemplates = (templateSettings: FieldSettings[]): Template[] => {
-        const initializedTemplates: Template[] = [];
-        templateSettings.forEach(settings => initializedTemplates.push(new Template(settings)));
-        return initializedTemplates;
-    }
-
-    getValidTemplates = (cols: Col[]): Template[] => {
-        console.log('called in manager with templates: ', this.templates)
-        return this.templates.filter(template => template.isValidTemplate(cols));
-    }
-
-    addTemplate = (newTemplate: Template) =>{
-        this.templates.push(newTemplate);
-    }
-
-    removeTemplate = (template: Template) => {
-        this.templates.splice(this.templates.indexOf(template), 1);
-        template.cleanup();
-    }
-}
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

