aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/documents/Documents.ts6
-rw-r--r--src/client/util/Scripting.ts9
-rw-r--r--src/client/views/collections/collectionSchema/CollectionSchemaView.scss1
-rw-r--r--src/client/views/collections/collectionSchema/SchemaCellField.tsx4
-rw-r--r--src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx6
-rw-r--r--src/client/views/collections/collectionSchema/SchemaRowBox.tsx6
-rw-r--r--src/client/views/collections/collectionSchema/SchemaTableCell.tsx26
-rw-r--r--src/client/views/nodes/FieldView.tsx2
-rw-r--r--src/client/views/nodes/KeyValueBox.tsx2
9 files changed, 43 insertions, 19 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index dabbf9591..1b1608cd5 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -143,7 +143,12 @@ class ListInfo extends FInfo {
fieldType? = FInfoFieldType.list;
values?: List<any>[] = [];
}
+class MapInfo extends FInfo {
+ fieldType? = FInfoFieldType.list;
+ values?: List<any>[] = [];
+}
type BOOLt = BoolInfo | boolean;
+type MAPt = MapInfo | Map<any, any>;
type NUMt = NumInfo | number;
type STRt = StrInfo | string;
type LISTt = ListInfo | List<any>;
@@ -229,6 +234,7 @@ export class DocumentOptions {
_lockedTransform?: BOOLt = new BoolInfo('lock the freeform_panx,freeform_pany and scale parameters of the document so that it be panned/zoomed');
_childrenSharedWithSchema?: BOOLt = new BoolInfo("whether this document's children are displayed in its parent schema view", false);
_lockedSchemaEditing?: BOOLt = new BoolInfo("", false);
+ _schemaInputs?: LISTt = new ListInfo('user inputs to schema field', false)
dataViz_title?: string;
dataViz_line?: string;
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 6ef592ef2..c7aa56c1e 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -183,14 +183,19 @@ function forEachNode(node: ts.Node, onEnter: Traverser, onExit?: Traverser, inde
);
}
+ScriptField.CompileScript(value, {}, true, undefined, DocumentIconContainer.getTransformer());
+//addreturn = true
+//capturedvariables = undefined
+//
+
export function CompileScript(script: string, options: ScriptOptions = {}): CompileResult {
- const captured = options.capturedVariables ?? {};
+ const captured = options.capturedVariables ?? {};
const signature = Object.keys(captured).reduce((p, v) => {
const formatCapture = (obj: any) => `${v}=${obj instanceof RefField ? 'XXX' : obj.toString()}`;
if (captured[v] instanceof Array) return p + (captured[v] as any).map(formatCapture);
return p + formatCapture(captured[v]);
}, '');
- const found = ScriptField.GetScriptFieldCache(script + ':' + signature);
+ const found = ScriptField.GetScriptFieldCache(script + ':' + signature); // if already compiled, found is the result; cache set below
if (found) return found as CompiledScript;
const { requiredType = '', addReturn = false, params = {}, capturedVariables = {}, typecheck = true } = options;
if (options.params && !options.params.this) options.params.this = Doc.name;
diff --git a/src/client/views/collections/collectionSchema/CollectionSchemaView.scss b/src/client/views/collections/collectionSchema/CollectionSchemaView.scss
index 6b53eb1cc..425b67fa9 100644
--- a/src/client/views/collections/collectionSchema/CollectionSchemaView.scss
+++ b/src/client/views/collections/collectionSchema/CollectionSchemaView.scss
@@ -155,7 +155,6 @@
padding: 0;
z-index: 1;
border: 1px solid $medium-gray;
- //overflow: hidden;
.schema-column-title {
flex-grow: 2;
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
index 27ca37c2b..c7c483df8 100644
--- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
@@ -321,11 +321,13 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
}
}
+ //<FieldView {...this._props.fieldContents}/>
+
staticDisplay = () => {
return <span className='editableView-static'>
{
// eslint-disable-next-line react/jsx-props-no-spreading
- this._props.fieldContents ? <FieldView {...this._props.fieldContents} /> : this.props.contents ? this._props.contents?.valueOf() : ''
+ this._props.fieldContents ? <FieldView {...this._props.fieldContents}/> : ''
}
</span>
}
diff --git a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
index d16cde1f8..83a136737 100644
--- a/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaColumnHeader.tsx
@@ -237,11 +237,11 @@ export class SchemaColumnHeader extends ObservableReactComponent<SchemaColumnHea
}}>
<div className="schema-column-resizer left" onPointerDown={e => this._props.resizeColumn(e, this._props.columnIndex)} />
- <div>{this.editableView}</div>
+ <div className="schema-header-text">{this.editableView}</div>
<div className="schema-header-menu">
- <div className="schema-header-button">
- {this.displayButton ? this.headerButton : null}
+ <div className="schema-header-button" style={{opacity: this.displayButton ? '1.0' : '0.0'}}>
+ {this.headerButton}
</div>
</div>
</div>
diff --git a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
index c9feeac6b..077d95c57 100644
--- a/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaRowBox.tsx
@@ -97,10 +97,6 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() {
return ''
}
- @computed get refSelectModeInfo() {
- return this.schemaView._referenceSelectMode;
- }
-
@computed get menuInfos() {
const infos: Array<IconProp> = [];
if (this.Document._lockedSchemaEditing) infos.push('lock');
@@ -178,7 +174,7 @@ export class SchemaRowBox extends ViewBoxBaseComponent<SchemaRowBoxProps>() {
{this.schemaView?.columnKeys?.map((key, index) => (
<SchemaTableCell
selectReference={this.selectReference}
- refSelectModeInfo={this.refSelectModeInfo}
+ refSelectModeInfo={this.schemaView._referenceSelectMode}
eqHighlightFunc={this.eqHighlightFunc}
equationHighlightRef={this.schemaView._cellHighlightColors}
highlightCells={this.highlightCells}
diff --git a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
index 016ab5e69..c0e1743a5 100644
--- a/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaTableCell.tsx
@@ -16,7 +16,7 @@ import { DateField } from '../../../../fields/DateField';
import { Doc, DocListCast, Field, IdToDoc } from '../../../../fields/Doc';
import { RichTextField } from '../../../../fields/RichTextField';
import { ColumnType } from '../../../../fields/SchemaHeaderField';
-import { BoolCast, Cast, DateCast, DocCast, FieldValue, StrCast, toList } from '../../../../fields/Types';
+import { BoolCast, Cast, DateCast, DocCast, FieldValue, ScriptCast, StrCast, toList } from '../../../../fields/Types';
import { ImageField } from '../../../../fields/URLField';
import { FInfo, FInfoFieldType } from '../../../documents/Documents';
import { dropActionType } from '../../../util/DropActionTypes';
@@ -35,6 +35,7 @@ import './CollectionSchemaView.scss';
import { SchemaColumnHeader } from './SchemaColumnHeader';
import { ContextMenu } from '../../ContextMenu';
import { SchemaCellField } from './SchemaCellField';
+import { ComputedField } from '../../../../fields/ScriptField';
export interface SchemaTableCellProps {
Document: Doc;
@@ -80,6 +81,7 @@ function selectedCell(props: SchemaTableCellProps) {
export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellProps> {
// private _fieldRef: SchemaCellField | null = null;
+ private _submittedValue: string = '';
constructor(props: SchemaTableCellProps) {
super(props);
@@ -157,19 +159,31 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
// parses a field from the "idToDoc(####)" format to DocumentId (d#) format for readability
cleanupField = (field: string) => {
- const idPattern = /idToDoc\((.*?)\)/g;
let modField = field.slice();
+ let eqSymbol: string = '';
+ if (modField.startsWith('=')) {modField = modField.substring(1); eqSymbol += '=';}
+ if (modField.startsWith(':=')) {modField = modField.substring(2); eqSymbol += ':=';}
+
+ const idPattern = /idToDoc\((.*?)\)/g;
let matches;
let results = new Array<[id: string, func: string]>();
while ((matches = idPattern.exec(field)) !== null) {results.push([matches[0], matches[1].replace(/"/g, '')]); }
results.forEach((idFuncPair) => {modField = modField.replace(idFuncPair[0], 'd' + (DocumentView.getDocViewIndex(IdToDoc(idFuncPair[1]))).toString());})
- if (modField.charAt(modField.length - 1) === ';') modField = modField.substring(0, modField.length - 1);
+
+ for (let i = 0; i < modField.length; ++i){
+
+ }
+
+ if (modField.endsWith(';')) modField = modField.substring(0, modField.length - 1);
+
+ const inQuotes = (field: string) => {return ((field.startsWith('`') && field.endsWith('`')) || (field.startsWith("'") && field.endsWith("'")) || (field.startsWith('"') && field.endsWith('"')))}
+ if (!inQuotes(this._submittedValue) && inQuotes(modField)) modField = modField.substring(1, modField.length - 1);
const selfRefPattern = `d${this.docIndex}.${this._props.fieldKey}`
const selfRefRegX = RegExp(selfRefPattern, 'g');
if (selfRefRegX.exec(modField) !== null) { return 'Invalid'}
- return modField;
+ return eqSymbol + modField;
}
@computed get defaultCellContent() {
@@ -196,7 +210,8 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
contents={undefined}
fieldContents={fieldProps}
editing={selectedCell(this._props) ? undefined : false}
- GetValue={() => this.cleanupField(Field.toKeyValueString(fieldProps.Document, this._props.fieldKey, SnappingManager.MetaKey))}
+ ////const script = ScriptCast(fieldProps.Document[this._props.fieldKey]).rawscript;
+ GetValue={() => ScriptCast(fieldProps.Document[this._props.fieldKey])?.rawscript ?? ''}
SetValue={undoable((value: string, shiftDown?: boolean, enterKey?: boolean) => {
if (shiftDown && enterKey) {
this._props.setColumnValues(this._props.fieldKey.replace(/^_/, ''), value);
@@ -205,6 +220,7 @@ export class SchemaTableCell extends ObservableReactComponent<SchemaTableCellPro
}
const hasNoLayout = Doc.IsDataProto(fieldProps.Document) ? true : undefined; // the "delegate" is a a data document so never write to it's proto
const ret = Doc.SetField(fieldProps.Document, this._props.fieldKey.replace(/^_/, ''), value, hasNoLayout);
+ this._submittedValue = value;
this._props.finishEdit?.();
return ret;
}, 'edit schema cell')}
diff --git a/src/client/views/nodes/FieldView.tsx b/src/client/views/nodes/FieldView.tsx
index 818d26956..40da661c0 100644
--- a/src/client/views/nodes/FieldView.tsx
+++ b/src/client/views/nodes/FieldView.tsx
@@ -118,7 +118,7 @@ export class FieldView extends React.Component<FieldViewProps> {
const field = this.fieldval;
// prettier-ignore
if (field instanceof Doc) return <p> <b>{field.title?.toString()}</b></p>;
- if (field === undefined) return <p>{'<null>'}</p>;
+ if (field === undefined) return <p>{''}</p>;
if (field instanceof DateField) return <p>{field.date.toLocaleString()}</p>;
if (field instanceof List) return <div> {field.map(f => Field.toString(f)).join(', ')} </div>;
if (field instanceof WebField) return <p>{Field.toString(field.url.href)}</p>;
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx
index 66e210c03..bc6633f23 100644
--- a/src/client/views/nodes/KeyValueBox.tsx
+++ b/src/client/views/nodes/KeyValueBox.tsx
@@ -88,7 +88,7 @@ export class KeyValueBox extends ViewBoxBaseComponent<FieldViewProps>() {
const type: 'computed' | 'script' | false = rawvalue.startsWith(':=') ? 'computed' : rawvalue.startsWith('$=') ? 'script' : false;
rawvalue = type ? rawvalue.substring(2) : rawvalue;
rawvalue = rawvalue.replace(/.*\(\((.*)\)\)/, 'dashCallChat(_setCacheResult_, this, `$1`)');
- const value = ["'", '"', '`'].includes(rawvalue.length ? rawvalue[0] : '') || !isNaN(rawvalue as any) ? rawvalue : '`' + rawvalue + '`';
+ const value = (["'", '"', '`'].includes(rawvalue.length ? rawvalue[0] : '') || !isNaN(rawvalue as any)) ? rawvalue : '`' + rawvalue + '`';
let script = ScriptField.CompileScript(rawvalue, {}, true, undefined, DocumentIconContainer.getTransformer());
if (!script.compiled) {