UNPKG

@tldraw/tlschema

Version:

tldraw infinite canvas SDK (schema).

170 lines (169 loc) 4.1 kB
import { T } from "@tldraw/validate"; import { richTextValidator, toRichText } from "../misc/TLRichText.mjs"; import { createShapePropsMigrationIds, createShapePropsMigrationSequence } from "../records/TLShape.mjs"; import { DefaultColorStyle, DefaultLabelColorStyle } from "../styles/TLColorStyle.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 noteShapeProps = { color: DefaultColorStyle, labelColor: DefaultLabelColorStyle, size: DefaultSizeStyle, font: DefaultFontStyle, fontSizeAdjustment: T.positiveNumber.nullable(), align: DefaultHorizontalAlignStyle, verticalAlign: DefaultVerticalAlignStyle, growY: T.positiveNumber, url: T.linkUrl, richText: richTextValidator, scale: T.nonZeroNumber, textFirstEditedBy: T.string.nullable() }; const Versions = createShapePropsMigrationIds("note", { AddUrlProp: 1, RemoveJustify: 2, MigrateLegacyAlign: 3, AddVerticalAlign: 4, MakeUrlsValid: 5, AddFontSizeAdjustment: 6, AddScale: 7, AddLabelColor: 8, AddRichText: 9, AddRichTextAttrs: 10, AddFirstEditedBy: 11, MakeFontSizeAdjustmentRatio: 12 }); const noteShapeMigrations = createShapePropsMigrationSequence({ sequence: [ { id: Versions.AddUrlProp, up: (props) => { props.url = ""; }, down: "retired" }, { id: Versions.RemoveJustify, up: (props) => { if (props.align === "justify") { props.align = "start"; } }, down: "retired" }, { id: Versions.MigrateLegacyAlign, up: (props) => { switch (props.align) { case "start": props.align = "start-legacy"; return; case "end": props.align = "end-legacy"; return; default: props.align = "middle-legacy"; return; } }, down: "retired" }, { id: Versions.AddVerticalAlign, up: (props) => { props.verticalAlign = "middle"; }, down: "retired" }, { id: Versions.MakeUrlsValid, up: (props) => { if (!T.linkUrl.isValid(props.url)) { props.url = ""; } }, down: (_props) => { } }, { id: Versions.AddFontSizeAdjustment, up: (props) => { props.fontSizeAdjustment = 0; }, down: (props) => { delete props.fontSizeAdjustment; } }, { id: Versions.AddScale, up: (props) => { props.scale = 1; }, down: (props) => { delete props.scale; } }, { id: Versions.AddLabelColor, up: (props) => { props.labelColor = "black"; }, down: (props) => { delete props.labelColor; } }, { 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; } } }, { id: Versions.AddFirstEditedBy, up: (props) => { props.textFirstEditedBy = null; }, down: (props) => { delete props.textFirstEditedBy; } }, { id: Versions.MakeFontSizeAdjustmentRatio, up: (props) => { props.fontSizeAdjustment = props.fontSizeAdjustment === 0 ? 1 : null; }, down: (props) => { props.fontSizeAdjustment = 0; } } ] }); export { noteShapeMigrations, noteShapeProps, Versions as noteShapeVersions }; //# sourceMappingURL=TLNoteShape.mjs.map