@tldraw/editor 5.4.0-canary.587f42e00c65 → 5.4.0-canary.5a084792df77
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.js +1 -1
- package/dist-cjs/lib/editor/Editor.js +39 -62
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +3 -3
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js +1 -1
- package/dist-cjs/lib/editor/tools/BaseBoxShapeTool/children/Pointing.js.map +2 -2
- package/dist-cjs/lib/hooks/useCanvasEvents.js +2 -0
- package/dist-cjs/lib/hooks/useCanvasEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js +1 -0
- package/dist-cjs/lib/hooks/usePassThroughWheelEvents.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js +2 -1
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/utils/deepLinks.js +5 -1
- package/dist-cjs/lib/utils/deepLinks.js.map +2 -2
- package/dist-cjs/lib/utils/sync/alerts.js +1 -1
- package/dist-cjs/lib/utils/sync/alerts.js.map +1 -1
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/editor/Editor.mjs +40 -62
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +3 -3
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs +1 -1
- package/dist-esm/lib/editor/tools/BaseBoxShapeTool/children/Pointing.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCanvasEvents.mjs +2 -0
- package/dist-esm/lib/hooks/useCanvasEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs +1 -0
- package/dist-esm/lib/hooks/usePassThroughWheelEvents.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +2 -1
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/utils/deepLinks.mjs +5 -1
- package/dist-esm/lib/utils/deepLinks.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/alerts.mjs +1 -1
- package/dist-esm/lib/utils/sync/alerts.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/editor/Editor.ts +70 -87
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +5 -3
- package/src/lib/editor/tools/BaseBoxShapeTool/children/Pointing.ts +4 -1
- package/src/lib/hooks/useCanvasEvents.ts +2 -0
- package/src/lib/hooks/usePassThroughWheelEvents.ts +3 -0
- package/src/lib/hooks/usePeerIds.ts +2 -1
- package/src/lib/test/useCanvasEvents.test.tsx +74 -0
- package/src/lib/test/usePassThroughWheelEvents.test.tsx +25 -2
- package/src/lib/utils/deepLinks.test.ts +15 -0
- package/src/lib/utils/deepLinks.ts +7 -1
- package/src/lib/utils/sync/alerts.ts +1 -1
- package/src/version.ts +3 -3
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
Result,
|
|
40
40
|
ZERO_INDEX_KEY,
|
|
41
41
|
annotateError,
|
|
42
|
+
areArraysShallowEqual,
|
|
42
43
|
assert,
|
|
43
44
|
assertExists,
|
|
44
45
|
bind,
|
|
@@ -296,6 +297,10 @@ class Editor extends EventEmitter {
|
|
|
296
297
|
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
297
298
|
nextPageState.editingShapeId = null;
|
|
298
299
|
}
|
|
300
|
+
if (prevPageState.croppingShapeId && shapesNoLongerInPage.has(prevPageState.croppingShapeId)) {
|
|
301
|
+
if (!nextPageState) nextPageState = { ...prevPageState };
|
|
302
|
+
nextPageState.croppingShapeId = null;
|
|
303
|
+
}
|
|
299
304
|
const hintingShapeIds = prevPageState.hintingShapeIds.filter(
|
|
300
305
|
(id) => !shapesNoLongerInPage.has(id)
|
|
301
306
|
);
|
|
@@ -1998,42 +2003,28 @@ class Editor extends EventEmitter {
|
|
|
1998
2003
|
*/
|
|
1999
2004
|
setEditingShape(shape) {
|
|
2000
2005
|
const id = typeof shape === "string" ? shape : shape?.id ?? null;
|
|
2001
|
-
if (!id)
|
|
2006
|
+
if (id && !this.canEditShape(id)) return this;
|
|
2007
|
+
this.run(() => {
|
|
2008
|
+
const prevEditingShapeId = this.getEditingShapeId();
|
|
2009
|
+
if (prevEditingShapeId) {
|
|
2010
|
+
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
2011
|
+
if (prevEditingShape) {
|
|
2012
|
+
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2002
2015
|
this.run(
|
|
2003
2016
|
() => {
|
|
2004
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
2005
|
-
if (prevEditingShapeId) {
|
|
2006
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
2007
|
-
if (prevEditingShape) {
|
|
2008
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
2009
|
-
}
|
|
2010
|
-
}
|
|
2011
2017
|
this._updateCurrentPageState({ editingShapeId: null });
|
|
2012
2018
|
this._currentRichTextEditor.set(null);
|
|
2019
|
+
if (!id) return;
|
|
2020
|
+
this.select(id);
|
|
2021
|
+
this._updateCurrentPageState({ editingShapeId: id });
|
|
2022
|
+
const nextEditingShape = this.getShape(id);
|
|
2023
|
+
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
2013
2024
|
},
|
|
2014
2025
|
{ history: "ignore" }
|
|
2015
2026
|
);
|
|
2016
|
-
|
|
2017
|
-
}
|
|
2018
|
-
if (!this.canEditShape(id)) return this;
|
|
2019
|
-
this.run(
|
|
2020
|
-
() => {
|
|
2021
|
-
const prevEditingShapeId = this.getEditingShapeId();
|
|
2022
|
-
if (prevEditingShapeId) {
|
|
2023
|
-
const prevEditingShape = this.getShape(prevEditingShapeId);
|
|
2024
|
-
if (prevEditingShape) {
|
|
2025
|
-
this.getShapeUtil(prevEditingShape).onEditEnd?.(prevEditingShape);
|
|
2026
|
-
}
|
|
2027
|
-
}
|
|
2028
|
-
this._updateCurrentPageState({ editingShapeId: null });
|
|
2029
|
-
this._currentRichTextEditor.set(null);
|
|
2030
|
-
this.select(id);
|
|
2031
|
-
this._updateCurrentPageState({ editingShapeId: id });
|
|
2032
|
-
const nextEditingShape = this.getShape(id);
|
|
2033
|
-
this.getShapeUtil(nextEditingShape).onEditStart?.(nextEditingShape);
|
|
2034
|
-
},
|
|
2035
|
-
{ history: "ignore" }
|
|
2036
|
-
);
|
|
2027
|
+
});
|
|
2037
2028
|
return this;
|
|
2038
2029
|
}
|
|
2039
2030
|
// Rich text editor
|
|
@@ -2139,19 +2130,12 @@ class Editor extends EventEmitter {
|
|
|
2139
2130
|
* @public
|
|
2140
2131
|
*/
|
|
2141
2132
|
setErasingShapes(shapes) {
|
|
2142
|
-
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((shape) => shape.id);
|
|
2133
|
+
const ids = typeof shapes[0] === "string" ? shapes.slice() : shapes.map((shape) => shape.id);
|
|
2143
2134
|
ids.sort();
|
|
2144
2135
|
const erasingShapeIds = this.getErasingShapeIds();
|
|
2145
2136
|
this.run(
|
|
2146
2137
|
() => {
|
|
2147
|
-
if (ids
|
|
2148
|
-
for (let i = 0; i < ids.length; i++) {
|
|
2149
|
-
if (ids[i] !== erasingShapeIds[i]) {
|
|
2150
|
-
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2151
|
-
break;
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
} else {
|
|
2138
|
+
if (!areArraysShallowEqual(ids, erasingShapeIds)) {
|
|
2155
2139
|
this._updateCurrentPageState({ erasingShapeIds: ids });
|
|
2156
2140
|
}
|
|
2157
2141
|
},
|
|
@@ -2184,6 +2168,7 @@ class Editor extends EventEmitter {
|
|
|
2184
2168
|
if (!_shape) return false;
|
|
2185
2169
|
const util = this.getShapeUtil(_shape);
|
|
2186
2170
|
if (!util.canCrop(_shape)) return false;
|
|
2171
|
+
if (this.getIsReadonly()) return false;
|
|
2187
2172
|
if (this.isShapeOrAncestorLocked(_shape)) return false;
|
|
2188
2173
|
return true;
|
|
2189
2174
|
}
|
|
@@ -2393,7 +2378,7 @@ class Editor extends EventEmitter {
|
|
|
2393
2378
|
...this._cameraOptions.__unsafe__getWithoutCapture(),
|
|
2394
2379
|
...opts
|
|
2395
2380
|
});
|
|
2396
|
-
if (next.zoomSteps
|
|
2381
|
+
if (!next.zoomSteps || next.zoomSteps.length < 1) next.zoomSteps = [1];
|
|
2397
2382
|
this._cameraOptions.set(next);
|
|
2398
2383
|
this.setCamera(this.getCamera());
|
|
2399
2384
|
return this;
|
|
@@ -2414,8 +2399,8 @@ class Editor extends EventEmitter {
|
|
|
2414
2399
|
const vsb = this.getViewportScreenBounds();
|
|
2415
2400
|
if (cameraOptions.constraints) {
|
|
2416
2401
|
const { constraints } = cameraOptions;
|
|
2417
|
-
const
|
|
2418
|
-
const
|
|
2402
|
+
const px = Math.min(constraints.padding.x, vsb.w / 2);
|
|
2403
|
+
const py = Math.min(constraints.padding.y, vsb.h / 2);
|
|
2419
2404
|
const bounds = Box.From(cameraOptions.constraints.bounds);
|
|
2420
2405
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
2421
2406
|
const zy = (vsb.h - py * 2) / bounds.h;
|
|
@@ -2454,12 +2439,12 @@ class Editor extends EventEmitter {
|
|
|
2454
2439
|
break;
|
|
2455
2440
|
}
|
|
2456
2441
|
case "inside": {
|
|
2457
|
-
if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w);
|
|
2442
|
+
if (z < zx) x = clamp(x, minX, (vsb.w - px) / z - bounds.w - bounds.x);
|
|
2458
2443
|
else x = clamp(x, minX + freeW, minX);
|
|
2459
2444
|
break;
|
|
2460
2445
|
}
|
|
2461
2446
|
case "outside": {
|
|
2462
|
-
x = clamp(x, px / z - bounds.w, (vsb.w - px) / z);
|
|
2447
|
+
x = clamp(x, px / z - bounds.w - bounds.x, (vsb.w - px) / z - bounds.x);
|
|
2463
2448
|
break;
|
|
2464
2449
|
}
|
|
2465
2450
|
case "free": {
|
|
@@ -2480,12 +2465,12 @@ class Editor extends EventEmitter {
|
|
|
2480
2465
|
break;
|
|
2481
2466
|
}
|
|
2482
2467
|
case "inside": {
|
|
2483
|
-
if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h);
|
|
2468
|
+
if (z < zy) y = clamp(y, minY, (vsb.h - py) / z - bounds.h - bounds.y);
|
|
2484
2469
|
else y = clamp(y, minY + freeH, minY);
|
|
2485
2470
|
break;
|
|
2486
2471
|
}
|
|
2487
2472
|
case "outside": {
|
|
2488
|
-
y = clamp(y, py / z - bounds.h, (vsb.h - py) / z);
|
|
2473
|
+
y = clamp(y, py / z - bounds.h - bounds.y, (vsb.h - py) / z - bounds.y);
|
|
2489
2474
|
break;
|
|
2490
2475
|
}
|
|
2491
2476
|
case "free": {
|
|
@@ -4097,7 +4082,9 @@ class Editor extends EventEmitter {
|
|
|
4097
4082
|
if (pageMask) {
|
|
4098
4083
|
if (pageMask.length === 0) return void 0;
|
|
4099
4084
|
const { corners } = pageBounds;
|
|
4100
|
-
if (corners.every((p, i) =>
|
|
4085
|
+
if (pageMask.length === corners.length && corners.every((p, i) => Vec.Equals(p, pageMask[i]))) {
|
|
4086
|
+
return pageBounds.clone();
|
|
4087
|
+
}
|
|
4101
4088
|
const intersection = intersectPolygonPolygon(pageMask, corners);
|
|
4102
4089
|
if (!intersection) return;
|
|
4103
4090
|
return Box.FromPoints(intersection);
|
|
@@ -4336,7 +4323,7 @@ class Editor extends EventEmitter {
|
|
|
4336
4323
|
const pointInShapeSpace = this.getPointInShapeSpace(shape, point);
|
|
4337
4324
|
const shapeUtil = this.getShapeUtil(shape);
|
|
4338
4325
|
const isShapeFrameLike = this.isShapeFrameLike(shape);
|
|
4339
|
-
if (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim()) {
|
|
4326
|
+
if (isGroup && (isShapeFrameLike || (this.isShapeOfType(shape, "note") || this.isShapeOfType(shape, "arrow") || this.isShapeOfType(shape, "geo") && shape.props.fill === "none") && shapeUtil.getText(shape)?.trim())) {
|
|
4340
4327
|
for (const childGeometry of geometry.children) {
|
|
4341
4328
|
if (childGeometry.isLabel && childGeometry.isPointInBounds(pointInShapeSpace)) {
|
|
4342
4329
|
return shape;
|
|
@@ -5259,26 +5246,17 @@ class Editor extends EventEmitter {
|
|
|
5259
5246
|
toggleLock(shapes) {
|
|
5260
5247
|
const ids = typeof shapes[0] === "string" ? shapes : shapes.map((s) => s.id);
|
|
5261
5248
|
if (this.getIsReadonly() || ids.length === 0) return this;
|
|
5262
|
-
let allLocked = true
|
|
5249
|
+
let allLocked = true;
|
|
5263
5250
|
const shapesToToggle = [];
|
|
5264
5251
|
for (const id of ids) {
|
|
5265
5252
|
const shape = this.getShape(id);
|
|
5266
5253
|
if (shape) {
|
|
5267
5254
|
shapesToToggle.push(shape);
|
|
5268
|
-
if (shape.isLocked)
|
|
5269
|
-
allUnlocked = false;
|
|
5270
|
-
} else {
|
|
5271
|
-
allLocked = false;
|
|
5272
|
-
}
|
|
5255
|
+
if (!shape.isLocked) allLocked = false;
|
|
5273
5256
|
}
|
|
5274
5257
|
}
|
|
5275
5258
|
this.run(() => {
|
|
5276
|
-
if (
|
|
5277
|
-
this.updateShapes(
|
|
5278
|
-
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5279
|
-
);
|
|
5280
|
-
this.setSelectedShapes([]);
|
|
5281
|
-
} else if (allLocked) {
|
|
5259
|
+
if (allLocked) {
|
|
5282
5260
|
this.updateShapes(
|
|
5283
5261
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: false }))
|
|
5284
5262
|
);
|
|
@@ -5286,6 +5264,7 @@ class Editor extends EventEmitter {
|
|
|
5286
5264
|
this.updateShapes(
|
|
5287
5265
|
shapesToToggle.map((shape) => ({ id: shape.id, type: shape.type, isLocked: true }))
|
|
5288
5266
|
);
|
|
5267
|
+
this.setSelectedShapes([]);
|
|
5289
5268
|
}
|
|
5290
5269
|
});
|
|
5291
5270
|
return this;
|
|
@@ -8767,10 +8746,9 @@ function withIsolatedShapes(editor, shapeIds, callback) {
|
|
|
8767
8746
|
}
|
|
8768
8747
|
function getCameraFitXFitY(editor, cameraOptions) {
|
|
8769
8748
|
if (!cameraOptions.constraints) throw Error("Should have constraints here");
|
|
8770
|
-
const {
|
|
8771
|
-
padding: { x: px, y: py }
|
|
8772
|
-
} = cameraOptions.constraints;
|
|
8773
8749
|
const vsb = editor.getViewportScreenBounds();
|
|
8750
|
+
const px = Math.min(cameraOptions.constraints.padding.x, vsb.w / 2);
|
|
8751
|
+
const py = Math.min(cameraOptions.constraints.padding.y, vsb.h / 2);
|
|
8774
8752
|
const bounds = Box.From(cameraOptions.constraints.bounds);
|
|
8775
8753
|
const zx = (vsb.w - px * 2) / bounds.w;
|
|
8776
8754
|
const zy = (vsb.h - py * 2) / bounds.h;
|