@wordpress/core-commands 1.30.0 → 1.30.1-next.836ecdcae.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/README.md CHANGED
@@ -20,6 +20,10 @@ _This package assumes that your code will run in an **ES2015+** environment. If
20
20
 
21
21
  Initializes the Command Palette.
22
22
 
23
+ _Parameters_
24
+
25
+ - _settings_ `Object`: Command palette settings.
26
+
23
27
  ### privateApis
24
28
 
25
29
  Undocumented declaration.
@@ -6,177 +6,39 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useAdminNavigationCommands = useAdminNavigationCommands;
7
7
  var _commands = require("@wordpress/commands");
8
8
  var _i18n = require("@wordpress/i18n");
9
- var _icons = require("@wordpress/icons");
10
- var _url = require("@wordpress/url");
11
- var _coreData = require("@wordpress/core-data");
12
- var _data = require("@wordpress/data");
13
9
  var _element = require("@wordpress/element");
14
- var _notices = require("@wordpress/notices");
15
- var _router = require("@wordpress/router");
16
- var _lockUnlock = require("./lock-unlock");
17
10
  /**
18
11
  * WordPress dependencies
19
12
  */
20
13
 
21
- /**
22
- * Internal dependencies
23
- */
24
-
25
- const {
26
- useHistory
27
- } = (0, _lockUnlock.unlock)(_router.privateApis);
28
- const getAddNewPageCommand = () => function useAddNewPageCommand() {
29
- const canCreatePage = (0, _data.useSelect)(select => select(_coreData.store).canUser('create', {
30
- kind: 'postType',
31
- name: 'page'
32
- }), []);
33
- const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
34
- const history = useHistory();
35
- const isBlockBasedTheme = (0, _data.useSelect)(select => {
36
- return select(_coreData.store).getCurrentTheme()?.is_block_theme;
37
- }, []);
38
- const {
39
- saveEntityRecord
40
- } = (0, _data.useDispatch)(_coreData.store);
41
- const {
42
- createErrorNotice
43
- } = (0, _data.useDispatch)(_notices.store);
44
- const createPageEntity = (0, _element.useCallback)(async ({
45
- close
46
- }) => {
47
- try {
48
- const page = await saveEntityRecord('postType', 'page', {
49
- status: 'draft'
50
- }, {
51
- throwOnError: true
52
- });
53
- if (page?.id) {
54
- history.navigate(`/page/${page.id}?canvas=edit`);
55
- }
56
- } catch (error) {
57
- const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while creating the item.');
58
- createErrorNotice(errorMessage, {
59
- type: 'snackbar'
60
- });
61
- } finally {
62
- close();
63
- }
64
- }, [createErrorNotice, history, saveEntityRecord]);
14
+ const getAdminNavigationCommands = menuCommands => function useAdminBasicNavigationCommands() {
65
15
  const commands = (0, _element.useMemo)(() => {
66
- if (!canCreatePage) {
67
- return [];
68
- }
69
- const addNewPage = isSiteEditor && isBlockBasedTheme ? createPageEntity : () => document.location.href = 'post-new.php?post_type=page';
70
- return [{
71
- name: 'core/add-new-page',
72
- label: (0, _i18n.__)('Add Page'),
73
- icon: _icons.plus,
74
- callback: addNewPage,
75
- keywords: [(0, _i18n.__)('page'), (0, _i18n.__)('new'), (0, _i18n.__)('add'), (0, _i18n.__)('create')]
76
- }];
77
- }, [createPageEntity, isSiteEditor, isBlockBasedTheme, canCreatePage]);
78
- return {
79
- isLoading: false,
80
- commands
81
- };
82
- };
83
- const getAdminBasicNavigationCommands = () => function useAdminBasicNavigationCommands() {
84
- const {
85
- isBlockBasedTheme,
86
- canCreateTemplate
87
- } = (0, _data.useSelect)(select => {
88
- return {
89
- isBlockBasedTheme: select(_coreData.store).getCurrentTheme()?.is_block_theme,
90
- canCreateTemplate: select(_coreData.store).canUser('create', {
91
- kind: 'postType',
92
- name: 'wp_template'
93
- })
94
- };
16
+ return (menuCommands !== null && menuCommands !== void 0 ? menuCommands : []).map(menuCommand => {
17
+ const label = (0, _i18n.sprintf)(/* translators: %s: menu label */
18
+ (0, _i18n.__)('Go to: %s'), menuCommand.label);
19
+ return {
20
+ label,
21
+ searchLabel: label,
22
+ name: menuCommand.name,
23
+ url: menuCommand.url,
24
+ callback: ({
25
+ close
26
+ }) => {
27
+ document.location = menuCommand.url;
28
+ close();
29
+ }
30
+ };
31
+ });
95
32
  }, []);
96
- const commands = (0, _element.useMemo)(() => {
97
- if (canCreateTemplate && isBlockBasedTheme) {
98
- const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
99
- if (!isSiteEditor) {
100
- return [{
101
- name: 'core/go-to-site-editor',
102
- label: (0, _i18n.__)('Open Site Editor'),
103
- callback: ({
104
- close
105
- }) => {
106
- close();
107
- document.location = 'site-editor.php';
108
- }
109
- }];
110
- }
111
- }
112
- return [];
113
- }, [canCreateTemplate, isBlockBasedTheme]);
114
33
  return {
115
34
  commands,
116
35
  isLoading: false
117
36
  };
118
37
  };
119
- const getDashboardCommand = () => function useDashboardCommand() {
120
- const currentPath = (0, _url.getPath)(window.location.href);
121
- const isEditorScreen = currentPath?.includes('site-editor.php') || currentPath?.includes('post.php') || currentPath?.includes('post-new.php') || currentPath?.includes('widgets.php') || currentPath?.includes('customize.php');
122
- const commands = (0, _element.useMemo)(() => {
123
- if (isEditorScreen) {
124
- return [{
125
- name: 'core/dashboard',
126
- label: (0, _i18n.__)('Dashboard'),
127
- icon: _icons.dashboard,
128
- callback: () => {
129
- document.location.assign('index.php');
130
- }
131
- }];
132
- }
133
- return [];
134
- }, [isEditorScreen]);
135
- return {
136
- isLoading: false,
137
- commands
138
- };
139
- };
140
- const getAddNewPostCommand = () => function useAddNewPostCommand() {
141
- const canCreatePost = (0, _data.useSelect)(select => select(_coreData.store).canUser('create', {
142
- kind: 'postType',
143
- name: 'post'
144
- }), []);
145
- const commands = (0, _element.useMemo)(() => {
146
- if (!canCreatePost) {
147
- return [];
148
- }
149
- return [{
150
- name: 'core/add-new-post',
151
- label: (0, _i18n.__)('Add Post'),
152
- icon: _icons.plus,
153
- callback: () => {
154
- document.location.assign('post-new.php');
155
- },
156
- keywords: [(0, _i18n.__)('post'), (0, _i18n.__)('new'), (0, _i18n.__)('add'), (0, _i18n.__)('create')]
157
- }];
158
- }, [canCreatePost]);
159
- return {
160
- isLoading: false,
161
- commands
162
- };
163
- };
164
- function useAdminNavigationCommands() {
165
- (0, _commands.useCommandLoader)({
166
- name: 'core/add-new-post',
167
- hook: getAddNewPostCommand()
168
- });
169
- (0, _commands.useCommandLoader)({
170
- name: 'core/dashboard',
171
- hook: getDashboardCommand()
172
- });
173
- (0, _commands.useCommandLoader)({
174
- name: 'core/add-new-page',
175
- hook: getAddNewPageCommand()
176
- });
38
+ function useAdminNavigationCommands(menuCommands) {
177
39
  (0, _commands.useCommandLoader)({
178
40
  name: 'core/admin-navigation',
179
- hook: getAdminBasicNavigationCommands()
41
+ hook: getAdminNavigationCommands(menuCommands)
180
42
  });
181
43
  }
182
44
  //# sourceMappingURL=admin-navigation-commands.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_commands","require","_i18n","_icons","_url","_coreData","_data","_element","_notices","_router","_lockUnlock","useHistory","unlock","routerPrivateApis","getAddNewPageCommand","useAddNewPageCommand","canCreatePage","useSelect","select","coreStore","canUser","kind","name","isSiteEditor","getPath","window","location","href","includes","history","isBlockBasedTheme","getCurrentTheme","is_block_theme","saveEntityRecord","useDispatch","createErrorNotice","noticesStore","createPageEntity","useCallback","close","page","status","throwOnError","id","navigate","error","errorMessage","message","code","__","type","commands","useMemo","addNewPage","document","label","icon","plus","callback","keywords","isLoading","getAdminBasicNavigationCommands","useAdminBasicNavigationCommands","canCreateTemplate","getDashboardCommand","useDashboardCommand","currentPath","isEditorScreen","dashboard","assign","getAddNewPostCommand","useAddNewPostCommand","canCreatePost","useAdminNavigationCommands","useCommandLoader","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus, dashboard } from '@wordpress/icons';\nimport { getPath } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst getAddNewPageCommand = () =>\n\tfunction useAddNewPageCommand() {\n\t\tconst canCreatePage = useSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'page',\n\t\t\t\t} ),\n\t\t\t[]\n\t\t);\n\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t'site-editor.php'\n\t\t);\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useSelect( ( select ) => {\n\t\t\treturn select( coreStore ).getCurrentTheme()?.is_block_theme;\n\t\t}, [] );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\t\tconst createPageEntity = useCallback(\n\t\t\tasync ( { close } ) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await saveEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'page',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 'draft',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tif ( page?.id ) {\n\t\t\t\t\t\thistory.navigate( `/page/${ page.id }?canvas=edit` );\n\t\t\t\t\t}\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while creating the item.'\n\t\t\t\t\t\t\t );\n\n\t\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t} );\n\t\t\t\t} finally {\n\t\t\t\t\tclose();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ createErrorNotice, history, saveEntityRecord ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( ! canCreatePage ) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tconst addNewPage =\n\t\t\t\tisSiteEditor && isBlockBasedTheme\n\t\t\t\t\t? createPageEntity\n\t\t\t\t\t: () =>\n\t\t\t\t\t\t\t( document.location.href =\n\t\t\t\t\t\t\t\t'post-new.php?post_type=page' );\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tname: 'core/add-new-page',\n\t\t\t\t\tlabel: __( 'Add Page' ),\n\t\t\t\t\ticon: plus,\n\t\t\t\t\tcallback: addNewPage,\n\t\t\t\t\tkeywords: [\n\t\t\t\t\t\t__( 'page' ),\n\t\t\t\t\t\t__( 'new' ),\n\t\t\t\t\t\t__( 'add' ),\n\t\t\t\t\t\t__( 'create' ),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t}, [\n\t\t\tcreatePageEntity,\n\t\t\tisSiteEditor,\n\t\t\tisBlockBasedTheme,\n\t\t\tcanCreatePage,\n\t\t] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nconst getAdminBasicNavigationCommands = () =>\n\tfunction useAdminBasicNavigationCommands() {\n\t\tconst { isBlockBasedTheme, canCreateTemplate } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\treturn {\n\t\t\t\t\tisBlockBasedTheme:\n\t\t\t\t\t\tselect( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t\t\t\tcanCreateTemplate: select( coreStore ).canUser( 'create', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template',\n\t\t\t\t\t} ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( canCreateTemplate && isBlockBasedTheme ) {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tif ( ! isSiteEditor ) {\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'core/go-to-site-editor',\n\t\t\t\t\t\t\tlabel: __( 'Open Site Editor' ),\n\t\t\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t\t\tdocument.location = 'site-editor.php';\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn [];\n\t\t}, [ canCreateTemplate, isBlockBasedTheme ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading: false,\n\t\t};\n\t};\n\nconst getDashboardCommand = () =>\n\tfunction useDashboardCommand() {\n\t\tconst currentPath = getPath( window.location.href );\n\n\t\tconst isEditorScreen =\n\t\t\tcurrentPath?.includes( 'site-editor.php' ) ||\n\t\t\tcurrentPath?.includes( 'post.php' ) ||\n\t\t\tcurrentPath?.includes( 'post-new.php' ) ||\n\t\t\tcurrentPath?.includes( 'widgets.php' ) ||\n\t\t\tcurrentPath?.includes( 'customize.php' );\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( isEditorScreen ) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/dashboard',\n\t\t\t\t\t\tlabel: __( 'Dashboard' ),\n\t\t\t\t\t\ticon: dashboard,\n\t\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\t\tdocument.location.assign( 'index.php' );\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn [];\n\t\t}, [ isEditorScreen ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nconst getAddNewPostCommand = () =>\n\tfunction useAddNewPostCommand() {\n\t\tconst canCreatePost = useSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'post',\n\t\t\t\t} ),\n\t\t\t[]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( ! canCreatePost ) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tname: 'core/add-new-post',\n\t\t\t\t\tlabel: __( 'Add Post' ),\n\t\t\t\t\ticon: plus,\n\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t\t\t\t},\n\t\t\t\t\tkeywords: [\n\t\t\t\t\t\t__( 'post' ),\n\t\t\t\t\t\t__( 'new' ),\n\t\t\t\t\t\t__( 'add' ),\n\t\t\t\t\t\t__( 'create' ),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t}, [ canCreatePost ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-post',\n\t\thook: getAddNewPostCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/dashboard',\n\t\thook: getDashboardCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-page',\n\t\thook: getAddNewPageCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/admin-navigation',\n\t\thook: getAdminBasicNavigationCommands(),\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,G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cAAe,CAAC;MAC3C,CAAC;MACDV,QAAQ,EAAE,CACT,IAAAV,QAAE,EAAE,MAAO,CAAC,EACZ,IAAAA,QAAE,EAAE,KAAM,CAAC,EACX,IAAAA,QAAE,EAAE,KAAM,CAAC,EACX,IAAAA,QAAE,EAAE,QAAS,CAAC;IAEhB,CAAC,CACD;EACF,CAAC,EAAE,CAAEuB,aAAa,CAAG,CAAC;EAEtB,OAAO;IACNZ,SAAS,EAAE,KAAK;IAChBT;EACD,CAAC;AACF,CAAC;AAEK,SAASsB,0BAA0BA,CAAA,EAAG;EAC5C,IAAAC,0BAAgB,EAAE;IACjBpD,IAAI,EAAE,mBAAmB;IACzBqD,IAAI,EAAEL,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEH,IAAAI,0BAAgB,EAAE;IACjBpD,IAAI,EAAE,gBAAgB;IACtBqD,IAAI,EAAEX,mBAAmB,CAAC;EAC3B,CAAE,CAAC;EAEH,IAAAU,0BAAgB,EAAE;IACjBpD,IAAI,EAAE,mBAAmB;IACzBqD,IAAI,EAAE7D,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEH,IAAA4D,0BAAgB,EAAE;IACjBpD,IAAI,EAAE,uBAAuB;IAC7BqD,IAAI,EAAEd,+BAA+B,CAAC;EACvC,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_commands","require","_i18n","_element","getAdminNavigationCommands","menuCommands","useAdminBasicNavigationCommands","commands","useMemo","map","menuCommand","label","sprintf","__","searchLabel","name","url","callback","close","document","location","isLoading","useAdminNavigationCommands","useCommandLoader","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\n\nconst getAdminNavigationCommands = ( menuCommands ) =>\n\tfunction useAdminBasicNavigationCommands() {\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( menuCommands ?? [] ).map( ( menuCommand ) => {\n\t\t\t\tconst label = sprintf(\n\t\t\t\t\t/* translators: %s: menu label */\n\t\t\t\t\t__( 'Go to: %s' ),\n\t\t\t\t\tmenuCommand.label\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tlabel,\n\t\t\t\t\tsearchLabel: label,\n\t\t\t\t\tname: menuCommand.name,\n\t\t\t\t\turl: menuCommand.url,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tdocument.location = menuCommand.url;\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading: false,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands( menuCommands ) {\n\tuseCommandLoader( {\n\t\tname: 'core/admin-navigation',\n\t\thook: getAdminNavigationCommands( menuCommands ),\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKA,MAAMG,0BAA0B,GAAKC,YAAY,IAChD,SAASC,+BAA+BA,CAAA,EAAG;EAC1C,MAAMC,QAAQ,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC/B,OAAO,CAAEH,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,EAAE,EAAGI,GAAG,CAAIC,WAAW,IAAM;MACrD,MAAMC,KAAK,GAAG,IAAAC,aAAO,EACpB;MACA,IAAAC,QAAE,EAAE,WAAY,CAAC,EACjBH,WAAW,CAACC,KACb,CAAC;MACD,OAAO;QACNA,KAAK;QACLG,WAAW,EAAEH,KAAK;QAClBI,IAAI,EAAEL,WAAW,CAACK,IAAI;QACtBC,GAAG,EAAEN,WAAW,CAACM,GAAG;QACpBC,QAAQ,EAAEA,CAAE;UAAEC;QAAM,CAAC,KAAM;UAC1BC,QAAQ,CAACC,QAAQ,GAAGV,WAAW,CAACM,GAAG;UACnCE,KAAK,CAAC,CAAC;QACR;MACD,CAAC;IACF,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO;IACNX,QAAQ;IACRc,SAAS,EAAE;EACZ,CAAC;AACF,CAAC;AAEK,SAASC,0BAA0BA,CAAEjB,YAAY,EAAG;EAC1D,IAAAkB,0BAAgB,EAAE;IACjBR,IAAI,EAAE,uBAAuB;IAC7BS,IAAI,EAAEpB,0BAA0B,CAAEC,YAAa;EAChD,CAAE,CAAC;AACJ","ignoreList":[]}
package/build/index.js CHANGED
@@ -31,8 +31,13 @@ const {
31
31
  } = (0, _lockUnlock.unlock)(_router.privateApis);
32
32
 
33
33
  // Register core commands and render the Command Palette.
34
- function CommandPalette() {
35
- (0, _adminNavigationCommands.useAdminNavigationCommands)();
34
+ function CommandPalette({
35
+ settings
36
+ }) {
37
+ const {
38
+ menu_commands: menuCommands
39
+ } = settings;
40
+ (0, _adminNavigationCommands.useAdminNavigationCommands)(menuCommands);
36
41
  (0, _siteEditorNavigationCommands.useSiteEditorNavigationCommands)();
37
42
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(RouterProvider, {
38
43
  pathArg: "p",
@@ -42,12 +47,16 @@ function CommandPalette() {
42
47
 
43
48
  /**
44
49
  * Initializes the Command Palette.
50
+ *
51
+ * @param {Object} settings Command palette settings.
45
52
  */
46
- function initializeCommandPalette() {
53
+ function initializeCommandPalette(settings) {
47
54
  const root = document.createElement('div');
48
55
  document.body.appendChild(root);
49
56
  (0, _element.createRoot)(root).render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_element.StrictMode, {
50
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CommandPalette, {})
57
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CommandPalette, {
58
+ settings: settings
59
+ })
51
60
  }));
52
61
  }
53
62
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_router","_commands","_adminNavigationCommands","_siteEditorNavigationCommands","_lockUnlock","_jsxRuntime","_privateApis","RouterProvider","unlock","routerPrivateApis","CommandPalette","useAdminNavigationCommands","useSiteEditorNavigationCommands","jsx","pathArg","children","CommandMenu","initializeCommandPalette","root","document","createElement","body","appendChild","createRoot","render","StrictMode"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { CommandMenu } from '@wordpress/commands';\n\n/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { unlock } from './lock-unlock';\nexport { privateApis } from './private-apis';\n\nconst { RouterProvider } = unlock( routerPrivateApis );\n\n// Register core commands and render the Command Palette.\nfunction CommandPalette() {\n\tuseAdminNavigationCommands();\n\tuseSiteEditorNavigationCommands();\n\treturn (\n\t\t<RouterProvider pathArg=\"p\">\n\t\t\t<CommandMenu />\n\t\t</RouterProvider>\n\t);\n}\n\n/**\n * Initializes the Command Palette.\n */\nexport function initializeCommandPalette() {\n\tconst root = document.createElement( 'div' );\n\tdocument.body.appendChild( root );\n\tcreateRoot( root ).render(\n\t\t<StrictMode>\n\t\t\t<CommandPalette />\n\t\t</StrictMode>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAAuC,IAAAM,WAAA,GAAAN,OAAA;AACvC,IAAAO,YAAA,GAAAP,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMA,MAAM;EAAEQ;AAAe,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;;AAEtD;AACA,SAASC,cAAcA,CAAA,EAAG;EACzB,IAAAC,mDAA0B,EAAC,CAAC;EAC5B,IAAAC,6DAA+B,EAAC,CAAC;EACjC,oBACC,IAAAP,WAAA,CAAAQ,GAAA,EAACN,cAAc;IAACO,OAAO,EAAC,GAAG;IAAAC,QAAA,eAC1B,IAAAV,WAAA,CAAAQ,GAAA,EAACZ,SAAA,CAAAe,WAAW,IAAE;EAAC,CACA,CAAC;AAEnB;;AAEA;AACA;AACA;AACO,SAASC,wBAAwBA,CAAA,EAAG;EAC1C,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAE,KAAM,CAAC;EAC5CD,QAAQ,CAACE,IAAI,CAACC,WAAW,CAAEJ,IAAK,CAAC;EACjC,IAAAK,mBAAU,EAAEL,IAAK,CAAC,CAACM,MAAM,cACxB,IAAAnB,WAAA,CAAAQ,GAAA,EAACf,QAAA,CAAA2B,UAAU;IAAAV,QAAA,eACV,IAAAV,WAAA,CAAAQ,GAAA,EAACH,cAAc,IAAE;EAAC,CACP,CACb,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_router","_commands","_adminNavigationCommands","_siteEditorNavigationCommands","_lockUnlock","_jsxRuntime","_privateApis","RouterProvider","unlock","routerPrivateApis","CommandPalette","settings","menu_commands","menuCommands","useAdminNavigationCommands","useSiteEditorNavigationCommands","jsx","pathArg","children","CommandMenu","initializeCommandPalette","root","document","createElement","body","appendChild","createRoot","render","StrictMode"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { CommandMenu } from '@wordpress/commands';\n\n/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { unlock } from './lock-unlock';\nexport { privateApis } from './private-apis';\n\nconst { RouterProvider } = unlock( routerPrivateApis );\n\n// Register core commands and render the Command Palette.\nfunction CommandPalette( { settings } ) {\n\tconst { menu_commands: menuCommands } = settings;\n\tuseAdminNavigationCommands( menuCommands );\n\tuseSiteEditorNavigationCommands();\n\treturn (\n\t\t<RouterProvider pathArg=\"p\">\n\t\t\t<CommandMenu />\n\t\t</RouterProvider>\n\t);\n}\n\n/**\n * Initializes the Command Palette.\n *\n * @param {Object} settings Command palette settings.\n */\nexport function initializeCommandPalette( settings ) {\n\tconst root = document.createElement( 'div' );\n\tdocument.body.appendChild( root );\n\tcreateRoot( root ).render(\n\t\t<StrictMode>\n\t\t\t<CommandPalette settings={ settings } />\n\t\t</StrictMode>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAKA,IAAAG,wBAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAAuC,IAAAM,WAAA,GAAAN,OAAA;AACvC,IAAAO,YAAA,GAAAP,OAAA;AAbA;AACA;AACA;;AAKA;AACA;AACA;;AAMA,MAAM;EAAEQ;AAAe,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;;AAEtD;AACA,SAASC,cAAcA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACvC,MAAM;IAAEC,aAAa,EAAEC;EAAa,CAAC,GAAGF,QAAQ;EAChD,IAAAG,mDAA0B,EAAED,YAAa,CAAC;EAC1C,IAAAE,6DAA+B,EAAC,CAAC;EACjC,oBACC,IAAAV,WAAA,CAAAW,GAAA,EAACT,cAAc;IAACU,OAAO,EAAC,GAAG;IAAAC,QAAA,eAC1B,IAAAb,WAAA,CAAAW,GAAA,EAACf,SAAA,CAAAkB,WAAW,IAAE;EAAC,CACA,CAAC;AAEnB;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,wBAAwBA,CAAET,QAAQ,EAAG;EACpD,MAAMU,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAE,KAAM,CAAC;EAC5CD,QAAQ,CAACE,IAAI,CAACC,WAAW,CAAEJ,IAAK,CAAC;EACjC,IAAAK,mBAAU,EAAEL,IAAK,CAAC,CAACM,MAAM,cACxB,IAAAtB,WAAA,CAAAW,GAAA,EAAClB,QAAA,CAAA8B,UAAU;IAAAV,QAAA,eACV,IAAAb,WAAA,CAAAW,GAAA,EAACN,cAAc;MAACC,QAAQ,EAAGA;IAAU,CAAE;EAAC,CAC7B,CACb,CAAC;AACF","ignoreList":[]}
@@ -2,174 +2,36 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useCommandLoader } from '@wordpress/commands';
5
- import { __ } from '@wordpress/i18n';
6
- import { plus, dashboard } from '@wordpress/icons';
7
- import { getPath } from '@wordpress/url';
8
- import { store as coreStore } from '@wordpress/core-data';
9
- import { useSelect, useDispatch } from '@wordpress/data';
10
- import { useCallback, useMemo } from '@wordpress/element';
11
- import { store as noticesStore } from '@wordpress/notices';
12
- import { privateApis as routerPrivateApis } from '@wordpress/router';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import { unlock } from './lock-unlock';
18
- const {
19
- useHistory
20
- } = unlock(routerPrivateApis);
21
- const getAddNewPageCommand = () => function useAddNewPageCommand() {
22
- const canCreatePage = useSelect(select => select(coreStore).canUser('create', {
23
- kind: 'postType',
24
- name: 'page'
25
- }), []);
26
- const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
27
- const history = useHistory();
28
- const isBlockBasedTheme = useSelect(select => {
29
- return select(coreStore).getCurrentTheme()?.is_block_theme;
30
- }, []);
31
- const {
32
- saveEntityRecord
33
- } = useDispatch(coreStore);
34
- const {
35
- createErrorNotice
36
- } = useDispatch(noticesStore);
37
- const createPageEntity = useCallback(async ({
38
- close
39
- }) => {
40
- try {
41
- const page = await saveEntityRecord('postType', 'page', {
42
- status: 'draft'
43
- }, {
44
- throwOnError: true
45
- });
46
- if (page?.id) {
47
- history.navigate(`/page/${page.id}?canvas=edit`);
48
- }
49
- } catch (error) {
50
- const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the item.');
51
- createErrorNotice(errorMessage, {
52
- type: 'snackbar'
53
- });
54
- } finally {
55
- close();
56
- }
57
- }, [createErrorNotice, history, saveEntityRecord]);
5
+ import { __, sprintf } from '@wordpress/i18n';
6
+ import { useMemo } from '@wordpress/element';
7
+ const getAdminNavigationCommands = menuCommands => function useAdminBasicNavigationCommands() {
58
8
  const commands = useMemo(() => {
59
- if (!canCreatePage) {
60
- return [];
61
- }
62
- const addNewPage = isSiteEditor && isBlockBasedTheme ? createPageEntity : () => document.location.href = 'post-new.php?post_type=page';
63
- return [{
64
- name: 'core/add-new-page',
65
- label: __('Add Page'),
66
- icon: plus,
67
- callback: addNewPage,
68
- keywords: [__('page'), __('new'), __('add'), __('create')]
69
- }];
70
- }, [createPageEntity, isSiteEditor, isBlockBasedTheme, canCreatePage]);
71
- return {
72
- isLoading: false,
73
- commands
74
- };
75
- };
76
- const getAdminBasicNavigationCommands = () => function useAdminBasicNavigationCommands() {
77
- const {
78
- isBlockBasedTheme,
79
- canCreateTemplate
80
- } = useSelect(select => {
81
- return {
82
- isBlockBasedTheme: select(coreStore).getCurrentTheme()?.is_block_theme,
83
- canCreateTemplate: select(coreStore).canUser('create', {
84
- kind: 'postType',
85
- name: 'wp_template'
86
- })
87
- };
9
+ return (menuCommands !== null && menuCommands !== void 0 ? menuCommands : []).map(menuCommand => {
10
+ const label = sprintf(/* translators: %s: menu label */
11
+ __('Go to: %s'), menuCommand.label);
12
+ return {
13
+ label,
14
+ searchLabel: label,
15
+ name: menuCommand.name,
16
+ url: menuCommand.url,
17
+ callback: ({
18
+ close
19
+ }) => {
20
+ document.location = menuCommand.url;
21
+ close();
22
+ }
23
+ };
24
+ });
88
25
  }, []);
89
- const commands = useMemo(() => {
90
- if (canCreateTemplate && isBlockBasedTheme) {
91
- const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
92
- if (!isSiteEditor) {
93
- return [{
94
- name: 'core/go-to-site-editor',
95
- label: __('Open Site Editor'),
96
- callback: ({
97
- close
98
- }) => {
99
- close();
100
- document.location = 'site-editor.php';
101
- }
102
- }];
103
- }
104
- }
105
- return [];
106
- }, [canCreateTemplate, isBlockBasedTheme]);
107
26
  return {
108
27
  commands,
109
28
  isLoading: false
110
29
  };
111
30
  };
112
- const getDashboardCommand = () => function useDashboardCommand() {
113
- const currentPath = getPath(window.location.href);
114
- const isEditorScreen = currentPath?.includes('site-editor.php') || currentPath?.includes('post.php') || currentPath?.includes('post-new.php') || currentPath?.includes('widgets.php') || currentPath?.includes('customize.php');
115
- const commands = useMemo(() => {
116
- if (isEditorScreen) {
117
- return [{
118
- name: 'core/dashboard',
119
- label: __('Dashboard'),
120
- icon: dashboard,
121
- callback: () => {
122
- document.location.assign('index.php');
123
- }
124
- }];
125
- }
126
- return [];
127
- }, [isEditorScreen]);
128
- return {
129
- isLoading: false,
130
- commands
131
- };
132
- };
133
- const getAddNewPostCommand = () => function useAddNewPostCommand() {
134
- const canCreatePost = useSelect(select => select(coreStore).canUser('create', {
135
- kind: 'postType',
136
- name: 'post'
137
- }), []);
138
- const commands = useMemo(() => {
139
- if (!canCreatePost) {
140
- return [];
141
- }
142
- return [{
143
- name: 'core/add-new-post',
144
- label: __('Add Post'),
145
- icon: plus,
146
- callback: () => {
147
- document.location.assign('post-new.php');
148
- },
149
- keywords: [__('post'), __('new'), __('add'), __('create')]
150
- }];
151
- }, [canCreatePost]);
152
- return {
153
- isLoading: false,
154
- commands
155
- };
156
- };
157
- export function useAdminNavigationCommands() {
158
- useCommandLoader({
159
- name: 'core/add-new-post',
160
- hook: getAddNewPostCommand()
161
- });
162
- useCommandLoader({
163
- name: 'core/dashboard',
164
- hook: getDashboardCommand()
165
- });
166
- useCommandLoader({
167
- name: 'core/add-new-page',
168
- hook: getAddNewPageCommand()
169
- });
31
+ export function useAdminNavigationCommands(menuCommands) {
170
32
  useCommandLoader({
171
33
  name: 'core/admin-navigation',
172
- hook: getAdminBasicNavigationCommands()
34
+ hook: getAdminNavigationCommands(menuCommands)
173
35
  });
174
36
  }
175
37
  //# sourceMappingURL=admin-navigation-commands.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCommandLoader","__","plus","dashboard","getPath","store","coreStore","useSelect","useDispatch","useCallback","useMemo","noticesStore","privateApis","routerPrivateApis","unlock","useHistory","getAddNewPageCommand","useAddNewPageCommand","canCreatePage","select","canUser","kind","name","isSiteEditor","window","location","href","includes","history","isBlockBasedTheme","getCurrentTheme","is_block_theme","saveEntityRecord","createErrorNotice","createPageEntity","close","page","status","throwOnError","id","navigate","error","errorMessage","message","code","type","commands","addNewPage","document","label","icon","callback","keywords","isLoading","getAdminBasicNavigationCommands","useAdminBasicNavigationCommands","canCreateTemplate","getDashboardCommand","useDashboardCommand","currentPath","isEditorScreen","assign","getAddNewPostCommand","useAddNewPostCommand","canCreatePost","useAdminNavigationCommands","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus, dashboard } from '@wordpress/icons';\nimport { getPath } from '@wordpress/url';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst getAddNewPageCommand = () =>\n\tfunction useAddNewPageCommand() {\n\t\tconst canCreatePage = useSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'page',\n\t\t\t\t} ),\n\t\t\t[]\n\t\t);\n\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t'site-editor.php'\n\t\t);\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useSelect( ( select ) => {\n\t\t\treturn select( coreStore ).getCurrentTheme()?.is_block_theme;\n\t\t}, [] );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\t\tconst createPageEntity = useCallback(\n\t\t\tasync ( { close } ) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst page = await saveEntityRecord(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'page',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tstatus: 'draft',\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tif ( page?.id ) {\n\t\t\t\t\t\thistory.navigate( `/page/${ page.id }?canvas=edit` );\n\t\t\t\t\t}\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: __(\n\t\t\t\t\t\t\t\t\t'An error occurred while creating the item.'\n\t\t\t\t\t\t\t );\n\n\t\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t} );\n\t\t\t\t} finally {\n\t\t\t\t\tclose();\n\t\t\t\t}\n\t\t\t},\n\t\t\t[ createErrorNotice, history, saveEntityRecord ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( ! canCreatePage ) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tconst addNewPage =\n\t\t\t\tisSiteEditor && isBlockBasedTheme\n\t\t\t\t\t? createPageEntity\n\t\t\t\t\t: () =>\n\t\t\t\t\t\t\t( document.location.href =\n\t\t\t\t\t\t\t\t'post-new.php?post_type=page' );\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tname: 'core/add-new-page',\n\t\t\t\t\tlabel: __( 'Add Page' ),\n\t\t\t\t\ticon: plus,\n\t\t\t\t\tcallback: addNewPage,\n\t\t\t\t\tkeywords: [\n\t\t\t\t\t\t__( 'page' ),\n\t\t\t\t\t\t__( 'new' ),\n\t\t\t\t\t\t__( 'add' ),\n\t\t\t\t\t\t__( 'create' ),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t}, [\n\t\t\tcreatePageEntity,\n\t\t\tisSiteEditor,\n\t\t\tisBlockBasedTheme,\n\t\t\tcanCreatePage,\n\t\t] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nconst getAdminBasicNavigationCommands = () =>\n\tfunction useAdminBasicNavigationCommands() {\n\t\tconst { isBlockBasedTheme, canCreateTemplate } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\treturn {\n\t\t\t\t\tisBlockBasedTheme:\n\t\t\t\t\t\tselect( coreStore ).getCurrentTheme()?.is_block_theme,\n\t\t\t\t\tcanCreateTemplate: select( coreStore ).canUser( 'create', {\n\t\t\t\t\t\tkind: 'postType',\n\t\t\t\t\t\tname: 'wp_template',\n\t\t\t\t\t} ),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( canCreateTemplate && isBlockBasedTheme ) {\n\t\t\t\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t\t\t\t'site-editor.php'\n\t\t\t\t);\n\t\t\t\tif ( ! isSiteEditor ) {\n\t\t\t\t\treturn [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: 'core/go-to-site-editor',\n\t\t\t\t\t\t\tlabel: __( 'Open Site Editor' ),\n\t\t\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t\t\tdocument.location = 'site-editor.php';\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn [];\n\t\t}, [ canCreateTemplate, isBlockBasedTheme ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading: false,\n\t\t};\n\t};\n\nconst getDashboardCommand = () =>\n\tfunction useDashboardCommand() {\n\t\tconst currentPath = getPath( window.location.href );\n\n\t\tconst isEditorScreen =\n\t\t\tcurrentPath?.includes( 'site-editor.php' ) ||\n\t\t\tcurrentPath?.includes( 'post.php' ) ||\n\t\t\tcurrentPath?.includes( 'post-new.php' ) ||\n\t\t\tcurrentPath?.includes( 'widgets.php' ) ||\n\t\t\tcurrentPath?.includes( 'customize.php' );\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( isEditorScreen ) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'core/dashboard',\n\t\t\t\t\t\tlabel: __( 'Dashboard' ),\n\t\t\t\t\t\ticon: dashboard,\n\t\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\t\tdocument.location.assign( 'index.php' );\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\t\t\treturn [];\n\t\t}, [ isEditorScreen ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nconst getAddNewPostCommand = () =>\n\tfunction useAddNewPostCommand() {\n\t\tconst canCreatePost = useSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).canUser( 'create', {\n\t\t\t\t\tkind: 'postType',\n\t\t\t\t\tname: 'post',\n\t\t\t\t} ),\n\t\t\t[]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif ( ! canCreatePost ) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tname: 'core/add-new-post',\n\t\t\t\t\tlabel: __( 'Add Post' ),\n\t\t\t\t\ticon: plus,\n\t\t\t\t\tcallback: () => {\n\t\t\t\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t\t\t\t},\n\t\t\t\t\tkeywords: [\n\t\t\t\t\t\t__( 'post' ),\n\t\t\t\t\t\t__( 'new' ),\n\t\t\t\t\t\t__( 'add' ),\n\t\t\t\t\t\t__( 'create' ),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t}, [ canCreatePost ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-post',\n\t\thook: getAddNewPostCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/dashboard',\n\t\thook: getDashboardCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-page',\n\t\thook: getAddNewPageCommand(),\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/admin-navigation',\n\t\thook: getAdminBasicNavigationCommands(),\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,IAAI,EAAEC,SAAS,QAAQ,kBAAkB;AAClD,SAASC,OAAO,QAAQ,gBAAgB;AACxC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;AACzD,SAASL,KAAK,IAAIM,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;;AAEpE;AACA;AACA;AACA,SAASC,MAAM,QAAQ,eAAe;AAEtC,MAAM;EAAEC;AAAW,CAAC,GAAGD,M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BAA0BA,CAAA,EAAG;EAC5CjE,gBAAgB,CAAE;IACjBsB,IAAI,EAAE,mBAAmB;IACzB4C,IAAI,EAAEJ,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEH9D,gBAAgB,CAAE;IACjBsB,IAAI,EAAE,gBAAgB;IACtB4C,IAAI,EAAET,mBAAmB,CAAC;EAC3B,CAAE,CAAC;EAEHzD,gBAAgB,CAAE;IACjBsB,IAAI,EAAE,mBAAmB;IACzB4C,IAAI,EAAElD,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEHhB,gBAAgB,CAAE;IACjBsB,IAAI,EAAE,uBAAuB;IAC7B4C,IAAI,EAAEZ,+BAA+B,CAAC;EACvC,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["useCommandLoader","__","sprintf","useMemo","getAdminNavigationCommands","menuCommands","useAdminBasicNavigationCommands","commands","map","menuCommand","label","searchLabel","name","url","callback","close","document","location","isLoading","useAdminNavigationCommands","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\n\nconst getAdminNavigationCommands = ( menuCommands ) =>\n\tfunction useAdminBasicNavigationCommands() {\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( menuCommands ?? [] ).map( ( menuCommand ) => {\n\t\t\t\tconst label = sprintf(\n\t\t\t\t\t/* translators: %s: menu label */\n\t\t\t\t\t__( 'Go to: %s' ),\n\t\t\t\t\tmenuCommand.label\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tlabel,\n\t\t\t\t\tsearchLabel: label,\n\t\t\t\t\tname: menuCommand.name,\n\t\t\t\t\turl: menuCommand.url,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tdocument.location = menuCommand.url;\n\t\t\t\t\t\tclose();\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t} );\n\t\t}, [] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading: false,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands( menuCommands ) {\n\tuseCommandLoader( {\n\t\tname: 'core/admin-navigation',\n\t\thook: getAdminNavigationCommands( menuCommands ),\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAQ,oBAAoB;AAE5C,MAAMC,0BAA0B,GAAKC,YAAY,IAChD,SAASC,+BAA+BA,CAAA,EAAG;EAC1C,MAAMC,QAAQ,GAAGJ,OAAO,CAAE,MAAM;IAC/B,OAAO,CAAEE,YAAY,aAAZA,YAAY,cAAZA,YAAY,GAAI,EAAE,EAAGG,GAAG,CAAIC,WAAW,IAAM;MACrD,MAAMC,KAAK,GAAGR,OAAO,CACpB;MACAD,EAAE,CAAE,WAAY,CAAC,EACjBQ,WAAW,CAACC,KACb,CAAC;MACD,OAAO;QACNA,KAAK;QACLC,WAAW,EAAED,KAAK;QAClBE,IAAI,EAAEH,WAAW,CAACG,IAAI;QACtBC,GAAG,EAAEJ,WAAW,CAACI,GAAG;QACpBC,QAAQ,EAAEA,CAAE;UAAEC;QAAM,CAAC,KAAM;UAC1BC,QAAQ,CAACC,QAAQ,GAAGR,WAAW,CAACI,GAAG;UACnCE,KAAK,CAAC,CAAC;QACR;MACD,CAAC;IACF,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO;IACNR,QAAQ;IACRW,SAAS,EAAE;EACZ,CAAC;AACF,CAAC;AAEF,OAAO,SAASC,0BAA0BA,CAAEd,YAAY,EAAG;EAC1DL,gBAAgB,CAAE;IACjBY,IAAI,EAAE,uBAAuB;IAC7BQ,IAAI,EAAEhB,0BAA0B,CAAEC,YAAa;EAChD,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -18,8 +18,13 @@ const {
18
18
  } = unlock(routerPrivateApis);
19
19
 
20
20
  // Register core commands and render the Command Palette.
21
- function CommandPalette() {
22
- useAdminNavigationCommands();
21
+ function CommandPalette({
22
+ settings
23
+ }) {
24
+ const {
25
+ menu_commands: menuCommands
26
+ } = settings;
27
+ useAdminNavigationCommands(menuCommands);
23
28
  useSiteEditorNavigationCommands();
24
29
  return /*#__PURE__*/_jsx(RouterProvider, {
25
30
  pathArg: "p",
@@ -29,12 +34,16 @@ function CommandPalette() {
29
34
 
30
35
  /**
31
36
  * Initializes the Command Palette.
37
+ *
38
+ * @param {Object} settings Command palette settings.
32
39
  */
33
- export function initializeCommandPalette() {
40
+ export function initializeCommandPalette(settings) {
34
41
  const root = document.createElement('div');
35
42
  document.body.appendChild(root);
36
43
  createRoot(root).render(/*#__PURE__*/_jsx(StrictMode, {
37
- children: /*#__PURE__*/_jsx(CommandPalette, {})
44
+ children: /*#__PURE__*/_jsx(CommandPalette, {
45
+ settings: settings
46
+ })
38
47
  }));
39
48
  }
40
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createRoot","StrictMode","privateApis","routerPrivateApis","CommandMenu","useAdminNavigationCommands","useSiteEditorNavigationCommands","unlock","jsx","_jsx","RouterProvider","CommandPalette","pathArg","children","initializeCommandPalette","root","document","createElement","body","appendChild","render"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { CommandMenu } from '@wordpress/commands';\n\n/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { unlock } from './lock-unlock';\nexport { privateApis } from './private-apis';\n\nconst { RouterProvider } = unlock( routerPrivateApis );\n\n// Register core commands and render the Command Palette.\nfunction CommandPalette() {\n\tuseAdminNavigationCommands();\n\tuseSiteEditorNavigationCommands();\n\treturn (\n\t\t<RouterProvider pathArg=\"p\">\n\t\t\t<CommandMenu />\n\t\t</RouterProvider>\n\t);\n}\n\n/**\n * Initializes the Command Palette.\n */\nexport function initializeCommandPalette() {\n\tconst root = document.createElement( 'div' );\n\tdocument.body.appendChild( root );\n\tcreateRoot( root ).render(\n\t\t<StrictMode>\n\t\t\t<CommandPalette />\n\t\t</StrictMode>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,UAAU,QAAQ,oBAAoB;AAC3D,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;AACpE,SAASC,WAAW,QAAQ,qBAAqB;;AAEjD;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,6BAA6B;AACxE,SAASC,+BAA+B,QAAQ,mCAAmC;AACnF,SAASC,MAAM,QAAQ,eAAe;AAAC,SAAAC,GAAA,IAAAC,IAAA;AACvC,SAASP,WAAW,QAAQ,gBAAgB;AAE5C,MAAM;EAAEQ;AAAe,CAAC,GAAGH,MAAM,CAAEJ,iBAAkB,CAAC;;AAEtD;AACA,SAASQ,cAAcA,CAAA,EAAG;EACzBN,0BAA0B,CAAC,CAAC;EAC5BC,+BAA+B,CAAC,CAAC;EACjC,oBACCG,IAAA,CAACC,cAAc;IAACE,OAAO,EAAC,GAAG;IAAAC,QAAA,eAC1BJ,IAAA,CAACL,WAAW,IAAE;EAAC,CACA,CAAC;AAEnB;;AAEA;AACA;AACA;AACA,OAAO,SAASU,wBAAwBA,CAAA,EAAG;EAC1C,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAE,KAAM,CAAC;EAC5CD,QAAQ,CAACE,IAAI,CAACC,WAAW,CAAEJ,IAAK,CAAC;EACjCf,UAAU,CAAEe,IAAK,CAAC,CAACK,MAAM,cACxBX,IAAA,CAACR,UAAU;IAAAY,QAAA,eACVJ,IAAA,CAACE,cAAc,IAAE;EAAC,CACP,CACb,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["createRoot","StrictMode","privateApis","routerPrivateApis","CommandMenu","useAdminNavigationCommands","useSiteEditorNavigationCommands","unlock","jsx","_jsx","RouterProvider","CommandPalette","settings","menu_commands","menuCommands","pathArg","children","initializeCommandPalette","root","document","createElement","body","appendChild","render"],"sources":["@wordpress/core-commands/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRoot, StrictMode } from '@wordpress/element';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { CommandMenu } from '@wordpress/commands';\n\n/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { unlock } from './lock-unlock';\nexport { privateApis } from './private-apis';\n\nconst { RouterProvider } = unlock( routerPrivateApis );\n\n// Register core commands and render the Command Palette.\nfunction CommandPalette( { settings } ) {\n\tconst { menu_commands: menuCommands } = settings;\n\tuseAdminNavigationCommands( menuCommands );\n\tuseSiteEditorNavigationCommands();\n\treturn (\n\t\t<RouterProvider pathArg=\"p\">\n\t\t\t<CommandMenu />\n\t\t</RouterProvider>\n\t);\n}\n\n/**\n * Initializes the Command Palette.\n *\n * @param {Object} settings Command palette settings.\n */\nexport function initializeCommandPalette( settings ) {\n\tconst root = document.createElement( 'div' );\n\tdocument.body.appendChild( root );\n\tcreateRoot( root ).render(\n\t\t<StrictMode>\n\t\t\t<CommandPalette settings={ settings } />\n\t\t</StrictMode>\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,UAAU,QAAQ,oBAAoB;AAC3D,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;AACpE,SAASC,WAAW,QAAQ,qBAAqB;;AAEjD;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,6BAA6B;AACxE,SAASC,+BAA+B,QAAQ,mCAAmC;AACnF,SAASC,MAAM,QAAQ,eAAe;AAAC,SAAAC,GAAA,IAAAC,IAAA;AACvC,SAASP,WAAW,QAAQ,gBAAgB;AAE5C,MAAM;EAAEQ;AAAe,CAAC,GAAGH,MAAM,CAAEJ,iBAAkB,CAAC;;AAEtD;AACA,SAASQ,cAAcA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACvC,MAAM;IAAEC,aAAa,EAAEC;EAAa,CAAC,GAAGF,QAAQ;EAChDP,0BAA0B,CAAES,YAAa,CAAC;EAC1CR,+BAA+B,CAAC,CAAC;EACjC,oBACCG,IAAA,CAACC,cAAc;IAACK,OAAO,EAAC,GAAG;IAAAC,QAAA,eAC1BP,IAAA,CAACL,WAAW,IAAE;EAAC,CACA,CAAC;AAEnB;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASa,wBAAwBA,CAAEL,QAAQ,EAAG;EACpD,MAAMM,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAE,KAAM,CAAC;EAC5CD,QAAQ,CAACE,IAAI,CAACC,WAAW,CAAEJ,IAAK,CAAC;EACjClB,UAAU,CAAEkB,IAAK,CAAC,CAACK,MAAM,cACxBd,IAAA,CAACR,UAAU;IAAAe,QAAA,eACVP,IAAA,CAACE,cAAc;MAACC,QAAQ,EAAGA;IAAU,CAAE;EAAC,CAC7B,CACb,CAAC;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-commands",
3
- "version": "1.30.0",
3
+ "version": "1.30.1-next.836ecdcae.0",
4
4
  "description": "WordPress core reusable commands.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,19 +29,19 @@
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "7.25.7",
32
- "@wordpress/block-editor": "^15.3.0",
33
- "@wordpress/commands": "^1.30.0",
34
- "@wordpress/compose": "^7.30.0",
35
- "@wordpress/core-data": "^7.30.0",
36
- "@wordpress/data": "^10.30.0",
37
- "@wordpress/element": "^6.30.0",
38
- "@wordpress/html-entities": "^4.30.0",
39
- "@wordpress/i18n": "^6.3.0",
40
- "@wordpress/icons": "^10.30.0",
41
- "@wordpress/notices": "^5.30.0",
42
- "@wordpress/private-apis": "^1.30.0",
43
- "@wordpress/router": "^1.30.0",
44
- "@wordpress/url": "^4.30.0"
32
+ "@wordpress/block-editor": "^15.3.1-next.836ecdcae.0",
33
+ "@wordpress/commands": "^1.30.1-next.836ecdcae.0",
34
+ "@wordpress/compose": "^7.30.1-next.836ecdcae.0",
35
+ "@wordpress/core-data": "^7.30.1-next.836ecdcae.0",
36
+ "@wordpress/data": "^10.30.1-next.836ecdcae.0",
37
+ "@wordpress/element": "^6.30.1-next.836ecdcae.0",
38
+ "@wordpress/html-entities": "^4.30.1-next.836ecdcae.0",
39
+ "@wordpress/i18n": "^6.3.1-next.836ecdcae.0",
40
+ "@wordpress/icons": "^10.30.1-next.836ecdcae.0",
41
+ "@wordpress/notices": "^5.30.1-next.836ecdcae.0",
42
+ "@wordpress/private-apis": "^1.30.1-next.836ecdcae.0",
43
+ "@wordpress/router": "^1.30.1-next.836ecdcae.0",
44
+ "@wordpress/url": "^4.30.1-next.836ecdcae.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "^18.0.0",
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "c66cb089eed19d4f4956962fa7b4c81abe6dd513"
53
+ "gitHead": "3e60b4c1e78d7b27acbf1d7dd172bbd64358a0f2"
54
54
  }
@@ -2,249 +2,40 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { useCommandLoader } from '@wordpress/commands';
5
- import { __ } from '@wordpress/i18n';
6
- import { plus, dashboard } from '@wordpress/icons';
7
- import { getPath } from '@wordpress/url';
8
- import { store as coreStore } from '@wordpress/core-data';
9
- import { useSelect, useDispatch } from '@wordpress/data';
10
- import { useCallback, useMemo } from '@wordpress/element';
11
- import { store as noticesStore } from '@wordpress/notices';
12
- import { privateApis as routerPrivateApis } from '@wordpress/router';
5
+ import { __, sprintf } from '@wordpress/i18n';
6
+ import { useMemo } from '@wordpress/element';
13
7
 
14
- /**
15
- * Internal dependencies
16
- */
17
- import { unlock } from './lock-unlock';
18
-
19
- const { useHistory } = unlock( routerPrivateApis );
20
-
21
- const getAddNewPageCommand = () =>
22
- function useAddNewPageCommand() {
23
- const canCreatePage = useSelect(
24
- ( select ) =>
25
- select( coreStore ).canUser( 'create', {
26
- kind: 'postType',
27
- name: 'page',
28
- } ),
29
- []
30
- );
31
- const isSiteEditor = getPath( window.location.href )?.includes(
32
- 'site-editor.php'
33
- );
34
- const history = useHistory();
35
- const isBlockBasedTheme = useSelect( ( select ) => {
36
- return select( coreStore ).getCurrentTheme()?.is_block_theme;
37
- }, [] );
38
- const { saveEntityRecord } = useDispatch( coreStore );
39
- const { createErrorNotice } = useDispatch( noticesStore );
40
-
41
- const createPageEntity = useCallback(
42
- async ( { close } ) => {
43
- try {
44
- const page = await saveEntityRecord(
45
- 'postType',
46
- 'page',
47
- {
48
- status: 'draft',
49
- },
50
- {
51
- throwOnError: true,
52
- }
53
- );
54
- if ( page?.id ) {
55
- history.navigate( `/page/${ page.id }?canvas=edit` );
56
- }
57
- } catch ( error ) {
58
- const errorMessage =
59
- error.message && error.code !== 'unknown_error'
60
- ? error.message
61
- : __(
62
- 'An error occurred while creating the item.'
63
- );
64
-
65
- createErrorNotice( errorMessage, {
66
- type: 'snackbar',
67
- } );
68
- } finally {
69
- close();
70
- }
71
- },
72
- [ createErrorNotice, history, saveEntityRecord ]
73
- );
74
-
75
- const commands = useMemo( () => {
76
- if ( ! canCreatePage ) {
77
- return [];
78
- }
79
-
80
- const addNewPage =
81
- isSiteEditor && isBlockBasedTheme
82
- ? createPageEntity
83
- : () =>
84
- ( document.location.href =
85
- 'post-new.php?post_type=page' );
86
- return [
87
- {
88
- name: 'core/add-new-page',
89
- label: __( 'Add Page' ),
90
- icon: plus,
91
- callback: addNewPage,
92
- keywords: [
93
- __( 'page' ),
94
- __( 'new' ),
95
- __( 'add' ),
96
- __( 'create' ),
97
- ],
98
- },
99
- ];
100
- }, [
101
- createPageEntity,
102
- isSiteEditor,
103
- isBlockBasedTheme,
104
- canCreatePage,
105
- ] );
106
-
107
- return {
108
- isLoading: false,
109
- commands,
110
- };
111
- };
112
-
113
- const getAdminBasicNavigationCommands = () =>
8
+ const getAdminNavigationCommands = ( menuCommands ) =>
114
9
  function useAdminBasicNavigationCommands() {
115
- const { isBlockBasedTheme, canCreateTemplate } = useSelect(
116
- ( select ) => {
117
- return {
118
- isBlockBasedTheme:
119
- select( coreStore ).getCurrentTheme()?.is_block_theme,
120
- canCreateTemplate: select( coreStore ).canUser( 'create', {
121
- kind: 'postType',
122
- name: 'wp_template',
123
- } ),
124
- };
125
- },
126
- []
127
- );
128
-
129
10
  const commands = useMemo( () => {
130
- if ( canCreateTemplate && isBlockBasedTheme ) {
131
- const isSiteEditor = getPath( window.location.href )?.includes(
132
- 'site-editor.php'
11
+ return ( menuCommands ?? [] ).map( ( menuCommand ) => {
12
+ const label = sprintf(
13
+ /* translators: %s: menu label */
14
+ __( 'Go to: %s' ),
15
+ menuCommand.label
133
16
  );
134
- if ( ! isSiteEditor ) {
135
- return [
136
- {
137
- name: 'core/go-to-site-editor',
138
- label: __( 'Open Site Editor' ),
139
- callback: ( { close } ) => {
140
- close();
141
- document.location = 'site-editor.php';
142
- },
143
- },
144
- ];
145
- }
146
- }
147
-
148
- return [];
149
- }, [ canCreateTemplate, isBlockBasedTheme ] );
150
-
151
- return {
152
- commands,
153
- isLoading: false,
154
- };
155
- };
156
-
157
- const getDashboardCommand = () =>
158
- function useDashboardCommand() {
159
- const currentPath = getPath( window.location.href );
160
-
161
- const isEditorScreen =
162
- currentPath?.includes( 'site-editor.php' ) ||
163
- currentPath?.includes( 'post.php' ) ||
164
- currentPath?.includes( 'post-new.php' ) ||
165
- currentPath?.includes( 'widgets.php' ) ||
166
- currentPath?.includes( 'customize.php' );
167
-
168
- const commands = useMemo( () => {
169
- if ( isEditorScreen ) {
170
- return [
171
- {
172
- name: 'core/dashboard',
173
- label: __( 'Dashboard' ),
174
- icon: dashboard,
175
- callback: () => {
176
- document.location.assign( 'index.php' );
177
- },
17
+ return {
18
+ label,
19
+ searchLabel: label,
20
+ name: menuCommand.name,
21
+ url: menuCommand.url,
22
+ callback: ( { close } ) => {
23
+ document.location = menuCommand.url;
24
+ close();
178
25
  },
179
- ];
180
- }
181
- return [];
182
- }, [ isEditorScreen ] );
26
+ };
27
+ } );
28
+ }, [] );
183
29
 
184
30
  return {
185
- isLoading: false,
186
31
  commands,
187
- };
188
- };
189
-
190
- const getAddNewPostCommand = () =>
191
- function useAddNewPostCommand() {
192
- const canCreatePost = useSelect(
193
- ( select ) =>
194
- select( coreStore ).canUser( 'create', {
195
- kind: 'postType',
196
- name: 'post',
197
- } ),
198
- []
199
- );
200
-
201
- const commands = useMemo( () => {
202
- if ( ! canCreatePost ) {
203
- return [];
204
- }
205
-
206
- return [
207
- {
208
- name: 'core/add-new-post',
209
- label: __( 'Add Post' ),
210
- icon: plus,
211
- callback: () => {
212
- document.location.assign( 'post-new.php' );
213
- },
214
- keywords: [
215
- __( 'post' ),
216
- __( 'new' ),
217
- __( 'add' ),
218
- __( 'create' ),
219
- ],
220
- },
221
- ];
222
- }, [ canCreatePost ] );
223
-
224
- return {
225
32
  isLoading: false,
226
- commands,
227
33
  };
228
34
  };
229
35
 
230
- export function useAdminNavigationCommands() {
231
- useCommandLoader( {
232
- name: 'core/add-new-post',
233
- hook: getAddNewPostCommand(),
234
- } );
235
-
236
- useCommandLoader( {
237
- name: 'core/dashboard',
238
- hook: getDashboardCommand(),
239
- } );
240
-
241
- useCommandLoader( {
242
- name: 'core/add-new-page',
243
- hook: getAddNewPageCommand(),
244
- } );
245
-
36
+ export function useAdminNavigationCommands( menuCommands ) {
246
37
  useCommandLoader( {
247
38
  name: 'core/admin-navigation',
248
- hook: getAdminBasicNavigationCommands(),
39
+ hook: getAdminNavigationCommands( menuCommands ),
249
40
  } );
250
41
  }
package/src/index.js CHANGED
@@ -16,8 +16,9 @@ export { privateApis } from './private-apis';
16
16
  const { RouterProvider } = unlock( routerPrivateApis );
17
17
 
18
18
  // Register core commands and render the Command Palette.
19
- function CommandPalette() {
20
- useAdminNavigationCommands();
19
+ function CommandPalette( { settings } ) {
20
+ const { menu_commands: menuCommands } = settings;
21
+ useAdminNavigationCommands( menuCommands );
21
22
  useSiteEditorNavigationCommands();
22
23
  return (
23
24
  <RouterProvider pathArg="p">
@@ -28,13 +29,15 @@ function CommandPalette() {
28
29
 
29
30
  /**
30
31
  * Initializes the Command Palette.
32
+ *
33
+ * @param {Object} settings Command palette settings.
31
34
  */
32
- export function initializeCommandPalette() {
35
+ export function initializeCommandPalette( settings ) {
33
36
  const root = document.createElement( 'div' );
34
37
  document.body.appendChild( root );
35
38
  createRoot( root ).render(
36
39
  <StrictMode>
37
- <CommandPalette />
40
+ <CommandPalette settings={ settings } />
38
41
  </StrictMode>
39
42
  );
40
43
  }