@bridgebrew/shell 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ // The navigators' node actions from workspace plugins (bridge#126): a workspace plugin registers an action (Projects'
2
+ // "New project…") that the sidebar's menus show first, on the workspace and on each node where its plugin is active,
3
+ // in the workspace it was registered from. Its plugin's own dialog does the rest (Bridge's `dialogs`).
4
+ import type { ShellNodeAction } from './shell.d.ts';
5
+
6
+ export function createNodeActions() {
7
+ let actions: readonly ShellNodeAction[] = [];
8
+ const listeners = new Set<() => void>();
9
+ const changed = () => {
10
+ for (const listener of listeners) listener();
11
+ };
12
+ return {
13
+ register(action: ShellNodeAction) {
14
+ const key = (each: ShellNodeAction) => `${each.workspace}\0${each.id}`;
15
+ actions = [...actions.filter((each) => key(each) !== key(action)), action];
16
+ changed();
17
+ return () => {
18
+ if (!actions.includes(action)) return;
19
+ actions = actions.filter((each) => each !== action);
20
+ changed();
21
+ };
22
+ },
23
+ list: () => actions,
24
+ subscribe(listener: () => void) {
25
+ listeners.add(listener);
26
+ return () => void listeners.delete(listener);
27
+ },
28
+ };
29
+ }