/** * 표 놓기(PLACETABLE · M02 41장) — 부모 화면이 보낸 표(면적산출 범위)를 커서에 붙여 따라오게 * 그리고, 누르면 그 자리(표 왼쪽 위)에 놓는다. Esc = 그만 · 놓기는 되돌리기 한 걸음. * 놓을 표는 브리지(`integration/aislo-table-bridge.ts`)가 `setPendingTable` 로 맡긴 뒤 이 명령을 켠다. */ import type { Point } from '@flatten-js/core'; import { TableEntity } from '../../entities/TableEntity'; import { addEntities, getActiveLayerId } from '../../state'; import { Tool } from '../../tools'; import { createSequenceTool } from '../factories/sequence-tool'; let pending: TableEntity | null = null; /** 다음 PLACETABLE 이 놓을 표 — 놓으면 비워진다 */ export function setPendingTable(table: TableEntity | null): void { pending = table; } export function getPendingTable(): TableEntity | null { return pending; } /** `table` 과 같은 꼴(칸 · 크기 · style.연결)을 `at`(왼쪽 위)에 둔 새 표 */ export function tableAt(table: TableEntity, at: Point, layerId: string): TableEntity { const placed = new TableEntity( layerId, at.clone(), table.getColumnWidths(), table.getRowHeights(), table.getCells().map((row) => row.map((cell) => (cell ? { ...cell } : null))), table.getStyle() ); placed.lineColor = table.lineColor; placed.lineWidth = table.lineWidth; return placed; } export const placeTableToolStateMachine = createSequenceTool({ tool: Tool.PLACETABLE, steps: [{ kind: 'point', instructions: '표를 놓을 자리(왼쪽 위)를 누르십시오 · Esc 그만.' }], helpers: true, restart: false, preview: (input) => (pending ? [tableAt(pending, input.cursor, getActiveLayerId())] : []), commit: (input) => { if (!pending) return; addEntities([tableAt(pending, input.point(0), getActiveLayerId())], true); pending = null; }, });