@h-rig/omp-extension-plugin 0.0.6-alpha.186

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,55 @@
1
+ import type { PanelRegistration } from "@rig/contracts";
2
+ /** A keyboard shortcut a screen registers against the OMP extension API. */
3
+ export interface ScreenShortcut {
4
+ readonly key: string;
5
+ readonly description: string;
6
+ }
7
+ /** Cockpit navigation row metadata (the `to:<screen>` rows on the cockpit). */
8
+ export interface ScreenNav {
9
+ readonly order: number;
10
+ readonly label: string;
11
+ readonly description: string;
12
+ }
13
+ /** One cockpit screen, described as data. */
14
+ export interface ScreenDescriptor {
15
+ readonly id: string;
16
+ readonly title: string;
17
+ readonly label?: string;
18
+ readonly shortcut?: ScreenShortcut;
19
+ readonly nav?: ScreenNav;
20
+ readonly disabled?: boolean;
21
+ }
22
+ /**
23
+ * The cockpit host's OWN frame screens — NOT a domain's. The cockpit dashboard
24
+ * and the generic task/run detail composers are the host's own navigation frame,
25
+ * so it owns them; everything else is contributed. This is the fallback catalog
26
+ * when no cockpit panels are contributed (headless-ish / no plugin host).
27
+ */
28
+ export declare const DEFAULT_SCREEN_CATALOG: readonly ScreenDescriptor[];
29
+ /**
30
+ * A cockpit screen id. The concrete set is CONTRIBUTED at runtime (host frame
31
+ * screens + every plugin's contributed `screen` descriptor), so this is a plain
32
+ * string rather than a hardcoded compile-time union — the host does not enumerate
33
+ * the domains' screens.
34
+ */
35
+ export type RigScreen = string;
36
+ /**
37
+ * Build the cockpit screen catalog from the host's own frame screens PLUS every
38
+ * contributed cockpit-slot panel that carries a `screen` descriptor. The SET,
39
+ * nav, shortcuts and routing all come from contributions — the host adds nothing
40
+ * domain-specific of its own.
41
+ */
42
+ export declare function resolveScreenCatalog(panels?: readonly PanelRegistration[]): readonly ScreenDescriptor[];
43
+ export declare function isRigScreen(value: unknown, catalog?: readonly ScreenDescriptor[]): value is RigScreen;
44
+ export declare function screenTitle(screen: RigScreen, catalog?: readonly ScreenDescriptor[]): string;
45
+ export declare function screenLabel(screen: RigScreen, catalog?: readonly ScreenDescriptor[]): string;
46
+ /** Screens that register a keyboard shortcut, in catalog order. */
47
+ export declare function screenShortcuts(catalog?: readonly ScreenDescriptor[]): readonly {
48
+ readonly screen: string;
49
+ readonly shortcut: ScreenShortcut;
50
+ }[];
51
+ /** Cockpit navigation screens (have a `nav`), sorted by nav order. */
52
+ export declare function cockpitNavScreens(catalog?: readonly ScreenDescriptor[]): readonly {
53
+ readonly screen: string;
54
+ readonly nav: ScreenNav;
55
+ }[];
@@ -0,0 +1,65 @@
1
+ // @bun
2
+ // packages/omp-extension-plugin/src/cockpit/screen-catalog.ts
3
+ var DEFAULT_SCREEN_CATALOG = [
4
+ { id: "cockpit", title: "Project Cockpit", shortcut: { key: "g", description: "Rig cockpit" } },
5
+ { id: "task-detail", title: "Task Detail" },
6
+ { id: "run-detail", title: "Run Detail", label: "run detail" }
7
+ ];
8
+ function buildScreenFromPanel(panel) {
9
+ const meta = panel.screen ?? {};
10
+ const id = panel.id;
11
+ return {
12
+ id,
13
+ title: meta.title || panel.title || id,
14
+ ...meta.label !== undefined ? { label: meta.label } : {},
15
+ ...meta.shortcutKey ? { shortcut: { key: meta.shortcutKey, description: meta.shortcutDescription ?? panel.title } } : {},
16
+ ...meta.navOrder !== undefined ? {
17
+ nav: {
18
+ order: meta.navOrder,
19
+ label: meta.navLabel ?? panel.title.toUpperCase(),
20
+ description: meta.navDescription ?? panel.description ?? ""
21
+ }
22
+ } : {},
23
+ ...panel.disabled !== undefined ? { disabled: panel.disabled } : {}
24
+ };
25
+ }
26
+ function resolveScreenCatalog(panels = []) {
27
+ const contributed = panels.filter((panel) => panel.slot === "cockpit" && panel.screen).map(buildScreenFromPanel);
28
+ const seen = new Set(DEFAULT_SCREEN_CATALOG.map((screen) => screen.id));
29
+ const merged = [...DEFAULT_SCREEN_CATALOG];
30
+ for (const screen of contributed) {
31
+ if (seen.has(screen.id))
32
+ continue;
33
+ seen.add(screen.id);
34
+ merged.push(screen);
35
+ }
36
+ return merged;
37
+ }
38
+ function findScreen(catalog, screen) {
39
+ return catalog.find((entry) => entry.id === screen);
40
+ }
41
+ function isRigScreen(value, catalog = DEFAULT_SCREEN_CATALOG) {
42
+ return typeof value === "string" && catalog.some((screen) => screen.id === value);
43
+ }
44
+ function screenTitle(screen, catalog = DEFAULT_SCREEN_CATALOG) {
45
+ return findScreen(catalog, screen)?.title ?? screen;
46
+ }
47
+ function screenLabel(screen, catalog = DEFAULT_SCREEN_CATALOG) {
48
+ const descriptor = findScreen(catalog, screen);
49
+ return descriptor?.label ?? descriptor?.id ?? screen;
50
+ }
51
+ function screenShortcuts(catalog = DEFAULT_SCREEN_CATALOG) {
52
+ return catalog.flatMap((entry) => entry.shortcut ? [{ screen: entry.id, shortcut: entry.shortcut }] : []);
53
+ }
54
+ function cockpitNavScreens(catalog = DEFAULT_SCREEN_CATALOG) {
55
+ return catalog.flatMap((entry) => entry.nav && !entry.disabled ? [{ screen: entry.id, nav: entry.nav }] : []).sort((left, right) => left.nav.order - right.nav.order);
56
+ }
57
+ export {
58
+ screenTitle,
59
+ screenShortcuts,
60
+ screenLabel,
61
+ resolveScreenCatalog,
62
+ isRigScreen,
63
+ cockpitNavScreens,
64
+ DEFAULT_SCREEN_CATALOG
65
+ };
@@ -0,0 +1,4 @@
1
+ import { type RigPlugin } from "@rig/core/config";
2
+ export declare const OMP_EXTENSION_PLUGIN_NAME = "@rig/omp-extension-plugin";
3
+ export declare function createOmpExtensionPlugin(): RigPlugin;
4
+ export default createOmpExtensionPlugin;