@tldraw/editor 3.11.0-canary.271f68c07747 → 3.11.0-canary.3758de89732a

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 (28) hide show
  1. package/dist-cjs/index.d.ts +16 -8
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/index.js.map +2 -2
  4. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js +4 -4
  5. package/dist-cjs/lib/components/default-components/DefaultShapeIndicator.js.map +2 -2
  6. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js +37 -25
  7. package/dist-cjs/lib/components/default-components/DefaultShapeIndicators.js.map +2 -2
  8. package/dist-cjs/lib/editor/Editor.js +11 -9
  9. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  10. package/dist-cjs/version.js +3 -3
  11. package/dist-cjs/version.js.map +1 -1
  12. package/dist-esm/index.d.mts +16 -8
  13. package/dist-esm/index.mjs +4 -2
  14. package/dist-esm/index.mjs.map +2 -2
  15. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs +4 -4
  16. package/dist-esm/lib/components/default-components/DefaultShapeIndicator.mjs.map +2 -2
  17. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs +37 -25
  18. package/dist-esm/lib/components/default-components/DefaultShapeIndicators.mjs.map +2 -2
  19. package/dist-esm/lib/editor/Editor.mjs +11 -9
  20. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  21. package/dist-esm/version.mjs +3 -3
  22. package/dist-esm/version.mjs.map +1 -1
  23. package/package.json +7 -7
  24. package/src/index.ts +4 -1
  25. package/src/lib/components/default-components/DefaultShapeIndicator.tsx +4 -4
  26. package/src/lib/components/default-components/DefaultShapeIndicators.tsx +51 -28
  27. package/src/lib/editor/Editor.ts +13 -10
  28. package/src/version.ts +3 -3
@@ -1,8 +1,8 @@
1
- const version = "3.11.0-canary.271f68c07747";
1
+ const version = "3.11.0-canary.3758de89732a";
2
2
  const publishDates = {
3
3
  major: "2024-09-13T14:36:29.063Z",
4
- minor: "2025-03-14T09:49:25.689Z",
5
- patch: "2025-03-14T09:49:25.689Z"
4
+ minor: "2025-03-15T13:28:31.594Z",
5
+ patch: "2025-03-15T13:28:31.594Z"
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 = '3.11.0-canary.271f68c07747'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-14T09:49:25.689Z',\n\tpatch: '2025-03-14T09:49:25.689Z',\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 = '3.11.0-canary.3758de89732a'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-03-15T13:28:31.594Z',\n\tpatch: '2025-03-15T13:28:31.594Z',\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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "A tiny little drawing app (editor).",
4
- "version": "3.11.0-canary.271f68c07747",
4
+ "version": "3.11.0-canary.3758de89732a",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -48,12 +48,12 @@
48
48
  "@tiptap/core": "^2.9.1",
49
49
  "@tiptap/pm": "^2.9.1",
50
50
  "@tiptap/react": "^2.9.1",
51
- "@tldraw/state": "3.11.0-canary.271f68c07747",
52
- "@tldraw/state-react": "3.11.0-canary.271f68c07747",
53
- "@tldraw/store": "3.11.0-canary.271f68c07747",
54
- "@tldraw/tlschema": "3.11.0-canary.271f68c07747",
55
- "@tldraw/utils": "3.11.0-canary.271f68c07747",
56
- "@tldraw/validate": "3.11.0-canary.271f68c07747",
51
+ "@tldraw/state": "3.11.0-canary.3758de89732a",
52
+ "@tldraw/state-react": "3.11.0-canary.3758de89732a",
53
+ "@tldraw/store": "3.11.0-canary.3758de89732a",
54
+ "@tldraw/tlschema": "3.11.0-canary.3758de89732a",
55
+ "@tldraw/utils": "3.11.0-canary.3758de89732a",
56
+ "@tldraw/validate": "3.11.0-canary.3758de89732a",
57
57
  "@types/core-js": "^2.5.8",
58
58
  "@use-gesture/react": "^10.3.1",
59
59
  "classnames": "^2.5.1",
package/src/index.ts CHANGED
@@ -109,7 +109,10 @@ export {
109
109
  type TLShapeIndicatorProps,
110
110
  } from './lib/components/default-components/DefaultShapeIndicator'
111
111
  export { type TLShapeIndicatorErrorFallbackComponent } from './lib/components/default-components/DefaultShapeIndicatorErrorFallback'
112
- export { DefaultShapeIndicators } from './lib/components/default-components/DefaultShapeIndicators'
112
+ export {
113
+ DefaultShapeIndicators,
114
+ type TLShapeIndicatorsProps,
115
+ } from './lib/components/default-components/DefaultShapeIndicators'
113
116
  export {
114
117
  DefaultSnapIndicator,
115
118
  type TLSnapIndicatorProps,
@@ -9,15 +9,15 @@ import { useEditorComponents } from '../../hooks/useEditorComponents'
9
9
  import { OptionalErrorBoundary } from '../ErrorBoundary'
10
10
 
11
11
  // need an extra layer of indirection here to allow hooks to be used inside the indicator render
12
- const EvenInnererIndicator = ({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {
12
+ const EvenInnererIndicator = memo(({ shape, util }: { shape: TLShape; util: ShapeUtil<any> }) => {
13
13
  return useStateTracking('Indicator: ' + shape.type, () =>
14
14
  // always fetch the latest shape from the store even if the props/meta have not changed, to avoid
15
15
  // calling the render method with stale data.
16
16
  util.indicator(util.editor.store.unsafeGetWithoutCapture(shape.id) as TLShape)
17
17
  )
18
- }
18
+ })
19
19
 
20
- const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => {
20
+ const InnerIndicator = memo(({ editor, id }: { editor: Editor; id: TLShapeId }) => {
21
21
  const shape = useValue('shape for indicator', () => editor.store.get(id), [editor, id])
22
22
 
23
23
  const { ShapeIndicatorErrorFallback } = useEditorComponents()
@@ -34,7 +34,7 @@ const InnerIndicator = ({ editor, id }: { editor: Editor; id: TLShapeId }) => {
34
34
  <EvenInnererIndicator key={shape.id} shape={shape} util={editor.getShapeUtil(shape)} />
35
35
  </OptionalErrorBoundary>
36
36
  )
37
- }
37
+ })
38
38
 
39
39
  /** @public */
40
40
  export interface TLShapeIndicatorProps {
@@ -4,10 +4,24 @@ import { memo, useRef } from 'react'
4
4
  import { useEditor } from '../../hooks/useEditor'
5
5
  import { useEditorComponents } from '../../hooks/useEditorComponents'
6
6
 
7
+ /** @public */
8
+ export interface TLShapeIndicatorsProps {
9
+ /** Whether to hide all of the indicators */
10
+ hideAll?: boolean
11
+ /** Whether to show all of the indicators */
12
+ showAll?: boolean
13
+ }
14
+
7
15
  /** @public @react */
8
- export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
16
+ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators({
17
+ hideAll,
18
+ showAll,
19
+ }: TLShapeIndicatorsProps) {
9
20
  const editor = useEditor()
10
21
 
22
+ if (hideAll && showAll)
23
+ throw Error('You cannot set both hideAll and showAll props to true, cmon now')
24
+
11
25
  const rPreviousSelectedShapeIds = useRef<Set<TLShapeId>>(new Set())
12
26
 
13
27
  const idsToDisplay = useValue(
@@ -16,33 +30,38 @@ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
16
30
  const prev = rPreviousSelectedShapeIds.current
17
31
  const next = new Set<TLShapeId>()
18
32
 
19
- if (
20
- // We only show indicators when in the following states...
21
- editor.isInAny(
22
- 'select.idle',
23
- 'select.brushing',
24
- 'select.scribble_brushing',
25
- 'select.editing_shape',
26
- 'select.pointing_shape',
27
- 'select.pointing_selection',
28
- 'select.pointing_handle'
29
- ) &&
30
- // ...but we hide indicators when we've just changed a style (so that the user can see the change)
31
- !editor.getInstanceState().isChangingStyle
32
- ) {
33
- // We always want to show indicators for the selected shapes, if any
34
- const selected = editor.getSelectedShapeIds()
35
- for (const id of selected) {
36
- next.add(id)
37
- }
33
+ const isChangingStyle = editor.getInstanceState().isChangingStyle
34
+
35
+ // todo: this is tldraw specific and is duplicated at the tldraw layer. What should we do here instead?
36
+ const isInSelectState = editor.isInAny(
37
+ 'select.idle',
38
+ 'select.brushing',
39
+ 'select.scribble_brushing',
40
+ 'select.editing_shape',
41
+ 'select.pointing_shape',
42
+ 'select.pointing_selection',
43
+ 'select.pointing_handle'
44
+ )
45
+
46
+ // We hide all indicators if we're changing style or in certain interactions
47
+ // todo: move this to some kind of Tool.hideIndicators property
48
+ if (isChangingStyle || !isInSelectState) {
49
+ rPreviousSelectedShapeIds.current = next
50
+ return next
51
+ }
52
+
53
+ // We always want to show indicators for the selected shapes, if any
54
+ const selected = editor.getSelectedShapeIds()
55
+ for (const id of selected) {
56
+ next.add(id)
57
+ }
38
58
 
39
- // If we're idle or editing a shape, we want to also show an indicator for the hovered shape, if any
40
- if (editor.isInAny('select.idle', 'select.editing_shape')) {
41
- const instanceState = editor.getInstanceState()
42
- if (instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {
43
- const hovered = editor.getHoveredShapeId()
44
- if (hovered) next.add(hovered)
45
- }
59
+ // If we're idle or editing a shape, we want to also show an indicator for the hovered shape, if any
60
+ if (editor.isInAny('select.idle', 'select.editing_shape')) {
61
+ const instanceState = editor.getInstanceState()
62
+ if (instanceState.isHoveringCanvas && !instanceState.isCoarsePointer) {
63
+ const hovered = editor.getHoveredShapeId()
64
+ if (hovered) next.add(hovered)
46
65
  }
47
66
  }
48
67
 
@@ -75,6 +94,10 @@ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators() {
75
94
  if (!ShapeIndicator) return null
76
95
 
77
96
  return renderingShapes.map(({ id }) => (
78
- <ShapeIndicator key={id + '_indicator'} shapeId={id} hidden={!idsToDisplay.has(id)} />
97
+ <ShapeIndicator
98
+ key={id + '_indicator'}
99
+ shapeId={id}
100
+ hidden={!showAll && (hideAll || !idsToDisplay.has(id))}
101
+ />
79
102
  ))
80
103
  })
@@ -6328,21 +6328,22 @@ export class Editor extends EventEmitter<TLEventMap> {
6328
6328
  *
6329
6329
  * @example
6330
6330
  * ```ts
6331
- * editor.stackShapes([box1, box2], 'horizontal', 32)
6332
- * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal', 32)
6331
+ * editor.stackShapes([box1, box2], 'horizontal')
6332
+ * editor.stackShapes(editor.getSelectedShapeIds(), 'horizontal')
6333
6333
  * ```
6334
6334
  *
6335
6335
  * @param shapes - The shapes (or shape ids) to stack.
6336
6336
  * @param operation - Whether to stack horizontally or vertically.
6337
- * @param gap - The gap to leave between shapes.
6337
+ * @param gap - The gap to leave between shapes. By default, uses the editor's `adjacentShapeMargin` option.
6338
6338
  *
6339
6339
  * @public
6340
6340
  */
6341
6341
  stackShapes(
6342
6342
  shapes: TLShapeId[] | TLShape[],
6343
6343
  operation: 'horizontal' | 'vertical',
6344
- gap: number
6344
+ gap?: number
6345
6345
  ): this {
6346
+ const _gap = gap ?? this.options.adjacentShapeMargin
6346
6347
  const ids =
6347
6348
  typeof shapes[0] === 'string'
6348
6349
  ? (shapes as TLShapeId[])
@@ -6400,7 +6401,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6400
6401
  }
6401
6402
 
6402
6403
  const len = shapeClustersToStack.length
6403
- if ((gap === 0 && len < 3) || len < 2) return this
6404
+ if ((_gap === 0 && len < 3) || len < 2) return this
6404
6405
 
6405
6406
  let val: 'x' | 'y'
6406
6407
  let min: 'minX' | 'minY'
@@ -6421,7 +6422,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6421
6422
 
6422
6423
  let shapeGap: number = 0
6423
6424
 
6424
- if (gap === 0) {
6425
+ if (_gap === 0) {
6425
6426
  // note: this is not used in the current tldraw.com; there we use a specified stack
6426
6427
 
6427
6428
  const gaps: Record<number, number> = {}
@@ -6461,7 +6462,7 @@ export class Editor extends EventEmitter<TLEventMap> {
6461
6462
  }
6462
6463
  } else {
6463
6464
  // If a gap was provided, then use that instead.
6464
- shapeGap = gap
6465
+ shapeGap = _gap
6465
6466
  }
6466
6467
 
6467
6468
  const changes: TLShapePartial[] = []
@@ -6500,17 +6501,19 @@ export class Editor extends EventEmitter<TLEventMap> {
6500
6501
  *
6501
6502
  * @example
6502
6503
  * ```ts
6503
- * editor.packShapes([box1, box2], 32)
6504
+ * editor.packShapes([box1, box2])
6504
6505
  * editor.packShapes(editor.getSelectedShapeIds(), 32)
6505
6506
  * ```
6506
6507
  *
6507
6508
  *
6508
6509
  * @param shapes - The shapes (or shape ids) to pack.
6509
- * @param gap - The padding to apply to the packed shapes. Defaults to 16.
6510
+ * @param gap - The padding to apply to the packed shapes. Defaults to the editor's `adjacentShapeMargin` option.
6510
6511
  */
6511
- packShapes(shapes: TLShapeId[] | TLShape[], gap: number): this {
6512
+ packShapes(shapes: TLShapeId[] | TLShape[], _gap?: number): this {
6512
6513
  if (this.getIsReadonly()) return this
6513
6514
 
6515
+ const gap = _gap ?? this.options.adjacentShapeMargin
6516
+
6514
6517
  const ids =
6515
6518
  typeof shapes[0] === 'string'
6516
6519
  ? (shapes as TLShapeId[])
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.271f68c07747'
4
+ export const version = '3.11.0-canary.3758de89732a'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-03-14T09:49:25.689Z',
8
- patch: '2025-03-14T09:49:25.689Z',
7
+ minor: '2025-03-15T13:28:31.594Z',
8
+ patch: '2025-03-15T13:28:31.594Z',
9
9
  }