refactor(commands): centralize command ids
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import { toolCommands } from "@commands/tool";
|
||||
import { viewportCommands } from "@commands/viewport";
|
||||
import { createCommandRegistry } from "@commands/registry";
|
||||
@@ -29,7 +30,7 @@ describe("viewport pan store integration", () => {
|
||||
expect(controller.pointerMove(pointerEvent({ buttons: 1, position: { x: 10, y: 0 } }))).toBe(false);
|
||||
expect(store.getState().editor.viewport.center).toEqual({ x: 0, y: 0 });
|
||||
|
||||
store.dispatch("tool.enterTemporaryPan", undefined);
|
||||
store.dispatch(commandIds.toolEnterTemporaryPan, undefined);
|
||||
|
||||
expect(controller.pointerDown(pointerEvent({ buttons: 1, position: { x: 0, y: 0 } }))).toBe(true);
|
||||
expect(controller.pointerMove(pointerEvent({ buttons: 1, position: { x: 10, y: 0 } }))).toBe(true);
|
||||
@@ -40,7 +41,7 @@ describe("viewport pan store integration", () => {
|
||||
const store = createAppStore(createInitialAppState("Test"), registry);
|
||||
const controller = createController(store);
|
||||
|
||||
store.dispatch("tool.setActive", { tool: "pan" });
|
||||
store.dispatch(commandIds.toolSetActive, { tool: "pan" });
|
||||
|
||||
expect(controller.pointerDown(pointerEvent({ buttons: 1, position: { x: 0, y: 0 } }))).toBe(true);
|
||||
expect(controller.pointerMove(pointerEvent({ buttons: 1, position: { x: 4, y: -2 } }))).toBe(true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import { createViewportPanInputController } from "./viewport-pan";
|
||||
|
||||
const ignoredState = undefined as never;
|
||||
@@ -20,8 +21,8 @@ describe("viewport pan input controller", () => {
|
||||
expect(controller.keyDown(keyEvent("Space"))).toBe(true);
|
||||
expect(controller.keyUp(keyEvent("Space"))).toBe(true);
|
||||
expect(dispatched).toEqual([
|
||||
{ commandId: "tool.enterTemporaryPan", payload: undefined },
|
||||
{ commandId: "tool.exitTemporaryPan", payload: undefined },
|
||||
{ commandId: commandIds.toolEnterTemporaryPan, payload: undefined },
|
||||
{ commandId: commandIds.toolExitTemporaryPan, payload: undefined },
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Dispatch } from "@commands/dispatcher";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import type { GlobalKeybindConsumer, KeybindEvent } from "./keyboard";
|
||||
import type { GlobalPointerConsumer, PointerInputEvent } from "./pointer";
|
||||
import { createViewportPointerPanHandler } from "./viewport";
|
||||
@@ -31,13 +32,13 @@ export function createViewportPanInputController(options: {
|
||||
if (options.globalKeyConsumer(event)) return true;
|
||||
if (event.code !== "Space") return false;
|
||||
|
||||
options.dispatch("tool.enterTemporaryPan", undefined);
|
||||
options.dispatch(commandIds.toolEnterTemporaryPan, undefined);
|
||||
return true;
|
||||
},
|
||||
keyUp(event) {
|
||||
if (event.code !== "Space") return false;
|
||||
|
||||
options.dispatch("tool.exitTemporaryPan", undefined);
|
||||
options.dispatch(commandIds.toolExitTemporaryPan, undefined);
|
||||
return true;
|
||||
},
|
||||
pointerDown: pointerPan.pointerDown,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import { createViewportPointerPanHandler, handleViewportWheel } from "./viewport";
|
||||
|
||||
const ignoredState = undefined as never;
|
||||
@@ -17,7 +18,7 @@ describe("viewport input", () => {
|
||||
});
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(dispatched[0]).toEqual({ commandId: "viewport.zoomAroundPoint", payload: { zoom: Math.exp(0.1), point: { x: 10, y: 20 } } });
|
||||
expect(dispatched[0]).toEqual({ commandId: commandIds.viewportZoomAroundPoint, payload: { zoom: Math.exp(0.1), point: { x: 10, y: 20 } } });
|
||||
});
|
||||
|
||||
test("global wheel consumer prevents command dispatch", () => {
|
||||
@@ -49,7 +50,7 @@ describe("viewport input", () => {
|
||||
|
||||
expect(pan.pointerDown(basePointer({ buttons: 4, position: { x: 10, y: 10 } }))).toBe(true);
|
||||
expect(pan.pointerMove(basePointer({ buttons: 4, position: { x: 14, y: 6 } }))).toBe(true);
|
||||
expect(dispatched[0]).toEqual({ commandId: "viewport.pan", payload: { delta: { x: -2, y: 2 } } });
|
||||
expect(dispatched[0]).toEqual({ commandId: commandIds.viewportPan, payload: { delta: { x: -2, y: 2 } } });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Dispatch } from "@commands/dispatcher";
|
||||
import { commandIds } from "@commands/ids";
|
||||
import type { GlobalPointerConsumer, GlobalWheelConsumer, PointerInputEvent, WheelInputEvent } from "./pointer";
|
||||
|
||||
export type ViewportPointerPanHandler = {
|
||||
@@ -37,7 +38,7 @@ export function createViewportPointerPanHandler(options: {
|
||||
};
|
||||
|
||||
lastPosition = event.position;
|
||||
options.dispatch("viewport.pan", {
|
||||
options.dispatch(commandIds.viewportPan, {
|
||||
delta: {
|
||||
x: -screenDelta.x / zoom,
|
||||
y: -screenDelta.y / zoom,
|
||||
@@ -69,7 +70,7 @@ export function handleViewportWheel(options: {
|
||||
if (options.globalConsumer(options.event)) return true;
|
||||
|
||||
const zoomFactor = Math.exp(-options.event.delta.y * 0.001);
|
||||
options.dispatch("viewport.zoomAroundPoint", {
|
||||
options.dispatch(commandIds.viewportZoomAroundPoint, {
|
||||
zoom: options.currentZoom * zoomFactor,
|
||||
point: options.event.position,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user