파일마다 포맷 폭이 달라(≈80 대 100) 한 줄만 고쳐도 포맷터가 무관한 줄을 대량 재포맷했음. 사용자 지시로 전체를 한 번에 맞춤. 코드 동작 변경 없음 — 포맷만. - 프론트엔드 `.ts/.css/.html` → 저장소 prettier (`.prettierrc`, printWidth 100) - `B07_DesignDetail/openwebcad/**` → 자체 biome (tab 들여쓰기·single quote·lineWidth 100). `biome format` 만 사용 — `biome lint --write` 는 포맷 아닌 코드 수정까지 하므로 제외 - 파이썬 → `ruff format` (엔진 코드는 이미 정합, resources·scratch 스크립트 24개만 변경) 두 포맷터가 서로 되돌리지 않도록 `.prettierignore` 신규 — openwebcad 와 빌드·산출물 폴더를 prettier 대상에서 뺌. `.prettierrc` 에 `endOfLine: "auto"` 추가 — 기본값 `lf` 가 `core.autocrlf=true` 로 받은 CRLF 파일을 매번 전부 다시 써서 `--list-different` 가 실제 포맷 차이를 가리고 있었음. 검증: `tsc --noEmit` 통과(루트·openwebcad 둘 다), pytest 349 passed / 17 skipped / 0 failed, CAD vitest 87건 중 81 passed / 6 failed(laptop-sub 기준선과 동일, 회귀 없음). 포맷터 재실행 시 prettier·biome 모두 변경 0건. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
182 lines
4.9 KiB
TypeScript
182 lines
4.9 KiB
TypeScript
import type { Point } from '@flatten-js/core';
|
|
import {
|
|
getNotSelectedEntities,
|
|
setEntities,
|
|
setGhostHelperEntities,
|
|
setSelectedEntityIds,
|
|
setShouldDrawHelpers,
|
|
} from '../state';
|
|
import type { DrawEvent, MouseClickEvent, StateEvent, ToolContext } from './tool.types';
|
|
import { Tool } from '../tools';
|
|
import { assign, createMachine } from 'xstate';
|
|
import {
|
|
drawTempSelectionRectangle,
|
|
handleFirstSelectionPoint,
|
|
selectEntitiesInsideRectangle,
|
|
} from './select-tool.helpers';
|
|
|
|
export interface SelectContext extends ToolContext {
|
|
startPoint: Point | null;
|
|
}
|
|
|
|
export enum SelectState {
|
|
INIT = 'INIT',
|
|
WAITING_FOR_FIRST_SELECT_POINT = 'WAITING_FOR_FIRST_SELECT_POINT',
|
|
CHECK_SELECTION = 'CHECK_SELECTION',
|
|
WAITING_FOR_SECOND_SELECT_POINT = 'WAITING_FOR_SECOND_SELECT_POINT',
|
|
SELECTION_COMPLETED = 'SELECTION_COMPLETED',
|
|
}
|
|
|
|
export enum SelectAction {
|
|
INIT_SELECT_TOOL = 'INIT_SELECT_TOOL',
|
|
HANDLE_FIRST_SELECT_POINT = 'HANDLE_FIRST_SELECT_POINT',
|
|
SELECT_ENTITIES_INSIDE_RECTANGLE = 'SELECT_ENTITIES_INSIDE_RECTANGLE',
|
|
DRAW_TEMP_SELECTION_RECTANGLE = 'DRAW_TEMP_SELECTION_RECTANGLE',
|
|
DELETE_SELECTED_ENTITIES = 'DELETE_SELECTED_ENTITIES',
|
|
}
|
|
|
|
export const selectToolStateMachine = createMachine(
|
|
{
|
|
types: {} as {
|
|
context: SelectContext;
|
|
events: StateEvent;
|
|
},
|
|
context: {
|
|
startPoint: null,
|
|
type: Tool.SELECT,
|
|
},
|
|
initial: SelectState.INIT,
|
|
states: {
|
|
[SelectState.INIT]: {
|
|
description: 'Initializing the select tool',
|
|
always: {
|
|
actions: SelectAction.INIT_SELECT_TOOL,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
},
|
|
[SelectState.WAITING_FOR_FIRST_SELECT_POINT]: {
|
|
description: 'Select a line or select the first point of a selection rectangle',
|
|
meta: {
|
|
instructions: 'Select a line or start drawing a selection rectangle',
|
|
},
|
|
on: {
|
|
MOUSE_CLICK: {
|
|
actions: SelectAction.HANDLE_FIRST_SELECT_POINT,
|
|
target: SelectState.CHECK_SELECTION,
|
|
},
|
|
ESC: {
|
|
actions: SelectAction.INIT_SELECT_TOOL,
|
|
},
|
|
ENTER: {
|
|
target: SelectState.SELECTION_COMPLETED,
|
|
},
|
|
DELETE: {
|
|
actions: SelectAction.DELETE_SELECTED_ENTITIES,
|
|
target: SelectState.INIT,
|
|
},
|
|
},
|
|
},
|
|
[SelectState.CHECK_SELECTION]: {
|
|
description: 'Checking to select one line or start drawing a selection rectangle',
|
|
meta: {
|
|
instructions: 'Select one line or start drawing a selection rectangle',
|
|
},
|
|
always: [
|
|
{
|
|
// User started drawing a selection rectangle
|
|
guard: ({ context }: { context: SelectContext }) => !!context.startPoint,
|
|
target: SelectState.WAITING_FOR_SECOND_SELECT_POINT,
|
|
},
|
|
{
|
|
// User clicked on an entity
|
|
guard: ({ context }: { context: SelectContext }) => !context.startPoint,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
],
|
|
},
|
|
[SelectState.WAITING_FOR_SECOND_SELECT_POINT]: {
|
|
description: 'Select the second point of a selection rectangle',
|
|
meta: {
|
|
instructions: 'Select the second point of a selection rectangle',
|
|
},
|
|
on: {
|
|
DRAW: {
|
|
actions: SelectAction.DRAW_TEMP_SELECTION_RECTANGLE,
|
|
},
|
|
MOUSE_CLICK: {
|
|
actions: SelectAction.SELECT_ENTITIES_INSIDE_RECTANGLE,
|
|
target: SelectState.WAITING_FOR_FIRST_SELECT_POINT,
|
|
},
|
|
ESC: {
|
|
target: SelectState.INIT,
|
|
},
|
|
},
|
|
},
|
|
[SelectState.SELECTION_COMPLETED]: {
|
|
description: 'Selection completed',
|
|
type: 'final',
|
|
},
|
|
},
|
|
},
|
|
{
|
|
actions: {
|
|
INIT_SELECT_TOOL: () => {
|
|
setShouldDrawHelpers(false);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
HANDLE_FIRST_SELECT_POINT: assign(
|
|
({ context, event }: { context: SelectContext; event: StateEvent }) => {
|
|
return handleFirstSelectionPoint(context, event as MouseClickEvent);
|
|
}
|
|
),
|
|
DRAW_TEMP_SELECTION_RECTANGLE: ({
|
|
context,
|
|
event,
|
|
}: {
|
|
context: SelectContext;
|
|
event: StateEvent;
|
|
}) => {
|
|
if (!context.startPoint) {
|
|
// assert
|
|
throw new Error('[SELECT] Calling drawTempSelectionRectangle without startPoint set');
|
|
}
|
|
drawTempSelectionRectangle(
|
|
context.startPoint as Point,
|
|
(event as DrawEvent).drawController.getWorldMouseLocation()
|
|
);
|
|
},
|
|
SELECT_ENTITIES_INSIDE_RECTANGLE: ({
|
|
context,
|
|
event,
|
|
}: {
|
|
context: SelectContext;
|
|
event: StateEvent;
|
|
}) => {
|
|
if (!context.startPoint) {
|
|
//
|
|
throw new Error('[SELECT] calling SELECT_ENTITIES_INSIDE_RECTANGLE without start point');
|
|
}
|
|
selectEntitiesInsideRectangle(
|
|
context.startPoint,
|
|
(event as MouseClickEvent).worldMouseLocation,
|
|
(event as MouseClickEvent).holdingCtrl
|
|
// (event as MouseClickEvent).holdingShift,
|
|
);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
DELETE_SELECTED_ENTITIES: () => {
|
|
setEntities(getNotSelectedEntities(), true);
|
|
setSelectedEntityIds([]);
|
|
setGhostHelperEntities([]);
|
|
},
|
|
RESET_SELECTION: assign(() => {
|
|
setGhostHelperEntities([]);
|
|
setSelectedEntityIds([]);
|
|
return {
|
|
startPoint: null,
|
|
};
|
|
}),
|
|
},
|
|
}
|
|
);
|