Tldraw/packages/tlschema/src/shapes/TLBookmarkShape.ts

51 wiersze
1.2 KiB
TypeScript
Czysty Zwykły widok Historia

import { defineMigrations } from '@tldraw/store'
import { T } from '@tldraw/validate'
import { assetIdValidator } from '../assets/TLBaseAsset'
2023-04-25 11:01:25 +00:00
import { TLAssetId } from '../records/TLAsset'
import { ShapeProps, TLBaseShape } from './TLBaseShape'
2023-04-25 11:01:25 +00:00
/** @public */
export type TLBookmarkShapeProps = {
w: number
h: number
assetId: TLAssetId | null
url: string
}
/** @public */
export type TLBookmarkShape = TLBaseShape<'bookmark', TLBookmarkShapeProps>
/** @internal */
export const bookmarkShapeProps: ShapeProps<TLBookmarkShape> = {
w: T.nonZeroNumber,
h: T.nonZeroNumber,
assetId: assetIdValidator.nullable(),
url: T.string,
}
2023-04-25 11:01:25 +00:00
const Versions = {
NullAssetId: 1,
} as const
/** @internal */
export const bookmarkShapeMigrations = defineMigrations({
2023-04-25 11:01:25 +00:00
currentVersion: Versions.NullAssetId,
migrators: {
[Versions.NullAssetId]: {
up: (shape: TLBookmarkShape) => {
if (shape.props.assetId === undefined) {
return { ...shape, props: { ...shape.props, assetId: null } } as typeof shape
}
return shape
},
down: (shape: TLBookmarkShape) => {
if (shape.props.assetId === null) {
const { assetId: _, ...props } = shape.props
return { ...shape, props } as typeof shape
}
return shape
},
},
},
})