@tldraw/tlschema 4.2.1 → 4.2.2

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 +242 -71
  4. package/dist-cjs/index.js +4 -1
  5. package/dist-cjs/index.js.map +2 -2
  6. package/dist-cjs/misc/TLOpacity.js +1 -5
  7. package/dist-cjs/misc/TLOpacity.js.map +2 -2
  8. package/dist-cjs/misc/TLRichText.js +5 -1
  9. package/dist-cjs/misc/TLRichText.js.map +2 -2
  10. package/dist-cjs/misc/b64Vecs.js +224 -0
  11. package/dist-cjs/misc/b64Vecs.js.map +7 -0
  12. package/dist-cjs/records/TLAsset.js.map +1 -1
  13. package/dist-cjs/records/TLBinding.js.map +2 -2
  14. package/dist-cjs/records/TLShape.js.map +2 -2
  15. package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
  16. package/dist-cjs/shapes/TLArrowShape.js +26 -13
  17. package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
  18. package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
  19. package/dist-cjs/shapes/TLDrawShape.js +37 -4
  20. package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
  21. package/dist-cjs/shapes/TLEmbedShape.js +17 -0
  22. package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
  23. package/dist-cjs/shapes/TLGeoShape.js +12 -1
  24. package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
  25. package/dist-cjs/shapes/TLHighlightShape.js +29 -2
  26. package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
  27. package/dist-cjs/shapes/TLNoteShape.js +12 -1
  28. package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
  29. package/dist-cjs/shapes/TLTextShape.js +12 -1
  30. package/dist-cjs/shapes/TLTextShape.js.map +2 -2
  31. package/dist-cjs/store-migrations.js +15 -15
  32. package/dist-cjs/store-migrations.js.map +2 -2
  33. package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
  34. package/dist-esm/createTLSchema.mjs.map +2 -2
  35. package/dist-esm/index.d.mts +242 -71
  36. package/dist-esm/index.mjs +5 -1
  37. package/dist-esm/index.mjs.map +2 -2
  38. package/dist-esm/misc/TLOpacity.mjs +1 -5
  39. package/dist-esm/misc/TLOpacity.mjs.map +2 -2
  40. package/dist-esm/misc/TLRichText.mjs +5 -1
  41. package/dist-esm/misc/TLRichText.mjs.map +2 -2
  42. package/dist-esm/misc/b64Vecs.mjs +204 -0
  43. package/dist-esm/misc/b64Vecs.mjs.map +7 -0
  44. package/dist-esm/records/TLAsset.mjs.map +1 -1
  45. package/dist-esm/records/TLBinding.mjs.map +2 -2
  46. package/dist-esm/records/TLShape.mjs.map +2 -2
  47. package/dist-esm/shapes/TLArrowShape.mjs +26 -13
  48. package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
  49. package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
  50. package/dist-esm/shapes/TLDrawShape.mjs +37 -4
  51. package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
  52. package/dist-esm/shapes/TLEmbedShape.mjs +17 -0
  53. package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
  54. package/dist-esm/shapes/TLGeoShape.mjs +12 -1
  55. package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
  56. package/dist-esm/shapes/TLHighlightShape.mjs +29 -2
  57. package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
  58. package/dist-esm/shapes/TLNoteShape.mjs +12 -1
  59. package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
  60. package/dist-esm/shapes/TLTextShape.mjs +12 -1
  61. package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
  62. package/dist-esm/store-migrations.mjs +15 -15
  63. package/dist-esm/store-migrations.mjs.map +2 -2
  64. package/package.json +8 -8
  65. package/src/__tests__/migrationTestUtils.ts +9 -3
  66. package/src/bindings/TLBaseBinding.ts +25 -14
  67. package/src/createTLSchema.ts +8 -2
  68. package/src/index.ts +9 -0
  69. package/src/migrations.test.ts +149 -1
  70. package/src/misc/TLOpacity.ts +1 -5
  71. package/src/misc/TLRichText.ts +6 -1
  72. package/src/misc/b64Vecs.ts +308 -0
  73. package/src/records/TLAsset.ts +2 -2
  74. package/src/records/TLBinding.ts +65 -23
  75. package/src/records/TLShape.ts +100 -5
  76. package/src/shapes/ShapeWithCrop.ts +2 -2
  77. package/src/shapes/TLArrowShape.ts +28 -14
  78. package/src/shapes/TLBaseShape.ts +34 -10
  79. package/src/shapes/TLDrawShape.ts +59 -12
  80. package/src/shapes/TLEmbedShape.ts +17 -0
  81. package/src/shapes/TLGeoShape.ts +14 -1
  82. package/src/shapes/TLHighlightShape.ts +37 -0
  83. package/src/shapes/TLNoteShape.ts +15 -1
  84. package/src/shapes/TLTextShape.ts +16 -2
  85. package/src/store-migrations.ts +17 -16
  86. package/src/assets/TLBookmarkAsset.test.ts +0 -96
  87. package/src/assets/TLImageAsset.test.ts +0 -213
  88. package/src/assets/TLVideoAsset.test.ts +0 -105
  89. package/src/bindings/TLArrowBinding.test.ts +0 -55
  90. package/src/misc/id-validator.test.ts +0 -50
  91. package/src/records/TLAsset.test.ts +0 -234
  92. package/src/records/TLBinding.test.ts +0 -22
  93. package/src/records/TLCamera.test.ts +0 -19
  94. package/src/records/TLDocument.test.ts +0 -35
  95. package/src/records/TLInstance.test.ts +0 -201
  96. package/src/records/TLPage.test.ts +0 -110
  97. package/src/records/TLPageState.test.ts +0 -228
  98. package/src/records/TLPointer.test.ts +0 -63
  99. package/src/records/TLPresence.test.ts +0 -190
  100. package/src/records/TLRecord.test.ts +0 -70
  101. package/src/records/TLShape.test.ts +0 -232
  102. package/src/shapes/ShapeWithCrop.test.ts +0 -18
  103. package/src/shapes/TLArrowShape.test.ts +0 -505
  104. package/src/shapes/TLBaseShape.test.ts +0 -142
  105. package/src/shapes/TLBookmarkShape.test.ts +0 -122
  106. package/src/shapes/TLDrawShape.test.ts +0 -177
  107. package/src/shapes/TLEmbedShape.test.ts +0 -286
  108. package/src/shapes/TLFrameShape.test.ts +0 -71
  109. package/src/shapes/TLGeoShape.test.ts +0 -247
  110. package/src/shapes/TLGroupShape.test.ts +0 -59
  111. package/src/shapes/TLHighlightShape.test.ts +0 -325
  112. package/src/shapes/TLImageShape.test.ts +0 -534
  113. package/src/shapes/TLLineShape.test.ts +0 -269
  114. package/src/shapes/TLNoteShape.test.ts +0 -1568
  115. package/src/shapes/TLTextShape.test.ts +0 -407
  116. package/src/shapes/TLVideoShape.test.ts +0 -112
  117. package/src/styles/TLColorStyle.test.ts +0 -439
@@ -1,269 +0,0 @@
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
- })