@tldraw/editor 3.16.0-next.df90ce0ff566 → 3.16.0-next.e57e478c23e0
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 +134 -110
- package/dist-cjs/index.js +3 -5
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +8 -6
- 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 +4 -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 +9 -3
- package/dist-cjs/lib/config/TLUserPreferences.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +77 -133
- 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 +13 -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 +31 -25
- package/dist-cjs/lib/hooks/useCanvasEvents.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/{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 +17 -22
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +5 -0
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/license/Watermark.js +8 -8
- package/dist-cjs/lib/license/Watermark.js.map +1 -1
- 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 +26 -18
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Group2d.js +3 -0
- 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/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 +134 -110
- package/dist-esm/index.mjs +3 -5
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +8 -6
- 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 +4 -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 +9 -3
- package/dist-esm/lib/config/TLUserPreferences.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +77 -133
- 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 +13 -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 +32 -26
- package/dist-esm/lib/hooks/useCanvasEvents.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/useStateAttribute.mjs +15 -0
- package/dist-esm/lib/hooks/useStateAttribute.mjs.map +7 -0
- package/dist-esm/lib/license/LicenseManager.mjs +17 -22
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +5 -0
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/license/Watermark.mjs +8 -8
- package/dist-esm/lib/license/Watermark.mjs.map +1 -1
- 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 +29 -19
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Group2d.mjs +3 -0
- 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/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 +301 -288
- package/package.json +14 -37
- package/src/index.ts +3 -9
- package/src/lib/TldrawEditor.tsx +13 -17
- package/src/lib/components/MenuClickCapture.tsx +0 -8
- package/src/lib/components/Shape.tsx +6 -12
- package/src/lib/components/default-components/DefaultCanvas.tsx +5 -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 +8 -1
- package/src/lib/editor/Editor.test.ts +12 -11
- package/src/lib/editor/Editor.ts +108 -193
- 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 +35 -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 +45 -38
- package/src/lib/hooks/usePassThroughMouseOverEvents.ts +4 -1
- package/src/lib/hooks/usePassThroughWheelEvents.ts +6 -1
- package/src/lib/hooks/useStateAttribute.ts +15 -0
- package/src/lib/license/LicenseManager.test.ts +61 -52
- package/src/lib/license/LicenseManager.ts +32 -24
- package/src/lib/license/LicenseProvider.tsx +8 -0
- package/src/lib/license/Watermark.test.tsx +2 -1
- package/src/lib/license/Watermark.tsx +8 -8
- 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.ts +49 -19
- package/src/lib/primitives/geometry/Group2d.ts +4 -0
- package/src/lib/utils/EditorAtom.ts +37 -0
- 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.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/src/lib/editor/Editor.ts
CHANGED
|
@@ -116,7 +116,6 @@ import {
|
|
|
116
116
|
} from '../constants'
|
|
117
117
|
import { exportToSvg } from '../exports/exportToSvg'
|
|
118
118
|
import { getSvgAsImage } from '../exports/getSvgAsImage'
|
|
119
|
-
import { tlenv } from '../globals/environment'
|
|
120
119
|
import { tlmenus } from '../globals/menus'
|
|
121
120
|
import { tltime } from '../globals/time'
|
|
122
121
|
import { TldrawOptions, defaultTldrawOptions } from '../options'
|
|
@@ -176,6 +175,7 @@ import {
|
|
|
176
175
|
RequiredKeys,
|
|
177
176
|
TLCameraMoveOptions,
|
|
178
177
|
TLCameraOptions,
|
|
178
|
+
TLGetShapeAtPointOptions,
|
|
179
179
|
TLImageExportOptions,
|
|
180
180
|
TLSvgExportOptions,
|
|
181
181
|
TLUpdatePointerOptions,
|
|
@@ -243,16 +243,6 @@ export interface TLEditorOptions {
|
|
|
243
243
|
options?: Partial<TldrawOptions>
|
|
244
244
|
licenseKey?: string
|
|
245
245
|
fontAssetUrls?: { [key: string]: string | undefined }
|
|
246
|
-
/**
|
|
247
|
-
* A predicate that should return true if the given shape should be hidden.
|
|
248
|
-
*
|
|
249
|
-
* @deprecated Use {@link Editor#getShapeVisibility} instead.
|
|
250
|
-
*
|
|
251
|
-
* @param shape - The shape to check.
|
|
252
|
-
* @param editor - The editor instance.
|
|
253
|
-
*/
|
|
254
|
-
isShapeHidden?(shape: TLShape, editor: Editor): boolean
|
|
255
|
-
|
|
256
246
|
/**
|
|
257
247
|
* Provides a way to hide shapes.
|
|
258
248
|
*
|
|
@@ -308,21 +298,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
308
298
|
autoFocus,
|
|
309
299
|
inferDarkMode,
|
|
310
300
|
options,
|
|
311
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
312
|
-
isShapeHidden,
|
|
313
301
|
getShapeVisibility,
|
|
314
302
|
fontAssetUrls,
|
|
315
303
|
}: TLEditorOptions) {
|
|
316
304
|
super()
|
|
317
|
-
assert(
|
|
318
|
-
!(isShapeHidden && getShapeVisibility),
|
|
319
|
-
'Cannot use both isShapeHidden and getShapeVisibility'
|
|
320
|
-
)
|
|
321
305
|
|
|
322
|
-
this._getShapeVisibility =
|
|
323
|
-
? // eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
324
|
-
(shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
|
|
325
|
-
: getShapeVisibility
|
|
306
|
+
this._getShapeVisibility = getShapeVisibility
|
|
326
307
|
|
|
327
308
|
this.options = { ...defaultTldrawOptions, ...options }
|
|
328
309
|
|
|
@@ -906,14 +887,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
906
887
|
*/
|
|
907
888
|
readonly fonts: FontManager
|
|
908
889
|
|
|
909
|
-
/**
|
|
910
|
-
* A manager for the editor's environment.
|
|
911
|
-
*
|
|
912
|
-
* @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
|
|
913
|
-
* @public
|
|
914
|
-
*/
|
|
915
|
-
readonly environment = tlenv
|
|
916
|
-
|
|
917
890
|
/**
|
|
918
891
|
* A manager for the editor's scribbles.
|
|
919
892
|
*
|
|
@@ -1118,35 +1091,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1118
1091
|
return this.history.getNumRedos() > 0
|
|
1119
1092
|
}
|
|
1120
1093
|
|
|
1121
|
-
/**
|
|
1122
|
-
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
1123
|
-
* any redos.
|
|
1124
|
-
*
|
|
1125
|
-
* @example
|
|
1126
|
-
* ```ts
|
|
1127
|
-
* editor.mark()
|
|
1128
|
-
* editor.mark('flip shapes')
|
|
1129
|
-
* ```
|
|
1130
|
-
*
|
|
1131
|
-
* @param markId - The mark's id, usually the reason for adding the mark.
|
|
1132
|
-
*
|
|
1133
|
-
* @public
|
|
1134
|
-
* @deprecated use {@link Editor.markHistoryStoppingPoint} instead
|
|
1135
|
-
*/
|
|
1136
|
-
mark(markId?: string): this {
|
|
1137
|
-
if (typeof markId === 'string') {
|
|
1138
|
-
console.warn(
|
|
1139
|
-
`[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
|
|
1140
|
-
)
|
|
1141
|
-
} else {
|
|
1142
|
-
console.warn(
|
|
1143
|
-
'[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead.'
|
|
1144
|
-
)
|
|
1145
|
-
}
|
|
1146
|
-
this.history._mark(markId ?? uniqueId())
|
|
1147
|
-
return this
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
1094
|
/**
|
|
1151
1095
|
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
1152
1096
|
* any redos. You typically want to do this just before a user interaction begins or is handled.
|
|
@@ -1271,13 +1215,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1271
1215
|
return this
|
|
1272
1216
|
}
|
|
1273
1217
|
|
|
1274
|
-
/**
|
|
1275
|
-
* @deprecated Use `Editor.run` instead.
|
|
1276
|
-
*/
|
|
1277
|
-
batch(fn: () => void, opts?: TLEditorRunOptions): this {
|
|
1278
|
-
return this.run(fn, opts)
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
1218
|
/* --------------------- Errors --------------------- */
|
|
1282
1219
|
|
|
1283
1220
|
/** @internal */
|
|
@@ -1579,54 +1516,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1579
1516
|
|
|
1580
1517
|
menus = tlmenus.forContext(this.contextId)
|
|
1581
1518
|
|
|
1582
|
-
/**
|
|
1583
|
-
* @deprecated Use `editor.menus.getOpenMenus` instead.
|
|
1584
|
-
*
|
|
1585
|
-
* @public
|
|
1586
|
-
*/
|
|
1587
|
-
@computed getOpenMenus(): string[] {
|
|
1588
|
-
return this.menus.getOpenMenus()
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
/**
|
|
1592
|
-
* @deprecated Use `editor.menus.addOpenMenu` instead.
|
|
1593
|
-
*
|
|
1594
|
-
* @public
|
|
1595
|
-
*/
|
|
1596
|
-
addOpenMenu(id: string): this {
|
|
1597
|
-
this.menus.addOpenMenu(id)
|
|
1598
|
-
return this
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
/**
|
|
1602
|
-
* @deprecated Use `editor.menus.deleteOpenMenu` instead.
|
|
1603
|
-
*
|
|
1604
|
-
* @public
|
|
1605
|
-
*/
|
|
1606
|
-
deleteOpenMenu(id: string): this {
|
|
1607
|
-
this.menus.deleteOpenMenu(id)
|
|
1608
|
-
return this
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
/**
|
|
1612
|
-
* @deprecated Use `editor.menus.clearOpenMenus` instead.
|
|
1613
|
-
*
|
|
1614
|
-
* @public
|
|
1615
|
-
*/
|
|
1616
|
-
clearOpenMenus(): this {
|
|
1617
|
-
this.menus.clearOpenMenus()
|
|
1618
|
-
return this
|
|
1619
|
-
}
|
|
1620
|
-
|
|
1621
|
-
/**
|
|
1622
|
-
* @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
|
|
1623
|
-
*
|
|
1624
|
-
* @public
|
|
1625
|
-
*/
|
|
1626
|
-
@computed getIsMenuOpen(): boolean {
|
|
1627
|
-
return this.menus.hasAnyOpenMenus()
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
1519
|
/* --------------------- Cursor --------------------- */
|
|
1631
1520
|
|
|
1632
1521
|
/**
|
|
@@ -4859,27 +4748,25 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4859
4748
|
return this.store.createComputedCache('pageMaskCache', (shape) => {
|
|
4860
4749
|
if (isPageId(shape.parentId)) return undefined
|
|
4861
4750
|
|
|
4862
|
-
const
|
|
4863
|
-
|
|
4864
|
-
)
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
return []
|
|
4882
|
-
})
|
|
4751
|
+
const clipPaths: Vec[][] = []
|
|
4752
|
+
// Get all ancestors that can potentially clip this shape
|
|
4753
|
+
for (const ancestor of this.getShapeAncestors(shape.id)) {
|
|
4754
|
+
const util = this.getShapeUtil(ancestor)
|
|
4755
|
+
const clipPath = util.getClipPath?.(ancestor)
|
|
4756
|
+
if (!clipPath) continue
|
|
4757
|
+
if (util.shouldClipChild?.(shape) === false) continue
|
|
4758
|
+
const pageTransform = this.getShapePageTransform(ancestor.id)
|
|
4759
|
+
clipPaths.push(pageTransform.applyToPoints(clipPath))
|
|
4760
|
+
}
|
|
4761
|
+
if (clipPaths.length === 0) return undefined
|
|
4762
|
+
|
|
4763
|
+
const pageMask = clipPaths.reduce((acc, b) => {
|
|
4764
|
+
const intersection = intersectPolygonPolygon(acc, b)
|
|
4765
|
+
if (intersection) {
|
|
4766
|
+
return intersection.map(Vec.Cast)
|
|
4767
|
+
}
|
|
4768
|
+
return []
|
|
4769
|
+
})
|
|
4883
4770
|
|
|
4884
4771
|
return pageMask
|
|
4885
4772
|
})
|
|
@@ -5154,20 +5041,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5154
5041
|
*
|
|
5155
5042
|
* @returns The shape at the given point, or undefined if there is no shape at the point.
|
|
5156
5043
|
*/
|
|
5157
|
-
getShapeAtPoint(
|
|
5158
|
-
point: VecLike,
|
|
5159
|
-
opts = {} as {
|
|
5160
|
-
renderingOnly?: boolean
|
|
5161
|
-
margin?: number
|
|
5162
|
-
hitInside?: boolean
|
|
5163
|
-
hitLocked?: boolean
|
|
5164
|
-
// TODO: we probably need to rename this, we don't quite _always_
|
|
5165
|
-
// respect this esp. in the part below that does "Check labels first"
|
|
5166
|
-
hitLabels?: boolean
|
|
5167
|
-
hitFrameInside?: boolean
|
|
5168
|
-
filter?(shape: TLShape): boolean
|
|
5169
|
-
}
|
|
5170
|
-
): TLShape | undefined {
|
|
5044
|
+
getShapeAtPoint(point: VecLike, opts: TLGetShapeAtPointOptions = {}): TLShape | undefined {
|
|
5171
5045
|
const zoomLevel = this.getZoomLevel()
|
|
5172
5046
|
const viewportPageBounds = this.getViewportPageBounds()
|
|
5173
5047
|
const {
|
|
@@ -5179,6 +5053,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5179
5053
|
hitFrameInside = false,
|
|
5180
5054
|
} = opts
|
|
5181
5055
|
|
|
5056
|
+
const [innerMargin, outerMargin] = Array.isArray(margin) ? margin : [margin, margin]
|
|
5057
|
+
|
|
5182
5058
|
let inHollowSmallestArea = Infinity
|
|
5183
5059
|
let inHollowSmallestAreaHit: TLShape | null = null
|
|
5184
5060
|
|
|
@@ -5198,7 +5074,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5198
5074
|
return false
|
|
5199
5075
|
const pageMask = this.getShapeMask(shape)
|
|
5200
5076
|
if (pageMask && !pointInPolygon(point, pageMask)) return false
|
|
5201
|
-
if (filter
|
|
5077
|
+
if (filter && !filter(shape)) return false
|
|
5202
5078
|
return true
|
|
5203
5079
|
})
|
|
5204
5080
|
|
|
@@ -5224,13 +5100,18 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5224
5100
|
}
|
|
5225
5101
|
}
|
|
5226
5102
|
|
|
5227
|
-
if (this.isShapeOfType(shape, 'frame')) {
|
|
5103
|
+
if (this.isShapeOfType<TLFrameShape>(shape, 'frame')) {
|
|
5228
5104
|
// On the rare case that we've hit a frame (not its label), test again hitInside to be forced true;
|
|
5229
5105
|
// this prevents clicks from passing through the body of a frame to shapes behind it.
|
|
5230
5106
|
|
|
5231
5107
|
// If the hit is within the frame's outer margin, then select the frame
|
|
5232
|
-
const distance = geometry.distanceToPoint(pointInShapeSpace,
|
|
5233
|
-
if (
|
|
5108
|
+
const distance = geometry.distanceToPoint(pointInShapeSpace, hitFrameInside)
|
|
5109
|
+
if (
|
|
5110
|
+
hitFrameInside
|
|
5111
|
+
? (distance > 0 && distance <= outerMargin) ||
|
|
5112
|
+
(distance <= 0 && distance > -innerMargin)
|
|
5113
|
+
: distance > 0 && distance <= outerMargin
|
|
5114
|
+
) {
|
|
5234
5115
|
return inMarginClosestToEdgeHit || shape
|
|
5235
5116
|
}
|
|
5236
5117
|
|
|
@@ -5269,11 +5150,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5269
5150
|
// If the margin is zero and the geometry has a very small width or height,
|
|
5270
5151
|
// then check the actual distance. This is to prevent a bug where straight
|
|
5271
5152
|
// lines would never pass the broad phase (point-in-bounds) check.
|
|
5272
|
-
if (
|
|
5153
|
+
if (outerMargin === 0 && (geometry.bounds.w < 1 || geometry.bounds.h < 1)) {
|
|
5273
5154
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside)
|
|
5274
5155
|
} else {
|
|
5275
5156
|
// Broad phase
|
|
5276
|
-
if (geometry.bounds.containsPoint(pointInShapeSpace,
|
|
5157
|
+
if (geometry.bounds.containsPoint(pointInShapeSpace, outerMargin)) {
|
|
5277
5158
|
// Narrow phase (actual distance)
|
|
5278
5159
|
distance = geometry.distanceToPoint(pointInShapeSpace, hitInside)
|
|
5279
5160
|
} else {
|
|
@@ -5288,7 +5169,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5288
5169
|
// the shape or negative if inside of the shape. If the distance
|
|
5289
5170
|
// is greater than the margin, then it's a miss. Otherwise...
|
|
5290
5171
|
|
|
5291
|
-
|
|
5172
|
+
// Are we close to the shape's edge?
|
|
5173
|
+
if (distance <= outerMargin || (hitInside && distance <= 0 && distance > -innerMargin)) {
|
|
5292
5174
|
if (geometry.isFilled || (isGroup && geometry.children[0].isFilled)) {
|
|
5293
5175
|
// If the shape is filled, then it's a hit. Remember, we're
|
|
5294
5176
|
// starting from the TOP-MOST shape in z-index order, so any
|
|
@@ -5298,11 +5180,21 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5298
5180
|
// If the shape is bigger than the viewport, then skip it.
|
|
5299
5181
|
if (this.getShapePageBounds(shape)!.contains(viewportPageBounds)) continue
|
|
5300
5182
|
|
|
5301
|
-
//
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5183
|
+
// If we're close to the edge of the shape, and if it's the closest edge among
|
|
5184
|
+
// all the edges that we've gotten close to so far, then we will want to hit the
|
|
5185
|
+
// shape unless we hit something else or closer in later iterations.
|
|
5186
|
+
if (
|
|
5187
|
+
hitInside
|
|
5188
|
+
? // On hitInside, the distance will be negative for hits inside
|
|
5189
|
+
// If the distance is positive, check against the outer margin
|
|
5190
|
+
(distance > 0 && distance <= outerMargin) ||
|
|
5191
|
+
// If the distance is negative, check against the inner margin
|
|
5192
|
+
(distance <= 0 && distance > -innerMargin)
|
|
5193
|
+
: // If hitInside is false, then sadly _we do not know_ whether the
|
|
5194
|
+
// point is inside or outside of the shape, so we check against
|
|
5195
|
+
// the max of the two margins
|
|
5196
|
+
Math.abs(distance) <= Math.max(innerMargin, outerMargin)
|
|
5197
|
+
) {
|
|
5306
5198
|
if (Math.abs(distance) < inMarginClosestToEdgeDistance) {
|
|
5307
5199
|
inMarginClosestToEdgeDistance = Math.abs(distance)
|
|
5308
5200
|
inMarginClosestToEdgeHit = shape
|
|
@@ -5324,6 +5216,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5324
5216
|
} else {
|
|
5325
5217
|
// For open shapes (e.g. lines or draw shapes) always use the margin.
|
|
5326
5218
|
// If the distance is less than the margin, return the shape as the hit.
|
|
5219
|
+
// Use the editor's configurable hit test margin.
|
|
5327
5220
|
if (distance < this.options.hitTestMargin / zoomLevel) {
|
|
5328
5221
|
return shape
|
|
5329
5222
|
}
|
|
@@ -5834,11 +5727,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5834
5727
|
return shapeIds
|
|
5835
5728
|
}
|
|
5836
5729
|
|
|
5837
|
-
/** @deprecated Use {@link Editor.getDraggingOverShape} instead */
|
|
5838
|
-
getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5839
|
-
return this.getDraggingOverShape(point, droppingShapes)
|
|
5840
|
-
}
|
|
5841
|
-
|
|
5842
5730
|
/**
|
|
5843
5731
|
* Get the shape that some shapes should be dropped on at a given point.
|
|
5844
5732
|
*
|
|
@@ -6326,7 +6214,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6326
6214
|
|
|
6327
6215
|
this.createShapes(shapesToCreate)
|
|
6328
6216
|
this.createBindings(bindingsToCreate)
|
|
6329
|
-
|
|
6217
|
+
|
|
6218
|
+
this.setSelectedShapes(
|
|
6219
|
+
compact(
|
|
6220
|
+
ids.map((oldId) => {
|
|
6221
|
+
const newId = shapeIds.get(oldId)
|
|
6222
|
+
if (!newId) return null
|
|
6223
|
+
if (!this.getShape(newId)) return null
|
|
6224
|
+
return newId
|
|
6225
|
+
})
|
|
6226
|
+
)
|
|
6227
|
+
)
|
|
6330
6228
|
|
|
6331
6229
|
if (offset !== undefined) {
|
|
6332
6230
|
// If we've offset the duplicated shapes, check to see whether their new bounds is entirely
|
|
@@ -7380,7 +7278,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7380
7278
|
if (
|
|
7381
7279
|
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7382
7280
|
type: 'stretch',
|
|
7383
|
-
shapes: shapesToStretchFirstPass,
|
|
7384
7281
|
})
|
|
7385
7282
|
) {
|
|
7386
7283
|
continue
|
|
@@ -7851,25 +7748,32 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7851
7748
|
) {
|
|
7852
7749
|
let parentId: TLParentId = this.getFocusedGroupId()
|
|
7853
7750
|
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
|
|
7872
|
-
|
|
7751
|
+
const isPositioned = partial.x !== undefined && partial.y !== undefined
|
|
7752
|
+
|
|
7753
|
+
// If the shape has been explicitly positioned, we'll try to find a parent at
|
|
7754
|
+
// that position. If not, we'll assume the user isn't deliberately placing the
|
|
7755
|
+
// shape and the positioning will be handled later by another system.
|
|
7756
|
+
if (isPositioned) {
|
|
7757
|
+
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
|
7758
|
+
const parent = currentPageShapesSorted[i]
|
|
7759
|
+
const util = this.getShapeUtil(parent)
|
|
7760
|
+
if (
|
|
7761
|
+
util.canReceiveNewChildrenOfType(parent, partial.type) &&
|
|
7762
|
+
!this.isShapeHidden(parent) &&
|
|
7763
|
+
this.isPointInShape(
|
|
7764
|
+
parent,
|
|
7765
|
+
// If no parent is provided, then we can treat the
|
|
7766
|
+
// shape's provided x/y as being in the page's space.
|
|
7767
|
+
{ x: partial.x ?? 0, y: partial.y ?? 0 },
|
|
7768
|
+
{
|
|
7769
|
+
margin: 0,
|
|
7770
|
+
hitInside: true,
|
|
7771
|
+
}
|
|
7772
|
+
)
|
|
7773
|
+
) {
|
|
7774
|
+
parentId = parent.id
|
|
7775
|
+
break
|
|
7776
|
+
}
|
|
7873
7777
|
}
|
|
7874
7778
|
}
|
|
7875
7779
|
|
|
@@ -9438,13 +9342,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9438
9342
|
}
|
|
9439
9343
|
}
|
|
9440
9344
|
|
|
9441
|
-
/** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
|
|
9442
|
-
async getSvg(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
|
|
9443
|
-
const result = await this.getSvgElement(shapes, opts)
|
|
9444
|
-
if (!result) return undefined
|
|
9445
|
-
return result.svg
|
|
9446
|
-
}
|
|
9447
|
-
|
|
9448
9345
|
/**
|
|
9449
9346
|
* Get an exported image of the given shapes.
|
|
9450
9347
|
*
|
|
@@ -9496,6 +9393,24 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9496
9393
|
}
|
|
9497
9394
|
}
|
|
9498
9395
|
|
|
9396
|
+
/**
|
|
9397
|
+
* Get an exported image of the given shapes as a data URL.
|
|
9398
|
+
*
|
|
9399
|
+
* @param shapes - The shapes (or shape ids) to export.
|
|
9400
|
+
* @param opts - Options for the export.
|
|
9401
|
+
*
|
|
9402
|
+
* @returns A data URL of the image.
|
|
9403
|
+
* @public
|
|
9404
|
+
*/
|
|
9405
|
+
async toImageDataUrl(shapes: TLShapeId[] | TLShape[], opts: TLImageExportOptions = {}) {
|
|
9406
|
+
const { blob, width, height } = await this.toImage(shapes, opts)
|
|
9407
|
+
return {
|
|
9408
|
+
url: await FileHelpers.blobToDataUrl(blob),
|
|
9409
|
+
width,
|
|
9410
|
+
height,
|
|
9411
|
+
}
|
|
9412
|
+
}
|
|
9413
|
+
|
|
9499
9414
|
/* --------------------- Events --------------------- */
|
|
9500
9415
|
|
|
9501
9416
|
/**
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { Mocked, vi } from 'vitest'
|
|
1
2
|
import { Editor } from '../../Editor'
|
|
2
3
|
import { TLClickEventInfo, TLPointerEventInfo } from '../../types/event-types'
|
|
3
4
|
import { ClickManager } from './ClickManager'
|
|
4
5
|
|
|
5
6
|
// Mock the Editor class
|
|
6
|
-
|
|
7
|
+
vi.mock('../../Editor')
|
|
7
8
|
|
|
8
9
|
describe('ClickManager', () => {
|
|
9
|
-
let editor:
|
|
10
|
+
let editor: Mocked<Editor>
|
|
10
11
|
let clickManager: ClickManager
|
|
11
12
|
let mockTimers: any
|
|
12
13
|
|
|
@@ -29,14 +30,14 @@ describe('ClickManager', () => {
|
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
beforeEach(() => {
|
|
32
|
-
|
|
33
|
+
vi.useFakeTimers()
|
|
33
34
|
mockTimers = {
|
|
34
|
-
setTimeout:
|
|
35
|
+
setTimeout: vi.fn((fn, delay) => setTimeout(fn, delay)),
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
editor = {
|
|
38
39
|
timers: mockTimers,
|
|
39
|
-
dispatch:
|
|
40
|
+
dispatch: vi.fn(),
|
|
40
41
|
options: {
|
|
41
42
|
doubleClickDurationMs: 300,
|
|
42
43
|
multiClickDurationMs: 300,
|
|
@@ -46,7 +47,7 @@ describe('ClickManager', () => {
|
|
|
46
47
|
inputs: {
|
|
47
48
|
currentScreenPoint: { x: 0, y: 0 },
|
|
48
49
|
},
|
|
49
|
-
getInstanceState:
|
|
50
|
+
getInstanceState: vi.fn(() => ({
|
|
50
51
|
isCoarsePointer: false,
|
|
51
52
|
})),
|
|
52
53
|
} as any
|
|
@@ -55,8 +56,8 @@ describe('ClickManager', () => {
|
|
|
55
56
|
})
|
|
56
57
|
|
|
57
58
|
afterEach(() => {
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
vi.useRealTimers()
|
|
60
|
+
vi.clearAllMocks()
|
|
60
61
|
})
|
|
61
62
|
|
|
62
63
|
describe('constructor and initial state', () => {
|
|
@@ -100,7 +101,7 @@ describe('ClickManager', () => {
|
|
|
100
101
|
clickManager.handlePointerEvent(pointerEvent)
|
|
101
102
|
expect(clickManager.clickState).toBe('pendingDouble')
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
vi.advanceTimersByTime(350)
|
|
104
105
|
|
|
105
106
|
expect(clickManager.clickState).toBe('idle')
|
|
106
107
|
})
|
|
@@ -141,7 +142,7 @@ describe('ClickManager', () => {
|
|
|
141
142
|
clickManager.handlePointerEvent(firstDown)
|
|
142
143
|
clickManager.handlePointerEvent(secondDown)
|
|
143
144
|
|
|
144
|
-
|
|
145
|
+
vi.advanceTimersByTime(350)
|
|
145
146
|
|
|
146
147
|
expect(editor.dispatch).toHaveBeenCalledWith(
|
|
147
148
|
expect.objectContaining({
|
|
@@ -235,7 +236,7 @@ describe('ClickManager', () => {
|
|
|
235
236
|
clickManager.handlePointerEvent(pointerDown) // second
|
|
236
237
|
clickManager.handlePointerEvent(pointerDown) // third
|
|
237
238
|
|
|
238
|
-
|
|
239
|
+
vi.advanceTimersByTime(350)
|
|
239
240
|
|
|
240
241
|
expect(editor.dispatch).toHaveBeenCalledWith(
|
|
241
242
|
expect.objectContaining({
|
|
@@ -255,7 +256,7 @@ describe('ClickManager', () => {
|
|
|
255
256
|
clickManager.handlePointerEvent(pointerDown) // third
|
|
256
257
|
clickManager.handlePointerEvent(pointerDown) // fourth
|
|
257
258
|
|
|
258
|
-
|
|
259
|
+
vi.advanceTimersByTime(350)
|
|
259
260
|
|
|
260
261
|
expect(editor.dispatch).toHaveBeenCalledWith(
|
|
261
262
|
expect.objectContaining({
|
|
@@ -277,7 +278,7 @@ describe('ClickManager', () => {
|
|
|
277
278
|
editor.options.doubleClickDurationMs
|
|
278
279
|
)
|
|
279
280
|
|
|
280
|
-
|
|
281
|
+
vi.clearAllMocks()
|
|
281
282
|
|
|
282
283
|
// Second click - should use multiClickDurationMs
|
|
283
284
|
clickManager.handlePointerEvent(pointerDown)
|
|
@@ -392,7 +393,7 @@ describe('ClickManager', () => {
|
|
|
392
393
|
clickManager.cancelDoubleClickTimeout()
|
|
393
394
|
|
|
394
395
|
// Advance time - should not dispatch settle event
|
|
395
|
-
|
|
396
|
+
vi.advanceTimersByTime(350)
|
|
396
397
|
|
|
397
398
|
expect(editor.dispatch).not.toHaveBeenCalled()
|
|
398
399
|
expect(clickManager.clickState).toBe('idle')
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { Mock, Mocked, vi } from 'vitest'
|
|
1
2
|
import { Box } from '../../../primitives/Box'
|
|
2
3
|
import { Vec } from '../../../primitives/Vec'
|
|
3
4
|
import { Editor } from '../../Editor'
|
|
4
5
|
import { EdgeScrollManager } from './EdgeScrollManager'
|
|
5
6
|
|
|
6
7
|
// Mock the Editor class
|
|
7
|
-
|
|
8
|
+
vi.mock('../../Editor')
|
|
8
9
|
|
|
9
10
|
describe('EdgeScrollManager', () => {
|
|
10
|
-
let editor:
|
|
11
|
+
let editor: Mocked<
|
|
11
12
|
Editor & {
|
|
12
|
-
user: { getEdgeScrollSpeed:
|
|
13
|
-
getCamera:
|
|
14
|
-
getCameraOptions:
|
|
15
|
-
getZoomLevel:
|
|
16
|
-
getViewportScreenBounds:
|
|
13
|
+
user: { getEdgeScrollSpeed: Mock }
|
|
14
|
+
getCamera: Mock
|
|
15
|
+
getCameraOptions: Mock
|
|
16
|
+
getZoomLevel: Mock
|
|
17
|
+
getViewportScreenBounds: Mock
|
|
17
18
|
}
|
|
18
19
|
>
|
|
19
20
|
let edgeScrollManager: EdgeScrollManager
|
|
@@ -33,33 +34,33 @@ describe('EdgeScrollManager', () => {
|
|
|
33
34
|
isPanning: false,
|
|
34
35
|
},
|
|
35
36
|
user: {
|
|
36
|
-
getEdgeScrollSpeed:
|
|
37
|
+
getEdgeScrollSpeed: vi.fn(() => 1),
|
|
37
38
|
},
|
|
38
|
-
getViewportScreenBounds:
|
|
39
|
-
getInstanceState:
|
|
39
|
+
getViewportScreenBounds: vi.fn(() => new Box(0, 0, 1000, 600)),
|
|
40
|
+
getInstanceState: vi.fn(
|
|
40
41
|
() =>
|
|
41
42
|
({
|
|
42
43
|
isCoarsePointer: false,
|
|
43
44
|
insets: [false, false, false, false], // [top, right, bottom, left]
|
|
44
45
|
}) as any
|
|
45
46
|
),
|
|
46
|
-
getCameraOptions:
|
|
47
|
+
getCameraOptions: vi.fn(() => ({
|
|
47
48
|
isLocked: false,
|
|
48
49
|
panSpeed: 1,
|
|
49
50
|
zoomSpeed: 1,
|
|
50
51
|
zoomSteps: [1],
|
|
51
52
|
wheelBehavior: 'pan' as const,
|
|
52
53
|
})),
|
|
53
|
-
getZoomLevel:
|
|
54
|
-
getCamera:
|
|
55
|
-
setCamera:
|
|
54
|
+
getZoomLevel: vi.fn(() => 1),
|
|
55
|
+
getCamera: vi.fn(() => new Vec(0, 0, 1)),
|
|
56
|
+
setCamera: vi.fn(),
|
|
56
57
|
} as any
|
|
57
58
|
|
|
58
59
|
edgeScrollManager = new EdgeScrollManager(editor as any)
|
|
59
60
|
})
|
|
60
61
|
|
|
61
62
|
afterEach(() => {
|
|
62
|
-
|
|
63
|
+
vi.clearAllMocks()
|
|
63
64
|
})
|
|
64
65
|
|
|
65
66
|
describe('constructor and initialization', () => {
|