@tldraw/tlschema 4.3.0-next.7810f2131b3c → 4.3.0-next.7f179bd04d6c
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 +160 -37
- 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 +160 -37
- 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 +25 -14
- package/src/createTLSchema.ts +8 -2
- package/src/index.ts +6 -0
- package/src/records/TLAsset.ts +2 -2
- package/src/records/TLBinding.ts +65 -23
- package/src/records/TLRecord.test.ts +17 -5
- package/src/records/TLShape.ts +100 -5
- package/src/shapes/ShapeWithCrop.ts +2 -2
- package/src/shapes/TLBaseShape.ts +34 -10
- package/src/store-migrations.ts +2 -1
package/dist-esm/index.d.mts
CHANGED
|
@@ -1478,6 +1478,24 @@ 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
|
+
|
|
1481
1499
|
/**
|
|
1482
1500
|
* Migration sequence for frame shape properties across different schema versions.
|
|
1483
1501
|
* Handles adding color properties to existing frame shapes.
|
|
@@ -2599,7 +2617,7 @@ export declare const shapeIdValidator: T.Validator<TLShapeId>;
|
|
|
2599
2617
|
*
|
|
2600
2618
|
* @public
|
|
2601
2619
|
*/
|
|
2602
|
-
export declare type ShapeWithCrop =
|
|
2620
|
+
export declare type ShapeWithCrop = ExtractShapeByProps<{
|
|
2603
2621
|
crop: null | TLShapeCrop;
|
|
2604
2622
|
h: number;
|
|
2605
2623
|
w: number;
|
|
@@ -3140,10 +3158,8 @@ export declare type TLAssetPartial<T extends TLAsset = TLAsset> = T extends T ?
|
|
|
3140
3158
|
*
|
|
3141
3159
|
* @public
|
|
3142
3160
|
*/
|
|
3143
|
-
export declare type TLAssetShape =
|
|
3144
|
-
|
|
3145
|
-
assetId: TLAssetId;
|
|
3146
|
-
};
|
|
3161
|
+
export declare type TLAssetShape = ExtractShapeByProps<{
|
|
3162
|
+
assetId: TLAssetId;
|
|
3147
3163
|
}>;
|
|
3148
3164
|
|
|
3149
3165
|
/**
|
|
@@ -3253,33 +3269,41 @@ export declare interface TLBaseAsset<Type extends string, Props> extends BaseRec
|
|
|
3253
3269
|
* Base interface for all binding types in tldraw. Bindings represent relationships
|
|
3254
3270
|
* between shapes, such as arrows connecting to other shapes or organizational connections.
|
|
3255
3271
|
*
|
|
3256
|
-
* All bindings extend this base interface with specific type and property definitions.
|
|
3272
|
+
* All default bindings extend this base interface with specific type and property definitions.
|
|
3257
3273
|
* The binding system enables shapes to maintain relationships that persist through
|
|
3258
3274
|
* transformations, movements, and other operations.
|
|
3259
3275
|
*
|
|
3276
|
+
* Custom bindings should be defined by augmenting the TLGlobalBindingPropsMap type and getting the binding type from the TLBinding type.
|
|
3277
|
+
*
|
|
3260
3278
|
* @param Type - String literal type identifying the specific binding type (e.g., 'arrow')
|
|
3261
3279
|
* @param Props - Object containing binding-specific properties and configuration
|
|
3262
3280
|
*
|
|
3263
3281
|
* @example
|
|
3264
3282
|
* ```ts
|
|
3265
|
-
* // Define a
|
|
3266
|
-
* interface
|
|
3283
|
+
* // Define a default binding type
|
|
3284
|
+
* interface TLArrowBinding extends TLBaseBinding<'arrow', TLArrowBindingProps> {}
|
|
3267
3285
|
*
|
|
3268
|
-
* interface
|
|
3269
|
-
*
|
|
3270
|
-
*
|
|
3286
|
+
* interface TLArrowBindingProps {
|
|
3287
|
+
* terminal: 'start' | 'end'
|
|
3288
|
+
* normalizedAnchor: VecModel
|
|
3289
|
+
* isExact: boolean
|
|
3290
|
+
* isPrecise: boolean
|
|
3291
|
+
* snap: ElbowArrowSnap
|
|
3271
3292
|
* }
|
|
3272
3293
|
*
|
|
3273
3294
|
* // Create a binding instance
|
|
3274
|
-
* const
|
|
3295
|
+
* const arrowBinding: TLArrowBinding = {
|
|
3275
3296
|
* id: 'binding:abc123',
|
|
3276
3297
|
* typeName: 'binding',
|
|
3277
|
-
* type: '
|
|
3298
|
+
* type: 'arrow',
|
|
3278
3299
|
* fromId: 'shape:source1',
|
|
3279
3300
|
* toId: 'shape:target1',
|
|
3280
3301
|
* props: {
|
|
3281
|
-
*
|
|
3282
|
-
*
|
|
3302
|
+
* terminal: 'end',
|
|
3303
|
+
* normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
3304
|
+
* isExact: false,
|
|
3305
|
+
* isPrecise: true,
|
|
3306
|
+
* snap: 'edge'
|
|
3283
3307
|
* },
|
|
3284
3308
|
* meta: {}
|
|
3285
3309
|
* }
|
|
@@ -3287,7 +3311,9 @@ export declare interface TLBaseAsset<Type extends string, Props> extends BaseRec
|
|
|
3287
3311
|
*
|
|
3288
3312
|
* @public
|
|
3289
3313
|
*/
|
|
3290
|
-
export declare interface TLBaseBinding<Type extends string, Props extends object>
|
|
3314
|
+
export declare interface TLBaseBinding<Type extends string, Props extends object> {
|
|
3315
|
+
readonly id: TLBindingId;
|
|
3316
|
+
readonly typeName: 'binding';
|
|
3291
3317
|
/** The specific type of this binding (e.g., 'arrow', 'custom') */
|
|
3292
3318
|
type: Type;
|
|
3293
3319
|
/** ID of the source shape in this binding relationship */
|
|
@@ -3304,18 +3330,37 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3304
3330
|
* Base interface for all shapes in tldraw.
|
|
3305
3331
|
*
|
|
3306
3332
|
* This interface defines the common properties that all shapes share, regardless of their
|
|
3307
|
-
* specific type. Every shape extends this base with additional type-specific properties.
|
|
3308
|
-
*
|
|
3309
|
-
*
|
|
3310
|
-
*
|
|
3311
|
-
*
|
|
3312
|
-
*
|
|
3333
|
+
* specific type. Every default shape extends this base with additional type-specific properties.
|
|
3334
|
+
*
|
|
3335
|
+
* Custom shapes should be defined by augmenting the TLGlobalShapePropsMap type and getting the shape type from the TLShape type.
|
|
3336
|
+
*
|
|
3337
|
+
* @example
|
|
3338
|
+
* ```ts
|
|
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
|
+
* }> {}
|
|
3313
3358
|
*
|
|
3314
3359
|
* // Create a shape instance
|
|
3315
|
-
* const
|
|
3360
|
+
* const arrowShape: TLArrowShape = {
|
|
3316
3361
|
* id: 'shape:abc123',
|
|
3317
3362
|
* typeName: 'shape',
|
|
3318
|
-
* type: '
|
|
3363
|
+
* type: 'arrow',
|
|
3319
3364
|
* x: 100,
|
|
3320
3365
|
* y: 200,
|
|
3321
3366
|
* rotation: 0,
|
|
@@ -3324,8 +3369,10 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3324
3369
|
* isLocked: false,
|
|
3325
3370
|
* opacity: 1,
|
|
3326
3371
|
* props: {
|
|
3327
|
-
*
|
|
3328
|
-
*
|
|
3372
|
+
* kind: 'arc',
|
|
3373
|
+
* start: { x: 0, y: 0 },
|
|
3374
|
+
* end: { x: 100, y: 100 },
|
|
3375
|
+
* // ... other props
|
|
3329
3376
|
* },
|
|
3330
3377
|
* meta: {}
|
|
3331
3378
|
* }
|
|
@@ -3333,7 +3380,9 @@ export declare interface TLBaseBinding<Type extends string, Props extends object
|
|
|
3333
3380
|
*
|
|
3334
3381
|
* @public
|
|
3335
3382
|
*/
|
|
3336
|
-
export declare interface TLBaseShape<Type extends string, Props extends object>
|
|
3383
|
+
export declare interface TLBaseShape<Type extends string, Props extends object> {
|
|
3384
|
+
readonly id: TLShapeId;
|
|
3385
|
+
readonly typeName: 'shape';
|
|
3337
3386
|
type: Type;
|
|
3338
3387
|
x: number;
|
|
3339
3388
|
y: number;
|
|
@@ -3347,9 +3396,12 @@ export declare interface TLBaseShape<Type extends string, Props extends object>
|
|
|
3347
3396
|
}
|
|
3348
3397
|
|
|
3349
3398
|
/**
|
|
3350
|
-
* The set of all bindings that are available in the editor
|
|
3399
|
+
* The set of all bindings that are available in the editor.
|
|
3351
3400
|
* Bindings represent relationships between shapes, such as arrows connecting to other shapes.
|
|
3352
3401
|
*
|
|
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
|
+
*
|
|
3353
3405
|
* @example
|
|
3354
3406
|
* ```ts
|
|
3355
3407
|
* // Check binding type and handle accordingly
|
|
@@ -3363,11 +3415,16 @@ export declare interface TLBaseShape<Type extends string, Props extends object>
|
|
|
3363
3415
|
* break
|
|
3364
3416
|
* }
|
|
3365
3417
|
* }
|
|
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
|
+
* }
|
|
3366
3423
|
* ```
|
|
3367
3424
|
*
|
|
3368
3425
|
* @public
|
|
3369
3426
|
*/
|
|
3370
|
-
export declare type TLBinding =
|
|
3427
|
+
export declare type TLBinding<K extends keyof TLIndexedBindings = keyof TLIndexedBindings> = TLIndexedBindings[K];
|
|
3371
3428
|
|
|
3372
3429
|
/**
|
|
3373
3430
|
* Type for creating new bindings with required fromId and toId.
|
|
@@ -3393,7 +3450,7 @@ export declare type TLBinding = TLDefaultBinding | TLUnknownBinding;
|
|
|
3393
3450
|
*
|
|
3394
3451
|
* @public
|
|
3395
3452
|
*/
|
|
3396
|
-
export declare type TLBindingCreate<T extends TLBinding = TLBinding> =
|
|
3453
|
+
export declare type TLBindingCreate<T extends TLBinding = TLBinding> = T extends T ? {
|
|
3397
3454
|
fromId: T['fromId'];
|
|
3398
3455
|
id?: TLBindingId;
|
|
3399
3456
|
meta?: Partial<T['meta']>;
|
|
@@ -3401,7 +3458,7 @@ export declare type TLBindingCreate<T extends TLBinding = TLBinding> = Expand<{
|
|
|
3401
3458
|
toId: T['toId'];
|
|
3402
3459
|
type: T['type'];
|
|
3403
3460
|
typeName?: T['typeName'];
|
|
3404
|
-
}
|
|
3461
|
+
} : never;
|
|
3405
3462
|
|
|
3406
3463
|
/**
|
|
3407
3464
|
* Branded string type for binding record identifiers.
|
|
@@ -3426,7 +3483,7 @@ export declare type TLBindingCreate<T extends TLBinding = TLBinding> = Expand<{
|
|
|
3426
3483
|
*
|
|
3427
3484
|
* @public
|
|
3428
3485
|
*/
|
|
3429
|
-
export declare type TLBindingId = RecordId<
|
|
3486
|
+
export declare type TLBindingId = RecordId<TLBinding>;
|
|
3430
3487
|
|
|
3431
3488
|
/**
|
|
3432
3489
|
* Type for updating existing bindings with partial properties.
|
|
@@ -3448,7 +3505,7 @@ export declare type TLBindingId = RecordId<TLUnknownBinding>;
|
|
|
3448
3505
|
*
|
|
3449
3506
|
* @public
|
|
3450
3507
|
*/
|
|
3451
|
-
export declare type TLBindingUpdate<T extends TLBinding = TLBinding> =
|
|
3508
|
+
export declare type TLBindingUpdate<T extends TLBinding = TLBinding> = T extends T ? {
|
|
3452
3509
|
fromId?: T['fromId'];
|
|
3453
3510
|
id: TLBindingId;
|
|
3454
3511
|
meta?: Partial<T['meta']>;
|
|
@@ -3456,7 +3513,7 @@ export declare type TLBindingUpdate<T extends TLBinding = TLBinding> = Expand<{
|
|
|
3456
3513
|
toId?: T['toId'];
|
|
3457
3514
|
type: T['type'];
|
|
3458
3515
|
typeName?: T['typeName'];
|
|
3459
|
-
}
|
|
3516
|
+
} : never;
|
|
3460
3517
|
|
|
3461
3518
|
/**
|
|
3462
3519
|
* An asset used for URL bookmarks, used by the TLBookmarkShape.
|
|
@@ -3596,6 +3653,39 @@ export declare type TLCameraId = RecordId<TLCamera>;
|
|
|
3596
3653
|
*/
|
|
3597
3654
|
export declare type TLCanvasUiColor = SetValue<typeof TL_CANVAS_UI_COLOR_TYPES>;
|
|
3598
3655
|
|
|
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
|
+
|
|
3599
3689
|
/**
|
|
3600
3690
|
* A cursor object used throughout the tldraw editor.
|
|
3601
3691
|
*
|
|
@@ -4260,6 +4350,14 @@ export declare interface TLGeoShapeProps {
|
|
|
4260
4350
|
richText: TLRichText;
|
|
4261
4351
|
}
|
|
4262
4352
|
|
|
4353
|
+
/** @public */
|
|
4354
|
+
export declare interface TLGlobalBindingPropsMap {
|
|
4355
|
+
}
|
|
4356
|
+
|
|
4357
|
+
/** @public */
|
|
4358
|
+
export declare interface TLGlobalShapePropsMap {
|
|
4359
|
+
}
|
|
4360
|
+
|
|
4263
4361
|
/**
|
|
4264
4362
|
* A group shape that acts as a container for organizing multiple shapes into a single logical unit.
|
|
4265
4363
|
* Groups enable users to move, transform, and manage collections of shapes together while maintaining
|
|
@@ -4537,6 +4635,22 @@ export declare interface TLImageShapeProps {
|
|
|
4537
4635
|
altText: string;
|
|
4538
4636
|
}
|
|
4539
4637
|
|
|
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
|
+
|
|
4540
4654
|
/**
|
|
4541
4655
|
* State that is particular to a single browser tab. The TLInstance record stores
|
|
4542
4656
|
* all session-specific state including cursor position, selected tools, UI preferences,
|
|
@@ -5372,11 +5486,15 @@ export declare interface TLScribble {
|
|
|
5372
5486
|
export declare type TLSerializedStore = SerializedStore<TLRecord>;
|
|
5373
5487
|
|
|
5374
5488
|
/**
|
|
5375
|
-
* The set of all shapes that are available in the editor
|
|
5489
|
+
* The set of all shapes that are available in the editor.
|
|
5376
5490
|
*
|
|
5377
5491
|
* This is the primary shape type used throughout tldraw. It includes both the
|
|
5378
5492
|
* built-in default shapes and any custom shapes that might be added.
|
|
5379
5493
|
*
|
|
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
|
+
*
|
|
5380
5498
|
* @example
|
|
5381
5499
|
* ```ts
|
|
5382
5500
|
* // Work with any shape in the editor
|
|
@@ -5387,11 +5505,16 @@ export declare type TLSerializedStore = SerializedStore<TLRecord>;
|
|
|
5387
5505
|
* y: shape.y + deltaY
|
|
5388
5506
|
* }
|
|
5389
5507
|
* }
|
|
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
|
+
* }
|
|
5390
5513
|
* ```
|
|
5391
5514
|
*
|
|
5392
5515
|
* @public
|
|
5393
5516
|
*/
|
|
5394
|
-
export declare type TLShape =
|
|
5517
|
+
export declare type TLShape<K extends keyof TLIndexedShapes = keyof TLIndexedShapes> = TLIndexedShapes[K];
|
|
5395
5518
|
|
|
5396
5519
|
/**
|
|
5397
5520
|
* Defines cropping parameters for shapes that support cropping.
|
|
@@ -5438,7 +5561,7 @@ export declare interface TLShapeCrop {
|
|
|
5438
5561
|
*
|
|
5439
5562
|
* @public
|
|
5440
5563
|
*/
|
|
5441
|
-
export declare type TLShapeId = RecordId<
|
|
5564
|
+
export declare type TLShapeId = RecordId<TLShape>;
|
|
5442
5565
|
|
|
5443
5566
|
/**
|
|
5444
5567
|
* 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 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,
|
|
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 TLGlobalBindingPropsMap,\n\ttype TLIndexedBindings,\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 ExtractShapeByProps,\n\ttype TLCreateShapePartial,\n\ttype TLDefaultShape,\n\ttype TLGlobalShapePropsMap,\n\ttype TLIndexedShapes,\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,OASM;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,OAWM;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 { ExtractShapeByProps } 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 = ExtractShapeByProps<{ 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 { 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,
|
|
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,SAAS,oBAAoB,gBAAgB;AAC7C,SAAS,SAAS;AAElB,SAAwB,8BAA8B;AAwN/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,iBAAiB,WAAW;AAAA,IAClC,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
|
}
|