@tldraw/editor 5.5.0-next.c25ed1f4cf7f → 5.5.0-next.c91b2de0a423
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 +49 -23
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +16 -12
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/MenuClickCapture.js +42 -3
- package/dist-cjs/lib/components/MenuClickCapture.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +5 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +2 -5
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +3 -3
- package/dist-cjs/lib/components/default-components/DefaultSpinner.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +154 -173
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js +2 -0
- package/dist-cjs/lib/editor/derivations/bindingsIndex.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EditorManager.js +11 -2
- package/dist-cjs/lib/editor/managers/EditorManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js +49 -63
- package/dist-cjs/lib/editor/managers/PerformanceManager/PerformanceManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +1 -1
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +24 -24
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +7 -1
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +4 -3
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +4 -4
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/types/external-content.js.map +1 -1
- package/dist-cjs/lib/exports/ExportDelay.js +10 -2
- package/dist-cjs/lib/exports/ExportDelay.js.map +2 -2
- package/dist-cjs/lib/exports/FontEmbedder.js +25 -11
- package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/StyleEmbedder.js +9 -4
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/fetchCache.js +3 -0
- package/dist-cjs/lib/exports/fetchCache.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgAsImage.js +10 -4
- package/dist-cjs/lib/exports/getSvgAsImage.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js +18 -9
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/exports/parseCss.js +1 -1
- package/dist-cjs/lib/exports/parseCss.js.map +1 -1
- package/dist-cjs/lib/hooks/EditorComponentsContext.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +24 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/useIdentity.js +6 -2
- package/dist-cjs/lib/hooks/useIdentity.js.map +3 -3
- package/dist-cjs/lib/license/LicenseManager.js +9 -1
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/license/LicenseProvider.js +12 -4
- package/dist-cjs/lib/license/LicenseProvider.js.map +2 -2
- package/dist-cjs/lib/utils/debug-flags.js +0 -6
- package/dist-cjs/lib/utils/debug-flags.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js +2 -1
- package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +19 -8
- package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -0
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +49 -23
- package/dist-esm/index.mjs +4 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +17 -13
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/MenuClickCapture.mjs +42 -3
- package/dist-esm/lib/components/MenuClickCapture.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +5 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +2 -5
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +3 -3
- package/dist-esm/lib/components/default-components/DefaultSpinner.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +154 -173
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs +2 -0
- package/dist-esm/lib/editor/derivations/bindingsIndex.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EditorManager.mjs +11 -2
- package/dist-esm/lib/editor/managers/EditorManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs +49 -63
- package/dist-esm/lib/editor/managers/PerformanceManager/PerformanceManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +24 -24
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +7 -1
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +4 -3
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +4 -4
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/exports/ExportDelay.mjs +11 -3
- package/dist-esm/lib/exports/ExportDelay.mjs.map +2 -2
- package/dist-esm/lib/exports/FontEmbedder.mjs +25 -11
- package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/StyleEmbedder.mjs +9 -4
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/fetchCache.mjs +3 -0
- package/dist-esm/lib/exports/fetchCache.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgAsImage.mjs +10 -4
- package/dist-esm/lib/exports/getSvgAsImage.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs +18 -9
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/exports/parseCss.mjs +1 -1
- package/dist-esm/lib/exports/parseCss.mjs.map +1 -1
- package/dist-esm/lib/hooks/EditorComponentsContext.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +24 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useIdentity.mjs +7 -3
- package/dist-esm/lib/hooks/useIdentity.mjs.map +3 -3
- package/dist-esm/lib/license/LicenseManager.mjs +9 -1
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseProvider.mjs +13 -5
- package/dist-esm/lib/license/LicenseProvider.mjs.map +2 -2
- package/dist-esm/lib/utils/debug-flags.mjs +0 -6
- package/dist-esm/lib/utils/debug-flags.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs +2 -1
- package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +19 -8
- package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -0
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +9 -1
- package/package.json +8 -11
- package/src/index.ts +5 -1
- package/src/lib/TldrawEditor.tsx +35 -21
- package/src/lib/components/MenuClickCapture.tsx +55 -4
- package/src/lib/components/default-components/DefaultCanvas.tsx +7 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +13 -5
- package/src/lib/components/default-components/DefaultSpinner.tsx +4 -1
- package/src/lib/editor/Editor.test.ts +65 -0
- package/src/lib/editor/Editor.ts +230 -279
- package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
- package/src/lib/editor/managers/ClickManager/ClickManager.test.ts +1 -0
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +3 -2
- package/src/lib/editor/managers/EditorManager.test.ts +32 -1
- package/src/lib/editor/managers/EditorManager.ts +15 -3
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.test.ts +80 -0
- package/src/lib/editor/managers/PerformanceManager/PerformanceManager.ts +54 -81
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +1 -1
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +32 -36
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +13 -2
- package/src/lib/editor/managers/SnapManager/SnapManager.test.ts +13 -0
- package/src/lib/editor/managers/SnapManager/SnapManager.ts +6 -4
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +74 -0
- package/src/lib/editor/managers/TextManager/TextManager.ts +6 -5
- package/src/lib/editor/types/external-content.ts +5 -0
- package/src/lib/exports/ExportDelay.tsx +16 -4
- package/src/lib/exports/FontEmbedder.test.ts +99 -0
- package/src/lib/exports/FontEmbedder.ts +32 -11
- package/src/lib/exports/StyleEmbedder.ts +13 -4
- package/src/lib/exports/fetchCache.test.ts +22 -0
- package/src/lib/exports/fetchCache.ts +4 -0
- package/src/lib/exports/getSvgAsImage.ts +13 -5
- package/src/lib/exports/getSvgJsx.test.ts +43 -1
- package/src/lib/exports/getSvgJsx.tsx +28 -16
- package/src/lib/exports/parseCss.test.ts +4 -0
- package/src/lib/exports/parseCss.ts +2 -2
- package/src/lib/hooks/EditorComponentsContext.tsx +2 -1
- package/src/lib/hooks/useCanvasEvents.ts +42 -0
- package/src/lib/hooks/useIdentity.tsx +12 -1
- package/src/lib/license/LicenseManager.ts +13 -1
- package/src/lib/license/LicenseProvider.test.tsx +76 -0
- package/src/lib/license/LicenseProvider.tsx +19 -5
- package/src/lib/test/preserveFocus.test.tsx +81 -0
- package/src/lib/utils/debug-flags.ts +0 -6
- package/src/lib/utils/deepLinks.test.ts +15 -0
- package/src/lib/utils/deepLinks.ts +8 -3
- package/src/lib/utils/sync/LocalIndexedDb.test.ts +93 -1
- package/src/lib/utils/sync/LocalIndexedDb.ts +23 -8
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +21 -1
- package/src/lib/utils/sync/TLLocalSyncClient.ts +6 -0
- package/src/version.ts +3 -3
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js +0 -133
- package/dist-cjs/lib/primitives/geometry/geometry.bench.js.map +0 -7
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs +0 -132
- package/dist-esm/lib/primitives/geometry/geometry.bench.mjs.map +0 -7
- package/src/lib/primitives/geometry/geometry.bench.ts +0 -179
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -341,6 +341,11 @@ export interface TLRenderingShape {
|
|
|
341
341
|
|
|
342
342
|
const RENDERING_SHAPES_SORT_CACHE_THRESHOLD = 100
|
|
343
343
|
|
|
344
|
+
const AXIS = {
|
|
345
|
+
horizontal: { val: 'x', min: 'minX', max: 'maxX', dim: 'width' },
|
|
346
|
+
vertical: { val: 'y', min: 'minY', max: 'maxY', dim: 'height' },
|
|
347
|
+
} as const
|
|
348
|
+
|
|
344
349
|
/** @public */
|
|
345
350
|
export class Editor extends EventEmitter<TLEventMap> {
|
|
346
351
|
readonly id = uniqueId()
|
|
@@ -753,7 +758,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
753
758
|
}
|
|
754
759
|
|
|
755
760
|
if (deleteBindingIds.length) {
|
|
756
|
-
this
|
|
761
|
+
// straight to the store: this cleanup must run even when deleteBindings would
|
|
762
|
+
// refuse (readonly), e.g. for a deletion that arrived from a remote peer
|
|
763
|
+
this.store.remove(deleteBindingIds)
|
|
757
764
|
}
|
|
758
765
|
},
|
|
759
766
|
},
|
|
@@ -1970,6 +1977,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
1970
1977
|
* @public
|
|
1971
1978
|
**/
|
|
1972
1979
|
updateDocumentSettings(settings: Partial<TLDocument>): this {
|
|
1980
|
+
if (this.getIsReadonly()) return this
|
|
1973
1981
|
this.run(
|
|
1974
1982
|
() => {
|
|
1975
1983
|
this.store.put([{ ...this.getDocumentSettings(), ...settings }])
|
|
@@ -2005,7 +2013,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2005
2013
|
this._updateInstanceState(partial, { history: 'ignore', ...historyOptions })
|
|
2006
2014
|
|
|
2007
2015
|
if (partial.isChangingStyle !== undefined) {
|
|
2008
|
-
clearTimeout(this._isChangingStyleTimeout)
|
|
2016
|
+
this.timers.clearTimeout(this._isChangingStyleTimeout)
|
|
2009
2017
|
if (partial.isChangingStyle === true) {
|
|
2010
2018
|
// If we've set to true, set a new reset timeout to change the value back to false after 1 seconds
|
|
2011
2019
|
this._isChangingStyleTimeout = this.timers.setTimeout(() => {
|
|
@@ -2197,10 +2205,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2197
2205
|
* @public
|
|
2198
2206
|
*/
|
|
2199
2207
|
select(...shapes: TLShapeId[] | TLShape[]): this {
|
|
2200
|
-
const ids =
|
|
2201
|
-
typeof shapes[0] === 'string'
|
|
2202
|
-
? (shapes as TLShapeId[])
|
|
2203
|
-
: (shapes as TLShape[]).map((shape) => shape.id)
|
|
2208
|
+
const ids = toShapeIds(shapes)
|
|
2204
2209
|
this.setSelectedShapes(ids)
|
|
2205
2210
|
return this
|
|
2206
2211
|
}
|
|
@@ -2216,10 +2221,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2216
2221
|
* @public
|
|
2217
2222
|
*/
|
|
2218
2223
|
deselect(...shapes: TLShapeId[] | TLShape[]): this {
|
|
2219
|
-
const ids =
|
|
2220
|
-
typeof shapes[0] === 'string'
|
|
2221
|
-
? (shapes as TLShapeId[])
|
|
2222
|
-
: (shapes as TLShape[]).map((shape) => shape.id)
|
|
2224
|
+
const ids = toShapeIds(shapes)
|
|
2223
2225
|
const selectedShapeIds = this.getSelectedShapeIds()
|
|
2224
2226
|
if (selectedShapeIds.length > 0 && ids.length > 0) {
|
|
2225
2227
|
this.setSelectedShapes(selectedShapeIds.filter((id) => !ids.includes(id)))
|
|
@@ -2264,10 +2266,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2264
2266
|
parentToSelectWithinId = this.getCurrentPageId()
|
|
2265
2267
|
}
|
|
2266
2268
|
|
|
2267
|
-
// Select all the unlocked shapes within the parent
|
|
2269
|
+
// Select all the unlocked shapes within the parent. Only the shape's own lock matters here:
|
|
2270
|
+
// selecting inside a locked frame or group is allowed, mutating is not.
|
|
2268
2271
|
const ids = this.getSortedChildIdsForParent(parentToSelectWithinId)
|
|
2269
2272
|
if (ids.length <= 0) return this
|
|
2270
|
-
this.setSelectedShapes(this.
|
|
2273
|
+
this.setSelectedShapes(ids.filter((id) => !this.getShape(id)?.isLocked))
|
|
2271
2274
|
return this
|
|
2272
2275
|
}
|
|
2273
2276
|
|
|
@@ -2455,8 +2458,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2455
2458
|
|
|
2456
2459
|
// Ok, now score that subset of shapes.
|
|
2457
2460
|
const lowestScoringShape = minBy(shapesInDirection, ({ center }) => {
|
|
2458
|
-
//
|
|
2459
|
-
|
|
2461
|
+
// Linear, not squared: the off-axis and diagonal penalties below are page units too, and
|
|
2462
|
+
// squared distance swamps them, so a nearer diagonal shape beats an aligned one.
|
|
2463
|
+
const distance = Vec.Dist(currentCenter, center)
|
|
2460
2464
|
|
|
2461
2465
|
// Distance along the primary axis.
|
|
2462
2466
|
const dirProp = ['left', 'right'].includes(direction) ? 'x' : 'y'
|
|
@@ -2466,9 +2470,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2466
2470
|
const offProp = ['left', 'right'].includes(direction) ? 'y' : 'x'
|
|
2467
2471
|
const offAxisDeviation = Math.abs(center[offProp] - currentCenter[offProp])
|
|
2468
2472
|
|
|
2469
|
-
//
|
|
2470
|
-
|
|
2471
|
-
const
|
|
2473
|
+
// atan2 gives -180..180, so 'up' is -90; normalize to 0..360 to match 270, and wrap the
|
|
2474
|
+
// deviation so that 350 is 10 away from 'right' (0), not 350.
|
|
2475
|
+
const angle = (Vec.Angle(currentCenter, center) * (180 / Math.PI) + 360) % 360
|
|
2476
|
+
const rawAngleDeviation = Math.abs(angle - directionToAngle[direction])
|
|
2477
|
+
const angleDeviation = Math.min(rawAngleDeviation, 360 - rawAngleDeviation)
|
|
2472
2478
|
|
|
2473
2479
|
// Calculate final score (lower is better).
|
|
2474
2480
|
// Weight factors to prioritize:
|
|
@@ -2973,10 +2979,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
2973
2979
|
* @public
|
|
2974
2980
|
*/
|
|
2975
2981
|
setHintingShapes(shapes: TLShapeId[] | TLShape[]): this {
|
|
2976
|
-
const ids =
|
|
2977
|
-
typeof shapes[0] === 'string'
|
|
2978
|
-
? (shapes as TLShapeId[])
|
|
2979
|
-
: (shapes as TLShape[]).map((shape) => shape.id)
|
|
2982
|
+
const ids = toShapeIds(shapes)
|
|
2980
2983
|
// always ephemeral
|
|
2981
2984
|
this.run(
|
|
2982
2985
|
() => {
|
|
@@ -3023,10 +3026,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
3023
3026
|
*/
|
|
3024
3027
|
setErasingShapes(shapes: TLShapeId[] | TLShape[]): this {
|
|
3025
3028
|
// copy before sorting: the caller may pass a store-owned (frozen) array
|
|
3026
|
-
const ids =
|
|
3027
|
-
typeof shapes[0] === 'string'
|
|
3028
|
-
? (shapes as TLShapeId[]).slice()
|
|
3029
|
-
: (shapes as TLShape[]).map((shape) => shape.id)
|
|
3029
|
+
const ids = toShapeIds(shapes).slice()
|
|
3030
3030
|
ids.sort() // sort the incoming ids
|
|
3031
3031
|
const erasingShapeIds = this.getErasingShapeIds()
|
|
3032
3032
|
this.run(
|
|
@@ -3600,7 +3600,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
3600
3600
|
const { isLocked } = this._cameraOptions.__unsafe__getWithoutCapture()
|
|
3601
3601
|
if (isLocked && !opts?.force) return this
|
|
3602
3602
|
|
|
3603
|
-
|
|
3603
|
+
// Resolve the zoom before building the Vec: Vec.Cast would default a missing z to 1,
|
|
3604
|
+
// and a missing z should keep the current zoom level instead
|
|
3605
|
+
const _point = new Vec(point.x, point.y, point.z ?? this.getZoomLevel())
|
|
3604
3606
|
|
|
3605
3607
|
// Reject non-finite values before anything else, so the call is a no-op rather than a
|
|
3606
3608
|
// partial one. An animated move writes the camera from a 'tick' listener, and a listener
|
|
@@ -3954,6 +3956,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
3954
3956
|
easing(t: number): number
|
|
3955
3957
|
start: Box
|
|
3956
3958
|
end: Box
|
|
3959
|
+
opts: TLCameraMoveOptions
|
|
3957
3960
|
}
|
|
3958
3961
|
|
|
3959
3962
|
/** @internal */
|
|
@@ -3962,12 +3965,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
3962
3965
|
|
|
3963
3966
|
this._viewportAnimation.elapsed += ms
|
|
3964
3967
|
|
|
3965
|
-
const { elapsed, easing, duration, start, end } = this._viewportAnimation
|
|
3968
|
+
const { elapsed, easing, duration, start, end, opts } = this._viewportAnimation
|
|
3966
3969
|
|
|
3967
3970
|
if (elapsed > duration) {
|
|
3968
3971
|
this.off('tick', this._animateViewport)
|
|
3969
3972
|
this._viewportAnimation = null
|
|
3970
|
-
|
|
3973
|
+
// Forward the caller's options, otherwise a forced move to a position outside the
|
|
3974
|
+
// constraints animates there and then snaps back on this last frame
|
|
3975
|
+
this._setCamera(
|
|
3976
|
+
new Vec(-end.x, -end.y, this.getViewportScreenBounds().width / end.width),
|
|
3977
|
+
opts
|
|
3978
|
+
)
|
|
3971
3979
|
return
|
|
3972
3980
|
}
|
|
3973
3981
|
|
|
@@ -4021,6 +4029,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
4021
4029
|
easing,
|
|
4022
4030
|
start: viewportPageBounds.clone(),
|
|
4023
4031
|
end: targetViewportPage.clone(),
|
|
4032
|
+
opts: rest,
|
|
4024
4033
|
}
|
|
4025
4034
|
|
|
4026
4035
|
// If we ever get a "stop-camera-animation" event, we stop
|
|
@@ -5243,7 +5252,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5243
5252
|
|
|
5244
5253
|
this.run(
|
|
5245
5254
|
() => {
|
|
5246
|
-
|
|
5255
|
+
// the asset store's remove is async; surface failures instead of leaving an unhandled rejection
|
|
5256
|
+
Promise.resolve(this.store.props.assets.remove?.(ids)).catch((err) =>
|
|
5257
|
+
console.error('Error while removing assets from the asset store:', err)
|
|
5258
|
+
)
|
|
5247
5259
|
this.store.remove(ids)
|
|
5248
5260
|
},
|
|
5249
5261
|
{ history: 'ignore' }
|
|
@@ -5705,10 +5717,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5705
5717
|
return
|
|
5706
5718
|
}
|
|
5707
5719
|
|
|
5708
|
-
const ids =
|
|
5709
|
-
typeof shapes[0] === 'string'
|
|
5710
|
-
? (shapes as TLShapeId[])
|
|
5711
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
5720
|
+
const ids = toShapeIds(shapes)
|
|
5712
5721
|
const freshShapes = compact(ids.map((id) => this.getShape(id)))
|
|
5713
5722
|
|
|
5714
5723
|
if (freshShapes.length === 1) {
|
|
@@ -5856,14 +5865,16 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
5856
5865
|
*/
|
|
5857
5866
|
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined {
|
|
5858
5867
|
const selectedShapeIds = this.getSelectedShapeIds()
|
|
5859
|
-
|
|
5868
|
+
if (selectedShapeIds.length === 0) return undefined
|
|
5869
|
+
const selectedShapeIdSet = new Set(selectedShapeIds)
|
|
5870
|
+
const margin = this.getHitTestMargin()
|
|
5860
5871
|
const sortedShapes = this.getCurrentPageShapesSorted()
|
|
5861
5872
|
|
|
5862
5873
|
// iterate from the top (highest z-index) to find the top-most matching shape
|
|
5863
5874
|
for (let i = sortedShapes.length - 1; i >= 0; i--) {
|
|
5864
5875
|
const shape = sortedShapes[i]
|
|
5865
5876
|
if (shape.type === 'group') continue
|
|
5866
|
-
if (!
|
|
5877
|
+
if (!selectedShapeIdSet.has(shape.id)) continue
|
|
5867
5878
|
if (
|
|
5868
5879
|
this.getShapeGeometry(shape).hitTestPoint(
|
|
5869
5880
|
this.getPointInShapeSpace(shape, point),
|
|
@@ -6034,9 +6045,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6034
6045
|
// other hits would be occluded by the shape.
|
|
6035
6046
|
return inMarginClosestToEdgeHit || shape
|
|
6036
6047
|
} else {
|
|
6037
|
-
// If the shape is bigger than the viewport, then skip it.
|
|
6038
|
-
if (this.getShapePageBounds(shape)!.contains(viewportPageBounds)) continue
|
|
6039
|
-
|
|
6040
6048
|
// If we're close to the edge of the shape, and if it's the closest edge among
|
|
6041
6049
|
// all the edges that we've gotten close to so far, then we will want to hit the
|
|
6042
6050
|
// shape unless we hit something else or closer in later iterations.
|
|
@@ -6057,6 +6065,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6057
6065
|
inMarginClosestToEdgeHit = shape
|
|
6058
6066
|
}
|
|
6059
6067
|
} else if (!inMarginClosestToEdgeHit) {
|
|
6068
|
+
// If the shape is bigger than the viewport, then skip it. (Only here: its
|
|
6069
|
+
// edges should still be hittable within the margin.)
|
|
6070
|
+
if (this.getShapePageBounds(shape)!.contains(viewportPageBounds)) continue
|
|
6071
|
+
|
|
6060
6072
|
// If we're not within margin distance to any edge, and if the
|
|
6061
6073
|
// shape is hollow, then we want to hit the shape with the
|
|
6062
6074
|
// smallest area. (There's a bug here with self-intersecting
|
|
@@ -6075,6 +6087,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6075
6087
|
// If the distance is less than the margin, return the shape as the hit.
|
|
6076
6088
|
// Use the editor's configurable hit test margin.
|
|
6077
6089
|
if (distance < this.getHitTestMargin()) {
|
|
6090
|
+
// An edge we already hit (above this shape) that is at least as close still wins,
|
|
6091
|
+
// matching the closest-edge rule used for hollow shapes
|
|
6092
|
+
if (inMarginClosestToEdgeHit && inMarginClosestToEdgeDistance <= distance) {
|
|
6093
|
+
return inMarginClosestToEdgeHit
|
|
6094
|
+
}
|
|
6078
6095
|
return shape
|
|
6079
6096
|
}
|
|
6080
6097
|
}
|
|
@@ -6439,8 +6456,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6439
6456
|
* @public
|
|
6440
6457
|
*/
|
|
6441
6458
|
reparentShapes(shapes: TLShapeId[] | TLShape[], parentId: TLParentId, insertIndex?: IndexKey) {
|
|
6442
|
-
const ids =
|
|
6443
|
-
typeof shapes[0] === 'string' ? (shapes as TLShapeId[]) : shapes.map((s) => (s as TLShape).id)
|
|
6459
|
+
const ids = toShapeIds(shapes)
|
|
6444
6460
|
if (ids.length === 0) return this
|
|
6445
6461
|
|
|
6446
6462
|
const changes: TLShapePartial[] = []
|
|
@@ -6789,6 +6805,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6789
6805
|
* binding, but the `type`, `toId`, and `fromId` must all be provided.
|
|
6790
6806
|
*/
|
|
6791
6807
|
createBindings<B extends TLBinding = TLBinding>(partials: TLBindingCreate<B>[]) {
|
|
6808
|
+
if (this.getIsReadonly()) return this
|
|
6809
|
+
|
|
6792
6810
|
const bindings: TLBinding[] = []
|
|
6793
6811
|
for (const partial of partials) {
|
|
6794
6812
|
const fromShape = this.getShape(partial.fromId)
|
|
@@ -6828,6 +6846,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6828
6846
|
* binding is skipped. The changes from the partial are merged into the existing record.
|
|
6829
6847
|
*/
|
|
6830
6848
|
updateBindings(partials: (TLBindingUpdate | null | undefined)[]) {
|
|
6849
|
+
if (this.getIsReadonly()) return this
|
|
6850
|
+
|
|
6831
6851
|
const updated: TLBinding[] = []
|
|
6832
6852
|
|
|
6833
6853
|
for (const partial of partials) {
|
|
@@ -6865,6 +6885,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6865
6885
|
* Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
|
|
6866
6886
|
*/
|
|
6867
6887
|
deleteBindings(bindings: (TLBinding | TLBindingId)[], { isolateShapes = false } = {}) {
|
|
6888
|
+
if (this.getIsReadonly()) return this
|
|
6889
|
+
return this._deleteBindings(bindings, { isolateShapes })
|
|
6890
|
+
}
|
|
6891
|
+
|
|
6892
|
+
/**
|
|
6893
|
+
* Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
|
|
6894
|
+
* readonly mode; the public deleteBindings is what readonly blocks.
|
|
6895
|
+
*
|
|
6896
|
+
* @internal
|
|
6897
|
+
*/
|
|
6898
|
+
_deleteBindings(bindings: (TLBinding | TLBindingId)[], { isolateShapes = false } = {}) {
|
|
6868
6899
|
const ids = bindings.map((binding) => (typeof binding === 'string' ? binding : binding.id))
|
|
6869
6900
|
if (isolateShapes) {
|
|
6870
6901
|
this.store.atomic(() => {
|
|
@@ -6939,10 +6970,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6939
6970
|
delta: number,
|
|
6940
6971
|
opts?: { center?: VecLike }
|
|
6941
6972
|
): this {
|
|
6942
|
-
const ids =
|
|
6943
|
-
typeof shapes[0] === 'string'
|
|
6944
|
-
? (shapes as TLShapeId[])
|
|
6945
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
6973
|
+
const ids = toShapeIds(shapes)
|
|
6946
6974
|
|
|
6947
6975
|
if (ids.length <= 0) return this
|
|
6948
6976
|
|
|
@@ -6989,6 +7017,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6989
7017
|
return workingShape
|
|
6990
7018
|
}
|
|
6991
7019
|
|
|
7020
|
+
// Counter-rotates the page-space delta into the parent's space; without that a child of a rotated
|
|
7021
|
+
// frame or group would move along its parent's axes instead of the page's.
|
|
7022
|
+
// todo: a shape laid out together with its own parent moves twice, once with the parent and once
|
|
7023
|
+
// on its own; the layout commands should skip shapes whose ancestors are also being laid out
|
|
7024
|
+
private getChangesToTranslateShapeByPageDelta(shape: TLShape, pageDelta: VecLike): TLShape {
|
|
7025
|
+
const localDelta = Vec.From(pageDelta).rot(-this.getShapeParentTransform(shape).rotation())
|
|
7026
|
+
return this.getChangesToTranslateShape(shape, localDelta.add(shape))
|
|
7027
|
+
}
|
|
7028
|
+
|
|
6992
7029
|
/**
|
|
6993
7030
|
* Move shapes by a delta.
|
|
6994
7031
|
*
|
|
@@ -7001,20 +7038,14 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7001
7038
|
* @param offset - The offset to apply to the shapes.
|
|
7002
7039
|
*/
|
|
7003
7040
|
nudgeShapes(shapes: TLShapeId[] | TLShape[], offset: VecLike): this {
|
|
7004
|
-
const ids =
|
|
7005
|
-
typeof shapes[0] === 'string'
|
|
7006
|
-
? (shapes as TLShapeId[])
|
|
7007
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7041
|
+
const ids = toShapeIds(shapes)
|
|
7008
7042
|
|
|
7009
7043
|
if (ids.length <= 0) return this
|
|
7010
7044
|
const changes: TLShapePartial[] = []
|
|
7011
7045
|
|
|
7012
7046
|
for (const id of ids) {
|
|
7013
7047
|
const shape = this.getShape(id)!
|
|
7014
|
-
|
|
7015
|
-
localDelta.rot(-this.getShapeParentTransform(shape).rotation())
|
|
7016
|
-
|
|
7017
|
-
changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)))
|
|
7048
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, offset))
|
|
7018
7049
|
}
|
|
7019
7050
|
|
|
7020
7051
|
this.updateShapes(changes)
|
|
@@ -7038,10 +7069,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7038
7069
|
*/
|
|
7039
7070
|
duplicateShapes(shapes: TLShapeId[] | TLShape[], offset?: VecLike): this {
|
|
7040
7071
|
this.run(() => {
|
|
7041
|
-
const _ids =
|
|
7042
|
-
typeof shapes[0] === 'string'
|
|
7043
|
-
? (shapes as TLShapeId[])
|
|
7044
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7072
|
+
const _ids = toShapeIds(shapes)
|
|
7045
7073
|
|
|
7046
7074
|
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids)
|
|
7047
7075
|
if (ids.length <= 0) return this
|
|
@@ -7183,10 +7211,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7183
7211
|
* @public
|
|
7184
7212
|
*/
|
|
7185
7213
|
moveShapesToPage(shapes: TLShapeId[] | TLShape[], pageId: TLPageId): this {
|
|
7186
|
-
const ids =
|
|
7187
|
-
typeof shapes[0] === 'string'
|
|
7188
|
-
? (shapes as TLShapeId[])
|
|
7189
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7214
|
+
const ids = toShapeIds(shapes)
|
|
7190
7215
|
|
|
7191
7216
|
if (ids.length === 0) return this
|
|
7192
7217
|
if (this.getIsReadonly()) return this
|
|
@@ -7247,10 +7272,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7247
7272
|
* @public
|
|
7248
7273
|
*/
|
|
7249
7274
|
toggleLock(shapes: TLShapeId[] | TLShape[]): this {
|
|
7250
|
-
const ids =
|
|
7251
|
-
typeof shapes[0] === 'string'
|
|
7252
|
-
? (shapes as TLShapeId[])
|
|
7253
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7275
|
+
const ids = toShapeIds(shapes)
|
|
7254
7276
|
|
|
7255
7277
|
if (this.getIsReadonly() || ids.length === 0) return this
|
|
7256
7278
|
|
|
@@ -7293,11 +7315,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7293
7315
|
* @public
|
|
7294
7316
|
*/
|
|
7295
7317
|
sendToBack(shapes: TLShapeId[] | TLShape[]): this {
|
|
7296
|
-
const ids =
|
|
7297
|
-
|
|
7298
|
-
? (shapes as TLShapeId[])
|
|
7299
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7300
|
-
const changes = getReorderingShapesChanges(this, 'toBack', ids as TLShapeId[], {
|
|
7318
|
+
const ids = toShapeIds(shapes)
|
|
7319
|
+
const changes = getReorderingShapesChanges(this, 'toBack', ids, {
|
|
7301
7320
|
considerAllShapes: true,
|
|
7302
7321
|
})
|
|
7303
7322
|
if (changes) this.updateShapes(changes)
|
|
@@ -7327,11 +7346,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7327
7346
|
* @public
|
|
7328
7347
|
*/
|
|
7329
7348
|
sendBackward(shapes: TLShapeId[] | TLShape[], opts: { considerAllShapes?: boolean } = {}): this {
|
|
7330
|
-
const ids =
|
|
7331
|
-
|
|
7332
|
-
? (shapes as TLShapeId[])
|
|
7333
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7334
|
-
const changes = getReorderingShapesChanges(this, 'backward', ids as TLShapeId[], opts)
|
|
7349
|
+
const ids = toShapeIds(shapes)
|
|
7350
|
+
const changes = getReorderingShapesChanges(this, 'backward', ids, opts)
|
|
7335
7351
|
if (changes) this.updateShapes(changes)
|
|
7336
7352
|
return this
|
|
7337
7353
|
}
|
|
@@ -7359,11 +7375,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7359
7375
|
* @public
|
|
7360
7376
|
*/
|
|
7361
7377
|
bringForward(shapes: TLShapeId[] | TLShape[], opts: { considerAllShapes?: boolean } = {}): this {
|
|
7362
|
-
const ids =
|
|
7363
|
-
|
|
7364
|
-
? (shapes as TLShapeId[])
|
|
7365
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7366
|
-
const changes = getReorderingShapesChanges(this, 'forward', ids as TLShapeId[], opts)
|
|
7378
|
+
const ids = toShapeIds(shapes)
|
|
7379
|
+
const changes = getReorderingShapesChanges(this, 'forward', ids, opts)
|
|
7367
7380
|
if (changes) this.updateShapes(changes)
|
|
7368
7381
|
return this
|
|
7369
7382
|
}
|
|
@@ -7382,11 +7395,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7382
7395
|
* @public
|
|
7383
7396
|
*/
|
|
7384
7397
|
bringToFront(shapes: TLShapeId[] | TLShape[]): this {
|
|
7385
|
-
const ids =
|
|
7386
|
-
|
|
7387
|
-
? (shapes as TLShapeId[])
|
|
7388
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7389
|
-
const changes = getReorderingShapesChanges(this, 'toFront', ids as TLShapeId[])
|
|
7398
|
+
const ids = toShapeIds(shapes)
|
|
7399
|
+
const changes = getReorderingShapesChanges(this, 'toFront', ids)
|
|
7390
7400
|
if (changes) this.updateShapes(changes)
|
|
7391
7401
|
return this
|
|
7392
7402
|
}
|
|
@@ -7402,10 +7412,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7402
7412
|
type: TLShapeUtilCanBeLaidOutOpts['type'],
|
|
7403
7413
|
opts?: { filterAxisAligned?: boolean }
|
|
7404
7414
|
): { clusters: { shapes: TLShape[]; pageBounds: Box }[]; allBounds: Box[] } {
|
|
7405
|
-
const ids =
|
|
7406
|
-
typeof shapes[0] === 'string'
|
|
7407
|
-
? (shapes as TLShapeId[])
|
|
7408
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7415
|
+
const ids = toShapeIds(shapes)
|
|
7409
7416
|
|
|
7410
7417
|
// always fresh shapes
|
|
7411
7418
|
let freshShapes = compact(ids.map((id) => this.getShape(id)))
|
|
@@ -7515,10 +7522,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7515
7522
|
flipShapes(shapes: TLShapeId[] | TLShape[], operation: 'horizontal' | 'vertical'): this {
|
|
7516
7523
|
if (this.getIsReadonly()) return this
|
|
7517
7524
|
|
|
7518
|
-
const ids =
|
|
7519
|
-
typeof shapes[0] === 'string'
|
|
7520
|
-
? (shapes as TLShapeId[])
|
|
7521
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7525
|
+
const ids = toShapeIds(shapes)
|
|
7522
7526
|
|
|
7523
7527
|
// Collect a greedy list of shapes to flip
|
|
7524
7528
|
const shapesToFlipFirstPass = compact(ids.map((id) => this.getShape(id)))
|
|
@@ -7621,22 +7625,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7621
7625
|
const len = shapeClustersToStack.length
|
|
7622
7626
|
if ((_gap === 0 && len < 3) || len < 2) return this
|
|
7623
7627
|
|
|
7624
|
-
|
|
7625
|
-
let min: 'minX' | 'minY'
|
|
7626
|
-
let max: 'maxX' | 'maxY'
|
|
7627
|
-
let dim: 'width' | 'height'
|
|
7628
|
-
|
|
7629
|
-
if (operation === 'horizontal') {
|
|
7630
|
-
val = 'x'
|
|
7631
|
-
min = 'minX'
|
|
7632
|
-
max = 'maxX'
|
|
7633
|
-
dim = 'width'
|
|
7634
|
-
} else {
|
|
7635
|
-
val = 'y'
|
|
7636
|
-
min = 'minY'
|
|
7637
|
-
max = 'maxY'
|
|
7638
|
-
dim = 'height'
|
|
7639
|
-
}
|
|
7628
|
+
const { val, min, max, dim } = AXIS[operation]
|
|
7640
7629
|
|
|
7641
7630
|
let shapeGap: number = 0
|
|
7642
7631
|
|
|
@@ -7694,17 +7683,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7694
7683
|
delta[val] = v + shapeGap - pageBounds[val]
|
|
7695
7684
|
|
|
7696
7685
|
for (const shape of shapes) {
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
// If the shape has another shape as its parent, and if the parent has a rotation, we need to rotate the counter-rotate delta
|
|
7700
|
-
// todo: ensure that the parent isn't being aligned together with its children
|
|
7701
|
-
const parent = this.getShapeParent(shape)
|
|
7702
|
-
if (parent) {
|
|
7703
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation())
|
|
7704
|
-
}
|
|
7705
|
-
|
|
7706
|
-
shapeDelta.add(shape) // add the shape's x and y to the delta
|
|
7707
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta))
|
|
7686
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta))
|
|
7708
7687
|
}
|
|
7709
7688
|
|
|
7710
7689
|
v += pageBounds[dim] + shapeGap
|
|
@@ -7820,15 +7799,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7820
7799
|
const delta = Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta)
|
|
7821
7800
|
|
|
7822
7801
|
for (const shape of shapes) {
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
const parent = this.getShapeParent(shape)
|
|
7826
|
-
if (parent) {
|
|
7827
|
-
shapeDelta.rot(-this.getShapeParentTransform(shape).rotation())
|
|
7828
|
-
}
|
|
7829
|
-
|
|
7830
|
-
shapeDelta.add(shape)
|
|
7831
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta))
|
|
7802
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta))
|
|
7832
7803
|
}
|
|
7833
7804
|
}
|
|
7834
7805
|
|
|
@@ -7908,17 +7879,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7908
7879
|
}
|
|
7909
7880
|
|
|
7910
7881
|
for (const shape of shapes) {
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
// If the shape has another shape as its parent, and if the parent has a rotation, we need to rotate the counter-rotate delta
|
|
7914
|
-
// todo: ensure that the parent isn't being aligned together with its children
|
|
7915
|
-
const parent = this.getShapeParent(shape)
|
|
7916
|
-
if (parent) {
|
|
7917
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation())
|
|
7918
|
-
}
|
|
7919
|
-
|
|
7920
|
-
shapeDelta.add(shape) // add the shape's x and y to the delta
|
|
7921
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta))
|
|
7882
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta))
|
|
7922
7883
|
}
|
|
7923
7884
|
})
|
|
7924
7885
|
|
|
@@ -7947,22 +7908,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7947
7908
|
|
|
7948
7909
|
if (shapeClustersToDistribute.length < 3) return this
|
|
7949
7910
|
|
|
7950
|
-
|
|
7951
|
-
let min: 'minX' | 'minY'
|
|
7952
|
-
let max: 'maxX' | 'maxY'
|
|
7953
|
-
let dim: 'width' | 'height'
|
|
7954
|
-
|
|
7955
|
-
if (operation === 'horizontal') {
|
|
7956
|
-
val = 'x'
|
|
7957
|
-
min = 'minX'
|
|
7958
|
-
max = 'maxX'
|
|
7959
|
-
dim = 'width'
|
|
7960
|
-
} else {
|
|
7961
|
-
val = 'y'
|
|
7962
|
-
min = 'minY'
|
|
7963
|
-
max = 'maxY'
|
|
7964
|
-
dim = 'height'
|
|
7965
|
-
}
|
|
7911
|
+
const { val, min, max, dim } = AXIS[operation]
|
|
7966
7912
|
const changes: TLShapePartial[] = []
|
|
7967
7913
|
|
|
7968
7914
|
const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0]
|
|
@@ -7971,10 +7917,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7971
7917
|
// If the first shape group is also the last shape group, distribute without it
|
|
7972
7918
|
if (first === last) {
|
|
7973
7919
|
const excludedShapeIds = new Set(first.shapes.map((s) => s.id))
|
|
7974
|
-
const ids =
|
|
7975
|
-
typeof shapes[0] === 'string'
|
|
7976
|
-
? (shapes as TLShapeId[])
|
|
7977
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7920
|
+
const ids = toShapeIds(shapes)
|
|
7978
7921
|
return this.distributeShapes(
|
|
7979
7922
|
ids.filter((id) => !excludedShapeIds.has(id)),
|
|
7980
7923
|
operation
|
|
@@ -8008,17 +7951,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8008
7951
|
}
|
|
8009
7952
|
|
|
8010
7953
|
for (const shape of shapes) {
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
// If the shape has another shape as its parent, and if the parent has a rotation, we need to rotate the counter-rotate delta
|
|
8014
|
-
// todo: ensure that the parent isn't being aligned together with its children
|
|
8015
|
-
const parent = this.getShapeParent(shape)
|
|
8016
|
-
if (parent) {
|
|
8017
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation())
|
|
8018
|
-
}
|
|
8019
|
-
|
|
8020
|
-
shapeDelta.add(shape) // add the shape's x and y to the delta
|
|
8021
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta))
|
|
7954
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta))
|
|
8022
7955
|
}
|
|
8023
7956
|
|
|
8024
7957
|
v += pageBounds[dim] + gap
|
|
@@ -8054,24 +7987,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8054
7987
|
if (shapeClustersToStretch.length < 2) return this
|
|
8055
7988
|
|
|
8056
7989
|
const commonBounds = Box.Common(allBounds)
|
|
8057
|
-
|
|
8058
|
-
let min: 'minX' | 'minY'
|
|
8059
|
-
let dim: 'width' | 'height'
|
|
8060
|
-
|
|
8061
|
-
if (operation === 'horizontal') {
|
|
8062
|
-
val = 'x'
|
|
8063
|
-
min = 'minX'
|
|
8064
|
-
dim = 'width'
|
|
8065
|
-
} else {
|
|
8066
|
-
val = 'y'
|
|
8067
|
-
min = 'minY'
|
|
8068
|
-
dim = 'height'
|
|
8069
|
-
}
|
|
7990
|
+
const { val, min, dim } = AXIS[operation]
|
|
8070
7991
|
|
|
8071
7992
|
this.run(() => {
|
|
8072
7993
|
shapeClustersToStretch.forEach(({ shapes, pageBounds }) => {
|
|
8073
|
-
const
|
|
8074
|
-
|
|
7994
|
+
const pageOffset = new Vec()
|
|
7995
|
+
pageOffset[val] = commonBounds[min] - pageBounds[min]
|
|
8075
7996
|
|
|
8076
7997
|
const scaleOrigin = pageBounds.center.clone()
|
|
8077
7998
|
scaleOrigin[val] = commonBounds[min]
|
|
@@ -8081,11 +8002,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8081
8002
|
|
|
8082
8003
|
for (const shape of shapes) {
|
|
8083
8004
|
// First translate
|
|
8084
|
-
|
|
8085
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation())
|
|
8086
|
-
shapeLocalOffset.add(shape)
|
|
8087
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset)
|
|
8088
|
-
this.updateShape(changes)
|
|
8005
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset))
|
|
8089
8006
|
|
|
8090
8007
|
// Then resize
|
|
8091
8008
|
this.resizeShape(shape.id, scale, {
|
|
@@ -8138,7 +8055,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8138
8055
|
const scale = new Vec(scaleX, scaleY)
|
|
8139
8056
|
|
|
8140
8057
|
shapeClusters.forEach(({ shapes, pageBounds }) => {
|
|
8141
|
-
const
|
|
8058
|
+
const pageOffset = new Vec(
|
|
8142
8059
|
targetBounds.minX -
|
|
8143
8060
|
commonBounds.minX +
|
|
8144
8061
|
(pageBounds.minX - commonBounds.minX) * (scaleX - 1),
|
|
@@ -8152,11 +8069,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8152
8069
|
|
|
8153
8070
|
for (const shape of shapes) {
|
|
8154
8071
|
// First translate
|
|
8155
|
-
|
|
8156
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation())
|
|
8157
|
-
shapeLocalOffset.add(shape)
|
|
8158
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset)
|
|
8159
|
-
this.updateShape(changes)
|
|
8072
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset))
|
|
8160
8073
|
|
|
8161
8074
|
// Then resize
|
|
8162
8075
|
this.resizeShape(shape.id, scale, {
|
|
@@ -8801,6 +8714,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8801
8714
|
|
|
8802
8715
|
const animations: ShapeAnimation[] = []
|
|
8803
8716
|
|
|
8717
|
+
// Snapshot the lock override now: when this animation is started inside
|
|
8718
|
+
// editor.run(..., { ignoreShapeLock: true }), run() restores the flag before any tick
|
|
8719
|
+
// fires, so the final updateShapes below would refuse the locked shape and strand it
|
|
8720
|
+
const ignoreShapeLock = this._shouldIgnoreShapeLock
|
|
8721
|
+
|
|
8804
8722
|
let partial: TLShapePartial | null | undefined, result: ShapeAnimation
|
|
8805
8723
|
for (let i = 0, n = partials.length; i < n; i++) {
|
|
8806
8724
|
partial = partials[i]
|
|
@@ -8809,6 +8727,14 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8809
8727
|
const shape = this.getShape(partial.id)!
|
|
8810
8728
|
if (!shape) continue
|
|
8811
8729
|
|
|
8730
|
+
// Apply the same lock rule as updateShapes up front: the intermediate frames go through
|
|
8731
|
+
// _updateShapes, which doesn't check locks, so a locked shape would otherwise be moved by
|
|
8732
|
+
// every frame but the last and end up stranded at the penultimate one
|
|
8733
|
+
const unlocks = shape.isLocked && Object.hasOwn(partial, 'isLocked') && !partial.isLocked
|
|
8734
|
+
if (!ignoreShapeLock && !unlocks && this.isShapeOrAncestorLocked(shape)) {
|
|
8735
|
+
continue
|
|
8736
|
+
}
|
|
8737
|
+
|
|
8812
8738
|
result = {
|
|
8813
8739
|
start: structuredClone(shape),
|
|
8814
8740
|
end: applyPartialToRecordWithProps(structuredClone(shape), partial),
|
|
@@ -8829,7 +8755,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8829
8755
|
if (partialsToUpdate.length) {
|
|
8830
8756
|
// the regular update shapes also removes the shape from
|
|
8831
8757
|
// the animating shapes set
|
|
8832
|
-
this.updateShapes(partialsToUpdate)
|
|
8758
|
+
this.run(() => this.updateShapes(partialsToUpdate), { ignoreShapeLock })
|
|
8833
8759
|
}
|
|
8834
8760
|
|
|
8835
8761
|
this.off('tick', handleTick)
|
|
@@ -8896,18 +8822,16 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8896
8822
|
}
|
|
8897
8823
|
if (this.getIsReadonly()) return this
|
|
8898
8824
|
|
|
8899
|
-
const ids =
|
|
8900
|
-
typeof shapes[0] === 'string'
|
|
8901
|
-
? (shapes as TLShapeId[])
|
|
8902
|
-
: (shapes.map((s) => (s as TLShape).id) as TLShapeId[])
|
|
8903
|
-
|
|
8904
|
-
if (ids.length <= 1) return this
|
|
8825
|
+
const ids = toShapeIds(shapes)
|
|
8905
8826
|
|
|
8906
8827
|
const shapesToGroup = compact(
|
|
8907
8828
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map((id) =>
|
|
8908
8829
|
this.getShape(id)
|
|
8909
8830
|
)
|
|
8910
8831
|
)
|
|
8832
|
+
// Re-check after the lock filter: Box.Common of nothing is not a valid box and would throw
|
|
8833
|
+
if (shapesToGroup.length <= 1) return this
|
|
8834
|
+
|
|
8911
8835
|
const sortedShapeIds = shapesToGroup.sort(sortByIndex).map((s) => s.id)
|
|
8912
8836
|
const childBounds = compact(shapesToGroup.map((shape) => this.getShapePageBounds(shape)))
|
|
8913
8837
|
const pageBounds = Box.Common(childBounds)
|
|
@@ -8920,11 +8844,15 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8920
8844
|
|
|
8921
8845
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId()
|
|
8922
8846
|
|
|
8923
|
-
//
|
|
8924
|
-
|
|
8847
|
+
// createShapes bails out when the page is full, so check first; otherwise the shapes get
|
|
8848
|
+
// reparented into a group that was never created and vanish from the page
|
|
8849
|
+
if (!this.canCreateShapes([groupId])) {
|
|
8850
|
+
alertMaxShapes(this)
|
|
8851
|
+
return this
|
|
8852
|
+
}
|
|
8925
8853
|
|
|
8926
|
-
// If
|
|
8927
|
-
if (!this.isIn('select.idle')) {
|
|
8854
|
+
// If the select tool is mid-interaction, cancel it (get back to idle) before grouping
|
|
8855
|
+
if (this.isIn('select') && !this.isIn('select.idle')) {
|
|
8928
8856
|
this.cancel()
|
|
8929
8857
|
}
|
|
8930
8858
|
|
|
@@ -8978,10 +8906,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8978
8906
|
if (this.getIsReadonly()) return this
|
|
8979
8907
|
|
|
8980
8908
|
const { select = true } = opts
|
|
8981
|
-
const ids =
|
|
8982
|
-
typeof shapes[0] === 'string'
|
|
8983
|
-
? (shapes as TLShapeId[])
|
|
8984
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
8909
|
+
const ids = toShapeIds(shapes)
|
|
8985
8910
|
|
|
8986
8911
|
const shapesToUngroup = compact(
|
|
8987
8912
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map((id) =>
|
|
@@ -8991,9 +8916,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
8991
8916
|
|
|
8992
8917
|
if (shapesToUngroup.length === 0) return this
|
|
8993
8918
|
|
|
8994
|
-
//
|
|
8995
|
-
if (this.
|
|
8996
|
-
if (!this.isIn('select.idle')) {
|
|
8919
|
+
// If the select tool is mid-interaction, cancel it (get back to idle) before ungrouping
|
|
8920
|
+
if (this.isIn('select') && !this.isIn('select.idle')) {
|
|
8997
8921
|
this.cancel()
|
|
8998
8922
|
}
|
|
8999
8923
|
|
|
@@ -9016,10 +8940,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9016
8940
|
if (groups.length === 0) return this
|
|
9017
8941
|
|
|
9018
8942
|
this.run(() => {
|
|
9019
|
-
let group: TLGroupShape
|
|
9020
|
-
|
|
9021
8943
|
for (let i = 0, n = groups.length; i < n; i++) {
|
|
9022
|
-
group
|
|
8944
|
+
// Re-read the group: ungrouping an outer group earlier in this loop reparents the
|
|
8945
|
+
// inner ones, and the stale parentId would send their children into a group that's
|
|
8946
|
+
// about to be deleted
|
|
8947
|
+
const group = this.getShape<TLGroupShape>(groups[i].id)
|
|
8948
|
+
if (!group) continue
|
|
9023
8949
|
const childIds = this.getSortedChildIdsForParent(group.id)
|
|
9024
8950
|
|
|
9025
8951
|
for (let j = 0, n = childIds.length; j < n; j++) {
|
|
@@ -9146,7 +9072,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9146
9072
|
|
|
9147
9073
|
/** @internal */
|
|
9148
9074
|
private _getUnlockedShapeIds(ids: TLShapeId[]): TLShapeId[] {
|
|
9149
|
-
|
|
9075
|
+
// Match updateShapes, which also refuses shapes under a locked ancestor; otherwise a child
|
|
9076
|
+
// of a locked frame can't be moved but can still be deleted or duplicated
|
|
9077
|
+
return ids.filter((id) => !this.isShapeOrAncestorLocked(id))
|
|
9150
9078
|
}
|
|
9151
9079
|
|
|
9152
9080
|
/**
|
|
@@ -9170,8 +9098,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9170
9098
|
throw Error('Editor.deleteShapes: must provide an array of shapes or shapeIds')
|
|
9171
9099
|
}
|
|
9172
9100
|
|
|
9173
|
-
const shapeIds =
|
|
9174
|
-
typeof _ids[0] === 'string' ? (_ids as TLShapeId[]) : (_ids as TLShape[]).map((s) => s.id)
|
|
9101
|
+
const shapeIds = toShapeIds(_ids)
|
|
9175
9102
|
|
|
9176
9103
|
// Normally we don't want to delete locked shapes, but if the force option is set, we'll delete them anyway
|
|
9177
9104
|
const shapeIdsToDelete = this._shouldIgnoreShapeLock
|
|
@@ -9645,10 +9572,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9645
9572
|
*/
|
|
9646
9573
|
getContentFromCurrentPage(shapes: TLShapeId[] | TLShape[]): TLContent | undefined {
|
|
9647
9574
|
// todo: make this work with any page, not just the current page
|
|
9648
|
-
const ids =
|
|
9649
|
-
typeof shapes[0] === 'string'
|
|
9650
|
-
? (shapes as TLShapeId[])
|
|
9651
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
9575
|
+
const ids = toShapeIds(shapes)
|
|
9652
9576
|
|
|
9653
9577
|
if (!ids) return
|
|
9654
9578
|
if (ids.length === 0) return
|
|
@@ -9735,21 +9659,34 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
9735
9659
|
!asset.props.src?.startsWith('data:video') &&
|
|
9736
9660
|
!asset.props.src?.startsWith('http')
|
|
9737
9661
|
) {
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9662
|
+
// If the asset can't be inlined (unresolvable src, fetch failure), fall through and
|
|
9663
|
+
// keep the original record; dropping it leaves the pasted shapes pointing at an
|
|
9664
|
+
// asset that doesn't exist
|
|
9665
|
+
try {
|
|
9666
|
+
const objectUrl = await this.store.props.assets.resolve(asset, {
|
|
9667
|
+
screenScale: 1,
|
|
9668
|
+
steppedScreenScale: 1,
|
|
9669
|
+
dpr: 1,
|
|
9670
|
+
networkEffectiveType: null,
|
|
9671
|
+
shouldResolveToOriginal: true,
|
|
9672
|
+
})
|
|
9673
|
+
if (objectUrl) {
|
|
9674
|
+
// fetch resolves on 4xx/5xx, so without this check a 404 error page would be
|
|
9675
|
+
// inlined as a data:text/html src
|
|
9676
|
+
const response = await fetch(objectUrl)
|
|
9677
|
+
if (response.ok) {
|
|
9678
|
+
const assetWithDataUrl = structuredClone(asset as TLImageAsset | TLVideoAsset)
|
|
9679
|
+
assetWithDataUrl.props.src = await FileHelpers.blobToDataUrl(await response.blob())
|
|
9680
|
+
assets.push(assetWithDataUrl)
|
|
9681
|
+
return
|
|
9682
|
+
}
|
|
9683
|
+
console.warn(`Could not inline asset ${asset.id}: fetch returned ${response.status}`)
|
|
9684
|
+
}
|
|
9685
|
+
} catch (err) {
|
|
9686
|
+
console.warn(`Could not inline asset ${asset.id}`, err)
|
|
9687
|
+
}
|
|
9752
9688
|
}
|
|
9689
|
+
assets.push(asset)
|
|
9753
9690
|
})
|
|
9754
9691
|
)
|
|
9755
9692
|
content.assets = assets
|
|
@@ -10171,12 +10108,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
10171
10108
|
* @public
|
|
10172
10109
|
*/
|
|
10173
10110
|
async getSvgElement(shapes: TLShapeId[] | TLShape[], opts: TLSvgExportOptions = {}) {
|
|
10174
|
-
const ids =
|
|
10175
|
-
shapes.length === 0
|
|
10176
|
-
? this.getCurrentPageShapeIdsSorted()
|
|
10177
|
-
: typeof shapes[0] === 'string'
|
|
10178
|
-
? (shapes as TLShapeId[])
|
|
10179
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
10111
|
+
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes)
|
|
10180
10112
|
|
|
10181
10113
|
if (ids.length === 0) return undefined
|
|
10182
10114
|
|
|
@@ -10865,22 +10797,22 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
10865
10797
|
const releaseMeta = this._metaKeyTimeout !== -1
|
|
10866
10798
|
|
|
10867
10799
|
if (releaseShift) {
|
|
10868
|
-
clearTimeout(this._shiftKeyTimeout)
|
|
10800
|
+
this.timers.clearTimeout(this._shiftKeyTimeout)
|
|
10869
10801
|
this._shiftKeyTimeout = -1
|
|
10870
10802
|
this.inputs.setShiftKey(false)
|
|
10871
10803
|
}
|
|
10872
10804
|
if (releaseAlt) {
|
|
10873
|
-
clearTimeout(this._altKeyTimeout)
|
|
10805
|
+
this.timers.clearTimeout(this._altKeyTimeout)
|
|
10874
10806
|
this._altKeyTimeout = -1
|
|
10875
10807
|
this.inputs.setAltKey(false)
|
|
10876
10808
|
}
|
|
10877
10809
|
if (releaseCtrl) {
|
|
10878
|
-
clearTimeout(this._ctrlKeyTimeout)
|
|
10810
|
+
this.timers.clearTimeout(this._ctrlKeyTimeout)
|
|
10879
10811
|
this._ctrlKeyTimeout = -1
|
|
10880
10812
|
this.inputs.setCtrlKey(false)
|
|
10881
10813
|
}
|
|
10882
10814
|
if (releaseMeta) {
|
|
10883
|
-
clearTimeout(this._metaKeyTimeout)
|
|
10815
|
+
this.timers.clearTimeout(this._metaKeyTimeout)
|
|
10884
10816
|
this._metaKeyTimeout = -1
|
|
10885
10817
|
this.inputs.setMetaKey(false)
|
|
10886
10818
|
}
|
|
@@ -11030,7 +10962,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11030
10962
|
}
|
|
11031
10963
|
|
|
11032
10964
|
if (info.shiftKey) {
|
|
11033
|
-
clearTimeout(this._shiftKeyTimeout)
|
|
10965
|
+
this.timers.clearTimeout(this._shiftKeyTimeout)
|
|
11034
10966
|
this._shiftKeyTimeout = -1
|
|
11035
10967
|
inputs.setShiftKey(true)
|
|
11036
10968
|
} else if (!info.shiftKey && inputs.getShiftKey() && this._shiftKeyTimeout === -1) {
|
|
@@ -11038,7 +10970,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11038
10970
|
}
|
|
11039
10971
|
|
|
11040
10972
|
if (info.altKey) {
|
|
11041
|
-
clearTimeout(this._altKeyTimeout)
|
|
10973
|
+
this.timers.clearTimeout(this._altKeyTimeout)
|
|
11042
10974
|
this._altKeyTimeout = -1
|
|
11043
10975
|
inputs.setAltKey(true)
|
|
11044
10976
|
} else if (!info.altKey && inputs.getAltKey() && this._altKeyTimeout === -1) {
|
|
@@ -11046,7 +10978,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11046
10978
|
}
|
|
11047
10979
|
|
|
11048
10980
|
if (info.ctrlKey) {
|
|
11049
|
-
clearTimeout(this._ctrlKeyTimeout)
|
|
10981
|
+
this.timers.clearTimeout(this._ctrlKeyTimeout)
|
|
11050
10982
|
this._ctrlKeyTimeout = -1
|
|
11051
10983
|
inputs.setCtrlKey(true)
|
|
11052
10984
|
} else if (!info.ctrlKey && inputs.getCtrlKey() && this._ctrlKeyTimeout === -1) {
|
|
@@ -11056,7 +10988,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11056
10988
|
if (info.metaKey && info.name !== 'key_up') {
|
|
11057
10989
|
// Unlike the other modifiers, the native metaKey property is still true on keyup.
|
|
11058
10990
|
// If we don't have this guard, then the metakey will be left true without the timeout.
|
|
11059
|
-
clearTimeout(this._metaKeyTimeout)
|
|
10991
|
+
this.timers.clearTimeout(this._metaKeyTimeout)
|
|
11060
10992
|
this._metaKeyTimeout = -1
|
|
11061
10993
|
inputs.setMetaKey(true)
|
|
11062
10994
|
} else if (!info.metaKey && inputs.getMetaKey() && this._metaKeyTimeout === -1) {
|
|
@@ -11073,8 +11005,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11073
11005
|
|
|
11074
11006
|
switch (type) {
|
|
11075
11007
|
case 'pinch': {
|
|
11076
|
-
|
|
11077
|
-
clearTimeout(this._longPressTimeout)
|
|
11008
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11078
11009
|
this.inputs.updateFromEvent(info)
|
|
11079
11010
|
|
|
11080
11011
|
switch (info.name) {
|
|
@@ -11111,6 +11042,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11111
11042
|
}
|
|
11112
11043
|
case 'pinch': {
|
|
11113
11044
|
if (!inputs.getIsPinching()) return
|
|
11045
|
+
// Lock the zoom, not the gesture: skipping pinch_start would send the fingers'
|
|
11046
|
+
// pointer events to the tool, and skipping pinch_end would leave isPinching stuck.
|
|
11047
|
+
if (cameraOptions.isLocked) return
|
|
11114
11048
|
|
|
11115
11049
|
const {
|
|
11116
11050
|
point: { z = 1 },
|
|
@@ -11184,8 +11118,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11184
11118
|
let wheelBehavior = cameraOptions.wheelBehavior
|
|
11185
11119
|
const inputMode = this.user.getUserPreferences().inputMode
|
|
11186
11120
|
|
|
11187
|
-
//
|
|
11188
|
-
|
|
11121
|
+
// The user's input mode preference picks between pan and zoom, but it must not
|
|
11122
|
+
// re-enable a wheel the app disabled with `wheelBehavior: 'none'`.
|
|
11123
|
+
if (inputMode !== null && wheelBehavior !== 'none') {
|
|
11189
11124
|
wheelBehavior = inputMode === 'trackpad' ? 'pan' : 'zoom'
|
|
11190
11125
|
}
|
|
11191
11126
|
|
|
@@ -11259,15 +11194,18 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11259
11194
|
// Ignore pointer events while we're pinching
|
|
11260
11195
|
if (inputs.getIsPinching()) return
|
|
11261
11196
|
|
|
11262
|
-
this.inputs.updateFromEvent(info)
|
|
11263
11197
|
const { isPen } = info
|
|
11264
11198
|
const { isPenMode } = instanceState
|
|
11265
11199
|
|
|
11200
|
+
// In pen mode, reject non-pen input (a resting palm) before it touches any
|
|
11201
|
+
// state: otherwise updateFromEvent moves the origin point out from under the
|
|
11202
|
+
// pen's drag, and a palm pointer_up clears the pen's isPointing/isDragging.
|
|
11203
|
+
if (isPenMode && !isPen) return
|
|
11204
|
+
|
|
11205
|
+
this.inputs.updateFromEvent(info)
|
|
11206
|
+
|
|
11266
11207
|
switch (info.name) {
|
|
11267
11208
|
case 'pointer_down': {
|
|
11268
|
-
// If we're in pen mode and the input is not a pen type, then stop here
|
|
11269
|
-
if (isPenMode && !isPen) return
|
|
11270
|
-
|
|
11271
11209
|
// A pointer down starts a new interaction, so flush any modifier that's
|
|
11272
11210
|
// still lingering in its release-debounce window: treat it as released now.
|
|
11273
11211
|
this._releaseDebouncedModifiers()
|
|
@@ -11309,6 +11247,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11309
11247
|
inputs.setIsPointing(true)
|
|
11310
11248
|
inputs.setIsDragging(false)
|
|
11311
11249
|
|
|
11250
|
+
// A camera still animating under a held pointer would shift the page
|
|
11251
|
+
// point past the drag threshold and turn a click into a drag (#10706)
|
|
11252
|
+
this.stopCameraAnimation()
|
|
11253
|
+
|
|
11312
11254
|
// If pen mode is off, turn it on for direct-display pen input only (e.g. Apple
|
|
11313
11255
|
// Pencil on an iPad or a Surface Pen on a touchscreen). Indirect desktop tablet
|
|
11314
11256
|
// styluses still draw as pens, but should not auto-enable pen mode.
|
|
@@ -11319,8 +11261,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11319
11261
|
this.interrupt()
|
|
11320
11262
|
}
|
|
11321
11263
|
|
|
11322
|
-
// On devices with erasers (like the Surface Pen or Wacom Pen), button 5 is the eraser
|
|
11323
|
-
|
|
11264
|
+
// On devices with erasers (like the Surface Pen or Wacom Pen), button 5 is the eraser.
|
|
11265
|
+
// Guarded on the eraser tool existing: the bare editor can be configured without
|
|
11266
|
+
// it, and an unguarded transition would throw and crash the editor.
|
|
11267
|
+
if (info.button === STYLUS_ERASER_BUTTON && this.getStateDescendant('eraser')) {
|
|
11324
11268
|
this._restoreToolId = this.getCurrentToolId()
|
|
11325
11269
|
this.complete()
|
|
11326
11270
|
this.setCurrentTool('eraser')
|
|
@@ -11330,10 +11274,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11330
11274
|
this._prevCursor = this.getInstanceState().cursor.type
|
|
11331
11275
|
}
|
|
11332
11276
|
this.inputs.setIsPanning(true)
|
|
11333
|
-
clearTimeout(this._longPressTimeout)
|
|
11277
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11334
11278
|
} else if (info.button === RIGHT_MOUSE_BUTTON && this.options.rightClickPanning) {
|
|
11335
11279
|
this.inputs.setIsRightPointing(true)
|
|
11336
|
-
clearTimeout(this._longPressTimeout)
|
|
11280
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11337
11281
|
return this
|
|
11338
11282
|
}
|
|
11339
11283
|
|
|
@@ -11348,9 +11292,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11348
11292
|
break
|
|
11349
11293
|
}
|
|
11350
11294
|
case 'pointer_move': {
|
|
11351
|
-
// If the user is in pen mode, but the pointer is not a pen, stop here.
|
|
11352
|
-
if (!isPen && isPenMode) return
|
|
11353
|
-
|
|
11354
11295
|
const { x: cx, y: cy, z: cz } = unsafe__withoutCapture(() => this.getCamera())
|
|
11355
11296
|
|
|
11356
11297
|
// Right-click pointing: waiting to see if this becomes a drag
|
|
@@ -11401,7 +11342,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11401
11342
|
) {
|
|
11402
11343
|
// Start dragging
|
|
11403
11344
|
inputs.setIsDragging(true)
|
|
11404
|
-
clearTimeout(this._longPressTimeout)
|
|
11345
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11405
11346
|
}
|
|
11406
11347
|
break
|
|
11407
11348
|
}
|
|
@@ -11409,13 +11350,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11409
11350
|
// Stop dragging / pointing
|
|
11410
11351
|
inputs.setIsDragging(false)
|
|
11411
11352
|
inputs.setIsPointing(false)
|
|
11412
|
-
clearTimeout(this._longPressTimeout)
|
|
11353
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11413
11354
|
// Remove the button from the buttons set
|
|
11414
11355
|
inputs.buttons.delete(info.button)
|
|
11415
11356
|
|
|
11416
|
-
// If we're in pen mode and we're not using a pen, stop here
|
|
11417
|
-
if (instanceState.isPenMode && !isPen) return
|
|
11418
|
-
|
|
11419
11357
|
// Right-click pointing ended without dragging—this is a static
|
|
11420
11358
|
// right-click, so let it through to the state chart as right_click.
|
|
11421
11359
|
// Check isPanning first: if we transitioned to panning, isRightPointing
|
|
@@ -11485,7 +11423,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11485
11423
|
})
|
|
11486
11424
|
}
|
|
11487
11425
|
} else {
|
|
11488
|
-
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
11426
|
+
if (info.button === STYLUS_ERASER_BUTTON && this.getStateDescendant('eraser')) {
|
|
11489
11427
|
// If we were erasing with a stylus button, restore the tool we were using before we started erasing
|
|
11490
11428
|
this.complete()
|
|
11491
11429
|
this.setCurrentTool(this._restoreToolId)
|
|
@@ -11525,7 +11463,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11525
11463
|
|
|
11526
11464
|
this.inputs.setIsPanning(true)
|
|
11527
11465
|
this.inputs.setIsSpacebarPanning(true)
|
|
11528
|
-
clearTimeout(this._longPressTimeout)
|
|
11466
|
+
this.timers.clearTimeout(this._longPressTimeout)
|
|
11529
11467
|
this.setCursor({
|
|
11530
11468
|
type: this.inputs.getIsPointing() ? 'grabbing' : 'grab',
|
|
11531
11469
|
rotation: 0,
|
|
@@ -11553,7 +11491,8 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11553
11491
|
}
|
|
11554
11492
|
}
|
|
11555
11493
|
|
|
11556
|
-
|
|
11494
|
+
// `_animateToViewport` bypasses `setCamera`, so honor the lock here.
|
|
11495
|
+
if (offset && !cameraOptions.isLocked) {
|
|
11557
11496
|
const bounds = this.getViewportPageBounds()
|
|
11558
11497
|
const next = bounds.clone().translate(offset.mulV({ x: bounds.w, y: bounds.h }))
|
|
11559
11498
|
this._animateToViewport(next, { animation: { duration: 320 } })
|
|
@@ -11615,9 +11554,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11615
11554
|
this.setCurrentTool('select')
|
|
11616
11555
|
}
|
|
11617
11556
|
|
|
11618
|
-
//
|
|
11557
|
+
// Send the event to the click manager. In pen mode only pen clicks count; otherwise
|
|
11558
|
+
// every pointer does, including an indirect tablet stylus (a pen that never enables
|
|
11559
|
+
// pen mode), which would otherwise never produce double-click events.
|
|
11619
11560
|
const { isPenMode } = this.store.unsafeGetWithoutCapture(TLINSTANCE_ID)!
|
|
11620
|
-
if (info.isPen
|
|
11561
|
+
if (!isPenMode || info.isPen) {
|
|
11621
11562
|
// The click manager may return a new event, i.e. a double click event
|
|
11622
11563
|
// depending on the event coming in and its own state. If the event has
|
|
11623
11564
|
// changed then hand both events to the statechart
|
|
@@ -11649,7 +11590,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
11649
11590
|
private maybeTrackPerformance(name: string) {
|
|
11650
11591
|
if (debugFlags.measurePerformance.get()) {
|
|
11651
11592
|
if (this.performanceTracker.isStarted()) {
|
|
11652
|
-
clearTimeout(this.performanceTrackerTimeout)
|
|
11593
|
+
this.timers.clearTimeout(this.performanceTrackerTimeout)
|
|
11653
11594
|
} else {
|
|
11654
11595
|
this.performanceTracker.start(name)
|
|
11655
11596
|
}
|
|
@@ -11713,6 +11654,16 @@ function pushShapeWithDescendants(editor: Editor, id: TLShapeId, result: TLShape
|
|
|
11713
11654
|
}
|
|
11714
11655
|
}
|
|
11715
11656
|
|
|
11657
|
+
/**
|
|
11658
|
+
* When `shapes` already holds ids this returns that same array, not a copy, so a caller that
|
|
11659
|
+
* mutates the result (for example to sort it) must copy it first.
|
|
11660
|
+
*/
|
|
11661
|
+
function toShapeIds(shapes: TLShapeId[] | TLShape[]): TLShapeId[] {
|
|
11662
|
+
return typeof shapes[0] === 'string'
|
|
11663
|
+
? (shapes as TLShapeId[])
|
|
11664
|
+
: (shapes as TLShape[]).map((shape) => shape.id)
|
|
11665
|
+
}
|
|
11666
|
+
|
|
11716
11667
|
/**
|
|
11717
11668
|
* Run `callback` in a world where all bindings from the shapes in `shapeIds` to shapes not in
|
|
11718
11669
|
* `shapeIds` are removed. This is useful when you want to duplicate/copy shapes without worrying
|
|
@@ -11750,7 +11701,7 @@ function withIsolatedShapes<T>(
|
|
|
11750
11701
|
}
|
|
11751
11702
|
}
|
|
11752
11703
|
|
|
11753
|
-
editor.
|
|
11704
|
+
editor._deleteBindings([...bindingsToRemove], { isolateShapes: true })
|
|
11754
11705
|
|
|
11755
11706
|
try {
|
|
11756
11707
|
result = Result.ok(callback(bindingsWithBoth))
|