aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionSchema/SchemaCellField.tsx
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-20 17:50:00 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-06-20 17:50:00 -0400
commit83a2f119bf908d07e08ac89171e73d2211e1eb8f (patch)
tree91e26934cf95a47b69f2e1b03406edc4bf99e99e /src/client/views/collections/collectionSchema/SchemaCellField.tsx
parent20128eb11d5146e9f199d04a94ca9a6b5ac109d7 (diff)
eq highlight working 70%
Diffstat (limited to 'src/client/views/collections/collectionSchema/SchemaCellField.tsx')
-rw-r--r--src/client/views/collections/collectionSchema/SchemaCellField.tsx35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/client/views/collections/collectionSchema/SchemaCellField.tsx b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
index 4ba8c8469..6663fb68f 100644
--- a/src/client/views/collections/collectionSchema/SchemaCellField.tsx
+++ b/src/client/views/collections/collectionSchema/SchemaCellField.tsx
@@ -6,12 +6,15 @@ import { DocumentIconContainer } from "../../nodes/DocumentIcon";
import React, { FormEvent } from "react";
import { FieldView, FieldViewProps } from "../../nodes/FieldView";
import { ObjectField } from "../../../../fields/ObjectField";
+import { Doc } from "../../../../fields/Doc";
+import { DocumentView } from "../../nodes/DocumentView";
export interface SchemaCellFieldProps {
contents: any;
fieldContents?: FieldViewProps;
editing?: boolean;
oneLine?: boolean;
+ Document: Doc;
highlightCells?: (text: string) => void;
GetValue(): string | undefined;
SetValue(value: string, shiftDown?: boolean, enterKey?: boolean): boolean;
@@ -33,7 +36,11 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
makeObservable(this);
}
+ get docIndex(){return DocumentView.getDocViewIndex(this._props.Document);} // prettier-ignore
+
componentDidMount(): void {
+ this._content = this.props.GetValue() ?? '';
+ this.setContent(this._content);
this._disposers.editing = reaction(
() => this._editing,
editing => {
@@ -43,6 +50,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
this._overlayDisposer?.();
this._overlayDisposer = OverlayView.Instance.addElement(<DocumentIconContainer />, { x: 0, y: 0 });
this._props.highlightCells?.(this._props.GetValue() ?? '');
+ this.setContent(this._content);
}
});
} else {
@@ -53,8 +61,6 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
},
{ fireImmediately: true }
);
- this._content = this.props.GetValue() ?? '';
- this.setContent(this._content);
}
componentDidUpdate(prevProps: Readonly<SchemaCellFieldProps>) {
@@ -74,13 +80,24 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
}
chunkContent = (content: string) => {
- const matches = this._props.func(content, true);
+ const pattern = /(this|d(\d+))\.(\w+)/g;
+ interface Match { docRef: string; field: string; }
+
+ const matches: Match[] = [];
+ let match: RegExpExecArray | null;
+
+ while ((match = pattern.exec(content)) !== null) {
+ const docRef = match[1] === 'this' ? match[1] : match[2];
+ matches.push({ docRef, field: match[3] });
+ }
+
const cells = this._props.func(content, false);
let chunkedText = content;
let matchNum = 0;
- matches.forEach((docRef, field) => {
- console.log('cell: ' + cells[matchNum] + ' border: ' + cells[matchNum].style.borderTop)
- chunkedText = chunkedText.replace(`d5.type`, `<span style="color: ${cells[matchNum].style.borderTop.replace('2px solid', '')}">d5.type</span>`);
+ matches.forEach((match: Match) => {
+ const {docRef, field} = match;
+ // const refToUse = docRef === 'this' ? `${this.docIndex}` : docRef;
+ chunkedText = chunkedText.replace(`d${docRef}.${field}`, `<span style="color: ${cells[matchNum].style.borderTop.replace('2px solid', '')}">d${docRef}.${field}</span>`);
++matchNum;
})
return chunkedText;
@@ -88,9 +105,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
@action
setContent = (content: string) => {
- console.log(this.chunkContent(content));
this._displayedContent = this.chunkContent(content);
- console.log('displayed: ' + this._displayedContent);
}
@action
@@ -157,11 +172,11 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
this._overlayDisposer = OverlayView.Instance.addElement(<DocumentIconContainer />, { x: 0, y: 0 });
}
this._content = targVal;
+ this._props.highlightCells?.(targVal);
if (this._props.func(targVal, true).length > this._props.func(prevVal, true).length) {
this.setContent(targVal);
setTimeout(() => this.restoreCursorPosition(cursorPos), 0);
}
- this._props.highlightCells?.(targVal);
};
@action
@@ -245,7 +260,7 @@ export class SchemaCellField extends ObservableReactComponent<SchemaCellFieldPro
onPointerDown={e => e.stopPropagation}
onClick={e => e.stopPropagation}
onPointerUp={e => e.stopPropagation}
- dangerouslySetInnerHTML={{ __html: `<span>${this._displayedContent}</span>` }}
+ dangerouslySetInnerHTML={{ __html: this._displayedContent }}
>
</div>
);