@wordpress/core-commands 1.29.0 → 1.29.1-next.e256d081a.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.
@@ -64,7 +64,8 @@ const getAddNewPageCommand = () => function useAddNewPageCommand() {
64
64
  name: 'core/add-new-page',
65
65
  label: (0, _i18n.__)('Add Page'),
66
66
  icon: _icons.plus,
67
- callback: addNewPage
67
+ callback: addNewPage,
68
+ keywords: [(0, _i18n.__)('page'), (0, _i18n.__)('new'), (0, _i18n.__)('add'), (0, _i18n.__)('create')]
68
69
  }];
69
70
  }, [createPageEntity, isSiteEditor, isBlockBasedTheme]);
70
71
  return {
@@ -72,6 +73,63 @@ const getAddNewPageCommand = () => function useAddNewPageCommand() {
72
73
  commands
73
74
  };
74
75
  };
76
+ const getAdminBasicNavigationCommands = () => function useAdminBasicNavigationCommands() {
77
+ const {
78
+ isBlockBasedTheme,
79
+ canCreateTemplate
80
+ } = (0, _data.useSelect)(select => {
81
+ return {
82
+ isBlockBasedTheme: select(_coreData.store).getCurrentTheme()?.is_block_theme,
83
+ canCreateTemplate: select(_coreData.store).canUser('create', {
84
+ kind: 'postType',
85
+ name: 'wp_template'
86
+ })
87
+ };
88
+ }, []);
89
+ const commands = (0, _element.useMemo)(() => {
90
+ if (canCreateTemplate && isBlockBasedTheme) {
91
+ const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
92
+ if (!isSiteEditor) {
93
+ return [{
94
+ name: 'core/go-to-site-editor',
95
+ label: (0, _i18n.__)('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
+ return {
108
+ commands,
109
+ isLoading: false
110
+ };
111
+ };
112
+ const getDashboardCommand = () => function useDashboardCommand() {
113
+ const currentPath = (0, _url.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 = (0, _element.useMemo)(() => {
116
+ if (isEditorScreen) {
117
+ return [{
118
+ name: 'core/dashboard',
119
+ label: (0, _i18n.__)('Dashboard'),
120
+ icon: _icons.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
+ };
75
133
  function useAdminNavigationCommands() {
76
134
  (0, _commands.useCommand)({
77
135
  name: 'core/add-new-post',
@@ -79,11 +137,20 @@ function useAdminNavigationCommands() {
79
137
  icon: _icons.plus,
80
138
  callback: () => {
81
139
  document.location.assign('post-new.php');
82
- }
140
+ },
141
+ keywords: [(0, _i18n.__)('post'), (0, _i18n.__)('new'), (0, _i18n.__)('add'), (0, _i18n.__)('create')]
142
+ });
143
+ (0, _commands.useCommandLoader)({
144
+ name: 'core/dashboard',
145
+ hook: getDashboardCommand()
83
146
  });
84
147
  (0, _commands.useCommandLoader)({
85
148
  name: 'core/add-new-page',
86
149
  hook: getAddNewPageCommand()
87
150
  });
151
+ (0, _commands.useCommandLoader)({
152
+ name: 'core/admin-navigation',
153
+ hook: getAdminBasicNavigationCommands()
154
+ });
88
155
  }
89
156
  //# 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","isSiteEditor","getPath","window","location","href","includes","history","isBlockBasedTheme","useSelect","select","coreStore","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","name","label","icon","plus","callback","isLoading","useAdminNavigationCommands","useCommand","assign","useCommandLoader","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand, useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } 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 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\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},\n\t\t\t];\n\t\t}, [ createPageEntity, isSiteEditor, isBlockBasedTheme ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add Post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t},\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-page',\n\t\thook: getAddNewPageCommand(),\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,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AACA,IA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AC;MAELd,iBAAiB,CAAEW,YAAY,EAAE;QAChCI,IAAI,EAAE;MACP,CAAE,CAAC;IACJ,CAAC,SAAS;MACTX,KAAK,CAAC,CAAC;IACR;EACD,CAAC,EACD,CAAEJ,iBAAiB,EAAET,OAAO,EAAEO,gBAAgB,CAC/C,CAAC;EAED,MAAMkB,QAAQ,GAAG,IAAAC,gBAAO,EAAE,MAAM;IAC/B,MAAMC,UAAU,GACfjC,YAAY,IAAIO,iBAAiB,GAC9BU,gBAAgB,GAChB,MACEiB,QAAQ,CAAC/B,QAAQ,CAACC,IAAI,GACvB,6BAA+B;IACpC,OAAO,CACN;MACC+B,IAAI,EAAE,mBAAmB;MACzBC,KAAK,EAAE,IAAAP,QAAE,EAAE,UAAW,CAAC;MACvBQ,IAAI,EAAEC,WAAI;MACVC,QAAQ,EAAEN;IACX,CAAC,CACD;EACF,CAAC,EAAE,CAAEhB,gBAAgB,EAAEjB,YAAY,EAAEO,iBAAiB,CAAG,CAAC;EAE1D,OAAO;IACNiC,SAAS,EAAE,KAAK;IAChBT;EACD,CAAC;AACF,CAAC;AAEK,SAASU,0BAA0BA,CAAA,EAAG;EAC5C,IAAAC,oBAAU,EAAE;IACXP,IAAI,EAAE,mBAAmB;IACzBC,KAAK,EAAE,IAAAP,QAAE,EAAE,UAAW,CAAC;IACvBQ,IAAI,EAAEC,WAAI;IACVC,QAAQ,EAAEA,CAAA,KAAM;MACfL,QAAQ,CAAC/B,QAAQ,CAACwC,MAAM,CAAE,cAAe,CAAC;IAC3C;EACD,CAAE,CAAC;EAEH,IAAAC,0BAAgB,EAAE;IACjBT,IAAI,EAAE,mBAAmB;IACzBU,IAAI,EAAE/C,oBAAoB,CAAC;EAC5B,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_commands","require","_i18n","_icons","_url","_coreData","_data","_element","_notices","_router","_lockUnlock","useHistory","unlock","routerPrivateApis","getAddNewPageCommand","useAddNewPageCommand","isSiteEditor","getPath","window","location","href","includes","history","isBlockBasedTheme","useSelect","select","coreStore","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","name","label","icon","plus","callback","keywords","isLoading","getAdminBasicNavigationCommands","useAdminBasicNavigationCommands","canCreateTemplate","canUser","kind","getDashboardCommand","useDashboardCommand","currentPath","isEditorScreen","dashboard","assign","useAdminNavigationCommands","useCommand","useCommandLoader","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand, 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 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\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}, [ createPageEntity, isSiteEditor, isBlockBasedTheme ] );\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\nexport function useAdminNavigationCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add Post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t},\n\t\tkeywords: [ __( 'post' ), __( 'new' ), __( 'add' ), __( 'create' ) ],\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,GAAAN,OAAA;AACA,IAAAO,QAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAKA,IAAAS,WAAA,GAAAT,OAAA;AAhBA;AACA;AACA;;AAWA;AACA;AACA;;AAGA,MAAM;EAAEU;AAAW,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAElD,MAAMC,oBAAoB,GAAGA,CAAA,KAC5B,SAASC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;IACA,OAAO,EAAE;EACV,CAAC,EAAE,CAAEF,cAAc,CAAG,CAAC;EAEvB,OAAO;IACNT,SAAS,EAAE,KAAK;IAChBV;EACD,CAAC;AACF,CAAC;AAEK,SAASsB,0BAA0BA,CAAA,EAAG;EAC5C,IAAAC,oBAAU,EAAE;IACXnB,IAAI,EAAE,mBAAmB;IACzBC,KAAK,EAAE,IAAAP,QAAE,EAAE,UAAW,CAAC;IACvBQ,IAAI,EAAEC,WAAI;IACVC,QAAQ,EAAEA,CAAA,KAAM;MACfL,QAAQ,CAAC/B,QAAQ,CAACiD,MAAM,CAAE,cAAe,CAAC;IAC3C,CAAC;IACDZ,QAAQ,EAAE,CAAE,IAAAX,QAAE,EAAE,MAAO,CAAC,EAAE,IAAAA,QAAE,EAAE,KAAM,CAAC,EAAE,IAAAA,QAAE,EAAE,KAAM,CAAC,EAAE,IAAAA,QAAE,EAAE,QAAS,CAAC;EACnE,CAAE,CAAC;EAEH,IAAA0B,0BAAgB,EAAE;IACjBpB,IAAI,EAAE,gBAAgB;IACtBqB,IAAI,EAAET,mBAAmB,CAAC;EAC3B,CAAE,CAAC;EAEH,IAAAQ,0BAAgB,EAAE;IACjBpB,IAAI,EAAE,mBAAmB;IACzBqB,IAAI,EAAE1D,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEH,IAAAyD,0BAAgB,EAAE;IACjBpB,IAAI,EAAE,uBAAuB;IAC7BqB,IAAI,EAAEd,+BAA+B,CAAC;EACvC,CAAE,CAAC;AACJ","ignoreList":[]}
package/build/index.js CHANGED
@@ -44,9 +44,6 @@ function CommandPalette() {
44
44
  * Initializes the Command Palette.
45
45
  */
46
46
  function initializeCommandPalette() {
47
- if (!globalThis.IS_GUTENBERG_PLUGIN) {
48
- return;
49
- }
50
47
  const root = document.createElement('div');
51
48
  document.body.appendChild(root);
52
49
  (0, _element.createRoot)(root).render(/*#__PURE__*/(0, _jsxRuntime.jsx)(_element.StrictMode, {
@@ -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","globalThis","IS_GUTENBERG_PLUGIN","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\tif ( ! globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\treturn;\n\t}\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,IAAK,CAAEC,UAAU,CAACC,mBAAmB,EAAG;IACvC;EACD;EACA,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,IAAArB,WAAA,CAAAQ,GAAA,EAACf,QAAA,CAAA6B,UAAU;IAAAZ,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","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":[]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { useCommand, useCommandLoader } from '@wordpress/commands';
5
5
  import { __ } from '@wordpress/i18n';
6
- import { plus } from '@wordpress/icons';
6
+ import { plus, dashboard } from '@wordpress/icons';
7
7
  import { getPath } from '@wordpress/url';
8
8
  import { store as coreStore } from '@wordpress/core-data';
9
9
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -57,7 +57,8 @@ const getAddNewPageCommand = () => function useAddNewPageCommand() {
57
57
  name: 'core/add-new-page',
58
58
  label: __('Add Page'),
59
59
  icon: plus,
60
- callback: addNewPage
60
+ callback: addNewPage,
61
+ keywords: [__('page'), __('new'), __('add'), __('create')]
61
62
  }];
62
63
  }, [createPageEntity, isSiteEditor, isBlockBasedTheme]);
63
64
  return {
@@ -65,6 +66,63 @@ const getAddNewPageCommand = () => function useAddNewPageCommand() {
65
66
  commands
66
67
  };
67
68
  };
69
+ const getAdminBasicNavigationCommands = () => function useAdminBasicNavigationCommands() {
70
+ const {
71
+ isBlockBasedTheme,
72
+ canCreateTemplate
73
+ } = useSelect(select => {
74
+ return {
75
+ isBlockBasedTheme: select(coreStore).getCurrentTheme()?.is_block_theme,
76
+ canCreateTemplate: select(coreStore).canUser('create', {
77
+ kind: 'postType',
78
+ name: 'wp_template'
79
+ })
80
+ };
81
+ }, []);
82
+ const commands = useMemo(() => {
83
+ if (canCreateTemplate && isBlockBasedTheme) {
84
+ const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
85
+ if (!isSiteEditor) {
86
+ return [{
87
+ name: 'core/go-to-site-editor',
88
+ label: __('Open Site Editor'),
89
+ callback: ({
90
+ close
91
+ }) => {
92
+ close();
93
+ document.location = 'site-editor.php';
94
+ }
95
+ }];
96
+ }
97
+ }
98
+ return [];
99
+ }, [canCreateTemplate, isBlockBasedTheme]);
100
+ return {
101
+ commands,
102
+ isLoading: false
103
+ };
104
+ };
105
+ const getDashboardCommand = () => function useDashboardCommand() {
106
+ const currentPath = getPath(window.location.href);
107
+ const isEditorScreen = currentPath?.includes('site-editor.php') || currentPath?.includes('post.php') || currentPath?.includes('post-new.php') || currentPath?.includes('widgets.php') || currentPath?.includes('customize.php');
108
+ const commands = useMemo(() => {
109
+ if (isEditorScreen) {
110
+ return [{
111
+ name: 'core/dashboard',
112
+ label: __('Dashboard'),
113
+ icon: dashboard,
114
+ callback: () => {
115
+ document.location.assign('index.php');
116
+ }
117
+ }];
118
+ }
119
+ return [];
120
+ }, [isEditorScreen]);
121
+ return {
122
+ isLoading: false,
123
+ commands
124
+ };
125
+ };
68
126
  export function useAdminNavigationCommands() {
69
127
  useCommand({
70
128
  name: 'core/add-new-post',
@@ -72,11 +130,20 @@ export function useAdminNavigationCommands() {
72
130
  icon: plus,
73
131
  callback: () => {
74
132
  document.location.assign('post-new.php');
75
- }
133
+ },
134
+ keywords: [__('post'), __('new'), __('add'), __('create')]
135
+ });
136
+ useCommandLoader({
137
+ name: 'core/dashboard',
138
+ hook: getDashboardCommand()
76
139
  });
77
140
  useCommandLoader({
78
141
  name: 'core/add-new-page',
79
142
  hook: getAddNewPageCommand()
80
143
  });
144
+ useCommandLoader({
145
+ name: 'core/admin-navigation',
146
+ hook: getAdminBasicNavigationCommands()
147
+ });
81
148
  }
82
149
  //# sourceMappingURL=admin-navigation-commands.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCommand","useCommandLoader","__","plus","getPath","store","coreStore","useSelect","useDispatch","useCallback","useMemo","noticesStore","privateApis","routerPrivateApis","unlock","useHistory","getAddNewPageCommand","useAddNewPageCommand","isSiteEditor","window","location","href","includes","history","isBlockBasedTheme","select","getCurrentTheme","is_block_theme","saveEntityRecord","createErrorNotice","createPageEntity","close","page","status","throwOnError","id","navigate","error","errorMessage","message","code","type","commands","addNewPage","document","name","label","icon","callback","isLoading","useAdminNavigationCommands","assign","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand, useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { plus } 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 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\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},\n\t\t\t];\n\t\t}, [ createPageEntity, isSiteEditor, isBlockBasedTheme ] );\n\n\t\treturn {\n\t\t\tisLoading: false,\n\t\t\tcommands,\n\t\t};\n\t};\n\nexport function useAdminNavigationCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add Post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t},\n\t} );\n\n\tuseCommandLoader( {\n\t\tname: 'core/add-new-page',\n\t\thook: getAddNewPageCommand(),\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,gBAAgB,QAAQ,qBAAqB;AAClE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4C,IAAI,EAAE,mBAAmB;IACzBO,IAAI,EAAEpC,oBAAoB,CAAC;EAC5B,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["useCommand","useCommandLoader","__","plus","dashboard","getPath","store","coreStore","useSelect","useDispatch","useCallback","useMemo","noticesStore","privateApis","routerPrivateApis","unlock","useHistory","getAddNewPageCommand","useAddNewPageCommand","isSiteEditor","window","location","href","includes","history","isBlockBasedTheme","select","getCurrentTheme","is_block_theme","saveEntityRecord","createErrorNotice","createPageEntity","close","page","status","throwOnError","id","navigate","error","errorMessage","message","code","type","commands","addNewPage","document","name","label","icon","callback","keywords","isLoading","getAdminBasicNavigationCommands","useAdminBasicNavigationCommands","canCreateTemplate","canUser","kind","getDashboardCommand","useDashboardCommand","currentPath","isEditorScreen","assign","useAdminNavigationCommands","hook"],"sources":["@wordpress/core-commands/src/admin-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommand, 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 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\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}, [ createPageEntity, isSiteEditor, isBlockBasedTheme ] );\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\nexport function useAdminNavigationCommands() {\n\tuseCommand( {\n\t\tname: 'core/add-new-post',\n\t\tlabel: __( 'Add Post' ),\n\t\ticon: plus,\n\t\tcallback: () => {\n\t\t\tdocument.location.assign( 'post-new.php' );\n\t\t},\n\t\tkeywords: [ __( 'post' ), __( 'new' ), __( 'add' ), __( 'create' ) ],\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,UAAU,EAAEC,gBAAgB,QAAQ,qBAAqB;AAClE,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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AAgB;QACtBC,KAAK,EAAE7C,EAAE,CAAE,WAAY,CAAC;QACxB8C,IAAI,EAAE5C,SAAS;QACf6C,QAAQ,EAAEA,CAAA,KAAM;UACfJ,QAAQ,CAACxB,QAAQ,CAACwC,MAAM,CAAE,WAAY,CAAC;QACxC;MACD,CAAC,CACD;IACF;IACA,OAAO,EAAE;EACV,CAAC,EAAE,CAAED,cAAc,CAAG,CAAC;EAEvB,OAAO;IACNT,SAAS,EAAE,KAAK;IAChBR;EACD,CAAC;AACF,CAAC;AAEF,OAAO,SAASmB,0BAA0BA,CAAA,EAAG;EAC5C9D,UAAU,CAAE;IACX8C,IAAI,EAAE,mBAAmB;IACzBC,KAAK,EAAE7C,EAAE,CAAE,UAAW,CAAC;IACvB8C,IAAI,EAAE7C,IAAI;IACV8C,QAAQ,EAAEA,CAAA,KAAM;MACfJ,QAAQ,CAACxB,QAAQ,CAACwC,MAAM,CAAE,cAAe,CAAC;IAC3C,CAAC;IACDX,QAAQ,EAAE,CAAEhD,EAAE,CAAE,MAAO,CAAC,EAAEA,EAAE,CAAE,KAAM,CAAC,EAAEA,EAAE,CAAE,KAAM,CAAC,EAAEA,EAAE,CAAE,QAAS,CAAC;EACnE,CAAE,CAAC;EAEHD,gBAAgB,CAAE;IACjB6C,IAAI,EAAE,gBAAgB;IACtBiB,IAAI,EAAEN,mBAAmB,CAAC;EAC3B,CAAE,CAAC;EAEHxD,gBAAgB,CAAE;IACjB6C,IAAI,EAAE,mBAAmB;IACzBiB,IAAI,EAAE9C,oBAAoB,CAAC;EAC5B,CAAE,CAAC;EAEHhB,gBAAgB,CAAE;IACjB6C,IAAI,EAAE,uBAAuB;IAC7BiB,IAAI,EAAEX,+BAA+B,CAAC;EACvC,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -31,9 +31,6 @@ function CommandPalette() {
31
31
  * Initializes the Command Palette.
32
32
  */
33
33
  export function initializeCommandPalette() {
34
- if (!globalThis.IS_GUTENBERG_PLUGIN) {
35
- return;
36
- }
37
34
  const root = document.createElement('div');
38
35
  document.body.appendChild(root);
39
36
  createRoot(root).render(/*#__PURE__*/_jsx(StrictMode, {
@@ -1 +1 @@
1
- {"version":3,"names":["createRoot","StrictMode","privateApis","routerPrivateApis","CommandMenu","useAdminNavigationCommands","useSiteEditorNavigationCommands","unlock","jsx","_jsx","RouterProvider","CommandPalette","pathArg","children","initializeCommandPalette","globalThis","IS_GUTENBERG_PLUGIN","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\tif ( ! globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\treturn;\n\t}\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,IAAK,CAAEC,UAAU,CAACC,mBAAmB,EAAG;IACvC;EACD;EACA,MAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAE,KAAM,CAAC;EAC5CD,QAAQ,CAACE,IAAI,CAACC,WAAW,CAAEJ,IAAK,CAAC;EACjCjB,UAAU,CAAEiB,IAAK,CAAC,CAACK,MAAM,cACxBb,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","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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-commands",
3
- "version": "1.29.0",
3
+ "version": "1.29.1-next.e256d081a.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.2.0",
33
- "@wordpress/commands": "^1.29.0",
34
- "@wordpress/compose": "^7.29.0",
35
- "@wordpress/core-data": "^7.29.0",
36
- "@wordpress/data": "^10.29.0",
37
- "@wordpress/element": "^6.29.0",
38
- "@wordpress/html-entities": "^4.29.0",
39
- "@wordpress/i18n": "^6.2.0",
40
- "@wordpress/icons": "^10.29.0",
41
- "@wordpress/notices": "^5.29.0",
42
- "@wordpress/private-apis": "^1.29.0",
43
- "@wordpress/router": "^1.29.0",
44
- "@wordpress/url": "^4.29.0"
32
+ "@wordpress/block-editor": "^15.2.1-next.e256d081a.0",
33
+ "@wordpress/commands": "^1.29.1-next.e256d081a.0",
34
+ "@wordpress/compose": "^7.29.1-next.e256d081a.0",
35
+ "@wordpress/core-data": "^7.29.1-next.e256d081a.0",
36
+ "@wordpress/data": "^10.29.1-next.e256d081a.0",
37
+ "@wordpress/element": "^6.29.1-next.e256d081a.0",
38
+ "@wordpress/html-entities": "^4.29.1-next.e256d081a.0",
39
+ "@wordpress/i18n": "^6.2.1-next.e256d081a.0",
40
+ "@wordpress/icons": "^10.29.1-next.e256d081a.0",
41
+ "@wordpress/notices": "^5.29.1-next.e256d081a.0",
42
+ "@wordpress/private-apis": "^1.29.1-next.e256d081a.0",
43
+ "@wordpress/router": "^1.29.1-next.e256d081a.0",
44
+ "@wordpress/url": "^4.29.1-next.e256d081a.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": "445ede01e8abc8e49a1101b21a3651adbe852120"
53
+ "gitHead": "7d529ba9a461795d5f1572d3856de33f744287c2"
54
54
  }
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { useCommand, useCommandLoader } from '@wordpress/commands';
5
5
  import { __ } from '@wordpress/i18n';
6
- import { plus } from '@wordpress/icons';
6
+ import { plus, dashboard } from '@wordpress/icons';
7
7
  import { getPath } from '@wordpress/url';
8
8
  import { store as coreStore } from '@wordpress/core-data';
9
9
  import { useSelect, useDispatch } from '@wordpress/data';
@@ -77,6 +77,12 @@ const getAddNewPageCommand = () =>
77
77
  label: __( 'Add Page' ),
78
78
  icon: plus,
79
79
  callback: addNewPage,
80
+ keywords: [
81
+ __( 'page' ),
82
+ __( 'new' ),
83
+ __( 'add' ),
84
+ __( 'create' ),
85
+ ],
80
86
  },
81
87
  ];
82
88
  }, [ createPageEntity, isSiteEditor, isBlockBasedTheme ] );
@@ -87,6 +93,83 @@ const getAddNewPageCommand = () =>
87
93
  };
88
94
  };
89
95
 
96
+ const getAdminBasicNavigationCommands = () =>
97
+ function useAdminBasicNavigationCommands() {
98
+ const { isBlockBasedTheme, canCreateTemplate } = useSelect(
99
+ ( select ) => {
100
+ return {
101
+ isBlockBasedTheme:
102
+ select( coreStore ).getCurrentTheme()?.is_block_theme,
103
+ canCreateTemplate: select( coreStore ).canUser( 'create', {
104
+ kind: 'postType',
105
+ name: 'wp_template',
106
+ } ),
107
+ };
108
+ },
109
+ []
110
+ );
111
+
112
+ const commands = useMemo( () => {
113
+ if ( canCreateTemplate && isBlockBasedTheme ) {
114
+ const isSiteEditor = getPath( window.location.href )?.includes(
115
+ 'site-editor.php'
116
+ );
117
+ if ( ! isSiteEditor ) {
118
+ return [
119
+ {
120
+ name: 'core/go-to-site-editor',
121
+ label: __( 'Open Site Editor' ),
122
+ callback: ( { close } ) => {
123
+ close();
124
+ document.location = 'site-editor.php';
125
+ },
126
+ },
127
+ ];
128
+ }
129
+ }
130
+
131
+ return [];
132
+ }, [ canCreateTemplate, isBlockBasedTheme ] );
133
+
134
+ return {
135
+ commands,
136
+ isLoading: false,
137
+ };
138
+ };
139
+
140
+ const getDashboardCommand = () =>
141
+ function useDashboardCommand() {
142
+ const currentPath = getPath( window.location.href );
143
+
144
+ const isEditorScreen =
145
+ currentPath?.includes( 'site-editor.php' ) ||
146
+ currentPath?.includes( 'post.php' ) ||
147
+ currentPath?.includes( 'post-new.php' ) ||
148
+ currentPath?.includes( 'widgets.php' ) ||
149
+ currentPath?.includes( 'customize.php' );
150
+
151
+ const commands = useMemo( () => {
152
+ if ( isEditorScreen ) {
153
+ return [
154
+ {
155
+ name: 'core/dashboard',
156
+ label: __( 'Dashboard' ),
157
+ icon: dashboard,
158
+ callback: () => {
159
+ document.location.assign( 'index.php' );
160
+ },
161
+ },
162
+ ];
163
+ }
164
+ return [];
165
+ }, [ isEditorScreen ] );
166
+
167
+ return {
168
+ isLoading: false,
169
+ commands,
170
+ };
171
+ };
172
+
90
173
  export function useAdminNavigationCommands() {
91
174
  useCommand( {
92
175
  name: 'core/add-new-post',
@@ -95,10 +178,21 @@ export function useAdminNavigationCommands() {
95
178
  callback: () => {
96
179
  document.location.assign( 'post-new.php' );
97
180
  },
181
+ keywords: [ __( 'post' ), __( 'new' ), __( 'add' ), __( 'create' ) ],
182
+ } );
183
+
184
+ useCommandLoader( {
185
+ name: 'core/dashboard',
186
+ hook: getDashboardCommand(),
98
187
  } );
99
188
 
100
189
  useCommandLoader( {
101
190
  name: 'core/add-new-page',
102
191
  hook: getAddNewPageCommand(),
103
192
  } );
193
+
194
+ useCommandLoader( {
195
+ name: 'core/admin-navigation',
196
+ hook: getAdminBasicNavigationCommands(),
197
+ } );
104
198
  }
package/src/index.js CHANGED
@@ -30,9 +30,6 @@ function CommandPalette() {
30
30
  * Initializes the Command Palette.
31
31
  */
32
32
  export function initializeCommandPalette() {
33
- if ( ! globalThis.IS_GUTENBERG_PLUGIN ) {
34
- return;
35
- }
36
33
  const root = document.createElement( 'div' );
37
34
  document.body.appendChild( root );
38
35
  createRoot( root ).render(