@tldraw/tlschema 4.2.2 → 4.2.3

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 (117) hide show
  1. package/dist-cjs/bindings/TLBaseBinding.js.map +2 -2
  2. package/dist-cjs/createTLSchema.js.map +2 -2
  3. package/dist-cjs/index.d.ts +71 -242
  4. package/dist-cjs/index.js +1 -4
  5. package/dist-cjs/index.js.map +2 -2
  6. package/dist-cjs/misc/TLOpacity.js +5 -1
  7. package/dist-cjs/misc/TLOpacity.js.map +2 -2
  8. package/dist-cjs/misc/TLRichText.js +1 -5
  9. package/dist-cjs/misc/TLRichText.js.map +2 -2
  10. package/dist-cjs/records/TLAsset.js.map +1 -1
  11. package/dist-cjs/records/TLBinding.js.map +2 -2
  12. package/dist-cjs/records/TLShape.js.map +2 -2
  13. package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
  14. package/dist-cjs/shapes/TLArrowShape.js +13 -26
  15. package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
  16. package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
  17. package/dist-cjs/shapes/TLDrawShape.js +4 -37
  18. package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
  19. package/dist-cjs/shapes/TLEmbedShape.js +0 -17
  20. package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
  21. package/dist-cjs/shapes/TLGeoShape.js +1 -12
  22. package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
  23. package/dist-cjs/shapes/TLHighlightShape.js +2 -29
  24. package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
  25. package/dist-cjs/shapes/TLNoteShape.js +1 -12
  26. package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
  27. package/dist-cjs/shapes/TLTextShape.js +1 -12
  28. package/dist-cjs/shapes/TLTextShape.js.map +2 -2
  29. package/dist-cjs/store-migrations.js +15 -15
  30. package/dist-cjs/store-migrations.js.map +2 -2
  31. package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
  32. package/dist-esm/createTLSchema.mjs.map +2 -2
  33. package/dist-esm/index.d.mts +71 -242
  34. package/dist-esm/index.mjs +1 -5
  35. package/dist-esm/index.mjs.map +2 -2
  36. package/dist-esm/misc/TLOpacity.mjs +5 -1
  37. package/dist-esm/misc/TLOpacity.mjs.map +2 -2
  38. package/dist-esm/misc/TLRichText.mjs +1 -5
  39. package/dist-esm/misc/TLRichText.mjs.map +2 -2
  40. package/dist-esm/records/TLAsset.mjs.map +1 -1
  41. package/dist-esm/records/TLBinding.mjs.map +2 -2
  42. package/dist-esm/records/TLShape.mjs.map +2 -2
  43. package/dist-esm/shapes/TLArrowShape.mjs +13 -26
  44. package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
  45. package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
  46. package/dist-esm/shapes/TLDrawShape.mjs +4 -37
  47. package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
  48. package/dist-esm/shapes/TLEmbedShape.mjs +0 -17
  49. package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
  50. package/dist-esm/shapes/TLGeoShape.mjs +1 -12
  51. package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
  52. package/dist-esm/shapes/TLHighlightShape.mjs +2 -29
  53. package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
  54. package/dist-esm/shapes/TLNoteShape.mjs +1 -12
  55. package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
  56. package/dist-esm/shapes/TLTextShape.mjs +1 -12
  57. package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
  58. package/dist-esm/store-migrations.mjs +15 -15
  59. package/dist-esm/store-migrations.mjs.map +2 -2
  60. package/package.json +8 -8
  61. package/src/__tests__/migrationTestUtils.ts +3 -9
  62. package/src/assets/TLBookmarkAsset.test.ts +96 -0
  63. package/src/assets/TLImageAsset.test.ts +213 -0
  64. package/src/assets/TLVideoAsset.test.ts +105 -0
  65. package/src/bindings/TLArrowBinding.test.ts +55 -0
  66. package/src/bindings/TLBaseBinding.ts +14 -25
  67. package/src/createTLSchema.ts +2 -8
  68. package/src/index.ts +0 -9
  69. package/src/migrations.test.ts +1 -149
  70. package/src/misc/TLOpacity.ts +5 -1
  71. package/src/misc/TLRichText.ts +1 -6
  72. package/src/misc/id-validator.test.ts +50 -0
  73. package/src/records/TLAsset.test.ts +234 -0
  74. package/src/records/TLAsset.ts +2 -2
  75. package/src/records/TLBinding.test.ts +22 -0
  76. package/src/records/TLBinding.ts +23 -65
  77. package/src/records/TLCamera.test.ts +19 -0
  78. package/src/records/TLDocument.test.ts +35 -0
  79. package/src/records/TLInstance.test.ts +201 -0
  80. package/src/records/TLPage.test.ts +110 -0
  81. package/src/records/TLPageState.test.ts +228 -0
  82. package/src/records/TLPointer.test.ts +63 -0
  83. package/src/records/TLPresence.test.ts +190 -0
  84. package/src/records/TLRecord.test.ts +70 -0
  85. package/src/records/TLShape.test.ts +232 -0
  86. package/src/records/TLShape.ts +5 -100
  87. package/src/shapes/ShapeWithCrop.test.ts +18 -0
  88. package/src/shapes/ShapeWithCrop.ts +2 -2
  89. package/src/shapes/TLArrowShape.test.ts +505 -0
  90. package/src/shapes/TLArrowShape.ts +14 -28
  91. package/src/shapes/TLBaseShape.test.ts +142 -0
  92. package/src/shapes/TLBaseShape.ts +10 -34
  93. package/src/shapes/TLBookmarkShape.test.ts +122 -0
  94. package/src/shapes/TLDrawShape.test.ts +177 -0
  95. package/src/shapes/TLDrawShape.ts +12 -59
  96. package/src/shapes/TLEmbedShape.test.ts +286 -0
  97. package/src/shapes/TLEmbedShape.ts +0 -17
  98. package/src/shapes/TLFrameShape.test.ts +71 -0
  99. package/src/shapes/TLGeoShape.test.ts +247 -0
  100. package/src/shapes/TLGeoShape.ts +1 -14
  101. package/src/shapes/TLGroupShape.test.ts +59 -0
  102. package/src/shapes/TLHighlightShape.test.ts +325 -0
  103. package/src/shapes/TLHighlightShape.ts +0 -37
  104. package/src/shapes/TLImageShape.test.ts +534 -0
  105. package/src/shapes/TLLineShape.test.ts +269 -0
  106. package/src/shapes/TLNoteShape.test.ts +1568 -0
  107. package/src/shapes/TLNoteShape.ts +1 -15
  108. package/src/shapes/TLTextShape.test.ts +407 -0
  109. package/src/shapes/TLTextShape.ts +2 -16
  110. package/src/shapes/TLVideoShape.test.ts +112 -0
  111. package/src/store-migrations.ts +16 -17
  112. package/src/styles/TLColorStyle.test.ts +439 -0
  113. package/dist-cjs/misc/b64Vecs.js +0 -224
  114. package/dist-cjs/misc/b64Vecs.js.map +0 -7
  115. package/dist-esm/misc/b64Vecs.mjs +0 -204
  116. package/dist-esm/misc/b64Vecs.mjs.map +0 -7
  117. package/src/misc/b64Vecs.ts +0 -308
@@ -0,0 +1,269 @@
1
+ import { IndexKey } from '@tldraw/utils'
2
+ import { T } from '@tldraw/validate'
3
+ import { describe, expect, it } from 'vitest'
4
+ import { getTestMigration } from '../__tests__/migrationTestUtils'
5
+ import {
6
+ lineShapeMigrations,
7
+ lineShapeProps,
8
+ LineShapeSplineStyle,
9
+ lineShapeVersions,
10
+ } from './TLLineShape'
11
+
12
+ describe('TLLineShape', () => {
13
+ describe('LineShapeSplineStyle', () => {
14
+ it('should validate correct spline values', () => {
15
+ expect(() => LineShapeSplineStyle.validate('cubic')).not.toThrow()
16
+ expect(() => LineShapeSplineStyle.validate('line')).not.toThrow()
17
+ })
18
+
19
+ it('should reject invalid spline values', () => {
20
+ expect(() => LineShapeSplineStyle.validate('bezier')).toThrow()
21
+ expect(() => LineShapeSplineStyle.validate('')).toThrow()
22
+ expect(() => LineShapeSplineStyle.validate(null)).toThrow()
23
+ })
24
+ })
25
+
26
+ describe('lineShapeProps validation schema', () => {
27
+ it('should validate complete props object', () => {
28
+ const fullValidator = T.object(lineShapeProps)
29
+ const validProps = {
30
+ color: 'red' as const,
31
+ dash: 'dotted' as const,
32
+ size: 's' as const,
33
+ spline: 'line' as const,
34
+ points: {
35
+ start: { id: 'start', index: 'a1' as IndexKey, x: 0, y: 0 },
36
+ end: { id: 'end', index: 'a2' as IndexKey, x: 100, y: 50 },
37
+ },
38
+ scale: 1.5,
39
+ }
40
+
41
+ expect(() => fullValidator.validate(validProps)).not.toThrow()
42
+ })
43
+
44
+ it('should validate points dictionary structure', () => {
45
+ const validPoints = {
46
+ a: { id: 'a', index: 'a1' as IndexKey, x: 0, y: 0 },
47
+ b: { id: 'b', index: 'a2' as IndexKey, x: 100, y: 50 },
48
+ }
49
+ expect(() => lineShapeProps.points.validate(validPoints)).not.toThrow()
50
+
51
+ // Invalid point structures
52
+ expect(() => lineShapeProps.points.validate({ a: { id: 'a', x: 0, y: 0 } })).toThrow() // Missing index
53
+ expect(() => lineShapeProps.points.validate({ a: { index: 'a1', x: 0, y: 0 } })).toThrow() // Missing id
54
+ })
55
+
56
+ it('should validate scale as nonZeroNumber', () => {
57
+ expect(() => lineShapeProps.scale.validate(1.5)).not.toThrow()
58
+ expect(() => lineShapeProps.scale.validate(0)).toThrow() // Zero should be invalid
59
+ expect(() => lineShapeProps.scale.validate(-1)).toThrow() // Negative should be invalid
60
+ })
61
+ })
62
+
63
+ describe('lineShapeMigrations - AddSnapHandles migration', () => {
64
+ const { up } = getTestMigration(lineShapeVersions.AddSnapHandles)
65
+
66
+ it('should add canSnap property to all handles', () => {
67
+ const oldRecord = {
68
+ id: 'shape:line1',
69
+ props: {
70
+ handles: {
71
+ start: { x: 0, y: 0 },
72
+ end: { x: 100, y: 100 },
73
+ },
74
+ },
75
+ }
76
+
77
+ const result = up(oldRecord)
78
+ expect(result.props.handles.start.canSnap).toBe(true)
79
+ expect(result.props.handles.end.canSnap).toBe(true)
80
+ })
81
+ })
82
+
83
+ describe('lineShapeMigrations - RemoveExtraHandleProps migration', () => {
84
+ const { up, down } = getTestMigration(lineShapeVersions.RemoveExtraHandleProps)
85
+
86
+ it('should preserve only x and y properties from handles', () => {
87
+ const oldRecord = {
88
+ id: 'shape:line1',
89
+ props: {
90
+ handles: {
91
+ a1: {
92
+ x: 10,
93
+ y: 20,
94
+ canSnap: true,
95
+ id: 'start',
96
+ type: 'vertex',
97
+ index: 'a1',
98
+ extraProp: 'remove this',
99
+ },
100
+ },
101
+ },
102
+ }
103
+
104
+ const result = up(oldRecord)
105
+ expect(result.props.handles.a1).toEqual({ x: 10, y: 20 })
106
+ })
107
+
108
+ it('should restore full handle structure in down migration', () => {
109
+ const newRecord = {
110
+ id: 'shape:line1',
111
+ props: {
112
+ handles: {
113
+ a1: { x: 0, y: 0 },
114
+ a2: { x: 100, y: 100 },
115
+ },
116
+ },
117
+ }
118
+
119
+ const result = down(newRecord)
120
+ expect(result.props.handles.start).toEqual({
121
+ id: 'start',
122
+ type: 'vertex',
123
+ canBind: false,
124
+ canSnap: true,
125
+ index: 'a1',
126
+ x: 0,
127
+ y: 0,
128
+ })
129
+ })
130
+ })
131
+
132
+ describe('lineShapeMigrations - HandlesToPoints migration', () => {
133
+ const { up, down } = getTestMigration(lineShapeVersions.HandlesToPoints)
134
+
135
+ it('should convert handles to points array', () => {
136
+ const oldRecord = {
137
+ id: 'shape:line1',
138
+ props: {
139
+ handles: {
140
+ a1: { x: 0, y: 0 },
141
+ a2: { x: 50, y: 25 },
142
+ },
143
+ },
144
+ }
145
+
146
+ const result = up(oldRecord)
147
+ expect(result.props.handles).toBeUndefined()
148
+ expect(result.props.points).toEqual([
149
+ { x: 0, y: 0 },
150
+ { x: 50, y: 25 },
151
+ ])
152
+ })
153
+
154
+ it('should convert points back to handles', () => {
155
+ const newRecord = {
156
+ id: 'shape:line1',
157
+ props: {
158
+ points: [
159
+ { x: 0, y: 0 },
160
+ { x: 100, y: 50 },
161
+ ],
162
+ },
163
+ }
164
+
165
+ const result = down(newRecord)
166
+ expect(result.props.points).toBeUndefined()
167
+ expect(result.props.handles).toBeDefined()
168
+ expect(Object.keys(result.props.handles)).toHaveLength(2)
169
+ })
170
+ })
171
+
172
+ describe('lineShapeMigrations - PointIndexIds migration', () => {
173
+ const { up, down } = getTestMigration(lineShapeVersions.PointIndexIds)
174
+
175
+ it('should convert points array to indexed points object', () => {
176
+ const oldRecord = {
177
+ id: 'shape:line1',
178
+ props: {
179
+ points: [
180
+ { x: 0, y: 0 },
181
+ { x: 50, y: 25 },
182
+ ],
183
+ },
184
+ }
185
+
186
+ const result = up(oldRecord)
187
+ expect(Array.isArray(result.props.points)).toBe(false)
188
+ expect(typeof result.props.points).toBe('object')
189
+
190
+ const pointKeys = Object.keys(result.props.points)
191
+ expect(pointKeys).toHaveLength(2)
192
+
193
+ // Each point should have id, index, x, y
194
+ pointKeys.forEach((key) => {
195
+ const point = result.props.points[key]
196
+ expect(point.id).toBe(key)
197
+ expect(point.index).toBe(key)
198
+ })
199
+ })
200
+
201
+ it('should convert indexed points object back to points array', () => {
202
+ const newRecord = {
203
+ id: 'shape:line1',
204
+ props: {
205
+ points: {
206
+ a1: { id: 'a1', index: 'a1' as IndexKey, x: 0, y: 0 },
207
+ a2: { id: 'a2', index: 'a2' as IndexKey, x: 50, y: 25 },
208
+ },
209
+ },
210
+ }
211
+
212
+ const result = down(newRecord)
213
+ expect(Array.isArray(result.props.points)).toBe(true)
214
+ expect(result.props.points).toEqual([
215
+ { x: 0, y: 0 },
216
+ { x: 50, y: 25 },
217
+ ])
218
+ })
219
+ })
220
+
221
+ describe('lineShapeMigrations - AddScale migration', () => {
222
+ const { up, down } = getTestMigration(lineShapeVersions.AddScale)
223
+
224
+ it('should add scale property with default value 1', () => {
225
+ const oldRecord = {
226
+ id: 'shape:line1',
227
+ props: {
228
+ color: 'blue',
229
+ points: {
230
+ a1: { id: 'a1', index: 'a1' as IndexKey, x: 0, y: 0 },
231
+ },
232
+ },
233
+ }
234
+
235
+ const result = up(oldRecord)
236
+ expect(result.props.scale).toBe(1)
237
+ expect(result.props.color).toBe('blue')
238
+ })
239
+
240
+ it('should remove scale property in down migration', () => {
241
+ const newRecord = {
242
+ id: 'shape:line1',
243
+ props: {
244
+ color: 'blue',
245
+ scale: 1.5,
246
+ points: {},
247
+ },
248
+ }
249
+
250
+ const result = down(newRecord)
251
+ expect(result.props.scale).toBeUndefined()
252
+ expect(result.props.color).toBe('blue')
253
+ })
254
+ })
255
+
256
+ describe('migration integration', () => {
257
+ it('should have migrations for all version IDs', () => {
258
+ const migrationIds = lineShapeMigrations.sequence
259
+ .filter((migration) => 'id' in migration)
260
+ .map((migration) => ('id' in migration ? migration.id : ''))
261
+ .filter(Boolean)
262
+
263
+ const versionIds = Object.values(lineShapeVersions)
264
+ versionIds.forEach((versionId) => {
265
+ expect(migrationIds).toContain(versionId)
266
+ })
267
+ })
268
+ })
269
+ })