Files
Aislo/B07_DesignDetail/openwebcad/src/helpers/undo-stack.ts
T
eomsangdonandClaude Fable 5 6e195afb69 feat(B07,B08): 워크플로 순서 교환 — 상세설계를 수량산출 앞으로
횡단설계(B06) 다음을 상세설계 → 수량산출 → 설계도서 순으로 재배열하고,
폴더 번호가 흐름과 일치하도록 이름을 맞바꾼다.

- B08_DesignDetail → B07_DesignDetail, B07_Quantity → B08_Quantity
  (파일 접두어·식별자·라우트·locale 키 전량 스왑)
- STAGE_KEYS 4=DESIGN_DETAIL, 5=QUANTITY 스왑 + 라우터 stage 리터럴 교체
- CAD 마운트 /b08-cad → /b07-cad (main.py·vite proxy·iframe URL),
  openwebcad Toolbar 라벨 B07로 수정 후 재빌드
- 유지: openwebcad postMessage 프로토콜 aislo:b08:*·패키지명(내부 식별자)
- 기존 프로젝트 storage 폴더 rename + project_manifest 갱신,
  DB project_workflow_stages stage_no 4↔5 행 스왑 완료

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-29 16:16:46 +09:00

85 lines
2.2 KiB
TypeScript

export interface UndoState {
variable: StateVariable;
// biome-ignore lint/suspicious/noExplicitAny: TODO list all undo state types
value: any;
}
export enum StateVariable {
canvasSize = 'canvasSize',
canvas = 'canvas',
context = 'context',
screenMouseLocation = 'screenMouseLocation',
activeTool = 'activeTool',
entities = 'entities',
activeEntity = 'activeEntity',
shouldDrawCursor = 'shouldDrawCursor',
helperEntities = 'helperEntities',
debugEntities = 'debugEntities',
angleStep = 'angleStep',
screenOffset = 'screenOffset',
screenZoom = 'screenZoom',
panStartLocation = 'panStartLocation',
snapPoint = 'snapPoint',
snapPointOnAngleGuide = 'snapPointOnAngleGuide',
hoveredSnapPoints = 'hoveredSnapPoints',
lastDrawTimestamp = 'lastDrawTimestamp',
activeLineColor = 'activeLineColor',
activeLineWidth = 'activeLineWidth',
activeLineDash = 'activeLineDash',
activeTextStyle = 'activeTextStyle',
designMeta = 'designMeta',
layers = 'layers',
}
/**
* Based on https://github.com/wobsoriano/undo-stacker
*/
export function createStack() {
let stack: UndoState[] = [];
let index = stack.length;
function peek() {
return stack[index - 1];
}
return {
push: (value: UndoState) => {
stack.length = index;
stack[index++] = value;
// console.log('stack push', JSON.stringify(stack, null, 2));
return peek();
},
replace: (value: UndoState) => {
stack[index - 1] = value;
// console.log('stack replace', JSON.stringify(stack, null, 2));
return peek();
},
peek: () => {
return peek();
},
undo: () => {
if (index > 1) index -= 1;
// console.log('stack undo', JSON.stringify(stack, null, 2));
return peek();
},
redo: () => {
if (index < stack.length) index += 1;
// console.log('stack redo', JSON.stringify(stack, null, 2));
return peek();
},
// Clear certain states from the undo stack
clear: (variable: StateVariable) => {
// Update the index be reducing it by the number of states that are removed to the left of the index
index = index - stack.slice(0, index).filter((state) => state.variable === variable).length;
stack = stack.filter((state) => state.variable !== variable);
},
};
}