@tldraw/tlschema 4.3.0-canary.fd6b7f2a8adc → 4.3.0-next.2b3bfbba757b
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.
- package/dist-cjs/bindings/TLBaseBinding.js.map +2 -2
- package/dist-cjs/createTLSchema.js.map +2 -2
- package/dist-cjs/index.d.ts +37 -160
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/records/TLAsset.js.map +1 -1
- package/dist-cjs/records/TLBinding.js.map +2 -2
- package/dist-cjs/records/TLShape.js.map +2 -2
- package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
- package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
- package/dist-cjs/store-migrations.js +1 -1
- package/dist-cjs/store-migrations.js.map +2 -2
- package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
- package/dist-esm/createTLSchema.mjs.map +2 -2
- package/dist-esm/index.d.mts +37 -160
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/records/TLAsset.mjs.map +1 -1
- package/dist-esm/records/TLBinding.mjs.map +2 -2
- package/dist-esm/records/TLShape.mjs.map +2 -2
- package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
- package/dist-esm/store-migrations.mjs +1 -1
- package/dist-esm/store-migrations.mjs.map +2 -2
- package/package.json +5 -5
- package/src/bindings/TLBaseBinding.ts +14 -25
- package/src/createTLSchema.ts +2 -8
- package/src/index.ts +0 -6
- package/src/records/TLAsset.ts +2 -2
- package/src/records/TLBinding.ts +23 -65
- package/src/records/TLRecord.test.ts +5 -17
- package/src/records/TLShape.ts +5 -100
- package/src/shapes/ShapeWithCrop.ts +2 -2
- package/src/shapes/TLBaseShape.ts +10 -34
- package/src/store-migrations.ts +1 -2
package/dist-esm/index.d.mts
CHANGED
|
@@ -1478,24 +1478,6 @@ export declare class EnumStyleProp<T> extends StyleProp<T> {
|
|
|
1478
1478
|
/* Excluded from this release type: __constructor */
|
|
1479
1479
|
}
|
|
1480
1480
|
|
|
1481
|
-
/**
|
|
1482
|
-
* Extract a shape type by its props.
|
|
1483
|
-
*
|
|
1484
|
-
* This utility type takes a props object type and returns the corresponding shape type
|
|
1485
|
-
* from the TLShape union whose props match the given type.
|
|
1486
|
-
*
|
|
1487
|
-
* @example
|
|
1488
|
-
* ```ts
|
|
1489
|
-
* type MyShape = ExtractShapeByProps<{ w: number; h: number }>
|
|
1490
|
-
* // MyShape is now the type of shape(s) that have props with w and h as numbers
|
|
1491
|
-
* ```
|
|
1492
|
-
*
|
|
1493
|
-
* @public
|
|
1494
|
-
*/
|
|
1495
|
-
export declare type ExtractShapeByProps<P> = Extract<TLShape, {
|
|
1496
|
-
props: P;
|
|
1497
|
-
}>;
|
|
1498
|
-
|
|
1499
1481
|
/**
|
|
1500
1482
|
* Migration sequence for frame shape properties across different schema versions.
|
|
1501
1483
|
* Handles adding color properties to existing frame shapes.
|
|
@@ -2617,7 +2599,7 @@ export declare const shapeIdValidator: T.Validator<TLShapeId>;
|
|
|
2617
2599
|
*
|
|
2618
2600
|
* @public
|
|
2619
2601
|
*/
|
|
2620
|
-
export declare type ShapeWithCrop =
|
|
2602
|
+
export declare type ShapeWithCrop = TLBaseShape<string, {
|
|
2621
2603
|
crop: null | TLShapeCrop;
|
|
2622
2604
|
h: number;
|
|
2623
2605
|
w: number;
|
|
@@ -3158,8 +3140,10 @@ export declare type TLAssetPartial<T extends TLAsset = TLAsset> = T extends T ?
|
|
|
3158
3140
|
*
|
|
3159
3141
|
* @public
|
|
3160
3142
|
*/
|
|
3161
|
-
export declare type TLAssetShape =
|
|
3162
|
-
|
|
3143
|
+
export declare type TLAssetShape = Extract<TLShape, {
|
|
3144
|
+
props: {
|
|
3145
|
+
assetId: TLAssetId;
|
|
3146
|
+
};
|
|
3163
3147
|
}>;
|
|
3164
3148
|
|
|
3165
3149
|
/**
|
|
@@ -3269,41 +3253,33 @@ export declare interface TLBaseAsset<Type extends string, Props> extends BaseRec
|
|
|
3269
3253
|
* Base interface for all binding types in tldraw. Bindings represent relationships
|
|
3270
3254
|
* between shapes, such as arrows connecting to other shapes or organizational connections.
|
|
3271
3255
|
*
|
|
3272
|
-
* All
|
|
3256
|
+
* All bindings extend this base interface with specific type and property definitions.
|
|
3273
3257
|
* The binding system enables shapes to maintain relationships that persist through
|
|
3274
3258
|
* transformations, movements, and other operations.
|
|
3275
3259
|
*
|
|
3276
|
-
* Custom bindings should be defined by augmenting the TLGlobalBindingPropsMap type and getting the binding type from the TLBinding type.
|
|
3277
|
-
*
|
|
3278
3260
|
* @param Type - String literal type identifying the specific binding type (e.g., 'arrow')
|
|
3279
3261
|
* @param Props - Object containing binding-specific properties and configuration
|
|
3280
3262
|
*
|
|
3281
3263
|
* @example
|
|
3282
3264
|
* ```ts
|
|
3283
|
-
* // Define a
|
|
3284
|
-
* interface
|
|
3265
|
+
* // Define a custom binding type
|
|
3266
|
+
* interface MyCustomBinding extends TLBaseBinding<'custom', MyCustomProps> {}
|
|
3285
3267
|
*
|
|
3286
|
-
* interface
|
|
3287
|
-
*
|
|
3288
|
-
*
|
|
3289
|
-
* isExact: boolean
|
|
3290
|
-
* isPrecise: boolean
|
|
3291
|
-
* snap: ElbowArrowSnap
|
|
3268
|
+
* interface MyCustomProps {
|
|
3269
|
+
* strength: number
|
|
3270
|
+
* color: string
|
|
3292
3271
|
* }
|
|
3293
3272
|
*
|
|
3294
3273
|
* // Create a binding instance
|
|
3295
|
-
* const
|
|
3274
|
+
* const binding: MyCustomBinding = {
|
|
3296
3275
|
* id: 'binding:abc123',
|
|
3297
3276
|
* typeName: 'binding',
|
|
3298
|
-
* type: '
|
|
3277
|
+
* type: 'custom',
|
|
3299
3278
|
* fromId: 'shape:source1',
|
|
3300
3279
|
* toId: 'shape:target1',
|
|
3301
3280
|
* props: {
|
|
3302
|
-
*
|
|
3303
|
-
*
|
|
3304
|
-
* isExact: false,
|
|
3305
|
-
* isPrecise: true,
|
|
3306
|
-
* snap: 'edge'
|
|
3281
|
+
* strength: 0.8,
|
|
3282
|
+
* color: 'red'
|
|
3307
3283
|
* },
|
|
3308
3284
|
* meta: {}
|
|
3309
3285
|
* }
|
|
@@ -3311,9 +3287,7 @@ export declare interface TLBaseAsset<Type extends string, Props> extends BaseRec
|
|
|
3311
3287
|
*
|
|
3312
3288
|
* @public
|
|
3313
3289
|
*/
|
|
3314
|
-
export declare interface TLBaseBinding<Type extends string, Props extends object> {
|
|
3315
|
-
readonly id: TLBindingId;
|
|
3316
|
-
readonly typeName: 'binding';
|
|
3290
|
+
export declare interface TLBaseBinding<Type extends string, Props extends object> extends BaseRecord<'binding', TLBindingId> {
|
|
3317
3291
|
/** The specific type of this binding (e.g., 'arrow', 'custom') */
|
|
3318
3292
|
type: Type;
|
|
3319
3293
|
/** ID of the source shape in this binding relationship */
|
|
@@ -3330,37 +3304,18 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3330
3304
|
* Base interface for all shapes in tldraw.
|
|
3331
3305
|
*
|
|
3332
3306
|
* This interface defines the common properties that all shapes share, regardless of their
|
|
3333
|
-
* specific type. Every
|
|
3334
|
-
*
|
|
3335
|
-
*
|
|
3336
|
-
*
|
|
3337
|
-
*
|
|
3338
|
-
*
|
|
3339
|
-
* // Define a default shape type
|
|
3340
|
-
* interface TLArrowShape extends TLBaseShape<'arrow', {
|
|
3341
|
-
* kind: TLArrowShapeKind
|
|
3342
|
-
* labelColor: TLDefaultColorStyle
|
|
3343
|
-
* color: TLDefaultColorStyle
|
|
3344
|
-
* fill: TLDefaultFillStyle
|
|
3345
|
-
* dash: TLDefaultDashStyle
|
|
3346
|
-
* size: TLDefaultSizeStyle
|
|
3347
|
-
* arrowheadStart: TLArrowShapeArrowheadStyle
|
|
3348
|
-
* arrowheadEnd: TLArrowShapeArrowheadStyle
|
|
3349
|
-
* font: TLDefaultFontStyle
|
|
3350
|
-
* start: VecModel
|
|
3351
|
-
* end: VecModel
|
|
3352
|
-
* bend: number
|
|
3353
|
-
* richText: TLRichText
|
|
3354
|
-
* labelPosition: number
|
|
3355
|
-
* scale: number
|
|
3356
|
-
* elbowMidPoint: number
|
|
3357
|
-
* }> {}
|
|
3307
|
+
* specific type. Every shape extends this base with additional type-specific properties.
|
|
3308
|
+
*
|
|
3309
|
+
* @example
|
|
3310
|
+
* ```ts
|
|
3311
|
+
* // Define a custom shape type
|
|
3312
|
+
* interface MyCustomShape extends TLBaseShape<'custom', { size: number; color: string }> {}
|
|
3358
3313
|
*
|
|
3359
3314
|
* // Create a shape instance
|
|
3360
|
-
* const
|
|
3315
|
+
* const myShape: MyCustomShape = {
|
|
3361
3316
|
* id: 'shape:abc123',
|
|
3362
3317
|
* typeName: 'shape',
|
|
3363
|
-
* type: '
|
|
3318
|
+
* type: 'custom',
|
|
3364
3319
|
* x: 100,
|
|
3365
3320
|
* y: 200,
|
|
3366
3321
|
* rotation: 0,
|
|
@@ -3369,10 +3324,8 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3369
3324
|
* isLocked: false,
|
|
3370
3325
|
* opacity: 1,
|
|
3371
3326
|
* props: {
|
|
3372
|
-
*
|
|
3373
|
-
*
|
|
3374
|
-
* end: { x: 100, y: 100 },
|
|
3375
|
-
* // ... other props
|
|
3327
|
+
* size: 50,
|
|
3328
|
+
* color: 'blue'
|
|
3376
3329
|
* },
|
|
3377
3330
|
* meta: {}
|
|
3378
3331
|
* }
|
|
@@ -3380,9 +3333,7 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3380
3333
|
*
|
|
3381
3334
|
* @public
|
|
3382
3335
|
*/
|
|
3383
|
-
export declare interface TLBaseShape<Type extends string, Props extends object> {
|
|
3384
|
-
readonly id: TLShapeId;
|
|
3385
|
-
readonly typeName: 'shape';
|
|
3336
|
+
export declare interface TLBaseShape<Type extends string, Props extends object> extends BaseRecord<'shape', TLShapeId> {
|
|
3386
3337
|
type: Type;
|
|
3387
3338
|
x: number;
|
|
3388
3339
|
y: number;
|
|
@@ -3396,12 +3347,9 @@ export declare interface TLBaseShape<Type extends string, Props extends object>
|
|
|
3396
3347
|
}
|
|
3397
3348
|
|
|
3398
3349
|
/**
|
|
3399
|
-
* The set of all bindings that are available in the editor.
|
|
3350
|
+
* The set of all bindings that are available in the editor, including unknown bindings.
|
|
3400
3351
|
* Bindings represent relationships between shapes, such as arrows connecting to other shapes.
|
|
3401
3352
|
*
|
|
3402
|
-
* You can use this type without a type argument to work with any binding, or pass
|
|
3403
|
-
* a specific binding type string (e.g., `'arrow'`) to narrow down to that specific binding type.
|
|
3404
|
-
*
|
|
3405
3353
|
* @example
|
|
3406
3354
|
* ```ts
|
|
3407
3355
|
* // Check binding type and handle accordingly
|
|
@@ -3415,16 +3363,11 @@ export declare interface TLBaseShape<Type extends string, Props extends object>
|
|
|
3415
3363
|
* break
|
|
3416
3364
|
* }
|
|
3417
3365
|
* }
|
|
3418
|
-
*
|
|
3419
|
-
* // Narrow to a specific binding type by passing the type as a generic argument
|
|
3420
|
-
* function getArrowSourceId(binding: TLBinding<'arrow'>) {
|
|
3421
|
-
* return binding.fromId // TypeScript knows this is a TLArrowBinding
|
|
3422
|
-
* }
|
|
3423
3366
|
* ```
|
|
3424
3367
|
*
|
|
3425
3368
|
* @public
|
|
3426
3369
|
*/
|
|
3427
|
-
export declare type TLBinding
|
|
3370
|
+
export declare type TLBinding = TLDefaultBinding | TLUnknownBinding;
|
|
3428
3371
|
|
|
3429
3372
|
/**
|
|
3430
3373
|
* Type for creating new bindings with required fromId and toId.
|
|
@@ -3450,7 +3393,7 @@ export declare type TLBinding<K extends keyof TLIndexedBindings = keyof TLIndexe
|
|
|
3450
3393
|
*
|
|
3451
3394
|
* @public
|
|
3452
3395
|
*/
|
|
3453
|
-
export declare type TLBindingCreate<T extends TLBinding = TLBinding> =
|
|
3396
|
+
export declare type TLBindingCreate<T extends TLBinding = TLBinding> = Expand<{
|
|
3454
3397
|
fromId: T['fromId'];
|
|
3455
3398
|
id?: TLBindingId;
|
|
3456
3399
|
meta?: Partial<T['meta']>;
|
|
@@ -3458,7 +3401,7 @@ export declare type TLBindingCreate<T extends TLBinding = TLBinding> = T extends
|
|
|
3458
3401
|
toId: T['toId'];
|
|
3459
3402
|
type: T['type'];
|
|
3460
3403
|
typeName?: T['typeName'];
|
|
3461
|
-
}
|
|
3404
|
+
}>;
|
|
3462
3405
|
|
|
3463
3406
|
/**
|
|
3464
3407
|
* Branded string type for binding record identifiers.
|
|
@@ -3483,7 +3426,7 @@ export declare type TLBindingCreate<T extends TLBinding = TLBinding> = T extends
|
|
|
3483
3426
|
*
|
|
3484
3427
|
* @public
|
|
3485
3428
|
*/
|
|
3486
|
-
export declare type TLBindingId = RecordId<
|
|
3429
|
+
export declare type TLBindingId = RecordId<TLUnknownBinding>;
|
|
3487
3430
|
|
|
3488
3431
|
/**
|
|
3489
3432
|
* Type for updating existing bindings with partial properties.
|
|
@@ -3505,7 +3448,7 @@ export declare type TLBindingId = RecordId<TLBinding>;
|
|
|
3505
3448
|
*
|
|
3506
3449
|
* @public
|
|
3507
3450
|
*/
|
|
3508
|
-
export declare type TLBindingUpdate<T extends TLBinding = TLBinding> =
|
|
3451
|
+
export declare type TLBindingUpdate<T extends TLBinding = TLBinding> = Expand<{
|
|
3509
3452
|
fromId?: T['fromId'];
|
|
3510
3453
|
id: TLBindingId;
|
|
3511
3454
|
meta?: Partial<T['meta']>;
|
|
@@ -3513,7 +3456,7 @@ export declare type TLBindingUpdate<T extends TLBinding = TLBinding> = T extends
|
|
|
3513
3456
|
toId?: T['toId'];
|
|
3514
3457
|
type: T['type'];
|
|
3515
3458
|
typeName?: T['typeName'];
|
|
3516
|
-
}
|
|
3459
|
+
}>;
|
|
3517
3460
|
|
|
3518
3461
|
/**
|
|
3519
3462
|
* An asset used for URL bookmarks, used by the TLBookmarkShape.
|
|
@@ -3653,39 +3596,6 @@ export declare type TLCameraId = RecordId<TLCamera>;
|
|
|
3653
3596
|
*/
|
|
3654
3597
|
export declare type TLCanvasUiColor = SetValue<typeof TL_CANVAS_UI_COLOR_TYPES>;
|
|
3655
3598
|
|
|
3656
|
-
/**
|
|
3657
|
-
* A partial version of a shape, useful for creating shapes.
|
|
3658
|
-
*
|
|
3659
|
-
* This type represents a shape where all properties except `type` are optional.
|
|
3660
|
-
* It's commonly used when creating shapes.
|
|
3661
|
-
*
|
|
3662
|
-
* @example
|
|
3663
|
-
* ```ts
|
|
3664
|
-
* // Create a shape
|
|
3665
|
-
* const shapeCreate: TLCreateShapePartial = {
|
|
3666
|
-
* type: 'geo',
|
|
3667
|
-
* x: 100,
|
|
3668
|
-
* y: 200
|
|
3669
|
-
* }
|
|
3670
|
-
*
|
|
3671
|
-
* // Create shape properties
|
|
3672
|
-
* const propsCreate: TLCreateShapePartial<TLGeoShape> = {
|
|
3673
|
-
* type: 'geo',
|
|
3674
|
-
* props: {
|
|
3675
|
-
* w: 150,
|
|
3676
|
-
* h: 100
|
|
3677
|
-
* }
|
|
3678
|
-
* }
|
|
3679
|
-
* ```
|
|
3680
|
-
*
|
|
3681
|
-
* @public
|
|
3682
|
-
*/
|
|
3683
|
-
export declare type TLCreateShapePartial<T extends TLShape = TLShape> = T extends T ? {
|
|
3684
|
-
meta?: Partial<T['meta']>;
|
|
3685
|
-
props?: Partial<T['props']>;
|
|
3686
|
-
type: T['type'];
|
|
3687
|
-
} & Partial<Omit<T, 'meta' | 'props' | 'type'>> : never;
|
|
3688
|
-
|
|
3689
3599
|
/**
|
|
3690
3600
|
* A cursor object used throughout the tldraw editor.
|
|
3691
3601
|
*
|
|
@@ -4350,14 +4260,6 @@ export declare interface TLGeoShapeProps {
|
|
|
4350
4260
|
richText: TLRichText;
|
|
4351
4261
|
}
|
|
4352
4262
|
|
|
4353
|
-
/** @public */
|
|
4354
|
-
export declare interface TLGlobalBindingPropsMap {
|
|
4355
|
-
}
|
|
4356
|
-
|
|
4357
|
-
/** @public */
|
|
4358
|
-
export declare interface TLGlobalShapePropsMap {
|
|
4359
|
-
}
|
|
4360
|
-
|
|
4361
4263
|
/**
|
|
4362
4264
|
* A group shape that acts as a container for organizing multiple shapes into a single logical unit.
|
|
4363
4265
|
* Groups enable users to move, transform, and manage collections of shapes together while maintaining
|
|
@@ -4635,22 +4537,6 @@ export declare interface TLImageShapeProps {
|
|
|
4635
4537
|
altText: string;
|
|
4636
4538
|
}
|
|
4637
4539
|
|
|
4638
|
-
/** @public */
|
|
4639
|
-
export declare type TLIndexedBindings = {
|
|
4640
|
-
[K in keyof TLGlobalBindingPropsMap | TLDefaultBinding['type'] as K extends TLDefaultBinding['type'] ? K extends keyof TLGlobalBindingPropsMap ? TLGlobalBindingPropsMap[K] extends null | undefined ? never : K : K : K]: K extends TLDefaultBinding['type'] ? K extends keyof TLGlobalBindingPropsMap ? TLBaseBinding<K, TLGlobalBindingPropsMap[K]> : Extract<TLDefaultBinding, {
|
|
4641
|
-
type: K;
|
|
4642
|
-
}> : TLBaseBinding<K, TLGlobalBindingPropsMap[K & keyof TLGlobalBindingPropsMap]>;
|
|
4643
|
-
};
|
|
4644
|
-
|
|
4645
|
-
/** @public */
|
|
4646
|
-
export declare type TLIndexedShapes = {
|
|
4647
|
-
[K in keyof TLGlobalShapePropsMap | TLDefaultShape['type'] as K extends TLDefaultShape['type'] ? K extends 'group' ? K : K extends keyof TLGlobalShapePropsMap ? TLGlobalShapePropsMap[K] extends null | undefined ? never : K : K : K]: K extends 'group' ? Extract<TLDefaultShape, {
|
|
4648
|
-
type: K;
|
|
4649
|
-
}> : K extends TLDefaultShape['type'] ? K extends keyof TLGlobalShapePropsMap ? TLBaseShape<K, TLGlobalShapePropsMap[K]> : Extract<TLDefaultShape, {
|
|
4650
|
-
type: K;
|
|
4651
|
-
}> : TLBaseShape<K, TLGlobalShapePropsMap[K & keyof TLGlobalShapePropsMap]>;
|
|
4652
|
-
};
|
|
4653
|
-
|
|
4654
4540
|
/**
|
|
4655
4541
|
* State that is particular to a single browser tab. The TLInstance record stores
|
|
4656
4542
|
* all session-specific state including cursor position, selected tools, UI preferences,
|
|
@@ -5486,15 +5372,11 @@ export declare interface TLScribble {
|
|
|
5486
5372
|
export declare type TLSerializedStore = SerializedStore<TLRecord>;
|
|
5487
5373
|
|
|
5488
5374
|
/**
|
|
5489
|
-
* The set of all shapes that are available in the editor.
|
|
5375
|
+
* The set of all shapes that are available in the editor, including unknown shapes.
|
|
5490
5376
|
*
|
|
5491
5377
|
* This is the primary shape type used throughout tldraw. It includes both the
|
|
5492
5378
|
* built-in default shapes and any custom shapes that might be added.
|
|
5493
5379
|
*
|
|
5494
|
-
* You can use this type without a type argument to work with any shape, or pass
|
|
5495
|
-
* a specific shape type string (e.g., `'geo'`, `'arrow'`, `'text'`) to narrow
|
|
5496
|
-
* down to that specific shape type.
|
|
5497
|
-
*
|
|
5498
5380
|
* @example
|
|
5499
5381
|
* ```ts
|
|
5500
5382
|
* // Work with any shape in the editor
|
|
@@ -5505,16 +5387,11 @@ export declare type TLSerializedStore = SerializedStore<TLRecord>;
|
|
|
5505
5387
|
* y: shape.y + deltaY
|
|
5506
5388
|
* }
|
|
5507
5389
|
* }
|
|
5508
|
-
*
|
|
5509
|
-
* // Narrow to a specific shape type by passing the type as a generic argument
|
|
5510
|
-
* function getArrowLabel(shape: TLShape<'arrow'>): string {
|
|
5511
|
-
* return shape.props.text // TypeScript knows this is a TLArrowShape
|
|
5512
|
-
* }
|
|
5513
5390
|
* ```
|
|
5514
5391
|
*
|
|
5515
5392
|
* @public
|
|
5516
5393
|
*/
|
|
5517
|
-
export declare type TLShape
|
|
5394
|
+
export declare type TLShape = TLDefaultShape | TLUnknownShape;
|
|
5518
5395
|
|
|
5519
5396
|
/**
|
|
5520
5397
|
* Defines cropping parameters for shapes that support cropping.
|
|
@@ -5561,7 +5438,7 @@ export declare interface TLShapeCrop {
|
|
|
5561
5438
|
*
|
|
5562
5439
|
* @public
|
|
5563
5440
|
*/
|
|
5564
|
-
export declare type TLShapeId = RecordId<
|
|
5441
|
+
export declare type TLShapeId = RecordId<TLUnknownShape>;
|
|
5565
5442
|
|
|
5566
5443
|
/**
|
|
5567
5444
|
* A partial version of a shape, useful for updates and patches.
|
package/dist-esm/index.mjs
CHANGED
package/dist-esm/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype
|
|
5
|
-
"mappings": "AAgCA,SAAS,oCAAoC;AAC7C,SAAS,kBAAkB,4BAA8C;AAIzE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP,SAAS,uBAAyD;AAClE,SAAS,uBAAyD;AAClE,SAAS,wBAA4C;AACrD,SAAS,mBAAmB,kBAAmC;AAC/D,SAAS,mBAAmB,0BAA2C;AACvE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype TLUnknownBinding,\n} from './records/TLBinding'\nexport { CameraRecordType, type TLCamera, type TLCameraId } from './records/TLCamera'\nexport {\n\tDocumentRecordType,\n\tisDocument,\n\tTLDOCUMENT_ID,\n\ttype TLDocument,\n} from './records/TLDocument'\nexport {\n\tpluckPreservingValues,\n\tTLINSTANCE_ID,\n\ttype TLInstance,\n\ttype TLInstanceId,\n} from './records/TLInstance'\nexport {\n\tisPageId,\n\tpageIdValidator,\n\tPageRecordType,\n\ttype TLPage,\n\ttype TLPageId,\n} from './records/TLPage'\nexport {\n\tInstancePageStateRecordType,\n\ttype TLInstancePageState,\n\ttype TLInstancePageStateId,\n} from './records/TLPageState'\nexport {\n\tPointerRecordType,\n\tTLPOINTER_ID,\n\ttype TLPointer,\n\ttype TLPointerId,\n} from './records/TLPointer'\nexport {\n\tInstancePresenceRecordType,\n\ttype TLInstancePresence,\n\ttype TLInstancePresenceID,\n} from './records/TLPresence'\nexport { type TLRecord } from './records/TLRecord'\nexport {\n\tcreateShapeId,\n\tcreateShapePropsMigrationIds,\n\tcreateShapePropsMigrationSequence,\n\tgetShapePropKeysByStyle,\n\tisShape,\n\tisShapeId,\n\trootShapeMigrations,\n\ttype TLDefaultShape,\n\ttype TLParentId,\n\ttype TLShape,\n\ttype TLShapeId,\n\ttype TLShapePartial,\n\ttype TLUnknownShape,\n} from './records/TLShape'\nexport {\n\ttype RecordProps,\n\ttype RecordPropsType,\n\ttype TLPropsMigration,\n\ttype TLPropsMigrations,\n} from './recordsWithProps'\nexport { type ShapeWithCrop, type TLShapeCrop } from './shapes/ShapeWithCrop'\nexport {\n\tArrowShapeArrowheadEndStyle,\n\tArrowShapeArrowheadStartStyle,\n\tArrowShapeKindStyle,\n\tarrowShapeMigrations,\n\tarrowShapeProps,\n\tarrowShapeVersions,\n\ttype TLArrowShape,\n\ttype TLArrowShapeArrowheadStyle,\n\ttype TLArrowShapeKind,\n\ttype TLArrowShapeProps,\n} from './shapes/TLArrowShape'\nexport {\n\tcreateShapeValidator,\n\tparentIdValidator,\n\tshapeIdValidator,\n\ttype TLBaseShape,\n} from './shapes/TLBaseShape'\nexport {\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\ttype TLBookmarkShape,\n\ttype TLBookmarkShapeProps,\n} from './shapes/TLBookmarkShape'\nexport {\n\tdrawShapeMigrations,\n\tdrawShapeProps,\n\ttype TLDrawShape,\n\ttype TLDrawShapeProps,\n\ttype TLDrawShapeSegment,\n} from './shapes/TLDrawShape'\nexport {\n\tembedShapeMigrations,\n\tembedShapeProps,\n\ttype TLEmbedShape,\n\ttype TLEmbedShapeProps,\n} from './shapes/TLEmbedShape'\nexport {\n\tframeShapeMigrations,\n\tframeShapeProps,\n\ttype TLFrameShape,\n\ttype TLFrameShapeProps,\n} from './shapes/TLFrameShape'\nexport {\n\tGeoShapeGeoStyle,\n\tgeoShapeMigrations,\n\tgeoShapeProps,\n\ttype TLGeoShape,\n\ttype TLGeoShapeGeoStyle,\n\ttype TLGeoShapeProps,\n} from './shapes/TLGeoShape'\nexport {\n\tgroupShapeMigrations,\n\tgroupShapeProps,\n\ttype TLGroupShape,\n\ttype TLGroupShapeProps,\n} from './shapes/TLGroupShape'\nexport {\n\thighlightShapeMigrations,\n\thighlightShapeProps,\n\ttype TLHighlightShape,\n\ttype TLHighlightShapeProps,\n} from './shapes/TLHighlightShape'\nexport {\n\tImageShapeCrop,\n\timageShapeMigrations,\n\timageShapeProps,\n\ttype TLImageShape,\n\ttype TLImageShapeProps,\n} from './shapes/TLImageShape'\nexport {\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tLineShapeSplineStyle,\n\ttype TLLineShape,\n\ttype TLLineShapePoint,\n\ttype TLLineShapeProps,\n\ttype TLLineShapeSplineStyle,\n} from './shapes/TLLineShape'\nexport {\n\tnoteShapeMigrations,\n\tnoteShapeProps,\n\ttype TLNoteShape,\n\ttype TLNoteShapeProps,\n} from './shapes/TLNoteShape'\nexport {\n\ttextShapeMigrations,\n\ttextShapeProps,\n\ttype TLTextShape,\n\ttype TLTextShapeProps,\n} from './shapes/TLTextShape'\nexport {\n\tvideoShapeMigrations,\n\tvideoShapeProps,\n\ttype TLVideoShape,\n\ttype TLVideoShapeProps,\n} from './shapes/TLVideoShape'\nexport { EnumStyleProp, StyleProp, type StylePropValue } from './styles/StyleProp'\nexport {\n\tdefaultColorNames,\n\tDefaultColorStyle,\n\tDefaultColorThemePalette,\n\tDefaultLabelColorStyle,\n\tgetColorValue,\n\tgetDefaultColorTheme,\n\ttype TLDefaultColorStyle,\n\ttype TLDefaultColorTheme,\n\ttype TLDefaultColorThemeColor,\n} from './styles/TLColorStyle'\nexport { DefaultDashStyle, type TLDefaultDashStyle } from './styles/TLDashStyle'\nexport { DefaultFillStyle, type TLDefaultFillStyle } from './styles/TLFillStyle'\nexport {\n\tDefaultFontFamilies,\n\tDefaultFontStyle,\n\ttype TLDefaultFontStyle,\n} from './styles/TLFontStyle'\nexport {\n\tDefaultHorizontalAlignStyle,\n\ttype TLDefaultHorizontalAlignStyle,\n} from './styles/TLHorizontalAlignStyle'\nexport { DefaultSizeStyle, type TLDefaultSizeStyle } from './styles/TLSizeStyle'\nexport { DefaultTextAlignStyle, type TLDefaultTextAlignStyle } from './styles/TLTextAlignStyle'\nexport {\n\tDefaultVerticalAlignStyle,\n\ttype TLDefaultVerticalAlignStyle,\n} from './styles/TLVerticalAlignStyle'\nexport {\n\ttype TLAssetContext,\n\ttype TLAssetStore,\n\ttype TLSerializedStore,\n\ttype TLStore,\n\ttype TLStoreProps,\n\ttype TLStoreSchema,\n\ttype TLStoreSnapshot,\n} from './TLStore'\nexport {\n\tgetDefaultTranslationLocale,\n\tLANGUAGES,\n\ttype TLLanguage,\n} from './translations/translations'\nexport { type SetValue } from './util-types'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n"],
|
|
5
|
+
"mappings": "AAgCA,SAAS,oCAAoC;AAC7C,SAAS,kBAAkB,4BAA8C;AAIzE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP,SAAS,uBAAyD;AAClE,SAAS,uBAAyD;AAClE,SAAS,wBAA4C;AACrD,SAAS,mBAAmB,kBAAmC;AAC/D,SAAS,mBAAmB,0BAA2C;AACvE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOM;AACP,SAAS,wBAAwD;AACjE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,OAGM;AAEP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOM;AAQP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAIM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OAGM;AACP,SAAS,eAAe,iBAAsC;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,wBAAiD;AAC1D,SAAS,wBAAiD;AAC1D;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AACP;AAAA,EACC;AAAA,OAEM;AACP,SAAS,wBAAiD;AAC1D,SAAS,6BAA2D;AACpE;AAAA,EACC;AAAA,OAEM;AAUP;AAAA,EACC;AAAA,EACA;AAAA,OAEM;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/records/TLAsset.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tcreateMigrationIds,\n\tcreateRecordMigrationSequence,\n\tcreateRecordType,\n\tRecordId,\n} from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLBaseAsset } from '../assets/TLBaseAsset'\nimport { bookmarkAssetValidator, TLBookmarkAsset } from '../assets/TLBookmarkAsset'\nimport { imageAssetValidator, TLImageAsset } from '../assets/TLImageAsset'\nimport { TLVideoAsset, videoAssetValidator } from '../assets/TLVideoAsset'\nimport {
|
|
4
|
+
"sourcesContent": ["import {\n\tcreateMigrationIds,\n\tcreateRecordMigrationSequence,\n\tcreateRecordType,\n\tRecordId,\n} from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { TLBaseAsset } from '../assets/TLBaseAsset'\nimport { bookmarkAssetValidator, TLBookmarkAsset } from '../assets/TLBookmarkAsset'\nimport { imageAssetValidator, TLImageAsset } from '../assets/TLImageAsset'\nimport { TLVideoAsset, videoAssetValidator } from '../assets/TLVideoAsset'\nimport { TLShape } from './TLShape'\n\n/**\n * Union type representing all possible asset types in tldraw.\n * Assets represent external resources like images, videos, or bookmarks that can be referenced by shapes.\n *\n * @example\n * ```ts\n * const imageAsset: TLAsset = {\n * id: 'asset:image123',\n * typeName: 'asset',\n * type: 'image',\n * props: {\n * src: 'https://example.com/image.jpg',\n * w: 800,\n * h: 600,\n * mimeType: 'image/jpeg',\n * isAnimated: false\n * },\n * meta: {}\n * }\n * ```\n *\n * @public\n */\nexport type TLAsset = TLImageAsset | TLVideoAsset | TLBookmarkAsset\n\n/**\n * Validator for TLAsset records that ensures runtime type safety.\n * Uses a discriminated union based on the 'type' field to validate different asset types.\n *\n * @example\n * ```ts\n * // Validation happens automatically when assets are stored\n * try {\n * const validatedAsset = assetValidator.validate(assetData)\n * store.put([validatedAsset])\n * } catch (error) {\n * console.error('Asset validation failed:', error.message)\n * }\n * ```\n *\n * @public\n */\nexport const assetValidator: T.Validator<TLAsset> = T.model(\n\t'asset',\n\tT.union('type', {\n\t\timage: imageAssetValidator,\n\t\tvideo: videoAssetValidator,\n\t\tbookmark: bookmarkAssetValidator,\n\t})\n)\n\n/**\n * Migration version identifiers for asset record schema evolution.\n * Each version represents a breaking change that requires data migration.\n *\n * @example\n * ```ts\n * // Check if a migration is needed\n * const needsMigration = currentVersion < assetVersions.AddMeta\n * ```\n *\n * @public\n */\nexport const assetVersions = createMigrationIds('com.tldraw.asset', {\n\tAddMeta: 1,\n} as const)\n\n/**\n * Migration sequence for evolving asset record structure over time.\n * Handles converting asset records from older schema versions to current format.\n *\n * @example\n * ```ts\n * // Migration is applied automatically when loading old documents\n * const migratedStore = migrator.migrateStoreSnapshot({\n * schema: oldSchema,\n * store: oldStoreSnapshot\n * })\n * ```\n *\n * @public\n */\nexport const assetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset',\n\trecordType: 'asset',\n\tsequence: [\n\t\t{\n\t\t\tid: assetVersions.AddMeta,\n\t\t\tup: (record) => {\n\t\t\t\t;(record as any).meta = {}\n\t\t\t},\n\t\t},\n\t],\n})\n\n/**\n * Partial type for TLAsset allowing optional properties except id and type.\n * Useful for creating or updating assets where not all properties need to be specified.\n *\n * @example\n * ```ts\n * // Create a partial asset for updating\n * const partialAsset: TLAssetPartial<TLImageAsset> = {\n * id: 'asset:image123',\n * type: 'image',\n * props: {\n * w: 800 // Only updating width\n * }\n * }\n *\n * // Use in asset updates\n * editor.updateAssets([partialAsset])\n * ```\n *\n * @public\n */\nexport type TLAssetPartial<T extends TLAsset = TLAsset> = T extends T\n\t? {\n\t\t\tid: TLAssetId\n\t\t\ttype: T['type']\n\t\t\tprops?: Partial<T['props']>\n\t\t\tmeta?: Partial<T['meta']>\n\t\t} & Partial<Omit<T, 'type' | 'id' | 'props' | 'meta'>>\n\t: never\n\n/**\n * Record type definition for TLAsset with validation and default properties.\n * Configures assets as document-scoped records that persist across sessions.\n *\n * @example\n * ```ts\n * // Create a new asset record\n * const assetRecord = AssetRecordType.create({\n * id: 'asset:image123',\n * type: 'image',\n * props: {\n * src: 'https://example.com/image.jpg',\n * w: 800,\n * h: 600,\n * mimeType: 'image/jpeg',\n * isAnimated: false\n * }\n * })\n *\n * // Store the asset\n * store.put([assetRecord])\n * ```\n *\n * @public\n */\nexport const AssetRecordType = createRecordType<TLAsset>('asset', {\n\tvalidator: assetValidator,\n\tscope: 'document',\n}).withDefaultProperties(() => ({\n\tmeta: {},\n}))\n\n/**\n * Branded string type for asset record identifiers.\n * Prevents mixing asset IDs with other types of record IDs at compile time.\n *\n * @example\n * ```ts\n * import { createAssetId } from '@tldraw/tlschema'\n *\n * // Create a new asset ID\n * const assetId: TLAssetId = createAssetId()\n *\n * // Use in asset records\n * const asset: TLAsset = {\n * id: assetId,\n * // ... other properties\n * }\n *\n * // Reference in shapes\n * const imageShape: TLImageShape = {\n * props: {\n * assetId: assetId,\n * // ... other properties\n * }\n * }\n * ```\n *\n * @public\n */\nexport type TLAssetId = RecordId<TLBaseAsset<any, any>>\n\n/**\n * Union type of all shapes that reference assets through an assetId property.\n * Includes image shapes, video shapes, and any other shapes that depend on external assets.\n *\n * @example\n * ```ts\n * // Function that works with any asset-based shape\n * function handleAssetShape(shape: TLAssetShape) {\n * const assetId = shape.props.assetId\n * if (assetId) {\n * const asset = editor.getAsset(assetId)\n * // Handle the asset...\n * }\n * }\n *\n * // Use with image or video shapes\n * const imageShape: TLImageShape = { props: { assetId: 'asset:img1' } }\n * const videoShape: TLVideoShape = { props: { assetId: 'asset:vid1' } }\n * handleAssetShape(imageShape) // Works\n * handleAssetShape(videoShape) // Works\n * ```\n *\n * @public\n */\nexport type TLAssetShape = Extract<TLShape, { props: { assetId: TLAssetId } }>\n"],
|
|
5
5
|
"mappings": "AAAA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,SAAS;AAElB,SAAS,8BAA+C;AACxD,SAAS,2BAAyC;AAClD,SAAuB,2BAA2B;AA6C3C,MAAM,iBAAuC,EAAE;AAAA,EACrD;AAAA,EACA,EAAE,MAAM,QAAQ;AAAA,IACf,OAAO;AAAA,IACP,OAAO;AAAA,IACP,UAAU;AAAA,EACX,CAAC;AACF;AAcO,MAAM,gBAAgB,mBAAmB,oBAAoB;AAAA,EACnE,SAAS;AACV,CAAU;AAiBH,MAAM,kBAAkB,8BAA8B;AAAA,EAC5D,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,UAAU;AAAA,IACT;AAAA,MACC,IAAI,cAAc;AAAA,MAClB,IAAI,CAAC,WAAW;AACf;AAAC,QAAC,OAAe,OAAO,CAAC;AAAA,MAC1B;AAAA,IACD;AAAA,EACD;AACD,CAAC;AAyDM,MAAM,kBAAkB,iBAA0B,SAAS;AAAA,EACjE,WAAW;AAAA,EACX,OAAO;AACR,CAAC,EAAE,sBAAsB,OAAO;AAAA,EAC/B,MAAM,CAAC;AACR,EAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/records/TLBinding.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tRecordId,\n\tUnknownRecord,\n\tcreateMigrationIds,\n\tcreateRecordMigrationSequence,\n\tcreateRecordType,\n} from '@tldraw/store'\nimport { mapObjectMapValues, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { TLArrowBinding } from '../bindings/TLArrowBinding'\nimport { TLBaseBinding, createBindingValidator } from '../bindings/TLBaseBinding'\nimport { SchemaPropsInfo } from '../createTLSchema'\nimport { TLPropsMigrations } from '../recordsWithProps'\n\n/**\n * The default set of bindings that are available in the editor.\n * Currently includes only arrow bindings, but can be extended with custom bindings.\n *\n * @example\n * ```ts\n * // Arrow binding connects an arrow to shapes\n * const arrowBinding: TLDefaultBinding = {\n * id: 'binding:arrow1',\n * typeName: 'binding',\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * props: {\n * terminal: 'end',\n * normalizedAnchor: { x: 0.5, y: 0.5 },\n * isExact: false,\n * isPrecise: true\n * }\n * }\n * ```\n *\n * @public\n */\nexport type TLDefaultBinding = TLArrowBinding\n\n/**\n * A type for a binding that is available in the editor but whose type is\n * unknown\u2014either one of the editor's default bindings or else a custom binding.\n * Used internally for type-safe handling of bindings with unknown structure.\n *\n * @example\n * ```ts\n * // Function that works with any binding type\n * function processBinding(binding: TLUnknownBinding) {\n * console.log(`Processing ${binding.type} binding from ${binding.fromId} to ${binding.toId}`)\n * // Handle binding properties generically\n * }\n * ```\n *\n * @public\n */\nexport type TLUnknownBinding = TLBaseBinding<string, object>\n\n/** @public */\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface TLGlobalBindingPropsMap {}\n\n/** @public */\n// prettier-ignore\nexport type TLIndexedBindings = {\n\t// We iterate over a union of augmented keys and default binding types.\n\t// This allows us to include (or conditionally exclude or override) the default bindings in one go.\n\t//\n\t// In the `as` clause we are filtering out disabled bindings.\n\t[K in keyof TLGlobalBindingPropsMap | TLDefaultBinding['type'] as K extends TLDefaultBinding['type']\n\t\t? K extends keyof TLGlobalBindingPropsMap\n\t\t\t? // if it extends a nullish value the user has disabled this binding type so we filter it out with never\n\t\t\t\tTLGlobalBindingPropsMap[K] extends null | undefined\n\t\t\t\t? never\n\t\t\t\t: K\n\t\t\t: K\n\t\t: K]: K extends TLDefaultBinding['type']\n\t\t\t? // if it's a default binding type we need to check if it's been overridden\n\t\t\t\tK extends keyof TLGlobalBindingPropsMap\n\t\t\t\t? // if it has been overriden then use the custom binding definition\n\t\t\t\t\tTLBaseBinding<K, TLGlobalBindingPropsMap[K]>\n\t\t\t\t: // if it has not been overriden then reuse existing type aliases for better type display\n\t\t\t\t\tExtract<TLDefaultBinding, { type: K }>\n\t\t\t: // use the custom binding definition\n\t\t\t\tTLBaseBinding<K, TLGlobalBindingPropsMap[K & keyof TLGlobalBindingPropsMap]>\n}\n\n/**\n * The set of all bindings that are available in the editor.\n * Bindings represent relationships between shapes, such as arrows connecting to other shapes.\n *\n * You can use this type without a type argument to work with any binding, or pass\n * a specific binding type string (e.g., `'arrow'`) to narrow down to that specific binding type.\n *\n * @example\n * ```ts\n * // Check binding type and handle accordingly\n * function handleBinding(binding: TLBinding) {\n * switch (binding.type) {\n * case 'arrow':\n * // Handle arrow binding\n * break\n * default:\n * // Handle unknown custom binding\n * break\n * }\n * }\n *\n * // Narrow to a specific binding type by passing the type as a generic argument\n * function getArrowSourceId(binding: TLBinding<'arrow'>) {\n * return binding.fromId // TypeScript knows this is a TLArrowBinding\n * }\n * ```\n *\n * @public\n */\nexport type TLBinding<K extends keyof TLIndexedBindings = keyof TLIndexedBindings> =\n\tTLIndexedBindings[K]\n\n/**\n * Type for updating existing bindings with partial properties.\n * Only the id and type are required, all other properties are optional.\n *\n * @example\n * ```ts\n * // Update arrow binding properties\n * const bindingUpdate: TLBindingUpdate<TLArrowBinding> = {\n * id: 'binding:arrow1',\n * type: 'arrow',\n * props: {\n * normalizedAnchor: { x: 0.7, y: 0.3 } // Only update anchor position\n * }\n * }\n *\n * editor.updateBindings([bindingUpdate])\n * ```\n *\n * @public\n */\nexport type TLBindingUpdate<T extends TLBinding = TLBinding> = T extends T\n\t? {\n\t\t\tid: TLBindingId\n\t\t\ttype: T['type']\n\t\t\ttypeName?: T['typeName']\n\t\t\tfromId?: T['fromId']\n\t\t\ttoId?: T['toId']\n\t\t\tprops?: Partial<T['props']>\n\t\t\tmeta?: Partial<T['meta']>\n\t\t}\n\t: never\n\n/**\n * Type for creating new bindings with required fromId and toId.\n * The id is optional and will be generated if not provided.\n *\n * @example\n * ```ts\n * // Create a new arrow binding\n * const newBinding: TLBindingCreate<TLArrowBinding> = {\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * props: {\n * terminal: 'end',\n * normalizedAnchor: { x: 0.5, y: 0.5 },\n * isExact: false,\n * isPrecise: true\n * }\n * }\n *\n * editor.createBindings([newBinding])\n * ```\n *\n * @public\n */\nexport type TLBindingCreate<T extends TLBinding = TLBinding> = T extends T\n\t? {\n\t\t\tid?: TLBindingId\n\t\t\ttype: T['type']\n\t\t\ttypeName?: T['typeName']\n\t\t\tfromId: T['fromId']\n\t\t\ttoId: T['toId']\n\t\t\tprops?: Partial<T['props']>\n\t\t\tmeta?: Partial<T['meta']>\n\t\t}\n\t: never\n\n/**\n * Branded string type for binding record identifiers.\n * Prevents mixing binding IDs with other types of record IDs at compile time.\n *\n * @example\n * ```ts\n * import { createBindingId } from '@tldraw/tlschema'\n *\n * // Create a new binding ID\n * const bindingId: TLBindingId = createBindingId()\n *\n * // Use in binding records\n * const binding: TLBinding = {\n * id: bindingId,\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * // ... other properties\n * }\n * ```\n *\n * @public\n */\nexport type TLBindingId = RecordId<TLBinding>\n\n/**\n * Migration version identifiers for the root binding record schema.\n * Currently empty as no migrations have been applied to the base binding structure.\n *\n * @example\n * ```ts\n * // Future migrations would be defined here\n * const rootBindingVersions = createMigrationIds('com.tldraw.binding', {\n * AddNewProperty: 1,\n * } as const)\n * ```\n *\n * @public\n */\nexport const rootBindingVersions = createMigrationIds('com.tldraw.binding', {} as const)\n\n/**\n * Migration sequence for the root binding record structure.\n * Currently empty as the binding schema has not required any migrations yet.\n *\n * @example\n * ```ts\n * // Migrations would be automatically applied when loading old documents\n * const migratedStore = migrator.migrateStoreSnapshot({\n * schema: oldSchema,\n * store: oldStoreSnapshot\n * })\n * ```\n *\n * @public\n */\nexport const rootBindingMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.binding',\n\trecordType: 'binding',\n\tsequence: [],\n})\n\n/**\n * Type guard to check if a record is a TLBinding.\n * Useful for filtering or type narrowing when working with mixed record types.\n *\n * @param record - The record to check\n * @returns True if the record is a binding, false otherwise\n *\n * @example\n * ```ts\n * // Filter bindings from mixed records\n * const allRecords = store.allRecords()\n * const bindings = allRecords.filter(isBinding)\n *\n * // Type guard usage\n * function processRecord(record: UnknownRecord) {\n * if (isBinding(record)) {\n * // record is now typed as TLBinding\n * console.log(`Binding from ${record.fromId} to ${record.toId}`)\n * }\n * }\n * ```\n *\n * @public\n */\nexport function isBinding(record?: UnknownRecord): record is TLBinding {\n\tif (!record) return false\n\treturn record.typeName === 'binding'\n}\n\n/**\n * Type guard to check if a string is a valid TLBindingId.\n * Validates that the ID follows the correct format for binding identifiers.\n *\n * @param id - The string to check\n * @returns True if the string is a valid binding ID, false otherwise\n *\n * @example\n * ```ts\n * // Validate binding IDs\n * const maybeBindingId = 'binding:abc123'\n * if (isBindingId(maybeBindingId)) {\n * // maybeBindingId is now typed as TLBindingId\n * const binding = store.get(maybeBindingId)\n * }\n *\n * // Filter binding IDs from mixed ID array\n * const mixedIds = ['shape:1', 'binding:2', 'page:3']\n * const bindingIds = mixedIds.filter(isBindingId)\n * ```\n *\n * @public\n */\nexport function isBindingId(id?: string): id is TLBindingId {\n\tif (!id) return false\n\treturn id.startsWith('binding:')\n}\n\n/**\n * Creates a new TLBindingId with proper formatting.\n * Generates a unique ID if none is provided, or formats a provided ID correctly.\n *\n * @param id - Optional custom ID suffix. If not provided, a unique ID is generated\n * @returns A properly formatted binding ID\n *\n * @example\n * ```ts\n * // Create with auto-generated ID\n * const bindingId1 = createBindingId() // 'binding:abc123'\n *\n * // Create with custom ID\n * const bindingId2 = createBindingId('myCustomBinding') // 'binding:myCustomBinding'\n *\n * // Use in binding creation\n * const binding: TLBinding = {\n * id: createBindingId(),\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * // ... other properties\n * }\n * ```\n *\n * @public\n */\nexport function createBindingId(id?: string): TLBindingId {\n\treturn `binding:${id ?? uniqueId()}` as TLBindingId\n}\n\n/**\n * Creates a migration sequence for binding properties.\n * This is a pass-through function that validates and returns the provided migrations.\n *\n * @param migrations - The migration sequence for binding properties\n * @returns The validated migration sequence\n *\n * @example\n * ```ts\n * // Define migrations for custom binding properties\n * const myBindingMigrations = createBindingPropsMigrationSequence({\n * sequence: [\n * {\n * id: 'com.myapp.binding.custom/1.0.0',\n * up: (props) => ({ ...props, newProperty: 'default' }),\n * down: ({ newProperty, ...props }) => props\n * }\n * ]\n * })\n * ```\n *\n * @public\n */\nexport function createBindingPropsMigrationSequence(\n\tmigrations: TLPropsMigrations\n): TLPropsMigrations {\n\treturn migrations\n}\n\n/**\n * Creates properly formatted migration IDs for binding property migrations.\n * Follows the convention: 'com.tldraw.binding.\\{bindingType\\}/\\{version\\}'\n *\n * @param bindingType - The type of binding these migrations apply to\n * @param ids - Object mapping migration names to version numbers\n * @returns Object with formatted migration IDs\n *\n * @example\n * ```ts\n * // Create migration IDs for custom binding\n * const myBindingVersions = createBindingPropsMigrationIds('myCustomBinding', {\n * AddNewProperty: 1,\n * UpdateProperty: 2\n * })\n *\n * // Result:\n * // {\n * // AddNewProperty: 'com.tldraw.binding.myCustomBinding/1',\n * // UpdateProperty: 'com.tldraw.binding.myCustomBinding/2'\n * // }\n * ```\n *\n * @public\n */\nexport function createBindingPropsMigrationIds<S extends string, T extends Record<string, number>>(\n\tbindingType: S,\n\tids: T\n): { [k in keyof T]: `com.tldraw.binding.${S}/${T[k]}` } {\n\treturn mapObjectMapValues(ids, (_k, v) => `com.tldraw.binding.${bindingType}/${v}`) as any\n}\n\n/**\n * Creates a record type for TLBinding with validation based on the provided binding schemas.\n * This function is used internally to configure the binding record type in the schema.\n *\n * @param bindings - Record mapping binding type names to their schema information\n * @returns A configured record type for bindings with validation\n *\n * @example\n * ```ts\n * // Used internally when creating schemas\n * const bindingRecordType = createBindingRecordType({\n * arrow: {\n * props: arrowBindingProps,\n * meta: arrowBindingMeta\n * }\n * })\n * ```\n *\n * @internal\n */\nexport function createBindingRecordType(bindings: Record<string, SchemaPropsInfo>) {\n\treturn createRecordType('binding', {\n\t\tscope: 'document',\n\t\tvalidator: T.model(\n\t\t\t'binding',\n\t\t\tT.union(\n\t\t\t\t'type',\n\t\t\t\tmapObjectMapValues(bindings, (type, { props, meta }) =>\n\t\t\t\t\tcreateBindingValidator(type, props, meta)\n\t\t\t\t)\n\t\t\t)\n\t\t),\n\t}).withDefaultProperties(() => ({\n\t\tmeta: {},\n\t}))\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,
|
|
4
|
+
"sourcesContent": ["import {\n\tRecordId,\n\tUnknownRecord,\n\tcreateMigrationIds,\n\tcreateRecordMigrationSequence,\n\tcreateRecordType,\n} from '@tldraw/store'\nimport { Expand, mapObjectMapValues, uniqueId } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { TLArrowBinding } from '../bindings/TLArrowBinding'\nimport { TLBaseBinding, createBindingValidator } from '../bindings/TLBaseBinding'\nimport { SchemaPropsInfo } from '../createTLSchema'\nimport { TLPropsMigrations } from '../recordsWithProps'\n\n/**\n * The default set of bindings that are available in the editor.\n * Currently includes only arrow bindings, but can be extended with custom bindings.\n *\n * @example\n * ```ts\n * // Arrow binding connects an arrow to shapes\n * const arrowBinding: TLDefaultBinding = {\n * id: 'binding:arrow1',\n * typeName: 'binding',\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * props: {\n * terminal: 'end',\n * normalizedAnchor: { x: 0.5, y: 0.5 },\n * isExact: false,\n * isPrecise: true\n * }\n * }\n * ```\n *\n * @public\n */\nexport type TLDefaultBinding = TLArrowBinding\n\n/**\n * A type for a binding that is available in the editor but whose type is\n * unknown\u2014either one of the editor's default bindings or else a custom binding.\n * Used internally for type-safe handling of bindings with unknown structure.\n *\n * @example\n * ```ts\n * // Function that works with any binding type\n * function processBinding(binding: TLUnknownBinding) {\n * console.log(`Processing ${binding.type} binding from ${binding.fromId} to ${binding.toId}`)\n * // Handle binding properties generically\n * }\n * ```\n *\n * @public\n */\nexport type TLUnknownBinding = TLBaseBinding<string, object>\n\n/**\n * The set of all bindings that are available in the editor, including unknown bindings.\n * Bindings represent relationships between shapes, such as arrows connecting to other shapes.\n *\n * @example\n * ```ts\n * // Check binding type and handle accordingly\n * function handleBinding(binding: TLBinding) {\n * switch (binding.type) {\n * case 'arrow':\n * // Handle arrow binding\n * break\n * default:\n * // Handle unknown custom binding\n * break\n * }\n * }\n * ```\n *\n * @public\n */\nexport type TLBinding = TLDefaultBinding | TLUnknownBinding\n\n/**\n * Type for updating existing bindings with partial properties.\n * Only the id and type are required, all other properties are optional.\n *\n * @example\n * ```ts\n * // Update arrow binding properties\n * const bindingUpdate: TLBindingUpdate<TLArrowBinding> = {\n * id: 'binding:arrow1',\n * type: 'arrow',\n * props: {\n * normalizedAnchor: { x: 0.7, y: 0.3 } // Only update anchor position\n * }\n * }\n *\n * editor.updateBindings([bindingUpdate])\n * ```\n *\n * @public\n */\nexport type TLBindingUpdate<T extends TLBinding = TLBinding> = Expand<{\n\tid: TLBindingId\n\ttype: T['type']\n\ttypeName?: T['typeName']\n\tfromId?: T['fromId']\n\ttoId?: T['toId']\n\tprops?: Partial<T['props']>\n\tmeta?: Partial<T['meta']>\n}>\n\n/**\n * Type for creating new bindings with required fromId and toId.\n * The id is optional and will be generated if not provided.\n *\n * @example\n * ```ts\n * // Create a new arrow binding\n * const newBinding: TLBindingCreate<TLArrowBinding> = {\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * props: {\n * terminal: 'end',\n * normalizedAnchor: { x: 0.5, y: 0.5 },\n * isExact: false,\n * isPrecise: true\n * }\n * }\n *\n * editor.createBindings([newBinding])\n * ```\n *\n * @public\n */\nexport type TLBindingCreate<T extends TLBinding = TLBinding> = Expand<{\n\tid?: TLBindingId\n\ttype: T['type']\n\ttypeName?: T['typeName']\n\tfromId: T['fromId']\n\ttoId: T['toId']\n\tprops?: Partial<T['props']>\n\tmeta?: Partial<T['meta']>\n}>\n\n/**\n * Branded string type for binding record identifiers.\n * Prevents mixing binding IDs with other types of record IDs at compile time.\n *\n * @example\n * ```ts\n * import { createBindingId } from '@tldraw/tlschema'\n *\n * // Create a new binding ID\n * const bindingId: TLBindingId = createBindingId()\n *\n * // Use in binding records\n * const binding: TLBinding = {\n * id: bindingId,\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * // ... other properties\n * }\n * ```\n *\n * @public\n */\nexport type TLBindingId = RecordId<TLUnknownBinding>\n\n/**\n * Migration version identifiers for the root binding record schema.\n * Currently empty as no migrations have been applied to the base binding structure.\n *\n * @example\n * ```ts\n * // Future migrations would be defined here\n * const rootBindingVersions = createMigrationIds('com.tldraw.binding', {\n * AddNewProperty: 1,\n * } as const)\n * ```\n *\n * @public\n */\nexport const rootBindingVersions = createMigrationIds('com.tldraw.binding', {} as const)\n\n/**\n * Migration sequence for the root binding record structure.\n * Currently empty as the binding schema has not required any migrations yet.\n *\n * @example\n * ```ts\n * // Migrations would be automatically applied when loading old documents\n * const migratedStore = migrator.migrateStoreSnapshot({\n * schema: oldSchema,\n * store: oldStoreSnapshot\n * })\n * ```\n *\n * @public\n */\nexport const rootBindingMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.binding',\n\trecordType: 'binding',\n\tsequence: [],\n})\n\n/**\n * Type guard to check if a record is a TLBinding.\n * Useful for filtering or type narrowing when working with mixed record types.\n *\n * @param record - The record to check\n * @returns True if the record is a binding, false otherwise\n *\n * @example\n * ```ts\n * // Filter bindings from mixed records\n * const allRecords = store.allRecords()\n * const bindings = allRecords.filter(isBinding)\n *\n * // Type guard usage\n * function processRecord(record: UnknownRecord) {\n * if (isBinding(record)) {\n * // record is now typed as TLBinding\n * console.log(`Binding from ${record.fromId} to ${record.toId}`)\n * }\n * }\n * ```\n *\n * @public\n */\nexport function isBinding(record?: UnknownRecord): record is TLBinding {\n\tif (!record) return false\n\treturn record.typeName === 'binding'\n}\n\n/**\n * Type guard to check if a string is a valid TLBindingId.\n * Validates that the ID follows the correct format for binding identifiers.\n *\n * @param id - The string to check\n * @returns True if the string is a valid binding ID, false otherwise\n *\n * @example\n * ```ts\n * // Validate binding IDs\n * const maybeBindingId = 'binding:abc123'\n * if (isBindingId(maybeBindingId)) {\n * // maybeBindingId is now typed as TLBindingId\n * const binding = store.get(maybeBindingId)\n * }\n *\n * // Filter binding IDs from mixed ID array\n * const mixedIds = ['shape:1', 'binding:2', 'page:3']\n * const bindingIds = mixedIds.filter(isBindingId)\n * ```\n *\n * @public\n */\nexport function isBindingId(id?: string): id is TLBindingId {\n\tif (!id) return false\n\treturn id.startsWith('binding:')\n}\n\n/**\n * Creates a new TLBindingId with proper formatting.\n * Generates a unique ID if none is provided, or formats a provided ID correctly.\n *\n * @param id - Optional custom ID suffix. If not provided, a unique ID is generated\n * @returns A properly formatted binding ID\n *\n * @example\n * ```ts\n * // Create with auto-generated ID\n * const bindingId1 = createBindingId() // 'binding:abc123'\n *\n * // Create with custom ID\n * const bindingId2 = createBindingId('myCustomBinding') // 'binding:myCustomBinding'\n *\n * // Use in binding creation\n * const binding: TLBinding = {\n * id: createBindingId(),\n * type: 'arrow',\n * fromId: 'shape:arrow1',\n * toId: 'shape:rectangle1',\n * // ... other properties\n * }\n * ```\n *\n * @public\n */\nexport function createBindingId(id?: string): TLBindingId {\n\treturn `binding:${id ?? uniqueId()}` as TLBindingId\n}\n\n/**\n * Creates a migration sequence for binding properties.\n * This is a pass-through function that validates and returns the provided migrations.\n *\n * @param migrations - The migration sequence for binding properties\n * @returns The validated migration sequence\n *\n * @example\n * ```ts\n * // Define migrations for custom binding properties\n * const myBindingMigrations = createBindingPropsMigrationSequence({\n * sequence: [\n * {\n * id: 'com.myapp.binding.custom/1.0.0',\n * up: (props) => ({ ...props, newProperty: 'default' }),\n * down: ({ newProperty, ...props }) => props\n * }\n * ]\n * })\n * ```\n *\n * @public\n */\nexport function createBindingPropsMigrationSequence(\n\tmigrations: TLPropsMigrations\n): TLPropsMigrations {\n\treturn migrations\n}\n\n/**\n * Creates properly formatted migration IDs for binding property migrations.\n * Follows the convention: 'com.tldraw.binding.\\{bindingType\\}/\\{version\\}'\n *\n * @param bindingType - The type of binding these migrations apply to\n * @param ids - Object mapping migration names to version numbers\n * @returns Object with formatted migration IDs\n *\n * @example\n * ```ts\n * // Create migration IDs for custom binding\n * const myBindingVersions = createBindingPropsMigrationIds('myCustomBinding', {\n * AddNewProperty: 1,\n * UpdateProperty: 2\n * })\n *\n * // Result:\n * // {\n * // AddNewProperty: 'com.tldraw.binding.myCustomBinding/1',\n * // UpdateProperty: 'com.tldraw.binding.myCustomBinding/2'\n * // }\n * ```\n *\n * @public\n */\nexport function createBindingPropsMigrationIds<S extends string, T extends Record<string, number>>(\n\tbindingType: S,\n\tids: T\n): { [k in keyof T]: `com.tldraw.binding.${S}/${T[k]}` } {\n\treturn mapObjectMapValues(ids, (_k, v) => `com.tldraw.binding.${bindingType}/${v}`) as any\n}\n\n/**\n * Creates a record type for TLBinding with validation based on the provided binding schemas.\n * This function is used internally to configure the binding record type in the schema.\n *\n * @param bindings - Record mapping binding type names to their schema information\n * @returns A configured record type for bindings with validation\n *\n * @example\n * ```ts\n * // Used internally when creating schemas\n * const bindingRecordType = createBindingRecordType({\n * arrow: {\n * props: arrowBindingProps,\n * meta: arrowBindingMeta\n * }\n * })\n * ```\n *\n * @internal\n */\nexport function createBindingRecordType(bindings: Record<string, SchemaPropsInfo>) {\n\treturn createRecordType<TLBinding>('binding', {\n\t\tscope: 'document',\n\t\tvalidator: T.model(\n\t\t\t'binding',\n\t\t\tT.union(\n\t\t\t\t'type',\n\t\t\t\tmapObjectMapValues(bindings, (type, { props, meta }) =>\n\t\t\t\t\tcreateBindingValidator(type, props, meta)\n\t\t\t\t)\n\t\t\t)\n\t\t),\n\t}).withDefaultProperties(() => ({\n\t\tmeta: {},\n\t}))\n}\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAiB,oBAAoB,gBAAgB;AACrD,SAAS,SAAS;AAElB,SAAwB,8BAA8B;AA8K/C,MAAM,sBAAsB,mBAAmB,sBAAsB,CAAC,CAAU;AAiBhF,MAAM,wBAAwB,8BAA8B;AAAA,EAClE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,UAAU,CAAC;AACZ,CAAC;AA0BM,SAAS,UAAU,QAA6C;AACtE,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,aAAa;AAC5B;AAyBO,SAAS,YAAY,IAAgC;AAC3D,MAAI,CAAC,GAAI,QAAO;AAChB,SAAO,GAAG,WAAW,UAAU;AAChC;AA6BO,SAAS,gBAAgB,IAA0B;AACzD,SAAO,WAAW,MAAM,SAAS,CAAC;AACnC;AAyBO,SAAS,oCACf,YACoB;AACpB,SAAO;AACR;AA2BO,SAAS,+BACf,aACA,KACwD;AACxD,SAAO,mBAAmB,KAAK,CAAC,IAAI,MAAM,sBAAsB,WAAW,IAAI,CAAC,EAAE;AACnF;AAsBO,SAAS,wBAAwB,UAA2C;AAClF,SAAO,iBAA4B,WAAW;AAAA,IAC7C,OAAO;AAAA,IACP,WAAW,EAAE;AAAA,MACZ;AAAA,MACA,EAAE;AAAA,QACD;AAAA,QACA;AAAA,UAAmB;AAAA,UAAU,CAAC,MAAM,EAAE,OAAO,KAAK,MACjD,uBAAuB,MAAM,OAAO,IAAI;AAAA,QACzC;AAAA,MACD;AAAA,IACD;AAAA,EACD,CAAC,EAAE,sBAAsB,OAAO;AAAA,IAC/B,MAAM,CAAC;AAAA,EACR,EAAE;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|