@tldraw/editor 4.5.0-next.752e1005c7c7 → 4.5.0-next.dad6df23ab1f
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 +18 -1
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +13 -16
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +117 -167
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +15 -16
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +3 -3
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +1 -1
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +18 -1
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +13 -16
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +117 -167
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +15 -16
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +3 -3
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +1 -1
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/lib/components/default-components/DefaultCanvas.tsx +19 -26
- package/src/lib/editor/Editor.ts +160 -269
- package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +6 -5
- package/src/lib/editor/shapes/ShapeUtil.ts +1 -1
- package/src/version.ts +3 -3
package/src/lib/editor/Editor.ts
CHANGED
|
@@ -158,6 +158,7 @@ import {
|
|
|
158
158
|
TLEditStartInfo,
|
|
159
159
|
TLGeometryOpts,
|
|
160
160
|
TLResizeMode,
|
|
161
|
+
TLShapeUtilCanBeLaidOutOpts,
|
|
161
162
|
TLShapeUtilCanBindOpts,
|
|
162
163
|
} from './shapes/ShapeUtil'
|
|
163
164
|
import { RootState } from './tools/RootState'
|
|
@@ -6771,6 +6772,77 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6771
6772
|
return this
|
|
6772
6773
|
}
|
|
6773
6774
|
|
|
6775
|
+
/**
|
|
6776
|
+
* Shared clustering logic for layout methods. Resolves shapes, optionally filters to
|
|
6777
|
+
* axis-aligned shapes, checks canBeLaidOut, and groups shapes into clusters via arrow bindings.
|
|
6778
|
+
*
|
|
6779
|
+
* @internal
|
|
6780
|
+
*/
|
|
6781
|
+
private getShapeClusters(
|
|
6782
|
+
shapes: TLShapeId[] | TLShape[],
|
|
6783
|
+
type: TLShapeUtilCanBeLaidOutOpts['type'],
|
|
6784
|
+
opts?: { filterAxisAligned?: boolean }
|
|
6785
|
+
): { clusters: { shapes: TLShape[]; pageBounds: Box }[]; allBounds: Box[] } {
|
|
6786
|
+
const ids =
|
|
6787
|
+
typeof shapes[0] === 'string'
|
|
6788
|
+
? (shapes as TLShapeId[])
|
|
6789
|
+
: (shapes as TLShape[]).map((s) => s.id)
|
|
6790
|
+
|
|
6791
|
+
// always fresh shapes
|
|
6792
|
+
let freshShapes = compact(ids.map((id) => this.getShape(id)))
|
|
6793
|
+
|
|
6794
|
+
// optionally filter to axis-aligned shapes (rotation is a multiple of 90 degrees)
|
|
6795
|
+
if (opts?.filterAxisAligned) {
|
|
6796
|
+
freshShapes = freshShapes.filter(
|
|
6797
|
+
(s) => this.getShapePageTransform(s)?.rotation() % (PI / 2) === 0
|
|
6798
|
+
)
|
|
6799
|
+
}
|
|
6800
|
+
|
|
6801
|
+
const clusters: { shapes: TLShape[]; pageBounds: Box }[] = []
|
|
6802
|
+
const allBounds: Box[] = []
|
|
6803
|
+
const visited = new Set<TLShapeId>()
|
|
6804
|
+
|
|
6805
|
+
for (const shape of freshShapes) {
|
|
6806
|
+
if (visited.has(shape.id)) continue
|
|
6807
|
+
visited.add(shape.id)
|
|
6808
|
+
|
|
6809
|
+
const shapePageBounds = this.getShapePageBounds(shape)
|
|
6810
|
+
if (!shapePageBounds) continue
|
|
6811
|
+
|
|
6812
|
+
if (
|
|
6813
|
+
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
6814
|
+
type,
|
|
6815
|
+
shapes: freshShapes,
|
|
6816
|
+
})
|
|
6817
|
+
) {
|
|
6818
|
+
continue
|
|
6819
|
+
}
|
|
6820
|
+
|
|
6821
|
+
const shapesMovingTogether = [shape]
|
|
6822
|
+
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
6823
|
+
|
|
6824
|
+
this.collectShapesViaArrowBindings({
|
|
6825
|
+
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
6826
|
+
initialShapes: freshShapes,
|
|
6827
|
+
resultShapes: shapesMovingTogether,
|
|
6828
|
+
resultBounds: boundsOfShapesMovingTogether,
|
|
6829
|
+
visited,
|
|
6830
|
+
})
|
|
6831
|
+
|
|
6832
|
+
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
6833
|
+
if (!commonPageBounds) continue
|
|
6834
|
+
|
|
6835
|
+
clusters.push({
|
|
6836
|
+
shapes: shapesMovingTogether,
|
|
6837
|
+
pageBounds: commonPageBounds,
|
|
6838
|
+
})
|
|
6839
|
+
|
|
6840
|
+
allBounds.push(commonPageBounds)
|
|
6841
|
+
}
|
|
6842
|
+
|
|
6843
|
+
return { clusters, allBounds }
|
|
6844
|
+
}
|
|
6845
|
+
|
|
6774
6846
|
/**
|
|
6775
6847
|
* @internal
|
|
6776
6848
|
*/
|
|
@@ -6916,61 +6988,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
6916
6988
|
gap?: number
|
|
6917
6989
|
): this {
|
|
6918
6990
|
const _gap = gap ?? this.options.adjacentShapeMargin
|
|
6919
|
-
const ids =
|
|
6920
|
-
typeof shapes[0] === 'string'
|
|
6921
|
-
? (shapes as TLShapeId[])
|
|
6922
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
6923
6991
|
if (this.getIsReadonly()) return this
|
|
6924
6992
|
|
|
6925
6993
|
// todo: this has a lot of extra code to handle stacking with custom gaps or auto gaps or other things like that. I don't think anyone has ever used this stuff.
|
|
6926
6994
|
|
|
6927
|
-
|
|
6928
|
-
const shapesToStackFirstPass = compact(ids.map((id) => this.getShape(id)))
|
|
6929
|
-
|
|
6930
|
-
const shapeClustersToStack: {
|
|
6931
|
-
shapes: TLShape[]
|
|
6932
|
-
pageBounds: Box
|
|
6933
|
-
}[] = []
|
|
6934
|
-
const allBounds: Box[] = []
|
|
6935
|
-
const visited = new Set<TLShapeId>()
|
|
6936
|
-
|
|
6937
|
-
for (const shape of shapesToStackFirstPass) {
|
|
6938
|
-
if (visited.has(shape.id)) continue
|
|
6939
|
-
visited.add(shape.id)
|
|
6940
|
-
|
|
6941
|
-
const shapePageBounds = this.getShapePageBounds(shape)
|
|
6942
|
-
if (!shapePageBounds) continue
|
|
6943
|
-
|
|
6944
|
-
if (
|
|
6945
|
-
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
6946
|
-
type: 'stack',
|
|
6947
|
-
shapes: shapesToStackFirstPass,
|
|
6948
|
-
})
|
|
6949
|
-
) {
|
|
6950
|
-
continue
|
|
6951
|
-
}
|
|
6952
|
-
|
|
6953
|
-
const shapesMovingTogether = [shape]
|
|
6954
|
-
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
6955
|
-
|
|
6956
|
-
this.collectShapesViaArrowBindings({
|
|
6957
|
-
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
6958
|
-
initialShapes: shapesToStackFirstPass,
|
|
6959
|
-
resultShapes: shapesMovingTogether,
|
|
6960
|
-
resultBounds: boundsOfShapesMovingTogether,
|
|
6961
|
-
visited,
|
|
6962
|
-
})
|
|
6963
|
-
|
|
6964
|
-
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
6965
|
-
if (!commonPageBounds) continue
|
|
6966
|
-
|
|
6967
|
-
shapeClustersToStack.push({
|
|
6968
|
-
shapes: shapesMovingTogether,
|
|
6969
|
-
pageBounds: commonPageBounds,
|
|
6970
|
-
})
|
|
6971
|
-
|
|
6972
|
-
allBounds.push(commonPageBounds)
|
|
6973
|
-
}
|
|
6995
|
+
const { clusters: shapeClustersToStack } = this.getShapeClusters(shapes, 'stack')
|
|
6974
6996
|
|
|
6975
6997
|
const len = shapeClustersToStack.length
|
|
6976
6998
|
if ((_gap === 0 && len < 3) || len < 2) return this
|
|
@@ -7086,61 +7108,12 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7086
7108
|
|
|
7087
7109
|
const gap = _gap ?? this.options.adjacentShapeMargin
|
|
7088
7110
|
|
|
7089
|
-
const
|
|
7090
|
-
typeof shapes[0] === 'string'
|
|
7091
|
-
? (shapes as TLShapeId[])
|
|
7092
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7093
|
-
|
|
7094
|
-
// Always fresh shapes
|
|
7095
|
-
const shapesToPackFirstPass = compact(ids.map((id) => this.getShape(id)))
|
|
7096
|
-
|
|
7097
|
-
const shapeClustersToPack: {
|
|
7098
|
-
shapes: TLShape[]
|
|
7099
|
-
pageBounds: Box
|
|
7100
|
-
nextPageBounds: Box
|
|
7101
|
-
}[] = []
|
|
7111
|
+
const { clusters, allBounds } = this.getShapeClusters(shapes, 'pack')
|
|
7102
7112
|
|
|
7103
|
-
const
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
if (visited.has(shape.id)) continue
|
|
7108
|
-
visited.add(shape.id)
|
|
7109
|
-
|
|
7110
|
-
const shapePageBounds = this.getShapePageBounds(shape)
|
|
7111
|
-
if (!shapePageBounds) continue
|
|
7112
|
-
|
|
7113
|
-
if (
|
|
7114
|
-
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7115
|
-
type: 'pack',
|
|
7116
|
-
shapes: shapesToPackFirstPass,
|
|
7117
|
-
})
|
|
7118
|
-
) {
|
|
7119
|
-
continue
|
|
7120
|
-
}
|
|
7121
|
-
|
|
7122
|
-
const shapesMovingTogether = [shape]
|
|
7123
|
-
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
7124
|
-
|
|
7125
|
-
this.collectShapesViaArrowBindings({
|
|
7126
|
-
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
7127
|
-
initialShapes: shapesToPackFirstPass,
|
|
7128
|
-
resultShapes: shapesMovingTogether,
|
|
7129
|
-
resultBounds: boundsOfShapesMovingTogether,
|
|
7130
|
-
visited,
|
|
7131
|
-
})
|
|
7132
|
-
|
|
7133
|
-
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
7134
|
-
if (!commonPageBounds) continue
|
|
7135
|
-
|
|
7136
|
-
shapeClustersToPack.push({
|
|
7137
|
-
shapes: shapesMovingTogether,
|
|
7138
|
-
pageBounds: commonPageBounds,
|
|
7139
|
-
nextPageBounds: commonPageBounds.clone(),
|
|
7140
|
-
})
|
|
7141
|
-
|
|
7142
|
-
allBounds.push(commonPageBounds)
|
|
7143
|
-
}
|
|
7113
|
+
const shapeClustersToPack = clusters.map((cluster) => ({
|
|
7114
|
+
...cluster,
|
|
7115
|
+
nextPageBounds: cluster.pageBounds.clone(),
|
|
7116
|
+
}))
|
|
7144
7117
|
|
|
7145
7118
|
if (shapeClustersToPack.length < 2) return this
|
|
7146
7119
|
|
|
@@ -7262,63 +7235,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7262
7235
|
): this {
|
|
7263
7236
|
if (this.getIsReadonly()) return this
|
|
7264
7237
|
|
|
7265
|
-
const
|
|
7266
|
-
typeof shapes[0] === 'string'
|
|
7267
|
-
? (shapes as TLShapeId[])
|
|
7268
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7269
|
-
|
|
7270
|
-
// Always get fresh shapes
|
|
7271
|
-
const shapesToAlignFirstPass = compact(ids.map((id) => this.getShape(id)))
|
|
7272
|
-
|
|
7273
|
-
const shapeClustersToAlign: {
|
|
7274
|
-
shapes: TLShape[]
|
|
7275
|
-
pageBounds: Box
|
|
7276
|
-
}[] = []
|
|
7277
|
-
const allBounds: Box[] = []
|
|
7278
|
-
const visited = new Set<TLShapeId>()
|
|
7279
|
-
|
|
7280
|
-
for (const shape of shapesToAlignFirstPass) {
|
|
7281
|
-
if (visited.has(shape.id)) continue
|
|
7282
|
-
visited.add(shape.id)
|
|
7283
|
-
|
|
7284
|
-
const shapePageBounds = this.getShapePageBounds(shape)
|
|
7285
|
-
if (!shapePageBounds) continue
|
|
7286
|
-
|
|
7287
|
-
if (
|
|
7288
|
-
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7289
|
-
type: 'align',
|
|
7290
|
-
shapes: shapesToAlignFirstPass,
|
|
7291
|
-
})
|
|
7292
|
-
) {
|
|
7293
|
-
continue
|
|
7294
|
-
}
|
|
7295
|
-
|
|
7296
|
-
// In this implementation, we want to create psuedo-groups out of shapes that
|
|
7297
|
-
// are moving together. At the moment shapes only move together if they're connected
|
|
7298
|
-
// by arrows. So let's say A -> B -> C -> D and A, B, and C are selected. If we're
|
|
7299
|
-
// aligning A, B, and C, then we want these to move together as one unit.
|
|
7300
|
-
|
|
7301
|
-
const shapesMovingTogether = [shape]
|
|
7302
|
-
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
7303
|
-
|
|
7304
|
-
this.collectShapesViaArrowBindings({
|
|
7305
|
-
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
7306
|
-
initialShapes: shapesToAlignFirstPass,
|
|
7307
|
-
resultShapes: shapesMovingTogether,
|
|
7308
|
-
resultBounds: boundsOfShapesMovingTogether,
|
|
7309
|
-
visited,
|
|
7310
|
-
})
|
|
7311
|
-
|
|
7312
|
-
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
7313
|
-
if (!commonPageBounds) continue
|
|
7314
|
-
|
|
7315
|
-
shapeClustersToAlign.push({
|
|
7316
|
-
shapes: shapesMovingTogether,
|
|
7317
|
-
pageBounds: commonPageBounds,
|
|
7318
|
-
})
|
|
7319
|
-
|
|
7320
|
-
allBounds.push(commonPageBounds)
|
|
7321
|
-
}
|
|
7238
|
+
const { clusters: shapeClustersToAlign, allBounds } = this.getShapeClusters(shapes, 'align')
|
|
7322
7239
|
|
|
7323
7240
|
if (shapeClustersToAlign.length < 2) return this
|
|
7324
7241
|
|
|
@@ -7393,59 +7310,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7393
7310
|
distributeShapes(shapes: TLShapeId[] | TLShape[], operation: 'horizontal' | 'vertical'): this {
|
|
7394
7311
|
if (this.getIsReadonly()) return this
|
|
7395
7312
|
|
|
7396
|
-
const
|
|
7397
|
-
typeof shapes[0] === 'string'
|
|
7398
|
-
? (shapes as TLShapeId[])
|
|
7399
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7400
|
-
|
|
7401
|
-
// always fresh shapes
|
|
7402
|
-
const shapesToDistributeFirstPass = compact(ids.map((id) => this.getShape(id)))
|
|
7403
|
-
|
|
7404
|
-
const shapeClustersToDistribute: {
|
|
7405
|
-
shapes: TLShape[]
|
|
7406
|
-
pageBounds: Box
|
|
7407
|
-
}[] = []
|
|
7408
|
-
|
|
7409
|
-
const allBounds: Box[] = []
|
|
7410
|
-
const visited = new Set<TLShapeId>()
|
|
7411
|
-
|
|
7412
|
-
for (const shape of shapesToDistributeFirstPass) {
|
|
7413
|
-
if (visited.has(shape.id)) continue
|
|
7414
|
-
visited.add(shape.id)
|
|
7415
|
-
|
|
7416
|
-
const shapePageBounds = this.getShapePageBounds(shape)
|
|
7417
|
-
if (!shapePageBounds) continue
|
|
7418
|
-
|
|
7419
|
-
if (
|
|
7420
|
-
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7421
|
-
type: 'distribute',
|
|
7422
|
-
shapes: shapesToDistributeFirstPass,
|
|
7423
|
-
})
|
|
7424
|
-
) {
|
|
7425
|
-
continue
|
|
7426
|
-
}
|
|
7427
|
-
|
|
7428
|
-
const shapesMovingTogether = [shape]
|
|
7429
|
-
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
7430
|
-
|
|
7431
|
-
this.collectShapesViaArrowBindings({
|
|
7432
|
-
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
7433
|
-
initialShapes: shapesToDistributeFirstPass,
|
|
7434
|
-
resultShapes: shapesMovingTogether,
|
|
7435
|
-
resultBounds: boundsOfShapesMovingTogether,
|
|
7436
|
-
visited,
|
|
7437
|
-
})
|
|
7438
|
-
|
|
7439
|
-
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
7440
|
-
if (!commonPageBounds) continue
|
|
7441
|
-
|
|
7442
|
-
shapeClustersToDistribute.push({
|
|
7443
|
-
shapes: shapesMovingTogether,
|
|
7444
|
-
pageBounds: commonPageBounds,
|
|
7445
|
-
})
|
|
7446
|
-
|
|
7447
|
-
allBounds.push(commonPageBounds)
|
|
7448
|
-
}
|
|
7313
|
+
const { clusters: shapeClustersToDistribute } = this.getShapeClusters(shapes, 'distribute')
|
|
7449
7314
|
|
|
7450
7315
|
if (shapeClustersToDistribute.length < 3) return this
|
|
7451
7316
|
|
|
@@ -7473,6 +7338,10 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7473
7338
|
// If the first shape group is also the last shape group, distribute without it
|
|
7474
7339
|
if (first === last) {
|
|
7475
7340
|
const excludedShapeIds = new Set(first.shapes.map((s) => s.id))
|
|
7341
|
+
const ids =
|
|
7342
|
+
typeof shapes[0] === 'string'
|
|
7343
|
+
? (shapes as TLShapeId[])
|
|
7344
|
+
: (shapes as TLShape[]).map((s) => s.id)
|
|
7476
7345
|
return this.distributeShapes(
|
|
7477
7346
|
ids.filter((id) => !excludedShapeIds.has(id)),
|
|
7478
7347
|
operation
|
|
@@ -7542,63 +7411,14 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7542
7411
|
* @public
|
|
7543
7412
|
*/
|
|
7544
7413
|
stretchShapes(shapes: TLShapeId[] | TLShape[], operation: 'horizontal' | 'vertical'): this {
|
|
7545
|
-
const ids =
|
|
7546
|
-
typeof shapes[0] === 'string'
|
|
7547
|
-
? (shapes as TLShapeId[])
|
|
7548
|
-
: (shapes as TLShape[]).map((s) => s.id)
|
|
7549
|
-
|
|
7550
7414
|
if (this.getIsReadonly()) return this
|
|
7551
7415
|
|
|
7552
|
-
|
|
7553
|
-
|
|
7554
|
-
|
|
7416
|
+
const { clusters: shapeClustersToStretch, allBounds } = this.getShapeClusters(
|
|
7417
|
+
shapes,
|
|
7418
|
+
'stretch',
|
|
7419
|
+
{ filterAxisAligned: true }
|
|
7555
7420
|
)
|
|
7556
7421
|
|
|
7557
|
-
const shapeClustersToStretch: {
|
|
7558
|
-
shapes: TLShape[]
|
|
7559
|
-
pageBounds: Box
|
|
7560
|
-
}[] = []
|
|
7561
|
-
|
|
7562
|
-
const allBounds: Box[] = []
|
|
7563
|
-
const visited = new Set<TLShapeId>()
|
|
7564
|
-
|
|
7565
|
-
for (const shape of shapesToStretchFirstPass) {
|
|
7566
|
-
if (visited.has(shape.id)) continue
|
|
7567
|
-
visited.add(shape.id)
|
|
7568
|
-
|
|
7569
|
-
const shapePageBounds = this.getShapePageBounds(shape)
|
|
7570
|
-
if (!shapePageBounds) continue
|
|
7571
|
-
|
|
7572
|
-
const shapesMovingTogether = [shape]
|
|
7573
|
-
const boundsOfShapesMovingTogether: Box[] = [shapePageBounds]
|
|
7574
|
-
|
|
7575
|
-
if (
|
|
7576
|
-
!this.getShapeUtil(shape).canBeLaidOut?.(shape, {
|
|
7577
|
-
type: 'stretch',
|
|
7578
|
-
})
|
|
7579
|
-
) {
|
|
7580
|
-
continue
|
|
7581
|
-
}
|
|
7582
|
-
|
|
7583
|
-
this.collectShapesViaArrowBindings({
|
|
7584
|
-
bindings: this.getBindingsToShape(shape.id, 'arrow'),
|
|
7585
|
-
initialShapes: shapesToStretchFirstPass,
|
|
7586
|
-
resultShapes: shapesMovingTogether,
|
|
7587
|
-
resultBounds: boundsOfShapesMovingTogether,
|
|
7588
|
-
visited,
|
|
7589
|
-
})
|
|
7590
|
-
|
|
7591
|
-
const commonPageBounds = Box.Common(boundsOfShapesMovingTogether)
|
|
7592
|
-
if (!commonPageBounds) continue
|
|
7593
|
-
|
|
7594
|
-
shapeClustersToStretch.push({
|
|
7595
|
-
shapes: shapesMovingTogether,
|
|
7596
|
-
pageBounds: commonPageBounds,
|
|
7597
|
-
})
|
|
7598
|
-
|
|
7599
|
-
allBounds.push(commonPageBounds)
|
|
7600
|
-
}
|
|
7601
|
-
|
|
7602
7422
|
if (shapeClustersToStretch.length < 2) return this
|
|
7603
7423
|
|
|
7604
7424
|
const commonBounds = Box.Common(allBounds)
|
|
@@ -7631,7 +7451,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7631
7451
|
// First translate
|
|
7632
7452
|
const shapeLocalOffset = localOffset.clone()
|
|
7633
7453
|
const parentTransform = this.getShapeParentTransform(shape)
|
|
7634
|
-
if (parentTransform)
|
|
7454
|
+
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation())
|
|
7635
7455
|
shapeLocalOffset.add(shape)
|
|
7636
7456
|
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset)
|
|
7637
7457
|
this.updateShape(changes)
|
|
@@ -7650,6 +7470,77 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|
|
7650
7470
|
return this
|
|
7651
7471
|
}
|
|
7652
7472
|
|
|
7473
|
+
/**
|
|
7474
|
+
* Resize and reposition a set of shapes so that their combined page bounds matches the given
|
|
7475
|
+
* target bounds.
|
|
7476
|
+
*
|
|
7477
|
+
* @example
|
|
7478
|
+
* ```ts
|
|
7479
|
+
* editor.resizeToBounds([box1, box2], { x: 0, y: 0, w: 500, h: 500 })
|
|
7480
|
+
* editor.resizeToBounds(editor.getSelectedShapeIds(), new Box(0, 0, 500, 500))
|
|
7481
|
+
* ```
|
|
7482
|
+
*
|
|
7483
|
+
* @param shapes - The shapes (or shape ids) to resize.
|
|
7484
|
+
* @param bounds - The target bounding box.
|
|
7485
|
+
*
|
|
7486
|
+
* @public
|
|
7487
|
+
*/
|
|
7488
|
+
resizeToBounds(shapes: TLShapeId[] | TLShape[], bounds: BoxLike): this {
|
|
7489
|
+
if (this.getIsReadonly()) return this
|
|
7490
|
+
|
|
7491
|
+
const targetBounds = Box.From(bounds)
|
|
7492
|
+
|
|
7493
|
+
const { clusters: shapeClusters, allBounds } = this.getShapeClusters(
|
|
7494
|
+
shapes,
|
|
7495
|
+
'resize_to_bounds',
|
|
7496
|
+
{ filterAxisAligned: true }
|
|
7497
|
+
)
|
|
7498
|
+
|
|
7499
|
+
if (shapeClusters.length === 0) return this
|
|
7500
|
+
|
|
7501
|
+
const commonBounds = Box.Common(allBounds)
|
|
7502
|
+
if (!commonBounds) return this
|
|
7503
|
+
if (commonBounds.width === 0 || commonBounds.height === 0) return this
|
|
7504
|
+
|
|
7505
|
+
const scaleX = targetBounds.width / commonBounds.width
|
|
7506
|
+
const scaleY = targetBounds.height / commonBounds.height
|
|
7507
|
+
const scale = new Vec(scaleX, scaleY)
|
|
7508
|
+
|
|
7509
|
+
shapeClusters.forEach(({ shapes, pageBounds }) => {
|
|
7510
|
+
const localOffset = new Vec(
|
|
7511
|
+
targetBounds.minX -
|
|
7512
|
+
commonBounds.minX +
|
|
7513
|
+
(pageBounds.minX - commonBounds.minX) * (scaleX - 1),
|
|
7514
|
+
targetBounds.minY - commonBounds.minY + (pageBounds.minY - commonBounds.minY) * (scaleY - 1)
|
|
7515
|
+
)
|
|
7516
|
+
|
|
7517
|
+
const scaleOrigin = new Vec(
|
|
7518
|
+
targetBounds.minX + (pageBounds.minX - commonBounds.minX) * scaleX,
|
|
7519
|
+
targetBounds.minY + (pageBounds.minY - commonBounds.minY) * scaleY
|
|
7520
|
+
)
|
|
7521
|
+
|
|
7522
|
+
for (const shape of shapes) {
|
|
7523
|
+
// First translate
|
|
7524
|
+
const shapeLocalOffset = localOffset.clone()
|
|
7525
|
+
const parentTransform = this.getShapeParentTransform(shape)
|
|
7526
|
+
if (parentTransform) shapeLocalOffset.rot(-parentTransform.rotation())
|
|
7527
|
+
shapeLocalOffset.add(shape)
|
|
7528
|
+
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset)
|
|
7529
|
+
this.updateShape(changes)
|
|
7530
|
+
|
|
7531
|
+
// Then resize
|
|
7532
|
+
this.resizeShape(shape.id, scale, {
|
|
7533
|
+
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
7534
|
+
scaleOrigin,
|
|
7535
|
+
isAspectRatioLocked: this.getShapeUtil(shape).isAspectRatioLocked(shape),
|
|
7536
|
+
scaleAxisRotation: 0,
|
|
7537
|
+
})
|
|
7538
|
+
}
|
|
7539
|
+
})
|
|
7540
|
+
|
|
7541
|
+
return this
|
|
7542
|
+
}
|
|
7543
|
+
|
|
7653
7544
|
/**
|
|
7654
7545
|
* Resize a shape.
|
|
7655
7546
|
*
|
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
import { exhaustiveSwitchError, noop } from '@tldraw/utils'
|
|
12
12
|
import { TLHistoryBatchOptions, TLHistoryEntry } from '../../types/history-types'
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
Recording
|
|
16
|
-
RecordingPreserveRedoStack
|
|
17
|
-
Paused
|
|
18
|
-
}
|
|
14
|
+
const HistoryRecorderState = {
|
|
15
|
+
Recording: 'recording',
|
|
16
|
+
RecordingPreserveRedoStack: 'recordingPreserveRedoStack',
|
|
17
|
+
Paused: 'paused',
|
|
18
|
+
} as const
|
|
19
|
+
type HistoryRecorderState = (typeof HistoryRecorderState)[keyof typeof HistoryRecorderState]
|
|
19
20
|
|
|
20
21
|
/** @public */
|
|
21
22
|
export class HistoryManager<R extends UnknownRecord> {
|
|
@@ -69,7 +69,7 @@ export interface TLShapeUtilCanBindOpts<Shape extends TLShape = TLShape> {
|
|
|
69
69
|
*/
|
|
70
70
|
export interface TLShapeUtilCanBeLaidOutOpts {
|
|
71
71
|
/** The type of action causing the layout. */
|
|
72
|
-
type?: 'align' | 'distribute' | 'pack' | 'stack' | 'flip' | 'stretch'
|
|
72
|
+
type?: 'align' | 'distribute' | 'pack' | 'stack' | 'flip' | 'stretch' | 'resize_to_bounds'
|
|
73
73
|
/** The other shapes being laid out */
|
|
74
74
|
shapes?: TLShape[]
|
|
75
75
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '4.5.0-next.
|
|
4
|
+
export const version = '4.5.0-next.dad6df23ab1f'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2026-
|
|
8
|
-
patch: '2026-
|
|
7
|
+
minor: '2026-03-04T10:05:37.505Z',
|
|
8
|
+
patch: '2026-03-04T10:05:37.505Z',
|
|
9
9
|
}
|