@tldraw/tlschema
Version:
A tiny little drawing app (schema).
138 lines (137 loc) • 3.31 kB
JavaScript
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,
align: DefaultHorizontalAlignStyle,
verticalAlign: DefaultVerticalAlignStyle,
growY: T.positiveNumber,
url: T.linkUrl,
richText: richTextValidator,
scale: T.nonZeroNumber
};
const Versions = createShapePropsMigrationIds("note", {
AddUrlProp: 1,
RemoveJustify: 2,
MigrateLegacyAlign: 3,
AddVerticalAlign: 4,
MakeUrlsValid: 5,
AddFontSizeAdjustment: 6,
AddScale: 7,
AddLabelColor: 8,
AddRichText: 9
});
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
// },
}
]
});
export {
noteShapeMigrations,
noteShapeProps,
Versions as noteShapeVersions
};
//# sourceMappingURL=TLNoteShape.mjs.map