@wordpress/commands 0.10.0 → 0.11.0
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/CHANGELOG.md +2 -0
- package/build/components/command-menu.js +25 -40
- package/build/components/command-menu.js.map +1 -1
- package/build/hooks/use-command-context.js +3 -7
- package/build/hooks/use-command-context.js.map +1 -1
- package/build/hooks/use-command-loader.js +0 -4
- package/build/hooks/use-command-loader.js.map +1 -1
- package/build/hooks/use-command.js +0 -4
- package/build/hooks/use-command.js.map +1 -1
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +1 -4
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +5 -11
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -11
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +0 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/reducer.js +7 -18
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/command-menu.js +26 -35
- package/build-module/components/command-menu.js.map +1 -1
- package/build-module/hooks/use-command-context.js +5 -4
- package/build-module/hooks/use-command-context.js.map +1 -1
- package/build-module/hooks/use-command-loader.js +2 -2
- package/build-module/hooks/use-command-loader.js.map +1 -1
- package/build-module/hooks/use-command.js +2 -2
- package/build-module/hooks/use-command.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +5 -5
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/reducer.js +8 -17
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +34 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +36 -18
- package/build-style/style.css +36 -18
- package/package.json +12 -10
- package/src/components/command-menu.js +17 -7
- package/src/components/style.scss +38 -19
- package/src/store/selectors.js +30 -0
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","_reducer","_interopRequireDefault","actions","_interopRequireWildcard","selectors","privateActions","_lockUnlock","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","STORE_NAME","store","createReduxStore","reducer","exports","register","unlock","registerPrivateActions"],"sources":["@wordpress/commands/src/store/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport * as privateActions from './private-actions';\nimport { unlock } from '../lock-unlock';\n\nconst STORE_NAME = 'core/commands';\n\n/**\n * Store definition for the commands namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\nunlock( store ).registerPrivateActions( privateActions );\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAC,uBAAA,CAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAD,uBAAA,CAAAJ,OAAA;AACA,IAAAM,cAAA,GAAAF,uBAAA,CAAAJ,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AAAwC,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAA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AE,CAAC;AAAC6B,OAAA,CAAAH,KAAA,GAAAA,KAAA;AAEJ,IAAAI,cAAQ,EAAEJ,KAAM,CAAC;AACjB,IAAAK,kBAAM,EAAEL,KAAM,CAAC,CAACM,sBAAsB,CAAE/B,cAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["setContext","context","type"],"sources":["@wordpress/commands/src/store/private-actions.js"],"sourcesContent":["/**\n * Sets the active context.\n *\n * @param {string} context Context.\n *\n * @return {Object} action.\n */\nexport function setContext( context ) {\n\treturn {\n\t\ttype: 'SET_CONTEXT',\n\t\tcontext,\n\t};\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAUA,CAAEC,OAAO,EAAG;EACrC,OAAO;IACNC,IAAI,EAAE,aAAa;IACnBD;EACD,CAAC;AACF"}
|
package/build/store/reducer.js
CHANGED
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _data = require("@wordpress/data");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* WordPress dependencies
|
|
12
10
|
*/
|
|
@@ -22,7 +20,8 @@ var _data = require("@wordpress/data");
|
|
|
22
20
|
function commands(state = {}, action) {
|
|
23
21
|
switch (action.type) {
|
|
24
22
|
case 'REGISTER_COMMAND':
|
|
25
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
...state,
|
|
26
25
|
[action.name]: {
|
|
27
26
|
name: action.name,
|
|
28
27
|
label: action.label,
|
|
@@ -32,7 +31,6 @@ function commands(state = {}, action) {
|
|
|
32
31
|
icon: action.icon
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
|
|
36
34
|
case 'UNREGISTER_COMMAND':
|
|
37
35
|
{
|
|
38
36
|
const {
|
|
@@ -42,9 +40,9 @@ function commands(state = {}, action) {
|
|
|
42
40
|
return remainingState;
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
return state;
|
|
47
44
|
}
|
|
45
|
+
|
|
48
46
|
/**
|
|
49
47
|
* Reducer returning the command loaders
|
|
50
48
|
*
|
|
@@ -53,19 +51,17 @@ function commands(state = {}, action) {
|
|
|
53
51
|
*
|
|
54
52
|
* @return {Object} Updated state.
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
54
|
function commandLoaders(state = {}, action) {
|
|
59
55
|
switch (action.type) {
|
|
60
56
|
case 'REGISTER_COMMAND_LOADER':
|
|
61
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
...state,
|
|
62
59
|
[action.name]: {
|
|
63
60
|
name: action.name,
|
|
64
61
|
context: action.context,
|
|
65
62
|
hook: action.hook
|
|
66
63
|
}
|
|
67
64
|
};
|
|
68
|
-
|
|
69
65
|
case 'UNREGISTER_COMMAND_LOADER':
|
|
70
66
|
{
|
|
71
67
|
const {
|
|
@@ -75,9 +71,9 @@ function commandLoaders(state = {}, action) {
|
|
|
75
71
|
return remainingState;
|
|
76
72
|
}
|
|
77
73
|
}
|
|
78
|
-
|
|
79
74
|
return state;
|
|
80
75
|
}
|
|
76
|
+
|
|
81
77
|
/**
|
|
82
78
|
* Reducer returning the command palette open state.
|
|
83
79
|
*
|
|
@@ -86,19 +82,16 @@ function commandLoaders(state = {}, action) {
|
|
|
86
82
|
*
|
|
87
83
|
* @return {boolean} Updated state.
|
|
88
84
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
85
|
function isOpen(state = false, action) {
|
|
92
86
|
switch (action.type) {
|
|
93
87
|
case 'OPEN':
|
|
94
88
|
return true;
|
|
95
|
-
|
|
96
89
|
case 'CLOSE':
|
|
97
90
|
return false;
|
|
98
91
|
}
|
|
99
|
-
|
|
100
92
|
return state;
|
|
101
93
|
}
|
|
94
|
+
|
|
102
95
|
/**
|
|
103
96
|
* Reducer returning the command palette's active context.
|
|
104
97
|
*
|
|
@@ -107,17 +100,13 @@ function isOpen(state = false, action) {
|
|
|
107
100
|
*
|
|
108
101
|
* @return {boolean} Updated state.
|
|
109
102
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
112
103
|
function context(state = 'root', action) {
|
|
113
104
|
switch (action.type) {
|
|
114
105
|
case 'SET_CONTEXT':
|
|
115
106
|
return action.context;
|
|
116
107
|
}
|
|
117
|
-
|
|
118
108
|
return state;
|
|
119
109
|
}
|
|
120
|
-
|
|
121
110
|
const reducer = (0, _data.combineReducers)({
|
|
122
111
|
commands,
|
|
123
112
|
commandLoaders,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_data","require","commands","state","action","type","name","label","searchLabel","context","callback","icon","_","remainingState","commandLoaders","hook","isOpen","reducer","combineReducers","_default","exports","default"],"sources":["@wordpress/commands/src/store/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer returning the registered commands\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commands( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tlabel: action.label,\n\t\t\t\t\tsearchLabel: action.searchLabel,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\tcallback: action.callback,\n\t\t\t\t\ticon: action.icon,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command loaders\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nfunction commandLoaders( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'REGISTER_COMMAND_LOADER':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.name ]: {\n\t\t\t\t\tname: action.name,\n\t\t\t\t\tcontext: action.context,\n\t\t\t\t\thook: action.hook,\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND_LOADER': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } = state;\n\t\t\treturn remainingState;\n\t\t}\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette open state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction isOpen( state = false, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'OPEN':\n\t\t\treturn true;\n\t\tcase 'CLOSE':\n\t\t\treturn false;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning the command palette's active context.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {boolean} Updated state.\n */\nfunction context( state = 'root', action ) {\n\tswitch ( action.type ) {\n\t\tcase 'SET_CONTEXT':\n\t\t\treturn action.context;\n\t}\n\n\treturn state;\n}\n\nconst reducer = combineReducers( {\n\tcommands,\n\tcommandLoaders,\n\tisOpen,\n\tcontext,\n} );\n\nexport default reducer;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,KAAK,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAG;EACvC,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,kBAAkB;MACtB,OAAO;QACN,GAAGF,KAAK;QACR,CAAEC,MAAM,CAACE,IAAI,GAAI;UAChBA,IAAI,EAAEF,MAAM,CAACE,IAAI;UACjBC,KAAK,EAAEH,MAAM,CAACG,KAAK;UACnBC,WAAW,EAAEJ,MAAM,CAACI,W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OD,MAAM,CAACK,OAAO;EACvB;EAEA,OAAON,KAAK;AACb;AAEA,MAAMc,OAAO,GAAG,IAAAC,qBAAe,EAAE;EAChChB,QAAQ;EACRY,cAAc;EACdE,MAAM;EACNP;AACD,CAAE,CAAC;AAAC,IAAAU,QAAA,GAEWF,OAAO;AAAAG,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/store/selectors.js
CHANGED
|
@@ -1,34 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.getCommands = exports.getCommandLoaders = void 0;
|
|
9
8
|
exports.getContext = getContext;
|
|
10
9
|
exports.isOpen = isOpen;
|
|
11
|
-
|
|
12
10
|
var _rememo = _interopRequireDefault(require("rememo"));
|
|
13
|
-
|
|
14
11
|
/**
|
|
15
12
|
* External dependencies
|
|
16
13
|
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns the registered static commands.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} state State tree.
|
|
19
|
+
* @param {boolean} contextual Whether to return only contextual commands.
|
|
20
|
+
*
|
|
21
|
+
* @return {import('./actions').WPCommandConfig[]} The list of registered commands.
|
|
22
|
+
*/
|
|
17
23
|
const getCommands = (0, _rememo.default)((state, contextual = false) => Object.values(state.commands).filter(command => {
|
|
18
24
|
const isContextual = command.context && command.context === state.context;
|
|
19
25
|
return contextual ? isContextual : !isContextual;
|
|
20
26
|
}), state => [state.commands, state.context]);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the registered command loaders.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} state State tree.
|
|
32
|
+
* @param {boolean} contextual Whether to return only contextual command loaders.
|
|
33
|
+
*
|
|
34
|
+
* @return {import('./actions').WPCommandLoaderConfig[]} The list of registered command loaders.
|
|
35
|
+
*/
|
|
21
36
|
exports.getCommands = getCommands;
|
|
22
37
|
const getCommandLoaders = (0, _rememo.default)((state, contextual = false) => Object.values(state.commandLoaders).filter(loader => {
|
|
23
38
|
const isContextual = loader.context && loader.context === state.context;
|
|
24
39
|
return contextual ? isContextual : !isContextual;
|
|
25
40
|
}), state => [state.commandLoaders, state.context]);
|
|
26
|
-
exports.getCommandLoaders = getCommandLoaders;
|
|
27
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Returns whether the command palette is open.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} state State tree.
|
|
46
|
+
*
|
|
47
|
+
* @return {boolean} Returns whether the command palette is open.
|
|
48
|
+
*/
|
|
49
|
+
exports.getCommandLoaders = getCommandLoaders;
|
|
28
50
|
function isOpen(state) {
|
|
29
51
|
return state.isOpen;
|
|
30
52
|
}
|
|
31
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Returns whether the active context.
|
|
56
|
+
*
|
|
57
|
+
* @param {Object} state State tree.
|
|
58
|
+
*
|
|
59
|
+
* @return {string} Context.
|
|
60
|
+
*/
|
|
32
61
|
function getContext(state) {
|
|
33
62
|
return state.context;
|
|
34
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_rememo","_interopRequireDefault","require","getCommands","createSelector","state","contextual","Object","values","commands","filter","command","isContextual","context","exports","getCommandLoaders","commandLoaders","loader","isOpen","getContext"],"sources":["@wordpress/commands/src/store/selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\n/**\n * Returns the registered static commands.\n *\n * @param {Object} state State tree.\n * @param {boolean} contextual Whether to return only contextual commands.\n *\n * @return {import('./actions').WPCommandConfig[]} The list of registered commands.\n */\nexport const getCommands = createSelector(\n\t( state, contextual = false ) =>\n\t\tObject.values( state.commands ).filter( ( command ) => {\n\t\t\tconst isContextual =\n\t\t\t\tcommand.context && command.context === state.context;\n\t\t\treturn contextual ? isContextual : ! isContextual;\n\t\t} ),\n\t( state ) => [ state.commands, state.context ]\n);\n\n/**\n * Returns the registered command loaders.\n *\n * @param {Object} state State tree.\n * @param {boolean} contextual Whether to return only contextual command loaders.\n *\n * @return {import('./actions').WPCommandLoaderConfig[]} The list of registered command loaders.\n */\nexport const getCommandLoaders = createSelector(\n\t( state, contextual = false ) =>\n\t\tObject.values( state.commandLoaders ).filter( ( loader ) => {\n\t\t\tconst isContextual =\n\t\t\t\tloader.context && loader.context === state.context;\n\t\t\treturn contextual ? isContextual : ! isContextual;\n\t\t} ),\n\t( state ) => [ state.commandLoaders, state.context ]\n);\n\n/**\n * Returns whether the command palette is open.\n *\n * @param {Object} state State tree.\n *\n * @return {boolean} Returns whether the command palette is open.\n */\nexport function isOpen( state ) {\n\treturn state.isOpen;\n}\n\n/**\n * Returns whether the active context.\n *\n * @param {Object} state State tree.\n *\n * @return {string} Context.\n */\nexport function getContext( state ) {\n\treturn state.context;\n}\n"],"mappings":";;;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,GAAG,IAAAC,eAAc,EACxC,CAAEC,KAAK,EAAEC,UAAU,GAAG,KAAK,KAC1BC,MAAM,CAACC,MAAM,CAAEH,KAAK,CAACI,QAAS,CAAC,CAACC,MAAM,CAAIC,OAAO,IAAM;EACtD,MAAMC,YAAY,GACjBD,OAAO,CAACE,OAAO,IAAIF,OAAO,CAACE,OAAO,KAAKR,KAAK,CAACQ,OAAO;EACrD,OAAOP,UAAU,GAAGM,YAAY,GAAG,CAAEA,YAAY;AAClD,CAAE,CAAC,EACFP,KAAK,IAAM,CAAEA,KAAK,CAACI,QAAQ,EAAEJ,KAAK,CAACQ,OAAO,CAC7C,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAC,OAAA,CAAAX,WAAA,GAAAA,WAAA;AAQO,MAAMY,iBAAiB,GAAG,IAAAX,eAAc,EAC9C,CAAEC,KAAK,EAAEC,UAAU,GAAG,KAAK,KAC1BC,MAAM,CAACC,MAAM,CAAEH,KAAK,CAACW,cAAe,CAAC,CAACN,MAAM,CAAIO,MAAM,IAAM;EAC3D,MAAML,YAAY,GACjBK,MAAM,CAACJ,OAAO,IAAII,MAAM,CAACJ,OAAO,KAAKR,KAAK,CAACQ,OAAO;EACnD,OAAOP,UAAU,GAAGM,YAAY,GAAG,CAAEA,YAAY;AAClD,CAAE,CAAC,EACFP,KAAK,IAAM,CAAEA,KAAK,CAACW,cAAc,EAAEX,KAAK,CAACQ,OAAO,CACnD,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AANAC,OAAA,CAAAC,iBAAA,GAAAA,iBAAA;AAOO,SAASG,MAAMA,CAAEb,KAAK,EAAG;EAC/B,OAAOA,KAAK,CAACa,MAAM;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAAEd,KAAK,EAAG;EACnC,OAAOA,KAAK,CAACQ,OAAO;AACrB"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { Command, useCommandState } from 'cmdk';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* WordPress dependencies
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
12
|
import { useState, useEffect, useRef, useCallback, useMemo } from '@wordpress/element';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
14
14
|
import { Modal, TextHighlight, __experimentalHStack as HStack } from '@wordpress/components';
|
|
15
15
|
import { store as keyboardShortcutsStore, useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
16
|
-
import { Icon } from '@wordpress/icons';
|
|
16
|
+
import { Icon, search as inputIcon } from '@wordpress/icons';
|
|
17
|
+
|
|
17
18
|
/**
|
|
18
19
|
* Internal dependencies
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
21
|
import { store as commandsStore } from '../store';
|
|
22
|
-
|
|
23
22
|
function CommandMenuLoader({
|
|
24
23
|
name,
|
|
25
24
|
search,
|
|
@@ -28,7 +27,6 @@ function CommandMenuLoader({
|
|
|
28
27
|
close
|
|
29
28
|
}) {
|
|
30
29
|
var _hook;
|
|
31
|
-
|
|
32
30
|
const {
|
|
33
31
|
isLoading,
|
|
34
32
|
commands = []
|
|
@@ -38,14 +36,11 @@ function CommandMenuLoader({
|
|
|
38
36
|
useEffect(() => {
|
|
39
37
|
setLoader(name, isLoading);
|
|
40
38
|
}, [setLoader, name, isLoading]);
|
|
41
|
-
|
|
42
39
|
if (!commands.length) {
|
|
43
40
|
return null;
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
return createElement(Fragment, null, createElement(Command.List, null, commands.map(command => {
|
|
47
43
|
var _command$searchLabel;
|
|
48
|
-
|
|
49
44
|
return createElement(Command.Item, {
|
|
50
45
|
key: command.name,
|
|
51
46
|
value: (_command$searchLabel = command.searchLabel) !== null && _command$searchLabel !== void 0 ? _command$searchLabel : command.label,
|
|
@@ -55,8 +50,10 @@ function CommandMenuLoader({
|
|
|
55
50
|
id: command.name
|
|
56
51
|
}, createElement(HStack, {
|
|
57
52
|
alignment: "left",
|
|
58
|
-
className:
|
|
59
|
-
|
|
53
|
+
className: classnames('commands-command-menu__item', {
|
|
54
|
+
'has-icon': command.icon
|
|
55
|
+
})
|
|
56
|
+
}, command.icon && createElement(Icon, {
|
|
60
57
|
icon: command.icon
|
|
61
58
|
}), createElement("span", null, createElement(TextHighlight, {
|
|
62
59
|
text: command.label,
|
|
@@ -64,7 +61,6 @@ function CommandMenuLoader({
|
|
|
64
61
|
}))));
|
|
65
62
|
})));
|
|
66
63
|
}
|
|
67
|
-
|
|
68
64
|
export function CommandMenuLoaderWrapper({
|
|
69
65
|
hook,
|
|
70
66
|
search,
|
|
@@ -111,14 +107,11 @@ export function CommandMenuGroup({
|
|
|
111
107
|
loaders: getCommandLoaders(isContextual)
|
|
112
108
|
};
|
|
113
109
|
}, [isContextual]);
|
|
114
|
-
|
|
115
110
|
if (!commands.length && !loaders.length) {
|
|
116
111
|
return null;
|
|
117
112
|
}
|
|
118
|
-
|
|
119
113
|
return createElement(Command.Group, null, commands.map(command => {
|
|
120
114
|
var _command$searchLabel2;
|
|
121
|
-
|
|
122
115
|
return createElement(Command.Item, {
|
|
123
116
|
key: command.name,
|
|
124
117
|
value: (_command$searchLabel2 = command.searchLabel) !== null && _command$searchLabel2 !== void 0 ? _command$searchLabel2 : command.label,
|
|
@@ -128,8 +121,10 @@ export function CommandMenuGroup({
|
|
|
128
121
|
id: command.name
|
|
129
122
|
}, createElement(HStack, {
|
|
130
123
|
alignment: "left",
|
|
131
|
-
className:
|
|
132
|
-
|
|
124
|
+
className: classnames('commands-command-menu__item', {
|
|
125
|
+
'has-icon': command.icon
|
|
126
|
+
})
|
|
127
|
+
}, command.icon && createElement(Icon, {
|
|
133
128
|
icon: command.icon
|
|
134
129
|
}), createElement("span", null, createElement(TextHighlight, {
|
|
135
130
|
text: command.label,
|
|
@@ -143,16 +138,13 @@ export function CommandMenuGroup({
|
|
|
143
138
|
close: close
|
|
144
139
|
})));
|
|
145
140
|
}
|
|
146
|
-
|
|
147
141
|
function CommandInput({
|
|
148
142
|
isOpen,
|
|
149
143
|
search,
|
|
150
144
|
setSearch
|
|
151
145
|
}) {
|
|
152
146
|
const commandMenuInput = useRef();
|
|
153
|
-
|
|
154
147
|
const _value = useCommandState(state => state.value);
|
|
155
|
-
|
|
156
148
|
const selectedItemId = useMemo(() => {
|
|
157
149
|
const item = document.querySelector(`[cmdk-item=""][data-value="${_value}"]`);
|
|
158
150
|
return item?.getAttribute('id');
|
|
@@ -167,11 +159,11 @@ function CommandInput({
|
|
|
167
159
|
ref: commandMenuInput,
|
|
168
160
|
value: search,
|
|
169
161
|
onValueChange: setSearch,
|
|
170
|
-
placeholder: __('
|
|
171
|
-
"aria-activedescendant": selectedItemId
|
|
162
|
+
placeholder: __('Search for commands'),
|
|
163
|
+
"aria-activedescendant": selectedItemId,
|
|
164
|
+
icon: search
|
|
172
165
|
});
|
|
173
166
|
}
|
|
174
|
-
|
|
175
167
|
export function CommandMenu() {
|
|
176
168
|
const {
|
|
177
169
|
registerShortcut
|
|
@@ -187,20 +179,18 @@ export function CommandMenu() {
|
|
|
187
179
|
registerShortcut({
|
|
188
180
|
name: 'core/commands',
|
|
189
181
|
category: 'global',
|
|
190
|
-
description: __('Open the command palette'),
|
|
182
|
+
description: __('Open the command palette.'),
|
|
191
183
|
keyCombination: {
|
|
192
184
|
modifier: 'primary',
|
|
193
185
|
character: 'k'
|
|
194
186
|
}
|
|
195
187
|
});
|
|
196
188
|
}, [registerShortcut]);
|
|
197
|
-
useShortcut('core/commands',
|
|
198
|
-
/** @type {import('react').KeyboardEventHandler} */
|
|
189
|
+
useShortcut('core/commands', /** @type {import('react').KeyboardEventHandler} */
|
|
199
190
|
event => {
|
|
200
191
|
// Bails to avoid obscuring the effect of the preceding handler(s).
|
|
201
192
|
if (event.defaultPrevented) return;
|
|
202
193
|
event.preventDefault();
|
|
203
|
-
|
|
204
194
|
if (isOpen) {
|
|
205
195
|
close();
|
|
206
196
|
} else {
|
|
@@ -209,29 +199,28 @@ export function CommandMenu() {
|
|
|
209
199
|
}, {
|
|
210
200
|
bindGlobal: true
|
|
211
201
|
});
|
|
212
|
-
const setLoader = useCallback((name, value) => setLoaders(current => ({
|
|
202
|
+
const setLoader = useCallback((name, value) => setLoaders(current => ({
|
|
203
|
+
...current,
|
|
213
204
|
[name]: value
|
|
214
205
|
})), []);
|
|
215
|
-
|
|
216
206
|
const closeAndReset = () => {
|
|
217
207
|
setSearch('');
|
|
218
208
|
close();
|
|
219
209
|
};
|
|
220
|
-
|
|
221
210
|
if (!isOpen) {
|
|
222
211
|
return false;
|
|
223
212
|
}
|
|
224
|
-
|
|
225
213
|
const onKeyDown = event => {
|
|
226
|
-
if (
|
|
227
|
-
|
|
214
|
+
if (
|
|
215
|
+
// Ignore keydowns from IMEs
|
|
216
|
+
event.nativeEvent.isComposing ||
|
|
217
|
+
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition
|
|
228
218
|
// is `isComposing=false`, even though it's technically still part of the composition.
|
|
229
219
|
// These can only be detected by keyCode.
|
|
230
220
|
event.keyCode === 229) {
|
|
231
221
|
event.preventDefault();
|
|
232
222
|
}
|
|
233
223
|
};
|
|
234
|
-
|
|
235
224
|
const isLoading = Object.values(loaders).some(Boolean);
|
|
236
225
|
return createElement(Modal, {
|
|
237
226
|
className: "commands-command-menu",
|
|
@@ -245,7 +234,9 @@ export function CommandMenu() {
|
|
|
245
234
|
onKeyDown: onKeyDown
|
|
246
235
|
}, createElement("div", {
|
|
247
236
|
className: "commands-command-menu__header"
|
|
248
|
-
}, createElement(
|
|
237
|
+
}, createElement(Icon, {
|
|
238
|
+
icon: inputIcon
|
|
239
|
+
}), createElement(CommandInput, {
|
|
249
240
|
search: search,
|
|
250
241
|
setSearch: setSearch,
|
|
251
242
|
isOpen: isOpen
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/components/command-menu.js"],"names":["Command","useCommandState","useSelect","useDispatch","useState","useEffect","useRef","useCallback","useMemo","__","Modal","TextHighlight","__experimentalHStack","HStack","store","keyboardShortcutsStore","useShortcut","Icon","commandsStore","CommandMenuLoader","name","search","hook","setLoader","close","isLoading","commands","length","map","command","searchLabel","label","callback","icon","CommandMenuLoaderWrapper","currentLoader","key","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","state","value","selectedItemId","item","document","querySelector","getAttribute","focus","CommandMenu","registerShortcut","open","setLoaders","category","description","keyCombination","modifier","character","event","defaultPrevented","preventDefault","bindGlobal","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,eAAlB,QAAyC,MAAzC;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SACCC,QADD,EAECC,SAFD,EAGCC,MAHD,EAICC,WAJD,EAKCC,OALD,QAMO,oBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,KADD,EAECC,aAFD,EAGCC,oBAAoB,IAAIC,MAHzB,QAIO,uBAJP;AAKA,SACCC,KAAK,IAAIC,sBADV,EAECC,WAFD,QAGO,+BAHP;AAIA,SAASC,IAAT,QAAqB,kBAArB;AAEA;AACA;AACA;;AACA,SAASH,KAAK,IAAII,aAAlB,QAAuC,UAAvC;;AAEA,SAASC,iBAAT,CAA4B;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,MAAR;AAAgBC,EAAAA,IAAhB;AAAsBC,EAAAA,SAAtB;AAAiCC,EAAAA;AAAjC,CAA5B,EAAuE;AAAA;;AACtE,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,QAAQ,GAAG;AAAxB,eAA+BJ,IAAI,CAAE;AAAED,IAAAA;AAAF,GAAF,CAAnC,yCAAqD,EAA3D;AACAhB,EAAAA,SAAS,CAAE,MAAM;AAChBkB,IAAAA,SAAS,CAAEH,IAAF,EAAQK,SAAR,CAAT;AACA,GAFQ,EAEN,CAAEF,SAAF,EAAaH,IAAb,EAAmBK,SAAnB,CAFM,CAAT;;AAIA,MAAK,CAAEC,QAAQ,CAACC,MAAhB,EAAyB;AACxB,WAAO,IAAP;AACA;;AAED,SACC,8BACC,cAAC,OAAD,CAAS,IAAT,QACGD,QAAQ,CAACE,GAAT,CAAgBC,OAAF;AAAA;;AAAA,WACf,cAAC,OAAD,CAAS,IAAT;AACC,MAAA,GAAG,EAA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AA,SAAS,EAAGE,SAFb;AAGC,IAAA,KAAK,EAAGkD;AAHT,IAbF,CAXD,CADD,CAND,CADD;AA2CA","sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t\t<Command.Item\n\t\t\t\t\t\tkey={ command.name }\n\t\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\t\tid={ command.name }\n\t\t\t\t\t>\n\t\t\t\t\t\t<HStack\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Type a command or search' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t/>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"names":["Command","useCommandState","classnames","useSelect","useDispatch","useState","useEffect","useRef","useCallback","useMemo","__","Modal","TextHighlight","__experimentalHStack","HStack","store","keyboardShortcutsStore","useShortcut","Icon","search","inputIcon","commandsStore","CommandMenuLoader","name","hook","setLoader","close","_hook","isLoading","commands","length","createElement","Fragment","List","map","command","_command$searchLabel","Item","key","value","searchLabel","label","onSelect","callback","id","alignment","className","icon","text","highlight","CommandMenuLoaderWrapper","currentLoader","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","Group","_command$searchLabel2","loader","CommandInput","isOpen","setSearch","commandMenuInput","_value","state","selectedItemId","item","document","querySelector","getAttribute","focus","Input","ref","onValueChange","placeholder","CommandMenu","registerShortcut","open","setLoaders","category","description","keyCombination","modifier","character","event","defaultPrevented","preventDefault","bindGlobal","closeAndReset","onKeyDown","nativeEvent","isComposing","keyCode","Object","values","some","Boolean","overlayClassName","onRequestClose","__experimentalHideHeader","Empty"],"sources":["@wordpress/commands/src/components/command-menu.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { Command, useCommandState } from 'cmdk';\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon, search as inputIcon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t\t<Command.Item\n\t\t\t\t\t\tkey={ command.name }\n\t\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\t\tid={ command.name }\n\t\t\t\t\t>\n\t\t\t\t\t\t<HStack\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'commands-command-menu__item',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\tid={ command.name }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName={ classnames( 'commands-command-menu__item', {\n\t\t\t\t\t\t\t'has-icon': command.icon,\n\t\t\t\t\t\t} ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ command.icon && <Icon icon={ command.icon } /> }\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nfunction CommandInput( { isOpen, search, setSearch } ) {\n\tconst commandMenuInput = useRef();\n\tconst _value = useCommandState( ( state ) => state.value );\n\tconst selectedItemId = useMemo( () => {\n\t\tconst item = document.querySelector(\n\t\t\t`[cmdk-item=\"\"][data-value=\"${ _value }\"]`\n\t\t);\n\t\treturn item?.getAttribute( 'id' );\n\t}, [ _value ] );\n\tuseEffect( () => {\n\t\t// Focus the command palette input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\treturn (\n\t\t<Command.Input\n\t\t\tref={ commandMenuInput }\n\t\t\tvalue={ search }\n\t\t\tonValueChange={ setSearch }\n\t\t\tplaceholder={ __( 'Search for commands' ) }\n\t\t\taria-activedescendant={ selectedItemId }\n\t\t\ticon={ search }\n\t\t/>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\n\tuseEffect( () => {\n\t\tregisterShortcut( {\n\t\t\tname: 'core/commands',\n\t\t\tcategory: 'global',\n\t\t\tdescription: __( 'Open the command palette.' ),\n\t\t\tkeyCombination: {\n\t\t\t\tmodifier: 'primary',\n\t\t\t\tcharacter: 'k',\n\t\t\t},\n\t\t} );\n\t}, [ registerShortcut ] );\n\n\tuseShortcut(\n\t\t'core/commands',\n\t\t/** @type {import('react').KeyboardEventHandler} */\n\t\t( event ) => {\n\t\t\t// Bails to avoid obscuring the effect of the preceding handler(s).\n\t\t\tif ( event.defaultPrevented ) return;\n\n\t\t\tevent.preventDefault();\n\t\t\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tif ( ! isOpen ) {\n\t\treturn false;\n\t}\n\n\tconst onKeyDown = ( event ) => {\n\t\tif (\n\t\t\t// Ignore keydowns from IMEs\n\t\t\tevent.nativeEvent.isComposing ||\n\t\t\t// Workaround for Mac Safari where the final Enter/Backspace of an IME composition\n\t\t\t// is `isComposing=false`, even though it's technically still part of the composition.\n\t\t\t// These can only be detected by keyCode.\n\t\t\tevent.keyCode === 229\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t};\n\n\tconst isLoading = Object.values( loaders ).some( Boolean );\n\n\treturn (\n\t\t<Modal\n\t\t\tclassName=\"commands-command-menu\"\n\t\t\toverlayClassName=\"commands-command-menu__overlay\"\n\t\t\tonRequestClose={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command\n\t\t\t\t\tlabel={ __( 'Command palette' ) }\n\t\t\t\t\tonKeyDown={ onKeyDown }\n\t\t\t\t>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Icon icon={ inputIcon } />\n\t\t\t\t\t\t<CommandInput\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetSearch={ setSearch }\n\t\t\t\t\t\t\tisOpen={ isOpen }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n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,SAAS,IACtBG,aAAA,CAAC/B,OAAO,CAACyG,KAAK,QACX/F,EAAE,CAAE,mBAAoB,CACZ,CACf,EACDqB,aAAA,CAACwB,gBAAgB;IAChBpC,MAAM,EAAGA,MAAQ;IACjBM,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGmE,aAAe;IACvBrC,YAAY;EAAA,CACZ,CAAC,EACArC,MAAM,IACPY,aAAA,CAACwB,gBAAgB;IAChBpC,MAAM,EAAGA,MAAQ;IACjBM,SAAS,EAAGA,SAAW;IACvBC,KAAK,EAAGmE;EAAe,CACvB,CAEW,CACN,CACL,CACC,CAAC;AAEV"}
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect, useRef } from '@wordpress/element';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import { store as commandsStore } from '../store';
|
|
11
11
|
import { unlock } from '../lock-unlock';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Sets the active context of the command palette
|
|
14
15
|
*
|
|
15
16
|
* @param {string} context Context to set.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
export default function useCommandContext(context) {
|
|
19
19
|
const {
|
|
20
20
|
getContext
|
|
@@ -25,9 +25,10 @@ export default function useCommandContext(context) {
|
|
|
25
25
|
} = unlock(useDispatch(commandsStore));
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
setContext(context);
|
|
28
|
-
}, [context, setContext]);
|
|
29
|
-
// that was set before the component actually mounts.
|
|
28
|
+
}, [context, setContext]);
|
|
30
29
|
|
|
30
|
+
// This effects ensures that on unmount, we restore the context
|
|
31
|
+
// that was set before the component actually mounts.
|
|
31
32
|
useEffect(() => {
|
|
32
33
|
const initialContextRef = initialContext.current;
|
|
33
34
|
return () => setContext(initialContextRef);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useDispatch","useSelect","store","commandsStore","unlock","useCommandContext","context","getContext","initialContext","setContext","initialContextRef","current"],"sources":["@wordpress/commands/src/hooks/use-command-context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\nimport { unlock } from '../lock-unlock';\n\n/**\n * Sets the active context of the command palette\n *\n * @param {string} context Context to set.\n */\nexport default function useCommandContext( context ) {\n\tconst { getContext } = useSelect( commandsStore );\n\tconst initialContext = useRef( getContext() );\n\tconst { setContext } = unlock( useDispatch( commandsStore ) );\n\n\tuseEffect( () => {\n\t\tsetContext( context );\n\t}, [ context, setContext ] );\n\n\t// This effects ensures that on unmount, we restore the context\n\t// that was set before the component actually mounts.\n\tuseEffect( () => {\n\t\tconst initialContextRef = initialContext.current;\n\t\treturn () => setContext( initialContextRef );\n\t}, [ setContext ] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;;AAExD;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;AACjD,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,iBAAiBA,CAAEC,OAAO,EAAG;EACpD,MAAM;IAAEC;EAAW,CAAC,GAAGN,SAAS,CAAEE,aAAc,CAAC;EACjD,MAAMK,cAAc,GAAGT,MAAM,CAAEQ,UAAU,CAAC,CAAE,CAAC;EAC7C,MAAM;IAAEE;EAAW,CAAC,GAAGL,MAAM,CAAEJ,WAAW,CAAEG,aAAc,CAAE,CAAC;EAE7DL,SAAS,CAAE,MAAM;IAChBW,UAAU,CAAEH,OAAQ,CAAC;EACtB,CAAC,EAAE,CAAEA,OAAO,EAAEG,UAAU,CAAG,CAAC;;EAE5B;EACA;EACAX,SAAS,CAAE,MAAM;IAChB,MAAMY,iBAAiB,GAAGF,cAAc,CAACG,OAAO;IAChD,OAAO,MAAMF,UAAU,CAAEC,iBAAkB,CAAC;EAC7C,CAAC,EAAE,CAAED,UAAU,CAAG,CAAC;AACpB"}
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect } from '@wordpress/element';
|
|
5
5
|
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import { store as commandsStore } from '../store';
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Attach a command loader to the command palette.
|
|
13
14
|
*
|
|
14
15
|
* @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
export default function useCommandLoader(loader) {
|
|
18
18
|
const {
|
|
19
19
|
registerCommandLoader,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useEffect","useDispatch","store","commandsStore","useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","name","hook","context"],"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command loader to the command palette.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n */\nexport default function useCommandLoader( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAgBA,CAAEC,MAAM,EAAG;EAClD,MAAM;IAAEC,qBAAqB;IAAEC;EAAwB,CAAC,GACvDN,WAAW,CAAEE,aAAc,CAAC;EAC7BH,SAAS,CAAE,MAAM;IAChBM,qBAAqB,CAAE;MACtBE,IAAI,EAAEH,MAAM,CAACG,IAAI;MACjBC,IAAI,EAAEJ,MAAM,CAACI,IAAI;MACjBC,OAAO,EAAEL,MAAM,CAACK;IACjB,CAAE,CAAC;IACH,OAAO,MAAM;MACZH,uBAAuB,CAAEF,MAAM,CAACG,IAAK,CAAC;IACvC,CAAC;EACF,CAAC,EAAE,CACFH,MAAM,CAACG,IAAI,EACXH,MAAM,CAACI,IAAI,EACXJ,MAAM,CAACK,OAAO,EACdJ,qBAAqB,EACrBC,uBAAuB,CACtB,CAAC;AACJ"}
|
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useEffect, useRef } from '@wordpress/element';
|
|
5
5
|
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import { store as commandsStore } from '../store';
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Attach a command to the command palette.
|
|
13
14
|
*
|
|
14
15
|
* @param {import('../store/actions').WPCommandConfig} command command config.
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
export default function useCommand(command) {
|
|
18
18
|
const {
|
|
19
19
|
registerCommand,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallback","callback","current","name","context","label","searchLabel","icon","args"],"sources":["@wordpress/commands/src/hooks/use-command.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Attach a command to the command palette.\n *\n * @param {import('../store/actions').WPCommandConfig} command command config.\n */\nexport default function useCommand( command ) {\n\tconst { registerCommand, unregisterCommand } = useDispatch( commandsStore );\n\tconst currentCallback = useRef( command.callback );\n\tuseEffect( () => {\n\t\tcurrentCallback.current = command.callback;\n\t}, [ command.callback ] );\n\n\tuseEffect( () => {\n\t\tregisterCommand( {\n\t\t\tname: command.name,\n\t\t\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: ( ...args ) => currentCallback.current( ...args ),\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;;AAE7C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,aAAa,QAAQ,UAAU;;AAEjD;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAAEC,OAAO,EAAG;EAC7C,MAAM;IAAEC,eAAe;IAAEC;EAAkB,CAAC,GAAGN,WAAW,CAAEE,aAAc,CAAC;EAC3E,MAAMK,eAAe,GAAGR,MAAM,CAAEK,OAAO,CAACI,QAAS,CAAC;EAClDV,SAAS,CAAE,MAAM;IAChBS,eAAe,CAACE,OAAO,GAAGL,OAAO,CAACI,QAAQ;EAC3C,CAAC,EAAE,CAAEJ,OAAO,CAACI,QAAQ,CAAG,CAAC;EAEzBV,SAAS,CAAE,MAAM;IAChBO,eAAe,CAAE;MAChBK,IAAI,EAAEN,OAAO,CAACM,IAAI;MAClBC,OAAO,EAAEP,OAAO,CAACO,OAAO;MACxBC,KAAK,EAAER,OAAO,CAACQ,KAAK;MACpBC,WAAW,EAAET,OAAO,CAACS,WAAW;MAChCC,IAAI,EAAEV,OAAO,CAACU,IAAI;MAClBN,QAAQ,EAAEA,CAAE,GAAGO,IAAI,KAAMR,eAAe,CAACE,OAAO,CAAE,GAAGM,IAAK;IAC3D,CAAE,CAAC;IACH,OAAO,MAAM;MACZT,iBAAiB,CAAEF,OAAO,CAACM,IAAK,CAAC;IAClC,CAAC;EACF,CAAC,EAAE,CACFN,OAAO,CAACM,IAAI,EACZN,OAAO,CAACQ,KAAK,EACbR,OAAO,CAACS,WAAW,EACnBT,OAAO,CAACU,IAAI,EACZV,OAAO,CAACO,OAAO,EACfN,eAAe,EACfC,iBAAiB,CAChB,CAAC;AACJ"}
|