@trackunit/react-components 8.0.8 → 8.0.9
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.
- package/index.cjs.js +1433 -466
- package/index.esm.js +1427 -469
- package/migrations/assets/react-router-components/package.json +6 -6
- package/package.json +6 -6
- package/src/components/ShortcutKeys/ShortcutKeys.d.ts +63 -0
- package/src/components/ShortcutKeys/ShortcutKeys.variants.d.ts +74 -0
- package/src/hooks/useAction/actionRegistry.d.ts +231 -0
- package/src/hooks/useAction/useAction.d.ts +118 -0
- package/src/hooks/useAction/useActionIssueReporter.d.ts +15 -0
- package/src/hooks/useAction/useActionRelay.d.ts +17 -0
- package/src/hooks/useAction/useActions.d.ts +45 -0
- package/src/hooks/useAction/useRegisterAction.d.ts +8 -0
- package/src/hooks/useAction/useRegisteredActions.d.ts +12 -0
- package/src/hooks/useAction/useRegistrationOwner.d.ts +8 -0
- package/src/hooks/useAction/utils/shortcutTakenBy/shortcutTakenBy.d.ts +13 -0
- package/src/hooks/useAction/utils/toRegistered/toRegistered.d.ts +12 -0
- package/src/hooks/useKeyboardShortcut/claimShortcutEvent.d.ts +11 -0
- package/src/hooks/useKeyboardShortcut/formatShortcutLabel.d.ts +26 -2
- package/src/hooks/useKeyboardShortcut/isTypedInFieldInside.d.ts +13 -0
- package/src/hooks/useKeyboardShortcut/reservedShortcutTypes.d.ts +8 -4
- package/src/hooks/useKeyboardShortcut/shortcutMatcher.d.ts +13 -2
- package/src/hooks/useKeyboardShortcut/types.d.ts +32 -1
- package/src/hooks/useKeyboardShortcut/useKeyboardShortcut.d.ts +16 -7
- package/src/hooks/useKeyboardShortcut/useShortcutHelpers.d.ts +17 -0
- package/src/index.d.ts +23 -0
- package/migrations/entry.js.map +0 -1
- package/migrations/utils/jsx-utils.js.map +0 -1
- package/migrations/utils/move-named-imports.js.map +0 -1
- package/migrations/utils/package-json-utils.js.map +0 -1
- package/migrations/v2-0-0/breadcrumb-remove-deprecated-props.js.map +0 -1
- package/migrations/v2-0-0/cardheader-onclickclose-to-actions.js.map +0 -1
- package/migrations/v2-0-0/iconbutton-add-required-name.js.map +0 -1
- package/migrations/v2-0-0/kpi-tooltiplabel-to-wrapper.js.map +0 -1
- package/migrations/v2-0-0/notice-tooltiplabel-to-wrapper.js.map +0 -1
- package/migrations/v2-0-0/pagination-add-required-titles.js.map +0 -1
- package/migrations/v2-0-0/tag-add-removetaglabel.js.map +0 -1
- package/migrations/v2-0-0/togglegroup-remove-item-style.js.map +0 -1
- package/migrations/v2-6-0/menulist-rename-to-menucontent.js.map +0 -1
- package/migrations/v3-0-0/copyabletext-to-text-copybutton.js.map +0 -1
- package/migrations/v4-0-0/move-to-router-components.js.map +0 -1
- package/migrations/v8-0-0/collapse-native-details.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-router-components",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/css-class-variance-utilities": "^2.6.
|
|
11
|
-
"@trackunit/i18n-library-translation": "^2.14.
|
|
12
|
-
"@trackunit/react-components": "^8.0.
|
|
13
|
-
"@trackunit/react-drawer": "^3.0.
|
|
14
|
-
"@trackunit/shared-utils": "^1.22.
|
|
10
|
+
"@trackunit/css-class-variance-utilities": "^2.6.63",
|
|
11
|
+
"@trackunit/i18n-library-translation": "^2.14.60",
|
|
12
|
+
"@trackunit/react-components": "^8.0.9",
|
|
13
|
+
"@trackunit/react-drawer": "^3.0.21",
|
|
14
|
+
"@trackunit/shared-utils": "^1.22.63",
|
|
15
15
|
"dequal": "^2.0.3",
|
|
16
16
|
"zod": "^3.25.76"
|
|
17
17
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-components",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.9",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"migrations": "./migrations.json",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
"@floating-ui/react": "^0.26.25",
|
|
15
15
|
"string-ts": "^2.0.0",
|
|
16
16
|
"tailwind-merge": "^3.7.0",
|
|
17
|
-
"@trackunit/ui-design-tokens": "^1.21.
|
|
18
|
-
"@trackunit/css-class-variance-utilities": "^2.6.
|
|
19
|
-
"@trackunit/shared-utils": "^1.22.
|
|
20
|
-
"@trackunit/ui-icons": "^1.20.
|
|
17
|
+
"@trackunit/ui-design-tokens": "^1.21.60",
|
|
18
|
+
"@trackunit/css-class-variance-utilities": "^2.6.63",
|
|
19
|
+
"@trackunit/shared-utils": "^1.22.63",
|
|
20
|
+
"@trackunit/ui-icons": "^1.20.60",
|
|
21
21
|
"es-toolkit": "^1.52.0",
|
|
22
22
|
"@tanstack/react-virtual": "^3.14.13",
|
|
23
23
|
"fflate": "^0.8.3",
|
|
24
24
|
"zod": "^3.25.76",
|
|
25
|
-
"@trackunit/i18n-library-translation": "^2.14.
|
|
25
|
+
"@trackunit/i18n-library-translation": "^2.14.60"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^19.0.0",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from "react";
|
|
2
|
+
import { CommonProps } from "../../common/CommonProps";
|
|
3
|
+
import { Refable } from "../../common/Refable";
|
|
4
|
+
import type { Styleable } from "../../common/Styleable";
|
|
5
|
+
import { FormattedShortcut, ShortcutDefinition } from "../../hooks/useKeyboardShortcut/types";
|
|
6
|
+
export interface ShortcutKeysProps extends CommonProps, Styleable, Refable<HTMLSpanElement> {
|
|
7
|
+
/**
|
|
8
|
+
* The shortcut to show. Usually the value `useKeyboardShortcut` or `useAction` returns, or a shortcut definition
|
|
9
|
+
* like `{ key: "k", modifiers: "mod" }` to show one without listening for it.
|
|
10
|
+
*
|
|
11
|
+
* Keycaps that no definition can describe, such as a double tap, can be passed as `{ keys: ["⌘", "⌘"] }`.
|
|
12
|
+
* Add a `label` to give screen readers something better than the symbols.
|
|
13
|
+
*/
|
|
14
|
+
shortcut: ShortcutDefinition | Pick<FormattedShortcut, "keys"> | FormattedShortcut;
|
|
15
|
+
/**
|
|
16
|
+
* What the shortcut does, shown after the keycaps, e.g. "Open".
|
|
17
|
+
*/
|
|
18
|
+
title?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* `small` fits inside inputs, rows and footers. `medium` stands on its own.
|
|
21
|
+
*
|
|
22
|
+
* @default "medium"
|
|
23
|
+
*/
|
|
24
|
+
size?: "small" | "medium";
|
|
25
|
+
/**
|
|
26
|
+
* Lights the keycaps up, e.g. while the user holds the keys down.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
pressed?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Shows the keys of a keyboard shortcut as keycaps, with the platform's symbols: ⌘ K on Mac, Ctrl K elsewhere.
|
|
34
|
+
* Optionally followed by a title saying what the shortcut does.
|
|
35
|
+
*
|
|
36
|
+
* It only displays a shortcut. Use `useKeyboardShortcut` to make it work (or `useAction`, to also register it
|
|
37
|
+
* as an action with the host), and pass what it returns here, so the keys shown are always the keys that run it.
|
|
38
|
+
*
|
|
39
|
+
* _**Do use** it next to the control a shortcut runs, in tooltips, and in footers listing the keys that work right now._
|
|
40
|
+
*
|
|
41
|
+
* _**Do not use** it for shortcuts that aren't active where it's shown._
|
|
42
|
+
*
|
|
43
|
+
* @example Show the shortcut that runs an action
|
|
44
|
+
* ```tsx
|
|
45
|
+
* import { Button, ShortcutKeys, useKeyboardShortcut } from "@trackunit/react-components";
|
|
46
|
+
*
|
|
47
|
+
* const ExportButton = ({ onExport }: { onExport: () => void }) => {
|
|
48
|
+
* const shortcut = useKeyboardShortcut({ key: "e", modifiers: "mod" }, { onTrigger: onExport, preventDefault: "always" });
|
|
49
|
+
* return (
|
|
50
|
+
* <Button onClick={onExport} suffix={<ShortcutKeys shortcut={shortcut} size="small" />}>
|
|
51
|
+
* Export
|
|
52
|
+
* </Button>
|
|
53
|
+
* );
|
|
54
|
+
* };
|
|
55
|
+
* ```
|
|
56
|
+
* @example A key hint with a title, as in a footer
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <ShortcutKeys shortcut={{ key: "Enter" }} size="small" title="Open" />
|
|
59
|
+
* ```
|
|
60
|
+
* @param {ShortcutKeysProps} props - The props for the ShortcutKeys component
|
|
61
|
+
* @returns {ReactElement} ShortcutKeys component
|
|
62
|
+
*/
|
|
63
|
+
export declare const ShortcutKeys: ({ shortcut, title, size, pressed, className, style, ref, "data-testid": dataTestId, }: ShortcutKeysProps) => ReactElement;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare const cvaShortcutKeys: import("cva").CVAComponent<Omit<{
|
|
2
|
+
base: string[];
|
|
3
|
+
}, "defaultVariants"> & {
|
|
4
|
+
variants: unknown;
|
|
5
|
+
defaultVariants: Omit<{}, never>;
|
|
6
|
+
}, unknown>;
|
|
7
|
+
export declare const cvaShortcutKeysKeycap: import("cva").CVAComponent<Omit<{
|
|
8
|
+
base: string[];
|
|
9
|
+
variants: {
|
|
10
|
+
size: {
|
|
11
|
+
small: string[];
|
|
12
|
+
medium: string[];
|
|
13
|
+
};
|
|
14
|
+
pressed: {
|
|
15
|
+
true: string[];
|
|
16
|
+
false: never[];
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
size: "medium";
|
|
21
|
+
pressed: false;
|
|
22
|
+
};
|
|
23
|
+
}, "defaultVariants"> & {
|
|
24
|
+
variants: {
|
|
25
|
+
size: {
|
|
26
|
+
small: string[];
|
|
27
|
+
medium: string[];
|
|
28
|
+
};
|
|
29
|
+
pressed: {
|
|
30
|
+
true: string[];
|
|
31
|
+
false: never[];
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
defaultVariants: Omit<{}, "size" | "pressed"> & {
|
|
35
|
+
size: "medium";
|
|
36
|
+
pressed: false;
|
|
37
|
+
};
|
|
38
|
+
}, {
|
|
39
|
+
size: {
|
|
40
|
+
small: string[];
|
|
41
|
+
medium: string[];
|
|
42
|
+
};
|
|
43
|
+
pressed: {
|
|
44
|
+
true: string[];
|
|
45
|
+
false: never[];
|
|
46
|
+
};
|
|
47
|
+
}>;
|
|
48
|
+
export declare const cvaShortcutKeysTitle: import("cva").CVAComponent<Omit<{
|
|
49
|
+
base: string[];
|
|
50
|
+
variants: {
|
|
51
|
+
size: {
|
|
52
|
+
small: string[];
|
|
53
|
+
medium: string[];
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
size: "medium";
|
|
58
|
+
};
|
|
59
|
+
}, "defaultVariants"> & {
|
|
60
|
+
variants: {
|
|
61
|
+
size: {
|
|
62
|
+
small: string[];
|
|
63
|
+
medium: string[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
defaultVariants: Omit<{}, "size"> & {
|
|
67
|
+
size: "medium";
|
|
68
|
+
};
|
|
69
|
+
}, {
|
|
70
|
+
size: {
|
|
71
|
+
small: string[];
|
|
72
|
+
medium: string[];
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hints for an action that only changes what's on screen or where the user is: a map style, the
|
|
3
|
+
* sidebar, a drawer, going to a page or opening a wizard. Like MCP's `ToolAnnotations` with
|
|
4
|
+
* `readOnlyHint: true`, where `destructiveHint` and `idempotentHint` don't apply.
|
|
5
|
+
*/
|
|
6
|
+
export type ReadOnlyActionHints = {
|
|
7
|
+
readonly readOnlyHint: true;
|
|
8
|
+
/** Whether the action reaches outside Trackunit, as in MCP. */
|
|
9
|
+
readonly openWorldHint?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Hints for an action that changes data, like MCP's `ToolAnnotations` with `readOnlyHint: false`.
|
|
13
|
+
* Left out, `destructiveHint` means `true`, as in MCP: say `false` for an action that only adds,
|
|
14
|
+
* like an export or a create.
|
|
15
|
+
*/
|
|
16
|
+
export type WriteActionHints = {
|
|
17
|
+
readonly readOnlyHint: false;
|
|
18
|
+
/** Whether the action may delete or overwrite data. Defaults to `true`. */
|
|
19
|
+
readonly destructiveHint?: boolean;
|
|
20
|
+
/** Whether running it twice with the same input does nothing more than running it once. */
|
|
21
|
+
readonly idempotentHint?: boolean;
|
|
22
|
+
/** Whether the action reaches outside Trackunit, as in MCP. */
|
|
23
|
+
readonly openWorldHint?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* What an action does, for the host's tools, AI ones included, and for clients that can't run
|
|
27
|
+
* client actions, in the terms of MCP tool annotations, so the client action and the server tool
|
|
28
|
+
* that does the same thing describe it alike. Anything that changes data is a server (MCP) tool's
|
|
29
|
+
* job; the client action is a UI affordance for it.
|
|
30
|
+
*
|
|
31
|
+
* - Read-only (`hints.readOnlyHint: true`): `serverTool` optionally names a tool that does the
|
|
32
|
+
* same thing directly, e.g. the create tool for a "Create group" wizard opener.
|
|
33
|
+
* - Changes data (`hints.readOnlyHint: false`): `serverTool` is required: the tool's name, or
|
|
34
|
+
* `null` where none exists yet. Searching for `serverTool: null` lists the gaps.
|
|
35
|
+
*
|
|
36
|
+
* `serverTool` is the MCP tool's name as the gateway exposes it. Relayed from an Iris app, it's
|
|
37
|
+
* untrusted: check it against the tools the gateway actually has before calling anything.
|
|
38
|
+
*
|
|
39
|
+
* @example { hints: { readOnlyHint: true } } // toggles the sidebar
|
|
40
|
+
* @example { hints: { readOnlyHint: true }, serverTool: "organization_create_group" } // opens the create group form
|
|
41
|
+
* @example { hints: { readOnlyHint: false, destructiveHint: false }, serverTool: null } // builds an export in the browser; no tool yet
|
|
42
|
+
* @example { hints: { readOnlyHint: false }, serverTool: null, alwaysAllow: false } // submits whatever the form holds
|
|
43
|
+
*/
|
|
44
|
+
export type ActionAi = {
|
|
45
|
+
readonly hints: ReadOnlyActionHints;
|
|
46
|
+
readonly serverTool?: string;
|
|
47
|
+
} | {
|
|
48
|
+
readonly hints: WriteActionHints;
|
|
49
|
+
readonly serverTool: string | null;
|
|
50
|
+
/**
|
|
51
|
+
* Say `false` when what the action does depends on what's on the page, like submitting a form,
|
|
52
|
+
* so AI tools the host offers ask the user every time before running it. Defaults to `true`.
|
|
53
|
+
* They always ask before a destructive action anyway (`destructiveHint` left out or `true`).
|
|
54
|
+
*/
|
|
55
|
+
readonly alwaysAllow?: false;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Reads an `ai` that can't be trusted to match `ActionAi`: from an untyped caller (a plain-JS Iris
|
|
59
|
+
* app) or relayed from an iframe. Anything missing or malformed reads the strictest way: only
|
|
60
|
+
* `readOnlyHint: true` makes an action read-only, and only `destructiveHint: false` makes one that
|
|
61
|
+
* changes data non-destructive, so a hint can never loosen what's left out. A `serverTool` that
|
|
62
|
+
* isn't a short string counts as none. Sets `destructiveHint` and `serverTool` on an action that
|
|
63
|
+
* changes data, so readers don't have to apply the defaults.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export declare const parseActionAi: (value: unknown) => ActionAi;
|
|
68
|
+
/**
|
|
69
|
+
* What groups a set of actions together, e.g. "Map style" for one action per style. It's never
|
|
70
|
+
* registered itself: it's derived from the actions that share it.
|
|
71
|
+
*/
|
|
72
|
+
export type ActionSubmenu = {
|
|
73
|
+
/** Groups the actions within their group. Stable and never shown, e.g. "map-style". */
|
|
74
|
+
readonly id: string;
|
|
75
|
+
/** The row's title, e.g. "Map style". */
|
|
76
|
+
readonly title: string;
|
|
77
|
+
readonly icon?: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Something the user can do on the page right now, as the host sees it. Registered by `useAction`.
|
|
81
|
+
*
|
|
82
|
+
* Strings are plain strings rather than `IconName` / `ShortcutKey` because entries relayed
|
|
83
|
+
* from Iris app iframes arrive over postMessage and can't be trusted to match those types.
|
|
84
|
+
*/
|
|
85
|
+
export type RegisteredAction = {
|
|
86
|
+
/**
|
|
87
|
+
* Stable across renders, remounts and reloads, so the host can refer to it. See `isValidActionId`. Relayed actions get the host's
|
|
88
|
+
* `<app id>/<extension id>.<action id>`, which can't clash with an id registered in the host.
|
|
89
|
+
*/
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly title: string;
|
|
92
|
+
/** What the action does and when to use it. Empty for actions relayed from apps built before it existed. */
|
|
93
|
+
readonly description: string;
|
|
94
|
+
/**
|
|
95
|
+
* Not meant to be shown. Read through `parseActionAi`, so an action that changes data always has
|
|
96
|
+
* `destructiveHint` and `serverTool` set, and one without a valid `ai` gets the strictest reading.
|
|
97
|
+
*/
|
|
98
|
+
readonly ai: ActionAi;
|
|
99
|
+
readonly subtitle?: string;
|
|
100
|
+
readonly group?: string;
|
|
101
|
+
readonly keywords?: ReadonlyArray<string>;
|
|
102
|
+
readonly icon?: string;
|
|
103
|
+
/** Groups the action with the other actions that share its group and `submenu.id`. */
|
|
104
|
+
readonly submenu?: ActionSubmenu;
|
|
105
|
+
/** The action's short name inside its submenu. Defaults to `title`. */
|
|
106
|
+
readonly label?: string;
|
|
107
|
+
/** True when the action's value is the one in effect, e.g. the current map style. */
|
|
108
|
+
readonly checked?: boolean;
|
|
109
|
+
readonly shortcut?: {
|
|
110
|
+
readonly key: string;
|
|
111
|
+
readonly modifiers?: string;
|
|
112
|
+
};
|
|
113
|
+
/** True when the shortcut only fires while focus is inside a specific element. */
|
|
114
|
+
readonly scoped?: boolean;
|
|
115
|
+
/** Why AI tools the host offers mustn't run the action, for developers. Set means they never see it. */
|
|
116
|
+
readonly hiddenFromAssistantBecause?: string;
|
|
117
|
+
/** Name of the Iris app the action was relayed from. Unset for actions registered in this window. */
|
|
118
|
+
readonly source?: string;
|
|
119
|
+
readonly perform: () => void;
|
|
120
|
+
};
|
|
121
|
+
/** What crosses the iframe boundary: everything but `perform`, which is invoked by id instead. */
|
|
122
|
+
export type SerializedAction = Omit<RegisteredAction, "perform" | "source">;
|
|
123
|
+
/**
|
|
124
|
+
* An action relayed from an Iris app, as the host's forwarder hands it to `setRelayedActions`.
|
|
125
|
+
* `ai` is whatever the app sent; the registry reads it.
|
|
126
|
+
*/
|
|
127
|
+
export type RelayedAction = Omit<SerializedAction, "ai"> & {
|
|
128
|
+
readonly source: string;
|
|
129
|
+
readonly ai?: unknown;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* DOM event fired on `window` inside an Iris app iframe whenever its actions change, with
|
|
133
|
+
* `detail: { actions: Array<SerializedAction> }`. The iris-app-loader relays the list to the host.
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
export declare const ACTIONS_CHANGED_EVENT = "trackunit:actions-changed";
|
|
138
|
+
/**
|
|
139
|
+
* DOM event the iris-app-loader fires on `window` inside an Iris app iframe, with `detail: { id }`,
|
|
140
|
+
* when the host runs one of the app's actions.
|
|
141
|
+
*
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
export declare const INVOKE_ACTION_EVENT = "trackunit:invoke-action";
|
|
145
|
+
/**
|
|
146
|
+
* Something wrong with how actions are registered, for the host to report. `titles` are the
|
|
147
|
+
* earlier registration's and the later one's.
|
|
148
|
+
*
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
export type ActionIssue = {
|
|
152
|
+
readonly kind: "duplicate-action-id";
|
|
153
|
+
readonly id: string;
|
|
154
|
+
readonly titles: readonly [string, string];
|
|
155
|
+
};
|
|
156
|
+
/** @internal */
|
|
157
|
+
export type ActionIssueReporter = (issue: ActionIssue) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Says in the console why an action isn't listed the way it was registered, which nothing else on the page would.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export declare const logToDevelopers: (level: "warn" | "error", message: string) => void;
|
|
164
|
+
/**
|
|
165
|
+
* Adds a list of actions to the registry, in order, and tells listeners once. Used by useActions.
|
|
166
|
+
* Each action is registered as `registerAction` would; one with an id `isValidActionId` rejects
|
|
167
|
+
* isn't registered, and an id repeated within the list counts as a duplicate.
|
|
168
|
+
*
|
|
169
|
+
* - `owner`: who registers them, e.g. the owner stack React's `captureOwnerStack()` gives during
|
|
170
|
+
* render, named in the development warning for a duplicate id. Never listed.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
* @returns {() => void} Unregister function, which removes them all and tells listeners once
|
|
174
|
+
*/
|
|
175
|
+
export declare const registerActions: (actions: ReadonlyArray<RegisteredAction>, owner?: string) => (() => void);
|
|
176
|
+
/**
|
|
177
|
+
* Adds an action to the registry. Used by useAction. An action with an id `isValidActionId`
|
|
178
|
+
* rejects isn't registered.
|
|
179
|
+
*
|
|
180
|
+
* - `owner`: who registers it, e.g. the owner stack React's `captureOwnerStack()` gives during
|
|
181
|
+
* render, named in the development warning for a duplicate id. Never listed.
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
* @returns {() => void} Unregister function
|
|
185
|
+
*/
|
|
186
|
+
export declare const registerAction: (action: RegisteredAction, owner?: string) => (() => void);
|
|
187
|
+
/**
|
|
188
|
+
* Sets what's told, in production, about actions registered wrongly, like two with the same id at
|
|
189
|
+
* once. The host plugs in its error reporting; issues found before it's set are kept, one per id,
|
|
190
|
+
* and told to it when it is. Shared through `window` with the registry, so it hears from every
|
|
191
|
+
* copy of react-components on the page. Pass `undefined` to unset it.
|
|
192
|
+
*
|
|
193
|
+
* @internal
|
|
194
|
+
*/
|
|
195
|
+
export declare const setActionIssueReporter: (reporter: ActionIssueReporter | undefined) => void;
|
|
196
|
+
/**
|
|
197
|
+
* Replaces the actions relayed from one Iris app iframe. Pass an empty list when the iframe goes away.
|
|
198
|
+
*
|
|
199
|
+
* - `sourceId`: the iframe's mount, unique on the page. It only routes; it's never part of an action id.
|
|
200
|
+
* - `idPrefix`: who the actions come from, the app and extension, e.g. `@trackunit/fleet-insights/fleet-main`.
|
|
201
|
+
* Each action is listed as `<idPrefix>.<the app's id>`.
|
|
202
|
+
* - `invoke`: runs an action in this iframe by the app's own id.
|
|
203
|
+
*
|
|
204
|
+
* The registry is the last word on what an app may claim: an action whose id breaks
|
|
205
|
+
* `isValidActionId`'s rules is dropped, and `ai` is read the strictest way (`parseActionAi`).
|
|
206
|
+
*
|
|
207
|
+
* Used by the host's iframe event forwarder.
|
|
208
|
+
*
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
export declare const setRelayedActions: (sourceId: string, idPrefix: string, actions: ReadonlyArray<RelayedAction>, invoke?: (id: string) => void) => void;
|
|
212
|
+
/**
|
|
213
|
+
* Calls `listener` whenever the registered actions change. For `useRegisteredActions`.
|
|
214
|
+
*
|
|
215
|
+
* @internal
|
|
216
|
+
* @returns {() => void} Unsubscribe function
|
|
217
|
+
*/
|
|
218
|
+
export declare const subscribeToActions: (listener: () => void) => (() => void);
|
|
219
|
+
/**
|
|
220
|
+
* Every action currently registered in this window, plus those relayed from Iris app iframes. The
|
|
221
|
+
* same array until they change.
|
|
222
|
+
*
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
export declare const getActionsSnapshot: () => ReadonlyArray<RegisteredAction>;
|
|
226
|
+
/**
|
|
227
|
+
* What `useRegisteredActions` lists during server rendering: nothing.
|
|
228
|
+
*
|
|
229
|
+
* @internal
|
|
230
|
+
*/
|
|
231
|
+
export declare const getServerActionsSnapshot: () => ReadonlyArray<RegisteredAction>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { IconName } from "@trackunit/ui-icons";
|
|
2
|
+
import { ValidShortcutParam } from "../useKeyboardShortcut/reservedShortcutTypes";
|
|
3
|
+
import { FormattedShortcut, ShortcutDefinition, UseKeyboardShortcutOptions } from "../useKeyboardShortcut/types";
|
|
4
|
+
import { ActionAi } from "./actionRegistry";
|
|
5
|
+
/** What `useAction` takes: something the user can do on the page, registered with the host, and optionally its shortcut. */
|
|
6
|
+
export type ActionDefinition<TShortcut extends ShortcutDefinition = ShortcutDefinition> = {
|
|
7
|
+
/**
|
|
8
|
+
* Names the action for good: the host refers to it by this, across pages and reloads.
|
|
9
|
+
* Kebab-case, and never translated, e.g. "export-assets". 1 to 80 letters, digits, `-`, `_` or
|
|
10
|
+
* `:`, starting with a letter or digit; an action with any other id isn't registered, and the
|
|
11
|
+
* console says why. Keep it unique on the page: of two registered actions with the same id, only
|
|
12
|
+
* the one registered last counts. An action that changes data needs an id unique across the whole
|
|
13
|
+
* host, since a user's choice to always allow it is saved by id.
|
|
14
|
+
*/
|
|
15
|
+
id: string;
|
|
16
|
+
/** What the action does, as a short imperative, e.g. "Export assets". */
|
|
17
|
+
title: string;
|
|
18
|
+
/**
|
|
19
|
+
* One plain sentence on what the action does and when to use it, e.g. "Downloads the assets in
|
|
20
|
+
* the list as a CSV file, with the current filters applied." It's for search and for the host's
|
|
21
|
+
* tools to tell actions apart, so say what happens rather than repeat the title.
|
|
22
|
+
*/
|
|
23
|
+
description: string;
|
|
24
|
+
/**
|
|
25
|
+
* What the action does, as MCP tool annotation hints, and the server tool that does the same,
|
|
26
|
+
* if any. See `ActionAi`.
|
|
27
|
+
*
|
|
28
|
+
* @example { hints: { readOnlyHint: true } } // toggles the sidebar
|
|
29
|
+
* @example { hints: { readOnlyHint: true }, serverTool: "organization_create_group" } // opens the create group form
|
|
30
|
+
* @example { hints: { readOnlyHint: false, destructiveHint: false }, serverTool: null } // builds an export in the browser; no tool yet
|
|
31
|
+
*/
|
|
32
|
+
ai: ActionAi;
|
|
33
|
+
/** Runs the action, whether its shortcut is pressed or the host runs it. */
|
|
34
|
+
perform: () => void;
|
|
35
|
+
/** Extra context shown next to the title, e.g. the current value of a toggle. */
|
|
36
|
+
subtitle?: string;
|
|
37
|
+
/** Heading the action belongs under. Defaults to the Iris app's name, or a general heading in the host. */
|
|
38
|
+
group?: string;
|
|
39
|
+
/** Other words people might type to find the action. */
|
|
40
|
+
keywords?: ReadonlyArray<string>;
|
|
41
|
+
icon?: IconName;
|
|
42
|
+
/**
|
|
43
|
+
* Groups the action with the other actions in its group that share `submenu.id`, e.g. one action
|
|
44
|
+
* per map style under "Map style". The action stays an action of its own, found and run by its
|
|
45
|
+
* `title`.
|
|
46
|
+
*
|
|
47
|
+
* @example { id: "map-style", title: t("mapStyle"), icon: "Map" }
|
|
48
|
+
*/
|
|
49
|
+
submenu?: {
|
|
50
|
+
id: string;
|
|
51
|
+
title: string;
|
|
52
|
+
icon?: IconName;
|
|
53
|
+
};
|
|
54
|
+
/** The action's short name inside its submenu, e.g. "Satellite" for "Show satellite map". Defaults to `title`. */
|
|
55
|
+
label?: string;
|
|
56
|
+
/** True when the action's value is the one in effect, e.g. the current map style. */
|
|
57
|
+
checked?: boolean;
|
|
58
|
+
/** Also run the action from this key combination. Reserved combinations are type errors. */
|
|
59
|
+
shortcut?: TShortcut extends ValidShortcutParam<TShortcut> ? TShortcut : never;
|
|
60
|
+
/**
|
|
61
|
+
* Where the shortcut listens. Pass a ref for a key that only makes sense while focus is inside
|
|
62
|
+
* an element, like arrow keys on a map; the action is then marked as scoped.
|
|
63
|
+
*
|
|
64
|
+
* @default "window"
|
|
65
|
+
*/
|
|
66
|
+
target?: UseKeyboardShortcutOptions["target"];
|
|
67
|
+
/** Runs the shortcut only for key events this returns true for. See `useKeyboardShortcut`. */
|
|
68
|
+
acceptKey?: UseKeyboardShortcutOptions["acceptKey"];
|
|
69
|
+
/**
|
|
70
|
+
* How the shortcut treats the browser's default for the key. See `useKeyboardShortcut`. Use
|
|
71
|
+
* `"always"` for keys that are held down, like arrows, so every repeat runs the action.
|
|
72
|
+
*
|
|
73
|
+
* @default "once"
|
|
74
|
+
*/
|
|
75
|
+
preventDefault?: UseKeyboardShortcutOptions["preventDefault"];
|
|
76
|
+
/** Unregisters the action, and disables its shortcut. */
|
|
77
|
+
disabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Keeps the action away from AI tools the host offers. Say why, for the next developer; it's
|
|
80
|
+
* never shown or sent to a model.
|
|
81
|
+
*
|
|
82
|
+
* @example "Browsers only allow fullscreen right after a click or key press."
|
|
83
|
+
*/
|
|
84
|
+
hiddenFromAssistantBecause?: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Registers something the user can do on the current page with the host, while the calling
|
|
88
|
+
* component is mounted and the action isn't disabled. Give it a `shortcut` to also bind a key
|
|
89
|
+
* combination; the key runs the same `perform` as the host does. Registering actions gets all the
|
|
90
|
+
* more useful as the host gains more ways to use them.
|
|
91
|
+
*
|
|
92
|
+
* `useKeyboardShortcut` only binds a key and registers nothing. For a list of actions that comes
|
|
93
|
+
* from data, use `useActions`.
|
|
94
|
+
*
|
|
95
|
+
* Inside an Iris app the action is relayed to the host, and when the host runs it, `perform` runs
|
|
96
|
+
* in the app.
|
|
97
|
+
*
|
|
98
|
+
* @returns {FormattedShortcut | undefined} The shortcut's label and keycaps, for `ShortcutKeys`, when it has one
|
|
99
|
+
* @example
|
|
100
|
+
* useAction({
|
|
101
|
+
* id: "export-assets",
|
|
102
|
+
* title: t("exportAssets"),
|
|
103
|
+
* description: t("exportAssets.description"),
|
|
104
|
+
* ai: { hints: { readOnlyHint: false, destructiveHint: false }, serverTool: null },
|
|
105
|
+
* icon: "CloudArrowDown",
|
|
106
|
+
* keywords: ["download", "csv"],
|
|
107
|
+
* shortcut: { key: "e", modifiers: "mod+shift" },
|
|
108
|
+
* perform: exportAssets,
|
|
109
|
+
* });
|
|
110
|
+
* @example
|
|
111
|
+
* // Show the shortcut on the button that runs it
|
|
112
|
+
* const shortcut = useAction({ id: "export-assets", title: t("exportAssets"), description: t("exportAssets.description"), ai: { hints: { readOnlyHint: false, destructiveHint: false }, serverTool: null }, shortcut: { key: "e", modifiers: "mod+shift" }, perform: exportAssets });
|
|
113
|
+
* <Button suffix={shortcut ? <ShortcutKeys shortcut={shortcut} size="small" /> : null}>{t("export")}</Button>
|
|
114
|
+
* @example
|
|
115
|
+
* // A key that only works while the map has focus
|
|
116
|
+
* useAction({ id: "map-zoom-in", title: t("zoomIn"), description: t("zoomIn.description"), ai: { hints: { readOnlyHint: true } }, group: t("map"), shortcut: { key: "=" }, target: mapRef, perform: zoomIn });
|
|
117
|
+
*/
|
|
118
|
+
export declare const useAction: <const TShortcut extends ShortcutDefinition>({ id, title, description, ai, perform, subtitle, group, keywords, icon, submenu, label, checked, shortcut, target, acceptKey, preventDefault, disabled, hiddenFromAssistantBecause, }: ActionDefinition<TShortcut>) => FormattedShortcut | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { setActionIssueReporter } from "./actionRegistry";
|
|
2
|
+
export type ActionIssueReporting = {
|
|
3
|
+
/**
|
|
4
|
+
* Sets what's told, in production, about actions registered wrongly, like two with the same id
|
|
5
|
+
* at once. Pass `undefined` to unset it.
|
|
6
|
+
*/
|
|
7
|
+
readonly setActionIssueReporter: typeof setActionIssueReporter;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Lets the host's and Iris apps' providers plug their error reporting into the action registry.
|
|
11
|
+
* The returned object is stable.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare const useActionIssueReporter: () => ActionIssueReporting;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { setRelayedActions } from "./actionRegistry";
|
|
2
|
+
export type ActionRelay = {
|
|
3
|
+
/**
|
|
4
|
+
* Replaces the actions relayed from one source, such as an app's iframe; an empty list removes them.
|
|
5
|
+
* Ids that break the registry's rules are dropped.
|
|
6
|
+
*/
|
|
7
|
+
readonly setRelayedActions: typeof setRelayedActions;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Lets the host put actions registered in another window (an app's iframe) into this window's
|
|
11
|
+
* action registry. The returned object is stable.
|
|
12
|
+
*
|
|
13
|
+
* Used by the host's iframe event forwarder.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const useActionRelay: () => ActionRelay;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ShortcutDefinition } from "../useKeyboardShortcut/types";
|
|
2
|
+
import { ActionDefinition } from "./useAction";
|
|
3
|
+
/** One action in the list given to `useActions`. Like `ActionDefinition`, without `disabled`: leave the entry out instead. */
|
|
4
|
+
export type ActionListEntry = Omit<ActionDefinition, "shortcut" | "disabled"> & {
|
|
5
|
+
/**
|
|
6
|
+
* The action's id, as for `useAction`, e.g. a control's id plus the option it picks. While it
|
|
7
|
+
* stays the same, a new `perform` or a new list doesn't re-register the action.
|
|
8
|
+
*/
|
|
9
|
+
readonly id: string;
|
|
10
|
+
/**
|
|
11
|
+
* Also run the action from this key combination. Unlike `useAction`, reserved combinations
|
|
12
|
+
* aren't caught at compile time here, so keep to keys without Cmd/Ctrl. One the host or the
|
|
13
|
+
* browser uses, like Cmd/Ctrl+K, isn't bound or listed, and the console says why in development.
|
|
14
|
+
*/
|
|
15
|
+
readonly shortcut?: ShortcutDefinition;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Registers a list of actions with the host while the calling component is mounted, like calling
|
|
19
|
+
* `useAction` once per entry. For lists that come from data, where the number
|
|
20
|
+
* of actions changes and a hook per action can't be written, such as the actions a map's controls
|
|
21
|
+
* declare. To hide an action, leave it out of the list.
|
|
22
|
+
*
|
|
23
|
+
* Each entry is registered under its `id`, and `perform` is read when the action runs, so passing a
|
|
24
|
+
* new list with new callbacks every render doesn't re-register anything. An entry is re-registered
|
|
25
|
+
* when anything else about it changes, e.g. its `checked` state or its title.
|
|
26
|
+
*
|
|
27
|
+
* Entries with a `shortcut` bind it on their `target`, the window by default, and the key runs the
|
|
28
|
+
* entry's latest `perform`, as `useAction` does. A shortcut without Cmd/Ctrl or Alt ignores keys typed
|
|
29
|
+
* in a text field, select or contenteditable, wherever it listens. The rules for ids, `ai` and duplicate ids are the
|
|
30
|
+
* same as for `useAction`.
|
|
31
|
+
*
|
|
32
|
+
* @param actions - The actions to offer, each with a stable `id`. See `ActionListEntry`.
|
|
33
|
+
* @example
|
|
34
|
+
* useActions(options.map(option => ({
|
|
35
|
+
* id: `map-style:${option.value}`,
|
|
36
|
+
* title: option.title,
|
|
37
|
+
* description: option.description,
|
|
38
|
+
* ai: { hints: { readOnlyHint: true } },
|
|
39
|
+
* submenu: { id: "map-style", title: t("mapStyle"), icon: "Map" },
|
|
40
|
+
* label: option.label,
|
|
41
|
+
* checked: option.value === style,
|
|
42
|
+
* perform: () => setStyle(option.value),
|
|
43
|
+
* })));
|
|
44
|
+
*/
|
|
45
|
+
export declare const useActions: (actions: ReadonlyArray<ActionListEntry>) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RegisteredAction } from "./actionRegistry";
|
|
2
|
+
/**
|
|
3
|
+
* Registers `action` while it's defined, naming the calling component as its owner. `perform` is
|
|
4
|
+
* read through a ref, so a new callback every render doesn't re-register.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const useRegisterAction: (action: RegisteredAction | undefined) => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RegisteredAction } from "./actionRegistry";
|
|
2
|
+
/**
|
|
3
|
+
* Every action currently registered in this window, plus those relayed from Iris app iframes.
|
|
4
|
+
* For the host's surfaces that list or run actions.
|
|
5
|
+
*
|
|
6
|
+
* The list is in registration order, and an action that registers again (its `checked`, `subtitle`
|
|
7
|
+
* or `title` changed) moves to the end. A surface that shows a stable order must sort the list.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
* @returns {ReadonlyArray<RegisteredAction>} Active actions
|
|
11
|
+
*/
|
|
12
|
+
export declare const useRegisteredActions: () => ReadonlyArray<RegisteredAction>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The owner stack of the component calling the hook, read once during its first render, for
|
|
3
|
+
* `registerAction`'s duplicate id warning. Undefined in production.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
* @returns {string | undefined} The owner stack, e.g. "\n at AssetList\n at App"
|
|
7
|
+
*/
|
|
8
|
+
export declare const useRegistrationOwner: () => string | undefined;
|