aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/KeyValueBox.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-03-24 16:29:32 -0400
committerbobzel <zzzman@gmail.com>2025-03-24 16:29:32 -0400
commit858f5d2f1621695a703b0e3f8297521c3ebe692d (patch)
tree3180f91ee18bf8accef98cbbb6db6688666e8340 /src/client/views/nodes/KeyValueBox.tsx
parent9c5d14fdd562dc1bcc8aa0f73ce7ad189c9fbf23 (diff)
parentb6cf21b5a52184f89909898d292a79c57c043d7e (diff)
Merge branch 'fieldSyntaxUpdate' into aarav_edit
Diffstat (limited to 'src/client/views/nodes/KeyValueBox.tsx')
-rw-r--r--src/client/views/nodes/KeyValueBox.tsx36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx
index 40c687b7e..8911fac6d 100644
--- a/src/client/views/nodes/KeyValueBox.tsx
+++ b/src/client/views/nodes/KeyValueBox.tsx
@@ -54,16 +54,12 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
@observable private rows: KeyValuePair[] = [];
@observable _splitPercentage = 50;
- get fieldDocToLayout() {
- return DocCast(this.Document);
- }
-
@action
onEnterKey = (e: React.KeyboardEvent): void => {
if (e.key === 'Enter') {
e.stopPropagation();
- if (this._keyInput.current?.value && this._valInput.current?.value && this.fieldDocToLayout) {
- if (KeyValueBox.SetField(this.fieldDocToLayout, this._keyInput.current.value, this._valInput.current.value)) {
+ if (this._keyInput.current?.value && this._valInput.current?.value && this.Document) {
+ if (KeyValueBox.SetField(this.Document, this._keyInput.current.value, this._valInput.current.value)) {
this._keyInput.current.value = '';
this._valInput.current.value = '';
document.body.focus();
@@ -109,12 +105,12 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
if (setResult) setResult?.(value);
else target[key] = field;
};
- const res = script.run({ this: Doc.Layout(doc), _setCacheResult_ }, console.log);
+ const res = script.run({ this: doc, _setCacheResult_ }, console.log);
if (!res.success) {
if (key) target[key] = script.originalScript;
return false;
}
- field === undefined && (field = res.result instanceof Array ? new List<FieldType>(res.result) : (typeof res.result === 'function' ? res.result.name : res.result as FieldType));
+ field === undefined && (field = res.result instanceof Array ? new List<FieldType>(res.result) : typeof res.result === 'function' ? res.result.name : (res.result as FieldType));
}
}
if (!key) return false;
@@ -141,7 +137,7 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
rowHeight = () => 30;
@computed get createTable() {
- const doc = this.fieldDocToLayout;
+ const doc = this.Document;
if (!doc) {
return (
<tr>
@@ -149,25 +145,35 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
</tr>
);
}
- const realDoc = doc;
const ids: { [key: string]: string } = {};
const protos = Doc.GetAllPrototypes(doc);
protos.forEach(proto => {
Object.keys(proto).forEach(key => {
- if (!(key in ids) && realDoc[key] !== ComputedField.undefined) {
+ if (!(key in ids) && doc[key] !== ComputedField.undefined) {
ids[key] = key;
}
});
});
+ const layoutProtos = Doc.GetAllPrototypes(this.layoutDoc);
+ layoutProtos.forEach(proto => {
+ Object.keys(proto)
+ .map(key => '_' + key)
+ .forEach(key => {
+ if (!(key.replace(/^_/, '') in ids) && doc[key] !== ComputedField.undefined) {
+ ids[key] = key;
+ }
+ });
+ });
+
const rows: JSX.Element[] = [];
let i = 0;
const keys = Object.keys(ids).slice();
// for (const key of [...keys.filter(id => id !== 'layout' && !id.includes('_')).sort(), ...keys.filter(id => id === 'layout' || id.includes('_')).sort()]) {
const sortedKeys = keys.sort((a: string, b: string) => {
- const a_ = a.split('_')[0];
- const b_ = b.split('_')[0];
+ const a_ = a.replace(/^_/, '').split('_')[0];
+ const b_ = b.replace(/^_/, '').split('_')[0];
if (a_ < b_) return -1;
if (a_ > b_) return 1;
if (a === a_) return -1;
@@ -177,7 +183,7 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
sortedKeys.forEach(key => {
rows.push(
<KeyValuePair
- doc={realDoc}
+ doc={doc}
addDocTab={this._props.addDocTab}
PanelWidth={this._props.PanelWidth}
PanelHeight={this.rowHeight}
@@ -300,7 +306,7 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
description: 'Default Perspective',
event: () => {
this._props.addDocTab(this.Document, OpenWhere.close);
- this._props.addDocTab(this.fieldDocToLayout, OpenWhere.addRight);
+ this._props.addDocTab(this.Document, OpenWhere.addRight);
},
icon: 'image',
});