@tldraw/editor 4.4.0-next.f181afb0ab39 → 4.4.0-next.f2df7e20ec7b
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 +102 -19
- package/dist-cjs/index.js +1 -6
- package/dist-cjs/index.js.map +3 -3
- package/dist-cjs/lib/TldrawEditor.js +20 -8
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/Shape.js +12 -17
- package/dist-cjs/lib/components/Shape.js.map +2 -2
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js +26 -1
- package/dist-cjs/lib/components/default-components/CanvasShapeIndicators.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +16 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/config/createTLStore.js.map +1 -1
- package/dist-cjs/lib/editor/Editor.js +35 -17
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js +32 -13
- package/dist-cjs/lib/editor/derivations/notVisibleShapes.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +2 -3
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +13 -38
- package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +3 -3
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/tools/RootState.js +0 -13
- package/dist-cjs/lib/editor/tools/RootState.js.map +2 -2
- package/dist-cjs/lib/hooks/usePeerIds.js +8 -2
- package/dist-cjs/lib/hooks/usePeerIds.js.map +2 -2
- package/dist-cjs/lib/hooks/useShapeCulling.js +75 -0
- package/dist-cjs/lib/hooks/useShapeCulling.js.map +7 -0
- package/dist-cjs/lib/license/LicenseManager.js +6 -6
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/options.js +6 -1
- package/dist-cjs/lib/options.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 +102 -19
- package/dist-esm/index.mjs +1 -6
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +20 -8
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/Shape.mjs +12 -17
- package/dist-esm/lib/components/Shape.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs +27 -2
- package/dist-esm/lib/components/default-components/CanvasShapeIndicators.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +16 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/config/createTLStore.mjs.map +1 -1
- package/dist-esm/lib/editor/Editor.mjs +35 -17
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs +32 -13
- package/dist-esm/lib/editor/derivations/notVisibleShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +2 -3
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +14 -39
- package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/tools/RootState.mjs +0 -13
- package/dist-esm/lib/editor/tools/RootState.mjs.map +2 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs +8 -2
- package/dist-esm/lib/hooks/usePeerIds.mjs.map +2 -2
- package/dist-esm/lib/hooks/useShapeCulling.mjs +55 -0
- package/dist-esm/lib/hooks/useShapeCulling.mjs.map +7 -0
- package/dist-esm/lib/license/LicenseManager.mjs +6 -6
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +6 -1
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +22 -11
- package/package.json +8 -11
- package/src/index.ts +0 -5
- package/src/lib/TldrawEditor.tsx +35 -13
- package/src/lib/components/Shape.tsx +15 -16
- package/src/lib/components/default-components/CanvasShapeIndicators.tsx +46 -2
- package/src/lib/components/default-components/DefaultCanvas.tsx +24 -2
- package/src/lib/config/createTLStore.ts +1 -1
- package/src/lib/editor/Editor.ts +62 -19
- package/src/lib/editor/derivations/notVisibleShapes.ts +39 -17
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +0 -35
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +4 -8
- package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +19 -47
- package/src/lib/editor/shapes/ShapeUtil.ts +19 -5
- package/src/lib/editor/tools/RootState.ts +0 -16
- package/src/lib/hooks/usePeerIds.ts +9 -2
- package/src/lib/hooks/useShapeCulling.tsx +98 -0
- package/src/lib/license/LicenseManager.ts +6 -6
- package/src/lib/options.ts +41 -2
- package/src/version.ts +3 -3
|
@@ -132,12 +132,16 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
132
132
|
bindingUtils,
|
|
133
133
|
tools,
|
|
134
134
|
getContainer,
|
|
135
|
+
// needs to be here for backwards compatibility with TldrawEditor
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
135
137
|
cameraOptions,
|
|
136
|
-
textOptions,
|
|
137
138
|
initialState,
|
|
138
139
|
autoFocus,
|
|
139
140
|
inferDarkMode,
|
|
140
|
-
options,
|
|
141
|
+
options: _options,
|
|
142
|
+
// needs to be here for backwards compatibility with TldrawEditor
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
144
|
+
textOptions: _textOptions,
|
|
141
145
|
getShapeVisibility,
|
|
142
146
|
fontAssetUrls
|
|
143
147
|
}) {
|
|
@@ -298,7 +302,6 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
298
302
|
// unmount / remount in the DOM, which is expensive; and computing visibility is
|
|
299
303
|
// also expensive in large projects. For this reason, we use a second bounding
|
|
300
304
|
// box just for rendering, and we only update after the camera stops moving.
|
|
301
|
-
__publicField(this, "_cameraState", (0, import_state.atom)("camera state", "idle"));
|
|
302
305
|
__publicField(this, "_cameraStateTimeoutRemaining", 0);
|
|
303
306
|
/* @internal */
|
|
304
307
|
__publicField(this, "_currentPageShapeIds");
|
|
@@ -371,6 +374,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
371
374
|
__publicField(this, "handledEvents", /* @__PURE__ */ new WeakSet());
|
|
372
375
|
__publicField(this, "_pendingEventsForNextTick", []);
|
|
373
376
|
this._getShapeVisibility = getShapeVisibility;
|
|
377
|
+
const options = _textOptions ? { ..._options, text: _options?.text ?? _textOptions } : _options;
|
|
374
378
|
this.options = { ...import_options.defaultTldrawOptions, ...options };
|
|
375
379
|
this.store = store;
|
|
376
380
|
this.history = new import_HistoryManager.HistoryManager({
|
|
@@ -384,8 +388,12 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
384
388
|
this._spatialIndex = new import_SpatialIndexManager.SpatialIndexManager(this);
|
|
385
389
|
this.disposables.add(() => this._spatialIndex.dispose());
|
|
386
390
|
this.disposables.add(this.timers.dispose);
|
|
387
|
-
this._cameraOptions.set({
|
|
388
|
-
|
|
391
|
+
this._cameraOptions.set({
|
|
392
|
+
...import_constants.DEFAULT_CAMERA_OPTIONS,
|
|
393
|
+
...cameraOptions,
|
|
394
|
+
...options?.camera
|
|
395
|
+
});
|
|
396
|
+
this._textOptions = (0, import_state.atom)("text options", options?.text ?? null);
|
|
389
397
|
this.user = new import_UserPreferencesManager.UserPreferencesManager(user ?? (0, import_createTLUser.createTLUser)(), inferDarkMode ?? false);
|
|
390
398
|
this.disposables.add(() => this.user.dispose());
|
|
391
399
|
this.getContainer = getContainer;
|
|
@@ -2389,7 +2397,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
2389
2397
|
* @public
|
|
2390
2398
|
*/
|
|
2391
2399
|
zoomToFit(opts) {
|
|
2392
|
-
const ids = [...this.getCurrentPageShapeIds()];
|
|
2400
|
+
const ids = [...this.getCurrentPageShapeIds()].filter((id) => !this.isShapeHidden(id));
|
|
2393
2401
|
if (ids.length <= 0) return this;
|
|
2394
2402
|
const pageBounds = import_Box.Box.Common((0, import_utils.compact)(ids.map((id) => this.getShapePageBounds(id))));
|
|
2395
2403
|
this.zoomToBounds(pageBounds, opts);
|
|
@@ -3088,15 +3096,18 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3088
3096
|
this._cameraStateTimeoutRemaining -= elapsed;
|
|
3089
3097
|
if (this._cameraStateTimeoutRemaining > 0) return;
|
|
3090
3098
|
this.off("tick", this._decayCameraStateTimeout);
|
|
3091
|
-
this.
|
|
3099
|
+
this._setCameraState("idle");
|
|
3092
3100
|
}
|
|
3093
3101
|
_tickCameraState() {
|
|
3094
3102
|
this._cameraStateTimeoutRemaining = this.options.cameraMovingTimeoutMs;
|
|
3095
|
-
if (this.
|
|
3096
|
-
this.
|
|
3103
|
+
if (this.getInstanceState().cameraState !== "idle") return;
|
|
3104
|
+
this._setCameraState("moving");
|
|
3097
3105
|
this._debouncedZoomLevel.set((0, import_state.unsafe__withoutCapture)(() => this.getCamera().z));
|
|
3098
3106
|
this.on("tick", this._decayCameraStateTimeout);
|
|
3099
3107
|
}
|
|
3108
|
+
_setCameraState(cameraState) {
|
|
3109
|
+
this.updateInstanceState({ cameraState }, { history: "ignore" });
|
|
3110
|
+
}
|
|
3100
3111
|
/**
|
|
3101
3112
|
* Whether the camera is moving or idle.
|
|
3102
3113
|
*
|
|
@@ -3108,7 +3119,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3108
3119
|
* @public
|
|
3109
3120
|
*/
|
|
3110
3121
|
getCameraState() {
|
|
3111
|
-
return this.
|
|
3122
|
+
return this.getInstanceState().cameraState;
|
|
3112
3123
|
}
|
|
3113
3124
|
getRenderingShapes() {
|
|
3114
3125
|
const renderingShapes = this.getUnorderedRenderingShapes(true);
|
|
@@ -3874,6 +3885,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
3874
3885
|
getCurrentPageBounds() {
|
|
3875
3886
|
let commonBounds;
|
|
3876
3887
|
this.getCurrentPageShapeIdsSorted().forEach((shapeId) => {
|
|
3888
|
+
if (this.isShapeHidden(shapeId)) return;
|
|
3877
3889
|
const bounds = this.getShapeMaskedPageBounds(shapeId);
|
|
3878
3890
|
if (!bounds) return;
|
|
3879
3891
|
if (!commonBounds) {
|
|
@@ -4052,7 +4064,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
4052
4064
|
* @param bounds - The bounds to search within.
|
|
4053
4065
|
* @returns Unordered set of shape IDs within the given bounds.
|
|
4054
4066
|
*
|
|
4055
|
-
* @
|
|
4067
|
+
* @public
|
|
4056
4068
|
*/
|
|
4057
4069
|
getShapeIdsInsideBounds(bounds) {
|
|
4058
4070
|
return this._spatialIndex.getShapeIdsInsideBounds(bounds);
|
|
@@ -4595,7 +4607,13 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
4595
4607
|
const fromShapeType = typeof fromShape === "string" ? fromShape : fromShape.type;
|
|
4596
4608
|
const toShapeType = typeof toShape === "string" ? toShape : toShape.type;
|
|
4597
4609
|
const bindingType = typeof binding === "string" ? binding : binding.type;
|
|
4598
|
-
const canBindOpts = {
|
|
4610
|
+
const canBindOpts = {
|
|
4611
|
+
fromShape: typeof fromShape === "string" ? { type: fromShape } : fromShape,
|
|
4612
|
+
toShape: typeof toShape === "string" ? { type: toShape } : toShape,
|
|
4613
|
+
bindingType,
|
|
4614
|
+
fromShapeType,
|
|
4615
|
+
toShapeType
|
|
4616
|
+
};
|
|
4599
4617
|
if (fromShapeType === toShapeType) {
|
|
4600
4618
|
return this.getShapeUtil(fromShapeType).canBind(canBindOpts);
|
|
4601
4619
|
}
|
|
@@ -5735,7 +5753,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
5735
5753
|
this.resizeShape(id, shapeScale, {
|
|
5736
5754
|
initialShape: options.initialShape,
|
|
5737
5755
|
initialBounds: options.initialBounds,
|
|
5738
|
-
isAspectRatioLocked: options.isAspectRatioLocked
|
|
5756
|
+
isAspectRatioLocked: options.isAspectRatioLocked,
|
|
5757
|
+
initialPageTransform: options.initialPageTransform
|
|
5739
5758
|
});
|
|
5740
5759
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
5741
5760
|
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
@@ -7215,7 +7234,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7215
7234
|
/**
|
|
7216
7235
|
* Handles navigating to the content specified by the query param in the given URL.
|
|
7217
7236
|
*
|
|
7218
|
-
* Use {@link Editor
|
|
7237
|
+
* Use {@link Editor.createDeepLink} to create a URL with a deep link query param.
|
|
7219
7238
|
*
|
|
7220
7239
|
* If no URL is provided, it will look for the param in the current `window.location.href`.
|
|
7221
7240
|
*
|
|
@@ -7566,9 +7585,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7566
7585
|
case "pinch_start": {
|
|
7567
7586
|
if (inputs.getIsPinching()) return;
|
|
7568
7587
|
if (!inputs.getIsEditing()) {
|
|
7569
|
-
|
|
7570
|
-
this._selectedShapeIdsAtPointerDown = [...pageState.selectedShapeIds];
|
|
7571
|
-
}
|
|
7588
|
+
this._selectedShapeIdsAtPointerDown = [...pageState.selectedShapeIds];
|
|
7572
7589
|
this._didPinch = true;
|
|
7573
7590
|
inputs.setIsPinching(true);
|
|
7574
7591
|
this.interrupt();
|
|
@@ -7783,6 +7800,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
|
|
|
7783
7800
|
this.setCurrentTool(this._restoreToolId);
|
|
7784
7801
|
}
|
|
7785
7802
|
}
|
|
7803
|
+
this._selectedShapeIdsAtPointerDown = [];
|
|
7786
7804
|
break;
|
|
7787
7805
|
}
|
|
7788
7806
|
}
|