UNPKG

@tldraw/tlschema

Version:

tldraw infinite canvas SDK (schema).

75 lines (74 loc) 2.03 kB
import { T } from "@tldraw/validate"; import { richTextValidator, toRichText } from "../misc/TLRichText.mjs"; import { createShapePropsMigrationIds, createShapePropsMigrationSequence } from "../records/TLShape.mjs"; import { DefaultColorStyle } from "../styles/TLColorStyle.mjs"; import { DefaultFontStyle } from "../styles/TLFontStyle.mjs"; import { DefaultSizeStyle } from "../styles/TLSizeStyle.mjs"; import { DefaultTextAlignStyle } from "../styles/TLTextAlignStyle.mjs"; const textShapeProps = { color: DefaultColorStyle, size: DefaultSizeStyle, font: DefaultFontStyle, textAlign: DefaultTextAlignStyle, w: T.nonZeroNumber, richText: richTextValidator, scale: T.nonZeroNumber, autoSize: T.boolean }; const Versions = createShapePropsMigrationIds("text", { RemoveJustify: 1, AddTextAlign: 2, AddRichText: 3, AddRichTextAttrs: 4 }); const textShapeMigrations = createShapePropsMigrationSequence({ sequence: [ { id: Versions.RemoveJustify, up: (props) => { if (props.align === "justify") { props.align = "start"; } }, down: "retired" }, { id: Versions.AddTextAlign, up: (props) => { props.textAlign = props.align; delete props.align; }, down: (props) => { props.align = props.textAlign; delete props.textAlign; } }, { id: Versions.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 // }, }, { id: Versions.AddRichTextAttrs, up: (_props) => { }, down: (props) => { if (props.richText && "attrs" in props.richText) { delete props.richText.attrs; } } } ] }); export { textShapeMigrations, textShapeProps, Versions as textShapeVersions }; //# sourceMappingURL=TLTextShape.mjs.map