@wordpress/commands 0.2.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 +7 -0
- package/LICENSE.md +788 -0
- package/README.md +35 -0
- package/build/components/command-menu.js +213 -0
- package/build/components/command-menu.js.map +1 -0
- package/build/hooks/use-command-loader.js +48 -0
- package/build/hooks/use-command-loader.js.map +1 -0
- package/build/hooks/use-command.js +48 -0
- package/build/hooks/use-command.js.map +1 -0
- package/build/index.js +22 -0
- package/build/index.js.map +1 -0
- package/build/private-apis.js +35 -0
- package/build/private-apis.js.map +1 -0
- package/build/store/actions.js +116 -0
- package/build/store/actions.js.map +1 -0
- package/build/store/index.js +45 -0
- package/build/store/index.js.map +1 -0
- package/build/store/reducer.js +99 -0
- package/build/store/reducer.js.map +1 -0
- package/build/store/selectors.js +33 -0
- package/build/store/selectors.js.map +1 -0
- package/build-module/components/command-menu.js +198 -0
- package/build-module/components/command-menu.js.map +1 -0
- package/build-module/hooks/use-command-loader.js +38 -0
- package/build-module/hooks/use-command-loader.js.map +1 -0
- package/build-module/hooks/use-command.js +38 -0
- package/build-module/hooks/use-command.js.map +1 -0
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -0
- package/build-module/private-apis.js +20 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/store/actions.js +103 -0
- package/build-module/store/actions.js.map +1 -0
- package/build-module/store/index.js +27 -0
- package/build-module/store/index.js.map +1 -0
- package/build-module/store/reducer.js +90 -0
- package/build-module/store/reducer.js.map +1 -0
- package/build-module/store/selectors.js +21 -0
- package/build-module/store/selectors.js.map +1 -0
- package/build-style/style-rtl.css +264 -0
- package/build-style/style.css +264 -0
- package/package.json +47 -0
- package/src/components/command-menu.js +216 -0
- package/src/components/style.scss +179 -0
- package/src/hooks/use-command-loader.js +30 -0
- package/src/hooks/use-command.js +41 -0
- package/src/index.js +2 -0
- package/src/private-apis.js +22 -0
- package/src/store/actions.js +91 -0
- package/src/store/index.js +28 -0
- package/src/store/reducer.js +81 -0
- package/src/store/selectors.js +29 -0
- package/src/style.scss +1 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _data = require("@wordpress/data");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reducer returning the registered commands
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} state Current state.
|
|
18
|
+
* @param {Object} action Dispatched action.
|
|
19
|
+
*
|
|
20
|
+
* @return {Object} Updated state.
|
|
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
|
+
|
|
26
|
+
switch (action.type) {
|
|
27
|
+
case 'REGISTER_COMMAND':
|
|
28
|
+
return { ...state,
|
|
29
|
+
[action.group]: { ...state[action.group],
|
|
30
|
+
[action.name]: {
|
|
31
|
+
name: action.name,
|
|
32
|
+
label: action.label,
|
|
33
|
+
group: action.group,
|
|
34
|
+
callback: action.callback
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
case 'UNREGISTER_COMMAND':
|
|
40
|
+
{
|
|
41
|
+
const {
|
|
42
|
+
[action.name]: _,
|
|
43
|
+
...remainingState
|
|
44
|
+
} = state === null || state === void 0 ? void 0 : state[action.group];
|
|
45
|
+
return { ...state,
|
|
46
|
+
[action.group]: remainingState
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reducer returning the command loaders
|
|
55
|
+
*
|
|
56
|
+
* @param {Object} state Current state.
|
|
57
|
+
* @param {Object} action Dispatched action.
|
|
58
|
+
*
|
|
59
|
+
* @return {Object} Updated state.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function commandLoaders() {
|
|
64
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
66
|
+
|
|
67
|
+
switch (action.type) {
|
|
68
|
+
case 'REGISTER_COMMAND_LOADER':
|
|
69
|
+
return { ...state,
|
|
70
|
+
[action.group]: { ...state[action.group],
|
|
71
|
+
[action.name]: {
|
|
72
|
+
name: action.name,
|
|
73
|
+
hook: action.hook
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
case 'UNREGISTER_COMMAND_LOADER':
|
|
79
|
+
{
|
|
80
|
+
const {
|
|
81
|
+
[action.name]: _,
|
|
82
|
+
...remainingState
|
|
83
|
+
} = state === null || state === void 0 ? void 0 : state[action.group];
|
|
84
|
+
return { ...state,
|
|
85
|
+
[action.group]: remainingState
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return state;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const reducer = (0, _data.combineReducers)({
|
|
94
|
+
commands,
|
|
95
|
+
commandLoaders
|
|
96
|
+
});
|
|
97
|
+
var _default = reducer;
|
|
98
|
+
exports.default = _default;
|
|
99
|
+
//# sourceMappingURL=reducer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/reducer.js"],"names":["commands","state","action","type","group","name","label","callback","_","remainingState","commandLoaders","hook","reducer"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,GAAwC;AA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AE,WAAET,MAAM,CAACG,IAAT,GAAiBG,CAAnB;AAAsB,aAAGC;AAAzB,YACLR,KADK,aACLA,KADK,uBACLA,KAAK,CAAIC,MAAM,CAACE,KAAX,CADN;AAEA,eAAO,EACN,GAAGH,KADG;AAEN,WAAEC,MAAM,CAACE,KAAT,GAAkBK;AAFZ,SAAP;AAIA;AAnBF;;AAsBA,SAAOR,KAAP;AACA;;AAED,MAAMW,OAAO,GAAG,2BAAiB;AAChCZ,EAAAA,QADgC;AAEhCU,EAAAA;AAFgC,CAAjB,CAAhB;eAKeE,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.group ]: {\n\t\t\t\t\t...state[ action.group ],\n\t\t\t\t\t[ action.name ]: {\n\t\t\t\t\t\tname: action.name,\n\t\t\t\t\t\tlabel: action.label,\n\t\t\t\t\t\tgroup: action.group,\n\t\t\t\t\t\tcallback: action.callback,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } =\n\t\t\t\tstate?.[ action.group ];\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.group ]: remainingState,\n\t\t\t};\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.group ]: {\n\t\t\t\t\t...state[ action.group ],\n\t\t\t\t\t[ action.name ]: {\n\t\t\t\t\t\tname: action.name,\n\t\t\t\t\t\thook: action.hook,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\tcase 'UNREGISTER_COMMAND_LOADER': {\n\t\t\tconst { [ action.name ]: _, ...remainingState } =\n\t\t\t\tstate?.[ action.group ];\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.group ]: remainingState,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n\nconst reducer = combineReducers( {\n\tcommands,\n\tcommandLoaders,\n} );\n\nexport default reducer;\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getGroups = exports.getCommands = exports.getCommandLoaders = void 0;
|
|
9
|
+
|
|
10
|
+
var _rememo = _interopRequireDefault(require("rememo"));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* External dependencies
|
|
14
|
+
*/
|
|
15
|
+
function unique(array) {
|
|
16
|
+
return array.filter((value, index, current) => current.indexOf(value) === index);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const getGroups = (0, _rememo.default)(state => unique(Object.keys(state.commands).concat(Object.keys(state.commandLoaders))), state => [state.commands, state.commandLoaders]);
|
|
20
|
+
exports.getGroups = getGroups;
|
|
21
|
+
const getCommands = (0, _rememo.default)((state, group) => {
|
|
22
|
+
var _state$commands$group;
|
|
23
|
+
|
|
24
|
+
return Object.values((_state$commands$group = state.commands[group]) !== null && _state$commands$group !== void 0 ? _state$commands$group : {});
|
|
25
|
+
}, (state, group) => [state.commands[group]]);
|
|
26
|
+
exports.getCommands = getCommands;
|
|
27
|
+
const getCommandLoaders = (0, _rememo.default)((state, group) => {
|
|
28
|
+
var _state$commandLoaders;
|
|
29
|
+
|
|
30
|
+
return Object.values((_state$commandLoaders = state.commandLoaders[group]) !== null && _state$commandLoaders !== void 0 ? _state$commandLoaders : {});
|
|
31
|
+
}, (state, group) => [state.commandLoaders[group]]);
|
|
32
|
+
exports.getCommandLoaders = getCommandLoaders;
|
|
33
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/selectors.js"],"names":["unique","array","filter","value","index","current","indexOf","getGroups","state","Object","keys","commands","concat","commandLoaders","getCommands","group","values","getCommandLoaders"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,SAASA,MAAT,CAAiBC,KAAjB,EAAyB;AACxB,SAAOA,KAAK,CAACC,MAAN,CACN,CAAEC,KAAF,EAASC,KAAT,EAAgBC,OAAhB,KAA6BA,OAAO,CAACC,OAAR,CAAiBH,KAAjB,MAA6BC,KADpD,CAAP;AAGA;;AAEM,MAAMG,SAAS,GAAG,qBACtBC,KAAF,IACCR,MAAM,CACLS,MAAM,CAACC,IAAP,CAAaF,KAAK,CAACG,QAAnB,EAA8BC,MAA9B,CACCH,MAAM,CAACC,IAAP,CAAaF,KAAK,CAACK,cAAnB,CADD,CADK,CAFiB,EAOtBL,KAAF,IAAa,CAAEA,KAAK,CAACG,QAAR,EAAkBH,KAAK,CAACK,cAAxB,CAPW,CAAlB;;AASA,MAAMC,WAAW,GAAG,qBAC1B,CAAEN,KAAF,EAASO,KAAT;AAAA;;AAAA,SAAoBN,MAAM,CAACO,MAAP,0BAAeR,KAAK,CAACG,QAAN,CAAgBI,KAAhB,CAAf,yEAA0C,EAA1C,CAApB;AAAA,CAD0B,EAE1B,CAAEP,KAAF,EAASO,KAAT,KAAoB,CAAEP,KAAK,CAACG,QAAN,CAAgBI,KAAhB,CAAF,CAFM,CAApB;;AAKA,MAAME,iBAAiB,GAAG,qBAChC,CAAET,KAAF,EAASO,KAAT;AAAA;;AAAA,SAAoBN,MAAM,CAACO,MAAP,0BAAeR,KAAK,CAACK,cAAN,CAAsBE,KAAtB,CAAf,yEAAgD,EAAhD,CAApB;AAAA,CADgC,EAEhC,CAAEP,KAAF,EAASO,KAAT,KAAoB,CAAEP,KAAK,CAACK,cAAN,CAAsBE,KAAtB,CAAF,CAFY,CAA1B","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\n\nfunction unique( array ) {\n\treturn array.filter(\n\t\t( value, index, current ) => current.indexOf( value ) === index\n\t);\n}\n\nexport const getGroups = createSelector(\n\t( state ) =>\n\t\tunique(\n\t\t\tObject.keys( state.commands ).concat(\n\t\t\t\tObject.keys( state.commandLoaders )\n\t\t\t)\n\t\t),\n\t( state ) => [ state.commands, state.commandLoaders ]\n);\nexport const getCommands = createSelector(\n\t( state, group ) => Object.values( state.commands[ group ] ?? {} ),\n\t( state, group ) => [ state.commands[ group ] ]\n);\n\nexport const getCommandLoaders = createSelector(\n\t( state, group ) => Object.values( state.commandLoaders[ group ] ?? {} ),\n\t( state, group ) => [ state.commandLoaders[ group ] ]\n);\n"]}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { Command } from 'cmdk';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
12
|
+
import { useState, useEffect, useRef, useCallback } from '@wordpress/element';
|
|
13
|
+
import { __ } from '@wordpress/i18n';
|
|
14
|
+
import { Modal, TextHighlight } from '@wordpress/components';
|
|
15
|
+
import { store as keyboardShortcutsStore, useShortcut } from '@wordpress/keyboard-shortcuts';
|
|
16
|
+
/**
|
|
17
|
+
* Internal dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { store as commandsStore } from '../store';
|
|
21
|
+
|
|
22
|
+
function CommandMenuLoader(_ref) {
|
|
23
|
+
var _hook;
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
name,
|
|
27
|
+
search,
|
|
28
|
+
hook,
|
|
29
|
+
setLoader,
|
|
30
|
+
close
|
|
31
|
+
} = _ref;
|
|
32
|
+
const {
|
|
33
|
+
isLoading,
|
|
34
|
+
commands = []
|
|
35
|
+
} = (_hook = hook({
|
|
36
|
+
search
|
|
37
|
+
})) !== null && _hook !== void 0 ? _hook : {};
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setLoader(name, isLoading);
|
|
40
|
+
}, [setLoader, name, isLoading]);
|
|
41
|
+
return createElement(Fragment, null, createElement(Command.List, null, isLoading && createElement(Command.Loading, null, __('Searching…')), commands.map(command => createElement(Command.Item, {
|
|
42
|
+
key: command.name,
|
|
43
|
+
value: command.name,
|
|
44
|
+
onSelect: () => command.callback({
|
|
45
|
+
close
|
|
46
|
+
})
|
|
47
|
+
}, createElement("span", {
|
|
48
|
+
className: "commands-command-menu__item"
|
|
49
|
+
}, createElement(TextHighlight, {
|
|
50
|
+
text: command.label,
|
|
51
|
+
highlight: search
|
|
52
|
+
}))))));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function CommandMenuLoaderWrapper(_ref2) {
|
|
56
|
+
let {
|
|
57
|
+
hook,
|
|
58
|
+
search,
|
|
59
|
+
setLoader,
|
|
60
|
+
close
|
|
61
|
+
} = _ref2;
|
|
62
|
+
// The "hook" prop is actually a custom React hook
|
|
63
|
+
// so to avoid breaking the rules of hooks
|
|
64
|
+
// the CommandMenuLoaderWrapper component need to be
|
|
65
|
+
// remounted on each hook prop change
|
|
66
|
+
// We use the key state to make sure we do that properly.
|
|
67
|
+
const currentLoader = useRef(hook);
|
|
68
|
+
const [key, setKey] = useState(0);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (currentLoader.current !== hook) {
|
|
71
|
+
currentLoader.current = hook;
|
|
72
|
+
setKey(prevKey => prevKey + 1);
|
|
73
|
+
}
|
|
74
|
+
}, [hook]);
|
|
75
|
+
return createElement(CommandMenuLoader, {
|
|
76
|
+
key: key,
|
|
77
|
+
hook: currentLoader.current,
|
|
78
|
+
search: search,
|
|
79
|
+
setLoader: setLoader,
|
|
80
|
+
close: close
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
export function CommandMenuGroup(_ref3) {
|
|
84
|
+
let {
|
|
85
|
+
group,
|
|
86
|
+
search,
|
|
87
|
+
setLoader,
|
|
88
|
+
close
|
|
89
|
+
} = _ref3;
|
|
90
|
+
const {
|
|
91
|
+
commands,
|
|
92
|
+
loaders
|
|
93
|
+
} = useSelect(select => {
|
|
94
|
+
const {
|
|
95
|
+
getCommands,
|
|
96
|
+
getCommandLoaders
|
|
97
|
+
} = select(commandsStore);
|
|
98
|
+
return {
|
|
99
|
+
commands: getCommands(group),
|
|
100
|
+
loaders: getCommandLoaders(group)
|
|
101
|
+
};
|
|
102
|
+
}, [group]);
|
|
103
|
+
return createElement(Command.Group, {
|
|
104
|
+
heading: group
|
|
105
|
+
}, commands.map(command => createElement(Command.Item, {
|
|
106
|
+
key: command.name,
|
|
107
|
+
value: command.name,
|
|
108
|
+
onSelect: () => command.callback({
|
|
109
|
+
close
|
|
110
|
+
})
|
|
111
|
+
}, createElement("span", {
|
|
112
|
+
className: "commands-command-menu__item"
|
|
113
|
+
}, createElement(TextHighlight, {
|
|
114
|
+
text: command.label,
|
|
115
|
+
highlight: search
|
|
116
|
+
})))), loaders.map(loader => createElement(CommandMenuLoaderWrapper, {
|
|
117
|
+
key: loader.name,
|
|
118
|
+
hook: loader.hook,
|
|
119
|
+
search: search,
|
|
120
|
+
setLoader: setLoader,
|
|
121
|
+
close: close
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
export function CommandMenu() {
|
|
125
|
+
const {
|
|
126
|
+
registerShortcut
|
|
127
|
+
} = useDispatch(keyboardShortcutsStore);
|
|
128
|
+
const [search, setSearch] = useState('');
|
|
129
|
+
const [open, setOpen] = useState(false);
|
|
130
|
+
const {
|
|
131
|
+
groups
|
|
132
|
+
} = useSelect(select => {
|
|
133
|
+
const {
|
|
134
|
+
getGroups
|
|
135
|
+
} = select(commandsStore);
|
|
136
|
+
return {
|
|
137
|
+
groups: getGroups()
|
|
138
|
+
};
|
|
139
|
+
}, []);
|
|
140
|
+
const [loaders, setLoaders] = useState({});
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
registerShortcut({
|
|
143
|
+
name: 'core/commands',
|
|
144
|
+
category: 'global',
|
|
145
|
+
description: __('Open the global command menu'),
|
|
146
|
+
keyCombination: {
|
|
147
|
+
modifier: 'primary',
|
|
148
|
+
character: 'k'
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}, [registerShortcut]);
|
|
152
|
+
useShortcut('core/commands', event => {
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
setOpen(prevOpen => !prevOpen);
|
|
155
|
+
}, {
|
|
156
|
+
bindGlobal: true
|
|
157
|
+
});
|
|
158
|
+
const setLoader = useCallback((name, value) => setLoaders(current => ({ ...current,
|
|
159
|
+
[name]: value
|
|
160
|
+
})), []);
|
|
161
|
+
|
|
162
|
+
const close = () => {
|
|
163
|
+
setSearch('');
|
|
164
|
+
setOpen(false);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
if (!open) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const isLoading = Object.values(loaders).some(Boolean);
|
|
172
|
+
return createElement(Modal, {
|
|
173
|
+
className: "commands-command-menu",
|
|
174
|
+
overlayClassName: "commands-command-menu__overlay",
|
|
175
|
+
onRequestClose: close,
|
|
176
|
+
__experimentalHideHeader: true
|
|
177
|
+
}, createElement("div", {
|
|
178
|
+
className: "commands-command-menu__container"
|
|
179
|
+
}, createElement(Command, {
|
|
180
|
+
label: __('Global Command Menu')
|
|
181
|
+
}, createElement("div", {
|
|
182
|
+
className: "commands-command-menu__header"
|
|
183
|
+
}, createElement(Command.Input, {
|
|
184
|
+
// The input should be focused when the modal is opened.
|
|
185
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
186
|
+
autoFocus: true,
|
|
187
|
+
value: search,
|
|
188
|
+
onValueChange: setSearch,
|
|
189
|
+
placeholder: __('Search for content and templates, or try commands like "Add…"')
|
|
190
|
+
})), createElement(Command.List, null, !isLoading && createElement(Command.Empty, null, __('No results found.')), groups.map(group => createElement(CommandMenuGroup, {
|
|
191
|
+
key: group,
|
|
192
|
+
group: group,
|
|
193
|
+
search: search,
|
|
194
|
+
setLoader: setLoader,
|
|
195
|
+
close: close
|
|
196
|
+
}))))));
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=command-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/components/command-menu.js"],"names":["Command","useSelect","useDispatch","useState","useEffect","useRef","useCallback","__","Modal","TextHighlight","store","keyboardShortcutsStore","useShortcut","commandsStore","CommandMenuLoader","name","search","hook","setLoader","close","isLoading","commands","map","command","callback","label","CommandMenuLoaderWrapper","currentLoader","key","setKey","current","prevKey","CommandMenuGroup","group","loaders","select","getCommands","getCommandLoaders","loader","CommandMenu","registerShortcut","setSearch","open","setOpen","groups","getGroups","setLoaders","category","description","keyCombination","modifier","character","event","preventDefault","prevOpen","bindGlobal","value","Object","values","some","Boolean"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,MAAxB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,QAAT,EAAmBC,SAAnB,EAA8BC,MAA9B,EAAsCC,WAAtC,QAAyD,oBAAzD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,EAAgBC,aAAhB,QAAqC,uBAArC;AACA,SACCC,KAAK,IAAIC,sBADV,EAECC,WAFD,QAGO,+BAHP;AAKA;AACA;AACA;;AACA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S,MAJT;AAKC,IAAA,aAAa,EAAGyB,SALjB;AAMC,IAAA,WAAW,EAAGlC,EAAE,CACf,+DADe;AANjB,IADD,CADD,EAaC,cAAC,OAAD,CAAS,IAAT,QACG,CAAEa,SAAF,IACD,cAAC,OAAD,CAAS,KAAT,QACGb,EAAE,CAAE,mBAAF,CADL,CAFF,EAMGqC,MAAM,CAACtB,GAAP,CAAcW,KAAF,IACb,cAAC,gBAAD;AACC,IAAA,GAAG,EAAGA,KADP;AAEC,IAAA,KAAK,EAAGA,KAFT;AAGC,IAAA,MAAM,EAAGjB,MAHV;AAIC,IAAA,SAAS,EAAGE,SAJb;AAKC,IAAA,KAAK,EAAGC;AALT,IADC,CANH,CAbD,CADD,CAND,CADD;AAyCA","sourcesContent":["/**\n * External dependencies\n */\nimport { Command } from 'cmdk';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useState, useEffect, useRef, useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Modal, TextHighlight } from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\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\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ isLoading && (\n\t\t\t\t\t<Command.Loading>{ __( 'Searching…' ) }</Command.Loading>\n\t\t\t\t) }\n\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.name }\n\t\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<span className=\"commands-command-menu__item\">\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</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( { group, 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( group ),\n\t\t\t\tloaders: getCommandLoaders( group ),\n\t\t\t};\n\t\t},\n\t\t[ group ]\n\t);\n\n\treturn (\n\t\t<Command.Group heading={ 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.name }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t>\n\t\t\t\t\t<span className=\"commands-command-menu__item\">\n\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</span>\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\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst [ open, setOpen ] = useState( false );\n\tconst { groups } = useSelect( ( select ) => {\n\t\tconst { getGroups } = select( commandsStore );\n\t\treturn {\n\t\t\tgroups: getGroups(),\n\t\t};\n\t}, [] );\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 global command menu' ),\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( event ) => {\n\t\t\tevent.preventDefault();\n\t\t\tsetOpen( ( prevOpen ) => ! prevOpen );\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 close = () => {\n\t\tsetSearch( '' );\n\t\tsetOpen( false );\n\t};\n\n\tif ( ! open ) {\n\t\treturn false;\n\t}\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={ close }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command label={ __( 'Global Command Menu' ) }>\n\t\t\t\t\t<div className=\"commands-command-menu__header\">\n\t\t\t\t\t\t<Command.Input\n\t\t\t\t\t\t\t// The input should be focused when the modal is opened.\n\t\t\t\t\t\t\t// eslint-disable-next-line jsx-a11y/no-autofocus\n\t\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\t\tvalue={ search }\n\t\t\t\t\t\t\tonValueChange={ setSearch }\n\t\t\t\t\t\t\tplaceholder={ __(\n\t\t\t\t\t\t\t\t'Search for content and templates, or try commands like \"Add…\"'\n\t\t\t\t\t\t\t) }\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{ ! 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{ groups.map( ( group ) => (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tkey={ group }\n\t\t\t\t\t\t\t\tgroup={ group }\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={ close }\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"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect } from '@wordpress/element';
|
|
5
|
+
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as commandsStore } from '../store';
|
|
11
|
+
/**
|
|
12
|
+
* Attach a command loader to the Global command menu.
|
|
13
|
+
*
|
|
14
|
+
* @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function useCommandLoader(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
name,
|
|
20
|
+
group,
|
|
21
|
+
hook
|
|
22
|
+
} = _ref;
|
|
23
|
+
const {
|
|
24
|
+
registerCommandLoader,
|
|
25
|
+
unregisterCommandLoader
|
|
26
|
+
} = useDispatch(commandsStore);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
registerCommandLoader({
|
|
29
|
+
name,
|
|
30
|
+
group,
|
|
31
|
+
hook
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
unregisterCommandLoader(name, group);
|
|
35
|
+
};
|
|
36
|
+
}, [name, group, hook, registerCommandLoader, unregisterCommandLoader]);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=use-command-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"names":["useEffect","useDispatch","store","commandsStore","useCommandLoader","name","group","hook","registerCommandLoader","unregisterCommandLoader"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,aAAlB,QAAuC,UAAvC;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,gBAAT,OAAmD;AAAA,MAAxB;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA;AAAf,GAAwB;AACjE,QAAM;AAAEC,IAAAA,qBAAF;AAAyBC,IAAAA;AAAzB,MACLR,WAAW,CAAEE,aAAF,CADZ;AAEAH,EAAAA,SAAS,CAAE,MAAM;AAChBQ,IAAAA,qBAAqB,CAAE;AACtBH,MAAAA,IADsB;AAEtBC,MAAAA,KAFsB;AAGtBC,MAAAA;AAHsB,KAAF,CAArB;AAKA,WAAO,MAAM;AACZE,MAAAA,uBAAuB,CAAEJ,IAAF,EAAQC,KAAR,CAAvB;AACA,KAFD;AAGA,GATQ,EASN,CAAED,IAAF,EAAQC,KAAR,EAAeC,IAAf,EAAqBC,qBAArB,EAA4CC,uBAA5C,CATM,CAAT;AAUA","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 Global command menu.\n *\n * @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.\n */\nexport default function useCommandLoader( { name, group, hook } ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname,\n\t\t\tgroup,\n\t\t\thook,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( name, group );\n\t\t};\n\t}, [ name, group, hook, registerCommandLoader, unregisterCommandLoader ] );\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useRef } from '@wordpress/element';
|
|
5
|
+
import { useDispatch } from '@wordpress/data';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { store as commandsStore } from '../store';
|
|
11
|
+
/**
|
|
12
|
+
* Attach a command to the Global command menu.
|
|
13
|
+
*
|
|
14
|
+
* @param {import('../store/actions').WPCommandConfig} command command config.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export default function useCommand(command) {
|
|
18
|
+
const {
|
|
19
|
+
registerCommand,
|
|
20
|
+
unregisterCommand
|
|
21
|
+
} = useDispatch(commandsStore);
|
|
22
|
+
const currentCallback = useRef(command.callback);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
currentCallback.current = command.callback;
|
|
25
|
+
}, [command.callback]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
registerCommand({
|
|
28
|
+
name: command.name,
|
|
29
|
+
group: command.group,
|
|
30
|
+
label: command.label,
|
|
31
|
+
callback: currentCallback.current
|
|
32
|
+
});
|
|
33
|
+
return () => {
|
|
34
|
+
unregisterCommand(command.name, command.group);
|
|
35
|
+
};
|
|
36
|
+
}, [command.name, command.label, command.group, registerCommand, unregisterCommand]);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=use-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command.js"],"names":["useEffect","useRef","useDispatch","store","commandsStore","useCommand","command","registerCommand","unregisterCommand","currentCallback","callback","current","name","group","label"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,oBAAlC;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,aAAlB,QAAuC,UAAvC;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,UAAT,CAAqBC,OAArB,EAA+B;AAC7C,QAAM;AAAEC,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAyCN,WAAW,CAAEE,aAAF,CAA1D;AACA,QAAMK,eAAe,GAAGR,MAAM,CAAEK,OAAO,CAACI,QAAV,CAA9B;AACAV,EAAAA,SAAS,CAAE,MAAM;AAChBS,IAAAA,eAAe,CAACE,OAAhB,GAA0BL,OAAO,CAACI,QAAlC;AACA,GAFQ,EAEN,CAAEJ,OAAO,CAACI,QAAV,CAFM,CAAT;AAIAV,EAAAA,SAAS,CAAE,MAAM;AAChBO,IAAAA,eAAe,CAAE;AAChBK,MAAAA,IAAI,EAAEN,OAAO,CAACM,IADE;AAEhBC,MAAAA,KAAK,EAAEP,OAAO,CAACO,KAFC;AAGhBC,MAAAA,KAAK,EAAER,OAAO,CAACQ,KAHC;AAIhBJ,MAAAA,QAAQ,EAAED,eAAe,CAACE;AAJV,KAAF,CAAf;AAMA,WAAO,MAAM;AACZH,MAAAA,iBAAiB,CAAEF,OAAO,CAACM,IAAV,EAAgBN,OAAO,CAACO,KAAxB,CAAjB;AACA,KAFD;AAGA,GAVQ,EAUN,CACFP,OAAO,CAACM,IADN,EAEFN,OAAO,CAACQ,KAFN,EAGFR,OAAO,CAACO,KAHN,EAIFN,eAJE,EAKFC,iBALE,CAVM,CAAT;AAiBA","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 Global command menu.\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\tgroup: command.group,\n\t\t\tlabel: command.label,\n\t\t\tcallback: currentCallback.current,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name, command.group );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.group,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/index.js"],"names":["CommandMenu","privateApis"],"mappings":"AAAA,SAASA,WAAT,QAA4B,2BAA5B;AACA,SAASC,WAAT,QAA4B,gBAA5B","sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { default as useCommand } from './hooks/use-command';
|
|
10
|
+
import { default as useCommandLoader } from './hooks/use-command-loader';
|
|
11
|
+
export const {
|
|
12
|
+
lock,
|
|
13
|
+
unlock
|
|
14
|
+
} = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/commands');
|
|
15
|
+
export const privateApis = {};
|
|
16
|
+
lock(privateApis, {
|
|
17
|
+
useCommand,
|
|
18
|
+
useCommandLoader
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/private-apis.js"],"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","default","useCommand","useCommandLoader","lock","unlock","privateApis"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAT,QAAiE,yBAAjE;AAEA;AACA;AACA;;AACA,SAASC,OAAO,IAAIC,UAApB,QAAsC,qBAAtC;AACA,SAASD,OAAO,IAAIE,gBAApB,QAA4C,4BAA5C;AAEA,OAAO,MAAM;AAAEC,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZL,gDAAgD,CAC/C,8GAD+C,EAE/C,qBAF+C,CAD1C;AAMP,OAAO,MAAMM,WAAW,GAAG,EAApB;AACPF,IAAI,CAAEE,WAAF,EAAe;AAClBJ,EAAAA,UADkB;AAElBC,EAAAA;AAFkB,CAAf,CAAJ","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\n/**\n * Internal dependencies\n */\nimport { default as useCommand } from './hooks/use-command';\nimport { default as useCommandLoader } from './hooks/use-command-loader';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/commands'\n\t);\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommand,\n\tuseCommandLoader,\n} );\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration of a registered keyboard shortcut.
|
|
5
|
+
*
|
|
6
|
+
* @typedef {Object} WPCommandConfig
|
|
7
|
+
*
|
|
8
|
+
* @property {string} name Command name.
|
|
9
|
+
* @property {string} label Command label.
|
|
10
|
+
* @property {string=} group Command group.
|
|
11
|
+
* @property {Function} callback Command callback.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Command loader config.
|
|
20
|
+
*
|
|
21
|
+
* @typedef {Object} WPCommandLoaderConfig
|
|
22
|
+
*
|
|
23
|
+
* @property {string} name Command loader name.
|
|
24
|
+
* @property {string=} group Command loader group.
|
|
25
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns an action object used to register a new command.
|
|
30
|
+
*
|
|
31
|
+
* @param {WPCommandConfig} config Command config.
|
|
32
|
+
*
|
|
33
|
+
* @return {Object} action.
|
|
34
|
+
*/
|
|
35
|
+
export function registerCommand(_ref) {
|
|
36
|
+
let {
|
|
37
|
+
name,
|
|
38
|
+
label,
|
|
39
|
+
callback,
|
|
40
|
+
group = ''
|
|
41
|
+
} = _ref;
|
|
42
|
+
return {
|
|
43
|
+
type: 'REGISTER_COMMAND',
|
|
44
|
+
name,
|
|
45
|
+
label,
|
|
46
|
+
callback,
|
|
47
|
+
group
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns an action object used to unregister a command.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} name Command name.
|
|
54
|
+
* @param {string} group Command group.
|
|
55
|
+
*
|
|
56
|
+
* @return {Object} action.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export function unregisterCommand(name, group) {
|
|
60
|
+
return {
|
|
61
|
+
type: 'UNREGISTER_COMMAND',
|
|
62
|
+
name,
|
|
63
|
+
group
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Register command loader.
|
|
68
|
+
*
|
|
69
|
+
* @param {WPCommandLoaderConfig} config Command loader config.
|
|
70
|
+
*
|
|
71
|
+
* @return {Object} action.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
export function registerCommandLoader(_ref2) {
|
|
75
|
+
let {
|
|
76
|
+
name,
|
|
77
|
+
group = '',
|
|
78
|
+
hook
|
|
79
|
+
} = _ref2;
|
|
80
|
+
return {
|
|
81
|
+
type: 'REGISTER_COMMAND_LOADER',
|
|
82
|
+
name,
|
|
83
|
+
group,
|
|
84
|
+
hook
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Unregister command loader hook.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} name Command loader name.
|
|
91
|
+
* @param {string} group Command loader group.
|
|
92
|
+
*
|
|
93
|
+
* @return {Object} action.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export function unregisterCommandLoader(name, group) {
|
|
97
|
+
return {
|
|
98
|
+
type: 'UNREGISTER_COMMAND_LOADER',
|
|
99
|
+
name,
|
|
100
|
+
group
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/actions.js"],"names":["registerCommand","name","label","callback","group","type","unregisterCommand","registerCommandLoader","hook","unregisterCommandLoader"],"mappings":"AAAA;;AAEA;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;AACA,OAAO,SAASA,eAAT,OAAkE;AAAA,MAAxC;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA,QAAf;AAAyBC,IAAAA,KAAK,GAAG;AAAjC,GAAwC;AACxE,SAAO;AACNC,IAAAA,IAAI,EAAE,kBADA;AAENJ,IAAAA,IAFM;AAGNC,IAAAA,KAHM;AAINC,IAAAA,QAJM;AAKNC,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,iBAAT,CAA4BL,IAA5B,EAAkCG,KAAlC,EAA0C;AAChD,SAAO;AACNC,IAAAA,IAAI,EAAE,oBADA;AAENJ,IAAAA,IAFM;AAGNG,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,qBAAT,QAA6D;AAAA,MAA7B;AAAEN,IAAAA,IAAF;AAAQG,IAAAA,KAAK,GAAG,EAAhB;AAAoBI,IAAAA;AAApB,GAA6B;AACnE,SAAO;AACNH,IAAAA,IAAI,EAAE,yBADA;AAENJ,IAAAA,IAFM;AAGNG,IAAAA,KAHM;AAINI,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uBAAT,CAAkCR,IAAlC,EAAwCG,KAAxC,EAAgD;AACtD,SAAO;AACNC,IAAAA,IAAI,EAAE,2BADA;AAENJ,IAAAA,IAFM;AAGNG,IAAAA;AAHM,GAAP;AAKA","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=} group Command group.\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=} group Command loader group.\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( { name, label, callback, group = '' } ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND',\n\t\tname,\n\t\tlabel,\n\t\tcallback,\n\t\tgroup,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a command.\n *\n * @param {string} name Command name.\n * @param {string} group Command group.\n *\n * @return {Object} action.\n */\nexport function unregisterCommand( name, group ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND',\n\t\tname,\n\t\tgroup,\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( { name, group = '', hook } ) {\n\treturn {\n\t\ttype: 'REGISTER_COMMAND_LOADER',\n\t\tname,\n\t\tgroup,\n\t\thook,\n\t};\n}\n\n/**\n * Unregister command loader hook.\n *\n * @param {string} name Command loader name.\n * @param {string} group Command loader group.\n *\n * @return {Object} action.\n */\nexport function unregisterCommandLoader( name, group ) {\n\treturn {\n\t\ttype: 'UNREGISTER_COMMAND_LOADER',\n\t\tname,\n\t\tgroup,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import reducer from './reducer';
|
|
10
|
+
import * as actions from './actions';
|
|
11
|
+
import * as selectors from './selectors';
|
|
12
|
+
const STORE_NAME = 'core/commands';
|
|
13
|
+
/**
|
|
14
|
+
* Store definition for the commands namespace.
|
|
15
|
+
*
|
|
16
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
17
|
+
*
|
|
18
|
+
* @type {Object}
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const store = createReduxStore(STORE_NAME, {
|
|
22
|
+
reducer,
|
|
23
|
+
actions,
|
|
24
|
+
selectors
|
|
25
|
+
});
|
|
26
|
+
register(store);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/index.js"],"names":["createReduxStore","register","reducer","actions","selectors","STORE_NAME","store"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,OAAZ,MAAyB,WAAzB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AAEA,MAAMC,UAAU,GAAG,eAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,KAAK,GAAGN,gBAAgB,CAAEK,UAAF,EAAc;AAClDH,EAAAA,OADkD;AAElDC,EAAAA,OAFkD;AAGlDC,EAAAA;AAHkD,CAAd,CAA9B;AAMPH,QAAQ,CAAEK,KAAF,CAAR","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';\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 );\n"]}
|