@tldraw/editor 5.5.0-canary.863d45e7dabe → 5.5.0-canary.89ff1861a295
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 +2 -0
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/editor/Editor.js +75 -119
- 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/exports/ExportDelay.js +10 -2
- package/dist-cjs/lib/exports/ExportDelay.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/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/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +2 -0
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/editor/Editor.mjs +75 -119
- 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/exports/ExportDelay.mjs +11 -3
- package/dist-esm/lib/exports/ExportDelay.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/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/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +7 -7
- package/src/lib/editor/Editor.test.ts +20 -0
- package/src/lib/editor/Editor.ts +99 -212
- package/src/lib/editor/derivations/bindingsIndex.ts +3 -0
- package/src/lib/exports/ExportDelay.tsx +16 -4
- 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/license/LicenseManager.ts +13 -1
- package/src/lib/license/LicenseProvider.test.tsx +76 -0
- package/src/lib/license/LicenseProvider.tsx +19 -5
- package/src/version.ts +3 -3
package/dist-cjs/index.d.ts
CHANGED
|
@@ -3483,6 +3483,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3483
3483
|
deleteBindings(bindings: (TLBinding | TLBindingId)[], { isolateShapes }?: {
|
|
3484
3484
|
isolateShapes?: boolean | undefined;
|
|
3485
3485
|
}): this;
|
|
3486
|
+
/* Excluded from this release type: _deleteBindings */
|
|
3486
3487
|
/**
|
|
3487
3488
|
* Delete a binding by its ID. If the binding doesn't exist, it's ignored.
|
|
3488
3489
|
*/
|
|
@@ -3515,6 +3516,7 @@ export declare class Editor extends EventEmitter<TLEventMap> {
|
|
|
3515
3516
|
center?: VecLike;
|
|
3516
3517
|
}): this;
|
|
3517
3518
|
private getChangesToTranslateShape;
|
|
3519
|
+
private getChangesToTranslateShapeByPageDelta;
|
|
3518
3520
|
/**
|
|
3519
3521
|
* Move shapes by a delta.
|
|
3520
3522
|
*
|
package/dist-cjs/index.js
CHANGED
|
@@ -392,7 +392,7 @@ var import_uniq = require("./lib/utils/uniq");
|
|
|
392
392
|
var import_defaultThemes2 = require("./lib/editor/managers/ThemeManager/defaultThemes");
|
|
393
393
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
394
394
|
"@tldraw/editor",
|
|
395
|
-
"5.5.0-canary.
|
|
395
|
+
"5.5.0-canary.89ff1861a295",
|
|
396
396
|
"cjs"
|
|
397
397
|
);
|
|
398
398
|
//# sourceMappingURL=index.js.map
|
|
@@ -95,6 +95,10 @@ var import_UserPreferencesManager = require("./managers/UserPreferencesManager/U
|
|
|
95
95
|
var import_OverlayManager = require("./overlays/OverlayManager");
|
|
96
96
|
var import_RootState = require("./tools/RootState");
|
|
97
97
|
const RENDERING_SHAPES_SORT_CACHE_THRESHOLD = 100;
|
|
98
|
+
const AXIS = {
|
|
99
|
+
horizontal: { val: "x", min: "minX", max: "maxX", dim: "width" },
|
|
100
|
+
vertical: { val: "y", min: "minY", max: "maxY", dim: "height" }
|
|
101
|
+
};
|
|
98
102
|
class Editor extends import_eventemitter3.default {
|
|
99
103
|
id = (0, import_utils.uniqueId)();
|
|
100
104
|
constructor({
|
|
@@ -421,7 +425,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
421
425
|
}
|
|
422
426
|
}
|
|
423
427
|
if (deleteBindingIds.length) {
|
|
424
|
-
this.
|
|
428
|
+
this.store.remove(deleteBindingIds);
|
|
425
429
|
}
|
|
426
430
|
}
|
|
427
431
|
},
|
|
@@ -1381,6 +1385,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1381
1385
|
* @public
|
|
1382
1386
|
**/
|
|
1383
1387
|
updateDocumentSettings(settings) {
|
|
1388
|
+
if (this.getIsReadonly()) return this;
|
|
1384
1389
|
this.run(
|
|
1385
1390
|
() => {
|
|
1386
1391
|
this.store.put([{ ...this.getDocumentSettings(), ...settings }]);
|
|
@@ -1540,7 +1545,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1540
1545
|
* @public
|
|
1541
1546
|
*/
|
|
1542
1547
|
select(...shapes) {
|
|
1543
|
-
const ids =
|
|
1548
|
+
const ids = toShapeIds(shapes);
|
|
1544
1549
|
this.setSelectedShapes(ids);
|
|
1545
1550
|
return this;
|
|
1546
1551
|
}
|
|
@@ -1555,7 +1560,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1555
1560
|
* @public
|
|
1556
1561
|
*/
|
|
1557
1562
|
deselect(...shapes) {
|
|
1558
|
-
const ids =
|
|
1563
|
+
const ids = toShapeIds(shapes);
|
|
1559
1564
|
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1560
1565
|
if (selectedShapeIds.length > 0 && ids.length > 0) {
|
|
1561
1566
|
this.setSelectedShapes(selectedShapeIds.filter((id) => !ids.includes(id)));
|
|
@@ -2064,7 +2069,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2064
2069
|
* @public
|
|
2065
2070
|
*/
|
|
2066
2071
|
setHintingShapes(shapes) {
|
|
2067
|
-
const ids =
|
|
2072
|
+
const ids = toShapeIds(shapes);
|
|
2068
2073
|
this.run(
|
|
2069
2074
|
() => {
|
|
2070
2075
|
this._updateCurrentPageState({ hintingShapeIds: (0, import_utils.dedupe)(ids) });
|
|
@@ -2094,7 +2099,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
2094
2099
|
* @public
|
|
2095
2100
|
*/
|
|
2096
2101
|
setErasingShapes(shapes) {
|
|
2097
|
-
const ids =
|
|
2102
|
+
const ids = toShapeIds(shapes).slice();
|
|
2098
2103
|
ids.sort();
|
|
2099
2104
|
const erasingShapeIds = this.getErasingShapeIds();
|
|
2100
2105
|
this.run(
|
|
@@ -4139,7 +4144,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4139
4144
|
if (shapes.length === 0) {
|
|
4140
4145
|
return;
|
|
4141
4146
|
}
|
|
4142
|
-
const ids =
|
|
4147
|
+
const ids = toShapeIds(shapes);
|
|
4143
4148
|
const freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
|
|
4144
4149
|
if (freshShapes.length === 1) {
|
|
4145
4150
|
const parentId = freshShapes[0].parentId;
|
|
@@ -4642,7 +4647,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4642
4647
|
* @public
|
|
4643
4648
|
*/
|
|
4644
4649
|
reparentShapes(shapes, parentId, insertIndex) {
|
|
4645
|
-
const ids =
|
|
4650
|
+
const ids = toShapeIds(shapes);
|
|
4646
4651
|
if (ids.length === 0) return this;
|
|
4647
4652
|
const changes = [];
|
|
4648
4653
|
const parentTransform = (0, import_tlschema.isPageId)(parentId) ? import_Mat.Mat.Identity() : this.getShapePageTransform(parentId);
|
|
@@ -4871,6 +4876,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4871
4876
|
* binding, but the `type`, `toId`, and `fromId` must all be provided.
|
|
4872
4877
|
*/
|
|
4873
4878
|
createBindings(partials) {
|
|
4879
|
+
if (this.getIsReadonly()) return this;
|
|
4874
4880
|
const bindings = [];
|
|
4875
4881
|
for (const partial of partials) {
|
|
4876
4882
|
const fromShape = this.getShape(partial.fromId);
|
|
@@ -4905,6 +4911,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4905
4911
|
* binding is skipped. The changes from the partial are merged into the existing record.
|
|
4906
4912
|
*/
|
|
4907
4913
|
updateBindings(partials) {
|
|
4914
|
+
if (this.getIsReadonly()) return this;
|
|
4908
4915
|
const updated = [];
|
|
4909
4916
|
for (const partial of partials) {
|
|
4910
4917
|
if (!partial) continue;
|
|
@@ -4933,6 +4940,16 @@ class Editor extends import_eventemitter3.default {
|
|
|
4933
4940
|
* Delete several bindings by their IDs. If a binding ID doesn't exist, it's ignored.
|
|
4934
4941
|
*/
|
|
4935
4942
|
deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4943
|
+
if (this.getIsReadonly()) return this;
|
|
4944
|
+
return this._deleteBindings(bindings, { isolateShapes });
|
|
4945
|
+
}
|
|
4946
|
+
/**
|
|
4947
|
+
* Unguarded so that withIsolatedShapes can transiently isolate shapes for copy and export in
|
|
4948
|
+
* readonly mode; the public deleteBindings is what readonly blocks.
|
|
4949
|
+
*
|
|
4950
|
+
* @internal
|
|
4951
|
+
*/
|
|
4952
|
+
_deleteBindings(bindings, { isolateShapes = false } = {}) {
|
|
4936
4953
|
const ids = bindings.map((binding) => typeof binding === "string" ? binding : binding.id);
|
|
4937
4954
|
if (isolateShapes) {
|
|
4938
4955
|
this.store.atomic(() => {
|
|
@@ -4991,7 +5008,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
4991
5008
|
* @param opts - The options for the rotation.
|
|
4992
5009
|
*/
|
|
4993
5010
|
rotateShapesBy(shapes, delta, opts) {
|
|
4994
|
-
const ids =
|
|
5011
|
+
const ids = toShapeIds(shapes);
|
|
4995
5012
|
if (ids.length <= 0) return this;
|
|
4996
5013
|
const snapshot = (0, import_rotation.getRotationSnapshot)({ editor: this, ids });
|
|
4997
5014
|
if (!snapshot) return this;
|
|
@@ -5028,6 +5045,14 @@ class Editor extends import_eventemitter3.default {
|
|
|
5028
5045
|
}
|
|
5029
5046
|
return workingShape;
|
|
5030
5047
|
}
|
|
5048
|
+
// Counter-rotates the page-space delta into the parent's space; without that a child of a rotated
|
|
5049
|
+
// frame or group would move along its parent's axes instead of the page's.
|
|
5050
|
+
// todo: a shape laid out together with its own parent moves twice, once with the parent and once
|
|
5051
|
+
// on its own; the layout commands should skip shapes whose ancestors are also being laid out
|
|
5052
|
+
getChangesToTranslateShapeByPageDelta(shape, pageDelta) {
|
|
5053
|
+
const localDelta = import_Vec.Vec.From(pageDelta).rot(-this.getShapeParentTransform(shape).rotation());
|
|
5054
|
+
return this.getChangesToTranslateShape(shape, localDelta.add(shape));
|
|
5055
|
+
}
|
|
5031
5056
|
/**
|
|
5032
5057
|
* Move shapes by a delta.
|
|
5033
5058
|
*
|
|
@@ -5040,14 +5065,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
5040
5065
|
* @param offset - The offset to apply to the shapes.
|
|
5041
5066
|
*/
|
|
5042
5067
|
nudgeShapes(shapes, offset) {
|
|
5043
|
-
const ids =
|
|
5068
|
+
const ids = toShapeIds(shapes);
|
|
5044
5069
|
if (ids.length <= 0) return this;
|
|
5045
5070
|
const changes = [];
|
|
5046
5071
|
for (const id of ids) {
|
|
5047
5072
|
const shape = this.getShape(id);
|
|
5048
|
-
|
|
5049
|
-
localDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5050
|
-
changes.push(this.getChangesToTranslateShape(shape, localDelta.add(shape)));
|
|
5073
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, offset));
|
|
5051
5074
|
}
|
|
5052
5075
|
this.updateShapes(changes);
|
|
5053
5076
|
return this;
|
|
@@ -5068,7 +5091,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5068
5091
|
*/
|
|
5069
5092
|
duplicateShapes(shapes, offset) {
|
|
5070
5093
|
this.run(() => {
|
|
5071
|
-
const _ids =
|
|
5094
|
+
const _ids = toShapeIds(shapes);
|
|
5072
5095
|
const ids = this._shouldIgnoreShapeLock ? _ids : this._getUnlockedShapeIds(_ids);
|
|
5073
5096
|
if (ids.length <= 0) return this;
|
|
5074
5097
|
const initialIds = new Set(ids);
|
|
@@ -5177,7 +5200,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5177
5200
|
* @public
|
|
5178
5201
|
*/
|
|
5179
5202
|
moveShapesToPage(shapes, pageId) {
|
|
5180
|
-
const ids =
|
|
5203
|
+
const ids = toShapeIds(shapes);
|
|
5181
5204
|
if (ids.length === 0) return this;
|
|
5182
5205
|
if (this.getIsReadonly()) return this;
|
|
5183
5206
|
const currentPageId = this.getCurrentPageId();
|
|
@@ -5213,7 +5236,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5213
5236
|
* @public
|
|
5214
5237
|
*/
|
|
5215
5238
|
toggleLock(shapes) {
|
|
5216
|
-
const ids =
|
|
5239
|
+
const ids = toShapeIds(shapes);
|
|
5217
5240
|
if (this.getIsReadonly() || ids.length === 0) return this;
|
|
5218
5241
|
let allLocked = true;
|
|
5219
5242
|
const shapesToToggle = [];
|
|
@@ -5252,7 +5275,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5252
5275
|
* @public
|
|
5253
5276
|
*/
|
|
5254
5277
|
sendToBack(shapes) {
|
|
5255
|
-
const ids =
|
|
5278
|
+
const ids = toShapeIds(shapes);
|
|
5256
5279
|
const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toBack", ids, {
|
|
5257
5280
|
considerAllShapes: true
|
|
5258
5281
|
});
|
|
@@ -5282,7 +5305,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5282
5305
|
* @public
|
|
5283
5306
|
*/
|
|
5284
5307
|
sendBackward(shapes, opts = {}) {
|
|
5285
|
-
const ids =
|
|
5308
|
+
const ids = toShapeIds(shapes);
|
|
5286
5309
|
const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "backward", ids, opts);
|
|
5287
5310
|
if (changes) this.updateShapes(changes);
|
|
5288
5311
|
return this;
|
|
@@ -5310,7 +5333,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5310
5333
|
* @public
|
|
5311
5334
|
*/
|
|
5312
5335
|
bringForward(shapes, opts = {}) {
|
|
5313
|
-
const ids =
|
|
5336
|
+
const ids = toShapeIds(shapes);
|
|
5314
5337
|
const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "forward", ids, opts);
|
|
5315
5338
|
if (changes) this.updateShapes(changes);
|
|
5316
5339
|
return this;
|
|
@@ -5329,7 +5352,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5329
5352
|
* @public
|
|
5330
5353
|
*/
|
|
5331
5354
|
bringToFront(shapes) {
|
|
5332
|
-
const ids =
|
|
5355
|
+
const ids = toShapeIds(shapes);
|
|
5333
5356
|
const changes = (0, import_reorderShapes.getReorderingShapesChanges)(this, "toFront", ids);
|
|
5334
5357
|
if (changes) this.updateShapes(changes);
|
|
5335
5358
|
return this;
|
|
@@ -5341,7 +5364,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5341
5364
|
* @internal
|
|
5342
5365
|
*/
|
|
5343
5366
|
getShapeClusters(shapes, type, opts) {
|
|
5344
|
-
const ids =
|
|
5367
|
+
const ids = toShapeIds(shapes);
|
|
5345
5368
|
let freshShapes = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
|
|
5346
5369
|
if (opts?.filterAxisAligned) {
|
|
5347
5370
|
freshShapes = freshShapes.filter((s) => {
|
|
@@ -5422,7 +5445,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5422
5445
|
*/
|
|
5423
5446
|
flipShapes(shapes, operation) {
|
|
5424
5447
|
if (this.getIsReadonly()) return this;
|
|
5425
|
-
const ids =
|
|
5448
|
+
const ids = toShapeIds(shapes);
|
|
5426
5449
|
const shapesToFlipFirstPass = (0, import_utils.compact)(ids.map((id) => this.getShape(id)));
|
|
5427
5450
|
for (const shape of shapesToFlipFirstPass) {
|
|
5428
5451
|
if (this.isShapeOfType(shape, "group")) {
|
|
@@ -5496,21 +5519,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5496
5519
|
const { clusters: shapeClustersToStack } = this.getShapeClusters(shapes, "stack");
|
|
5497
5520
|
const len = shapeClustersToStack.length;
|
|
5498
5521
|
if (_gap === 0 && len < 3 || len < 2) return this;
|
|
5499
|
-
|
|
5500
|
-
let min;
|
|
5501
|
-
let max;
|
|
5502
|
-
let dim;
|
|
5503
|
-
if (operation === "horizontal") {
|
|
5504
|
-
val = "x";
|
|
5505
|
-
min = "minX";
|
|
5506
|
-
max = "maxX";
|
|
5507
|
-
dim = "width";
|
|
5508
|
-
} else {
|
|
5509
|
-
val = "y";
|
|
5510
|
-
min = "minY";
|
|
5511
|
-
max = "maxY";
|
|
5512
|
-
dim = "height";
|
|
5513
|
-
}
|
|
5522
|
+
const { val, min, max, dim } = AXIS[operation];
|
|
5514
5523
|
let shapeGap = 0;
|
|
5515
5524
|
shapeClustersToStack.sort((a, b) => a.pageBounds[min] - b.pageBounds[min]);
|
|
5516
5525
|
if (_gap === 0) {
|
|
@@ -5549,13 +5558,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5549
5558
|
const delta = new import_Vec.Vec();
|
|
5550
5559
|
delta[val] = v + shapeGap - pageBounds[val];
|
|
5551
5560
|
for (const shape of shapes2) {
|
|
5552
|
-
|
|
5553
|
-
const parent = this.getShapeParent(shape);
|
|
5554
|
-
if (parent) {
|
|
5555
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5556
|
-
}
|
|
5557
|
-
shapeDelta.add(shape);
|
|
5558
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5561
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5559
5562
|
}
|
|
5560
5563
|
v += pageBounds[dim] + shapeGap;
|
|
5561
5564
|
}
|
|
@@ -5635,13 +5638,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5635
5638
|
for (const { shapes: shapes2, pageBounds, nextPageBounds } of shapeClustersToPack) {
|
|
5636
5639
|
const delta = import_Vec.Vec.Sub(nextPageBounds.point, pageBounds.point).add(centerDelta);
|
|
5637
5640
|
for (const shape of shapes2) {
|
|
5638
|
-
|
|
5639
|
-
const parent = this.getShapeParent(shape);
|
|
5640
|
-
if (parent) {
|
|
5641
|
-
shapeDelta.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5642
|
-
}
|
|
5643
|
-
shapeDelta.add(shape);
|
|
5644
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5641
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5645
5642
|
}
|
|
5646
5643
|
}
|
|
5647
5644
|
if (changes.length) {
|
|
@@ -5701,13 +5698,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5701
5698
|
}
|
|
5702
5699
|
}
|
|
5703
5700
|
for (const shape of shapes2) {
|
|
5704
|
-
|
|
5705
|
-
const parent = this.getShapeParent(shape);
|
|
5706
|
-
if (parent) {
|
|
5707
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5708
|
-
}
|
|
5709
|
-
shapeDelta.add(shape);
|
|
5710
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5701
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5711
5702
|
}
|
|
5712
5703
|
});
|
|
5713
5704
|
this.updateShapes(changes);
|
|
@@ -5731,27 +5722,13 @@ class Editor extends import_eventemitter3.default {
|
|
|
5731
5722
|
if (this.getIsReadonly()) return this;
|
|
5732
5723
|
const { clusters: shapeClustersToDistribute } = this.getShapeClusters(shapes, "distribute");
|
|
5733
5724
|
if (shapeClustersToDistribute.length < 3) return this;
|
|
5734
|
-
|
|
5735
|
-
let min;
|
|
5736
|
-
let max;
|
|
5737
|
-
let dim;
|
|
5738
|
-
if (operation === "horizontal") {
|
|
5739
|
-
val = "x";
|
|
5740
|
-
min = "minX";
|
|
5741
|
-
max = "maxX";
|
|
5742
|
-
dim = "width";
|
|
5743
|
-
} else {
|
|
5744
|
-
val = "y";
|
|
5745
|
-
min = "minY";
|
|
5746
|
-
max = "maxY";
|
|
5747
|
-
dim = "height";
|
|
5748
|
-
}
|
|
5725
|
+
const { val, min, max, dim } = AXIS[operation];
|
|
5749
5726
|
const changes = [];
|
|
5750
5727
|
const first = shapeClustersToDistribute.sort((a, b) => a.pageBounds[min] - b.pageBounds[min])[0];
|
|
5751
5728
|
const last2 = shapeClustersToDistribute.sort((a, b) => b.pageBounds[max] - a.pageBounds[max])[0];
|
|
5752
5729
|
if (first === last2) {
|
|
5753
5730
|
const excludedShapeIds = new Set(first.shapes.map((s) => s.id));
|
|
5754
|
-
const ids =
|
|
5731
|
+
const ids = toShapeIds(shapes);
|
|
5755
5732
|
return this.distributeShapes(
|
|
5756
5733
|
ids.filter((id) => !excludedShapeIds.has(id)),
|
|
5757
5734
|
operation
|
|
@@ -5775,13 +5752,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5775
5752
|
delta[val] = last2.pageBounds[max] - pageBounds[max] - 1;
|
|
5776
5753
|
}
|
|
5777
5754
|
for (const shape of shapes2) {
|
|
5778
|
-
|
|
5779
|
-
const parent = this.getShapeParent(shape);
|
|
5780
|
-
if (parent) {
|
|
5781
|
-
shapeDelta.rot(-this.getShapePageTransform(parent).rotation());
|
|
5782
|
-
}
|
|
5783
|
-
shapeDelta.add(shape);
|
|
5784
|
-
changes.push(this.getChangesToTranslateShape(shape, shapeDelta));
|
|
5755
|
+
changes.push(this.getChangesToTranslateShapeByPageDelta(shape, delta));
|
|
5785
5756
|
}
|
|
5786
5757
|
v += pageBounds[dim] + gap;
|
|
5787
5758
|
}
|
|
@@ -5811,32 +5782,17 @@ class Editor extends import_eventemitter3.default {
|
|
|
5811
5782
|
);
|
|
5812
5783
|
if (shapeClustersToStretch.length < 2) return this;
|
|
5813
5784
|
const commonBounds = import_Box.Box.Common(allBounds);
|
|
5814
|
-
|
|
5815
|
-
let min;
|
|
5816
|
-
let dim;
|
|
5817
|
-
if (operation === "horizontal") {
|
|
5818
|
-
val = "x";
|
|
5819
|
-
min = "minX";
|
|
5820
|
-
dim = "width";
|
|
5821
|
-
} else {
|
|
5822
|
-
val = "y";
|
|
5823
|
-
min = "minY";
|
|
5824
|
-
dim = "height";
|
|
5825
|
-
}
|
|
5785
|
+
const { val, min, dim } = AXIS[operation];
|
|
5826
5786
|
this.run(() => {
|
|
5827
5787
|
shapeClustersToStretch.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5828
|
-
const
|
|
5829
|
-
|
|
5788
|
+
const pageOffset = new import_Vec.Vec();
|
|
5789
|
+
pageOffset[val] = commonBounds[min] - pageBounds[min];
|
|
5830
5790
|
const scaleOrigin = pageBounds.center.clone();
|
|
5831
5791
|
scaleOrigin[val] = commonBounds[min];
|
|
5832
5792
|
const scale = new import_Vec.Vec(1, 1);
|
|
5833
5793
|
scale[val] = commonBounds[dim] / pageBounds[dim];
|
|
5834
5794
|
for (const shape of shapes2) {
|
|
5835
|
-
|
|
5836
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5837
|
-
shapeLocalOffset.add(shape);
|
|
5838
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5839
|
-
this.updateShape(changes);
|
|
5795
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
|
|
5840
5796
|
this.resizeShape(shape.id, scale, {
|
|
5841
5797
|
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
5842
5798
|
scaleOrigin,
|
|
@@ -5879,7 +5835,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5879
5835
|
const scaleY = targetBounds.height / commonBounds.height;
|
|
5880
5836
|
const scale = new import_Vec.Vec(scaleX, scaleY);
|
|
5881
5837
|
shapeClusters.forEach(({ shapes: shapes2, pageBounds }) => {
|
|
5882
|
-
const
|
|
5838
|
+
const pageOffset = new import_Vec.Vec(
|
|
5883
5839
|
targetBounds.minX - commonBounds.minX + (pageBounds.minX - commonBounds.minX) * (scaleX - 1),
|
|
5884
5840
|
targetBounds.minY - commonBounds.minY + (pageBounds.minY - commonBounds.minY) * (scaleY - 1)
|
|
5885
5841
|
);
|
|
@@ -5888,11 +5844,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
5888
5844
|
targetBounds.minY + (pageBounds.minY - commonBounds.minY) * scaleY
|
|
5889
5845
|
);
|
|
5890
5846
|
for (const shape of shapes2) {
|
|
5891
|
-
|
|
5892
|
-
shapeLocalOffset.rot(-this.getShapeParentTransform(shape).rotation());
|
|
5893
|
-
shapeLocalOffset.add(shape);
|
|
5894
|
-
const changes = this.getChangesToTranslateShape(shape, shapeLocalOffset);
|
|
5895
|
-
this.updateShape(changes);
|
|
5847
|
+
this.updateShape(this.getChangesToTranslateShapeByPageDelta(shape, pageOffset));
|
|
5896
5848
|
this.resizeShape(shape.id, scale, {
|
|
5897
5849
|
initialBounds: this.getShapeGeometry(shape).bounds,
|
|
5898
5850
|
scaleOrigin,
|
|
@@ -6370,8 +6322,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6370
6322
|
throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");
|
|
6371
6323
|
}
|
|
6372
6324
|
if (this.getIsReadonly()) return this;
|
|
6373
|
-
const ids =
|
|
6374
|
-
if (ids.length <= 1) return this;
|
|
6325
|
+
const ids = toShapeIds(shapes);
|
|
6375
6326
|
const shapesToGroup = (0, import_utils.compact)(
|
|
6376
6327
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
|
|
6377
6328
|
(id) => this.getShape(id)
|
|
@@ -6386,8 +6337,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
6386
6337
|
}
|
|
6387
6338
|
const { x, y } = pageBounds.point;
|
|
6388
6339
|
const parentId = this.findCommonAncestor(shapesToGroup) ?? this.getCurrentPageId();
|
|
6389
|
-
if (this.
|
|
6390
|
-
|
|
6340
|
+
if (!this.canCreateShapes([groupId])) {
|
|
6341
|
+
alertMaxShapes(this);
|
|
6342
|
+
return this;
|
|
6343
|
+
}
|
|
6344
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6391
6345
|
this.cancel();
|
|
6392
6346
|
}
|
|
6393
6347
|
const shapesWithRootParent = shapesToGroup.filter((shape) => shape.parentId === parentId).sort(import_utils.sortByIndex);
|
|
@@ -6415,15 +6369,14 @@ class Editor extends import_eventemitter3.default {
|
|
|
6415
6369
|
ungroupShapes(shapes, opts = {}) {
|
|
6416
6370
|
if (this.getIsReadonly()) return this;
|
|
6417
6371
|
const { select = true } = opts;
|
|
6418
|
-
const ids =
|
|
6372
|
+
const ids = toShapeIds(shapes);
|
|
6419
6373
|
const shapesToUngroup = (0, import_utils.compact)(
|
|
6420
6374
|
(this._shouldIgnoreShapeLock ? ids : this._getUnlockedShapeIds(ids)).map(
|
|
6421
6375
|
(id) => this.getShape(id)
|
|
6422
6376
|
)
|
|
6423
6377
|
);
|
|
6424
6378
|
if (shapesToUngroup.length === 0) return this;
|
|
6425
|
-
if (this.
|
|
6426
|
-
if (!this.isIn("select.idle")) {
|
|
6379
|
+
if (this.isIn("select") && !this.isIn("select.idle")) {
|
|
6427
6380
|
this.cancel();
|
|
6428
6381
|
}
|
|
6429
6382
|
const idsToSelect = /* @__PURE__ */ new Set();
|
|
@@ -6437,16 +6390,16 @@ class Editor extends import_eventemitter3.default {
|
|
|
6437
6390
|
});
|
|
6438
6391
|
if (groups.length === 0) return this;
|
|
6439
6392
|
this.run(() => {
|
|
6440
|
-
let group;
|
|
6441
6393
|
for (let i = 0, n = groups.length; i < n; i++) {
|
|
6442
|
-
group = groups[i];
|
|
6394
|
+
const group = this.getShape(groups[i].id);
|
|
6395
|
+
if (!group) continue;
|
|
6443
6396
|
const childIds = this.getSortedChildIdsForParent(group.id);
|
|
6444
6397
|
for (let j = 0, n2 = childIds.length; j < n2; j++) {
|
|
6445
6398
|
idsToSelect.add(childIds[j]);
|
|
6446
6399
|
}
|
|
6447
6400
|
this.reparentShapes(childIds, group.parentId, group.index);
|
|
6448
6401
|
}
|
|
6449
|
-
this.deleteShapes(groups.map((
|
|
6402
|
+
this.deleteShapes(groups.map((group) => group.id));
|
|
6450
6403
|
if (select) {
|
|
6451
6404
|
this.select(...idsToSelect);
|
|
6452
6405
|
}
|
|
@@ -6534,7 +6487,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6534
6487
|
if (!Array.isArray(_ids)) {
|
|
6535
6488
|
throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");
|
|
6536
6489
|
}
|
|
6537
|
-
const shapeIds =
|
|
6490
|
+
const shapeIds = toShapeIds(_ids);
|
|
6538
6491
|
const shapeIdsToDelete = this._shouldIgnoreShapeLock ? shapeIds : this._getUnlockedShapeIds(shapeIds);
|
|
6539
6492
|
if (shapeIdsToDelete.length === 0) return this;
|
|
6540
6493
|
const allShapeIdsToDelete = new Set(shapeIdsToDelete);
|
|
@@ -6879,7 +6832,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
6879
6832
|
* @public
|
|
6880
6833
|
*/
|
|
6881
6834
|
getContentFromCurrentPage(shapes) {
|
|
6882
|
-
const ids =
|
|
6835
|
+
const ids = toShapeIds(shapes);
|
|
6883
6836
|
if (!ids) return;
|
|
6884
6837
|
if (ids.length === 0) return;
|
|
6885
6838
|
const shapeIds = this.getShapeAndDescendantIds(ids);
|
|
@@ -7263,7 +7216,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
7263
7216
|
* @public
|
|
7264
7217
|
*/
|
|
7265
7218
|
async getSvgElement(shapes, opts = {}) {
|
|
7266
|
-
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() :
|
|
7219
|
+
const ids = shapes.length === 0 ? this.getCurrentPageShapeIdsSorted() : toShapeIds(shapes);
|
|
7267
7220
|
if (ids.length === 0) return void 0;
|
|
7268
7221
|
await this.fonts.loadRequiredFontsForCurrentPage(this.options.maxFontsToLoadBeforeRender);
|
|
7269
7222
|
return (0, import_exportToSvg.exportToSvg)(this, ids, opts);
|
|
@@ -8688,6 +8641,9 @@ function pushShapeWithDescendants(editor, id, result) {
|
|
|
8688
8641
|
pushShapeWithDescendants(editor, childIds[i], result);
|
|
8689
8642
|
}
|
|
8690
8643
|
}
|
|
8644
|
+
function toShapeIds(shapes) {
|
|
8645
|
+
return typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
|
|
8646
|
+
}
|
|
8691
8647
|
function withIsolatedShapes(editor, shapeIds, callback) {
|
|
8692
8648
|
let result;
|
|
8693
8649
|
editor.run(
|
|
@@ -8710,7 +8666,7 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8710
8666
|
}
|
|
8711
8667
|
}
|
|
8712
8668
|
}
|
|
8713
|
-
editor.
|
|
8669
|
+
editor._deleteBindings([...bindingsToRemove], { isolateShapes: true });
|
|
8714
8670
|
try {
|
|
8715
8671
|
result = import_utils.Result.ok(callback(bindingsWithBoth));
|
|
8716
8672
|
} catch (error) {
|