@wordpress/core-commands 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.10.0 (2023-08-31)
6
+
5
7
  ## 0.9.0 (2023-08-16)
6
8
 
7
9
  ## 0.8.0 (2023-08-10)
@@ -36,7 +36,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
36
36
  search
37
37
  }) {
38
38
  const history = useHistory();
39
- const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
39
+ const isBlockBasedTheme = (0, _hooks.useIsBlockBasedTheme)();
40
40
  const {
41
41
  records,
42
42
  isLoading
@@ -44,19 +44,91 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
44
44
  const {
45
45
  getEntityRecords
46
46
  } = select(_coreData.store);
47
- const query = supportsSearch ? {
47
+ const query = {
48
48
  search: !!search ? search : undefined,
49
49
  per_page: 10,
50
50
  orderby: search ? 'relevance' : 'date',
51
51
  status: ['publish', 'future', 'draft', 'pending', 'private']
52
- } : {
53
- per_page: -1
54
52
  };
55
53
  return {
56
54
  records: getEntityRecords('postType', postType, query),
57
55
  isLoading: !select(_coreData.store).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
58
56
  };
59
- }, [supportsSearch, search]);
57
+ }, [search]);
58
+ const commands = (0, _element.useMemo)(() => {
59
+ return (records !== null && records !== void 0 ? records : []).map(record => {
60
+ const command = {
61
+ name: postType + '-' + record.id,
62
+ searchLabel: record.title?.rendered + ' ' + record.id,
63
+ label: record.title?.rendered ? record.title?.rendered : (0, _i18n.__)('(no title)'),
64
+ icon: icons[postType]
65
+ };
66
+ if (postType === 'post' || postType === 'page' && !isBlockBasedTheme) {
67
+ return {
68
+ ...command,
69
+ callback: ({
70
+ close
71
+ }) => {
72
+ const args = {
73
+ post: record.id,
74
+ action: 'edit'
75
+ };
76
+ const targetUrl = (0, _url.addQueryArgs)('post.php', args);
77
+ document.location = targetUrl;
78
+ close();
79
+ }
80
+ };
81
+ }
82
+ const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
83
+ const extraArgs = isSiteEditor ? {
84
+ canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
85
+ } : {};
86
+ return {
87
+ ...command,
88
+ callback: ({
89
+ close
90
+ }) => {
91
+ const args = {
92
+ postType,
93
+ postId: record.id,
94
+ ...extraArgs
95
+ };
96
+ const targetUrl = (0, _url.addQueryArgs)('site-editor.php', args);
97
+ if (isSiteEditor) {
98
+ history.push(args);
99
+ } else {
100
+ document.location = targetUrl;
101
+ }
102
+ close();
103
+ }
104
+ };
105
+ });
106
+ }, [records, isBlockBasedTheme, history]);
107
+ return {
108
+ commands,
109
+ isLoading
110
+ };
111
+ };
112
+ const getNavigationCommandLoaderPerTemplate = templateType => function useNavigationCommandLoader({
113
+ search
114
+ }) {
115
+ const history = useHistory();
116
+ const isBlockBasedTheme = (0, _hooks.useIsBlockBasedTheme)();
117
+ const {
118
+ records,
119
+ isLoading
120
+ } = (0, _data.useSelect)(select => {
121
+ const {
122
+ getEntityRecords
123
+ } = select(_coreData.store);
124
+ const query = {
125
+ per_page: -1
126
+ };
127
+ return {
128
+ records: getEntityRecords('postType', templateType, query),
129
+ isLoading: !select(_coreData.store).hasFinishedResolution('getEntityRecords', ['postType', templateType, query])
130
+ };
131
+ }, []);
60
132
 
61
133
  /*
62
134
  * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
@@ -64,27 +136,27 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
64
136
  * records below using .slice().
65
137
  */
66
138
  const orderedRecords = (0, _element.useMemo)(() => {
67
- if (supportsSearch) {
68
- return records !== null && records !== void 0 ? records : [];
69
- }
70
139
  return (0, _orderEntityRecordsBySearch.orderEntityRecordsBySearch)(records, search).slice(0, 10);
71
- }, [supportsSearch, records, search]);
140
+ }, [records, search]);
72
141
  const commands = (0, _element.useMemo)(() => {
142
+ if (!isBlockBasedTheme && !templateType === 'wp_template_part') {
143
+ return [];
144
+ }
73
145
  return orderedRecords.map(record => {
74
146
  const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
75
147
  const extraArgs = isSiteEditor ? {
76
148
  canvas: (0, _url.getQueryArg)(window.location.href, 'canvas')
77
149
  } : {};
78
150
  return {
79
- name: postType + '-' + record.id,
151
+ name: templateType + '-' + record.id,
80
152
  searchLabel: record.title?.rendered + ' ' + record.id,
81
153
  label: record.title?.rendered ? record.title?.rendered : (0, _i18n.__)('(no title)'),
82
- icon: icons[postType],
154
+ icon: icons[templateType],
83
155
  callback: ({
84
156
  close
85
157
  }) => {
86
158
  const args = {
87
- postType,
159
+ postType: templateType,
88
160
  postId: record.id,
89
161
  ...extraArgs
90
162
  };
@@ -98,7 +170,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
98
170
  }
99
171
  };
100
172
  });
101
- }, [orderedRecords, history]);
173
+ }, [isBlockBasedTheme, orderedRecords, history]);
102
174
  return {
103
175
  commands,
104
176
  isLoading
@@ -106,8 +178,8 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
106
178
  };
107
179
  const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
108
180
  const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
109
- const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
110
- const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
181
+ const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template');
182
+ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template_part');
111
183
  function useSiteEditorBasicNavigationCommands() {
112
184
  const history = useHistory();
113
185
  const isSiteEditor = (0, _url.getPath)(window.location.href)?.includes('site-editor.php');
@@ -1 +1 @@
1
- {"version":3,"names":["_commands","require","_i18n","_element","_data","_coreData","_icons","_router","_url","_hooks","_lockUnlock","_orderEntityRecordsBySearch","useHistory","unlock","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","useSelect","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","status","hasFinishedResolution","orderedRecords","useMemo","orderEntityRecordsBySearch","slice","commands","map","record","isSiteEditor","getPath","window","location","href","extraArgs","canvas","getQueryArg","name","id","searchLabel","title","rendered","label","__","icon","callback","close","args","postId","targetUrl","addQueryArgs","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isTemplatesAccessible","useIsTemplatesAccessible","isBlockBasedTheme","useIsBlockBasedTheme","result","navigation","path","styles","symbol","useSiteEditorNavigationCommands","useCommandLoader","hook","context"],"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbol,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\nimport { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\t/*\n\t\t * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.\n\t\t * We need to sort the results based on the search query to avoid removing relevant\n\t\t * records below using .slice().\n\t\t */\n\t\tconst orderedRecords = useMemo( () => {\n\t\t\tif ( supportsSearch ) {\n\t\t\t\treturn records ?? [];\n\t\t\t}\n\n\t\t\treturn orderEntityRecordsBySearch( records, search ).slice( 0, 10 );\n\t\t}, [ supportsSearch, records, search ] );\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn orderedRecords.map( ( record ) => {\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ orderedRecords, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-styles',\n\t\t\tlabel: __( 'Styles' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-patterns',\n\t\t\tlabel: __( 'Patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useS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C;MAAM,CAAC,KAAM;QAC1B,MAAMC,IAAI,GAAG;UACZiB,IAAI,EAAE;QACP,CAAC;QACD,MAAMf,SAAS,GAAG,IAAAC,iBAAY,EAAE,iBAAiB,EAAEH,IAAK,CAAC;QACzD,IAAKlB,YAAY,EAAG;UACnBtB,OAAO,CAAC4C,IAAI,CAAEJ,IAAK,CAAC;QACrB,CAAC,MAAM;UACNK,QAAQ,CAACpB,QAAQ,GAAGiB,SAAS;QAC9B;QACAH,KAAK,CAAC,CAAC;MACR;IACD,CAAE,CAAC;IAEH,OAAOgB,MAAM;EACd,CAAC,EAAE,CAAEvD,OAAO,EAAEsB,YAAY,EAAE6B,qBAAqB,EAAEE,iBAAiB,CAAG,CAAC;EAExE,OAAO;IACNlC,QAAQ;IACRf,SAAS,EAAE;EACZ,CAAC;AACF;AAEO,SAASwD,+BAA+BA,CAAA,EAAG;EACjD,IAAAC,0BAAgB,EAAE;IACjB/B,IAAI,EAAE,+BAA+B;IACrCgC,IAAI,EAAEhB;EACP,CAAE,CAAC;EACH,IAAAe,0BAAgB,EAAE;IACjB/B,IAAI,EAAE,+BAA+B;IACrCgC,IAAI,EAAEf;EACP,CAAE,CAAC;EACH,IAAAc,0BAAgB,EAAE;IACjB/B,IAAI,EAAE,mCAAmC;IACzCgC,IAAI,EAAEd;EACP,CAAE,CAAC;EACH,IAAAa,0BAAgB,EAAE;IACjB/B,IAAI,EAAE,wCAAwC;IAC9CgC,IAAI,EAAEb;EACP,CAAE,CAAC;EACH,IAAAY,0BAAgB,EAAE;IACjB/B,IAAI,EAAE,iCAAiC;IACvCgC,IAAI,EAAEZ,oCAAoC;IAC1Ca,OAAO,EAAE;EACV,CAAE,CAAC;AACJ"}
1
+ {"version":3,"names":["_commands","require","_i18n","_element","_data","_coreData","_icons","_router","_url","_hooks","_lockUnlock","_orderEntityRecordsBySearch","useHistory","unlock","routerPrivateApis","icons","post","page","wp_template","layout","wp_template_part","symbolFilled","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","isBlockBasedTheme","useIsBlockBasedTheme","records","isLoading","useSelect","select","getEntityRecords","coreStore","query","undefined","per_page","orderby","status","hasFinishedResolution","commands","useMemo","map","record","command","name","id","searchLabel","title","rendered","label","__","icon","callback","close","args","action","targetUrl","addQueryArgs","document","location","isSiteEditor","getPath","window","href","includes","extraArgs","canvas","getQueryArg","postId","push","getNavigationCommandLoaderPerTemplate","templateType","orderedRecords","orderEntityRecordsBySearch","slice","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isTemplatesAccessible","useIsTemplatesAccessible","result","navigation","path","styles","symbol","useSiteEditorNavigationCommands","useCommandLoader","hook","context"],"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbol,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\nimport { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = {\n\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\tper_page: 10,\n\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\tstatus: [\n\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t'future',\n\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t'private',\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).map( ( record ) => {\n\t\t\t\tconst command = {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t};\n\n\t\t\t\tif (\n\t\t\t\t\tpostType === 'post' ||\n\t\t\t\t\t( postType === 'page' && ! isBlockBasedTheme )\n\t\t\t\t) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...command,\n\t\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\t\tpost: record.id,\n\t\t\t\t\t\t\t\taction: 'edit',\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst targetUrl = addQueryArgs( 'post.php', args );\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcanvas: getQueryArg(\n\t\t\t\t\t\t\t\twindow.location.href,\n\t\t\t\t\t\t\t\t'canvas'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t }\n\t\t\t\t\t: {};\n\n\t\t\t\treturn {\n\t\t\t\t\t...command,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ records, isBlockBasedTheme, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst getNavigationCommandLoaderPerTemplate = ( templateType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\t\tconst { records, isLoading } = useSelect( ( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst query = { per_page: -1 };\n\t\t\treturn {\n\t\t\t\trecords: getEntityRecords( 'postType', templateType, query ),\n\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t[ 'postType', templateType, query ]\n\t\t\t\t),\n\t\t\t};\n\t\t}, [] );\n\n\t\t/*\n\t\t * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.\n\t\t * We need to sort the results based on the search query to avoid removing relevant\n\t\t * records below using .slice().\n\t\t */\n\t\tconst orderedRecords = useMemo( () => {\n\t\t\treturn orderEntityRecordsBySearch( records, search ).slice( 0, 10 );\n\t\t}, [ records, search ] );\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif (\n\t\t\t\t! isBlockBasedTheme &&\n\t\t\t\t! templateType === 'wp_template_part'\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn orderedRecords.map( ( record ) => {\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\n\t\t\t\treturn {\n\t\t\t\t\tname: templateType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ templateType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType: templateType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ isBlockBasedTheme, orderedRecords, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerTemplate( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerTemplate( 'wp_template_part' );\n\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-styles',\n\t\t\tlabel: __( 'Styles' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-patterns',\n\t\t\tlabel: __( 'Patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AASA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,IAAA,GAAAP,OAAA;AAKA,IAAAQ,MAAA,GAAAR,OAAA;AACA,IAAAS,WAAA,GAAAT,OAAA;AACA,IAAAU,2BAAA,GAAAV,OAAA;AAzBA;AACA;AACA;;AAkBA;AACA;AACA;;AAKA,MAAM;EAAEW;AAAW,CAAC,GAAG,IAAAC,kBAAM,EAAEC,mBAAkB,CAAC;AAElD,MAAMC,KAAK,GAAG;EACbC,IAAI,EAAJA,WAAI;EACJC,IAAI,EAAJA,WAAI;EACJC,WAAW,EAAEC,aAAM;EACnBC,gBAAgB,EAAEC;AACnB,CAAC;AAED,MAAMC,qCAAqC,GAAKC,QAAQ,IACvD,SAASC,0BAA0BA,CAAE;EAAE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AAAW,0BAAgB,EAAE;IACjB5C,IAAI,EAAE,wCAAwC;IAC9C6C,IAAI,EAAEX;EACP,CAAE,CAAC;EACH,IAAAU,0BAAgB,EAAE;IACjB5C,IAAI,EAAE,iCAAiC;IACvC6C,IAAI,EAAEV,oCAAoC;IAC1CW,OAAO,EAAE;EACV,CAAE,CAAC;AACJ"}
@@ -29,7 +29,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
29
29
  search
30
30
  }) {
31
31
  const history = useHistory();
32
- const supportsSearch = !['wp_template', 'wp_template_part'].includes(postType);
32
+ const isBlockBasedTheme = useIsBlockBasedTheme();
33
33
  const {
34
34
  records,
35
35
  isLoading
@@ -37,19 +37,91 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
37
37
  const {
38
38
  getEntityRecords
39
39
  } = select(coreStore);
40
- const query = supportsSearch ? {
40
+ const query = {
41
41
  search: !!search ? search : undefined,
42
42
  per_page: 10,
43
43
  orderby: search ? 'relevance' : 'date',
44
44
  status: ['publish', 'future', 'draft', 'pending', 'private']
45
- } : {
46
- per_page: -1
47
45
  };
48
46
  return {
49
47
  records: getEntityRecords('postType', postType, query),
50
48
  isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
51
49
  };
52
- }, [supportsSearch, search]);
50
+ }, [search]);
51
+ const commands = useMemo(() => {
52
+ return (records !== null && records !== void 0 ? records : []).map(record => {
53
+ const command = {
54
+ name: postType + '-' + record.id,
55
+ searchLabel: record.title?.rendered + ' ' + record.id,
56
+ label: record.title?.rendered ? record.title?.rendered : __('(no title)'),
57
+ icon: icons[postType]
58
+ };
59
+ if (postType === 'post' || postType === 'page' && !isBlockBasedTheme) {
60
+ return {
61
+ ...command,
62
+ callback: ({
63
+ close
64
+ }) => {
65
+ const args = {
66
+ post: record.id,
67
+ action: 'edit'
68
+ };
69
+ const targetUrl = addQueryArgs('post.php', args);
70
+ document.location = targetUrl;
71
+ close();
72
+ }
73
+ };
74
+ }
75
+ const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
76
+ const extraArgs = isSiteEditor ? {
77
+ canvas: getQueryArg(window.location.href, 'canvas')
78
+ } : {};
79
+ return {
80
+ ...command,
81
+ callback: ({
82
+ close
83
+ }) => {
84
+ const args = {
85
+ postType,
86
+ postId: record.id,
87
+ ...extraArgs
88
+ };
89
+ const targetUrl = addQueryArgs('site-editor.php', args);
90
+ if (isSiteEditor) {
91
+ history.push(args);
92
+ } else {
93
+ document.location = targetUrl;
94
+ }
95
+ close();
96
+ }
97
+ };
98
+ });
99
+ }, [records, isBlockBasedTheme, history]);
100
+ return {
101
+ commands,
102
+ isLoading
103
+ };
104
+ };
105
+ const getNavigationCommandLoaderPerTemplate = templateType => function useNavigationCommandLoader({
106
+ search
107
+ }) {
108
+ const history = useHistory();
109
+ const isBlockBasedTheme = useIsBlockBasedTheme();
110
+ const {
111
+ records,
112
+ isLoading
113
+ } = useSelect(select => {
114
+ const {
115
+ getEntityRecords
116
+ } = select(coreStore);
117
+ const query = {
118
+ per_page: -1
119
+ };
120
+ return {
121
+ records: getEntityRecords('postType', templateType, query),
122
+ isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', templateType, query])
123
+ };
124
+ }, []);
53
125
 
54
126
  /*
55
127
  * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
@@ -57,27 +129,27 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
57
129
  * records below using .slice().
58
130
  */
59
131
  const orderedRecords = useMemo(() => {
60
- if (supportsSearch) {
61
- return records !== null && records !== void 0 ? records : [];
62
- }
63
132
  return orderEntityRecordsBySearch(records, search).slice(0, 10);
64
- }, [supportsSearch, records, search]);
133
+ }, [records, search]);
65
134
  const commands = useMemo(() => {
135
+ if (!isBlockBasedTheme && !templateType === 'wp_template_part') {
136
+ return [];
137
+ }
66
138
  return orderedRecords.map(record => {
67
139
  const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
68
140
  const extraArgs = isSiteEditor ? {
69
141
  canvas: getQueryArg(window.location.href, 'canvas')
70
142
  } : {};
71
143
  return {
72
- name: postType + '-' + record.id,
144
+ name: templateType + '-' + record.id,
73
145
  searchLabel: record.title?.rendered + ' ' + record.id,
74
146
  label: record.title?.rendered ? record.title?.rendered : __('(no title)'),
75
- icon: icons[postType],
147
+ icon: icons[templateType],
76
148
  callback: ({
77
149
  close
78
150
  }) => {
79
151
  const args = {
80
- postType,
152
+ postType: templateType,
81
153
  postId: record.id,
82
154
  ...extraArgs
83
155
  };
@@ -91,7 +163,7 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
91
163
  }
92
164
  };
93
165
  });
94
- }, [orderedRecords, history]);
166
+ }, [isBlockBasedTheme, orderedRecords, history]);
95
167
  return {
96
168
  commands,
97
169
  isLoading
@@ -99,8 +171,8 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
99
171
  };
100
172
  const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
101
173
  const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
102
- const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
103
- const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
174
+ const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template');
175
+ const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerTemplate('wp_template_part');
104
176
  function useSiteEditorBasicNavigationCommands() {
105
177
  const history = useHistory();
106
178
  const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
@@ -1 +1 @@
1
- {"version":3,"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbol","symbolFilled","styles","navigation","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","useIsTemplatesAccessible","useIsBlockBasedTheme","unlock","orderEntityRecordsBySearch","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","supportsSearch","includes","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","status","hasFinishedResolution","orderedRecords","slice","commands","map","record","isSiteEditor","window","location","href","extraArgs","canvas","name","id","searchLabel","title","rendered","label","icon","callback","close","args","postId","targetUrl","push","document","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isTemplatesAccessible","isBlockBasedTheme","result","path","useSiteEditorNavigationCommands","hook","context"],"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbol,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\nimport { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tpostType\n\t\t);\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = supportsSearch\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\t\t\tper_page: 10,\n\t\t\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\t\t\tstatus: [\n\t\t\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t\t\t'future',\n\t\t\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t\t\t'private',\n\t\t\t\t\t\t\t],\n\t\t\t\t\t }\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t };\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ supportsSearch, search ]\n\t\t);\n\n\t\t/*\n\t\t * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.\n\t\t * We need to sort the results based on the search query to avoid removing relevant\n\t\t * records below using .slice().\n\t\t */\n\t\tconst orderedRecords = useMemo( () => {\n\t\t\tif ( supportsSearch ) {\n\t\t\t\treturn records ?? [];\n\t\t\t}\n\n\t\t\treturn orderEntityRecordsBySearch( records, search ).slice( 0, 10 );\n\t\t}, [ supportsSearch, records, search ] );\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn orderedRecords.map( ( record ) => {\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\t\t\t\treturn {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ orderedRecords, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'wp_template_part' );\n\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-styles',\n\t\t\tlabel: __( 'Styles' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-patterns',\n\t\t\tlabel: __( 'Patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SACCC,IAAI,EACJC,I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C9B;QACAH,KAAK,CAAC,CAAC;MACR;IACD,CAAE,CAAC;IAEH,OAAOa,MAAM;EACd,CAAC,EAAE,CAAE7C,OAAO,EAAEkB,YAAY,EAAEyB,qBAAqB,EAAEC,iBAAiB,CAAG,CAAC;EAExE,OAAO;IACN7B,QAAQ;IACRX,SAAS,EAAE;EACZ,CAAC;AACF;AAEA,OAAO,SAAS2C,+BAA+BA,CAAA,EAAG;EACjD7E,gBAAgB,CAAE;IACjBsD,IAAI,EAAE,+BAA+B;IACrCwB,IAAI,EAAEV;EACP,CAAE,CAAC;EACHpE,gBAAgB,CAAE;IACjBsD,IAAI,EAAE,+BAA+B;IACrCwB,IAAI,EAAET;EACP,CAAE,CAAC;EACHrE,gBAAgB,CAAE;IACjBsD,IAAI,EAAE,mCAAmC;IACzCwB,IAAI,EAAER;EACP,CAAE,CAAC;EACHtE,gBAAgB,CAAE;IACjBsD,IAAI,EAAE,wCAAwC;IAC9CwB,IAAI,EAAEP;EACP,CAAE,CAAC;EACHvE,gBAAgB,CAAE;IACjBsD,IAAI,EAAE,iCAAiC;IACvCwB,IAAI,EAAEN,oCAAoC;IAC1CO,OAAO,EAAE;EACV,CAAE,CAAC;AACJ"}
1
+ {"version":3,"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbol","symbolFilled","styles","navigation","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","useIsTemplatesAccessible","useIsBlockBasedTheme","unlock","orderEntityRecordsBySearch","useHistory","icons","wp_template","wp_template_part","getNavigationCommandLoaderPerPostType","postType","useNavigationCommandLoader","search","history","isBlockBasedTheme","records","isLoading","select","getEntityRecords","query","undefined","per_page","orderby","status","hasFinishedResolution","commands","map","record","command","name","id","searchLabel","title","rendered","label","icon","callback","close","args","action","targetUrl","document","location","isSiteEditor","window","href","includes","extraArgs","canvas","postId","push","getNavigationCommandLoaderPerTemplate","templateType","orderedRecords","slice","usePageNavigationCommandLoader","usePostNavigationCommandLoader","useTemplateNavigationCommandLoader","useTemplatePartNavigationCommandLoader","useSiteEditorBasicNavigationCommands","isTemplatesAccessible","result","path","useSiteEditorNavigationCommands","hook","context"],"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCommandLoader } from '@wordpress/commands';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tpost,\n\tpage,\n\tlayout,\n\tsymbol,\n\tsymbolFilled,\n\tstyles,\n\tnavigation,\n} from '@wordpress/icons';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';\nimport { unlock } from './lock-unlock';\nimport { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst icons = {\n\tpost,\n\tpage,\n\twp_template: layout,\n\twp_template_part: symbolFilled,\n};\n\nconst getNavigationCommandLoaderPerPostType = ( postType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\t\tconst { records, isLoading } = useSelect(\n\t\t\t( select ) => {\n\t\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\t\tconst query = {\n\t\t\t\t\tsearch: !! search ? search : undefined,\n\t\t\t\t\tper_page: 10,\n\t\t\t\t\torderby: search ? 'relevance' : 'date',\n\t\t\t\t\tstatus: [\n\t\t\t\t\t\t'publish',\n\t\t\t\t\t\t'future',\n\t\t\t\t\t\t'draft',\n\t\t\t\t\t\t'pending',\n\t\t\t\t\t\t'private',\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t\treturn {\n\t\t\t\t\trecords: getEntityRecords( 'postType', postType, query ),\n\t\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t\t[ 'postType', postType, query ]\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ search ]\n\t\t);\n\n\t\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).map( ( record ) => {\n\t\t\t\tconst command = {\n\t\t\t\t\tname: postType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ postType ],\n\t\t\t\t};\n\n\t\t\t\tif (\n\t\t\t\t\tpostType === 'post' ||\n\t\t\t\t\t( postType === 'page' && ! isBlockBasedTheme )\n\t\t\t\t) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...command,\n\t\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\t\tpost: record.id,\n\t\t\t\t\t\t\t\taction: 'edit',\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst targetUrl = addQueryArgs( 'post.php', args );\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t\tclose();\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tcanvas: getQueryArg(\n\t\t\t\t\t\t\t\twindow.location.href,\n\t\t\t\t\t\t\t\t'canvas'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t }\n\t\t\t\t\t: {};\n\n\t\t\t\treturn {\n\t\t\t\t\t...command,\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ records, isBlockBasedTheme, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst getNavigationCommandLoaderPerTemplate = ( templateType ) =>\n\tfunction useNavigationCommandLoader( { search } ) {\n\t\tconst history = useHistory();\n\t\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\t\tconst { records, isLoading } = useSelect( ( select ) => {\n\t\t\tconst { getEntityRecords } = select( coreStore );\n\t\t\tconst query = { per_page: -1 };\n\t\t\treturn {\n\t\t\t\trecords: getEntityRecords( 'postType', templateType, query ),\n\t\t\t\tisLoading: ! select( coreStore ).hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\t[ 'postType', templateType, query ]\n\t\t\t\t),\n\t\t\t};\n\t\t}, [] );\n\n\t\t/*\n\t\t * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.\n\t\t * We need to sort the results based on the search query to avoid removing relevant\n\t\t * records below using .slice().\n\t\t */\n\t\tconst orderedRecords = useMemo( () => {\n\t\t\treturn orderEntityRecordsBySearch( records, search ).slice( 0, 10 );\n\t\t}, [ records, search ] );\n\n\t\tconst commands = useMemo( () => {\n\t\t\tif (\n\t\t\t\t! isBlockBasedTheme &&\n\t\t\t\t! templateType === 'wp_template_part'\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\treturn orderedRecords.map( ( record ) => {\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\tconst extraArgs = isSiteEditor\n\t\t\t\t\t? { canvas: getQueryArg( window.location.href, 'canvas' ) }\n\t\t\t\t\t: {};\n\n\t\t\t\treturn {\n\t\t\t\t\tname: templateType + '-' + record.id,\n\t\t\t\t\tsearchLabel: record.title?.rendered + ' ' + record.id,\n\t\t\t\t\tlabel: record.title?.rendered\n\t\t\t\t\t\t? record.title?.rendered\n\t\t\t\t\t\t: __( '(no title)' ),\n\t\t\t\t\ticon: icons[ templateType ],\n\t\t\t\t\tcallback: ( { close } ) => {\n\t\t\t\t\t\tconst args = {\n\t\t\t\t\t\t\tpostType: templateType,\n\t\t\t\t\t\t\tpostId: record.id,\n\t\t\t\t\t\t\t...extraArgs,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst targetUrl = addQueryArgs(\n\t\t\t\t\t\t\t'site-editor.php',\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\t\t\thistory.push( args );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t\t\t}\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}, [ isBlockBasedTheme, orderedRecords, history ] );\n\n\t\treturn {\n\t\t\tcommands,\n\t\t\tisLoading,\n\t\t};\n\t};\n\nconst usePageNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'page' );\nconst usePostNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerPostType( 'post' );\nconst useTemplateNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerTemplate( 'wp_template' );\nconst useTemplatePartNavigationCommandLoader =\n\tgetNavigationCommandLoaderPerTemplate( 'wp_template_part' );\n\nfunction useSiteEditorBasicNavigationCommands() {\n\tconst history = useHistory();\n\tconst isSiteEditor = getPath( window.location.href )?.includes(\n\t\t'site-editor.php'\n\t);\n\tconst isTemplatesAccessible = useIsTemplatesAccessible();\n\tconst isBlockBasedTheme = useIsBlockBasedTheme();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {\n\t\t\treturn result;\n\t\t}\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Navigation' ),\n\t\t\ticon: navigation,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/navigation',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-styles',\n\t\t\tlabel: __( 'Styles' ),\n\t\t\ticon: styles,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_global_styles',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-pages',\n\t\t\tlabel: __( 'Pages' ),\n\t\t\ticon: page,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/page',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-templates',\n\t\t\tlabel: __( 'Templates' ),\n\t\t\ticon: layout,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/wp_template',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-patterns',\n\t\t\tlabel: __( 'Patterns' ),\n\t\t\ticon: symbol,\n\t\t\tcallback: ( { close } ) => {\n\t\t\t\tconst args = {\n\t\t\t\t\tpath: '/patterns',\n\t\t\t\t};\n\t\t\t\tconst targetUrl = addQueryArgs( 'site-editor.php', args );\n\t\t\t\tif ( isSiteEditor ) {\n\t\t\t\t\thistory.push( args );\n\t\t\t\t} else {\n\t\t\t\t\tdocument.location = targetUrl;\n\t\t\t\t}\n\t\t\t\tclose();\n\t\t\t},\n\t\t} );\n\n\t\treturn result;\n\t}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );\n\n\treturn {\n\t\tcommands,\n\t\tisLoading: false,\n\t};\n}\n\nexport function useSiteEditorNavigationCommands() {\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-pages',\n\t\thook: usePageNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-posts',\n\t\thook: usePostNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-templates',\n\t\thook: useTemplateNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/navigate-template-parts',\n\t\thook: useTemplatePartNavigationCommandLoader,\n\t} );\n\tuseCommandLoader( {\n\t\tname: 'core/edit-site/basic-navigation',\n\t\thook: useSiteEditorBasicNavigationCommands,\n\t\tcontext: 'site-editor',\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SACCC,IAAI,EACJC,IAAI,EACJC,MAAM,EACNC,MAAM,EACNC,YAAY,EACZC,MAAM,EACNC,UAAU,QACJ,kBAAkB;AACzB,SAASC,WAAW,IAAIC,iBAAiB,QAAQ,mBAAmB;AACpE,SAASC,WAAW,EAAEC,YAAY,EAAEC,OAAO,QAAQ,gBAAgB;;AAEnE;AACA;AACA;AACA,SAASC,wBAAwB,EAAEC,oBAAoB,QAAQ,SAAS;AACxE,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,0BAA0B,QAAQ,wCAAwC;AAEnF,MAAM;EAAEC;AAAW,CAAC,GAAGF,MAAM,CAAEN,iBAAkB,CAAC;AAElD,MAAMS,KAAK,GAAG;EACbjB,IAAI;EACJC,IAAI;EACJiB,WAAW,EAAEhB,MAAM;EACnBiB,gBAAgB,EAAEf;AACnB,CAAC;AAED,MAAMgB,qCAAqC,GAAKC,QAAQ,IACvD,SAASC,0BAA0BA,CAAE;EAAEC;AAAO,CAAC,EAAG;EACjD,MAAMC,OAAO,GAAGR,UAAU,CAAC,CAAC;EAC5B,MAAMS,iBAAiB,GAAGZ,oBAAoB,CAAC,CAAC;EAChD,MAAM;IAAEa,OAAO;IAAEC;EAAU,CAAC,GAAG9B,SAAS,CACrC+B,MAAM,IAAM;IACb,MAAM;MAAEC;IAAiB,CAAC,GAAGD,MAAM,CAAE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E;QAAEC;MAAM,CAAC,KAAM;QAC1B,MAAMC,IAAI,GAAG;UACZwB,IAAI,EAAE;QACP,CAAC;QACD,MAAMtB,SAAS,GAAGzC,YAAY,CAAE,iBAAiB,EAAEuC,IAAK,CAAC;QACzD,IAAKK,YAAY,EAAG;UACnB9B,OAAO,CAACqC,IAAI,CAAEZ,IAAK,CAAC;QACrB,CAAC,MAAM;UACNG,QAAQ,CAACC,QAAQ,GAAGF,SAAS;QAC9B;QACAH,KAAK,CAAC,CAAC;MACR;IACD,CAAE,CAAC;IAEH,OAAOwB,MAAM;EACd,CAAC,EAAE,CAAEhD,OAAO,EAAE8B,YAAY,EAAEiB,qBAAqB,EAAE9C,iBAAiB,CAAG,CAAC;EAExE,OAAO;IACNW,QAAQ;IACRT,SAAS,EAAE;EACZ,CAAC;AACF;AAEA,OAAO,SAAS+C,+BAA+BA,CAAA,EAAG;EACjDhF,gBAAgB,CAAE;IACjB8C,IAAI,EAAE,+BAA+B;IACrCmC,IAAI,EAAET;EACP,CAAE,CAAC;EACHxE,gBAAgB,CAAE;IACjB8C,IAAI,EAAE,+BAA+B;IACrCmC,IAAI,EAAER;EACP,CAAE,CAAC;EACHzE,gBAAgB,CAAE;IACjB8C,IAAI,EAAE,mCAAmC;IACzCmC,IAAI,EAAEP;EACP,CAAE,CAAC;EACH1E,gBAAgB,CAAE;IACjB8C,IAAI,EAAE,wCAAwC;IAC9CmC,IAAI,EAAEN;EACP,CAAE,CAAC;EACH3E,gBAAgB,CAAE;IACjB8C,IAAI,EAAE,iCAAiC;IACvCmC,IAAI,EAAEL,oCAAoC;IAC1CM,OAAO,EAAE;EACV,CAAE,CAAC;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-commands",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "WordPress core reusable commands.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,16 +27,16 @@
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/block-editor": "^12.8.1",
31
- "@wordpress/commands": "^0.11.1",
32
- "@wordpress/core-data": "^6.17.1",
33
- "@wordpress/data": "^9.10.1",
34
- "@wordpress/element": "^5.17.1",
35
- "@wordpress/i18n": "^4.40.1",
36
- "@wordpress/icons": "^9.31.1",
37
- "@wordpress/private-apis": "^0.22.1",
38
- "@wordpress/router": "^0.9.1",
39
- "@wordpress/url": "^3.41.1"
30
+ "@wordpress/block-editor": "^12.9.0",
31
+ "@wordpress/commands": "^0.12.0",
32
+ "@wordpress/core-data": "^6.18.0",
33
+ "@wordpress/data": "^9.11.0",
34
+ "@wordpress/element": "^5.18.0",
35
+ "@wordpress/i18n": "^4.41.0",
36
+ "@wordpress/icons": "^9.32.0",
37
+ "@wordpress/private-apis": "^0.23.0",
38
+ "@wordpress/router": "^0.10.0",
39
+ "@wordpress/url": "^3.42.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": "^18.0.0",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
48
+ "gitHead": "5eac1734bcdca2301fdd37ec8cfe2a45e722a2c4"
49
49
  }
@@ -37,28 +37,22 @@ const icons = {
37
37
  const getNavigationCommandLoaderPerPostType = ( postType ) =>
38
38
  function useNavigationCommandLoader( { search } ) {
39
39
  const history = useHistory();
40
- const supportsSearch = ! [ 'wp_template', 'wp_template_part' ].includes(
41
- postType
42
- );
40
+ const isBlockBasedTheme = useIsBlockBasedTheme();
43
41
  const { records, isLoading } = useSelect(
44
42
  ( select ) => {
45
43
  const { getEntityRecords } = select( coreStore );
46
- const query = supportsSearch
47
- ? {
48
- search: !! search ? search : undefined,
49
- per_page: 10,
50
- orderby: search ? 'relevance' : 'date',
51
- status: [
52
- 'publish',
53
- 'future',
54
- 'draft',
55
- 'pending',
56
- 'private',
57
- ],
58
- }
59
- : {
60
- per_page: -1,
61
- };
44
+ const query = {
45
+ search: !! search ? search : undefined,
46
+ per_page: 10,
47
+ orderby: search ? 'relevance' : 'date',
48
+ status: [
49
+ 'publish',
50
+ 'future',
51
+ 'draft',
52
+ 'pending',
53
+ 'private',
54
+ ],
55
+ };
62
56
  return {
63
57
  records: getEntityRecords( 'postType', postType, query ),
64
58
  isLoading: ! select( coreStore ).hasFinishedResolution(
@@ -67,23 +61,111 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
67
61
  ),
68
62
  };
69
63
  },
70
- [ supportsSearch, search ]
64
+ [ search ]
71
65
  );
72
66
 
67
+ const commands = useMemo( () => {
68
+ return ( records ?? [] ).map( ( record ) => {
69
+ const command = {
70
+ name: postType + '-' + record.id,
71
+ searchLabel: record.title?.rendered + ' ' + record.id,
72
+ label: record.title?.rendered
73
+ ? record.title?.rendered
74
+ : __( '(no title)' ),
75
+ icon: icons[ postType ],
76
+ };
77
+
78
+ if (
79
+ postType === 'post' ||
80
+ ( postType === 'page' && ! isBlockBasedTheme )
81
+ ) {
82
+ return {
83
+ ...command,
84
+ callback: ( { close } ) => {
85
+ const args = {
86
+ post: record.id,
87
+ action: 'edit',
88
+ };
89
+ const targetUrl = addQueryArgs( 'post.php', args );
90
+ document.location = targetUrl;
91
+ close();
92
+ },
93
+ };
94
+ }
95
+
96
+ const isSiteEditor = getPath( window.location.href )?.includes(
97
+ 'site-editor.php'
98
+ );
99
+ const extraArgs = isSiteEditor
100
+ ? {
101
+ canvas: getQueryArg(
102
+ window.location.href,
103
+ 'canvas'
104
+ ),
105
+ }
106
+ : {};
107
+
108
+ return {
109
+ ...command,
110
+ callback: ( { close } ) => {
111
+ const args = {
112
+ postType,
113
+ postId: record.id,
114
+ ...extraArgs,
115
+ };
116
+ const targetUrl = addQueryArgs(
117
+ 'site-editor.php',
118
+ args
119
+ );
120
+ if ( isSiteEditor ) {
121
+ history.push( args );
122
+ } else {
123
+ document.location = targetUrl;
124
+ }
125
+ close();
126
+ },
127
+ };
128
+ } );
129
+ }, [ records, isBlockBasedTheme, history ] );
130
+
131
+ return {
132
+ commands,
133
+ isLoading,
134
+ };
135
+ };
136
+
137
+ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
138
+ function useNavigationCommandLoader( { search } ) {
139
+ const history = useHistory();
140
+ const isBlockBasedTheme = useIsBlockBasedTheme();
141
+ const { records, isLoading } = useSelect( ( select ) => {
142
+ const { getEntityRecords } = select( coreStore );
143
+ const query = { per_page: -1 };
144
+ return {
145
+ records: getEntityRecords( 'postType', templateType, query ),
146
+ isLoading: ! select( coreStore ).hasFinishedResolution(
147
+ 'getEntityRecords',
148
+ [ 'postType', templateType, query ]
149
+ ),
150
+ };
151
+ }, [] );
152
+
73
153
  /*
74
154
  * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
75
155
  * We need to sort the results based on the search query to avoid removing relevant
76
156
  * records below using .slice().
77
157
  */
78
158
  const orderedRecords = useMemo( () => {
79
- if ( supportsSearch ) {
80
- return records ?? [];
81
- }
82
-
83
159
  return orderEntityRecordsBySearch( records, search ).slice( 0, 10 );
84
- }, [ supportsSearch, records, search ] );
160
+ }, [ records, search ] );
85
161
 
86
162
  const commands = useMemo( () => {
163
+ if (
164
+ ! isBlockBasedTheme &&
165
+ ! templateType === 'wp_template_part'
166
+ ) {
167
+ return [];
168
+ }
87
169
  return orderedRecords.map( ( record ) => {
88
170
  const isSiteEditor = getPath( window.location.href )?.includes(
89
171
  'site-editor.php'
@@ -91,16 +173,17 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
91
173
  const extraArgs = isSiteEditor
92
174
  ? { canvas: getQueryArg( window.location.href, 'canvas' ) }
93
175
  : {};
176
+
94
177
  return {
95
- name: postType + '-' + record.id,
178
+ name: templateType + '-' + record.id,
96
179
  searchLabel: record.title?.rendered + ' ' + record.id,
97
180
  label: record.title?.rendered
98
181
  ? record.title?.rendered
99
182
  : __( '(no title)' ),
100
- icon: icons[ postType ],
183
+ icon: icons[ templateType ],
101
184
  callback: ( { close } ) => {
102
185
  const args = {
103
- postType,
186
+ postType: templateType,
104
187
  postId: record.id,
105
188
  ...extraArgs,
106
189
  };
@@ -117,7 +200,7 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
117
200
  },
118
201
  };
119
202
  } );
120
- }, [ orderedRecords, history ] );
203
+ }, [ isBlockBasedTheme, orderedRecords, history ] );
121
204
 
122
205
  return {
123
206
  commands,
@@ -130,9 +213,9 @@ const usePageNavigationCommandLoader =
130
213
  const usePostNavigationCommandLoader =
131
214
  getNavigationCommandLoaderPerPostType( 'post' );
132
215
  const useTemplateNavigationCommandLoader =
133
- getNavigationCommandLoaderPerPostType( 'wp_template' );
216
+ getNavigationCommandLoaderPerTemplate( 'wp_template' );
134
217
  const useTemplatePartNavigationCommandLoader =
135
- getNavigationCommandLoaderPerPostType( 'wp_template_part' );
218
+ getNavigationCommandLoaderPerTemplate( 'wp_template_part' );
136
219
 
137
220
  function useSiteEditorBasicNavigationCommands() {
138
221
  const history = useHistory();