14a66956d7
* implement line editing * line editing with rotation * ensure adding new points is disabled on point dragging * fix hotkey replacement * don't paint bounding box when creating new multipoint * tweak points style, account for zoom and z-index * don't persist editingLinearElement to localStorage * don't mutate on noop points updates * account for rotation when adding new point * ensure clicking on points doesn't deselect element * tweak history handling around editingline element * update snapshots * refactor pointerMove handling * factor out point dragging * factor out pointerDown * improve positioning with rotation * revert to use roughjs for calculating points bounds * migrate from storing editingLinearElement.element to id * make GlobalScene.getElement into O(1) * use Alt for adding new points * fix adding and deleting a point with rotation * disable resize handlers & bounding box on line edit Co-authored-by: daishi <daishi@axlight.com>
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
import oc from "open-color";
|
|
import { AppState, FlooredNumber } from "./types";
|
|
import { getDateTime } from "./utils";
|
|
import { t } from "./i18n";
|
|
import { FontFamily } from "./element/types";
|
|
|
|
export const DEFAULT_FONT_SIZE = 20;
|
|
export const DEFAULT_FONT_FAMILY: FontFamily = 1;
|
|
export const DEFAULT_TEXT_ALIGN = "left";
|
|
|
|
export const getDefaultAppState = (): AppState => {
|
|
return {
|
|
isLoading: false,
|
|
errorMessage: null,
|
|
draggingElement: null,
|
|
resizingElement: null,
|
|
multiElement: null,
|
|
editingElement: null,
|
|
editingLinearElement: null,
|
|
elementType: "selection",
|
|
elementLocked: false,
|
|
exportBackground: true,
|
|
shouldAddWatermark: false,
|
|
currentItemStrokeColor: oc.black,
|
|
currentItemBackgroundColor: "transparent",
|
|
currentItemFillStyle: "hachure",
|
|
currentItemStrokeWidth: 1,
|
|
currentItemStrokeStyle: "solid",
|
|
currentItemRoughness: 1,
|
|
currentItemOpacity: 100,
|
|
currentItemFontSize: DEFAULT_FONT_SIZE,
|
|
currentItemFontFamily: DEFAULT_FONT_FAMILY,
|
|
currentItemTextAlign: DEFAULT_TEXT_ALIGN,
|
|
viewBackgroundColor: oc.white,
|
|
scrollX: 0 as FlooredNumber,
|
|
scrollY: 0 as FlooredNumber,
|
|
cursorX: 0,
|
|
cursorY: 0,
|
|
cursorButton: "up",
|
|
scrolledOutside: false,
|
|
name: `${t("labels.untitled")}-${getDateTime()}`,
|
|
username: "",
|
|
isCollaborating: false,
|
|
isResizing: false,
|
|
isRotating: false,
|
|
selectionElement: null,
|
|
zoom: 1,
|
|
openMenu: null,
|
|
lastPointerDownWith: "mouse",
|
|
selectedElementIds: {},
|
|
collaborators: new Map(),
|
|
shouldCacheIgnoreZoom: false,
|
|
showShortcutsDialog: false,
|
|
zenModeEnabled: false,
|
|
editingGroupId: null,
|
|
selectedGroupIds: {},
|
|
};
|
|
};
|
|
|
|
export const clearAppStateForLocalStorage = (appState: AppState) => {
|
|
const {
|
|
draggingElement,
|
|
resizingElement,
|
|
multiElement,
|
|
editingElement,
|
|
selectionElement,
|
|
isResizing,
|
|
isRotating,
|
|
collaborators,
|
|
isCollaborating,
|
|
isLoading,
|
|
errorMessage,
|
|
showShortcutsDialog,
|
|
editingLinearElement,
|
|
...exportedState
|
|
} = appState;
|
|
return exportedState;
|
|
};
|
|
|
|
export const cleanAppStateForExport = (appState: AppState) => {
|
|
return {
|
|
viewBackgroundColor: appState.viewBackgroundColor,
|
|
};
|
|
};
|