diff options
| author | bobzel <zzzman@gmail.com> | 2025-03-27 12:12:20 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2025-03-27 12:12:20 -0400 |
| commit | b1f85154edc250a18d0bc033df91ee1249975946 (patch) | |
| tree | 1a96d9d48ef82e39acedbb92c0b68cf2c418f12a /src/client/views/nodes/KeyValueBox.tsx | |
| parent | 64f65dd17f9dea4e0cee17600d2b0daa847bab73 (diff) | |
fix so that schemacellfield doesn't trigger a finalizeEdit when it's not editing. added 'red' color for template fields to schematablecell. fixed set field to allow setting data fields when field is an '_' and no template. fixed setting '=' when getting a keyValueString for empty fields with an '_' key.
Diffstat (limited to 'src/client/views/nodes/KeyValueBox.tsx')
| -rw-r--r-- | src/client/views/nodes/KeyValueBox.tsx | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx index b54004697..bb711a5fc 100644 --- a/src/client/views/nodes/KeyValueBox.tsx +++ b/src/client/views/nodes/KeyValueBox.tsx @@ -91,10 +91,11 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() { return !script.compiled ? undefined : { script, type, onDelegate }; }; - public static ApplyKVPScript = (doc: Doc, key: string, kvpScript: KVPScript, forceOnDelegate?: boolean, setResult?: (value: FieldResult) => void) => { + public static ApplyKVPScript = (doc: Doc, keyIn: string, kvpScript: KVPScript, forceOnDelegate?: boolean, setResult?: (value: FieldResult) => void) => { const { script, type, onDelegate } = kvpScript; - // const target = onDelegate ? Doc.Layout(doc.layout) : Doc.GetProto(doc); // bcz: TODO need to be able to set fields on layout templates - const target = forceOnDelegate || onDelegate || key.startsWith('_') ? doc : DocCast(doc.proto, doc); + const chooseDelegate = forceOnDelegate || onDelegate || keyIn.startsWith('_'); + const key = chooseDelegate && keyIn.startsWith('$') ? keyIn.slice(1) : keyIn; + const target = chooseDelegate ? doc : DocCast(doc.proto, doc); let field: FieldType | undefined; switch (type) { case 'computed': field = new ComputedField(script); break; // prettier-ignore @@ -126,7 +127,10 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() { if (!script) return false; const ldoc = key.startsWith('_') ? Doc.Layout(doc) : doc; const forceOnDelegate = forceOnDelegateIn || (ldoc !== doc && !value.startsWith('=')); - const setKey = value.startsWith('=') ? key.replace(/^_/, '') : key; // an '=' value redirects a key targeting the render template to the root document + // an '=' value redirects a key targeting the render template to the root document. + // also, if ldoc and doc are equal, allow redirecting to data document when not using an equal + // in either case, get rid of initial '_' which forces writing to layout + const setKey = value.startsWith('=') || ldoc === doc ? key.replace(/^_/, '') : key; return KeyValueBox.ApplyKVPScript(doc, setKey, script, forceOnDelegate, setResult); }, 'Set Doc Field'); |
