@wordpress/core-commands 0.8.0 → 0.9.1

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/admin-navigation-commands.js +6 -15
  3. package/build/admin-navigation-commands.js.map +1 -1
  4. package/build/hooks.js +8 -8
  5. package/build/hooks.js.map +1 -1
  6. package/build/index.js +0 -1
  7. package/build/index.js.map +1 -1
  8. package/build/lock-unlock.js +1 -2
  9. package/build/lock-unlock.js.map +1 -1
  10. package/build/private-apis.js +1 -5
  11. package/build/private-apis.js.map +1 -1
  12. package/build/site-editor-navigation-commands.js +49 -42
  13. package/build/site-editor-navigation-commands.js.map +1 -1
  14. package/build/utils/order-entity-records-by-search.js +26 -0
  15. package/build/utils/order-entity-records-by-search.js.map +1 -0
  16. package/build-module/admin-navigation-commands.js +7 -8
  17. package/build-module/admin-navigation-commands.js.map +1 -1
  18. package/build-module/hooks.js +5 -3
  19. package/build-module/hooks.js.map +1 -1
  20. package/build-module/index.js.map +1 -1
  21. package/build-module/lock-unlock.js.map +1 -1
  22. package/build-module/private-apis.js +0 -2
  23. package/build-module/private-apis.js.map +1 -1
  24. package/build-module/site-editor-navigation-commands.js +51 -34
  25. package/build-module/site-editor-navigation-commands.js.map +1 -1
  26. package/build-module/utils/order-entity-records-by-search.js +20 -0
  27. package/build-module/utils/order-entity-records-by-search.js.map +1 -0
  28. package/package.json +14 -13
  29. package/src/admin-navigation-commands.js +6 -5
  30. package/src/hooks.js +9 -6
  31. package/src/site-editor-navigation-commands.js +51 -16
  32. package/src/utils/order-entity-records-by-search.js +25 -0
  33. package/src/utils/test/order-entity-records-by-search.js +83 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-commands/src/lock-unlock.js"],"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAT,QAAiE,yBAAjE;AAEA,OAAO,MAAM;AAAEC,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZF,gDAAgD,CAC/C,8GAD+C,EAE/C,0BAF+C,CAD1C","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/core-commands'\n\t);\n"]}
1
+ {"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/core-commands/src/lock-unlock.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/core-commands'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAE1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,8GAA8G,EAC9G,0BACD,CAAC"}
@@ -4,12 +4,10 @@
4
4
  import { useAdminNavigationCommands } from './admin-navigation-commands';
5
5
  import { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';
6
6
  import { lock } from './lock-unlock';
7
-
8
7
  function useCommands() {
9
8
  useAdminNavigationCommands();
10
9
  useSiteEditorNavigationCommands();
11
10
  }
12
-
13
11
  export const privateApis = {};
14
12
  lock(privateApis, {
15
13
  useCommands
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-commands/src/private-apis.js"],"names":["useAdminNavigationCommands","useSiteEditorNavigationCommands","lock","useCommands","privateApis"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,0BAAT,QAA2C,6BAA3C;AACA,SAASC,+BAAT,QAAgD,mCAAhD;AACA,SAASC,IAAT,QAAqB,eAArB;;AAEA,SAASC,WAAT,GAAuB;AACtBH,EAAAA,0BAA0B;AAC1BC,EAAAA,+BAA+B;AAC/B;;AAED,OAAO,MAAMG,WAAW,GAAG,EAApB;AACPF,IAAI,CAAEE,WAAF,EAAe;AAClBD,EAAAA;AADkB,CAAf,CAAJ","sourcesContent":["/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { lock } from './lock-unlock';\n\nfunction useCommands() {\n\tuseAdminNavigationCommands();\n\tuseSiteEditorNavigationCommands();\n}\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommands,\n} );\n"]}
1
+ {"version":3,"names":["useAdminNavigationCommands","useSiteEditorNavigationCommands","lock","useCommands","privateApis"],"sources":["@wordpress/core-commands/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useAdminNavigationCommands } from './admin-navigation-commands';\nimport { useSiteEditorNavigationCommands } from './site-editor-navigation-commands';\nimport { lock } from './lock-unlock';\n\nfunction useCommands() {\n\tuseAdminNavigationCommands();\n\tuseSiteEditorNavigationCommands();\n}\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseCommands,\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,0BAA0B,QAAQ,6BAA6B;AACxE,SAASC,+BAA+B,QAAQ,mCAAmC;AACnF,SAASC,IAAI,QAAQ,eAAe;AAEpC,SAASC,WAAWA,CAAA,EAAG;EACtBH,0BAA0B,CAAC,CAAC;EAC5BC,+BAA+B,CAAC,CAAC;AAClC;AAEA,OAAO,MAAMG,WAAW,GAAG,CAAC,CAAC;AAC7BF,IAAI,CAAEE,WAAW,EAAE;EAClBD;AACD,CAAE,CAAC"}
@@ -6,15 +6,16 @@ import { __ } from '@wordpress/i18n';
6
6
  import { useMemo } from '@wordpress/element';
7
7
  import { useSelect } from '@wordpress/data';
8
8
  import { store as coreStore } from '@wordpress/core-data';
9
- import { post, page, layout, symbolFilled, styles, navigation } from '@wordpress/icons';
9
+ import { post, page, layout, symbol, symbolFilled, styles, navigation } from '@wordpress/icons';
10
10
  import { privateApis as routerPrivateApis } from '@wordpress/router';
11
11
  import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
12
+
12
13
  /**
13
14
  * Internal dependencies
14
15
  */
15
-
16
- import { useIsSiteEditorAccessible } from './hooks';
16
+ import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
17
17
  import { unlock } from './lock-unlock';
18
+ import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';
18
19
  const {
19
20
  useHistory
20
21
  } = unlock(routerPrivateApis);
@@ -24,7 +25,6 @@ const icons = {
24
25
  wp_template: layout,
25
26
  wp_template_part: symbolFilled
26
27
  };
27
-
28
28
  const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
29
29
  search
30
30
  }) {
@@ -50,8 +50,20 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
50
50
  isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
51
51
  };
52
52
  }, [supportsSearch, search]);
53
+
54
+ /*
55
+ * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
56
+ * We need to sort the results based on the search query to avoid removing relevant
57
+ * records below using .slice().
58
+ */
59
+ const orderedRecords = useMemo(() => {
60
+ if (supportsSearch) {
61
+ return records !== null && records !== void 0 ? records : [];
62
+ }
63
+ return orderEntityRecordsBySearch(records, search).slice(0, 10);
64
+ }, [supportsSearch, records, search]);
53
65
  const commands = useMemo(() => {
54
- return (records !== null && records !== void 0 ? records : []).slice(0, 10).map(record => {
66
+ return orderedRecords.map(record => {
55
67
  const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
56
68
  const extraArgs = isSiteEditor ? {
57
69
  canvas: getQueryArg(window.location.href, 'canvas')
@@ -70,43 +82,38 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
70
82
  ...extraArgs
71
83
  };
72
84
  const targetUrl = addQueryArgs('site-editor.php', args);
73
-
74
85
  if (isSiteEditor) {
75
86
  history.push(args);
76
87
  } else {
77
88
  document.location = targetUrl;
78
89
  }
79
-
80
90
  close();
81
91
  }
82
92
  };
83
93
  });
84
- }, [records, history]);
94
+ }, [orderedRecords, history]);
85
95
  return {
86
96
  commands,
87
97
  isLoading
88
98
  };
89
99
  };
90
-
91
100
  const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
92
101
  const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
93
102
  const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
94
103
  const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
95
-
96
104
  function useSiteEditorBasicNavigationCommands() {
97
105
  const history = useHistory();
98
106
  const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
99
- const isSiteEditorAccessible = useIsSiteEditorAccessible();
107
+ const isTemplatesAccessible = useIsTemplatesAccessible();
108
+ const isBlockBasedTheme = useIsBlockBasedTheme();
100
109
  const commands = useMemo(() => {
101
110
  const result = [];
102
-
103
- if (!isSiteEditorAccessible) {
111
+ if (!isTemplatesAccessible || !isBlockBasedTheme) {
104
112
  return result;
105
113
  }
106
-
107
114
  result.push({
108
115
  name: 'core/edit-site/open-navigation',
109
- label: __('Open navigation'),
116
+ label: __('Navigation'),
110
117
  icon: navigation,
111
118
  callback: ({
112
119
  close
@@ -115,61 +122,55 @@ function useSiteEditorBasicNavigationCommands() {
115
122
  path: '/navigation'
116
123
  };
117
124
  const targetUrl = addQueryArgs('site-editor.php', args);
118
-
119
125
  if (isSiteEditor) {
120
126
  history.push(args);
121
127
  } else {
122
128
  document.location = targetUrl;
123
129
  }
124
-
125
130
  close();
126
131
  }
127
132
  });
128
133
  result.push({
129
- name: 'core/edit-site/open-pages',
130
- label: __('Open pages'),
131
- icon: page,
134
+ name: 'core/edit-site/open-styles',
135
+ label: __('Styles'),
136
+ icon: styles,
132
137
  callback: ({
133
138
  close
134
139
  }) => {
135
140
  const args = {
136
- path: '/page'
141
+ path: '/wp_global_styles'
137
142
  };
138
143
  const targetUrl = addQueryArgs('site-editor.php', args);
139
-
140
144
  if (isSiteEditor) {
141
145
  history.push(args);
142
146
  } else {
143
147
  document.location = targetUrl;
144
148
  }
145
-
146
149
  close();
147
150
  }
148
151
  });
149
152
  result.push({
150
- name: 'core/edit-site/open-style-variations',
151
- label: __('Open style variations'),
152
- icon: styles,
153
+ name: 'core/edit-site/open-pages',
154
+ label: __('Pages'),
155
+ icon: page,
153
156
  callback: ({
154
157
  close
155
158
  }) => {
156
159
  const args = {
157
- path: '/wp_global_styles'
160
+ path: '/page'
158
161
  };
159
162
  const targetUrl = addQueryArgs('site-editor.php', args);
160
-
161
163
  if (isSiteEditor) {
162
164
  history.push(args);
163
165
  } else {
164
166
  document.location = targetUrl;
165
167
  }
166
-
167
168
  close();
168
169
  }
169
170
  });
170
171
  result.push({
171
172
  name: 'core/edit-site/open-templates',
172
- label: __('Open templates'),
173
+ label: __('Templates'),
173
174
  icon: layout,
174
175
  callback: ({
175
176
  close
@@ -178,24 +179,40 @@ function useSiteEditorBasicNavigationCommands() {
178
179
  path: '/wp_template'
179
180
  };
180
181
  const targetUrl = addQueryArgs('site-editor.php', args);
181
-
182
182
  if (isSiteEditor) {
183
183
  history.push(args);
184
184
  } else {
185
185
  document.location = targetUrl;
186
186
  }
187
-
187
+ close();
188
+ }
189
+ });
190
+ result.push({
191
+ name: 'core/edit-site/open-patterns',
192
+ label: __('Patterns'),
193
+ icon: symbol,
194
+ callback: ({
195
+ close
196
+ }) => {
197
+ const args = {
198
+ path: '/patterns'
199
+ };
200
+ const targetUrl = addQueryArgs('site-editor.php', args);
201
+ if (isSiteEditor) {
202
+ history.push(args);
203
+ } else {
204
+ document.location = targetUrl;
205
+ }
188
206
  close();
189
207
  }
190
208
  });
191
209
  return result;
192
- }, [history, isSiteEditor, isSiteEditorAccessible]);
210
+ }, [history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme]);
193
211
  return {
194
212
  commands,
195
213
  isLoading: false
196
214
  };
197
215
  }
198
-
199
216
  export function useSiteEditorNavigationCommands() {
200
217
  useCommandLoader({
201
218
  name: 'core/edit-site/navigate-pages',
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-commands/src/site-editor-navigation-commands.js"],"names":["useCommandLoader","__","useMemo","useSelect","store","coreStore","post","page","layout","symbolFilled","styles","navigation","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","useIsSiteEditorAccessible","unlock","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","commands","slice","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","isSiteEditorAccessible","result","path","useSiteEditorNavigationCommands","hook","context"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,QAAiC,qBAAjC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,IADD,EAECC,IAFD,EAGCC,MAHD,EAICC,YAJD,EAKCC,MALD,EAMCC,UAND,QAOO,kBAPP;AAQA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,yBAAT,QAA0C,SAA1C;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AAA,IAAI,EAAEN;AAFW,GAAF,CAAhB;AAIAnE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,iCADW;AAEjBuB,IAAAA,IAAI,EAAEL,oCAFW;AAGjBM,IAAAA,OAAO,EAAE;AAHQ,GAAF,CAAhB;AAKA","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\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 { useIsSiteEditorAccessible } from './hooks';\nimport { unlock } from './lock-unlock';\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\tconst commands = useMemo( () => {\n\t\t\treturn ( records ?? [] ).slice( 0, 10 ).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}, [ records, 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 isSiteEditorAccessible = useIsSiteEditorAccessible();\n\tconst commands = useMemo( () => {\n\t\tconst result = [];\n\n\t\tif ( ! isSiteEditorAccessible ) {\n\t\t\treturn result;\n\t\t}\n\t\tresult.push( {\n\t\t\tname: 'core/edit-site/open-navigation',\n\t\t\tlabel: __( 'Open 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-pages',\n\t\t\tlabel: __( 'Open 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-style-variations',\n\t\t\tlabel: __( 'Open style variations' ),\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-templates',\n\t\t\tlabel: __( 'Open 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\treturn result;\n\t}, [ history, isSiteEditor, isSiteEditorAccessible ] );\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"]}
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,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,cAAc,GAAG,CAAE,CAAE,aAAa,EAAE,kBAAkB,CAAE,CAACC,QAAQ,CACtEL,QACD,CAAC;EACD,MAAM;IAAEM,OAAO;IAAEC;EAAU,CAAC,GAAG/B,SAAS,CACrCgC,MAAM,IAAM;IACb,MAAM;MAAEC;IAAiB,CAAC,GAAGD,MAAM,CAAE9B,SAAU,CAAC;IAChD,MAA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,CAAC;MACvB2D,IAAI,EAAEnD,MAAM;MACZoD,QAAQ,EAAEA,CAAE;QAAEC;MAAM,CAAC,KAAM;QAC1B,MAAMC,IAAI,GAAG;UACZa,IAAI,EAAE;QACP,CAAC;QACD,MAAMX,SAAS,GAAGjD,YAAY,CAAE,iBAAiB,EAAE+C,IAAK,CAAC;QACzD,IAAKf,YAAY,EAAG;UACnBlB,OAAO,CAACoC,IAAI,CAAEH,IAAK,CAAC;QACrB,CAAC,MAAM;UACNI,QAAQ,CAACjB,QAAQ,GAAGe,SAAS;QAC9B;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"}
@@ -0,0 +1,20 @@
1
+ export function orderEntityRecordsBySearch(records = [], search = '') {
2
+ if (!Array.isArray(records) || !records.length) {
3
+ return [];
4
+ }
5
+ if (!search) {
6
+ return records;
7
+ }
8
+ const priority = [];
9
+ const nonPriority = [];
10
+ for (let i = 0; i < records.length; i++) {
11
+ const record = records[i];
12
+ if (record?.title?.raw?.toLowerCase()?.includes(search?.toLowerCase())) {
13
+ priority.push(record);
14
+ } else {
15
+ nonPriority.push(record);
16
+ }
17
+ }
18
+ return priority.concat(nonPriority);
19
+ }
20
+ //# sourceMappingURL=order-entity-records-by-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["orderEntityRecordsBySearch","records","search","Array","isArray","length","priority","nonPriority","i","record","title","raw","toLowerCase","includes","push","concat"],"sources":["@wordpress/core-commands/src/utils/order-entity-records-by-search.js"],"sourcesContent":["export function orderEntityRecordsBySearch( records = [], search = '' ) {\n\tif ( ! Array.isArray( records ) || ! records.length ) {\n\t\treturn [];\n\t}\n\n\tif ( ! search ) {\n\t\treturn records;\n\t}\n\n\tconst priority = [];\n\tconst nonPriority = [];\n\n\tfor ( let i = 0; i < records.length; i++ ) {\n\t\tconst record = records[ i ];\n\t\tif (\n\t\t\trecord?.title?.raw?.toLowerCase()?.includes( search?.toLowerCase() )\n\t\t) {\n\t\t\tpriority.push( record );\n\t\t} else {\n\t\t\tnonPriority.push( record );\n\t\t}\n\t}\n\n\treturn priority.concat( nonPriority );\n}\n"],"mappings":"AAAA,OAAO,SAASA,0BAA0BA,CAAEC,OAAO,GAAG,EAAE,EAAEC,MAAM,GAAG,EAAE,EAAG;EACvE,IAAK,CAAEC,KAAK,CAACC,OAAO,CAAEH,OAAQ,CAAC,IAAI,CAAEA,OAAO,CAACI,MAAM,EAAG;IACrD,OAAO,EAAE;EACV;EAEA,IAAK,CAAEH,MAAM,EAAG;IACf,OAAOD,OAAO;EACf;EAEA,MAAMK,QAAQ,GAAG,EAAE;EACnB,MAAMC,WAAW,GAAG,EAAE;EAEtB,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGP,OAAO,CAACI,MAAM,EAAEG,CAAC,EAAE,EAAG;IAC1C,MAAMC,MAAM,GAAGR,OAAO,CAAEO,CAAC,CAAE;IAC3B,IACCC,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAEC,WAAW,CAAC,CAAC,EAAEC,QAAQ,CAAEX,MAAM,EAAEU,WAAW,CAAC,CAAE,CAAC,EACnE;MACDN,QAAQ,CAACQ,IAAI,CAAEL,MAAO,CAAC;IACxB,CAAC,MAAM;MACNF,WAAW,CAACO,IAAI,CAAEL,MAAO,CAAC;IAC3B;EACD;EAEA,OAAOH,QAAQ,CAACS,MAAM,CAAER,WAAY,CAAC;AACtC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-commands",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "WordPress core reusable commands.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -27,22 +27,23 @@
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.16.0",
30
- "@wordpress/block-editor": "^12.7.0",
31
- "@wordpress/commands": "^0.10.0",
32
- "@wordpress/core-data": "^6.16.0",
33
- "@wordpress/data": "^9.9.0",
34
- "@wordpress/element": "^5.16.0",
35
- "@wordpress/i18n": "^4.39.0",
36
- "@wordpress/icons": "^9.30.0",
37
- "@wordpress/private-apis": "^0.21.0",
38
- "@wordpress/router": "^0.8.0",
39
- "@wordpress/url": "^3.40.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"
40
40
  },
41
41
  "peerDependencies": {
42
- "react": "^18.0.0"
42
+ "react": "^18.0.0",
43
+ "react-dom": "^18.0.0"
43
44
  },
44
45
  "publishConfig": {
45
46
  "access": "public"
46
47
  },
47
- "gitHead": "b898cf1dc8e70841d1647ea0994ac6278acc18a7"
48
+ "gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
48
49
  }
@@ -10,14 +10,15 @@ import { privateApis as routerPrivateApis } from '@wordpress/router';
10
10
  /**
11
11
  * Internal dependencies
12
12
  */
13
- import { useIsSiteEditorAccessible } from './hooks';
13
+ import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
14
14
  import { unlock } from './lock-unlock';
15
15
 
16
16
  const { useHistory } = unlock( routerPrivateApis );
17
17
 
18
18
  export function useAdminNavigationCommands() {
19
19
  const history = useHistory();
20
- const isSiteEditorAccessible = useIsSiteEditorAccessible();
20
+ const isTemplatesAccessible = useIsTemplatesAccessible();
21
+ const isBlockBasedTheme = useIsBlockBasedTheme();
21
22
 
22
23
  const isSiteEditor = getPath( window.location.href )?.includes(
23
24
  'site-editor.php'
@@ -43,9 +44,7 @@ export function useAdminNavigationCommands() {
43
44
  name: 'core/manage-reusable-blocks',
44
45
  label: __( 'Open patterns' ),
45
46
  callback: ( { close } ) => {
46
- if ( ! isSiteEditorAccessible ) {
47
- document.location.href = 'edit.php?post_type=wp_block';
48
- } else {
47
+ if ( isTemplatesAccessible && isBlockBasedTheme ) {
49
48
  const args = {
50
49
  path: '/patterns',
51
50
  };
@@ -55,6 +54,8 @@ export function useAdminNavigationCommands() {
55
54
  document.location = addQueryArgs( 'site-editor.php', args );
56
55
  }
57
56
  close();
57
+ } else {
58
+ document.location.href = 'edit.php?post_type=wp_block';
58
59
  }
59
60
  },
60
61
  icon: isSiteEditor ? symbol : external,
package/src/hooks.js CHANGED
@@ -1,16 +1,19 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store as blockEditorStore } from '@wordpress/block-editor';
5
4
  import { store as coreStore } from '@wordpress/core-data';
6
5
  import { useSelect } from '@wordpress/data';
7
6
 
8
- export function useIsSiteEditorAccessible() {
7
+ export function useIsTemplatesAccessible() {
9
8
  return useSelect(
10
- ( select ) =>
11
- select( blockEditorStore ).getSettings()
12
- .__unstableIsBlockBasedTheme &&
13
- select( coreStore ).canUser( 'read', 'templates' ),
9
+ ( select ) => select( coreStore ).canUser( 'read', 'templates' ),
10
+ []
11
+ );
12
+ }
13
+
14
+ export function useIsBlockBasedTheme() {
15
+ return useSelect(
16
+ ( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme,
14
17
  []
15
18
  );
16
19
  }
@@ -10,6 +10,7 @@ import {
10
10
  post,
11
11
  page,
12
12
  layout,
13
+ symbol,
13
14
  symbolFilled,
14
15
  styles,
15
16
  navigation,
@@ -20,8 +21,9 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
20
21
  /**
21
22
  * Internal dependencies
22
23
  */
23
- import { useIsSiteEditorAccessible } from './hooks';
24
+ import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
24
25
  import { unlock } from './lock-unlock';
26
+ import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';
25
27
 
26
28
  const { useHistory } = unlock( routerPrivateApis );
27
29
 
@@ -68,8 +70,21 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
68
70
  [ supportsSearch, search ]
69
71
  );
70
72
 
73
+ /*
74
+ * wp_template and wp_template_part endpoints do not support per_page or orderby parameters.
75
+ * We need to sort the results based on the search query to avoid removing relevant
76
+ * records below using .slice().
77
+ */
78
+ const orderedRecords = useMemo( () => {
79
+ if ( supportsSearch ) {
80
+ return records ?? [];
81
+ }
82
+
83
+ return orderEntityRecordsBySearch( records, search ).slice( 0, 10 );
84
+ }, [ supportsSearch, records, search ] );
85
+
71
86
  const commands = useMemo( () => {
72
- return ( records ?? [] ).slice( 0, 10 ).map( ( record ) => {
87
+ return orderedRecords.map( ( record ) => {
73
88
  const isSiteEditor = getPath( window.location.href )?.includes(
74
89
  'site-editor.php'
75
90
  );
@@ -102,7 +117,7 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
102
117
  },
103
118
  };
104
119
  } );
105
- }, [ records, history ] );
120
+ }, [ orderedRecords, history ] );
106
121
 
107
122
  return {
108
123
  commands,
@@ -124,16 +139,18 @@ function useSiteEditorBasicNavigationCommands() {
124
139
  const isSiteEditor = getPath( window.location.href )?.includes(
125
140
  'site-editor.php'
126
141
  );
127
- const isSiteEditorAccessible = useIsSiteEditorAccessible();
142
+ const isTemplatesAccessible = useIsTemplatesAccessible();
143
+ const isBlockBasedTheme = useIsBlockBasedTheme();
128
144
  const commands = useMemo( () => {
129
145
  const result = [];
130
146
 
131
- if ( ! isSiteEditorAccessible ) {
147
+ if ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {
132
148
  return result;
133
149
  }
150
+
134
151
  result.push( {
135
152
  name: 'core/edit-site/open-navigation',
136
- label: __( 'Open navigation' ),
153
+ label: __( 'Navigation' ),
137
154
  icon: navigation,
138
155
  callback: ( { close } ) => {
139
156
  const args = {
@@ -150,12 +167,12 @@ function useSiteEditorBasicNavigationCommands() {
150
167
  } );
151
168
 
152
169
  result.push( {
153
- name: 'core/edit-site/open-pages',
154
- label: __( 'Open pages' ),
155
- icon: page,
170
+ name: 'core/edit-site/open-styles',
171
+ label: __( 'Styles' ),
172
+ icon: styles,
156
173
  callback: ( { close } ) => {
157
174
  const args = {
158
- path: '/page',
175
+ path: '/wp_global_styles',
159
176
  };
160
177
  const targetUrl = addQueryArgs( 'site-editor.php', args );
161
178
  if ( isSiteEditor ) {
@@ -168,12 +185,12 @@ function useSiteEditorBasicNavigationCommands() {
168
185
  } );
169
186
 
170
187
  result.push( {
171
- name: 'core/edit-site/open-style-variations',
172
- label: __( 'Open style variations' ),
173
- icon: styles,
188
+ name: 'core/edit-site/open-pages',
189
+ label: __( 'Pages' ),
190
+ icon: page,
174
191
  callback: ( { close } ) => {
175
192
  const args = {
176
- path: '/wp_global_styles',
193
+ path: '/page',
177
194
  };
178
195
  const targetUrl = addQueryArgs( 'site-editor.php', args );
179
196
  if ( isSiteEditor ) {
@@ -187,7 +204,7 @@ function useSiteEditorBasicNavigationCommands() {
187
204
 
188
205
  result.push( {
189
206
  name: 'core/edit-site/open-templates',
190
- label: __( 'Open templates' ),
207
+ label: __( 'Templates' ),
191
208
  icon: layout,
192
209
  callback: ( { close } ) => {
193
210
  const args = {
@@ -203,8 +220,26 @@ function useSiteEditorBasicNavigationCommands() {
203
220
  },
204
221
  } );
205
222
 
223
+ result.push( {
224
+ name: 'core/edit-site/open-patterns',
225
+ label: __( 'Patterns' ),
226
+ icon: symbol,
227
+ callback: ( { close } ) => {
228
+ const args = {
229
+ path: '/patterns',
230
+ };
231
+ const targetUrl = addQueryArgs( 'site-editor.php', args );
232
+ if ( isSiteEditor ) {
233
+ history.push( args );
234
+ } else {
235
+ document.location = targetUrl;
236
+ }
237
+ close();
238
+ },
239
+ } );
240
+
206
241
  return result;
207
- }, [ history, isSiteEditor, isSiteEditorAccessible ] );
242
+ }, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );
208
243
 
209
244
  return {
210
245
  commands,
@@ -0,0 +1,25 @@
1
+ export function orderEntityRecordsBySearch( records = [], search = '' ) {
2
+ if ( ! Array.isArray( records ) || ! records.length ) {
3
+ return [];
4
+ }
5
+
6
+ if ( ! search ) {
7
+ return records;
8
+ }
9
+
10
+ const priority = [];
11
+ const nonPriority = [];
12
+
13
+ for ( let i = 0; i < records.length; i++ ) {
14
+ const record = records[ i ];
15
+ if (
16
+ record?.title?.raw?.toLowerCase()?.includes( search?.toLowerCase() )
17
+ ) {
18
+ priority.push( record );
19
+ } else {
20
+ nonPriority.push( record );
21
+ }
22
+ }
23
+
24
+ return priority.concat( nonPriority );
25
+ }