2023-06-03 08:59:04 +00:00
|
|
|
import { defineMigrations } from '@tldraw/store'
|
2023-06-03 08:27:44 +00:00
|
|
|
import { T } from '@tldraw/validate'
|
2023-06-03 20:46:53 +00:00
|
|
|
import { assetIdValidator } from '../assets/TLBaseAsset'
|
2023-04-25 11:01:25 +00:00
|
|
|
import { TLAssetId } from '../records/TLAsset'
|
2023-06-12 14:04:14 +00:00
|
|
|
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>
|
|
|
|
|
2023-06-03 20:46:53 +00:00
|
|
|
/** @internal */
|
2023-06-12 14:04:14 +00:00
|
|
|
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
|
|
|
|
|
2023-06-03 20:46:53 +00:00
|
|
|
/** @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
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|