@tldraw/editor 3.16.0-next.f9f54ec051f3 → 4.0.0
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 +197 -114
- package/dist-cjs/index.js +5 -5
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +9 -9
- 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 +7 -10
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +14 -23
- package/dist-cjs/lib/components/default-components/DefaultCanvas.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/config/TLUserPreferences.js +21 -4
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +121 -138
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +4 -0
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +4 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +14 -4
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +23 -0
- 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 +35 -16
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +47 -38
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +5 -5
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js +1 -2
- package/dist-cjs/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useGestureEvents.js +1 -1
- package/dist-cjs/lib/hooks/useGestureEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useHandleEvents.js +6 -6
- package/dist-cjs/lib/hooks/useHandleEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughMouseOverEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +4 -1
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useSelectionEvents.js +8 -8
- package/dist-cjs/lib/hooks/useSelectionEvents.js.map +2 -2
- package/dist-cjs/lib/{utils/nearestMultiple.js → hooks/useStateAttribute.js} +15 -14
- package/dist-cjs/lib/hooks/useStateAttribute.js.map +7 -0
- package/dist-cjs/lib/license/LicenseManager.js +143 -53
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +39 -1
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +144 -75
- package/dist-cjs/lib/license/Watermark.js.map +3 -3
- package/dist-cjs/lib/license/useLicenseManagerState.js.map +2 -2
- package/dist-cjs/lib/options.js +7 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +3 -0
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +0 -4
- package/dist-cjs/lib/primitives/Vec.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +50 -20
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +8 -1
- package/dist-cjs/lib/primitives/geometry/Group2d.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/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js +2 -3
- package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +7 -36
- package/dist-cjs/lib/utils/reparenting.js.map +3 -3
- package/dist-cjs/version.js +4 -4
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +197 -114
- package/dist-esm/index.mjs +5 -5
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +9 -9
- 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 +7 -10
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +14 -23
- package/dist-esm/lib/components/default-components/DefaultCanvas.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/config/TLUserPreferences.mjs +21 -4
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +121 -138
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +4 -0
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +4 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +14 -4
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +23 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +36 -16
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +49 -45
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +6 -6
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +1 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs +2 -2
- package/dist-esm/lib/hooks/useGestureEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useHandleEvents.mjs +6 -6
- package/dist-esm/lib/hooks/useHandleEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughMouseOverEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +4 -1
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useSelectionEvents.mjs +9 -14
- package/dist-esm/lib/hooks/useSelectionEvents.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/LicenseManager.mjs +144 -54
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +39 -2
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +145 -76
- package/dist-esm/lib/license/Watermark.mjs.map +3 -3
- package/dist-esm/lib/license/useLicenseManagerState.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +7 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +4 -1
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +0 -4
- package/dist-esm/lib/primitives/Vec.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +53 -21
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +8 -1
- package/dist-esm/lib/primitives/geometry/Group2d.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/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs +2 -3
- package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +8 -41
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/version.mjs +4 -4
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +308 -290
- package/package.json +14 -37
- package/src/index.ts +4 -9
- package/src/lib/TldrawEditor.tsx +14 -21
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/Shape.tsx +6 -12
- package/src/lib/components/default-components/DefaultCanvas.tsx +11 -22
- 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/config/TLUserPreferences.ts +21 -1
- package/src/lib/editor/Editor.test.ts +102 -11
- package/src/lib/editor/Editor.ts +165 -198
- package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
- 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/FocusManager/FocusManager.ts +6 -2
- 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 +56 -26
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +13 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +46 -0
- package/src/lib/editor/types/misc-types.ts +54 -7
- package/src/lib/exports/getSvgJsx.test.ts +868 -0
- package/src/lib/exports/getSvgJsx.tsx +78 -21
- package/src/lib/hooks/useCanvasEvents.ts +62 -55
- package/src/lib/hooks/useDocumentEvents.ts +6 -6
- package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +1 -1
- package/src/lib/hooks/useGestureEvents.ts +2 -2
- package/src/lib/hooks/useHandleEvents.ts +6 -6
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/lib/hooks/useSelectionEvents.ts +9 -14
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/lib/license/LicenseManager.test.ts +724 -383
- package/src/lib/license/LicenseManager.ts +204 -58
- package/src/lib/license/LicenseProvider.tsx +74 -2
- package/src/lib/license/Watermark.test.tsx +2 -1
- package/src/lib/license/Watermark.tsx +152 -77
- package/src/lib/license/useLicenseManagerState.ts +2 -2
- package/src/lib/options.ts +8 -0
- package/src/lib/primitives/Box.test.ts +126 -0
- package/src/lib/primitives/Box.ts +10 -1
- package/src/lib/primitives/Vec.ts +0 -5
- package/src/lib/primitives/geometry/Geometry2d.test.ts +420 -0
- package/src/lib/primitives/geometry/Geometry2d.ts +78 -21
- package/src/lib/primitives/geometry/Group2d.ts +10 -1
- package/src/lib/test/InFrontOfTheCanvas.test.tsx +187 -0
- package/src/lib/utils/EditorAtom.ts +37 -0
- package/src/lib/utils/dom.test.ts +103 -0
- package/src/lib/utils/dom.ts +8 -1
- package/src/lib/utils/getPointerInfo.ts +3 -2
- package/src/lib/utils/reparenting.ts +10 -70
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +2 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +15 -15
- package/src/version.ts +4 -4
- package/dist-cjs/lib/utils/nearestMultiple.js.map +0 -7
- package/dist-esm/lib/utils/nearestMultiple.mjs +0 -14
- package/dist-esm/lib/utils/nearestMultiple.mjs.map +0 -7
- package/src/lib/utils/nearestMultiple.ts +0 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tldraw/editor",
|
|
3
3
|
"description": "tldraw infinite canvas SDK (editor).",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -34,27 +34,28 @@
|
|
|
34
34
|
"src"
|
|
35
35
|
],
|
|
36
36
|
"scripts": {
|
|
37
|
-
"test-ci": "
|
|
38
|
-
"test": "yarn run -T
|
|
37
|
+
"test-ci": "yarn run -T vitest run --passWithNoTests",
|
|
38
|
+
"test": "yarn run -T vitest --passWithNoTests",
|
|
39
39
|
"benchmark": "yarn run -T tsx ./internal/scripts/benchmark.ts",
|
|
40
|
-
"test-coverage": "
|
|
40
|
+
"test-coverage": "yarn run -T vitest run --coverage --passWithNoTests",
|
|
41
41
|
"build": "yarn run -T tsx ../../internal/scripts/build-package.ts",
|
|
42
42
|
"build-api": "yarn run -T tsx ../../internal/scripts/build-api.ts",
|
|
43
43
|
"prepack": "yarn run -T tsx ../../internal/scripts/prepack.ts",
|
|
44
44
|
"postpack": "../../internal/scripts/postpack.sh",
|
|
45
45
|
"pack-tarball": "yarn pack",
|
|
46
|
-
"lint": "yarn run -T tsx ../../internal/scripts/lint.ts"
|
|
46
|
+
"lint": "yarn run -T tsx ../../internal/scripts/lint.ts",
|
|
47
|
+
"context": "yarn run -T tsx ../../internal/scripts/context.ts"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"@tiptap/core": "^2.9.1",
|
|
50
51
|
"@tiptap/pm": "^2.9.1",
|
|
51
52
|
"@tiptap/react": "^2.9.1",
|
|
52
|
-
"@tldraw/state": "
|
|
53
|
-
"@tldraw/state-react": "
|
|
54
|
-
"@tldraw/store": "
|
|
55
|
-
"@tldraw/tlschema": "
|
|
56
|
-
"@tldraw/utils": "
|
|
57
|
-
"@tldraw/validate": "
|
|
53
|
+
"@tldraw/state": "4.0.0",
|
|
54
|
+
"@tldraw/state-react": "4.0.0",
|
|
55
|
+
"@tldraw/store": "4.0.0",
|
|
56
|
+
"@tldraw/tlschema": "4.0.0",
|
|
57
|
+
"@tldraw/utils": "4.0.0",
|
|
58
|
+
"@tldraw/validate": "4.0.0",
|
|
58
59
|
"@types/core-js": "^2.5.8",
|
|
59
60
|
"@use-gesture/react": "^10.3.1",
|
|
60
61
|
"classnames": "^2.5.1",
|
|
@@ -69,41 +70,17 @@
|
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@peculiar/webcrypto": "^1.5.0",
|
|
72
|
-
"@testing-library/jest-dom": "^5.17.0",
|
|
73
73
|
"@testing-library/react": "^15.0.7",
|
|
74
74
|
"@types/benchmark": "^2.1.5",
|
|
75
75
|
"@types/react": "^18.3.18",
|
|
76
76
|
"@types/wicg-file-system-access": "^2020.9.8",
|
|
77
77
|
"benchmark": "^2.1.4",
|
|
78
78
|
"fake-indexeddb": "^4.0.2",
|
|
79
|
-
"jest-canvas-mock": "^2.5.2",
|
|
80
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
81
79
|
"lazyrepo": "0.0.0-alpha.27",
|
|
82
80
|
"react": "^18.3.1",
|
|
83
81
|
"react-dom": "^18.3.1",
|
|
84
|
-
"resize-observer-polyfill": "^1.5.1"
|
|
85
|
-
|
|
86
|
-
"jest": {
|
|
87
|
-
"preset": "../../internal/config/jest/node/jest-preset.js",
|
|
88
|
-
"testEnvironment": "../../../packages/utils/patchedJestJsDom.js",
|
|
89
|
-
"fakeTimers": {
|
|
90
|
-
"enableGlobally": true
|
|
91
|
-
},
|
|
92
|
-
"testPathIgnorePatterns": [
|
|
93
|
-
"^.+\\.*.css$"
|
|
94
|
-
],
|
|
95
|
-
"moduleNameMapper": {
|
|
96
|
-
"^~(.*)": "<rootDir>/src/$1",
|
|
97
|
-
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
|
|
98
|
-
},
|
|
99
|
-
"setupFiles": [
|
|
100
|
-
"raf/polyfill",
|
|
101
|
-
"jest-canvas-mock",
|
|
102
|
-
"<rootDir>/setupTests.js"
|
|
103
|
-
],
|
|
104
|
-
"setupFilesAfterEnv": [
|
|
105
|
-
"../../internal/config/setupJest.ts"
|
|
106
|
-
]
|
|
82
|
+
"resize-observer-polyfill": "^1.5.1",
|
|
83
|
+
"vitest": "^3.2.4"
|
|
107
84
|
},
|
|
108
85
|
"module": "dist-esm/index.mjs",
|
|
109
86
|
"source": "src/index.ts",
|
package/src/index.ts
CHANGED
|
@@ -265,9 +265,9 @@ export {
|
|
|
265
265
|
type TLCameraMoveOptions,
|
|
266
266
|
type TLCameraOptions,
|
|
267
267
|
type TLExportType,
|
|
268
|
+
type TLGetShapeAtPointOptions,
|
|
268
269
|
type TLImageExportOptions,
|
|
269
270
|
type TLSvgExportOptions,
|
|
270
|
-
type TLSvgOptions,
|
|
271
271
|
type TLUpdatePointerOptions,
|
|
272
272
|
} from './lib/editor/types/misc-types'
|
|
273
273
|
export {
|
|
@@ -330,9 +330,11 @@ export {
|
|
|
330
330
|
type InvalidLicenseReason,
|
|
331
331
|
type LicenseFromKeyResult,
|
|
332
332
|
type LicenseInfo,
|
|
333
|
+
type LicenseState,
|
|
333
334
|
type TestEnvironment,
|
|
334
335
|
type ValidLicenseKeyResult,
|
|
335
336
|
} from './lib/license/LicenseManager'
|
|
337
|
+
export { LICENSE_TIMEOUT } from './lib/license/LicenseProvider'
|
|
336
338
|
export { defaultTldrawOptions, type TldrawOptions } from './lib/options'
|
|
337
339
|
export {
|
|
338
340
|
Box,
|
|
@@ -450,6 +452,7 @@ export {
|
|
|
450
452
|
setPointerCapture,
|
|
451
453
|
stopEventPropagation,
|
|
452
454
|
} from './lib/utils/dom'
|
|
455
|
+
export { EditorAtom } from './lib/utils/EditorAtom'
|
|
453
456
|
export { getIncrementedName } from './lib/utils/getIncrementedName'
|
|
454
457
|
export { getPointerInfo } from './lib/utils/getPointerInfo'
|
|
455
458
|
export { getSvgPathFromPoints } from './lib/utils/getSvgPathFromPoints'
|
|
@@ -483,14 +486,6 @@ export { type TLStoreWithStatus } from './lib/utils/sync/StoreWithStatus'
|
|
|
483
486
|
export { uniq } from './lib/utils/uniq'
|
|
484
487
|
export { openWindow } from './lib/utils/window-open'
|
|
485
488
|
|
|
486
|
-
/**
|
|
487
|
-
* @deprecated Licensing is now enabled in the tldraw SDK.
|
|
488
|
-
* @public */
|
|
489
|
-
export function debugEnableLicensing() {
|
|
490
|
-
// noop
|
|
491
|
-
return
|
|
492
|
-
}
|
|
493
|
-
|
|
494
489
|
registerTldrawLibraryVersion(
|
|
495
490
|
(globalThis as any).TLDRAW_LIBRARY_NAME,
|
|
496
491
|
(globalThis as any).TLDRAW_LIBRARY_VERSION,
|
package/src/lib/TldrawEditor.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MigrationSequence, Store } from '@tldraw/store'
|
|
2
2
|
import { TLShape, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'
|
|
3
|
-
import {
|
|
3
|
+
import { annotateError, Required } from '@tldraw/utils'
|
|
4
|
+
import classNames from 'classnames'
|
|
4
5
|
import React, {
|
|
5
|
-
ReactNode,
|
|
6
6
|
memo,
|
|
7
|
+
ReactNode,
|
|
7
8
|
useCallback,
|
|
8
9
|
useEffect,
|
|
9
10
|
useLayoutEffect,
|
|
@@ -12,16 +13,14 @@ import React, {
|
|
|
12
13
|
useState,
|
|
13
14
|
useSyncExternalStore,
|
|
14
15
|
} from 'react'
|
|
15
|
-
|
|
16
|
-
import classNames from 'classnames'
|
|
17
16
|
import { version } from '../version'
|
|
18
|
-
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
|
19
17
|
import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
|
|
20
|
-
import {
|
|
18
|
+
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
|
21
19
|
import { TLStoreBaseOptions } from './config/createTLStore'
|
|
22
|
-
import {
|
|
20
|
+
import { createTLUser, TLUser } from './config/createTLUser'
|
|
23
21
|
import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
|
|
24
22
|
import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
|
23
|
+
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
|
25
24
|
import { Editor } from './editor/Editor'
|
|
26
25
|
import { TLStateNodeConstructor } from './editor/tools/StateNode'
|
|
27
26
|
import { TLCameraOptions } from './editor/types/misc-types'
|
|
@@ -39,12 +38,12 @@ import { useForceUpdate } from './hooks/useForceUpdate'
|
|
|
39
38
|
import { useShallowObjectIdentity } from './hooks/useIdentity'
|
|
40
39
|
import { useLocalStore } from './hooks/useLocalStore'
|
|
41
40
|
import { useRefState } from './hooks/useRefState'
|
|
41
|
+
import { useStateAttribute } from './hooks/useStateAttribute'
|
|
42
42
|
import { useZoomCss } from './hooks/useZoomCss'
|
|
43
43
|
import { LicenseProvider } from './license/LicenseProvider'
|
|
44
44
|
import { Watermark } from './license/Watermark'
|
|
45
45
|
import { TldrawOptions } from './options'
|
|
46
46
|
import { TLDeepLinkOptions } from './utils/deepLinks'
|
|
47
|
-
import { stopEventPropagation } from './utils/dom'
|
|
48
47
|
import { TLTextOptions } from './utils/richText'
|
|
49
48
|
import { TLStoreWithStatus } from './utils/sync/StoreWithStatus'
|
|
50
49
|
|
|
@@ -188,13 +187,6 @@ export interface TldrawEditorBaseProps {
|
|
|
188
187
|
*/
|
|
189
188
|
deepLinks?: true | TLDeepLinkOptions
|
|
190
189
|
|
|
191
|
-
/**
|
|
192
|
-
* Predicate for whether or not a shape should be hidden.
|
|
193
|
-
*
|
|
194
|
-
* @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.
|
|
195
|
-
*/
|
|
196
|
-
isShapeHidden?(shape: TLShape, editor: Editor): boolean
|
|
197
|
-
|
|
198
190
|
/**
|
|
199
191
|
* Provides a way to hide shapes.
|
|
200
192
|
*
|
|
@@ -282,7 +274,6 @@ export const TldrawEditor = memo(function TldrawEditor({
|
|
|
282
274
|
data-tldraw={version}
|
|
283
275
|
draggable={false}
|
|
284
276
|
className={classNames(`${TL_CONTAINER_CLASS} tl-theme__light`, className)}
|
|
285
|
-
onPointerDown={stopEventPropagation}
|
|
286
277
|
tabIndex={-1}
|
|
287
278
|
role="application"
|
|
288
279
|
aria-label={_options?.branding ?? 'tldraw'}
|
|
@@ -411,8 +402,6 @@ function TldrawEditorWithReadyStore({
|
|
|
411
402
|
options,
|
|
412
403
|
licenseKey,
|
|
413
404
|
deepLinks: _deepLinks,
|
|
414
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
415
|
-
isShapeHidden,
|
|
416
405
|
getShapeVisibility,
|
|
417
406
|
assetUrls,
|
|
418
407
|
}: Required<
|
|
@@ -472,7 +461,6 @@ function TldrawEditorWithReadyStore({
|
|
|
472
461
|
textOptions,
|
|
473
462
|
options,
|
|
474
463
|
licenseKey,
|
|
475
|
-
isShapeHidden,
|
|
476
464
|
getShapeVisibility,
|
|
477
465
|
fontAssetUrls: assetUrls?.fonts,
|
|
478
466
|
})
|
|
@@ -508,7 +496,6 @@ function TldrawEditorWithReadyStore({
|
|
|
508
496
|
user,
|
|
509
497
|
setEditor,
|
|
510
498
|
licenseKey,
|
|
511
|
-
isShapeHidden,
|
|
512
499
|
getShapeVisibility,
|
|
513
500
|
textOptions,
|
|
514
501
|
assetUrls,
|
|
@@ -585,8 +572,13 @@ function TldrawEditorWithReadyStore({
|
|
|
585
572
|
if (editor !== fontLoadingState?.editor) {
|
|
586
573
|
fontLoadingState = null
|
|
587
574
|
}
|
|
588
|
-
|
|
575
|
+
useLayoutEffect(() => {
|
|
589
576
|
if (!editor) return
|
|
577
|
+
if (editor.options.maxFontsToLoadBeforeRender === 0) {
|
|
578
|
+
setFontLoadingState({ editor, isLoaded: true })
|
|
579
|
+
return
|
|
580
|
+
}
|
|
581
|
+
|
|
590
582
|
let isCancelled = false
|
|
591
583
|
|
|
592
584
|
setFontLoadingState({ editor, isLoaded: false })
|
|
@@ -646,6 +638,7 @@ function Layout({ children, onMount }: { children: ReactNode; onMount?: TLOnMoun
|
|
|
646
638
|
useCursor()
|
|
647
639
|
useDarkMode()
|
|
648
640
|
useForceUpdate()
|
|
641
|
+
useStateAttribute()
|
|
649
642
|
useOnMount((editor) => {
|
|
650
643
|
const teardownStore = editor.store.props.onMount(editor)
|
|
651
644
|
const teardownCallback = onMount?.(editor)
|
|
@@ -50,12 +50,6 @@ export function MenuClickCapture() {
|
|
|
50
50
|
// Do nothing unless we're pointing
|
|
51
51
|
if (!rPointerState.current.isDown) return
|
|
52
52
|
|
|
53
|
-
// If we're already dragging, pass on the event as it is
|
|
54
|
-
if (rPointerState.current.isDragging) {
|
|
55
|
-
canvasEvents.onPointerMove?.(e)
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
53
|
if (
|
|
60
54
|
// We're pointing, but are we dragging?
|
|
61
55
|
Vec.Dist2(rPointerState.current.start, new Vec(e.clientX, e.clientY)) >
|
|
@@ -75,8 +69,6 @@ export function MenuClickCapture() {
|
|
|
75
69
|
clientY: y,
|
|
76
70
|
button: 0,
|
|
77
71
|
})
|
|
78
|
-
// call the pointer move with the current pointer position
|
|
79
|
-
canvasEvents.onPointerMove?.(e)
|
|
80
72
|
}
|
|
81
73
|
},
|
|
82
74
|
[canvasEvents, editor]
|
|
@@ -28,7 +28,6 @@ export const Shape = memo(function Shape({
|
|
|
28
28
|
index,
|
|
29
29
|
backgroundIndex,
|
|
30
30
|
opacity,
|
|
31
|
-
dprMultiple,
|
|
32
31
|
}: {
|
|
33
32
|
id: TLShapeId
|
|
34
33
|
shape: TLShape
|
|
@@ -36,7 +35,6 @@ export const Shape = memo(function Shape({
|
|
|
36
35
|
index: number
|
|
37
36
|
backgroundIndex: number
|
|
38
37
|
opacity: number
|
|
39
|
-
dprMultiple: number
|
|
40
38
|
}) {
|
|
41
39
|
const editor = useEditor()
|
|
42
40
|
|
|
@@ -91,18 +89,14 @@ export const Shape = memo(function Shape({
|
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
// Width / Height
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const widthRemainder = bounds.w % dprMultiple
|
|
97
|
-
const heightRemainder = bounds.h % dprMultiple
|
|
98
|
-
const width = widthRemainder === 0 ? bounds.w : bounds.w + (dprMultiple - widthRemainder)
|
|
99
|
-
const height = heightRemainder === 0 ? bounds.h : bounds.h + (dprMultiple - heightRemainder)
|
|
92
|
+
const width = Math.max(bounds.width, 1)
|
|
93
|
+
const height = Math.max(bounds.height, 1)
|
|
100
94
|
|
|
101
95
|
if (width !== prev.width || height !== prev.height) {
|
|
102
|
-
setStyleProperty(containerRef.current, 'width',
|
|
103
|
-
setStyleProperty(containerRef.current, 'height',
|
|
104
|
-
setStyleProperty(bgContainerRef.current, 'width',
|
|
105
|
-
setStyleProperty(bgContainerRef.current, 'height',
|
|
96
|
+
setStyleProperty(containerRef.current, 'width', width + 'px')
|
|
97
|
+
setStyleProperty(containerRef.current, 'height', height + 'px')
|
|
98
|
+
setStyleProperty(bgContainerRef.current, 'width', width + 'px')
|
|
99
|
+
setStyleProperty(bgContainerRef.current, 'height', height + 'px')
|
|
106
100
|
prev.width = width
|
|
107
101
|
prev.height = height
|
|
108
102
|
}
|
|
@@ -22,7 +22,6 @@ import { Vec } from '../../primitives/Vec'
|
|
|
22
22
|
import { toDomPrecision } from '../../primitives/utils'
|
|
23
23
|
import { debugFlags } from '../../utils/debug-flags'
|
|
24
24
|
import { setStyleProperty } from '../../utils/dom'
|
|
25
|
-
import { nearestMultiple } from '../../utils/nearestMultiple'
|
|
26
25
|
import { GeometryDebuggingView } from '../GeometryDebuggingView'
|
|
27
26
|
import { LiveCollaborators } from '../LiveCollaborators'
|
|
28
27
|
import { MenuClickCapture } from '../MenuClickCapture'
|
|
@@ -173,10 +172,18 @@ export function DefaultCanvas({ className }: TLCanvasComponentProps) {
|
|
|
173
172
|
<LiveCollaborators />
|
|
174
173
|
</div>
|
|
175
174
|
</div>
|
|
175
|
+
<div
|
|
176
|
+
className="tl-canvas__in-front"
|
|
177
|
+
onPointerDown={editor.markEventAsHandled}
|
|
178
|
+
onPointerUp={editor.markEventAsHandled}
|
|
179
|
+
onTouchStart={editor.markEventAsHandled}
|
|
180
|
+
onTouchEnd={editor.markEventAsHandled}
|
|
181
|
+
>
|
|
182
|
+
<InFrontOfTheCanvasWrapper />
|
|
183
|
+
</div>
|
|
176
184
|
<MovingCameraHitTestBlocker />
|
|
177
185
|
</div>
|
|
178
186
|
<MenuClickCapture />
|
|
179
|
-
<InFrontOfTheCanvasWrapper />
|
|
180
187
|
</>
|
|
181
188
|
)
|
|
182
189
|
}
|
|
@@ -390,18 +397,9 @@ function ShapesWithSVGs() {
|
|
|
390
397
|
|
|
391
398
|
const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
|
|
392
399
|
|
|
393
|
-
const dprMultiple = useValue(
|
|
394
|
-
'dpr multiple',
|
|
395
|
-
() =>
|
|
396
|
-
// dprMultiple is the smallest number we can multiply dpr by to get an integer
|
|
397
|
-
// it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
|
|
398
|
-
nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
|
|
399
|
-
[editor]
|
|
400
|
-
)
|
|
401
|
-
|
|
402
400
|
return renderingShapes.map((result) => (
|
|
403
401
|
<Fragment key={result.id + '_fragment'}>
|
|
404
|
-
<Shape {...result}
|
|
402
|
+
<Shape {...result} />
|
|
405
403
|
<DebugSvgCopy id={result.id} mode="iframe" />
|
|
406
404
|
</Fragment>
|
|
407
405
|
))
|
|
@@ -436,19 +434,10 @@ function ShapesToDisplay() {
|
|
|
436
434
|
|
|
437
435
|
const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
|
|
438
436
|
|
|
439
|
-
const dprMultiple = useValue(
|
|
440
|
-
'dpr multiple',
|
|
441
|
-
() =>
|
|
442
|
-
// dprMultiple is the smallest number we can multiply dpr by to get an integer
|
|
443
|
-
// it's usually 1, 2, or 4 (for e.g. dpr of 2, 2.5 and 2.25 respectively)
|
|
444
|
-
nearestMultiple(Math.floor(editor.getInstanceState().devicePixelRatio * 100) / 100),
|
|
445
|
-
[editor]
|
|
446
|
-
)
|
|
447
|
-
|
|
448
437
|
return (
|
|
449
438
|
<>
|
|
450
439
|
{renderingShapes.map((result) => (
|
|
451
|
-
<Shape key={result.id + '_shape'} {...result}
|
|
440
|
+
<Shape key={result.id + '_shape'} {...result} />
|
|
452
441
|
))}
|
|
453
442
|
{tlenv.isSafari && <ReflowIfNeeded />}
|
|
454
443
|
</>
|
|
@@ -44,7 +44,7 @@ export function DefaultCollaboratorHint({
|
|
|
44
44
|
href={`#${cursorHintId}`}
|
|
45
45
|
color={color}
|
|
46
46
|
strokeWidth={3}
|
|
47
|
-
stroke="var(--color-background)"
|
|
47
|
+
stroke="var(--tl-color-background)"
|
|
48
48
|
/>
|
|
49
49
|
<use href={`#${cursorHintId}`} color={color} opacity={opacity} />
|
|
50
50
|
</svg>
|
|
@@ -75,7 +75,7 @@ export const DefaultErrorFallback: TLErrorFallbackComponent = ({ error, editor }
|
|
|
75
75
|
|
|
76
76
|
// if we can't find a theme class from the app or from a parent, we have
|
|
77
77
|
// to fall back on using a media query:
|
|
78
|
-
if (typeof window !== 'undefined' &&
|
|
78
|
+
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
79
79
|
setIsDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
80
80
|
}
|
|
81
81
|
}, [isDarkModeFromApp])
|
|
@@ -21,7 +21,7 @@ export function DefaultScribble({ scribble, zoom, color, opacity, className }: T
|
|
|
21
21
|
<path
|
|
22
22
|
className="tl-scribble"
|
|
23
23
|
d={getSvgPathFromPoints(scribble.points, false)}
|
|
24
|
-
stroke={color ?? `var(--color-${scribble.color})`}
|
|
24
|
+
stroke={color ?? `var(--tl-color-${scribble.color})`}
|
|
25
25
|
fill="none"
|
|
26
26
|
strokeWidth={8 / zoom}
|
|
27
27
|
opacity={opacity ?? scribble.opacity}
|
|
@@ -87,7 +87,11 @@ export const DefaultShapeIndicator = memo(function DefaultShapeIndicator({
|
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
89
|
<svg ref={rIndicator} className={classNames('tl-overlays__item', className)} aria-hidden="true">
|
|
90
|
-
<g
|
|
90
|
+
<g
|
|
91
|
+
className="tl-shape-indicator"
|
|
92
|
+
stroke={color ?? 'var(--tl-color-selected)'}
|
|
93
|
+
opacity={opacity}
|
|
94
|
+
>
|
|
91
95
|
<InnerIndicator editor={editor} id={shapeId} />
|
|
92
96
|
</g>
|
|
93
97
|
</svg>
|
|
@@ -24,6 +24,8 @@ export interface TLUserPreferences {
|
|
|
24
24
|
isWrapMode?: boolean | null
|
|
25
25
|
isDynamicSizeMode?: boolean | null
|
|
26
26
|
isPasteAtCursorMode?: boolean | null
|
|
27
|
+
enhancedA11yMode?: boolean | null
|
|
28
|
+
inputMode?: 'trackpad' | 'mouse' | null
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
interface UserDataSnapshot {
|
|
@@ -52,6 +54,8 @@ export const userTypeValidator: T.Validator<TLUserPreferences> = T.object<TLUser
|
|
|
52
54
|
isWrapMode: T.boolean.nullable().optional(),
|
|
53
55
|
isDynamicSizeMode: T.boolean.nullable().optional(),
|
|
54
56
|
isPasteAtCursorMode: T.boolean.nullable().optional(),
|
|
57
|
+
enhancedA11yMode: T.boolean.nullable().optional(),
|
|
58
|
+
inputMode: T.literalEnum('trackpad', 'mouse').nullable().optional(),
|
|
55
59
|
})
|
|
56
60
|
|
|
57
61
|
const Versions = {
|
|
@@ -64,6 +68,9 @@ const Versions = {
|
|
|
64
68
|
AllowSystemColorScheme: 7,
|
|
65
69
|
AddPasteAtCursor: 8,
|
|
66
70
|
AddKeyboardShortcuts: 9,
|
|
71
|
+
AddShowUiLabels: 10,
|
|
72
|
+
AddPointerPeripheral: 11,
|
|
73
|
+
RenameShowUiLabelsToEnhancedA11yMode: 12,
|
|
67
74
|
} as const
|
|
68
75
|
|
|
69
76
|
const CURRENT_VERSION = Math.max(...Object.values(Versions))
|
|
@@ -102,6 +109,17 @@ function migrateSnapshot(data: { version: number; user: any }) {
|
|
|
102
109
|
if (data.version < Versions.AddKeyboardShortcuts) {
|
|
103
110
|
data.user.areKeyboardShortcutsEnabled = true
|
|
104
111
|
}
|
|
112
|
+
if (data.version < Versions.AddShowUiLabels) {
|
|
113
|
+
data.user.showUiLabels = false
|
|
114
|
+
}
|
|
115
|
+
if (data.version < Versions.RenameShowUiLabelsToEnhancedA11yMode) {
|
|
116
|
+
data.user.enhancedA11yMode = data.user.showUiLabels
|
|
117
|
+
delete data.user.showUiLabels
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (data.version < Versions.AddPointerPeripheral) {
|
|
121
|
+
data.user.inputMode = null
|
|
122
|
+
}
|
|
105
123
|
|
|
106
124
|
// finally
|
|
107
125
|
data.version = CURRENT_VERSION
|
|
@@ -129,7 +147,7 @@ function getRandomColor() {
|
|
|
129
147
|
|
|
130
148
|
/** @internal */
|
|
131
149
|
export function userPrefersReducedMotion() {
|
|
132
|
-
if (typeof window !== 'undefined' &&
|
|
150
|
+
if (typeof window !== 'undefined' && window.matchMedia) {
|
|
133
151
|
return window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false
|
|
134
152
|
}
|
|
135
153
|
|
|
@@ -150,7 +168,9 @@ export const defaultUserPreferences = Object.freeze({
|
|
|
150
168
|
isWrapMode: false,
|
|
151
169
|
isDynamicSizeMode: false,
|
|
152
170
|
isPasteAtCursorMode: false,
|
|
171
|
+
enhancedA11yMode: false,
|
|
153
172
|
colorScheme: 'light',
|
|
173
|
+
inputMode: null,
|
|
154
174
|
}) satisfies Readonly<Omit<TLUserPreferences, 'id'>>
|
|
155
175
|
|
|
156
176
|
/** @public */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { vi } from 'vitest'
|
|
1
2
|
import {
|
|
2
3
|
Box,
|
|
3
4
|
Geometry2d,
|
|
@@ -59,8 +60,8 @@ beforeEach(() => {
|
|
|
59
60
|
getContainer: () => document.body,
|
|
60
61
|
})
|
|
61
62
|
editor.setCameraOptions({ isLocked: true })
|
|
62
|
-
editor.setCamera =
|
|
63
|
-
editor.user.getAnimationSpeed =
|
|
63
|
+
editor.setCamera = vi.fn()
|
|
64
|
+
editor.user.getAnimationSpeed = vi.fn()
|
|
64
65
|
})
|
|
65
66
|
|
|
66
67
|
describe('centerOnPoint', () => {
|
|
@@ -94,13 +95,13 @@ describe('updateShape', () => {
|
|
|
94
95
|
|
|
95
96
|
describe('zoomToFit', () => {
|
|
96
97
|
it('no-op when isLocked is set', () => {
|
|
97
|
-
editor.getCurrentPageShapeIds =
|
|
98
|
+
editor.getCurrentPageShapeIds = vi.fn(() => new Set([createShapeId('box1')]))
|
|
98
99
|
editor.zoomToFit()
|
|
99
100
|
expect(editor.setCamera).not.toHaveBeenCalled()
|
|
100
101
|
})
|
|
101
102
|
|
|
102
103
|
it('sets camera when isLocked is set and force flag is set', () => {
|
|
103
|
-
editor.getCurrentPageShapeIds =
|
|
104
|
+
editor.getCurrentPageShapeIds = vi.fn(() => new Set([createShapeId('box1')]))
|
|
104
105
|
editor.zoomToFit({ force: true })
|
|
105
106
|
expect(editor.setCamera).toHaveBeenCalled()
|
|
106
107
|
})
|
|
@@ -144,13 +145,13 @@ describe('zoomOut', () => {
|
|
|
144
145
|
|
|
145
146
|
describe('zoomToSelection', () => {
|
|
146
147
|
it('no-op when isLocked is set', () => {
|
|
147
|
-
editor.getSelectionPageBounds =
|
|
148
|
+
editor.getSelectionPageBounds = vi.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
|
|
148
149
|
editor.zoomToSelection()
|
|
149
150
|
expect(editor.setCamera).not.toHaveBeenCalled()
|
|
150
151
|
})
|
|
151
152
|
|
|
152
153
|
it('sets camera when isLocked is set and force flag is set', () => {
|
|
153
|
-
editor.getSelectionPageBounds =
|
|
154
|
+
editor.getSelectionPageBounds = vi.fn(() => Box.From({ x: 0, y: 0, w: 100, h: 100 }))
|
|
154
155
|
editor.zoomToSelection({ force: true })
|
|
155
156
|
expect(editor.setCamera).toHaveBeenCalled()
|
|
156
157
|
})
|
|
@@ -286,7 +287,7 @@ describe('getShapesAtPoint', () => {
|
|
|
286
287
|
|
|
287
288
|
it('filters out hidden shapes', () => {
|
|
288
289
|
// Create a spy to mock isShapeHidden
|
|
289
|
-
const isShapeHiddenSpy =
|
|
290
|
+
const isShapeHiddenSpy = vi.spyOn(editor, 'isShapeHidden')
|
|
290
291
|
isShapeHiddenSpy.mockImplementation((shape) => {
|
|
291
292
|
return typeof shape === 'string' ? shape === ids.shape3 : shape.id === ids.shape3
|
|
292
293
|
})
|
|
@@ -352,7 +353,7 @@ describe('getShapesAtPoint', () => {
|
|
|
352
353
|
|
|
353
354
|
it('returns empty array when all shapes are hidden', () => {
|
|
354
355
|
// Mock all shapes as hidden
|
|
355
|
-
const isShapeHiddenSpy =
|
|
356
|
+
const isShapeHiddenSpy = vi.spyOn(editor, 'isShapeHidden')
|
|
356
357
|
isShapeHiddenSpy.mockReturnValue(true)
|
|
357
358
|
|
|
358
359
|
const shapes = editor.getShapesAtPoint({ x: 50, y: 50 })
|
|
@@ -692,7 +693,7 @@ describe('selectAll', () => {
|
|
|
692
693
|
const initialSelectedIds = editor.getSelectedShapeIds()
|
|
693
694
|
|
|
694
695
|
// Spy on setSelectedShapes to verify it's not called
|
|
695
|
-
const setSelectedShapesSpy =
|
|
696
|
+
const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
|
|
696
697
|
|
|
697
698
|
// Call selectAll
|
|
698
699
|
editor.selectAll()
|
|
@@ -713,7 +714,7 @@ describe('selectAll', () => {
|
|
|
713
714
|
const initialSelectedIds = editor.getSelectedShapeIds()
|
|
714
715
|
|
|
715
716
|
// Spy on setSelectedShapes to verify it's not called
|
|
716
|
-
const setSelectedShapesSpy =
|
|
717
|
+
const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
|
|
717
718
|
|
|
718
719
|
// Call selectAll
|
|
719
720
|
editor.selectAll()
|
|
@@ -818,7 +819,7 @@ describe('selectAll', () => {
|
|
|
818
819
|
const initialSelectedIds = Array.from(editor.getSelectedShapeIds())
|
|
819
820
|
|
|
820
821
|
// Spy on setSelectedShapes to verify it's not called
|
|
821
|
-
const setSelectedShapesSpy =
|
|
822
|
+
const setSelectedShapesSpy = vi.spyOn(editor, 'setSelectedShapes')
|
|
822
823
|
|
|
823
824
|
// Call selectAll
|
|
824
825
|
editor.selectAll()
|
|
@@ -832,3 +833,93 @@ describe('selectAll', () => {
|
|
|
832
833
|
setSelectedShapesSpy.mockRestore()
|
|
833
834
|
})
|
|
834
835
|
})
|
|
836
|
+
|
|
837
|
+
describe('putExternalContent', () => {
|
|
838
|
+
let mockHandler: any
|
|
839
|
+
|
|
840
|
+
beforeEach(() => {
|
|
841
|
+
mockHandler = vi.fn()
|
|
842
|
+
editor.registerExternalContentHandler('text', mockHandler)
|
|
843
|
+
})
|
|
844
|
+
|
|
845
|
+
it('calls external content handler when not readonly', async () => {
|
|
846
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(false)
|
|
847
|
+
|
|
848
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
849
|
+
await editor.putExternalContent(info)
|
|
850
|
+
|
|
851
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
it('does not call external content handler when readonly', async () => {
|
|
855
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(true)
|
|
856
|
+
|
|
857
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
858
|
+
await editor.putExternalContent(info)
|
|
859
|
+
|
|
860
|
+
expect(mockHandler).not.toHaveBeenCalled()
|
|
861
|
+
})
|
|
862
|
+
|
|
863
|
+
it('calls external content handler when readonly but force is true', async () => {
|
|
864
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(true)
|
|
865
|
+
|
|
866
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
867
|
+
await editor.putExternalContent(info, { force: true })
|
|
868
|
+
|
|
869
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
870
|
+
})
|
|
871
|
+
|
|
872
|
+
it('calls external content handler when force is false and not readonly', async () => {
|
|
873
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(false)
|
|
874
|
+
|
|
875
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
876
|
+
await editor.putExternalContent(info, { force: false })
|
|
877
|
+
|
|
878
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
879
|
+
})
|
|
880
|
+
})
|
|
881
|
+
|
|
882
|
+
describe('replaceExternalContent', () => {
|
|
883
|
+
let mockHandler: any
|
|
884
|
+
|
|
885
|
+
beforeEach(() => {
|
|
886
|
+
mockHandler = vi.fn()
|
|
887
|
+
editor.registerExternalContentHandler('text', mockHandler)
|
|
888
|
+
})
|
|
889
|
+
|
|
890
|
+
it('calls external content handler when not readonly', async () => {
|
|
891
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(false)
|
|
892
|
+
|
|
893
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
894
|
+
await editor.replaceExternalContent(info)
|
|
895
|
+
|
|
896
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
897
|
+
})
|
|
898
|
+
|
|
899
|
+
it('does not call external content handler when readonly', async () => {
|
|
900
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(true)
|
|
901
|
+
|
|
902
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
903
|
+
await editor.replaceExternalContent(info)
|
|
904
|
+
|
|
905
|
+
expect(mockHandler).not.toHaveBeenCalled()
|
|
906
|
+
})
|
|
907
|
+
|
|
908
|
+
it('calls external content handler when readonly but force is true', async () => {
|
|
909
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(true)
|
|
910
|
+
|
|
911
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
912
|
+
await editor.replaceExternalContent(info, { force: true })
|
|
913
|
+
|
|
914
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
915
|
+
})
|
|
916
|
+
|
|
917
|
+
it('calls external content handler when force is false and not readonly', async () => {
|
|
918
|
+
vi.spyOn(editor, 'getIsReadonly').mockReturnValue(false)
|
|
919
|
+
|
|
920
|
+
const info = { type: 'text' as const, text: 'test-data' }
|
|
921
|
+
await editor.replaceExternalContent(info, { force: false })
|
|
922
|
+
|
|
923
|
+
expect(mockHandler).toHaveBeenCalledWith(info)
|
|
924
|
+
})
|
|
925
|
+
})
|