@tldraw/editor 5.5.4 → 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 +166 -1
- 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 +59 -0
- package/dist-cjs/lib/license/LicenseManager.js.map +2 -2
- 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 +166 -1
- 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 +59 -0
- package/dist-esm/lib/license/LicenseManager.mjs.map +2 -2
- 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/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 +156 -0
- package/src/lib/license/LicenseManager.ts +83 -0
- 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
|
@@ -49,6 +49,7 @@ var import_defaultAssets = require("../config/defaultAssets");
|
|
|
49
49
|
var import_defaultBindings = require("../config/defaultBindings");
|
|
50
50
|
var import_defaultShapes = require("../config/defaultShapes");
|
|
51
51
|
var import_TLEditorSnapshot = require("../config/TLEditorSnapshot");
|
|
52
|
+
var import_TLI18n = require("../config/TLI18n");
|
|
52
53
|
var import_constants = require("../constants");
|
|
53
54
|
var import_domUtils = require("../exports/domUtils");
|
|
54
55
|
var import_exportToSvg = require("../exports/exportToSvg");
|
|
@@ -123,9 +124,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
123
124
|
colorScheme,
|
|
124
125
|
fontAssetUrls,
|
|
125
126
|
themes,
|
|
126
|
-
initialTheme
|
|
127
|
+
initialTheme,
|
|
128
|
+
i18n
|
|
127
129
|
}) {
|
|
128
130
|
super();
|
|
131
|
+
this.i18n = i18n ?? import_TLI18n.defaultI18n;
|
|
129
132
|
this._getShapeVisibility = getShapeVisibility;
|
|
130
133
|
const options = _textOptions ? { ..._options, text: _options?.text ?? _textOptions } : _options;
|
|
131
134
|
this.options = { ...import_options.defaultTldrawOptions, ...options };
|
|
@@ -637,6 +640,12 @@ class Editor extends import_eventemitter3.default {
|
|
|
637
640
|
*/
|
|
638
641
|
licenseManager;
|
|
639
642
|
contextId = (0, import_utils.uniqueId)();
|
|
643
|
+
/**
|
|
644
|
+
* The i18n adapter for translating strings.
|
|
645
|
+
*
|
|
646
|
+
* @public
|
|
647
|
+
*/
|
|
648
|
+
i18n;
|
|
640
649
|
/**
|
|
641
650
|
* The editor's store
|
|
642
651
|
*
|
|
@@ -1616,7 +1625,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
1616
1625
|
const firstParentId = selectedShapeIds[0] ? this.getShape(selectedShapeIds[0])?.parentId : null;
|
|
1617
1626
|
const isSelectedWithinContainer = firstParentId && selectedShapeIds.every((shapeId) => this.getShape(shapeId)?.parentId === firstParentId) && !(0, import_tlschema.isPageId)(firstParentId);
|
|
1618
1627
|
const filteredShapes = this.getCurrentPageShapes().filter(
|
|
1619
|
-
(shape2) =>
|
|
1628
|
+
(shape2) => isSelectedWithinContainer ? shape2.parentId === firstParentId : (0, import_tlschema.isPageId)(shape2.parentId)
|
|
1620
1629
|
);
|
|
1621
1630
|
const readingOrderShapes = this._getShapesInReadingOrder(filteredShapes);
|
|
1622
1631
|
const currentShapeId = selectedShapeIds.length === 1 ? selectedShapeIds[0] : readingOrderShapes.find((shape2) => selectedShapeIds.includes(shape2.id))?.id;
|
|
@@ -1759,6 +1768,11 @@ class Editor extends import_eventemitter3.default {
|
|
|
1759
1768
|
this._selectShapesAndZoom([sortedChildren[0].id]);
|
|
1760
1769
|
}
|
|
1761
1770
|
_selectShapesAndZoom(ids) {
|
|
1771
|
+
const selectedShapeIds = this.getSelectedShapeIds();
|
|
1772
|
+
const isSelectionChanging = ids.length !== selectedShapeIds.length || ids.some((id) => !selectedShapeIds.includes(id));
|
|
1773
|
+
if (isSelectionChanging) {
|
|
1774
|
+
this.markHistoryStoppingPoint("selecting adjacent shape");
|
|
1775
|
+
}
|
|
1762
1776
|
this.setSelectedShapes(ids);
|
|
1763
1777
|
this.zoomToSelectionIfOffscreen(256, {
|
|
1764
1778
|
animation: {
|
|
@@ -3657,7 +3671,9 @@ class Editor extends import_eventemitter3.default {
|
|
|
3657
3671
|
const id = typeof page === "string" ? page : page.id;
|
|
3658
3672
|
const freshPage = this.getPage(id);
|
|
3659
3673
|
if (!freshPage) return this;
|
|
3660
|
-
const prevCamera = {
|
|
3674
|
+
const prevCamera = {
|
|
3675
|
+
...this.store.get(import_tlschema.CameraRecordType.createId(freshPage.id)) ?? this.getCamera()
|
|
3676
|
+
};
|
|
3661
3677
|
const content = this.getContentFromCurrentPage(this.getSortedChildIdsForParent(freshPage.id));
|
|
3662
3678
|
this.run(() => {
|
|
3663
3679
|
const pages = this.getPages();
|
|
@@ -3666,7 +3682,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
3666
3682
|
this.setCurrentPage(createId);
|
|
3667
3683
|
this.setCamera(prevCamera);
|
|
3668
3684
|
if (content) {
|
|
3669
|
-
return this.putContentOntoCurrentPage(content);
|
|
3685
|
+
return this.putContentOntoCurrentPage(content, { preservePosition: true });
|
|
3670
3686
|
}
|
|
3671
3687
|
});
|
|
3672
3688
|
return this;
|
|
@@ -5926,9 +5942,10 @@ class Editor extends import_eventemitter3.default {
|
|
|
5926
5942
|
}
|
|
5927
5943
|
}
|
|
5928
5944
|
let workingShape = null;
|
|
5945
|
+
const initialPagePoint = import_Mat.Mat.applyToPoint(pageTransform, new import_Vec.Vec());
|
|
5929
5946
|
if (util.onResize && util.canResize(initialShape)) {
|
|
5930
5947
|
const newPagePoint = this._scalePagePoint(
|
|
5931
|
-
|
|
5948
|
+
initialPagePoint,
|
|
5932
5949
|
scaleOrigin,
|
|
5933
5950
|
scale,
|
|
5934
5951
|
scaleAxisRotation
|
|
@@ -5941,7 +5958,6 @@ class Editor extends import_eventemitter3.default {
|
|
|
5941
5958
|
);
|
|
5942
5959
|
myScale.x = areWidthAndHeightAlignedWithCorrectAxis ? scale.x : scale.y;
|
|
5943
5960
|
myScale.y = areWidthAndHeightAlignedWithCorrectAxis ? scale.y : scale.x;
|
|
5944
|
-
const initialPagePoint = import_Mat.Mat.applyToPoint(pageTransform, new import_Vec.Vec());
|
|
5945
5961
|
const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint);
|
|
5946
5962
|
workingShape = initialShape;
|
|
5947
5963
|
if (!opts.skipStartAndEndCallbacks) {
|
|
@@ -5987,24 +6003,26 @@ class Editor extends import_eventemitter3.default {
|
|
|
5987
6003
|
scale,
|
|
5988
6004
|
scaleAxisRotation
|
|
5989
6005
|
);
|
|
5990
|
-
const
|
|
6006
|
+
const repositionedPagePoint = import_Vec.Vec.Add(
|
|
6007
|
+
newPageCenter,
|
|
6008
|
+
import_Vec.Vec.Sub(initialPagePoint, initialPageCenter)
|
|
6009
|
+
);
|
|
6010
|
+
const repositionedLocalPoint = this.getPointInParentSpace(
|
|
5991
6011
|
initialShape.id,
|
|
5992
|
-
|
|
6012
|
+
repositionedPagePoint
|
|
5993
6013
|
);
|
|
5994
|
-
const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter);
|
|
5995
|
-
const delta = import_Vec.Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace);
|
|
5996
6014
|
if (workingShape) {
|
|
5997
6015
|
return {
|
|
5998
6016
|
...workingShape,
|
|
5999
|
-
x:
|
|
6000
|
-
y:
|
|
6017
|
+
x: repositionedLocalPoint.x,
|
|
6018
|
+
y: repositionedLocalPoint.y
|
|
6001
6019
|
};
|
|
6002
6020
|
}
|
|
6003
6021
|
return {
|
|
6004
6022
|
id,
|
|
6005
6023
|
type: initialShape.type,
|
|
6006
|
-
x:
|
|
6007
|
-
y:
|
|
6024
|
+
x: repositionedLocalPoint.x,
|
|
6025
|
+
y: repositionedLocalPoint.y
|
|
6008
6026
|
};
|
|
6009
6027
|
}
|
|
6010
6028
|
/** @internal */
|
|
@@ -6030,11 +6048,20 @@ class Editor extends import_eventemitter3.default {
|
|
|
6030
6048
|
initialShape: options.initialShape,
|
|
6031
6049
|
initialBounds: options.initialBounds,
|
|
6032
6050
|
isAspectRatioLocked: options.isAspectRatioLocked,
|
|
6033
|
-
initialPageTransform: options.initialPageTransform
|
|
6051
|
+
initialPageTransform: options.initialPageTransform,
|
|
6052
|
+
dragHandle: options.dragHandle,
|
|
6053
|
+
mode: options.mode,
|
|
6054
|
+
// this is one frame of the same resize, not a new one, so don't fire start/end again
|
|
6055
|
+
skipStartAndEndCallbacks: options.skipStartAndEndCallbacks
|
|
6034
6056
|
});
|
|
6035
6057
|
if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
|
|
6036
6058
|
const parentRotation = this.getShapeParentTransform(id).rotation();
|
|
6037
|
-
const
|
|
6059
|
+
const parentDelta = (0, import_utils2.shortAngleDist)(
|
|
6060
|
+
import_Mat.Mat.Cast(options.initialPageTransform).rotation() - options.initialShape.rotation,
|
|
6061
|
+
parentRotation
|
|
6062
|
+
);
|
|
6063
|
+
const initialParentRotation = parentRotation - parentDelta;
|
|
6064
|
+
const rotation = 2 * options.scaleAxisRotation - options.initialShape.rotation - 2 * initialParentRotation - parentDelta;
|
|
6038
6065
|
this.updateShapes([{ id, type, rotation }]);
|
|
6039
6066
|
}
|
|
6040
6067
|
const preScaleShapePageCenter = import_Mat.Mat.applyToPoint(
|
|
@@ -8343,6 +8370,7 @@ class Editor extends import_eventemitter3.default {
|
|
|
8343
8370
|
break;
|
|
8344
8371
|
}
|
|
8345
8372
|
case "key_repeat": {
|
|
8373
|
+
inputs.keys.add(info.code);
|
|
8346
8374
|
break;
|
|
8347
8375
|
}
|
|
8348
8376
|
}
|