@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ShortcutDefinition } from "../../../useKeyboardShortcut/types";
|
|
2
|
+
/**
|
|
3
|
+
* What already uses a key combination, the host or the browser, when it's one `useAction` rejects
|
|
4
|
+
* at compile time. For shortcuts that come from data, which no type can check, so the modifiers
|
|
5
|
+
* may come in any order (`"shift+mod"`).
|
|
6
|
+
*
|
|
7
|
+
* @param shortcut - The shortcut to check
|
|
8
|
+
* @returns {string | undefined} What uses it, e.g. `the host's "Global Search"`, or undefined when it's free
|
|
9
|
+
*/
|
|
10
|
+
export declare const shortcutTakenBy: (shortcut: ShortcutDefinition | {
|
|
11
|
+
readonly key: string;
|
|
12
|
+
readonly modifiers?: string;
|
|
13
|
+
}) => string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RegisteredAction } from "../../actionRegistry";
|
|
2
|
+
import type { ActionListEntry } from "../../useActions";
|
|
3
|
+
/**
|
|
4
|
+
* The fields of a `useActions` entry the registry lists, without `perform`. Anything else on the
|
|
5
|
+
* entry, like `target` or a field an untyped caller added, is left out; a `target` other than the
|
|
6
|
+
* window marks the action as scoped. A shortcut the host or the browser already uses (see
|
|
7
|
+
* `shortcutTakenBy`) is left out too, as `useActions` doesn't bind it.
|
|
8
|
+
*
|
|
9
|
+
* @param entry - One entry of the list given to `useActions`
|
|
10
|
+
* @returns {Omit<RegisteredAction, "perform">} The action as the registry lists it
|
|
11
|
+
*/
|
|
12
|
+
export declare const toRegistered: (entry: ActionListEntry) => Omit<RegisteredAction, "perform">;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PreventDefaultMode } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Applies a shortcut's `preventDefault` mode to a key event that matched it, and says whether the
|
|
4
|
+
* shortcut should run. In `"once"` mode, a second press within the repeat window goes to the browser.
|
|
5
|
+
*
|
|
6
|
+
* @param event - The matched key event
|
|
7
|
+
* @param mode - The shortcut's preventDefault mode
|
|
8
|
+
* @param lastTrigger - When the shortcut last ran, in ms since the epoch
|
|
9
|
+
* @returns {number | undefined} The time to record as the shortcut's last run, or undefined if it shouldn't run
|
|
10
|
+
*/
|
|
11
|
+
export declare const claimShortcutEvent: (event: KeyboardEvent, mode: PreventDefaultMode, lastTrigger: number) => number | undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ShortcutDefinition } from "./types";
|
|
2
1
|
/**
|
|
3
2
|
* Formats a shortcut definition into a human-readable label.
|
|
4
3
|
*
|
|
@@ -6,7 +5,11 @@ import { ShortcutDefinition } from "./types";
|
|
|
6
5
|
* - Mac: "Cmd + K", "Option + Shift + L"
|
|
7
6
|
* - Windows/Linux: "Ctrl + K", "Alt + Shift + L"
|
|
8
7
|
*
|
|
8
|
+
* Accepts loosely typed input, like `formatShortcutKeys`, so keys no definition names (a lone modifier) get a label too.
|
|
9
|
+
*
|
|
9
10
|
* @param shortcut - The shortcut definition to format
|
|
11
|
+
* @param shortcut.key - The key, e.g. "k" or "Escape"
|
|
12
|
+
* @param shortcut.modifiers - "+"-joined semantic modifiers, e.g. "mod+shift"
|
|
10
13
|
* @param separator - The separator between parts (default: " + ")
|
|
11
14
|
* @returns {string} A formatted string like "Cmd + K" or "Ctrl + Shift + L"
|
|
12
15
|
* @example
|
|
@@ -21,4 +24,25 @@ import { ShortcutDefinition } from "./types";
|
|
|
21
24
|
* formatShortcutLabel({ key: "Escape" })
|
|
22
25
|
* // "Esc"
|
|
23
26
|
*/
|
|
24
|
-
export declare const formatShortcutLabel: (shortcut:
|
|
27
|
+
export declare const formatShortcutLabel: (shortcut: {
|
|
28
|
+
key: string;
|
|
29
|
+
modifiers?: string;
|
|
30
|
+
}, separator?: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Formats a shortcut into the individual keycaps a user presses, using platform symbols.
|
|
33
|
+
*
|
|
34
|
+
* Accepts loosely typed input so shortcuts relayed from Iris app iframes can be formatted too.
|
|
35
|
+
*
|
|
36
|
+
* @param shortcut - The key and optional modifiers
|
|
37
|
+
* @param shortcut.key - The key, e.g. "k" or "ArrowUp"
|
|
38
|
+
* @param shortcut.modifiers - "+"-joined semantic modifiers, e.g. "mod+shift"
|
|
39
|
+
* @returns {ReadonlyArray<string>} Keycaps in press order, e.g. ["⌘", "⇧", "L"] on Mac or ["Ctrl", "Shift", "L"] elsewhere
|
|
40
|
+
* @example
|
|
41
|
+
* formatShortcutKeys({ key: "k", modifiers: "mod" })
|
|
42
|
+
* // Mac: ["⌘", "K"]
|
|
43
|
+
* // Windows: ["Ctrl", "K"]
|
|
44
|
+
*/
|
|
45
|
+
export declare const formatShortcutKeys: (shortcut: {
|
|
46
|
+
key: string;
|
|
47
|
+
modifiers?: string;
|
|
48
|
+
}) => ReadonlyArray<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ShortcutDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a key event reached an element-bound shortcut from a text field, select or contenteditable
|
|
4
|
+
* inside that element. There a key without Cmd/Ctrl or Alt types (or moves the caret), so it isn't
|
|
5
|
+
* the shortcut. Escape doesn't edit text, so it still counts as the shortcut, as does any key when
|
|
6
|
+
* the field is the listening element itself.
|
|
7
|
+
*
|
|
8
|
+
* @param event - The keyboard event
|
|
9
|
+
* @param listener - The element the shortcut listens on, or undefined for the window, where any field counts
|
|
10
|
+
* @param shortcut - The shortcut definition
|
|
11
|
+
* @returns {boolean} true if the shortcut should leave the event alone
|
|
12
|
+
*/
|
|
13
|
+
export declare const isTypedInFieldInside: (event: KeyboardEvent, listener: HTMLElement | undefined, shortcut: ShortcutDefinition) => boolean;
|
|
@@ -13,7 +13,7 @@ import { ShortcutDefinition } from "./types";
|
|
|
13
13
|
* - Undo/Redo: mod+z, mod+shift+z, mod+y
|
|
14
14
|
* - Find: mod+f, mod+g, mod+shift+g
|
|
15
15
|
* - Navigation: mod+r, mod+shift+r, mod+t, mod+w, mod+shift+t, mod+n, mod+shift+n, mod+l, mod+d
|
|
16
|
-
* - Zoom: mod+=, mod+-, mod+0
|
|
16
|
+
* - Zoom: mod+=, mod++, mod+-, mod+0
|
|
17
17
|
* - Other: mod+p, mod+s, mod+o, mod+h, mod+j, mod+q
|
|
18
18
|
*
|
|
19
19
|
* The type system prevents their use. Legitimate uses (in host-navigation)
|
|
@@ -119,6 +119,10 @@ type BrowserReservedModEquals = {
|
|
|
119
119
|
readonly key: "=";
|
|
120
120
|
readonly modifiers: "mod";
|
|
121
121
|
};
|
|
122
|
+
type BrowserReservedModPlus = {
|
|
123
|
+
readonly key: "+";
|
|
124
|
+
readonly modifiers: "mod";
|
|
125
|
+
};
|
|
122
126
|
type BrowserReservedModMinus = {
|
|
123
127
|
readonly key: "-";
|
|
124
128
|
readonly modifiers: "mod";
|
|
@@ -152,11 +156,11 @@ type BrowserReservedModQ = {
|
|
|
152
156
|
readonly modifiers: "mod";
|
|
153
157
|
};
|
|
154
158
|
/** Union of all browser-reserved shortcuts */
|
|
155
|
-
type BrowserReservedShortcut = BrowserReservedModC | BrowserReservedModV | BrowserReservedModX | BrowserReservedModA | BrowserReservedModZ | BrowserReservedModShiftZ | BrowserReservedModY | BrowserReservedModF | BrowserReservedModG | BrowserReservedModShiftG | BrowserReservedModR | BrowserReservedModShiftR | BrowserReservedModT | BrowserReservedModW | BrowserReservedModShiftT | BrowserReservedModN | BrowserReservedModShiftN | BrowserReservedModL | BrowserReservedModD | BrowserReservedModEquals | BrowserReservedModMinus | BrowserReservedMod0 | BrowserReservedModP | BrowserReservedModS | BrowserReservedModO | BrowserReservedModH | BrowserReservedModJ | BrowserReservedModQ;
|
|
159
|
+
type BrowserReservedShortcut = BrowserReservedModC | BrowserReservedModV | BrowserReservedModX | BrowserReservedModA | BrowserReservedModZ | BrowserReservedModShiftZ | BrowserReservedModY | BrowserReservedModF | BrowserReservedModG | BrowserReservedModShiftG | BrowserReservedModR | BrowserReservedModShiftR | BrowserReservedModT | BrowserReservedModW | BrowserReservedModShiftT | BrowserReservedModN | BrowserReservedModShiftN | BrowserReservedModL | BrowserReservedModD | BrowserReservedModEquals | BrowserReservedModPlus | BrowserReservedModMinus | BrowserReservedMod0 | BrowserReservedModP | BrowserReservedModS | BrowserReservedModO | BrowserReservedModH | BrowserReservedModJ | BrowserReservedModQ;
|
|
156
160
|
/** Maps each browser-reserved shortcut to its feature description */
|
|
157
|
-
type BrowserShortcutFeature<TShortcut> = TShortcut extends BrowserReservedModC ? "Copy" : TShortcut extends BrowserReservedModV ? "Paste" : TShortcut extends BrowserReservedModX ? "Cut" : TShortcut extends BrowserReservedModA ? "Select All" : TShortcut extends BrowserReservedModZ ? "Undo" : TShortcut extends BrowserReservedModShiftZ ? "Redo (Mac)" : TShortcut extends BrowserReservedModY ? "Redo (Windows/Linux)" : TShortcut extends BrowserReservedModF ? "Find on page" : TShortcut extends BrowserReservedModG ? "Find next" : TShortcut extends BrowserReservedModShiftG ? "Find previous" : TShortcut extends BrowserReservedModR ? "Reload page" : TShortcut extends BrowserReservedModShiftR ? "Hard reload" : TShortcut extends BrowserReservedModT ? "New tab" : TShortcut extends BrowserReservedModW ? "Close tab" : TShortcut extends BrowserReservedModShiftT ? "Reopen closed tab" : TShortcut extends BrowserReservedModN ? "New window" : TShortcut extends BrowserReservedModShiftN ? "New incognito/private window" : TShortcut extends BrowserReservedModL ? "Focus address bar" : TShortcut extends BrowserReservedModD ? "Bookmark page" : TShortcut extends BrowserReservedModEquals ? "Zoom in" : TShortcut extends BrowserReservedModMinus ? "Zoom out" : TShortcut extends BrowserReservedMod0 ? "Reset zoom" : TShortcut extends BrowserReservedModP ? "Print" : TShortcut extends BrowserReservedModS ? "Save page" : TShortcut extends BrowserReservedModO ? "Open file" : TShortcut extends BrowserReservedModH ? "History (Chrome) / Hide window (Mac)" : TShortcut extends BrowserReservedModJ ? "Downloads" : TShortcut extends BrowserReservedModQ ? "Quit application (Mac only)" : never;
|
|
161
|
+
type BrowserShortcutFeature<TShortcut> = TShortcut extends BrowserReservedModC ? "Copy" : TShortcut extends BrowserReservedModV ? "Paste" : TShortcut extends BrowserReservedModX ? "Cut" : TShortcut extends BrowserReservedModA ? "Select All" : TShortcut extends BrowserReservedModZ ? "Undo" : TShortcut extends BrowserReservedModShiftZ ? "Redo (Mac)" : TShortcut extends BrowserReservedModY ? "Redo (Windows/Linux)" : TShortcut extends BrowserReservedModF ? "Find on page" : TShortcut extends BrowserReservedModG ? "Find next" : TShortcut extends BrowserReservedModShiftG ? "Find previous" : TShortcut extends BrowserReservedModR ? "Reload page" : TShortcut extends BrowserReservedModShiftR ? "Hard reload" : TShortcut extends BrowserReservedModT ? "New tab" : TShortcut extends BrowserReservedModW ? "Close tab" : TShortcut extends BrowserReservedModShiftT ? "Reopen closed tab" : TShortcut extends BrowserReservedModN ? "New window" : TShortcut extends BrowserReservedModShiftN ? "New incognito/private window" : TShortcut extends BrowserReservedModL ? "Focus address bar" : TShortcut extends BrowserReservedModD ? "Bookmark page" : TShortcut extends BrowserReservedModEquals | BrowserReservedModPlus ? "Zoom in" : TShortcut extends BrowserReservedModMinus ? "Zoom out" : TShortcut extends BrowserReservedMod0 ? "Reset zoom" : TShortcut extends BrowserReservedModP ? "Print" : TShortcut extends BrowserReservedModS ? "Save page" : TShortcut extends BrowserReservedModO ? "Open file" : TShortcut extends BrowserReservedModH ? "History (Chrome) / Hide window (Mac)" : TShortcut extends BrowserReservedModJ ? "Downloads" : TShortcut extends BrowserReservedModQ ? "Quit application (Mac only)" : never;
|
|
158
162
|
/** Maps each browser-reserved shortcut to its key string */
|
|
159
|
-
type BrowserShortcutKeys<TShortcut> = TShortcut extends BrowserReservedModC ? "mod+c" : TShortcut extends BrowserReservedModV ? "mod+v" : TShortcut extends BrowserReservedModX ? "mod+x" : TShortcut extends BrowserReservedModA ? "mod+a" : TShortcut extends BrowserReservedModZ ? "mod+z" : TShortcut extends BrowserReservedModShiftZ ? "mod+shift+z" : TShortcut extends BrowserReservedModY ? "mod+y" : TShortcut extends BrowserReservedModF ? "mod+f" : TShortcut extends BrowserReservedModG ? "mod+g" : TShortcut extends BrowserReservedModShiftG ? "mod+shift+g" : TShortcut extends BrowserReservedModR ? "mod+r" : TShortcut extends BrowserReservedModShiftR ? "mod+shift+r" : TShortcut extends BrowserReservedModT ? "mod+t" : TShortcut extends BrowserReservedModW ? "mod+w" : TShortcut extends BrowserReservedModShiftT ? "mod+shift+t" : TShortcut extends BrowserReservedModN ? "mod+n" : TShortcut extends BrowserReservedModShiftN ? "mod+shift+n" : TShortcut extends BrowserReservedModL ? "mod+l" : TShortcut extends BrowserReservedModD ? "mod+d" : TShortcut extends BrowserReservedModEquals ? "mod+=" : TShortcut extends BrowserReservedModMinus ? "mod+-" : TShortcut extends BrowserReservedMod0 ? "mod+0" : TShortcut extends BrowserReservedModP ? "mod+p" : TShortcut extends BrowserReservedModS ? "mod+s" : TShortcut extends BrowserReservedModO ? "mod+o" : TShortcut extends BrowserReservedModH ? "mod+h" : TShortcut extends BrowserReservedModJ ? "mod+j" : TShortcut extends BrowserReservedModQ ? "mod+q" : never;
|
|
163
|
+
type BrowserShortcutKeys<TShortcut> = TShortcut extends BrowserReservedModC ? "mod+c" : TShortcut extends BrowserReservedModV ? "mod+v" : TShortcut extends BrowserReservedModX ? "mod+x" : TShortcut extends BrowserReservedModA ? "mod+a" : TShortcut extends BrowserReservedModZ ? "mod+z" : TShortcut extends BrowserReservedModShiftZ ? "mod+shift+z" : TShortcut extends BrowserReservedModY ? "mod+y" : TShortcut extends BrowserReservedModF ? "mod+f" : TShortcut extends BrowserReservedModG ? "mod+g" : TShortcut extends BrowserReservedModShiftG ? "mod+shift+g" : TShortcut extends BrowserReservedModR ? "mod+r" : TShortcut extends BrowserReservedModShiftR ? "mod+shift+r" : TShortcut extends BrowserReservedModT ? "mod+t" : TShortcut extends BrowserReservedModW ? "mod+w" : TShortcut extends BrowserReservedModShiftT ? "mod+shift+t" : TShortcut extends BrowserReservedModN ? "mod+n" : TShortcut extends BrowserReservedModShiftN ? "mod+shift+n" : TShortcut extends BrowserReservedModL ? "mod+l" : TShortcut extends BrowserReservedModD ? "mod+d" : TShortcut extends BrowserReservedModEquals ? "mod+=" : TShortcut extends BrowserReservedModPlus ? "mod++" : TShortcut extends BrowserReservedModMinus ? "mod+-" : TShortcut extends BrowserReservedMod0 ? "mod+0" : TShortcut extends BrowserReservedModP ? "mod+p" : TShortcut extends BrowserReservedModS ? "mod+s" : TShortcut extends BrowserReservedModO ? "mod+o" : TShortcut extends BrowserReservedModH ? "mod+h" : TShortcut extends BrowserReservedModJ ? "mod+j" : TShortcut extends BrowserReservedModQ ? "mod+q" : never;
|
|
160
164
|
/** Maps each browser-reserved shortcut to its error message */
|
|
161
165
|
type BrowserReservedErrorMessage<TShortcut> = ReservedMessage<"Browser", BrowserShortcutKeys<TShortcut>, BrowserShortcutFeature<TShortcut>>;
|
|
162
166
|
/** Union of all reserved shortcuts (app + browser) */
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { ShortcutDefinition } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Parses a modifier string into a Set for easy lookup.
|
|
4
|
+
*
|
|
5
|
+
* @param modifiers - The modifier string (e.g., "mod+shift")
|
|
6
|
+
* @returns {Set<string>} A Set containing the individual modifiers
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseModifiers: (modifiers?: string) => Set<string>;
|
|
2
9
|
/**
|
|
3
10
|
* Checks if a keyboard event matches the shortcut definition.
|
|
4
11
|
*
|
|
5
12
|
* This is a pure function that handles:
|
|
6
|
-
* -
|
|
13
|
+
* - Keyboard layouts: the key is the character typed, and letters and digits fall back to their
|
|
14
|
+
* US QWERTY position where the layout types something else (Ctrl+K on a Russian layout types
|
|
15
|
+
* "л"; see `matchesShortcutKey`), except with Alt held, where Option and AltGr type accented
|
|
16
|
+
* letters and only the typed character counts
|
|
7
17
|
* - Platform-aware modifier key checking (Cmd on Mac, Ctrl on Windows/Linux)
|
|
8
18
|
* - Space key normalization
|
|
9
|
-
* - Extra modifier rejection (ensures only expected modifiers are pressed)
|
|
19
|
+
* - Extra modifier rejection (ensures only expected modifiers are pressed), except Shift for a
|
|
20
|
+
* symbol without other modifiers, which may take Shift to type (`=` is Shift+0 on a German keyboard)
|
|
10
21
|
*
|
|
11
22
|
* @param event - The keyboard event to check
|
|
12
23
|
* @param shortcut - The shortcut definition to match against
|
|
@@ -24,7 +24,7 @@ export type ModifierString = "mod" | "alt" | "shift" | "alt+mod" | "alt+shift" |
|
|
|
24
24
|
* Supported shortcut keys.
|
|
25
25
|
* These map to the `event.key` values from KeyboardEvent.
|
|
26
26
|
*/
|
|
27
|
-
export type ShortcutKey = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "Enter" | "Escape" | "Tab" | "Space" | "Backspace" | "Delete" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "/" | "[" | "]" | "," | "." | "-" | "=" | "`" | "\\";
|
|
27
|
+
export type ShortcutKey = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "Enter" | "Escape" | "Tab" | "Space" | "Backspace" | "Delete" | "ArrowUp" | "ArrowDown" | "ArrowLeft" | "ArrowRight" | "Home" | "End" | "PageUp" | "PageDown" | "F1" | "F2" | "F3" | "F4" | "F5" | "F6" | "F7" | "F8" | "F9" | "F10" | "F11" | "F12" | "/" | "[" | "]" | "," | "." | "-" | "=" | "+" | "`" | "\\";
|
|
28
28
|
/**
|
|
29
29
|
* Defines a keyboard shortcut with a key and optional modifiers.
|
|
30
30
|
*/
|
|
@@ -38,6 +38,16 @@ export type ShortcutDefinition = {
|
|
|
38
38
|
*/
|
|
39
39
|
readonly modifiers?: ModifierString;
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* A shortcut formatted for the current platform, as returned by `useKeyboardShortcut`.
|
|
43
|
+
* Pass it to `ShortcutKeys` to show it.
|
|
44
|
+
*/
|
|
45
|
+
export type FormattedShortcut = {
|
|
46
|
+
/** Readable label, e.g. "Cmd + K" on Mac or "Ctrl + K" elsewhere. Use it in tooltips and for screen readers. */
|
|
47
|
+
readonly label: string;
|
|
48
|
+
/** Keycaps in press order, e.g. ["⌘", "K"] on Mac or ["Ctrl", "K"] elsewhere. */
|
|
49
|
+
readonly keys: ReadonlyArray<string>;
|
|
50
|
+
};
|
|
41
51
|
/**
|
|
42
52
|
* Controls how the shortcut handles the browser's default behavior.
|
|
43
53
|
*
|
|
@@ -78,9 +88,30 @@ export type UseKeyboardShortcutOptions = {
|
|
|
78
88
|
* Target element for the keyboard listener.
|
|
79
89
|
* Can be a ref to an HTMLElement or "window" for global shortcuts.
|
|
80
90
|
*
|
|
91
|
+
* On an element, a shortcut without Cmd/Ctrl or Alt ignores keys pressed in a text field,
|
|
92
|
+
* select or contenteditable inside it, since those keys type there. A text field that is
|
|
93
|
+
* the target itself still gets them.
|
|
94
|
+
*
|
|
81
95
|
* @default "window"
|
|
82
96
|
*/
|
|
83
97
|
target?: RefObject<HTMLElement | null> | "window";
|
|
98
|
+
/**
|
|
99
|
+
* Runs the shortcut only for key events this returns true for, and leaves the others alone,
|
|
100
|
+
* default not prevented. For an element whose keys are only its own when pressed in part of it,
|
|
101
|
+
* like a map whose arrow keys belong to a focused panel button rather than to the map.
|
|
102
|
+
*
|
|
103
|
+
* @default Every key event
|
|
104
|
+
*/
|
|
105
|
+
acceptKey?: (event: KeyboardEvent) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Also ignore keys typed in a text field, select or contenteditable when the target is the window.
|
|
108
|
+
* A shortcut without Cmd/Ctrl or Alt then leaves those keys alone, so it doesn't run (or swallow
|
|
109
|
+
* the character) while someone types. An element target always does this. It is off by default,
|
|
110
|
+
* because window-level handlers such as Enter or "?" are expected to fire from a field.
|
|
111
|
+
*
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
ignoreKeysTypedInFields?: boolean;
|
|
84
115
|
};
|
|
85
116
|
/**
|
|
86
117
|
* Detected platform for keyboard shortcut handling.
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ValidShortcutParam } from "./reservedShortcutTypes";
|
|
2
|
-
import { ShortcutDefinition, UseKeyboardShortcutOptions } from "./types";
|
|
2
|
+
import { FormattedShortcut, ShortcutDefinition, UseKeyboardShortcutOptions } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Hook for handling keyboard shortcuts with platform-aware modifiers.
|
|
5
5
|
*
|
|
6
|
+
* It only binds the key. Something the user can do on the page, with or without a shortcut, is an
|
|
7
|
+
* action: use `useAction` to register it with the host.
|
|
8
|
+
*
|
|
6
9
|
* Reserved shortcuts are blocked at the type level and will show specific error messages.
|
|
7
10
|
* There are two categories:
|
|
8
11
|
*
|
|
@@ -17,7 +20,7 @@ import { ShortcutDefinition, UseKeyboardShortcutOptions } from "./types";
|
|
|
17
20
|
* - Navigation: mod+r (Reload), mod+shift+r (Hard reload), mod+t (New tab),
|
|
18
21
|
* mod+w (Close tab), mod+shift+t (Reopen tab), mod+n (New window),
|
|
19
22
|
* mod+shift+n (Incognito), mod+l (Address bar), mod+d (Bookmark)
|
|
20
|
-
* - Zoom: mod+= (Zoom in), mod+- (Zoom out), mod+0 (Reset zoom)
|
|
23
|
+
* - Zoom: mod+= and mod++ (Zoom in), mod+- (Zoom out), mod+0 (Reset zoom)
|
|
21
24
|
* - Other: mod+p (Print), mod+s (Save), mod+o (Open), mod+h (History/Hide),
|
|
22
25
|
* mod+j (Downloads), mod+q (Quit Mac)
|
|
23
26
|
*
|
|
@@ -31,8 +34,16 @@ import { ShortcutDefinition, UseKeyboardShortcutOptions } from "./types";
|
|
|
31
34
|
* - `"never"` (default) - Browser handles the event normally
|
|
32
35
|
* - `"once"` - Prevent default, but rapid repeat (within 400ms) passes to browser
|
|
33
36
|
* - `"always"` - Always prevent default, no browser escape hatch
|
|
34
|
-
* @param options.target - Target element for the listener (default: "window")
|
|
35
|
-
*
|
|
37
|
+
* @param options.target - Target element for the listener (default: "window"). On an element, a
|
|
38
|
+
* shortcut without Cmd/Ctrl or Alt ignores keys typed in a field (input, textarea, select or
|
|
39
|
+
* contenteditable) inside it. Escape still fires.
|
|
40
|
+
* @param options.acceptKey - Runs the shortcut only for key events this returns true for (default: every key event)
|
|
41
|
+
* @param options.ignoreKeysTypedInFields - Do the same on the window target (default: false)
|
|
42
|
+
* @returns {FormattedShortcut} The readable label (e.g. "Cmd + K") and the keycaps (e.g. ["⌘", "K"]). Pass it to `ShortcutKeys` to show it.
|
|
43
|
+
* @example
|
|
44
|
+
* // Show the shortcut next to the button it runs
|
|
45
|
+
* const shortcut = useKeyboardShortcut({ key: "Enter", modifiers: "mod" }, { onTrigger: submit });
|
|
46
|
+
* <Button onClick={submit} suffix={<ShortcutKeys shortcut={shortcut} size="small" />}>Submit</Button>
|
|
36
47
|
* @example
|
|
37
48
|
* // Simple Escape key handler (no preventDefault)
|
|
38
49
|
* const { label } = useKeyboardShortcut(
|
|
@@ -51,6 +62,4 @@ import { ShortcutDefinition, UseKeyboardShortcutOptions } from "./types";
|
|
|
51
62
|
* );
|
|
52
63
|
* // label = "Cmd + M" (Mac) or "Ctrl + M" (Windows/Linux)
|
|
53
64
|
*/
|
|
54
|
-
export declare const useKeyboardShortcut: <const TShortcut extends ShortcutDefinition>(shortcut: TShortcut extends ValidShortcutParam<TShortcut> ? TShortcut : never, { onTrigger, disabled, preventDefault, target }: UseKeyboardShortcutOptions) =>
|
|
55
|
-
label: string;
|
|
56
|
-
};
|
|
65
|
+
export declare const useKeyboardShortcut: <const TShortcut extends ShortcutDefinition>(shortcut: TShortcut extends ValidShortcutParam<TShortcut> ? TShortcut : never, { onTrigger, disabled, preventDefault, target, acceptKey, ignoreKeysTypedInFields, }: UseKeyboardShortcutOptions) => FormattedShortcut;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { formatShortcutKeys } from "./formatShortcutLabel";
|
|
2
|
+
import { getPlatform } from "./platformUtils";
|
|
3
|
+
export type ShortcutHelpers = {
|
|
4
|
+
/** One label per key of a shortcut, in the platform's order and symbols (`["⌘", "K"]`). */
|
|
5
|
+
readonly formatShortcutKeys: typeof formatShortcutKeys;
|
|
6
|
+
/** The platform the user is on, which decides what "mod" means. */
|
|
7
|
+
readonly getPlatform: typeof getPlatform;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Helpers for showing keyboard shortcuts outside `useKeyboardShortcut`, such as keycaps on a list of actions.
|
|
11
|
+
* The returned object is stable, so it can be passed to plain functions or used in effect dependencies.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const { formatShortcutKeys } = useShortcutHelpers();
|
|
15
|
+
* const keys = formatShortcutKeys({ key: "k", modifiers: "mod" });
|
|
16
|
+
*/
|
|
17
|
+
export declare const useShortcutHelpers: () => ShortcutHelpers;
|
package/src/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export { SHEET_TRANSITION_DURATION, SHEET_TRANSITION_DURATION_MS, SHEET_TRANSITI
|
|
|
89
89
|
export type { SheetAnchor, SheetDefaultSize, SheetEntryAnimation, SheetFloatingUiProps, SheetGeometry, SheetProps, SheetSizingMode, SheetSnapActions, SheetState, SheetVariant, UseSheetProps, UseSheetReturnValue, UseSheetSnapReturn, } from "./components/Sheet/sheet-types";
|
|
90
90
|
export { useSheet } from "./components/Sheet/useSheet";
|
|
91
91
|
export { useSheetSnap } from "./components/Sheet/useSheetSnap";
|
|
92
|
+
export * from "./components/ShortcutKeys/ShortcutKeys";
|
|
92
93
|
export * from "./components/Sidebar/Sidebar";
|
|
93
94
|
export * from "./components/Sidebar/useOverflowItems";
|
|
94
95
|
export * from "./components/SidebarContentLayout/SidebarContentLayout";
|
|
@@ -126,6 +127,26 @@ export * from "./hooks/localStorage/useSessionStorageReducer";
|
|
|
126
127
|
export * from "./hooks/noPagination";
|
|
127
128
|
export * from "./hooks/persistence/useStorageKey";
|
|
128
129
|
export * from "./hooks/persistence/useStripForeignIdentityHash";
|
|
130
|
+
export { type ActionAi, type ReadOnlyActionHints, type WriteActionHints } from "./hooks/useAction/actionRegistry";
|
|
131
|
+
/**
|
|
132
|
+
* For Manager's own surfaces that list, run and relay actions, and for the host's and Iris apps'
|
|
133
|
+
* providers to report actions registered wrongly.
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
export { ACTIONS_CHANGED_EVENT, INVOKE_ACTION_EVENT, type ActionIssue, type ActionIssueReporter, type ActionSubmenu, type RegisteredAction, type RelayedAction, type SerializedAction, } from "./hooks/useAction/actionRegistry";
|
|
138
|
+
export { useAction, type ActionDefinition } from "./hooks/useAction/useAction";
|
|
139
|
+
/** @internal */
|
|
140
|
+
export { useActionIssueReporter, type ActionIssueReporting } from "./hooks/useAction/useActionIssueReporter";
|
|
141
|
+
/** @internal */
|
|
142
|
+
export { useActionRelay, type ActionRelay } from "./hooks/useAction/useActionRelay";
|
|
143
|
+
export { useActions, type ActionListEntry } from "./hooks/useAction/useActions";
|
|
144
|
+
/**
|
|
145
|
+
* For Manager's own surfaces that list and run actions.
|
|
146
|
+
*
|
|
147
|
+
* @internal
|
|
148
|
+
*/
|
|
149
|
+
export { useRegisteredActions } from "./hooks/useAction/useRegisteredActions";
|
|
129
150
|
export * from "./hooks/useBidirectionalScroll";
|
|
130
151
|
export * from "./hooks/useClickOutside";
|
|
131
152
|
export * from "./hooks/useContainerBreakpoints";
|
|
@@ -140,7 +161,9 @@ export * from "./hooks/useInfiniteScroll";
|
|
|
140
161
|
export * from "./hooks/useIsFirstRender";
|
|
141
162
|
export * from "./hooks/useIsFullScreen";
|
|
142
163
|
export * from "./hooks/useIsTextTruncated";
|
|
164
|
+
export type { FormattedShortcut, ShortcutDefinition } from "./hooks/useKeyboardShortcut/types";
|
|
143
165
|
export { useKeyboardShortcut } from "./hooks/useKeyboardShortcut/useKeyboardShortcut";
|
|
166
|
+
export { useShortcutHelpers, type ShortcutHelpers } from "./hooks/useKeyboardShortcut/useShortcutHelpers";
|
|
144
167
|
export * from "./hooks/useMeasure";
|
|
145
168
|
export * from "./hooks/useMergeRefs";
|
|
146
169
|
export * from "./hooks/useModifierKey";
|
package/migrations/entry.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/components/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["// Migration entry point for @nx/js:tsc build target.\n// Migrations are registered in ../migrations.json and resolved by NX at runtime.\nexport {};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsx-utils.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/utils/jsx-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uC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E,CAChF,EAAE,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAD7E,QAAA,QAAQ,YACqE;AAE1F;;;GAGG;AACI,MAAM,UAAU,GAAG,CAAC,aAAqB,EAAE,OAAe,EAAE,kBAA2B,EAAQ,EAAE;IACtG,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;QAClB,eAAM,CAAC,IAAI,CAAC,KAAK,aAAa,oBAAoB,CAAC,CAAC;QACpD,OAAO;IACT,CAAC;IACD,MAAM,YAAY,GAChB,kBAAkB,KAAK,SAAS,IAAI,kBAAkB,GAAG,CAAC;QACxD,CAAC,CAAC,KAAK,kBAAkB,kCAAkC;QAC3D,CAAC,CAAC,EAAE,CAAC;IACT,eAAM,CAAC,IAAI,CAAC,KAAK,aAAa,aAAa,OAAO,WAAW,YAAY,EAAE,CAAC,CAAC;AAC/E,CAAC,CAAC;AAVW,QAAA,UAAU,cAUrB;AAEF;;;;;;GAMG;AACI,MAAM,6BAA6B,GAAG,CAC3C,OAAe,EACf,cAA+D,EAC/D,aAAqB,EACb,EAAE;IACV,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC;IACvC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACnC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AACtF,CAAC,CAAC;AARW,QAAA,6BAA6B,iCAQxC","sourcesContent":["import { logger, type Tree, visitNotIgnoredFiles } from \"@nx/devkit\";\nimport * as ts from \"typescript\";\n\nconst TSX_EXTENSIONS = [\".tsx\", \".jsx\"] as const;\nconst TS_EXTENSIONS = [\".ts\", \".tsx\", \".jsx\"] as const;\n\nconst isTsxFile = (filePath: string): boolean => TSX_EXTENSIONS.some(ext => filePath.endsWith(ext));\nconst isTsFile = (filePath: string): boolean => TS_EXTENSIONS.some(ext => filePath.endsWith(ext));\n\nconst isUnderNodeModules = (filePath: string): boolean =>\n filePath.includes(\"/node_modules/\") || filePath.startsWith(\"node_modules/\");\n\nconst isUnderDist = (filePath: string): boolean =>\n filePath.includes(\"/dist/\") || filePath.startsWith(\"dist/\") || filePath.includes(\"/.nx/\");\n\n/**\n * Whether a path is a `.ts`/`.tsx`/`.jsx` file that migrations look at: not under `node_modules`, `dist` or `.nx`.\n * Use it when a codemod walks the tree itself instead of going through {@link visitTsFiles}.\n */\nexport const isWorkspaceSourceFile = (filePath: string): boolean =>\n isTsFile(filePath) && !isUnderNodeModules(filePath) && !isUnderDist(filePath);\n\n/**\n * Visits every `.tsx`/`.jsx` file under the workspace root and invokes the\n * callback with the file path and its current contents. Files that don't\n * include the marker substring are skipped, which makes large workspaces\n * cheap to scan.\n */\nexport const visitTsxFiles = (\n tree: Tree,\n marker: string,\n callback: (filePath: string, content: string) => string | null | undefined\n): number => {\n let touched = 0;\n visitNotIgnoredFiles(tree, \"/\", filePath => {\n if (!isTsxFile(filePath)) return;\n if (isUnderNodeModules(filePath) || isUnderDist(filePath)) return;\n const content = tree.read(filePath, \"utf-8\");\n if (content === null) return;\n if (!content.includes(marker)) return;\n const updated = callback(filePath, content);\n if (updated !== null && updated !== undefined && updated !== content) {\n tree.write(filePath, updated);\n touched += 1;\n }\n });\n return touched;\n};\n\n/**\n * Same as {@link visitTsxFiles} but also includes plain `.ts` files. Use this\n * when the codemod also rewrites non-JSX files such as helpers or hooks.\n */\nexport const visitTsFiles = (\n tree: Tree,\n marker: string,\n callback: (filePath: string, content: string) => string | null | undefined\n): number => {\n let touched = 0;\n visitNotIgnoredFiles(tree, \"/\", filePath => {\n if (!isTsFile(filePath)) return;\n if (isUnderNodeModules(filePath) || isUnderDist(filePath)) return;\n const content = tree.read(filePath, \"utf-8\");\n if (content === null) return;\n if (!content.includes(marker)) return;\n const updated = callback(filePath, content);\n if (updated !== null && updated !== undefined && updated !== content) {\n tree.write(filePath, updated);\n touched += 1;\n }\n });\n return touched;\n};\n\n/**\n * Mapping of imported component aliases to their original names for a given\n * package. For `import { IconButton as Btn } from \"@trackunit/react-components\"`\n * this returns `{ Btn: \"IconButton\" }`.\n *\n * Returns `null` when the file imports nothing from the package, which lets\n * callers short-circuit before parsing JSX.\n */\nexport const getImportedAliases = (sourceFile: ts.SourceFile, packageName: string): Record<string, string> | null => {\n const result: Record<string, string> = {};\n let found = false;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const moduleSpecifier = stmt.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier)) continue;\n if (moduleSpecifier.text !== packageName) continue;\n\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings === undefined || !ts.isNamedImports(namedBindings)) continue;\n\n for (const element of namedBindings.elements) {\n const localName = element.name.text;\n const importedName = element.propertyName?.text ?? localName;\n result[localName] = importedName;\n found = true;\n }\n }\n\n return found ? result : null;\n};\n\n/**\n * Returns the local alias used in this file for `originalName` when imported\n * from `packageName`, or `null` if the component is not imported.\n */\nexport const getLocalAliasFor = (\n sourceFile: ts.SourceFile,\n packageName: string,\n originalName: string\n): string | null => {\n const aliases = getImportedAliases(sourceFile, packageName);\n if (aliases === null) return null;\n for (const [local, original] of Object.entries(aliases)) {\n if (original === originalName) return local;\n }\n return null;\n};\n\nexport type JsxElementMatch = {\n /** The opening JSX element (the one carrying the attributes). */\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement;\n /** The full element including children, or the self-closing element. */\n element: ts.JsxElement | ts.JsxSelfClosingElement;\n};\n\n/**\n * Finds every JSX element whose tag name resolves to one of `tagNames`\n * (typically the local aliases returned by {@link getImportedAliases}).\n *\n * The result intentionally includes both opening and full elements so callers\n * can manipulate attributes (via `openingElement`) or wrap/replace the whole\n * element (via `element`).\n */\nexport const findJsxElements = (\n sourceFile: ts.SourceFile,\n tagNames: ReadonlyArray<string>\n): ReadonlyArray<JsxElementMatch> => {\n const matches: Array<JsxElementMatch> = [];\n const tagSet = new Set(tagNames);\n\n const visit = (node: ts.Node): void => {\n if (ts.isJsxSelfClosingElement(node)) {\n if (ts.isIdentifier(node.tagName) && tagSet.has(node.tagName.text)) {\n matches.push({ openingElement: node, element: node });\n }\n } else if (ts.isJsxElement(node)) {\n const opening = node.openingElement;\n if (ts.isIdentifier(opening.tagName) && tagSet.has(opening.tagName.text)) {\n matches.push({ openingElement: opening, element: node });\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(sourceFile);\n return matches;\n};\n\n/**\n * Looks up a named JSX attribute on the opening element. Returns `null` when\n * the attribute is missing or part of a spread attribute (which we cannot\n * statically inspect).\n */\nexport const findJsxAttribute = (\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement,\n attributeName: string\n): ts.JsxAttribute | null => {\n for (const attr of openingElement.attributes.properties) {\n if (!ts.isJsxAttribute(attr)) continue;\n if (!ts.isIdentifier(attr.name)) continue;\n if (attr.name.text === attributeName) return attr;\n }\n return null;\n};\n\n/**\n * `true` when the element forwards a spread expression such as `{...rest}`,\n * which means we can't be sure which attributes are actually set.\n */\nexport const hasSpreadAttribute = (openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement): boolean => {\n return openingElement.attributes.properties.some(prop => ts.isJsxSpreadAttribute(prop));\n};\n\n/**\n * Parses the file as TSX so JSX is recognised. We do not need a full program\n * here; tsquery's `ast` helper produces a script-kind source file which loses\n * JSX context, so we go through `createSourceFile` directly.\n */\nexport const parseTsx = (content: string, fileName = \"file.tsx\"): ts.SourceFile =>\n ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);\n\n/**\n * Helper for codemods to log a one-line summary at the end of a run. Migration\n * runners aggregate logs per migration, so this keeps output focused.\n */\nexport const logSummary = (migrationName: string, touched: number, manualReviewNeeded?: number): void => {\n if (touched === 0) {\n logger.info(` ${migrationName}: no files changed`);\n return;\n }\n const reviewSuffix =\n manualReviewNeeded !== undefined && manualReviewNeeded > 0\n ? ` (${manualReviewNeeded} location(s) need manual review)`\n : \"\";\n logger.info(` ${migrationName}: updated ${touched} file(s)${reviewSuffix}`);\n};\n\n/**\n * Inserts an attribute string immediately after the tag name (so the new\n * attribute appears first). Returns the resulting source content.\n *\n * The added attribute is rendered verbatim, so callers are responsible for\n * including the leading space (e.g. ` title=\"Close\"`).\n */\nexport const insertAttributeIntoOpeningTag = (\n content: string,\n openingElement: ts.JsxOpeningElement | ts.JsxSelfClosingElement,\n attributeText: string\n): string => {\n const tagName = openingElement.tagName;\n const insertPos = tagName.getEnd();\n return `${content.slice(0, insertPos)} ${attributeText}${content.slice(insertPos)}`;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"move-named-imports.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/utils/move-named-imports.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAA+C;AAC/C,+CAAiC;AACjC,2CAA2C;AAyC3C,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAClE,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC;IAChD,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,cAAc;IACd,YAAY;IACZ,eAAe;IACf,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,CAAC,KAAiB,EAA+B,EAAE,CACrE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC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AQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAChE,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QAC1C,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO;YAAE,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC5D,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AACxC,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B;AAEF,mFAAmF;AAC5E,MAAM,eAAe,GAAG,CAAC,aAAqB,EAAE,KAAsC,EAAQ,EAAE;IACrG,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QAC3C,eAAM,CAAC,IAAI,CAAC,KAAK,aAAa,6BAA6B,IAAI,IAAI,IAAI,MAAM,MAAM,EAAE,CAAC,CAAC;IACzF,CAAC;AACH,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B","sourcesContent":["import { logger, type Tree } from \"@nx/devkit\";\nimport * as ts from \"typescript\";\nimport { visitTsFiles } from \"./jsx-utils\";\n\n/**\n * Names to move. A list keeps every name; a record maps each old exported\n * name to its new exported name in the target module.\n */\nexport type MovedNames = ReadonlyArray<string> | Readonly<Record<string, string>>;\n\nexport type MoveNamedImportsOptions = {\n /** Module the names are imported from today, e.g. `@trackunit/ui-connected-components`. */\n readonly fromModule: string;\n /** Module that exports the names now, e.g. `@trackunit/react-router-components`. */\n readonly toModule: string;\n readonly names: MovedNames;\n};\n\nexport type ManualReviewItem = {\n readonly file: string;\n /** 1-based line of the usage. */\n readonly line: number;\n readonly reason: string;\n};\n\nexport type MoveNamedImportsResult = {\n readonly changedFiles: ReadonlyArray<string>;\n /** Usages the codemod could not rewrite safely. They are left as-is and must be fixed by hand. */\n readonly manualReview: ReadonlyArray<ManualReviewItem>;\n};\n\ntype Edit = { start: number; end: number; text: string };\n\n/** A moved specifier as it should be written against the target module. */\ntype MovedSpecifier = {\n /** Exported name in the target module. */\n readonly imported: string;\n /** Local binding (imports) or public name (re-exports). */\n readonly local: string;\n /** `true` for an inline `type` modifier, or any specifier of an `import type` / `export type`. */\n readonly isTypeOnly: boolean;\n};\n\nconst MOCK_OBJECTS: ReadonlySet<string> = new Set([\"vi\", \"jest\"]);\nconst MOCK_METHODS: ReadonlySet<string> = new Set([\n \"mock\",\n \"doMock\",\n \"unmock\",\n \"doUnmock\",\n \"importActual\",\n \"importMock\",\n \"requireActual\",\n \"requireMock\",\n]);\n\nconst toRenameMap = (names: MovedNames): ReadonlyMap<string, string> =>\n Array.isArray(names) ? new Map(names.map(name => [name, name])) : new Map(Object.entries(names));\n\nconst parseSource = (filePath: string, content: string): ts.SourceFile =>\n ts.createSourceFile(\n filePath,\n content,\n ts.ScriptTarget.Latest,\n true,\n filePath.endsWith(\".ts\") ? ts.ScriptKind.TS : ts.ScriptKind.TSX\n );\n\nconst isModule = (node: ts.Expression | undefined, moduleName: string): boolean =>\n node !== undefined &&\n (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) &&\n node.text === moduleName;\n\n/** Renders `moduleName` with the quote style of an existing specifier. */\nconst quoteLike = (specifier: ts.Expression, moduleName: string): string => {\n const quote = specifier.getText().startsWith(\"'\") ? \"'\" : '\"';\n return `${quote}${moduleName}${quote}`;\n};\n\nconst renderSpecifier = ({ imported, local, isTypeOnly }: MovedSpecifier, withTypePrefix: boolean): string =>\n `${withTypePrefix && isTypeOnly ? \"type \" : \"\"}${imported === local ? imported : `${imported} as ${local}`}`;\n\nconst statementTerminator = (statement: ts.Statement): string => (statement.getText().endsWith(\";\") ? \";\" : \"\");\n\nconst lineOf = (sourceFile: ts.SourceFile, node: ts.Node): number =>\n sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;\n\n/** `true` when `node` is a property-like key (`a.X`, `{ X: 1 }`, `<C X=\"\" />`) rather than a reference to a binding. */\nconst isPropertyKey = (node: ts.Identifier): boolean => {\n const parent = node.parent;\n if (ts.isPropertyAccessExpression(parent) || ts.isQualifiedName(parent)) {\n return ts.isPropertyAccessExpression(parent) ? parent.name === node : parent.right === node;\n }\n if (ts.isBindingElement(parent)) return parent.propertyName === node;\n if (\n ts.isPropertyAssignment(parent) ||\n ts.isPropertyDeclaration(parent) ||\n ts.isPropertySignature(parent) ||\n ts.isMethodDeclaration(parent) ||\n ts.isMethodSignature(parent) ||\n ts.isGetAccessorDeclaration(parent) ||\n ts.isSetAccessorDeclaration(parent) ||\n ts.isEnumMember(parent) ||\n ts.isJsxAttribute(parent)\n ) {\n return parent.name === node;\n }\n return false;\n};\n\n/** `true` when `node` declares a new binding (variable, parameter, function, class, type...). */\nconst isBindingDeclaration = (node: ts.Identifier): boolean => {\n const parent = node.parent;\n if (ts.isBindingElement(parent)) return parent.name === node;\n if (\n ts.isVariableDeclaration(parent) ||\n ts.isParameter(parent) ||\n ts.isFunctionDeclaration(parent) ||\n ts.isFunctionExpression(parent) ||\n ts.isClassDeclaration(parent) ||\n ts.isClassExpression(parent) ||\n ts.isInterfaceDeclaration(parent) ||\n ts.isTypeAliasDeclaration(parent) ||\n ts.isEnumDeclaration(parent) ||\n ts.isTypeParameterDeclaration(parent) ||\n ts.isImportSpecifier(parent) ||\n ts.isImportClause(parent) ||\n ts.isNamespaceImport(parent) ||\n ts.isImportEqualsDeclaration(parent)\n ) {\n return parent.name === node;\n }\n return false;\n};\n\n/** Import and re-export statements are rewritten as a whole, so their identifiers are never edited one by one. */\nconst isInsideModuleStatement = (node: ts.Node): boolean =>\n ts.findAncestor(\n node,\n ancestor =>\n ts.isImportDeclaration(ancestor) || (ts.isExportDeclaration(ancestor) && ancestor.moduleSpecifier !== undefined)\n ) !== undefined;\n\nconst collectIdentifiers = (sourceFile: ts.SourceFile): ReadonlyArray<ts.Identifier> => {\n const identifiers: Array<ts.Identifier> = [];\n const visit = (node: ts.Node): void => {\n if (ts.isIdentifier(node)) identifiers.push(node);\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return identifiers;\n};\n\n/**\n * Edits that rename every reference to the local binding `oldName` to\n * `newName`, or `null` when that can't be done safely (the new name is\n * already used in the file, or `oldName` is redeclared and might be shadowed).\n */\nconst renameReferenceEdits = (\n sourceFile: ts.SourceFile,\n identifiers: ReadonlyArray<ts.Identifier>,\n oldName: string,\n newName: string\n): Array<Edit> | null => {\n if (identifiers.some(id => id.text === newName)) return null;\n const outside = identifiers.filter(id => id.text === oldName && !isInsideModuleStatement(id));\n if (outside.some(isBindingDeclaration)) return null;\n\n const edits: Array<Edit> = [];\n for (const id of outside) {\n if (isPropertyKey(id)) continue;\n const start = id.getStart(sourceFile);\n const end = id.getEnd();\n const parent = id.parent;\n if (ts.isShorthandPropertyAssignment(parent)) {\n edits.push({ start, end, text: `${oldName}: ${newName}` });\n } else if (ts.isExportSpecifier(parent)) {\n if (parent.propertyName === undefined) edits.push({ start, end, text: `${newName} as ${oldName}` });\n else if (parent.propertyName === id) edits.push({ start, end, text: newName });\n } else {\n edits.push({ start, end, text: newName });\n }\n }\n return edits;\n};\n\n/**\n * Usages of `fromModule` the codemod can't rewrite statically. They are only\n * reported when the file references a moved name at all, so e.g. a\n * `vi.mock(fromModule, ...)` in a spec that never touches a moved name is not\n * noise. `export *` is always reported: the moved names silently drop out of it.\n */\nconst findManualReviewItems = (\n sourceFile: ts.SourceFile,\n identifiers: ReadonlyArray<ts.Identifier>,\n fromModule: string,\n toModule: string,\n renames: ReadonlyMap<string, string>\n): Array<ManualReviewItem> => {\n const items: Array<ManualReviewItem> = [];\n const file = sourceFile.fileName;\n const mentionsMovedName =\n identifiers.some(id => renames.has(id.text)) || sourceFile.text.split(/[\"'`]/).some(chunk => renames.has(chunk));\n const movedList = [...renames.keys()].join(\", \");\n const hint = `moved names (${movedList}) now come from \"${toModule}\"`;\n\n const report = (node: ts.Node, what: string): void => {\n items.push({ file, line: lineOf(sourceFile, node), reason: `${what} of \"${fromModule}\"; ${hint}` });\n };\n\n const visit = (node: ts.Node): void => {\n if (ts.isImportDeclaration(node) && isModule(node.moduleSpecifier, fromModule)) {\n const bindings = node.importClause?.namedBindings;\n if (bindings !== undefined && ts.isNamespaceImport(bindings) && mentionsMovedName) {\n report(node, `namespace import \\`* as ${bindings.name.text}\\``);\n }\n } else if (ts.isExportDeclaration(node) && isModule(node.moduleSpecifier, fromModule)) {\n if (node.exportClause === undefined) report(node, \"`export *`\");\n else if (ts.isNamespaceExport(node.exportClause)) report(node, \"`export * as`\");\n } else if (ts.isImportEqualsDeclaration(node) && mentionsMovedName) {\n const reference = node.moduleReference;\n if (ts.isExternalModuleReference(reference) && isModule(reference.expression, fromModule)) {\n report(node, \"`import = require()`\");\n }\n } else if (ts.isImportTypeNode(node) && mentionsMovedName) {\n const argument = node.argument;\n if (ts.isLiteralTypeNode(argument) && isModule(argument.literal, fromModule)) report(node, \"`import()` type\");\n } else if (ts.isCallExpression(node) && mentionsMovedName && isModule(node.arguments[0], fromModule)) {\n const callee = node.expression;\n if (callee.kind === ts.SyntaxKind.ImportKeyword) {\n report(node, \"dynamic import()\");\n } else if (ts.isIdentifier(callee) && callee.text === \"require\") {\n report(node, \"require()\");\n } else if (\n ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n MOCK_OBJECTS.has(callee.expression.text) &&\n MOCK_METHODS.has(callee.name.text)\n ) {\n report(node, `${callee.expression.text}.${callee.name.text}()`);\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(sourceFile);\n return items;\n};\n\ntype TargetImport = {\n readonly statement: ts.ImportDeclaration;\n readonly elements: ts.NodeArray<ts.ImportSpecifier>;\n readonly additions: Array<MovedSpecifier>;\n};\n\nconst findTargetImport = (sourceFile: ts.SourceFile, toModule: string, typeOnly: boolean): TargetImport | null => {\n for (const statement of sourceFile.statements) {\n if (!ts.isImportDeclaration(statement) || !isModule(statement.moduleSpecifier, toModule)) continue;\n const clause = statement.importClause;\n if (clause === undefined || clause.isTypeOnly !== typeOnly) continue;\n const bindings = clause.namedBindings;\n if (bindings === undefined || !ts.isNamedImports(bindings)) continue;\n return { statement, elements: bindings.elements, additions: [] };\n }\n return null;\n};\n\nconst specifierKey = ({ imported, local }: MovedSpecifier): string => `${imported} as ${local}`;\n\nconst specifierOf = (element: ts.ImportSpecifier, parentTypeOnly: boolean): MovedSpecifier => ({\n imported: (element.propertyName ?? element.name).text,\n local: element.name.text,\n isTypeOnly: parentTypeOnly || element.isTypeOnly,\n});\n\nconst rewriteFile = (\n filePath: string,\n content: string,\n { fromModule, toModule }: MoveNamedImportsOptions,\n renames: ReadonlyMap<string, string>\n): { content: string; manualReview: Array<ManualReviewItem> } => {\n const sourceFile = parseSource(filePath, content);\n const identifiers = collectIdentifiers(sourceFile);\n const manualReview = findManualReviewItems(sourceFile, identifiers, fromModule, toModule, renames);\n\n const edits: Array<Edit> = [];\n const valueTarget = findTargetImport(sourceFile, toModule, false);\n const typeTarget = findTargetImport(sourceFile, toModule, true);\n\n const targetFor = (spec: MovedSpecifier): TargetImport | null => {\n if (!spec.isTypeOnly) return valueTarget;\n return typeTarget ?? valueTarget;\n };\n\n const replaceStatement = (statement: ts.Statement, kept: string | null, added: ReadonlyArray<string>): void => {\n const parts = [...(kept === null ? [] : [kept]), ...added];\n const start = statement.getStart(sourceFile);\n let end = statement.getEnd();\n if (parts.length === 0) {\n if (content.startsWith(\"\\r\\n\", end)) end += 2;\n else if (content.startsWith(\"\\n\", end)) end += 1;\n const leading = content.slice(statement.getFullStart(), start);\n if (leading.includes(\"eslint-disable\")) {\n manualReview.push({\n file: filePath,\n line: lineOf(sourceFile, statement),\n reason: `removed import of \"${fromModule}\" had an eslint-disable comment, which now applies to the next line`,\n });\n }\n }\n edits.push({ start, end, text: parts.join(\"\\n\") });\n };\n\n /**\n * Moved names with no existing target import, keyed by whether they came\n * from an `import type`. Each kind is written as one new import at the\n * first statement that needed it, so several old imports never become\n * several imports of `toModule`.\n */\n type CreatedImport = { readonly anchor: ts.ImportDeclaration; readonly specs: Array<MovedSpecifier> };\n const createdImports = new Map<boolean, CreatedImport>();\n const deferredImports: Array<{ statement: ts.ImportDeclaration; keptText: string | null }> = [];\n\n for (const statement of sourceFile.statements) {\n if (ts.isImportDeclaration(statement) && isModule(statement.moduleSpecifier, fromModule)) {\n const clause = statement.importClause;\n const bindings = clause?.namedBindings;\n if (clause === undefined || bindings === undefined || !ts.isNamedImports(bindings)) continue;\n const moved = bindings.elements.filter(element => renames.has((element.propertyName ?? element.name).text));\n if (moved.length === 0) continue;\n\n const kept = bindings.elements.filter(element => !moved.includes(element));\n const createdKind = clause.isTypeOnly;\n const addCreated = (spec: MovedSpecifier): void => {\n const created = createdImports.get(createdKind) ?? { anchor: statement, specs: [] };\n createdImports.set(createdKind, created);\n if (!created.specs.some(existing => specifierKey(existing) === specifierKey(spec))) created.specs.push(spec);\n };\n for (const element of moved) {\n const original = specifierOf(element, clause.isTypeOnly);\n const newName = renames.get(original.imported) ?? original.imported;\n let local = original.local;\n if (newName !== original.imported && original.local === original.imported) {\n const renameEdits = renameReferenceEdits(sourceFile, identifiers, original.local, newName);\n if (renameEdits !== null) {\n edits.push(...renameEdits);\n local = newName;\n }\n }\n const spec: MovedSpecifier = { imported: newName, local, isTypeOnly: original.isTypeOnly };\n const target = targetFor(spec);\n if (target === null) {\n addCreated(spec);\n continue;\n }\n const existing = new Set([\n ...target.elements.map(e => specifierKey(specifierOf(e, false))),\n ...target.additions.map(specifierKey),\n ]);\n if (!existing.has(specifierKey(spec))) target.additions.push(spec);\n }\n\n const terminator = statementTerminator(statement);\n const defaultName = clause.name?.text;\n const keptText =\n kept.length === 0 && defaultName === undefined\n ? null\n : `import ${clause.isTypeOnly ? \"type \" : \"\"}${[\n ...(defaultName === undefined ? [] : [defaultName]),\n ...(kept.length === 0 ? [] : [`{ ${kept.map(e => e.getText(sourceFile)).join(\", \")} }`]),\n ].join(\", \")} from ${statement.moduleSpecifier.getText(sourceFile)}${terminator}`;\n deferredImports.push({ statement, keptText });\n } else if (\n ts.isExportDeclaration(statement) &&\n isModule(statement.moduleSpecifier, fromModule) &&\n statement.moduleSpecifier !== undefined &&\n statement.exportClause !== undefined &&\n ts.isNamedExports(statement.exportClause)\n ) {\n const elements = statement.exportClause.elements;\n const moved = elements.filter(element => renames.has((element.propertyName ?? element.name).text));\n if (moved.length === 0) continue;\n const kept = elements.filter(element => !moved.includes(element));\n const typePrefix = statement.isTypeOnly ? \"type \" : \"\";\n const terminator = statementTerminator(statement);\n const specs = moved.map(element => {\n const imported = (element.propertyName ?? element.name).text;\n return renderSpecifier(\n { imported: renames.get(imported) ?? imported, local: element.name.text, isTypeOnly: element.isTypeOnly },\n true\n );\n });\n replaceStatement(\n statement,\n kept.length === 0\n ? null\n : `export ${typePrefix}{ ${kept.map(e => e.getText(sourceFile)).join(\", \")} } from ${statement.moduleSpecifier.getText(sourceFile)}${terminator}`,\n [\n `export ${typePrefix}{ ${specs.join(\", \")} } from ${quoteLike(statement.moduleSpecifier, toModule)}${terminator}`,\n ]\n );\n }\n }\n\n for (const { statement, keptText } of deferredImports) {\n const createdText = [...createdImports.entries()]\n .filter(([, created]) => created.anchor === statement)\n .map(\n ([typeOnly, created]) =>\n `import ${typeOnly ? \"type \" : \"\"}{ ${created.specs\n .map(spec => renderSpecifier(spec, !typeOnly))\n .join(\", \")} } from ${quoteLike(statement.moduleSpecifier, toModule)}${statementTerminator(statement)}`\n );\n replaceStatement(statement, keptText, createdText);\n }\n\n for (const target of [valueTarget, typeTarget]) {\n if (target === null || target.additions.length === 0) continue;\n const typeOnly = target.statement.importClause?.isTypeOnly === true;\n const bindings = target.statement.importClause?.namedBindings;\n if (bindings === undefined) continue;\n const merged = [\n ...target.elements.map(e => e.getText(sourceFile)),\n ...target.additions.map(spec => renderSpecifier(spec, !typeOnly)),\n ];\n edits.push({ start: bindings.getStart(sourceFile), end: bindings.getEnd(), text: `{ ${merged.join(\", \")} }` });\n }\n\n if (edits.length === 0) return { content, manualReview };\n edits.sort((a, b) => b.start - a.start);\n let updated = content;\n for (const { start, end, text } of edits) {\n updated = updated.slice(0, start) + text + updated.slice(end);\n }\n return { content: updated, manualReview };\n};\n\n/**\n * Moves named imports and named re-exports of `names` from `fromModule` to\n * `toModule` across every `.ts`/`.tsx`/`.jsx` file in the tree.\n *\n * - Mixed imports are split; names that didn't move stay on `fromModule`.\n * - Aliases (`as`), `import type` and inline `type` modifiers are preserved.\n * - Moved names are merged into an existing named import of `toModule`, or\n * else into one new import per kind (value / `import type`).\n * - With a rename record, an unaliased import has its references renamed too;\n * when that isn't safe (name clash or shadowing) it is imported as\n * `{ NewName as OldName }` instead. Re-exports keep their public name.\n * - Namespace imports, `export *`, dynamic `import()`, `require()` and\n * `vi`/`jest` mocks of `fromModule` are left untouched and returned in\n * `manualReview`, never skipped silently.\n *\n * Synchronous and format-free, so it can run inside a `run-migrations`\n * migration; callers format changed files themselves (e.g. `formatFiles`).\n */\nexport const moveNamedImports = (tree: Tree, options: MoveNamedImportsOptions): MoveNamedImportsResult => {\n const renames = toRenameMap(options.names);\n const changedFiles: Array<string> = [];\n const manualReview: Array<ManualReviewItem> = [];\n\n visitTsFiles(tree, options.fromModule, (filePath, content) => {\n const result = rewriteFile(filePath, content, options, renames);\n manualReview.push(...result.manualReview);\n if (result.content !== content) changedFiles.push(filePath);\n return result.content;\n });\n\n return { changedFiles, manualReview };\n};\n\n/** Logs each manual-review item as a warning, prefixed with the migration name. */\nexport const logManualReview = (migrationName: string, items: ReadonlyArray<ManualReviewItem>): void => {\n for (const { file, line, reason } of items) {\n logger.warn(` ${migrationName}: manual review needed at ${file}:${line} - ${reason}`);\n }\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package-json-utils.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/utils/package-json-utils.ts"],"names":[],"mappings":";;;AAAA,uCAAqG;AACrG,qCAAmD;AAEnD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AK,CAAC,iCAAiC,WAAW,gBAAgB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3G,CAAC,CAAC;AATW,QAAA,oBAAoB,wBAS/B","sourcesContent":["import { addDependenciesToPackageJson, readJson, type Tree, visitNotIgnoredFiles } from \"@nx/devkit\";\nimport { existsSync, readFileSync } from \"node:fs\";\n\n/** Root package name of the manager monorepo, where `@trackunit/*` versions are owned by CI. */\nconst MANAGER_WORKSPACE_PACKAGE_NAME = \"@trackunit/manager\";\n\ntype PackageJson = {\n readonly name?: string;\n readonly version?: string;\n readonly dependencies?: Readonly<Record<string, string>>;\n readonly devDependencies?: Readonly<Record<string, string>>;\n readonly peerDependencies?: Readonly<Record<string, string>>;\n};\n\nexport type EnsureDependencyOptions = {\n readonly packageName: string;\n /** Range written when the dependency is added, e.g. `^1.2.0`. */\n readonly range: string;\n /**\n * Put the dependency in the same field as this package: `devDependencies`\n * when it is only a devDependency, otherwise `dependencies`.\n */\n readonly besidePackage?: string;\n /** Defaults to the workspace root `package.json`. */\n readonly packageJsonPath?: string;\n};\n\nexport type EnsureDependencyResult = \"added\" | \"already-present\" | \"no-package-json\" | \"manager-workspace\";\n\n/**\n * Adds `packageName@range` to a package.json unless it is already declared\n * in `dependencies` or `devDependencies` (an existing entry is never\n * changed). Does nothing in the manager monorepo itself. Doesn't install;\n * the consumer has to re-install afterwards.\n */\nexport const ensureDependency = (tree: Tree, options: EnsureDependencyOptions): EnsureDependencyResult => {\n const { packageName, range, besidePackage, packageJsonPath = \"package.json\" } = options;\n if (!tree.exists(packageJsonPath)) return \"no-package-json\";\n\n const packageJson = readJson<PackageJson>(tree, packageJsonPath);\n if (packageJson.name === MANAGER_WORKSPACE_PACKAGE_NAME) return \"manager-workspace\";\n if (\n packageJson.dependencies?.[packageName] !== undefined ||\n packageJson.devDependencies?.[packageName] !== undefined\n ) {\n return \"already-present\";\n }\n\n const asDevDependency =\n besidePackage !== undefined &&\n packageJson.dependencies?.[besidePackage] === undefined &&\n packageJson.devDependencies?.[besidePackage] !== undefined;\n const entry = { [packageName]: range };\n addDependenciesToPackageJson(tree, asDevDependency ? {} : entry, asDevDependency ? entry : {}, packageJsonPath, true);\n return \"added\";\n};\n\n/**\n * Every package.json except the root one (and anything under\n * `node_modules`) that declares `packageName` as a dependency, devDependency\n * or peerDependency.\n */\nexport const findPackageJsonsDeclaring = (tree: Tree, packageName: string): Array<string> => {\n const found: Array<string> = [];\n visitNotIgnoredFiles(tree, \"/\", filePath => {\n if (filePath === \"package.json\" || !filePath.endsWith(\"/package.json\")) return;\n if (filePath.startsWith(\"node_modules/\") || filePath.includes(\"/node_modules/\")) return;\n const packageJson = readJson<PackageJson>(tree, filePath);\n if (\n packageJson.dependencies?.[packageName] !== undefined ||\n packageJson.devDependencies?.[packageName] !== undefined ||\n packageJson.peerDependencies?.[packageName] !== undefined\n ) {\n found.push(filePath);\n }\n });\n return found;\n};\n\n/**\n * Version of a companion package, read from the first of `candidatePaths`\n * (absolute file-system paths, not tree paths) that is the package.json of\n * `packageName`. Throws when none is, so a migration fails and stays pending\n * instead of writing a wrong range.\n */\nexport const readCompanionVersion = (packageName: string, candidatePaths: ReadonlyArray<string>): string => {\n for (const candidatePath of candidatePaths) {\n if (!existsSync(candidatePath)) continue;\n const packageJson: PackageJson = JSON.parse(readFileSync(candidatePath, \"utf-8\"));\n if (packageJson.name === packageName && typeof packageJson.version === \"string\" && packageJson.version !== \"\") {\n return packageJson.version;\n }\n }\n throw new Error(`Could not find the version of ${packageName}. Looked in: ${candidatePaths.join(\", \")}`);\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"breadcrumb-remove-deprecated-props.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/v2-0-0/breadcrumb-remove-deprecated-props.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,kDAO4B;AAE5B,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,eAAe,G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n parseTsx,\n visitTsxFiles,\n} from \"../utils/jsx-utils\";\n\nconst PACKAGE_NAME = \"@trackunit/react-components\";\nconst COMPONENT_NAMES = [\"Breadcrumb\", \"BreadcrumbContainer\", \"BreadcrumbForMediumScreen\"] as const;\nconst PROPS_TO_REMOVE = [\"backButtonTitle\", \"expandCollapsedItemsTitle\"] as const;\n\nconst stripDeprecatedProps = (filePath: string, content: string): string | null => {\n const sourceFile = parseTsx(content, filePath);\n\n const aliases = getImportedAliases(sourceFile, PACKAGE_NAME);\n if (aliases === null) return null;\n\n const localTagNames: Array<string> = [];\n for (const [local, original] of Object.entries(aliases)) {\n if (COMPONENT_NAMES.some(name => name === original)) {\n localTagNames.push(local);\n }\n }\n if (localTagNames.length === 0) return null;\n\n const matches = findJsxElements(sourceFile, localTagNames);\n if (matches.length === 0) return null;\n\n // Collect every (start, end) range we want to delete. We process them in\n // reverse so earlier offsets stay valid while we splice.\n const ranges: Array<{ start: number; end: number }> = [];\n for (const { openingElement } of matches) {\n for (const propName of PROPS_TO_REMOVE) {\n const attr = findJsxAttribute(openingElement, propName);\n if (attr === null) continue;\n\n // Drop trailing whitespace + the attribute itself so we don't leave a\n // dangling space inside the opening tag. e.g. `<X foo=\"a\" bar=\"b\" />`\n // becomes `<X foo=\"a\" />` and `<X bar=\"b\" />` becomes `<X />`.\n let start = attr.getFullStart();\n const end = attr.getEnd();\n // getFullStart includes leading whitespace which is what we want.\n // Guard against negative ranges if multiple props collapse later.\n if (start < 0) start = attr.getStart();\n ranges.push({ start, end });\n }\n }\n\n if (ranges.length === 0) return null;\n\n ranges.sort((a, b) => b.start - a.start);\n\n let updated = content;\n for (const { start, end } of ranges) {\n updated = updated.slice(0, start) + updated.slice(end);\n }\n\n return updated;\n};\n\n/**\n * Removes the no-longer-supported `backButtonTitle` and\n * `expandCollapsedItemsTitle` props from `<Breadcrumb>`,\n * `<BreadcrumbContainer>`, and `<BreadcrumbForMediumScreen>`. Their accessible\n * names are now sourced from the `react-components` library translations.\n */\nexport const breadcrumbRemoveDeprecatedProps = (tree: Tree): void => {\n const touched = visitTsxFiles(tree, \"Breadcrumb\", stripDeprecatedProps);\n logSummary(\"breadcrumb-remove-deprecated-props\", touched);\n logger.info(\n \" Ensure the host application registers the @trackunit/react-components library translations so the back/expand buttons render localized labels.\"\n );\n};\n\nexport default breadcrumbRemoveDeprecatedProps;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cardheader-onclickclose-to-actions.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/v2-0-0/cardheader-onclickclose-to-actions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,kDAO4B;AAE5B,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,cAAc,GAAG,YAAY,CAAC;AAEpC,MAAM,kBAAkB,GAAG,CAAC,YAAY,EAAE,MAAM,CAAU,CAAC;AAE3D,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAE,SAAiB,EAAE,eAAuB,EAAU,EAAE,CACpG,IAAI,eAAe,WAAW,SAAS,2CAA2C,WAAW,4CAA4C,CAAC;AAE5I,MAAM,iBAAiB,GAAG,CAAC,OAAe,EAAE,WAAmB,EAAE,UAAiC,EAAU,EAAE;IAC5G,MAAM,UAAU,GAAG,IAAA,oBAAQ,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAA,8BAAkB,EAAC,UAAU,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;IAElE,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAClF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAEzC,KAAK,MAAM,IAAI,IAAI,UA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{ type Tree } from \"@nx/devkit\";\nimport * as ts from \"typescript\";\nimport {\n findJsxAttribute,\n findJsxElements,\n getImportedAliases,\n logSummary,\n parseTsx,\n visitTsxFiles,\n} from \"../utils/jsx-utils\";\n\nconst PACKAGE_NAME = \"@trackunit/react-components\";\nconst COMPONENT_NAME = \"CardHeader\";\n\nconst CLOSE_BUTTON_NAMES = [\"IconButton\", \"Icon\"] as const;\n\nconst renderCloseButton = (handlerExpr: string, iconAlias: string, iconButtonAlias: string): string =>\n `<${iconButtonAlias} icon={<${iconAlias} name=\"XMark\" size=\"small\" />} onClick={${handlerExpr}} title=\"Close\" variant=\"ghost-neutral\" />`;\n\nconst ensureNamedImport = (content: string, packageName: string, namesToAdd: ReadonlyArray<string>): string => {\n const sourceFile = parseTsx(content, \"source.tsx\");\n const aliases = getImportedAliases(sourceFile, packageName) ?? {};\n\n const missing = namesToAdd.filter(name => !Object.values(aliases).includes(name));\n if (missing.length === 0) return content;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const moduleSpecifier = stmt.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier) || moduleSpecifier.text !== packageName) continue;\n\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings === undefined || !ts.isNamedImports(namedBindings)) continue;\n\n const elementsText = namedBindings.elements.map(el => el.getText()).join(\", \");\n const merged = [elementsText, ...missing].join(\", \");\n const before = content.slice(0, namedBindings.getStart());\n const after = content.slice(namedBindings.getEnd());\n return `${before}{ ${merged} }${after}`;\n }\n\n // No existing import from the package; add a fresh line near the top.\n const importLine = `import { ${missing.join(\", \")} } from \"${packageName}\";\\n`;\n return importLine + content;\n};\n\nconst transformCardHeaderUsage = (filePath: string, content: string): string | null => {\n const sourceFile = parseTsx(content, filePath);\n\n const aliases = getImportedAliases(sourceFile, PACKAGE_NAME);\n if (aliases === null) return null;\n\n const cardHeaderAlias = Object.entries(aliases).find(([, name]) => name === COMPONENT_NAME)?.[0];\n if (cardHeaderAlias === undefined) return null;\n\n const matches = findJsxElements(sourceFile, [cardHeaderAlias]);\n if (matches.length === 0) return null;\n\n type Edit = { start: number; end: number; replacement: string };\n const edits: Array<Edit> = [];\n\n for (const { openingElement } of matches) {\n const onClickCloseAttr = findJsxAttribute(openingElement, \"onClickClose\");\n if (onClickCloseAttr === null) continue;\n\n const initializer = onClickCloseAttr.initializer;\n if (initializer === undefined) continue;\n\n let handlerExpr: string;\n if (ts.isJsxExpression(initializer) && initializer.expression !== undefined) {\n handlerExpr = initializer.expression.getText();\n } else if (ts.isStringLiteral(initializer)) {\n handlerExpr = `\"${initializer.text}\"`;\n } else {\n continue;\n }\n\n const actionsAttr = findJsxAttribute(openingElement, \"actions\");\n if (actionsAttr !== null) {\n // Don't try to merge with an existing actions prop; flag and skip.\n continue;\n }\n\n const replacement = `actions={${renderCloseButton(handlerExpr, \"Icon\", \"IconButton\")}}`;\n edits.push({\n start: onClickCloseAttr.getStart(),\n end: onClickCloseAttr.getEnd(),\n replacement,\n });\n }\n\n if (edits.length === 0) return null;\n\n edits.sort((a, b) => b.start - a.start);\n\n let updated = content;\n for (const { start, end, replacement } of edits) {\n updated = updated.slice(0, start) + replacement + updated.slice(end);\n }\n\n updated = ensureNamedImport(updated, PACKAGE_NAME, [...CLOSE_BUTTON_NAMES]);\n\n return updated;\n};\n\n/**\n * Replaces the removed `onClickClose` prop on `<CardHeader>` with the\n * equivalent action rendered through the `actions` slot using `IconButton` +\n * the `XMark` icon.\n *\n * Cards that already declared `actions` are skipped to avoid clobbering\n * existing markup.\n */\nexport const cardHeaderOnClickCloseToActions = (tree: Tree): void => {\n const touched = visitTsxFiles(tree, \"CardHeader\", transformCardHeaderUsage);\n logSummary(\"cardheader-onclickclose-to-actions\", touched);\n};\n\nexport default cardHeaderOnClickCloseToActions;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iconbutton-add-required-name.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/v2-0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,KAAK,CAAC,IAAI,CAAC;YACT,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE;YACvC,IAAI,EAAE,WAAW,iBAAiB,GAAG;SACtC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAExE,IAAI,OAAO,GAAG,OAAO,CAAC;IACtB,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;QACrC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACI,MAAM,yBAAyB,GAAG,CAAC,IAAU,EAAQ,EAAE;IAC5D,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,IAAI,EAAE,YAAY,EAAE,wBAAwB,CAAC,CAAC;IAC5E,IAAA,sBAAU,EAAC,8BAA8B,EAAE,OAAO,CAAC,CAAC;IACpD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;QAChB,eAAM,CAAC,IAAI,CACT,8BAA8B,iBAAiB,6EAA6E,CAC7H,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AARW,QAAA,yBAAyB,6BAQpC;AAEF,kBAAe,iCAAyB,CAAC","sourcesContent":["import { type Tree, logger } from \"@nx/devkit\";\nimport {\n findJsxAttribute,\n findJsxElements,\n getImportedAliases,\n hasSpreadAttribute,\n logSummary,\n parseTsx,\n visitTsxFiles,\n} from \"../utils/jsx-utils\";\n\nconst PACKAGE_NAME = \"@trackunit/react-components\";\nconst COMPONENT_NAME = \"IconButton\";\n\nconst PLACEHOLDER_TITLE = \"TODO Replace with localized button title\";\n\nconst transformIconButtonUsage = (filePath: string, content: string): string | null => {\n const sourceFile = parseTsx(content, filePath);\n\n const aliases = getImportedAliases(sourceFile, PACKAGE_NAME);\n if (aliases === null) return null;\n\n const localAlias = Object.entries(aliases).find(([, name]) => name === COMPONENT_NAME)?.[0];\n if (localAlias === undefined) return null;\n\n const matches = findJsxElements(sourceFile, [localAlias]);\n if (matches.length === 0) return null;\n\n type Edit = { offset: number; text: string };\n const edits: Array<Edit> = [];\n\n for (const { openingElement } of matches) {\n if (hasSpreadAttribute(openingElement)) continue;\n\n const hasTitle = findJsxAttribute(openingElement, \"title\") !== null;\n const hasAriaLabel = findJsxAttribute(openingElement, \"ariaLabel\") !== null;\n if (hasTitle || hasAriaLabel) continue;\n\n edits.push({\n offset: openingElement.tagName.getEnd(),\n text: ` title=\"${PLACEHOLDER_TITLE}\"`,\n });\n }\n\n if (edits.length === 0) return null;\n\n edits.sort((a, b) => (a.offset === b.offset ? 0 : b.offset - a.offset));\n\n let updated = content;\n for (const { offset, text } of edits) {\n updated = updated.slice(0, offset) + text + updated.slice(offset);\n }\n return updated;\n};\n\n/**\n * Adds a placeholder `title` to `<IconButton>` usages that don't already\n * provide either `title` or `ariaLabel`. The new accessible name requirement\n * means every icon button must carry one of these two props.\n *\n * Usages with a spread attribute (e.g. `<IconButton {...props} />`) are\n * skipped because we cannot tell whether `title`/`ariaLabel` is forwarded.\n */\nexport const iconButtonAddRequiredName = (tree: Tree): void => {\n const touched = visitTsxFiles(tree, \"IconButton\", transformIconButtonUsage);\n logSummary(\"iconbutton-add-required-name\", touched);\n if (touched > 0) {\n logger.info(\n ` Replace the placeholder \"${PLACEHOLDER_TITLE}\" titles with localized strings (or switch to ariaLabel where appropriate).`\n );\n }\n};\n\nexport default iconButtonAddRequiredName;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kpi-tooltiplabel-to-wrapper.js","sourceRoot":"","sources":["../../../../../../libs/react/components/migrations/v2-0-0/kpi-tooltiplabel-to-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+CAAiC;AACjC,kDAO4B;AAE5B,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,cAAc,GAAG,KAAK,CAAC;AAE7B,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAU,EAAE;IACtD,MAAM,UAAU,GAAG,IAAA,oBAAQ,EAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnD,MAAM,OAAO,GAAG,IAAA,8BAAkB,EAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAC7D,IAAI,OAAO,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,OAAO,CAAC;IAEnF,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QACzC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC;YAAE,SAAS;QAC5C,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,eAAe,CAAC,IAAI,eAAe,CAAC,IAAI,KAAK,YAAY;YAAE,SAAS;QAE5F,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC;QACvD,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC;YAAE,SAAS;QAE/E,MAAM,YAAY,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC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MAAM,kBAAkB,GACtB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC;YAC7D,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3D,MAAM,OAAO,GAAG,kBAAkB,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,uBAAuB,kBAAkB,YAAY,CAAC;QAC3H,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAEvC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CAAC,IAAU,EAAQ,EAAE;IAC3D,MAAM,OAAO,GAAG,IAAA,yBAAa,EAAC,IAAI,EAAE,cAAc,EAAE,iBAAiB,CAAC,CAAC;IACvE,IAAA,sBAAU,EAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC,CAAC;AAHW,QAAA,wBAAwB,4BAGnC;AAEF,kBAAe,gCAAwB,CAAC","sourcesContent":["import { type Tree } from \"@nx/devkit\";\nimport * as ts from \"typescript\";\nimport {\n findJsxAttribute,\n findJsxElements,\n getImportedAliases,\n logSummary,\n parseTsx,\n visitTsxFiles,\n} from \"../utils/jsx-utils\";\n\nconst PACKAGE_NAME = \"@trackunit/react-components\";\nconst COMPONENT_NAME = \"KPI\";\n\nconst ensureTooltipImport = (content: string): string => {\n const sourceFile = parseTsx(content, \"source.tsx\");\n const aliases = getImportedAliases(sourceFile, PACKAGE_NAME);\n if (aliases !== null && Object.values(aliases).includes(\"Tooltip\")) return content;\n\n for (const stmt of sourceFile.statements) {\n if (!ts.isImportDeclaration(stmt)) continue;\n const moduleSpecifier = stmt.moduleSpecifier;\n if (!ts.isStringLiteral(moduleSpecifier) || moduleSpecifier.text !== PACKAGE_NAME) continue;\n\n const namedBindings = stmt.importClause?.namedBindings;\n if (namedBindings === undefined || !ts.isNamedImports(namedBindings)) continue;\n\n const elementsText = namedBindings.elements.map(el => el.getText()).join(\", \");\n const merged = `${elementsText}, Tooltip`;\n const before = content.slice(0, namedBindings.getStart());\n const after = content.slice(namedBindings.getEnd());\n return `${before}{ ${merged} }${after}`;\n }\n\n return `import { Tooltip } from \"${PACKAGE_NAME}\";\\n${content}`;\n};\n\nconst renderTooltipExpression = (label: string): string => label;\n\nconst transformKpiUsage = (filePath: string, content: string): string | null => {\n const sourceFile = parseTsx(content, filePath);\n\n const aliases = getImportedAliases(sourceFile, PACKAGE_NAME);\n if (aliases === null) return null;\n\n const localAlias = Object.entries(aliases).find(([, name]) => name === COMPONENT_NAME)?.[0];\n if (localAlias === undefined) return null;\n\n const matches = findJsxElements(sourceFile, [localAlias]);\n if (matches.length === 0) return null;\n\n type Edit = {\n elementStart: number;\n elementEnd: number;\n attrStart: number;\n attrEnd: number;\n label: string;\n elementText: string;\n };\n const edits: Array<Edit> = [];\n\n for (const { openingElement, element } of matches) {\n const tooltipLabelAttr = findJsxAttribute(openingElement, \"tooltipLabel\");\n if (tooltipLabelAttr === null) continue;\n\n const initializer = tooltipLabelAttr.initializer;\n if (initializer === undefined) continue;\n\n let label: string;\n if (ts.isStringLiteral(initializer)) {\n label = `\"${initializer.text}\"`;\n } else if (ts.isJsxExpression(initializer) && initializer.expression !== undefined) {\n label = `{${initializer.expression.getText()}}`;\n } else {\n continue;\n }\n\n edits.push({\n elementStart: element.getStart(),\n elementEnd: element.getEnd(),\n attrStart: tooltipLabelAttr.getFullStart(),\n attrEnd: tooltipLabelAttr.getEnd(),\n label,\n elementText: content.slice(element.getStart(), element.getEnd()),\n });\n }\n\n if (edits.length === 0) return null;\n\n edits.sort((a, b) => b.elementStart - a.elementStart);\n\n let updated = content;\n for (const edit of edits) {\n // Remove the tooltipLabel attribute first (it's inside the element).\n const elementWithoutAttr =\n edit.elementText.slice(0, edit.attrStart - edit.elementStart) +\n edit.elementText.slice(edit.attrEnd - edit.elementStart);\n const wrapped = `<Tooltip label=${renderTooltipExpression(edit.label)} placement=\"bottom\">${elementWithoutAttr}</Tooltip>`;\n updated = updated.slice(0, edit.elementStart) + wrapped + updated.slice(edit.elementEnd);\n }\n\n updated = ensureTooltipImport(updated);\n\n return updated;\n};\n\n/**\n * Replaces the removed `tooltipLabel` prop on `<KPI>` with an explicit\n * `<Tooltip>` wrapper. The `KPICard` variant is intentionally not touched\n * because it still owns its own `tooltipLabel` prop.\n */\nexport const kpiTooltipLabelToWrapper = (tree: Tree): void => {\n const touched = visitTsxFiles(tree, \"tooltipLabel\", transformKpiUsage);\n logSummary(\"kpi-tooltiplabel-to-wrapper\", touched);\n};\n\nexport default kpiTooltipLabelToWrapper;\n"]}
|