Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
Add workspace editor tools
This commit is contained in:
@@ -0,0 +1,463 @@
|
||||
"use client";
|
||||
|
||||
import { ChevronDown, ChevronUp, LockKeyhole, LockKeyholeOpen } from "lucide-react";
|
||||
import { useState, type CSSProperties, type Dispatch, type SetStateAction } from "react";
|
||||
import { ToolbarHideSelectedIcon } from "@/components/icons";
|
||||
import { fallbackSolidColor, resizedShapeSize, shapeDepth, shapeWidth } from "@/lib/workplaneShapes";
|
||||
import type { GridSize, WorkplaneShape } from "@/types/sketchforge";
|
||||
|
||||
const GRID_SIZES: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"];
|
||||
const MIN_SHAPE_SIZE = 0.01;
|
||||
const SOLID_COLORS = [
|
||||
"#d41721",
|
||||
"#ff4b4b",
|
||||
"#ff7a1a",
|
||||
"#d97813",
|
||||
"#f6a21a",
|
||||
"#f2cf10",
|
||||
"#f7e65a",
|
||||
"#a8d642",
|
||||
"#33983d",
|
||||
"#1fb66d",
|
||||
"#18b99a",
|
||||
"#0098c7",
|
||||
"#49c7ef",
|
||||
"#3b82f6",
|
||||
"#294c93",
|
||||
"#5b5ce2",
|
||||
"#6e2786",
|
||||
"#9b3bd2",
|
||||
"#c9009a",
|
||||
"#f062b6",
|
||||
"#8a5a2b",
|
||||
"#b98254",
|
||||
"#f2caa0",
|
||||
"#ffffff",
|
||||
"#cfd8df",
|
||||
"#8a98a6",
|
||||
"#4b5563",
|
||||
"#111111",
|
||||
];
|
||||
const TEXT_FONT_OPTIONS = ["Multilanguage", "Sans", "Serif", "Script", "Monospace", "Rounded", "Stencil"];
|
||||
|
||||
type RangePropertyConfig = {
|
||||
type?: "range";
|
||||
label: string;
|
||||
value: number;
|
||||
min: number;
|
||||
max: number;
|
||||
step?: number;
|
||||
onChange: (value: number) => void;
|
||||
};
|
||||
|
||||
type TextPropertyConfig = {
|
||||
type: "text";
|
||||
label: string;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
};
|
||||
|
||||
type SelectPropertyConfig = {
|
||||
type: "select";
|
||||
label: string;
|
||||
value: string;
|
||||
options: string[];
|
||||
onChange: (value: string) => void;
|
||||
};
|
||||
|
||||
type ShapePropertyConfig = RangePropertyConfig | TextPropertyConfig | SelectPropertyConfig;
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function formatPanelNumber(value: number) {
|
||||
return (Math.abs(value) < 0.005 ? 0 : value).toFixed(2);
|
||||
}
|
||||
|
||||
function getShapeProperties(shape: WorkplaneShape, onUpdate: (patch: Partial<WorkplaneShape>) => void): ShapePropertyConfig[] {
|
||||
const width = shapeWidth(shape);
|
||||
const depth = shapeDepth(shape);
|
||||
const setWidth = (value: number) => onUpdate({ width: value, size: resizedShapeSize(value, depth) });
|
||||
const setDepth = (value: number) => onUpdate({ depth: value, size: resizedShapeSize(width, value) });
|
||||
const setConeWidth = (value: number) => onUpdate({ width: value, baseRadius: value / 2, size: resizedShapeSize(value, depth) });
|
||||
const setBaseRadius = (value: number) => {
|
||||
const diameter = value * 2;
|
||||
onUpdate({ baseRadius: value, width: diameter, size: resizedShapeSize(diameter, depth) });
|
||||
};
|
||||
|
||||
if (shape.kind === "box") {
|
||||
return [
|
||||
{ label: "Radius", value: shape.radius ?? 0, min: 0, max: 10, onChange: (radius) => onUpdate({ radius }) },
|
||||
{ label: "Steps", value: shape.steps ?? 10, min: 1, max: 64, step: 1, onChange: (steps) => onUpdate({ steps: Math.round(steps) }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "sphere") {
|
||||
return [
|
||||
{ label: "Steps", value: shape.steps ?? 24, min: 6, max: 64, step: 1, onChange: (steps) => onUpdate({ steps: Math.round(steps) }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "halfSphere") {
|
||||
return [
|
||||
{ label: "Steps", value: shape.steps ?? 32, min: 6, max: 64, step: 1, onChange: (steps) => onUpdate({ steps: Math.round(steps) }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "cone") {
|
||||
return [
|
||||
{ label: "Top Radius", value: shape.topRadius ?? 0, min: 0, max: 40, onChange: (topRadius) => onUpdate({ topRadius }) },
|
||||
{ label: "Base Radius", value: shape.baseRadius ?? width / 2, min: MIN_SHAPE_SIZE, max: 80, onChange: setBaseRadius },
|
||||
{ label: "Length", value: depth, min: MIN_SHAPE_SIZE, max: 160, onChange: setDepth },
|
||||
{ label: "Width", value: width, min: MIN_SHAPE_SIZE, max: 160, onChange: setConeWidth },
|
||||
{ label: "Height", value: shape.height, min: MIN_SHAPE_SIZE, max: 160, onChange: (height) => onUpdate({ height }) },
|
||||
{ label: "Sides", value: shape.sides ?? 96, min: 3, max: 128, step: 1, onChange: (sides) => onUpdate({ sides: Math.round(sides) }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "pyramid") {
|
||||
return [
|
||||
{ label: "Sides", value: shape.sides ?? 4, min: 3, max: 24, step: 1, onChange: (sides) => onUpdate({ sides: Math.round(sides) }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "roundRoof") {
|
||||
return [
|
||||
{ label: "Sides", value: shape.sides ?? 64, min: 4, max: 128, step: 1, onChange: (sides) => onUpdate({ sides: Math.round(sides) }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "tube" || shape.kind === "ring") {
|
||||
return [
|
||||
{ label: "Thickness", value: shape.bevel ?? 4, min: 0.5, max: 20, onChange: (bevel) => onUpdate({ bevel }) },
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
if (shape.kind === "text") {
|
||||
return [
|
||||
{
|
||||
type: "text",
|
||||
label: "Text",
|
||||
value: shape.text ?? "TEXT",
|
||||
onChange: (text) => {
|
||||
const nextText = text.slice(0, 24) || " ";
|
||||
const nextWidth = clamp(Math.max(46, nextText.length * 19), 46, 260);
|
||||
onUpdate({ text: nextText, width: nextWidth, size: nextWidth });
|
||||
},
|
||||
},
|
||||
{ type: "select", label: "Font", value: shape.font ?? "Multilanguage", options: TEXT_FONT_OPTIONS, onChange: (font) => onUpdate({ font }) },
|
||||
{ label: "Height", value: shape.height, min: MIN_SHAPE_SIZE, max: 40, onChange: (height) => onUpdate({ height }) },
|
||||
{ label: "Bevel", value: shape.bevel ?? 0, min: 0, max: 8, onChange: (bevel) => onUpdate({ bevel }) },
|
||||
{ label: "Segments", value: shape.segments ?? 0, min: 0, max: 24, step: 1, onChange: (segments) => onUpdate({ segments: Math.round(segments) }) },
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
{ 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: (height) => onUpdate({ height }) },
|
||||
];
|
||||
}
|
||||
|
||||
export function ShapeInspector({
|
||||
shape,
|
||||
snap,
|
||||
snapOpen,
|
||||
onUpdate,
|
||||
onClose,
|
||||
onSnapChange,
|
||||
onSnapOpenChange,
|
||||
}: {
|
||||
shape: WorkplaneShape;
|
||||
snap: GridSize;
|
||||
snapOpen: boolean;
|
||||
onUpdate: (patch: Partial<WorkplaneShape>) => void;
|
||||
onClose: () => void;
|
||||
onSnapChange: Dispatch<SetStateAction<GridSize>>;
|
||||
onSnapOpenChange: Dispatch<SetStateAction<boolean>>;
|
||||
}) {
|
||||
const solidColor = shape.hole ? fallbackSolidColor(shape) : shape.color;
|
||||
const locked = Boolean(shape.locked);
|
||||
const properties = getShapeProperties(shape, onUpdate);
|
||||
const [propertiesOpen, setPropertiesOpen] = useState(true);
|
||||
const [colorOpen, setColorOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<aside className="shape-inspector" aria-label={`${shape.name} shape settings`} onPointerDown={(event) => event.stopPropagation()}>
|
||||
<div className="shape-inspector-header">
|
||||
<button className="inspector-header-icon" aria-label="Close shape settings" onClick={onClose}>
|
||||
<ChevronUp size={26} strokeWidth={2.8} />
|
||||
</button>
|
||||
<strong>{shape.name}</strong>
|
||||
<div className="inspector-header-actions">
|
||||
<button className={locked ? "inspector-header-icon active" : "inspector-header-icon"} aria-label={locked ? "Unlock shape" : "Lock shape"} onClick={() => onUpdate({ locked: !locked })}>
|
||||
{locked ? <LockKeyhole size={31} strokeWidth={2.4} /> : <LockKeyholeOpen size={31} strokeWidth={2.4} />}
|
||||
</button>
|
||||
<button className={shape.hidden ? "inspector-header-icon active" : "inspector-header-icon"} aria-label={shape.hidden ? "Show shape" : "Hide shape"} onClick={() => onUpdate({ hidden: !shape.hidden })}>
|
||||
<ToolbarHideSelectedIcon />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="shape-state-card" role="group" aria-label="Shape mode">
|
||||
<button
|
||||
className={!shape.hole ? "active solid-choice" : "solid-choice"}
|
||||
onClick={() => {
|
||||
const wasHole = Boolean(shape.hole);
|
||||
onUpdate({ hole: false, color: solidColor });
|
||||
setColorOpen((open) => (wasHole ? false : !open));
|
||||
}}
|
||||
disabled={locked}
|
||||
aria-pressed={!shape.hole}
|
||||
aria-expanded={colorOpen}
|
||||
>
|
||||
<span className="large-solid-swatch" style={{ "--swatch": solidColor } as CSSProperties} />
|
||||
<span>Solid</span>
|
||||
</button>
|
||||
<button
|
||||
className={shape.hole ? "active hole-choice" : "hole-choice"}
|
||||
onClick={() => {
|
||||
onUpdate({ hole: true, color: "#b8c2cc" });
|
||||
setColorOpen(false);
|
||||
}}
|
||||
disabled={locked}
|
||||
aria-pressed={shape.hole}
|
||||
>
|
||||
<span className="large-hole-swatch" />
|
||||
<span>Hole</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{colorOpen ? (
|
||||
<div className="color-card" aria-label="Shape color">
|
||||
<div className="color-card-header">
|
||||
<span>Color</span>
|
||||
<span className="color-value">{solidColor.toUpperCase()}</span>
|
||||
</div>
|
||||
<div className="color-grid">
|
||||
{SOLID_COLORS.map((color) => (
|
||||
<button
|
||||
key={color}
|
||||
className={solidColor.toLowerCase() === color.toLowerCase() && !shape.hole ? "selected" : ""}
|
||||
type="button"
|
||||
style={{ "--shape-swatch": color } as CSSProperties}
|
||||
title={color.toUpperCase()}
|
||||
aria-label={`Set color ${color}`}
|
||||
disabled={locked}
|
||||
onClick={() => {
|
||||
onUpdate({ color, hole: false });
|
||||
setColorOpen(false);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
<label className={locked ? "custom-color disabled" : "custom-color"} title="Custom color">
|
||||
<input
|
||||
type="color"
|
||||
value={solidColor}
|
||||
disabled={locked}
|
||||
onChange={(event) => {
|
||||
onUpdate({ color: event.target.value, hole: false });
|
||||
setColorOpen(false);
|
||||
}}
|
||||
/>
|
||||
<span>Custom</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="property-card">
|
||||
<button
|
||||
className="property-card-header"
|
||||
type="button"
|
||||
aria-expanded={propertiesOpen}
|
||||
aria-controls={`properties-${shape.id}`}
|
||||
onClick={() => setPropertiesOpen((open) => !open)}
|
||||
>
|
||||
<span>Properties</span>
|
||||
<ChevronUp className={propertiesOpen ? "" : "collapsed"} size={25} strokeWidth={2.8} />
|
||||
</button>
|
||||
{propertiesOpen ? (
|
||||
<div className="property-list" id={`properties-${shape.id}`}>
|
||||
{properties.map((property) => {
|
||||
if (property.type === "text") {
|
||||
return <TextProperty key={property.label} {...property} disabled={locked} />;
|
||||
}
|
||||
if (property.type === "select") {
|
||||
return <SelectProperty key={property.label} {...property} disabled={locked} />;
|
||||
}
|
||||
return <RangeProperty key={property.label} {...property} disabled={locked} />;
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="inspector-snap-dock">
|
||||
<SnapGridControl snap={snap} snapOpen={snapOpen} onSnapChange={onSnapChange} onSnapOpenChange={onSnapOpenChange} />
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
export function SnapGridControl({
|
||||
snap,
|
||||
snapOpen,
|
||||
onSnapChange,
|
||||
onSnapOpenChange,
|
||||
}: {
|
||||
snap: GridSize;
|
||||
snapOpen: boolean;
|
||||
onSnapChange: Dispatch<SetStateAction<GridSize>>;
|
||||
onSnapOpenChange: Dispatch<SetStateAction<boolean>>;
|
||||
}) {
|
||||
return (
|
||||
<div className="snap-row">
|
||||
<span>Snap Grid</span>
|
||||
<button className="snap-select" onClick={() => onSnapOpenChange((value) => !value)}>
|
||||
{snap}
|
||||
<ChevronDown size={12} fill="currentColor" />
|
||||
</button>
|
||||
{snapOpen ? (
|
||||
<div className="snap-menu">
|
||||
{GRID_SIZES.map((size) => (
|
||||
<button
|
||||
key={size}
|
||||
className={size === snap ? "selected" : ""}
|
||||
onClick={() => {
|
||||
onSnapChange(size);
|
||||
onSnapOpenChange(false);
|
||||
}}
|
||||
>
|
||||
{size}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RangeProperty({ label, value, min, max, step = 0.01, disabled, onChange }: RangePropertyConfig & { disabled?: boolean }) {
|
||||
const safeValue = clamp(value, min, max);
|
||||
const position = ((safeValue - min) / Math.max(1, max - min)) * 100;
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState(formatPanelNumber(safeValue));
|
||||
const commitDraft = () => {
|
||||
const next = Number(draft);
|
||||
onChange(clamp(Number.isFinite(next) ? next : safeValue, min, max));
|
||||
setEditing(false);
|
||||
};
|
||||
return (
|
||||
<label className="range-property" style={{ "--slider-pos": `${position}%` } as CSSProperties}>
|
||||
<span>{label}</span>
|
||||
<div className="range-control">
|
||||
{editing ? (
|
||||
<input
|
||||
className="range-value-input"
|
||||
type="number"
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={draft}
|
||||
autoFocus
|
||||
onChange={(event) => setDraft(event.currentTarget.value)}
|
||||
onBlur={commitDraft}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.currentTarget.blur();
|
||||
} else if (event.key === "Escape") {
|
||||
setDraft(formatPanelNumber(safeValue));
|
||||
setEditing(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<output
|
||||
onDoubleClick={(event) => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
setDraft(formatPanelNumber(safeValue));
|
||||
setEditing(true);
|
||||
}}
|
||||
>
|
||||
{formatPanelNumber(safeValue)}
|
||||
</output>
|
||||
)}
|
||||
<input
|
||||
type="range"
|
||||
min={min}
|
||||
max={max}
|
||||
step={step}
|
||||
value={safeValue}
|
||||
disabled={disabled}
|
||||
onChange={(event) => {
|
||||
const next = Number(event.currentTarget.value);
|
||||
onChange(clamp(Number.isFinite(next) ? next : min, min, max));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function TextProperty({ label, value, disabled, onChange }: TextPropertyConfig & { disabled?: boolean }) {
|
||||
return (
|
||||
<label className="text-property">
|
||||
<span>{label}</span>
|
||||
<input
|
||||
type="text"
|
||||
value={value}
|
||||
disabled={disabled}
|
||||
maxLength={24}
|
||||
spellCheck={false}
|
||||
onChange={(event) => onChange(event.currentTarget.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectProperty({ label, value, options, disabled, onChange }: SelectPropertyConfig & { disabled?: boolean }) {
|
||||
return (
|
||||
<label className="select-property">
|
||||
<span>{label}</span>
|
||||
<select value={value} disabled={disabled} onChange={(event) => onChange(event.currentTarget.value)}>
|
||||
{options.map((option) => (
|
||||
<option key={option} value={option}>
|
||||
{option}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ export function TransformOverlay({
|
||||
<line className="rotation-zero-line" x1="0" y1="0" x2="0" y2="-92" />
|
||||
<line className="rotation-current-line" x1="0" y1="0" x2={activeLine.x} y2={activeLine.y} />
|
||||
<text className="rotation-zero-label" x="0" y="-75">
|
||||
0Β°
|
||||
0°
|
||||
</text>
|
||||
</g>
|
||||
</svg>
|
||||
@@ -173,7 +173,7 @@ export function TransformOverlay({
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span>Β°</span>
|
||||
<span>°</span>
|
||||
</label>
|
||||
) : null}
|
||||
{box.handles.map((handle) => (
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
"use client";
|
||||
|
||||
import { X } from "lucide-react";
|
||||
import type { CSSProperties } from "react";
|
||||
import { DEFAULT_WORKPLANE_WORKSPACE } from "@/lib/workplaneSettings";
|
||||
import type { GridSize, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||
|
||||
type WorkspaceSettings = WorkplaneWorkspaceSettings;
|
||||
|
||||
const GRID_SIZES: GridSize[] = ["Off", "0.1 mm", "0.25 mm", "0.5 mm", "1.0 mm", "2.0 mm", "5.0 mm", "Brick"];
|
||||
const MIN_WORKSPACE_SIZE = 60;
|
||||
const MAX_WORKSPACE_SIZE = 2000;
|
||||
const MIN_GRID_BLOCK_SIZE = 1;
|
||||
const MAX_GRID_BLOCK_SIZE = 200;
|
||||
const WORKSPACE_SIZE_PRESETS = [
|
||||
{ label: "200 x 200 mm", width: 200, depth: 200 },
|
||||
{ label: "300 x 300 mm", width: 300, depth: 300 },
|
||||
{ label: "500 x 500 mm", width: 500, depth: 500 },
|
||||
{ label: "1000 x 1000 mm", width: 1000, depth: 1000 },
|
||||
{ label: "2000 x 2000 mm", width: 2000, depth: 2000 },
|
||||
{ label: "Custom", width: 200, depth: 200 },
|
||||
];
|
||||
const GRID_BLOCK_PRESETS = ["1 mm", "2.5 mm", "5 mm", "10 mm", "20 mm", "50 mm", "100 mm", "Custom"] as const;
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
function gridBlockSizeForPreset(preset: string, fallback: number) {
|
||||
if (preset === "Custom") {
|
||||
return clamp(fallback, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE);
|
||||
}
|
||||
return clamp(Number.parseFloat(preset) || DEFAULT_WORKPLANE_WORKSPACE.gridBlockSize, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
export function WorkspaceSettingsModal({
|
||||
workspace,
|
||||
snap,
|
||||
onWorkspaceChange,
|
||||
onSnapChange,
|
||||
onClose,
|
||||
}: {
|
||||
workspace: WorkspaceSettings;
|
||||
snap: GridSize;
|
||||
onWorkspaceChange: (next: WorkspaceSettings) => void;
|
||||
onSnapChange: (next: GridSize) => void;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const patchWorkspace = (patch: Partial<WorkspaceSettings>) => onWorkspaceChange({ ...workspace, ...patch });
|
||||
const setDimension = (key: "width" | "depth", value: string) => {
|
||||
const next = clamp(Number.parseFloat(value) || DEFAULT_WORKPLANE_WORKSPACE[key], MIN_WORKSPACE_SIZE, MAX_WORKSPACE_SIZE);
|
||||
patchWorkspace({ [key]: next, sizePreset: "Custom" } as Partial<WorkspaceSettings>);
|
||||
};
|
||||
const setWorkspaceSizePreset = (sizePreset: string) => {
|
||||
const preset = WORKSPACE_SIZE_PRESETS.find((entry) => entry.label === sizePreset);
|
||||
if (!preset || sizePreset === "Custom") {
|
||||
patchWorkspace({ sizePreset: "Custom" });
|
||||
return;
|
||||
}
|
||||
patchWorkspace({ sizePreset, width: preset.width, depth: preset.depth });
|
||||
};
|
||||
const setGridBlockPreset = (gridBlockPreset: string) => {
|
||||
patchWorkspace({ gridBlockPreset, gridBlockSize: gridBlockSizeForPreset(gridBlockPreset, workspace.gridBlockSize) });
|
||||
};
|
||||
const setGridBlockSize = (value: string) => {
|
||||
const next = clamp(Number.parseFloat(value) || DEFAULT_WORKPLANE_WORKSPACE.gridBlockSize, MIN_GRID_BLOCK_SIZE, MAX_GRID_BLOCK_SIZE);
|
||||
patchWorkspace({ gridBlockPreset: "Custom", gridBlockSize: next });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="workspace-modal" role="dialog" aria-modal="true" aria-label="Workspace settings">
|
||||
<div className="workspace-modal-card" onPointerDown={(event) => event.stopPropagation()}>
|
||||
<header className="workspace-modal-header">
|
||||
<strong>Workspace settings</strong>
|
||||
<button aria-label="Close settings" onClick={onClose}>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div className="workspace-modal-body">
|
||||
<div className="workspace-row">
|
||||
<span>Background color</span>
|
||||
<button
|
||||
className="workspace-color-button"
|
||||
style={{ "--workspace-bg": workspace.background } as CSSProperties}
|
||||
aria-label="Background color"
|
||||
onClick={() => patchWorkspace({ background: workspace.background === "#f8fbfc" ? "#eaf7fb" : "#f8fbfc" })}
|
||||
/>
|
||||
</div>
|
||||
<WorkspaceToggle label="Show shadows" checked={workspace.showShadows} onChange={(showShadows) => patchWorkspace({ showShadows })} />
|
||||
<WorkspaceToggle label="Show grid" checked={workspace.showGrid} onChange={(showGrid) => patchWorkspace({ showGrid })} />
|
||||
<WorkspaceToggle
|
||||
label="Cruise when adding new shapes"
|
||||
checked={workspace.cruiseShapes}
|
||||
onChange={(cruiseShapes) => patchWorkspace({ cruiseShapes })}
|
||||
/>
|
||||
|
||||
<label className="workspace-range">
|
||||
<span>Zoom speed</span>
|
||||
<input
|
||||
type="range"
|
||||
min={1}
|
||||
max={10}
|
||||
value={workspace.zoomSpeed}
|
||||
onChange={(event) => patchWorkspace({ zoomSpeed: Number(event.currentTarget.value) })}
|
||||
/>
|
||||
<small>
|
||||
<span>Slow</span>
|
||||
<span>Fast</span>
|
||||
</small>
|
||||
</label>
|
||||
|
||||
<WorkspaceSelect
|
||||
label="Units"
|
||||
value={workspace.units}
|
||||
options={["Metric (Default)", "Imperial", "Bricks"]}
|
||||
onChange={(units) => patchWorkspace({ units })}
|
||||
/>
|
||||
<WorkspaceSelect
|
||||
label="Scale"
|
||||
value={workspace.scale}
|
||||
options={["1:1 (millimeters)", "1:10 (centimeters)", "1:100 (meters)", "1:1000 (meters)"]}
|
||||
onChange={(scale) => patchWorkspace({ scale })}
|
||||
/>
|
||||
<WorkspaceSelect label="Snap Grid" value={snap} options={GRID_SIZES} onChange={(next) => onSnapChange(next as GridSize)} />
|
||||
<WorkspaceSelect
|
||||
label="Workplane size"
|
||||
value={workspace.sizePreset}
|
||||
options={WORKSPACE_SIZE_PRESETS.map((preset) => preset.label)}
|
||||
onChange={setWorkspaceSizePreset}
|
||||
/>
|
||||
|
||||
<div className="workspace-dimensions">
|
||||
<label>
|
||||
<span>Width</span>
|
||||
<input
|
||||
type="number"
|
||||
value={workspace.width.toFixed(2)}
|
||||
min={MIN_WORKSPACE_SIZE}
|
||||
max={MAX_WORKSPACE_SIZE}
|
||||
step={1}
|
||||
onChange={(event) => setDimension("width", event.currentTarget.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<span>Length</span>
|
||||
<input
|
||||
type="number"
|
||||
value={workspace.depth.toFixed(2)}
|
||||
min={MIN_WORKSPACE_SIZE}
|
||||
max={MAX_WORKSPACE_SIZE}
|
||||
step={1}
|
||||
onChange={(event) => setDimension("depth", event.currentTarget.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<WorkspaceSelect label="Grid block size" value={workspace.gridBlockPreset} options={GRID_BLOCK_PRESETS} onChange={setGridBlockPreset} />
|
||||
{workspace.gridBlockPreset === "Custom" ? (
|
||||
<div className="workspace-dimensions workspace-grid-dimensions">
|
||||
<label>
|
||||
<span>Block size</span>
|
||||
<input
|
||||
type="number"
|
||||
value={workspace.gridBlockSize.toFixed(2)}
|
||||
min={MIN_GRID_BLOCK_SIZE}
|
||||
max={MAX_GRID_BLOCK_SIZE}
|
||||
step={0.5}
|
||||
onChange={(event) => setGridBlockSize(event.currentTarget.value)}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<button className="make-default-button" onClick={() => onWorkspaceChange(DEFAULT_WORKPLANE_WORKSPACE)}>
|
||||
Make default
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button className="workspace-modal-backdrop" aria-label="Close settings" onClick={onClose} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WorkspaceToggle({ label, checked, onChange }: { label: string; checked: boolean; onChange: (checked: boolean) => void }) {
|
||||
return (
|
||||
<label className="workspace-toggle">
|
||||
<span>{label}</span>
|
||||
<input type="checkbox" checked={checked} onChange={(event) => onChange(event.currentTarget.checked)} />
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function WorkspaceSelect({
|
||||
label,
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
options: readonly string[];
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
return (
|
||||
<label className="workspace-select">
|
||||
<span>{label}</span>
|
||||
<select value={value} onChange={(event) => onChange(event.currentTarget.value)}>
|
||||
{options.map((option) => (
|
||||
<option key={option} value={option}>
|
||||
{option}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user