aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Doc.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-05-09 23:02:18 -0400
committerbobzel <zzzman@gmail.com>2025-05-09 23:02:18 -0400
commitafc2b90c3eab26a8a3d17bdb711652b68d2528d9 (patch)
tree58f9edb8a79c9e1e983c9cc4e8c07988e7dd5f1d /src/fields/Doc.ts
parent076bdacc5f05dd124823981e49174d276a7aebfd (diff)
parent299398cb7e21259de3bf7597995840b84e7e0590 (diff)
Merge branch 'master' into lanyi-branch
Diffstat (limited to 'src/fields/Doc.ts')
-rw-r--r--src/fields/Doc.ts23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index ba94f0504..990b6606f 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -25,6 +25,7 @@ import { ComputedField, ScriptField } from './ScriptField';
import { BoolCast, Cast, DocCast, FieldValue, ImageCastWithSuffix, NumCast, RTFCast, StrCast, ToConstructor, toList } from './Types';
import { containedFieldChangedHandler, deleteProperty, GetEffectiveAcl, getField, getter, makeEditable, makeReadOnly, setter, SharingPermissions } from './util';
import { gptImageLabel } from '../client/apis/gpt/GPT';
+import { DateField } from './DateField';
export let ObjGetRefField: (id: string, force?: boolean) => Promise<Doc | undefined>;
export let ObjGetRefFields: (ids: string[]) => Promise<Map<string, Doc | undefined>>;
@@ -1109,6 +1110,10 @@ export namespace Doc {
Cast(templateFieldValue, listSpec(Doc), [])?.map(d => d instanceof Doc && MakeMetadataFieldTemplate(d, templateDoc));
Doc.GetProto(templateField)[metadataFieldKey] = ObjectField.MakeCopy(templateFieldValue);
}
+ if (templateField.type === DocumentType.IMG) {
+ // bcz: should be a better way .. but, if the image is a template, then we can't expect to know the aspect ratio. When the image is replaced by data and rendered, we want to recomputed the native dimensions.
+ templateField[DocData].layout_resetNativeDim = true;
+ }
// get the layout string that the template uses to specify its layout
const templateFieldLayoutString = StrCast(Doc.LayoutField(templateField[DocLayout]));
@@ -1184,13 +1189,15 @@ export namespace Doc {
return Doc.NativeWidth(doc, dataDoc, useDim) / (Doc.NativeHeight(doc, dataDoc, useDim) || 1);
}
export function NativeWidth(doc?: Doc, dataDoc?: Doc, useWidth?: boolean) {
- return !doc ? 0 : NumCast(doc._nativeWidth, NumCast((dataDoc || doc)[Doc.LayoutDataKey(doc) + '_nativeWidth'], useWidth ? NumCast(doc._width) : 0));
+ // if this is a field template, then don't use the doc's nativeWidth/height
+ return !doc ? 0 : NumCast(doc.isTemplateForField ? undefined : doc._nativeWidth, NumCast((dataDoc || doc)[Doc.LayoutDataKey(doc) + '_nativeWidth'], !doc.isTemplateForField && useWidth ? NumCast(doc._width) : 0));
}
export function NativeHeight(doc?: Doc, dataDoc?: Doc, useHeight?: boolean) {
if (!doc) return 0;
const nheight = (Doc.NativeWidth(doc, dataDoc, useHeight) / NumCast(doc._width)) * NumCast(doc._height); // divide before multiply to avoid floating point errrorin case nativewidth = width
const dheight = NumCast((dataDoc || doc)[Doc.LayoutDataKey(doc) + '_nativeHeight'], useHeight ? NumCast(doc._height) : 0);
- return NumCast(doc._nativeHeight, nheight || dheight);
+ // if this is a field template, then don't use the doc's nativeWidth/height
+ return NumCast(doc.isTemplateForField ? undefined : doc._nativeHeight, nheight || dheight);
}
export function OutpaintingWidth(doc?: Doc, dataDoc?: Doc, useWidth?: boolean) {
@@ -1504,7 +1511,13 @@ export namespace Doc {
case DocumentType.RTF: return RTFCast(tdoc[Doc.LayoutDataKey(tdoc)])?.Text ?? StrCast(tdoc[Doc.LayoutDataKey(tdoc)]);
default: return StrCast(tdoc.title).startsWith("Untitled") ? "" : StrCast(tdoc.title);
}}); // prettier-ignore
- return docText(doc).then(text => (doc['$' + Doc.LayoutDataKey(doc) + '_description'] = text));
+ return docText(doc).then(
+ action(text => {
+ // set the time when the date changes. This also allows a live textbox view to react to the update, otherwise, it wouldn't take effect until the next time the view is rerendered.
+ doc['$' + Doc.LayoutDataKey(doc) + '_description_modificationDate'] = new DateField();
+ return (doc['$' + Doc.LayoutDataKey(doc) + '_description'] = text);
+ })
+ );
}
// prettier-ignore
@@ -1820,3 +1833,7 @@ ScriptingGlobals.add(function setDocRangeFilter(container: Doc, key: string, ran
ScriptingGlobals.add(function toJavascriptString(str: string) {
return Field.toJavascriptString(str as FieldType);
});
+// eslint-disable-next-line prefer-arrow-callback
+ScriptingGlobals.add(function getDescription(doc: Doc) {
+ return Doc.getDescription(doc);
+});