aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/CollectionDockingView.tsx
diff options
context:
space:
mode:
authorMichael Foiani <sotech117@Michaels-MacBook-Pro-5.local>2022-06-10 12:04:03 -0400
committerMichael Foiani <sotech117@Michaels-MacBook-Pro-5.local>2022-06-10 12:04:03 -0400
commit91e193ef15bfc82d21653e9f150ccc25389dd6f3 (patch)
treeddca3cfebcb32be50045b8483eb3a349cf93914c /src/client/views/collections/CollectionDockingView.tsx
parenta2c3ed470c941b108aede045ac294e3b966990bc (diff)
parente08c690dbeca3e58b1bc0d387df0287f60f58b7a (diff)
merge with jenny bug fixes and fix small ui
Diffstat (limited to 'src/client/views/collections/CollectionDockingView.tsx')
-rw-r--r--src/client/views/collections/CollectionDockingView.tsx148
1 files changed, 61 insertions, 87 deletions
diff --git a/src/client/views/collections/CollectionDockingView.tsx b/src/client/views/collections/CollectionDockingView.tsx
index 64a5f38d4..a790a0475 100644
--- a/src/client/views/collections/CollectionDockingView.tsx
+++ b/src/client/views/collections/CollectionDockingView.tsx
@@ -26,6 +26,7 @@ import { CollectionSubView, SubCollectionViewProps } from "./CollectionSubView";
import { CollectionViewType } from './CollectionView';
import { TabDocView } from './TabDocView';
import React = require("react");
+import { SelectionManager } from '../../util/SelectionManager';
const _global = (window /* browser */ || global /* node */) as any;
@observer
@@ -50,9 +51,8 @@ export class CollectionDockingView extends CollectionSubView() {
public _flush: UndoManager.Batch | undefined;
private _ignoreStateChange = "";
public tabMap: Set<any> = new Set();
- public get initialized() { return this._goldenLayout !== null; }
public get HasFullScreen() { return this._goldenLayout._maximisedItem !== null; }
- @observable private _goldenLayout: any = null;
+ private _goldenLayout: any = null;
constructor(props: SubCollectionViewProps) {
super(props);
@@ -81,6 +81,8 @@ export class CollectionDockingView extends CollectionSubView() {
tabItemDropped = () => DragManager.CompleteWindowDrag?.(false);
tabDragStart = (proxy: any, finishDrag?: (aborted: boolean) => void) => {
+ const dashDoc = proxy?._contentItem?.tab?.DashDoc as Doc;
+ dashDoc && (DragManager.DocDragData = new DragManager.DocumentDragData([proxy._contentItem.tab.DashDoc]));
DragManager.CompleteWindowDrag = (aborted: boolean) => {
if (aborted) {
proxy._dragListener.AbortDrag();
@@ -116,6 +118,7 @@ export class CollectionDockingView extends CollectionSubView() {
@undoBatch
public static OpenFullScreen(doc: Doc) {
+ SelectionManager.DeselectAll();
const instance = CollectionDockingView.Instance;
if (doc._viewType === CollectionViewType.Docking && doc.layoutKey === "layout") {
return CurrentUserUtils.openDashboard(Doc.UserDoc(), doc);
@@ -169,12 +172,6 @@ export class CollectionDockingView extends CollectionSubView() {
@undoBatch
@action
public static AddSplit(document: Doc, pullSide: string, stack?: any, panelName?: string) {
- if (document.type === DocumentType.PRES) {
- const docs = Cast(Cast(Doc.UserDoc().myOverlayDocs, Doc, null).data, listSpec(Doc), []);
- if (docs.includes(document)) {
- docs.splice(docs.indexOf(document), 1);
- }
- }
if (document._viewType === CollectionViewType.Docking) return CurrentUserUtils.openDashboard(Doc.UserDoc(), document);
const tab = Array.from(CollectionDockingView.Instance.tabMap).find(tab => tab.DashDoc === document);
@@ -183,19 +180,8 @@ export class CollectionDockingView extends CollectionSubView() {
return true;
}
const instance = CollectionDockingView.Instance;
+ const glayRoot = instance._goldenLayout.root;
if (!instance) return false;
- else {
- const docList = DocListCast(instance.props.Document[DataSym]["data-all"]);
- // adds the doc of the newly created tab to the data-all field if it doesn't already include that doc or one of its aliases
- !docList.includes(document) && !docList.includes(document.aliasOf as Doc) && Doc.AddDocToList(instance.props.Document[DataSym], "data-all", document);
- // adds an alias of the doc to the data-all field of the layoutdocs of the aliases
- DocListCast(instance.props.Document[DataSym].aliases).forEach(alias => {
- const aliasDocList = DocListCast(alias["data-all"]);
- // if aliasDocList contains the alias, don't do anything
- // otherwise add the original or an alias depending on whether the doc you're looking at is the current doc or a different alias
- !DocListCast(document.aliases).some(a => aliasDocList.includes(a)) && Doc.AddDocToList(alias, "data-all", document);//alias !== instance.props.Document ? Doc.MakeAlias(document) : document);
- });
- }
const docContentConfig = CollectionDockingView.makeDocumentConfig(document, panelName);
if (!pullSide && stack) {
@@ -203,29 +189,29 @@ export class CollectionDockingView extends CollectionSubView() {
stack.setActiveContentItem(stack.contentItems[stack.contentItems.length - 1]);
} else {
const newItemStackConfig = { type: 'stack', content: [docContentConfig] };
- const newContentItem = instance._goldenLayout.root.layoutManager.createContentItem(newItemStackConfig, instance._goldenLayout);
- if (instance._goldenLayout.root.contentItems.length === 0) { // if no rows / columns
- instance._goldenLayout.root.addChild(newContentItem);
- } else if (instance._goldenLayout.root.contentItems[0].isStack) {
- instance._goldenLayout.root.contentItems[0].addChild(docContentConfig);
+ const newContentItem = glayRoot.layoutManager.createContentItem(newItemStackConfig, instance._goldenLayout);
+ if (glayRoot.contentItems.length === 0) { // if no rows / columns
+ glayRoot.addChild(newContentItem);
+ } else if (glayRoot.contentItems[0].isStack) {
+ glayRoot.contentItems[0].addChild(docContentConfig);
} else if (
- instance._goldenLayout.root.contentItems.length === 1 &&
- instance._goldenLayout.root.contentItems[0].contentItems.length === 1 &&
- instance._goldenLayout.root.contentItems[0].contentItems[0].contentItems.length === 0) {
- instance._goldenLayout.root.contentItems[0].contentItems[0].addChild(docContentConfig);
+ glayRoot.contentItems.length === 1 &&
+ glayRoot.contentItems[0].contentItems.length === 1 &&
+ glayRoot.contentItems[0].contentItems[0].contentItems.length === 0) {
+ glayRoot.contentItems[0].contentItems[0].addChild(docContentConfig);
}
else if (instance._goldenLayout.root.contentItems[0].isRow) { // if row
switch (pullSide) {
default:
- case "right": instance._goldenLayout.root.contentItems[0].addChild(newContentItem); break;
- case "left": instance._goldenLayout.root.contentItems[0].addChild(newContentItem, 0); break;
+ case "right": glayRoot.contentItems[0].addChild(newContentItem); break;
+ case "left": glayRoot.contentItems[0].addChild(newContentItem, 0); break;
case "top":
case "bottom":
// if not going in a row layout, must add already existing content into column
- const rowlayout = instance._goldenLayout.root.contentItems[0];
+ const rowlayout = glayRoot.contentItems[0];
const newColumn = rowlayout.layoutManager.createContentItem({ type: "column" }, instance._goldenLayout);
- CollectionDockingView.Instance._goldenLayout.saveScrollTops(rowlayout.element);
+ instance._goldenLayout.saveScrollTops(rowlayout.element);
rowlayout.parent.replaceChild(rowlayout, newColumn);
if (pullSide === "top") {
newColumn.addChild(rowlayout, undefined, true);
@@ -234,23 +220,23 @@ export class CollectionDockingView extends CollectionSubView() {
newColumn.addChild(newContentItem, undefined, true);
newColumn.addChild(rowlayout, 0, true);
}
- CollectionDockingView.Instance._goldenLayout.restoreScrollTops(rowlayout.element);
+ instance._goldenLayout.restoreScrollTops(rowlayout.element);
rowlayout.config.height = 50;
newContentItem.config.height = 50;
}
} else {// if (instance._goldenLayout.root.contentItems[0].isColumn) { // if column
switch (pullSide) {
- case "top": instance._goldenLayout.root.contentItems[0].addChild(newContentItem, 0); break;
- case "bottom": instance._goldenLayout.root.contentItems[0].addChild(newContentItem); break;
+ case "top": glayRoot.contentItems[0].addChild(newContentItem, 0); break;
+ case "bottom": glayRoot.contentItems[0].addChild(newContentItem); break;
case "left":
case "right":
default:
// if not going in a row layout, must add already existing content into column
- const collayout = instance._goldenLayout.root.contentItems[0];
+ const collayout = glayRoot.contentItems[0];
const newRow = collayout.layoutManager.createContentItem({ type: "row" }, instance._goldenLayout);
- CollectionDockingView.Instance._goldenLayout.saveScrollTops(collayout.element);
+ instance._goldenLayout.saveScrollTops(collayout.element);
collayout.parent.replaceChild(collayout, newRow);
if (pullSide === "left") {
newRow.addChild(collayout, undefined, true);
@@ -259,7 +245,7 @@ export class CollectionDockingView extends CollectionSubView() {
newRow.addChild(newContentItem, undefined, true);
newRow.addChild(collayout, 0, true);
}
- CollectionDockingView.Instance._goldenLayout.restoreScrollTops(collayout.element);
+ instance._goldenLayout.restoreScrollTops(collayout.element);
collayout.config.width = 50;
newContentItem.config.width = 50;
@@ -281,7 +267,7 @@ export class CollectionDockingView extends CollectionSubView() {
return true;
}
- async setupGoldenLayout() {
+ setupGoldenLayout = async () => {
const config = StrCast(this.props.Document.dockingConfig);
if (config) {
const matches = config.match(/\"documentId\":\"[a-z0-9-]+\"/g);
@@ -298,26 +284,19 @@ export class CollectionDockingView extends CollectionSubView() {
this._goldenLayout.unbind('stackCreated', this.stackCreated);
} catch (e) { }
}
+ this.tabMap.clear();
+ this._goldenLayout.destroy();
}
- this.tabMap.clear();
- this._goldenLayout?.destroy();
- runInAction(() => this._goldenLayout = new GoldenLayout(JSON.parse(config)));
- this._goldenLayout.on('tabCreated', this.tabCreated);
- this._goldenLayout.on('tabDestroyed', this.tabDestroyed);
- this._goldenLayout.on('stackCreated', this.stackCreated);
- this._goldenLayout.registerComponent('DocumentFrameRenderer', TabDocView);
- this._goldenLayout.container = this._containerRef.current;
- if (this._goldenLayout.config.maximisedItemId === '__glMaximised') {
- try {
- this._goldenLayout.config.root.getItemsById(this._goldenLayout.config.maximisedItemId)[0].toggleMaximise();
- } catch (e) {
- this._goldenLayout.config.maximisedItemId = null;
- }
- }
- this._goldenLayout.init();
- this._goldenLayout.root.layoutManager.on('itemDropped', this.tabItemDropped);
- this._goldenLayout.root.layoutManager.on('dragStart', this.tabDragStart);
- this._goldenLayout.root.layoutManager.on('activeContentItemChanged', this.stateChanged);
+ const glay = this._goldenLayout = new GoldenLayout(JSON.parse(config));
+ glay.on('tabCreated', this.tabCreated);
+ glay.on('tabDestroyed', this.tabDestroyed);
+ glay.on('stackCreated', this.stackCreated);
+ glay.registerComponent('DocumentFrameRenderer', TabDocView);
+ glay.container = this._containerRef.current;
+ glay.init();
+ glay.root.layoutManager.on('itemDropped', this.tabItemDropped);
+ glay.root.layoutManager.on('dragStart', this.tabDragStart);
+ glay.root.layoutManager.on('activeContentItemChanged', this.stateChanged);
}
}
@@ -332,7 +311,7 @@ export class CollectionDockingView extends CollectionSubView() {
}
this._ignoreStateChange = "";
});
- setTimeout(() => this.setupGoldenLayout(), 0);
+ setTimeout(this.setupGoldenLayout);
//window.addEventListener('resize', this.onResize); // bcz: would rather add this event to the parent node, but resize events only come from Window
}
}
@@ -378,13 +357,14 @@ export class CollectionDockingView extends CollectionSubView() {
const htmlTarget = e.target as HTMLElement;
window.addEventListener("mouseup", this.onPointerUp);
if (!htmlTarget.closest("*.lm_content") && (htmlTarget.closest("*.lm_tab") || htmlTarget.closest("*.lm_stack"))) {
- if (htmlTarget.className !== "lm_close_tab") {
+ const className = typeof htmlTarget.className === "string" ? htmlTarget.className : "";
+ if (!className.includes("lm_close") && !className.includes("lm_maximise")) {
this._flush = UndoManager.StartBatch("golden layout edit");
}
}
}
if (!e.nativeEvent.cancelBubble && !InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE) && !InteractionUtils.IsType(e, InteractionUtils.PENTYPE) &&
- ![InkTool.Highlighter, InkTool.Pen].includes(CurrentUserUtils.SelectedTool)) {
+ ![InkTool.Highlighter, InkTool.Pen, InkTool.Write].includes(CurrentUserUtils.SelectedTool)) {
e.stopPropagation();
}
}
@@ -404,7 +384,10 @@ export class CollectionDockingView extends CollectionSubView() {
const origtabdocs = DocListCast(origtab.data);
const newtab = origtabdocs.length ? Doc.MakeCopy(origtab, true, undefined, true) : Doc.MakeAlias(origtab);
const newtabdocs = origtabdocs.map(origtabdoc => Doc.MakeAlias(origtabdoc));
- newtabdocs.length && (Doc.GetProto(newtab).data = new List<Doc>(newtabdocs));
+ if (newtabdocs.length) {
+ Doc.GetProto(newtab).data = new List<Doc>(newtabdocs);
+ newtabdocs.forEach(ntab => ntab.context = newtab);
+ }
json = json.replace(origtab[Id], newtab[Id]);
return newtab;
});
@@ -418,40 +401,27 @@ export class CollectionDockingView extends CollectionSubView() {
const matches = json.match(/\"documentId\":\"[a-z0-9-]+\"/g);
const docids = matches?.map(m => m.replace("\"documentId\":\"", "").replace("\"", ""));
const docs = !docids ? [] : docids.map(id => DocServer.GetCachedRefField(id)).filter(f => f).map(f => f as Doc);
- const changesMade = this.props.Document.dockingConfig !== json;
+ const changesMade = this.props.Document.dockcingConfig !== json;
if (changesMade && !this._flush) {
- this.props.Document.dockingConfig = json;
- setTimeout(async () => {
- const sublists = await DocListCastAsync(this.props.Document[this.props.fieldKey]);
- const tabs = sublists && Cast(sublists[0], Doc, null);
- // const other = sublists && Cast(sublists[1], Doc, null);
- const tabdocs = await DocListCastAsync(tabs?.data);
- // const otherdocs = await DocListCastAsync(other?.data);
- if (tabs) {
- tabs.data = new List<Doc>(docs);
- // DocListCast(tabs.aliases).forEach(tab => tab !== tabs && (tab.data = new List<Doc>(docs)));
- }
- // const otherSet = new Set<Doc>();
- // otherdocs?.filter(doc => !docs.includes(doc)).forEach(doc => otherSet.add(doc));
- // tabdocs?.filter(doc => !docs.includes(doc) && doc.type !== DocumentType.KVP).forEach(doc => otherSet.add(doc));
- // const vals = Array.from(otherSet.values()).filter(val => val instanceof Doc).map(d => d).filter(d => d.type !== DocumentType.KVP);
- // this.props.Document[DataSym][this.props.fieldKey + "-all"] = new List<Doc>([...docs, ...vals]);
- // if (other) {
- // other.data = new List<Doc>(vals);
- // // DocListCast(other.aliases).forEach(tab => tab !== other && (tab.data = new List<Doc>(vals)));
- // }
- }, 0);
+ UndoManager.RunInBatch(() => {
+ this.props.Document.dockingConfig = json;
+ this.props.Document.data = new List<Doc>(docs);
+ }, "state changed");
}
return changesMade;
}
tabDestroyed = (tab: any) => {
+ const dview = CollectionDockingView.Instance.props.Document;
+ const fieldKey = CollectionDockingView.Instance.props.fieldKey;
+ Doc.RemoveDocFromList(dview, fieldKey, tab.DashDoc);
this.tabMap.delete(tab);
tab._disposers && Object.values(tab._disposers).forEach((disposer: any) => disposer?.());
tab.reactComponents?.forEach((ele: any) => ReactDOM.unmountComponentAtNode(ele));
this.stateChanged();
}
tabCreated = (tab: any) => {
+ this.tabMap.add(tab);
tab.contentItem.element[0]?.firstChild?.firstChild?.InitTab?.(tab); // have to explicitly initialize tabs that reuse contents from previous tabs (ie, when dragging a tab around a new tab is created for the old content)
}
@@ -474,12 +444,14 @@ export class CollectionDockingView extends CollectionSubView() {
//if (confirm('really close this?')) {
if (!stack.parent.parent.isRoot || stack.parent.contentItems.length > 1) {
stack.remove();
- stack.contentItems.forEach((contentItem: any) => Doc.AddDocToList(CurrentUserUtils.MyRecentlyClosed, "data", contentItem.tab.DashDoc, undefined, true, true));
} else {
alert('cant delete the last stack');
}
}));
- stack.header?.controlsContainer.find('.lm_popout') //get the close icon
+
+ stack.header?.controlsContainer.find('.lm_maximise') //get the close icon
+ .click(() => setTimeout(this.stateChanged));
+ stack.header?.controlsContainer.find('.lm_popout') //get the popout icon
.off('click') //unbind the current click handler
.click(action(() => {
// stack.config.fixed = !stack.config.fixed; // force the stack to have a fixed size
@@ -502,4 +474,6 @@ ScriptingGlobals.add(function openInLightbox(doc: any) { LightboxView.AddDocTab(
"opens up document in a lightbox", "(doc: any)");
ScriptingGlobals.add(function openOnRight(doc: any) { return CollectionDockingView.AddSplit(doc, "right"); },
"opens up document in tab on right side of the screen", "(doc: any)");
+ScriptingGlobals.add(function openInOverlay(doc: any) { return Doc.AddDocToList((Doc.UserDoc().myOverlayDocs as Doc), undefined, doc); },
+ "opens up document in screen overlay layer", "(doc: any)");
ScriptingGlobals.add(function useRightSplit(doc: any, shiftKey?: boolean) { CollectionDockingView.ReplaceTab(doc, "right", undefined, shiftKey); }); \ No newline at end of file