feat(editor): add tool interaction state
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
export type { AppState, EditorState, SelectionState, ViewportState } from "./state";
|
export type { AppState, EditorState, SelectionState, ViewportState } from "./state";
|
||||||
|
export type { InteractionMode, ToolId, ToolState } from "./tools";
|
||||||
|
export { initialToolState } from "./tools";
|
||||||
export { createInitialAppState, initialEditorState } from "./initial-state";
|
export { createInitialAppState, initialEditorState } from "./initial-state";
|
||||||
export type { AppStore, StateListener } from "./store";
|
export type { AppStore, StateListener } from "./store";
|
||||||
export { createAppStore } from "./store";
|
export { createAppStore } from "./store";
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { AppState, EditorState } from "./state";
|
import type { AppState, EditorState } from "./state";
|
||||||
|
import { initialToolState } from "./tools";
|
||||||
|
|
||||||
export const initialEditorState: EditorState = {
|
export const initialEditorState: EditorState = {
|
||||||
viewport: {
|
viewport: {
|
||||||
@@ -10,6 +11,7 @@ export const initialEditorState: EditorState = {
|
|||||||
selection: {
|
selection: {
|
||||||
layerIds: [],
|
layerIds: [],
|
||||||
},
|
},
|
||||||
|
tools: initialToolState,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function createInitialAppState(name = "Untitled"): AppState {
|
export function createInitialAppState(name = "Untitled"): AppState {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { ImageDocument } from "@core/document";
|
import type { ImageDocument } from "@core/document";
|
||||||
import type { Angle, Size, Vec2D } from "@core/geometry";
|
import type { Angle, Size, Vec2D } from "@core/geometry";
|
||||||
import type { ArtboardId, LayerId } from "@core/id";
|
import type { ArtboardId, LayerId } from "@core/id";
|
||||||
|
import type { ToolState } from "./tools";
|
||||||
|
|
||||||
export type ViewportState = {
|
export type ViewportState = {
|
||||||
center: Vec2D;
|
center: Vec2D;
|
||||||
@@ -17,6 +18,7 @@ export type SelectionState = {
|
|||||||
export type EditorState = {
|
export type EditorState = {
|
||||||
viewport: ViewportState;
|
viewport: ViewportState;
|
||||||
selection: SelectionState;
|
selection: SelectionState;
|
||||||
|
tools: ToolState;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
|
|||||||
15
editor/tools.ts
Normal file
15
editor/tools.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export type ToolId = "select" | "pan";
|
||||||
|
|
||||||
|
export type InteractionMode =
|
||||||
|
| { type: "tool"; tool: ToolId }
|
||||||
|
| { type: "temporary-pan"; previousTool: ToolId };
|
||||||
|
|
||||||
|
export type ToolState = {
|
||||||
|
activeTool: ToolId;
|
||||||
|
interactionMode: InteractionMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const initialToolState: ToolState = {
|
||||||
|
activeTool: "select",
|
||||||
|
interactionMode: { type: "tool", tool: "select" },
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user