@tldraw/editor 3.16.0-canary.bcde131f3274 → 3.16.0-canary.bf7be9dad88b
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 +83 -104
- package/dist-cjs/index.js +6 -6
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +2 -6
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +11 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +23 -113
- 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/shapes/ShapeUtil.js +10 -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/hooks/useCanvasEvents.js +15 -12
- 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/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 +143 -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/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 +83 -104
- package/dist-esm/index.mjs +9 -7
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +3 -7
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +12 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +23 -113
- 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/shapes/ShapeUtil.mjs +10 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +17 -13
- 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/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 +144 -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/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 +8 -3
- package/package.json +7 -7
- package/src/index.ts +4 -9
- package/src/lib/TldrawEditor.tsx +3 -15
- package/src/lib/components/default-components/DefaultCanvas.tsx +8 -2
- package/src/lib/editor/Editor.test.ts +90 -0
- package/src/lib/editor/Editor.ts +36 -150
- package/src/lib/editor/derivations/notVisibleShapes.ts +6 -0
- package/src/lib/editor/managers/FocusManager/FocusManager.ts +6 -2
- package/src/lib/editor/shapes/ShapeUtil.ts +32 -0
- package/src/lib/editor/types/misc-types.ts +0 -6
- package/src/lib/hooks/useCanvasEvents.ts +17 -11
- 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/useSelectionEvents.ts +6 -5
- package/src/lib/license/LicenseManager.test.ts +721 -382
- package/src/lib/license/LicenseManager.ts +204 -58
- package/src/lib/license/LicenseProvider.tsx +74 -2
- package/src/lib/license/Watermark.tsx +151 -77
- package/src/lib/license/useLicenseManagerState.ts +2 -2
- 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/version.ts +3 -3
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'
|
|
@@ -244,16 +243,6 @@ export interface TLEditorOptions {
|
|
|
244
243
|
options?: Partial<TldrawOptions>
|
|
245
244
|
licenseKey?: string
|
|
246
245
|
fontAssetUrls?: { [key: string]: string | undefined }
|
|
247
|
-
/**
|
|
248
|
-
* A predicate that should return true if the given shape should be hidden.
|
|
249
|
-
*
|
|
250
|
-
* @deprecated Use {@link Editor#getShapeVisibility} instead.
|
|
251
|
-
*
|
|
252
|
-
* @param shape - The shape to check.
|
|
253
|
-
* @param editor - The editor instance.
|
|
254
|
-
*/
|
|
255
|
-
isShapeHidden?(shape: TLShape, editor: Editor): boolean
|
|
256
|
-
|
|
257
246
|
/**
|
|
258
247
|
* Provides a way to hide shapes.
|
|
259
248
|
*
|
|
@@ -309,21 +298,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
309
298
|
autoFocus,
|
|
310
299
|
inferDarkMode,
|
|
311
300
|
options,
|
|
312
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
313
|
-
isShapeHidden,
|
|
314
301
|
getShapeVisibility,
|
|
315
302
|
fontAssetUrls,
|
|
316
303
|
}: TLEditorOptions) {
|
|
317
304
|
super()
|
|
318
|
-
assert(
|
|
319
|
-
!(isShapeHidden && getShapeVisibility),
|
|
320
|
-
'Cannot use both isShapeHidden and getShapeVisibility'
|
|
321
|
-
)
|
|
322
305
|
|
|
323
|
-
this._getShapeVisibility =
|
|
324
|
-
? // eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
325
|
-
(shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
|
|
326
|
-
: getShapeVisibility
|
|
306
|
+
this._getShapeVisibility = getShapeVisibility
|
|
327
307
|
|
|
328
308
|
this.options = { ...defaultTldrawOptions, ...options }
|
|
329
309
|
|
|
@@ -907,14 +887,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
907
887
|
*/
|
|
908
888
|
readonly fonts: FontManager
|
|
909
889
|
|
|
910
|
-
/**
|
|
911
|
-
* A manager for the editor's environment.
|
|
912
|
-
*
|
|
913
|
-
* @deprecated This is deprecated and will be removed in a future version. Use the `tlenv` global export instead.
|
|
914
|
-
* @public
|
|
915
|
-
*/
|
|
916
|
-
readonly environment = tlenv
|
|
917
|
-
|
|
918
890
|
/**
|
|
919
891
|
* A manager for the editor's scribbles.
|
|
920
892
|
*
|
|
@@ -1119,35 +1091,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1119
1091
|
return this.history.getNumRedos() > 0
|
|
1120
1092
|
}
|
|
1121
1093
|
|
|
1122
|
-
/**
|
|
1123
|
-
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
1124
|
-
* any redos.
|
|
1125
|
-
*
|
|
1126
|
-
* @example
|
|
1127
|
-
* ```ts
|
|
1128
|
-
* editor.mark()
|
|
1129
|
-
* editor.mark('flip shapes')
|
|
1130
|
-
* ```
|
|
1131
|
-
*
|
|
1132
|
-
* @param markId - The mark's id, usually the reason for adding the mark.
|
|
1133
|
-
*
|
|
1134
|
-
* @public
|
|
1135
|
-
* @deprecated use {@link Editor.markHistoryStoppingPoint} instead
|
|
1136
|
-
*/
|
|
1137
|
-
mark(markId?: string): this {
|
|
1138
|
-
if (typeof markId === 'string') {
|
|
1139
|
-
console.warn(
|
|
1140
|
-
`[tldraw] \`editor.history.mark("${markId}")\` is deprecated. Please use \`const myMarkId = editor.markHistoryStoppingPoint()\` instead.`
|
|
1141
|
-
)
|
|
1142
|
-
} else {
|
|
1143
|
-
console.warn(
|
|
1144
|
-
'[tldraw] `editor.mark()` is deprecated. Use `editor.markHistoryStoppingPoint()` instead.'
|
|
1145
|
-
)
|
|
1146
|
-
}
|
|
1147
|
-
this.history._mark(markId ?? uniqueId())
|
|
1148
|
-
return this
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
1094
|
/**
|
|
1152
1095
|
* Create a new "mark", or stopping point, in the undo redo history. Creating a mark will clear
|
|
1153
1096
|
* any redos. You typically want to do this just before a user interaction begins or is handled.
|
|
@@ -1272,13 +1215,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1272
1215
|
return this
|
|
1273
1216
|
}
|
|
1274
1217
|
|
|
1275
|
-
/**
|
|
1276
|
-
* @deprecated Use `Editor.run` instead.
|
|
1277
|
-
*/
|
|
1278
|
-
batch(fn: () => void, opts?: TLEditorRunOptions): this {
|
|
1279
|
-
return this.run(fn, opts)
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
1218
|
/* --------------------- Errors --------------------- */
|
|
1283
1219
|
|
|
1284
1220
|
/** @internal */
|
|
@@ -1580,54 +1516,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1580
1516
|
|
|
1581
1517
|
menus = tlmenus.forContext(this.contextId)
|
|
1582
1518
|
|
|
1583
|
-
/**
|
|
1584
|
-
* @deprecated Use `editor.menus.getOpenMenus` instead.
|
|
1585
|
-
*
|
|
1586
|
-
* @public
|
|
1587
|
-
*/
|
|
1588
|
-
@computed getOpenMenus(): string[] {
|
|
1589
|
-
return this.menus.getOpenMenus()
|
|
1590
|
-
}
|
|
1591
|
-
|
|
1592
|
-
/**
|
|
1593
|
-
* @deprecated Use `editor.menus.addOpenMenu` instead.
|
|
1594
|
-
*
|
|
1595
|
-
* @public
|
|
1596
|
-
*/
|
|
1597
|
-
addOpenMenu(id: string): this {
|
|
1598
|
-
this.menus.addOpenMenu(id)
|
|
1599
|
-
return this
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
|
-
/**
|
|
1603
|
-
* @deprecated Use `editor.menus.deleteOpenMenu` instead.
|
|
1604
|
-
*
|
|
1605
|
-
* @public
|
|
1606
|
-
*/
|
|
1607
|
-
deleteOpenMenu(id: string): this {
|
|
1608
|
-
this.menus.deleteOpenMenu(id)
|
|
1609
|
-
return this
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
/**
|
|
1613
|
-
* @deprecated Use `editor.menus.clearOpenMenus` instead.
|
|
1614
|
-
*
|
|
1615
|
-
* @public
|
|
1616
|
-
*/
|
|
1617
|
-
clearOpenMenus(): this {
|
|
1618
|
-
this.menus.clearOpenMenus()
|
|
1619
|
-
return this
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
/**
|
|
1623
|
-
* @deprecated Use `editor.menus.hasAnyOpenMenus` instead.
|
|
1624
|
-
*
|
|
1625
|
-
* @public
|
|
1626
|
-
*/
|
|
1627
|
-
@computed getIsMenuOpen(): boolean {
|
|
1628
|
-
return this.menus.hasAnyOpenMenus()
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
1519
|
/* --------------------- Cursor --------------------- */
|
|
1632
1520
|
|
|
1633
1521
|
/**
|
|
@@ -4792,8 +4680,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4792
4680
|
return this.store.createComputedCache<Box, TLShape>('pageBoundsCache', (shape) => {
|
|
4793
4681
|
const pageTransform = this.getShapePageTransform(shape)
|
|
4794
4682
|
if (!pageTransform) return undefined
|
|
4795
|
-
|
|
4796
|
-
return Box.FromPoints(
|
|
4683
|
+
|
|
4684
|
+
return Box.FromPoints(
|
|
4685
|
+
pageTransform.applyToPoints(this.getShapeGeometry(shape).boundsVertices)
|
|
4686
|
+
)
|
|
4797
4687
|
})
|
|
4798
4688
|
}
|
|
4799
4689
|
|
|
@@ -4860,27 +4750,25 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4860
4750
|
return this.store.createComputedCache('pageMaskCache', (shape) => {
|
|
4861
4751
|
if (isPageId(shape.parentId)) return undefined
|
|
4862
4752
|
|
|
4863
|
-
const
|
|
4864
|
-
|
|
4865
|
-
)
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
return []
|
|
4883
|
-
})
|
|
4753
|
+
const clipPaths: Vec[][] = []
|
|
4754
|
+
// Get all ancestors that can potentially clip this shape
|
|
4755
|
+
for (const ancestor of this.getShapeAncestors(shape.id)) {
|
|
4756
|
+
const util = this.getShapeUtil(ancestor)
|
|
4757
|
+
const clipPath = util.getClipPath?.(ancestor)
|
|
4758
|
+
if (!clipPath) continue
|
|
4759
|
+
if (util.shouldClipChild?.(shape) === false) continue
|
|
4760
|
+
const pageTransform = this.getShapePageTransform(ancestor.id)
|
|
4761
|
+
clipPaths.push(pageTransform.applyToPoints(clipPath))
|
|
4762
|
+
}
|
|
4763
|
+
if (clipPaths.length === 0) return undefined
|
|
4764
|
+
|
|
4765
|
+
const pageMask = clipPaths.reduce((acc, b) => {
|
|
4766
|
+
const intersection = intersectPolygonPolygon(acc, b)
|
|
4767
|
+
if (intersection) {
|
|
4768
|
+
return intersection.map(Vec.Cast)
|
|
4769
|
+
}
|
|
4770
|
+
return []
|
|
4771
|
+
})
|
|
4884
4772
|
|
|
4885
4773
|
return pageMask
|
|
4886
4774
|
})
|
|
@@ -5841,11 +5729,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5841
5729
|
return shapeIds
|
|
5842
5730
|
}
|
|
5843
5731
|
|
|
5844
|
-
/** @deprecated Use {@link Editor.getDraggingOverShape} instead */
|
|
5845
|
-
getDroppingOverShape(point: Vec, droppingShapes: TLShape[]): TLShape | undefined {
|
|
5846
|
-
return this.getDraggingOverShape(point, droppingShapes)
|
|
5847
|
-
}
|
|
5848
|
-
|
|
5849
5732
|
/**
|
|
5850
5733
|
* Get the shape that some shapes should be dropped on at a given point.
|
|
5851
5734
|
*
|
|
@@ -8950,8 +8833,13 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8950
8833
|
* Handle external content, such as files, urls, embeds, or plain text which has been put into the app, for example by pasting external text or dropping external images onto canvas.
|
|
8951
8834
|
*
|
|
8952
8835
|
* @param info - Info about the external content.
|
|
8836
|
+
* @param opts - Options for handling external content, including force flag to bypass readonly checks.
|
|
8953
8837
|
*/
|
|
8954
|
-
async putExternalContent<E>(
|
|
8838
|
+
async putExternalContent<E>(
|
|
8839
|
+
info: TLExternalContent<E>,
|
|
8840
|
+
opts = {} as { force?: boolean }
|
|
8841
|
+
): Promise<void> {
|
|
8842
|
+
if (!opts.force && this.getIsReadonly()) return
|
|
8955
8843
|
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8956
8844
|
}
|
|
8957
8845
|
|
|
@@ -8959,8 +8847,13 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8959
8847
|
* Handle replacing external content.
|
|
8960
8848
|
*
|
|
8961
8849
|
* @param info - Info about the external content.
|
|
8850
|
+
* @param opts - Options for handling external content, including force flag to bypass readonly checks.
|
|
8962
8851
|
*/
|
|
8963
|
-
async replaceExternalContent<E>(
|
|
8852
|
+
async replaceExternalContent<E>(
|
|
8853
|
+
info: TLExternalContent<E>,
|
|
8854
|
+
opts = {} as { force?: boolean }
|
|
8855
|
+
): Promise<void> {
|
|
8856
|
+
if (!opts.force && this.getIsReadonly()) return
|
|
8964
8857
|
return this.externalContentHandlers[info.type]?.(info as any)
|
|
8965
8858
|
}
|
|
8966
8859
|
|
|
@@ -9461,13 +9354,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9461
9354
|
}
|
|
9462
9355
|
}
|
|
9463
9356
|
|
|
9464
|
-
/** @deprecated Use {@link Editor.getSvgString} or {@link Editor.getSvgElement} instead. */
|
|
9465
|
-
async getSvg(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
|
|
9466
|
-
const result = await this.getSvgElement(shapes, opts)
|
|
9467
|
-
if (!result) return undefined
|
|
9468
|
-
return result.svg
|
|
9469
|
-
}
|
|
9470
|
-
|
|
9471
9357
|
/**
|
|
9472
9358
|
* Get an exported image of the given shapes.
|
|
9473
9359
|
*
|
|
@@ -7,6 +7,12 @@ function fromScratch(editor: Editor): Set<TLShapeId> {
|
|
|
7
7
|
const viewportPageBounds = editor.getViewportPageBounds()
|
|
8
8
|
const notVisibleShapes = new Set<TLShapeId>()
|
|
9
9
|
shapesIds.forEach((id) => {
|
|
10
|
+
const shape = editor.getShape(id)
|
|
11
|
+
if (!shape) return
|
|
12
|
+
|
|
13
|
+
const canCull = editor.getShapeUtil(shape.type).canCull(shape)
|
|
14
|
+
if (!canCull) return
|
|
15
|
+
|
|
10
16
|
// If the shape is fully outside of the viewport page bounds, add it to the set.
|
|
11
17
|
// We'll ignore masks here, since they're more expensive to compute and the overhead is not worth it.
|
|
12
18
|
const pageBounds = editor.getShapePageBounds(id)
|
|
@@ -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
|
}
|
|
@@ -283,6 +283,17 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
283
283
|
return true
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Whether this shape can be culled. By default, shapes are culled for
|
|
288
|
+
* performance reasons when they are outside of the viewport. Culled shapes are still rendered
|
|
289
|
+
* to the DOM, but have their `display` property set to `none`.
|
|
290
|
+
*
|
|
291
|
+
* @param shape - The shape.
|
|
292
|
+
*/
|
|
293
|
+
canCull(_shape: Shape): boolean {
|
|
294
|
+
return true
|
|
295
|
+
}
|
|
296
|
+
|
|
286
297
|
/**
|
|
287
298
|
* Does this shape provide a background for its children? If this is true,
|
|
288
299
|
* then any children with a `renderBackground` method will have their
|
|
@@ -296,6 +307,27 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
|
|
|
296
307
|
return false
|
|
297
308
|
}
|
|
298
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Get the clip path to apply to this shape's children.
|
|
312
|
+
*
|
|
313
|
+
* @param shape - The shape to get the clip path for
|
|
314
|
+
* @returns Array of points defining the clipping polygon in local coordinates, or undefined if no clipping
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
getClipPath?(shape: Shape): Vec[] | undefined
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Whether a specific child shape should be clipped by this shape.
|
|
321
|
+
* Only called if getClipPath returns a valid polygon.
|
|
322
|
+
*
|
|
323
|
+
* If not defined, the default behavior is to clip all children.
|
|
324
|
+
*
|
|
325
|
+
* @param child - The child shape to check
|
|
326
|
+
* @returns boolean indicating if this child should be clipped
|
|
327
|
+
* @public
|
|
328
|
+
*/
|
|
329
|
+
shouldClipChild?(child: TLShape): boolean
|
|
330
|
+
|
|
299
331
|
/**
|
|
300
332
|
* Whether the shape should hide its resize handles when selected.
|
|
301
333
|
*
|
|
@@ -72,12 +72,6 @@ export interface TLImageExportOptions extends TLSvgExportOptions {
|
|
|
72
72
|
format?: TLExportType
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* @public
|
|
77
|
-
* @deprecated use {@link TLImageExportOptions} instead
|
|
78
|
-
*/
|
|
79
|
-
export type TLSvgOptions = TLImageExportOptions
|
|
80
|
-
|
|
81
75
|
/** @public */
|
|
82
76
|
export interface TLCameraMoveOptions {
|
|
83
77
|
/** Whether to move the camera immediately, rather than on the next tick. */
|
|
@@ -2,10 +2,11 @@ import { useValue } from '@tldraw/state-react'
|
|
|
2
2
|
import React, { useEffect, useMemo } from 'react'
|
|
3
3
|
import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
4
4
|
import {
|
|
5
|
+
markEventAsHandled,
|
|
5
6
|
preventDefault,
|
|
6
7
|
releasePointerCapture,
|
|
7
8
|
setPointerCapture,
|
|
8
|
-
|
|
9
|
+
wasEventAlreadyHandled,
|
|
9
10
|
} from '../utils/dom'
|
|
10
11
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
11
12
|
import { useEditor } from './useEditor'
|
|
@@ -17,7 +18,7 @@ export function useCanvasEvents() {
|
|
|
17
18
|
const events = useMemo(
|
|
18
19
|
function canvasEvents() {
|
|
19
20
|
function onPointerDown(e: React.PointerEvent) {
|
|
20
|
-
if ((e
|
|
21
|
+
if (wasEventAlreadyHandled(e)) return
|
|
21
22
|
|
|
22
23
|
if (e.button === RIGHT_MOUSE_BUTTON) {
|
|
23
24
|
editor.dispatch({
|
|
@@ -42,7 +43,7 @@ export function useCanvasEvents() {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
function onPointerUp(e: React.PointerEvent) {
|
|
45
|
-
if ((e
|
|
46
|
+
if (wasEventAlreadyHandled(e)) return
|
|
46
47
|
if (e.button !== 0 && e.button !== 1 && e.button !== 2 && e.button !== 5) return
|
|
47
48
|
|
|
48
49
|
releasePointerCapture(e.currentTarget, e)
|
|
@@ -56,26 +57,28 @@ export function useCanvasEvents() {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
function onPointerEnter(e: React.PointerEvent) {
|
|
59
|
-
if ((e
|
|
60
|
+
if (wasEventAlreadyHandled(e)) return
|
|
60
61
|
if (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return
|
|
61
62
|
const canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'
|
|
62
63
|
editor.updateInstanceState({ isHoveringCanvas: canHover ? true : null })
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
function onPointerLeave(e: React.PointerEvent) {
|
|
66
|
-
if ((e
|
|
67
|
+
if (wasEventAlreadyHandled(e)) return
|
|
67
68
|
if (editor.getInstanceState().isPenMode && e.pointerType !== 'pen') return
|
|
68
69
|
const canHover = e.pointerType === 'mouse' || e.pointerType === 'pen'
|
|
69
70
|
editor.updateInstanceState({ isHoveringCanvas: canHover ? false : null })
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function onTouchStart(e: React.TouchEvent) {
|
|
73
|
-
|
|
74
|
+
if (wasEventAlreadyHandled(e)) return
|
|
75
|
+
markEventAsHandled(e)
|
|
74
76
|
preventDefault(e)
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
function onTouchEnd(e: React.TouchEvent) {
|
|
78
|
-
|
|
80
|
+
if (wasEventAlreadyHandled(e)) return
|
|
81
|
+
markEventAsHandled(e)
|
|
79
82
|
// check that e.target is an HTMLElement
|
|
80
83
|
if (!(e.target instanceof HTMLElement)) return
|
|
81
84
|
|
|
@@ -94,12 +97,14 @@ export function useCanvasEvents() {
|
|
|
94
97
|
}
|
|
95
98
|
|
|
96
99
|
function onDragOver(e: React.DragEvent<Element>) {
|
|
100
|
+
if (wasEventAlreadyHandled(e)) return
|
|
97
101
|
preventDefault(e)
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
async function onDrop(e: React.DragEvent<Element>) {
|
|
105
|
+
if (wasEventAlreadyHandled(e)) return
|
|
101
106
|
preventDefault(e)
|
|
102
|
-
|
|
107
|
+
e.stopPropagation()
|
|
103
108
|
|
|
104
109
|
if (e.dataTransfer?.files?.length) {
|
|
105
110
|
const files = Array.from(e.dataTransfer.files)
|
|
@@ -124,7 +129,8 @@ export function useCanvasEvents() {
|
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
function onClick(e: React.MouseEvent) {
|
|
127
|
-
|
|
132
|
+
if (wasEventAlreadyHandled(e)) return
|
|
133
|
+
e.stopPropagation()
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
return {
|
|
@@ -151,8 +157,8 @@ export function useCanvasEvents() {
|
|
|
151
157
|
let lastX: number, lastY: number
|
|
152
158
|
|
|
153
159
|
function onPointerMove(e: PointerEvent) {
|
|
154
|
-
if ((e
|
|
155
|
-
|
|
160
|
+
if (wasEventAlreadyHandled(e)) return
|
|
161
|
+
markEventAsHandled(e)
|
|
156
162
|
|
|
157
163
|
if (e.clientX === lastX && e.clientY === lastY) return
|
|
158
164
|
lastX = e.clientX
|
|
@@ -2,7 +2,12 @@ import { useValue } from '@tldraw/state-react'
|
|
|
2
2
|
import { useEffect } from 'react'
|
|
3
3
|
import { Editor } from '../editor/Editor'
|
|
4
4
|
import { TLKeyboardEventInfo } from '../editor/types/event-types'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
activeElementShouldCaptureKeys,
|
|
7
|
+
markEventAsHandled,
|
|
8
|
+
preventDefault,
|
|
9
|
+
wasEventAlreadyHandled,
|
|
10
|
+
} from '../utils/dom'
|
|
6
11
|
import { isAccelKey } from '../utils/keyboard'
|
|
7
12
|
import { useContainer } from './useContainer'
|
|
8
13
|
import { useEditor } from './useEditor'
|
|
@@ -29,7 +34,7 @@ export function useDocumentEvents() {
|
|
|
29
34
|
// re-dispatched, which would lead to an infinite loop.
|
|
30
35
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
31
36
|
preventDefault(e)
|
|
32
|
-
|
|
37
|
+
e.stopPropagation()
|
|
33
38
|
const cvs = container.querySelector('.tl-canvas')
|
|
34
39
|
if (!cvs) return
|
|
35
40
|
const newEvent = new DragEvent(e.type, e)
|
|
@@ -103,8 +108,8 @@ export function useDocumentEvents() {
|
|
|
103
108
|
preventDefault(e)
|
|
104
109
|
}
|
|
105
110
|
|
|
106
|
-
if ((e
|
|
107
|
-
|
|
111
|
+
if (wasEventAlreadyHandled(e)) return
|
|
112
|
+
markEventAsHandled(e)
|
|
108
113
|
const hasSelectedShapes = !!editor.getSelectedShapeIds().length
|
|
109
114
|
|
|
110
115
|
switch (e.key) {
|
|
@@ -211,8 +216,8 @@ export function useDocumentEvents() {
|
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
const handleKeyUp = (e: KeyboardEvent) => {
|
|
214
|
-
if ((e
|
|
215
|
-
|
|
219
|
+
if (wasEventAlreadyHandled(e)) return
|
|
220
|
+
markEventAsHandled(e)
|
|
216
221
|
|
|
217
222
|
if (areShortcutsDisabled(editor)) {
|
|
218
223
|
return
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react'
|
|
2
|
-
import { preventDefault } from '../utils/dom'
|
|
2
|
+
import { markEventAsHandled, preventDefault } from '../utils/dom'
|
|
3
3
|
import { useEditor } from './useEditor'
|
|
4
4
|
|
|
5
5
|
const IGNORED_TAGS = ['textarea', 'input']
|
|
@@ -19,7 +19,7 @@ export function useFixSafariDoubleTapZoomPencilEvents(ref: React.RefObject<HTMLE
|
|
|
19
19
|
|
|
20
20
|
const handleEvent = (e: PointerEvent | TouchEvent) => {
|
|
21
21
|
if (e instanceof PointerEvent && e.pointerType === 'pen') {
|
|
22
|
-
|
|
22
|
+
markEventAsHandled(e)
|
|
23
23
|
const { target } = e
|
|
24
24
|
|
|
25
25
|
// Allow events to propagate if the app is editing a shape, or if the event is occurring in a text area or input
|
|
@@ -3,7 +3,7 @@ import { createUseGesture, pinchAction, wheelAction } from '@use-gesture/react'
|
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { TLWheelEventInfo } from '../editor/types/event-types'
|
|
5
5
|
import { Vec } from '../primitives/Vec'
|
|
6
|
-
import { preventDefault
|
|
6
|
+
import { preventDefault } from '../utils/dom'
|
|
7
7
|
import { isAccelKey } from '../utils/keyboard'
|
|
8
8
|
import { normalizeWheel } from '../utils/normalizeWheel'
|
|
9
9
|
import { useEditor } from './useEditor'
|
|
@@ -113,7 +113,7 @@ export function useGestureEvents(ref: React.RefObject<HTMLDivElement>) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
preventDefault(event)
|
|
116
|
-
|
|
116
|
+
event.stopPropagation()
|
|
117
117
|
const delta = normalizeWheel(event)
|
|
118
118
|
|
|
119
119
|
if (delta.x === 0 && delta.y === 0) return
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { TLArrowShape, TLLineShape, TLShapeId } from '@tldraw/tlschema'
|
|
2
2
|
import * as React from 'react'
|
|
3
3
|
import { Editor } from '../editor/Editor'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
loopToHtmlElement,
|
|
6
|
+
releasePointerCapture,
|
|
7
|
+
setPointerCapture,
|
|
8
|
+
wasEventAlreadyHandled,
|
|
9
|
+
} from '../utils/dom'
|
|
5
10
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
6
11
|
import { useEditor } from './useEditor'
|
|
7
12
|
|
|
@@ -16,7 +21,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
16
21
|
|
|
17
22
|
return React.useMemo(() => {
|
|
18
23
|
const onPointerDown = (e: React.PointerEvent) => {
|
|
19
|
-
if ((e
|
|
24
|
+
if (wasEventAlreadyHandled(e)) return
|
|
20
25
|
|
|
21
26
|
// Must set pointer capture on an HTML element!
|
|
22
27
|
const target = loopToHtmlElement(e.currentTarget)
|
|
@@ -40,7 +45,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
40
45
|
let lastX: number, lastY: number
|
|
41
46
|
|
|
42
47
|
const onPointerMove = (e: React.PointerEvent) => {
|
|
43
|
-
if ((e
|
|
48
|
+
if (wasEventAlreadyHandled(e)) return
|
|
44
49
|
if (e.clientX === lastX && e.clientY === lastY) return
|
|
45
50
|
lastX = e.clientX
|
|
46
51
|
lastY = e.clientY
|
|
@@ -60,7 +65,7 @@ export function useHandleEvents(id: TLShapeId, handleId: string) {
|
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
const onPointerUp = (e: React.PointerEvent) => {
|
|
63
|
-
if ((e
|
|
68
|
+
if (wasEventAlreadyHandled(e)) return
|
|
64
69
|
|
|
65
70
|
const target = loopToHtmlElement(e.currentTarget)
|
|
66
71
|
releasePointerCapture(target, e)
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { RefObject, useEffect } from 'react'
|
|
2
2
|
import { preventDefault } from '../utils/dom'
|
|
3
3
|
import { useContainer } from './useContainer'
|
|
4
|
+
import { useMaybeEditor } from './useEditor'
|
|
4
5
|
|
|
5
6
|
/** @public */
|
|
6
7
|
export function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {
|
|
7
8
|
if (!ref) throw Error('usePassThroughWheelEvents must be passed a ref')
|
|
8
9
|
const container = useContainer()
|
|
10
|
+
const editor = useMaybeEditor()
|
|
9
11
|
|
|
10
12
|
useEffect(() => {
|
|
11
13
|
function onMouseOver(e: MouseEvent) {
|
|
14
|
+
if (!editor?.getInstanceState().isFocused) return
|
|
12
15
|
if ((e as any).isSpecialRedispatchedEvent) return
|
|
13
16
|
preventDefault(e)
|
|
14
17
|
const cvs = container.querySelector('.tl-canvas')
|
|
@@ -25,5 +28,5 @@ export function usePassThroughMouseOverEvents(ref: RefObject<HTMLElement>) {
|
|
|
25
28
|
return () => {
|
|
26
29
|
elm.removeEventListener('mouseover', onMouseOver)
|
|
27
30
|
}
|
|
28
|
-
}, [container, ref])
|
|
31
|
+
}, [container, editor, ref])
|
|
29
32
|
}
|
|
@@ -3,9 +3,10 @@ import { RIGHT_MOUSE_BUTTON } from '../constants'
|
|
|
3
3
|
import { TLSelectionHandle } from '../editor/types/selection-types'
|
|
4
4
|
import {
|
|
5
5
|
loopToHtmlElement,
|
|
6
|
+
markEventAsHandled,
|
|
6
7
|
releasePointerCapture,
|
|
7
8
|
setPointerCapture,
|
|
8
|
-
|
|
9
|
+
wasEventAlreadyHandled,
|
|
9
10
|
} from '../utils/dom'
|
|
10
11
|
import { getPointerInfo } from '../utils/getPointerInfo'
|
|
11
12
|
import { useEditor } from './useEditor'
|
|
@@ -17,7 +18,7 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
17
18
|
const events = useMemo(
|
|
18
19
|
function selectionEvents() {
|
|
19
20
|
const onPointerDown: React.PointerEventHandler = (e) => {
|
|
20
|
-
if ((e
|
|
21
|
+
if (wasEventAlreadyHandled(e)) return
|
|
21
22
|
|
|
22
23
|
if (e.button === RIGHT_MOUSE_BUTTON) {
|
|
23
24
|
editor.dispatch({
|
|
@@ -54,14 +55,14 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
54
55
|
handle,
|
|
55
56
|
...getPointerInfo(e),
|
|
56
57
|
})
|
|
57
|
-
|
|
58
|
+
markEventAsHandled(e)
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
// Track the last screen point
|
|
61
62
|
let lastX: number, lastY: number
|
|
62
63
|
|
|
63
64
|
function onPointerMove(e: React.PointerEvent) {
|
|
64
|
-
if ((e
|
|
65
|
+
if (wasEventAlreadyHandled(e)) return
|
|
65
66
|
if (e.button !== 0) return
|
|
66
67
|
if (e.clientX === lastX && e.clientY === lastY) return
|
|
67
68
|
lastX = e.clientX
|
|
@@ -77,7 +78,7 @@ export function useSelectionEvents(handle: TLSelectionHandle) {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
const onPointerUp: React.PointerEventHandler = (e) => {
|
|
80
|
-
if ((e
|
|
81
|
+
if (wasEventAlreadyHandled(e)) return
|
|
81
82
|
if (e.button !== 0) return
|
|
82
83
|
|
|
83
84
|
editor.dispatch({
|