summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-02-23 06:50:53 +0100
committerMaze Winther <mazewinther@gmail.com>2026-02-23 06:50:53 +0100
commita982304bb3af7d3a26be1bfbd38eb0a67b2ff42d (patch)
tree1d462f454865b777947f85eba1b7189dbe7b101a /docs
parent5616d4e9f35e20775791ada8d0a271620fc74925 (diff)
downloadopencut-a982304bb3af7d3a26be1bfbd38eb0a67b2ff42d.tar.gz
docs: actions
Diffstat (limited to 'docs')
-rw-r--r--docs/actions.md62
1 files changed, 62 insertions, 0 deletions
diff --git a/docs/actions.md b/docs/actions.md
new file mode 100644
index 00000000..f9586a86
--- /dev/null
+++ b/docs/actions.md
@@ -0,0 +1,62 @@
+# Actions System
+
+Actions are the trigger layer for user-initiated operations. They connect keyboard shortcuts, UI buttons, and context menus to editor functionality.
+
+## Adding a New Action
+
+### 1. Define the action — `src/lib/actions/definitions.ts`
+
+Add an entry to the `ACTIONS` object:
+
+```typescript
+"my-action": {
+ description: "What it does",
+ category: "editing", // playback | navigation | editing | selection | history | timeline | controls
+ defaultShortcuts: ["ctrl+m"], // optional
+ args: { someValue: "number" }, // optional, only if it takes args
+},
+```
+
+### 2. Register the handler — `src/hooks/actions/use-editor-actions.ts`
+
+```typescript
+useActionHandler(
+ "my-action",
+ () => {
+ editor.timeline.doSomething();
+ },
+ undefined, // isActive: MutableRefObject<boolean> | boolean | undefined
+);
+```
+
+### 3. Register arg types (if needed) — `src/lib/actions/types.ts`
+
+Only required if your action accepts arguments:
+
+```typescript
+export type TActionArgsMap = {
+ // ...existing actions...
+ "my-action": { someValue: number } | undefined; // | undefined = optional args
+};
+```
+
+## Invoking Actions
+
+Use `invokeAction` for any user-triggered operation (buttons, context menus, etc.):
+
+```typescript
+import { invokeAction } from "@/lib/actions";
+
+invokeAction("my-action");
+invokeAction("seek-forward", { seconds: 5 });
+```
+
+Avoid calling `editor.xxx()` directly from UI components — that bypasses the action layer (toasts, validation feedback, keybinding support).
+
+## The `isActive` parameter
+
+The third argument to `useActionHandler` controls when the handler is active:
+
+- `undefined` — always active
+- `true` / `false` — statically enabled/disabled
+- `MutableRefObject<boolean>` — reactive, toggled at runtime (e.g. only active when a panel is focused)