feat: add size presets for tools

This commit is contained in:
2026-10-04 21:59:18 +05:00
parent 4d9cd2cfcb
commit 91150a14bf
9 changed files with 85 additions and 18 deletions
@@ -30,7 +30,7 @@
spec: FieldSpec;
toolId: string;
fieldId: string;
onchange?: (value: unknown, axis?: "width" | "height") => void;
onchange?: (value: unknown, axis?: "width" | "height" | "both") => void;
}
const FIELDS: Record<FieldSpecKind, Component<FieldControlProps>> = {
@@ -54,7 +54,11 @@
schema: ToolSchema<Record<string, unknown>>;
values: Record<string, unknown>;
toolId: string;
onchange: (id: string, value: unknown, axis?: "width" | "height") => void;
onchange: (
id: string,
value: unknown,
axis?: "width" | "height" | "both",
) => void;
onreset: () => void;
}
let { schema, values, toolId, onchange, onreset }: Props = $props();
@@ -74,9 +74,13 @@
values = defaultSchemaParams(schema);
}
function setValue(id: string, value: unknown, axis?: "width" | "height") {
function setValue(
id: string,
value: unknown,
axis?: "width" | "height" | "both",
) {
touched.add(id);
if (axis) lastAxis[id] = axis;
if (axis) lastAxis[id] = axis === "both" ? "width" : axis;
const next: Record<string, unknown> = { ...values, [id]: value };
const spec = schema?.fields[id]?.spec;
if (source && schema && spec) {
@@ -84,6 +88,7 @@
if (
spec.kind === "dimension" &&
spec.lockAspectWith &&
axis !== "both" &&
next[spec.lockAspectWith] === true
) {
next[id] = withAspectLock(