@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.
- package/dist-cjs/bindings/TLBaseBinding.js.map +2 -2
- package/dist-cjs/createTLSchema.js.map +2 -2
- package/dist-cjs/index.d.ts +242 -71
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/misc/TLOpacity.js +1 -5
- package/dist-cjs/misc/TLOpacity.js.map +2 -2
- package/dist-cjs/misc/TLRichText.js +5 -1
- package/dist-cjs/misc/TLRichText.js.map +2 -2
- package/dist-cjs/misc/b64Vecs.js +224 -0
- package/dist-cjs/misc/b64Vecs.js.map +7 -0
- package/dist-cjs/records/TLAsset.js.map +1 -1
- package/dist-cjs/records/TLBinding.js.map +2 -2
- package/dist-cjs/records/TLShape.js.map +2 -2
- package/dist-cjs/shapes/ShapeWithCrop.js.map +1 -1
- package/dist-cjs/shapes/TLArrowShape.js +26 -13
- package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
- package/dist-cjs/shapes/TLBaseShape.js.map +2 -2
- package/dist-cjs/shapes/TLDrawShape.js +37 -4
- package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
- package/dist-cjs/shapes/TLEmbedShape.js +17 -0
- package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
- package/dist-cjs/shapes/TLGeoShape.js +12 -1
- package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
- package/dist-cjs/shapes/TLHighlightShape.js +29 -2
- package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
- package/dist-cjs/shapes/TLNoteShape.js +12 -1
- package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
- package/dist-cjs/shapes/TLTextShape.js +12 -1
- package/dist-cjs/shapes/TLTextShape.js.map +2 -2
- package/dist-cjs/store-migrations.js +15 -15
- package/dist-cjs/store-migrations.js.map +2 -2
- package/dist-esm/bindings/TLBaseBinding.mjs.map +2 -2
- package/dist-esm/createTLSchema.mjs.map +2 -2
- package/dist-esm/index.d.mts +242 -71
- package/dist-esm/index.mjs +5 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/misc/TLOpacity.mjs +1 -5
- package/dist-esm/misc/TLOpacity.mjs.map +2 -2
- package/dist-esm/misc/TLRichText.mjs +5 -1
- package/dist-esm/misc/TLRichText.mjs.map +2 -2
- package/dist-esm/misc/b64Vecs.mjs +204 -0
- package/dist-esm/misc/b64Vecs.mjs.map +7 -0
- package/dist-esm/records/TLAsset.mjs.map +1 -1
- package/dist-esm/records/TLBinding.mjs.map +2 -2
- package/dist-esm/records/TLShape.mjs.map +2 -2
- package/dist-esm/shapes/TLArrowShape.mjs +26 -13
- package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
- package/dist-esm/shapes/TLBaseShape.mjs.map +2 -2
- package/dist-esm/shapes/TLDrawShape.mjs +37 -4
- package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
- package/dist-esm/shapes/TLEmbedShape.mjs +17 -0
- package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
- package/dist-esm/shapes/TLGeoShape.mjs +12 -1
- package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
- package/dist-esm/shapes/TLHighlightShape.mjs +29 -2
- package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
- package/dist-esm/shapes/TLNoteShape.mjs +12 -1
- package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
- package/dist-esm/shapes/TLTextShape.mjs +12 -1
- package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
- package/dist-esm/store-migrations.mjs +15 -15
- package/dist-esm/store-migrations.mjs.map +2 -2
- package/package.json +8 -8
- package/src/__tests__/migrationTestUtils.ts +9 -3
- package/src/bindings/TLBaseBinding.ts +25 -14
- package/src/createTLSchema.ts +8 -2
- package/src/index.ts +9 -0
- package/src/migrations.test.ts +149 -1
- package/src/misc/TLOpacity.ts +1 -5
- package/src/misc/TLRichText.ts +6 -1
- package/src/misc/b64Vecs.ts +308 -0
- package/src/records/TLAsset.ts +2 -2
- package/src/records/TLBinding.ts +65 -23
- package/src/records/TLShape.ts +100 -5
- package/src/shapes/ShapeWithCrop.ts +2 -2
- package/src/shapes/TLArrowShape.ts +28 -14
- package/src/shapes/TLBaseShape.ts +34 -10
- package/src/shapes/TLDrawShape.ts +59 -12
- package/src/shapes/TLEmbedShape.ts +17 -0
- package/src/shapes/TLGeoShape.ts +14 -1
- package/src/shapes/TLHighlightShape.ts +37 -0
- package/src/shapes/TLNoteShape.ts +15 -1
- package/src/shapes/TLTextShape.ts +16 -2
- package/src/store-migrations.ts +17 -16
- package/src/assets/TLBookmarkAsset.test.ts +0 -96
- package/src/assets/TLImageAsset.test.ts +0 -213
- package/src/assets/TLVideoAsset.test.ts +0 -105
- package/src/bindings/TLArrowBinding.test.ts +0 -55
- package/src/misc/id-validator.test.ts +0 -50
- package/src/records/TLAsset.test.ts +0 -234
- package/src/records/TLBinding.test.ts +0 -22
- package/src/records/TLCamera.test.ts +0 -19
- package/src/records/TLDocument.test.ts +0 -35
- package/src/records/TLInstance.test.ts +0 -201
- package/src/records/TLPage.test.ts +0 -110
- package/src/records/TLPageState.test.ts +0 -228
- package/src/records/TLPointer.test.ts +0 -63
- package/src/records/TLPresence.test.ts +0 -190
- package/src/records/TLRecord.test.ts +0 -70
- package/src/records/TLShape.test.ts +0 -232
- package/src/shapes/ShapeWithCrop.test.ts +0 -18
- package/src/shapes/TLArrowShape.test.ts +0 -505
- package/src/shapes/TLBaseShape.test.ts +0 -142
- package/src/shapes/TLBookmarkShape.test.ts +0 -122
- package/src/shapes/TLDrawShape.test.ts +0 -177
- package/src/shapes/TLEmbedShape.test.ts +0 -286
- package/src/shapes/TLFrameShape.test.ts +0 -71
- package/src/shapes/TLGeoShape.test.ts +0 -247
- package/src/shapes/TLGroupShape.test.ts +0 -59
- package/src/shapes/TLHighlightShape.test.ts +0 -325
- package/src/shapes/TLImageShape.test.ts +0 -534
- package/src/shapes/TLLineShape.test.ts +0 -269
- package/src/shapes/TLNoteShape.test.ts +0 -1568
- package/src/shapes/TLTextShape.test.ts +0 -407
- package/src/shapes/TLVideoShape.test.ts +0 -112
- package/src/styles/TLColorStyle.test.ts +0 -439
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { getTestMigration } from '../__tests__/migrationTestUtils'
|
|
3
|
-
import { bookmarkAssetVersions } from './TLBookmarkAsset'
|
|
4
|
-
|
|
5
|
-
describe('TLBookmarkAsset', () => {
|
|
6
|
-
describe('MakeUrlsValid migration', () => {
|
|
7
|
-
const { up, down } = getTestMigration(bookmarkAssetVersions.MakeUrlsValid)
|
|
8
|
-
|
|
9
|
-
it('should clean invalid src URLs and preserve valid ones', () => {
|
|
10
|
-
const assetWithInvalidSrc = {
|
|
11
|
-
id: 'asset:bookmark1',
|
|
12
|
-
type: 'bookmark',
|
|
13
|
-
props: {
|
|
14
|
-
title: 'Test Bookmark',
|
|
15
|
-
description: 'Test Description',
|
|
16
|
-
image: 'https://example.com/image.jpg',
|
|
17
|
-
src: 'invalid-url-format',
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const result = up(assetWithInvalidSrc)
|
|
22
|
-
expect(result.props.src).toBe('')
|
|
23
|
-
|
|
24
|
-
// Test valid URL is preserved
|
|
25
|
-
const assetWithValidSrc = {
|
|
26
|
-
...assetWithInvalidSrc,
|
|
27
|
-
props: { ...assetWithInvalidSrc.props, src: 'https://example.com' },
|
|
28
|
-
}
|
|
29
|
-
const validResult = up(assetWithValidSrc)
|
|
30
|
-
expect(validResult.props.src).toBe('https://example.com')
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should be a no-op down migration', () => {
|
|
34
|
-
const asset = {
|
|
35
|
-
id: 'asset:bookmark1',
|
|
36
|
-
type: 'bookmark',
|
|
37
|
-
props: {
|
|
38
|
-
title: 'Test Bookmark',
|
|
39
|
-
description: 'Test Description',
|
|
40
|
-
image: 'https://example.com/image.jpg',
|
|
41
|
-
src: 'https://example.com',
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const result = down(asset)
|
|
46
|
-
expect(result).toEqual(asset)
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
describe('AddFavicon migration', () => {
|
|
51
|
-
const { up, down } = getTestMigration(bookmarkAssetVersions.AddFavicon)
|
|
52
|
-
|
|
53
|
-
it('should add favicon property and clean invalid URLs', () => {
|
|
54
|
-
// Test adding favicon property to asset without one
|
|
55
|
-
const assetWithoutFavicon = {
|
|
56
|
-
id: 'asset:bookmark1',
|
|
57
|
-
type: 'bookmark',
|
|
58
|
-
props: {
|
|
59
|
-
title: 'Test Bookmark',
|
|
60
|
-
description: 'Test Description',
|
|
61
|
-
image: 'https://example.com/image.jpg',
|
|
62
|
-
src: 'https://example.com',
|
|
63
|
-
},
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const result = up(assetWithoutFavicon)
|
|
67
|
-
expect(result.props.favicon).toBe('')
|
|
68
|
-
|
|
69
|
-
// Test cleaning invalid favicon URL
|
|
70
|
-
const assetWithInvalidFavicon = {
|
|
71
|
-
...assetWithoutFavicon,
|
|
72
|
-
props: { ...assetWithoutFavicon.props, favicon: 'invalid-url' },
|
|
73
|
-
}
|
|
74
|
-
const cleanResult = up(assetWithInvalidFavicon)
|
|
75
|
-
expect(cleanResult.props.favicon).toBe('')
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('should remove favicon property in down migration', () => {
|
|
79
|
-
const assetWithFavicon = {
|
|
80
|
-
id: 'asset:bookmark1',
|
|
81
|
-
type: 'bookmark',
|
|
82
|
-
props: {
|
|
83
|
-
title: 'Test Bookmark',
|
|
84
|
-
description: 'Test Description',
|
|
85
|
-
image: 'https://example.com/image.jpg',
|
|
86
|
-
src: 'https://example.com',
|
|
87
|
-
favicon: 'https://example.com/favicon.ico',
|
|
88
|
-
},
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const result = down(assetWithFavicon)
|
|
92
|
-
expect(result.props).not.toHaveProperty('favicon')
|
|
93
|
-
expect(result.props.title).toBe('Test Bookmark')
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
})
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { getTestMigration } from '../__tests__/migrationTestUtils'
|
|
3
|
-
import { imageAssetVersions } from './TLImageAsset'
|
|
4
|
-
|
|
5
|
-
describe('TLImageAsset', () => {
|
|
6
|
-
describe('AddIsAnimated migration', () => {
|
|
7
|
-
const { up, down } = getTestMigration(imageAssetVersions.AddIsAnimated)
|
|
8
|
-
|
|
9
|
-
it('should add isAnimated property in up migration', () => {
|
|
10
|
-
const assetWithoutIsAnimated = {
|
|
11
|
-
id: 'asset:image1',
|
|
12
|
-
type: 'image',
|
|
13
|
-
props: {
|
|
14
|
-
w: 100,
|
|
15
|
-
h: 100,
|
|
16
|
-
name: 'test.jpg',
|
|
17
|
-
mimeType: 'image/jpeg',
|
|
18
|
-
src: 'https://example.com/test.jpg',
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const result = up(assetWithoutIsAnimated)
|
|
23
|
-
expect(result.props.isAnimated).toBe(false)
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('should remove isAnimated property in down migration', () => {
|
|
27
|
-
const assetWithIsAnimated = {
|
|
28
|
-
id: 'asset:image3',
|
|
29
|
-
type: 'image',
|
|
30
|
-
props: {
|
|
31
|
-
w: 100,
|
|
32
|
-
h: 100,
|
|
33
|
-
name: 'test.jpg',
|
|
34
|
-
mimeType: 'image/jpeg',
|
|
35
|
-
src: 'https://example.com/test.jpg',
|
|
36
|
-
isAnimated: false,
|
|
37
|
-
},
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const result = down(assetWithIsAnimated)
|
|
41
|
-
expect(result.props).not.toHaveProperty('isAnimated')
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
describe('RenameWidthHeight migration', () => {
|
|
46
|
-
const { up, down } = getTestMigration(imageAssetVersions.RenameWidthHeight)
|
|
47
|
-
|
|
48
|
-
it('should rename width and height to w and h in up migration', () => {
|
|
49
|
-
const assetWithWidthHeight = {
|
|
50
|
-
id: 'asset:image1',
|
|
51
|
-
type: 'image',
|
|
52
|
-
props: {
|
|
53
|
-
width: 800,
|
|
54
|
-
height: 600,
|
|
55
|
-
name: 'test.jpg',
|
|
56
|
-
isAnimated: false,
|
|
57
|
-
mimeType: 'image/jpeg',
|
|
58
|
-
src: 'https://example.com/test.jpg',
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const result = up(assetWithWidthHeight)
|
|
63
|
-
expect(result.props.w).toBe(800)
|
|
64
|
-
expect(result.props.h).toBe(600)
|
|
65
|
-
expect(result.props).not.toHaveProperty('width')
|
|
66
|
-
expect(result.props).not.toHaveProperty('height')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should rename w and h to width and height in down migration', () => {
|
|
70
|
-
const assetWithWH = {
|
|
71
|
-
id: 'asset:image3',
|
|
72
|
-
type: 'image',
|
|
73
|
-
props: {
|
|
74
|
-
w: 1024,
|
|
75
|
-
h: 768,
|
|
76
|
-
name: 'test.png',
|
|
77
|
-
isAnimated: false,
|
|
78
|
-
mimeType: 'image/png',
|
|
79
|
-
src: 'https://example.com/test.png',
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const result = down(assetWithWH)
|
|
84
|
-
expect(result.props.width).toBe(1024)
|
|
85
|
-
expect(result.props.height).toBe(768)
|
|
86
|
-
expect(result.props).not.toHaveProperty('w')
|
|
87
|
-
expect(result.props).not.toHaveProperty('h')
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
describe('MakeUrlsValid migration', () => {
|
|
92
|
-
const { up, down: _down } = getTestMigration(imageAssetVersions.MakeUrlsValid)
|
|
93
|
-
|
|
94
|
-
it('should clean invalid src URLs in up migration', () => {
|
|
95
|
-
const assetWithInvalidSrc = {
|
|
96
|
-
id: 'asset:image1',
|
|
97
|
-
type: 'image',
|
|
98
|
-
props: {
|
|
99
|
-
w: 100,
|
|
100
|
-
h: 100,
|
|
101
|
-
name: 'test.jpg',
|
|
102
|
-
isAnimated: false,
|
|
103
|
-
mimeType: 'image/jpeg',
|
|
104
|
-
src: 'invalid-url-format',
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const result = up(assetWithInvalidSrc)
|
|
109
|
-
expect(result.props.src).toBe('')
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('should preserve valid src URLs in up migration', () => {
|
|
113
|
-
const assetWithValidSrc = {
|
|
114
|
-
id: 'asset:image2',
|
|
115
|
-
type: 'image',
|
|
116
|
-
props: {
|
|
117
|
-
w: 100,
|
|
118
|
-
h: 100,
|
|
119
|
-
name: 'test.jpg',
|
|
120
|
-
isAnimated: false,
|
|
121
|
-
mimeType: 'image/jpeg',
|
|
122
|
-
src: 'https://example.com/test.jpg',
|
|
123
|
-
},
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const result = up(assetWithValidSrc)
|
|
127
|
-
expect(result.props.src).toBe('https://example.com/test.jpg')
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
describe('AddFileSize migration', () => {
|
|
132
|
-
const { up, down } = getTestMigration(imageAssetVersions.AddFileSize)
|
|
133
|
-
|
|
134
|
-
it('should add fileSize property with -1 default in up migration', () => {
|
|
135
|
-
const assetWithoutFileSize = {
|
|
136
|
-
id: 'asset:image1',
|
|
137
|
-
type: 'image',
|
|
138
|
-
props: {
|
|
139
|
-
w: 100,
|
|
140
|
-
h: 100,
|
|
141
|
-
name: 'test.jpg',
|
|
142
|
-
isAnimated: false,
|
|
143
|
-
mimeType: 'image/jpeg',
|
|
144
|
-
src: 'https://example.com/test.jpg',
|
|
145
|
-
},
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const result = up(assetWithoutFileSize)
|
|
149
|
-
expect(result.props.fileSize).toBe(-1)
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
it('should remove fileSize property in down migration', () => {
|
|
153
|
-
const assetWithFileSize = {
|
|
154
|
-
id: 'asset:image3',
|
|
155
|
-
type: 'image',
|
|
156
|
-
props: {
|
|
157
|
-
w: 100,
|
|
158
|
-
h: 100,
|
|
159
|
-
name: 'test.jpg',
|
|
160
|
-
isAnimated: false,
|
|
161
|
-
mimeType: 'image/jpeg',
|
|
162
|
-
src: 'https://example.com/test.jpg',
|
|
163
|
-
fileSize: 50000,
|
|
164
|
-
},
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const result = down(assetWithFileSize)
|
|
168
|
-
expect(result.props).not.toHaveProperty('fileSize')
|
|
169
|
-
})
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
describe('MakeFileSizeOptional migration', () => {
|
|
173
|
-
const { up, down } = getTestMigration(imageAssetVersions.MakeFileSizeOptional)
|
|
174
|
-
|
|
175
|
-
it('should convert fileSize -1 to undefined in up migration', () => {
|
|
176
|
-
const assetWithNegativeFileSize = {
|
|
177
|
-
id: 'asset:image1',
|
|
178
|
-
type: 'image',
|
|
179
|
-
props: {
|
|
180
|
-
w: 100,
|
|
181
|
-
h: 100,
|
|
182
|
-
name: 'test.jpg',
|
|
183
|
-
isAnimated: false,
|
|
184
|
-
mimeType: 'image/jpeg',
|
|
185
|
-
src: 'https://example.com/test.jpg',
|
|
186
|
-
fileSize: -1,
|
|
187
|
-
},
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const result = up(assetWithNegativeFileSize)
|
|
191
|
-
expect(result.props.fileSize).toBeUndefined()
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('should convert undefined fileSize to -1 in down migration', () => {
|
|
195
|
-
const assetWithUndefinedFileSize = {
|
|
196
|
-
id: 'asset:image5',
|
|
197
|
-
type: 'image',
|
|
198
|
-
props: {
|
|
199
|
-
w: 100,
|
|
200
|
-
h: 100,
|
|
201
|
-
name: 'test.jpg',
|
|
202
|
-
isAnimated: false,
|
|
203
|
-
mimeType: 'image/jpeg',
|
|
204
|
-
src: 'https://example.com/test.jpg',
|
|
205
|
-
fileSize: undefined,
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const result = down(assetWithUndefinedFileSize)
|
|
210
|
-
expect(result.props.fileSize).toBe(-1)
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
})
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { getTestMigration } from '../__tests__/migrationTestUtils'
|
|
3
|
-
import { videoAssetVersions } from './TLVideoAsset'
|
|
4
|
-
|
|
5
|
-
describe('TLVideoAsset', () => {
|
|
6
|
-
describe('migrations', () => {
|
|
7
|
-
it('should handle AddIsAnimated migration', () => {
|
|
8
|
-
const { up, down } = getTestMigration(videoAssetVersions.AddIsAnimated)
|
|
9
|
-
|
|
10
|
-
const assetWithoutIsAnimated = {
|
|
11
|
-
id: 'asset:video1',
|
|
12
|
-
type: 'video',
|
|
13
|
-
props: {
|
|
14
|
-
w: 640,
|
|
15
|
-
h: 480,
|
|
16
|
-
name: 'test.mp4',
|
|
17
|
-
mimeType: 'video/mp4',
|
|
18
|
-
src: 'https://example.com/test.mp4',
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const upResult = up(assetWithoutIsAnimated)
|
|
23
|
-
expect(upResult.props.isAnimated).toBe(false)
|
|
24
|
-
|
|
25
|
-
const downResult = down(upResult)
|
|
26
|
-
expect(downResult.props).not.toHaveProperty('isAnimated')
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should handle RenameWidthHeight migration', () => {
|
|
30
|
-
const { up, down } = getTestMigration(videoAssetVersions.RenameWidthHeight)
|
|
31
|
-
|
|
32
|
-
const assetWithWidthHeight = {
|
|
33
|
-
id: 'asset:video1',
|
|
34
|
-
type: 'video',
|
|
35
|
-
props: {
|
|
36
|
-
width: 1920,
|
|
37
|
-
height: 1080,
|
|
38
|
-
name: 'test.mp4',
|
|
39
|
-
isAnimated: true,
|
|
40
|
-
mimeType: 'video/mp4',
|
|
41
|
-
src: 'https://example.com/test.mp4',
|
|
42
|
-
},
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const upResult = up(assetWithWidthHeight)
|
|
46
|
-
expect(upResult.props.w).toBe(1920)
|
|
47
|
-
expect(upResult.props.h).toBe(1080)
|
|
48
|
-
expect(upResult.props).not.toHaveProperty('width')
|
|
49
|
-
expect(upResult.props).not.toHaveProperty('height')
|
|
50
|
-
|
|
51
|
-
const downResult = down(upResult)
|
|
52
|
-
expect(downResult.props.width).toBe(1920)
|
|
53
|
-
expect(downResult.props.height).toBe(1080)
|
|
54
|
-
expect(downResult.props).not.toHaveProperty('w')
|
|
55
|
-
expect(downResult.props).not.toHaveProperty('h')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should handle MakeUrlsValid migration', () => {
|
|
59
|
-
const { up } = getTestMigration(videoAssetVersions.MakeUrlsValid)
|
|
60
|
-
|
|
61
|
-
const assetWithInvalidSrc = {
|
|
62
|
-
id: 'asset:video1',
|
|
63
|
-
type: 'video',
|
|
64
|
-
props: {
|
|
65
|
-
w: 640,
|
|
66
|
-
h: 480,
|
|
67
|
-
name: 'test.mp4',
|
|
68
|
-
isAnimated: true,
|
|
69
|
-
mimeType: 'video/mp4',
|
|
70
|
-
src: 'invalid-url-format',
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const result = up(assetWithInvalidSrc)
|
|
75
|
-
expect(result.props.src).toBe('')
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('should handle MakeFileSizeOptional migration', () => {
|
|
79
|
-
const { up, down } = getTestMigration(videoAssetVersions.MakeFileSizeOptional)
|
|
80
|
-
|
|
81
|
-
const assetWithNegativeFileSize = {
|
|
82
|
-
id: 'asset:video1',
|
|
83
|
-
type: 'video',
|
|
84
|
-
props: {
|
|
85
|
-
w: 640,
|
|
86
|
-
h: 480,
|
|
87
|
-
name: 'test.mp4',
|
|
88
|
-
isAnimated: true,
|
|
89
|
-
mimeType: 'video/mp4',
|
|
90
|
-
src: 'https://example.com/test.mp4',
|
|
91
|
-
fileSize: -1,
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const upResult = up(assetWithNegativeFileSize)
|
|
96
|
-
expect(upResult.props.fileSize).toBeUndefined()
|
|
97
|
-
|
|
98
|
-
const downResult = down({
|
|
99
|
-
...assetWithNegativeFileSize,
|
|
100
|
-
props: { ...assetWithNegativeFileSize.props, fileSize: undefined },
|
|
101
|
-
})
|
|
102
|
-
expect(downResult.props.fileSize).toBe(-1)
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
})
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { getTestMigration } from '../__tests__/migrationTestUtils'
|
|
3
|
-
import { arrowBindingVersions } from './TLArrowBinding'
|
|
4
|
-
|
|
5
|
-
describe('TLArrowBinding', () => {
|
|
6
|
-
describe('AddSnap migration', () => {
|
|
7
|
-
const { up, down } = getTestMigration(arrowBindingVersions.AddSnap)
|
|
8
|
-
|
|
9
|
-
it('should add snap property with default value "none"', () => {
|
|
10
|
-
const oldRecord = {
|
|
11
|
-
props: {
|
|
12
|
-
terminal: 'end',
|
|
13
|
-
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
14
|
-
isExact: true,
|
|
15
|
-
isPrecise: false,
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const result = up(oldRecord)
|
|
20
|
-
expect(result.props.snap).toBe('none')
|
|
21
|
-
expect(result.props.terminal).toBe('end')
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it('should remove snap property on down migration', () => {
|
|
25
|
-
const newRecord = {
|
|
26
|
-
props: {
|
|
27
|
-
terminal: 'end',
|
|
28
|
-
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
29
|
-
isExact: true,
|
|
30
|
-
isPrecise: false,
|
|
31
|
-
snap: 'center',
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const result = down(newRecord)
|
|
36
|
-
expect(result.props.snap).toBeUndefined()
|
|
37
|
-
expect(result.props.terminal).toBe('end')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should be reversible', () => {
|
|
41
|
-
const originalRecord = {
|
|
42
|
-
props: {
|
|
43
|
-
terminal: 'start',
|
|
44
|
-
normalizedAnchor: { x: 0.5, y: 0.5 },
|
|
45
|
-
isExact: true,
|
|
46
|
-
isPrecise: false,
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const upResult = up(originalRecord)
|
|
51
|
-
const downResult = down(upResult)
|
|
52
|
-
expect(downResult.props).toEqual(originalRecord.props)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { RecordId, UnknownRecord } from '@tldraw/store'
|
|
2
|
-
import { describe, expect, it } from 'vitest'
|
|
3
|
-
import { idValidator } from './id-validator'
|
|
4
|
-
|
|
5
|
-
// Mock record types for testing
|
|
6
|
-
interface MockShapeRecord extends UnknownRecord {
|
|
7
|
-
typeName: 'shape'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface MockPageRecord extends UnknownRecord {
|
|
11
|
-
typeName: 'page'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type MockShapeId = RecordId<MockShapeRecord>
|
|
15
|
-
type MockPageId = RecordId<MockPageRecord>
|
|
16
|
-
|
|
17
|
-
describe('idValidator', () => {
|
|
18
|
-
it('should validate correct IDs with proper prefix', () => {
|
|
19
|
-
const shapeValidator = idValidator<MockShapeId>('shape')
|
|
20
|
-
const pageValidator = idValidator<MockPageId>('page')
|
|
21
|
-
|
|
22
|
-
expect(shapeValidator.validate('shape:abc123')).toBe('shape:abc123')
|
|
23
|
-
expect(shapeValidator.validate('shape:')).toBe('shape:')
|
|
24
|
-
expect(pageValidator.validate('page:main')).toBe('page:main')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should reject IDs with wrong prefix', () => {
|
|
28
|
-
const shapeValidator = idValidator<MockShapeId>('shape')
|
|
29
|
-
|
|
30
|
-
expect(() => shapeValidator.validate('page:abc123')).toThrow(
|
|
31
|
-
'shape ID must start with "shape:"'
|
|
32
|
-
)
|
|
33
|
-
expect(() => shapeValidator.validate('asset:xyz789')).toThrow(
|
|
34
|
-
'shape ID must start with "shape:"'
|
|
35
|
-
)
|
|
36
|
-
expect(() => shapeValidator.validate('abc123')).toThrow('shape ID must start with "shape:"')
|
|
37
|
-
expect(() => shapeValidator.validate('')).toThrow('shape ID must start with "shape:"')
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should work with different prefixes independently', () => {
|
|
41
|
-
const shapeValidator = idValidator<MockShapeId>('shape')
|
|
42
|
-
const pageValidator = idValidator<MockPageId>('page')
|
|
43
|
-
|
|
44
|
-
expect(shapeValidator.isValid('shape:abc123')).toBe(true)
|
|
45
|
-
expect(shapeValidator.isValid('page:abc123')).toBe(false)
|
|
46
|
-
|
|
47
|
-
expect(pageValidator.isValid('shape:abc123')).toBe(false)
|
|
48
|
-
expect(pageValidator.isValid('page:abc123')).toBe(true)
|
|
49
|
-
})
|
|
50
|
-
})
|