aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/global/globalScripts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/global/globalScripts.ts')
-rw-r--r--src/client/views/global/globalScripts.ts385
1 files changed, 305 insertions, 80 deletions
diff --git a/src/client/views/global/globalScripts.ts b/src/client/views/global/globalScripts.ts
index 7730ed385..a48e3f9d9 100644
--- a/src/client/views/global/globalScripts.ts
+++ b/src/client/views/global/globalScripts.ts
@@ -1,23 +1,7 @@
import { Colors } from 'browndash-components';
import { action, runInAction } from 'mobx';
import { aggregateBounds } from '../../../Utils';
-import {
- ActiveFillColor,
- ActiveEraserWidth,
- ActiveInkColor,
- ActiveInkHideTextLabels,
- ActiveInkWidth,
- ActiveIsInkMask,
- Doc,
- DocListCast,
- Opt,
- SetActiveFillColor,
- SetActiveInkColor,
- SetActiveInkHideTextLabels,
- SetActiveInkWidth,
- SetActiveIsInkMask,
- SetEraserWidth,
-} from '../../../fields/Doc';
+import { Doc, DocListCast, Opt } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
import { InkTool } from '../../../fields/InkField';
import { BoolCast, Cast, NumCast, StrCast } from '../../../fields/Types';
@@ -31,16 +15,35 @@ import { GestureOverlay } from '../GestureOverlay';
import { InkingStroke } from '../InkingStroke';
import { CollectionFreeFormView } from '../collections/collectionFreeForm';
import { CollectionFreeFormDocumentView } from '../nodes/CollectionFreeFormDocumentView';
-import { DocumentView } from '../nodes/DocumentView';
+import {
+ ActiveEraserWidth,
+ ActiveFillColor,
+ ActiveInkColor,
+ ActiveInkHideTextLabels,
+ ActiveInkWidth,
+ ActiveIsInkMask,
+ DocumentView,
+ SetActiveFillColor,
+ SetActiveInkColor,
+ SetActiveInkHideTextLabels,
+ SetActiveInkWidth,
+ SetActiveIsInkMask,
+ SetEraserWidth,
+} from '../nodes/DocumentView';
import { ImageBox } from '../nodes/ImageBox';
import { VideoBox } from '../nodes/VideoBox';
import { WebBox } from '../nodes/WebBox';
import { RichTextMenu } from '../nodes/formattedText/RichTextMenu';
-import { NumListCast } from '../../../fields/Doc';
+import { NumListCast, StrListCast } from '../../../fields/Doc';
import { List } from '../../../fields/List';
-
+import { CollectionViewType } from '../../documents/DocumentTypes';
// import { InkTranscription } from '../InkTranscription';
-
+import { Docs } from '../../documents/Documents';
+import { CollectionSubView } from '../collections/CollectionSubView';
+import { GPTPopup, GPTPopupMode } from '../pdf/GPTPopup/GPTPopup';
+import { PropertiesView } from '../PropertiesView';
+import { MainView } from '../MainView';
+import { SnappingManager } from '../../util/SnappingManager';
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function IsNoneSelected() {
return DocumentView.Selected().length <= 0;
@@ -59,7 +62,7 @@ ScriptingGlobals.add(function setView(view: string, getSelected: boolean) {
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: boolean) {
const selectedViews = DocumentView.Selected();
- if (Doc.ActiveTool !== InkTool.None) {
+ if (Doc.ActiveTool !== InkTool.None && !selectedViews.lastElement()?.Document._layout_isSvg) {
if (checkResult) {
return ActiveFillColor();
}
@@ -137,20 +140,25 @@ ScriptingGlobals.add(function toggleOverlay(checkResult?: boolean) {
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function showFreeform(attr: 'center' | 'grid' | 'snaplines' | 'clusters' | 'viewAll' | 'fitOnce', checkResult?: boolean, persist?: boolean) {
const selected = DocumentView.SelectedDocs().lastElement();
+
+ function isAttrFiltered(attr: string) {
+ return StrListCast(selected._childFilters).some(filter => filter.includes(attr));
+ }
+
// prettier-ignore
- const map: Map<'flashcards' | 'center' | 'grid' | 'snaplines' | 'clusters' | 'arrange' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'links' | 'like' | 'star' | 'idea' | 'chat' | '1' | '2' | '3' | '4',
+ const map: Map<'flashcards' | 'center' | 'grid' | 'snaplines' | 'clusters' | 'arrange' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'chat' | 'up' | 'down' | 'pile' | 'toggle-chat',
{
waitForRender?: boolean;
checkResult: (doc: Doc) => any;
setDoc: (doc: Doc, dv: DocumentView) => void;
}> = new Map([
['grid', {
- checkResult: (doc:Doc) => BoolCast(doc?._freeform_backgroundGrid, false),
- setDoc: (doc:Doc) => { doc._freeform_backgroundGrid = !doc._freeform_backgroundGrid; },
+ checkResult: (doc: Doc) => BoolCast(doc?._freeform_backgroundGrid, false),
+ setDoc: (doc: Doc) => { doc._freeform_backgroundGrid = !doc._freeform_backgroundGrid; },
}],
['snaplines', {
- checkResult: (doc:Doc) => BoolCast(doc?._freeform_snapLines, false),
- setDoc: (doc:Doc) => { doc._freeform_snapLines = !doc._freeform_snapLines; },
+ checkResult: (doc: Doc) => BoolCast(doc?._freeform_snapLines, false),
+ setDoc: (doc: Doc) => { doc._freeform_snapLines = !doc._freeform_snapLines; },
}],
['viewAll', {
checkResult: (doc: Doc) => BoolCast(doc?._freeform_fitContentsToBox, false),
@@ -161,13 +169,13 @@ ScriptingGlobals.add(function showFreeform(attr: 'center' | 'grid' | 'snaplines'
},
}],
['center', {
- checkResult: (doc:Doc) => BoolCast(doc?._stacking_alignCenter, false),
- setDoc: (doc:Doc) => { doc._stacking_alignCenter = !doc._stacking_alignCenter; },
+ checkResult: (doc: Doc) => BoolCast(doc?._stacking_alignCenter, false),
+ setDoc: (doc: Doc) => { doc._stacking_alignCenter = !doc._stacking_alignCenter; },
}],
['clusters', {
waitForRender: true, // flags that undo batch should terminate after a re-render giving the script the chance to fire
- checkResult: (doc:Doc) => BoolCast(doc?._freeform_useClusters, false),
- setDoc: (doc:Doc) => { doc._freeform_useClusters = !doc._freeform_useClusters; },
+ checkResult: (doc: Doc) => BoolCast(doc?._freeform_useClusters, false),
+ setDoc: (doc: Doc) => { doc._freeform_useClusters = !doc._freeform_useClusters; },
}],
['flashcards', {
checkResult: (doc: Doc) => BoolCast(Doc.UserDoc().defaultToFlashcards, false),
@@ -175,77 +183,289 @@ ScriptingGlobals.add(function showFreeform(attr: 'center' | 'grid' | 'snaplines'
}],
['time', {
checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "time",
- setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort = "time",
+ setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort === "time" ? doc.cardSort = '' : doc.cardSort = 'time',
}],
['docType', {
checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "type",
- setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort = "type",
+ setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort === "type" ? doc.cardSort = '' : doc.cardSort = 'type',
}],
['color', {
checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "color",
- setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort = "color",
- }],
- ['links', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "links",
- setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort = "links",
+ setDoc: (doc: Doc, dv: DocumentView) => doc.cardSort === "color" ? doc.cardSort = '' : doc.cardSort = 'color',
}],
- ['like', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "custom" && StrCast(doc?.cardSort_customField) === "like",
+ // ['heart', {
+ // checkResult: (doc: Doc) => isAttrFiltered('heart'),
+ // setDoc: (doc: Doc, dv: DocumentView) => {
+ // isAttrFiltered('heart') ? Doc.setDocFilter(doc, 'heart', true, 'remove') : Doc.setDocFilter(doc, 'heart', true, 'match');
+
+ // }
+ // }],
+ // ['star', {
+ // checkResult: (doc: Doc) => isAttrFiltered('star'),
+
+ // setDoc: (doc: Doc, dv: DocumentView) => {
+ // isAttrFiltered('star') ? Doc.setDocFilter(doc, 'star', true, 'remove') : Doc.setDocFilter(doc, 'star', true, 'match');
+ // }
+ // }],
+ // ['bolt', {
+ // checkResult: (doc: Doc) => isAttrFiltered('bolt'),
+ // setDoc: (doc: Doc, dv: DocumentView) => {
+ // isAttrFiltered('bolt') ? Doc.setDocFilter(doc, 'bolt', true, 'remove') : Doc.setDocFilter(doc, 'bolt', true, 'match');
+
+ // }
+ // }],
+ // ['cloud', {
+ // checkResult: (doc: Doc) => isAttrFiltered('cloud'),
+ // setDoc: (doc: Doc, dv: DocumentView) => {
+ // isAttrFiltered('cloud') ? Doc.setDocFilter(doc, 'cloud', true, 'remove') : Doc.setDocFilter(doc, 'cloud', true, 'match');
+
+ // }
+ // }],
+ ['chat', {
+ checkResult: (doc: Doc) => {
+
+ if (StrCast(doc?.cardSort) === "chat"){
+ return true
+ }} ,
setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort = "custom";
- doc.cardSort_customField = "like";
- doc.cardSort_visibleSortGroups = new List<number>();
- }
+ doc.cardSort === "chat" ? doc.cardSort = '' : doc.cardSort = 'chat';
+ },
}],
- ['star', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "custom" && StrCast(doc?.cardSort_customField) === "star",
+ ['up', {
+ checkResult: (doc: Doc) => BoolCast(!doc?.cardSort_isDesc),
setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort = "custom";
- doc.cardSort_customField = "star";
- doc.cardSort_visibleSortGroups = new List<number>();
- }
+ doc.cardSort_isDesc = false;
+ },
}],
- ['idea', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "custom" && StrCast(doc?.cardSort_customField) === "idea",
+ ['down', {
+ checkResult: (doc: Doc) => BoolCast(doc?.cardSort_isDesc),
setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort = "custom";
- doc.cardSort_customField = "idea";
- doc.cardSort_visibleSortGroups = new List<number>();
- }
+ doc.cardSort_isDesc = true;
+ },
}],
- ['chat', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "custom" && StrCast(doc?.cardSort_customField) === "chat",
+ ['toggle-chat', {
+ checkResult: (doc: Doc) => GPTPopup.Instance.visible,
setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort = "custom";
- doc.cardSort_customField = "chat";
- doc.cardSort_visibleSortGroups = new List<number>();
+ GPTPopup.Instance.setVisible(!GPTPopup.Instance.visible);
+ GPTPopup.Instance.setMode(GPTPopupMode.SORT);
+
},
}],
- ]);
- for (let i = 0; i < 8; i++) {
- map.set((i + 1 + '') as any, {
- checkResult: (doc: Doc) => NumListCast(doc?.cardSort_visibleSortGroups).includes(i),
+ ['pile', {
+ checkResult: (doc: Doc) => doc._type_collection == CollectionViewType.Freeform,
setDoc: (doc: Doc, dv: DocumentView) => {
- const list = NumListCast(doc.cardSort_visibleSortGroups);
- doc.cardSort_visibleSortGroups = new List<number>(list.includes(i) ? list.filter(d => d !== i) : [...list, i]);
+ doc._type_collection = CollectionViewType.Freeform;
+ const newCol = Docs.Create.CarouselDocument(DocListCast(doc[Doc.LayoutFieldKey(doc)]), {
+ _width: 250,
+ _height: 200,
+ _layout_fitWidth: false,
+ _layout_autoHeight: true,
+ });
+
+
+ const iconMap: { [key: number]: any } = {
+ 0: 'star',
+ 1: 'heart',
+ 2: 'cloud',
+ 3: 'bolt'
+ };
+
+ for (let i=0; i<4; i++){
+ if (isAttrFiltered(iconMap[i])){
+ newCol[iconMap[i]] = true
+ }
+ }
+
+ newCol && dv.ComponentView?.addDocument?.(newCol);
+ DocumentView.showDocument(newCol, { willZoomCentered: true })
+
},
- });
- }
+ }],
+ ]);
if (checkResult) {
return map.get(attr)?.checkResult(selected);
}
+ const filters = StrListCast(selected._childFilters).concat(StrListCast(selected?._childFiltersByRanges).filter((filter, i) => !(i % 3)));
+
+ // console.log(filters.some(filter => filter.includes('star'))+ "SUOOOOPPP")
+
const batch = map.get(attr)?.waitForRender ? UndoManager.StartBatch('set freeform attribute') : { end: () => {} };
DocumentView.Selected().map(dv => map.get(attr)?.setDoc(dv.layoutDoc, dv));
setTimeout(() => batch.end(), 100);
return undefined;
});
-ScriptingGlobals.add(function cardHasLabel(label: string) {
+
+ScriptingGlobals.add(function handleTags(value?: any, checkResult?: boolean) {
const selected = DocumentView.SelectedDocs().lastElement();
- const labelNum = Number(label) - 1;
- return labelNum < 4 || (selected && DocListCast(selected[Doc.LayoutFieldKey(selected)]).some(doc => doc[StrCast(selected.cardSort_customField)] == labelNum));
-}, '');
+
+ function isAttrFiltered(attr: string) {
+ return StrListCast(selected._childFilters).some(filter => filter.includes(attr));
+ }
+
+ if (checkResult) {
+ return value=== 'opts' ? PropertiesView.Instance.openFilters : isAttrFiltered(value)
+ }
+
+ if (value != 'opts'){
+ isAttrFiltered(value) ? Doc.setDocFilter(selected, value, true, 'remove') : Doc.setDocFilter(selected, value, true, 'match');
+ }
+ else {
+ SnappingManager.PropertiesWidth < 5 && SnappingManager.SetPropertiesWidth(0);
+ SnappingManager.SetPropertiesWidth(MainView.Instance.propertiesWidth() < 15 ? Math.min(MainView.Instance._dashUIWidth - 50, 250) : 0);
+
+ PropertiesView.Instance.CloseAll()
+ PropertiesView.Instance.openFilters = true
+ }
+
+
+ return undefined;
+ }, '');
+
+
+
+// ScriptingGlobals.add(function cardHasLabel(label: string) {
+// const selected = DocumentView.SelectedDocs().lastElement();
+// const labelNum = Number(label) - 1;
+// return labelNum < 4 || (selected && DocListCast(selected[Doc.LayoutFieldKey(selected)]).some(doc => doc[StrCast(selected.cardSort_customField)] == labelNum));
+// }, '');
+
+// ScriptingGlobals.add(function setCardSort(attr: "Time" | "Type"| "Color"| "ChatGPT"| "Custom 1"| "Custom 2"| "Custom 3", value?: any, checkResult?: boolean) {
+// // const editorView = RichTextMenu.Instance?.TextView?.EditorView;
+// const selected = DocumentView.SelectedDocs().lastElement();
+
+// // prettier-ignore
+// const map: Map<"Time" | "Type"| "Color"| "ChatGPT"| "Custom 1"| "Custom 2"| "Custom 3", { checkResult: (doc: Doc) => any; setDoc: (doc: Doc) => void;}> = new Map([
+// ['Time', {
+
+// checkResult: (doc: Doc) => {StrCast(doc?.cardSort);
+// console.log(StrCast(doc?.cardSort + "card sort"))},
+// setDoc: (doc: Doc) => {doc.cardSort = "time"
+// console.log("hewwo")}
+
+// ,
+// }],
+// ['Type', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort),
+// setDoc: (doc: Doc) => doc.cardSort = "type",
+// }],
+// ['Color', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort),
+// setDoc: (doc: Doc) => doc.cardSort = "color",
+// }],
+// // ['links', {
+// // checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "links",
+// // setDoc: (doc: Doc) => doc.cardSort = "links",
+// // }],
+// ['Custom 1', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort) + " 1",
+// setDoc: (doc: Doc) => {
+// doc.cardSort = "custom";
+// doc.cardSort_customField = "like";
+// doc.cardSort_visibleSortGroups = new List<number>();
+// }
+// }],
+// ['Custom 2', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort) + " 2",
+// setDoc: (doc: Doc) => {
+// doc.cardSort = "custom";
+// doc.cardSort_customField = "star";
+// doc.cardSort_visibleSortGroups = new List<number>();
+// }
+// }],
+// ['Custom 3', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort) + " 3",
+// setDoc: (doc: Doc) => {
+// doc.cardSort = "custom";
+// doc.cardSort_customField = "idea";
+// doc.cardSort_visibleSortGroups = new List<number>();
+// }
+// }],
+// ['ChatGPT', {
+// checkResult: (doc: Doc) => StrCast(doc?.cardSort_customField),
+// setDoc: (doc: Doc) => {
+// doc.cardSort = "custom";
+// doc.cardSort_customField = "chat";
+// doc.cardSort_visibleSortGroups = new List<number>();
+// },
+// }],
+// ]);
+
+// for (let i = 0; i < 8; i++) {
+// map.set((i + 1 + '') as any, {
+// checkResult: (doc: Doc) => NumListCast(doc?.cardSort_visibleSortGroups).includes(i),
+// setDoc: (doc: Doc) => {
+// const list = NumListCast(doc.cardSort_visibleSortGroups);
+// doc.cardSort_visibleSortGroups = new List<number>(list.includes(i) ? list.filter(d => d !== i) : [...list, i]);
+// },
+// });
+// }
+
+// if (checkResult) {
+// console.log(attr + "attricute")
+// console.log(map.get(attr)?.checkResult(selected) + "check result")
+// return map.get(attr)?.checkResult(selected);
+// }
+
+// console.log(attr + "attricute lol")
+
+// // const batch = map.get(attr)?.waitForRender ? UndoManager.StartBatch('set freeform attribute') : { end: () => {} };
+// DocumentView.Selected().map(dv => map.get(attr)?.setDoc(dv.layoutDoc));
+// // setTimeout(() => batch.end(), 100);
+// return undefined;
+
+// // map.get(attr)?.setDoc?.();
+// // return undefined;
+// });
+
+// ScriptingGlobals.add(function setCardSort(value?: any, checkResult?: boolean) {
+// // const editorView = RichTextMenu.Instance?.TextView?.EditorView;
+// const selected = DocumentView.SelectedDocs().lastElement();
+// if (checkResult) {
+// // console.log(attr + "attricute")
+// // console.log(map.get(attr)?.checkResult(selected) + "check result")
+// console.log(StrCast(selected?.cardSort) + 'check');
+// const hi = StrCast(selected?.cardSort);
+// return StrCast(selected?.cardSortForDropDown) ?? 'Time';
+// }
+// function docFields(doc: Doc): void {
+// switch (value) {
+// case 'Custom 1':
+// doc.cardSort_customField = 'like';
+// break;
+// case 'Custom 2':
+// doc.cardSort_customField = 'star';
+// break;
+// case 'Custom 3':
+// doc.cardSort_customField = 'idea';
+// break;
+// case 'Chat GPT':
+// doc.cardSort = 'custom';
+// doc.cardSort_customField = 'chat';
+// break;
+// default:
+// break;
+// }
+
+// doc.cardSort_visibleSortGroups = new List<number>();
+// }
+
+// // const batch = map.get(attr)?.waitForRender ? UndoManager.StartBatch('set freeform attribute') : { end: () => {} };
+// DocumentView.Selected().map(dv => {
+// dv.Document.cardSortForDropDown = value;
+
+// if (value != 'Chat GPT') {
+// dv.Document.cardSort = value.trim().split(/\s+/)[0].toLowerCase();
+// }
+// docFields(dv.Document);
+// });
+
+// return undefined;
+
+// // map.get(attr)?.setDoc?.();
+// // return undefined;
+// });
// ScriptingGlobals.add(function setCardSortAttr(attr: 'time' | 'docType' | 'color', value: any, checkResult?: boolean) {
// // const editorView = RichTextMenu.Instance?.TextView?.EditorView;
@@ -313,6 +533,7 @@ ScriptingGlobals.add(function setFontAttr(attr: 'font' | 'fontColor' | 'highligh
]);
if (checkResult) {
+ // console.log(map.get(attr)?.checkResult() + "font check result")
return map.get(attr)?.checkResult();
}
map.get(attr)?.setDoc?.();
@@ -450,15 +671,19 @@ function setActiveTool(tool: InkTool | Gestures, keepPrim: boolean, checkResult?
GestureOverlay.Instance.InkShape = tool as Gestures;
}
} else if (tool) {
- if ([InkTool.StrokeEraser, InkTool.RadiusEraser, InkTool.SegmentEraser].includes(tool as any)) {
- Doc.UserDoc().activeEraserTool = tool;
- }
- // pen or eraser
- if (Doc.ActiveTool === tool && !GestureOverlay.Instance.InkShape && !keepPrim) {
+ if (Doc.UserDoc().ActiveTool === tool) {
Doc.ActiveTool = InkTool.None;
} else {
- Doc.ActiveTool = tool as any;
- GestureOverlay.Instance.InkShape = undefined;
+ if ([InkTool.StrokeEraser, InkTool.RadiusEraser, InkTool.SegmentEraser].includes(tool as any)) {
+ Doc.UserDoc().activeEraserTool = tool;
+ }
+ // pen or eraser
+ if (Doc.ActiveTool === tool && !GestureOverlay.Instance.InkShape && !keepPrim) {
+ Doc.ActiveTool = InkTool.None;
+ } else {
+ Doc.ActiveTool = tool as any;
+ GestureOverlay.Instance.InkShape = undefined;
+ }
}
} else {
Doc.ActiveTool = InkTool.None;