@flipdish/ui-library 0.40.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/organisms/CommandMenu/commandMenu.utils.cjs +54 -0
- package/dist/components/organisms/CommandMenu/commandMenu.utils.cjs.map +1 -1
- package/dist/components/organisms/CommandMenu/commandMenu.utils.d.ts +62 -0
- package/dist/components/organisms/CommandMenu/commandMenu.utils.d.ts.map +1 -1
- package/dist/components/organisms/CommandMenu/commandMenu.utils.js +53 -1
- package/dist/components/organisms/CommandMenu/commandMenu.utils.js.map +1 -1
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.cjs +43 -0
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.cjs.map +1 -0
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.d.ts +19 -0
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.d.ts.map +1 -0
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.js +41 -0
- package/dist/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.js.map +1 -0
- package/dist/components/organisms/CommandMenu/index.cjs +2 -47
- package/dist/components/organisms/CommandMenu/index.cjs.map +1 -1
- package/dist/components/organisms/CommandMenu/index.d.ts.map +1 -1
- package/dist/components/organisms/CommandMenu/index.js +4 -49
- package/dist/components/organisms/CommandMenu/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var hotkeys_utils = require('../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.cjs');
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Compares two values to determine if they are deeply equal.
|
|
5
7
|
*
|
|
@@ -30,6 +32,58 @@ const isDeepEqual = (obj1, obj2) => {
|
|
|
30
32
|
}
|
|
31
33
|
return true;
|
|
32
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Turns menu items into the hotkey registrations `CommandMenu` installs.
|
|
37
|
+
* Disabled items and disabled keys are left out, and an empty shortcut registers nothing.
|
|
38
|
+
*
|
|
39
|
+
* @param items Flat menu items, in display order.
|
|
40
|
+
* @param disabledKeys Ids the list treats as disabled, in addition to each item's `isDisabled`.
|
|
41
|
+
* @returns The hotkey strings to register for each triggerable kind, plus whether any shortcut can never fire.
|
|
42
|
+
*/
|
|
43
|
+
const planCommandItemHotkeys = (items, disabledKeys) => {
|
|
44
|
+
const disabled = new Set(disabledKeys);
|
|
45
|
+
const registered = [];
|
|
46
|
+
for (const item of items) {
|
|
47
|
+
if (item.isDisabled || disabled.has(item.id))
|
|
48
|
+
continue;
|
|
49
|
+
const steps = hotkeys_utils.toHotkeySteps(item.shortcutKeys ?? []);
|
|
50
|
+
if (steps.length === 0)
|
|
51
|
+
continue;
|
|
52
|
+
registered.push({ id: item.id, steps, kind: hotkeys_utils.getItemHotkeyKind(steps) });
|
|
53
|
+
}
|
|
54
|
+
const ofKind = (kind) => registered.filter((entry) => entry.kind === kind);
|
|
55
|
+
// Registering a hotkey twice would run the handler twice for one keypress.
|
|
56
|
+
const unique = (kind) => [...new Set(ofKind(kind).map((entry) => entry.steps[0]))];
|
|
57
|
+
return {
|
|
58
|
+
combination: unique('combination'),
|
|
59
|
+
guarded: unique('guarded'),
|
|
60
|
+
typed: ofKind('typed'),
|
|
61
|
+
matchable: registered.filter((entry) => entry.kind === 'combination' || entry.kind === 'guarded'),
|
|
62
|
+
hasUnsupported: ofKind('unsupported').length > 0,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
// `hotkeysEvent` carries fields (e.g. `metadata`) the vendored parser never produces, so compare only the identifying ones.
|
|
66
|
+
const hotkeyMatches = (step, fired) => {
|
|
67
|
+
const parsed = hotkeys_utils.parseHotkey(step);
|
|
68
|
+
return (parsed.hotkey.trim().toLowerCase() === fired.hotkey?.trim().toLowerCase() &&
|
|
69
|
+
parsed.isSequence === fired.isSequence &&
|
|
70
|
+
parsed.alt === fired.alt &&
|
|
71
|
+
parsed.ctrl === fired.ctrl &&
|
|
72
|
+
parsed.shift === fired.shift &&
|
|
73
|
+
parsed.meta === fired.meta &&
|
|
74
|
+
parsed.mod === fired.mod &&
|
|
75
|
+
isDeepEqual(parsed.keys, fired.keys));
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* The item a fired combination or guarded hotkey selects.
|
|
79
|
+
*
|
|
80
|
+
* @param matchable Combination and guarded registrations, in source order. A typed or unsupported entry never matches.
|
|
81
|
+
* @param fired The event `react-hotkeys-hook` reports for the key that was pressed.
|
|
82
|
+
* @returns The first matching registration, or `undefined` when the key selects nothing.
|
|
83
|
+
*/
|
|
84
|
+
const findCommandItemForHotkey = (matchable, fired) => matchable.find((entry) => (entry.kind === 'combination' || entry.kind === 'guarded') && hotkeyMatches(entry.steps[0], fired));
|
|
33
85
|
|
|
86
|
+
exports.findCommandItemForHotkey = findCommandItemForHotkey;
|
|
34
87
|
exports.isDeepEqual = isDeepEqual;
|
|
88
|
+
exports.planCommandItemHotkeys = planCommandItemHotkeys;
|
|
35
89
|
//# sourceMappingURL=commandMenu.utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandMenu.utils.cjs","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandMenu.utils.cjs","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"sourcesContent":[null],"names":["toHotkeySteps","getItemHotkeyKind","parseHotkey"],"mappings":";;;;AAmDA;;;;;;;AAOG;AACH;MACa,WAAW,GAAG,CAAC,IAAS,EAAE,IAAS,KAAa;;IAE3D,IAAI,IAAI,KAAK,IAAI;AAAE,QAAA,OAAO,IAAI;;AAG9B,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAA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;MACU,wBAAwB,GAAG,CAAC,SAAuC,EAAE,KAAkB,KAClG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,KAAK,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;;;;"}
|
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
/** How an item shortcut can be triggered. Matches `getItemHotkeyKind`. */
|
|
2
|
+
export type CommandHotkeyKind = 'combination' | 'guarded' | 'typed' | 'unsupported';
|
|
3
|
+
/** A menu item that may register a shortcut. */
|
|
4
|
+
export interface CommandHotkeyItem {
|
|
5
|
+
/** Id reported through `onSelectionChange` when the shortcut fires. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Skips registration, the same way a disabled list key does. */
|
|
8
|
+
isDisabled?: boolean;
|
|
9
|
+
/** Shortcut entries in hook format or symbol shorthand. Empty and missing shortcuts register nothing. */
|
|
10
|
+
shortcutKeys?: string[];
|
|
11
|
+
}
|
|
12
|
+
/** One registered shortcut, in the order the item appeared. */
|
|
13
|
+
export interface CommandItemHotkey {
|
|
14
|
+
/** Id reported through `onSelectionChange` when the shortcut fires. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Hook-format steps from `toHotkeySteps`. */
|
|
17
|
+
steps: string[];
|
|
18
|
+
/** How the shortcut can be triggered. */
|
|
19
|
+
kind: CommandHotkeyKind;
|
|
20
|
+
}
|
|
21
|
+
/** The hotkey strings and items `CommandMenu` registers from its items. */
|
|
22
|
+
export interface CommandHotkeyPlan {
|
|
23
|
+
/** Combination hotkeys, each registered once. */
|
|
24
|
+
combination: string[];
|
|
25
|
+
/** Guarded hotkeys, each registered once. */
|
|
26
|
+
guarded: string[];
|
|
27
|
+
/** Typed shortcuts in source order. The sequence index selects `id`. */
|
|
28
|
+
typed: CommandItemHotkey[];
|
|
29
|
+
/** Combination and guarded shortcuts, in source order. The first match wins. */
|
|
30
|
+
matchable: CommandItemHotkey[];
|
|
31
|
+
/** Whether any shortcut is drawn but can never be triggered. */
|
|
32
|
+
hasUnsupported: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** The fields of a fired hotkey that identify it. Extra event fields are ignored. */
|
|
35
|
+
interface FiredHotkey {
|
|
36
|
+
hotkey?: string;
|
|
37
|
+
isSequence?: boolean;
|
|
38
|
+
alt?: boolean;
|
|
39
|
+
ctrl?: boolean;
|
|
40
|
+
shift?: boolean;
|
|
41
|
+
meta?: boolean;
|
|
42
|
+
mod?: boolean;
|
|
43
|
+
keys?: readonly string[] | null;
|
|
44
|
+
}
|
|
1
45
|
/**
|
|
2
46
|
* Compares two values to determine if they are deeply equal.
|
|
3
47
|
*
|
|
@@ -7,4 +51,22 @@
|
|
|
7
51
|
* @returns True if the values are deeply equal, otherwise false.
|
|
8
52
|
*/
|
|
9
53
|
export declare const isDeepEqual: (obj1: any, obj2: any) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Turns menu items into the hotkey registrations `CommandMenu` installs.
|
|
56
|
+
* Disabled items and disabled keys are left out, and an empty shortcut registers nothing.
|
|
57
|
+
*
|
|
58
|
+
* @param items Flat menu items, in display order.
|
|
59
|
+
* @param disabledKeys Ids the list treats as disabled, in addition to each item's `isDisabled`.
|
|
60
|
+
* @returns The hotkey strings to register for each triggerable kind, plus whether any shortcut can never fire.
|
|
61
|
+
*/
|
|
62
|
+
export declare const planCommandItemHotkeys: (items: readonly CommandHotkeyItem[], disabledKeys?: Iterable<string | number>) => CommandHotkeyPlan;
|
|
63
|
+
/**
|
|
64
|
+
* The item a fired combination or guarded hotkey selects.
|
|
65
|
+
*
|
|
66
|
+
* @param matchable Combination and guarded registrations, in source order. A typed or unsupported entry never matches.
|
|
67
|
+
* @param fired The event `react-hotkeys-hook` reports for the key that was pressed.
|
|
68
|
+
* @returns The first matching registration, or `undefined` when the key selects nothing.
|
|
69
|
+
*/
|
|
70
|
+
export declare const findCommandItemForHotkey: (matchable: readonly CommandItemHotkey[], fired: FiredHotkey) => CommandItemHotkey | undefined;
|
|
71
|
+
export {};
|
|
10
72
|
//# sourceMappingURL=commandMenu.utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandMenu.utils.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandMenu.utils.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,aAAa,CAAC;AAEpF,gDAAgD;AAChD,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yGAAyG;IACzG,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,8CAA8C;IAC9C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED,2EAA2E;AAC3E,MAAM,WAAW,iBAAiB;IAChC,iDAAiD;IACjD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,wEAAwE;IACxE,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,gFAAgF;IAChF,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC/B,gEAAgE;IAChE,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,qFAAqF;AACrF,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAC;CACjC;AAED;;;;;;;GAOG;AAEH,eAAO,MAAM,WAAW,GAAI,MAAM,GAAG,EAAE,MAAM,GAAG,KAAG,OAsBlD,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,SAAS,iBAAiB,EAAE,EAAE,eAAe,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,KAAG,iBAsBtH,CAAC;AAkBF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GAAI,WAAW,SAAS,iBAAiB,EAAE,EAAE,OAAO,WAAW,KAAG,iBAAiB,GAAG,SACI,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { toHotkeySteps, getItemHotkeyKind, parseHotkey } from '../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Compares two values to determine if they are deeply equal.
|
|
3
5
|
*
|
|
@@ -28,6 +30,56 @@ const isDeepEqual = (obj1, obj2) => {
|
|
|
28
30
|
}
|
|
29
31
|
return true;
|
|
30
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Turns menu items into the hotkey registrations `CommandMenu` installs.
|
|
35
|
+
* Disabled items and disabled keys are left out, and an empty shortcut registers nothing.
|
|
36
|
+
*
|
|
37
|
+
* @param items Flat menu items, in display order.
|
|
38
|
+
* @param disabledKeys Ids the list treats as disabled, in addition to each item's `isDisabled`.
|
|
39
|
+
* @returns The hotkey strings to register for each triggerable kind, plus whether any shortcut can never fire.
|
|
40
|
+
*/
|
|
41
|
+
const planCommandItemHotkeys = (items, disabledKeys) => {
|
|
42
|
+
const disabled = new Set(disabledKeys);
|
|
43
|
+
const registered = [];
|
|
44
|
+
for (const item of items) {
|
|
45
|
+
if (item.isDisabled || disabled.has(item.id))
|
|
46
|
+
continue;
|
|
47
|
+
const steps = toHotkeySteps(item.shortcutKeys ?? []);
|
|
48
|
+
if (steps.length === 0)
|
|
49
|
+
continue;
|
|
50
|
+
registered.push({ id: item.id, steps, kind: getItemHotkeyKind(steps) });
|
|
51
|
+
}
|
|
52
|
+
const ofKind = (kind) => registered.filter((entry) => entry.kind === kind);
|
|
53
|
+
// Registering a hotkey twice would run the handler twice for one keypress.
|
|
54
|
+
const unique = (kind) => [...new Set(ofKind(kind).map((entry) => entry.steps[0]))];
|
|
55
|
+
return {
|
|
56
|
+
combination: unique('combination'),
|
|
57
|
+
guarded: unique('guarded'),
|
|
58
|
+
typed: ofKind('typed'),
|
|
59
|
+
matchable: registered.filter((entry) => entry.kind === 'combination' || entry.kind === 'guarded'),
|
|
60
|
+
hasUnsupported: ofKind('unsupported').length > 0,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
// `hotkeysEvent` carries fields (e.g. `metadata`) the vendored parser never produces, so compare only the identifying ones.
|
|
64
|
+
const hotkeyMatches = (step, fired) => {
|
|
65
|
+
const parsed = parseHotkey(step);
|
|
66
|
+
return (parsed.hotkey.trim().toLowerCase() === fired.hotkey?.trim().toLowerCase() &&
|
|
67
|
+
parsed.isSequence === fired.isSequence &&
|
|
68
|
+
parsed.alt === fired.alt &&
|
|
69
|
+
parsed.ctrl === fired.ctrl &&
|
|
70
|
+
parsed.shift === fired.shift &&
|
|
71
|
+
parsed.meta === fired.meta &&
|
|
72
|
+
parsed.mod === fired.mod &&
|
|
73
|
+
isDeepEqual(parsed.keys, fired.keys));
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* The item a fired combination or guarded hotkey selects.
|
|
77
|
+
*
|
|
78
|
+
* @param matchable Combination and guarded registrations, in source order. A typed or unsupported entry never matches.
|
|
79
|
+
* @param fired The event `react-hotkeys-hook` reports for the key that was pressed.
|
|
80
|
+
* @returns The first matching registration, or `undefined` when the key selects nothing.
|
|
81
|
+
*/
|
|
82
|
+
const findCommandItemForHotkey = (matchable, fired) => matchable.find((entry) => (entry.kind === 'combination' || entry.kind === 'guarded') && hotkeyMatches(entry.steps[0], fired));
|
|
31
83
|
|
|
32
|
-
export { isDeepEqual };
|
|
84
|
+
export { findCommandItemForHotkey, isDeepEqual, planCommandItemHotkeys };
|
|
33
85
|
//# sourceMappingURL=commandMenu.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandMenu.utils.js","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandMenu.utils.js","sources":["../../../../src/components/organisms/CommandMenu/commandMenu.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAmDA;;;;;;;AAOG;AACH;MACa,WAAW,GAAG,CAAC,IAAS,EAAE,IAAS,KAAa;;IAE3D,IAAI,IAAI,KAAK,IAAI;AAAE,QAAA,OAAO,IAAI;;AAG9B,IAAA,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE;AAC1F,QAAA,OAAO,KAAK;IACd;;IAGA,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;AAC/B,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;AAAE,QAAA,OAAO,KAAK;;AAG/C,IAAA,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,WAA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C,KAAK,KAAK,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;QACjG,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC;KACjD;AACH;AAEA;AACA,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,KAAkB,KAAa;AAClE,IAAA,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC;AAEhC,IAAA,QACE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE;AACzE,QAAA,MAAM,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU;AACtC,QAAA,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;AACxB,QAAA,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;AAC1B,QAAA,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;AAC5B,QAAA,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;AAC1B,QAAA,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC;AAExC,CAAC;AAED;;;;;;AAMG;MACU,wBAAwB,GAAG,CAAC,SAAuC,EAAE,KAAkB,KAClG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,aAAa,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,KAAK,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactHotkeysHook = require('react-hotkeys-hook');
|
|
5
|
+
var useKeySequences = require('../../../../hooks/__internal__/useKeySequences/useKeySequences.cjs');
|
|
6
|
+
var hotkeys_utils = require('../../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.cjs');
|
|
7
|
+
var log_utils = require('../../../../utilities/__internal__/logUtils/log.utils.cjs');
|
|
8
|
+
var commandMenu_utils = require('../commandMenu.utils.cjs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Registers each command item's `shortcutKeys` and reports the item it selects.
|
|
12
|
+
* Combinations held with ⌘/Ctrl/Alt also fire while typing; everything else is ignored in a field.
|
|
13
|
+
* A shortcut that can never be triggered warns once.
|
|
14
|
+
*
|
|
15
|
+
* @param options The flat items, any extra disabled ids, and the selection callback.
|
|
16
|
+
* @returns Nothing. Selection is reported through `onSelectionChange`.
|
|
17
|
+
*/
|
|
18
|
+
const useCommandItemHotkeys = ({ items, disabledKeys, onSelectionChange }) => {
|
|
19
|
+
const plan = commandMenu_utils.planCommandItemHotkeys(items, disabledKeys);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (!plan.hasUnsupported)
|
|
22
|
+
return;
|
|
23
|
+
log_utils.warnOnce('CommandMenu:unsupported-shortcut', "CommandMenu: an item's `shortcutKeys` is drawn but can never be triggered. A sequence cannot contain a modifier (['⌘k', 'p']) and a modifier needs a key (['⌘']).");
|
|
24
|
+
}, [plan.hasUnsupported]);
|
|
25
|
+
const selectItemForHotkey = (keyboardEvent, hotkeysEvent) => {
|
|
26
|
+
keyboardEvent.preventDefault();
|
|
27
|
+
const match = commandMenu_utils.findCommandItemForHotkey(plan.matchable, hotkeysEvent);
|
|
28
|
+
if (match)
|
|
29
|
+
onSelectionChange?.(new Set([match.id]));
|
|
30
|
+
};
|
|
31
|
+
// Combinations held with ⌘/Ctrl/Alt cannot be mistaken for typing, so they also work inside the search input.
|
|
32
|
+
reactHotkeysHook.useHotkeys(plan.combination, selectItemForHotkey, {
|
|
33
|
+
enableOnFormTags: true,
|
|
34
|
+
// react-aria re-dispatches a key typed in the search input onto the list; once handled, skip the copy.
|
|
35
|
+
ignoreEventWhen: (event) => event.defaultPrevented,
|
|
36
|
+
});
|
|
37
|
+
// Everything typing could produce (Shift+A, `?`, G then P) is ignored in fields so it never hijacks text entry.
|
|
38
|
+
reactHotkeysHook.useHotkeys(plan.guarded, selectItemForHotkey, { ignoreEventWhen: (event) => event.defaultPrevented || hotkeys_utils.isTypingInField(event) });
|
|
39
|
+
useKeySequences.useKeySequences(plan.typed.map(({ steps }) => steps.map(hotkeys_utils.hotkeyCharacter)), (index) => onSelectionChange?.(new Set([plan.typed[index].id])));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.useCommandItemHotkeys = useCommandItemHotkeys;
|
|
43
|
+
//# sourceMappingURL=useCommandItemHotkeys.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommandItemHotkeys.cjs","sources":["../../../../../src/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.ts"],"sourcesContent":[null],"names":["planCommandItemHotkeys","useEffect","warnOnce","findCommandItemForHotkey","useHotkeys","isTypingInField","useKeySequences","hotkeyCharacter"],"mappings":";;;;;;;;;AAkBA;;;;;;;AAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAgC,KAAU;IACtH,MAAM,IAAI,GAAGA,wCAAsB,CAAC,KAAK,EAAE,YAAY,CAAC;IAExDC,eAAS,CAAC,MAAK;QACb,IAAI,CAAC,IAAI,CAAC,cAAc;YAAE;AAC1B,QAAAC,kBAAQ,CACN,kCAAkC,EAClC,mKAAmK,CACpK;AACH,IAAA,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEzB,IAAA,MAAM,mBAAmB,GAAmB,CAAC,aAAa,EAAE,YAAY,KAAI;QAC1E,aAAa,CAAC,cAAc,EAAE;QAC9B,MAAM,KAAK,GAAGC,0CAAwB,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC;AACpE,QAAA,IAAI,KAAK;AAAE,YAAA,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,IAAA,CAAC;;AAGD,IAAAC,2BAAU,CAAC,IAAI,CAAC,WAAW,EAAE,mBAAmB,EAAE;AAChD,QAAA,gBAAgB,EAAE,IAAI;;QAEtB,eAAe,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,gBAAgB;AACnD,KAAA,CAAC;;IAEFA,2BAAU,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,gBAAgB,IAAIC,6BAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/HC,+BAAe,CACb,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,GAAG,CAACC,6BAAe,CAAC,CAAC,EACzD,CAAC,KAAK,KAAK,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAChE;AACH;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type CommandHotkeyItem } from '../commandMenu.utils';
|
|
2
|
+
export interface UseCommandItemHotkeysOptions {
|
|
3
|
+
/** Flat menu items in display order. */
|
|
4
|
+
items: readonly CommandHotkeyItem[];
|
|
5
|
+
/** Ids the list disables in addition to each item's `isDisabled`. */
|
|
6
|
+
disabledKeys?: Iterable<string | number>;
|
|
7
|
+
/** Called with a one-id set when a registered shortcut selects an item. */
|
|
8
|
+
onSelectionChange?: (keys: Set<string>) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Registers each command item's `shortcutKeys` and reports the item it selects.
|
|
12
|
+
* Combinations held with ⌘/Ctrl/Alt also fire while typing; everything else is ignored in a field.
|
|
13
|
+
* A shortcut that can never be triggered warns once.
|
|
14
|
+
*
|
|
15
|
+
* @param options The flat items, any extra disabled ids, and the selection callback.
|
|
16
|
+
* @returns Nothing. Selection is reported through `onSelectionChange`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const useCommandItemHotkeys: ({ items, disabledKeys, onSelectionChange }: UseCommandItemHotkeysOptions) => void;
|
|
19
|
+
//# sourceMappingURL=useCommandItemHotkeys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommandItemHotkeys.d.ts","sourceRoot":"","sources":["../../../../../src/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,iBAAiB,EAAoD,MAAM,sBAAsB,CAAC;AAEhH,MAAM,WAAW,4BAA4B;IAC3C,wCAAwC;IACxC,KAAK,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACpC,qEAAqE;IACrE,YAAY,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACzC,2EAA2E;IAC3E,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;CACjD;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,4CAA4C,4BAA4B,KAAG,IA6BhH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useHotkeys } from 'react-hotkeys-hook';
|
|
3
|
+
import { useKeySequences } from '../../../../hooks/__internal__/useKeySequences/useKeySequences.js';
|
|
4
|
+
import { isTypingInField, hotkeyCharacter } from '../../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.js';
|
|
5
|
+
import { warnOnce } from '../../../../utilities/__internal__/logUtils/log.utils.js';
|
|
6
|
+
import { planCommandItemHotkeys, findCommandItemForHotkey } from '../commandMenu.utils.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Registers each command item's `shortcutKeys` and reports the item it selects.
|
|
10
|
+
* Combinations held with ⌘/Ctrl/Alt also fire while typing; everything else is ignored in a field.
|
|
11
|
+
* A shortcut that can never be triggered warns once.
|
|
12
|
+
*
|
|
13
|
+
* @param options The flat items, any extra disabled ids, and the selection callback.
|
|
14
|
+
* @returns Nothing. Selection is reported through `onSelectionChange`.
|
|
15
|
+
*/
|
|
16
|
+
const useCommandItemHotkeys = ({ items, disabledKeys, onSelectionChange }) => {
|
|
17
|
+
const plan = planCommandItemHotkeys(items, disabledKeys);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!plan.hasUnsupported)
|
|
20
|
+
return;
|
|
21
|
+
warnOnce('CommandMenu:unsupported-shortcut', "CommandMenu: an item's `shortcutKeys` is drawn but can never be triggered. A sequence cannot contain a modifier (['⌘k', 'p']) and a modifier needs a key (['⌘']).");
|
|
22
|
+
}, [plan.hasUnsupported]);
|
|
23
|
+
const selectItemForHotkey = (keyboardEvent, hotkeysEvent) => {
|
|
24
|
+
keyboardEvent.preventDefault();
|
|
25
|
+
const match = findCommandItemForHotkey(plan.matchable, hotkeysEvent);
|
|
26
|
+
if (match)
|
|
27
|
+
onSelectionChange?.(new Set([match.id]));
|
|
28
|
+
};
|
|
29
|
+
// Combinations held with ⌘/Ctrl/Alt cannot be mistaken for typing, so they also work inside the search input.
|
|
30
|
+
useHotkeys(plan.combination, selectItemForHotkey, {
|
|
31
|
+
enableOnFormTags: true,
|
|
32
|
+
// react-aria re-dispatches a key typed in the search input onto the list; once handled, skip the copy.
|
|
33
|
+
ignoreEventWhen: (event) => event.defaultPrevented,
|
|
34
|
+
});
|
|
35
|
+
// Everything typing could produce (Shift+A, `?`, G then P) is ignored in fields so it never hijacks text entry.
|
|
36
|
+
useHotkeys(plan.guarded, selectItemForHotkey, { ignoreEventWhen: (event) => event.defaultPrevented || isTypingInField(event) });
|
|
37
|
+
useKeySequences(plan.typed.map(({ steps }) => steps.map(hotkeyCharacter)), (index) => onSelectionChange?.(new Set([plan.typed[index].id])));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { useCommandItemHotkeys };
|
|
41
|
+
//# sourceMappingURL=useCommandItemHotkeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCommandItemHotkeys.js","sources":["../../../../../src/components/organisms/CommandMenu/hooks/useCommandItemHotkeys.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAkBA;;;;;;;AAOG;AACI,MAAM,qBAAqB,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAgC,KAAU;IACtH,MAAM,IAAI,GAAG,sBAAsB,CAAC,KAAK,EAAE,YAAY,CAAC;IAExD,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,IAAI,CAAC,cAAc;YAAE;AAC1B,QAAA,QAAQ,CACN,kCAAkC,EAClC,mKAAmK,CACpK;AACH,IAAA,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAEzB,IAAA,MAAM,mBAAmB,GAAmB,CAAC,aAAa,EAAE,YAAY,KAAI;QAC1E,aAAa,CAAC,cAAc,EAAE;QAC9B,MAAM,KAAK,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC;AACpE,QAAA,IAAI,KAAK;AAAE,YAAA,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,IAAA,CAAC;;AAGD,IAAA,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,mBAAmB,EAAE;AAChD,QAAA,gBAAgB,EAAE,IAAI;;QAEtB,eAAe,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,gBAAgB;AACnD,KAAA,CAAC;;IAEF,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,gBAAgB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/H,eAAe,CACb,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EACzD,CAAC,KAAK,KAAK,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAChE;AACH;;"}
|
|
@@ -7,15 +7,13 @@ var React = require('react');
|
|
|
7
7
|
var reactAriaComponents = require('react-aria-components');
|
|
8
8
|
var reactHotkeysHook = require('react-hotkeys-hook');
|
|
9
9
|
var useHotkeyHint = require('../../../hooks/__internal__/useHotkeyHint/useHotkeyHint.cjs');
|
|
10
|
-
var useKeySequences = require('../../../hooks/__internal__/useKeySequences/useKeySequences.cjs');
|
|
11
10
|
var children_utils = require('../../../utilities/__internal__/childrenUtils/children.utils.cjs');
|
|
12
11
|
var hotkeys_utils = require('../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.cjs');
|
|
13
|
-
var log_utils = require('../../../utilities/__internal__/logUtils/log.utils.cjs');
|
|
14
|
-
var commandMenu_utils = require('./commandMenu.utils.cjs');
|
|
15
12
|
var CommandInput = require('./components/CommandInput.cjs');
|
|
16
13
|
var CommandMenuFooter = require('./components/CommandMenuFooter.cjs');
|
|
17
14
|
var CommandMenuHeader = require('./components/CommandMenuHeader.cjs');
|
|
18
15
|
var CommandMenuItem = require('./components/CommandMenuItem.cjs');
|
|
16
|
+
var useCommandItemHotkeys = require('./hooks/useCommandItemHotkeys.cjs');
|
|
19
17
|
var CommandMenuLink_context = require('./providers/CommandMenuLink.context.cjs');
|
|
20
18
|
|
|
21
19
|
const DEFAULT_SHORTCUT = '⌘/';
|
|
@@ -44,50 +42,7 @@ const CommandMenuRoot = ({ items, children, dialogClassName, overlayClassName, f
|
|
|
44
42
|
// Flatten the items and register hotkeys for items with shortcut keys.
|
|
45
43
|
const resolvedItems = items ?? defaultItems ?? [];
|
|
46
44
|
const flatItems = resolvedItems.flatMap((group) => group.items);
|
|
47
|
-
|
|
48
|
-
const itemHotkeys = flatItems
|
|
49
|
-
.filter((item) => !item.isDisabled && !disabledKeys.has(item.id))
|
|
50
|
-
.map((item) => ({ item, steps: hotkeys_utils.toHotkeySteps(item.shortcutKeys ?? []) }))
|
|
51
|
-
.filter(({ steps }) => steps.length > 0)
|
|
52
|
-
.map(({ item, steps }) => ({ item, steps, kind: hotkeys_utils.getItemHotkeyKind(steps) }));
|
|
53
|
-
const hotkeysOfKind = (kind) => itemHotkeys.filter((itemHotkey) => itemHotkey.kind === kind);
|
|
54
|
-
// Registering a hotkey twice would run the handler twice for one keypress.
|
|
55
|
-
const uniqueHotkeys = (kind) => [...new Set(hotkeysOfKind(kind).map(({ steps }) => steps[0]))];
|
|
56
|
-
const typedHotkeys = hotkeysOfKind('typed');
|
|
57
|
-
const hasUnsupportedHotkey = hotkeysOfKind('unsupported').length > 0;
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
if (!hasUnsupportedHotkey)
|
|
60
|
-
return;
|
|
61
|
-
log_utils.warnOnce('CommandMenu:unsupported-shortcut', "CommandMenu: an item's `shortcutKeys` is drawn but can never be triggered. A sequence cannot contain a modifier (['⌘k', 'p']) and a modifier needs a key (['⌘']).");
|
|
62
|
-
}, [hasUnsupportedHotkey]);
|
|
63
|
-
const selectItemForHotkey = (keyboardEvent, hotkeysEvent) => {
|
|
64
|
-
keyboardEvent.preventDefault();
|
|
65
|
-
const match = itemHotkeys.find(({ kind, steps }) => {
|
|
66
|
-
if (kind !== 'combination' && kind !== 'guarded')
|
|
67
|
-
return false;
|
|
68
|
-
const parsedHotkey = hotkeys_utils.parseHotkey(steps[0]);
|
|
69
|
-
// `hotkeysEvent` carries fields (e.g. `metadata`) the vendored parser never produces, so compare only the identifying ones.
|
|
70
|
-
return (parsedHotkey.hotkey.trim().toLowerCase() === hotkeysEvent.hotkey?.trim().toLowerCase() &&
|
|
71
|
-
parsedHotkey.isSequence === hotkeysEvent.isSequence &&
|
|
72
|
-
parsedHotkey.alt === hotkeysEvent.alt &&
|
|
73
|
-
parsedHotkey.ctrl === hotkeysEvent.ctrl &&
|
|
74
|
-
parsedHotkey.shift === hotkeysEvent.shift &&
|
|
75
|
-
parsedHotkey.meta === hotkeysEvent.meta &&
|
|
76
|
-
parsedHotkey.mod === hotkeysEvent.mod &&
|
|
77
|
-
commandMenu_utils.isDeepEqual(parsedHotkey.keys, hotkeysEvent.keys));
|
|
78
|
-
});
|
|
79
|
-
if (match)
|
|
80
|
-
onSelectionChange?.(new Set([match.item.id]));
|
|
81
|
-
};
|
|
82
|
-
// Combinations held with ⌘/Ctrl/Alt cannot be mistaken for typing, so they also work inside the search input.
|
|
83
|
-
reactHotkeysHook.useHotkeys(uniqueHotkeys('combination'), selectItemForHotkey, {
|
|
84
|
-
enableOnFormTags: true,
|
|
85
|
-
// react-aria re-dispatches a key typed in the search input onto the list; once handled, skip the copy.
|
|
86
|
-
ignoreEventWhen: (event) => event.defaultPrevented,
|
|
87
|
-
});
|
|
88
|
-
// Everything typing could produce (Shift+A, `?`, G then P) is ignored in fields so it never hijacks text entry.
|
|
89
|
-
reactHotkeysHook.useHotkeys(uniqueHotkeys('guarded'), selectItemForHotkey, { ignoreEventWhen: (event) => event.defaultPrevented || hotkeys_utils.isTypingInField(event) });
|
|
90
|
-
useKeySequences.useKeySequences(typedHotkeys.map(({ steps }) => steps.map(hotkeys_utils.hotkeyCharacter)), (index) => onSelectionChange?.(new Set([typedHotkeys[index].item.id])));
|
|
45
|
+
useCommandItemHotkeys.useCommandItemHotkeys({ items: flatItems, disabledKeys: otherProps.disabledKeys, onSelectionChange });
|
|
91
46
|
// The shortcut only returns focus to the search input while the menu is open; opening is the app's job.
|
|
92
47
|
reactHotkeysHook.useHotkeys(hotkey, () => inputRef.current?.focus(), {
|
|
93
48
|
enabled: Boolean(hotkey) && isOpen,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"sourcesContent":[null],"names":["createContext","useRef","useContext","OverlayTriggerStateContext","normalizeHotkey","useHotkeyHint","useFilter","useResolvedTestId","useState","
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"sourcesContent":[null],"names":["createContext","useRef","useContext","OverlayTriggerStateContext","normalizeHotkey","useHotkeyHint","useFilter","useResolvedTestId","useState","useCommandItemHotkeys","useHotkeys","useMemo","flattenChildren","isValidElement","CommandMenuFooter","_jsx","TestIdProvider","CommandMenuLinkContext","_jsxs","AriaAutocomplete","AriaTextField","CommandInput","AriaModalOverlay","cx","AriaModal","AriaDialog","AriaListBox","AriaListBoxSection","CommandMenuHeader","AriaCollection","Fragment","CommandDropdownMenuItem","AriaDialogTrigger"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,MAAM,gBAAgB,GAAG,IAAI;AAyB7B,MAAM,kBAAkB,GAAGA,mBAAa,CAAyB;AAC/D,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,IAAI,GAAG,EAAE;AACvB,IAAA,eAAe,EAAE,MAAK,EAAE,CAAC;AAC1B,CAAA,CAAC;AA8CF,MAAM,eAAe,GAAG,CAAC,EACvB,KAAK,EACL,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,WAAW,GAAG,MAAM,EACpB,WAAW,GAAG,QAAQ,EACtB,mBAAmB,EACnB,QAAQ,GAAG,gBAAgB,EAC3B,eAAe,GAAG,IAAI,EACtB,MAAM,EACN,aAAa,EAAE,UAAU,EACzB,GAAG,UAAU,EACQ,KAAI;AACzB,IAAA,MAAM,QAAQ,GAAGC,YAAM,CAAmB,IAAI,CAAC;;AAE/C,IAAA,MAAM,YAAY,GAAGC,gBAAU,CAACC,8CAA0B,CAAC;IAC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AC,UAAU,GAAGH,8BAAc;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC9I,OAAO,EAEL,UAAU,IAAI,cAAc,EAE5B,aAAa,IAAI,iBAAiB,EAQnC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,EAAE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC9I,OAAO,EAEL,UAAU,IAAI,cAAc,EAE5B,aAAa,IAAI,iBAAiB,EAQnC,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,uBAAuB,EAAE,KAAK,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAI1G,MAAM,MAAM,oBAAoB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,4BAA4B,EAAE,CAAA;CAAE,CAAC;AAEzG,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,MAAM,CAAC,EAAE,M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OAAO,iBAAiB,CAAC;IAClC,UAAU,EAAE,OAAO,cAAc,CAAC;CACnC,CAAC;AAWF,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
import { useResolvedTestId, TestIdProvider } from '@flipdish/ui-library/utilities/testIdUtils';
|
|
4
|
-
import { createContext, useRef, useContext, useState,
|
|
4
|
+
import { createContext, useRef, useContext, useState, useMemo, isValidElement, Fragment } from 'react';
|
|
5
5
|
import { ModalOverlay, Modal, Dialog, OverlayTriggerStateContext, useFilter, Autocomplete, TextField, ListBox, ListBoxSection, Collection, DialogTrigger } from 'react-aria-components';
|
|
6
6
|
import { useHotkeys } from 'react-hotkeys-hook';
|
|
7
7
|
import { useHotkeyHint } from '../../../hooks/__internal__/useHotkeyHint/useHotkeyHint.js';
|
|
8
|
-
import { useKeySequences } from '../../../hooks/__internal__/useKeySequences/useKeySequences.js';
|
|
9
8
|
import { flattenChildren } from '../../../utilities/__internal__/childrenUtils/children.utils.js';
|
|
10
|
-
import { normalizeHotkey
|
|
11
|
-
import { warnOnce } from '../../../utilities/__internal__/logUtils/log.utils.js';
|
|
12
|
-
import { isDeepEqual } from './commandMenu.utils.js';
|
|
9
|
+
import { normalizeHotkey } from '../../../utilities/__internal__/hotkeysUtils/hotkeys.utils.js';
|
|
13
10
|
import { CommandInput } from './components/CommandInput.js';
|
|
14
11
|
import { CommandMenuFooter } from './components/CommandMenuFooter.js';
|
|
15
12
|
import { CommandMenuHeader } from './components/CommandMenuHeader.js';
|
|
16
13
|
import { CommandDropdownMenuItem } from './components/CommandMenuItem.js';
|
|
14
|
+
import { useCommandItemHotkeys } from './hooks/useCommandItemHotkeys.js';
|
|
17
15
|
import { CommandMenuLinkContext } from './providers/CommandMenuLink.context.js';
|
|
18
16
|
|
|
19
17
|
const DEFAULT_SHORTCUT = '⌘/';
|
|
@@ -42,50 +40,7 @@ const CommandMenuRoot = ({ items, children, dialogClassName, overlayClassName, f
|
|
|
42
40
|
// Flatten the items and register hotkeys for items with shortcut keys.
|
|
43
41
|
const resolvedItems = items ?? defaultItems ?? [];
|
|
44
42
|
const flatItems = resolvedItems.flatMap((group) => group.items);
|
|
45
|
-
|
|
46
|
-
const itemHotkeys = flatItems
|
|
47
|
-
.filter((item) => !item.isDisabled && !disabledKeys.has(item.id))
|
|
48
|
-
.map((item) => ({ item, steps: toHotkeySteps(item.shortcutKeys ?? []) }))
|
|
49
|
-
.filter(({ steps }) => steps.length > 0)
|
|
50
|
-
.map(({ item, steps }) => ({ item, steps, kind: getItemHotkeyKind(steps) }));
|
|
51
|
-
const hotkeysOfKind = (kind) => itemHotkeys.filter((itemHotkey) => itemHotkey.kind === kind);
|
|
52
|
-
// Registering a hotkey twice would run the handler twice for one keypress.
|
|
53
|
-
const uniqueHotkeys = (kind) => [...new Set(hotkeysOfKind(kind).map(({ steps }) => steps[0]))];
|
|
54
|
-
const typedHotkeys = hotkeysOfKind('typed');
|
|
55
|
-
const hasUnsupportedHotkey = hotkeysOfKind('unsupported').length > 0;
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (!hasUnsupportedHotkey)
|
|
58
|
-
return;
|
|
59
|
-
warnOnce('CommandMenu:unsupported-shortcut', "CommandMenu: an item's `shortcutKeys` is drawn but can never be triggered. A sequence cannot contain a modifier (['⌘k', 'p']) and a modifier needs a key (['⌘']).");
|
|
60
|
-
}, [hasUnsupportedHotkey]);
|
|
61
|
-
const selectItemForHotkey = (keyboardEvent, hotkeysEvent) => {
|
|
62
|
-
keyboardEvent.preventDefault();
|
|
63
|
-
const match = itemHotkeys.find(({ kind, steps }) => {
|
|
64
|
-
if (kind !== 'combination' && kind !== 'guarded')
|
|
65
|
-
return false;
|
|
66
|
-
const parsedHotkey = parseHotkey(steps[0]);
|
|
67
|
-
// `hotkeysEvent` carries fields (e.g. `metadata`) the vendored parser never produces, so compare only the identifying ones.
|
|
68
|
-
return (parsedHotkey.hotkey.trim().toLowerCase() === hotkeysEvent.hotkey?.trim().toLowerCase() &&
|
|
69
|
-
parsedHotkey.isSequence === hotkeysEvent.isSequence &&
|
|
70
|
-
parsedHotkey.alt === hotkeysEvent.alt &&
|
|
71
|
-
parsedHotkey.ctrl === hotkeysEvent.ctrl &&
|
|
72
|
-
parsedHotkey.shift === hotkeysEvent.shift &&
|
|
73
|
-
parsedHotkey.meta === hotkeysEvent.meta &&
|
|
74
|
-
parsedHotkey.mod === hotkeysEvent.mod &&
|
|
75
|
-
isDeepEqual(parsedHotkey.keys, hotkeysEvent.keys));
|
|
76
|
-
});
|
|
77
|
-
if (match)
|
|
78
|
-
onSelectionChange?.(new Set([match.item.id]));
|
|
79
|
-
};
|
|
80
|
-
// Combinations held with ⌘/Ctrl/Alt cannot be mistaken for typing, so they also work inside the search input.
|
|
81
|
-
useHotkeys(uniqueHotkeys('combination'), selectItemForHotkey, {
|
|
82
|
-
enableOnFormTags: true,
|
|
83
|
-
// react-aria re-dispatches a key typed in the search input onto the list; once handled, skip the copy.
|
|
84
|
-
ignoreEventWhen: (event) => event.defaultPrevented,
|
|
85
|
-
});
|
|
86
|
-
// Everything typing could produce (Shift+A, `?`, G then P) is ignored in fields so it never hijacks text entry.
|
|
87
|
-
useHotkeys(uniqueHotkeys('guarded'), selectItemForHotkey, { ignoreEventWhen: (event) => event.defaultPrevented || isTypingInField(event) });
|
|
88
|
-
useKeySequences(typedHotkeys.map(({ steps }) => steps.map(hotkeyCharacter)), (index) => onSelectionChange?.(new Set([typedHotkeys[index].item.id])));
|
|
43
|
+
useCommandItemHotkeys({ items: flatItems, disabledKeys: otherProps.disabledKeys, onSelectionChange });
|
|
89
44
|
// The shortcut only returns focus to the search input while the menu is open; opening is the app's job.
|
|
90
45
|
useHotkeys(hotkey, () => inputRef.current?.focus(), {
|
|
91
46
|
enabled: Boolean(hotkey) && isOpen,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","AriaAutocomplete","AriaTextField","AriaModalOverlay","AriaModal","AriaDialog","AriaListBox","AriaListBoxSection","AriaCollection","AriaDialogTrigger"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/organisms/CommandMenu/index.tsx"],"sourcesContent":[null],"names":["_jsx","_jsxs","AriaAutocomplete","AriaTextField","AriaModalOverlay","AriaModal","AriaDialog","AriaListBox","AriaListBoxSection","AriaCollection","AriaDialogTrigger"],"mappings":";;;;;;;;;;;;;;;;AA2CA,MAAM,gBAAgB,GAAG,IAAI;AAyB7B,MAAM,kBAAkB,GAAG,aAAa,CAAyB;AAC/D,IAAA,SAAS,EAAE,KAAK;AAChB,IAAA,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,IAAI,GAAG,EAAE;AACvB,IAAA,eAAe,EAAE,MAAK,EAAE,CAAC;AAC1B,CAAA,CAAC;AA8CF,MAAM,eAAe,GAAG,CAAC,EACvB,KAAK,EACL,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,MAAM,EACN,UAAU,EACV,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,WAAW,GAAG,MAAM,EACpB,WAAW,GAAG,QAAQ,EACtB,mBAAmB,EACnB,QAAQ,GAAG,gBAAgB,EAC3B,eAAe,GAAG,IAAI,EACtB,MAAM,EACN,aAAa,EAAE,UAAU,EACzB,GAAG,UAAU,EACQ,KAAI;AACzB,IAAA,MAAM,QAAQ,GAAG,MAAM,CAAmB,IAAI,CAAC;;AAE/C,IAAA,MAAM,YAAY,GAAG,UAAU,CAAC,0BAA0B,CAAC;IAC3D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,IAAI,YAAY,EAAE,MAAM,IAAI,KAAK;IACjE,MAAM,KAAK,GAAG,MAAK;;AAEjB,QAAA,IAAI,UAAU,CAAC,MAAM,KAAK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