@tldraw/editor 3.7.0-internal.acaf9fbbd3cc → 3.7.1

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 (62) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist-cjs/index.d.ts +11 -2
  3. package/dist-cjs/index.js +5 -1
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/TldrawEditor.js +5 -3
  6. package/dist-cjs/lib/TldrawEditor.js.map +2 -2
  7. package/dist-cjs/lib/components/LiveCollaborators.js +2 -1
  8. package/dist-cjs/lib/components/LiveCollaborators.js.map +2 -2
  9. package/dist-cjs/lib/components/Shape.js +6 -4
  10. package/dist-cjs/lib/components/Shape.js.map +2 -2
  11. package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js +2 -1
  12. package/dist-cjs/lib/components/default-components/DefaultSelectionForeground.js.map +2 -2
  13. package/dist-cjs/lib/editor/Editor.js +10 -4
  14. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  15. package/dist-cjs/lib/editor/managers/TextManager.js +9 -15
  16. package/dist-cjs/lib/editor/managers/TextManager.js.map +2 -2
  17. package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +2 -2
  18. package/dist-cjs/lib/exports/FontEmbedder.js +2 -1
  19. package/dist-cjs/lib/exports/FontEmbedder.js.map +2 -2
  20. package/dist-cjs/lib/hooks/useEvent.js +18 -1
  21. package/dist-cjs/lib/hooks/useEvent.js.map +2 -2
  22. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +1 -0
  23. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  24. package/dist-cjs/version.js +3 -3
  25. package/dist-cjs/version.js.map +1 -1
  26. package/dist-esm/index.d.mts +11 -2
  27. package/dist-esm/index.mjs +6 -2
  28. package/dist-esm/index.mjs.map +2 -2
  29. package/dist-esm/lib/TldrawEditor.mjs +5 -3
  30. package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
  31. package/dist-esm/lib/components/LiveCollaborators.mjs +2 -1
  32. package/dist-esm/lib/components/LiveCollaborators.mjs.map +2 -2
  33. package/dist-esm/lib/components/Shape.mjs +6 -4
  34. package/dist-esm/lib/components/Shape.mjs.map +2 -2
  35. package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs +2 -1
  36. package/dist-esm/lib/components/default-components/DefaultSelectionForeground.mjs.map +2 -2
  37. package/dist-esm/lib/editor/Editor.mjs +11 -4
  38. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  39. package/dist-esm/lib/editor/managers/TextManager.mjs +9 -15
  40. package/dist-esm/lib/editor/managers/TextManager.mjs.map +2 -2
  41. package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +2 -2
  42. package/dist-esm/lib/exports/FontEmbedder.mjs +2 -1
  43. package/dist-esm/lib/exports/FontEmbedder.mjs.map +2 -2
  44. package/dist-esm/lib/hooks/useEvent.mjs +18 -1
  45. package/dist-esm/lib/hooks/useEvent.mjs.map +2 -2
  46. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +1 -0
  47. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  48. package/dist-esm/version.mjs +3 -3
  49. package/dist-esm/version.mjs.map +1 -1
  50. package/package.json +7 -7
  51. package/src/index.ts +2 -1
  52. package/src/lib/TldrawEditor.tsx +3 -1
  53. package/src/lib/components/LiveCollaborators.tsx +3 -1
  54. package/src/lib/components/Shape.tsx +22 -10
  55. package/src/lib/components/default-components/DefaultSelectionForeground.tsx +4 -1
  56. package/src/lib/editor/Editor.ts +14 -7
  57. package/src/lib/editor/managers/TextManager.ts +9 -17
  58. package/src/lib/editor/shapes/ShapeUtil.ts +1 -1
  59. package/src/lib/exports/FontEmbedder.ts +2 -1
  60. package/src/lib/hooks/useEvent.tsx +29 -0
  61. package/src/lib/utils/sync/LocalIndexedDb.ts +7 -5
  62. package/src/version.ts +3 -3
@@ -37,6 +37,7 @@ var import_classnames = __toESM(require("classnames"));
37
37
  var import_react = require("react");
38
38
  var import_useEditor = require("../../hooks/useEditor");
39
39
  var import_useTransform = require("../../hooks/useTransform");
40
+ var import_Box = require("../../primitives/Box");
40
41
  var import_utils = require("../../primitives/utils");
41
42
  function DefaultSelectionForeground({ bounds, rotation }) {
42
43
  const editor = (0, import_useEditor.useEditor)();
@@ -47,7 +48,7 @@ function DefaultSelectionForeground({ bounds, rotation }) {
47
48
  x: -expandOutlineBy,
48
49
  y: -expandOutlineBy
49
50
  });
50
- bounds = bounds.clone().expandBy(expandOutlineBy).zeroFix();
51
+ bounds = expandOutlineBy instanceof import_Box.Box ? bounds.clone().expand(expandOutlineBy).zeroFix() : bounds.clone().expandBy(expandOutlineBy).zeroFix();
51
52
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
52
53
  "svg",
53
54
  {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/components/default-components/DefaultSelectionForeground.tsx"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport classNames from 'classnames'\nimport { useRef } from 'react'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useTransform } from '../../hooks/useTransform'\nimport { Box } from '../../primitives/Box'\nimport { toDomPrecision } from '../../primitives/utils'\n\n/** @public */\nexport interface TLSelectionForegroundProps {\n\tbounds: Box\n\trotation: number\n}\n\n/** @public @react */\nexport function DefaultSelectionForeground({ bounds, rotation }: TLSelectionForegroundProps) {\n\tconst editor = useEditor()\n\tconst rSvg = useRef<SVGSVGElement>(null)\n\n\tconst onlyShape = useValue('only selected shape', () => editor.getOnlySelectedShape(), [editor])\n\n\t// if all shapes have an expandBy for the selection outline, we can expand by the l\n\tconst expandOutlineBy = onlyShape\n\t\t? editor.getShapeUtil(onlyShape).expandSelectionOutlinePx(onlyShape)\n\t\t: 0\n\n\tuseTransform(rSvg, bounds?.x, bounds?.y, 1, rotation, {\n\t\tx: -expandOutlineBy,\n\t\ty: -expandOutlineBy,\n\t})\n\n\tbounds = bounds.clone().expandBy(expandOutlineBy).zeroFix()\n\n\treturn (\n\t\t<svg\n\t\t\tref={rSvg}\n\t\t\tclassName=\"tl-overlays__item tl-selection__fg\"\n\t\t\tdata-testid=\"selection-foreground\"\n\t\t>\n\t\t\t<rect\n\t\t\t\tclassName={classNames('tl-selection__fg__outline')}\n\t\t\t\twidth={toDomPrecision(bounds.width)}\n\t\t\t\theight={toDomPrecision(bounds.height)}\n\t\t\t/>\n\t\t</svg>\n\t)\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCG;AAvCH,yBAAyB;AACzB,wBAAuB;AACvB,mBAAuB;AACvB,uBAA0B;AAC1B,0BAA6B;AAE7B,mBAA+B;AASxB,SAAS,2BAA2B,EAAE,QAAQ,SAAS,GAA+B;AAC5F,QAAM,aAAS,4BAAU;AACzB,QAAM,WAAO,qBAAsB,IAAI;AAEvC,QAAM,gBAAY,6BAAS,uBAAuB,MAAM,OAAO,qBAAqB,GAAG,CAAC,MAAM,CAAC;AAG/F,QAAM,kBAAkB,YACrB,OAAO,aAAa,SAAS,EAAE,yBAAyB,SAAS,IACjE;AAEH,wCAAa,MAAM,QAAQ,GAAG,QAAQ,GAAG,GAAG,UAAU;AAAA,IACrD,GAAG,CAAC;AAAA,IACJ,GAAG,CAAC;AAAA,EACL,CAAC;AAED,WAAS,OAAO,MAAM,EAAE,SAAS,eAAe,EAAE,QAAQ;AAE1D,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAK;AAAA,MACL,WAAU;AAAA,MACV,eAAY;AAAA,MAEZ;AAAA,QAAC;AAAA;AAAA,UACA,eAAW,kBAAAA,SAAW,2BAA2B;AAAA,UACjD,WAAO,6BAAe,OAAO,KAAK;AAAA,UAClC,YAAQ,6BAAe,OAAO,MAAM;AAAA;AAAA,MACrC;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport classNames from 'classnames'\nimport { useRef } from 'react'\nimport { useEditor } from '../../hooks/useEditor'\nimport { useTransform } from '../../hooks/useTransform'\nimport { Box } from '../../primitives/Box'\nimport { toDomPrecision } from '../../primitives/utils'\n\n/** @public */\nexport interface TLSelectionForegroundProps {\n\tbounds: Box\n\trotation: number\n}\n\n/** @public @react */\nexport function DefaultSelectionForeground({ bounds, rotation }: TLSelectionForegroundProps) {\n\tconst editor = useEditor()\n\tconst rSvg = useRef<SVGSVGElement>(null)\n\n\tconst onlyShape = useValue('only selected shape', () => editor.getOnlySelectedShape(), [editor])\n\n\t// if all shapes have an expandBy for the selection outline, we can expand by the l\n\tconst expandOutlineBy = onlyShape\n\t\t? editor.getShapeUtil(onlyShape).expandSelectionOutlinePx(onlyShape)\n\t\t: 0\n\n\tuseTransform(rSvg, bounds?.x, bounds?.y, 1, rotation, {\n\t\tx: -expandOutlineBy,\n\t\ty: -expandOutlineBy,\n\t})\n\n\tbounds =\n\t\texpandOutlineBy instanceof Box\n\t\t\t? bounds.clone().expand(expandOutlineBy).zeroFix()\n\t\t\t: bounds.clone().expandBy(expandOutlineBy).zeroFix()\n\n\treturn (\n\t\t<svg\n\t\t\tref={rSvg}\n\t\t\tclassName=\"tl-overlays__item tl-selection__fg\"\n\t\t\tdata-testid=\"selection-foreground\"\n\t\t>\n\t\t\t<rect\n\t\t\t\tclassName={classNames('tl-selection__fg__outline')}\n\t\t\t\twidth={toDomPrecision(bounds.width)}\n\t\t\t\theight={toDomPrecision(bounds.height)}\n\t\t\t/>\n\t\t</svg>\n\t)\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA0CG;AA1CH,yBAAyB;AACzB,wBAAuB;AACvB,mBAAuB;AACvB,uBAA0B;AAC1B,0BAA6B;AAC7B,iBAAoB;AACpB,mBAA+B;AASxB,SAAS,2BAA2B,EAAE,QAAQ,SAAS,GAA+B;AAC5F,QAAM,aAAS,4BAAU;AACzB,QAAM,WAAO,qBAAsB,IAAI;AAEvC,QAAM,gBAAY,6BAAS,uBAAuB,MAAM,OAAO,qBAAqB,GAAG,CAAC,MAAM,CAAC;AAG/F,QAAM,kBAAkB,YACrB,OAAO,aAAa,SAAS,EAAE,yBAAyB,SAAS,IACjE;AAEH,wCAAa,MAAM,QAAQ,GAAG,QAAQ,GAAG,GAAG,UAAU;AAAA,IACrD,GAAG,CAAC;AAAA,IACJ,GAAG,CAAC;AAAA,EACL,CAAC;AAED,WACC,2BAA2B,iBACxB,OAAO,MAAM,EAAE,OAAO,eAAe,EAAE,QAAQ,IAC/C,OAAO,MAAM,EAAE,SAAS,eAAe,EAAE,QAAQ;AAErD,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAK;AAAA,MACL,WAAU;AAAA,MACV,eAAY;AAAA,MAEZ;AAAA,QAAC;AAAA;AAAA,UACA,eAAW,kBAAAA,SAAW,2BAA2B;AAAA,UACjD,WAAO,6BAAe,OAAO,KAAK;AAAA,UAClC,YAAQ,6BAAe,OAAO,MAAM;AAAA;AAAA,MACrC;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": ["classNames"]
7
7
  }
@@ -1751,6 +1751,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
1751
1751
  if (!followingUserId) return null;
1752
1752
  const leaderPresence = this.getCollaborators().find((c) => c.userId === followingUserId);
1753
1753
  if (!leaderPresence) return null;
1754
+ if (!leaderPresence.camera || !leaderPresence.screenBounds) return null;
1754
1755
  const { w: lw, h: lh } = leaderPresence.screenBounds;
1755
1756
  const { x: lx, y: ly, z: lz } = leaderPresence.camera;
1756
1757
  const theirViewport = new import_Box.Box(-lx, -ly, lw / lz, lh / lz);
@@ -2445,6 +2446,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2445
2446
  zoomToUser(userId, opts = { animation: { duration: 500 } }) {
2446
2447
  const presence = this.getCollaborators().find((c) => c.userId === userId);
2447
2448
  if (!presence) return this;
2449
+ const cursor = presence.cursor;
2450
+ if (!cursor) return this;
2448
2451
  this.run(() => {
2449
2452
  if (this.getInstanceState().followingUserId !== null) {
2450
2453
  this.stopFollowingUser();
@@ -2456,7 +2459,7 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2456
2459
  if (opts && opts.animation && !isOnSamePage) {
2457
2460
  opts.animation = void 0;
2458
2461
  }
2459
- this.centerOnPoint(presence.cursor, opts);
2462
+ this.centerOnPoint(cursor, opts);
2460
2463
  const { highlightedUserIds } = this.getInstanceState();
2461
2464
  this.updateInstanceState({ highlightedUserIds: [...highlightedUserIds, userId] });
2462
2465
  this.timers.setTimeout(() => {
@@ -2613,7 +2616,10 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
2613
2616
  if (!allPresenceRecords.length) return import_state.EMPTY_ARRAY;
2614
2617
  const userIds = [...new Set(allPresenceRecords.map((c) => c.userId))].sort();
2615
2618
  return userIds.map((id) => {
2616
- const latestPresence = allPresenceRecords.filter((c) => c.userId === id).sort((a, b) => b.lastActivityTimestamp - a.lastActivityTimestamp)[0];
2619
+ const latestPresence = (0, import_utils.maxBy)(
2620
+ allPresenceRecords.filter((c) => c.userId === id),
2621
+ (p) => p.lastActivityTimestamp ?? 0
2622
+ );
2617
2623
  return latestPresence;
2618
2624
  });
2619
2625
  }
@@ -3165,8 +3171,8 @@ class Editor extends (_a = import_eventemitter3.default, _getIsShapeHiddenCache_
3165
3171
  * Upload an asset to the store's asset service, returning a URL that can be used to resolve the
3166
3172
  * asset.
3167
3173
  */
3168
- async uploadAsset(asset, file) {
3169
- return await this.store.props.assets.upload(asset, file);
3174
+ async uploadAsset(asset, file, abortSignal) {
3175
+ return await this.store.props.assets.upload(asset, file, abortSignal);
3170
3176
  }
3171
3177
  _getShapeGeometryCache() {
3172
3178
  return this.store.createComputedCache(