2023-04-25 11:01:25 +00:00
|
|
|
import { defineMigrations } from '@tldraw/tlstore'
|
|
|
|
import { T } from '@tldraw/tlvalidate'
|
|
|
|
import {
|
|
|
|
TLAlignType,
|
|
|
|
TLColorType,
|
|
|
|
TLDashType,
|
|
|
|
TLFillType,
|
|
|
|
TLFontType,
|
|
|
|
TLGeoType,
|
|
|
|
TLOpacityType,
|
|
|
|
TLSizeType,
|
2023-05-19 10:23:43 +00:00
|
|
|
TLVerticalAlignType,
|
2023-04-25 11:01:25 +00:00
|
|
|
} from '../style-types'
|
|
|
|
import {
|
|
|
|
alignValidator,
|
|
|
|
colorValidator,
|
|
|
|
dashValidator,
|
|
|
|
fillValidator,
|
|
|
|
fontValidator,
|
|
|
|
geoValidator,
|
|
|
|
opacityValidator,
|
|
|
|
sizeValidator,
|
2023-05-19 10:23:43 +00:00
|
|
|
verticalAlignValidator,
|
2023-04-25 11:01:25 +00:00
|
|
|
} from '../validation'
|
|
|
|
import { TLBaseShape, createShapeValidator } from './shape-validation'
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLGeoShapeProps = {
|
|
|
|
geo: TLGeoType
|
|
|
|
labelColor: TLColorType
|
|
|
|
color: TLColorType
|
|
|
|
fill: TLFillType
|
|
|
|
dash: TLDashType
|
|
|
|
size: TLSizeType
|
|
|
|
opacity: TLOpacityType
|
|
|
|
font: TLFontType
|
|
|
|
align: TLAlignType
|
2023-05-19 10:23:43 +00:00
|
|
|
verticalAlign: TLVerticalAlignType
|
2023-04-25 11:01:25 +00:00
|
|
|
url: string
|
|
|
|
w: number
|
|
|
|
h: number
|
|
|
|
text: string
|
|
|
|
growY: number
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export type TLGeoShape = TLBaseShape<'geo', TLGeoShapeProps>
|
|
|
|
|
|
|
|
/** @public */
|
|
|
|
export const geoShapeTypeValidator: T.Validator<TLGeoShape> = createShapeValidator(
|
|
|
|
'geo',
|
|
|
|
T.object({
|
|
|
|
geo: geoValidator,
|
|
|
|
labelColor: colorValidator,
|
|
|
|
color: colorValidator,
|
|
|
|
fill: fillValidator,
|
|
|
|
dash: dashValidator,
|
|
|
|
size: sizeValidator,
|
|
|
|
opacity: opacityValidator,
|
|
|
|
font: fontValidator,
|
|
|
|
align: alignValidator,
|
2023-05-19 10:23:43 +00:00
|
|
|
verticalAlign: verticalAlignValidator,
|
2023-04-25 11:01:25 +00:00
|
|
|
url: T.string,
|
|
|
|
w: T.nonZeroNumber,
|
|
|
|
h: T.nonZeroNumber,
|
|
|
|
growY: T.positiveNumber,
|
|
|
|
text: T.string,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
const Versions = {
|
|
|
|
AddUrlProp: 1,
|
|
|
|
AddLabelColor: 2,
|
|
|
|
RemoveJustify: 3,
|
2023-05-09 13:32:04 +00:00
|
|
|
AddCheckBox: 4,
|
2023-05-19 10:23:43 +00:00
|
|
|
AddVerticalAlign: 5,
|
2023-04-25 11:01:25 +00:00
|
|
|
} as const
|
|
|
|
|
|
|
|
/** @public */
|
2023-05-22 21:46:24 +00:00
|
|
|
export const geoShapeTypeMigrations = defineMigrations({
|
2023-05-19 10:23:43 +00:00
|
|
|
currentVersion: Versions.AddVerticalAlign,
|
2023-04-25 11:01:25 +00:00
|
|
|
migrators: {
|
|
|
|
[Versions.AddUrlProp]: {
|
|
|
|
up: (shape) => {
|
|
|
|
return { ...shape, props: { ...shape.props, url: '' } }
|
|
|
|
},
|
|
|
|
down: (shape) => {
|
|
|
|
const { url: _, ...props } = shape.props
|
|
|
|
return { ...shape, props }
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[Versions.AddLabelColor]: {
|
|
|
|
up: (record) => {
|
|
|
|
return {
|
|
|
|
...record,
|
|
|
|
props: {
|
|
|
|
...record.props,
|
|
|
|
labelColor: 'black',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
down: (record) => {
|
|
|
|
const { labelColor: _, ...props } = record.props
|
|
|
|
return {
|
|
|
|
...record,
|
|
|
|
props,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[Versions.RemoveJustify]: {
|
|
|
|
up: (shape) => {
|
|
|
|
let newAlign = shape.props.align
|
|
|
|
if (newAlign === 'justify') {
|
|
|
|
newAlign = 'start'
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...shape,
|
|
|
|
props: {
|
|
|
|
...shape.props,
|
|
|
|
align: newAlign,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
down: (shape) => {
|
|
|
|
return { ...shape }
|
|
|
|
},
|
|
|
|
},
|
2023-05-09 13:32:04 +00:00
|
|
|
[Versions.AddCheckBox]: {
|
|
|
|
up: (shape) => {
|
|
|
|
return { ...shape }
|
|
|
|
},
|
|
|
|
down: (shape) => {
|
|
|
|
return {
|
|
|
|
...shape,
|
|
|
|
props: {
|
|
|
|
...shape.props,
|
|
|
|
geo: shape.props.geo === 'check-box' ? 'rectangle' : shape.props.geo,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2023-05-19 10:23:43 +00:00
|
|
|
[Versions.AddVerticalAlign]: {
|
|
|
|
up: (shape) => {
|
|
|
|
return {
|
|
|
|
...shape,
|
|
|
|
props: {
|
|
|
|
...shape.props,
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
down: (shape) => {
|
|
|
|
const { verticalAlign: _, ...props } = shape.props
|
|
|
|
return {
|
|
|
|
...shape,
|
|
|
|
props,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2023-04-25 11:01:25 +00:00
|
|
|
},
|
|
|
|
})
|