@tldraw/tlschema 4.6.0-next.d8328a2dcc3d → 4.6.0-next.e390fde97eab
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/assets/TLBaseAsset.js +4 -3
- package/dist-cjs/assets/TLBaseAsset.js.map +2 -2
- package/dist-cjs/assets/TLBookmarkAsset.js +9 -7
- package/dist-cjs/assets/TLBookmarkAsset.js.map +2 -2
- package/dist-cjs/assets/TLImageAsset.js +12 -10
- package/dist-cjs/assets/TLImageAsset.js.map +2 -2
- package/dist-cjs/assets/TLVideoAsset.js +11 -9
- package/dist-cjs/assets/TLVideoAsset.js.map +2 -2
- package/dist-cjs/createTLSchema.js +10 -4
- package/dist-cjs/createTLSchema.js.map +2 -2
- package/dist-cjs/index.d.ts +601 -343
- package/dist-cjs/index.js +17 -7
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/records/TLAsset.js +29 -14
- package/dist-cjs/records/TLAsset.js.map +2 -2
- package/dist-cjs/shapes/TLFrameShape.js +3 -1
- package/dist-cjs/shapes/TLFrameShape.js.map +2 -2
- package/dist-cjs/shapes/TLNoteShape.js +12 -2
- package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
- package/dist-cjs/styles/StyleProp.js +38 -1
- package/dist-cjs/styles/StyleProp.js.map +2 -2
- package/dist-cjs/styles/TLColorStyle.js +36 -487
- package/dist-cjs/styles/TLColorStyle.js.map +2 -2
- package/dist-cjs/styles/TLDashStyle.js +1 -1
- package/dist-cjs/styles/TLDashStyle.js.map +2 -2
- package/dist-cjs/styles/TLFontFace.js +17 -0
- package/dist-cjs/styles/TLFontFace.js.map +7 -0
- package/dist-cjs/styles/TLFontStyle.js +36 -1
- package/dist-cjs/styles/TLFontStyle.js.map +2 -2
- package/dist-cjs/styles/TLTheme.js +17 -0
- package/dist-cjs/styles/TLTheme.js.map +7 -0
- package/dist-esm/assets/TLBaseAsset.mjs +4 -3
- package/dist-esm/assets/TLBaseAsset.mjs.map +2 -2
- package/dist-esm/assets/TLBookmarkAsset.mjs +9 -7
- package/dist-esm/assets/TLBookmarkAsset.mjs.map +2 -2
- package/dist-esm/assets/TLImageAsset.mjs +12 -10
- package/dist-esm/assets/TLImageAsset.mjs.map +2 -2
- package/dist-esm/assets/TLVideoAsset.mjs +11 -9
- package/dist-esm/assets/TLVideoAsset.mjs.map +2 -2
- package/dist-esm/createTLSchema.mjs +17 -8
- package/dist-esm/createTLSchema.mjs.map +2 -2
- package/dist-esm/index.d.mts +601 -343
- package/dist-esm/index.mjs +28 -14
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/records/TLAsset.mjs +29 -14
- package/dist-esm/records/TLAsset.mjs.map +2 -2
- package/dist-esm/shapes/TLFrameShape.mjs +3 -1
- package/dist-esm/shapes/TLFrameShape.mjs.map +2 -2
- package/dist-esm/shapes/TLNoteShape.mjs +12 -2
- package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
- package/dist-esm/styles/StyleProp.mjs +38 -1
- package/dist-esm/styles/StyleProp.mjs.map +2 -2
- package/dist-esm/styles/TLColorStyle.mjs +36 -487
- package/dist-esm/styles/TLColorStyle.mjs.map +2 -2
- package/dist-esm/styles/TLDashStyle.mjs +1 -1
- package/dist-esm/styles/TLDashStyle.mjs.map +2 -2
- package/dist-esm/styles/TLFontFace.mjs +1 -0
- package/dist-esm/styles/TLFontFace.mjs.map +7 -0
- package/dist-esm/styles/TLFontStyle.mjs +36 -1
- package/dist-esm/styles/TLFontStyle.mjs.map +2 -2
- package/dist-esm/styles/TLTheme.mjs +1 -0
- package/dist-esm/styles/TLTheme.mjs.map +7 -0
- package/package.json +5 -5
- package/src/assets/TLBaseAsset.ts +25 -28
- package/src/assets/TLBookmarkAsset.ts +13 -33
- package/src/assets/TLImageAsset.ts +16 -42
- package/src/assets/TLVideoAsset.ts +15 -40
- package/src/createTLSchema.ts +54 -15
- package/src/index.ts +31 -11
- package/src/migrations.test.ts +22 -0
- package/src/records/TLAsset.ts +139 -74
- package/src/shapes/TLFrameShape.ts +3 -1
- package/src/shapes/TLNoteShape.ts +19 -5
- package/src/styles/StyleProp.ts +42 -5
- package/src/styles/TLColorStyle.ts +55 -698
- package/src/styles/TLDashStyle.ts +1 -1
- package/src/styles/TLFontFace.ts +65 -0
- package/src/styles/TLFontStyle.ts +53 -4
- package/src/styles/TLTheme.ts +240 -0
|
@@ -25,13 +25,14 @@ module.exports = __toCommonJS(TLBaseAsset_exports);
|
|
|
25
25
|
var import_validate = require("@tldraw/validate");
|
|
26
26
|
var import_id_validator = require("../misc/id-validator");
|
|
27
27
|
const assetIdValidator = (0, import_id_validator.idValidator)("asset");
|
|
28
|
-
function createAssetValidator(type, props) {
|
|
28
|
+
function createAssetValidator(type, props, meta) {
|
|
29
|
+
const propsValidator = props instanceof import_validate.T.Validator ? props : props ? import_validate.T.object(props) : import_validate.T.jsonValue;
|
|
29
30
|
return import_validate.T.object({
|
|
30
31
|
id: assetIdValidator,
|
|
31
32
|
typeName: import_validate.T.literal("asset"),
|
|
32
33
|
type: import_validate.T.literal(type),
|
|
33
|
-
props,
|
|
34
|
-
meta: import_validate.T.jsonValue
|
|
34
|
+
props: propsValidator,
|
|
35
|
+
meta: meta ? import_validate.T.object(meta) : import_validate.T.jsonValue
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
//# sourceMappingURL=TLBaseAsset.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/assets/TLBaseAsset.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseRecord } from '@tldraw/store'\nimport { JsonObject } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { idValidator } from '../misc/id-validator'\nimport { TLAssetId } from '../records/TLAsset'\n\n/**\n * Base interface for all asset records in tldraw. Assets represent external resources\n * like images, videos, or bookmarks that shapes can reference. This interface extends\n * the base record system with asset-specific typing.\n *\n * @param Type - The specific asset type identifier (e.g., 'image', 'video', 'bookmark')\n * @param Props - The properties object specific to this asset type\n *\n * @example\n * ```ts\n * // Define a custom asset type\n * interface MyCustomAsset extends TLBaseAsset<'custom', { url: string; title: string }> {}\n *\n * const customAsset: MyCustomAsset = {\n * id: 'asset:custom123',\n * typeName: 'asset',\n * type: 'custom',\n * props: {\n * url: 'https://example.com',\n * title: 'My Custom Asset'\n * },\n * meta: {}\n * }\n * ```\n *\n * @public\n */\nexport interface TLBaseAsset<Type extends string, Props> extends BaseRecord<'asset', TLAssetId> {\n\t/** The specific type of this asset (e.g., 'image', 'video', 'bookmark') */\n\ttype: Type\n\t/** Type-specific properties for this asset */\n\tprops: Props\n\t/** User-defined metadata that can be attached to this asset */\n\tmeta: JsonObject\n}\n\n/**\n * A validator for asset record type IDs. This validator ensures that asset IDs\n * follow the correct format and type structure required by tldraw's asset system.\n * Asset IDs are prefixed with 'asset:' followed by a unique identifier.\n *\n * @example\n * ```ts\n * import { assetIdValidator } from '@tldraw/tlschema'\n *\n * // Valid asset ID\n * const validId = 'asset:abc123'\n * console.log(assetIdValidator.isValid(validId)) // true\n *\n * // Invalid asset ID\n * const invalidId = 'shape:abc123'\n * console.log(assetIdValidator.isValid(invalidId)) // false\n * ```\n *\n * @public\n */\nexport const assetIdValidator = idValidator<TLAssetId>('asset')\n\n/**\n * Creates a validator for a specific asset record type. This factory function generates\n * a complete validator that validates the entire asset record structure including the\n * base properties (id, typeName, type, meta) and the type-specific props.\n *\n * @param type - The asset type identifier (e.g., 'image', 'video', 'bookmark')\n * @param props -
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAkB;AAClB,0BAA4B;AA2DrB,MAAM,uBAAmB,iCAAuB,OAAO;
|
|
4
|
+
"sourcesContent": ["import { BaseRecord } from '@tldraw/store'\nimport { JsonObject } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { idValidator } from '../misc/id-validator'\nimport { TLAssetId } from '../records/TLAsset'\n\n/**\n * Base interface for all asset records in tldraw. Assets represent external resources\n * like images, videos, or bookmarks that shapes can reference. This interface extends\n * the base record system with asset-specific typing.\n *\n * @param Type - The specific asset type identifier (e.g., 'image', 'video', 'bookmark')\n * @param Props - The properties object specific to this asset type\n *\n * @example\n * ```ts\n * // Define a custom asset type\n * interface MyCustomAsset extends TLBaseAsset<'custom', { url: string; title: string }> {}\n *\n * const customAsset: MyCustomAsset = {\n * id: 'asset:custom123',\n * typeName: 'asset',\n * type: 'custom',\n * props: {\n * url: 'https://example.com',\n * title: 'My Custom Asset'\n * },\n * meta: {}\n * }\n * ```\n *\n * @public\n */\nexport interface TLBaseAsset<Type extends string, Props> extends BaseRecord<'asset', TLAssetId> {\n\t/** The specific type of this asset (e.g., 'image', 'video', 'bookmark') */\n\ttype: Type\n\t/** Type-specific properties for this asset */\n\tprops: Props\n\t/** User-defined metadata that can be attached to this asset */\n\tmeta: JsonObject\n}\n\n/**\n * A validator for asset record type IDs. This validator ensures that asset IDs\n * follow the correct format and type structure required by tldraw's asset system.\n * Asset IDs are prefixed with 'asset:' followed by a unique identifier.\n *\n * @example\n * ```ts\n * import { assetIdValidator } from '@tldraw/tlschema'\n *\n * // Valid asset ID\n * const validId = 'asset:abc123'\n * console.log(assetIdValidator.isValid(validId)) // true\n *\n * // Invalid asset ID\n * const invalidId = 'shape:abc123'\n * console.log(assetIdValidator.isValid(invalidId)) // false\n * ```\n *\n * @public\n */\nexport const assetIdValidator = idValidator<TLAssetId>('asset')\n\n/**\n * Creates a validator for a specific asset record type. This factory function generates\n * a complete validator that validates the entire asset record structure including the\n * base properties (id, typeName, type, meta) and the type-specific props.\n *\n * @param type - The asset type identifier (e.g., 'image', 'video', 'bookmark')\n * @param props - A validator or per-key validator record for the asset's type-specific properties\n * @param meta - An optional per-key validator record for the asset's meta properties\n * @returns A complete validator for the asset record type\n *\n * @example\n * ```ts\n * import { createAssetValidator, TLBaseAsset } from '@tldraw/tlschema'\n * import { T } from '@tldraw/validate'\n *\n * // Define a custom asset type\n * type TLCustomAsset = TLBaseAsset<'custom', {\n * url: string\n * title: string\n * description?: string\n * }>\n *\n * // Create validator using a per-key record (recommended)\n * const customAssetValidator = createAssetValidator('custom', {\n * url: T.string,\n * title: T.string,\n * description: T.string.optional()\n * })\n *\n * // Or using a T.object validator\n * const customAssetValidator2 = createAssetValidator('custom', T.object({\n * url: T.string,\n * title: T.string,\n * description: T.string.optional()\n * }))\n * ```\n *\n * @public\n */\nexport function createAssetValidator<\n\tType extends string,\n\tProps extends JsonObject,\n\tMeta extends JsonObject = JsonObject,\n>(\n\ttype: Type,\n\tprops?: T.Validator<Props> | { [K in keyof Props]: T.Validatable<Props[K]> },\n\tmeta?: { [K in keyof Meta]: T.Validatable<Meta[K]> }\n) {\n\t// Determine if props is a Validator instance or a per-key record\n\tconst propsValidator =\n\t\tprops instanceof T.Validator ? props : props ? T.object(props) : (T.jsonValue as any)\n\n\treturn T.object<TLBaseAsset<Type, Props>>({\n\t\tid: assetIdValidator,\n\t\ttypeName: T.literal('asset'),\n\t\ttype: T.literal(type),\n\t\tprops: propsValidator,\n\t\tmeta: meta ? T.object(meta) : (T.jsonValue as T.ObjectValidator<JsonObject>),\n\t})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAkB;AAClB,0BAA4B;AA2DrB,MAAM,uBAAmB,iCAAuB,OAAO;AAyCvD,SAAS,qBAKf,MACA,OACA,MACC;AAED,QAAM,iBACL,iBAAiB,kBAAE,YAAY,QAAQ,QAAQ,kBAAE,OAAO,KAAK,IAAK,kBAAE;AAErE,SAAO,kBAAE,OAAiC;AAAA,IACzC,IAAI;AAAA,IACJ,UAAU,kBAAE,QAAQ,OAAO;AAAA,IAC3B,MAAM,kBAAE,QAAQ,IAAI;AAAA,IACpB,OAAO;AAAA,IACP,MAAM,OAAO,kBAAE,OAAO,IAAI,IAAK,kBAAE;AAAA,EAClC,CAAC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var TLBookmarkAsset_exports = {};
|
|
20
20
|
__export(TLBookmarkAsset_exports, {
|
|
21
21
|
bookmarkAssetMigrations: () => bookmarkAssetMigrations,
|
|
22
|
+
bookmarkAssetProps: () => bookmarkAssetProps,
|
|
22
23
|
bookmarkAssetValidator: () => bookmarkAssetValidator,
|
|
23
24
|
bookmarkAssetVersions: () => Versions
|
|
24
25
|
});
|
|
@@ -26,15 +27,16 @@ module.exports = __toCommonJS(TLBookmarkAsset_exports);
|
|
|
26
27
|
var import_store = require("@tldraw/store");
|
|
27
28
|
var import_validate = require("@tldraw/validate");
|
|
28
29
|
var import_TLBaseAsset = require("./TLBaseAsset");
|
|
30
|
+
const bookmarkAssetProps = {
|
|
31
|
+
title: import_validate.T.string,
|
|
32
|
+
description: import_validate.T.string,
|
|
33
|
+
image: import_validate.T.string,
|
|
34
|
+
favicon: import_validate.T.string,
|
|
35
|
+
src: import_validate.T.srcUrl.nullable()
|
|
36
|
+
};
|
|
29
37
|
const bookmarkAssetValidator = (0, import_TLBaseAsset.createAssetValidator)(
|
|
30
38
|
"bookmark",
|
|
31
|
-
import_validate.T.object(
|
|
32
|
-
title: import_validate.T.string,
|
|
33
|
-
description: import_validate.T.string,
|
|
34
|
-
image: import_validate.T.string,
|
|
35
|
-
favicon: import_validate.T.string,
|
|
36
|
-
src: import_validate.T.srcUrl.nullable()
|
|
37
|
-
})
|
|
39
|
+
import_validate.T.object(bookmarkAssetProps)
|
|
38
40
|
);
|
|
39
41
|
const Versions = (0, import_store.createMigrationIds)("com.tldraw.asset.bookmark", {
|
|
40
42
|
MakeUrlsValid: 1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/assets/TLBookmarkAsset.ts"],
|
|
4
|
-
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;
|
|
4
|
+
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { RecordProps } from '../recordsWithProps'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset used for URL bookmarks, used by the TLBookmarkShape.\n *\n * @public */\nexport type TLBookmarkAsset = TLBaseAsset<\n\t'bookmark',\n\t{\n\t\ttitle: string\n\t\tdescription: string\n\t\timage: string\n\t\tfavicon: string\n\t\tsrc: string | null\n\t}\n>\n\n/** @public */\nexport const bookmarkAssetProps = {\n\ttitle: T.string,\n\tdescription: T.string,\n\timage: T.string,\n\tfavicon: T.string,\n\tsrc: T.srcUrl.nullable(),\n} satisfies RecordProps<TLBookmarkAsset>\n\n/** Validator for bookmark assets. @public */\nexport const bookmarkAssetValidator: T.Validator<TLBookmarkAsset> = createAssetValidator(\n\t'bookmark',\n\tT.object(bookmarkAssetProps)\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.bookmark', {\n\tMakeUrlsValid: 1,\n\tAddFavicon: 2,\n} as const)\n\n/**\n * Migration version identifiers for bookmark assets. These versions track\n * the evolution of the bookmark asset schema over time.\n *\n * Available versions:\n * - `MakeUrlsValid` (v1): Ensures src URLs are valid or empty\n * - `AddFavicon` (v2): Adds favicon property to bookmark assets\n *\n * @example\n * ```ts\n * import { bookmarkAssetVersions } from '@tldraw/tlschema'\n *\n * // Check if a migration exists\n * console.log(bookmarkAssetVersions.AddFavicon) // 2\n * ```\n *\n * @public\n */\nexport { Versions as bookmarkAssetVersions }\n\n/**\n * Migration sequence for bookmark assets. Handles the evolution of bookmark asset\n * data structure over time, ensuring backward and forward compatibility.\n *\n * The migration sequence includes:\n * 1. **MakeUrlsValid** (v1): Validates and cleans up src URLs, setting invalid URLs to empty string\n * 2. **AddFavicon** (v2): Adds the favicon property and validates it, setting invalid favicons to empty string\n *\n * @public\n */\nexport const bookmarkAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.bookmark',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLBookmarkAsset).type === 'bookmark',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFavicon,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.favicon)) {\n\t\t\t\t\tasset.props.favicon = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.favicon\n\t\t\t},\n\t\t},\n\t],\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;AAkB3C,MAAM,qBAAqB;AAAA,EACjC,OAAO,kBAAE;AAAA,EACT,aAAa,kBAAE;AAAA,EACf,OAAO,kBAAE;AAAA,EACT,SAAS,kBAAE;AAAA,EACX,KAAK,kBAAE,OAAO,SAAS;AACxB;AAGO,MAAM,6BAAuD;AAAA,EACnE;AAAA,EACA,kBAAE,OAAO,kBAAkB;AAC5B;AAEA,MAAM,eAAW,iCAAmB,6BAA6B;AAAA,EAChE,eAAe;AAAA,EACf,YAAY;AACb,CAAU;AAgCH,MAAM,8BAA0B,4CAA8B;AAAA,EACpE,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,QAAQ,CAAC,UAAW,MAA0B,SAAS;AAAA,EACvD,UAAU;AAAA,IACT;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,CAAC,kBAAE,OAAO,QAAQ,MAAM,MAAM,GAAG,GAAG;AACvC,gBAAM,MAAM,MAAM;AAAA,QACnB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,WAAW;AAAA,MAElB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,CAAC,kBAAE,OAAO,QAAQ,MAAM,MAAM,OAAO,GAAG;AAC3C,gBAAM,MAAM,UAAU;AAAA,QACvB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,EACD;AACD,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var TLImageAsset_exports = {};
|
|
20
20
|
__export(TLImageAsset_exports, {
|
|
21
21
|
imageAssetMigrations: () => imageAssetMigrations,
|
|
22
|
+
imageAssetProps: () => imageAssetProps,
|
|
22
23
|
imageAssetValidator: () => imageAssetValidator,
|
|
23
24
|
imageAssetVersions: () => Versions
|
|
24
25
|
});
|
|
@@ -26,18 +27,19 @@ module.exports = __toCommonJS(TLImageAsset_exports);
|
|
|
26
27
|
var import_store = require("@tldraw/store");
|
|
27
28
|
var import_validate = require("@tldraw/validate");
|
|
28
29
|
var import_TLBaseAsset = require("./TLBaseAsset");
|
|
30
|
+
const imageAssetProps = {
|
|
31
|
+
w: import_validate.T.number,
|
|
32
|
+
h: import_validate.T.number,
|
|
33
|
+
name: import_validate.T.string,
|
|
34
|
+
isAnimated: import_validate.T.boolean,
|
|
35
|
+
mimeType: import_validate.T.string.nullable(),
|
|
36
|
+
src: import_validate.T.srcUrl.nullable(),
|
|
37
|
+
fileSize: import_validate.T.nonZeroNumber.optional(),
|
|
38
|
+
pixelRatio: import_validate.T.positiveNumber.optional()
|
|
39
|
+
};
|
|
29
40
|
const imageAssetValidator = (0, import_TLBaseAsset.createAssetValidator)(
|
|
30
41
|
"image",
|
|
31
|
-
import_validate.T.object(
|
|
32
|
-
w: import_validate.T.number,
|
|
33
|
-
h: import_validate.T.number,
|
|
34
|
-
name: import_validate.T.string,
|
|
35
|
-
isAnimated: import_validate.T.boolean,
|
|
36
|
-
mimeType: import_validate.T.string.nullable(),
|
|
37
|
-
src: import_validate.T.srcUrl.nullable(),
|
|
38
|
-
fileSize: import_validate.T.nonZeroNumber.optional(),
|
|
39
|
-
pixelRatio: import_validate.T.positiveNumber.optional()
|
|
40
|
-
})
|
|
42
|
+
import_validate.T.object(imageAssetProps)
|
|
41
43
|
);
|
|
42
44
|
const Versions = (0, import_store.createMigrationIds)("com.tldraw.asset.image", {
|
|
43
45
|
AddIsAnimated: 1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/assets/TLImageAsset.ts"],
|
|
4
|
-
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;
|
|
4
|
+
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { RecordProps } from '../recordsWithProps'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset for images such as PNGs and JPEGs, used by the TLImageShape.\n *\n * @public */\nexport type TLImageAsset = TLBaseAsset<\n\t'image',\n\t{\n\t\tw: number\n\t\th: number\n\t\tname: string\n\t\tisAnimated: boolean\n\t\tmimeType: string | null\n\t\tsrc: string | null\n\t\tfileSize?: number\n\t\tpixelRatio?: number\n\t}\n>\n\n/** @public */\nexport const imageAssetProps = {\n\tw: T.number,\n\th: T.number,\n\tname: T.string,\n\tisAnimated: T.boolean,\n\tmimeType: T.string.nullable(),\n\tsrc: T.srcUrl.nullable(),\n\tfileSize: T.nonZeroNumber.optional(),\n\tpixelRatio: T.positiveNumber.optional(),\n} satisfies RecordProps<TLImageAsset>\n\n/** Validator for image assets. @public */\nexport const imageAssetValidator: T.Validator<TLImageAsset> = createAssetValidator(\n\t'image',\n\tT.object(imageAssetProps)\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.image', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n\tAddPixelRatio: 6,\n} as const)\n\n/**\n * Migration version identifiers for image assets. These define the different schema versions\n * that image assets have gone through during the evolution of the tldraw data model.\n *\n * @example\n * ```ts\n * import { imageAssetVersions } from '@tldraw/tlschema'\n *\n * // Access specific version IDs\n * console.log(imageAssetVersions.AddIsAnimated) // Version when isAnimated was added\n * console.log(imageAssetVersions.RenameWidthHeight) // Version when width/height became w/h\n * ```\n *\n * @public\n */\nexport { Versions as imageAssetVersions }\n\n/**\n * Migration sequence for image assets. Handles the evolution of the image asset schema\n * over time, providing both forward (up) and backward (down) migration functions to\n * maintain compatibility across different versions of the tldraw data model.\n *\n * The sequence includes migrations for:\n * - Adding the `isAnimated` property to track animated images\n * - Renaming `width`/`height` properties to shorter `w`/`h` names\n * - Ensuring URLs are valid format\n * - Adding file size tracking\n * - Making file size optional\n *\n *\n * @public\n */\nexport const imageAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.image',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLImageAsset).type === 'image',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddPixelRatio,\n\t\t\tup: (_asset: any) => {\n\t\t\t\t// noop \u2014 pixelRatio is optional and undefined by default\n\t\t\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,MACA,MAAM,CAAC,UAAe;AACrB,cAAM,MAAM,QAAQ,MAAM,MAAM;AAChC,cAAM,MAAM,SAAS,MAAM,MAAM;AACjC,eAAO,MAAM,MAAM;AACnB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,CAAC,kBAAE,OAAO,QAAQ,MAAM,MAAM,GAAG,GAAG;AACvC,gBAAM,MAAM,MAAM;AAAA,QACnB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,WAAW;AAAA,MAElB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,cAAM,MAAM,WAAW;AAAA,MACxB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,UAAe;AACnB,YAAI,MAAM,MAAM,aAAa,IAAI;AAChC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,YAAI,MAAM,MAAM,aAAa,QAAW;AACvC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAAA,IACA;AAAA,MACC,IAAI,SAAS;AAAA,MACb,IAAI,CAAC,WAAgB;AAAA,MAErB;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,eAAO,MAAM,MAAM;AAAA,MACpB;AAAA,IACD;AAAA,EACD;AACD,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var TLVideoAsset_exports = {};
|
|
20
20
|
__export(TLVideoAsset_exports, {
|
|
21
21
|
videoAssetMigrations: () => videoAssetMigrations,
|
|
22
|
+
videoAssetProps: () => videoAssetProps,
|
|
22
23
|
videoAssetValidator: () => videoAssetValidator,
|
|
23
24
|
videoAssetVersions: () => Versions
|
|
24
25
|
});
|
|
@@ -26,17 +27,18 @@ module.exports = __toCommonJS(TLVideoAsset_exports);
|
|
|
26
27
|
var import_store = require("@tldraw/store");
|
|
27
28
|
var import_validate = require("@tldraw/validate");
|
|
28
29
|
var import_TLBaseAsset = require("./TLBaseAsset");
|
|
30
|
+
const videoAssetProps = {
|
|
31
|
+
w: import_validate.T.number,
|
|
32
|
+
h: import_validate.T.number,
|
|
33
|
+
name: import_validate.T.string,
|
|
34
|
+
isAnimated: import_validate.T.boolean,
|
|
35
|
+
mimeType: import_validate.T.string.nullable(),
|
|
36
|
+
src: import_validate.T.srcUrl.nullable(),
|
|
37
|
+
fileSize: import_validate.T.number.optional()
|
|
38
|
+
};
|
|
29
39
|
const videoAssetValidator = (0, import_TLBaseAsset.createAssetValidator)(
|
|
30
40
|
"video",
|
|
31
|
-
import_validate.T.object(
|
|
32
|
-
w: import_validate.T.number,
|
|
33
|
-
h: import_validate.T.number,
|
|
34
|
-
name: import_validate.T.string,
|
|
35
|
-
isAnimated: import_validate.T.boolean,
|
|
36
|
-
mimeType: import_validate.T.string.nullable(),
|
|
37
|
-
src: import_validate.T.srcUrl.nullable(),
|
|
38
|
-
fileSize: import_validate.T.number.optional()
|
|
39
|
-
})
|
|
41
|
+
import_validate.T.object(videoAssetProps)
|
|
40
42
|
);
|
|
41
43
|
const Versions = (0, import_store.createMigrationIds)("com.tldraw.asset.video", {
|
|
42
44
|
AddIsAnimated: 1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/assets/TLVideoAsset.ts"],
|
|
4
|
-
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;
|
|
4
|
+
"sourcesContent": ["import { createMigrationIds, createRecordMigrationSequence } from '@tldraw/store'\nimport { T } from '@tldraw/validate'\nimport { RecordProps } from '../recordsWithProps'\nimport { TLBaseAsset, createAssetValidator } from './TLBaseAsset'\n\n/**\n * An asset record representing video files that can be displayed in video shapes.\n * Video assets store metadata about video files including dimensions, MIME type,\n * animation status, and file source information. They are referenced by TLVideoShape\n * instances to display video content on the canvas.\n *\n * @example\n * ```ts\n * import { TLVideoAsset } from '@tldraw/tlschema'\n *\n * const videoAsset: TLVideoAsset = {\n * id: 'asset:video123',\n * typeName: 'asset',\n * type: 'video',\n * props: {\n * w: 1920,\n * h: 1080,\n * name: 'my-video.mp4',\n * isAnimated: true,\n * mimeType: 'video/mp4',\n * src: 'https://example.com/video.mp4',\n * fileSize: 5242880\n * },\n * meta: {}\n * }\n * ```\n *\n * @public\n */\nexport type TLVideoAsset = TLBaseAsset<\n\t'video',\n\t{\n\t\t/** The width of the video in pixels */\n\t\tw: number\n\t\t/** The height of the video in pixels */\n\t\th: number\n\t\t/** The original filename or display name of the video */\n\t\tname: string\n\t\t/** Whether the video contains animation/motion (true for most videos) */\n\t\tisAnimated: boolean\n\t\t/** The MIME type of the video file (e.g., 'video/mp4', 'video/webm'), null if unknown */\n\t\tmimeType: string | null\n\t\t/** The source URL or data URI for the video file, null if not yet available */\n\t\tsrc: string | null\n\t\t/** The file size in bytes, optional for backward compatibility */\n\t\tfileSize?: number\n\t}\n>\n\n/** @public */\nexport const videoAssetProps = {\n\tw: T.number,\n\th: T.number,\n\tname: T.string,\n\tisAnimated: T.boolean,\n\tmimeType: T.string.nullable(),\n\tsrc: T.srcUrl.nullable(),\n\tfileSize: T.number.optional(),\n} satisfies RecordProps<TLVideoAsset>\n\n/** Validator for video assets. @public */\nexport const videoAssetValidator: T.Validator<TLVideoAsset> = createAssetValidator(\n\t'video',\n\tT.object(videoAssetProps)\n)\n\nconst Versions = createMigrationIds('com.tldraw.asset.video', {\n\tAddIsAnimated: 1,\n\tRenameWidthHeight: 2,\n\tMakeUrlsValid: 3,\n\tAddFileSize: 4,\n\tMakeFileSizeOptional: 5,\n} as const)\n\n/**\n * Version identifiers for video asset migration sequences. These versions track\n * the evolution of the video asset schema over time, enabling proper data migration\n * when the asset structure changes.\n *\n * @example\n * ```ts\n * import { videoAssetVersions } from '@tldraw/tlschema'\n *\n * // Check the current version of a specific migration\n * console.log(videoAssetVersions.AddFileSize) // 4\n * ```\n *\n * @public\n */\nexport { Versions as videoAssetVersions }\n\n/**\n * Migration sequence for video assets that handles schema evolution over time.\n * This sequence defines how video asset data should be transformed when upgrading\n * or downgrading between different schema versions. Each migration step handles\n * specific changes like adding properties, renaming fields, or changing data formats.\n *\n * The migrations handle:\n * - Adding animation detection (isAnimated property)\n * - Renaming width/height properties to w/h for consistency\n * - Ensuring URL validity for src properties\n * - Adding file size tracking\n * - Making file size optional for backward compatibility\n *\n * @public\n */\nexport const videoAssetMigrations = createRecordMigrationSequence({\n\tsequenceId: 'com.tldraw.asset.video',\n\trecordType: 'asset',\n\tfilter: (asset) => (asset as TLVideoAsset).type === 'video',\n\tsequence: [\n\t\t{\n\t\t\tid: Versions.AddIsAnimated,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.isAnimated = false\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.isAnimated\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.RenameWidthHeight,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.w = asset.props.width\n\t\t\t\tasset.props.h = asset.props.height\n\t\t\t\tdelete asset.props.width\n\t\t\t\tdelete asset.props.height\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tasset.props.width = asset.props.w\n\t\t\t\tasset.props.height = asset.props.h\n\t\t\t\tdelete asset.props.w\n\t\t\t\tdelete asset.props.h\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeUrlsValid,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (!T.srcUrl.isValid(asset.props.src)) {\n\t\t\t\t\tasset.props.src = ''\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (_asset) => {\n\t\t\t\t// noop\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.AddFileSize,\n\t\t\tup: (asset: any) => {\n\t\t\t\tasset.props.fileSize = -1\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tdelete asset.props.fileSize\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tid: Versions.MakeFileSizeOptional,\n\t\t\tup: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === -1) {\n\t\t\t\t\tasset.props.fileSize = undefined\n\t\t\t\t}\n\t\t\t},\n\t\t\tdown: (asset: any) => {\n\t\t\t\tif (asset.props.fileSize === undefined) {\n\t\t\t\t\tasset.props.fileSize = -1\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t],\n})\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkE;AAClE,sBAAkB;AAElB,yBAAkD;AAoD3C,MAAM,kBAAkB;AAAA,EAC9B,GAAG,kBAAE;AAAA,EACL,GAAG,kBAAE;AAAA,EACL,MAAM,kBAAE;AAAA,EACR,YAAY,kBAAE;AAAA,EACd,UAAU,kBAAE,OAAO,SAAS;AAAA,EAC5B,KAAK,kBAAE,OAAO,SAAS;AAAA,EACvB,UAAU,kBAAE,OAAO,SAAS;AAC7B;AAGO,MAAM,0BAAiD;AAAA,EAC7D;AAAA,EACA,kBAAE,OAAO,eAAe;AACzB;AAEA,MAAM,eAAW,iCAAmB,0BAA0B;AAAA,EAC7D,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,eAAe;AAAA,EACf,aAAa;AAAA,EAC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;AAAA,MACD;AAAA,MACA,MAAM,CAAC,UAAe;AACrB,YAAI,MAAM,MAAM,aAAa,QAAW;AACvC,gBAAM,MAAM,WAAW;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var createTLSchema_exports = {};
|
|
20
20
|
__export(createTLSchema_exports, {
|
|
21
21
|
createTLSchema: () => createTLSchema,
|
|
22
|
+
defaultAssetSchemas: () => defaultAssetSchemas,
|
|
22
23
|
defaultBindingSchemas: () => defaultBindingSchemas,
|
|
23
24
|
defaultShapeSchemas: () => defaultShapeSchemas
|
|
24
25
|
});
|
|
@@ -75,9 +76,15 @@ const defaultShapeSchemas = {
|
|
|
75
76
|
const defaultBindingSchemas = {
|
|
76
77
|
arrow: { migrations: import_TLArrowBinding.arrowBindingMigrations, props: import_TLArrowBinding.arrowBindingProps }
|
|
77
78
|
};
|
|
79
|
+
const defaultAssetSchemas = {
|
|
80
|
+
image: { migrations: import_TLImageAsset.imageAssetMigrations, props: import_TLImageAsset.imageAssetProps },
|
|
81
|
+
video: { migrations: import_TLVideoAsset.videoAssetMigrations, props: import_TLVideoAsset.videoAssetProps },
|
|
82
|
+
bookmark: { migrations: import_TLBookmarkAsset.bookmarkAssetMigrations, props: import_TLBookmarkAsset.bookmarkAssetProps }
|
|
83
|
+
};
|
|
78
84
|
function createTLSchema({
|
|
79
85
|
shapes = defaultShapeSchemas,
|
|
80
86
|
bindings = defaultBindingSchemas,
|
|
87
|
+
assets = defaultAssetSchemas,
|
|
81
88
|
user,
|
|
82
89
|
records = {},
|
|
83
90
|
migrations
|
|
@@ -93,6 +100,7 @@ function createTLSchema({
|
|
|
93
100
|
}
|
|
94
101
|
const ShapeRecordType = (0, import_TLShape.createShapeRecordType)(shapes);
|
|
95
102
|
const BindingRecordType = (0, import_TLBinding.createBindingRecordType)(bindings);
|
|
103
|
+
const _AssetRecordType = (0, import_TLAsset.createAssetRecordType)(assets);
|
|
96
104
|
const InstanceRecordType = (0, import_TLInstance.createInstanceRecordType)(stylesById);
|
|
97
105
|
const CustomUserRecordType = user ? (0, import_TLUser.createUserRecordType)(user) : import_TLUser.UserRecordType;
|
|
98
106
|
const builtInTypeNames = /* @__PURE__ */ new Set([
|
|
@@ -120,7 +128,7 @@ function createTLSchema({
|
|
|
120
128
|
}
|
|
121
129
|
return import_store.StoreSchema.create(
|
|
122
130
|
{
|
|
123
|
-
asset:
|
|
131
|
+
asset: _AssetRecordType,
|
|
124
132
|
binding: BindingRecordType,
|
|
125
133
|
camera: import_TLCamera.CameraRecordType,
|
|
126
134
|
document: import_TLDocument.DocumentRecordType,
|
|
@@ -146,9 +154,7 @@ function createTLSchema({
|
|
|
146
154
|
import_TLPointer.pointerMigrations,
|
|
147
155
|
import_TLShape.rootShapeMigrations,
|
|
148
156
|
import_TLUser.userMigrations,
|
|
149
|
-
|
|
150
|
-
import_TLImageAsset.imageAssetMigrations,
|
|
151
|
-
import_TLVideoAsset.videoAssetMigrations,
|
|
157
|
+
...(0, import_recordsWithProps.processPropsMigrations)("asset", assets),
|
|
152
158
|
...(0, import_recordsWithProps.processPropsMigrations)("shape", shapes),
|
|
153
159
|
...(0, import_recordsWithProps.processPropsMigrations)("binding", bindings),
|
|
154
160
|
...(0, import_TLCustomRecord.processCustomRecordMigrations)(records),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/createTLSchema.ts"],
|
|
4
|
-
"sourcesContent": ["import { LegacyMigrations, MigrationSequence, StoreSchema, StoreValidator } from '@tldraw/store'\nimport { objectMapValues } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { bookmarkAssetMigrations } from './assets/TLBookmarkAsset'\nimport { imageAssetMigrations } from './assets/TLImageAsset'\nimport { videoAssetMigrations } from './assets/TLVideoAsset'\nimport { arrowBindingMigrations, arrowBindingProps } from './bindings/TLArrowBinding'\nimport { AssetRecordType, assetMigrations } from './records/TLAsset'\nimport { TLBinding, TLDefaultBinding, createBindingRecordType } from './records/TLBinding'\nimport { CameraRecordType, cameraMigrations } from './records/TLCamera'\nimport {\n\tCustomRecordInfo,\n\tcreateCustomRecordType,\n\tprocessCustomRecordMigrations,\n} from './records/TLCustomRecord'\nimport { DocumentRecordType, documentMigrations } from './records/TLDocument'\nimport { createInstanceRecordType, instanceMigrations } from './records/TLInstance'\nimport { PageRecordType, pageMigrations } from './records/TLPage'\nimport { InstancePageStateRecordType, instancePageStateMigrations } from './records/TLPageState'\nimport { PointerRecordType, pointerMigrations } from './records/TLPointer'\nimport { InstancePresenceRecordType, instancePresenceMigrations } from './records/TLPresence'\nimport { TLRecord } from './records/TLRecord'\nimport {\n\tTLDefaultShape,\n\tTLShape,\n\tcreateShapeRecordType,\n\tgetShapePropKeysByStyle,\n\trootShapeMigrations,\n} from './records/TLShape'\nimport { UserRecordType, createUserRecordType, userMigrations } from './records/TLUser'\nimport { RecordProps, TLPropsMigrations, processPropsMigrations } from './recordsWithProps'\nimport { arrowShapeMigrations, arrowShapeProps } from './shapes/TLArrowShape'\nimport { TLBaseShape } from './shapes/TLBaseShape'\nimport { bookmarkShapeMigrations, bookmarkShapeProps } from './shapes/TLBookmarkShape'\nimport { drawShapeMigrations, drawShapeProps } from './shapes/TLDrawShape'\nimport { embedShapeMigrations, embedShapeProps } from './shapes/TLEmbedShape'\nimport { frameShapeMigrations, frameShapeProps } from './shapes/TLFrameShape'\nimport { geoShapeMigrations, geoShapeProps } from './shapes/TLGeoShape'\nimport { groupShapeMigrations, groupShapeProps } from './shapes/TLGroupShape'\nimport { highlightShapeMigrations, highlightShapeProps } from './shapes/TLHighlightShape'\nimport { imageShapeMigrations, imageShapeProps } from './shapes/TLImageShape'\nimport { lineShapeMigrations, lineShapeProps } from './shapes/TLLineShape'\nimport { noteShapeMigrations, noteShapeProps } from './shapes/TLNoteShape'\nimport { textShapeMigrations, textShapeProps } from './shapes/TLTextShape'\nimport { videoShapeMigrations, videoShapeProps } from './shapes/TLVideoShape'\nimport { storeMigrations } from './store-migrations'\nimport { StyleProp } from './styles/StyleProp'\nimport { TLStoreProps, createIntegrityChecker, onValidationFailure } from './TLStore'\n\n/**\n * Configuration information for a schema type (shape or binding), including its properties,\n * metadata, and migration sequences for data evolution over time.\n *\n * @public\n * @example\n * ```ts\n * import { arrowShapeMigrations, arrowShapeProps } from './shapes/TLArrowShape'\n *\n * const myShapeSchema: SchemaPropsInfo = {\n * migrations: arrowShapeMigrations,\n * props: arrowShapeProps,\n * meta: {\n * customField: T.string,\n * },\n * }\n * ```\n */\nexport interface SchemaPropsInfo {\n\t/**\n\t * Migration sequences for handling data evolution over time. Can be legacy migrations,\n\t * props-specific migrations, or general migration sequences.\n\t */\n\tmigrations?: LegacyMigrations | TLPropsMigrations | MigrationSequence\n\n\t/**\n\t * Validation schema for the shape or binding properties. Maps property names to their validators.\n\t */\n\tprops?: Record<string, StoreValidator<any>>\n\n\t/**\n\t * Validation schema for metadata fields. Maps metadata field names to their validators.\n\t */\n\tmeta?: Record<string, StoreValidator<any>>\n}\n\n/**\n * The complete schema definition for a tldraw store, encompassing all record types,\n * validation rules, and migration sequences. This schema defines the structure of\n * the persistent data model used by tldraw.\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'\n * import { Store } from '@tldraw/store'\n *\n * const schema: TLSchema = createTLSchema({\n * shapes: defaultShapeSchemas,\n * })\n *\n * const store = new Store({ schema })\n * ```\n */\nexport type TLSchema = StoreSchema<TLRecord, TLStoreProps>\n\n/**\n * Default shape schema configurations for all built-in tldraw shape types.\n * Each shape type includes its validation props and migration sequences.\n *\n * This object contains schema information for:\n * - arrow: Directional lines that can bind to other shapes\n * - bookmark: Website bookmark cards with preview information\n * - draw: Freehand drawing paths created with drawing tools\n * - embed: Embedded content from external services (YouTube, Figma, etc.)\n * - frame: Container shapes for organizing content\n * - geo: Geometric shapes (rectangles, ellipses, triangles, etc.)\n * - group: Logical groupings of multiple shapes\n * - highlight: Highlighting strokes from the highlighter tool\n * - image: Raster image shapes referencing image assets\n * - line: Multi-point lines and splines\n * - note: Sticky note shapes with text content\n * - text: Rich text shapes with formatting support\n * - video: Video shapes referencing video assets\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'\n *\n * // Use all default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas,\n * })\n *\n * // Use only specific default shapes\n * const minimalSchema = createTLSchema({\n * shapes: {\n * geo: defaultShapeSchemas.geo,\n * text: defaultShapeSchemas.text,\n * },\n * })\n * ```\n */\nexport const defaultShapeSchemas = {\n\tarrow: { migrations: arrowShapeMigrations, props: arrowShapeProps },\n\tbookmark: { migrations: bookmarkShapeMigrations, props: bookmarkShapeProps },\n\tdraw: { migrations: drawShapeMigrations, props: drawShapeProps },\n\tembed: { migrations: embedShapeMigrations, props: embedShapeProps },\n\tframe: { migrations: frameShapeMigrations, props: frameShapeProps },\n\tgeo: { migrations: geoShapeMigrations, props: geoShapeProps },\n\tgroup: { migrations: groupShapeMigrations, props: groupShapeProps },\n\thighlight: { migrations: highlightShapeMigrations, props: highlightShapeProps },\n\timage: { migrations: imageShapeMigrations, props: imageShapeProps },\n\tline: { migrations: lineShapeMigrations, props: lineShapeProps },\n\tnote: { migrations: noteShapeMigrations, props: noteShapeProps },\n\ttext: { migrations: textShapeMigrations, props: textShapeProps },\n\tvideo: { migrations: videoShapeMigrations, props: videoShapeProps },\n} satisfies {\n\t[T in TLDefaultShape['type']]: {\n\t\tmigrations: SchemaPropsInfo['migrations']\n\t\tprops: RecordProps<TLBaseShape<T, Extract<TLDefaultShape, { type: T }>['props']>>\n\t}\n}\n\n/**\n * Default binding schema configurations for all built-in tldraw binding types.\n * Bindings represent relationships between shapes, such as arrows connected to shapes.\n *\n * Currently includes:\n * - arrow: Bindings that connect arrow shapes to other shapes at specific anchor points\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultBindingSchemas } from '@tldraw/tlschema'\n *\n * // Use default bindings\n * const schema = createTLSchema({\n * bindings: defaultBindingSchemas,\n * })\n *\n * // Add custom binding alongside defaults\n * const customSchema = createTLSchema({\n * bindings: {\n * ...defaultBindingSchemas,\n * myCustomBinding: {\n * props: myCustomBindingProps,\n * migrations: myCustomBindingMigrations,\n * },\n * },\n * })\n * ```\n */\nexport const defaultBindingSchemas = {\n\tarrow: { migrations: arrowBindingMigrations, props: arrowBindingProps },\n} satisfies { [T in TLDefaultBinding['type']]: SchemaPropsInfo }\n\n/**\n * Configuration for extending the user record type with custom metadata\n * validators and migration sequences.\n *\n * @example\n * ```ts\n * import { T } from '@tldraw/validate'\n *\n * const userSchema: UserSchemaInfo = {\n * meta: {\n * isAdmin: T.boolean,\n * department: T.string,\n * },\n * }\n * ```\n *\n * @public\n */\nexport interface UserSchemaInfo {\n\t/**\n\t * Validators for custom metadata fields on user records. Each field is\n\t * treated as optional \u2014 user records without these fields remain valid,\n\t * but when present, values are validated against the provided validators.\n\t */\n\tmeta?: Record<string, T.Validatable<any>>\n\n\t/**\n\t * Additional migration sequences for evolving custom user data over time.\n\t */\n\tmigrations?: readonly MigrationSequence[]\n}\n\n/**\n * Creates a complete TLSchema for use with tldraw stores. This schema defines the structure,\n * validation, and migration sequences for all record types in a tldraw application.\n *\n * The schema includes all core record types (pages, cameras, instances, etc.) plus the\n * shape, binding, and custom record types you specify. Style properties are automatically\n * collected from all shapes to ensure consistency across the application.\n *\n * @param options - Configuration options for the schema\n * - shapes - Shape schema configurations. Defaults to defaultShapeSchemas if not provided\n * - bindings - Binding schema configurations. Defaults to defaultBindingSchemas if not provided\n * - user - Custom user record configuration with meta validators and migrations\n * - records - Custom record type configurations. These are additional record types beyond\n * the built-in shapes, bindings, assets, etc.\n * - migrations - Additional migration sequences to include in the schema\n * @returns A complete TLSchema ready for use with Store creation\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, defaultBindingSchemas } from '@tldraw/tlschema'\n * import { Store } from '@tldraw/store'\n *\n * // Create schema with all default shapes and bindings\n * const schema = createTLSchema()\n *\n * // Create schema with custom shapes added\n * const customSchema = createTLSchema({\n * shapes: {\n * ...defaultShapeSchemas,\n * myCustomShape: {\n * props: myCustomShapeProps,\n * migrations: myCustomShapeMigrations,\n * },\n * },\n * })\n *\n * // Create schema with custom user metadata\n * const schemaWithCustomUser = createTLSchema({\n * user: {\n * meta: {\n * isAdmin: T.boolean,\n * department: T.string,\n * },\n * },\n * })\n *\n * // Create schema with custom record types\n * const schemaWithCustomRecords = createTLSchema({\n * records: {\n * comment: {\n * scope: 'document',\n * validator: T.object({\n * id: T.string,\n * typeName: T.literal('comment'),\n * text: T.string,\n * shapeId: T.string,\n * }),\n * },\n * },\n * })\n *\n * // Use the schema with a store\n * const store = new Store({\n * schema: customSchema,\n * props: {\n * defaultName: 'My Drawing',\n * },\n * })\n * ```\n */\nexport function createTLSchema({\n\tshapes = defaultShapeSchemas,\n\tbindings = defaultBindingSchemas,\n\tuser,\n\trecords = {},\n\tmigrations,\n}: {\n\tshapes?: Record<string, SchemaPropsInfo>\n\tbindings?: Record<string, SchemaPropsInfo>\n\tuser?: UserSchemaInfo\n\trecords?: Record<string, CustomRecordInfo>\n\tmigrations?: readonly MigrationSequence[]\n} = {}): TLSchema {\n\tconst stylesById = new Map<string, StyleProp<unknown>>()\n\tfor (const shape of objectMapValues(shapes)) {\n\t\tfor (const style of getShapePropKeysByStyle(shape.props ?? {}).keys()) {\n\t\t\tif (stylesById.has(style.id) && stylesById.get(style.id) !== style) {\n\t\t\t\tthrow new Error(`Multiple StyleProp instances with the same id: ${style.id}`)\n\t\t\t}\n\t\t\tstylesById.set(style.id, style)\n\t\t}\n\t}\n\n\tconst ShapeRecordType = createShapeRecordType(shapes)\n\tconst BindingRecordType = createBindingRecordType(bindings)\n\tconst InstanceRecordType = createInstanceRecordType(stylesById)\n\tconst CustomUserRecordType = user ? createUserRecordType(user) : UserRecordType\n\n\t// Create RecordTypes for custom records\n\tconst builtInTypeNames = new Set([\n\t\t'asset',\n\t\t'binding',\n\t\t'camera',\n\t\t'document',\n\t\t'instance',\n\t\t'instance_page_state',\n\t\t'page',\n\t\t'instance_presence',\n\t\t'pointer',\n\t\t'shape',\n\t\t'store',\n\t\t'user',\n\t])\n\tconst customRecordTypes: Record<string, { createId: any }> = {}\n\tfor (const [typeName, config] of Object.entries(records)) {\n\t\tif (builtInTypeNames.has(typeName)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Custom record type name '${typeName}' conflicts with tldraw's built-in record type of that name. Choose a different name instead.`\n\t\t\t)\n\t\t}\n\t\tcustomRecordTypes[typeName] = createCustomRecordType(typeName, config)\n\t}\n\n\treturn StoreSchema.create(\n\t\t{\n\t\t\tasset: AssetRecordType,\n\t\t\tbinding: BindingRecordType,\n\t\t\tcamera: CameraRecordType,\n\t\t\tdocument: DocumentRecordType,\n\t\t\tinstance: InstanceRecordType,\n\t\t\tinstance_page_state: InstancePageStateRecordType,\n\t\t\tpage: PageRecordType,\n\t\t\tinstance_presence: InstancePresenceRecordType,\n\t\t\tpointer: PointerRecordType,\n\t\t\tshape: ShapeRecordType,\n\t\t\tuser: CustomUserRecordType,\n\t\t\t...customRecordTypes,\n\t\t},\n\t\t{\n\t\t\tmigrations: [\n\t\t\t\tstoreMigrations,\n\t\t\t\tassetMigrations,\n\t\t\t\tcameraMigrations,\n\t\t\t\tdocumentMigrations,\n\t\t\t\tinstanceMigrations,\n\t\t\t\tinstancePageStateMigrations,\n\t\t\t\tpageMigrations,\n\t\t\t\tinstancePresenceMigrations,\n\t\t\t\tpointerMigrations,\n\t\t\t\trootShapeMigrations,\n\n\t\t\t\tuserMigrations,\n\t\t\t\tbookmarkAssetMigrations,\n\t\t\t\timageAssetMigrations,\n\t\t\t\tvideoAssetMigrations,\n\n\t\t\t\t...processPropsMigrations<TLShape>('shape', shapes),\n\t\t\t\t...processPropsMigrations<TLBinding>('binding', bindings),\n\t\t\t\t...processCustomRecordMigrations(records),\n\n\t\t\t\t...(user?.migrations ?? []),\n\t\t\t\t...(migrations ?? []),\n\t\t\t],\n\t\t\tonValidationFailure,\n\t\t\tcreateIntegrityChecker,\n\t\t}\n\t)\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiF;AACjF,mBAAgC;
|
|
4
|
+
"sourcesContent": ["import { LegacyMigrations, MigrationSequence, StoreSchema, StoreValidator } from '@tldraw/store'\nimport { objectMapValues } from '@tldraw/utils'\nimport { T } from '@tldraw/validate'\nimport { TLBaseAsset } from './assets/TLBaseAsset'\nimport { bookmarkAssetMigrations, bookmarkAssetProps } from './assets/TLBookmarkAsset'\nimport { imageAssetMigrations, imageAssetProps } from './assets/TLImageAsset'\nimport { videoAssetMigrations, videoAssetProps } from './assets/TLVideoAsset'\nimport { arrowBindingMigrations, arrowBindingProps } from './bindings/TLArrowBinding'\nimport {\n\tTLDefaultAsset,\n\tTLUnknownAsset,\n\tassetMigrations,\n\tcreateAssetRecordType,\n} from './records/TLAsset'\nimport { TLBinding, TLDefaultBinding, createBindingRecordType } from './records/TLBinding'\nimport { CameraRecordType, cameraMigrations } from './records/TLCamera'\nimport {\n\tCustomRecordInfo,\n\tcreateCustomRecordType,\n\tprocessCustomRecordMigrations,\n} from './records/TLCustomRecord'\nimport { DocumentRecordType, documentMigrations } from './records/TLDocument'\nimport { createInstanceRecordType, instanceMigrations } from './records/TLInstance'\nimport { PageRecordType, pageMigrations } from './records/TLPage'\nimport { InstancePageStateRecordType, instancePageStateMigrations } from './records/TLPageState'\nimport { PointerRecordType, pointerMigrations } from './records/TLPointer'\nimport { InstancePresenceRecordType, instancePresenceMigrations } from './records/TLPresence'\nimport { TLRecord } from './records/TLRecord'\nimport {\n\tTLDefaultShape,\n\tTLShape,\n\tcreateShapeRecordType,\n\tgetShapePropKeysByStyle,\n\trootShapeMigrations,\n} from './records/TLShape'\nimport { UserRecordType, createUserRecordType, userMigrations } from './records/TLUser'\nimport { RecordProps, TLPropsMigrations, processPropsMigrations } from './recordsWithProps'\nimport { arrowShapeMigrations, arrowShapeProps } from './shapes/TLArrowShape'\nimport { TLBaseShape } from './shapes/TLBaseShape'\nimport { bookmarkShapeMigrations, bookmarkShapeProps } from './shapes/TLBookmarkShape'\nimport { drawShapeMigrations, drawShapeProps } from './shapes/TLDrawShape'\nimport { embedShapeMigrations, embedShapeProps } from './shapes/TLEmbedShape'\nimport { frameShapeMigrations, frameShapeProps } from './shapes/TLFrameShape'\nimport { geoShapeMigrations, geoShapeProps } from './shapes/TLGeoShape'\nimport { groupShapeMigrations, groupShapeProps } from './shapes/TLGroupShape'\nimport { highlightShapeMigrations, highlightShapeProps } from './shapes/TLHighlightShape'\nimport { imageShapeMigrations, imageShapeProps } from './shapes/TLImageShape'\nimport { lineShapeMigrations, lineShapeProps } from './shapes/TLLineShape'\nimport { noteShapeMigrations, noteShapeProps } from './shapes/TLNoteShape'\nimport { textShapeMigrations, textShapeProps } from './shapes/TLTextShape'\nimport { videoShapeMigrations, videoShapeProps } from './shapes/TLVideoShape'\nimport { storeMigrations } from './store-migrations'\nimport { StyleProp } from './styles/StyleProp'\nimport { TLStoreProps, createIntegrityChecker, onValidationFailure } from './TLStore'\n\n/**\n * Configuration information for a schema type (shape, binding, or asset), including its properties,\n * metadata, and migration sequences for data evolution over time.\n *\n * @public\n * @example\n * ```ts\n * import { arrowShapeMigrations, arrowShapeProps } from './shapes/TLArrowShape'\n *\n * const myShapeSchema: SchemaPropsInfo = {\n * migrations: arrowShapeMigrations,\n * props: arrowShapeProps,\n * meta: {\n * customField: T.string,\n * },\n * }\n * ```\n */\nexport interface SchemaPropsInfo {\n\t/**\n\t * Migration sequences for handling data evolution over time. Can be legacy migrations,\n\t * props-specific migrations, or general migration sequences.\n\t */\n\tmigrations?: LegacyMigrations | TLPropsMigrations | MigrationSequence\n\n\t/**\n\t * Validation schema for the shape, binding, or asset properties.\n\t */\n\tprops?: Record<string, StoreValidator<any>>\n\n\t/**\n\t * Validation schema for metadata fields.\n\t */\n\tmeta?: Record<string, StoreValidator<any>>\n}\n\n/**\n * The complete schema definition for a tldraw store, encompassing all record types,\n * validation rules, and migration sequences. This schema defines the structure of\n * the persistent data model used by tldraw.\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'\n * import { Store } from '@tldraw/store'\n *\n * const schema: TLSchema = createTLSchema({\n * shapes: defaultShapeSchemas,\n * })\n *\n * const store = new Store({ schema })\n * ```\n */\nexport type TLSchema = StoreSchema<TLRecord, TLStoreProps>\n\n/**\n * Default shape schema configurations for all built-in tldraw shape types.\n * Each shape type includes its validation props and migration sequences.\n *\n * This object contains schema information for:\n * - arrow: Directional lines that can bind to other shapes\n * - bookmark: Website bookmark cards with preview information\n * - draw: Freehand drawing paths created with drawing tools\n * - embed: Embedded content from external services (YouTube, Figma, etc.)\n * - frame: Container shapes for organizing content\n * - geo: Geometric shapes (rectangles, ellipses, triangles, etc.)\n * - group: Logical groupings of multiple shapes\n * - highlight: Highlighting strokes from the highlighter tool\n * - image: Raster image shapes referencing image assets\n * - line: Multi-point lines and splines\n * - note: Sticky note shapes with text content\n * - text: Rich text shapes with formatting support\n * - video: Video shapes referencing video assets\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'\n *\n * // Use all default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas,\n * })\n *\n * // Use only specific default shapes\n * const minimalSchema = createTLSchema({\n * shapes: {\n * geo: defaultShapeSchemas.geo,\n * text: defaultShapeSchemas.text,\n * },\n * })\n * ```\n */\nexport const defaultShapeSchemas = {\n\tarrow: { migrations: arrowShapeMigrations, props: arrowShapeProps },\n\tbookmark: { migrations: bookmarkShapeMigrations, props: bookmarkShapeProps },\n\tdraw: { migrations: drawShapeMigrations, props: drawShapeProps },\n\tembed: { migrations: embedShapeMigrations, props: embedShapeProps },\n\tframe: { migrations: frameShapeMigrations, props: frameShapeProps },\n\tgeo: { migrations: geoShapeMigrations, props: geoShapeProps },\n\tgroup: { migrations: groupShapeMigrations, props: groupShapeProps },\n\thighlight: { migrations: highlightShapeMigrations, props: highlightShapeProps },\n\timage: { migrations: imageShapeMigrations, props: imageShapeProps },\n\tline: { migrations: lineShapeMigrations, props: lineShapeProps },\n\tnote: { migrations: noteShapeMigrations, props: noteShapeProps },\n\ttext: { migrations: textShapeMigrations, props: textShapeProps },\n\tvideo: { migrations: videoShapeMigrations, props: videoShapeProps },\n} satisfies {\n\t[T in TLDefaultShape['type']]: {\n\t\tmigrations: SchemaPropsInfo['migrations']\n\t\tprops: RecordProps<TLBaseShape<T, Extract<TLDefaultShape, { type: T }>['props']>>\n\t}\n}\n\n/**\n * Default binding schema configurations for all built-in tldraw binding types.\n * Bindings represent relationships between shapes, such as arrows connected to shapes.\n *\n * Currently includes:\n * - arrow: Bindings that connect arrow shapes to other shapes at specific anchor points\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultBindingSchemas } from '@tldraw/tlschema'\n *\n * // Use default bindings\n * const schema = createTLSchema({\n * bindings: defaultBindingSchemas,\n * })\n *\n * // Add custom binding alongside defaults\n * const customSchema = createTLSchema({\n * bindings: {\n * ...defaultBindingSchemas,\n * myCustomBinding: {\n * props: myCustomBindingProps,\n * migrations: myCustomBindingMigrations,\n * },\n * },\n * })\n * ```\n */\nexport const defaultBindingSchemas = {\n\tarrow: { migrations: arrowBindingMigrations, props: arrowBindingProps },\n} satisfies { [T in TLDefaultBinding['type']]: SchemaPropsInfo }\n\n/**\n * Default asset schema configurations for all built-in tldraw asset types.\n *\n * @public\n * @example\n * ```ts\n * import { createTLSchema, defaultAssetSchemas } from '@tldraw/tlschema'\n *\n * const schema = createTLSchema({\n * assets: defaultAssetSchemas,\n * })\n * ```\n */\nexport const defaultAssetSchemas = {\n\timage: { migrations: imageAssetMigrations, props: imageAssetProps },\n\tvideo: { migrations: videoAssetMigrations, props: videoAssetProps },\n\tbookmark: { migrations: bookmarkAssetMigrations, props: bookmarkAssetProps },\n} satisfies {\n\t[T in TLDefaultAsset['type']]: {\n\t\tmigrations: SchemaPropsInfo['migrations']\n\t\tprops: RecordProps<TLBaseAsset<T, Extract<TLDefaultAsset, { type: T }>['props']>>\n\t}\n}\n\n/**\n * Configuration for extending the user record type with custom metadata\n * validators and migration sequences.\n *\n * @example\n * ```ts\n * import { T } from '@tldraw/validate'\n *\n * const userSchema: UserSchemaInfo = {\n * meta: {\n * isAdmin: T.boolean,\n * department: T.string,\n * },\n * }\n * ```\n *\n * @public\n */\nexport interface UserSchemaInfo {\n\t/**\n\t * Validators for custom metadata fields on user records. Each field is\n\t * treated as optional \u2014 user records without these fields remain valid,\n\t * but when present, values are validated against the provided validators.\n\t */\n\tmeta?: Record<string, T.Validatable<any>>\n\n\t/**\n\t * Additional migration sequences for evolving custom user data over time.\n\t */\n\tmigrations?: readonly MigrationSequence[]\n}\n\n/**\n * Creates a complete TLSchema for use with tldraw stores. This schema defines the structure,\n * validation, and migration sequences for all record types in a tldraw application.\n *\n * The schema includes all core record types (pages, cameras, instances, etc.) plus the\n * shape, binding, asset, and custom record types you specify. Style properties are\n * automatically collected from all shapes to ensure consistency across the application.\n *\n * @param options - Configuration options for the schema\n * - shapes - Shape schema configurations. Defaults to defaultShapeSchemas if not provided\n * - bindings - Binding schema configurations. Defaults to defaultBindingSchemas if not provided\n * - assets - Asset schema configurations. Defaults to defaultAssetSchemas if not provided\n * - user - Custom user record configuration with meta validators and migrations\n * - records - Custom record type configurations. These are additional record types beyond\n * the built-in shapes, bindings, assets, etc.\n * - migrations - Additional migration sequences to include in the schema\n * @returns A complete TLSchema ready for use with Store creation\n *\n * @public\n * @example\n * ```ts\n * import {\n * createTLSchema,\n * defaultShapeSchemas,\n * defaultBindingSchemas,\n * defaultAssetSchemas,\n * } from '@tldraw/tlschema'\n * import { Store } from '@tldraw/store'\n *\n * // Create schema with all default shapes, bindings, and assets\n * const schema = createTLSchema()\n *\n * // Create schema with custom shapes added\n * const customSchema = createTLSchema({\n * shapes: {\n * ...defaultShapeSchemas,\n * myCustomShape: {\n * props: myCustomShapeProps,\n * migrations: myCustomShapeMigrations,\n * },\n * },\n * bindings: defaultBindingSchemas,\n * assets: defaultAssetSchemas,\n * })\n *\n * // Create schema with custom user metadata\n * const schemaWithCustomUser = createTLSchema({\n * user: {\n * meta: {\n * isAdmin: T.boolean,\n * department: T.string,\n * },\n * },\n * })\n *\n * // Create schema with custom record types\n * const schemaWithCustomRecords = createTLSchema({\n * records: {\n * comment: {\n * scope: 'document',\n * validator: T.object({\n * id: T.string,\n * typeName: T.literal('comment'),\n * text: T.string,\n * shapeId: T.string,\n * }),\n * },\n * },\n * })\n *\n * // Use the schema with a store\n * const store = new Store({\n * schema: customSchema,\n * props: {\n * defaultName: 'My Drawing',\n * },\n * })\n * ```\n */\nexport function createTLSchema({\n\tshapes = defaultShapeSchemas,\n\tbindings = defaultBindingSchemas,\n\tassets = defaultAssetSchemas,\n\tuser,\n\trecords = {},\n\tmigrations,\n}: {\n\tshapes?: Record<string, SchemaPropsInfo>\n\tbindings?: Record<string, SchemaPropsInfo>\n\tassets?: Record<string, SchemaPropsInfo>\n\tuser?: UserSchemaInfo\n\trecords?: Record<string, CustomRecordInfo>\n\tmigrations?: readonly MigrationSequence[]\n} = {}): TLSchema {\n\tconst stylesById = new Map<string, StyleProp<unknown>>()\n\tfor (const shape of objectMapValues(shapes)) {\n\t\tfor (const style of getShapePropKeysByStyle(shape.props ?? {}).keys()) {\n\t\t\tif (stylesById.has(style.id) && stylesById.get(style.id) !== style) {\n\t\t\t\tthrow new Error(`Multiple StyleProp instances with the same id: ${style.id}`)\n\t\t\t}\n\t\t\tstylesById.set(style.id, style)\n\t\t}\n\t}\n\n\tconst ShapeRecordType = createShapeRecordType(shapes)\n\tconst BindingRecordType = createBindingRecordType(bindings)\n\tconst _AssetRecordType = createAssetRecordType(assets)\n\tconst InstanceRecordType = createInstanceRecordType(stylesById)\n\tconst CustomUserRecordType = user ? createUserRecordType(user) : UserRecordType\n\n\t// Create RecordTypes for custom records\n\tconst builtInTypeNames = new Set([\n\t\t'asset',\n\t\t'binding',\n\t\t'camera',\n\t\t'document',\n\t\t'instance',\n\t\t'instance_page_state',\n\t\t'page',\n\t\t'instance_presence',\n\t\t'pointer',\n\t\t'shape',\n\t\t'store',\n\t\t'user',\n\t])\n\tconst customRecordTypes: Record<string, { createId: any }> = {}\n\tfor (const [typeName, config] of Object.entries(records)) {\n\t\tif (builtInTypeNames.has(typeName)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Custom record type name '${typeName}' conflicts with tldraw's built-in record type of that name. Choose a different name instead.`\n\t\t\t)\n\t\t}\n\t\tcustomRecordTypes[typeName] = createCustomRecordType(typeName, config)\n\t}\n\n\treturn StoreSchema.create(\n\t\t{\n\t\t\tasset: _AssetRecordType,\n\t\t\tbinding: BindingRecordType,\n\t\t\tcamera: CameraRecordType,\n\t\t\tdocument: DocumentRecordType,\n\t\t\tinstance: InstanceRecordType,\n\t\t\tinstance_page_state: InstancePageStateRecordType,\n\t\t\tpage: PageRecordType,\n\t\t\tinstance_presence: InstancePresenceRecordType,\n\t\t\tpointer: PointerRecordType,\n\t\t\tshape: ShapeRecordType,\n\t\t\tuser: CustomUserRecordType,\n\t\t\t...customRecordTypes,\n\t\t},\n\t\t{\n\t\t\tmigrations: [\n\t\t\t\tstoreMigrations,\n\t\t\t\tassetMigrations,\n\t\t\t\tcameraMigrations,\n\t\t\t\tdocumentMigrations,\n\t\t\t\tinstanceMigrations,\n\t\t\t\tinstancePageStateMigrations,\n\t\t\t\tpageMigrations,\n\t\t\t\tinstancePresenceMigrations,\n\t\t\t\tpointerMigrations,\n\t\t\t\trootShapeMigrations,\n\n\t\t\t\tuserMigrations,\n\n\t\t\t\t...processPropsMigrations<TLUnknownAsset>('asset', assets),\n\t\t\t\t...processPropsMigrations<TLShape>('shape', shapes),\n\t\t\t\t...processPropsMigrations<TLBinding>('binding', bindings),\n\t\t\t\t...processCustomRecordMigrations(records),\n\n\t\t\t\t...(user?.migrations ?? []),\n\t\t\t\t...(migrations ?? []),\n\t\t\t],\n\t\t\tonValidationFailure,\n\t\t\tcreateIntegrityChecker,\n\t\t}\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiF;AACjF,mBAAgC;AAGhC,6BAA4D;AAC5D,0BAAsD;AACtD,0BAAsD;AACtD,4BAA0D;AAC1D,qBAKO;AACP,uBAAqE;AACrE,sBAAmD;AACnD,4BAIO;AACP,wBAAuD;AACvD,wBAA6D;AAC7D,oBAA+C;AAC/C,yBAAyE;AACzE,uBAAqD;AACrD,wBAAuE;AAEvE,qBAMO;AACP,oBAAqE;AACrE,8BAAuE;AACvE,0BAAsD;AAEtD,6BAA4D;AAC5D,yBAAoD;AACpD,0BAAsD;AACtD,0BAAsD;AACtD,wBAAkD;AAClD,0BAAsD;AACtD,8BAA8D;AAC9D,0BAAsD;AACtD,yBAAoD;AACpD,yBAAoD;AACpD,yBAAoD;AACpD,0BAAsD;AACtD,8BAAgC;AAEhC,qBAA0E;AAgGnE,MAAM,sBAAsB;AAAA,EAClC,OAAO,EAAE,YAAY,0CAAsB,OAAO,oCAAgB;AAAA,EAClE,UAAU,EAAE,YAAY,gDAAyB,OAAO,0CAAmB;AAAA,EAC3E,MAAM,EAAE,YAAY,wCAAqB,OAAO,kCAAe;AAAA,EAC/D,OAAO,EAAE,YAAY,0CAAsB,OAAO,oCAAgB;AAAA,EAClE,OAAO,EAAE,YAAY,0CAAsB,OAAO,oCAAgB;AAAA,EAClE,KAAK,EAAE,YAAY,sCAAoB,OAAO,gCAAc;AAAA,EAC5D,OAAO,EAAE,YA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