diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-12-04 17:49:11 -0500 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-12-04 17:49:11 -0500 |
commit | 2b9251f36be19b9fab9ce6ccc9280321c032fc0f (patch) | |
tree | 58d52635076eca9f0cf6681d9e15f5f3c9e4ac88 | |
parent | af94458be6620ae8a05730f17ee3fc4ec403cf09 (diff) |
stuff seems to have broken... (some changes relating to doc rerendering)
4 files changed, 48 insertions, 15 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx index 5ff809170..d45e11f95 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx @@ -589,7 +589,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { 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 const field = template.getFieldByID(Number(fieldID)); - //console.log(field); field.setContent(col.defaultContent ?? '', col.type === TemplateFieldType.VISUAL ? FieldContentType.IMAGE : FieldContentType.STRING); field.setTitle(col.title); } else { diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx index 9ae04d086..507790977 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx @@ -34,7 +34,7 @@ export class FieldUtils { doc._height = oldDoc ? oldDoc.height : parentDimensions.height; doc._width = oldDoc ? oldDoc.width : parentDimensions.width; doc.backgroundColor = oldDoc ? oldDoc.backgroundColor : opts.backgroundColor ?? ''; - doc._layout_borderRounding = !opts._layout_borderRounding ? '0px' : ScriptField.MakeFunction(`${opts._layout_borderRounding} * this.width + 'px'`); + //doc._layout_borderRounding = !opts._layout_borderRounding ? '0px' : ScriptField.MakeFunction(`${opts._layout_borderRounding} * this.width + 'px'`); doc.borderColor = oldDoc ? oldDoc.borderColor : opts.borderColor; doc.borderWidth = oldDoc ? oldDoc.borderWidth : opts.borderWidth; doc.opacity = oldDoc ? oldDoc.opacity : opts.opacity; diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx index db54f1397..f5d86f56e 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx @@ -34,7 +34,7 @@ export class StaticField { this.dimensions = FieldUtils.getLocalDimensions({tl: settings.tl, br: settings.br}, this.parent.getDimensions); this.content = ''; this.subfields = this.setupSubfields(); - this.renderedDocument = this.setupRenderedDoc(this.contentType ?? FieldContentType.STRING); + this.renderedDocument = this.updateRenderedDoc(); this.storedAttributes = new DocumentOptions(); }; @@ -64,14 +64,13 @@ export class StaticField { setContent = (newContent: string, type?: FieldContentType) => { this.content = newContent; if (type) this.contentType = type; - this.updateRenderedDoc(this.renderedDocument, true); + this.updateRenderedDoc(this.renderedDocument /*, true*/); }; getContent() { return this.content }; setTitle = (title: string) => { this.title = title; this.renderedDocument.title = title; - this.updateRenderedDoc(this.renderedDocument); }; getTitle = () => { return this.title }; @@ -110,25 +109,61 @@ export class StaticField { return matches; }; + // updateRenderedDoc = (oldDoc?: Doc): Doc => { + // const opts = this.settings.opts; + + // if (!this.contentType) { this.contentType = FieldContentType.STRING }; + + // let doc: Doc; + + // switch (this.contentType) { + // case FieldContentType.STRING: + // const text = String(this.content); + // doc = Docs.Create.TextDocument(text, { + // title: this.title, + // text_fontColor: oldDoc ? String(oldDoc.color) : opts.text_fontColor, + // contentBold: oldDoc ? Boolean(oldDoc.fontBold) : opts.contentBold, + // textTransform: oldDoc ? String(oldDoc.fontTransform) : opts.textTransform, + // color: oldDoc ? String(oldDoc.color) : opts.text_fontColor, + // _text_fontSize: `${FieldUtils.calculateFontSize(this.dimensions.width, this.dimensions.height, text, true)}` + // }); + // FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings, oldDoc); + // break; + // case FieldContentType.IMAGE: + // const url = String(this.content); + // doc = Docs.Create.ImageDocument(url, { + // title: this.title, + // _layout_fitWidth: false, + // }); + // FieldUtils.applyBasicOpts(doc, this.dimensions, this.settings, oldDoc); + // break; + // } + + // this.renderedDocument = doc; + + // return doc; + // }; + updateRenderedDoc = (currDoc?: Doc, forceRerender?: boolean) => { - const opts = this.settings.opts; if (!this.contentType) { this.contentType = FieldContentType.STRING }; let doc: Doc; - if (this.shouldRerender()) { + if (this.shouldRerender() || forceRerender) { this.updateStoredAttributes(this.renderedDocument); switch (this.contentType) { case FieldContentType.STRING: const text = String(this.content); + this.storedAttributes._text_fontSize = `${FieldUtils.calculateFontSize(this.dimensions.width, this.dimensions.height, this.content, true)}` doc = Docs.Create.TextDocument(text, this.storedAttributes); break; case FieldContentType.IMAGE: const url = String(this.content); doc = Docs.Create.ImageDocument(url, this.storedAttributes); break; - } + } + doc._layout_hideScroll = true; this.renderedDocument = doc; } else { this.updateStoredAttributes(this.renderedDocument); @@ -153,9 +188,7 @@ export class StaticField { ); }; - private setupRenderedDoc = (contentType: FieldContentType): Doc => { - const opts = this.settings.opts; - + private setupRenderedDoc = (): Doc => { const docOptions: Record<string, any> = new DocumentOptions(); docOptions.isDefaultTemplateDoc = true; @@ -166,7 +199,7 @@ export class StaticField { docOptions._nativeWidth = this.dimensions.width; docOptions._nativeHeight = this.dimensions.height; - Object.keys(opts).forEach(([key, value]) => { + Object.entries(this.settings.opts).forEach(([key, value]) => { docOptions[key] = value; }); @@ -184,8 +217,11 @@ export class StaticField { } doc._layout_hideScroll = true; - doc._layout_borderRounding = !opts._layout_borderRounding ? '0px' : ScriptField.MakeFunction(`${opts._layout_borderRounding} * this.width + 'px'`); + //doc._layout_borderRounding = !opts._layout_borderRounding ? '0px' : ScriptField.MakeFunction(`${opts._layout_borderRounding} * this.width + 'px'`); + + 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 4680b0316..94ef1d212 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Template.tsx @@ -147,8 +147,6 @@ export class Template { if (mt[i] !== -1) ++count; } - console.log(this.mainField.getTitle(), count) - return count; }; |