From 57361a3b2a995139f834aea2c5e8bf7453954338 Mon Sep 17 00:00:00 2001 From: Formsmith Date: Sat, 20 Jun 2026 10:07:33 +0300 Subject: [PATCH] Release v0.2.0 with Docker deployment --- .dockerignore | 26 ++ Dockerfile | 26 ++ README.md | 78 +++++ apps/web/src/app/globals.css | 214 +++++++++++++- apps/web/src/app/page.tsx | 103 ++++++- apps/web/src/components/SketchForgeEditor.tsx | 10 +- .../workplane/WorkspaceSettingsModal.tsx | 273 ++++++++++-------- apps/web/src/lib/exportNames.ts | 11 + compose.yaml | 9 + deploy/nginx.conf | 32 ++ package-lock.json | 4 +- package.json | 6 +- tests/unit/exportNames.test.ts | 17 ++ 13 files changed, 669 insertions(+), 140 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 apps/web/src/lib/exportNames.ts create mode 100644 compose.yaml create mode 100644 deploy/nginx.conf create mode 100644 tests/unit/exportNames.test.ts diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..532cedf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +.git +.github +.codex +.codex-remote-attachments + +node_modules +**/node_modules +**/.next +**/out +build +dist + +coverage +test-results +playwright-report +.playwright-cli + +.env +.env*.local +*.log +*.tsbuildinfo + +.DS_Store +Thumbs.db +.idea +.vscode diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27e53d3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# syntax=docker/dockerfile:1 + +FROM node:22-alpine AS builder + +WORKDIR /app + +ENV NEXT_TELEMETRY_DISABLED=1 +ENV STATIC_EXPORT=true + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +RUN npm run build + +FROM nginx:stable-alpine AS runner + +COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=builder /app/apps/web/out /usr/share/nginx/html + +EXPOSE 80 + +HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ + CMD wget -q -O - http://127.0.0.1/healthz | grep -q '^ok$' || exit 1 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/README.md b/README.md index 82cb7dc..3cadbce 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ MIT license GitHub stars Local first + Version 0.2.0

@@ -64,6 +65,83 @@ Open: http://127.0.0.1:3000/ ``` +## Docker / FabLab Server (Recommended) + +The Docker image contains a static SketchForge build served by Nginx. Projects stay in each user's browser; STL and OBJ files download through that browser. The container does not receive or store project files. + +Docker is the recommended server setup because it packages the correct Node build environment, static app, Nginx configuration, health check, and restart policy together. It is easier to reproduce and update than configuring each part by hand. + +Requirements: + +- Docker Engine with Docker Compose + +Build and start SketchForge: + +```bash +docker compose up --build -d +``` + +Open it on the server: + +```text +http://127.0.0.1:3000/ +``` + +Other computers on the same network can use the server's LAN address: + +```text +http://SERVER_IP:3000/ +``` + +To use another host port: + +```bash +SKETCHFORGE_PORT=8080 docker compose up --build -d +``` + +On PowerShell: + +```powershell +$env:SKETCHFORGE_PORT = "8080" +docker compose up --build -d +``` + +Stop the server with: + +```bash +docker compose down +``` + +### Manual Static Deployment (Advanced) + +This is the harder alternative for servers where Docker cannot be used. The administrator must install and maintain Node.js, npm, Nginx or another static web server, firewall access, startup behavior, and future updates separately. + +Requirements: + +- Node.js 20 or newer +- npm +- Nginx, Apache, Caddy, or another static web server + +Create the static build on Linux or macOS: + +```bash +npm ci +STATIC_EXPORT=true npm run build +``` + +Create it with PowerShell on Windows: + +```powershell +npm ci +$env:STATIC_EXPORT = "true" +npm run build +Remove-Item Env:STATIC_EXPORT +``` + +The deployable files are generated in `apps/web/out`. Configure the web server to serve that directory and fall back to `index.html` for unknown application paths. [`deploy/nginx.conf`](deploy/nginx.conf) is the configuration used by the Docker image and can be adapted for a manual Nginx installation. + +The administrator must also open the chosen LAN port in the server firewall and arrange for the web server to start automatically after a reboot. For each SketchForge update, pull the new source, install dependencies, rebuild `apps/web/out`, replace the served files, and reload the web server. + ## Development ```bash diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 1aa4c1d..6407643 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -413,7 +413,7 @@ button { grid-row: 1 / span 2; } -.project-delete { +.project-menu-trigger { position: absolute; top: 12px; right: 12px; @@ -430,15 +430,59 @@ button { box-shadow: 0 2px 6px rgba(24, 43, 60, 0.1); } -.project-card:hover .project-delete, -.project-delete:focus-visible { +.project-card:hover .project-menu-trigger, +.project-menu-trigger:focus-visible { opacity: 1; } -.project-delete:hover { +.project-menu-trigger:hover, +.project-menu-trigger[aria-expanded="true"] { + color: #264d6b; + border-color: #a9bdcc; + background: #f5f9fc; +} + +.project-card-menu { + position: absolute; + top: 52px; + right: 12px; + z-index: 4; + display: grid; + width: 148px; + gap: 3px; + padding: 5px; + color: #314b61; + background: #ffffff; + border: 1px solid #ccd9e3; + border-radius: 7px; + box-shadow: 0 10px 28px rgba(24, 43, 60, 0.18); +} + +.project-card-menu button { + display: flex; + align-items: center; + gap: 9px; + min-height: 36px; + padding: 0 10px; + color: inherit; + background: transparent; + border-radius: 5px; + font-weight: 700; + text-align: left; +} + +.project-card-menu button:hover, +.project-card-menu button:focus-visible { + background: #eef5fa; +} + +.project-card-menu button.delete { color: #b01925; - border-color: #efb7be; - background: #fff4f5; +} + +.project-card-menu button.delete:hover, +.project-card-menu button.delete:focus-visible { + background: #fff1f2; } .dashboard-confirm-overlay { @@ -524,6 +568,44 @@ button { background: #c82031; } +.dashboard-confirm-save { + color: #ffffff; + border: 1px solid #147ca8; + background: #147ca8; +} + +.dashboard-confirm-save:disabled { + cursor: not-allowed; + opacity: 0.45; +} + +.dashboard-rename-dialog > label { + display: grid; + gap: 7px; + padding: 18px; + color: #40586c; + font-size: 13px; + font-weight: 800; +} + +.dashboard-rename-dialog input { + width: 100%; + height: 42px; + padding: 0 12px; + color: #1d3448; + background: #ffffff; + border: 1px solid #b9cad7; + border-radius: 6px; + font: inherit; + font-weight: 600; + outline: none; +} + +.dashboard-rename-dialog input:focus { + border-color: #1486b5; + box-shadow: 0 0 0 3px rgba(20, 134, 181, 0.14); +} + .project-empty { display: grid; min-height: 190px; @@ -2707,9 +2789,9 @@ button { .workspace-modal-card { position: relative; z-index: 2; - width: 520px; + width: 760px; max-width: calc(100vw - 32px); - min-height: min(720px, calc(100vh - 104px)); + height: min(650px, calc(100vh - 104px)); max-height: calc(100vh - 104px); overflow: hidden; color: #264158; @@ -2753,14 +2835,86 @@ button { cursor: pointer; } +.workspace-modal-layout { + display: grid; + grid-template-columns: 190px minmax(0, 1fr); + height: calc(100% - 55px); + min-height: 0; +} + +.workspace-settings-nav { + display: grid; + align-content: start; + gap: 6px; + padding: 16px 10px; + background: #f4f7f9; + border-right: 1px solid #d8e1e8; +} + +.workspace-settings-nav button { + display: flex; + align-items: center; + gap: 10px; + width: 100%; + min-height: 42px; + padding: 0 12px; + color: #526b7e; + background: transparent; + border: 1px solid transparent; + border-radius: 5px; + cursor: pointer; + font-size: 13px; + font-weight: 800; + text-align: left; +} + +.workspace-settings-nav button:hover { + color: #274861; + background: #e9f0f4; +} + +.workspace-settings-nav button.active { + color: #176f95; + background: #ffffff; + border-color: #c7d9e4; + box-shadow: 0 1px 3px rgba(31, 64, 84, 0.08); +} + +.workspace-modal-content { + display: grid; + grid-template-rows: minmax(0, 1fr) auto; + min-width: 0; + min-height: 0; + overflow: hidden; +} + .workspace-modal-body { display: grid; + align-content: start; gap: 20px; - max-height: calc(100vh - 159px); - padding: 18px 18px 22px; + min-height: 0; + padding: 22px 24px; overflow: auto; } +.workspace-section-heading { + display: grid; + gap: 5px; + padding-bottom: 15px; + border-bottom: 1px solid #e2e9ee; +} + +.workspace-section-heading strong { + color: #213d54; + font-size: 17px; +} + +.workspace-section-heading span { + color: #718697; + font-size: 12px; + font-weight: 650; +} + .workspace-row, .workspace-toggle, .workspace-select { @@ -2858,7 +3012,9 @@ button { } .make-default-button { - height: 30px; + min-width: 128px; + height: 34px; + padding: 0 14px; color: #264158; background: #f7fafc; border: 1px solid #d6e0e8; @@ -2868,9 +3024,18 @@ button { font-weight: 800; } -.make-default-button { - width: 240px; - margin-left: 153px; +.workspace-modal-footer { + display: flex; + align-items: center; + justify-content: space-between; + gap: 16px; + min-height: 64px; + padding: 12px 24px; + color: #718697; + background: #fbfcfd; + border-top: 1px solid #dfe7ed; + font-size: 12px; + font-weight: 700; } .workspace-modal-header button:hover, @@ -3333,11 +3498,28 @@ button { } .workspace-modal-card { - width: min(520px, calc(100vw - 24px)); - min-height: calc(100vh - 112px); + width: min(760px, calc(100vw - 24px)); + height: calc(100vh - 112px); max-height: calc(100vh - 112px); } + .workspace-modal-layout { + grid-template-columns: 165px minmax(0, 1fr); + } + + .workspace-settings-nav { + padding-inline: 8px; + } + + .workspace-settings-nav button { + padding-inline: 9px; + } + + .workspace-modal-body, + .workspace-modal-footer { + padding-inline: 18px; + } + .workplane-plane { inset: 0; } diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index 958728f..6005ece 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { Clock3, FileUp, Grid3X3, HomeIcon, List, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react"; +import { Clock3, EllipsisVertical, FileUp, Grid3X3, HomeIcon, List, Pencil, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor"; import { createLocalId } from "@/lib/localIds"; @@ -574,6 +574,14 @@ export default function Home() { }); }; + const renameProject = (projectId: string, name: string) => { + const nextName = name.trim().slice(0, 80); + if (!nextName) return; + setProjects((current) => + current.map((project) => (project.id === projectId ? { ...project, name: nextName, updatedAt: Date.now() } : project)), + ); + }; + if (!mounted) { return null; } @@ -629,6 +637,7 @@ export default function Home() { onOpenProject={openEditor} onOpenSettings={() => setSettingsOpen(true)} onQueryChange={setQuery} + onRenameProject={renameProject} onSortModeChange={setSortMode} onViewModeChange={setViewMode} onWorkspace={openLatestProject} @@ -645,6 +654,7 @@ export default function Home() { onProjectSnapshot={updateProjectSnapshot} onProjectWorkspaceChange={updateProjectWorkspace} projectId={activeProjectId} + projectName={activeProject?.name} projectRevision={activeProjectShapeEntry?.revision ?? activeProject?.revision ?? 0} /> @@ -672,6 +682,7 @@ function Dashboard({ onOpenProject, onOpenSettings, onQueryChange, + onRenameProject, onSortModeChange, onViewModeChange, onWorkspace, @@ -694,12 +705,17 @@ function Dashboard({ onOpenProject: (projectId: string) => void; onOpenSettings: () => void; onQueryChange: (value: string) => void; + onRenameProject: (projectId: string, name: string) => void; onSortModeChange: (value: string) => void; onViewModeChange: (value: ViewMode) => void; onWorkspace: () => void; }) { + const [openProjectMenuId, setOpenProjectMenuId] = useState(null); const [projectPendingDeleteId, setProjectPendingDeleteId] = useState(null); + const [projectPendingRenameId, setProjectPendingRenameId] = useState(null); + const [projectNameDraft, setProjectNameDraft] = useState(""); const projectPendingDelete = projects.find((project) => project.id === projectPendingDeleteId) ?? null; + const projectPendingRename = projects.find((project) => project.id === projectPendingRenameId) ?? null; useEffect(() => { if (!projectPendingDeleteId) return; @@ -713,6 +729,23 @@ function Dashboard({ setProjectPendingDeleteId(null); }; + const startProjectRename = (project: DashboardProject) => { + setOpenProjectMenuId(null); + setProjectPendingRenameId(project.id); + setProjectNameDraft(project.name); + }; + + const closeProjectRename = () => { + setProjectPendingRenameId(null); + setProjectNameDraft(""); + }; + + const confirmProjectRename = () => { + if (!projectPendingRename || !projectNameDraft.trim()) return; + onRenameProject(projectPendingRename.id, projectNameDraft); + closeProjectRename(); + }; + return (
@@ -806,9 +839,36 @@ function Dashboard({ {formatUpdated(project.updatedAt)} - {project.shapes} shapes - + {openProjectMenuId === project.id ? ( +
+ + +
+ ) : null} ))} @@ -845,6 +905,43 @@ function Dashboard({ ) : null} + {projectPendingRename ? ( +
+
{ + event.preventDefault(); + confirmProjectRename(); + }} + > +
+ Rename project + +
+ +
+ + +
+
+
+ ) : null} + {settingsOpen ? (
diff --git a/apps/web/src/components/SketchForgeEditor.tsx b/apps/web/src/components/SketchForgeEditor.tsx index f96f22b..b51be2f 100644 --- a/apps/web/src/components/SketchForgeEditor.tsx +++ b/apps/web/src/components/SketchForgeEditor.tsx @@ -56,6 +56,7 @@ import { workplaneShapesEqual, } from "@/lib/workplaneShapes"; import { createLocalId } from "@/lib/localIds"; +import { projectExportFileName } from "@/lib/exportNames"; import { makeShapeFromAsset, sceneShape, toolbarShapeAssets, type ToolbarShapeAsset } from "@/lib/shapeCatalog"; import { importedShapeFromStl, importExtensionSupported } from "@/lib/stlImport"; import type { AlignAxis, AlignHandleStatus, AlignTarget, GridSize, ShapeAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; @@ -4006,6 +4007,7 @@ export function SketchForgeEditor({ onProjectSnapshot, onProjectWorkspaceChange, projectId, + projectName = "SketchForge design", projectRevision = 0, }: { initialShapes?: WorkplaneShape[]; @@ -4016,6 +4018,7 @@ export function SketchForgeEditor({ onProjectSnapshot?: (snapshot: { image: string; projectId: string; shapes: number }) => void; onProjectWorkspaceChange?: (snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => void; projectId?: string | null; + projectName?: string; projectRevision?: number; } = {}) { const [shapes, setShapes] = useState(() => initialShapes.map(canonicalizeShape)); @@ -4983,7 +4986,6 @@ export function SketchForgeEditor({ return; } const meshes = exportable.map(meshForShape); - const scope = hasSelection ? "selection" : "design"; const selectedNotice = `Exported ${exportable.length} selected shape${exportable.length === 1 ? "" : "s"}`; const finishNotice = (label: string, result: DownloadResult) => { if (result.mode === "folder") { @@ -4996,15 +4998,15 @@ export function SketchForgeEditor({ setNotice(error instanceof Error ? error.message : `Could not export ${label}`); }; if (format === "stl") { - void downloadTextFile(`sketchforge-${scope}.stl`, toStl(meshes), "model/stl") + void downloadTextFile(projectExportFileName(projectName, "stl"), toStl(meshes), "model/stl") .then((result) => finishNotice("STL", result)) .catch((error: unknown) => failNotice("STL", error)); return; } - void downloadTextFile(`sketchforge-${scope}.obj`, toObj(meshes), "text/plain") + void downloadTextFile(projectExportFileName(projectName, "obj"), toObj(meshes), "text/plain") .then((result) => finishNotice("OBJ", result)) .catch((error: unknown) => failNotice("OBJ", error)); - }, [hasSelection, selectedShapes, shapes]); + }, [hasSelection, projectName, selectedShapes, shapes]); const clearDesign = useCallback(() => { commitShapes([], [], "New empty design"); diff --git a/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx b/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx index ab31371..89bd41d 100644 --- a/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx +++ b/apps/web/src/components/workplane/WorkspaceSettingsModal.tsx @@ -1,11 +1,12 @@ "use client"; -import { X } from "lucide-react"; +import { Grid3X3, Palette, Ruler, X } from "lucide-react"; import { useState, type CSSProperties } from "react"; import { DEFAULT_WORKPLANE_WORKSPACE } from "@/lib/workplaneSettings"; import type { GridSize, WorkplaneWorkspaceSettings } from "@/types/sketchforge"; type WorkspaceSettings = WorkplaneWorkspaceSettings; +type WorkspaceSettingsSection = "appearance" | "measurement" | "workplane"; 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; @@ -49,6 +50,7 @@ export function WorkspaceSettingsModal({ onClose: () => void; }) { const [defaultSaved, setDefaultSaved] = useState(false); + const [activeSection, setActiveSection] = useState("appearance"); const patchWorkspace = (patch: Partial) => { setDefaultSaved(false); onWorkspaceChange({ ...workspace, ...patch }); @@ -83,123 +85,168 @@ export function WorkspaceSettingsModal({
-
-
- Background color -
- patchWorkspace({ showShadows })} /> - patchWorkspace({ showGrid })} /> - patchWorkspace({ cruiseShapes })} - /> +
+ - +
+
+ {activeSection === "appearance" ? ( + <> +
+ Appearance + Adjust the canvas and navigation behavior. +
+
+ Background color +
+ patchWorkspace({ showShadows })} /> + patchWorkspace({ showGrid })} /> + patchWorkspace({ cruiseShapes })} + /> + + + ) : null} - patchWorkspace({ units })} - /> - patchWorkspace({ scale })} - /> - patchWorkspace({ accuracy: accuracy.slice(2).length as WorkspaceSettings["accuracy"] })} - /> - { - setDefaultSaved(false); - onSnapChange(next as GridSize); - }} - /> - preset.label)} - onChange={setWorkspaceSizePreset} - /> + {activeSection === "measurement" ? ( + <> +
+ Measurement + Choose units, precision, scale, and snapping. +
+ patchWorkspace({ units })} + /> + patchWorkspace({ scale })} + /> + patchWorkspace({ accuracy: accuracy.slice(2).length as WorkspaceSettings["accuracy"] })} + /> + { + setDefaultSaved(false); + onSnapChange(next as GridSize); + }} + /> + + ) : null} -
- - -
- - {workspace.gridBlockPreset === "Custom" ? ( -
- + {activeSection === "workplane" ? ( + <> +
+ Workplane + Set the plate dimensions and visible grid spacing. +
+ preset.label)} + onChange={setWorkspaceSizePreset} + /> +
+ + +
+ + {workspace.gridBlockPreset === "Custom" ? ( +
+ +
+ ) : null} + + ) : null}
- ) : null} - +
+ Save the current settings for this project. + +
+