@tldraw/tlschema 4.1.0-next.542f014c3fac → 4.1.0-next.cb6f90590225

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist-cjs/TLStore.js +3 -10
  2. package/dist-cjs/TLStore.js.map +2 -2
  3. package/dist-cjs/assets/TLBaseAsset.js.map +2 -2
  4. package/dist-cjs/assets/TLBookmarkAsset.js.map +2 -2
  5. package/dist-cjs/assets/TLImageAsset.js.map +2 -2
  6. package/dist-cjs/assets/TLVideoAsset.js.map +2 -2
  7. package/dist-cjs/bindings/TLArrowBinding.js.map +2 -2
  8. package/dist-cjs/bindings/TLBaseBinding.js.map +2 -2
  9. package/dist-cjs/createPresenceStateDerivation.js.map +2 -2
  10. package/dist-cjs/createTLSchema.js.map +2 -2
  11. package/dist-cjs/index.d.ts +4416 -223
  12. package/dist-cjs/index.js +1 -1
  13. package/dist-cjs/index.js.map +2 -2
  14. package/dist-cjs/misc/TLColor.js.map +2 -2
  15. package/dist-cjs/misc/TLCursor.js.map +2 -2
  16. package/dist-cjs/misc/TLHandle.js.map +2 -2
  17. package/dist-cjs/misc/TLOpacity.js.map +2 -2
  18. package/dist-cjs/misc/TLRichText.js.map +2 -2
  19. package/dist-cjs/misc/TLScribble.js.map +2 -2
  20. package/dist-cjs/misc/geometry-types.js.map +2 -2
  21. package/dist-cjs/misc/id-validator.js.map +2 -2
  22. package/dist-cjs/records/TLAsset.js.map +2 -2
  23. package/dist-cjs/records/TLBinding.js.map +2 -2
  24. package/dist-cjs/records/TLCamera.js.map +2 -2
  25. package/dist-cjs/records/TLDocument.js.map +2 -2
  26. package/dist-cjs/records/TLInstance.js.map +2 -2
  27. package/dist-cjs/records/TLPage.js.map +2 -2
  28. package/dist-cjs/records/TLPageState.js.map +2 -2
  29. package/dist-cjs/records/TLPointer.js.map +2 -2
  30. package/dist-cjs/records/TLPresence.js.map +2 -2
  31. package/dist-cjs/records/TLRecord.js.map +1 -1
  32. package/dist-cjs/records/TLShape.js.map +2 -2
  33. package/dist-cjs/recordsWithProps.js.map +2 -2
  34. package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
  35. package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
  36. package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
  37. package/dist-cjs/shapes/TLBookmarkShape.js.map +2 -2
  38. package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
  39. package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
  40. package/dist-cjs/shapes/TLFrameShape.js.map +2 -2
  41. package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
  42. package/dist-cjs/shapes/TLGroupShape.js.map +2 -2
  43. package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
  44. package/dist-cjs/shapes/TLImageShape.js.map +2 -2
  45. package/dist-cjs/shapes/TLLineShape.js.map +2 -2
  46. package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
  47. package/dist-cjs/shapes/TLTextShape.js.map +2 -2
  48. package/dist-cjs/shapes/TLVideoShape.js.map +2 -2
  49. package/dist-cjs/store-migrations.js.map +2 -2
  50. package/dist-cjs/styles/TLColorStyle.js.map +2 -2
  51. package/dist-cjs/styles/TLDashStyle.js.map +2 -2
  52. package/dist-cjs/styles/TLFillStyle.js.map +2 -2
  53. package/dist-cjs/styles/TLFontStyle.js.map +2 -2
  54. package/dist-cjs/styles/TLHorizontalAlignStyle.js.map +2 -2
  55. package/dist-cjs/styles/TLSizeStyle.js.map +2 -2
  56. package/dist-cjs/styles/TLTextAlignStyle.js.map +2 -2
  57. package/dist-cjs/styles/TLVerticalAlignStyle.js.map +2 -2
  58. package/dist-cjs/translations/translations.js +1 -1
  59. package/dist-cjs/translations/translations.js.map +2 -2
  60. package/dist-cjs/util-types.js.map +1 -1
  61. package/dist-esm/TLStore.mjs +3 -10
  62. package/dist-esm/TLStore.mjs.map +2 -2
  63. package/dist-esm/assets/TLBaseAsset.mjs.map +2 -2
  64. package/dist-esm/assets/TLBookmarkAsset.mjs.map +2 -2
  65. package/dist-esm/assets/TLImageAsset.mjs.map +2 -2
  66. package/dist-esm/assets/TLVideoAsset.mjs.map +2 -2
  67. package/dist-esm/bindings/TLArrowBinding.mjs.map +2 -2
  68. package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
  69. package/dist-esm/createPresenceStateDerivation.mjs.map +2 -2
  70. package/dist-esm/createTLSchema.mjs.map +2 -2
  71. package/dist-esm/index.d.mts +4416 -223
  72. package/dist-esm/index.mjs +1 -1
  73. package/dist-esm/index.mjs.map +2 -2
  74. package/dist-esm/misc/TLColor.mjs.map +2 -2
  75. package/dist-esm/misc/TLCursor.mjs.map +2 -2
  76. package/dist-esm/misc/TLHandle.mjs.map +2 -2
  77. package/dist-esm/misc/TLOpacity.mjs.map +2 -2
  78. package/dist-esm/misc/TLRichText.mjs.map +2 -2
  79. package/dist-esm/misc/TLScribble.mjs.map +2 -2
  80. package/dist-esm/misc/geometry-types.mjs.map +2 -2
  81. package/dist-esm/misc/id-validator.mjs.map +2 -2
  82. package/dist-esm/records/TLAsset.mjs.map +2 -2
  83. package/dist-esm/records/TLBinding.mjs.map +2 -2
  84. package/dist-esm/records/TLCamera.mjs.map +2 -2
  85. package/dist-esm/records/TLDocument.mjs.map +2 -2
  86. package/dist-esm/records/TLInstance.mjs.map +2 -2
  87. package/dist-esm/records/TLPage.mjs.map +2 -2
  88. package/dist-esm/records/TLPageState.mjs.map +2 -2
  89. package/dist-esm/records/TLPointer.mjs.map +2 -2
  90. package/dist-esm/records/TLPresence.mjs.map +2 -2
  91. package/dist-esm/records/TLShape.mjs.map +2 -2
  92. package/dist-esm/recordsWithProps.mjs.map +2 -2
  93. package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
  94. package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
  95. package/dist-esm/shapes/TLBookmarkShape.mjs.map +2 -2
  96. package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
  97. package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
  98. package/dist-esm/shapes/TLFrameShape.mjs.map +2 -2
  99. package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
  100. package/dist-esm/shapes/TLGroupShape.mjs.map +2 -2
  101. package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
  102. package/dist-esm/shapes/TLImageShape.mjs.map +2 -2
  103. package/dist-esm/shapes/TLLineShape.mjs.map +2 -2
  104. package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
  105. package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
  106. package/dist-esm/shapes/TLVideoShape.mjs.map +2 -2
  107. package/dist-esm/store-migrations.mjs.map +2 -2
  108. package/dist-esm/styles/TLColorStyle.mjs.map +2 -2
  109. package/dist-esm/styles/TLDashStyle.mjs.map +2 -2
  110. package/dist-esm/styles/TLFillStyle.mjs.map +2 -2
  111. package/dist-esm/styles/TLFontStyle.mjs.map +2 -2
  112. package/dist-esm/styles/TLHorizontalAlignStyle.mjs.map +2 -2
  113. package/dist-esm/styles/TLSizeStyle.mjs.map +2 -2
  114. package/dist-esm/styles/TLTextAlignStyle.mjs.map +2 -2
  115. package/dist-esm/styles/TLVerticalAlignStyle.mjs.map +2 -2
  116. package/dist-esm/translations/translations.mjs +1 -1
  117. package/dist-esm/translations/translations.mjs.map +2 -2
  118. package/package.json +5 -5
  119. package/src/TLStore.test.ts +644 -0
  120. package/src/TLStore.ts +205 -20
  121. package/src/assets/TLBaseAsset.ts +90 -7
  122. package/src/assets/TLBookmarkAsset.test.ts +96 -0
  123. package/src/assets/TLBookmarkAsset.ts +52 -2
  124. package/src/assets/TLImageAsset.test.ts +213 -0
  125. package/src/assets/TLImageAsset.ts +60 -2
  126. package/src/assets/TLVideoAsset.test.ts +105 -0
  127. package/src/assets/TLVideoAsset.ts +93 -4
  128. package/src/bindings/TLArrowBinding.test.ts +55 -0
  129. package/src/bindings/TLArrowBinding.ts +132 -10
  130. package/src/bindings/TLBaseBinding.ts +140 -3
  131. package/src/createPresenceStateDerivation.test.ts +158 -0
  132. package/src/createPresenceStateDerivation.ts +71 -2
  133. package/src/createTLSchema.test.ts +181 -0
  134. package/src/createTLSchema.ts +164 -7
  135. package/src/index.ts +32 -0
  136. package/src/misc/TLColor.ts +50 -6
  137. package/src/misc/TLCursor.ts +110 -8
  138. package/src/misc/TLHandle.ts +86 -6
  139. package/src/misc/TLOpacity.ts +51 -2
  140. package/src/misc/TLRichText.ts +56 -3
  141. package/src/misc/TLScribble.ts +105 -5
  142. package/src/misc/geometry-types.ts +30 -2
  143. package/src/misc/id-validator.test.ts +50 -0
  144. package/src/misc/id-validator.ts +20 -1
  145. package/src/records/TLAsset.test.ts +234 -0
  146. package/src/records/TLAsset.ts +165 -8
  147. package/src/records/TLBinding.test.ts +22 -0
  148. package/src/records/TLBinding.ts +277 -11
  149. package/src/records/TLCamera.test.ts +19 -0
  150. package/src/records/TLCamera.ts +118 -7
  151. package/src/records/TLDocument.test.ts +35 -0
  152. package/src/records/TLDocument.ts +148 -8
  153. package/src/records/TLInstance.test.ts +201 -0
  154. package/src/records/TLInstance.ts +117 -9
  155. package/src/records/TLPage.test.ts +110 -0
  156. package/src/records/TLPage.ts +106 -8
  157. package/src/records/TLPageState.test.ts +228 -0
  158. package/src/records/TLPageState.ts +88 -7
  159. package/src/records/TLPointer.test.ts +63 -0
  160. package/src/records/TLPointer.ts +105 -7
  161. package/src/records/TLPresence.test.ts +190 -0
  162. package/src/records/TLPresence.ts +99 -5
  163. package/src/records/TLRecord.test.ts +70 -0
  164. package/src/records/TLRecord.ts +43 -1
  165. package/src/records/TLShape.test.ts +232 -0
  166. package/src/records/TLShape.ts +289 -12
  167. package/src/recordsWithProps.test.ts +188 -0
  168. package/src/recordsWithProps.ts +131 -2
  169. package/src/shapes/ShapeWithCrop.test.ts +18 -0
  170. package/src/shapes/ShapeWithCrop.ts +64 -2
  171. package/src/shapes/TLArrowShape.test.ts +505 -0
  172. package/src/shapes/TLArrowShape.ts +188 -10
  173. package/src/shapes/TLBaseShape.test.ts +142 -0
  174. package/src/shapes/TLBaseShape.ts +103 -4
  175. package/src/shapes/TLBookmarkShape.test.ts +122 -0
  176. package/src/shapes/TLBookmarkShape.ts +58 -4
  177. package/src/shapes/TLDrawShape.test.ts +177 -0
  178. package/src/shapes/TLDrawShape.ts +97 -6
  179. package/src/shapes/TLEmbedShape.test.ts +286 -0
  180. package/src/shapes/TLEmbedShape.ts +57 -4
  181. package/src/shapes/TLFrameShape.test.ts +71 -0
  182. package/src/shapes/TLFrameShape.ts +59 -4
  183. package/src/shapes/TLGeoShape.test.ts +247 -0
  184. package/src/shapes/TLGeoShape.ts +103 -7
  185. package/src/shapes/TLGroupShape.test.ts +59 -0
  186. package/src/shapes/TLGroupShape.ts +52 -4
  187. package/src/shapes/TLHighlightShape.test.ts +325 -0
  188. package/src/shapes/TLHighlightShape.ts +79 -4
  189. package/src/shapes/TLImageShape.test.ts +534 -0
  190. package/src/shapes/TLImageShape.ts +105 -5
  191. package/src/shapes/TLLineShape.test.ts +269 -0
  192. package/src/shapes/TLLineShape.ts +128 -8
  193. package/src/shapes/TLNoteShape.test.ts +1568 -0
  194. package/src/shapes/TLNoteShape.ts +97 -4
  195. package/src/shapes/TLTextShape.test.ts +407 -0
  196. package/src/shapes/TLTextShape.ts +94 -4
  197. package/src/shapes/TLVideoShape.test.ts +112 -0
  198. package/src/shapes/TLVideoShape.ts +99 -4
  199. package/src/store-migrations.test.ts +88 -0
  200. package/src/store-migrations.ts +47 -1
  201. package/src/styles/TLColorStyle.test.ts +439 -0
  202. package/src/styles/TLColorStyle.ts +228 -10
  203. package/src/styles/TLDashStyle.ts +54 -2
  204. package/src/styles/TLFillStyle.ts +54 -2
  205. package/src/styles/TLFontStyle.ts +72 -3
  206. package/src/styles/TLHorizontalAlignStyle.ts +55 -2
  207. package/src/styles/TLSizeStyle.ts +54 -2
  208. package/src/styles/TLTextAlignStyle.ts +52 -2
  209. package/src/styles/TLVerticalAlignStyle.ts +52 -2
  210. package/src/translations/translations.test.ts +378 -35
  211. package/src/translations/translations.ts +157 -10
  212. package/src/util-types.ts +51 -1
@@ -0,0 +1,181 @@
1
+ import { createMigrationSequence, MigrationSequence, StoreSchema } from '@tldraw/store'
2
+ import { T } from '@tldraw/validate'
3
+ import { describe, expect, it } from 'vitest'
4
+ import { createTLSchema, defaultBindingSchemas, defaultShapeSchemas } from './createTLSchema'
5
+ import { TLDefaultBinding } from './records/TLBinding'
6
+ import { TLDefaultShape } from './records/TLShape'
7
+ import { StyleProp } from './styles/StyleProp'
8
+ import { DefaultColorStyle } from './styles/TLColorStyle'
9
+
10
+ describe('defaultShapeSchemas', () => {
11
+ const expectedShapeTypes: Array<TLDefaultShape['type']> = [
12
+ 'arrow',
13
+ 'bookmark',
14
+ 'draw',
15
+ 'embed',
16
+ 'frame',
17
+ 'geo',
18
+ 'group',
19
+ 'highlight',
20
+ 'image',
21
+ 'line',
22
+ 'note',
23
+ 'text',
24
+ 'video',
25
+ ]
26
+
27
+ it('should contain all default shape types', () => {
28
+ const actualShapeTypes = Object.keys(defaultShapeSchemas)
29
+
30
+ expect(actualShapeTypes).toHaveLength(expectedShapeTypes.length)
31
+
32
+ for (const shapeType of expectedShapeTypes) {
33
+ expect(actualShapeTypes).toContain(shapeType)
34
+ }
35
+ })
36
+
37
+ it('should contain style properties in shape props', () => {
38
+ // Test a few known shapes that should have style properties
39
+ const geoProps = defaultShapeSchemas.geo.props
40
+ const arrowProps = defaultShapeSchemas.arrow.props
41
+
42
+ // Check that some props are StyleProp instances
43
+ let hasStyleProp = false
44
+ for (const prop of Object.values(geoProps || {})) {
45
+ if (prop instanceof StyleProp) {
46
+ hasStyleProp = true
47
+ break
48
+ }
49
+ }
50
+ expect(hasStyleProp).toBe(true)
51
+
52
+ // Check arrow props too
53
+ hasStyleProp = false
54
+ for (const prop of Object.values(arrowProps || {})) {
55
+ if (prop instanceof StyleProp) {
56
+ hasStyleProp = true
57
+ break
58
+ }
59
+ }
60
+ expect(hasStyleProp).toBe(true)
61
+ })
62
+ })
63
+
64
+ describe('defaultBindingSchemas', () => {
65
+ const expectedBindingTypes: Array<TLDefaultBinding['type']> = ['arrow']
66
+
67
+ it('should contain all default binding types', () => {
68
+ const actualBindingTypes = Object.keys(defaultBindingSchemas)
69
+
70
+ expect(actualBindingTypes).toHaveLength(expectedBindingTypes.length)
71
+
72
+ for (const bindingType of expectedBindingTypes) {
73
+ expect(actualBindingTypes).toContain(bindingType)
74
+ }
75
+ })
76
+ })
77
+
78
+ describe('createTLSchema', () => {
79
+ it('should create a valid schema with default parameters', () => {
80
+ const schema = createTLSchema()
81
+
82
+ expect(schema).toBeInstanceOf(StoreSchema)
83
+ expect(schema.types).toBeDefined()
84
+ expect(schema.migrations).toBeDefined()
85
+ })
86
+
87
+ it('should create schema with custom shapes', () => {
88
+ const customShapeProps = {
89
+ customProp: T.string,
90
+ color: DefaultColorStyle,
91
+ }
92
+
93
+ const customShapes = {
94
+ ...defaultShapeSchemas,
95
+ custom: {
96
+ props: customShapeProps,
97
+ migrations: createMigrationSequence({
98
+ sequenceId: 'com.tldraw.shape.custom', // Use the expected format
99
+ sequence: [],
100
+ }),
101
+ },
102
+ }
103
+
104
+ const schema = createTLSchema({ shapes: customShapes })
105
+
106
+ expect(schema).toBeInstanceOf(StoreSchema)
107
+ expect(schema.types.shape).toBeDefined()
108
+ })
109
+
110
+ it('should create schema with custom bindings', () => {
111
+ const customBindingProps = {
112
+ customProp: T.number,
113
+ }
114
+
115
+ const customBindings = {
116
+ ...defaultBindingSchemas,
117
+ custom: {
118
+ props: customBindingProps,
119
+ migrations: createMigrationSequence({
120
+ sequenceId: 'com.tldraw.binding.custom', // Use the expected format
121
+ sequence: [],
122
+ }),
123
+ },
124
+ }
125
+
126
+ const schema = createTLSchema({ bindings: customBindings })
127
+
128
+ expect(schema).toBeInstanceOf(StoreSchema)
129
+ expect(schema.types.binding).toBeDefined()
130
+ })
131
+
132
+ it('should create schema with additional migrations', () => {
133
+ const additionalMigrations: MigrationSequence[] = [
134
+ createMigrationSequence({
135
+ sequenceId: 'com.test.additional',
136
+ sequence: [],
137
+ }),
138
+ ]
139
+
140
+ const schema = createTLSchema({ migrations: additionalMigrations })
141
+
142
+ expect(schema).toBeInstanceOf(StoreSchema)
143
+ expect(schema.migrations).toBeDefined()
144
+ })
145
+
146
+ it('should create schema with only specific shapes', () => {
147
+ const minimalShapes = {
148
+ geo: defaultShapeSchemas.geo,
149
+ text: defaultShapeSchemas.text,
150
+ arrow: defaultShapeSchemas.arrow, // Include arrow to satisfy binding dependencies
151
+ }
152
+
153
+ const schema = createTLSchema({ shapes: minimalShapes })
154
+
155
+ expect(schema).toBeInstanceOf(StoreSchema)
156
+ expect(schema.types.shape).toBeDefined()
157
+ })
158
+
159
+ describe('style property collection and validation', () => {
160
+ it('should throw error for duplicate style property IDs', () => {
161
+ // Create a duplicate style property with same ID as DefaultColorStyle
162
+ const duplicateColorStyle = StyleProp.defineEnum('tldraw:color', {
163
+ defaultValue: 'black',
164
+ values: ['black', 'white'],
165
+ })
166
+
167
+ const conflictingShapes = {
168
+ shape1: {
169
+ props: { color: DefaultColorStyle },
170
+ },
171
+ shape2: {
172
+ props: { color: duplicateColorStyle },
173
+ },
174
+ }
175
+
176
+ expect(() => createTLSchema({ shapes: conflictingShapes })).toThrow(
177
+ 'Multiple StyleProp instances with the same id: tldraw:color'
178
+ )
179
+ })
180
+ })
181
+ })
@@ -39,17 +39,100 @@ import { videoShapeMigrations, videoShapeProps } from './shapes/TLVideoShape'
39
39
  import { storeMigrations } from './store-migrations'
40
40
  import { StyleProp } from './styles/StyleProp'
41
41
 
42
- /** @public */
42
+ /**
43
+ * Configuration information for a schema type (shape or binding), including its properties,
44
+ * metadata, and migration sequences for data evolution over time.
45
+ *
46
+ * @public
47
+ * @example
48
+ * ```ts
49
+ * import { arrowShapeMigrations, arrowShapeProps } from './shapes/TLArrowShape'
50
+ *
51
+ * const myShapeSchema: SchemaPropsInfo = {
52
+ * migrations: arrowShapeMigrations,
53
+ * props: arrowShapeProps,
54
+ * meta: {
55
+ * customField: T.string,
56
+ * },
57
+ * }
58
+ * ```
59
+ */
43
60
  export interface SchemaPropsInfo {
61
+ /**
62
+ * Migration sequences for handling data evolution over time. Can be legacy migrations,
63
+ * props-specific migrations, or general migration sequences.
64
+ */
44
65
  migrations?: LegacyMigrations | TLPropsMigrations | MigrationSequence
66
+
67
+ /**
68
+ * Validation schema for the shape or binding properties. Maps property names to their validators.
69
+ */
45
70
  props?: Record<string, StoreValidator<any>>
71
+
72
+ /**
73
+ * Validation schema for metadata fields. Maps metadata field names to their validators.
74
+ */
46
75
  meta?: Record<string, StoreValidator<any>>
47
76
  }
48
77
 
49
- /** @public */
78
+ /**
79
+ * The complete schema definition for a tldraw store, encompassing all record types,
80
+ * validation rules, and migration sequences. This schema defines the structure of
81
+ * the persistent data model used by tldraw.
82
+ *
83
+ * @public
84
+ * @example
85
+ * ```ts
86
+ * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'
87
+ * import { Store } from '@tldraw/store'
88
+ *
89
+ * const schema: TLSchema = createTLSchema({
90
+ * shapes: defaultShapeSchemas,
91
+ * })
92
+ *
93
+ * const store = new Store({ schema })
94
+ * ```
95
+ */
50
96
  export type TLSchema = StoreSchema<TLRecord, TLStoreProps>
51
97
 
52
- /** @public */
98
+ /**
99
+ * Default shape schema configurations for all built-in tldraw shape types.
100
+ * Each shape type includes its validation props and migration sequences.
101
+ *
102
+ * This object contains schema information for:
103
+ * - arrow: Directional lines that can bind to other shapes
104
+ * - bookmark: Website bookmark cards with preview information
105
+ * - draw: Freehand drawing paths created with drawing tools
106
+ * - embed: Embedded content from external services (YouTube, Figma, etc.)
107
+ * - frame: Container shapes for organizing content
108
+ * - geo: Geometric shapes (rectangles, ellipses, triangles, etc.)
109
+ * - group: Logical groupings of multiple shapes
110
+ * - highlight: Highlighting strokes from the highlighter tool
111
+ * - image: Raster image shapes referencing image assets
112
+ * - line: Multi-point lines and splines
113
+ * - note: Sticky note shapes with text content
114
+ * - text: Rich text shapes with formatting support
115
+ * - video: Video shapes referencing video assets
116
+ *
117
+ * @public
118
+ * @example
119
+ * ```ts
120
+ * import { createTLSchema, defaultShapeSchemas } from '@tldraw/tlschema'
121
+ *
122
+ * // Use all default shapes
123
+ * const schema = createTLSchema({
124
+ * shapes: defaultShapeSchemas,
125
+ * })
126
+ *
127
+ * // Use only specific default shapes
128
+ * const minimalSchema = createTLSchema({
129
+ * shapes: {
130
+ * geo: defaultShapeSchemas.geo,
131
+ * text: defaultShapeSchemas.text,
132
+ * },
133
+ * })
134
+ * ```
135
+ */
53
136
  export const defaultShapeSchemas = {
54
137
  arrow: { migrations: arrowShapeMigrations, props: arrowShapeProps },
55
138
  bookmark: { migrations: bookmarkShapeMigrations, props: bookmarkShapeProps },
@@ -66,17 +149,91 @@ export const defaultShapeSchemas = {
66
149
  video: { migrations: videoShapeMigrations, props: videoShapeProps },
67
150
  } satisfies { [T in TLDefaultShape['type']]: SchemaPropsInfo }
68
151
 
69
- /** @public */
152
+ /**
153
+ * Default binding schema configurations for all built-in tldraw binding types.
154
+ * Bindings represent relationships between shapes, such as arrows connected to shapes.
155
+ *
156
+ * Currently includes:
157
+ * - arrow: Bindings that connect arrow shapes to other shapes at specific anchor points
158
+ *
159
+ * @public
160
+ * @example
161
+ * ```ts
162
+ * import { createTLSchema, defaultBindingSchemas } from '@tldraw/tlschema'
163
+ *
164
+ * // Use default bindings
165
+ * const schema = createTLSchema({
166
+ * bindings: defaultBindingSchemas,
167
+ * })
168
+ *
169
+ * // Add custom binding alongside defaults
170
+ * const customSchema = createTLSchema({
171
+ * bindings: {
172
+ * ...defaultBindingSchemas,
173
+ * myCustomBinding: {
174
+ * props: myCustomBindingProps,
175
+ * migrations: myCustomBindingMigrations,
176
+ * },
177
+ * },
178
+ * })
179
+ * ```
180
+ */
70
181
  export const defaultBindingSchemas = {
71
182
  arrow: { migrations: arrowBindingMigrations, props: arrowBindingProps },
72
183
  } satisfies { [T in TLDefaultBinding['type']]: SchemaPropsInfo }
73
184
 
74
185
  /**
75
- * Create a TLSchema with custom shapes. Custom shapes cannot override default shapes.
186
+ * Creates a complete TLSchema for use with tldraw stores. This schema defines the structure,
187
+ * validation, and migration sequences for all record types in a tldraw application.
188
+ *
189
+ * The schema includes all core record types (pages, cameras, instances, etc.) plus the
190
+ * shape and binding types you specify. Style properties are automatically collected from
191
+ * all shapes to ensure consistency across the application.
192
+ *
193
+ * @param options - Configuration options for the schema
194
+ * - shapes - Shape schema configurations. Defaults to defaultShapeSchemas if not provided
195
+ * - bindings - Binding schema configurations. Defaults to defaultBindingSchemas if not provided
196
+ * - migrations - Additional migration sequences to include in the schema
197
+ * @returns A complete TLSchema ready for use with Store creation
198
+ *
199
+ * @public
200
+ * @example
201
+ * ```ts
202
+ * import { createTLSchema, defaultShapeSchemas, defaultBindingSchemas } from '@tldraw/tlschema'
203
+ * import { Store } from '@tldraw/store'
204
+ *
205
+ * // Create schema with all default shapes and bindings
206
+ * const schema = createTLSchema()
207
+ *
208
+ * // Create schema with custom shapes added
209
+ * const customSchema = createTLSchema({
210
+ * shapes: {
211
+ * ...defaultShapeSchemas,
212
+ * myCustomShape: {
213
+ * props: myCustomShapeProps,
214
+ * migrations: myCustomShapeMigrations,
215
+ * },
216
+ * },
217
+ * })
76
218
  *
77
- * @param opts - Options
219
+ * // Create schema with only specific shapes
220
+ * const minimalSchema = createTLSchema({
221
+ * shapes: {
222
+ * geo: defaultShapeSchemas.geo,
223
+ * text: defaultShapeSchemas.text,
224
+ * },
225
+ * bindings: defaultBindingSchemas,
226
+ * })
78
227
  *
79
- * @public */
228
+ * // Use the schema with a store
229
+ * const store = new Store({
230
+ * schema: customSchema,
231
+ * props: {
232
+ * defaultName: 'My Drawing',
233
+ * },
234
+ * })
235
+ * ```
236
+ */
80
237
  export function createTLSchema({
81
238
  shapes = defaultShapeSchemas,
82
239
  bindings = defaultBindingSchemas,
package/src/index.ts CHANGED
@@ -1,3 +1,35 @@
1
+ /**
2
+ * @fileoverview
3
+ * Main entry point for the tldraw schema package. Exports the complete type system,
4
+ * data structures, validation, and migrations for tldraw's persisted data.
5
+ *
6
+ * This package provides:
7
+ * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)
8
+ * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)
9
+ * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)
10
+ * - Binding system for shape relationships (TLArrowBinding)
11
+ * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)
12
+ * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)
13
+ * - Validation utilities and type guards
14
+ * - Migration systems for schema evolution
15
+ * - Geometry and utility types
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'
20
+ *
21
+ * // Create a schema with default shapes
22
+ * const schema = createTLSchema({
23
+ * shapes: defaultShapeSchemas
24
+ * })
25
+ *
26
+ * // Use with a store
27
+ * const store = new Store({ schema })
28
+ * ```
29
+ *
30
+ * @public
31
+ */
32
+
1
33
  import { registerTldrawLibraryVersion } from '@tldraw/utils'
2
34
  export { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'
3
35
  export { type TLBookmarkAsset } from './assets/TLBookmarkAsset'
@@ -2,9 +2,23 @@ import { T } from '@tldraw/validate'
2
2
  import { SetValue } from '../util-types'
3
3
 
4
4
  /**
5
- * The colors used by tldraw's default shapes.
5
+ * The colors used by tldraw's canvas UI system.
6
6
  *
7
- * @public */
7
+ * These are special color types used for canvas UI elements like selections,
8
+ * accents, and other interface components that overlay the drawing canvas.
9
+ * Unlike shape colors, these are semantic color types that adapt to the
10
+ * current theme.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Check if a color is a canvas UI color
15
+ * if (TL_CANVAS_UI_COLOR_TYPES.has('selection-stroke')) {
16
+ * console.log('This is a valid canvas UI color')
17
+ * }
18
+ * ```
19
+ *
20
+ * @public
21
+ */
8
22
  export const TL_CANVAS_UI_COLOR_TYPES = new Set([
9
23
  'accent',
10
24
  'white',
@@ -16,13 +30,43 @@ export const TL_CANVAS_UI_COLOR_TYPES = new Set([
16
30
  ] as const)
17
31
 
18
32
  /**
19
- * A type for the colors used by tldraw's default shapes.
33
+ * A union type representing the available canvas UI color types.
34
+ *
35
+ * Canvas UI colors are semantic color types used for interface elements
36
+ * that overlay the drawing canvas, such as selection indicators, accents,
37
+ * and other UI components.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const selectionColor: TLCanvasUiColor = 'selection-stroke'
42
+ * const accentColor: TLCanvasUiColor = 'accent'
43
+ * const backgroundColor: TLCanvasUiColor = 'white'
44
+ * ```
20
45
  *
21
- * @public */
46
+ * @public
47
+ */
22
48
  export type TLCanvasUiColor = SetValue<typeof TL_CANVAS_UI_COLOR_TYPES>
23
49
 
24
50
  /**
25
- * A validator for the colors used by tldraw's default shapes.
51
+ * A validator for canvas UI color types.
52
+ *
53
+ * This validator ensures that color values are one of the valid canvas UI
54
+ * color types defined in {@link TL_CANVAS_UI_COLOR_TYPES}. It provides
55
+ * runtime type checking for canvas UI color properties.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { canvasUiColorTypeValidator } from '@tldraw/tlschema'
60
+ *
61
+ * // Validate a color value
62
+ * try {
63
+ * const validColor = canvasUiColorTypeValidator.validate('accent')
64
+ * console.log('Valid color:', validColor)
65
+ * } catch (error) {
66
+ * console.error('Invalid color:', error.message)
67
+ * }
68
+ * ```
26
69
  *
27
- * @public */
70
+ * @public
71
+ */
28
72
  export const canvasUiColorTypeValidator = T.setEnum(TL_CANVAS_UI_COLOR_TYPES)
@@ -2,9 +2,26 @@ import { T } from '@tldraw/validate'
2
2
  import { SetValue } from '../util-types'
3
3
 
4
4
  /**
5
- * The cursor types used by tldraw's default shapes.
5
+ * All available cursor types used throughout the tldraw editor.
6
6
  *
7
- * @public */
7
+ * These cursor types correspond to CSS cursor values and are used to indicate
8
+ * different interaction modes and states within the editor. The cursor types
9
+ * cover selection, resizing, rotation, text editing, and various other editor
10
+ * interactions.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * // Check if a cursor type is valid
15
+ * if (TL_CURSOR_TYPES.has('resize-corner')) {
16
+ * console.log('Valid cursor type')
17
+ * }
18
+ *
19
+ * // Get all available cursor types
20
+ * const allCursors = Array.from(TL_CURSOR_TYPES)
21
+ * ```
22
+ *
23
+ * @public
24
+ */
8
25
  export const TL_CURSOR_TYPES = new Set([
9
26
  'none',
10
27
  'default',
@@ -30,24 +47,109 @@ export const TL_CURSOR_TYPES = new Set([
30
47
  ])
31
48
 
32
49
  /**
33
- * A type for the cursor types used by tldraw's default shapes.
50
+ * A union type representing all available cursor types in the tldraw editor.
51
+ *
52
+ * Each cursor type corresponds to a different interaction mode or state,
53
+ * helping users understand what action they can perform at any given moment.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const defaultCursor: TLCursorType = 'default'
58
+ * const textCursor: TLCursorType = 'text'
59
+ * const resizeCursor: TLCursorType = 'resize-corner'
60
+ * const rotateCursor: TLCursorType = 'nesw-rotate'
61
+ * ```
34
62
  *
35
- * @public */
63
+ * @public
64
+ */
36
65
  export type TLCursorType = SetValue<typeof TL_CURSOR_TYPES>
37
66
 
38
- /** @public */
67
+ /**
68
+ * A validator for cursor types.
69
+ *
70
+ * This validator ensures that cursor type values are one of the valid types
71
+ * defined in {@link TL_CURSOR_TYPES}. It provides runtime type checking for
72
+ * cursor properties throughout the editor.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { cursorTypeValidator } from '@tldraw/tlschema'
77
+ *
78
+ * // Validate a cursor type
79
+ * try {
80
+ * const validCursor = cursorTypeValidator.validate('pointer')
81
+ * console.log('Valid cursor:', validCursor)
82
+ * } catch (error) {
83
+ * console.error('Invalid cursor:', error.message)
84
+ * }
85
+ * ```
86
+ *
87
+ * @public
88
+ */
39
89
  export const cursorTypeValidator = T.setEnum(TL_CURSOR_TYPES)
40
90
 
41
91
  /**
42
- * A cursor used by tldraw.
92
+ * A cursor object used throughout the tldraw editor.
43
93
  *
44
- * @public */
94
+ * Represents both the cursor type (which determines the visual appearance)
95
+ * and its rotation angle. The rotation is particularly useful for resize
96
+ * and rotation cursors that need to align with the current interaction angle.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * // Default cursor
101
+ * const defaultCursor: TLCursor = {
102
+ * type: 'default',
103
+ * rotation: 0
104
+ * }
105
+ *
106
+ * // Rotated resize cursor
107
+ * const rotatedResizeCursor: TLCursor = {
108
+ * type: 'resize-corner',
109
+ * rotation: Math.PI / 4 // 45 degrees
110
+ * }
111
+ *
112
+ * // Text editing cursor
113
+ * const textCursor: TLCursor = {
114
+ * type: 'text',
115
+ * rotation: 0
116
+ * }
117
+ * ```
118
+ *
119
+ * @public
120
+ */
45
121
  export interface TLCursor {
122
+ /** The cursor type, determining the visual appearance and interaction mode */
46
123
  type: TLCursorType
124
+ /** The rotation angle in radians, used for rotated cursors like resize handles */
47
125
  rotation: number
48
126
  }
49
127
 
50
- /** @public */
128
+ /**
129
+ * A validator for TLCursor objects.
130
+ *
131
+ * This validator ensures that cursor objects have valid cursor types and
132
+ * numeric rotation values. It provides runtime validation for cursor
133
+ * properties used throughout the editor.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { cursorValidator } from '@tldraw/tlschema'
138
+ *
139
+ * // Validate a cursor object
140
+ * try {
141
+ * const validCursor = cursorValidator.validate({
142
+ * type: 'pointer',
143
+ * rotation: 0.5
144
+ * })
145
+ * console.log('Valid cursor:', validCursor)
146
+ * } catch (error) {
147
+ * console.error('Invalid cursor:', error.message)
148
+ * }
149
+ * ```
150
+ *
151
+ * @public
152
+ */
51
153
  export const cursorValidator: T.ObjectValidator<TLCursor> = T.object<TLCursor>({
52
154
  type: cursorTypeValidator,
53
155
  rotation: T.number,