@tldraw/editor 3.11.0-canary.c79c9bec2242 → 3.11.0-canary.e37f515de668

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 (73) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/dist-cjs/index.d.ts +17 -9
  3. package/dist-cjs/index.js +1 -1
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +4 -4
  6. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  7. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +37 -25
  8. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
  9. package/dist-cjs/lib/config/TLUserPreferences.js +1 -1
  10. package/dist-cjs/lib/config/TLUserPreferences.js.map +1 -1
  11. package/dist-cjs/lib/config/createTLStore.js +2 -1
  12. package/dist-cjs/lib/config/createTLStore.js.map +2 -2
  13. package/dist-cjs/lib/constants.js +1 -1
  14. package/dist-cjs/lib/constants.js.map +2 -2
  15. package/dist-cjs/lib/editor/Editor.js +18 -10
  16. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  17. package/dist-cjs/lib/editor/managers/FocusManager.js +15 -0
  18. package/dist-cjs/lib/editor/managers/FocusManager.js.map +2 -2
  19. package/dist-cjs/lib/editor/managers/UserPreferencesManager.js +1 -1
  20. package/dist-cjs/lib/editor/managers/UserPreferencesManager.js.map +2 -2
  21. package/dist-cjs/lib/exports/exportToSvg.js.map +1 -1
  22. package/dist-cjs/lib/hooks/useLocalStore.js +3 -0
  23. package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
  24. package/dist-cjs/lib/license/Watermark.js +5 -0
  25. package/dist-cjs/lib/license/Watermark.js.map +2 -2
  26. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js +8 -0
  27. package/dist-cjs/lib/utils/sync/LocalIndexedDb.js.map +2 -2
  28. package/dist-cjs/version.js +3 -3
  29. package/dist-cjs/version.js.map +1 -1
  30. package/dist-esm/index.d.mts +17 -9
  31. package/dist-esm/index.mjs +4 -2
  32. package/dist-esm/index.mjs.map +2 -2
  33. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +4 -4
  34. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  35. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +37 -25
  36. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
  37. package/dist-esm/lib/config/TLUserPreferences.mjs +1 -1
  38. package/dist-esm/lib/config/TLUserPreferences.mjs.map +1 -1
  39. package/dist-esm/lib/config/createTLStore.mjs +2 -1
  40. package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
  41. package/dist-esm/lib/constants.mjs +1 -1
  42. package/dist-esm/lib/constants.mjs.map +2 -2
  43. package/dist-esm/lib/editor/Editor.mjs +18 -10
  44. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  45. package/dist-esm/lib/editor/managers/FocusManager.mjs +15 -0
  46. package/dist-esm/lib/editor/managers/FocusManager.mjs.map +2 -2
  47. package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs +1 -1
  48. package/dist-esm/lib/editor/managers/UserPreferencesManager.mjs.map +2 -2
  49. package/dist-esm/lib/exports/exportToSvg.mjs.map +1 -1
  50. package/dist-esm/lib/hooks/useLocalStore.mjs +3 -0
  51. package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
  52. package/dist-esm/lib/license/Watermark.mjs +5 -0
  53. package/dist-esm/lib/license/Watermark.mjs.map +2 -2
  54. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs +8 -0
  55. package/dist-esm/lib/utils/sync/LocalIndexedDb.mjs.map +2 -2
  56. package/dist-esm/version.mjs +3 -3
  57. package/dist-esm/version.mjs.map +1 -1
  58. package/editor.css +1 -1
  59. package/package.json +7 -7
  60. package/src/index.ts +4 -1
  61. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +4 -4
  62. package/src/lib/components/default-components/DefaultShapeIndicators.tsx +51 -28
  63. package/src/lib/config/TLUserPreferences.ts +1 -1
  64. package/src/lib/config/createTLStore.ts +1 -0
  65. package/src/lib/constants.ts +1 -1
  66. package/src/lib/editor/Editor.ts +20 -11
  67. package/src/lib/editor/managers/FocusManager.ts +18 -0
  68. package/src/lib/editor/managers/UserPreferencesManager.ts +1 -1
  69. package/src/lib/exports/exportToSvg.tsx +1 -1
  70. package/src/lib/hooks/useLocalStore.ts +3 -0
  71. package/src/lib/license/Watermark.tsx +5 -0
  72. package/src/lib/utils/sync/LocalIndexedDb.ts +9 -0
  73. package/src/version.ts +3 -3
@@ -4218,7 +4218,13 @@ export class Editor extends EventEmitter<TLEventMap> {
4218
4218
  : (assets as TLAsset[]).map((a) => a.id)
4219
4219
  if (ids.length <= 0) return this
4220
4220
 
4221
- this.run(() => this.store.remove(ids), { history: 'ignore' })
4221
+ this.run(
4222
+ () => {
4223
+ this.store.props.assets.remove?.(ids)
4224
+ this.store.remove(ids)
4225
+ },
4226
+ { history: 'ignore' }
4227
+ )
4222
4228
  return this
4223
4229
  }
4224
4230
 
@@ -6328,21 +6334,22 @@ export class Editor extends EventEmitter<TLEventMap> {
6328
6334
  *
6329
6335
  * @example
6330
6336
  * ```ts
6331
- * editor.stackShapes([box1, box2], 'horizontal', 32)
6332
- * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
6337
+ * editor.stackShapes([box1, box2], 'horizontal')
6338
+ * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal')
6333
6339
  * ```
6334
6340
  *
6335
6341
  * @param shapes - The shapes (or shape ids) to stack.
6336
6342
  * @param operation - Whether to stack horizontally or vertically.
6337
- * @param gap - The gap to leave between shapes.
6343
+ * @param gap - The gap to leave between shapes. By default, uses the editor's `adjacentShapeMargin` option.
6338
6344
  *
6339
6345
  * @public
6340
6346
  */
6341
6347
  stackShapes(
6342
6348
  shapes: TLShapeId[] | TLShape[],
6343
6349
  operation: 'horizontal' | 'vertical',
6344
- gap: number
6350
+ gap?: number
6345
6351
  ): this {
6352
+ const _gap = gap ?? this.options.adjacentShapeMargin
6346
6353
  const ids =
6347
6354
  typeof shapes[0] === 'string'
6348
6355
  ? (shapes as TLShapeId[])
@@ -6400,7 +6407,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6400
6407
  }
6401
6408
 
6402
6409
  const len = shapeClustersToStack.length
6403
- if ((gap === 0 && len < 3) || len < 2) return this
6410
+ if ((_gap === 0 && len < 3) || len < 2) return this
6404
6411
 
6405
6412
  let val: 'x' | 'y'
6406
6413
  let min: 'minX' | 'minY'
@@ -6421,7 +6428,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6421
6428
 
6422
6429
  let shapeGap: number = 0
6423
6430
 
6424
- if (gap === 0) {
6431
+ if (_gap === 0) {
6425
6432
  // note: this is not used in the current tldraw.com; there we use a specified stack
6426
6433
 
6427
6434
  const gaps: Record<number, number> = {}
@@ -6461,7 +6468,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6461
6468
  }
6462
6469
  } else {
6463
6470
  // If a gap was provided, then use that instead.
6464
- shapeGap = gap
6471
+ shapeGap = _gap
6465
6472
  }
6466
6473
 
6467
6474
  const changes: TLShapePartial[] = []
@@ -6500,17 +6507,19 @@ export class Editor extends EventEmitter<TLEventMap> {
6500
6507
  *
6501
6508
  * @example
6502
6509
  * ```ts
6503
- * editor.packShapes([box1, box2], 32)
6510
+ * editor.packShapes([box1, box2])
6504
6511
  * editor.packShapes(editor.getSelectedShapeIds(), 32)
6505
6512
  * ```
6506
6513
  *
6507
6514
  *
6508
6515
  * @param shapes - The shapes (or shape ids) to pack.
6509
- * @param gap - The padding to apply to the packed shapes. Defaults to 16.
6516
+ * @param gap - The padding to apply to the packed shapes. Defaults to the editor's `adjacentShapeMargin` option.
6510
6517
  */
6511
- packShapes(shapes: TLShapeId[] | TLShape[], gap: number): this {
6518
+ packShapes(shapes: TLShapeId[] | TLShape[], _gap?: number): this {
6512
6519
  if (this.getIsReadonly()) return this
6513
6520
 
6521
+ const gap = _gap ?? this.options.adjacentShapeMargin
6522
+
6514
6523
  const ids =
6515
6524
  typeof shapes[0] === 'string'
6516
6525
  ? (shapes as TLShapeId[])
@@ -30,6 +30,9 @@ export class FocusManager {
30
30
  editor.updateInstanceState({ isFocused: !!autoFocus })
31
31
  }
32
32
  this.updateContainerClass()
33
+
34
+ document.body.addEventListener('keydown', this.handleKeyDown.bind(this))
35
+ document.body.addEventListener('mousedown', this.handleMouseDown.bind(this))
33
36
  }
34
37
 
35
38
  /**
@@ -50,6 +53,19 @@ export class FocusManager {
50
53
  } else {
51
54
  container.classList.remove('tl-container__focused')
52
55
  }
56
+ container.classList.add('tl-container__no-focus-ring')
57
+ }
58
+
59
+ private handleKeyDown(keyEvent: KeyboardEvent) {
60
+ const container = this.editor.getContainer()
61
+ if (keyEvent.key === 'Tab') {
62
+ container.classList.remove('tl-container__no-focus-ring')
63
+ }
64
+ }
65
+
66
+ private handleMouseDown() {
67
+ const container = this.editor.getContainer()
68
+ container.classList.add('tl-container__no-focus-ring')
53
69
  }
54
70
 
55
71
  focus() {
@@ -62,6 +78,8 @@ export class FocusManager {
62
78
  }
63
79
 
64
80
  dispose() {
81
+ document.body.removeEventListener('keydown', this.handleKeyDown.bind(this))
82
+ document.body.removeEventListener('mousedown', this.handleMouseDown.bind(this))
65
83
  this.disposeSideEffectListener?.()
66
84
  }
67
85
  }
@@ -80,7 +80,7 @@ export class UserPreferencesManager {
80
80
  }
81
81
 
82
82
  @computed getName() {
83
- return this.user.userPreferences.get().name ?? defaultUserPreferences.name
83
+ return this.user.userPreferences.get().name?.trim() ?? defaultUserPreferences.name
84
84
  }
85
85
 
86
86
  @computed getLocale() {
@@ -62,7 +62,7 @@ export async function exportToSvg(
62
62
  const svg = renderTarget.firstElementChild
63
63
  assert(svg instanceof SVGSVGElement, 'Expected an SVG element')
64
64
 
65
- // And apply any changes to <foreignObject> elements that we need to make. Whilst we're in
65
+ // And apply any changes to <foreignObject> elements that we need to make. while we're in
66
66
  // the document, these elements work exactly as we'd expect from other dom elements - they
67
67
  // can load external resources, and any stylesheets in the document apply to them as we
68
68
  // would expect them to. But when we pull the SVG into its own file or draw it to a canvas
@@ -52,6 +52,9 @@ export function useLocalStore(
52
52
 
53
53
  return asset.props.src
54
54
  },
55
+ remove: async (assetIds) => {
56
+ await client.db.removeAssets(assetIds)
57
+ },
55
58
  ...rest.assets,
56
59
  }
57
60
 
@@ -157,8 +157,13 @@ To remove the watermark, please purchase a license at tldraw.dev.
157
157
  animation: delayed_link 0.2s forwards ease-in-out;
158
158
  animation-delay: 0.32s;
159
159
  }
160
+
161
+ .${className} > a:focus-visible {
162
+ opacity: 1;
163
+ }
160
164
  }
161
165
 
166
+
162
167
  @keyframes delayed_link {
163
168
  0% {
164
169
  cursor: inherit;
@@ -303,6 +303,15 @@ export class LocalIndexedDb {
303
303
  await assetsStore.put(blob, assetId)
304
304
  })
305
305
  }
306
+
307
+ async removeAssets(assetId: string[]) {
308
+ await this.tx('readwrite', [Table.Assets], async (tx) => {
309
+ const assetsStore = tx.objectStore(Table.Assets)
310
+ for (const id of assetId) {
311
+ await assetsStore.delete(id)
312
+ }
313
+ })
314
+ }
306
315
  }
307
316
 
308
317
  /** @internal */
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '3.11.0-canary.c79c9bec2242'
4
+ export const version = '3.11.0-canary.e37f515de668'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-03-12T11:32:29.935Z',
8
- patch: '2025-03-12T11:32:29.935Z',
7
+ minor: '2025-03-17T14:55:13.953Z',
8
+ patch: '2025-03-17T14:55:13.953Z',
9
9
  }