@tldraw/editor 5.5.2 → 5.6.0-canary.035b741dc331

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.
Files changed (35) hide show
  1. package/dist-cjs/index.js +1 -1
  2. package/dist-cjs/lib/editor/Editor.js +15 -4
  3. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  4. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js +3 -5
  5. package/dist-cjs/lib/editor/managers/ScribbleManager/ScribbleManager.js.map +2 -2
  6. package/dist-cjs/lib/editor/shapes/shared/resizeBox.js +21 -16
  7. package/dist-cjs/lib/editor/shapes/shared/resizeBox.js.map +2 -2
  8. package/dist-cjs/lib/hooks/useCursor.js +12 -8
  9. package/dist-cjs/lib/hooks/useCursor.js.map +2 -2
  10. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +12 -5
  11. package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
  12. package/dist-cjs/version.js +3 -3
  13. package/dist-cjs/version.js.map +1 -1
  14. package/dist-esm/index.mjs +1 -1
  15. package/dist-esm/lib/editor/Editor.mjs +17 -5
  16. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  17. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs +3 -5
  18. package/dist-esm/lib/editor/managers/ScribbleManager/ScribbleManager.mjs.map +2 -2
  19. package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs +21 -16
  20. package/dist-esm/lib/editor/shapes/shared/resizeBox.mjs.map +2 -2
  21. package/dist-esm/lib/hooks/useCursor.mjs +12 -8
  22. package/dist-esm/lib/hooks/useCursor.mjs.map +2 -2
  23. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +13 -6
  24. package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
  25. package/dist-esm/version.mjs +3 -3
  26. package/dist-esm/version.mjs.map +1 -1
  27. package/package.json +17 -19
  28. package/src/lib/editor/Editor.ts +38 -9
  29. package/src/lib/editor/managers/ScribbleManager/ScribbleManager.ts +4 -6
  30. package/src/lib/editor/shapes/shared/resizeBox.ts +21 -16
  31. package/src/lib/hooks/useCursor.ts +14 -7
  32. package/src/lib/test/useCursor.test.tsx +36 -0
  33. package/src/lib/utils/sync/TLLocalSyncClient.test.ts +73 -0
  34. package/src/lib/utils/sync/TLLocalSyncClient.ts +24 -8
  35. package/src/version.ts +3 -3
@@ -99,7 +99,8 @@ import {
99
99
  approximately,
100
100
  areAnglesCompatible,
101
101
  clamp,
102
- pointInPolygon
102
+ pointInPolygon,
103
+ shortAngleDist
103
104
  } from "../primitives/utils.mjs";
104
105
  import { Vec } from "../primitives/Vec.mjs";
105
106
  import { areShapesContentEqual } from "../utils/areShapesContentEqual.mjs";
@@ -3698,7 +3699,9 @@ class Editor extends EventEmitter {
3698
3699
  const id = typeof page === "string" ? page : page.id;
3699
3700
  const freshPage = this.getPage(id);
3700
3701
  if (!freshPage) return this;
3701
- const prevCamera = { ...this.getCamera() };
3702
+ const prevCamera = {
3703
+ ...(this.store.get(CameraRecordType.createId(freshPage.id)) ?? this.getCamera())
3704
+ };
3702
3705
  const content = this.getContentFromCurrentPage(this.getSortedChildIdsForParent(freshPage.id));
3703
3706
  this.run(() => {
3704
3707
  const pages = this.getPages();
@@ -3707,7 +3710,7 @@ class Editor extends EventEmitter {
3707
3710
  this.setCurrentPage(createId);
3708
3711
  this.setCamera(prevCamera);
3709
3712
  if (content) {
3710
- return this.putContentOntoCurrentPage(content);
3713
+ return this.putContentOntoCurrentPage(content, { preservePosition: true });
3711
3714
  }
3712
3715
  });
3713
3716
  return this;
@@ -6071,11 +6074,20 @@ class Editor extends EventEmitter {
6071
6074
  initialShape: options.initialShape,
6072
6075
  initialBounds: options.initialBounds,
6073
6076
  isAspectRatioLocked: options.isAspectRatioLocked,
6074
- initialPageTransform: options.initialPageTransform
6077
+ initialPageTransform: options.initialPageTransform,
6078
+ dragHandle: options.dragHandle,
6079
+ mode: options.mode,
6080
+ // this is one frame of the same resize, not a new one, so don't fire start/end again
6081
+ skipStartAndEndCallbacks: options.skipStartAndEndCallbacks
6075
6082
  });
6076
6083
  if (Math.sign(scale.x) * Math.sign(scale.y) < 0) {
6077
6084
  const parentRotation = this.getShapeParentTransform(id).rotation();
6078
- const rotation = -options.initialShape.rotation - 2 * parentRotation;
6085
+ const parentDelta = shortAngleDist(
6086
+ Mat.Cast(options.initialPageTransform).rotation() - options.initialShape.rotation,
6087
+ parentRotation
6088
+ );
6089
+ const initialParentRotation = parentRotation - parentDelta;
6090
+ const rotation = 2 * options.scaleAxisRotation - options.initialShape.rotation - 2 * initialParentRotation - parentDelta;
6079
6091
  this.updateShapes([{ id, type, rotation }]);
6080
6092
  }
6081
6093
  const preScaleShapePageCenter = Mat.applyToPoint(