@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
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Commands
|
|
2
|
+
|
|
3
|
+
Commands is a generic package that allows registering and modifying commands to be displayed using the commands menu (Also called cmd+k).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the module
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @wordpress/commands --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
<!-- START TOKEN(Autogenerated API docs) -->
|
|
18
|
+
|
|
19
|
+
### CommandMenu
|
|
20
|
+
|
|
21
|
+
Undocumented declaration.
|
|
22
|
+
|
|
23
|
+
### privateApis
|
|
24
|
+
|
|
25
|
+
Undocumented declaration.
|
|
26
|
+
|
|
27
|
+
<!-- END TOKEN(Autogenerated API docs) -->
|
|
28
|
+
|
|
29
|
+
## Contributing to this package
|
|
30
|
+
|
|
31
|
+
This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.
|
|
32
|
+
|
|
33
|
+
To find out more about contributing to this package or Gutenberg as a whole, please read the project's main [contributor guide](https://github.com/WordPress/gutenberg/tree/HEAD/CONTRIBUTING.md).
|
|
34
|
+
|
|
35
|
+
<br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CommandMenu = CommandMenu;
|
|
7
|
+
exports.CommandMenuGroup = CommandMenuGroup;
|
|
8
|
+
exports.CommandMenuLoaderWrapper = CommandMenuLoaderWrapper;
|
|
9
|
+
|
|
10
|
+
var _element = require("@wordpress/element");
|
|
11
|
+
|
|
12
|
+
var _cmdk = require("cmdk");
|
|
13
|
+
|
|
14
|
+
var _data = require("@wordpress/data");
|
|
15
|
+
|
|
16
|
+
var _i18n = require("@wordpress/i18n");
|
|
17
|
+
|
|
18
|
+
var _components = require("@wordpress/components");
|
|
19
|
+
|
|
20
|
+
var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
|
|
21
|
+
|
|
22
|
+
var _store = require("../store");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* External dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* WordPress dependencies
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Internal dependencies
|
|
34
|
+
*/
|
|
35
|
+
function CommandMenuLoader(_ref) {
|
|
36
|
+
var _hook;
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
name,
|
|
40
|
+
search,
|
|
41
|
+
hook,
|
|
42
|
+
setLoader,
|
|
43
|
+
close
|
|
44
|
+
} = _ref;
|
|
45
|
+
const {
|
|
46
|
+
isLoading,
|
|
47
|
+
commands = []
|
|
48
|
+
} = (_hook = hook({
|
|
49
|
+
search
|
|
50
|
+
})) !== null && _hook !== void 0 ? _hook : {};
|
|
51
|
+
(0, _element.useEffect)(() => {
|
|
52
|
+
setLoader(name, isLoading);
|
|
53
|
+
}, [setLoader, name, isLoading]);
|
|
54
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_cmdk.Command.List, null, isLoading && (0, _element.createElement)(_cmdk.Command.Loading, null, (0, _i18n.__)('Searching…')), commands.map(command => (0, _element.createElement)(_cmdk.Command.Item, {
|
|
55
|
+
key: command.name,
|
|
56
|
+
value: command.name,
|
|
57
|
+
onSelect: () => command.callback({
|
|
58
|
+
close
|
|
59
|
+
})
|
|
60
|
+
}, (0, _element.createElement)("span", {
|
|
61
|
+
className: "commands-command-menu__item"
|
|
62
|
+
}, (0, _element.createElement)(_components.TextHighlight, {
|
|
63
|
+
text: command.label,
|
|
64
|
+
highlight: search
|
|
65
|
+
}))))));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function CommandMenuLoaderWrapper(_ref2) {
|
|
69
|
+
let {
|
|
70
|
+
hook,
|
|
71
|
+
search,
|
|
72
|
+
setLoader,
|
|
73
|
+
close
|
|
74
|
+
} = _ref2;
|
|
75
|
+
// The "hook" prop is actually a custom React hook
|
|
76
|
+
// so to avoid breaking the rules of hooks
|
|
77
|
+
// the CommandMenuLoaderWrapper component need to be
|
|
78
|
+
// remounted on each hook prop change
|
|
79
|
+
// We use the key state to make sure we do that properly.
|
|
80
|
+
const currentLoader = (0, _element.useRef)(hook);
|
|
81
|
+
const [key, setKey] = (0, _element.useState)(0);
|
|
82
|
+
(0, _element.useEffect)(() => {
|
|
83
|
+
if (currentLoader.current !== hook) {
|
|
84
|
+
currentLoader.current = hook;
|
|
85
|
+
setKey(prevKey => prevKey + 1);
|
|
86
|
+
}
|
|
87
|
+
}, [hook]);
|
|
88
|
+
return (0, _element.createElement)(CommandMenuLoader, {
|
|
89
|
+
key: key,
|
|
90
|
+
hook: currentLoader.current,
|
|
91
|
+
search: search,
|
|
92
|
+
setLoader: setLoader,
|
|
93
|
+
close: close
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function CommandMenuGroup(_ref3) {
|
|
98
|
+
let {
|
|
99
|
+
group,
|
|
100
|
+
search,
|
|
101
|
+
setLoader,
|
|
102
|
+
close
|
|
103
|
+
} = _ref3;
|
|
104
|
+
const {
|
|
105
|
+
commands,
|
|
106
|
+
loaders
|
|
107
|
+
} = (0, _data.useSelect)(select => {
|
|
108
|
+
const {
|
|
109
|
+
getCommands,
|
|
110
|
+
getCommandLoaders
|
|
111
|
+
} = select(_store.store);
|
|
112
|
+
return {
|
|
113
|
+
commands: getCommands(group),
|
|
114
|
+
loaders: getCommandLoaders(group)
|
|
115
|
+
};
|
|
116
|
+
}, [group]);
|
|
117
|
+
return (0, _element.createElement)(_cmdk.Command.Group, {
|
|
118
|
+
heading: group
|
|
119
|
+
}, commands.map(command => (0, _element.createElement)(_cmdk.Command.Item, {
|
|
120
|
+
key: command.name,
|
|
121
|
+
value: command.name,
|
|
122
|
+
onSelect: () => command.callback({
|
|
123
|
+
close
|
|
124
|
+
})
|
|
125
|
+
}, (0, _element.createElement)("span", {
|
|
126
|
+
className: "commands-command-menu__item"
|
|
127
|
+
}, (0, _element.createElement)(_components.TextHighlight, {
|
|
128
|
+
text: command.label,
|
|
129
|
+
highlight: search
|
|
130
|
+
})))), loaders.map(loader => (0, _element.createElement)(CommandMenuLoaderWrapper, {
|
|
131
|
+
key: loader.name,
|
|
132
|
+
hook: loader.hook,
|
|
133
|
+
search: search,
|
|
134
|
+
setLoader: setLoader,
|
|
135
|
+
close: close
|
|
136
|
+
})));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function CommandMenu() {
|
|
140
|
+
const {
|
|
141
|
+
registerShortcut
|
|
142
|
+
} = (0, _data.useDispatch)(_keyboardShortcuts.store);
|
|
143
|
+
const [search, setSearch] = (0, _element.useState)('');
|
|
144
|
+
const [open, setOpen] = (0, _element.useState)(false);
|
|
145
|
+
const {
|
|
146
|
+
groups
|
|
147
|
+
} = (0, _data.useSelect)(select => {
|
|
148
|
+
const {
|
|
149
|
+
getGroups
|
|
150
|
+
} = select(_store.store);
|
|
151
|
+
return {
|
|
152
|
+
groups: getGroups()
|
|
153
|
+
};
|
|
154
|
+
}, []);
|
|
155
|
+
const [loaders, setLoaders] = (0, _element.useState)({});
|
|
156
|
+
(0, _element.useEffect)(() => {
|
|
157
|
+
registerShortcut({
|
|
158
|
+
name: 'core/commands',
|
|
159
|
+
category: 'global',
|
|
160
|
+
description: (0, _i18n.__)('Open the global command menu'),
|
|
161
|
+
keyCombination: {
|
|
162
|
+
modifier: 'primary',
|
|
163
|
+
character: 'k'
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}, [registerShortcut]);
|
|
167
|
+
(0, _keyboardShortcuts.useShortcut)('core/commands', event => {
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
setOpen(prevOpen => !prevOpen);
|
|
170
|
+
}, {
|
|
171
|
+
bindGlobal: true
|
|
172
|
+
});
|
|
173
|
+
const setLoader = (0, _element.useCallback)((name, value) => setLoaders(current => ({ ...current,
|
|
174
|
+
[name]: value
|
|
175
|
+
})), []);
|
|
176
|
+
|
|
177
|
+
const close = () => {
|
|
178
|
+
setSearch('');
|
|
179
|
+
setOpen(false);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (!open) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const isLoading = Object.values(loaders).some(Boolean);
|
|
187
|
+
return (0, _element.createElement)(_components.Modal, {
|
|
188
|
+
className: "commands-command-menu",
|
|
189
|
+
overlayClassName: "commands-command-menu__overlay",
|
|
190
|
+
onRequestClose: close,
|
|
191
|
+
__experimentalHideHeader: true
|
|
192
|
+
}, (0, _element.createElement)("div", {
|
|
193
|
+
className: "commands-command-menu__container"
|
|
194
|
+
}, (0, _element.createElement)(_cmdk.Command, {
|
|
195
|
+
label: (0, _i18n.__)('Global Command Menu')
|
|
196
|
+
}, (0, _element.createElement)("div", {
|
|
197
|
+
className: "commands-command-menu__header"
|
|
198
|
+
}, (0, _element.createElement)(_cmdk.Command.Input, {
|
|
199
|
+
// The input should be focused when the modal is opened.
|
|
200
|
+
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
201
|
+
autoFocus: true,
|
|
202
|
+
value: search,
|
|
203
|
+
onValueChange: setSearch,
|
|
204
|
+
placeholder: (0, _i18n.__)('Search for content and templates, or try commands like "Add…"')
|
|
205
|
+
})), (0, _element.createElement)(_cmdk.Command.List, null, !isLoading && (0, _element.createElement)(_cmdk.Command.Empty, null, (0, _i18n.__)('No results found.')), groups.map(group => (0, _element.createElement)(CommandMenuGroup, {
|
|
206
|
+
key: group,
|
|
207
|
+
group: group,
|
|
208
|
+
search: search,
|
|
209
|
+
setLoader: setLoader,
|
|
210
|
+
close: close
|
|
211
|
+
}))))));
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=command-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/components/command-menu.js"],"names":["CommandMenuLoader","name","search","hook","setLoader","close","isLoading","commands","map","command","callback","label","CommandMenuLoaderWrapper","currentLoader","key","setKey","current","prevKey","CommandMenuGroup","group","loaders","select","getCommands","getCommandLoaders","commandsStore","loader","CommandMenu","registerShortcut","keyboardShortcutsStore","setSearch","open","setOpen","groups","getGroups","setLoaders","category","description","keyCombination","modifier","character","event","preventDefault","prevOpen","bindGlobal","value","Object","values","some","Boolean"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AACA;;AAQA;;AApBA;AACA;AACA;;AAGA;AACA;AACA;;AAUA;AACA;AACA;AAGA,SAASA,iBAAT,OAAuE;AAAA;;AAAA,MAA3C;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,MAAR;AAAgBC,IAAAA,IAAhB;AAAsBC,IAAAA,SAAtB;AAAiCC,IAAAA;AAAjC,GAA2C;AACtE,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,QAAQ,GAAG;AAAxB,eAA+BJ,IAAI,CAAE;AAAED,IAAAA;AAAF,GAAF,CAAnC,yCAAqD,EAA3D;AACA,0BAAW,MAAM;AAChBE,IAAAA,SAAS,CAAEH,IAAF,EAAQK,SAAR,CAAT;AACA,GAFD,EAEG,CAA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AAK,GAAG,MAAM;AACnBwB,IAAAA,SAAS,CAAE,EAAF,CAAT;AACAE,IAAAA,OAAO,CAAE,KAAF,CAAP;AACA,GAHD;;AAKA,MAAK,CAAED,IAAP,EAAc;AACb,WAAO,KAAP;AACA;;AACD,QAAMxB,SAAS,GAAGuC,MAAM,CAACC,MAAP,CAAe1B,OAAf,EAAyB2B,IAAzB,CAA+BC,OAA/B,CAAlB;AAEA,SACC,4BAAC,iBAAD;AACC,IAAA,SAAS,EAAC,uBADX;AAEC,IAAA,gBAAgB,EAAC,gCAFlB;AAGC,IAAA,cAAc,EAAG3C,KAHlB;AAIC,IAAA,wBAAwB;AAJzB,KAMC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,aAAD;AAAS,IAAA,KAAK,EAAG,cAAI,qBAAJ;AAAjB,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,aAAD,CAAS,KAAT;AACC;AACA;AACA,IAAA,SAAS,MAHV;AAIC,IAAA,KAAK,EAAGH,MAJT;AAKC,IAAA,aAAa,EAAG2B,SALjB;AAMC,IAAA,WAAW,EAAG,cACb,+DADa;AANf,IADD,CADD,EAaC,4BAAC,aAAD,CAAS,IAAT,QACG,CAAEvB,SAAF,IACD,4BAAC,aAAD,CAAS,KAAT,QACG,cAAI,mBAAJ,CADH,CAFF,EAMG0B,MAAM,CAACxB,GAAP,CAAcW,KAAF,IACb,4BAAC,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,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useCommandLoader;
|
|
7
|
+
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _store = require("../store");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Attach a command loader to the Global command menu.
|
|
24
|
+
*
|
|
25
|
+
* @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
|
|
26
|
+
*/
|
|
27
|
+
function useCommandLoader(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
name,
|
|
30
|
+
group,
|
|
31
|
+
hook
|
|
32
|
+
} = _ref;
|
|
33
|
+
const {
|
|
34
|
+
registerCommandLoader,
|
|
35
|
+
unregisterCommandLoader
|
|
36
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
37
|
+
(0, _element.useEffect)(() => {
|
|
38
|
+
registerCommandLoader({
|
|
39
|
+
name,
|
|
40
|
+
group,
|
|
41
|
+
hook
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
unregisterCommandLoader(name, group);
|
|
45
|
+
};
|
|
46
|
+
}, [name, group, hook, registerCommandLoader, unregisterCommandLoader]);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=use-command-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"names":["useCommandLoader","name","group","hook","registerCommandLoader","unregisterCommandLoader","commandsStore"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,gBAAT,OAAmD;AAAA,MAAxB;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,KAAR;AAAeC,IAAAA;AAAf,GAAwB;AACjE,QAAM;AAAEC,IAAAA,qBAAF;AAAyBC,IAAAA;AAAzB,MACL,uBAAaC,YAAb,CADD;AAEA,0BAAW,MAAM;AAChBF,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,GATD,EASG,CAAED,IAAF,EAAQC,KAAR,EAAeC,IAAf,EAAqBC,qBAArB,EAA4CC,uBAA5C,CATH;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,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useCommand;
|
|
7
|
+
|
|
8
|
+
var _element = require("@wordpress/element");
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _store = require("../store");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* WordPress dependencies
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Attach a command to the Global command menu.
|
|
24
|
+
*
|
|
25
|
+
* @param {import('../store/actions').WPCommandConfig} command command config.
|
|
26
|
+
*/
|
|
27
|
+
function useCommand(command) {
|
|
28
|
+
const {
|
|
29
|
+
registerCommand,
|
|
30
|
+
unregisterCommand
|
|
31
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
32
|
+
const currentCallback = (0, _element.useRef)(command.callback);
|
|
33
|
+
(0, _element.useEffect)(() => {
|
|
34
|
+
currentCallback.current = command.callback;
|
|
35
|
+
}, [command.callback]);
|
|
36
|
+
(0, _element.useEffect)(() => {
|
|
37
|
+
registerCommand({
|
|
38
|
+
name: command.name,
|
|
39
|
+
group: command.group,
|
|
40
|
+
label: command.label,
|
|
41
|
+
callback: currentCallback.current
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
unregisterCommand(command.name, command.group);
|
|
45
|
+
};
|
|
46
|
+
}, [command.name, command.label, command.group, registerCommand, unregisterCommand]);
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=use-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command.js"],"names":["useCommand","command","registerCommand","unregisterCommand","commandsStore","currentCallback","callback","current","name","group","label"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,UAAT,CAAqBC,OAArB,EAA+B;AAC7C,QAAM;AAAEC,IAAAA,eAAF;AAAmBC,IAAAA;AAAnB,MAAyC,uBAAaC,YAAb,CAA/C;AACA,QAAMC,eAAe,GAAG,qBAAQJ,OAAO,CAACK,QAAhB,CAAxB;AACA,0BAAW,MAAM;AAChBD,IAAAA,eAAe,CAACE,OAAhB,GAA0BN,OAAO,CAACK,QAAlC;AACA,GAFD,EAEG,CAAEL,OAAO,CAACK,QAAV,CAFH;AAIA,0BAAW,MAAM;AAChBJ,IAAAA,eAAe,CAAE;AAChBM,MAAAA,IAAI,EAAEP,OAAO,CAACO,IADE;AAEhBC,MAAAA,KAAK,EAAER,OAAO,CAACQ,KAFC;AAGhBC,MAAAA,KAAK,EAAET,OAAO,CAACS,KAHC;AAIhBJ,MAAAA,QAAQ,EAAED,eAAe,CAACE;AAJV,KAAF,CAAf;AAMA,WAAO,MAAM;AACZJ,MAAAA,iBAAiB,CAAEF,OAAO,CAACO,IAAV,EAAgBP,OAAO,CAACQ,KAAxB,CAAjB;AACA,KAFD;AAGA,GAVD,EAUG,CACFR,OAAO,CAACO,IADN,EAEFP,OAAO,CAACS,KAFN,EAGFT,OAAO,CAACQ,KAHN,EAIFP,eAJE,EAKFC,iBALE,CAVH;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"]}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "CommandMenu", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _commandMenu.CommandMenu;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "privateApis", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _privateApis.privateApis;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _commandMenu = require("./components/command-menu");
|
|
20
|
+
|
|
21
|
+
var _privateApis = require("./private-apis");
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.unlock = exports.privateApis = exports.lock = void 0;
|
|
9
|
+
|
|
10
|
+
var _privateApis = require("@wordpress/private-apis");
|
|
11
|
+
|
|
12
|
+
var _useCommand = _interopRequireDefault(require("./hooks/use-command"));
|
|
13
|
+
|
|
14
|
+
var _useCommandLoader = _interopRequireDefault(require("./hooks/use-command-loader"));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WordPress dependencies
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Internal dependencies
|
|
22
|
+
*/
|
|
23
|
+
const {
|
|
24
|
+
lock,
|
|
25
|
+
unlock
|
|
26
|
+
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/commands');
|
|
27
|
+
exports.unlock = unlock;
|
|
28
|
+
exports.lock = lock;
|
|
29
|
+
const privateApis = {};
|
|
30
|
+
exports.privateApis = privateApis;
|
|
31
|
+
lock(privateApis, {
|
|
32
|
+
useCommand: _useCommand.default,
|
|
33
|
+
useCommandLoader: _useCommandLoader.default
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/private-apis.js"],"names":["lock","unlock","privateApis","useCommand","useCommandLoader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAM;AAAEA,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZ,mEACC,8GADD,EAEC,qBAFD,CADM;;;AAMA,MAAMC,WAAW,GAAG,EAApB;;AACPF,IAAI,CAAEE,WAAF,EAAe;AAClBC,EAAAA,UAAU,EAAVA,mBADkB;AAElBC,EAAAA,gBAAgB,EAAhBA;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,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.registerCommand = registerCommand;
|
|
7
|
+
exports.registerCommandLoader = registerCommandLoader;
|
|
8
|
+
exports.unregisterCommand = unregisterCommand;
|
|
9
|
+
exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
10
|
+
|
|
11
|
+
/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Configuration of a registered keyboard shortcut.
|
|
15
|
+
*
|
|
16
|
+
* @typedef {Object} WPCommandConfig
|
|
17
|
+
*
|
|
18
|
+
* @property {string} name Command name.
|
|
19
|
+
* @property {string} label Command label.
|
|
20
|
+
* @property {string=} group Command group.
|
|
21
|
+
* @property {Function} callback Command callback.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {(search: string) => WPCommandConfig[]} WPCommandLoaderHook hoo
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Command loader config.
|
|
30
|
+
*
|
|
31
|
+
* @typedef {Object} WPCommandLoaderConfig
|
|
32
|
+
*
|
|
33
|
+
* @property {string} name Command loader name.
|
|
34
|
+
* @property {string=} group Command loader group.
|
|
35
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns an action object used to register a new command.
|
|
40
|
+
*
|
|
41
|
+
* @param {WPCommandConfig} config Command config.
|
|
42
|
+
*
|
|
43
|
+
* @return {Object} action.
|
|
44
|
+
*/
|
|
45
|
+
function registerCommand(_ref) {
|
|
46
|
+
let {
|
|
47
|
+
name,
|
|
48
|
+
label,
|
|
49
|
+
callback,
|
|
50
|
+
group = ''
|
|
51
|
+
} = _ref;
|
|
52
|
+
return {
|
|
53
|
+
type: 'REGISTER_COMMAND',
|
|
54
|
+
name,
|
|
55
|
+
label,
|
|
56
|
+
callback,
|
|
57
|
+
group
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns an action object used to unregister a command.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} name Command name.
|
|
64
|
+
* @param {string} group Command group.
|
|
65
|
+
*
|
|
66
|
+
* @return {Object} action.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
function unregisterCommand(name, group) {
|
|
71
|
+
return {
|
|
72
|
+
type: 'UNREGISTER_COMMAND',
|
|
73
|
+
name,
|
|
74
|
+
group
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Register command loader.
|
|
79
|
+
*
|
|
80
|
+
* @param {WPCommandLoaderConfig} config Command loader config.
|
|
81
|
+
*
|
|
82
|
+
* @return {Object} action.
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
function registerCommandLoader(_ref2) {
|
|
87
|
+
let {
|
|
88
|
+
name,
|
|
89
|
+
group = '',
|
|
90
|
+
hook
|
|
91
|
+
} = _ref2;
|
|
92
|
+
return {
|
|
93
|
+
type: 'REGISTER_COMMAND_LOADER',
|
|
94
|
+
name,
|
|
95
|
+
group,
|
|
96
|
+
hook
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Unregister command loader hook.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} name Command loader name.
|
|
103
|
+
* @param {string} group Command loader group.
|
|
104
|
+
*
|
|
105
|
+
* @return {Object} action.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
function unregisterCommandLoader(name, group) {
|
|
110
|
+
return {
|
|
111
|
+
type: 'UNREGISTER_COMMAND_LOADER',
|
|
112
|
+
name,
|
|
113
|
+
group
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# 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;AACO,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;;;AACO,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;;;AACO,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;;;AACO,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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.store = void 0;
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
13
|
+
|
|
14
|
+
var actions = _interopRequireWildcard(require("./actions"));
|
|
15
|
+
|
|
16
|
+
var selectors = _interopRequireWildcard(require("./selectors"));
|
|
17
|
+
|
|
18
|
+
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
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WordPress dependencies
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Internal dependencies
|
|
28
|
+
*/
|
|
29
|
+
const STORE_NAME = 'core/commands';
|
|
30
|
+
/**
|
|
31
|
+
* Store definition for the commands namespace.
|
|
32
|
+
*
|
|
33
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
34
|
+
*
|
|
35
|
+
* @type {Object}
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const store = (0, _data.createReduxStore)(STORE_NAME, {
|
|
39
|
+
reducer: _reducer.default,
|
|
40
|
+
actions,
|
|
41
|
+
selectors
|
|
42
|
+
});
|
|
43
|
+
exports.store = store;
|
|
44
|
+
(0, _data.register)(store);
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/store/index.js"],"names":["STORE_NAME","store","reducer","actions","selectors"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;;;;;AAVA;AACA;AACA;;AAGA;AACA;AACA;AAKA,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","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"]}
|