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.ts317
1 files changed, 166 insertions, 151 deletions
diff --git a/src/client/views/global/globalScripts.ts b/src/client/views/global/globalScripts.ts
index 6c3f4eaff..835c28daa 100644
--- a/src/client/views/global/globalScripts.ts
+++ b/src/client/views/global/globalScripts.ts
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
-import { Colors } from 'browndash-components';
+import { Colors } from '@dash/components';
import { runInAction } from 'mobx';
import { Doc, DocListCast, Opt, StrListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
-import { InkTool } from '../../../fields/InkField';
+import { InkEraserTool, InkInkTool, InkProperty, InkTool } from '../../../fields/InkField';
+import { List } from '../../../fields/List';
import { BoolCast, Cast, NumCast, StrCast } from '../../../fields/Types';
import { WebField } from '../../../fields/URLField';
import { Gestures } from '../../../pen-gestures/GestureTypes';
@@ -15,22 +16,20 @@ import { SnappingManager } from '../../util/SnappingManager';
import { UndoManager, undoable } from '../../util/UndoManager';
import { GestureOverlay } from '../GestureOverlay';
import { InkTranscription } from '../InkTranscription';
-import { InkingStroke } from '../InkingStroke';
-import { MainView } from '../MainView';
import { PropertiesView } from '../PropertiesView';
import { CollectionFreeFormView } from '../collections/collectionFreeForm';
import { CollectionFreeFormDocumentView } from '../nodes/CollectionFreeFormDocumentView';
import {
ActiveEraserWidth,
- ActiveFillColor,
+ ActiveInkFillColor,
ActiveInkColor,
- ActiveInkHideTextLabels,
+ ActiveHideTextLabels,
ActiveInkWidth,
ActiveIsInkMask,
DocumentView,
- SetActiveFillColor,
+ SetActiveInkFillColor,
SetActiveInkColor,
- SetActiveInkHideTextLabels,
+ SetactiveHideTextLabels,
SetActiveInkWidth,
SetActiveIsInkMask,
SetEraserWidth,
@@ -40,6 +39,8 @@ import { VideoBox } from '../nodes/VideoBox';
import { WebBox } from '../nodes/WebBox';
import { RichTextMenu } from '../nodes/formattedText/RichTextMenu';
import { GPTPopup, GPTPopupMode } from '../pdf/GPTPopup/GPTPopup';
+import { OpenWhere } from '../nodes/OpenWhere';
+import { docSortings } from '../collections/CollectionSubView';
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function IsNoneSelected() {
@@ -48,31 +49,85 @@ ScriptingGlobals.add(function IsNoneSelected() {
// toggle: Set overlay status of selected document
// eslint-disable-next-line prefer-arrow-callback
-ScriptingGlobals.add(function setView(view: string, getSelected: boolean) {
- if (getSelected) return DocumentView.SelectedDocs();
- const selected = DocumentView.SelectedDocs().lastElement();
- selected ? (selected._type_collection = view) : console.log('[FontIconBox.tsx] changeView failed');
+ScriptingGlobals.add(function setView(view: string, shiftKey: boolean, checkResult?: boolean) {
+ if (checkResult) return DocumentView.SelectedDocs();
+ const selected = DocumentView.Selected().lastElement();
+ if (selected) {
+ if (shiftKey) {
+ const newCol = Doc.MakeEmbedding(selected.Document);
+ newCol._type_collection = view;
+ selected._props.addDocTab?.(newCol, OpenWhere.addRight);
+ } else {
+ selected.Document._type_collection = view;
+ }
+ } else {
+ console.log('[FontIconBox.tsx] changeView failed');
+ }
return undefined;
});
// toggle: Set overlay status of selected document
// eslint-disable-next-line prefer-arrow-callback
-ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: boolean) {
+ScriptingGlobals.add(function setBorderColor(color?: string, checkResult?: boolean) {
const selectedViews = DocumentView.Selected();
- if (Doc.ActiveTool !== InkTool.None && !selectedViews.lastElement()?.Document._layout_isSvg) {
+ const defaultBorder = () => StrCast(Doc.UserDoc().borderColor, 'transparent');
+ const setDefaultBorder = (c: string) => { Doc.UserDoc().borderColor = c; }; // prettier-ignore
+ const fieldKey = 'borderColor';
+ if (selectedViews.length) {
+ if (checkResult) {
+ const selView = selectedViews.lastElement();
+ const layoutFrameNumber = Cast(selView.containerViewPath?.().lastElement()?.Document?._currentFrame, 'number'); // frame number that container is at which determines layout frame values
+ const contentFrameNumber = Cast(selView.Document?._currentFrame, 'number', layoutFrameNumber ?? null); // frame number that content is at which determines what content is displayed
+ return CollectionFreeFormDocumentView.getStringValues(selView?.Document, contentFrameNumber)[fieldKey] || defaultBorder();
+ }
+ setDefaultBorder(color ?? 'transparent');
+ selectedViews.forEach(dv => {
+ const layoutFrameNumber = Cast(dv.containerViewPath?.().lastElement()?.Document?._currentFrame, 'number'); // frame number that container is at which determines layout frame values
+ const contentFrameNumber = Cast(dv.Document?._currentFrame, 'number', layoutFrameNumber ?? null); // frame number that content is at which determines what content is displayed
+ if (contentFrameNumber !== undefined) {
+ const obj: { [key: string]: Opt<string> } = {};
+ obj[fieldKey] = color;
+ CollectionFreeFormDocumentView.setStringValues(contentFrameNumber, dv.Document, obj);
+ } else {
+ const dataKey = Doc.LayoutFieldKey(dv.Document);
+ const alternate = (dv.layoutDoc[dataKey + '_usePath'] ? '_' + dv.layoutDoc[dataKey + '_usePath'] : '').replace(':hover', '');
+ dv.layoutDoc[fieldKey + alternate] = undefined;
+ dv.dataDoc[fieldKey + alternate] = color;
+ }
+ });
+ } else {
+ const selected = DocumentView.SelectedDocs().length ? DocumentView.SelectedDocs() : LinkManager.Instance.currentLink ? [LinkManager.Instance.currentLink] : [];
if (checkResult) {
- return ActiveFillColor();
+ return (selected.lastElement() ?? Doc.UserDoc()).borderColor ?? defaultBorder();
}
- SetActiveFillColor(color ?? 'transparent');
+ if (!selected.length) setDefaultBorder(color ?? 'transparent');
+ else
+ selected.forEach(doc => {
+ doc[DocData].borderColor = color;
+ });
+ }
+ return '';
+});
+
+// toggle: Set overlay status of selected document
+// eslint-disable-next-line prefer-arrow-callback
+ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: boolean) {
+ const selectedViews = DocumentView.Selected();
+ const selectedDoc = selectedViews.lastElement()?.Document;
+ const defaultFill = selectedDoc?._layout_isSvg ? () => StrCast(selectedDoc[DocData].fillColor) : !Doc.ActiveTool || Doc.ActiveTool === InkTool.None ? () => StrCast(Doc.UserDoc().textBackgroundColor, 'transparent') : () => ActiveInkFillColor();
+ const setDefaultFill = !Doc.ActiveTool || Doc.ActiveTool === InkTool.None ? (c: string) => { Doc.UserDoc().textBackgroundColor = c; }: SetActiveInkFillColor; // prettier-ignore
+ if (Doc.ActiveTool !== InkTool.None && !selectedViews.lastElement()?.Document._layout_isSvg) {
+ if (checkResult) return defaultFill();
+ setDefaultFill(color ?? 'transparent');
} else if (selectedViews.length) {
if (checkResult) {
const selView = selectedViews.lastElement();
const fieldKey = selView.Document._layout_isSvg ? 'fillColor' : 'backgroundColor';
const layoutFrameNumber = Cast(selView.containerViewPath?.().lastElement()?.Document?._currentFrame, 'number'); // frame number that container is at which determines layout frame values
const contentFrameNumber = Cast(selView.Document?._currentFrame, 'number', layoutFrameNumber ?? null); // frame number that content is at which determines what content is displayed
- return CollectionFreeFormDocumentView.getStringValues(selView?.Document, contentFrameNumber)[fieldKey] ?? 'transparent';
+ return CollectionFreeFormDocumentView.getStringValues(selView?.Document, contentFrameNumber)[fieldKey] || defaultFill();
}
- selectedViews.some(dv => dv.ComponentView instanceof InkingStroke) && SetActiveFillColor(color ?? 'transparent');
+ !selectedViews.length && setDefaultFill(color ?? 'transparent');
selectedViews.forEach(dv => {
const fieldKey = dv.Document._layout_isSvg ? 'fillColor' : 'backgroundColor';
const layoutFrameNumber = Cast(dv.containerViewPath?.().lastElement()?.Document?._currentFrame, 'number'); // frame number that container is at which determines layout frame values
@@ -91,10 +146,13 @@ ScriptingGlobals.add(function setBackgroundColor(color?: string, checkResult?: b
} else {
const selected = DocumentView.SelectedDocs().length ? DocumentView.SelectedDocs() : LinkManager.Instance.currentLink ? [LinkManager.Instance.currentLink] : [];
if (checkResult) {
- return selected.lastElement()?._backgroundColor ?? 'transparent';
+ return selected.lastElement()?._backgroundColor ?? defaultFill();
}
- SetActiveFillColor(color ?? 'transparent');
- selected.forEach(doc => { doc[DocData].backgroundColor = color; }); // prettier-ignore
+ if (!selected.length) setDefaultFill(color ?? 'transparent');
+ else
+ selected.forEach(doc => {
+ doc[DocData][doc._layout_isSvg ? 'fillColor' : 'backgroundColor'] = color;
+ });
}
return '';
});
@@ -137,7 +195,7 @@ ScriptingGlobals.add(function toggleOverlay(checkResult?: boolean) {
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function showFreeform(
- attr: 'flashcards' | 'hcenter' | 'vcenter' | 'grid' | 'snaplines' | 'clusters' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'chat' | 'up' | 'down' | 'pile' | 'toggle-chat' | 'toggle-tags' | 'tag',
+ attr: 'flashcards' | 'hcenter' | 'vcenter' | 'grid' | 'snaplines' | 'clusters' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'chat' | 'reverse' | 'toggle-chat' | 'toggle-tags' | 'tag',
checkResult?: boolean,
persist?: boolean
) {
@@ -148,7 +206,7 @@ ScriptingGlobals.add(function showFreeform(
}
// prettier-ignore
- const map: Map<'flashcards' | 'hcenter' | 'vcenter' | 'grid' | 'snaplines' | 'clusters' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'chat' | 'up' | 'down' | 'pile' | 'toggle-chat' | 'toggle-tags' | 'tag',
+ const map: Map<'flashcards' | 'hcenter' | 'vcenter' | 'grid' | 'snaplines' | 'clusters' | 'viewAll' | 'fitOnce' | 'time' | 'docType' | 'color' | 'chat' | 'reverse'| 'toggle-chat' | 'toggle-tags' | 'tag',
{
waitForRender?: boolean;
checkResult: (doc: Doc) => boolean;
@@ -183,53 +241,36 @@ ScriptingGlobals.add(function showFreeform(
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),
- setDoc: (doc: Doc, dv: DocumentView) => { Doc.UserDoc().defaultToFlashcards = !Doc.UserDoc().defaultToFlashcards}, // prettier-ignore
- }],
['time', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "time",
- setDoc: (doc: Doc, dv: DocumentView) => { doc.cardSort === "time" ? doc.cardSort = '' : doc.cardSort = 'time'}, // prettier-ignore
+ checkResult: (doc: Doc) => StrCast(doc?.[Doc.LayoutFieldKey(doc)+"_sort"]) === "time",
+ setDoc: (doc: Doc, dv: DocumentView) => { doc[Doc.LayoutFieldKey(doc)+"_sort"] === "time" ? doc[Doc.LayoutFieldKey(doc)+"_sort"] = '' : doc[Doc.LayoutFieldKey(doc)+"_sort"] = docSortings.Time}, // prettier-ignore
}],
['docType', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "type",
- setDoc: (doc: Doc, dv: DocumentView) => { doc.cardSort === "type" ? doc.cardSort = '' : doc.cardSort = 'type'}, // prettier-ignore
+ checkResult: (doc: Doc) => StrCast(doc?.[Doc.LayoutFieldKey(doc)+"_sort"]) === "type",
+ setDoc: (doc: Doc, dv: DocumentView) => { doc[Doc.LayoutFieldKey(doc)+"_sort"] === "type" ? doc[Doc.LayoutFieldKey(doc)+"_sort"] = '' : doc[Doc.LayoutFieldKey(doc)+"_sort"] = docSortings.Type}, // prettier-ignore
}],
['color', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "color",
- setDoc: (doc: Doc, dv: DocumentView) => { doc.cardSort === "color" ? doc.cardSort = '' : doc.cardSort = 'color'}, // prettier-ignore
+ checkResult: (doc: Doc) => StrCast(doc?.[Doc.LayoutFieldKey(doc)+"_sort"]) === "color",
+ setDoc: (doc: Doc, dv: DocumentView) => { doc?.[Doc.LayoutFieldKey(doc)+"_sort"] === "color" ? doc[Doc.LayoutFieldKey(doc)+"_sort"] = '' : doc[Doc.LayoutFieldKey(doc)+"_sort"] = docSortings.Color}, // prettier-ignore
}],
['tag', {
- checkResult: (doc: Doc) => StrCast(doc?.cardSort) === "tag",
- setDoc: (doc: Doc, dv: DocumentView) => { doc.cardSort === "tag" ? doc.cardSort = '' : doc.cardSort = 'tag'}, // prettier-ignore
+ checkResult: (doc: Doc) => StrCast(doc?.[Doc.LayoutFieldKey(doc)+"_sort"]) === "tag",
+ setDoc: (doc: Doc, dv: DocumentView) => { doc[Doc.LayoutFieldKey(doc)+"_sort"] === "tag" ? doc[Doc.LayoutFieldKey(doc)+"_sort"] = '' : doc[Doc.LayoutFieldKey(doc)+"_sort"] = docSortings.Tag}, // prettier-ignore
}],
- ['up', {
- checkResult: (doc: Doc) => BoolCast(!doc?.cardSort_isDesc),
- setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort_isDesc = false;
- },
- }],
- ['down', {
- checkResult: (doc: Doc) => BoolCast(doc?.cardSort_isDesc),
- setDoc: (doc: Doc, dv: DocumentView) => {
- doc.cardSort_isDesc = true;
- },
+ ['reverse', {
+ checkResult: (doc: Doc) => BoolCast(doc?.[Doc.LayoutFieldKey(doc)+"_sort_reverse"]),
+ setDoc: (doc: Doc, dv: DocumentView) => { doc[Doc.LayoutFieldKey(doc)+"_sort_reverse"] = !doc[Doc.LayoutFieldKey(doc)+"_sort_reverse"]; },
}],
['toggle-chat', {
- checkResult: (doc: Doc) => GPTPopup.Instance.visible,
+ checkResult: (doc: Doc) => SnappingManager.ChatVisible,
setDoc: (doc: Doc, dv: DocumentView) => {
- if (GPTPopup.Instance.visible){
- doc.cardSort = ''
- GPTPopup.Instance.setVisible(false);
-
+ if (SnappingManager.ChatVisible){
+ doc[Doc.LayoutFieldKey(doc)+"_sort"] = '';
+ SnappingManager.SetChatVisible(false);
} else {
- GPTPopup.Instance.setVisible(true);
- GPTPopup.Instance.setMode(GPTPopupMode.CARD);
- GPTPopup.Instance.setCardsDoneLoading(true);
-
+ SnappingManager.SetChatVisible(true);
+ GPTPopup.Instance.setMode(GPTPopupMode.GPT_MENU);
}
-
-
},
}],
['toggle-tags', {
@@ -238,36 +279,6 @@ ScriptingGlobals.add(function showFreeform(
doc.showChildTags = !doc.showChildTags;
},
}],
- ['pile', {
- checkResult: (doc: Doc) => doc._type_collection == CollectionViewType.Freeform,
- setDoc: (doc: Doc, dv: DocumentView) => {
- 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]: string } = {
- 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) {
@@ -301,7 +312,7 @@ ScriptingGlobals.add(function setTagFilter(tag: string, added: boolean, checkRes
added ? Doc.setDocFilter(selected, 'tags', tag, 'check') : Doc.setDocFilter(selected, 'tags', tag, 'remove');
} else {
SnappingManager.PropertiesWidth < 5 && SnappingManager.SetPropertiesWidth(0);
- SnappingManager.SetPropertiesWidth(MainView.Instance.propertiesWidth() < 15 ? 250 : 0);
+ SnappingManager.SetPropertiesWidth(SnappingManager.PropertiesWidth < 15 ? 250 : 0);
PropertiesView.Instance?.CloseAll();
runInAction(() => (PropertiesView.Instance.openFilters = SnappingManager.PropertiesWidth > 5));
}
@@ -310,10 +321,10 @@ ScriptingGlobals.add(function setTagFilter(tag: string, added: boolean, checkRes
}, '');
// eslint-disable-next-line prefer-arrow-callback
-ScriptingGlobals.add(function setFontAttr(attr: 'font' | 'fontColor' | 'highlight' | 'fontSize' | 'alignment', value: string | number, checkResult?: boolean) {
+ScriptingGlobals.add(function setFontAttr(attr: 'font' | 'fontColor' | 'highlight' | 'fontSize', value: string | number, checkResult?: boolean) {
const editorView = RichTextMenu.Instance?.TextView?.EditorView;
// prettier-ignore
- const map: Map<'font'|'fontColor'|'highlight'|'fontSize'|'alignment', { checkResult: () => string | undefined; setDoc: () => void;}> = new Map([
+ const map: Map<'font'|'fontColor'|'highlight'|'fontSize', { checkResult: () => string | undefined; setDoc: () => void;}> = new Map([
['font', {
checkResult: () => RichTextMenu.Instance?.fontFamily,
setDoc: () => value && RichTextMenu.Instance?.setFontField(value.toString(), 'fontFamily'),
@@ -326,10 +337,6 @@ ScriptingGlobals.add(function setFontAttr(attr: 'font' | 'fontColor' | 'highligh
checkResult: () => RichTextMenu.Instance?.fontColor,
setDoc: () => value && RichTextMenu.Instance?.setFontField(value.toString(), 'fontColor'),
}],
- ['alignment', {
- checkResult: () => RichTextMenu.Instance?.textAlign,
- setDoc: () => { value && editorView?.state ? RichTextMenu.Instance?.align(editorView, editorView.dispatch, value.toString() as "center"|"left"|"right"):(Doc.UserDoc().textAlign = value); },
- }],
['fontSize', {
checkResult: () => RichTextMenu.Instance?.fontSize.replace('px', ''),
setDoc: () => {
@@ -349,7 +356,7 @@ ScriptingGlobals.add(function setFontAttr(attr: 'font' | 'fontColor' | 'highligh
return undefined;
});
-type attrname = 'noAutoLink' | 'dictation' | 'bold' | 'italics' | 'elide' | 'underline' | 'left' | 'center' | 'right' | 'vcent' | 'bullet' | 'decimal';
+type attrname = 'noAutoLink' | 'dictation' | 'fitBox' | 'bold' | 'italic' | 'elide' | 'underline' | 'left' | 'center' | 'right' | 'vcent' | 'bullet' | 'decimal';
type attrfuncs = [attrname, { checkResult: () => boolean; toggle?: () => unknown }];
// eslint-disable-next-line prefer-arrow-callback
@@ -358,14 +365,10 @@ ScriptingGlobals.add(function toggleCharStyle(charStyle: attrname, checkResult?:
const editorView = textView?.EditorView;
// prettier-ignore
const alignments:attrfuncs[] = (['left','right','center','vcent'] as ("left"|"center"|"right"|"vcent")[]).map((where) =>
- [ where, { checkResult: () => editorView ? (where === 'vcent' ? RichTextMenu.Instance?.textVcenter ?? false:
- (RichTextMenu.Instance?.textAlign === where)):
- where === 'vcent' ? BoolCast(Doc.UserDoc()._layout_centered):
- (Doc.UserDoc().textAlign === where),
- toggle: () => { editorView?.state ? (where === 'vcent' ? RichTextMenu.Instance?.vcenterToggle():
- RichTextMenu.Instance?.align(editorView, editorView.dispatch, where)):
- where === 'vcent' ? Doc.UserDoc()._layout_centered = !Doc.UserDoc()._layout_centered:
- (Doc.UserDoc().textAlign = where); }
+ [ where, { checkResult: () => (where === 'vcent' ? RichTextMenu.Instance?.textVcenter ?? false:
+ (RichTextMenu.Instance?.textAlign === where)),
+ toggle: () => { (where === 'vcent' ? RichTextMenu.Instance?.vcenterToggle():
+ RichTextMenu.Instance?.align(editorView, editorView?.dispatch, where)); }
}]); // prettier-ignore
// prettier-ignore
const listings:attrfuncs[] = (['bullet','decimal'] as attrname[]).map(list =>
@@ -375,16 +378,18 @@ ScriptingGlobals.add(function toggleCharStyle(charStyle: attrname, checkResult?:
const attrs:attrfuncs[] = [
['dictation', { checkResult: () => !!textView?._recordingDictation,
toggle: () => textView && runInAction(() => { textView._recordingDictation = !textView._recordingDictation;} ) }],
+ ['fitBox', { checkResult: () => RichTextMenu.Instance?.fitBox ?? false,
+ toggle: () => RichTextMenu.Instance?.toggleFitBox()}],
['elide', { checkResult: () => false,
toggle: () => editorView ? RichTextMenu.Instance?.elideSelection(): 0}],
['noAutoLink',{ checkResult: () => ((editorView && RichTextMenu.Instance?.noAutoLink) ?? false),
toggle: () => editorView && RichTextMenu.Instance?.toggleNoAutoLinkAnchor()}],
['bold', { checkResult: () => (editorView ? RichTextMenu.Instance?.bold??false : (Doc.UserDoc().fontWeight === 'bold')),
toggle: editorView ? RichTextMenu.Instance?.toggleBold : () => { Doc.UserDoc().fontWeight = Doc.UserDoc().fontWeight === 'bold' ? undefined : 'bold'; }}],
- ['italics', { checkResult: () => (editorView ? RichTextMenu.Instance?.italics ?? false : (Doc.UserDoc().fontStyle === 'italics')),
- toggle: editorView ? RichTextMenu.Instance?.toggleItalics : () => { Doc.UserDoc().fontStyle = Doc.UserDoc().fontStyle === 'italics' ? undefined : 'italics'; }}],
- ['underline', { checkResult: () => (editorView ? RichTextMenu.Instance?.underline ?? false: (Doc.UserDoc().textDecoration === 'underline')),
- toggle: editorView ? RichTextMenu.Instance?.toggleUnderline : () => { Doc.UserDoc().textDecoration = Doc.UserDoc().textDecoration === 'underline' ? undefined : 'underline'; } }]]
+ ['italic', { checkResult: () => (editorView ? RichTextMenu.Instance?.italic ?? false : (Doc.UserDoc().fontStyle === 'italic')),
+ toggle: editorView ? RichTextMenu.Instance?.toggleItalic : () => { Doc.UserDoc().fontStyle = Doc.UserDoc().fontStyle === 'italic' ? undefined : 'italic'; }}],
+ ['underline', { checkResult: () => (editorView ? RichTextMenu.Instance?.underline ?? false: (Doc.UserDoc().fontDecoration === 'underline')),
+ toggle: editorView ? RichTextMenu.Instance?.toggleUnderline : () => { Doc.UserDoc().fontDecoration = Doc.UserDoc().fontDecoration === 'underline' ? undefined : 'underline'; } }]]
const map = new Map(attrs.concat(alignments).concat(listings));
if (checkResult) {
@@ -394,43 +399,46 @@ ScriptingGlobals.add(function toggleCharStyle(charStyle: attrname, checkResult?:
return undefined;
});
-function setActiveTool(toolIn: InkTool | Gestures, keepPrim: boolean, checkResult?: boolean) {
+function setActiveTool(tool: InkTool | InkEraserTool | InkInkTool | Gestures, keepPrim: boolean, checkResult?: boolean) {
InkTranscription.Instance?.createInkGroup();
- const tool = toolIn === InkTool.Eraser ? Doc.UserDoc().activeEraserTool : toolIn;
if (checkResult) {
- return ((Doc.ActiveTool === tool || (Doc.UserDoc().activeEraserTool === tool && (tool === toolIn || Doc.ActiveTool === tool))) && !GestureOverlay.Instance?.InkShape) || GestureOverlay.Instance?.InkShape === tool
- ? GestureOverlay.Instance?.KeepPrimitiveMode || ![Gestures.Circle, Gestures.Line, Gestures.Rectangle].includes(tool as Gestures)
+ return Doc.ActiveTool === tool || Doc.ActiveEraser === tool || Doc.ActiveInk === tool || SnappingManager.InkShape === tool
+ ? true //SnappingManager.KeepGestureMode || ![Gestures.Circle, Gestures.Line, Gestures.Rectangle].includes(tool as Gestures)
: false;
}
runInAction(() => {
+ const eraserTool = tool === InkTool.Eraser ? Doc.ActiveEraser : [InkEraserTool.Stroke, InkEraserTool.Radius, InkEraserTool.Segment].includes(tool as InkEraserTool) ? (tool as InkEraserTool) : undefined;
+ const inkTool = tool === InkTool.Ink ? Doc.ActiveInk : [InkInkTool.Pen, InkInkTool.Write, InkInkTool.Highlight].includes(tool as InkInkTool) ? (tool as InkInkTool) : undefined;
if (GestureOverlay.Instance) {
- GestureOverlay.Instance.KeepPrimitiveMode = keepPrim;
+ SnappingManager.SetKeepGestureMode(keepPrim);
}
if (Object.values(Gestures).includes(tool as Gestures)) {
- if (GestureOverlay.Instance.InkShape === tool && !keepPrim) {
+ if (SnappingManager.InkShape === tool && !keepPrim) {
Doc.ActiveTool = InkTool.None;
- GestureOverlay.Instance.InkShape = undefined;
+ SnappingManager.SetInkShape(undefined);
} else {
- Doc.ActiveTool = InkTool.Pen;
- GestureOverlay.Instance.InkShape = tool as Gestures;
+ Doc.ActiveTool = InkTool.Ink;
+ SnappingManager.SetInkShape(tool as Gestures);
}
- } else if (tool) {
- if (Doc.UserDoc().ActiveTool === tool) {
+ } else if (eraserTool) {
+ if (Doc.ActiveTool === InkTool.Eraser && Doc.ActiveTool === tool) {
Doc.ActiveTool = InkTool.None;
} else {
- if ([InkTool.StrokeEraser, InkTool.RadiusEraser, InkTool.SegmentEraser].includes(tool as InkTool)) {
- Doc.UserDoc().activeEraserTool = tool;
- }
- // pen or eraser
- if (Doc.ActiveTool === tool && !GestureOverlay.Instance.InkShape && !keepPrim) {
- Doc.ActiveTool = InkTool.None;
- } else {
- Doc.ActiveTool = tool as InkTool;
- GestureOverlay.Instance.InkShape = undefined;
- }
+ Doc.ActiveEraser = eraserTool;
+ Doc.ActiveTool = InkTool.Eraser;
+ SnappingManager.SetInkShape(undefined);
+ }
+ } else if (inkTool) {
+ if (Doc.ActiveTool === InkTool.Ink && Doc.ActiveTool === tool) {
+ Doc.ActiveTool = InkTool.None;
+ } else {
+ Doc.ActiveInk = inkTool;
+ Doc.ActiveTool = InkTool.Ink;
+ SnappingManager.SetInkShape(undefined);
}
} else {
- Doc.ActiveTool = InkTool.None;
+ if ((Doc.ActiveTool === tool || !tool) && !keepPrim) Doc.ActiveTool = InkTool.None;
+ else Doc.ActiveTool = tool as InkTool;
}
});
return undefined;
@@ -440,44 +448,51 @@ ScriptingGlobals.add(setActiveTool, 'sets the active ink tool mode');
// eslint-disable-next-line prefer-arrow-callback
ScriptingGlobals.add(function activeEraserTool() {
- return StrCast(Doc.UserDoc().activeEraserTool, InkTool.StrokeEraser);
+ return StrCast(Doc.UserDoc().activeEraserTool, InkEraserTool.Stroke);
}, 'returns the current eraser tool');
+// eslint-disable-next-line prefer-arrow-callback
+ScriptingGlobals.add(function setBorderWidth(value: number, checkResult?: boolean) {
+ const selected = DocumentView.SelectedDocs().lastElement();
+ if (checkResult) return NumCast((selected ?? Doc.UserDoc()).borderWidth);
+ if (!selected) Doc.UserDoc().borderWidth = value;
+ else
+ DocumentView.SelectedDocs().map(doc => {
+ doc.borderWidth = value;
+ });
+ return undefined;
+}, 'sets the border width of the selected document');
+
// toggle: Set overlay status of selected document
// eslint-disable-next-line prefer-arrow-callback
-ScriptingGlobals.add(function setInkProperty(option: 'inkMask' | 'labels' | 'fillColor' | 'strokeWidth' | 'strokeColor' | 'eraserWidth', value: string | number, checkResult?: boolean) {
- const selected = DocumentView.SelectedDocs().lastElement() ?? Doc.UserDoc();
+ScriptingGlobals.add(function setInkProperty(option: InkProperty, value: string | number, checkResult?: boolean) {
+ const selected = DocumentView.SelectedDocs().lastElement();
// prettier-ignore
- const map: Map<'inkMask' | 'labels' | 'fillColor' | 'strokeWidth' | 'strokeColor' | 'eraserWidth', { checkResult: () => number|boolean|string|undefined; setInk: (doc: Doc) => void; setMode: () => void }> = new Map([
- ['inkMask', {
+ const map: Map<InkProperty, { checkResult: () => number|boolean|string|undefined; setInk: (doc: Doc) => void; setMode: () => void }> = new Map([
+ [InkProperty.Mask, {
checkResult: () => ((selected?._layout_isSvg ? BoolCast(selected[DocData].stroke_isInkMask) : ActiveIsInkMask())),
setInk: (doc: Doc) => { doc[DocData].stroke_isInkMask = !doc.stroke_isInkMask; },
- setMode: () => selected?.type !== DocumentType.INK && SetActiveIsInkMask(!ActiveIsInkMask()),
- }],
- ['labels', {
- checkResult: () => ((selected?._stroke_showLabel ? BoolCast(selected[DocData].stroke_showLabel) : ActiveInkHideTextLabels())),
- setInk: (doc: Doc) => { doc[DocData].stroke_showLabel = !doc.stroke_showLabel; },
- setMode: () => selected?.type !== DocumentType.INK && SetActiveInkHideTextLabels(!ActiveInkHideTextLabels()),
+ setMode: () => SetActiveIsInkMask(value ? true : false)
}],
- ['fillColor', {
- checkResult: () => (selected?._layout_isSvg ? StrCast(selected[DocData].fillColor) : ActiveFillColor() ?? "transparent"),
- setInk: (doc: Doc) => { doc[DocData].fillColor = StrCast(value); },
- setMode: () => SetActiveFillColor(StrCast(value)),
+ [InkProperty.Labels, {
+ checkResult: () => ((selected?._layout_isSvg ? BoolCast(selected[DocData].stroke_showLabel) : !ActiveHideTextLabels())),
+ setInk: (doc: Doc) => { doc[DocData].stroke_showLabel = value; },
+ setMode: () => SetactiveHideTextLabels(value? false : true),
}],
- [ 'strokeWidth', {
- checkResult: () => (selected?._layout_isSvg ? NumCast(selected[DocData].stroke_width) : ActiveInkWidth()),
+ [ InkProperty.StrokeWidth, {
+ checkResult: () => (selected?._layout_isSvg ? NumCast(selected[DocData].stroke_width, 1) : ActiveInkWidth()),
setInk: (doc: Doc) => { doc[DocData].stroke_width = NumCast(value); },
- setMode: () => { SetActiveInkWidth(value.toString()); selected?.type === DocumentType.INK && setActiveTool( GestureOverlay.Instance.InkShape ?? InkTool.Pen, true, false);},
+ setMode: () => SetActiveInkWidth(value.toString()),
}],
- ['strokeColor', {
+ [InkProperty.StrokeColor, {
checkResult: () => (selected?._layout_isSvg? StrCast(selected[DocData].color) : ActiveInkColor()),
setInk: (doc: Doc) => { doc[DocData].color = String(value); },
- setMode: () => { SetActiveInkColor(StrCast(value)); selected?.type === DocumentType.INK && setActiveTool(GestureOverlay.Instance.InkShape ?? InkTool.Pen, true, false);},
+ setMode: () => SetActiveInkColor(StrCast(value))
}],
- [ 'eraserWidth', {
+ [ InkProperty.EraserWidth, {
checkResult: () => ActiveEraserWidth() === 0 ? 1 : ActiveEraserWidth(),
setInk: (doc: Doc) => { },
- setMode: () => { SetEraserWidth(+value);},
+ setMode: () => SetEraserWidth(+value),
}]
]);