@tldraw/tlschema
Version:
A tiny little drawing app (schema).
64 lines (63 loc) • 1.78 kB
JavaScript
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
});
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
// },
}
]
});
export {
textShapeMigrations,
textShapeProps,
Versions as textShapeVersions
};
//# sourceMappingURL=TLTextShape.mjs.map