tldraw/packages/tlschema/src/shapes/TLVideoShape.ts
Steve Ruiz 4b6383ed90
tlschema cleanup (#1509)
This PR cleans up the file names and imports for @tldraw/tlschema.

It also:
- renames some erroneously named validators / migrators (e.g.
`pageTypeValidator` -> `pageValidator`)
- removes the duplicated `languages.ts` and makes `tlschema` the source
of truth for languages
- renames ID to RecordId

### Change Type

- [x] `major` — Breaking Change

### Release Notes

- [editor] Remove `app.createShapeId`
- [tlschema] Cleans up exports
2023-06-03 20:46:53 +00:00

54 lines
1.3 KiB
TypeScript

import { defineMigrations } from '@tldraw/store'
import { T } from '@tldraw/validate'
import { assetIdValidator } from '../assets/TLBaseAsset'
import { TLAssetId } from '../records/TLAsset'
import { TLOpacityType, opacityValidator } from '../styles/TLOpacityStyle'
import { TLBaseShape, createShapeValidator } from './TLBaseShape'
/** @public */
export type TLVideoShapeProps = {
opacity: TLOpacityType
w: number
h: number
time: number
playing: boolean
url: string
assetId: TLAssetId | null
}
/** @public */
export type TLVideoShape = TLBaseShape<'video', TLVideoShapeProps>
/** @internal */
export const videoShapeValidator: T.Validator<TLVideoShape> = createShapeValidator(
'video',
T.object({
opacity: opacityValidator,
w: T.nonZeroNumber,
h: T.nonZeroNumber,
time: T.number,
playing: T.boolean,
url: T.string,
assetId: assetIdValidator.nullable(),
})
)
const Versions = {
AddUrlProp: 1,
} as const
/** @internal */
export const videoShapeMigrations = defineMigrations({
currentVersion: Versions.AddUrlProp,
migrators: {
[Versions.AddUrlProp]: {
up: (shape) => {
return { ...shape, props: { ...shape.props, url: '' } }
},
down: (shape) => {
const { url: _, ...props } = shape.props
return { ...shape, props }
},
},
},
})