@wordpress/commands 0.4.0 → 0.6.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 +4 -0
- package/README.md +28 -0
- package/build/components/command-menu.js +78 -72
- package/build/components/command-menu.js.map +1 -1
- package/build/hooks/use-command-context.js +47 -0
- package/build/hooks/use-command-context.js.map +1 -0
- package/build/hooks/use-command-loader.js +6 -11
- package/build/hooks/use-command-loader.js.map +1 -1
- package/build/hooks/use-command.js +4 -3
- package/build/hooks/use-command.js.map +1 -1
- package/build/index.js +26 -0
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +19 -0
- package/build/lock-unlock.js.map +1 -0
- package/build/private-apis.js +5 -21
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +19 -40
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +5 -0
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +21 -0
- package/build/store/private-actions.js.map +1 -0
- package/build/store/reducer.js +38 -34
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +14 -17
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/command-menu.js +78 -72
- package/build-module/components/command-menu.js.map +1 -1
- package/build-module/hooks/use-command-context.js +36 -0
- package/build-module/hooks/use-command-context.js.map +1 -0
- package/build-module/hooks/use-command-loader.js +6 -11
- package/build-module/hooks/use-command-loader.js.map +1 -1
- package/build-module/hooks/use-command.js +4 -3
- package/build-module/hooks/use-command.js.map +1 -1
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +9 -0
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/private-apis.js +3 -15
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +19 -40
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +3 -0
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js +14 -0
- package/build-module/store/private-actions.js.map +1 -0
- package/build-module/store/reducer.js +38 -34
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +11 -16
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +6 -1
- package/build-style/style.css +6 -1
- package/package.json +9 -9
- package/src/components/command-menu.js +38 -35
- package/src/components/style.scss +8 -1
- package/src/hooks/use-command-context.js +33 -0
- package/src/hooks/use-command-loader.js +12 -6
- package/src/hooks/use-command.js +5 -3
- package/src/index.js +3 -0
- package/src/lock-unlock.js +10 -0
- package/src/private-apis.js +3 -17
- package/src/store/actions.js +17 -26
- package/src/store/index.js +3 -0
- package/src/store/private-actions.js +13 -0
- package/src/store/reducer.js +33 -27
- package/src/store/selectors.js +18 -20
package/build/store/actions.js
CHANGED
|
@@ -17,11 +17,12 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
17
17
|
*
|
|
18
18
|
* @typedef {Object} WPCommandConfig
|
|
19
19
|
*
|
|
20
|
-
* @property {string} name
|
|
21
|
-
* @property {string} label
|
|
22
|
-
* @property {string=}
|
|
23
|
-
* @property {
|
|
24
|
-
* @property {
|
|
20
|
+
* @property {string} name Command name.
|
|
21
|
+
* @property {string} label Command label.
|
|
22
|
+
* @property {string=} searchLabel Command search label.
|
|
23
|
+
* @property {string=} context Command context.
|
|
24
|
+
* @property {JSX.Element} icon Command icon.
|
|
25
|
+
* @property {Function} callback Command callback.
|
|
25
26
|
*/
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -33,9 +34,9 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
33
34
|
*
|
|
34
35
|
* @typedef {Object} WPCommandLoaderConfig
|
|
35
36
|
*
|
|
36
|
-
* @property {string} name
|
|
37
|
-
* @property {string=}
|
|
38
|
-
* @property {WPCommandLoaderHook} hook
|
|
37
|
+
* @property {string} name Command loader name.
|
|
38
|
+
* @property {string=} context Command loader context.
|
|
39
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
39
40
|
*/
|
|
40
41
|
|
|
41
42
|
/**
|
|
@@ -45,38 +46,25 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
45
46
|
*
|
|
46
47
|
* @return {Object} action.
|
|
47
48
|
*/
|
|
48
|
-
function registerCommand(
|
|
49
|
-
let {
|
|
50
|
-
name,
|
|
51
|
-
label,
|
|
52
|
-
icon,
|
|
53
|
-
callback,
|
|
54
|
-
group = ''
|
|
55
|
-
} = _ref;
|
|
49
|
+
function registerCommand(config) {
|
|
56
50
|
return {
|
|
57
51
|
type: 'REGISTER_COMMAND',
|
|
58
|
-
|
|
59
|
-
label,
|
|
60
|
-
icon,
|
|
61
|
-
callback,
|
|
62
|
-
group
|
|
52
|
+
...config
|
|
63
53
|
};
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
66
56
|
* Returns an action object used to unregister a command.
|
|
67
57
|
*
|
|
68
|
-
* @param {string} name
|
|
69
|
-
* @param {string} group Command group.
|
|
58
|
+
* @param {string} name Command name.
|
|
70
59
|
*
|
|
71
60
|
* @return {Object} action.
|
|
72
61
|
*/
|
|
73
62
|
|
|
74
63
|
|
|
75
|
-
function unregisterCommand(name
|
|
64
|
+
function unregisterCommand(name) {
|
|
76
65
|
return {
|
|
77
66
|
type: 'UNREGISTER_COMMAND',
|
|
78
|
-
name
|
|
79
|
-
group
|
|
67
|
+
name
|
|
80
68
|
};
|
|
81
69
|
}
|
|
82
70
|
/**
|
|
@@ -88,34 +76,25 @@ function unregisterCommand(name, group) {
|
|
|
88
76
|
*/
|
|
89
77
|
|
|
90
78
|
|
|
91
|
-
function registerCommandLoader(
|
|
92
|
-
let {
|
|
93
|
-
name,
|
|
94
|
-
group = '',
|
|
95
|
-
hook
|
|
96
|
-
} = _ref2;
|
|
79
|
+
function registerCommandLoader(config) {
|
|
97
80
|
return {
|
|
98
81
|
type: 'REGISTER_COMMAND_LOADER',
|
|
99
|
-
|
|
100
|
-
group,
|
|
101
|
-
hook
|
|
82
|
+
...config
|
|
102
83
|
};
|
|
103
84
|
}
|
|
104
85
|
/**
|
|
105
86
|
* Unregister command loader hook.
|
|
106
87
|
*
|
|
107
|
-
* @param {string} name
|
|
108
|
-
* @param {string} group Command loader group.
|
|
88
|
+
* @param {string} name Command loader name.
|
|
109
89
|
*
|
|
110
90
|
* @return {Object} action.
|
|
111
91
|
*/
|
|
112
92
|
|
|
113
93
|
|
|
114
|
-
function unregisterCommandLoader(name
|
|
94
|
+
function unregisterCommandLoader(name) {
|
|
115
95
|
return {
|
|
116
96
|
type: 'UNREGISTER_COMMAND_LOADER',
|
|
117
|
-
name
|
|
118
|
-
group
|
|
97
|
+
name
|
|
119
98
|
};
|
|
120
99
|
}
|
|
121
100
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/store/actions.js"],"names":["registerCommand","
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/actions.js"],"names":["registerCommand","config","type","unregisterCommand","name","registerCommandLoader","unregisterCommandLoader","open","close"],"mappings":";;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,MAA1B,EAAmC;AACzC,SAAO;AACNC,IAAAA,IAAI,EAAE,kBADA;AAEN,OAAGD;AAFG,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,SAAO;AACNF,IAAAA,IAAI,EAAE,oBADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,qBAAT,CAAgCJ,MAAhC,EAAyC;AAC/C,SAAO;AACNC,IAAAA,IAAI,EAAE,yBADA;AAEN,OAAGD;AAFG,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,uBAAT,CAAkCF,IAAlC,EAAyC;AAC/C,SAAO;AACNF,IAAAA,IAAI,EAAE,2BADA;AAENE,IAAAA;AAFM,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASG,IAAT,GAAgB;AACtB,SAAO;AACNL,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASM,KAAT,GAAiB;AACvB,SAAO;AACNN,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA","sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPCommandConfig\n *\n * @property {string} name Command name.\n * @property {string} label Command label.\n * @property {string=} searchLabel Command search label.\n * @property {string=} context Command context.\n * @property {JSX.Element} icon Command icon.\n * @property {Function} callback Command callback.\n */\n\n/**\n * @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo\n */\n\n/**\n * Command loader config.\n *\n * @typedef {Object} WPCommandLoaderConfig\n *\n * @property {string} name Command loader name.\n * @property {string=} context Command loader context.\n * @property {WPCommandLoaderHook} hook Command loader hook.\n */\n\n/**\n * Returns an action object used to register a new command.\n *\n * @param {WPCommandConfig} config Command config.\n *\n * @return {Object} action.\n */\nexport function registerCommand( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND',\n\t\t...config,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a command.\n *\n * @param {string} name Command name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommand( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND',\n\t\tname,\n\t};\n}\n\n/**\n * Register command loader.\n *\n * @param {WPCommandLoaderConfig} config Command loader config.\n *\n * @return {Object} action.\n */\nexport function registerCommandLoader( config ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND_LOADER',\n\t\t...config,\n\t};\n}\n\n/**\n * Unregister command loader hook.\n *\n * @param {string} name Command loader name.\n *\n * @return {Object} action.\n */\nexport function unregisterCommandLoader( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND_LOADER',\n\t\tname,\n\t};\n}\n\n/**\n * Opens the command center.\n *\n * @return {Object} action.\n */\nexport function open() {\n\treturn {\n\t\ttype: 'OPEN',\n\t};\n}\n\n/**\n * Closes the command center.\n *\n * @return {Object} action.\n */\nexport function close() {\n\treturn {\n\t\ttype: 'CLOSE',\n\t};\n}\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -15,6 +15,10 @@ var actions = _interopRequireWildcard(require("./actions"));
|
|
|
15
15
|
|
|
16
16
|
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
17
17
|
|
|
18
|
+
var privateActions = _interopRequireWildcard(require("./private-actions"));
|
|
19
|
+
|
|
20
|
+
var _lockUnlock = require("../lock-unlock");
|
|
21
|
+
|
|
18
22
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
23
|
|
|
20
24
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -42,4 +46,5 @@ const store = (0, _data.createReduxStore)(STORE_NAME, {
|
|
|
42
46
|
});
|
|
43
47
|
exports.store = store;
|
|
44
48
|
(0, _data.register)(store);
|
|
49
|
+
(0, _lockUnlock.unlock)(store).registerPrivateActions(privateActions);
|
|
45
50
|
//# sourceMappingURL=index.js.map
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/store/index.js"],"names":["STORE_NAME","store","reducer","actions","selectors"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;;;;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/index.js"],"names":["STORE_NAME","store","reducer","actions","selectors","registerPrivateActions","privateActions"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;;;;;AAZA;AACA;AACA;;AAGA;AACA;AACA;AAOA,MAAMA,UAAU,GAAG,eAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,KAAK,GAAG,4BAAkBD,UAAlB,EAA8B;AAClDE,EAAAA,OAAO,EAAPA,gBADkD;AAElDC,EAAAA,OAFkD;AAGlDC,EAAAA;AAHkD,CAA9B,CAAd;;AAMP,oBAAUH,KAAV;AACA,wBAAQA,KAAR,EAAgBI,sBAAhB,CAAwCC,cAAxC","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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setContext = setContext;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sets the active context.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} context Context.
|
|
12
|
+
*
|
|
13
|
+
* @return {Object} action.
|
|
14
|
+
*/
|
|
15
|
+
function setContext(context) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'SET_CONTEXT',
|
|
18
|
+
context
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=private-actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/private-actions.js"],"names":["setContext","context","type"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,CAAqBC,OAArB,EAA+B;AACrC,SAAO;AACNC,IAAAA,IAAI,EAAE,aADA;AAEND,IAAAA;AAFM,GAAP;AAIA","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"]}
|
package/build/store/reducer.js
CHANGED
|
@@ -19,21 +19,17 @@ var _data = require("@wordpress/data");
|
|
|
19
19
|
*
|
|
20
20
|
* @return {Object} Updated state.
|
|
21
21
|
*/
|
|
22
|
-
function commands() {
|
|
23
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
25
|
-
|
|
22
|
+
function commands(state = {}, action) {
|
|
26
23
|
switch (action.type) {
|
|
27
24
|
case 'REGISTER_COMMAND':
|
|
28
25
|
return { ...state,
|
|
29
|
-
[action.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
26
|
+
[action.name]: {
|
|
27
|
+
name: action.name,
|
|
28
|
+
label: action.label,
|
|
29
|
+
searchLabel: action.searchLabel,
|
|
30
|
+
context: action.context,
|
|
31
|
+
callback: action.callback,
|
|
32
|
+
icon: action.icon
|
|
37
33
|
}
|
|
38
34
|
};
|
|
39
35
|
|
|
@@ -42,10 +38,8 @@ function commands() {
|
|
|
42
38
|
const {
|
|
43
39
|
[action.name]: _,
|
|
44
40
|
...remainingState
|
|
45
|
-
} = state
|
|
46
|
-
return
|
|
47
|
-
[action.group]: remainingState
|
|
48
|
-
};
|
|
41
|
+
} = state;
|
|
42
|
+
return remainingState;
|
|
49
43
|
}
|
|
50
44
|
}
|
|
51
45
|
|
|
@@ -61,18 +55,14 @@ function commands() {
|
|
|
61
55
|
*/
|
|
62
56
|
|
|
63
57
|
|
|
64
|
-
function commandLoaders() {
|
|
65
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
66
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
67
|
-
|
|
58
|
+
function commandLoaders(state = {}, action) {
|
|
68
59
|
switch (action.type) {
|
|
69
60
|
case 'REGISTER_COMMAND_LOADER':
|
|
70
61
|
return { ...state,
|
|
71
|
-
[action.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
62
|
+
[action.name]: {
|
|
63
|
+
name: action.name,
|
|
64
|
+
context: action.context,
|
|
65
|
+
hook: action.hook
|
|
76
66
|
}
|
|
77
67
|
};
|
|
78
68
|
|
|
@@ -81,10 +71,8 @@ function commandLoaders() {
|
|
|
81
71
|
const {
|
|
82
72
|
[action.name]: _,
|
|
83
73
|
...remainingState
|
|
84
|
-
} = state
|
|
85
|
-
return
|
|
86
|
-
[action.group]: remainingState
|
|
87
|
-
};
|
|
74
|
+
} = state;
|
|
75
|
+
return remainingState;
|
|
88
76
|
}
|
|
89
77
|
}
|
|
90
78
|
|
|
@@ -100,10 +88,7 @@ function commandLoaders() {
|
|
|
100
88
|
*/
|
|
101
89
|
|
|
102
90
|
|
|
103
|
-
function isOpen() {
|
|
104
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
105
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
106
|
-
|
|
91
|
+
function isOpen(state = false, action) {
|
|
107
92
|
switch (action.type) {
|
|
108
93
|
case 'OPEN':
|
|
109
94
|
return true;
|
|
@@ -114,11 +99,30 @@ function isOpen() {
|
|
|
114
99
|
|
|
115
100
|
return state;
|
|
116
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Reducer returning the command center's active context.
|
|
104
|
+
*
|
|
105
|
+
* @param {Object} state Current state.
|
|
106
|
+
* @param {Object} action Dispatched action.
|
|
107
|
+
*
|
|
108
|
+
* @return {boolean} Updated state.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
function context(state = 'root', action) {
|
|
113
|
+
switch (action.type) {
|
|
114
|
+
case 'SET_CONTEXT':
|
|
115
|
+
return action.context;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return state;
|
|
119
|
+
}
|
|
117
120
|
|
|
118
121
|
const reducer = (0, _data.combineReducers)({
|
|
119
122
|
commands,
|
|
120
123
|
commandLoaders,
|
|
121
|
-
isOpen
|
|
124
|
+
isOpen,
|
|
125
|
+
context
|
|
122
126
|
});
|
|
123
127
|
var _default = reducer;
|
|
124
128
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/store/reducer.js"],"names":["commands","state","action","type","
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/reducer.js"],"names":["commands","state","action","type","name","label","searchLabel","context","callback","icon","_","remainingState","commandLoaders","hook","isOpen","reducer"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,KAAK,GAAG,EAA3B,EAA+BC,MAA/B,EAAwC;AACvC,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,kBAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,IAAT,GAAiB;AAChBA,UAAAA,IAAI,EAAEF,MAAM,CAACE,IADG;AAEhBC,UAAAA,KAAK,EAAEH,MAAM,CAACG,KAFE;AAGhBC,UAAAA,WAAW,EAAEJ,MAAM,CAACI,WAHJ;AAIhBC,UAAAA,OAAO,EAAEL,MAAM,CAACK,OAJA;AAKhBC,UAAAA,QAAQ,EAAEN,MAAM,CAACM,QALD;AAMhBC,UAAAA,IAAI,EAAEP,MAAM,CAACO;AANG;AAFX,OAAP;;AAWD,SAAK,oBAAL;AAA2B;AAC1B,cAAM;AAAE,WAAEP,MAAM,CAACE,IAAT,GAAiBM,CAAnB;AAAsB,aAAGC;AAAzB,YAA4CV,KAAlD;AACA,eAAOU,cAAP;AACA;AAhBF;;AAmBA,SAAOV,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASW,cAAT,CAAyBX,KAAK,GAAG,EAAjC,EAAqCC,MAArC,EAA8C;AAC7C,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,yBAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,IAAT,GAAiB;AAChBA,UAAAA,IAAI,EAAEF,MAAM,CAACE,IADG;AAEhBG,UAAAA,OAAO,EAAEL,MAAM,CAACK,OAFA;AAGhBM,UAAAA,IAAI,EAAEX,MAAM,CAACW;AAHG;AAFX,OAAP;;AAQD,SAAK,2BAAL;AAAkC;AACjC,cAAM;AAAE,WAAEX,MAAM,CAACE,IAAT,GAAiBM,CAAnB;AAAsB,aAAGC;AAAzB,YAA4CV,KAAlD;AACA,eAAOU,cAAP;AACA;AAbF;;AAgBA,SAAOV,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASa,MAAT,CAAiBb,KAAK,GAAG,KAAzB,EAAgCC,MAAhC,EAAyC;AACxC,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,MAAL;AACC,aAAO,IAAP;;AACD,SAAK,OAAL;AACC,aAAO,KAAP;AAJF;;AAOA,SAAOF,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,OAAT,CAAkBN,KAAK,GAAG,MAA1B,EAAkCC,MAAlC,EAA2C;AAC1C,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,aAAL;AACC,aAAOD,MAAM,CAACK,OAAd;AAFF;;AAKA,SAAON,KAAP;AACA;;AAED,MAAMc,OAAO,GAAG,2BAAiB;AAChCf,EAAAA,QADgC;AAEhCY,EAAAA,cAFgC;AAGhCE,EAAAA,MAHgC;AAIhCP,EAAAA;AAJgC,CAAjB,CAAhB;eAOeQ,O","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 center 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 center'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"]}
|
package/build/store/selectors.js
CHANGED
|
@@ -5,7 +5,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.getCommands = exports.getCommandLoaders = void 0;
|
|
9
|
+
exports.getContext = getContext;
|
|
9
10
|
exports.isOpen = isOpen;
|
|
10
11
|
|
|
11
12
|
var _rememo = _interopRequireDefault(require("rememo"));
|
|
@@ -13,26 +14,22 @@ var _rememo = _interopRequireDefault(require("rememo"));
|
|
|
13
14
|
/**
|
|
14
15
|
* External dependencies
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getGroups = (0, _rememo.default)(state => unique(Object.keys(state.commands).concat(Object.keys(state.commandLoaders))), state => [state.commands, state.commandLoaders]);
|
|
21
|
-
exports.getGroups = getGroups;
|
|
22
|
-
const getCommands = (0, _rememo.default)((state, group) => {
|
|
23
|
-
var _state$commands$group;
|
|
24
|
-
|
|
25
|
-
return Object.values((_state$commands$group = state.commands[group]) !== null && _state$commands$group !== void 0 ? _state$commands$group : {});
|
|
26
|
-
}, (state, group) => [state.commands[group]]);
|
|
17
|
+
const getCommands = (0, _rememo.default)((state, contextual = false) => Object.values(state.commands).filter(command => {
|
|
18
|
+
const isContextual = command.context && command.context === state.context;
|
|
19
|
+
return contextual ? isContextual : !isContextual;
|
|
20
|
+
}), state => [state.commands, state.context]);
|
|
27
21
|
exports.getCommands = getCommands;
|
|
28
|
-
const getCommandLoaders = (0, _rememo.default)((state,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}, (state, group) => [state.commandLoaders[group]]);
|
|
22
|
+
const getCommandLoaders = (0, _rememo.default)((state, contextual = false) => Object.values(state.commandLoaders).filter(loader => {
|
|
23
|
+
const isContextual = loader.context && loader.context === state.context;
|
|
24
|
+
return contextual ? isContextual : !isContextual;
|
|
25
|
+
}), state => [state.commandLoaders, state.context]);
|
|
33
26
|
exports.getCommandLoaders = getCommandLoaders;
|
|
34
27
|
|
|
35
28
|
function isOpen(state) {
|
|
36
29
|
return state.isOpen;
|
|
37
30
|
}
|
|
31
|
+
|
|
32
|
+
function getContext(state) {
|
|
33
|
+
return state.context;
|
|
34
|
+
}
|
|
38
35
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/store/selectors.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/selectors.js"],"names":["getCommands","state","contextual","Object","values","commands","filter","command","isContextual","context","getCommandLoaders","commandLoaders","loader","isOpen","getContext"],"mappings":";;;;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAMA,WAAW,GAAG,qBAC1B,CAAEC,KAAF,EAASC,UAAU,GAAG,KAAtB,KACCC,MAAM,CAACC,MAAP,CAAeH,KAAK,CAACI,QAArB,EAAgCC,MAAhC,CAA0CC,OAAF,IAAe;AACtD,QAAMC,YAAY,GACjBD,OAAO,CAACE,OAAR,IAAmBF,OAAO,CAACE,OAAR,KAAoBR,KAAK,CAACQ,OAD9C;AAEA,SAAOP,UAAU,GAAGM,YAAH,GAAkB,CAAEA,YAArC;AACA,CAJD,CAFyB,EAOxBP,KAAF,IAAa,CAAEA,KAAK,CAACI,QAAR,EAAkBJ,KAAK,CAACQ,OAAxB,CAPa,CAApB;;AAUA,MAAMC,iBAAiB,GAAG,qBAChC,CAAET,KAAF,EAASC,UAAU,GAAG,KAAtB,KACCC,MAAM,CAACC,MAAP,CAAeH,KAAK,CAACU,cAArB,EAAsCL,MAAtC,CAAgDM,MAAF,IAAc;AAC3D,QAAMJ,YAAY,GACjBI,MAAM,CAACH,OAAP,IAAkBG,MAAM,CAACH,OAAP,KAAmBR,KAAK,CAACQ,OAD5C;AAEA,SAAOP,UAAU,GAAGM,YAAH,GAAkB,CAAEA,YAArC;AACA,CAJD,CAF+B,EAO9BP,KAAF,IAAa,CAAEA,KAAK,CAACU,cAAR,EAAwBV,KAAK,CAACQ,OAA9B,CAPmB,CAA1B;;;AAUA,SAASI,MAAT,CAAiBZ,KAAjB,EAAyB;AAC/B,SAAOA,KAAK,CAACY,MAAb;AACA;;AAEM,SAASC,UAAT,CAAqBb,KAArB,EAA6B;AACnC,SAAOA,KAAK,CAACQ,OAAb;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\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\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\nexport function isOpen( state ) {\n\treturn state.isOpen;\n}\n\nexport function getContext( state ) {\n\treturn state.context;\n}\n"]}
|
|
@@ -20,16 +20,15 @@ import { Icon } from '@wordpress/icons';
|
|
|
20
20
|
|
|
21
21
|
import { store as commandsStore } from '../store';
|
|
22
22
|
|
|
23
|
-
function CommandMenuLoader(
|
|
23
|
+
function CommandMenuLoader({
|
|
24
|
+
name,
|
|
25
|
+
search,
|
|
26
|
+
hook,
|
|
27
|
+
setLoader,
|
|
28
|
+
close
|
|
29
|
+
}) {
|
|
24
30
|
var _hook;
|
|
25
31
|
|
|
26
|
-
let {
|
|
27
|
-
name,
|
|
28
|
-
search,
|
|
29
|
-
hook,
|
|
30
|
-
setLoader,
|
|
31
|
-
close
|
|
32
|
-
} = _ref;
|
|
33
32
|
const {
|
|
34
33
|
isLoading,
|
|
35
34
|
commands = []
|
|
@@ -39,30 +38,38 @@ function CommandMenuLoader(_ref) {
|
|
|
39
38
|
useEffect(() => {
|
|
40
39
|
setLoader(name, isLoading);
|
|
41
40
|
}, [setLoader, name, isLoading]);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
|
|
42
|
+
if (!commands.length) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return createElement(Fragment, null, createElement(Command.List, null, commands.map(command => {
|
|
47
|
+
var _command$searchLabel;
|
|
48
|
+
|
|
49
|
+
return createElement(Command.Item, {
|
|
50
|
+
key: command.name,
|
|
51
|
+
value: (_command$searchLabel = command.searchLabel) !== null && _command$searchLabel !== void 0 ? _command$searchLabel : command.label,
|
|
52
|
+
onSelect: () => command.callback({
|
|
53
|
+
close
|
|
54
|
+
})
|
|
55
|
+
}, createElement(HStack, {
|
|
56
|
+
alignment: "left",
|
|
57
|
+
className: "commands-command-menu__item"
|
|
58
|
+
}, createElement(Icon, {
|
|
59
|
+
icon: command.icon
|
|
60
|
+
}), createElement("span", null, createElement(TextHighlight, {
|
|
61
|
+
text: command.label,
|
|
62
|
+
highlight: search
|
|
63
|
+
}))));
|
|
64
|
+
})));
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
export function CommandMenuLoaderWrapper(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
} = _ref2;
|
|
67
|
+
export function CommandMenuLoaderWrapper({
|
|
68
|
+
hook,
|
|
69
|
+
search,
|
|
70
|
+
setLoader,
|
|
71
|
+
close
|
|
72
|
+
}) {
|
|
66
73
|
// The "hook" prop is actually a custom React hook
|
|
67
74
|
// so to avoid breaking the rules of hooks
|
|
68
75
|
// the CommandMenuLoaderWrapper component need to be
|
|
@@ -84,13 +91,12 @@ export function CommandMenuLoaderWrapper(_ref2) {
|
|
|
84
91
|
close: close
|
|
85
92
|
});
|
|
86
93
|
}
|
|
87
|
-
export function CommandMenuGroup(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} = _ref3;
|
|
94
|
+
export function CommandMenuGroup({
|
|
95
|
+
isContextual,
|
|
96
|
+
search,
|
|
97
|
+
setLoader,
|
|
98
|
+
close
|
|
99
|
+
}) {
|
|
94
100
|
const {
|
|
95
101
|
commands,
|
|
96
102
|
loaders
|
|
@@ -100,25 +106,34 @@ export function CommandMenuGroup(_ref3) {
|
|
|
100
106
|
getCommandLoaders
|
|
101
107
|
} = select(commandsStore);
|
|
102
108
|
return {
|
|
103
|
-
commands: getCommands(
|
|
104
|
-
loaders: getCommandLoaders(
|
|
109
|
+
commands: getCommands(isContextual),
|
|
110
|
+
loaders: getCommandLoaders(isContextual)
|
|
105
111
|
};
|
|
106
|
-
}, [
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
112
|
+
}, [isContextual]);
|
|
113
|
+
|
|
114
|
+
if (!commands.length && !loaders.length) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return createElement(Command.Group, null, commands.map(command => {
|
|
119
|
+
var _command$searchLabel2;
|
|
120
|
+
|
|
121
|
+
return createElement(Command.Item, {
|
|
122
|
+
key: command.name,
|
|
123
|
+
value: (_command$searchLabel2 = command.searchLabel) !== null && _command$searchLabel2 !== void 0 ? _command$searchLabel2 : command.label,
|
|
124
|
+
onSelect: () => command.callback({
|
|
125
|
+
close
|
|
126
|
+
})
|
|
127
|
+
}, createElement(HStack, {
|
|
128
|
+
alignment: "left",
|
|
129
|
+
className: "commands-command-menu__item"
|
|
130
|
+
}, createElement(Icon, {
|
|
131
|
+
icon: command.icon
|
|
132
|
+
}), createElement("span", null, createElement(TextHighlight, {
|
|
133
|
+
text: command.label,
|
|
134
|
+
highlight: search
|
|
135
|
+
}))));
|
|
136
|
+
}), loaders.map(loader => createElement(CommandMenuLoaderWrapper, {
|
|
122
137
|
key: loader.name,
|
|
123
138
|
hook: loader.hook,
|
|
124
139
|
search: search,
|
|
@@ -131,19 +146,7 @@ export function CommandMenu() {
|
|
|
131
146
|
registerShortcut
|
|
132
147
|
} = useDispatch(keyboardShortcutsStore);
|
|
133
148
|
const [search, setSearch] = useState('');
|
|
134
|
-
const
|
|
135
|
-
groups,
|
|
136
|
-
isOpen
|
|
137
|
-
} = useSelect(select => {
|
|
138
|
-
const {
|
|
139
|
-
getGroups,
|
|
140
|
-
isOpen: _isOpen
|
|
141
|
-
} = select(commandsStore);
|
|
142
|
-
return {
|
|
143
|
-
groups: getGroups(),
|
|
144
|
-
isOpen: _isOpen()
|
|
145
|
-
};
|
|
146
|
-
}, []);
|
|
149
|
+
const isOpen = useSelect(select => select(commandsStore).isOpen(), []);
|
|
147
150
|
const {
|
|
148
151
|
open,
|
|
149
152
|
close
|
|
@@ -209,12 +212,15 @@ export function CommandMenu() {
|
|
|
209
212
|
value: search,
|
|
210
213
|
onValueChange: setSearch,
|
|
211
214
|
placeholder: __('Type a command or search')
|
|
212
|
-
})),
|
|
213
|
-
|
|
214
|
-
|
|
215
|
+
})), createElement(Command.List, null, search && !isLoading && createElement(Command.Empty, null, __('No results found.')), createElement(CommandMenuGroup, {
|
|
216
|
+
search: search,
|
|
217
|
+
setLoader: setLoader,
|
|
218
|
+
close: closeAndReset,
|
|
219
|
+
isContextual: true
|
|
220
|
+
}), search && createElement(CommandMenuGroup, {
|
|
215
221
|
search: search,
|
|
216
222
|
setLoader: setLoader,
|
|
217
223
|
close: closeAndReset
|
|
218
|
-
})))))
|
|
224
|
+
})))));
|
|
219
225
|
}
|
|
220
226
|
//# sourceMappingURL=command-menu.js.map
|