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
Checkpoint SKF project format and export updates
This commit is contained in:
@@ -5,7 +5,8 @@ import { NextResponse } from "next/server";
|
||||
export const revalidate = false;
|
||||
|
||||
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "::1"]);
|
||||
const MAX_LOCAL_DOWNLOAD_BYTES = 25 * 1024 * 1024;
|
||||
const MAX_TEXT_DOWNLOAD_BYTES = 25 * 1024 * 1024;
|
||||
const MAX_BINARY_DOWNLOAD_BYTES = 512 * 1024 * 1024;
|
||||
|
||||
function safeFileName(filename: string) {
|
||||
const base = path.basename(filename).replace(/[<>:"/\\|?*\u0000-\u001f]/g, "_").trim();
|
||||
@@ -40,28 +41,51 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ error: "Local folder downloads are only available from this localhost app" }, { status: 403 });
|
||||
}
|
||||
|
||||
const body = (await request.json()) as { content?: unknown; filename?: unknown; folder?: unknown };
|
||||
if (typeof body.content !== "string" || typeof body.filename !== "string" || typeof body.folder !== "string") {
|
||||
return NextResponse.json({ error: "Invalid download request" }, { status: 400 });
|
||||
const contentType = request.headers.get("content-type") ?? "";
|
||||
let filename: string;
|
||||
let folder: string;
|
||||
let content: string | Buffer;
|
||||
if (contentType.toLowerCase().startsWith("multipart/form-data")) {
|
||||
const formData = await request.formData();
|
||||
const file = formData.get("file");
|
||||
const requestedName = formData.get("filename");
|
||||
const requestedFolder = formData.get("folder");
|
||||
if (!(file instanceof Blob) || typeof requestedName !== "string" || typeof requestedFolder !== "string") {
|
||||
return NextResponse.json({ error: "Invalid binary download request" }, { status: 400 });
|
||||
}
|
||||
if (file.size > MAX_BINARY_DOWNLOAD_BYTES) {
|
||||
return NextResponse.json({ error: "File is too large for local folder download" }, { status: 413 });
|
||||
}
|
||||
filename = requestedName;
|
||||
folder = requestedFolder;
|
||||
content = Buffer.from(await file.arrayBuffer());
|
||||
} else {
|
||||
const body = (await request.json()) as { content?: unknown; filename?: unknown; folder?: unknown };
|
||||
if (typeof body.content !== "string" || typeof body.filename !== "string" || typeof body.folder !== "string") {
|
||||
return NextResponse.json({ error: "Invalid download request" }, { status: 400 });
|
||||
}
|
||||
if (Buffer.byteLength(body.content, "utf8") > MAX_TEXT_DOWNLOAD_BYTES) {
|
||||
return NextResponse.json({ error: "File is too large for local folder download" }, { status: 413 });
|
||||
}
|
||||
filename = body.filename;
|
||||
folder = body.folder;
|
||||
content = body.content;
|
||||
}
|
||||
|
||||
if (Buffer.byteLength(body.content, "utf8") > MAX_LOCAL_DOWNLOAD_BYTES) {
|
||||
return NextResponse.json({ error: "File is too large for local folder download" }, { status: 413 });
|
||||
}
|
||||
|
||||
const trimmedFolder = body.folder.trim();
|
||||
const trimmedFolder = folder.trim();
|
||||
if (!trimmedFolder) {
|
||||
return NextResponse.json({ error: "Choose a folder first" }, { status: 400 });
|
||||
}
|
||||
|
||||
const targetDirectory = path.resolve(path.isAbsolute(trimmedFolder) ? trimmedFolder : path.join(process.cwd(), trimmedFolder));
|
||||
await fs.mkdir(targetDirectory, { recursive: true });
|
||||
const targetPath = path.resolve(targetDirectory, safeFileName(body.filename));
|
||||
const targetPath = path.resolve(targetDirectory, safeFileName(filename));
|
||||
const relativeTarget = path.relative(targetDirectory, targetPath);
|
||||
if (relativeTarget.startsWith("..") || path.isAbsolute(relativeTarget)) {
|
||||
return NextResponse.json({ error: "Invalid file path" }, { status: 400 });
|
||||
}
|
||||
await fs.writeFile(targetPath, body.content, "utf8");
|
||||
if (typeof content === "string") await fs.writeFile(targetPath, content, "utf8");
|
||||
else await fs.writeFile(targetPath, content);
|
||||
|
||||
return NextResponse.json({ path: targetPath });
|
||||
} catch (error) {
|
||||
|
||||
@@ -1965,6 +1965,441 @@ button {
|
||||
background: #eef8fc;
|
||||
}
|
||||
|
||||
.top-action-heading {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.top-action-heading > span {
|
||||
color: #6b7f91;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.top-action-panel.export-action-panel,
|
||||
.top-action-panel.import-action-panel {
|
||||
width: min(440px, calc(100vw - 28px));
|
||||
overflow: hidden;
|
||||
border-color: #d8e1e8;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 18px 55px rgba(19, 37, 55, 0.24);
|
||||
}
|
||||
|
||||
.export-action-panel header,
|
||||
.import-action-panel header {
|
||||
height: 52px;
|
||||
padding: 0 12px 0 15px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.import-action-panel .top-action-body {
|
||||
padding: 14px;
|
||||
background: #f7f9fb;
|
||||
}
|
||||
|
||||
.export-dialog-body {
|
||||
display: grid;
|
||||
max-height: calc(100vh - var(--editor-toolbar-height) - 96px);
|
||||
overflow-y: auto;
|
||||
background: #f7f9fb;
|
||||
}
|
||||
|
||||
.export-setting-section {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 12px 14px;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #e5ebf0;
|
||||
}
|
||||
|
||||
.export-file-section {
|
||||
grid-template-columns: 72px minmax(0, 1fr);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.export-file-section label,
|
||||
.export-section-heading strong {
|
||||
color: #20384d;
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.export-file-input-wrap {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
background: #f7f9fb;
|
||||
border: 1px solid #d9e2e9;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.export-file-input-wrap:focus-within {
|
||||
background: #fff;
|
||||
border-color: #10a8d0;
|
||||
box-shadow: 0 0 0 2px rgba(16, 168, 208, 0.12);
|
||||
}
|
||||
|
||||
.export-file-input {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
height: 32px;
|
||||
padding: 0 2px 0 10px;
|
||||
color: #263e52;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
font-weight: 750;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.export-file-input-wrap > span {
|
||||
display: inline-flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
padding: 0 9px 0 4px;
|
||||
color: #6d8090;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.export-section-heading {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.export-section-heading > div {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.export-section-heading > div > span {
|
||||
color: #718494;
|
||||
font-size: 11px;
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.export-scope-badge {
|
||||
flex: none;
|
||||
padding: 4px 8px;
|
||||
color: #137897;
|
||||
font-size: 10px;
|
||||
font-weight: 850;
|
||||
text-transform: uppercase;
|
||||
background: #eaf9fd;
|
||||
border: 1px solid #c5edf7;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.export-format-slider {
|
||||
position: relative;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
height: 38px;
|
||||
padding: 3px;
|
||||
overflow: hidden;
|
||||
background: #edf2f5;
|
||||
border: 1px solid #dbe4eb;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.export-format-slider::before {
|
||||
position: absolute;
|
||||
top: 3px;
|
||||
bottom: 3px;
|
||||
left: 3px;
|
||||
width: calc((100% - 6px) / 5);
|
||||
content: "";
|
||||
background: #fff;
|
||||
border: 1px solid #a9dce9;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 7px rgba(27, 65, 89, 0.12);
|
||||
transition: transform 180ms ease;
|
||||
}
|
||||
|
||||
.export-format-slider[data-format="obj"]::before {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
|
||||
.export-format-slider[data-format="step"]::before {
|
||||
transform: translateX(200%);
|
||||
}
|
||||
|
||||
.export-format-slider[data-format="svg"]::before {
|
||||
transform: translateX(300%);
|
||||
}
|
||||
|
||||
.export-format-slider[data-format="skf"]::before {
|
||||
transform: translateX(400%);
|
||||
}
|
||||
|
||||
.export-format-slider button {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
min-width: 0;
|
||||
padding: 0 5px;
|
||||
color: #6f8291;
|
||||
font-size: 11px;
|
||||
font-weight: 850;
|
||||
letter-spacing: 0.02em;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: color 160ms ease;
|
||||
}
|
||||
|
||||
.export-format-slider button:hover {
|
||||
color: #22546a;
|
||||
}
|
||||
|
||||
.export-format-slider button[aria-checked="true"] {
|
||||
color: #087f9f;
|
||||
}
|
||||
|
||||
.skf-history-section {
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.skf-history-range-control {
|
||||
position: relative;
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.skf-history-range-control::before,
|
||||
.skf-history-range-control::after {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 9px;
|
||||
height: 6px;
|
||||
content: "";
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.skf-history-range-control::before {
|
||||
right: 9px;
|
||||
background: #dbe5eb;
|
||||
box-shadow: inset 0 1px 2px rgba(40, 65, 82, 0.12);
|
||||
}
|
||||
|
||||
.skf-history-range-control::after {
|
||||
width: 0;
|
||||
background: linear-gradient(90deg, #22b9dc, #079bc2);
|
||||
transition: width 140ms ease;
|
||||
}
|
||||
|
||||
.skf-history-range-control[data-limit="100"]::after {
|
||||
width: calc(33.333333% - 6px);
|
||||
}
|
||||
|
||||
.skf-history-range-control[data-limit="50"]::after {
|
||||
width: calc(66.666667% - 12px);
|
||||
}
|
||||
|
||||
.skf-history-range-control[data-limit="30"]::after {
|
||||
width: calc(100% - 18px);
|
||||
}
|
||||
|
||||
.skf-history-range {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
height: 26px;
|
||||
margin: 0;
|
||||
appearance: none;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.skf-history-range:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.skf-history-range:focus {
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
.skf-history-range::-webkit-slider-runnable-track {
|
||||
height: 6px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.skf-history-range::-webkit-slider-thumb {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin-top: -6px;
|
||||
appearance: none;
|
||||
background: #fff;
|
||||
border: 2px solid #0ba4ca;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 2px 6px rgba(22, 82, 108, 0.25);
|
||||
}
|
||||
|
||||
.skf-history-range::-moz-range-track {
|
||||
height: 6px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.skf-history-range::-moz-range-thumb {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
background: #fff;
|
||||
border: 2px solid #0ba4ca;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 2px 6px rgba(22, 82, 108, 0.25);
|
||||
}
|
||||
|
||||
.skf-history-range:focus-visible::-webkit-slider-thumb {
|
||||
box-shadow: 0 0 0 4px rgba(11, 164, 202, 0.17), 0 2px 6px rgba(22, 82, 108, 0.25);
|
||||
}
|
||||
|
||||
.skf-history-range:focus-visible::-moz-range-thumb {
|
||||
box-shadow: 0 0 0 4px rgba(11, 164, 202, 0.17), 0 2px 6px rgba(22, 82, 108, 0.25);
|
||||
}
|
||||
|
||||
.skf-history-range-labels {
|
||||
position: relative;
|
||||
height: 14px;
|
||||
margin-top: -3px;
|
||||
}
|
||||
|
||||
.skf-history-range-labels span {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
color: #718494;
|
||||
font-size: 10px;
|
||||
font-weight: 750;
|
||||
transform: translateX(-50%);
|
||||
transition: color 140ms ease;
|
||||
}
|
||||
|
||||
.skf-history-range-labels span:first-child {
|
||||
left: 0;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.skf-history-range-labels span:nth-child(2) {
|
||||
left: calc(33.333333% + 3px);
|
||||
}
|
||||
|
||||
.skf-history-range-labels span:nth-child(3) {
|
||||
left: calc(66.666667% - 3px);
|
||||
}
|
||||
|
||||
.skf-history-range-labels span:last-child {
|
||||
right: 0;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.skf-history-range-labels span.active {
|
||||
color: #087f9f;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.export-format-summary {
|
||||
display: grid;
|
||||
gap: 5px;
|
||||
margin: 10px 14px;
|
||||
padding: 9px 11px;
|
||||
background: #eef4f7;
|
||||
border: 1px solid #dde7ed;
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.export-format-summary > div {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.export-format-summary strong {
|
||||
color: #1f3c52;
|
||||
font-size: 12px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.export-format-summary span,
|
||||
.export-format-summary p {
|
||||
margin: 0;
|
||||
color: #627789;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.export-dialog-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
padding: 10px 14px 12px;
|
||||
background: #fff;
|
||||
border-top: 1px solid #e2e9ee;
|
||||
}
|
||||
|
||||
.export-dialog-footer > div {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 9px;
|
||||
}
|
||||
|
||||
.export-dialog-footer button {
|
||||
display: inline-flex;
|
||||
min-width: 78px;
|
||||
min-height: 34px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
padding: 0 13px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
font-weight: 850;
|
||||
}
|
||||
|
||||
.export-dialog-footer .export-primary-button {
|
||||
min-width: 118px;
|
||||
color: #fff;
|
||||
background: linear-gradient(180deg, #14b4dc, #0799c1);
|
||||
border: 1px solid #078daf;
|
||||
box-shadow: 0 5px 14px rgba(4, 145, 183, 0.22);
|
||||
}
|
||||
|
||||
.export-dialog-footer .export-primary-button:hover:not(:disabled) {
|
||||
background: linear-gradient(180deg, #0eadd4, #058db2);
|
||||
}
|
||||
|
||||
.export-dialog-footer .export-primary-button:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.export-primary-button svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.top-action-panel.export-action-panel,
|
||||
.top-action-panel.import-action-panel {
|
||||
right: 10px;
|
||||
width: calc(100vw - 20px);
|
||||
}
|
||||
|
||||
.export-file-section {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.export-dialog-footer {
|
||||
align-items: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
.top-action-body {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
@@ -1999,6 +2434,65 @@ button {
|
||||
background: #eef8fc;
|
||||
}
|
||||
|
||||
.top-action-body .open-skf-project-button {
|
||||
display: grid;
|
||||
grid-template-columns: 38px minmax(0, 1fr);
|
||||
min-height: 66px;
|
||||
justify-content: stretch;
|
||||
padding: 10px 12px;
|
||||
color: #173b5a;
|
||||
background: #fff;
|
||||
border-color: #cfe2eb;
|
||||
border-radius: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.open-skf-project-button > span:last-child {
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.open-skf-project-button strong,
|
||||
.open-skf-project-button small {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.open-skf-project-button small {
|
||||
color: #667d8e;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.open-skf-project-icon {
|
||||
display: grid;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
place-items: center;
|
||||
color: #087f9f;
|
||||
background: #eaf9fd;
|
||||
border: 1px solid #c5edf7;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.import-kind-divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
color: #7a8c9a;
|
||||
font-size: 10px;
|
||||
font-weight: 800;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.import-kind-divider::before,
|
||||
.import-kind-divider::after {
|
||||
height: 1px;
|
||||
flex: 1;
|
||||
content: "";
|
||||
background: #dfe7ed;
|
||||
}
|
||||
|
||||
.top-action-body button svg,
|
||||
.top-action-body button .vector-toolbar-sprite-icon,
|
||||
.top-action-body button .toolbar-command-icon {
|
||||
@@ -2013,16 +2507,16 @@ button {
|
||||
align-content: center;
|
||||
justify-items: center;
|
||||
gap: 8px;
|
||||
padding: 17px 14px;
|
||||
padding: 20px 14px;
|
||||
color: #244057;
|
||||
background: linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(244, 248, 251, 0.96));
|
||||
border: 1.5px dashed rgba(93, 124, 150, 0.62);
|
||||
border-radius: 5px;
|
||||
background: #fff;
|
||||
border: 1.5px dashed #b8cbd8;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.top-action-body .import-drop-zone:hover {
|
||||
background: #fff;
|
||||
background: #fafeff;
|
||||
border-color: rgba(0, 159, 227, 0.76);
|
||||
box-shadow: inset 0 0 0 1px rgba(0, 159, 227, 0.12), 0 4px 14px rgba(30, 50, 70, 0.1);
|
||||
}
|
||||
|
||||
+132
-25
@@ -5,9 +5,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { SketchForgeEditor, importedShapeFromStl, importedShapeFromSvg } from "@/components/SketchForgeEditor";
|
||||
import { hydrateEditorHistoryState, type EditorHistoryEntry } from "@/lib/editorHistory";
|
||||
import { createLocalId } from "@/lib/localIds";
|
||||
import { attachProjectAsset, dedupeProjectAssets, projectAssetFromBytes, sourceFormatForFileName } from "@/lib/projectAssets";
|
||||
import { importSkfProject } from "@/lib/skfProject";
|
||||
import { importExtensionSupported } from "@/lib/stlImport";
|
||||
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings, workplaneSettingsFingerprint } from "@/lib/workplaneSettings";
|
||||
import type { GridSize, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||
import type { GridSize, ProjectAsset, WorkplaneShape, WorkplaneWorkspaceSettings } from "@/types/sketchforge";
|
||||
|
||||
type AppView = "dashboard" | "editor";
|
||||
type ViewMode = "grid" | "list";
|
||||
@@ -26,6 +28,7 @@ type DashboardProject = {
|
||||
revision?: number;
|
||||
workspace?: WorkplaneWorkspaceSettings;
|
||||
snapGrid?: GridSize;
|
||||
placementElevation?: number;
|
||||
};
|
||||
|
||||
type StoredDashboardProject = Partial<DashboardProject> & {
|
||||
@@ -37,6 +40,7 @@ type ProjectShapeCacheEntry = {
|
||||
shapes: WorkplaneShape[];
|
||||
history: EditorHistoryEntry[];
|
||||
historyIndex: number;
|
||||
assets: ProjectAsset[];
|
||||
};
|
||||
|
||||
type ProjectShapeRecord = {
|
||||
@@ -45,6 +49,7 @@ type ProjectShapeRecord = {
|
||||
shapes: WorkplaneShape[];
|
||||
history?: EditorHistoryEntry[];
|
||||
historyIndex?: number;
|
||||
assets?: ProjectAsset[];
|
||||
updatedAt: number;
|
||||
};
|
||||
|
||||
@@ -69,6 +74,7 @@ function projectShapeCacheEntry(
|
||||
shapes: WorkplaneShape[],
|
||||
history?: EditorHistoryEntry[],
|
||||
historyIndex?: number,
|
||||
assets: ProjectAsset[] = [],
|
||||
): ProjectShapeCacheEntry {
|
||||
const hydrated = hydrateEditorHistoryState(shapes, history, historyIndex);
|
||||
return {
|
||||
@@ -76,6 +82,7 @@ function projectShapeCacheEntry(
|
||||
shapes: hydrated.entries[hydrated.index]?.shapes ?? shapes,
|
||||
history: hydrated.entries,
|
||||
historyIndex: hydrated.index,
|
||||
assets: dedupeProjectAssets(assets),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -187,6 +194,7 @@ function readStoredProjects() {
|
||||
revision,
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
placementElevation: typeof project.placementElevation === "number" && Number.isFinite(project.placementElevation) ? project.placementElevation : 0,
|
||||
};
|
||||
});
|
||||
return { projects, legacyShapes };
|
||||
@@ -217,6 +225,7 @@ function mergeProjectForStorage(project: DashboardProject, storedProject?: Dashb
|
||||
updatedAt: Math.max(project.updatedAt, storedProject.updatedAt),
|
||||
workspace: project.workspace ?? storedProject.workspace,
|
||||
snapGrid: project.snapGrid ?? storedProject.snapGrid,
|
||||
placementElevation: project.placementElevation ?? storedProject.placementElevation,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -233,6 +242,7 @@ function projectForStorage(project: DashboardProject): DashboardProject {
|
||||
revision: project.revision,
|
||||
workspace: normalizeWorkspaceSettings(project.workspace),
|
||||
snapGrid: normalizeSnapGrid(project.snapGrid),
|
||||
placementElevation: typeof project.placementElevation === "number" && Number.isFinite(project.placementElevation) ? project.placementElevation : 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -254,6 +264,7 @@ function newProject(name: string, index: number, shapeCount = 0): DashboardProje
|
||||
revision: now,
|
||||
workspace: DEFAULT_WORKPLANE_WORKSPACE,
|
||||
snapGrid: DEFAULT_SNAP_GRID,
|
||||
placementElevation: 0,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -370,7 +381,7 @@ export default function Home() {
|
||||
.then((record) => {
|
||||
if (canceled) return;
|
||||
const revision = activeProject.revision ?? record?.revision ?? Date.now();
|
||||
const entry = projectShapeCacheEntry(revision, record?.shapes ?? [], record?.history, record?.historyIndex);
|
||||
const entry = projectShapeCacheEntry(revision, record?.shapes ?? [], record?.history, record?.historyIndex, record?.assets);
|
||||
setProjectShapesById((current) => ({
|
||||
...current,
|
||||
[activeProjectId]: entry,
|
||||
@@ -471,10 +482,11 @@ export default function Home() {
|
||||
shapes: WorkplaneShape[];
|
||||
history: EditorHistoryEntry[];
|
||||
historyIndex: number;
|
||||
assets: ProjectAsset[];
|
||||
}) => {
|
||||
const revision = Math.max(Date.now(), nextProjectRevisionRef.current + 1);
|
||||
nextProjectRevisionRef.current = revision;
|
||||
const entry = projectShapeCacheEntry(revision, snapshot.shapes, snapshot.history, snapshot.historyIndex);
|
||||
const entry = projectShapeCacheEntry(revision, snapshot.shapes, snapshot.history, snapshot.historyIndex, snapshot.assets);
|
||||
setProjectShapesById((current) => {
|
||||
const existing = current[snapshot.projectId];
|
||||
if (existing && existing.revision > revision) {
|
||||
@@ -512,25 +524,29 @@ export default function Home() {
|
||||
});
|
||||
}, []);
|
||||
|
||||
const updateProjectWorkspace = useCallback((snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize }) => {
|
||||
const updateProjectWorkspace = useCallback((snapshot: { projectId: string; workspace: WorkplaneWorkspaceSettings; snap: GridSize; placementElevation?: number }) => {
|
||||
const version = Date.now();
|
||||
const workspace = normalizeWorkspaceSettings(snapshot.workspace);
|
||||
const snapGrid = normalizeSnapGrid(snapshot.snap);
|
||||
const nextFingerprint = workplaneSettingsFingerprint(workspace, snapGrid);
|
||||
const placementElevation = typeof snapshot.placementElevation === "number" && Number.isFinite(snapshot.placementElevation)
|
||||
? snapshot.placementElevation
|
||||
: 0;
|
||||
const nextFingerprint = `${workplaneSettingsFingerprint(workspace, snapGrid)}:${placementElevation}`;
|
||||
setProjects((current) => {
|
||||
let changed = false;
|
||||
const next = current.map((project) => {
|
||||
if (project.id !== snapshot.projectId) return project;
|
||||
const currentFingerprint = workplaneSettingsFingerprint(
|
||||
const currentFingerprint = `${workplaneSettingsFingerprint(
|
||||
normalizeWorkspaceSettings(project.workspace),
|
||||
normalizeSnapGrid(project.snapGrid),
|
||||
);
|
||||
)}:${project.placementElevation ?? 0}`;
|
||||
if (currentFingerprint === nextFingerprint) return project;
|
||||
changed = true;
|
||||
return {
|
||||
...project,
|
||||
workspace,
|
||||
snapGrid,
|
||||
placementElevation,
|
||||
updatedAt: version,
|
||||
};
|
||||
});
|
||||
@@ -551,34 +567,119 @@ export default function Home() {
|
||||
openEditor(project.id, { allowMissingFromStorage: true });
|
||||
};
|
||||
|
||||
const importFileFromDashboard = useCallback(
|
||||
async (file: File) => {
|
||||
const isSvg = /\.svg$/i.test(file.name) || file.type === "image/svg+xml";
|
||||
if (!isSvg && !importExtensionSupported(file.name)) {
|
||||
setDashboardNotice("Unsupported file type. Use STL or SVG.");
|
||||
const openSkfProjectFromFile = useCallback(async (file: File) => {
|
||||
setDashboardNotice(`Validating ${file.name} before opening it as a new project`);
|
||||
try {
|
||||
const restored = await importSkfProject(await file.arrayBuffer());
|
||||
const now = Date.now();
|
||||
const project: DashboardProject = {
|
||||
...newProject(restored.projectName, projects.length, restored.shapes.length),
|
||||
createdAt: restored.createdAt,
|
||||
updatedAt: now,
|
||||
revision: now,
|
||||
workspace: restored.workspace,
|
||||
snapGrid: restored.snapGrid,
|
||||
placementElevation: restored.placementElevation,
|
||||
};
|
||||
const entry = projectShapeCacheEntry(now, restored.shapes, restored.history, restored.historyIndex, restored.assets);
|
||||
await saveProjectShapes(project.id, entry);
|
||||
setProjectShapesById((current) => ({ ...current, [project.id]: entry }));
|
||||
setProjects((current) => [project, ...current]);
|
||||
setDashboardNotice(`Opened ${file.name} as a new editable local project`);
|
||||
openEditor(project.id, { allowMissingFromStorage: true });
|
||||
return { ok: true, message: `Opened ${file.name} as a new editable local project` };
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Could not open SketchForge project";
|
||||
setDashboardNotice(message);
|
||||
return { ok: false, message };
|
||||
}
|
||||
}, [projects.length]);
|
||||
|
||||
const importFilesFromDashboard = useCallback(
|
||||
async (files: File[]) => {
|
||||
if (!files.length) return;
|
||||
const projectFiles = files.filter((file) => /\.skf$/i.test(file.name));
|
||||
if (projectFiles.length) {
|
||||
if (files.length !== 1) {
|
||||
setDashboardNotice("Open one .skf project at a time; import STL, STEP, and SVG geometry separately");
|
||||
return;
|
||||
}
|
||||
await openSkfProjectFromFile(projectFiles[0]);
|
||||
return;
|
||||
}
|
||||
const importedShapes: WorkplaneShape[] = [];
|
||||
const importedAssets: ProjectAsset[] = [];
|
||||
const importedFileNames: string[] = [];
|
||||
const failures: Array<{ fileName: string; reason: string }> = [];
|
||||
|
||||
for (let index = 0; index < files.length; index += 1) {
|
||||
const file = files[index];
|
||||
const sourceFormat = sourceFormatForFileName(file.name) ?? (file.type === "image/svg+xml" ? "svg" : null);
|
||||
const isSvg = sourceFormat === "svg";
|
||||
const isStep = sourceFormat === "step";
|
||||
if (!sourceFormat || sourceFormat === "obj" || (!isSvg && !isStep && !importExtensionSupported(file.name))) {
|
||||
failures.push({ fileName: file.name, reason: "Unsupported file type" });
|
||||
continue;
|
||||
}
|
||||
|
||||
setDashboardNotice(`Importing ${index + 1} of ${files.length}: ${file.name}`);
|
||||
try {
|
||||
const bytes = new Uint8Array(await file.arrayBuffer());
|
||||
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
||||
const parsedShape = isStep
|
||||
? await import("@/lib/stepImport").then(({ importedShapeFromStep }) => importedShapeFromStep(file.name, buffer))
|
||||
: isSvg
|
||||
? importedShapeFromSvg(file.name, new TextDecoder().decode(bytes))
|
||||
: importedShapeFromStl(file.name, buffer);
|
||||
const asset = await projectAssetFromBytes(file.name, sourceFormat, bytes, file.type);
|
||||
importedShapes.push(attachProjectAsset(parsedShape, asset.id));
|
||||
importedAssets.push(asset);
|
||||
importedFileNames.push(file.name);
|
||||
} catch (error) {
|
||||
failures.push({
|
||||
fileName: file.name,
|
||||
reason: error instanceof Error ? error.message : "Could not read file",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const failureDetails = failures
|
||||
.slice(0, 3)
|
||||
.map((failure) => `${failure.fileName}: ${failure.reason}`)
|
||||
.join("; ");
|
||||
const remainingFailureCount = Math.max(0, failures.length - 3);
|
||||
const failureSummary = failures.length
|
||||
? ` Failed: ${failureDetails}${remainingFailureCount ? `; plus ${remainingFailureCount} more` : ""}`
|
||||
: "";
|
||||
|
||||
if (!importedShapes.length) {
|
||||
setDashboardNotice(files.length === 1 && failures[0] ? failures[0].reason : `Could not import any of the ${files.length} selected files.${failureSummary}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const shape = isSvg
|
||||
? importedShapeFromSvg(file.name, await file.text())
|
||||
: importedShapeFromStl(file.name, await file.arrayBuffer());
|
||||
const project = newProject(projectNameFromFileName(file.name), projects.length, 1);
|
||||
const projectName = importedShapes.length === 1
|
||||
? projectNameFromFileName(importedFileNames[0])
|
||||
: `Imported design (${importedShapes.length} files)`;
|
||||
const project = newProject(projectName, projects.length, importedShapes.length);
|
||||
const revision = project.revision ?? project.updatedAt;
|
||||
const entry = projectShapeCacheEntry(revision, [shape]);
|
||||
const entry = projectShapeCacheEntry(revision, importedShapes, undefined, undefined, dedupeProjectAssets(importedAssets));
|
||||
await saveProjectShapes(project.id, entry);
|
||||
setProjectShapesById((current) => ({
|
||||
...current,
|
||||
[project.id]: entry,
|
||||
}));
|
||||
setDashboardNotice(`Imported ${file.name}`);
|
||||
const successSummary = importedShapes.length === 1 && files.length === 1
|
||||
? `Imported ${files[0].name}`
|
||||
: `Imported ${importedShapes.length} of ${files.length} files`;
|
||||
setDashboardNotice(`${successSummary}.${failureSummary}`.trim());
|
||||
setProjects((current) => [project, ...current]);
|
||||
openEditor(project.id, { allowMissingFromStorage: true });
|
||||
} catch (error) {
|
||||
setDashboardNotice(error instanceof Error ? error.message : `Could not import ${file.name}`);
|
||||
setDashboardNotice(error instanceof Error ? error.message : "Could not create a project for the imported files");
|
||||
}
|
||||
},
|
||||
[projects.length],
|
||||
[openSkfProjectFromFile, projects.length],
|
||||
);
|
||||
|
||||
const openLatestProject = () => {
|
||||
@@ -653,11 +754,12 @@ export default function Home() {
|
||||
ref={dashboardImportInputRef}
|
||||
className="hidden-file-input"
|
||||
type="file"
|
||||
accept=".stl,.svg,image/svg+xml"
|
||||
multiple
|
||||
accept=".skf,.stl,.step,.stp,.svg,image/svg+xml"
|
||||
onChange={(event) => {
|
||||
const file = event.currentTarget.files?.[0];
|
||||
if (file) {
|
||||
void importFileFromDashboard(file);
|
||||
const files = event.currentTarget.files ? Array.from(event.currentTarget.files) : [];
|
||||
if (files.length) {
|
||||
void importFilesFromDashboard(files);
|
||||
}
|
||||
event.currentTarget.value = "";
|
||||
}}
|
||||
@@ -697,17 +799,22 @@ export default function Home() {
|
||||
{editorStarted && canRenderEditor ? (
|
||||
<div className={view === "editor" ? "editor-stage active" : "editor-stage"} aria-hidden={view !== "editor"}>
|
||||
<SketchForgeEditor
|
||||
initialAssets={activeProjectShapeEntry?.assets ?? []}
|
||||
initialShapes={activeProjectShapeEntry?.shapes ?? []}
|
||||
initialHistory={activeProjectShapeEntry?.history}
|
||||
initialHistoryIndex={activeProjectShapeEntry?.historyIndex}
|
||||
initialSnap={activeProject?.snapGrid ?? DEFAULT_SNAP_GRID}
|
||||
initialWorkspace={activeProject?.workspace ?? DEFAULT_WORKPLANE_WORKSPACE}
|
||||
initialPlacementElevation={activeProject?.placementElevation ?? 0}
|
||||
onHome={openDashboard}
|
||||
onOpenSkfProjectFile={openSkfProjectFromFile}
|
||||
onProjectShapesChange={updateProjectShapes}
|
||||
onProjectSnapshot={updateProjectSnapshot}
|
||||
onProjectWorkspaceChange={updateProjectWorkspace}
|
||||
projectId={activeProjectId}
|
||||
projectName={activeProject?.name}
|
||||
projectCreatedAt={activeProject?.createdAt}
|
||||
projectModifiedAt={activeProject?.updatedAt}
|
||||
projectRevision={activeProjectShapeEntry?.revision ?? activeProject?.revision ?? 0}
|
||||
/>
|
||||
</div>
|
||||
@@ -858,7 +965,7 @@ function Dashboard({
|
||||
<span className="dashboard-action-icon">
|
||||
<FileUp size={24} strokeWidth={2.4} />
|
||||
</span>
|
||||
<span>Import STL/SVG</span>
|
||||
<span>Open SKF or import geometry</span>
|
||||
</button>
|
||||
<button className="dashboard-action-tile" type="button" onClick={onWorkspace}>
|
||||
<span className="dashboard-action-icon">
|
||||
|
||||
Reference in New Issue
Block a user