aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/formattedText/RichTextSchema.tsx
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-04-29 13:48:13 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-04-29 13:48:13 -0400
commitd66aaffc27405f4231a29cd6edda3477077ae946 (patch)
treed7cade1077124e8a115f54713fc61812fd4d7e18 /src/client/views/nodes/formattedText/RichTextSchema.tsx
parenta5b7e73784e3f03ca7677f1d1f00b9943b40f0ec (diff)
fixes for text layout strings.
Diffstat (limited to 'src/client/views/nodes/formattedText/RichTextSchema.tsx')
-rw-r--r--src/client/views/nodes/formattedText/RichTextSchema.tsx181
1 files changed, 0 insertions, 181 deletions
diff --git a/src/client/views/nodes/formattedText/RichTextSchema.tsx b/src/client/views/nodes/formattedText/RichTextSchema.tsx
index 33caf5751..cdb7374f8 100644
--- a/src/client/views/nodes/formattedText/RichTextSchema.tsx
+++ b/src/client/views/nodes/formattedText/RichTextSchema.tsx
@@ -342,187 +342,6 @@ export class DashDocView {
}
}
-export class DashFieldView {
- _fieldWrapper: HTMLDivElement; // container for label and value
- _labelSpan: HTMLSpanElement; // field label
- _fieldSpan: HTMLSpanElement; // field value
- _fieldCheck: HTMLInputElement;
- _enumerables: HTMLDivElement; // field value
- _reactionDisposer: IReactionDisposer | undefined;
- _textBoxDoc: Doc;
- @observable _dashDoc: Doc | undefined;
- _fieldKey: string;
- _options: Doc[] = [];
-
- constructor(node: any, view: any, getPos: any, tbox: FormattedTextBox) {
- this._fieldKey = node.attrs.fieldKey;
- this._textBoxDoc = tbox.props.Document;
- this._fieldWrapper = document.createElement("p");
- this._fieldWrapper.style.width = node.attrs.width;
- this._fieldWrapper.style.height = node.attrs.height;
- this._fieldWrapper.style.fontWeight = "bold";
- this._fieldWrapper.style.position = "relative";
- this._fieldWrapper.style.display = "inline-block";
-
- const self = this;
-
- this._enumerables = document.createElement("div");
- this._enumerables.style.width = "10px";
- this._enumerables.style.height = "10px";
- this._enumerables.style.position = "relative";
- this._enumerables.style.display = "none";
-
- //Moved
- this._enumerables.onpointerdown = async (e) => {
- e.stopPropagation();
- const collview = await Doc.addFieldEnumerations(self._textBoxDoc, self._fieldKey, [{ title: self._fieldSpan.innerText }]);
- collview instanceof Doc && tbox.props.addDocTab(collview, "onRight");
- };
- //Moved
- const updateText = (forceMatch: boolean) => {
- self._enumerables.style.display = "none";
- const newText = self._fieldSpan.innerText.startsWith(":=") || self._fieldSpan.innerText.startsWith("=:=") ? ":=-computed-" : self._fieldSpan.innerText;
-
- // 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 => {
- let modText = "";
- (options instanceof Doc) && DocListCast(options.data).forEach(opt => (forceMatch ? StrCast(opt.title).startsWith(newText) : StrCast(opt.title) === newText) && (modText = StrCast(opt.title)));
- if (modText) {
- self._fieldSpan.innerHTML = self._dashDoc![self._fieldKey] = modText;
- Doc.addFieldEnumerations(self._textBoxDoc, self._fieldKey, []);
- } // if the text starts with a ':=' then treat it as an expression by making a computed field from its value storing it in the key
- else if (self._fieldSpan.innerText.startsWith(":=")) {
- self._dashDoc![self._fieldKey] = ComputedField.MakeFunction(self._fieldSpan.innerText.substring(2));
- } else if (self._fieldSpan.innerText.startsWith("=:=")) {
- Doc.Layout(tbox.props.Document)[self._fieldKey] = ComputedField.MakeFunction(self._fieldSpan.innerText.substring(3));
- } else {
- self._dashDoc![self._fieldKey] = newText;
- }
- });
- };
-
- //Moved
- this._fieldCheck = document.createElement("input");
- this._fieldCheck.id = Utils.GenerateGuid();
- this._fieldCheck.type = "checkbox";
- this._fieldCheck.style.position = "relative";
- this._fieldCheck.style.display = "none";
- this._fieldCheck.style.minWidth = "12px";
- this._fieldCheck.style.backgroundColor = "rgba(155, 155, 155, 0.24)";
- this._fieldCheck.onchange = function (e: any) {
- self._dashDoc![self._fieldKey] = e.target.checked;
- };
-
- this._fieldSpan = document.createElement("span");
- this._fieldSpan.id = Utils.GenerateGuid();
- this._fieldSpan.contentEditable = "true";
- this._fieldSpan.style.position = "relative";
- this._fieldSpan.style.display = "none";
- this._fieldSpan.style.minWidth = "12px";
- this._fieldSpan.style.fontSize = "large";
- this._fieldSpan.onkeypress = function (e: any) { e.stopPropagation(); };
- this._fieldSpan.onkeyup = function (e: any) { e.stopPropagation(); };
- this._fieldSpan.onmousedown = function (e: any) { e.stopPropagation(); self._enumerables.style.display = "inline-block"; };
- this._fieldSpan.onblur = function (e: any) { updateText(false); };
-
- // MOVED
- const setDashDoc = (doc: Doc) => {
- self._dashDoc = doc;
- if (self._options?.length && !self._dashDoc[self._fieldKey]) {
- self._dashDoc[self._fieldKey] = StrCast(self._options[0].title);
- }
- 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";
- this._fieldSpan.style.display = !(fieldVal === true || fieldVal === false) ? StrCast(this._dashDoc?.[self._fieldKey]) ? "" : "inline-block" : "none";
- };
-
- //Moved
- this._fieldSpan.onkeydown = function (e: any) {
- e.stopPropagation();
- if ((e.key === "a" && e.ctrlKey) || (e.key === "a" && e.metaKey)) {
- if (window.getSelection) {
- const range = document.createRange();
- range.selectNodeContents(self._fieldSpan);
- window.getSelection()!.removeAllRanges();
- window.getSelection()!.addRange(range);
- }
- e.preventDefault();
- }
- if (e.key === "Enter") {
- e.preventDefault();
- e.ctrlKey && Doc.addFieldEnumerations(self._textBoxDoc, self._fieldKey, [{ title: self._fieldSpan.innerText }]);
- updateText(true);
- }
- };
-
- this._labelSpan = document.createElement("span");
- this._labelSpan.style.position = "relative";
- this._labelSpan.style.fontSize = "small";
- this._labelSpan.title = "click to see related tags";
- this._labelSpan.style.fontSize = "x-small";
- this._labelSpan.onpointerdown = function (e: any) {
- e.stopPropagation();
- let container = tbox.props.ContainingCollectionView;
- while (container?.props.Document.isTemplateForField || container?.props.Document.isTemplateDoc) {
- container = container.props.ContainingCollectionView;
- }
- if (container) {
- const alias = Doc.MakeAlias(container.props.Document);
- alias.viewType = CollectionViewType.Time;
- let list = Cast(alias.schemaColumns, listSpec(SchemaHeaderField));
- if (!list) {
- alias.schemaColumns = list = new List<SchemaHeaderField>();
- }
- list.map(c => c.heading).indexOf(self._fieldKey) === -1 && list.push(new SchemaHeaderField(self._fieldKey, "#f1efeb"));
- list.map(c => c.heading).indexOf("text") === -1 && list.push(new SchemaHeaderField("text", "#f1efeb"));
- alias._pivotField = self._fieldKey;
- tbox.props.addDocTab(alias, "onRight");
- }
- };
- this._labelSpan.innerHTML = `${self._fieldKey}: `;
- //MOVED
- if (node.attrs.docid) {
- DocServer.GetRefField(node.attrs.docid).
- then(async dashDoc => dashDoc instanceof Doc && runInAction(() => setDashDoc(dashDoc)));
- } else {
- setDashDoc(tbox.props.DataDoc || tbox.dataDoc);
- }
-
- //Moved
- 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;
- }, fval => {
- const boolVal = Cast(fval, "boolean", null);
- if (boolVal === true || boolVal === false) {
- this._fieldCheck.checked = boolVal;
- } else {
- this._fieldSpan.innerHTML = Field.toString(fval as Field) || "";
- }
- this._fieldCheck.style.display = (boolVal === true || boolVal === false) ? "inline-block" : "none";
- this._fieldSpan.style.display = !(fval === true || fval === false) ? (StrCast(fval) ? "" : "inline-block") : "none";
- }, { fireImmediately: true });
-
- //MOVED IN ORDER
- this._fieldWrapper.appendChild(this._labelSpan);
- this._fieldWrapper.appendChild(this._fieldCheck);
- this._fieldWrapper.appendChild(this._fieldSpan);
- this._fieldWrapper.appendChild(this._enumerables);
- (this as any).dom = this._fieldWrapper;
- //updateText(false);
- }
- //MOVED
- destroy() {
- this._reactionDisposer?.();
- }
- //moved
- selectNode() { }
-}
-
export class FootnoteView {
innerView: any;
outerView: any;