@tldraw/editor 5.2.0-canary.4a316fdfb2bb → 5.2.0-canary.4e00299c3e28

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 (68) hide show
  1. package/README.md +7 -1
  2. package/dist-cjs/index.d.ts +39 -40
  3. package/dist-cjs/index.js +4 -4
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/editor/Editor.js +92 -53
  6. package/dist-cjs/lib/editor/Editor.js.map +3 -3
  7. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +3 -3
  8. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
  9. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +1 -2
  10. package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +2 -2
  11. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js +12 -2
  12. package/dist-cjs/lib/editor/managers/HistoryManager/HistoryManager.js.map +2 -2
  13. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -2
  14. package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
  15. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +7 -3
  16. package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +15 -2
  18. package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +79 -0
  20. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +7 -0
  21. package/dist-cjs/lib/hooks/usePresence.js.map +2 -2
  22. package/dist-cjs/version.js +3 -3
  23. package/dist-cjs/version.js.map +1 -1
  24. package/dist-esm/index.d.mts +39 -40
  25. package/dist-esm/index.mjs +5 -7
  26. package/dist-esm/index.mjs.map +2 -2
  27. package/dist-esm/lib/editor/Editor.mjs +92 -53
  28. package/dist-esm/lib/editor/Editor.mjs.map +3 -3
  29. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +3 -3
  30. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
  31. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +1 -2
  32. package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +2 -2
  33. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs +12 -2
  34. package/dist-esm/lib/editor/managers/HistoryManager/HistoryManager.mjs.map +2 -2
  35. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -2
  36. package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
  37. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +7 -3
  38. package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
  39. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +15 -2
  40. package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
  41. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +59 -0
  42. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +7 -0
  43. package/dist-esm/lib/hooks/usePresence.mjs.map +2 -2
  44. package/dist-esm/version.mjs +3 -3
  45. package/dist-esm/version.mjs.map +1 -1
  46. package/editor.css +2 -0
  47. package/package.json +8 -8
  48. package/src/index.ts +2 -5
  49. package/src/lib/editor/Editor.ts +124 -64
  50. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +43 -16
  51. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +8 -5
  52. package/src/lib/editor/managers/FocusManager/FocusManager.test.ts +4 -4
  53. package/src/lib/editor/managers/FocusManager/FocusManager.ts +1 -2
  54. package/src/lib/editor/managers/FontManager/FontManager.test.ts +13 -9
  55. package/src/lib/editor/managers/HistoryManager/HistoryManager.ts +20 -2
  56. package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +9 -2
  57. package/src/lib/editor/managers/TextManager/TextManager.test.ts +16 -14
  58. package/src/lib/editor/managers/TextManager/TextManager.ts +17 -2
  59. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +12 -2
  60. package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +27 -2
  61. package/src/lib/editor/overlays/strokeShapeIndicators.ts +86 -0
  62. package/src/lib/hooks/usePresence.ts +2 -2
  63. package/src/version.ts +3 -3
  64. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +0 -161
  65. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +0 -7
  66. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +0 -141
  67. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +0 -7
  68. package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +0 -216
@@ -0,0 +1,59 @@
1
+ import { createComputedCache } from "@tldraw/store";
2
+ const indicatorPathCache = createComputedCache(
3
+ "shapeIndicatorPath",
4
+ (editor, shape) => {
5
+ const util = editor.getShapeUtil(shape);
6
+ return util.getIndicatorPath(shape);
7
+ },
8
+ {
9
+ areRecordsEqual(a, b) {
10
+ return a.props === b.props;
11
+ }
12
+ }
13
+ );
14
+ function strokeShapeIndicators(editor, ctx, shapeIds) {
15
+ if (shapeIds.length === 0) return;
16
+ const batched = new Path2D();
17
+ for (const shapeId of shapeIds) {
18
+ const shape = editor.getShape(shapeId);
19
+ if (!shape || shape.isLocked) continue;
20
+ const pageTransform = editor.getShapePageTransform(shape);
21
+ if (!pageTransform) continue;
22
+ const indicatorPath = indicatorPathCache.get(editor, shape.id);
23
+ if (!indicatorPath) continue;
24
+ if (indicatorPath instanceof Path2D) {
25
+ batched.addPath(indicatorPath, pageTransform);
26
+ continue;
27
+ }
28
+ const { path, clipPath, additionalPaths } = indicatorPath;
29
+ if (!clipPath) {
30
+ batched.addPath(path, pageTransform);
31
+ if (additionalPaths) {
32
+ for (const p of additionalPaths) batched.addPath(p, pageTransform);
33
+ }
34
+ continue;
35
+ }
36
+ ctx.save();
37
+ ctx.transform(
38
+ pageTransform.a,
39
+ pageTransform.b,
40
+ pageTransform.c,
41
+ pageTransform.d,
42
+ pageTransform.e,
43
+ pageTransform.f
44
+ );
45
+ ctx.save();
46
+ ctx.clip(clipPath, "evenodd");
47
+ ctx.stroke(path);
48
+ ctx.restore();
49
+ if (additionalPaths) {
50
+ for (const p of additionalPaths) ctx.stroke(p);
51
+ }
52
+ ctx.restore();
53
+ }
54
+ ctx.stroke(batched);
55
+ }
56
+ export {
57
+ strokeShapeIndicators
58
+ };
59
+ //# sourceMappingURL=strokeShapeIndicators.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/lib/editor/overlays/strokeShapeIndicators.ts"],
4
+ "sourcesContent": ["import { createComputedCache } from '@tldraw/store'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport type { Editor } from '../Editor'\n\nconst indicatorPathCache = createComputedCache(\n\t'shapeIndicatorPath',\n\t(editor: Editor, shape: TLShape) => {\n\t\tconst util = editor.getShapeUtil(shape)\n\t\treturn util.getIndicatorPath(shape)\n\t},\n\t{\n\t\tareRecordsEqual(a, b) {\n\t\t\treturn a.props === b.props\n\t\t},\n\t}\n)\n\n/**\n * Combine every batchable shape indicator into a single page-space `Path2D` and\n * emit one stroke call. Shapes whose indicator needs an evenodd clip (e.g.\n * arrows with labels or complex arrowheads) can't be batched \u2014 they still\n * stroke individually inside a save/restore with `ctx.clip` applied.\n *\n * Shared by any overlay util that paints shape indicators (e.g. collaborator\n * selections).\n *\n * @public\n */\nexport function strokeShapeIndicators(\n\teditor: Editor,\n\tctx: CanvasRenderingContext2D,\n\tshapeIds: TLShapeId[]\n): void {\n\tif (shapeIds.length === 0) return\n\n\tconst batched = new Path2D()\n\n\tfor (const shapeId of shapeIds) {\n\t\tconst shape = editor.getShape(shapeId)\n\t\tif (!shape || shape.isLocked) continue\n\n\t\tconst pageTransform = editor.getShapePageTransform(shape)\n\t\tif (!pageTransform) continue\n\n\t\tconst indicatorPath = indicatorPathCache.get(editor, shape.id)\n\t\tif (!indicatorPath) continue\n\n\t\tif (indicatorPath instanceof Path2D) {\n\t\t\tbatched.addPath(indicatorPath, pageTransform)\n\t\t\tcontinue\n\t\t}\n\n\t\tconst { path, clipPath, additionalPaths } = indicatorPath\n\n\t\tif (!clipPath) {\n\t\t\tbatched.addPath(path, pageTransform)\n\t\t\tif (additionalPaths) {\n\t\t\t\tfor (const p of additionalPaths) batched.addPath(p, pageTransform)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\t// Clipped case: fall back to an individual stroke. Rare (arrows with\n\t\t// labels / complex arrowheads), so the extra save/restore/stroke\n\t\t// pair per such shape isn't worth batching away.\n\t\tctx.save()\n\t\tctx.transform(\n\t\t\tpageTransform.a,\n\t\t\tpageTransform.b,\n\t\t\tpageTransform.c,\n\t\t\tpageTransform.d,\n\t\t\tpageTransform.e,\n\t\t\tpageTransform.f\n\t\t)\n\t\tctx.save()\n\t\tctx.clip(clipPath, 'evenodd')\n\t\tctx.stroke(path)\n\t\tctx.restore()\n\t\tif (additionalPaths) {\n\t\t\tfor (const p of additionalPaths) ctx.stroke(p)\n\t\t}\n\t\tctx.restore()\n\t}\n\n\tctx.stroke(batched)\n}\n"],
5
+ "mappings": "AAAA,SAAS,2BAA2B;AAIpC,MAAM,qBAAqB;AAAA,EAC1B;AAAA,EACA,CAAC,QAAgB,UAAmB;AACnC,UAAM,OAAO,OAAO,aAAa,KAAK;AACtC,WAAO,KAAK,iBAAiB,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,IACC,gBAAgB,GAAG,GAAG;AACrB,aAAO,EAAE,UAAU,EAAE;AAAA,IACtB;AAAA,EACD;AACD;AAaO,SAAS,sBACf,QACA,KACA,UACO;AACP,MAAI,SAAS,WAAW,EAAG;AAE3B,QAAM,UAAU,IAAI,OAAO;AAE3B,aAAW,WAAW,UAAU;AAC/B,UAAM,QAAQ,OAAO,SAAS,OAAO;AACrC,QAAI,CAAC,SAAS,MAAM,SAAU;AAE9B,UAAM,gBAAgB,OAAO,sBAAsB,KAAK;AACxD,QAAI,CAAC,cAAe;AAEpB,UAAM,gBAAgB,mBAAmB,IAAI,QAAQ,MAAM,EAAE;AAC7D,QAAI,CAAC,cAAe;AAEpB,QAAI,yBAAyB,QAAQ;AACpC,cAAQ,QAAQ,eAAe,aAAa;AAC5C;AAAA,IACD;AAEA,UAAM,EAAE,MAAM,UAAU,gBAAgB,IAAI;AAE5C,QAAI,CAAC,UAAU;AACd,cAAQ,QAAQ,MAAM,aAAa;AACnC,UAAI,iBAAiB;AACpB,mBAAW,KAAK,gBAAiB,SAAQ,QAAQ,GAAG,aAAa;AAAA,MAClE;AACA;AAAA,IACD;AAKA,QAAI,KAAK;AACT,QAAI;AAAA,MACH,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,IACf;AACA,QAAI,KAAK;AACT,QAAI,KAAK,UAAU,SAAS;AAC5B,QAAI,OAAO,IAAI;AACf,QAAI,QAAQ;AACZ,QAAI,iBAAiB;AACpB,iBAAW,KAAK,gBAAiB,KAAI,OAAO,CAAC;AAAA,IAC9C;AACA,QAAI,QAAQ;AAAA,EACb;AAEA,MAAI,OAAO,OAAO;AACnB;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/lib/hooks/usePresence.ts"],
4
- "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { TLInstancePresence } from '@tldraw/tlschema'\nimport { useEditor } from './useEditor'\n\n// TODO: maybe move this to a computed property on the App class?\n/**\n * @returns The latest presence of the user matching userId\n * @public\n */\nexport function usePresence(userId: string): TLInstancePresence | null {\n\tconst editor = useEditor()\n\n\tconst latestPresence = useValue(\n\t\t`latestPresence:${userId}`,\n\t\t() => {\n\t\t\treturn editor.getCollaborators().find((c) => c.userId === userId)\n\t\t},\n\t\t[editor, userId]\n\t)\n\n\treturn latestPresence ?? null\n}\n"],
5
- "mappings": "AAAA,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAOnB,SAAS,YAAY,QAA2C;AACtE,QAAM,SAAS,UAAU;AAEzB,QAAM,iBAAiB;AAAA,IACtB,kBAAkB,MAAM;AAAA,IACxB,MAAM;AACL,aAAO,OAAO,iBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,MAAM;AAAA,IACjE;AAAA,IACA,CAAC,QAAQ,MAAM;AAAA,EAChB;AAEA,SAAO,kBAAkB;AAC1B;",
4
+ "sourcesContent": ["import { useValue } from '@tldraw/state-react'\nimport { TLInstancePresence, TLUserId } from '@tldraw/tlschema'\nimport { useEditor } from './useEditor'\n\n// TODO: maybe move this to a computed property on the App class?\n/**\n * @returns The latest presence of the user matching userId\n * @public\n */\nexport function usePresence(userId: TLUserId): TLInstancePresence | null {\n\tconst editor = useEditor()\n\n\tconst latestPresence = useValue(\n\t\t`latestPresence:${userId}`,\n\t\t() => {\n\t\t\treturn editor.getCollaborators().find((c) => c.userId === userId)\n\t\t},\n\t\t[editor, userId]\n\t)\n\n\treturn latestPresence ?? null\n}\n"],
5
+ "mappings": "AAAA,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAOnB,SAAS,YAAY,QAA6C;AACxE,QAAM,SAAS,UAAU;AAEzB,QAAM,iBAAiB;AAAA,IACtB,kBAAkB,MAAM;AAAA,IACxB,MAAM;AACL,aAAO,OAAO,iBAAiB,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,MAAM;AAAA,IACjE;AAAA,IACA,CAAC,QAAQ,MAAM;AAAA,EAChB;AAEA,SAAO,kBAAkB;AAC1B;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,8 @@
1
- const version = "5.2.0-canary.4a316fdfb2bb";
1
+ const version = "5.2.0-canary.4e00299c3e28";
2
2
  const publishDates = {
3
3
  major: "2026-05-06T16:28:18.473Z",
4
- minor: "2026-06-05T11:56:57.032Z",
5
- patch: "2026-06-05T11:56:57.032Z"
4
+ minor: "2026-06-15T08:32:04.112Z",
5
+ patch: "2026-06-15T08:32:04.112Z"
6
6
  };
7
7
  export {
8
8
  publishDates,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-canary.4a316fdfb2bb'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-05T11:56:57.032Z',\n\tpatch: '2026-06-05T11:56:57.032Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-canary.4e00299c3e28'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-15T08:32:04.112Z',\n\tpatch: '2026-06-15T08:32:04.112Z',\n}\n"],
5
5
  "mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
package/editor.css CHANGED
@@ -182,6 +182,7 @@
182
182
  --tl-color-text-0: hsl(0, 0%, 11%);
183
183
  --tl-color-text-1: hsl(0, 0%, 18%);
184
184
  --tl-color-text-3: hsl(204, 4%, 45%);
185
+ --tl-color-text-disabled: hsl(204, 4%, 55%);
185
186
  --tl-color-text-shadow: hsl(0, 0%, 100%);
186
187
  --tl-color-text-highlight: hsl(52, 100%, 50%);
187
188
  --tl-color-text-highlight-p3: color(display-p3 0.972 0.8205 0.05);
@@ -236,6 +237,7 @@
236
237
  --tl-color-text-0: hsl(0, 9%, 94%);
237
238
  --tl-color-text-1: hsl(0, 0%, 85%);
238
239
  --tl-color-text-3: hsl(204, 4%, 75%);
240
+ --tl-color-text-disabled: hsl(204, 4%, 50%);
239
241
  --tl-color-text-shadow: hsl(210, 13%, 18%);
240
242
  --tl-color-text-highlight: hsl(52, 100%, 41%);
241
243
  --tl-color-text-highlight-p3: color(display-p3 0.8078 0.6225 0.0312);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "tldraw infinite canvas SDK (editor).",
4
- "version": "5.2.0-canary.4a316fdfb2bb",
4
+ "version": "5.2.0-canary.4e00299c3e28",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -49,12 +49,12 @@
49
49
  "@tiptap/core": "^3.12.1",
50
50
  "@tiptap/pm": "^3.12.1",
51
51
  "@tiptap/react": "^3.12.1",
52
- "@tldraw/state": "5.2.0-canary.4a316fdfb2bb",
53
- "@tldraw/state-react": "5.2.0-canary.4a316fdfb2bb",
54
- "@tldraw/store": "5.2.0-canary.4a316fdfb2bb",
55
- "@tldraw/tlschema": "5.2.0-canary.4a316fdfb2bb",
56
- "@tldraw/utils": "5.2.0-canary.4a316fdfb2bb",
57
- "@tldraw/validate": "5.2.0-canary.4a316fdfb2bb",
52
+ "@tldraw/state": "5.2.0-canary.4e00299c3e28",
53
+ "@tldraw/state-react": "5.2.0-canary.4e00299c3e28",
54
+ "@tldraw/store": "5.2.0-canary.4e00299c3e28",
55
+ "@tldraw/tlschema": "5.2.0-canary.4e00299c3e28",
56
+ "@tldraw/utils": "5.2.0-canary.4e00299c3e28",
57
+ "@tldraw/validate": "5.2.0-canary.4e00299c3e28",
58
58
  "classnames": "^2.5.1",
59
59
  "eventemitter3": "^4.0.7",
60
60
  "idb": "^7.1.1",
@@ -80,7 +80,7 @@
80
80
  "react": "^19.2.1",
81
81
  "react-dom": "^19.2.1",
82
82
  "resize-observer-polyfill": "^1.5.1",
83
- "vitest": "^3.2.4"
83
+ "vitest": "^4.1.7"
84
84
  },
85
85
  "module": "dist-esm/index.mjs",
86
86
  "source": "src/index.ts",
package/src/index.ts CHANGED
@@ -128,6 +128,7 @@ export {
128
128
  export { SpatialIndexManager } from './lib/editor/managers/SpatialIndexManager/SpatialIndexManager'
129
129
  export {
130
130
  TextManager,
131
+ resolveLineHeightPx,
131
132
  type BatchMeasurementRequest,
132
133
  type TLMeasuredTextSize,
133
134
  type TLMeasureTextOpts,
@@ -185,11 +186,7 @@ export {
185
186
  type TLOverlay,
186
187
  type TLOverlayUtilConstructor,
187
188
  } from './lib/editor/overlays/OverlayUtil'
188
- export {
189
- ShapeIndicatorOverlayUtil,
190
- strokeShapeIndicators,
191
- type TLShapeIndicatorOverlay,
192
- } from './lib/editor/overlays/ShapeIndicatorOverlayUtil'
189
+ export { strokeShapeIndicators } from './lib/editor/overlays/strokeShapeIndicators'
193
190
  export {
194
191
  getPerfectDashProps,
195
192
  type PerfectDashTerminal,
@@ -3068,8 +3068,8 @@ export class Editor extends EventEmitter<TLEventMap> {
3068
3068
  return baseCamera
3069
3069
  }
3070
3070
 
3071
- private _getFollowingPresence(targetUserId: string | null) {
3072
- const visited = [this.user.getId()]
3071
+ private _getFollowingPresence(targetUserId: TLUserId | null) {
3072
+ const visited = [this.user.getRecordId()]
3073
3073
  const collaborators = this.getCollaborators()
3074
3074
  let leaderPresence = null as null | TLInstancePresence
3075
3075
  while (targetUserId && !visited.includes(targetUserId)) {
@@ -3336,6 +3336,15 @@ export class Editor extends EventEmitter<TLEventMap> {
3336
3336
 
3337
3337
  let { x, y, z = currentCamera.z } = point
3338
3338
 
3339
+ // `requested` kept the caller's focal point (e.g. the cursor) fixed at
3340
+ // zoom `rz`. When `rz` gets clamped, keep that same focal point fixed at
3341
+ // the clamped zoom `z` rather than snapping to the viewport center.
3342
+ const preserveFocalPoint = (current: number, requested: number, rz: number, z: number) => {
3343
+ const cz = currentCamera.z
3344
+ if (rz === cz) return current
3345
+ return current + ((requested - current) * (1 / z - 1 / cz)) / (1 / rz - 1 / cz)
3346
+ }
3347
+
3339
3348
  // If force is true, then we'll set the camera to the point regardless of
3340
3349
  // the camera options, so that we can handle gestures that permit elasticity
3341
3350
  // or decay, or animations that occur while the camera is locked.
@@ -3378,17 +3387,14 @@ export class Editor extends EventEmitter<TLEventMap> {
3378
3387
  }
3379
3388
 
3380
3389
  if (z < minZ || z > maxZ) {
3381
- // We're trying to zoom out past the minimum zoom level,
3382
- // or in past the maximum zoom level, so stop the camera
3383
- // but keep the current center
3384
- const { x: cx, y: cy, z: cz } = currentCamera
3385
- const cxA = -cx + vsb.w / cz / 2
3386
- const cyA = -cy + vsb.h / cz / 2
3390
+ // We're trying to zoom out past the minimum zoom level, or in
3391
+ // past the maximum zoom level, so clamp the zoom while keeping
3392
+ // the caller's focal point fixed. Axis constraints below still
3393
+ // apply on top of this.
3394
+ const rz = z
3387
3395
  z = clamp(z, minZ, maxZ)
3388
- const cxB = -cx + vsb.w / z / 2
3389
- const cyB = -cy + vsb.h / z / 2
3390
- x = cx + cxB - cxA
3391
- y = cy + cyB - cyA
3396
+ x = preserveFocalPoint(currentCamera.x, x, rz, z)
3397
+ y = preserveFocalPoint(currentCamera.y, y, rz, z)
3392
3398
  }
3393
3399
 
3394
3400
  // Calculate available space
@@ -3477,12 +3483,12 @@ export class Editor extends EventEmitter<TLEventMap> {
3477
3483
  }
3478
3484
  }
3479
3485
  } else {
3480
- // constrain the zoom, preserving the center
3486
+ // constrain the zoom, keeping the caller's focal point fixed
3481
3487
  if (z > zoomMax || z < zoomMin) {
3482
- const { x: cx, y: cy, z: cz } = currentCamera
3488
+ const rz = z
3483
3489
  z = clamp(z, zoomMin, zoomMax)
3484
- x = cx + (-cx + vsb.w / z / 2) - (-cx + vsb.w / cz / 2)
3485
- y = cy + (-cy + vsb.h / z / 2) - (-cy + vsb.h / cz / 2)
3490
+ x = preserveFocalPoint(currentCamera.x, x, rz, z)
3491
+ y = preserveFocalPoint(currentCamera.y, y, rz, z)
3486
3492
  }
3487
3493
  }
3488
3494
  }
@@ -4023,16 +4029,34 @@ export class Editor extends EventEmitter<TLEventMap> {
4023
4029
 
4024
4030
  this.once('stop-camera-animation', cancel)
4025
4031
 
4032
+ const dirZ = direction.z ?? 0
4033
+
4026
4034
  const moveCamera = (elapsed: number) => {
4027
4035
  const { x: cx, y: cy, z: cz } = this.getCamera()
4028
- const movementVec = Vec.Mul(direction, (currentSpeed * elapsed) / cz)
4036
+
4037
+ // Pan movement from x/y direction
4038
+ const dx = (direction.x * (currentSpeed * elapsed)) / cz
4039
+ const dy = (direction.y * (currentSpeed * elapsed)) / cz
4040
+
4041
+ let newCx = cx + dx
4042
+ let newCy = cy + dy
4043
+ let newCz = cz
4044
+
4045
+ // animate zoom if z direction is passed in
4046
+ if (dirZ !== 0) {
4047
+ newCz = cz * (1 + dirZ * currentSpeed * elapsed)
4048
+ // Adjust x/y to keep the viewport center fixed while zooming
4049
+ const center = this.getViewportScreenCenter()
4050
+ newCx += center.x / newCz - center.x / cz
4051
+ newCy += center.y / newCz - center.y / cz
4052
+ }
4029
4053
 
4030
4054
  // Apply friction
4031
4055
  currentSpeed *= 1 - friction
4032
4056
  if (currentSpeed < speedThreshold) {
4033
4057
  cancel()
4034
4058
  } else {
4035
- this._setCamera(new Vec(cx + movementVec.x, cy + movementVec.y, cz))
4059
+ this._setCamera(new Vec(newCx, newCy, newCz))
4036
4060
  }
4037
4061
  }
4038
4062
 
@@ -4054,7 +4078,7 @@ export class Editor extends EventEmitter<TLEventMap> {
4054
4078
  * @param opts - The camera move options.
4055
4079
  * @public
4056
4080
  */
4057
- zoomToUser(userId: string, opts: TLCameraMoveOptions = { animation: { duration: 500 } }): this {
4081
+ zoomToUser(userId: TLUserId, opts: TLCameraMoveOptions = { animation: { duration: 500 } }): this {
4058
4082
  const presence = this.getCollaborators().find((c) => c.userId === userId)
4059
4083
 
4060
4084
  if (!presence) return this
@@ -4426,11 +4450,11 @@ export class Editor extends EventEmitter<TLEventMap> {
4426
4450
  *
4427
4451
  * @public
4428
4452
  */
4429
- startFollowingUser(userId: string): this {
4453
+ startFollowingUser(userId: TLUserId): this {
4430
4454
  // if we were already following someone, stop following them
4431
4455
  this.stopFollowingUser()
4432
4456
 
4433
- const thisUserId = this.user.getId()
4457
+ const thisUserId = this.user.getExternalId()
4434
4458
 
4435
4459
  if (!thisUserId) {
4436
4460
  console.warn('You should set the userId for the current instance before following a user')
@@ -8078,32 +8102,53 @@ export class Editor extends EventEmitter<TLEventMap> {
8078
8102
  * @public
8079
8103
  */
8080
8104
  resizeShape(shape: TLShapeId | TLShape, scale: VecLike, opts: TLResizeShapeOptions = {}): this {
8105
+ const partial = this.getResizeShapePartial(shape, scale, opts)
8106
+ if (partial) this.updateShapes([partial])
8107
+ return this
8108
+ }
8109
+
8110
+ /**
8111
+ * Get the update for a resized shape without committing it to the store. Interactions that
8112
+ * resize many shapes at once use this to collect all of the updates and commit them in a
8113
+ * single batch. Returns null when there is nothing to update.
8114
+ *
8115
+ * Shapes that are rotated out of alignment with the scale axis cannot be resized with a
8116
+ * single update; those shapes are resized immediately (as `resizeShape` would do) and null
8117
+ * is returned.
8118
+ *
8119
+ * @internal
8120
+ */
8121
+ getResizeShapePartial(
8122
+ shape: TLShapeId | TLShape,
8123
+ scale: VecLike,
8124
+ opts: TLResizeShapeOptions = {}
8125
+ ): TLShapePartial | null {
8081
8126
  const id = typeof shape === 'string' ? shape : shape.id
8082
- if (this.getIsReadonly()) return this
8127
+ if (this.getIsReadonly()) return null
8083
8128
 
8084
8129
  if (!Number.isFinite(scale.x)) scale = new Vec(1, scale.y)
8085
8130
  if (!Number.isFinite(scale.y)) scale = new Vec(scale.x, 1)
8086
8131
 
8087
8132
  const initialShape = opts.initialShape ?? this.getShape(id)
8088
- if (!initialShape) return this
8133
+ if (!initialShape) return null
8089
8134
 
8090
8135
  const scaleOrigin = opts.scaleOrigin ?? this.getShapePageBounds(id)?.center
8091
- if (!scaleOrigin) return this
8136
+ if (!scaleOrigin) return null
8092
8137
 
8093
8138
  const pageTransform = opts.initialPageTransform
8094
8139
  ? Mat.Cast(opts.initialPageTransform)
8095
8140
  : this.getShapePageTransform(id)
8096
- if (!pageTransform) return this
8141
+ if (!pageTransform) return null
8097
8142
 
8098
8143
  const pageRotation = pageTransform.rotation()
8099
8144
 
8100
- if (pageRotation == null) return this
8145
+ if (pageRotation == null) return null
8101
8146
 
8102
8147
  const scaleAxisRotation = opts.scaleAxisRotation ?? pageRotation
8103
8148
 
8104
8149
  const initialBounds = opts.initialBounds ?? this.getShapeGeometry(id).bounds
8105
8150
 
8106
- if (!initialBounds) return this
8151
+ if (!initialBounds) return null
8107
8152
 
8108
8153
  const isAspectRatioLocked =
8109
8154
  opts.isAspectRatioLocked ?? this.getShapeUtil(initialShape).isAspectRatioLocked(initialShape)
@@ -8113,7 +8158,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8113
8158
  // from whichever axis is being scaled the least, to avoid the shape getting bigger
8114
8159
  // than the bounds of the selection
8115
8160
  // const minScale = Math.min(Math.abs(scale.x), Math.abs(scale.y))
8116
- return this._resizeUnalignedShape(id, scale, {
8161
+ this._resizeUnalignedShape(id, scale, {
8117
8162
  ...opts,
8118
8163
  initialBounds,
8119
8164
  scaleOrigin,
@@ -8122,6 +8167,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8122
8167
  isAspectRatioLocked,
8123
8168
  initialShape,
8124
8169
  })
8170
+ return null
8125
8171
  }
8126
8172
 
8127
8173
  const util = this.getShapeUtil(initialShape)
@@ -8134,7 +8180,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8134
8180
  }
8135
8181
  }
8136
8182
 
8137
- let didResize = false
8183
+ let workingShape: TLShape | null = null
8138
8184
 
8139
8185
  if (util.onResize && util.canResize(initialShape)) {
8140
8186
  // get the model changes from the shape util
@@ -8166,7 +8212,7 @@ export class Editor extends EventEmitter<TLEventMap> {
8166
8212
  // need to adjust the shape's x and y points in case the parent has moved since start of resizing
8167
8213
  const { x, y } = this.getPointInParentSpace(initialShape.id, initialPagePoint)
8168
8214
 
8169
- let workingShape = initialShape
8215
+ workingShape = initialShape
8170
8216
  if (!opts.skipStartAndEndCallbacks) {
8171
8217
  workingShape = applyPartialToRecordWithProps(
8172
8218
  initialShape,
@@ -8188,10 +8234,6 @@ export class Editor extends EventEmitter<TLEventMap> {
8188
8234
  }
8189
8235
  )
8190
8236
 
8191
- if (resizedShape) {
8192
- didResize = true
8193
- }
8194
-
8195
8237
  workingShape = applyPartialToRecordWithProps(workingShape, {
8196
8238
  id,
8197
8239
  type: initialShape.type as any,
@@ -8207,40 +8249,47 @@ export class Editor extends EventEmitter<TLEventMap> {
8207
8249
  )
8208
8250
  }
8209
8251
 
8210
- this.updateShapes([workingShape])
8252
+ if (resizedShape) {
8253
+ return workingShape
8254
+ }
8211
8255
  }
8212
8256
 
8213
- if (!didResize) {
8214
- // reposition shape (rather than resizing it) based on where its resized center would be
8257
+ // the shape was not resized by its util, so reposition it (rather than resizing it)
8258
+ // based on where its resized center would be
8215
8259
 
8216
- const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center)
8217
- // get the model changes from the shape util
8218
- const newPageCenter = this._scalePagePoint(
8219
- initialPageCenter,
8220
- scaleOrigin,
8221
- scale,
8222
- scaleAxisRotation
8223
- )
8260
+ const initialPageCenter = Mat.applyToPoint(pageTransform, initialBounds.center)
8261
+ // get the model changes from the shape util
8262
+ const newPageCenter = this._scalePagePoint(
8263
+ initialPageCenter,
8264
+ scaleOrigin,
8265
+ scale,
8266
+ scaleAxisRotation
8267
+ )
8224
8268
 
8225
- const initialPageCenterInParentSpace = this.getPointInParentSpace(
8226
- initialShape.id,
8227
- initialPageCenter
8228
- )
8229
- const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter)
8269
+ const initialPageCenterInParentSpace = this.getPointInParentSpace(
8270
+ initialShape.id,
8271
+ initialPageCenter
8272
+ )
8273
+ const newPageCenterInParentSpace = this.getPointInParentSpace(initialShape.id, newPageCenter)
8230
8274
 
8231
- const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace)
8232
- // apply the changes to the model
8233
- this.updateShapes([
8234
- {
8235
- id,
8236
- type: initialShape.type as any,
8237
- x: initialShape.x + delta.x,
8238
- y: initialShape.y + delta.y,
8239
- },
8240
- ])
8275
+ const delta = Vec.Sub(newPageCenterInParentSpace, initialPageCenterInParentSpace)
8276
+
8277
+ if (workingShape) {
8278
+ // the util's onResize ran but returned no change; keep the working update (which may
8279
+ // include changes from onResizeStart / onResizeEnd) and reposition the shape
8280
+ return {
8281
+ ...workingShape,
8282
+ x: initialShape.x + delta.x,
8283
+ y: initialShape.y + delta.y,
8284
+ }
8241
8285
  }
8242
8286
 
8243
- return this
8287
+ return {
8288
+ id,
8289
+ type: initialShape.type as any,
8290
+ x: initialShape.x + delta.x,
8291
+ y: initialShape.y + delta.y,
8292
+ }
8244
8293
  }
8245
8294
 
8246
8295
  /** @internal */
@@ -11167,7 +11216,12 @@ export class Editor extends EventEmitter<TLEventMap> {
11167
11216
  inputs.setIsDragging(false)
11168
11217
 
11169
11218
  // If pen mode is off but we're not already in pen mode, turn that on
11170
- if (!isPenMode && isPen) this.updateInstanceState({ isPenMode: true })
11219
+ if (!isPenMode && isPen) {
11220
+ this.updateInstanceState({ isPenMode: true })
11221
+ // Once pen mode is on, touch input is ignored, so we discard the
11222
+ // in-progress touch interaction .
11223
+ this.interrupt()
11224
+ }
11171
11225
 
11172
11226
  // On devices with erasers (like the Surface Pen or Wacom Pen), button 5 is the eraser
11173
11227
  if (info.button === STYLUS_ERASER_BUTTON) {
@@ -11317,7 +11371,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11317
11371
  // Don't pass right-click panning events to the state chart
11318
11372
  // as it causes unintended shape selection on release
11319
11373
  if (slideSpeed > 0) {
11320
- this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11374
+ this.slideCamera({
11375
+ speed: slideSpeed,
11376
+ direction: { x: slideDirection.x, y: slideDirection.y, z: 0 },
11377
+ })
11321
11378
  }
11322
11379
  this._selectedShapeIdsAtPointerDown = []
11323
11380
  this._didCaptureSelectionAtPointerDown = false
@@ -11326,7 +11383,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11326
11383
  }
11327
11384
 
11328
11385
  if (slideSpeed > 0) {
11329
- this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11386
+ this.slideCamera({
11387
+ speed: slideSpeed,
11388
+ direction: { x: slideDirection.x, y: slideDirection.y, z: 0 },
11389
+ })
11330
11390
  }
11331
11391
  } else {
11332
11392
  if (info.button === STYLUS_ERASER_BUTTON) {
@@ -1,11 +1,17 @@
1
- import { PageRecordType, type TLInstancePresence } from '@tldraw/tlschema'
1
+ import {
2
+ PageRecordType,
3
+ createUserId,
4
+ type TLInstancePresence,
5
+ type TLUserId,
6
+ } from '@tldraw/tlschema'
2
7
  import { vi } from 'vitest'
8
+ import { createTLStore } from '../../../config/createTLStore'
3
9
  import type { Editor } from '../../Editor'
4
10
  import { CollaboratorsManager } from './CollaboratorsManager'
5
11
 
6
12
  const currentPageId = PageRecordType.createId('page')
7
13
 
8
- function createPresence(userId: string): TLInstancePresence {
14
+ function createPresence(userId: TLUserId): TLInstancePresence {
9
15
  return {
10
16
  typeName: 'instance_presence',
11
17
  id: `instance_presence:${userId}` as TLInstancePresence['id'],
@@ -34,6 +40,9 @@ function createEditor(presences: TLInstancePresence[] = []) {
34
40
  }))
35
41
  const userGetId = vi.fn(() => 'current-user')
36
42
 
43
+ const store = createTLStore()
44
+ store.put(presences)
45
+
37
46
  const editor = {
38
47
  options: {
39
48
  collaboratorCheckIntervalMs: 1000,
@@ -45,14 +54,9 @@ function createEditor(presences: TLInstancePresence[] = []) {
45
54
  },
46
55
  user: {
47
56
  getId: userGetId,
57
+ getRecordId: () => createUserId(userGetId()),
48
58
  },
49
- store: {
50
- query: {
51
- records: vi.fn(() => ({
52
- get: () => presences,
53
- })),
54
- },
55
- },
59
+ store,
56
60
  getInstanceState,
57
61
  getCurrentPageId: vi.fn(() => currentPageId),
58
62
  } as unknown as Editor
@@ -88,10 +92,19 @@ describe(CollaboratorsManager, () => {
88
92
  expect(setInterval).toHaveBeenCalledTimes(1)
89
93
  })
90
94
 
95
+ it("excludes the local user's own other sessions", () => {
96
+ const ownSession = createPresence(createUserId('current-user'))
97
+ const peer = createPresence(createUserId('peer'))
98
+ const { editor } = createEditor([ownSession, peer])
99
+ const manager = new CollaboratorsManager(editor)
100
+
101
+ expect(manager.getCollaborators()).toEqual([peer])
102
+ })
103
+
91
104
  it('reads instance state once when filtering visible collaborators', () => {
92
105
  const { editor, getInstanceState } = createEditor([
93
- createPresence('user-1'),
94
- createPresence('user-2'),
106
+ createPresence(createUserId('user-1')),
107
+ createPresence(createUserId('user-2')),
95
108
  ])
96
109
  const manager = new CollaboratorsManager(editor)
97
110
 
@@ -101,9 +114,9 @@ describe(CollaboratorsManager, () => {
101
114
  })
102
115
 
103
116
  it('hides idle collaborators that are following us', () => {
104
- const presence = createPresence('peer')
117
+ const presence = createPresence(createUserId('peer'))
105
118
  presence.lastActivityTimestamp = Date.now() - 4000
106
- presence.followingUserId = 'current-user'
119
+ presence.followingUserId = createUserId('current-user')
107
120
  const { editor } = createEditor([presence])
108
121
  const manager = new CollaboratorsManager(editor)
109
122
 
@@ -111,9 +124,9 @@ describe(CollaboratorsManager, () => {
111
124
  })
112
125
 
113
126
  it('shows idle collaborators that are following us when they have a chat message', () => {
114
- const presence = createPresence('peer')
127
+ const presence = createPresence(createUserId('peer'))
115
128
  presence.lastActivityTimestamp = Date.now() - 4000
116
- presence.followingUserId = 'current-user'
129
+ presence.followingUserId = createUserId('current-user')
117
130
  presence.chatMessage = 'hi'
118
131
  const { editor } = createEditor([presence])
119
132
  const manager = new CollaboratorsManager(editor)
@@ -122,11 +135,25 @@ describe(CollaboratorsManager, () => {
122
135
  })
123
136
 
124
137
  it('shows idle collaborators that are not following us', () => {
125
- const presence = createPresence('peer')
138
+ const presence = createPresence(createUserId('peer'))
126
139
  presence.lastActivityTimestamp = Date.now() - 4000
127
140
  const { editor } = createEditor([presence])
128
141
  const manager = new CollaboratorsManager(editor)
129
142
 
130
143
  expect(manager.getVisibleCollaborators()).toHaveLength(1)
131
144
  })
145
+
146
+ it('shows newly-joined collaborators that have not recorded any activity yet', () => {
147
+ // A peer who has joined but not moved their pointer broadcasts the default
148
+ // `lastActivityTimestamp` of 0. They should still be treated as active so
149
+ // they appear in the people menu / face pile. See issue #9017.
150
+ const zero = createPresence(createUserId('zero'))
151
+ zero.lastActivityTimestamp = 0
152
+ const nullish = createPresence(createUserId('nullish'))
153
+ nullish.lastActivityTimestamp = null
154
+ const { editor } = createEditor([zero, nullish])
155
+ const manager = new CollaboratorsManager(editor)
156
+
157
+ expect(manager.getVisibleCollaborators()).toHaveLength(2)
158
+ })
132
159
  })