Improve editor history, CAD tools, and ruler workflows

This commit is contained in:
Formsmith
2026-07-14 09:43:37 +03:00
parent 20731043e4
commit 400c4bf86e
23 changed files with 1727 additions and 388 deletions
@@ -106,8 +106,6 @@ function getShapeProperties(shape: WorkplaneShape, onUpdate: ShapeInspectorUpdat
if (shape.kind === "cylinder") {
return [
{ label: "Sides", value: shape.sides ?? 96, min: 3, max: 128, step: 1, onChange: (sides) => onUpdate({ sides: Math.round(sides) }) },
{ label: "Bevel", value: shape.bevel ?? 0, min: 0, max: 10, onChange: (bevel) => onUpdate({ bevel }) },
{ label: "Segments", value: shape.segments ?? 1, min: 1, max: 24, step: 1, onChange: (segments) => onUpdate({ segments: Math.round(segments) }) },
{ label: "Length", value: depth, min: MIN_SHAPE_SIZE, max: 160, onChange: setDepth },
{ label: "Width", value: width, min: MIN_SHAPE_SIZE, max: 160, onChange: setWidth },
{ label: "Height", value: shape.height, min: MIN_SHAPE_SIZE, max: 160, onChange: setHeight },
@@ -208,6 +206,7 @@ export function ShapeInspector({
onEditSketch,
canSeparateParts = false,
onSeparateParts,
onInteractionActiveChange,
}: {
shape: WorkplaneShape;
snap: GridSize;
@@ -220,6 +219,7 @@ export function ShapeInspector({
onEditSketch?: () => void;
canSeparateParts?: boolean;
onSeparateParts?: () => void;
onInteractionActiveChange?: (active: boolean) => void;
}) {
const solidColor = shape.hole ? fallbackSolidColor(shape) : shape.color;
const locked = Boolean(shape.locked);
@@ -227,6 +227,8 @@ export function ShapeInspector({
const [propertiesOpen, setPropertiesOpen] = useState(true);
const [colorOpen, setColorOpen] = useState(false);
useEffect(() => () => onInteractionActiveChange?.(false), [onInteractionActiveChange]);
return (
<aside className="shape-inspector" aria-label={`${shape.name} shape settings`} onPointerDown={(event) => event.stopPropagation()}>
<div className="shape-inspector-header">
@@ -300,6 +302,8 @@ export function ShapeInspector({
type="color"
value={solidColor}
disabled={locked}
onFocus={() => onInteractionActiveChange?.(true)}
onBlur={() => onInteractionActiveChange?.(false)}
onChange={(event) => {
onUpdate({ color: event.target.value, hole: false });
setColorOpen(false);
@@ -339,12 +343,12 @@ export function ShapeInspector({
<div className="property-list" id={`properties-${shape.id}`}>
{properties.map((property) => {
if (property.type === "text") {
return <TextProperty key={property.label} {...property} disabled={locked} />;
return <TextProperty key={property.label} {...property} disabled={locked} onInteractionActiveChange={onInteractionActiveChange} />;
}
if (property.type === "select") {
return <SelectProperty key={property.label} {...property} disabled={locked} />;
}
return <RangeProperty key={property.label} {...property} workspace={workspace} disabled={locked} />;
return <RangeProperty key={property.label} {...property} workspace={workspace} disabled={locked} onInteractionActiveChange={onInteractionActiveChange} />;
})}
</div>
) : null}
@@ -403,7 +407,8 @@ function RangeProperty({
workspace,
disabled,
onChange,
}: RangePropertyConfig & { workspace: WorkplaneWorkspaceSettings; disabled?: boolean }) {
onInteractionActiveChange,
}: RangePropertyConfig & { workspace: WorkplaneWorkspaceSettings; disabled?: boolean; onInteractionActiveChange?: (active: boolean) => void }) {
const allowsAboveSliderMax = label === "Length" || label === "Width" || label === "Height";
const isLength = propertyUsesLengthUnit(label);
const accuracy = workspace.accuracy;
@@ -429,6 +434,7 @@ function RangeProperty({
const nextModelValue = toModelValue(finiteNext);
onChange(allowsAboveSliderMax ? Math.max(min, nextModelValue) : clamp(nextModelValue, min, max));
setEditing(false);
onInteractionActiveChange?.(false);
};
const handleSliderChange = (nextValue: number) => {
const next = clamp(Number.isFinite(nextValue) ? nextValue : controlMin, controlMin, controlMax);
@@ -449,6 +455,7 @@ function RangeProperty({
disabled={disabled}
inputMode="decimal"
onFocus={() => {
onInteractionActiveChange?.(true);
setDraft(formatPropertyNumber(controlValue, accuracy, controlStep));
setEditing(true);
}}
@@ -474,6 +481,11 @@ function RangeProperty({
step={controlStep}
value={sliderValue}
disabled={disabled}
onFocus={() => onInteractionActiveChange?.(true)}
onBlur={() => onInteractionActiveChange?.(false)}
onPointerDown={() => onInteractionActiveChange?.(true)}
onPointerUp={() => onInteractionActiveChange?.(false)}
onPointerCancel={() => onInteractionActiveChange?.(false)}
onChange={(event) => handleSliderChange(Number(event.currentTarget.value))}
/>
</div>
@@ -481,7 +493,7 @@ function RangeProperty({
);
}
function TextProperty({ label, value, disabled, onChange }: TextPropertyConfig & { disabled?: boolean }) {
function TextProperty({ label, value, disabled, onChange, onInteractionActiveChange }: TextPropertyConfig & { disabled?: boolean; onInteractionActiveChange?: (active: boolean) => void }) {
return (
<label className="text-property">
<span>{label}</span>
@@ -491,6 +503,8 @@ function TextProperty({ label, value, disabled, onChange }: TextPropertyConfig &
disabled={disabled}
maxLength={24}
spellCheck={false}
onFocus={() => onInteractionActiveChange?.(true)}
onBlur={() => onInteractionActiveChange?.(false)}
onChange={(event) => onChange(event.currentTarget.value)}
/>
</label>