@tldraw/editor 5.2.0-canary.4a316fdfb2bb → 5.2.0-canary.4e00299c3e28
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/README.md +7 -1
- package/dist-cjs/index.d.ts +39 -40
- package/dist-cjs/index.js +4 -4
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +92 -53
- package/dist-cjs/lib/editor/Editor.js.map +3 -3
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +3 -3
- package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +1 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +12 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +7 -3
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +15 -2
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +79 -0
- package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +7 -0
- package/dist-cjs/lib/hooks/usePresence.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 +39 -40
- package/dist-esm/index.mjs +5 -7
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +92 -53
- package/dist-esm/lib/editor/Editor.mjs.map +3 -3
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +3 -3
- package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +1 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +12 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +7 -3
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +15 -2
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +59 -0
- package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +7 -0
- package/dist-esm/lib/hooks/usePresence.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +2 -0
- package/package.json +8 -8
- package/src/index.ts +2 -5
- package/src/lib/editor/Editor.ts +124 -64
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +43 -16
- package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +8 -5
- package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +4 -4
- package/src/lib/editor/managers/FocusManager/FocusManager.ts +1 -2
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +13 -9
- package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +20 -2
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +9 -2
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +16 -14
- package/src/lib/editor/managers/TextManager/TextManager.ts +17 -2
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +12 -2
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +27 -2
- package/src/lib/editor/overlays/strokeShapeIndicators.ts +86 -0
- package/src/lib/hooks/usePresence.ts +2 -2
- package/src/version.ts +3 -3
- package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +0 -161
- package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +0 -7
- package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +0 -141
- package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +0 -7
- package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +0 -216
|
@@ -2185,7 +2185,7 @@ class Editor extends EventEmitter {
|
|
|
2185
2185
|
return baseCamera;
|
|
2186
2186
|
}
|
|
2187
2187
|
_getFollowingPresence(targetUserId) {
|
|
2188
|
-
const visited = [this.user.
|
|
2188
|
+
const visited = [this.user.getRecordId()];
|
|
2189
2189
|
const collaborators = this.getCollaborators();
|
|
2190
2190
|
let leaderPresence = null;
|
|
2191
2191
|
while (targetUserId && !visited.includes(targetUserId)) {
|
|
@@ -2373,6 +2373,11 @@ class Editor extends EventEmitter {
|
|
|
2373
2373
|
getConstrainedCamera(point, opts) {
|
|
2374
2374
|
const currentCamera = this.getCamera();
|
|
2375
2375
|
let { x, y, z = currentCamera.z } = point;
|
|
2376
|
+
const preserveFocalPoint = (current, requested, rz, z2) => {
|
|
2377
|
+
const cz = currentCamera.z;
|
|
2378
|
+
if (rz === cz) return current;
|
|
2379
|
+
return current + (requested - current) * (1 / z2 - 1 / cz) / (1 / rz - 1 / cz);
|
|
2380
|
+
};
|
|
2376
2381
|
if (!opts?.force) {
|
|
2377
2382
|
const cameraOptions = this.getCameraOptions();
|
|
2378
2383
|
const zoomMin = cameraOptions.zoomSteps[0];
|
|
@@ -2392,14 +2397,10 @@ class Editor extends EventEmitter {
|
|
|
2392
2397
|
z = this.getInitialZoom();
|
|
2393
2398
|
}
|
|
2394
2399
|
if (z < minZ || z > maxZ) {
|
|
2395
|
-
const
|
|
2396
|
-
const cxA = -cx + vsb.w / cz / 2;
|
|
2397
|
-
const cyA = -cy + vsb.h / cz / 2;
|
|
2400
|
+
const rz = z;
|
|
2398
2401
|
z = clamp(z, minZ, maxZ);
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
x = cx + cxB - cxA;
|
|
2402
|
-
y = cy + cyB - cyA;
|
|
2402
|
+
x = preserveFocalPoint(currentCamera.x, x, rz, z);
|
|
2403
|
+
y = preserveFocalPoint(currentCamera.y, y, rz, z);
|
|
2403
2404
|
}
|
|
2404
2405
|
const minX = px / z - bounds.x;
|
|
2405
2406
|
const minY = py / z - bounds.y;
|
|
@@ -2468,10 +2469,10 @@ class Editor extends EventEmitter {
|
|
|
2468
2469
|
}
|
|
2469
2470
|
} else {
|
|
2470
2471
|
if (z > zoomMax || z < zoomMin) {
|
|
2471
|
-
const
|
|
2472
|
+
const rz = z;
|
|
2472
2473
|
z = clamp(z, zoomMin, zoomMax);
|
|
2473
|
-
x =
|
|
2474
|
-
y =
|
|
2474
|
+
x = preserveFocalPoint(currentCamera.x, x, rz, z);
|
|
2475
|
+
y = preserveFocalPoint(currentCamera.y, y, rz, z);
|
|
2475
2476
|
}
|
|
2476
2477
|
}
|
|
2477
2478
|
}
|
|
@@ -2894,14 +2895,25 @@ class Editor extends EventEmitter {
|
|
|
2894
2895
|
this.off("stop-camera-animation", cancel);
|
|
2895
2896
|
};
|
|
2896
2897
|
this.once("stop-camera-animation", cancel);
|
|
2898
|
+
const dirZ = direction.z ?? 0;
|
|
2897
2899
|
const moveCamera = (elapsed) => {
|
|
2898
2900
|
const { x: cx, y: cy, z: cz } = this.getCamera();
|
|
2899
|
-
const
|
|
2901
|
+
const dx = direction.x * (currentSpeed * elapsed) / cz;
|
|
2902
|
+
const dy = direction.y * (currentSpeed * elapsed) / cz;
|
|
2903
|
+
let newCx = cx + dx;
|
|
2904
|
+
let newCy = cy + dy;
|
|
2905
|
+
let newCz = cz;
|
|
2906
|
+
if (dirZ !== 0) {
|
|
2907
|
+
newCz = cz * (1 + dirZ * currentSpeed * elapsed);
|
|
2908
|
+
const center = this.getViewportScreenCenter();
|
|
2909
|
+
newCx += center.x / newCz - center.x / cz;
|
|
2910
|
+
newCy += center.y / newCz - center.y / cz;
|
|
2911
|
+
}
|
|
2900
2912
|
currentSpeed *= 1 - friction;
|
|
2901
2913
|
if (currentSpeed < speedThreshold) {
|
|
2902
2914
|
cancel();
|
|
2903
2915
|
} else {
|
|
2904
|
-
this._setCamera(new Vec(
|
|
2916
|
+
this._setCamera(new Vec(newCx, newCy, newCz));
|
|
2905
2917
|
}
|
|
2906
2918
|
};
|
|
2907
2919
|
this.on("tick", moveCamera);
|
|
@@ -3221,7 +3233,7 @@ class Editor extends EventEmitter {
|
|
|
3221
3233
|
*/
|
|
3222
3234
|
startFollowingUser(userId) {
|
|
3223
3235
|
this.stopFollowingUser();
|
|
3224
|
-
const thisUserId = this.user.
|
|
3236
|
+
const thisUserId = this.user.getExternalId();
|
|
3225
3237
|
if (!thisUserId) {
|
|
3226
3238
|
console.warn("You should set the userId for the current instance before following a user");
|
|
3227
3239
|
}
|
|
@@ -5925,24 +5937,40 @@ class Editor extends EventEmitter {
|
|
|
5925
5937
|
* @public
|
|
5926
5938
|
*/
|
|
5927
5939
|
resizeShape(shape, scale, opts = {}) {
|
|
5940
|
+
const partial = this.getResizeShapePartial(shape, scale, opts);
|
|
5941
|
+
if (partial) this.updateShapes([partial]);
|
|
5942
|
+
return this;
|
|
5943
|
+
}
|
|
5944
|
+
/**
|
|
5945
|
+
* Get the update for a resized shape without committing it to the store. Interactions that
|
|
5946
|
+
* resize many shapes at once use this to collect all of the updates and commit them in a
|
|
5947
|
+
* single batch. Returns null when there is nothing to update.
|
|
5948
|
+
*
|
|
5949
|
+
* Shapes that are rotated out of alignment with the scale axis cannot be resized with a
|
|
5950
|
+
* single update; those shapes are resized immediately (as `resizeShape` would do) and null
|
|
5951
|
+
* is returned.
|
|
5952
|
+
*
|
|
5953
|
+
* @internal
|
|
5954
|
+
*/
|
|
5955
|
+
getResizeShapePartial(shape, scale, opts = {}) {
|
|
5928
5956
|
const id = typeof shape === "string" ? shape : shape.id;
|
|
5929
|
-
if (this.getIsReadonly()) return
|
|
5957
|
+
if (this.getIsReadonly()) return null;
|
|
5930
5958
|
if (!Number.isFinite(scale.x)) scale = new Vec(1, scale.y);
|
|
5931
5959
|
if (!Number.isFinite(scale.y)) scale = new Vec(scale.x, 1);
|
|
5932
5960
|
const initialShape = opts.initialShape ?? this.getShape(id);
|
|
5933
|
-
if (!initialShape) return
|
|
5961
|
+
if (!initialShape) return null;
|
|
5934
5962
|
const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center;
|
|
5935
|
-
if (!scaleOrigin) return
|
|
5963
|
+
if (!scaleOrigin) return null;
|
|
5936
5964
|
const pageTransform = opts.initialPageTransform ? Mat.Cast(opts.initialPageTransform) : this.getShapePageTransform(id);
|
|
5937
|
-
if (!pageTransform) return
|
|
5965
|
+
if (!pageTransform) return null;
|
|
5938
5966
|
const pageRotation = pageTransform.rotation();
|
|
5939
|
-
if (pageRotation == null) return
|
|
5967
|
+
if (pageRotation == null) return null;
|
|
5940
5968
|
const scaleAxisRotation = opts.scaleAxisRotation ?? pageRotation;
|
|
5941
5969
|
const initialBounds = opts.initialBounds ?? this.getShapeGeometry(id).bounds;
|
|
5942
|
-
if (!initialBounds) return
|
|
5970
|
+
if (!initialBounds) return null;
|
|
5943
5971
|
const isAspectRatioLocked = opts.isAspectRatioLocked ?? this.getShapeUtil(initialShape).isAspectRatioLocked(initialShape);
|
|
5944
5972
|
if (!areAnglesCompatible(pageRotation, scaleAxisRotation)) {
|
|
5945
|
-
|
|
5973
|
+
this._resizeUnalignedShape(id, scale, {
|
|
5946
5974
|
...opts,
|
|
5947
5975
|
initialBounds,
|
|
5948
5976
|
scaleOrigin,
|
|
@@ -5951,6 +5979,7 @@ class Editor extends EventEmitter {
|
|
|
5951
5979
|
isAspectRatioLocked,
|
|
5952
5980
|
initialShape
|
|
5953
5981
|
});
|
|
5982
|
+
return null;
|
|
5954
5983
|
}
|
|
5955
5984
|
const util = this.getShapeUtil(initialShape);
|
|
5956
5985
|
if (isAspectRatioLocked) {
|
|
@@ -5960,7 +5989,7 @@ class Editor extends EventEmitter {
|
|
|
5960
5989
|
scale = new Vec(Math.sign(scale.x) * Math.abs(scale.y), scale.y);
|
|
5961
5990
|
}
|
|
5962
5991
|
}
|
|
5963
|
-
let
|
|
5992
|
+
let workingShape = null;
|
|
5964
5993
|
if (util.onResize && util.canResize(initialShape)) {
|
|
5965
5994
|
const newPagePoint = this._scalePagePoint(
|
|
5966
5995
|
Mat.applyToPoint(pageTransform, new Vec(0, 0)),
|
|
@@ -5978,7 +6007,7 @@ class Editor extends EventEmitter {
|
|
|
5978
6007
|
myScale.y = areWidthAndHeightAlignedWithCorrectAxis ? scale.y : scale.x;
|
|
5979
6008
|
const initialPagePoint = Mat.applyToPoint(pageTransform, new Vec());
|
|
5980
6009
|
const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint);
|
|
5981
|
-
|
|
6010
|
+
workingShape = initialShape;
|
|
5982
6011
|
if (!opts.skipStartAndEndCallbacks) {
|
|
5983
6012
|
workingShape = applyPartialToRecordWithProps(
|
|
5984
6013
|
initialShape,
|
|
@@ -5998,9 +6027,6 @@ class Editor extends EventEmitter {
|
|
|
5998
6027
|
initialShape
|
|
5999
6028
|
}
|
|
6000
6029
|
);
|
|
6001
|
-
if (resizedShape) {
|
|
6002
|
-
didResize = true;
|
|
6003
|
-
}
|
|
6004
6030
|
workingShape = applyPartialToRecordWithProps(workingShape, {
|
|
6005
6031
|
id,
|
|
6006
6032
|
type: initialShape.type,
|
|
@@ -6014,32 +6040,36 @@ class Editor extends EventEmitter {
|
|
|
6014
6040
|
util.onResizeEnd?.(initialShape, workingShape) ?? void 0
|
|
6015
6041
|
);
|
|
6016
6042
|
}
|
|
6017
|
-
|
|
6043
|
+
if (resizedShape) {
|
|
6044
|
+
return workingShape;
|
|
6045
|
+
}
|
|
6018
6046
|
}
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
y: initialShape.y + delta.y
|
|
6039
|
-
}
|
|
6040
|
-
]);
|
|
6047
|
+
const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center);
|
|
6048
|
+
const newPageCenter = this._scalePagePoint(
|
|
6049
|
+
initialPageCenter,
|
|
6050
|
+
scaleOrigin,
|
|
6051
|
+
scale,
|
|
6052
|
+
scaleAxisRotation
|
|
6053
|
+
);
|
|
6054
|
+
const initialPageCenterInParentSpace = this.getPointInParentSpace(
|
|
6055
|
+
initialShape.id,
|
|
6056
|
+
initialPageCenter
|
|
6057
|
+
);
|
|
6058
|
+
const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter);
|
|
6059
|
+
const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace);
|
|
6060
|
+
if (workingShape) {
|
|
6061
|
+
return {
|
|
6062
|
+
...workingShape,
|
|
6063
|
+
x: initialShape.x + delta.x,
|
|
6064
|
+
y: initialShape.y + delta.y
|
|
6065
|
+
};
|
|
6041
6066
|
}
|
|
6042
|
-
return
|
|
6067
|
+
return {
|
|
6068
|
+
id,
|
|
6069
|
+
type: initialShape.type,
|
|
6070
|
+
x: initialShape.x + delta.x,
|
|
6071
|
+
y: initialShape.y + delta.y
|
|
6072
|
+
};
|
|
6043
6073
|
}
|
|
6044
6074
|
/** @internal */
|
|
6045
6075
|
_scalePagePoint(point, scaleOrigin, scale, scaleAxisRotation) {
|
|
@@ -8158,7 +8188,10 @@ class Editor extends EventEmitter {
|
|
|
8158
8188
|
inputs.buttons.add(info.button);
|
|
8159
8189
|
inputs.setIsPointing(true);
|
|
8160
8190
|
inputs.setIsDragging(false);
|
|
8161
|
-
if (!isPenMode && isPen)
|
|
8191
|
+
if (!isPenMode && isPen) {
|
|
8192
|
+
this.updateInstanceState({ isPenMode: true });
|
|
8193
|
+
this.interrupt();
|
|
8194
|
+
}
|
|
8162
8195
|
if (info.button === STYLUS_ERASER_BUTTON) {
|
|
8163
8196
|
this._restoreToolId = this.getCurrentToolId();
|
|
8164
8197
|
this.complete();
|
|
@@ -8261,7 +8294,10 @@ class Editor extends EventEmitter {
|
|
|
8261
8294
|
this.setCursor({ type: this._prevCursor, rotation: 0 });
|
|
8262
8295
|
}
|
|
8263
8296
|
if (slideSpeed > 0) {
|
|
8264
|
-
this.slideCamera({
|
|
8297
|
+
this.slideCamera({
|
|
8298
|
+
speed: slideSpeed,
|
|
8299
|
+
direction: { x: slideDirection.x, y: slideDirection.y, z: 0 }
|
|
8300
|
+
});
|
|
8265
8301
|
}
|
|
8266
8302
|
this._selectedShapeIdsAtPointerDown = [];
|
|
8267
8303
|
this._didCaptureSelectionAtPointerDown = false;
|
|
@@ -8269,7 +8305,10 @@ class Editor extends EventEmitter {
|
|
|
8269
8305
|
}
|
|
8270
8306
|
}
|
|
8271
8307
|
if (slideSpeed > 0) {
|
|
8272
|
-
this.slideCamera({
|
|
8308
|
+
this.slideCamera({
|
|
8309
|
+
speed: slideSpeed,
|
|
8310
|
+
direction: { x: slideDirection.x, y: slideDirection.y, z: 0 }
|
|
8311
|
+
});
|
|
8273
8312
|
}
|
|
8274
8313
|
} else {
|
|
8275
8314
|
if (info.button === STYLUS_ERASER_BUTTON) {
|