@tldraw/editor 3.16.0-canary.e9c30b532b82 → 3.16.0-canary.eb473ba53051
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 +113 -104
- package/dist-cjs/index.js +6 -6
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +7 -7
- package/dist-cjs/lib/TldrawEditor.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/DefaultErrorFallback.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +50 -114
- 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 +1 -1
- 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 +34 -14
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +22 -17
- 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 +3 -3
- 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 +4 -4
- package/dist-cjs/lib/hooks/useSelectionEvents.js.map +2 -2
- 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 +69 -7
- 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 +6 -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/dom.js +12 -1
- package/dist-cjs/lib/utils/dom.js.map +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js +2 -2
- package/dist-cjs/lib/utils/getPointerInfo.js.map +2 -2
- package/dist-cjs/lib/utils/reparenting.js +2 -35
- package/dist-cjs/lib/utils/reparenting.js.map +3 -3
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +113 -104
- package/dist-esm/index.mjs +9 -7
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +8 -8
- package/dist-esm/lib/TldrawEditor.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 +15 -24
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- 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/config/TLUserPreferences.mjs +1 -1
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +50 -114
- 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 +1 -1
- 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 +34 -14
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -18
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +11 -6
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.mjs +2 -3
- 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 +9 -4
- 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 +6 -5
- package/dist-esm/lib/hooks/useSelectionEvents.mjs.map +2 -2
- 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 +70 -8
- 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 +6 -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/dom.mjs +12 -1
- package/dist-esm/lib/utils/dom.mjs.map +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs +2 -2
- package/dist-esm/lib/utils/getPointerInfo.mjs.map +2 -2
- package/dist-esm/lib/utils/reparenting.mjs +3 -40
- package/dist-esm/lib/utils/reparenting.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +16 -3
- package/package.json +14 -37
- package/src/index.ts +4 -9
- package/src/lib/TldrawEditor.tsx +9 -16
- package/src/lib/components/Shape.tsx +6 -12
- package/src/lib/components/default-components/DefaultCanvas.tsx +12 -23
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -1
- package/src/lib/config/TLUserPreferences.ts +1 -1
- package/src/lib/editor/Editor.test.ts +102 -11
- package/src/lib/editor/Editor.ts +65 -151
- 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 +21 -26
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +46 -0
- package/src/lib/editor/types/misc-types.ts +0 -6
- package/src/lib/exports/getSvgJsx.test.ts +868 -0
- package/src/lib/exports/getSvgJsx.tsx +76 -19
- package/src/lib/hooks/useCanvasEvents.ts +23 -17
- package/src/lib/hooks/useDocumentEvents.ts +11 -6
- package/src/lib/hooks/useFixSafariDoubleTapZoomPencilEvents.ts +2 -2
- package/src/lib/hooks/useGestureEvents.ts +2 -2
- package/src/lib/hooks/useHandleEvents.ts +9 -4
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/lib/hooks/useSelectionEvents.ts +6 -5
- 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 +75 -8
- package/src/lib/license/useLicenseManagerState.ts +2 -2
- package/src/lib/options.ts +6 -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/dom.test.ts +94 -0
- package/src/lib/utils/dom.ts +38 -1
- package/src/lib/utils/getPointerInfo.ts +2 -1
- package/src/lib/utils/reparenting.ts +3 -69
- 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
- package/dist-cjs/lib/utils/nearestMultiple.js +0 -34
- 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
|
@@ -1,58 +1,59 @@
|
|
|
1
|
+
import { Mock, Mocked, vi } from 'vitest'
|
|
1
2
|
import { Editor } from '../../Editor'
|
|
2
3
|
import { FocusManager } from './FocusManager'
|
|
3
4
|
|
|
4
5
|
// Mock the Editor class
|
|
5
|
-
|
|
6
|
+
vi.mock('../../Editor')
|
|
6
7
|
|
|
7
8
|
describe('FocusManager', () => {
|
|
8
|
-
let editor:
|
|
9
|
+
let editor: Mocked<
|
|
9
10
|
Editor & {
|
|
10
11
|
sideEffects: {
|
|
11
|
-
registerAfterChangeHandler:
|
|
12
|
+
registerAfterChangeHandler: Mock
|
|
12
13
|
}
|
|
13
|
-
getInstanceState:
|
|
14
|
-
updateInstanceState:
|
|
15
|
-
getContainer:
|
|
16
|
-
isIn:
|
|
17
|
-
getSelectedShapeIds:
|
|
18
|
-
complete:
|
|
14
|
+
getInstanceState: Mock
|
|
15
|
+
updateInstanceState: Mock
|
|
16
|
+
getContainer: Mock
|
|
17
|
+
isIn: Mock
|
|
18
|
+
getSelectedShapeIds: Mock
|
|
19
|
+
complete: Mock
|
|
19
20
|
}
|
|
20
21
|
>
|
|
21
22
|
let focusManager: FocusManager
|
|
22
23
|
let mockContainer: HTMLElement
|
|
23
|
-
let mockDispose:
|
|
24
|
+
let mockDispose: Mock
|
|
24
25
|
let originalAddEventListener: typeof document.body.addEventListener
|
|
25
26
|
let originalRemoveEventListener: typeof document.body.removeEventListener
|
|
26
27
|
|
|
27
28
|
beforeEach(() => {
|
|
28
29
|
// Create mock container element
|
|
29
30
|
mockContainer = document.createElement('div')
|
|
30
|
-
mockContainer.focus =
|
|
31
|
-
mockContainer.blur =
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
mockContainer.focus = vi.fn()
|
|
32
|
+
mockContainer.blur = vi.fn()
|
|
33
|
+
vi.spyOn(mockContainer.classList, 'add')
|
|
34
|
+
vi.spyOn(mockContainer.classList, 'remove')
|
|
34
35
|
|
|
35
36
|
// Create mock dispose function
|
|
36
|
-
mockDispose =
|
|
37
|
+
mockDispose = vi.fn()
|
|
37
38
|
|
|
38
39
|
// Mock editor
|
|
39
40
|
editor = {
|
|
40
41
|
sideEffects: {
|
|
41
|
-
registerAfterChangeHandler:
|
|
42
|
+
registerAfterChangeHandler: vi.fn(() => mockDispose),
|
|
42
43
|
},
|
|
43
|
-
getInstanceState:
|
|
44
|
-
updateInstanceState:
|
|
45
|
-
getContainer:
|
|
46
|
-
isIn:
|
|
47
|
-
getSelectedShapeIds:
|
|
48
|
-
complete:
|
|
44
|
+
getInstanceState: vi.fn(() => ({ isFocused: false })),
|
|
45
|
+
updateInstanceState: vi.fn(),
|
|
46
|
+
getContainer: vi.fn(() => mockContainer),
|
|
47
|
+
isIn: vi.fn(() => false),
|
|
48
|
+
getSelectedShapeIds: vi.fn(() => []),
|
|
49
|
+
complete: vi.fn(),
|
|
49
50
|
} as any
|
|
50
51
|
|
|
51
52
|
// Mock document.body event listeners
|
|
52
53
|
originalAddEventListener = document.body.addEventListener
|
|
53
54
|
originalRemoveEventListener = document.body.removeEventListener
|
|
54
|
-
document.body.addEventListener =
|
|
55
|
-
document.body.removeEventListener =
|
|
55
|
+
document.body.addEventListener = vi.fn()
|
|
56
|
+
document.body.removeEventListener = vi.fn()
|
|
56
57
|
})
|
|
57
58
|
|
|
58
59
|
afterEach(() => {
|
|
@@ -65,7 +66,7 @@ describe('FocusManager', () => {
|
|
|
65
66
|
focusManager.dispose()
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
vi.clearAllMocks()
|
|
69
70
|
})
|
|
70
71
|
|
|
71
72
|
describe('constructor', () => {
|
|
@@ -131,7 +132,7 @@ describe('FocusManager', () => {
|
|
|
131
132
|
const handler = handlerCall[1]
|
|
132
133
|
|
|
133
134
|
// Clear previous calls
|
|
134
|
-
|
|
135
|
+
vi.clearAllMocks()
|
|
135
136
|
|
|
136
137
|
// Simulate focus state change
|
|
137
138
|
const prev = { isFocused: false }
|
|
@@ -149,7 +150,7 @@ describe('FocusManager', () => {
|
|
|
149
150
|
const handlerCall = editor.sideEffects.registerAfterChangeHandler.mock.calls[0]
|
|
150
151
|
const handler = handlerCall[1]
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
vi.clearAllMocks()
|
|
153
154
|
|
|
154
155
|
// Simulate no focus state change
|
|
155
156
|
const prev = { isFocused: true }
|
|
@@ -170,7 +171,7 @@ describe('FocusManager', () => {
|
|
|
170
171
|
// Get the handler before clearing mocks
|
|
171
172
|
const handlerCall = editor.sideEffects.registerAfterChangeHandler.mock.calls[0]
|
|
172
173
|
handler = handlerCall[1]
|
|
173
|
-
|
|
174
|
+
vi.clearAllMocks()
|
|
174
175
|
})
|
|
175
176
|
|
|
176
177
|
it('should add focused class when editor is focused', () => {
|
|
@@ -205,11 +206,11 @@ describe('FocusManager', () => {
|
|
|
205
206
|
focusManager = new FocusManager(editor)
|
|
206
207
|
|
|
207
208
|
// Get the keydown handler that was registered
|
|
208
|
-
const addEventListenerCalls = (document.body.addEventListener as
|
|
209
|
-
const keydownCall = addEventListenerCalls.find((call) => call[0] === 'keydown')
|
|
210
|
-
keydownHandler = keydownCall[1]
|
|
209
|
+
const addEventListenerCalls = (document.body.addEventListener as Mock).mock.calls
|
|
210
|
+
const keydownCall = addEventListenerCalls.find((call: any) => call[0] === 'keydown')
|
|
211
|
+
keydownHandler = keydownCall![1]
|
|
211
212
|
|
|
212
|
-
|
|
213
|
+
vi.clearAllMocks()
|
|
213
214
|
})
|
|
214
215
|
|
|
215
216
|
it('should remove no-focus-ring class on Tab key', () => {
|
|
@@ -283,11 +284,11 @@ describe('FocusManager', () => {
|
|
|
283
284
|
focusManager = new FocusManager(editor)
|
|
284
285
|
|
|
285
286
|
// Get the mousedown handler that was registered
|
|
286
|
-
const addEventListenerCalls = (document.body.addEventListener as
|
|
287
|
-
const mousedownCall = addEventListenerCalls.find((call) => call[0] === 'mousedown')
|
|
288
|
-
mousedownHandler = mousedownCall[1]
|
|
287
|
+
const addEventListenerCalls = (document.body.addEventListener as Mock).mock.calls
|
|
288
|
+
const mousedownCall = addEventListenerCalls.find((call: any) => call[0] === 'mousedown')
|
|
289
|
+
mousedownHandler = mousedownCall![1]
|
|
289
290
|
|
|
290
|
-
|
|
291
|
+
vi.clearAllMocks()
|
|
291
292
|
})
|
|
292
293
|
|
|
293
294
|
it('should add no-focus-ring class on mouse down', () => {
|
|
@@ -326,7 +327,7 @@ describe('FocusManager', () => {
|
|
|
326
327
|
it('should complete before bluring', () => {
|
|
327
328
|
const callOrder: string[] = []
|
|
328
329
|
editor.complete.mockImplementation(() => callOrder.push('complete'))
|
|
329
|
-
mockContainer.blur =
|
|
330
|
+
mockContainer.blur = vi.fn(() => callOrder.push('blur'))
|
|
330
331
|
|
|
331
332
|
focusManager.blur()
|
|
332
333
|
|
|
@@ -337,7 +338,7 @@ describe('FocusManager', () => {
|
|
|
337
338
|
describe('dispose', () => {
|
|
338
339
|
beforeEach(() => {
|
|
339
340
|
focusManager = new FocusManager(editor)
|
|
340
|
-
|
|
341
|
+
vi.clearAllMocks()
|
|
341
342
|
})
|
|
342
343
|
|
|
343
344
|
it('should remove keyboard event listener', () => {
|
|
@@ -376,7 +377,7 @@ describe('FocusManager', () => {
|
|
|
376
377
|
const handlerCall = editor.sideEffects.registerAfterChangeHandler.mock.calls[0]
|
|
377
378
|
const handler = handlerCall[1]
|
|
378
379
|
|
|
379
|
-
|
|
380
|
+
vi.clearAllMocks()
|
|
380
381
|
|
|
381
382
|
// Rapid focus changes
|
|
382
383
|
editor.getInstanceState.mockReturnValue({ isFocused: true })
|
|
@@ -394,9 +395,9 @@ describe('FocusManager', () => {
|
|
|
394
395
|
|
|
395
396
|
it('should handle keyboard navigation while editing', () => {
|
|
396
397
|
focusManager = new FocusManager(editor)
|
|
397
|
-
const addEventListenerCalls = (document.body.addEventListener as
|
|
398
|
-
const keydownCall = addEventListenerCalls.find((call) => call[0] === 'keydown')
|
|
399
|
-
const keydownHandler = keydownCall[1]
|
|
398
|
+
const addEventListenerCalls = (document.body.addEventListener as Mock).mock.calls
|
|
399
|
+
const keydownCall = addEventListenerCalls.find((call: any) => call[0] === 'keydown')
|
|
400
|
+
const keydownHandler = keydownCall![1]
|
|
400
401
|
|
|
401
402
|
editor.isIn.mockReturnValue(true) // Editing mode
|
|
402
403
|
|
|
@@ -409,15 +410,15 @@ describe('FocusManager', () => {
|
|
|
409
410
|
|
|
410
411
|
it('should handle mouse and keyboard interaction sequence', () => {
|
|
411
412
|
focusManager = new FocusManager(editor)
|
|
412
|
-
const addEventListenerCalls = (document.body.addEventListener as
|
|
413
|
+
const addEventListenerCalls = (document.body.addEventListener as Mock).mock.calls
|
|
413
414
|
|
|
414
|
-
const mousedownCall = addEventListenerCalls.find((call) => call[0] === 'mousedown')
|
|
415
|
-
const keydownCall = addEventListenerCalls.find((call) => call[0] === 'keydown')
|
|
415
|
+
const mousedownCall = addEventListenerCalls.find((call: any) => call[0] === 'mousedown')
|
|
416
|
+
const keydownCall = addEventListenerCalls.find((call: any) => call[0] === 'keydown')
|
|
416
417
|
|
|
417
|
-
const mousedownHandler = mousedownCall[1]
|
|
418
|
-
const keydownHandler = keydownCall[1]
|
|
418
|
+
const mousedownHandler = mousedownCall![1]
|
|
419
|
+
const keydownHandler = keydownCall![1]
|
|
419
420
|
|
|
420
|
-
|
|
421
|
+
vi.clearAllMocks()
|
|
421
422
|
|
|
422
423
|
// Mouse down adds no-focus-ring
|
|
423
424
|
mousedownHandler()
|
|
@@ -58,8 +58,12 @@ export class FocusManager {
|
|
|
58
58
|
|
|
59
59
|
private handleKeyDown(keyEvent: KeyboardEvent) {
|
|
60
60
|
const container = this.editor.getContainer()
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const activeEl = document.activeElement
|
|
62
|
+
// Edit mode should remove the focus ring, however if the active element's
|
|
63
|
+
// parent is the contextual toolbar, then allow it.
|
|
64
|
+
if (this.editor.isIn('select.editing_shape') && !activeEl?.closest('.tlui-contextual-toolbar'))
|
|
65
|
+
return
|
|
66
|
+
if (activeEl === container && this.editor.getSelectedShapeIds().length > 0) return
|
|
63
67
|
if (['Tab', 'ArrowUp', 'ArrowDown'].includes(keyEvent.key)) {
|
|
64
68
|
container.classList.remove('tl-container__no-focus-ring')
|
|
65
69
|
}
|
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { TLShape, TLShapeId, createShapeId } from '@tldraw/tlschema'
|
|
2
|
+
import { Mock, Mocked, vi } from 'vitest'
|
|
2
3
|
import { Editor } from '../../Editor'
|
|
3
4
|
import { FontManager, TLFontFace } from './FontManager'
|
|
4
5
|
|
|
5
6
|
// Mock the Editor class
|
|
6
|
-
|
|
7
|
+
vi.mock('../../Editor')
|
|
7
8
|
|
|
8
9
|
// Mock globals
|
|
9
|
-
global.FontFace =
|
|
10
|
+
global.FontFace = vi.fn().mockImplementation((family, src, descriptors) => ({
|
|
10
11
|
family,
|
|
11
12
|
src,
|
|
12
13
|
...descriptors,
|
|
13
|
-
load:
|
|
14
|
+
load: vi.fn(() => Promise.resolve()),
|
|
14
15
|
}))
|
|
15
16
|
|
|
16
17
|
Object.defineProperty(global.document, 'fonts', {
|
|
17
18
|
value: {
|
|
18
|
-
add:
|
|
19
|
-
[Symbol.iterator]:
|
|
19
|
+
add: vi.fn(),
|
|
20
|
+
[Symbol.iterator]: vi.fn(() => [].values()),
|
|
20
21
|
},
|
|
21
22
|
configurable: true,
|
|
22
23
|
})
|
|
23
24
|
|
|
24
|
-
global.queueMicrotask =
|
|
25
|
+
global.queueMicrotask = vi.fn((fn) => Promise.resolve().then(fn))
|
|
25
26
|
|
|
26
27
|
describe('FontManager', () => {
|
|
27
|
-
let editor:
|
|
28
|
+
let editor: Mocked<Editor>
|
|
28
29
|
let fontManager: FontManager
|
|
29
30
|
let mockAssetUrls: { [key: string]: string }
|
|
30
31
|
|
|
@@ -50,30 +51,30 @@ describe('FontManager', () => {
|
|
|
50
51
|
})
|
|
51
52
|
|
|
52
53
|
beforeEach(() => {
|
|
53
|
-
|
|
54
|
+
vi.clearAllMocks()
|
|
54
55
|
|
|
55
56
|
mockAssetUrls = {
|
|
56
57
|
'test-font.woff2': 'https://example.com/fonts/test-font.woff2',
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
const mockShapeUtil = {
|
|
60
|
-
getFontFaces:
|
|
61
|
+
getFontFaces: vi.fn(() => []),
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const mockStore = {
|
|
64
|
-
createComputedCache:
|
|
65
|
-
get:
|
|
65
|
+
createComputedCache: vi.fn(() => ({
|
|
66
|
+
get: vi.fn(() => []),
|
|
66
67
|
})),
|
|
67
|
-
createCache:
|
|
68
|
-
get:
|
|
68
|
+
createCache: vi.fn(() => ({
|
|
69
|
+
get: vi.fn(() => ({ get: vi.fn(() => []) })),
|
|
69
70
|
})),
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
editor = {
|
|
73
74
|
store: mockStore,
|
|
74
|
-
getShapeUtil:
|
|
75
|
-
getCurrentPageShapeIds:
|
|
76
|
-
getShape:
|
|
75
|
+
getShapeUtil: vi.fn(() => mockShapeUtil),
|
|
76
|
+
getCurrentPageShapeIds: vi.fn(() => new Set()),
|
|
77
|
+
getShape: vi.fn(),
|
|
77
78
|
isDisposed: false,
|
|
78
79
|
} as any
|
|
79
80
|
|
|
@@ -127,7 +128,7 @@ describe('FontManager', () => {
|
|
|
127
128
|
const shapes = shapeIds.map(createMockShape)
|
|
128
129
|
|
|
129
130
|
editor.getCurrentPageShapeIds.mockReturnValue(new Set(shapeIds))
|
|
130
|
-
editor.getShape.mockImplementation((id) => shapes.find((s) => s.id === id))
|
|
131
|
+
editor.getShape.mockImplementation((id: any) => shapes.find((s) => s.id === id))
|
|
131
132
|
|
|
132
133
|
await expect(fontManager.loadRequiredFontsForCurrentPage(3)).resolves.toBeUndefined()
|
|
133
134
|
})
|
|
@@ -150,12 +151,12 @@ describe('FontManager', () => {
|
|
|
150
151
|
const font = createMockFont()
|
|
151
152
|
const error = new Error('Font load failed')
|
|
152
153
|
|
|
153
|
-
;(global.FontFace as
|
|
154
|
+
;(global.FontFace as Mock).mockReturnValue({
|
|
154
155
|
family: font.family,
|
|
155
|
-
load:
|
|
156
|
+
load: vi.fn(() => Promise.reject(error)),
|
|
156
157
|
})
|
|
157
158
|
|
|
158
|
-
const consoleSpy =
|
|
159
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
159
160
|
|
|
160
161
|
await fontManager.ensureFontIsLoaded(font)
|
|
161
162
|
|
|
@@ -198,7 +199,7 @@ describe('FontManager', () => {
|
|
|
198
199
|
|
|
199
200
|
fontManager.requestFonts(fonts)
|
|
200
201
|
|
|
201
|
-
const callback = (queueMicrotask as
|
|
202
|
+
const callback = (queueMicrotask as Mock).mock.calls[0][0]
|
|
202
203
|
expect(() => callback()).not.toThrow()
|
|
203
204
|
})
|
|
204
205
|
})
|
|
@@ -213,7 +214,7 @@ describe('FontManager', () => {
|
|
|
213
214
|
src: url("mock-data-url");
|
|
214
215
|
}`
|
|
215
216
|
|
|
216
|
-
|
|
217
|
+
vi.spyOn(fontManager, 'toEmbeddedCssDeclaration').mockResolvedValue(mockCssDeclaration)
|
|
217
218
|
|
|
218
219
|
const result = await fontManager.toEmbeddedCssDeclaration(font)
|
|
219
220
|
|
|
@@ -227,7 +228,7 @@ describe('FontManager', () => {
|
|
|
227
228
|
const font = createMockFont()
|
|
228
229
|
|
|
229
230
|
// Simple spy to verify the method is called
|
|
230
|
-
const spy =
|
|
231
|
+
const spy = vi.spyOn(fontManager, 'toEmbeddedCssDeclaration').mockResolvedValue('mock-css')
|
|
231
232
|
|
|
232
233
|
await fontManager.toEmbeddedCssDeclaration(font)
|
|
233
234
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseRecord, RecordId, Store, StoreSchema, createRecordType } from '@tldraw/store'
|
|
2
|
+
import { vi } from 'vitest'
|
|
2
3
|
import { TLHistoryBatchOptions } from '../../types/history-types'
|
|
3
4
|
import { HistoryManager } from './HistoryManager'
|
|
4
5
|
|
|
@@ -489,7 +490,7 @@ describe('HistoryManager constructor and lifecycle', () => {
|
|
|
489
490
|
})
|
|
490
491
|
|
|
491
492
|
it('should initialize with optional annotateError callback', () => {
|
|
492
|
-
const mockAnnotateError =
|
|
493
|
+
const mockAnnotateError = vi.fn()
|
|
493
494
|
const manager = new HistoryManager({ store, annotateError: mockAnnotateError })
|
|
494
495
|
expect(manager).toBeDefined()
|
|
495
496
|
})
|
|
@@ -503,7 +504,7 @@ describe('HistoryManager constructor and lifecycle', () => {
|
|
|
503
504
|
})
|
|
504
505
|
|
|
505
506
|
it('should handle errors in batch operations with annotateError', () => {
|
|
506
|
-
const mockAnnotateError =
|
|
507
|
+
const mockAnnotateError = vi.fn()
|
|
507
508
|
const manager = new HistoryManager({ store, annotateError: mockAnnotateError })
|
|
508
509
|
|
|
509
510
|
const errorFn = () => {
|
|
@@ -515,7 +516,7 @@ describe('HistoryManager constructor and lifecycle', () => {
|
|
|
515
516
|
})
|
|
516
517
|
|
|
517
518
|
it('should handle nested batch error scenarios', () => {
|
|
518
|
-
const mockAnnotateError =
|
|
519
|
+
const mockAnnotateError = vi.fn()
|
|
519
520
|
const manager = new HistoryManager({ store, annotateError: mockAnnotateError })
|
|
520
521
|
|
|
521
522
|
const nestedErrorFn = () => {
|
|
@@ -695,7 +696,7 @@ describe('HistoryManager error scenarios and edge cases', () => {
|
|
|
695
696
|
describe('squashToMark error handling', () => {
|
|
696
697
|
it('should handle non-existent mark gracefully', () => {
|
|
697
698
|
store.update(ids.a, (s) => ({ ...s, value: 1 }))
|
|
698
|
-
const consoleSpy =
|
|
699
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
699
700
|
|
|
700
701
|
manager.squashToMark('non-existent-mark')
|
|
701
702
|
|
|
@@ -707,7 +708,7 @@ describe('HistoryManager error scenarios and edge cases', () => {
|
|
|
707
708
|
})
|
|
708
709
|
|
|
709
710
|
it('should handle empty stack when squashing', () => {
|
|
710
|
-
const consoleSpy =
|
|
711
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
711
712
|
|
|
712
713
|
manager.squashToMark('non-existent')
|
|
713
714
|
|
|
@@ -780,7 +781,7 @@ describe('HistoryManager error scenarios and edge cases', () => {
|
|
|
780
781
|
})
|
|
781
782
|
|
|
782
783
|
it('should maintain batch state correctly during errors', () => {
|
|
783
|
-
const mockAnnotateError =
|
|
784
|
+
const mockAnnotateError = vi.fn()
|
|
784
785
|
const errorManager = new HistoryManager({ store, annotateError: mockAnnotateError })
|
|
785
786
|
|
|
786
787
|
try {
|
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { TLScribble } from '@tldraw/tlschema'
|
|
2
|
+
import { Mock, Mocked, vi } from 'vitest'
|
|
2
3
|
import { Editor } from '../../Editor'
|
|
3
4
|
import { ScribbleItem, ScribbleManager } from './ScribbleManager'
|
|
4
5
|
|
|
5
6
|
// Mock the Editor class
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
uniqueId:
|
|
7
|
+
vi.mock('../../Editor')
|
|
8
|
+
vi.mock('@tldraw/utils', () => ({
|
|
9
|
+
uniqueId: vi.fn(() => 'test-id'),
|
|
9
10
|
}))
|
|
10
11
|
|
|
11
12
|
describe('ScribbleManager', () => {
|
|
12
|
-
let editor:
|
|
13
|
+
let editor: Mocked<Editor>
|
|
13
14
|
let scribbleManager: ScribbleManager
|
|
14
|
-
let mockUniqueId:
|
|
15
|
+
let mockUniqueId: Mock
|
|
15
16
|
|
|
16
|
-
beforeEach(() => {
|
|
17
|
+
beforeEach(async () => {
|
|
17
18
|
editor = {
|
|
18
|
-
updateInstanceState:
|
|
19
|
-
run:
|
|
19
|
+
updateInstanceState: vi.fn(),
|
|
20
|
+
run: vi.fn((fn) => fn()),
|
|
20
21
|
} as any
|
|
21
22
|
|
|
22
|
-
const { uniqueId } =
|
|
23
|
-
mockUniqueId = uniqueId
|
|
23
|
+
const { uniqueId } = await vi.importMock('@tldraw/utils')
|
|
24
|
+
mockUniqueId = uniqueId as Mock
|
|
24
25
|
mockUniqueId.mockReturnValue('test-id')
|
|
25
26
|
|
|
26
27
|
scribbleManager = new ScribbleManager(editor)
|
|
27
28
|
})
|
|
28
29
|
|
|
29
30
|
afterEach(() => {
|
|
30
|
-
|
|
31
|
+
vi.clearAllMocks()
|
|
31
32
|
})
|
|
32
33
|
|
|
33
34
|
describe('constructor and initialization', () => {
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TLFrameShape,
|
|
3
|
+
TLGroupShape,
|
|
4
|
+
TLPageId,
|
|
5
|
+
TLShape,
|
|
6
|
+
TLShapeId,
|
|
7
|
+
createShapeId,
|
|
8
|
+
} from '@tldraw/tlschema'
|
|
9
|
+
import { Mocked, vi } from 'vitest'
|
|
2
10
|
import { Box } from '../../../primitives/Box'
|
|
3
11
|
import { Vec } from '../../../primitives/Vec'
|
|
4
12
|
import { Editor } from '../../Editor'
|
|
@@ -7,32 +15,33 @@ import { HandleSnaps } from './HandleSnaps'
|
|
|
7
15
|
import { GapsSnapIndicator, PointsSnapIndicator, SnapManager } from './SnapManager'
|
|
8
16
|
|
|
9
17
|
// Mock the Editor class
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
vi.mock('../../Editor')
|
|
19
|
+
vi.mock('./BoundsSnaps')
|
|
20
|
+
vi.mock('./HandleSnaps')
|
|
13
21
|
|
|
14
22
|
describe('SnapManager', () => {
|
|
15
|
-
let editor:
|
|
23
|
+
let editor: Mocked<Editor>
|
|
16
24
|
let snapManager: SnapManager
|
|
17
25
|
|
|
18
26
|
const createMockShape = (
|
|
19
27
|
id: TLShapeId,
|
|
20
28
|
type: string = 'geo',
|
|
21
29
|
parentId: TLShapeId | string = 'page:page'
|
|
22
|
-
) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
) =>
|
|
31
|
+
({
|
|
32
|
+
id,
|
|
33
|
+
type,
|
|
34
|
+
parentId,
|
|
35
|
+
x: 0,
|
|
36
|
+
y: 0,
|
|
37
|
+
rotation: 0,
|
|
38
|
+
index: 'a1' as const,
|
|
39
|
+
opacity: 1,
|
|
40
|
+
isLocked: false,
|
|
41
|
+
meta: {},
|
|
42
|
+
props: {},
|
|
43
|
+
typeName: 'shape' as const,
|
|
44
|
+
}) as TLShape
|
|
36
45
|
|
|
37
46
|
const createMockFrameShape = (id: TLShapeId): TLFrameShape =>
|
|
38
47
|
({
|
|
@@ -54,26 +63,26 @@ describe('SnapManager', () => {
|
|
|
54
63
|
|
|
55
64
|
beforeEach(() => {
|
|
56
65
|
editor = {
|
|
57
|
-
getZoomLevel:
|
|
58
|
-
getViewportPageBounds:
|
|
59
|
-
getSelectedShapeIds:
|
|
60
|
-
getSelectedShapes:
|
|
61
|
-
findCommonAncestor:
|
|
62
|
-
getCurrentPageId:
|
|
63
|
-
getSortedChildIdsForParent:
|
|
64
|
-
getShape:
|
|
65
|
-
getShapeUtil:
|
|
66
|
-
canSnap:
|
|
66
|
+
getZoomLevel: vi.fn(() => 1),
|
|
67
|
+
getViewportPageBounds: vi.fn(() => new Box(0, 0, 1000, 1000)),
|
|
68
|
+
getSelectedShapeIds: vi.fn(() => []),
|
|
69
|
+
getSelectedShapes: vi.fn(() => []),
|
|
70
|
+
findCommonAncestor: vi.fn(() => createShapeId('page')),
|
|
71
|
+
getCurrentPageId: vi.fn(() => 'page:page' as TLPageId),
|
|
72
|
+
getSortedChildIdsForParent: vi.fn(() => []),
|
|
73
|
+
getShape: vi.fn(),
|
|
74
|
+
getShapeUtil: vi.fn(() => ({
|
|
75
|
+
canSnap: vi.fn(() => true),
|
|
67
76
|
})),
|
|
68
|
-
getShapePageBounds:
|
|
69
|
-
isShapeOfType:
|
|
77
|
+
getShapePageBounds: vi.fn(),
|
|
78
|
+
isShapeOfType: vi.fn(),
|
|
70
79
|
} as any
|
|
71
80
|
|
|
72
81
|
snapManager = new SnapManager(editor)
|
|
73
82
|
})
|
|
74
83
|
|
|
75
84
|
afterEach(() => {
|
|
76
|
-
|
|
85
|
+
vi.clearAllMocks()
|
|
77
86
|
})
|
|
78
87
|
|
|
79
88
|
describe('constructor and initialization', () => {
|
|
@@ -304,7 +313,7 @@ describe('SnapManager', () => {
|
|
|
304
313
|
editor.getSortedChildIdsForParent.mockReturnValue([shapeId])
|
|
305
314
|
editor.getShape.mockReturnValue(shape as any)
|
|
306
315
|
editor.getShapeUtil.mockReturnValue({
|
|
307
|
-
canSnap:
|
|
316
|
+
canSnap: vi.fn(() => false),
|
|
308
317
|
} as any)
|
|
309
318
|
|
|
310
319
|
const result = snapManager.getSnappableShapes()
|
|
@@ -329,7 +338,7 @@ describe('SnapManager', () => {
|
|
|
329
338
|
const frameShape = createMockFrameShape(frameId)
|
|
330
339
|
|
|
331
340
|
editor.getSortedChildIdsForParent.mockReturnValue([frameId])
|
|
332
|
-
editor.getShape.mockReturnValue(frameShape
|
|
341
|
+
editor.getShape.mockReturnValue(frameShape)
|
|
333
342
|
editor.isShapeOfType.mockImplementation((_shape, type) => type === 'frame')
|
|
334
343
|
editor.getShapePageBounds.mockReturnValue(new Box(10, 10, 50, 50))
|
|
335
344
|
|
|
@@ -348,14 +357,12 @@ describe('SnapManager', () => {
|
|
|
348
357
|
.mockReturnValueOnce([childId]) // Inside group
|
|
349
358
|
|
|
350
359
|
editor.getShape.mockImplementation((id) => {
|
|
351
|
-
if (id === groupId) return groupShape
|
|
352
|
-
if (id === childId) return childShape
|
|
360
|
+
if (id === groupId) return groupShape
|
|
361
|
+
if (id === childId) return childShape
|
|
353
362
|
return undefined
|
|
354
363
|
})
|
|
355
364
|
|
|
356
|
-
editor.isShapeOfType.mockImplementation(
|
|
357
|
-
(shape, type) => shape && (shape as any).type === type
|
|
358
|
-
)
|
|
365
|
+
editor.isShapeOfType.mockImplementation((shape: any, type) => shape && shape.type === type)
|
|
359
366
|
|
|
360
367
|
editor.getShapePageBounds.mockReturnValue(new Box(10, 10, 50, 50))
|
|
361
368
|
|
|
@@ -372,26 +379,26 @@ describe('SnapManager', () => {
|
|
|
372
379
|
|
|
373
380
|
// Override the getCurrentCommonAncestor mock for this specific test
|
|
374
381
|
const originalGetCurrentCommonAncestor = snapManager.getCurrentCommonAncestor
|
|
375
|
-
|
|
382
|
+
vi.spyOn(snapManager, 'getCurrentCommonAncestor').mockReturnValue(parentFrameId)
|
|
376
383
|
|
|
377
384
|
editor.getSortedChildIdsForParent.mockReturnValueOnce([childFrameId]) // Children of parent frame
|
|
378
385
|
|
|
379
|
-
editor.getShape.mockImplementation((id) => {
|
|
386
|
+
editor.getShape.mockImplementation((id: any) => {
|
|
380
387
|
if (id === parentFrameId) return parentFrame as any
|
|
381
388
|
if (id === childFrameId) return childFrame as any
|
|
382
389
|
return undefined
|
|
383
390
|
})
|
|
384
391
|
|
|
385
|
-
editor.isShapeOfType.mockImplementation((shape, type) => type === 'frame')
|
|
392
|
+
editor.isShapeOfType.mockImplementation((shape: any, type: any) => type === 'frame')
|
|
386
393
|
editor.getShapePageBounds.mockReturnValue(new Box(10, 10, 50, 50))
|
|
387
394
|
|
|
388
395
|
const result = snapManager.getSnappableShapes()
|
|
389
396
|
expect(result.has(childFrameId)).toBe(true)
|
|
390
397
|
|
|
391
398
|
// Restore original method
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
399
|
+
vi.spyOn(snapManager, 'getCurrentCommonAncestor').mockImplementation(
|
|
400
|
+
originalGetCurrentCommonAncestor
|
|
401
|
+
)
|
|
395
402
|
})
|
|
396
403
|
|
|
397
404
|
it('should handle missing shape bounds gracefully', () => {
|
|
@@ -422,7 +429,7 @@ describe('SnapManager', () => {
|
|
|
422
429
|
|
|
423
430
|
// Override the getCurrentCommonAncestor mock for this specific test
|
|
424
431
|
const originalGetCurrentCommonAncestor = snapManager.getCurrentCommonAncestor
|
|
425
|
-
|
|
432
|
+
vi.spyOn(snapManager, 'getCurrentCommonAncestor').mockReturnValue(undefined)
|
|
426
433
|
|
|
427
434
|
editor.getCurrentPageId.mockReturnValue('page:current' as TLPageId)
|
|
428
435
|
editor.getSortedChildIdsForParent.mockReturnValue([shapeId])
|
|
@@ -433,9 +440,9 @@ describe('SnapManager', () => {
|
|
|
433
440
|
expect(editor.getSortedChildIdsForParent).toHaveBeenCalledWith('page:current')
|
|
434
441
|
|
|
435
442
|
// Restore original method
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
443
|
+
vi.spyOn(snapManager, 'getCurrentCommonAncestor').mockImplementation(
|
|
444
|
+
originalGetCurrentCommonAncestor
|
|
445
|
+
)
|
|
439
446
|
})
|
|
440
447
|
})
|
|
441
448
|
|
|
@@ -470,7 +477,7 @@ describe('SnapManager', () => {
|
|
|
470
477
|
|
|
471
478
|
// Test with second set of shapes
|
|
472
479
|
editor.getSortedChildIdsForParent.mockReturnValue([shapeId1, shapeId2])
|
|
473
|
-
editor.getShape.mockImplementation((id) => {
|
|
480
|
+
editor.getShape.mockImplementation((id: any) => {
|
|
474
481
|
if (id === shapeId1) return createMockShape(shapeId1) as any
|
|
475
482
|
if (id === shapeId2) return createMockShape(shapeId2) as any
|
|
476
483
|
return undefined
|