diff options
-rw-r--r-- | src/client/util/RichTextSchema.tsx | 13 | ||||
-rw-r--r-- | src/new_fields/Doc.ts | 4 | ||||
-rw-r--r-- | src/new_fields/util.ts | 2 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/client/util/RichTextSchema.tsx b/src/client/util/RichTextSchema.tsx index 29fd28994..69296d8bc 100644 --- a/src/client/util/RichTextSchema.tsx +++ b/src/client/util/RichTextSchema.tsx @@ -799,7 +799,9 @@ export class DashDocView { doRender(dashDoc: Doc, removeDoc: any, node: any, view: any, getPos: any) { this._dashDoc = dashDoc; const self = this; - const finalLayout = this._textBox.props.Document instanceof Doc && (Doc.expandTemplateLayout(dashDoc, !Doc.AreProtosEqual(this._textBox.dataDoc, this._textBox.props.Document) ? this._textBox.dataDoc : undefined)); + const dashLayoutDoc = Doc.Layout(dashDoc); + const finalLayout = this._textBox.props.Document instanceof Doc && (Doc.expandTemplateLayout(dashLayoutDoc, + dashLayoutDoc !== dashDoc || !Doc.AreProtosEqual(this._textBox.dataDoc, this._textBox.props.Document) ? this._textBox.dataDoc : undefined, node.attrs.fieldKey)); if (!finalLayout) setTimeout(() => self.doRender(dashDoc, removeDoc, node, view, getPos), 0); else { const layoutKey = StrCast(finalLayout.layoutKey); @@ -929,7 +931,8 @@ export class DashFieldView { // look for a document whose id === the fieldKey being displayed. If there's a match, then that document // holds the different enumerated values for the field in the titles of its collected documents. // if there's a partial match from the start of the input text, complete the text --- TODO: make this an auto suggest box and select from a drop down. - DocServer.GetRefField(self._fieldKey).then(options => self._dashDoc![self._fieldKey] = e.target.checked); + const checked = e.target.checked; + DocServer.GetRefField(self._fieldKey).then(options => self._dashDoc![self._fieldKey] = checked); } @@ -952,7 +955,7 @@ export class DashFieldView { } const layout = tbox.props.Document; // NOTE: if the field key starts with "@", then the actual field key is stored in the "@"fieldKey. Dereferencing these fields happens in ImageBox and RichTextSchema - self._fieldKey = self._fieldKey.startsWith("@") ? StrCast(layout[StrCast(self._fieldKey)]) : self._fieldKey; + self._fieldKey = self._fieldKey.startsWith("@") ? StrCast(layout[StrCast(self._fieldKey).substring(1)]) : self._fieldKey; this._labelSpan.innerHTML = `${self._fieldKey}: `; const fieldVal = Cast(this._dashDoc?.[self._fieldKey], "boolean", null); this._fieldCheck.style.display = (fieldVal === true || fieldVal === false) ? "inline-block" : "none"; @@ -1010,7 +1013,7 @@ export class DashFieldView { this._reactionDisposer?.(); this._reactionDisposer = reaction(() => { // this reaction will update the displayed text whenever the document's fieldKey's value changes const dashVal = this._dashDoc?.[self._fieldKey]; - return StrCast(dashVal).startsWith(":=") || !dashVal ? Doc.Layout(tbox.props.Document)[self._fieldKey] : dashVal; + return StrCast(dashVal).startsWith(":=") || dashVal === "" ? Doc.Layout(tbox.props.Document)[self._fieldKey] : dashVal; }, fval => { const boolVal = Cast(fval, "boolean", null); if (boolVal === true || boolVal === false) { @@ -1018,6 +1021,8 @@ export class DashFieldView { } else { this._fieldSpan.innerHTML = Field.toString(fval as Field) || ""; } + this._fieldCheck.style.display = (boolVal === true || boolVal === false) ? "inline-block" : "none"; + this._fieldSpan.style.display = !(boolVal === true || boolVal === false) ? "inline-block" : "none"; }, { fireImmediately: true }); this._fieldWrapper.appendChild(this._labelSpan); diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index e84ddc684..219877f74 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -487,7 +487,7 @@ export namespace Doc { setTimeout(action(() => { if (!targetDoc[expandedLayoutFieldKey]) { const newLayoutDoc = Doc.MakeDelegate(templateLayoutDoc, undefined, "[" + templateLayoutDoc.title + "]"); - newLayoutDoc["@params"] = params; + newLayoutDoc["params"] = params; newLayoutDoc.expandedTemplate = targetDoc; // the template's parameters are stored in params which are derefenced to find // the actual field key where the template data is stored. Currently this is only used in RichTextSchema's docView @@ -512,7 +512,7 @@ export namespace Doc { } const existingResolvedDataDoc = childDoc[DataSym] !== Doc.GetProto(childDoc)[DataSym] && childDoc[DataSym]; const resolvedDataDoc = existingResolvedDataDoc || (Doc.AreProtosEqual(containerDataDoc, containerDoc) || !containerDataDoc || (!childDoc.isTemplateDoc && !childDoc.isTemplateForField) ? undefined : containerDataDoc); - return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc, "(" + StrCast(containerDoc["@params"]) + ")"), data: resolvedDataDoc }; + return { layout: Doc.expandTemplateLayout(childDoc, resolvedDataDoc, "(" + StrCast(containerDoc["params"]) + ")"), data: resolvedDataDoc }; } export function Overwrite(doc: Doc, overwrite: Doc, copyProto: boolean = false): Doc { diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts index 0b98be953..080123965 100644 --- a/src/new_fields/util.ts +++ b/src/new_fields/util.ts @@ -128,7 +128,7 @@ export function getter(target: any, in_prop: string | symbol | number, receiver: } if (target.__LAYOUT__) return target.__LAYOUT__[prop]; } - if (typeof prop === "string" && prop.startsWith("@@")) { + if (typeof prop === "string" && prop.startsWith("@")) { const expanded = target.__fields["expandedTemplate"]; if (expanded) return expanded.cache[target.__fields[prop.substring(1)]]; } |