diff options
author | bobzel <zzzman@gmail.com> | 2024-05-10 14:05:01 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-10 14:05:01 -0400 |
commit | 4b4d77f99bd55e6de0593c3acd1cf5798ae038bf (patch) | |
tree | 0fa27b0344c4252833b9d36dbe69f172141b846e /src | |
parent | e12f79e188c32787b5749eba54183002f270f998 (diff) |
added an always option for OpenWhere lightbox. cleaned up/fixed making collections capable of being a lightbox.
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/DocumentManager.ts | 4 | ||||
-rw-r--r-- | src/client/util/RTFMarkup.tsx | 8 | ||||
-rw-r--r-- | src/client/views/DocumentDecorations.tsx | 16 | ||||
-rw-r--r-- | src/client/views/LightboxView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/PropertiesView.tsx | 3 | ||||
-rw-r--r-- | src/client/views/collections/CollectionDockingView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/collections/TabDocView.tsx | 10 | ||||
-rw-r--r-- | src/client/views/collections/TreeView.tsx | 2 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 11 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 16 | ||||
-rw-r--r-- | src/client/views/nodes/OpenWhere.ts | 2 |
11 files changed, 32 insertions, 44 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts index 97051207b..09a8194ca 100644 --- a/src/client/util/DocumentManager.ts +++ b/src/client/util/DocumentManager.ts @@ -264,11 +264,11 @@ export class DocumentManager { (!DocumentView.LightboxDoc() && docContextPath.some(doc => DocumentView.activateTabView(doc))) || DocumentViewInternal.addDocTabFunc(docContextPath[0], options.openLocation ?? OpenWhere.addRight); this.AddViewRenderedCb(docContextPath[0], dv => res(dv)); })); - if (options.openLocation === OpenWhere.lightbox) { + if (options.openLocation?.includes(OpenWhere.lightbox)) { // even if we found the document view, if the target is a lightbox, we try to open it in the lightbox to preserve lightbox semantics (eg, there's only one active doc in the lightbox) const target = DocCast(targetDoc.annotationOn, targetDoc); const contextView = this.getDocumentView(DocCast(target.embedContainer)); - if (contextView?.ComponentView?.addDocTab?.(target, OpenWhere.lightbox)) { + if (contextView?.ComponentView?.addDocTab?.(target, options.openLocation)) { await new Promise<void>(waitres => { setTimeout(() => waitres()); }); diff --git a/src/client/util/RTFMarkup.tsx b/src/client/util/RTFMarkup.tsx index 248fda7e3..a07ad2047 100644 --- a/src/client/util/RTFMarkup.tsx +++ b/src/client/util/RTFMarkup.tsx @@ -27,10 +27,6 @@ export class RTFMarkup extends React.Component<{}> { return ( <div style={{ background: SnappingManager.userBackgroundColor, color: SnappingManager.userColor, textAlign: 'initial', height: '100%' }}> <p> - <b style={{ fontSize: 'larger' }}>(@wiki:phrase)</b> - {` display wikipedia page for entered text (terminate with carriage return)`} - </p> - <p> <b style={{ fontSize: 'larger' }}>(( any text ))</b> {` submit text to Chat GPT to have results appended afterward`} </p> @@ -107,6 +103,10 @@ export class RTFMarkup extends React.Component<{}> { {` start a block of text that begins with a hanging indent`} </p> <p> + <b style={{ fontSize: 'larger' }}>@(wiki:phrase)</b> + {` display wikipedia page for entered text (terminate with carriage return)`} + </p> + <p> <b style={{ fontSize: 'larger' }}>{`@(doctitle) `}</b> {` hyperlink to document specified by it’s title`} </p> diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index fd44909c0..93c3e3338 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -32,7 +32,7 @@ import { Colors } from './global/globalEnums'; import { CollectionFreeFormDocumentView } from './nodes/CollectionFreeFormDocumentView'; import { DocumentView } from './nodes/DocumentView'; import { ImageBox } from './nodes/ImageBox'; -import { OpenWhereMod } from './nodes/OpenWhere'; +import { OpenWhere, OpenWhereMod } from './nodes/OpenWhere'; import { FormattedTextBox } from './nodes/formattedText/FormattedTextBox'; interface DocumentDecorationsProps { @@ -255,28 +255,28 @@ export class DocumentDecorations extends ObservableReactComponent<DocumentDecora e.stopPropagation(); }; onMaximizeClick = (e: any): void => { - const selectedDocs = DocumentView.SelectedDocs(); - if (selectedDocs.length) { + const selView = DocumentView.Selected()[0]; + if (selView) { if (e.ctrlKey) { // open an embedding in a new tab with Ctrl Key - CollectionDockingView.AddSplit(Doc.BestEmbedding(selectedDocs[0]), OpenWhereMod.right); + CollectionDockingView.AddSplit(Doc.BestEmbedding(selView.Document), OpenWhereMod.right); } else if (e.shiftKey) { // open centered in a new workspace with Shift Key - const embedding = Doc.MakeEmbedding(selectedDocs[0]); + const embedding = Doc.MakeEmbedding(selView.Document); embedding.embedContainer = undefined; embedding.x = -NumCast(embedding._width) / 2; embedding.y = -NumCast(embedding._height) / 2; CollectionDockingView.AddSplit(Docs.Create.FreeformDocument([embedding], { title: 'Tab for ' + embedding.title }), OpenWhereMod.right); } else if (e.altKey) { // open same document in new tab - CollectionDockingView.ToggleSplit(selectedDocs[0], OpenWhereMod.right); + CollectionDockingView.ToggleSplit(selView.Document, OpenWhereMod.right); } else { - let openDoc = selectedDocs[0]; + let openDoc = selView.Document; if (openDoc.layout_fieldKey === 'layout_icon') { openDoc = Doc.GetEmbeddings(openDoc).find(embedding => !embedding.embedContainer) ?? Doc.MakeEmbedding(openDoc); Doc.deiconifyView(openDoc); } - DocumentView.SetLightboxDoc(openDoc, undefined, selectedDocs.slice(1)); + selView._props.addDocTab(openDoc, OpenWhere.lightboxAlways); } } DocumentView.DeselectAll(); diff --git a/src/client/views/LightboxView.tsx b/src/client/views/LightboxView.tsx index 269f4fa83..7198c7f05 100644 --- a/src/client/views/LightboxView.tsx +++ b/src/client/views/LightboxView.tsx @@ -341,5 +341,5 @@ export class LightboxTourBtn extends React.Component<LightboxTourBtnProps> { // eslint-disable-next-line prefer-arrow-callback ScriptingGlobals.add(function deiconifyViewToLightbox(documentView: DocumentView) { - LightboxView.Instance.AddDocTab(documentView.Document, OpenWhere.lightbox, 'layout'); // , 0); + LightboxView.Instance.AddDocTab(documentView.Document, OpenWhere.lightboxAlways, 'layout'); // , 0); }); diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index b03c1a64e..e4ca3daeb 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -1471,7 +1471,8 @@ export class PropertiesView extends ObservableReactComponent<PropertiesViewProps <option value={OpenWhere.addRight}>Opening in new right pane</option> <option value={OpenWhere.replaceLeft}>Replacing left tab</option> <option value={OpenWhere.replaceRight}>Replacing right tab</option> - <option value={OpenWhere.lightbox}>Opening in lightbox</option> + <option value={OpenWhere.lightboxAlways}>Opening in lightbox always</option> + <option value={OpenWhere.lightbox}>Opening in lightbox if not visible</option> <option value={OpenWhere.add}>Opening in new tab</option> <option value={OpenWhere.replace}>Replacing current tab</option> <option value={OpenWhere.inParent}>Opening in same collection</option> diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx index 8fb2b30f1..a723dc69d 100644 --- a/src/client/views/collections/CollectionDockingView.tsx +++ b/src/client/views/collections/CollectionDockingView.tsx @@ -634,7 +634,7 @@ export class CollectionDockingView extends CollectionSubView() { ScriptingGlobals.add( // eslint-disable-next-line prefer-arrow-callback function openInLightbox(doc: any) { - CollectionDockingView.Instance?._props.addDocTab(doc, OpenWhere.lightbox); + CollectionDockingView.Instance?._props.addDocTab(doc, OpenWhere.lightboxAlways); }, 'opens up document in a lightbox', '(doc: any)' diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx index afd584154..46f61290e 100644 --- a/src/client/views/collections/TabDocView.tsx +++ b/src/client/views/collections/TabDocView.tsx @@ -549,15 +549,7 @@ export class TabDocView extends ObservableReactComponent<TabDocViewProps> { // prettier-ignore switch (whereFields[0]) { case undefined: - case OpenWhere.lightbox: if (this.layoutDoc?._isLightbox) { - const lightboxView = !docs[0].annotationOn && DocCast(docs[0].embedContainer) ? DocumentView.getFirstDocumentView(DocCast(docs[0].embedContainer)) : undefined; - const data = lightboxView?.dataDoc[Doc.LayoutFieldKey(lightboxView.Document)]; - if (lightboxView && (!data || data instanceof List)) { - lightboxView.layoutDoc[Doc.LayoutFieldKey(lightboxView.Document)] = new List<Doc>(docs); - return true; - } - } - return LightboxView.Instance.AddDocTab(docs[0], OpenWhere.lightbox); + case OpenWhere.lightbox: return LightboxView.Instance.AddDocTab(docs[0], location); case OpenWhere.close: return CollectionDockingView.CloseSplit(docs[0], whereMods); case OpenWhere.replace: return CollectionDockingView.ReplaceTab(docs[0], whereMods, this.stack, panelName, undefined, keyValue); case OpenWhere.toggle: return CollectionDockingView.ToggleSplit(docs[0], whereMods, this.stack, TabDocView.DontSelectOnActivate, keyValue); diff --git a/src/client/views/collections/TreeView.tsx b/src/client/views/collections/TreeView.tsx index 3a187171a..bc12d1c28 100644 --- a/src/client/views/collections/TreeView.tsx +++ b/src/client/views/collections/TreeView.tsx @@ -231,7 +231,7 @@ export class TreeView extends ObservableReactComponent<TreeViewProps> { } else { // choose an appropriate embedding or make one. --- choose the first embedding that (1) user owns, (2) has no context field ... otherwise make a new embedding const bestEmbedding = docView.Document.author === ClientUtils.CurrentUserEmail() && !Doc.IsDataProto(docView.Document) ? docView.Document : Doc.BestEmbedding(docView.Document); - this._props.addDocTab(bestEmbedding, OpenWhere.lightbox); + this._props.addDocTab(bestEmbedding, OpenWhere.lightboxAlways); } }; diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index dbd9fb11f..92e29e94a 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -42,7 +42,7 @@ import { DocumentView } from '../../nodes/DocumentView'; import { FieldViewProps } from '../../nodes/FieldView'; import { FocusViewOptions } from '../../nodes/FocusViewOptions'; import { FormattedTextBox } from '../../nodes/formattedText/FormattedTextBox'; -import { OpenWhere } from '../../nodes/OpenWhere'; +import { OpenWhere, OpenWhereMod } from '../../nodes/OpenWhere'; import { PinDocView, PinProps } from '../../PinFuncs'; import { StyleProp } from '../../StyleProp'; import { CollectionSubView } from '../CollectionSubView'; @@ -1066,9 +1066,10 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection /> ); } - addDocTab = action((docsIn: Doc | Doc[], where: OpenWhere) => { + addDocTab = action((docsIn: Doc | Doc[], location: OpenWhere) => { const docs = toList(docsIn); - if (this._props.isAnnotationOverlay) return this._props.addDocTab(docs, where); + if (this._props.isAnnotationOverlay) return this._props.addDocTab(docs, location); + const where = location.split(':')[0]; switch (where) { case OpenWhere.inParent: return this._props.addDocument?.(docs) || false; @@ -1095,13 +1096,13 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection } if (firstDoc === this.Document || this.childDocList?.includes(firstDoc) || this.childLayoutPairs.map(pair => pair.layout)?.includes(firstDoc)) { if (firstDoc.hidden) firstDoc.hidden = false; - return true; + if (!location.includes(OpenWhereMod.always)) return true; } } break; default: } - return this._props.addDocTab(docs, where); + return this._props.addDocTab(docs, location); }); getCalculatedPositions(pair: { layout: Doc; data?: Doc }): PoolData { diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 3e154aead..14feca0b5 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -151,12 +151,9 @@ export class DocumentViewInternal extends DocComponent<FieldViewProps & Document @computed get disableClickScriptFunc() { const onScriptDisable = this._props.onClickScriptDisable ?? this._componentView?.onClickScriptDisable?.() ?? this.layoutDoc.onClickScriptDisable; - return ( - // eslint-disable-next-line no-use-before-define - DocumentView.LongPress || - onScriptDisable === 'always' || - (onScriptDisable !== 'never' && (this.rootSelected() || this._componentView?.isAnyChildContentActive?.())) - ); // prettier-ignore + return (DocumentView.LongPress || + onScriptDisable === 'always' || + (onScriptDisable !== 'never' && (this.rootSelected() || this._componentView?.isAnyChildContentActive?.()))); // prettier-ignore } @computed get _rootSelected() { return this._props.isSelected() || BoolCast(this._props.TemplateDataDocument && this._props.rootSelected?.()); @@ -321,7 +318,7 @@ export class DocumentViewInternal extends DocComponent<FieldViewProps & Document if (this.onDoubleClickHandler?.script) { UndoManager.RunInBatch(() => this.onDoubleClickHandler.script.run(scriptProps, console.log).result?.select && this._props.select(false), 'on double click: ' + this.Document.title); } else if (!Doc.IsSystem(this.Document) && defaultDblclick !== 'ignore') { - UndoManager.RunInBatch(() => this._props.addDocTab(this.Document, OpenWhere.lightbox), 'double tap'); + UndoManager.RunInBatch(() => this._props.addDocTab(this.Document, OpenWhere.lightboxAlways), 'double tap'); DocumentView.DeselectAll(); Doc.UnBrushDoc(this.Document); } else { @@ -334,12 +331,7 @@ export class DocumentViewInternal extends DocComponent<FieldViewProps & Document let clickFunc: undefined | (() => any); if (!this.disableClickScriptFunc && this.onClickHandler?.script) { clickFunc = undoable(() => { - // use this view's add doc func to override method for following links to undisplayed documents. - // e.g., if this document is part of a labeled 'lightbox' container, then documents will be shown in this container of in the global lightbox - const oldFunc = DocumentViewInternal.addDocTabFunc; - DocumentViewInternal.addDocTabFunc = this._props.addDocTab; this.onClickHandler?.script.run(scriptProps, console.log).result?.select && this._props.select(false); - DocumentViewInternal.addDocTabFunc = oldFunc; }, 'click ' + this.Document.title); } else { // onDragStart implies a button doc that we don't want to select when clicking. RootDocument & isTemplateForField implies we're clicking on part of a template instance and we want to select the whole template, not the part diff --git a/src/client/views/nodes/OpenWhere.ts b/src/client/views/nodes/OpenWhere.ts index e2a5f1f2a..f7101b103 100644 --- a/src/client/views/nodes/OpenWhere.ts +++ b/src/client/views/nodes/OpenWhere.ts @@ -5,9 +5,11 @@ export enum OpenWhereMod { top = 'top', bottom = 'bottom', keyvalue = 'keyValue', + always = 'always', // forces the open location (lightbox) instead of using an existing open view (see DocumentDecorations) } export enum OpenWhere { lightbox = 'lightbox', + lightboxAlways = 'lightbox:always', add = 'add', addLeft = 'add:left', addRight = 'add:right', |