@wordpress/commands 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +16 -0
- package/build/components/command-menu.js +60 -51
- package/build/components/command-menu.js.map +1 -1
- package/build/hooks/use-command-context.js +45 -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 +18 -0
- package/build/index.js.map +1 -1
- package/build/private-apis.js +2 -5
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +35 -40
- package/build/store/actions.js.map +1 -1
- package/build/store/reducer.js +38 -22
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +20 -17
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/command-menu.js +60 -51
- package/build-module/components/command-menu.js.map +1 -1
- package/build-module/hooks/use-command-context.js +35 -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 +2 -0
- package/build-module/index.js.map +1 -1
- package/build-module/private-apis.js +2 -4
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +33 -40
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/reducer.js +38 -22
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +17 -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 +32 -0
- package/src/hooks/use-command-loader.js +12 -6
- package/src/hooks/use-command.js +5 -3
- package/src/index.js +2 -0
- package/src/private-apis.js +2 -4
- package/src/store/actions.js +31 -26
- package/src/store/reducer.js +33 -27
- package/src/store/selectors.js +18 -20
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -24,6 +24,22 @@ Undocumented declaration.
|
|
|
24
24
|
|
|
25
25
|
Undocumented declaration.
|
|
26
26
|
|
|
27
|
+
### useCommand
|
|
28
|
+
|
|
29
|
+
Attach a command to the Global command menu.
|
|
30
|
+
|
|
31
|
+
_Parameters_
|
|
32
|
+
|
|
33
|
+
- _command_ `import('../store/actions').WPCommandConfig`: command config.
|
|
34
|
+
|
|
35
|
+
### useCommandLoader
|
|
36
|
+
|
|
37
|
+
Attach a command loader to the Global command menu.
|
|
38
|
+
|
|
39
|
+
_Parameters_
|
|
40
|
+
|
|
41
|
+
- _loader_ `import('../store/actions').WPCommandLoaderConfig`: command loader config.
|
|
42
|
+
|
|
27
43
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
28
44
|
|
|
29
45
|
## Contributing to this package
|
|
@@ -53,21 +53,30 @@ function CommandMenuLoader(_ref) {
|
|
|
53
53
|
(0, _element.useEffect)(() => {
|
|
54
54
|
setLoader(name, isLoading);
|
|
55
55
|
}, [setLoader, name, isLoading]);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
|
|
57
|
+
if (!commands.length) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)(_cmdk.Command.List, null, commands.map(command => {
|
|
62
|
+
var _command$searchLabel;
|
|
63
|
+
|
|
64
|
+
return (0, _element.createElement)(_cmdk.Command.Item, {
|
|
65
|
+
key: command.name,
|
|
66
|
+
value: (_command$searchLabel = command.searchLabel) !== null && _command$searchLabel !== void 0 ? _command$searchLabel : command.label,
|
|
67
|
+
onSelect: () => command.callback({
|
|
68
|
+
close
|
|
69
|
+
})
|
|
70
|
+
}, (0, _element.createElement)(_components.__experimentalHStack, {
|
|
71
|
+
alignment: "left",
|
|
72
|
+
className: "commands-command-menu__item"
|
|
73
|
+
}, (0, _element.createElement)(_icons.Icon, {
|
|
74
|
+
icon: command.icon
|
|
75
|
+
}), (0, _element.createElement)("span", null, (0, _element.createElement)(_components.TextHighlight, {
|
|
76
|
+
text: command.label,
|
|
77
|
+
highlight: search
|
|
78
|
+
}))));
|
|
79
|
+
})));
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
function CommandMenuLoaderWrapper(_ref2) {
|
|
@@ -101,7 +110,7 @@ function CommandMenuLoaderWrapper(_ref2) {
|
|
|
101
110
|
|
|
102
111
|
function CommandMenuGroup(_ref3) {
|
|
103
112
|
let {
|
|
104
|
-
|
|
113
|
+
isContextual,
|
|
105
114
|
search,
|
|
106
115
|
setLoader,
|
|
107
116
|
close
|
|
@@ -115,25 +124,34 @@ function CommandMenuGroup(_ref3) {
|
|
|
115
124
|
getCommandLoaders
|
|
116
125
|
} = select(_store.store);
|
|
117
126
|
return {
|
|
118
|
-
commands: getCommands(
|
|
119
|
-
loaders: getCommandLoaders(
|
|
127
|
+
commands: getCommands(isContextual),
|
|
128
|
+
loaders: getCommandLoaders(isContextual)
|
|
120
129
|
};
|
|
121
|
-
}, [
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
}, [isContextual]);
|
|
131
|
+
|
|
132
|
+
if (!commands.length && !loaders.length) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return (0, _element.createElement)(_cmdk.Command.Group, null, commands.map(command => {
|
|
137
|
+
var _command$searchLabel2;
|
|
138
|
+
|
|
139
|
+
return (0, _element.createElement)(_cmdk.Command.Item, {
|
|
140
|
+
key: command.name,
|
|
141
|
+
value: (_command$searchLabel2 = command.searchLabel) !== null && _command$searchLabel2 !== void 0 ? _command$searchLabel2 : command.label,
|
|
142
|
+
onSelect: () => command.callback({
|
|
143
|
+
close
|
|
144
|
+
})
|
|
145
|
+
}, (0, _element.createElement)(_components.__experimentalHStack, {
|
|
146
|
+
alignment: "left",
|
|
147
|
+
className: "commands-command-menu__item"
|
|
148
|
+
}, (0, _element.createElement)(_icons.Icon, {
|
|
149
|
+
icon: command.icon
|
|
150
|
+
}), (0, _element.createElement)("span", null, (0, _element.createElement)(_components.TextHighlight, {
|
|
151
|
+
text: command.label,
|
|
152
|
+
highlight: search
|
|
153
|
+
}))));
|
|
154
|
+
}), loaders.map(loader => (0, _element.createElement)(CommandMenuLoaderWrapper, {
|
|
137
155
|
key: loader.name,
|
|
138
156
|
hook: loader.hook,
|
|
139
157
|
search: search,
|
|
@@ -147,19 +165,7 @@ function CommandMenu() {
|
|
|
147
165
|
registerShortcut
|
|
148
166
|
} = (0, _data.useDispatch)(_keyboardShortcuts.store);
|
|
149
167
|
const [search, setSearch] = (0, _element.useState)('');
|
|
150
|
-
const
|
|
151
|
-
groups,
|
|
152
|
-
isOpen
|
|
153
|
-
} = (0, _data.useSelect)(select => {
|
|
154
|
-
const {
|
|
155
|
-
getGroups,
|
|
156
|
-
isOpen: _isOpen
|
|
157
|
-
} = select(_store.store);
|
|
158
|
-
return {
|
|
159
|
-
groups: getGroups(),
|
|
160
|
-
isOpen: _isOpen()
|
|
161
|
-
};
|
|
162
|
-
}, []);
|
|
168
|
+
const isOpen = (0, _data.useSelect)(select => select(_store.store).isOpen(), []);
|
|
163
169
|
const {
|
|
164
170
|
open,
|
|
165
171
|
close
|
|
@@ -225,12 +231,15 @@ function CommandMenu() {
|
|
|
225
231
|
value: search,
|
|
226
232
|
onValueChange: setSearch,
|
|
227
233
|
placeholder: (0, _i18n.__)('Type a command or search')
|
|
228
|
-
})),
|
|
229
|
-
|
|
230
|
-
|
|
234
|
+
})), (0, _element.createElement)(_cmdk.Command.List, null, search && !isLoading && (0, _element.createElement)(_cmdk.Command.Empty, null, (0, _i18n.__)('No results found.')), (0, _element.createElement)(CommandMenuGroup, {
|
|
235
|
+
search: search,
|
|
236
|
+
setLoader: setLoader,
|
|
237
|
+
close: closeAndReset,
|
|
238
|
+
isContextual: true
|
|
239
|
+
}), search && (0, _element.createElement)(CommandMenuGroup, {
|
|
231
240
|
search: search,
|
|
232
241
|
setLoader: setLoader,
|
|
233
242
|
close: closeAndReset
|
|
234
|
-
})))))
|
|
243
|
+
})))));
|
|
235
244
|
}
|
|
236
245
|
//# sourceMappingURL=command-menu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/components/command-menu.js"],"names":["CommandMenuLoader","name","search","hook","setLoader","close","isLoading","commands","map","command","callback","icon","label","CommandMenuLoaderWrapper","currentLoader","key","setKey","current","prevKey","CommandMenuGroup","group","loaders","select","getCommands","getCommandLoaders","commandsStore","loader","CommandMenu","registerShortcut","keyboardShortcutsStore","setSearch","groups","isOpen","getGroups","_isOpen","open","setLoaders","commandMenuInput","category","description","keyCombination","modifier","character","event","preventDefault","bindGlobal","value","closeAndReset","focus","Object","values","some","Boolean"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AAKA;;AAIA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAeA;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,G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f,KACC,4BAAC,aAAD,CAAS,KAAT;AACC,IAAA,GAAG,EAAGV,gBADP;AAEC,IAAA,KAAK,EAAGnC,MAFT;AAGC,IAAA,aAAa,EAAG4B,SAHjB;AAIC,IAAA,WAAW,EAAG,cAAI,0BAAJ;AAJf,IADD,CADD,EASG5B,MAAM,IACP,4BAAC,aAAD,CAAS,IAAT,QACG,CAAEI,SAAF,IACD,4BAAC,aAAD,CAAS,KAAT,QACG,cAAI,mBAAJ,CADH,CAFF,EAMGyB,MAAM,CAACvB,GAAP,CAAcY,KAAF,IACb,4BAAC,gBAAD;AACC,IAAA,GAAG,EAAGA,KADP;AAEC,IAAA,KAAK,EAAGA,KAFT;AAGC,IAAA,MAAM,EAAGlB,MAHV;AAIC,IAAA,SAAS,EAAGE,SAJb;AAKC,IAAA,KAAK,EAAG2C;AALT,IADC,CANH,CAVF,CADD,CAND,CADD;AAuCA","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 {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\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<HStack\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { 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>\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<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst { groups, isOpen } = useSelect( ( select ) => {\n\t\tconst { getGroups, isOpen: _isOpen } = select( commandsStore );\n\t\treturn {\n\t\t\tgroups: getGroups(),\n\t\t\tisOpen: _isOpen(),\n\t\t};\n\t}, [] );\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\tconst commandMenuInput = useRef();\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\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the command menu input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\n\tif ( ! isOpen ) {\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={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command 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\tref={ commandMenuInput }\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={ __( 'Type a command or search' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t{ search && (\n\t\t\t\t\t\t<Command.List>\n\t\t\t\t\t\t\t{ ! isLoading && (\n\t\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t{ groups.map( ( group ) => (\n\t\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\t\tkey={ group }\n\t\t\t\t\t\t\t\t\tgroup={ group }\n\t\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) ) }\n\t\t\t\t\t\t</Command.List>\n\t\t\t\t\t) }\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/components/command-menu.js"],"names":["CommandMenuLoader","name","search","hook","setLoader","close","isLoading","commands","length","map","command","searchLabel","label","callback","icon","CommandMenuLoaderWrapper","currentLoader","key","setKey","current","prevKey","CommandMenuGroup","isContextual","loaders","select","getCommands","getCommandLoaders","commandsStore","loader","CommandMenu","registerShortcut","keyboardShortcutsStore","setSearch","isOpen","open","setLoaders","commandMenuInput","category","description","keyCombination","modifier","character","event","preventDefault","bindGlobal","value","closeAndReset","focus","Object","values","some","Boolean"],"mappings":";;;;;;;;;AASA;;AANA;;AAKA;;AAEA;;AACA;;AAKA;;AAIA;;AAKA;;AAzBA;AACA;AACA;;AAGA;AACA;AACA;;AAeA;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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,MAFT;AAGC,IAAA,aAAa,EAAG8B,SAHjB;AAIC,IAAA,WAAW,EAAG,cAAI,0BAAJ;AAJf,IADD,CADD,EASC,4BAAC,aAAD,CAAS,IAAT,QACG9B,MAAM,IAAI,CAAEI,SAAZ,IACD,4BAAC,aAAD,CAAS,KAAT,QACG,cAAI,mBAAJ,CADH,CAFF,EAMC,4BAAC,gBAAD;AACC,IAAA,MAAM,EAAGJ,MADV;AAEC,IAAA,SAAS,EAAGE,SAFb;AAGC,IAAA,KAAK,EAAG0C,aAHT;AAIC,IAAA,YAAY;AAJb,IAND,EAYG5C,MAAM,IACP,4BAAC,gBAAD;AACC,IAAA,MAAM,EAAGA,MADV;AAEC,IAAA,SAAS,EAAGE,SAFb;AAGC,IAAA,KAAK,EAAG0C;AAHT,IAbF,CATD,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 {\n\tModal,\n\tTextHighlight,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport {\n\tstore as keyboardShortcutsStore,\n\tuseShortcut,\n} from '@wordpress/keyboard-shortcuts';\nimport { Icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\nfunction CommandMenuLoader( { name, search, hook, setLoader, close } ) {\n\tconst { isLoading, commands = [] } = hook( { search } ) ?? {};\n\tuseEffect( () => {\n\t\tsetLoader( name, isLoading );\n\t}, [ setLoader, name, isLoading ] );\n\n\tif ( ! commands.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Command.List>\n\t\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t\t<Command.Item\n\t\t\t\t\t\tkey={ command.name }\n\t\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t\t>\n\t\t\t\t\t\t<HStack\n\t\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</HStack>\n\t\t\t\t\t</Command.Item>\n\t\t\t\t) ) }\n\t\t\t</Command.List>\n\t\t</>\n\t);\n}\n\nexport function CommandMenuLoaderWrapper( { hook, search, setLoader, close } ) {\n\t// The \"hook\" prop is actually a custom React hook\n\t// so to avoid breaking the rules of hooks\n\t// the CommandMenuLoaderWrapper component need to be\n\t// remounted on each hook prop change\n\t// We use the key state to make sure we do that properly.\n\tconst currentLoader = useRef( hook );\n\tconst [ key, setKey ] = useState( 0 );\n\tuseEffect( () => {\n\t\tif ( currentLoader.current !== hook ) {\n\t\t\tcurrentLoader.current = hook;\n\t\t\tsetKey( ( prevKey ) => prevKey + 1 );\n\t\t}\n\t}, [ hook ] );\n\n\treturn (\n\t\t<CommandMenuLoader\n\t\t\tkey={ key }\n\t\t\thook={ currentLoader.current }\n\t\t\tsearch={ search }\n\t\t\tsetLoader={ setLoader }\n\t\t\tclose={ close }\n\t\t/>\n\t);\n}\n\nexport function CommandMenuGroup( { isContextual, search, setLoader, close } ) {\n\tconst { commands, loaders } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getCommands, getCommandLoaders } = select( commandsStore );\n\t\t\treturn {\n\t\t\t\tcommands: getCommands( isContextual ),\n\t\t\t\tloaders: getCommandLoaders( isContextual ),\n\t\t\t};\n\t\t},\n\t\t[ isContextual ]\n\t);\n\n\tif ( ! commands.length && ! loaders.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Command.Group>\n\t\t\t{ commands.map( ( command ) => (\n\t\t\t\t<Command.Item\n\t\t\t\t\tkey={ command.name }\n\t\t\t\t\tvalue={ command.searchLabel ?? command.label }\n\t\t\t\t\tonSelect={ () => command.callback( { close } ) }\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t\tclassName=\"commands-command-menu__item\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<Icon icon={ command.icon } />\n\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t<TextHighlight\n\t\t\t\t\t\t\t\ttext={ command.label }\n\t\t\t\t\t\t\t\thighlight={ search }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</HStack>\n\t\t\t\t</Command.Item>\n\t\t\t) ) }\n\t\t\t{ loaders.map( ( loader ) => (\n\t\t\t\t<CommandMenuLoaderWrapper\n\t\t\t\t\tkey={ loader.name }\n\t\t\t\t\thook={ loader.hook }\n\t\t\t\t\tsearch={ search }\n\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\tclose={ close }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Command.Group>\n\t);\n}\n\nexport function CommandMenu() {\n\tconst { registerShortcut } = useDispatch( keyboardShortcutsStore );\n\tconst [ search, setSearch ] = useState( '' );\n\tconst isOpen = useSelect(\n\t\t( select ) => select( commandsStore ).isOpen(),\n\t\t[]\n\t);\n\tconst { open, close } = useDispatch( commandsStore );\n\tconst [ loaders, setLoaders ] = useState( {} );\n\tconst commandMenuInput = useRef();\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\tif ( isOpen ) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\topen();\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tbindGlobal: true,\n\t\t}\n\t);\n\n\tconst setLoader = useCallback(\n\t\t( name, value ) =>\n\t\t\tsetLoaders( ( current ) => ( {\n\t\t\t\t...current,\n\t\t\t\t[ name ]: value,\n\t\t\t} ) ),\n\t\t[]\n\t);\n\tconst closeAndReset = () => {\n\t\tsetSearch( '' );\n\t\tclose();\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the command menu input when mounting the modal.\n\t\tif ( isOpen ) {\n\t\t\tcommandMenuInput.current.focus();\n\t\t}\n\t}, [ isOpen ] );\n\n\tif ( ! isOpen ) {\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={ closeAndReset }\n\t\t\t__experimentalHideHeader\n\t\t>\n\t\t\t<div className=\"commands-command-menu__container\">\n\t\t\t\t<Command 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\tref={ commandMenuInput }\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={ __( 'Type a command or search' ) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t\t<Command.List>\n\t\t\t\t\t\t{ search && ! isLoading && (\n\t\t\t\t\t\t\t<Command.Empty>\n\t\t\t\t\t\t\t\t{ __( 'No results found.' ) }\n\t\t\t\t\t\t\t</Command.Empty>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\tisContextual\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<CommandMenuGroup\n\t\t\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\t\t\tsetLoader={ setLoader }\n\t\t\t\t\t\t\t\tclose={ closeAndReset }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Command.List>\n\t\t\t\t</Command>\n\t\t\t</div>\n\t\t</Modal>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useCommandContext;
|
|
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
|
+
* Sets the active context of the command center
|
|
24
|
+
*
|
|
25
|
+
* @param {string} context Context to set.
|
|
26
|
+
*/
|
|
27
|
+
function useCommandContext(context) {
|
|
28
|
+
const {
|
|
29
|
+
getContext
|
|
30
|
+
} = (0, _data.useSelect)(_store.store);
|
|
31
|
+
const initialContext = (0, _element.useRef)(getContext());
|
|
32
|
+
const {
|
|
33
|
+
setContext
|
|
34
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
35
|
+
(0, _element.useEffect)(() => {
|
|
36
|
+
setContext(context);
|
|
37
|
+
}, [context, setContext]); // This effects ensures that on unmount, we restore the context
|
|
38
|
+
// that was set before the component actually mounts.
|
|
39
|
+
|
|
40
|
+
(0, _element.useEffect)(() => {
|
|
41
|
+
const initialContextRef = initialContext.current;
|
|
42
|
+
return () => setContext(initialContextRef);
|
|
43
|
+
}, [setContext]);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=use-command-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command-context.js"],"names":["useCommandContext","context","getContext","commandsStore","initialContext","setContext","initialContextRef","current"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,iBAAT,CAA4BC,OAA5B,EAAsC;AACpD,QAAM;AAAEC,IAAAA;AAAF,MAAiB,qBAAWC,YAAX,CAAvB;AACA,QAAMC,cAAc,GAAG,qBAAQF,UAAU,EAAlB,CAAvB;AACA,QAAM;AAAEG,IAAAA;AAAF,MAAiB,uBAAaF,YAAb,CAAvB;AAEA,0BAAW,MAAM;AAChBE,IAAAA,UAAU,CAAEJ,OAAF,CAAV;AACA,GAFD,EAEG,CAAEA,OAAF,EAAWI,UAAX,CAFH,EALoD,CASpD;AACA;;AACA,0BAAW,MAAM;AAChB,UAAMC,iBAAiB,GAAGF,cAAc,CAACG,OAAzC;AACA,WAAO,MAAMF,UAAU,CAAEC,iBAAF,CAAvB;AACA,GAHD,EAGG,CAAED,UAAF,CAHH;AAIA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { store as commandsStore } from '../store';\n\n/**\n * Sets the active context of the command center\n *\n * @param {string} context Context to set.\n */\nexport default function useCommandContext( context ) {\n\tconst { getContext } = useSelect( commandsStore );\n\tconst initialContext = useRef( getContext() );\n\tconst { setContext } = useDispatch( commandsStore );\n\n\tuseEffect( () => {\n\t\tsetContext( context );\n\t}, [ context, setContext ] );\n\n\t// This effects ensures that on unmount, we restore the context\n\t// that was set before the component actually mounts.\n\tuseEffect( () => {\n\t\tconst initialContextRef = initialContext.current;\n\t\treturn () => setContext( initialContextRef );\n\t}, [ setContext ] );\n}\n"]}
|
|
@@ -24,25 +24,20 @@ var _store = require("../store");
|
|
|
24
24
|
*
|
|
25
25
|
* @param {import('../store/actions').WPCommandLoaderConfig} loader command loader config.
|
|
26
26
|
*/
|
|
27
|
-
function useCommandLoader(
|
|
28
|
-
let {
|
|
29
|
-
name,
|
|
30
|
-
group,
|
|
31
|
-
hook
|
|
32
|
-
} = _ref;
|
|
27
|
+
function useCommandLoader(loader) {
|
|
33
28
|
const {
|
|
34
29
|
registerCommandLoader,
|
|
35
30
|
unregisterCommandLoader
|
|
36
31
|
} = (0, _data.useDispatch)(_store.store);
|
|
37
32
|
(0, _element.useEffect)(() => {
|
|
38
33
|
registerCommandLoader({
|
|
39
|
-
name,
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
name: loader.name,
|
|
35
|
+
hook: loader.hook,
|
|
36
|
+
context: loader.context
|
|
42
37
|
});
|
|
43
38
|
return () => {
|
|
44
|
-
unregisterCommandLoader(name
|
|
39
|
+
unregisterCommandLoader(loader.name);
|
|
45
40
|
};
|
|
46
|
-
}, [name,
|
|
41
|
+
}, [loader.name, loader.hook, loader.context, registerCommandLoader, unregisterCommandLoader]);
|
|
47
42
|
}
|
|
48
43
|
//# sourceMappingURL=use-command-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"names":["useCommandLoader","
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command-loader.js"],"names":["useCommandLoader","loader","registerCommandLoader","unregisterCommandLoader","commandsStore","name","hook","context"],"mappings":";;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACe,SAASA,gBAAT,CAA2BC,MAA3B,EAAoC;AAClD,QAAM;AAAEC,IAAAA,qBAAF;AAAyBC,IAAAA;AAAzB,MACL,uBAAaC,YAAb,CADD;AAEA,0BAAW,MAAM;AAChBF,IAAAA,qBAAqB,CAAE;AACtBG,MAAAA,IAAI,EAAEJ,MAAM,CAACI,IADS;AAEtBC,MAAAA,IAAI,EAAEL,MAAM,CAACK,IAFS;AAGtBC,MAAAA,OAAO,EAAEN,MAAM,CAACM;AAHM,KAAF,CAArB;AAKA,WAAO,MAAM;AACZJ,MAAAA,uBAAuB,CAAEF,MAAM,CAACI,IAAT,CAAvB;AACA,KAFD;AAGA,GATD,EASG,CACFJ,MAAM,CAACI,IADL,EAEFJ,MAAM,CAACK,IAFL,EAGFL,MAAM,CAACM,OAHL,EAIFL,qBAJE,EAKFC,uBALE,CATH;AAgBA","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( loader ) {\n\tconst { registerCommandLoader, unregisterCommandLoader } =\n\t\tuseDispatch( commandsStore );\n\tuseEffect( () => {\n\t\tregisterCommandLoader( {\n\t\t\tname: loader.name,\n\t\t\thook: loader.hook,\n\t\t\tcontext: loader.context,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommandLoader( loader.name );\n\t\t};\n\t}, [\n\t\tloader.name,\n\t\tloader.hook,\n\t\tloader.context,\n\t\tregisterCommandLoader,\n\t\tunregisterCommandLoader,\n\t] );\n}\n"]}
|
|
@@ -36,14 +36,15 @@ function useCommand(command) {
|
|
|
36
36
|
(0, _element.useEffect)(() => {
|
|
37
37
|
registerCommand({
|
|
38
38
|
name: command.name,
|
|
39
|
-
|
|
39
|
+
context: command.context,
|
|
40
40
|
label: command.label,
|
|
41
|
+
searchLabel: command.searchLabel,
|
|
41
42
|
icon: command.icon,
|
|
42
43
|
callback: currentCallback.current
|
|
43
44
|
});
|
|
44
45
|
return () => {
|
|
45
|
-
unregisterCommand(command.name
|
|
46
|
+
unregisterCommand(command.name);
|
|
46
47
|
};
|
|
47
|
-
}, [command.name, command.label, command.
|
|
48
|
+
}, [command.name, command.label, command.searchLabel, command.icon, command.context, registerCommand, unregisterCommand]);
|
|
48
49
|
}
|
|
49
50
|
//# sourceMappingURL=use-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command.js"],"names":["useCommand","command","registerCommand","unregisterCommand","commandsStore","currentCallback","callback","current","name","
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/hooks/use-command.js"],"names":["useCommand","command","registerCommand","unregisterCommand","commandsStore","currentCallback","callback","current","name","context","label","searchLabel","icon"],"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,OAAO,EAAER,OAAO,CAACQ,OAFD;AAGhBC,MAAAA,KAAK,EAAET,OAAO,CAACS,KAHC;AAIhBC,MAAAA,WAAW,EAAEV,OAAO,CAACU,WAJL;AAKhBC,MAAAA,IAAI,EAAEX,OAAO,CAACW,IALE;AAMhBN,MAAAA,QAAQ,EAAED,eAAe,CAACE;AANV,KAAF,CAAf;AAQA,WAAO,MAAM;AACZJ,MAAAA,iBAAiB,CAAEF,OAAO,CAACO,IAAV,CAAjB;AACA,KAFD;AAGA,GAZD,EAYG,CACFP,OAAO,CAACO,IADN,EAEFP,OAAO,CAACS,KAFN,EAGFT,OAAO,CAACU,WAHN,EAIFV,OAAO,CAACW,IAJN,EAKFX,OAAO,CAACQ,OALN,EAMFP,eANE,EAOFC,iBAPE,CAZH;AAqBA","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\tcontext: command.context,\n\t\t\tlabel: command.label,\n\t\t\tsearchLabel: command.searchLabel,\n\t\t\ticon: command.icon,\n\t\t\tcallback: currentCallback.current,\n\t\t} );\n\t\treturn () => {\n\t\t\tunregisterCommand( command.name );\n\t\t};\n\t}, [\n\t\tcommand.name,\n\t\tcommand.label,\n\t\tcommand.searchLabel,\n\t\tcommand.icon,\n\t\tcommand.context,\n\t\tregisterCommand,\n\t\tunregisterCommand,\n\t] );\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -15,8 +17,24 @@ Object.defineProperty(exports, "privateApis", {
|
|
|
15
17
|
return _privateApis.privateApis;
|
|
16
18
|
}
|
|
17
19
|
});
|
|
20
|
+
Object.defineProperty(exports, "useCommand", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () {
|
|
23
|
+
return _useCommand.default;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "useCommandLoader", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _useCommandLoader.default;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
18
32
|
|
|
19
33
|
var _commandMenu = require("./components/command-menu");
|
|
20
34
|
|
|
21
35
|
var _privateApis = require("./private-apis");
|
|
36
|
+
|
|
37
|
+
var _useCommand = _interopRequireDefault(require("./hooks/use-command"));
|
|
38
|
+
|
|
39
|
+
var _useCommandLoader = _interopRequireDefault(require("./hooks/use-command-loader"));
|
|
22
40
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA","sourcesContent":["export { CommandMenu } from './components/command-menu';\nexport { privateApis } from './private-apis';\nexport { default as useCommand } from './hooks/use-command';\nexport { default as useCommandLoader } from './hooks/use-command-loader';\n"]}
|
package/build/private-apis.js
CHANGED
|
@@ -9,9 +9,7 @@ exports.unlock = exports.privateApis = exports.lock = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _privateApis = require("@wordpress/private-apis");
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _useCommandLoader = _interopRequireDefault(require("./hooks/use-command-loader"));
|
|
12
|
+
var _useCommandContext = _interopRequireDefault(require("./hooks/use-command-context"));
|
|
15
13
|
|
|
16
14
|
var _store = require("./store");
|
|
17
15
|
|
|
@@ -31,8 +29,7 @@ exports.lock = lock;
|
|
|
31
29
|
const privateApis = {};
|
|
32
30
|
exports.privateApis = privateApis;
|
|
33
31
|
lock(privateApis, {
|
|
34
|
-
|
|
35
|
-
useCommandLoader: _useCommandLoader.default,
|
|
32
|
+
useCommandContext: _useCommandContext.default,
|
|
36
33
|
store: _store.store
|
|
37
34
|
});
|
|
38
35
|
//# sourceMappingURL=private-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/commands/src/private-apis.js"],"names":["lock","unlock","privateApis","
|
|
1
|
+
{"version":3,"sources":["@wordpress/commands/src/private-apis.js"],"names":["lock","unlock","privateApis","useCommandContext","store"],"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,iBAAiB,EAAjBA,0BADkB;AAElBC,EAAAA,KAAK,EAALA;AAFkB,CAAf,CAAJ","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\n/**\n * Internal dependencies\n */\nimport { default as useCommandContext } from './hooks/use-command-context';\nimport { store } from './store';\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\tuseCommandContext,\n\tstore,\n} );\n"]}
|
package/build/store/actions.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.close = close;
|
|
|
7
7
|
exports.open = open;
|
|
8
8
|
exports.registerCommand = registerCommand;
|
|
9
9
|
exports.registerCommandLoader = registerCommandLoader;
|
|
10
|
+
exports.setContext = setContext;
|
|
10
11
|
exports.unregisterCommand = unregisterCommand;
|
|
11
12
|
exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
12
13
|
|
|
@@ -17,11 +18,12 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
17
18
|
*
|
|
18
19
|
* @typedef {Object} WPCommandConfig
|
|
19
20
|
*
|
|
20
|
-
* @property {string} name
|
|
21
|
-
* @property {string} label
|
|
22
|
-
* @property {string=}
|
|
23
|
-
* @property {
|
|
24
|
-
* @property {
|
|
21
|
+
* @property {string} name Command name.
|
|
22
|
+
* @property {string} label Command label.
|
|
23
|
+
* @property {string=} searchLabel Command search label.
|
|
24
|
+
* @property {string=} context Command context.
|
|
25
|
+
* @property {JSX.Element} icon Command icon.
|
|
26
|
+
* @property {Function} callback Command callback.
|
|
25
27
|
*/
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -33,9 +35,9 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
33
35
|
*
|
|
34
36
|
* @typedef {Object} WPCommandLoaderConfig
|
|
35
37
|
*
|
|
36
|
-
* @property {string} name
|
|
37
|
-
* @property {string=}
|
|
38
|
-
* @property {WPCommandLoaderHook} hook
|
|
38
|
+
* @property {string} name Command loader name.
|
|
39
|
+
* @property {string=} context Command loader context.
|
|
40
|
+
* @property {WPCommandLoaderHook} hook Command loader hook.
|
|
39
41
|
*/
|
|
40
42
|
|
|
41
43
|
/**
|
|
@@ -45,38 +47,25 @@ exports.unregisterCommandLoader = unregisterCommandLoader;
|
|
|
45
47
|
*
|
|
46
48
|
* @return {Object} action.
|
|
47
49
|
*/
|
|
48
|
-
function registerCommand(
|
|
49
|
-
let {
|
|
50
|
-
name,
|
|
51
|
-
label,
|
|
52
|
-
icon,
|
|
53
|
-
callback,
|
|
54
|
-
group = ''
|
|
55
|
-
} = _ref;
|
|
50
|
+
function registerCommand(config) {
|
|
56
51
|
return {
|
|
57
52
|
type: 'REGISTER_COMMAND',
|
|
58
|
-
|
|
59
|
-
label,
|
|
60
|
-
icon,
|
|
61
|
-
callback,
|
|
62
|
-
group
|
|
53
|
+
...config
|
|
63
54
|
};
|
|
64
55
|
}
|
|
65
56
|
/**
|
|
66
57
|
* Returns an action object used to unregister a command.
|
|
67
58
|
*
|
|
68
|
-
* @param {string} name
|
|
69
|
-
* @param {string} group Command group.
|
|
59
|
+
* @param {string} name Command name.
|
|
70
60
|
*
|
|
71
61
|
* @return {Object} action.
|
|
72
62
|
*/
|
|
73
63
|
|
|
74
64
|
|
|
75
|
-
function unregisterCommand(name
|
|
65
|
+
function unregisterCommand(name) {
|
|
76
66
|
return {
|
|
77
67
|
type: 'UNREGISTER_COMMAND',
|
|
78
|
-
name
|
|
79
|
-
group
|
|
68
|
+
name
|
|
80
69
|
};
|
|
81
70
|
}
|
|
82
71
|
/**
|
|
@@ -88,34 +77,25 @@ function unregisterCommand(name, group) {
|
|
|
88
77
|
*/
|
|
89
78
|
|
|
90
79
|
|
|
91
|
-
function registerCommandLoader(
|
|
92
|
-
let {
|
|
93
|
-
name,
|
|
94
|
-
group = '',
|
|
95
|
-
hook
|
|
96
|
-
} = _ref2;
|
|
80
|
+
function registerCommandLoader(config) {
|
|
97
81
|
return {
|
|
98
82
|
type: 'REGISTER_COMMAND_LOADER',
|
|
99
|
-
|
|
100
|
-
group,
|
|
101
|
-
hook
|
|
83
|
+
...config
|
|
102
84
|
};
|
|
103
85
|
}
|
|
104
86
|
/**
|
|
105
87
|
* Unregister command loader hook.
|
|
106
88
|
*
|
|
107
|
-
* @param {string} name
|
|
108
|
-
* @param {string} group Command loader group.
|
|
89
|
+
* @param {string} name Command loader name.
|
|
109
90
|
*
|
|
110
91
|
* @return {Object} action.
|
|
111
92
|
*/
|
|
112
93
|
|
|
113
94
|
|
|
114
|
-
function unregisterCommandLoader(name
|
|
95
|
+
function unregisterCommandLoader(name) {
|
|
115
96
|
return {
|
|
116
97
|
type: 'UNREGISTER_COMMAND_LOADER',
|
|
117
|
-
name
|
|
118
|
-
group
|
|
98
|
+
name
|
|
119
99
|
};
|
|
120
100
|
}
|
|
121
101
|
/**
|
|
@@ -142,4 +122,19 @@ function close() {
|
|
|
142
122
|
type: 'CLOSE'
|
|
143
123
|
};
|
|
144
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Sets the active context.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} context Context.
|
|
129
|
+
*
|
|
130
|
+
* @return {Object} action.
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
function setContext(context) {
|
|
135
|
+
return {
|
|
136
|
+
type: 'SET_CONTEXT',
|
|
137
|
+
context
|
|
138
|
+
};
|
|
139
|
+
}
|
|
145
140
|
//# sourceMappingURL=actions.js.map
|
|
@@ -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","setContext","context"],"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;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,UAAT,CAAqBC,OAArB,EAA+B;AACrC,SAAO;AACNR,IAAAA,IAAI,EAAE,aADA;AAENQ,IAAAA;AAFM,GAAP;AAIA","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\n/**\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"]}
|