@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,232 +0,0 @@
1
- import { T } from '@tldraw/validate'
2
- import { describe, expect, it } from 'vitest'
3
- import { StyleProp } from '../styles/StyleProp'
4
- import {
5
- createShapeId,
6
- createShapePropsMigrationIds,
7
- createShapeRecordType,
8
- getShapePropKeysByStyle,
9
- isShape,
10
- isShapeId,
11
- rootShapeMigrations,
12
- rootShapeVersions,
13
- TLShapeId,
14
- } from './TLShape'
15
-
16
- describe('rootShapeMigrations', () => {
17
- it('should migrate AddIsLocked correctly', () => {
18
- const migration = rootShapeMigrations.sequence.find(
19
- (m) => m.id === rootShapeVersions.AddIsLocked
20
- )!
21
- expect(migration.up).toBeDefined()
22
- expect(migration.down).toBeDefined()
23
-
24
- const record: any = { id: 'shape:test', typeName: 'shape', type: 'geo' }
25
- migration.up(record)
26
- expect(record.isLocked).toBe(false)
27
-
28
- migration.down!(record)
29
- expect(record.isLocked).toBeUndefined()
30
- })
31
-
32
- it('should migrate HoistOpacity correctly', () => {
33
- const migration = rootShapeMigrations.sequence.find(
34
- (m) => m.id === rootShapeVersions.HoistOpacity
35
- )!
36
- expect(migration.up).toBeDefined()
37
- expect(migration.down).toBeDefined()
38
-
39
- // Test up migration
40
- const record: any = {
41
- id: 'shape:test',
42
- typeName: 'shape',
43
- type: 'geo',
44
- props: { opacity: '0.5', color: 'red' },
45
- }
46
- migration.up(record)
47
- expect(record.opacity).toBe(0.5)
48
- expect(record.props.opacity).toBeUndefined()
49
- expect(record.props.color).toBe('red')
50
-
51
- // Test down migration
52
- migration.down!(record)
53
- expect(record.props.opacity).toBe('0.5')
54
- expect(record.opacity).toBeUndefined()
55
- })
56
-
57
- it('should migrate AddMeta correctly', () => {
58
- const migration = rootShapeMigrations.sequence.find((m) => m.id === rootShapeVersions.AddMeta)!
59
- const record: any = { id: 'shape:test', typeName: 'shape', type: 'geo' }
60
- migration.up(record)
61
- expect(record.meta).toEqual({})
62
- })
63
-
64
- it('should handle AddWhite migration', () => {
65
- const migration = rootShapeMigrations.sequence.find((m) => m.id === rootShapeVersions.AddWhite)!
66
- expect(migration.up).toBeDefined()
67
- expect(migration.down).toBeDefined()
68
-
69
- // Up migration is noop
70
- const record: any = { props: { color: 'white' } }
71
- const original = { ...record }
72
- migration.up(record)
73
- expect(record).toEqual(original)
74
-
75
- // Down migration converts white to black
76
- migration.down!(record)
77
- expect(record.props.color).toBe('black')
78
- })
79
- })
80
-
81
- describe('isShape', () => {
82
- it('should return true for shape records', () => {
83
- const shape = {
84
- id: 'shape:test' as TLShapeId,
85
- typeName: 'shape',
86
- type: 'geo',
87
- x: 0,
88
- y: 0,
89
- rotation: 0,
90
- index: 'a1' as any,
91
- parentId: 'page:main' as any,
92
- isLocked: false,
93
- opacity: 1,
94
- props: {},
95
- meta: {},
96
- }
97
-
98
- expect(isShape(shape)).toBe(true)
99
- })
100
-
101
- it('should return false for non-shape records', () => {
102
- const notShape = {
103
- id: 'page:test',
104
- typeName: 'page',
105
- name: 'Test Page',
106
- }
107
-
108
- expect(isShape(notShape as any)).toBe(false)
109
- })
110
- })
111
-
112
- describe('isShapeId', () => {
113
- it('should return true for valid shape IDs', () => {
114
- expect(isShapeId('shape:test')).toBe(true)
115
- expect(isShapeId('shape:abc123')).toBe(true)
116
- expect(isShapeId('shape:')).toBe(true)
117
- })
118
-
119
- it('should return false for invalid shape IDs', () => {
120
- expect(isShapeId('page:test')).toBe(false)
121
- expect(isShapeId('asset:test')).toBe(false)
122
- expect(isShapeId('invalid')).toBe(false)
123
- expect(isShapeId('')).toBe(false)
124
- })
125
- })
126
-
127
- describe('createShapeId', () => {
128
- it('should create shape IDs with auto-generated suffix', () => {
129
- const id1 = createShapeId()
130
- const id2 = createShapeId()
131
-
132
- expect(id1.startsWith('shape:')).toBe(true)
133
- expect(id2.startsWith('shape:')).toBe(true)
134
- expect(id1).not.toBe(id2)
135
- expect(id1.length).toBeGreaterThan(6) // 'shape:' + some ID
136
- expect(id2.length).toBeGreaterThan(6)
137
- })
138
-
139
- it('should create shape IDs with custom suffix', () => {
140
- const customId = createShapeId('my-custom-id')
141
- expect(customId).toBe('shape:my-custom-id')
142
- })
143
- })
144
-
145
- describe('getShapePropKeysByStyle', () => {
146
- it('should map style props to their keys', () => {
147
- const colorStyle = StyleProp.define('color', { defaultValue: 'black' })
148
- const sizeStyle = StyleProp.define('size', { defaultValue: 'm' })
149
-
150
- const props = {
151
- color: colorStyle,
152
- size: sizeStyle,
153
- width: T.number,
154
- height: T.number,
155
- }
156
-
157
- const styleMap = getShapePropKeysByStyle(props)
158
- expect(styleMap.get(colorStyle)).toBe('color')
159
- expect(styleMap.get(sizeStyle)).toBe('size')
160
- expect(styleMap.size).toBe(2) // Only style props
161
- })
162
-
163
- it('should throw error for duplicate style props', () => {
164
- const colorStyle = StyleProp.define('color', { defaultValue: 'black' })
165
- const props = {
166
- color1: colorStyle,
167
- color2: colorStyle, // Same style prop used twice
168
- width: T.number,
169
- }
170
-
171
- expect(() => getShapePropKeysByStyle(props)).toThrow('Duplicate style prop')
172
- })
173
- })
174
-
175
- describe('createShapePropsMigrationIds', () => {
176
- it('should create formatted migration IDs', () => {
177
- const ids = createShapePropsMigrationIds('custom', {
178
- AddColor: 1,
179
- AddSize: 2,
180
- RefactorProps: 3,
181
- })
182
-
183
- expect(ids.AddColor).toBe('com.tldraw.shape.custom/1')
184
- expect(ids.AddSize).toBe('com.tldraw.shape.custom/2')
185
- expect(ids.RefactorProps).toBe('com.tldraw.shape.custom/3')
186
- })
187
- })
188
-
189
- describe('createShapeRecordType', () => {
190
- it('should create a record type for shapes', () => {
191
- const shapes = {
192
- geo: {
193
- props: {
194
- w: T.number,
195
- h: T.number,
196
- color: StyleProp.define('color', { defaultValue: 'black' }),
197
- },
198
- meta: {},
199
- },
200
- text: {
201
- props: {
202
- text: T.string,
203
- size: StyleProp.define('size', { defaultValue: 'm' }),
204
- },
205
- meta: {},
206
- },
207
- }
208
-
209
- const ShapeRecordType = createShapeRecordType(shapes)
210
-
211
- expect(ShapeRecordType.typeName).toBe('shape')
212
- expect(ShapeRecordType.scope).toBe('document')
213
-
214
- // Should be able to create shapes
215
- const geoShape = ShapeRecordType.create({
216
- id: createShapeId(),
217
- type: 'geo',
218
- parentId: 'page:main' as any,
219
- index: 'a1' as any,
220
- props: {},
221
- })
222
-
223
- expect(geoShape.typeName).toBe('shape')
224
- expect(geoShape.type).toBe('geo')
225
- expect(geoShape.x).toBe(0) // Default
226
- expect(geoShape.y).toBe(0) // Default
227
- expect(geoShape.rotation).toBe(0) // Default
228
- expect(geoShape.isLocked).toBe(false) // Default
229
- expect(geoShape.opacity).toBe(1) // Default
230
- expect(geoShape.meta).toEqual({}) // Default
231
- })
232
- })
@@ -1,18 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { TLShapeCrop } from './ShapeWithCrop'
3
-
4
- describe('TLShapeCrop', () => {
5
- test('should calculate crop dimensions correctly', () => {
6
- const crop: TLShapeCrop = {
7
- topLeft: { x: 0.2, y: 0.3 },
8
- bottomRight: { x: 0.8, y: 0.7 },
9
- }
10
-
11
- // This tests the actual utility of the crop interface - calculating dimensions
12
- const width = crop.bottomRight.x - crop.topLeft.x
13
- const height = crop.bottomRight.y - crop.topLeft.y
14
-
15
- expect(width).toBeCloseTo(0.6)
16
- expect(height).toBeCloseTo(0.4)
17
- })
18
- })