From 4b4d77f99bd55e6de0593c3acd1cf5798ae038bf Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 10 May 2024 14:05:01 -0400 Subject: added an always option for OpenWhere lightbox. cleaned up/fixed making collections capable of being a lightbox. --- src/client/util/DocumentManager.ts | 4 ++-- src/client/util/RTFMarkup.tsx | 8 ++++---- src/client/views/DocumentDecorations.tsx | 16 ++++++++-------- src/client/views/LightboxView.tsx | 2 +- src/client/views/PropertiesView.tsx | 3 ++- src/client/views/collections/CollectionDockingView.tsx | 2 +- src/client/views/collections/TabDocView.tsx | 10 +--------- src/client/views/collections/TreeView.tsx | 2 +- .../collectionFreeForm/CollectionFreeFormView.tsx | 11 ++++++----- src/client/views/nodes/DocumentView.tsx | 16 ++++------------ src/client/views/nodes/OpenWhere.ts | 2 ++ 11 files changed, 32 insertions(+), 44 deletions(-) (limited to 'src') 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(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 @@ -26,10 +26,6 @@ export class RTFMarkup extends React.Component<{}> { @computed get cheatSheet() { return (
-

- (@wiki:phrase) - {` display wikipedia page for entered text (terminate with carriage return)`} -

(( any text )) {` submit text to Chat GPT to have results appended afterward`} @@ -106,6 +102,10 @@ export class RTFMarkup extends React.Component<{}> { {`%h `} {` start a block of text that begins with a hanging indent`}

+

+ @(wiki:phrase) + {` display wikipedia page for entered text (terminate with carriage return)`} +

{`@(doctitle) `} {` hyperlink to document specified by it’s title`} 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 { - 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 { // 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 ObservableReactComponentOpening in new right pane - + + 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 { // 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(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 { } 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 ); } - 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 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 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 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', -- cgit v1.2.3-70-g09d2