[K4][6][8] S3/S4: Öffnen/Neu laden im Kern, Importe als Ops, diffToOps gelöscht

Öffnen/Vorlage/Wiederherstellen: Store openProjectFile (Kern liest, migriert, lädt
direkt ins Dokument, Verlauf leer); Neu/Musterhaus: loadProject (doc_load_json).
Autosave sichert den Datei-Text des Kerns, Wiederherstellen lädt ihn wie eine Datei.
CLI/MCP laden ins gemeinsame Abfrage-Dokument. DXF/PDF-Import als Ops in einer Gruppe
(ein Undo-Schritt), Bilder und IFC-Bauteile als Ops, CLI-Importe über fieldOps/addItems.
setProject/CommandResult.commit/ToolResult.commit nehmen nur noch ProjectMutation;
diffToOps, isOpsMutation, addNewElementsToActiveGroup, project_parse gelöscht.
documentFor folgt fremden Projekten feldweise (fieldOps). Tests: Laden/Speichern
zeichengleich zu JSON.stringify, Store-Laden, e2e Öffnen leert Verlauf und
DXF-Import = ein Schritt; Zufallsänderungen in Tests über projectDiff.testutil.
This commit is contained in:
Claude committed 2026-10-29 04:19:56 +00:00
1 parent 77b45c13a1
commit 256b7c0b4b
37 files changed
+582 -485

No files matched your search

+3 -3
View File
@@ -7,7 +7,7 @@ import type { Command, CommandContext, CmdInput } from "../types";
import { explodeOps } from "../../editors/explode";
import { translateOps, translateProject } from "../../model/geoRebase";
import { applyOps } from "../../core/ops";
import { isOpsMutation } from "../../core";
import type { ProjectMutation } from "../../core";
import { joinCommand } from "./join";
import { defblockCommand } from "./defblock";
import { terrainCommand } from "./terrain";
@@ -45,13 +45,13 @@ function ctxOf(p: Project, ids: string[] = []): CommandContext {
function commitOf(cmd: Command, p: Project, inputs: CmdInput[], ids: string[] = []): { out: Project; viaOps: boolean } {
const ctx = ctxOf(p, ids);
let st = cmd.init();
let fn: ((p: Project) => Project) | undefined = cmd.autoRun?.(ctx).commit;
let fn: ProjectMutation | undefined = cmd.autoRun?.(ctx).commit;
for (const input of inputs) {
const [ns, res] = cmd.onInput(st, input, ctx);
st = ns;
if (res.commit) fn = res.commit;
}
return { out: fn ? fn(p) : p, viaOps: fn ? isOpsMutation(fn) : true };
return { out: fn ? fn(p) : p, viaOps: fn ? typeof fn.toOps === "function" : true };
}
describe("Editier-Befehle: Ops", () => {
+3 -2
View File
@@ -13,8 +13,9 @@
// Zustandsänderung ruft sie `emit()` → React-Komponenten (CommandLine, App)
// abonnieren via subscribe() und re-rendern.
import type { Project, Vec2 } from "../model/types";
import type { Vec2 } from "../model/types";
import type { SnapResult, ToolDraft } from "../tools/types";
import type { ProjectMutation } from "../core";
import { parseInput, resolvePoint } from "./parseInput";
import { getCommand, resolveCommand, autocomplete } from "./registry";
import type {
@@ -49,7 +50,7 @@ export interface EngineHost {
/** Vorschau setzen (oder löschen). */
setDraft(draft: ToolDraft | null): void;
/** Commit immutabel anwenden. */
commit(mutate: (p: Project) => Project): void;
commit(mutate: ProjectMutation): void;
/** Ist die aktive Ebene ein Geschoss? (für floorOnly-Befehle). */
isFloor(): boolean;
/**
+3 -2
View File
@@ -6,7 +6,8 @@ import { describe, expect, it } from "vitest";
import { COMMANDS } from "./registry";
import type { CmdInput, CommandContext } from "./types";
import { sampleProject } from "../model/sampleProject";
import { applyOps, diffToOps, validateOps } from "../core/ops";
import { applyOps, validateOps } from "../core/ops";
import { projectDiffOps } from "../core/projectDiff.testutil";
const level = sampleProject.drawingLevels.find((l) => l.kind === "floor")!;
const ctx: CommandContext = {
@@ -76,7 +77,7 @@ describe("Befehle mit feindlichen Eingaben", () => {
else [state, res] = cmd.onInput(state, hostile(opts), ctx);
if (res?.commit) {
const next = res.commit(sampleProject);
const ops = diffToOps(sampleProject, next);
const ops = projectDiffOps(sampleProject, next);
const applied = applyOps(sampleProject, ops);
validateOps(applied, ops, sampleProject); // darf melden, aber nicht werfen
}
+3 -2
View File
@@ -13,6 +13,7 @@ import type { Project, Vec2 } from "../model/types";
import type { TranslationKey } from "../i18n";
import type { DrawingLevel } from "../model/types";
import type { SnapResult, ToolDraft } from "../tools/types";
import type { ProjectMutation } from "../core";
export type { DraftShape, SnapResult, ToolDraft } from "../tools/types";
@@ -112,8 +113,8 @@ export interface CommandContext {
export interface CommandResult {
/** Neuer Vorschau-Zustand; null = nichts zu zeigen. */
draft: ToolDraft | null;
/** Bei Abschluss: immutable Mutation, die die Engine über setProject anwendet. */
commit?: (p: Project) => Project;
/** Bei Abschluss: Änderung mit mitgeführten Ops (`opsMutation`), die die Engine über setProject anwendet. */
commit?: ProjectMutation;
/** true → Befehl ist fertig und kehrt in den Ruhezustand zurück. */
done?: boolean;
/**