@tldraw/editor 5.5.2 → 5.6.0-canary.0091c91994d6
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 +167 -2
- package/dist-cjs/index.js +7 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js +18 -5
- package/dist-cjs/lib/TldrawEditor.js.map +3 -3
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js +57 -15
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/config/TLI18n.js +64 -0
- package/dist-cjs/lib/config/TLI18n.js.map +7 -0
- package/dist-cjs/lib/editor/Editor.js +44 -16
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js +10 -3
- package/dist-cjs/lib/editor/derivations/shapeIdsInCurrentPage.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js +19 -2
- package/dist-cjs/lib/editor/managers/FontManager/FontManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +3 -5
- package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +7 -1
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js +28 -0
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js +3 -0
- package/dist-cjs/lib/editor/shapes/group/GroupShapeUtil.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/shared/resizeBox.js +21 -16
- package/dist-cjs/lib/editor/shapes/shared/resizeBox.js.map +2 -2
- package/dist-cjs/lib/hooks/useCursor.js +12 -8
- package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
- package/dist-cjs/lib/hooks/useDocumentEvents.js +28 -3
- package/dist-cjs/lib/hooks/useDocumentEvents.js.map +2 -2
- package/dist-cjs/lib/license/LicenseManager.js +64 -1
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- package/dist-cjs/lib/options.js +1 -1
- package/dist-cjs/lib/options.js.map +1 -1
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +12 -5
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.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 +167 -2
- package/dist-esm/index.mjs +13 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs +18 -5
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs +61 -16
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/config/TLI18n.mjs +44 -0
- package/dist-esm/lib/config/TLI18n.mjs.map +7 -0
- package/dist-esm/lib/editor/Editor.mjs +46 -17
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs +10 -3
- package/dist-esm/lib/editor/derivations/shapeIdsInCurrentPage.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs +20 -3
- package/dist-esm/lib/editor/managers/FontManager/FontManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +3 -5
- package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +7 -1
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs +28 -0
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs +3 -0
- package/dist-esm/lib/editor/shapes/group/GroupShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs +21 -16
- package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs.map +2 -2
- package/dist-esm/lib/hooks/useCursor.mjs +12 -8
- package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
- package/dist-esm/lib/hooks/useDocumentEvents.mjs +28 -3
- package/dist-esm/lib/hooks/useDocumentEvents.mjs.map +2 -2
- package/dist-esm/lib/license/LicenseManager.mjs +64 -1
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +1 -1
- package/dist-esm/lib/options.mjs.map +1 -1
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +13 -6
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/editor.css +1 -1
- package/package.json +17 -19
- package/src/index.ts +14 -2
- package/src/lib/TldrawEditor.tsx +44 -4
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +66 -18
- package/src/lib/config/TLI18n.test.ts +84 -0
- package/src/lib/config/TLI18n.ts +172 -0
- package/src/lib/editor/Editor.ts +90 -33
- package/src/lib/editor/derivations/shapeIdsInCurrentPage.ts +19 -3
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.test.ts +17 -0
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +2 -2
- package/src/lib/editor/managers/FontManager/FontManager.test.ts +1 -0
- package/src/lib/editor/managers/FontManager/FontManager.ts +26 -3
- package/src/lib/editor/managers/HistoryManager/HistoryManager.test.ts +32 -0
- package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +4 -6
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +16 -7
- package/src/lib/editor/shapes/ShapeUtil.ts +30 -0
- package/src/lib/editor/shapes/group/GroupShapeUtil.tsx +4 -0
- package/src/lib/editor/shapes/shared/resizeBox.ts +21 -16
- package/src/lib/hooks/useCursor.ts +14 -7
- package/src/lib/hooks/useDocumentEvents.ts +51 -3
- package/src/lib/license/LicenseManager.test.ts +220 -0
- package/src/lib/license/LicenseManager.ts +89 -1
- package/src/lib/options.ts +1 -1
- package/src/lib/test/useCursor.test.tsx +36 -0
- package/src/lib/test/useDocumentEvents.test.tsx +153 -22
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +73 -0
- package/src/lib/utils/sync/TLLocalSyncClient.ts +24 -8
- package/src/version.ts +3 -3
|
@@ -72,6 +72,7 @@ import {
|
|
|
72
72
|
getSnapshot,
|
|
73
73
|
loadSnapshot
|
|
74
74
|
} from "../config/TLEditorSnapshot.mjs";
|
|
75
|
+
import { defaultI18n } from "../config/TLI18n.mjs";
|
|
75
76
|
import {
|
|
76
77
|
DEFAULT_ANIMATION_OPTIONS,
|
|
77
78
|
DEFAULT_CAMERA_OPTIONS,
|
|
@@ -99,7 +100,8 @@ import {
|
|
|
99
100
|
approximately,
|
|
100
101
|
areAnglesCompatible,
|
|
101
102
|
clamp,
|
|
102
|
-
pointInPolygon
|
|
103
|
+
pointInPolygon,
|
|
104
|
+
shortAngleDist
|
|
103
105
|
} from "../primitives/utils.mjs";
|
|
104
106
|
import { Vec } from "../primitives/Vec.mjs";
|
|
105
107
|
import { areShapesContentEqual } from "../utils/areShapesContentEqual.mjs";
|
|
@@ -164,9 +166,11 @@ class Editor extends EventEmitter {
|
|
|
164
166
|
colorScheme,
|
|
165
167
|
fontAssetUrls,
|
|
166
168
|
themes,
|
|
167
|
-
initialTheme
|
|
169
|
+
initialTheme,
|
|
170
|
+
i18n
|
|
168
171
|
}) {
|
|
169
172
|
super();
|
|
173
|
+
this.i18n = i18n ?? defaultI18n;
|
|
170
174
|
this._getShapeVisibility = getShapeVisibility;
|
|
171
175
|
const options = _textOptions ? { ..._options, text: _options?.text ?? _textOptions } : _options;
|
|
172
176
|
this.options = { ...defaultTldrawOptions, ...options };
|
|
@@ -678,6 +682,12 @@ class Editor extends EventEmitter {
|
|
|
678
682
|
*/
|
|
679
683
|
licenseManager;
|
|
680
684
|
contextId = uniqueId();
|
|
685
|
+
/**
|
|
686
|
+
* The i18n adapter for translating strings.
|
|
687
|
+
*
|
|
688
|
+
* @public
|
|
689
|
+
*/
|
|
690
|
+
i18n;
|
|
681
691
|
/**
|
|
682
692
|
* The editor's store
|
|
683
693
|
*
|
|
@@ -1657,7 +1667,7 @@ class Editor extends EventEmitter {
|
|
|
1657
1667
|
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1658
1668
|
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !isPageId(firstParentId);
|
|
1659
1669
|
const filteredShapes = this.getCurrentPageShapes().filter(
|
|
1660
|
-
(shape2) =>
|
|
1670
|
+
(shape2) => isSelectedWithinContainer ? shape2.parentId === firstParentId : isPageId(shape2.parentId)
|
|
1661
1671
|
);
|
|
1662
1672
|
const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
|
|
1663
1673
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
@@ -1800,6 +1810,11 @@ class Editor extends EventEmitter {
|
|
|
1800
1810
|
this._selectShapesAndZoom([sortedChildren[0].id]);
|
|
1801
1811
|
}
|
|
1802
1812
|
_selectShapesAndZoom(ids) {
|
|
1813
|
+
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1814
|
+
const isSelectionChanging = ids.length !== selectedShapeIds.length || ids.some((id) => !selectedShapeIds.includes(id));
|
|
1815
|
+
if (isSelectionChanging) {
|
|
1816
|
+
this.markHistoryStoppingPoint("selecting adjacent shape");
|
|
1817
|
+
}
|
|
1803
1818
|
this.setSelectedShapes(ids);
|
|
1804
1819
|
this.zoomToSelectionIfOffscreen(256, {
|
|
1805
1820
|
animation: {
|
|
@@ -3698,7 +3713,9 @@ class Editor extends EventEmitter {
|
|
|
3698
3713
|
const id = typeof page === "string" ? page : page.id;
|
|
3699
3714
|
const freshPage = this.getPage(id);
|
|
3700
3715
|
if (!freshPage) return this;
|
|
3701
|
-
const prevCamera = {
|
|
3716
|
+
const prevCamera = {
|
|
3717
|
+
...(this.store.get(CameraRecordType.createId(freshPage.id)) ?? this.getCamera())
|
|
3718
|
+
};
|
|
3702
3719
|
const content = this.getContentFromCurrentPage(this.getSortedChildIdsForParent(freshPage.id));
|
|
3703
3720
|
this.run(() => {
|
|
3704
3721
|
const pages = this.getPages();
|
|
@@ -3707,7 +3724,7 @@ class Editor extends EventEmitter {
|
|
|
3707
3724
|
this.setCurrentPage(createId);
|
|
3708
3725
|
this.setCamera(prevCamera);
|
|
3709
3726
|
if (content) {
|
|
3710
|
-
return this.putContentOntoCurrentPage(content);
|
|
3727
|
+
return this.putContentOntoCurrentPage(content, { preservePosition: true });
|
|
3711
3728
|
}
|
|
3712
3729
|
});
|
|
3713
3730
|
return this;
|
|
@@ -5967,9 +5984,10 @@ class Editor extends EventEmitter {
|
|
|
5967
5984
|
}
|
|
5968
5985
|
}
|
|
5969
5986
|
let workingShape = null;
|
|
5987
|
+
const initialPagePoint = Mat.applyToPoint(pageTransform, new Vec());
|
|
5970
5988
|
if (util.onResize && util.canResize(initialShape)) {
|
|
5971
5989
|
const newPagePoint = this._scalePagePoint(
|
|
5972
|
-
|
|
5990
|
+
initialPagePoint,
|
|
5973
5991
|
scaleOrigin,
|
|
5974
5992
|
scale,
|
|
5975
5993
|
scaleAxisRotation
|
|
@@ -5982,7 +6000,6 @@ class Editor extends EventEmitter {
|
|
|
5982
6000
|
);
|
|
5983
6001
|
myScale.x = areWidthAndHeightAlignedWithCorrectAxis ? scale.x : scale.y;
|
|
5984
6002
|
myScale.y = areWidthAndHeightAlignedWithCorrectAxis ? scale.y : scale.x;
|
|
5985
|
-
const initialPagePoint = Mat.applyToPoint(pageTransform, new Vec());
|
|
5986
6003
|
const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint);
|
|
5987
6004
|
workingShape = initialShape;
|
|
5988
6005
|
if (!opts.skipStartAndEndCallbacks) {
|
|
@@ -6028,24 +6045,26 @@ class Editor extends EventEmitter {
|
|
|
6028
6045
|
scale,
|
|
6029
6046
|
scaleAxisRotation
|
|
6030
6047
|
);
|
|
6031
|
-
const
|
|
6048
|
+
const repositionedPagePoint = Vec.Add(
|
|
6049
|
+
newPageCenter,
|
|
6050
|
+
Vec.Sub(initialPagePoint, initialPageCenter)
|
|
6051
|
+
);
|
|
6052
|
+
const repositionedLocalPoint = this.getPointInParentSpace(
|
|
6032
6053
|
initialShape.id,
|
|
6033
|
-
|
|
6054
|
+
repositionedPagePoint
|
|
6034
6055
|
);
|
|
6035
|
-
const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter);
|
|
6036
|
-
const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace);
|
|
6037
6056
|
if (workingShape) {
|
|
6038
6057
|
return {
|
|
6039
6058
|
...workingShape,
|
|
6040
|
-
x:
|
|
6041
|
-
y:
|
|
6059
|
+
x: repositionedLocalPoint.x,
|
|
6060
|
+
y: repositionedLocalPoint.y
|
|
6042
6061
|
};
|
|
6043
6062
|
}
|
|
6044
6063
|
return {
|
|
6045
6064
|
id,
|
|
6046
6065
|
type: initialShape.type,
|
|
6047
|
-
x:
|
|
6048
|
-
y:
|
|
6066
|
+
x: repositionedLocalPoint.x,
|
|
6067
|
+
y: repositionedLocalPoint.y
|
|
6049
6068
|
};
|
|
6050
6069
|
}
|
|
6051
6070
|
/** @internal */
|
|
@@ -6071,11 +6090,20 @@ class Editor extends EventEmitter {
|
|
|
6071
6090
|
initialShape: options.initialShape,
|
|
6072
6091
|
initialBounds: options.initialBounds,
|
|
6073
6092
|
isAspectRatioLocked: options.isAspectRatioLocked,
|
|
6074
|
-
initialPageTransform: options.initialPageTransform
|
|
6093
|
+
initialPageTransform: options.initialPageTransform,
|
|
6094
|
+
dragHandle: options.dragHandle,
|
|
6095
|
+
mode: options.mode,
|
|
6096
|
+
// this is one frame of the same resize, not a new one, so don't fire start/end again
|
|
6097
|
+
skipStartAndEndCallbacks: options.skipStartAndEndCallbacks
|
|
6075
6098
|
});
|
|
6076
6099
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
6077
6100
|
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
6078
|
-
const
|
|
6101
|
+
const parentDelta = shortAngleDist(
|
|
6102
|
+
Mat.Cast(options.initialPageTransform).rotation() - options.initialShape.rotation,
|
|
6103
|
+
parentRotation
|
|
6104
|
+
);
|
|
6105
|
+
const initialParentRotation = parentRotation - parentDelta;
|
|
6106
|
+
const rotation = 2 * options.scaleAxisRotation - options.initialShape.rotation - 2 * initialParentRotation - parentDelta;
|
|
6079
6107
|
this.updateShapes([{ id, type, rotation }]);
|
|
6080
6108
|
}
|
|
6081
6109
|
const preScaleShapePageCenter = Mat.applyToPoint(
|
|
@@ -8384,6 +8412,7 @@ class Editor extends EventEmitter {
|
|
|
8384
8412
|
break;
|
|
8385
8413
|
}
|
|
8386
8414
|
case "key_repeat": {
|
|
8415
|
+
inputs.keys.add(info.code);
|
|
8387
8416
|
break;
|
|
8388
8417
|
}
|
|
8389
8418
|
}
|