UNPKG

@tldraw/tlschema

Version:

A tiny little drawing app (schema).

175 lines (174 loc) 4.07 kB
import { T } from "@tldraw/validate"; import { richTextValidator, toRichText } from "../misc/TLRichText.mjs"; import { createShapePropsMigrationIds, createShapePropsMigrationSequence } from "../records/TLShape.mjs"; import { StyleProp } from "../styles/StyleProp.mjs"; import { DefaultColorStyle, DefaultLabelColorStyle } from "../styles/TLColorStyle.mjs"; import { DefaultDashStyle } from "../styles/TLDashStyle.mjs"; import { DefaultFillStyle } from "../styles/TLFillStyle.mjs"; import { DefaultFontStyle } from "../styles/TLFontStyle.mjs"; import { DefaultHorizontalAlignStyle } from "../styles/TLHorizontalAlignStyle.mjs"; import { DefaultSizeStyle } from "../styles/TLSizeStyle.mjs"; import { DefaultVerticalAlignStyle } from "../styles/TLVerticalAlignStyle.mjs"; const GeoShapeGeoStyle = StyleProp.defineEnum("tldraw:geo", { defaultValue: "rectangle", values: [ "cloud", "rectangle", "ellipse", "triangle", "diamond", "pentagon", "hexagon", "octagon", "star", "rhombus", "rhombus-2", "oval", "trapezoid", "arrow-right", "arrow-left", "arrow-up", "arrow-down", "x-box", "check-box", "heart" ] }); const geoShapeProps = { geo: GeoShapeGeoStyle, labelColor: DefaultLabelColorStyle, color: DefaultColorStyle, fill: DefaultFillStyle, dash: DefaultDashStyle, size: DefaultSizeStyle, font: DefaultFontStyle, align: DefaultHorizontalAlignStyle, verticalAlign: DefaultVerticalAlignStyle, url: T.linkUrl, w: T.nonZeroNumber, h: T.nonZeroNumber, growY: T.positiveNumber, richText: richTextValidator, scale: T.nonZeroNumber }; const geoShapeVersions = createShapePropsMigrationIds("geo", { AddUrlProp: 1, AddLabelColor: 2, RemoveJustify: 3, AddCheckBox: 4, AddVerticalAlign: 5, MigrateLegacyAlign: 6, AddCloud: 7, MakeUrlsValid: 8, AddScale: 9, AddRichText: 10 }); const geoShapeMigrations = createShapePropsMigrationSequence({ sequence: [ { id: geoShapeVersions.AddUrlProp, up: (props) => { props.url = ""; }, down: "retired" }, { id: geoShapeVersions.AddLabelColor, up: (props) => { props.labelColor = "black"; }, down: "retired" }, { id: geoShapeVersions.RemoveJustify, up: (props) => { if (props.align === "justify") { props.align = "start"; } }, down: "retired" }, { id: geoShapeVersions.AddCheckBox, up: (_props) => { }, down: "retired" }, { id: geoShapeVersions.AddVerticalAlign, up: (props) => { props.verticalAlign = "middle"; }, down: "retired" }, { id: geoShapeVersions.MigrateLegacyAlign, up: (props) => { let newAlign; switch (props.align) { case "start": newAlign = "start-legacy"; break; case "end": newAlign = "end-legacy"; break; default: newAlign = "middle-legacy"; break; } props.align = newAlign; }, down: "retired" }, { id: geoShapeVersions.AddCloud, up: (_props) => { }, down: "retired" }, { id: geoShapeVersions.MakeUrlsValid, up: (props) => { if (!T.linkUrl.isValid(props.url)) { props.url = ""; } }, down: (_props) => { } }, { id: geoShapeVersions.AddScale, up: (props) => { props.scale = 1; }, down: (props) => { delete props.scale; } }, { id: geoShapeVersions.AddRichText, up: (props) => { props.richText = toRichText(props.text); delete props.text; } // N.B. Explicitly no down state so that we force clients to update. // down: (props) => { // delete props.richText // }, } ] }); export { GeoShapeGeoStyle, geoShapeMigrations, geoShapeProps, geoShapeVersions }; //# sourceMappingURL=TLGeoShape.mjs.map