task(A4.9): migrate event domain tools (chair/row/block/table/stage) to v2

This commit is contained in:
Agent Zero
2026-08-27 01:12:52 +02:00
parent cf67635732
commit 76f305fc6f
3 changed files with 135 additions and 1 deletions
@@ -0,0 +1,78 @@
/**
* event-tools Built-in V2-Plugin (Task A4.9).
*
* Fachwerkzeuge für Veranstaltungsplanung: chair, seating-row,
* seating-block, table, stage — alle Einzelklick-Platzierer über
* den (durch BUG-1-Fix korrigierten) SeatingService.
*
* Jede Platzierung = doc.transact → 1 Undo-Schritt (Multi-Element-Sets
* wie seating-block erscheinen/verschwinden gemeinsam).
*/
import type { PluginV2, ToolExtensionV2, FullToolContext } from '../../types';
import type { CADElement } from '../../../types/cad.types';
import { SeatingService } from '../../../services/seatingService';
const seating = new SeatingService();
/** Erzeugt ein Einzelklick-Platzierer-Werkzeug über einen placer. */
function makePlaceTool(
id: string,
label: string,
icon: string,
placer: (x: number, y: number, layerId: string) => CADElement | CADElement[],
statusNoun: string,
): ToolExtensionV2 {
return {
manifest: {
id,
label,
icon,
ribbonTab: 'insert',
tags: ['basic'],
description: `${statusNoun} per Klick platzieren`,
},
optionsSchema: [],
handlers: {
down(e, ctx) {
const c = ctx as FullToolContext;
if (!c.doc) return;
const layerId = (c.options.layerId as string | undefined) ?? 'layer-0';
const placed = placer(e.world.x, e.world.y, layerId);
const els = Array.isArray(placed) ? placed : [placed];
c.doc.transact(() => {
for (const el of els) c.doc!.addElement(el);
});
ctx.setStatus(`${statusNoun} platziert (${els.length} Element${els.length === 1 ? '' : 'e'})`);
},
},
};
}
export const chairTool = makePlaceTool('chair', 'Stuhl', '\u2570',
(x, y, layerId) => seating.createChair(x, y, layerId), 'Stuhl');
export const seatingRowTool = makePlaceTool('seating-row', 'Stuhldreihe', '\u2500\u2570\u2500',
(x, y, layerId) => seating.createSeatingRow(x, y, layerId), 'Reihe');
export const seatingBlockTool = makePlaceTool('seating-block', 'Stuhlblock', '\u2565',
(x, y, layerId) => seating.createSeatingBlock(x, y, layerId), 'Block');
export const tableTool = makePlaceTool('table', 'Tisch', '\u25cb',
(x, y, layerId) => seating.createTable(x, y, layerId), 'Tisch');
export const stageTool = makePlaceTool('stage', 'Bühne', '\u25ad',
(x, y, layerId) => seating.createStage(x, y, layerId), 'Bühne');
/** V2-Plugin: Event-Domain (Task A4.9). */
export const eventToolsV2Plugin: PluginV2 = {
manifest: {
id: 'event-tools',
name: 'Event-Bestuhlung',
version: '2.0.0',
author: 'web-cad team',
description: 'Stühle, Reihen, Blöcke, Tische, Bühne (V2).',
category: 'elements',
enabledByDefault: true,
},
tools: [chairTool, seatingRowTool, seatingBlockTool, tableTool, stageTool],
};
+3
View File
@@ -31,6 +31,7 @@ export { coreDrawingPlugin } from './builtin/core-drawing';
export { coreModifyPlugin } from './builtin/core-modify';
export { coreAnnotatePlugin } from './builtin/core-annotate';
export { coreMeasurePlugin } from './builtin/core-measure';
export { eventToolsV2Plugin } from './builtin/event-tools';
import { pluginRegistry } from './PluginRegistry';
import { eventToolsPlugin } from './builtin/eventTools';
@@ -38,6 +39,7 @@ import { coreDrawingPlugin } from './builtin/core-drawing';
import { coreModifyPlugin } from './builtin/core-modify';
import { coreAnnotatePlugin } from './builtin/core-annotate';
import { coreMeasurePlugin } from './builtin/core-measure';
import { eventToolsV2Plugin } from './builtin/event-tools';
/** Register all built-in plugins */
export function registerBuiltinPlugins() {
@@ -47,4 +49,5 @@ export function registerBuiltinPlugins() {
pluginRegistry.registerV2(coreModifyPlugin);
pluginRegistry.registerV2(coreAnnotatePlugin);
pluginRegistry.registerV2(coreMeasurePlugin);
pluginRegistry.registerV2(eventToolsV2Plugin);
}