aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes')
-rw-r--r--src/client/views/nodes/DocumentView.tsx6
-rw-r--r--src/client/views/nodes/EquationBox.tsx10
-rw-r--r--src/client/views/nodes/LabelBox.tsx5
-rw-r--r--src/client/views/nodes/MapBox/MapBox.tsx2
-rw-r--r--src/client/views/nodes/MapBox/MapBoxInfoWindow.tsx2
-rw-r--r--src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx2
-rw-r--r--src/client/views/nodes/formattedText/DailyJournal.tsx25
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx41
8 files changed, 37 insertions, 56 deletions
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 595abc7f8..a514ee04e 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -1110,6 +1110,12 @@ export class DocumentView extends DocComponent<DocumentViewProps>() {
public static DeselectAll: (except?: Doc) => void | undefined;
public static DeselectView: (dv: DocumentView | undefined) => void | undefined;
public static SelectView: (dv: DocumentView | undefined, extendSelection: boolean) => void | undefined;
+
+ public static SelectOnLoad: Doc | undefined;
+ public static SetSelectOnLoad(doc?: Doc) {
+ DocumentView.SelectOnLoad = doc;
+ doc && DocumentView.addViewRenderedCb(doc, dv => dv.select(false));
+ }
/**
* returns a list of all currently selected DocumentViews
*/
diff --git a/src/client/views/nodes/EquationBox.tsx b/src/client/views/nodes/EquationBox.tsx
index 576b5bbe0..dcc6e27ed 100644
--- a/src/client/views/nodes/EquationBox.tsx
+++ b/src/client/views/nodes/EquationBox.tsx
@@ -30,12 +30,12 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
componentDidMount() {
this._props.setContentViewBox?.(this);
- if (Doc.SelectOnLoad === this.Document && (!DocumentView.LightboxDoc() || DocumentView.LightboxContains(this.DocumentView?.()))) {
+ if (DocumentView.SelectOnLoad === this.Document && (!DocumentView.LightboxDoc() || DocumentView.LightboxContains(this.DocumentView?.()))) {
this._props.select(false);
- this._ref.current!.mathField.focus();
- this.dataDoc.text === 'x' && this._ref.current!.mathField.select();
- Doc.SetSelectOnLoad(undefined);
+ this._ref.current?.mathField.focus();
+ this.dataDoc.text === 'x' && this._ref.current?.mathField.select();
+ DocumentView.SetSelectOnLoad(undefined);
}
reaction(
() => this._props.isSelected(),
@@ -66,7 +66,7 @@ export class EquationBox extends ViewBoxBaseComponent<FieldViewProps>() {
color: StrCast(this.Document.color),
fontSize: this.fontSize,
});
- Doc.SetSelectOnLoad(nextEq);
+ DocumentView.SetSelectOnLoad(nextEq);
this._props.addDocument?.(nextEq);
e.stopPropagation();
}
diff --git a/src/client/views/nodes/LabelBox.tsx b/src/client/views/nodes/LabelBox.tsx
index dcf9e1fed..7fb83571f 100644
--- a/src/client/views/nodes/LabelBox.tsx
+++ b/src/client/views/nodes/LabelBox.tsx
@@ -17,6 +17,7 @@ import { FieldView, FieldViewProps } from './FieldView';
import './LabelBox.scss';
import { FormattedTextBox } from './formattedText/FormattedTextBox';
import { RichTextMenu } from './formattedText/RichTextMenu';
+import { DocumentView } from './DocumentView';
@observer
export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
@@ -230,8 +231,8 @@ export class LabelBox extends ViewBoxBaseComponent<FieldViewProps>() {
if (this._divRef) {
this._divRef.addEventListener('beforeinput', this.beforeInput);
- if (Doc.SelectOnLoad === this.Document) {
- Doc.SelectOnLoad = undefined;
+ if (DocumentView.SelectOnLoad === this.Document) {
+ DocumentView.SetSelectOnLoad(undefined);
this._divRef.focus();
}
this.fitTextToBox(this._divRef);
diff --git a/src/client/views/nodes/MapBox/MapBox.tsx b/src/client/views/nodes/MapBox/MapBox.tsx
index 541b41bf7..792cb6b46 100644
--- a/src/client/views/nodes/MapBox/MapBox.tsx
+++ b/src/client/views/nodes/MapBox/MapBox.tsx
@@ -353,7 +353,7 @@ export class MapBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const targetCreator = (annotationOn: Doc | undefined) => {
const target = DocUtils.GetNewTextDoc('Note linked to ' + this.Document.title, 0, 0, 100, 100, annotationOn, 'yellow');
- Doc.SetSelectOnLoad(target);
+ DocumentView.SetSelectOnLoad(target);
return target;
};
const docView = this.DocumentView?.();
diff --git a/src/client/views/nodes/MapBox/MapBoxInfoWindow.tsx b/src/client/views/nodes/MapBox/MapBoxInfoWindow.tsx
index eb0431b85..a27a8bda1 100644
--- a/src/client/views/nodes/MapBox/MapBoxInfoWindow.tsx
+++ b/src/client/views/nodes/MapBox/MapBoxInfoWindow.tsx
@@ -32,7 +32,7 @@
// addNoteClick = (e: React.PointerEvent) => {
// setupMoveUpEvents(this, e, returnFalse, emptyFunction, e => {
// const newDoc = Docs.Create.TextDocument('Note', { _layout_autoHeight: true });
-// Doc.SetSelectOnLoad(newDoc); // track the new text box so we can give it a prop that tells it to focus itself when it's displayed
+// DocumentView.SetSelectOnLoad(newDoc); // track the new text box so we can give it a prop that tells it to focus itself when it's displayed
// Doc.AddDocToList(this.props.place, 'data', newDoc);
// this._stack?.scrollToBottom();
// e.stopPropagation();
diff --git a/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx b/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx
index 95f89a573..0627d382e 100644
--- a/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx
+++ b/src/client/views/nodes/MapboxMapBox/MapboxContainer.tsx
@@ -237,7 +237,7 @@ export class MapBoxContainer extends ViewBoxAnnotatableComponent<FieldViewProps>
const targetCreator = (annotationOn: Doc | undefined) => {
const target = DocUtils.GetNewTextDoc('Note linked to ' + this.Document.title, 0, 0, 100, 100, annotationOn, 'yellow');
- Doc.SetSelectOnLoad(target);
+ DocumentView.SetSelectOnLoad(target);
return target;
};
const docView = this.DocumentView?.();
diff --git a/src/client/views/nodes/formattedText/DailyJournal.tsx b/src/client/views/nodes/formattedText/DailyJournal.tsx
index 9decbfaf0..7999357b0 100644
--- a/src/client/views/nodes/formattedText/DailyJournal.tsx
+++ b/src/client/views/nodes/formattedText/DailyJournal.tsx
@@ -51,22 +51,13 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>()
@action
setDailyText() {
console.log('setDailyText() called...');
- const initialText = `Journal Entry - ${this.journalDate}\n\nStart writing here...`;
+ const placeholderText = 'Start writing here...';
+ const initialText = `Journal Entry - ${this.journalDate}\n${placeholderText}`;
console.log('Checking if dataDoc has text field...');
console.log('Setting new text field with:', initialText);
- this.dataDoc[this.fieldKey] = new RichTextField(
- JSON.stringify({
- doc: {
- type: 'doc',
- content: [{ type: 'paragraph', content: [{ type: 'text', text: initialText }] }],
- },
- selection: { type: 'text', anchor: 1, head: 1 },
- storedMarks: [],
- }),
- initialText
- );
+ this.dataDoc[this.fieldKey] = RichTextField.textToRtf(initialText, undefined, placeholderText.length);
console.log('Current text field:', this.dataDoc[this.fieldKey]);
}
@@ -85,10 +76,11 @@ export class DailyJournal extends ViewBoxAnnotatableComponent<FieldViewProps>()
}
render() {
- return <div style={{ background: 'beige', width: '100%', height: '100%' }}>
- <FormattedTextBox {...this._props} fieldKey={'text'} Document={this.Document} TemplateDataDocument={undefined} />
-
- </div>;
+ return (
+ <div style={{ background: 'beige', width: '100%', height: '100%' }}>
+ <FormattedTextBox {...this._props} fieldKey={'text'} Document={this.Document} TemplateDataDocument={undefined} />
+ </div>
+ );
}
}
@@ -99,6 +91,7 @@ Docs.Prototypes.TemplateMap.set(DocumentType.JOURNAL, {
_height: 35,
_xMargin: 10,
_yMargin: 10,
+ _layout_autoHeight: true,
_layout_nativeDimEditable: true,
_layout_reflowVertical: true,
_layout_reflowHorizontal: true,
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index c2a2caecf..83ee619d0 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -99,7 +99,6 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
public static Init(nodeViews: (self: FormattedTextBox) => { [key: string]: NodeViewConstructor }) { FormattedTextBox._nodeViews = nodeViews; } // prettier-ignore
public static PasteOnLoad: ClipboardEvent | undefined;
- public static DontSelectInitialText = false; // whether initial text should be selected or not
public static SelectOnLoadChar = '';
public static LiveTextUndo: UndoManager.Batch | undefined; // undo batch when typing a new text note into a collection
@@ -286,7 +285,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
e.stopPropagation();
const targetCreator = (annotationOn?: Doc) => {
const target = DocUtils.GetNewTextDoc('Note linked to ' + this.Document.title, 0, 0, 100, 100, annotationOn);
- Doc.SetSelectOnLoad(target);
+ DocumentView.SetSelectOnLoad(target);
return target;
};
@@ -1542,44 +1541,26 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<FormattedTextB
this._editorView.TextView = this;
}
- const selectOnLoad = Doc.AreProtosEqual(this._props.TemplateDataDocument ?? this.Document, Doc.SelectOnLoad) && (!DocumentView.LightboxDoc() || DocumentView.LightboxContains(this.DocumentView?.()));
+ const selectOnLoad = Doc.AreProtosEqual(this._props.TemplateDataDocument ?? this.Document, DocumentView.SelectOnLoad) && (!DocumentView.LightboxDoc() || DocumentView.LightboxContains(this.DocumentView?.()));
const selLoadChar = FormattedTextBox.SelectOnLoadChar;
if (selectOnLoad) {
- Doc.SetSelectOnLoad(undefined);
+ DocumentView.SetSelectOnLoad(undefined);
FormattedTextBox.SelectOnLoadChar = '';
}
if (this.EditorView && selectOnLoad && !this._props.dontRegisterView && !this._props.dontSelectOnLoad && this.isActiveTab(this.ProseRef)) {
- this._props.select(false);
+ const $from = this.EditorView.state.selection.anchor ? this.EditorView.state.doc.resolve(this.EditorView.state.selection.anchor - 1) : undefined;
+ const mark = schema.marks.user_mark.create({ userid: ClientUtils.CurrentUserEmail(), modified: Math.floor(Date.now() / 1000) });
+ const curMarks = this.EditorView.state.storedMarks ?? $from?.marksAcross(this.EditorView.state.selection.$head) ?? [];
+ const storedMarks = [...curMarks.filter(m => m.type !== mark.type), mark];
+ let { tr } = this.EditorView.state;
if (selLoadChar) {
- const $from = this.EditorView.state.selection.anchor ? this.EditorView.state.doc.resolve(this.EditorView.state.selection.anchor - 1) : undefined;
- const mark = schema.marks.user_mark.create({ userid: ClientUtils.CurrentUserEmail(), modified: Math.floor(Date.now() / 1000) });
- const curMarks = this.EditorView.state.storedMarks ?? $from?.marksAcross(this.EditorView.state.selection.$head) ?? [];
- const storedMarks = [...curMarks.filter(m => m.type !== mark.type), mark];
const tr1 = this.EditorView.state.tr.setStoredMarks(storedMarks);
- const tr2 = selLoadChar === 'Enter' ? tr1.insert(this.EditorView.state.doc.content.size - 1, schema.nodes.paragraph.create()) : tr1.insertText(selLoadChar, this.EditorView.state.doc.content.size - 1);
- const tr = tr2.setStoredMarks(storedMarks);
-
- this.EditorView.dispatch(tr.setSelection(new TextSelection(tr.doc.resolve(tr.doc.content.size))));
- this.tryUpdateDoc(true); // calling select() above will make isContentActive() true only after a render .. which means the selectAll() above won't write to the Document and the incomingValue will overwrite the selection with the non-updated data
- } else if (!FormattedTextBox.DontSelectInitialText) {
- const mark = schema.marks.user_mark.create({ userid: ClientUtils.CurrentUserEmail(), modified: Math.floor(Date.now() / 1000) });
- selectAll(this.EditorView.state, (tx: Transaction) => {
- this.EditorView?.dispatch(tx.addStoredMark(mark));
- });
- this.EditorView?.dispatch(this.EditorView.state.tr.setSelection(new TextSelection(this.EditorView.state.doc.resolve(1))));
- this.tryUpdateDoc(true); // calling select() above will make isContentActive() true only after a render .. which means the selectAll() above won't write to the Document and the incomingValue will overwrite the selection with the non-updated data
- } else {
- const $from = this.EditorView.state.selection.anchor ? this.EditorView.state.doc.resolve(this.EditorView.state.selection.anchor - 1) : undefined;
- const mark = schema.marks.user_mark.create({ userid: ClientUtils.CurrentUserEmail(), modified: Math.floor(Date.now() / 1000) });
- const curMarks = this.EditorView.state.storedMarks ?? $from?.marksAcross(this.EditorView.state.selection.$head) ?? [];
- const storedMarks = [...curMarks.filter(m => m.type !== mark.type), mark];
- const { tr } = this.EditorView.state;
- this.EditorView.dispatch(tr.setSelection(new TextSelection(tr.doc.resolve(tr.doc.content.size))).setStoredMarks(storedMarks));
- this.tryUpdateDoc(true); // calling select() above will make isContentActive() true only after a render .. which means the selectAll() above won't write to the Document and the incomingValue will overwrite the selection with the non-updated data
+ tr = selLoadChar === 'Enter' ? tr1.insert(this.EditorView.state.doc.content.size - 1, schema.nodes.paragraph.create()) : tr1.insertText(selLoadChar, this.EditorView.state.doc.content.size - 1);
}
+ this.EditorView.dispatch(tr.setSelection(new TextSelection(tr.doc.resolve(tr.doc.content.size))).setStoredMarks(storedMarks));
+ this.tryUpdateDoc(true); // calling select() above will make isContentActive() true only after a render .. which means the selectAll() above won't write to the Document and the incomingValue will overwrite the selection with the non-updated data
}
if (selectOnLoad) {
- FormattedTextBox.DontSelectInitialText = false;
this.EditorView!.focus();
}
if (this._props.isContentActive()) this.prepareForTyping();