@tldraw/editor 3.15.0 → 3.16.0-canary.01f62b6d4455
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.d.ts +185 -9
- package/dist-cjs/index.js +5 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +3 -1
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +0 -5
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +4 -26
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultScribble.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultScribble.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +9 -1
- package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js +53 -0
- package/dist-cjs/lib/components/default-components/DefaultShapeWrapper.js.map +7 -0
- package/dist-cjs/lib/config/TLUserPreferences.js +9 -3
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +110 -59
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +9 -4
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/types/misc-types.js.map +1 -1
- package/dist-cjs/lib/exports/getSvgJsx.js +1 -2
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -20
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js +2 -0
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/useStateAttribute.js +35 -0
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
- package/dist-cjs/lib/license/Watermark.js +6 -6
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- package/dist-cjs/lib/options.js +7 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/utils/EditorAtom.js +45 -0
- package/dist-cjs/lib/utils/EditorAtom.js.map +7 -0
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +185 -9
- package/dist-esm/index.mjs +7 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +3 -1
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +0 -5
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +4 -26
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultScribble.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +9 -1
- package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs +23 -0
- package/dist-esm/lib/components/default-components/DefaultShapeWrapper.mjs.map +7 -0
- package/dist-esm/lib/config/TLUserPreferences.mjs +9 -3
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +110 -59
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +9 -4
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +25 -21
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs +4 -0
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useStateAttribute.mjs +15 -0
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
- package/dist-esm/lib/license/Watermark.mjs +6 -6
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- package/dist-esm/lib/options.mjs +7 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/utils/EditorAtom.mjs +25 -0
- package/dist-esm/lib/utils/EditorAtom.mjs.map +7 -0
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +297 -311
- package/package.json +12 -36
- package/src/index.ts +7 -0
- package/src/lib/TldrawEditor.tsx +7 -5
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/Shape.tsx +6 -21
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/components/default-components/DefaultScribble.tsx +1 -1
- package/src/lib/components/default-components/DefaultShapeIndicator.tsx +5 -1
- package/src/lib/components/default-components/DefaultShapeWrapper.tsx +35 -0
- package/src/lib/config/TLUserPreferences.ts +8 -1
- package/src/lib/editor/Editor.test.ts +12 -11
- package/src/lib/editor/Editor.ts +141 -82
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +15 -14
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +16 -15
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +49 -48
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +24 -23
- package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +7 -6
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.test.ts +12 -11
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +57 -50
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +51 -26
- package/src/lib/editor/managers/TickManager/TickManager.test.ts +14 -13
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +34 -26
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +6 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +57 -0
- package/src/lib/editor/types/misc-types.ts +73 -1
- package/src/lib/exports/getSvgJsx.tsx +2 -2
- package/src/lib/hooks/useCanvasEvents.ts +39 -32
- package/src/lib/hooks/useEditorComponents.tsx +7 -1
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/lib/license/LicenseManager.test.ts +3 -1
- package/src/lib/license/Watermark.test.tsx +2 -1
- package/src/lib/license/Watermark.tsx +6 -6
- package/src/lib/options.ts +8 -0
- package/src/lib/utils/EditorAtom.ts +37 -0
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
- package/src/version.ts +3 -3
|
@@ -45,7 +45,8 @@ const userTypeValidator = import_validate.T.object({
|
|
|
45
45
|
isSnapMode: import_validate.T.boolean.nullable().optional(),
|
|
46
46
|
isWrapMode: import_validate.T.boolean.nullable().optional(),
|
|
47
47
|
isDynamicSizeMode: import_validate.T.boolean.nullable().optional(),
|
|
48
|
-
isPasteAtCursorMode: import_validate.T.boolean.nullable().optional()
|
|
48
|
+
isPasteAtCursorMode: import_validate.T.boolean.nullable().optional(),
|
|
49
|
+
showUiLabels: import_validate.T.boolean.nullable().optional()
|
|
49
50
|
});
|
|
50
51
|
const Versions = {
|
|
51
52
|
AddAnimationSpeed: 1,
|
|
@@ -56,7 +57,8 @@ const Versions = {
|
|
|
56
57
|
AddDynamicSizeMode: 6,
|
|
57
58
|
AllowSystemColorScheme: 7,
|
|
58
59
|
AddPasteAtCursor: 8,
|
|
59
|
-
AddKeyboardShortcuts: 9
|
|
60
|
+
AddKeyboardShortcuts: 9,
|
|
61
|
+
AddShowUiLabels: 10
|
|
60
62
|
};
|
|
61
63
|
const CURRENT_VERSION = Math.max(...Object.values(Versions));
|
|
62
64
|
function migrateSnapshot(data) {
|
|
@@ -91,6 +93,9 @@ function migrateSnapshot(data) {
|
|
|
91
93
|
if (data.version < Versions.AddKeyboardShortcuts) {
|
|
92
94
|
data.user.areKeyboardShortcutsEnabled = true;
|
|
93
95
|
}
|
|
96
|
+
if (data.version < Versions.AddShowUiLabels) {
|
|
97
|
+
data.user.showUiLabels = false;
|
|
98
|
+
}
|
|
94
99
|
data.version = CURRENT_VERSION;
|
|
95
100
|
}
|
|
96
101
|
const USER_COLORS = [
|
|
@@ -111,7 +116,7 @@ function getRandomColor() {
|
|
|
111
116
|
return USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)];
|
|
112
117
|
}
|
|
113
118
|
function userPrefersReducedMotion() {
|
|
114
|
-
if (typeof window !== "undefined" &&
|
|
119
|
+
if (typeof window !== "undefined" && window.matchMedia) {
|
|
115
120
|
return window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches ?? false;
|
|
116
121
|
}
|
|
117
122
|
return false;
|
|
@@ -128,6 +133,7 @@ const defaultUserPreferences = Object.freeze({
|
|
|
128
133
|
isWrapMode: false,
|
|
129
134
|
isDynamicSizeMode: false,
|
|
130
135
|
isPasteAtCursorMode: false,
|
|
136
|
+
showUiLabels: false,
|
|
131
137
|
colorScheme: "light"
|
|
132
138
|
});
|
|
133
139
|
function getFreshUserPreferences() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/config/TLUserPreferences.ts"],
|
|
4
|
-
"sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getDefaultTranslationLocale } from '@tldraw/tlschema'\nimport { getFromLocalStorage, setInLocalStorage, structuredClone, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\n\nconst USER_DATA_KEY = 'TLDRAW_USER_DATA_v3'\n\n/**\n * A user of tldraw\n *\n * @public\n */\nexport interface TLUserPreferences {\n\tid: string\n\tname?: string | null\n\tcolor?: string | null\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale?: string | null\n\tanimationSpeed?: number | null\n\tareKeyboardShortcutsEnabled?: boolean | null\n\tedgeScrollSpeed?: number | null\n\tcolorScheme?: 'light' | 'dark' | 'system'\n\tisSnapMode?: boolean | null\n\tisWrapMode?: boolean | null\n\tisDynamicSizeMode?: boolean | null\n\tisPasteAtCursorMode?: boolean | null\n}\n\ninterface UserDataSnapshot {\n\tversion: number\n\tuser: TLUserPreferences\n}\n\ninterface UserChangeBroadcastMessage {\n\ttype: typeof broadcastEventKey\n\torigin: string\n\tdata: UserDataSnapshot\n}\n\n/** @public */\nexport const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUserPreferences>({\n\tid: T.string,\n\tname: T.string.nullable().optional(),\n\tcolor: T.string.nullable().optional(),\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale: T.string.nullable().optional(),\n\tanimationSpeed: T.number.nullable().optional(),\n\tareKeyboardShortcutsEnabled: T.boolean.nullable().optional(),\n\tedgeScrollSpeed: T.number.nullable().optional(),\n\tcolorScheme: T.literalEnum('light', 'dark', 'system').optional(),\n\tisSnapMode: T.boolean.nullable().optional(),\n\tisWrapMode: T.boolean.nullable().optional(),\n\tisDynamicSizeMode: T.boolean.nullable().optional(),\n\tisPasteAtCursorMode: T.boolean.nullable().optional(),\n})\n\nconst Versions = {\n\tAddAnimationSpeed: 1,\n\tAddIsSnapMode: 2,\n\tMakeFieldsNullable: 3,\n\tAddEdgeScrollSpeed: 4,\n\tAddExcalidrawSelectMode: 5,\n\tAddDynamicSizeMode: 6,\n\tAllowSystemColorScheme: 7,\n\tAddPasteAtCursor: 8,\n\tAddKeyboardShortcuts: 9,\n} as const\n\nconst CURRENT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrateSnapshot(data: { version: number; user: any }) {\n\tif (data.version < Versions.AddAnimationSpeed) {\n\t\tdata.user.animationSpeed = 1\n\t}\n\tif (data.version < Versions.AddIsSnapMode) {\n\t\tdata.user.isSnapMode = false\n\t}\n\tif (data.version < Versions.MakeFieldsNullable) {\n\t\t// noop\n\t}\n\tif (data.version < Versions.AddEdgeScrollSpeed) {\n\t\tdata.user.edgeScrollSpeed = 1\n\t}\n\tif (data.version < Versions.AddExcalidrawSelectMode) {\n\t\tdata.user.isWrapMode = false\n\t}\n\tif (data.version < Versions.AllowSystemColorScheme) {\n\t\tif (data.user.isDarkMode === true) {\n\t\t\tdata.user.colorScheme = 'dark'\n\t\t} else if (data.user.isDarkMode === false) {\n\t\t\tdata.user.colorScheme = 'light'\n\t\t}\n\t\tdelete data.user.isDarkMode\n\t}\n\n\tif (data.version < Versions.AddDynamicSizeMode) {\n\t\tdata.user.isDynamicSizeMode = false\n\t}\n\tif (data.version < Versions.AddPasteAtCursor) {\n\t\tdata.user.isPasteAtCursorMode = false\n\t}\n\tif (data.version < Versions.AddKeyboardShortcuts) {\n\t\tdata.user.areKeyboardShortcutsEnabled = true\n\t}\n\n\t// finally\n\tdata.version = CURRENT_VERSION\n}\n\n/** @internal */\nexport const USER_COLORS = [\n\t'#FF802B',\n\t'#EC5E41',\n\t'#F2555A',\n\t'#F04F88',\n\t'#E34BA9',\n\t'#BD54C6',\n\t'#9D5BD2',\n\t'#7B66DC',\n\t'#02B1CC',\n\t'#11B3A3',\n\t'#39B178',\n\t'#55B467',\n] as const\n\nfunction getRandomColor() {\n\treturn USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)]\n}\n\n/** @internal */\nexport function userPrefersReducedMotion() {\n\tif (typeof window !== 'undefined' &&
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqB;AACrB,sBAA4C;AAC5C,mBAAkF;AAClF,sBAAkB;AAElB,MAAM,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import { atom } from '@tldraw/state'\nimport { getDefaultTranslationLocale } from '@tldraw/tlschema'\nimport { getFromLocalStorage, setInLocalStorage, structuredClone, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\n\nconst USER_DATA_KEY = 'TLDRAW_USER_DATA_v3'\n\n/**\n * A user of tldraw\n *\n * @public\n */\nexport interface TLUserPreferences {\n\tid: string\n\tname?: string | null\n\tcolor?: string | null\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale?: string | null\n\tanimationSpeed?: number | null\n\tareKeyboardShortcutsEnabled?: boolean | null\n\tedgeScrollSpeed?: number | null\n\tcolorScheme?: 'light' | 'dark' | 'system'\n\tisSnapMode?: boolean | null\n\tisWrapMode?: boolean | null\n\tisDynamicSizeMode?: boolean | null\n\tisPasteAtCursorMode?: boolean | null\n\tshowUiLabels?: boolean | null\n}\n\ninterface UserDataSnapshot {\n\tversion: number\n\tuser: TLUserPreferences\n}\n\ninterface UserChangeBroadcastMessage {\n\ttype: typeof broadcastEventKey\n\torigin: string\n\tdata: UserDataSnapshot\n}\n\n/** @public */\nexport const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUserPreferences>({\n\tid: T.string,\n\tname: T.string.nullable().optional(),\n\tcolor: T.string.nullable().optional(),\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tlocale: T.string.nullable().optional(),\n\tanimationSpeed: T.number.nullable().optional(),\n\tareKeyboardShortcutsEnabled: T.boolean.nullable().optional(),\n\tedgeScrollSpeed: T.number.nullable().optional(),\n\tcolorScheme: T.literalEnum('light', 'dark', 'system').optional(),\n\tisSnapMode: T.boolean.nullable().optional(),\n\tisWrapMode: T.boolean.nullable().optional(),\n\tisDynamicSizeMode: T.boolean.nullable().optional(),\n\tisPasteAtCursorMode: T.boolean.nullable().optional(),\n\tshowUiLabels: T.boolean.nullable().optional(),\n})\n\nconst Versions = {\n\tAddAnimationSpeed: 1,\n\tAddIsSnapMode: 2,\n\tMakeFieldsNullable: 3,\n\tAddEdgeScrollSpeed: 4,\n\tAddExcalidrawSelectMode: 5,\n\tAddDynamicSizeMode: 6,\n\tAllowSystemColorScheme: 7,\n\tAddPasteAtCursor: 8,\n\tAddKeyboardShortcuts: 9,\n\tAddShowUiLabels: 10,\n} as const\n\nconst CURRENT_VERSION = Math.max(...Object.values(Versions))\n\nfunction migrateSnapshot(data: { version: number; user: any }) {\n\tif (data.version < Versions.AddAnimationSpeed) {\n\t\tdata.user.animationSpeed = 1\n\t}\n\tif (data.version < Versions.AddIsSnapMode) {\n\t\tdata.user.isSnapMode = false\n\t}\n\tif (data.version < Versions.MakeFieldsNullable) {\n\t\t// noop\n\t}\n\tif (data.version < Versions.AddEdgeScrollSpeed) {\n\t\tdata.user.edgeScrollSpeed = 1\n\t}\n\tif (data.version < Versions.AddExcalidrawSelectMode) {\n\t\tdata.user.isWrapMode = false\n\t}\n\tif (data.version < Versions.AllowSystemColorScheme) {\n\t\tif (data.user.isDarkMode === true) {\n\t\t\tdata.user.colorScheme = 'dark'\n\t\t} else if (data.user.isDarkMode === false) {\n\t\t\tdata.user.colorScheme = 'light'\n\t\t}\n\t\tdelete data.user.isDarkMode\n\t}\n\n\tif (data.version < Versions.AddDynamicSizeMode) {\n\t\tdata.user.isDynamicSizeMode = false\n\t}\n\tif (data.version < Versions.AddPasteAtCursor) {\n\t\tdata.user.isPasteAtCursorMode = false\n\t}\n\tif (data.version < Versions.AddKeyboardShortcuts) {\n\t\tdata.user.areKeyboardShortcutsEnabled = true\n\t}\n\tif (data.version < Versions.AddShowUiLabels) {\n\t\tdata.user.showUiLabels = false\n\t}\n\n\t// finally\n\tdata.version = CURRENT_VERSION\n}\n\n/** @internal */\nexport const USER_COLORS = [\n\t'#FF802B',\n\t'#EC5E41',\n\t'#F2555A',\n\t'#F04F88',\n\t'#E34BA9',\n\t'#BD54C6',\n\t'#9D5BD2',\n\t'#7B66DC',\n\t'#02B1CC',\n\t'#11B3A3',\n\t'#39B178',\n\t'#55B467',\n] as const\n\nfunction getRandomColor() {\n\treturn USER_COLORS[Math.floor(Math.random() * USER_COLORS.length)]\n}\n\n/** @internal */\nexport function userPrefersReducedMotion() {\n\tif (typeof window !== 'undefined' && window.matchMedia) {\n\t\treturn window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false\n\t}\n\n\treturn false\n}\n\n/** @public */\nexport const defaultUserPreferences = Object.freeze({\n\tname: '',\n\tlocale: getDefaultTranslationLocale(),\n\tcolor: getRandomColor(),\n\n\t// N.B. These are duplicated in TLdrawAppUser.\n\tedgeScrollSpeed: 1,\n\tanimationSpeed: userPrefersReducedMotion() ? 0 : 1,\n\tareKeyboardShortcutsEnabled: true,\n\tisSnapMode: false,\n\tisWrapMode: false,\n\tisDynamicSizeMode: false,\n\tisPasteAtCursorMode: false,\n\tshowUiLabels: false,\n\tcolorScheme: 'light',\n}) satisfies Readonly<Omit<TLUserPreferences, 'id'>>\n\n/** @public */\nexport function getFreshUserPreferences(): TLUserPreferences {\n\treturn {\n\t\tid: uniqueId(),\n\t\tcolor: getRandomColor(),\n\t}\n}\n\nfunction migrateUserPreferences(userData: unknown): TLUserPreferences {\n\tif (userData === null || typeof userData !== 'object') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tif (!('version' in userData) || !('user' in userData) || typeof userData.version !== 'number') {\n\t\treturn getFreshUserPreferences()\n\t}\n\n\tconst snapshot = structuredClone(userData) as any\n\n\tmigrateSnapshot(snapshot)\n\n\ttry {\n\t\treturn userTypeValidator.validate(snapshot.user)\n\t} catch {\n\t\treturn getFreshUserPreferences()\n\t}\n}\n\nfunction loadUserPreferences(): TLUserPreferences {\n\tconst userData = (JSON.parse(getFromLocalStorage(USER_DATA_KEY) || 'null') ??\n\t\tnull) as null | UserDataSnapshot\n\n\treturn migrateUserPreferences(userData)\n}\n\nconst globalUserPreferences = atom<TLUserPreferences | null>('globalUserData', null)\n\nfunction storeUserPreferences() {\n\tsetInLocalStorage(\n\t\tUSER_DATA_KEY,\n\t\tJSON.stringify({\n\t\t\tversion: CURRENT_VERSION,\n\t\t\tuser: globalUserPreferences.get(),\n\t\t})\n\t)\n}\n\n/** @public */\nexport function setUserPreferences(user: TLUserPreferences) {\n\tuserTypeValidator.validate(user)\n\tglobalUserPreferences.set(user)\n\tstoreUserPreferences()\n\tbroadcastUserPreferencesChange()\n}\n\nconst isTest = typeof process !== 'undefined' && process.env.NODE_ENV === 'test'\n\nconst channel =\n\ttypeof BroadcastChannel !== 'undefined' && !isTest\n\t\t? new BroadcastChannel('tldraw-user-sync')\n\t\t: null\n\nchannel?.addEventListener('message', (e) => {\n\tconst data = e.data as undefined | UserChangeBroadcastMessage\n\tif (data?.type === broadcastEventKey && data?.origin !== getBroadcastOrigin()) {\n\t\tglobalUserPreferences.set(migrateUserPreferences(data.data))\n\t}\n})\n\nlet _broadcastOrigin = null as null | string\nfunction getBroadcastOrigin() {\n\tif (_broadcastOrigin === null) {\n\t\t_broadcastOrigin = uniqueId()\n\t}\n\treturn _broadcastOrigin\n}\nconst broadcastEventKey = 'tldraw-user-preferences-change' as const\n\nfunction broadcastUserPreferencesChange() {\n\tchannel?.postMessage({\n\t\ttype: broadcastEventKey,\n\t\torigin: getBroadcastOrigin(),\n\t\tdata: {\n\t\t\tuser: getUserPreferences(),\n\t\t\tversion: CURRENT_VERSION,\n\t\t},\n\t} satisfies UserChangeBroadcastMessage)\n}\n\n/** @public */\nexport function getUserPreferences(): TLUserPreferences {\n\tlet prefs = globalUserPreferences.get()\n\tif (!prefs) {\n\t\tprefs = loadUserPreferences()\n\t\tsetUserPreferences(prefs)\n\t}\n\treturn prefs\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2323,28 +2323,11 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2323
2323
|
{ history: "ignore" }
|
|
2324
2324
|
);
|
|
2325
2325
|
const { currentScreenPoint, currentPagePoint } = this.inputs;
|
|
2326
|
-
const { screenBounds } = this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID);
|
|
2327
2326
|
if (currentScreenPoint.x / z - x !== currentPagePoint.x || currentScreenPoint.y / z - y !== currentPagePoint.y) {
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
// weird but true: we need to put the screen point back into client space
|
|
2333
|
-
point: import_Vec.Vec.AddXY(currentScreenPoint, screenBounds.x, screenBounds.y),
|
|
2334
|
-
pointerId: import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE,
|
|
2335
|
-
ctrlKey: this.inputs.ctrlKey,
|
|
2336
|
-
altKey: this.inputs.altKey,
|
|
2337
|
-
shiftKey: this.inputs.shiftKey,
|
|
2338
|
-
metaKey: this.inputs.metaKey,
|
|
2339
|
-
accelKey: (0, import_keyboard.isAccelKey)(this.inputs),
|
|
2340
|
-
button: 0,
|
|
2341
|
-
isPen: this.getInstanceState().isPenMode ?? false
|
|
2342
|
-
};
|
|
2343
|
-
if (opts?.immediate) {
|
|
2344
|
-
this._flushEventForTick(event);
|
|
2345
|
-
} else {
|
|
2346
|
-
this.dispatch(event);
|
|
2347
|
-
}
|
|
2327
|
+
this.updatePointer({
|
|
2328
|
+
immediate: opts?.immediate,
|
|
2329
|
+
pointerId: import_constants.INTERNAL_POINTER_IDS.CAMERA_MOVE
|
|
2330
|
+
});
|
|
2348
2331
|
}
|
|
2349
2332
|
this._tickCameraState();
|
|
2350
2333
|
});
|
|
@@ -3313,19 +3296,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3313
3296
|
*/
|
|
3314
3297
|
deletePage(page) {
|
|
3315
3298
|
const id = typeof page === "string" ? page : page.id;
|
|
3316
|
-
this.run(
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3299
|
+
this.run(
|
|
3300
|
+
() => {
|
|
3301
|
+
if (this.getIsReadonly()) return;
|
|
3302
|
+
const pages = this.getPages();
|
|
3303
|
+
if (pages.length === 1) return;
|
|
3304
|
+
const deletedPage = this.getPage(id);
|
|
3305
|
+
if (!deletedPage) return;
|
|
3306
|
+
if (id === this.getCurrentPageId()) {
|
|
3307
|
+
const index = pages.findIndex((page2) => page2.id === id);
|
|
3308
|
+
const next = pages[index - 1] ?? pages[index + 1];
|
|
3309
|
+
this.setCurrentPage(next.id);
|
|
3310
|
+
}
|
|
3311
|
+
const shapes = this.getSortedChildIdsForParent(deletedPage.id);
|
|
3312
|
+
this.deleteShapes(shapes);
|
|
3313
|
+
this.store.remove([deletedPage.id]);
|
|
3314
|
+
},
|
|
3315
|
+
{ ignoreShapeLock: true }
|
|
3316
|
+
);
|
|
3329
3317
|
return this;
|
|
3330
3318
|
}
|
|
3331
3319
|
/**
|
|
@@ -3922,6 +3910,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3922
3910
|
hitInside = false,
|
|
3923
3911
|
hitFrameInside = false
|
|
3924
3912
|
} = opts;
|
|
3913
|
+
const [innerMargin, outerMargin] = Array.isArray(margin) ? margin : [margin, margin];
|
|
3925
3914
|
let inHollowSmallestArea = Infinity;
|
|
3926
3915
|
let inHollowSmallestAreaHit = null;
|
|
3927
3916
|
let inMarginClosestToEdgeDistance = Infinity;
|
|
@@ -3931,7 +3920,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3931
3920
|
return false;
|
|
3932
3921
|
const pageMask = this.getShapeMask(shape);
|
|
3933
3922
|
if (pageMask && !(0, import_utils2.pointInPolygon)(point, pageMask)) return false;
|
|
3934
|
-
if (filter
|
|
3923
|
+
if (filter && !filter(shape)) return false;
|
|
3935
3924
|
return true;
|
|
3936
3925
|
});
|
|
3937
3926
|
for (let i = shapesToCheck.length - 1; i >= 0; i--) {
|
|
@@ -3939,7 +3928,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3939
3928
|
const geometry = this.getShapeGeometry(shape);
|
|
3940
3929
|
const isGroup = geometry instanceof import_Group2d.Group2d;
|
|
3941
3930
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
3942
|
-
if (this.isShapeOfType(shape, "frame") || this.isShapeOfType(shape, "
|
|
3931
|
+
if (this.isShapeOfType(shape, "frame") || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && this.getShapeUtil(shape).getText(shape)?.trim()) {
|
|
3943
3932
|
for (const childGeometry of geometry.children) {
|
|
3944
3933
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
3945
3934
|
return shape;
|
|
@@ -3947,8 +3936,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3947
3936
|
}
|
|
3948
3937
|
}
|
|
3949
3938
|
if (this.isShapeOfType(shape, "frame")) {
|
|
3950
|
-
const distance2 = geometry.distanceToPoint(pointInShapeSpace,
|
|
3951
|
-
if (
|
|
3939
|
+
const distance2 = geometry.distanceToPoint(pointInShapeSpace, hitFrameInside);
|
|
3940
|
+
if (hitFrameInside ? distance2 > 0 && distance2 <= outerMargin || distance2 <= 0 && distance2 > -innerMargin : distance2 > 0 && distance2 <= outerMargin) {
|
|
3952
3941
|
return inMarginClosestToEdgeHit || shape;
|
|
3953
3942
|
}
|
|
3954
3943
|
if (geometry.hitTestPoint(pointInShapeSpace, 0, true)) {
|
|
@@ -3968,10 +3957,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3968
3957
|
}
|
|
3969
3958
|
distance = minDistance;
|
|
3970
3959
|
} else {
|
|
3971
|
-
if (
|
|
3960
|
+
if (outerMargin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
|
|
3972
3961
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
|
|
3973
3962
|
} else {
|
|
3974
|
-
if (geometry.bounds.containsPoint(pointInShapeSpace,
|
|
3963
|
+
if (geometry.bounds.containsPoint(pointInShapeSpace, outerMargin)) {
|
|
3975
3964
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside);
|
|
3976
3965
|
} else {
|
|
3977
3966
|
distance = Infinity;
|
|
@@ -3979,12 +3968,22 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3979
3968
|
}
|
|
3980
3969
|
}
|
|
3981
3970
|
if (geometry.isClosed) {
|
|
3982
|
-
if (distance <=
|
|
3971
|
+
if (distance <= outerMargin || hitInside && distance <= 0 && distance > -innerMargin) {
|
|
3983
3972
|
if (geometry.isFilled || isGroup && geometry.children[0].isFilled) {
|
|
3984
3973
|
return inMarginClosestToEdgeHit || shape;
|
|
3985
3974
|
} else {
|
|
3986
3975
|
if (this.getShapePageBounds(shape).contains(viewportPageBounds)) continue;
|
|
3987
|
-
if (
|
|
3976
|
+
if (hitInside ? (
|
|
3977
|
+
// On hitInside, the distance will be negative for hits inside
|
|
3978
|
+
// If the distance is positive, check against the outer margin
|
|
3979
|
+
distance > 0 && distance <= outerMargin || // If the distance is negative, check against the inner margin
|
|
3980
|
+
distance <= 0 && distance > -innerMargin
|
|
3981
|
+
) : (
|
|
3982
|
+
// If hitInside is false, then sadly _we do not know_ whether the
|
|
3983
|
+
// point is inside or outside of the shape, so we check against
|
|
3984
|
+
// the max of the two margins
|
|
3985
|
+
Math.abs(distance) <= Math.max(innerMargin, outerMargin)
|
|
3986
|
+
)) {
|
|
3988
3987
|
if (Math.abs(distance) < inMarginClosestToEdgeDistance) {
|
|
3989
3988
|
inMarginClosestToEdgeDistance = Math.abs(distance);
|
|
3990
3989
|
inMarginClosestToEdgeHit = shape;
|
|
@@ -4749,7 +4748,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
4749
4748
|
}
|
|
4750
4749
|
this.createShapes(shapesToCreate);
|
|
4751
4750
|
this.createBindings(bindingsToCreate);
|
|
4752
|
-
this.setSelectedShapes(
|
|
4751
|
+
this.setSelectedShapes(
|
|
4752
|
+
(0, import_utils.compact)(
|
|
4753
|
+
ids.map((oldId) => {
|
|
4754
|
+
const newId = shapeIds.get(oldId);
|
|
4755
|
+
if (!newId) return null;
|
|
4756
|
+
if (!this.getShape(newId)) return null;
|
|
4757
|
+
return newId;
|
|
4758
|
+
})
|
|
4759
|
+
)
|
|
4760
|
+
);
|
|
4753
4761
|
if (offset !== void 0) {
|
|
4754
4762
|
const selectionPageBounds = this.getSelectionPageBounds();
|
|
4755
4763
|
const viewportPageBounds = this.getViewportPageBounds();
|
|
@@ -5503,8 +5511,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5503
5511
|
const shapesMovingTogether = [shape];
|
|
5504
5512
|
const boundsOfShapesMovingTogether = [shapePageBounds];
|
|
5505
5513
|
if (!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
5506
|
-
type: "stretch"
|
|
5507
|
-
shapes: shapesToStretchFirstPass
|
|
5514
|
+
type: "stretch"
|
|
5508
5515
|
})) {
|
|
5509
5516
|
continue;
|
|
5510
5517
|
}
|
|
@@ -5829,21 +5836,24 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5829
5836
|
}
|
|
5830
5837
|
if (!partial.parentId || !(this.store.has(partial.parentId) || shapes.some((p) => p.id === partial.parentId))) {
|
|
5831
5838
|
let parentId = this.getFocusedGroupId();
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
parent
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5839
|
+
const isPositioned = partial.x !== void 0 && partial.y !== void 0;
|
|
5840
|
+
if (isPositioned) {
|
|
5841
|
+
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
5842
|
+
const parent = currentPageShapesSorted[i];
|
|
5843
|
+
const util = this.getShapeUtil(parent);
|
|
5844
|
+
if (util.canReceiveNewChildrenOfType(parent, partial.type) && !this.isShapeHidden(parent) && this.isPointInShape(
|
|
5845
|
+
parent,
|
|
5846
|
+
// If no parent is provided, then we can treat the
|
|
5847
|
+
// shape's provided x/y as being in the page's space.
|
|
5848
|
+
{ x: partial.x ?? 0, y: partial.y ?? 0 },
|
|
5849
|
+
{
|
|
5850
|
+
margin: 0,
|
|
5851
|
+
hitInside: true
|
|
5852
|
+
}
|
|
5853
|
+
)) {
|
|
5854
|
+
parentId = parent.id;
|
|
5855
|
+
break;
|
|
5843
5856
|
}
|
|
5844
|
-
)) {
|
|
5845
|
-
parentId = parent.id;
|
|
5846
|
-
break;
|
|
5847
5857
|
}
|
|
5848
5858
|
}
|
|
5849
5859
|
const prevParentId = partial.parentId;
|
|
@@ -7028,6 +7038,47 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7028
7038
|
this.dispatch({ type: "misc", name: "complete" });
|
|
7029
7039
|
return this;
|
|
7030
7040
|
}
|
|
7041
|
+
/**
|
|
7042
|
+
* Dispatch a pointer move event in the current position of the pointer. This is useful when
|
|
7043
|
+
* external circumstances have changed (e.g. the camera moved or a shape was moved) and you want
|
|
7044
|
+
* the current interaction to respond to that change.
|
|
7045
|
+
*
|
|
7046
|
+
* @example
|
|
7047
|
+
* ```ts
|
|
7048
|
+
* editor.updatePointer()
|
|
7049
|
+
* ```
|
|
7050
|
+
*
|
|
7051
|
+
* @param options - The options for updating the pointer.
|
|
7052
|
+
* @returns The editor instance.
|
|
7053
|
+
* @public
|
|
7054
|
+
*/
|
|
7055
|
+
updatePointer(options) {
|
|
7056
|
+
const event = {
|
|
7057
|
+
type: "pointer",
|
|
7058
|
+
target: "canvas",
|
|
7059
|
+
name: "pointer_move",
|
|
7060
|
+
point: options?.point ?? // weird but true: what `inputs` calls screen-space is actually viewport space. so
|
|
7061
|
+
// we need to convert back into true screen space first. we should fix this...
|
|
7062
|
+
import_Vec.Vec.Add(
|
|
7063
|
+
this.inputs.currentScreenPoint,
|
|
7064
|
+
this.store.unsafeGetWithoutCapture(import_tlschema.TLINSTANCE_ID).screenBounds
|
|
7065
|
+
),
|
|
7066
|
+
pointerId: options?.pointerId ?? 0,
|
|
7067
|
+
button: options?.button ?? 0,
|
|
7068
|
+
isPen: options?.isPen ?? this.inputs.isPen,
|
|
7069
|
+
shiftKey: options?.shiftKey ?? this.inputs.shiftKey,
|
|
7070
|
+
altKey: options?.altKey ?? this.inputs.altKey,
|
|
7071
|
+
ctrlKey: options?.ctrlKey ?? this.inputs.ctrlKey,
|
|
7072
|
+
metaKey: options?.metaKey ?? this.inputs.metaKey,
|
|
7073
|
+
accelKey: options?.accelKey ?? (0, import_keyboard.isAccelKey)(this.inputs)
|
|
7074
|
+
};
|
|
7075
|
+
if (options?.immediate) {
|
|
7076
|
+
this._flushEventForTick(event);
|
|
7077
|
+
} else {
|
|
7078
|
+
this.dispatch(event);
|
|
7079
|
+
}
|
|
7080
|
+
return this;
|
|
7081
|
+
}
|
|
7031
7082
|
/**
|
|
7032
7083
|
* Puts the editor into focused mode.
|
|
7033
7084
|
*
|