@tldraw/editor 3.12.0-canary.688ddcb6ad5c → 3.12.0-canary.71368dc000db

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.
@@ -1,8 +1,8 @@
1
- const version = "3.12.0-canary.688ddcb6ad5c";
1
+ const version = "3.12.0-canary.71368dc000db";
2
2
  const publishDates = {
3
3
  major: "2024-09-13T14:36:29.063Z",
4
- minor: "2025-04-03T09:18:45.524Z",
5
- patch: "2025-04-03T09:18:45.524Z"
4
+ minor: "2025-04-03T09:35:34.669Z",
5
+ patch: "2025-04-03T09:35:34.669Z"
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.12.0-canary.688ddcb6ad5c'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-04-03T09:18:45.524Z',\n\tpatch: '2025-04-03T09:18:45.524Z',\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.12.0-canary.71368dc000db'\nexport const publishDates = {\n\tmajor: '2024-09-13T14:36:29.063Z',\n\tminor: '2025-04-03T09:35:34.669Z',\n\tpatch: '2025-04-03T09:35:34.669Z',\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.12.0-canary.688ddcb6ad5c",
4
+ "version": "3.12.0-canary.71368dc000db",
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.12.0-canary.688ddcb6ad5c",
52
- "@tldraw/state-react": "3.12.0-canary.688ddcb6ad5c",
53
- "@tldraw/store": "3.12.0-canary.688ddcb6ad5c",
54
- "@tldraw/tlschema": "3.12.0-canary.688ddcb6ad5c",
55
- "@tldraw/utils": "3.12.0-canary.688ddcb6ad5c",
56
- "@tldraw/validate": "3.12.0-canary.688ddcb6ad5c",
51
+ "@tldraw/state": "3.12.0-canary.71368dc000db",
52
+ "@tldraw/state-react": "3.12.0-canary.71368dc000db",
53
+ "@tldraw/store": "3.12.0-canary.71368dc000db",
54
+ "@tldraw/tlschema": "3.12.0-canary.71368dc000db",
55
+ "@tldraw/utils": "3.12.0-canary.71368dc000db",
56
+ "@tldraw/validate": "3.12.0-canary.71368dc000db",
57
57
  "@types/core-js": "^2.5.8",
58
58
  "@use-gesture/react": "^10.3.1",
59
59
  "classnames": "^2.5.1",
@@ -191,11 +191,33 @@ export interface TldrawEditorBaseProps {
191
191
  /**
192
192
  * Predicate for whether or not a shape should be hidden.
193
193
  *
194
+ * @deprecated Use {@link TldrawEditorBaseProps#getShapeVisibility} instead.
195
+ */
196
+ isShapeHidden?(shape: TLShape, editor: Editor): boolean
197
+
198
+ /**
199
+ * Provides a way to hide shapes.
200
+ *
194
201
  * Hidden shapes will not render in the editor, and they will not be eligible for hit test via
195
202
  * {@link Editor#getShapeAtPoint} and {@link Editor#getShapesAtPoint}. But otherwise they will
196
203
  * remain in the store and participate in all other operations.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}
208
+ * ```
209
+ *
210
+ * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.
211
+ * - `'hidden'` - The shape will be hidden.
212
+ * - `'visible'` - The shape will be visible.
213
+ *
214
+ * @param shape - The shape to check.
215
+ * @param editor - The editor instance.
197
216
  */
198
- isShapeHidden?(shape: TLShape, editor: Editor): boolean
217
+ getShapeVisibility?(
218
+ shape: TLShape,
219
+ editor: Editor
220
+ ): 'visible' | 'hidden' | 'inherit' | null | undefined
199
221
 
200
222
  /**
201
223
  * The URLs for the fonts to use in the editor.
@@ -387,7 +409,9 @@ function TldrawEditorWithReadyStore({
387
409
  options,
388
410
  licenseKey,
389
411
  deepLinks: _deepLinks,
412
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
390
413
  isShapeHidden,
414
+ getShapeVisibility,
391
415
  assetUrls,
392
416
  }: Required<
393
417
  TldrawEditorProps & {
@@ -447,6 +471,7 @@ function TldrawEditorWithReadyStore({
447
471
  options,
448
472
  licenseKey,
449
473
  isShapeHidden,
474
+ getShapeVisibility,
450
475
  fontAssetUrls: assetUrls?.fonts,
451
476
  })
452
477
 
@@ -482,6 +507,7 @@ function TldrawEditorWithReadyStore({
482
507
  setEditor,
483
508
  licenseKey,
484
509
  isShapeHidden,
510
+ getShapeVisibility,
485
511
  textOptions,
486
512
  assetUrls,
487
513
  ]
@@ -241,10 +241,33 @@ export interface TLEditorOptions {
241
241
  fontAssetUrls?: { [key: string]: string | undefined }
242
242
  /**
243
243
  * A predicate that should return true if the given shape should be hidden.
244
+ *
245
+ * @deprecated Use {@link Editor#getShapeVisibility} instead.
246
+ *
244
247
  * @param shape - The shape to check.
245
248
  * @param editor - The editor instance.
246
249
  */
247
250
  isShapeHidden?(shape: TLShape, editor: Editor): boolean
251
+
252
+ /**
253
+ * Provides a way to hide shapes.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * getShapeVisibility={(shape, editor) => shape.meta.hidden ? 'hidden' : 'inherit'}
258
+ * ```
259
+ *
260
+ * - `'inherit' | undefined` - (default) The shape will be visible unless its parent is hidden.
261
+ * - `'hidden'` - The shape will be hidden.
262
+ * - `'visible'` - The shape will be visible.
263
+ *
264
+ * @param shape - The shape to check.
265
+ * @param editor - The editor instance.
266
+ */
267
+ getShapeVisibility?(
268
+ shape: TLShape,
269
+ editor: Editor
270
+ ): 'visible' | 'hidden' | 'inherit' | null | undefined
248
271
  }
249
272
 
250
273
  /**
@@ -281,12 +304,21 @@ export class Editor extends EventEmitter<TLEventMap> {
281
304
  autoFocus,
282
305
  inferDarkMode,
283
306
  options,
307
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
284
308
  isShapeHidden,
309
+ getShapeVisibility,
285
310
  fontAssetUrls,
286
311
  }: TLEditorOptions) {
287
312
  super()
313
+ assert(
314
+ !(isShapeHidden && getShapeVisibility),
315
+ 'Cannot use both isShapeHidden and getShapeVisibility'
316
+ )
288
317
 
289
- this._isShapeHiddenPredicate = isShapeHidden
318
+ this._getShapeVisibility = isShapeHidden
319
+ ? // eslint-disable-next-line @typescript-eslint/no-deprecated
320
+ (shape: TLShape, editor: Editor) => (isShapeHidden(shape, editor) ? 'hidden' : 'inherit')
321
+ : getShapeVisibility
290
322
 
291
323
  this.options = { ...defaultTldrawOptions, ...options }
292
324
 
@@ -773,18 +805,22 @@ export class Editor extends EventEmitter<TLEventMap> {
773
805
  }
774
806
  }
775
807
 
776
- private readonly _isShapeHiddenPredicate?: (shape: TLShape, editor: Editor) => boolean
808
+ private readonly _getShapeVisibility?: TLEditorOptions['getShapeVisibility']
777
809
  @computed
778
810
  private getIsShapeHiddenCache() {
779
- if (!this._isShapeHiddenPredicate) return null
811
+ if (!this._getShapeVisibility) return null
780
812
  return this.store.createComputedCache<boolean, TLShape>('isShapeHidden', (shape: TLShape) => {
781
- const hiddenParent = this.findShapeAncestor(shape, (p) => this.isShapeHidden(p))
782
- if (hiddenParent) return true
783
- return this._isShapeHiddenPredicate!(shape, this) ?? false
813
+ const visibility = this._getShapeVisibility!(shape, this)
814
+ const isParentHidden = PageRecordType.isId(shape.parentId)
815
+ ? false
816
+ : this.isShapeHidden(shape.parentId)
817
+
818
+ if (isParentHidden) return visibility !== 'visible'
819
+ return visibility === 'hidden'
784
820
  })
785
821
  }
786
822
  isShapeHidden(shapeOrId: TLShape | TLShapeId): boolean {
787
- if (!this._isShapeHiddenPredicate) return false
823
+ if (!this._getShapeVisibility) return false
788
824
  return !!this.getIsShapeHiddenCache!()!.get(
789
825
  typeof shapeOrId === 'string' ? shapeOrId : shapeOrId.id
790
826
  )
@@ -3711,7 +3747,15 @@ export class Editor extends EventEmitter<TLEventMap> {
3711
3747
  const addShapeById = (id: TLShapeId, opacity: number, isAncestorErasing: boolean) => {
3712
3748
  const shape = this.getShape(id)
3713
3749
  if (!shape) return
3714
- if (this.isShapeHidden(shape)) return
3750
+
3751
+ if (this.isShapeHidden(shape)) {
3752
+ // process children just in case they are overriding the hidden state
3753
+ const isErasing = isAncestorErasing || erasingShapeIds.includes(id)
3754
+ for (const childId of this.getSortedChildIdsForParent(id)) {
3755
+ addShapeById(childId, opacity, isErasing)
3756
+ }
3757
+ return
3758
+ }
3715
3759
 
3716
3760
  opacity *= shape.opacity
3717
3761
  let isShapeErasing = false
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.12.0-canary.688ddcb6ad5c'
4
+ export const version = '3.12.0-canary.71368dc000db'
5
5
  export const publishDates = {
6
6
  major: '2024-09-13T14:36:29.063Z',
7
- minor: '2025-04-03T09:18:45.524Z',
8
- patch: '2025-04-03T09:18:45.524Z',
7
+ minor: '2025-04-03T09:35:34.669Z',
8
+ patch: '2025-04-03T09:35:34.669Z',
9
9
  }