@wordpress/core-commands 0.7.0 → 0.9.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 +4 -0
- package/build/admin-navigation-commands.js +34 -8
- package/build/admin-navigation-commands.js.map +1 -1
- package/build/hooks.js +20 -0
- package/build/hooks.js.map +1 -0
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +1 -5
- package/build/private-apis.js.map +1 -1
- package/build/site-editor-navigation-commands.js +35 -41
- package/build/site-editor-navigation-commands.js.map +1 -1
- package/build/utils/order-entity-records-by-search.js +26 -0
- package/build/utils/order-entity-records-by-search.js.map +1 -0
- package/build-module/admin-navigation-commands.js +34 -5
- package/build-module/admin-navigation-commands.js.map +1 -1
- package/build-module/hooks.js +12 -0
- package/build-module/hooks.js.map +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +0 -2
- package/build-module/private-apis.js.map +1 -1
- package/build-module/site-editor-navigation-commands.js +36 -33
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/build-module/utils/order-entity-records-by-search.js +20 -0
- package/build-module/utils/order-entity-records-by-search.js.map +1 -0
- package/package.json +14 -12
- package/src/admin-navigation-commands.js +35 -5
- package/src/hooks.js +19 -0
- package/src/site-editor-navigation-commands.js +39 -16
- package/src/utils/order-entity-records-by-search.js +25 -0
- package/src/utils/test/order-entity-records-by-search.js +83 -0
|
@@ -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,"
|
|
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,14 +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
|
|
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 { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
|
|
16
17
|
import { unlock } from './lock-unlock';
|
|
18
|
+
import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';
|
|
17
19
|
const {
|
|
18
20
|
useHistory
|
|
19
21
|
} = unlock(routerPrivateApis);
|
|
@@ -23,7 +25,6 @@ const icons = {
|
|
|
23
25
|
wp_template: layout,
|
|
24
26
|
wp_template_part: symbolFilled
|
|
25
27
|
};
|
|
26
|
-
|
|
27
28
|
const getNavigationCommandLoaderPerPostType = postType => function useNavigationCommandLoader({
|
|
28
29
|
search
|
|
29
30
|
}) {
|
|
@@ -49,8 +50,20 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
49
50
|
isLoading: !select(coreStore).hasFinishedResolution('getEntityRecords', ['postType', postType, query])
|
|
50
51
|
};
|
|
51
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]);
|
|
52
65
|
const commands = useMemo(() => {
|
|
53
|
-
return
|
|
66
|
+
return orderedRecords.map(record => {
|
|
54
67
|
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
55
68
|
const extraArgs = isSiteEditor ? {
|
|
56
69
|
canvas: getQueryArg(window.location.href, 'canvas')
|
|
@@ -69,37 +82,38 @@ const getNavigationCommandLoaderPerPostType = postType => function useNavigation
|
|
|
69
82
|
...extraArgs
|
|
70
83
|
};
|
|
71
84
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
72
|
-
|
|
73
85
|
if (isSiteEditor) {
|
|
74
86
|
history.push(args);
|
|
75
87
|
} else {
|
|
76
88
|
document.location = targetUrl;
|
|
77
89
|
}
|
|
78
|
-
|
|
79
90
|
close();
|
|
80
91
|
}
|
|
81
92
|
};
|
|
82
93
|
});
|
|
83
|
-
}, [
|
|
94
|
+
}, [orderedRecords, history]);
|
|
84
95
|
return {
|
|
85
96
|
commands,
|
|
86
97
|
isLoading
|
|
87
98
|
};
|
|
88
99
|
};
|
|
89
|
-
|
|
90
100
|
const usePageNavigationCommandLoader = getNavigationCommandLoaderPerPostType('page');
|
|
91
101
|
const usePostNavigationCommandLoader = getNavigationCommandLoaderPerPostType('post');
|
|
92
102
|
const useTemplateNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template');
|
|
93
103
|
const useTemplatePartNavigationCommandLoader = getNavigationCommandLoaderPerPostType('wp_template_part');
|
|
94
|
-
|
|
95
104
|
function useSiteEditorBasicNavigationCommands() {
|
|
96
105
|
const history = useHistory();
|
|
97
106
|
const isSiteEditor = getPath(window.location.href)?.includes('site-editor.php');
|
|
107
|
+
const isTemplatesAccessible = useIsTemplatesAccessible();
|
|
108
|
+
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
98
109
|
const commands = useMemo(() => {
|
|
99
110
|
const result = [];
|
|
111
|
+
if (!isTemplatesAccessible || !isBlockBasedTheme) {
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
100
114
|
result.push({
|
|
101
115
|
name: 'core/edit-site/open-navigation',
|
|
102
|
-
label: __('
|
|
116
|
+
label: __('Navigation'),
|
|
103
117
|
icon: navigation,
|
|
104
118
|
callback: ({
|
|
105
119
|
close
|
|
@@ -108,61 +122,55 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
108
122
|
path: '/navigation'
|
|
109
123
|
};
|
|
110
124
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
111
|
-
|
|
112
125
|
if (isSiteEditor) {
|
|
113
126
|
history.push(args);
|
|
114
127
|
} else {
|
|
115
128
|
document.location = targetUrl;
|
|
116
129
|
}
|
|
117
|
-
|
|
118
130
|
close();
|
|
119
131
|
}
|
|
120
132
|
});
|
|
121
133
|
result.push({
|
|
122
|
-
name: 'core/edit-site/open-
|
|
123
|
-
label: __('
|
|
124
|
-
icon:
|
|
134
|
+
name: 'core/edit-site/open-styles',
|
|
135
|
+
label: __('Styles'),
|
|
136
|
+
icon: styles,
|
|
125
137
|
callback: ({
|
|
126
138
|
close
|
|
127
139
|
}) => {
|
|
128
140
|
const args = {
|
|
129
|
-
path: '/
|
|
141
|
+
path: '/wp_global_styles'
|
|
130
142
|
};
|
|
131
143
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
132
|
-
|
|
133
144
|
if (isSiteEditor) {
|
|
134
145
|
history.push(args);
|
|
135
146
|
} else {
|
|
136
147
|
document.location = targetUrl;
|
|
137
148
|
}
|
|
138
|
-
|
|
139
149
|
close();
|
|
140
150
|
}
|
|
141
151
|
});
|
|
142
152
|
result.push({
|
|
143
|
-
name: 'core/edit-site/open-
|
|
144
|
-
label: __('
|
|
145
|
-
icon:
|
|
153
|
+
name: 'core/edit-site/open-pages',
|
|
154
|
+
label: __('Pages'),
|
|
155
|
+
icon: page,
|
|
146
156
|
callback: ({
|
|
147
157
|
close
|
|
148
158
|
}) => {
|
|
149
159
|
const args = {
|
|
150
|
-
path: '/
|
|
160
|
+
path: '/page'
|
|
151
161
|
};
|
|
152
162
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
153
|
-
|
|
154
163
|
if (isSiteEditor) {
|
|
155
164
|
history.push(args);
|
|
156
165
|
} else {
|
|
157
166
|
document.location = targetUrl;
|
|
158
167
|
}
|
|
159
|
-
|
|
160
168
|
close();
|
|
161
169
|
}
|
|
162
170
|
});
|
|
163
171
|
result.push({
|
|
164
172
|
name: 'core/edit-site/open-templates',
|
|
165
|
-
label: __('
|
|
173
|
+
label: __('Templates'),
|
|
166
174
|
icon: layout,
|
|
167
175
|
callback: ({
|
|
168
176
|
close
|
|
@@ -171,19 +179,17 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
171
179
|
path: '/wp_template'
|
|
172
180
|
};
|
|
173
181
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
174
|
-
|
|
175
182
|
if (isSiteEditor) {
|
|
176
183
|
history.push(args);
|
|
177
184
|
} else {
|
|
178
185
|
document.location = targetUrl;
|
|
179
186
|
}
|
|
180
|
-
|
|
181
187
|
close();
|
|
182
188
|
}
|
|
183
189
|
});
|
|
184
190
|
result.push({
|
|
185
|
-
name: 'core/edit-site/open-
|
|
186
|
-
label: __('
|
|
191
|
+
name: 'core/edit-site/open-patterns',
|
|
192
|
+
label: __('Patterns'),
|
|
187
193
|
icon: symbol,
|
|
188
194
|
callback: ({
|
|
189
195
|
close
|
|
@@ -192,24 +198,21 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
192
198
|
path: '/patterns'
|
|
193
199
|
};
|
|
194
200
|
const targetUrl = addQueryArgs('site-editor.php', args);
|
|
195
|
-
|
|
196
201
|
if (isSiteEditor) {
|
|
197
202
|
history.push(args);
|
|
198
203
|
} else {
|
|
199
204
|
document.location = targetUrl;
|
|
200
205
|
}
|
|
201
|
-
|
|
202
206
|
close();
|
|
203
207
|
}
|
|
204
208
|
});
|
|
205
209
|
return result;
|
|
206
|
-
}, [history, isSiteEditor]);
|
|
210
|
+
}, [history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme]);
|
|
207
211
|
return {
|
|
208
212
|
commands,
|
|
209
213
|
isLoading: false
|
|
210
214
|
};
|
|
211
215
|
}
|
|
212
|
-
|
|
213
216
|
export function useSiteEditorNavigationCommands() {
|
|
214
217
|
useCommandLoader({
|
|
215
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","symbol","privateApis","routerPrivateApis","getQueryArg","addQueryArgs","getPath","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","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,EAOCC,MAPD,QAQO,kBARP;AASA,SAASC,WAAW,IAAIC,iBAAxB,QAAiD,mBAAjD;AACA,SAASC,WAAT,EAAsBC,YAAtB,EAAoCC,OAApC,QAAmD,gBAAnD;AAEA;AACA;AACA;;AACA,SAASC,MAAT,QAAuB,eAAvB;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,MAAM,CAAEJ,iBAAF,CAA7B;AAEA,MAAMM,KAAK,GAAG;AACbd,EAAAA,IADa;AAEbC,EAAAA,IAFa;AAGbc,EAAAA,WAAW,EAAEb,MAHA;AAIbc,EAAAA,gBAAgB,EAAEb;AAJL,CAAd;;AAOA,MAAMc,qCAAqC,GAAKC,QAAF,IAC7C,SAASC,0BAAT,CAAqC;AAAEC,EAAAA;AAAF,CAArC,EAAkD;AACjD,QAAMC,OAAO,GAAGR,UAAU,EAA1B;AACA,QAAMS,c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,IAAI,EAAE,wCADW;AAEjBsB,IAAAA,IAAI,EAAEL;AAFW,GAAF,CAAhB;AAIAnE,EAAAA,gBAAgB,CAAE;AACjBkD,IAAAA,IAAI,EAAE,iCADW;AAEjBsB,IAAAA,IAAI,EAAEJ,oCAFW;AAGjBK,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\tsymbol,\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 { 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 commands = useMemo( () => {\n\t\tconst result = [];\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\tresult.push( {\n\t\t\tname: 'core/edit-site/open-template-parts',\n\t\t\tlabel: __( 'Open 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\t\treturn result;\n\t}, [ history, isSiteEditor ] );\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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E,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.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "WordPress core reusable commands.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -27,21 +27,23 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.16.0",
|
|
30
|
-
"@wordpress/
|
|
31
|
-
"@wordpress/
|
|
32
|
-
"@wordpress/data": "^
|
|
33
|
-
"@wordpress/
|
|
34
|
-
"@wordpress/
|
|
35
|
-
"@wordpress/
|
|
36
|
-
"@wordpress/
|
|
37
|
-
"@wordpress/
|
|
38
|
-
"@wordpress/
|
|
30
|
+
"@wordpress/block-editor": "^12.8.0",
|
|
31
|
+
"@wordpress/commands": "^0.11.0",
|
|
32
|
+
"@wordpress/core-data": "^6.17.0",
|
|
33
|
+
"@wordpress/data": "^9.10.0",
|
|
34
|
+
"@wordpress/element": "^5.17.0",
|
|
35
|
+
"@wordpress/i18n": "^4.40.0",
|
|
36
|
+
"@wordpress/icons": "^9.31.0",
|
|
37
|
+
"@wordpress/private-apis": "^0.22.0",
|
|
38
|
+
"@wordpress/router": "^0.9.0",
|
|
39
|
+
"@wordpress/url": "^3.41.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"react": "^18.0.0"
|
|
42
|
+
"react": "^18.0.0",
|
|
43
|
+
"react-dom": "^18.0.0"
|
|
42
44
|
},
|
|
43
45
|
"publishConfig": {
|
|
44
46
|
"access": "public"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "78a288d55b83a713b2f7d98d5a855c0771a2afc6"
|
|
47
49
|
}
|
|
@@ -3,9 +3,27 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useCommand } from '@wordpress/commands';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { external, plus } from '@wordpress/icons';
|
|
6
|
+
import { external, plus, symbol } from '@wordpress/icons';
|
|
7
|
+
import { addQueryArgs, getPath } from '@wordpress/url';
|
|
8
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks';
|
|
14
|
+
import { unlock } from './lock-unlock';
|
|
15
|
+
|
|
16
|
+
const { useHistory } = unlock( routerPrivateApis );
|
|
7
17
|
|
|
8
18
|
export function useAdminNavigationCommands() {
|
|
19
|
+
const history = useHistory();
|
|
20
|
+
const isTemplatesAccessible = useIsTemplatesAccessible();
|
|
21
|
+
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
22
|
+
|
|
23
|
+
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
24
|
+
'site-editor.php'
|
|
25
|
+
);
|
|
26
|
+
|
|
9
27
|
useCommand( {
|
|
10
28
|
name: 'core/add-new-post',
|
|
11
29
|
label: __( 'Add new post' ),
|
|
@@ -24,10 +42,22 @@ export function useAdminNavigationCommands() {
|
|
|
24
42
|
} );
|
|
25
43
|
useCommand( {
|
|
26
44
|
name: 'core/manage-reusable-blocks',
|
|
27
|
-
label: __( '
|
|
28
|
-
callback: () => {
|
|
29
|
-
|
|
45
|
+
label: __( 'Open patterns' ),
|
|
46
|
+
callback: ( { close } ) => {
|
|
47
|
+
if ( isTemplatesAccessible && isBlockBasedTheme ) {
|
|
48
|
+
const args = {
|
|
49
|
+
path: '/patterns',
|
|
50
|
+
};
|
|
51
|
+
if ( isSiteEditor ) {
|
|
52
|
+
history.push( args );
|
|
53
|
+
} else {
|
|
54
|
+
document.location = addQueryArgs( 'site-editor.php', args );
|
|
55
|
+
}
|
|
56
|
+
close();
|
|
57
|
+
} else {
|
|
58
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
59
|
+
}
|
|
30
60
|
},
|
|
31
|
-
icon: external,
|
|
61
|
+
icon: isSiteEditor ? symbol : external,
|
|
32
62
|
} );
|
|
33
63
|
}
|
package/src/hooks.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
export function useIsTemplatesAccessible() {
|
|
8
|
+
return useSelect(
|
|
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,
|
|
17
|
+
[]
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
post,
|
|
11
11
|
page,
|
|
12
12
|
layout,
|
|
13
|
+
symbol,
|
|
13
14
|
symbolFilled,
|
|
14
15
|
styles,
|
|
15
16
|
navigation,
|
|
16
|
-
symbol,
|
|
17
17
|
} from '@wordpress/icons';
|
|
18
18
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
19
19
|
import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
@@ -21,7 +21,9 @@ import { getQueryArg, addQueryArgs, getPath } from '@wordpress/url';
|
|
|
21
21
|
/**
|
|
22
22
|
* Internal dependencies
|
|
23
23
|
*/
|
|
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
|
|
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
|
-
}, [
|
|
120
|
+
}, [ orderedRecords, history ] );
|
|
106
121
|
|
|
107
122
|
return {
|
|
108
123
|
commands,
|
|
@@ -124,11 +139,18 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
124
139
|
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
125
140
|
'site-editor.php'
|
|
126
141
|
);
|
|
142
|
+
const isTemplatesAccessible = useIsTemplatesAccessible();
|
|
143
|
+
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
127
144
|
const commands = useMemo( () => {
|
|
128
145
|
const result = [];
|
|
146
|
+
|
|
147
|
+
if ( ! isTemplatesAccessible || ! isBlockBasedTheme ) {
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
|
|
129
151
|
result.push( {
|
|
130
152
|
name: 'core/edit-site/open-navigation',
|
|
131
|
-
label: __( '
|
|
153
|
+
label: __( 'Navigation' ),
|
|
132
154
|
icon: navigation,
|
|
133
155
|
callback: ( { close } ) => {
|
|
134
156
|
const args = {
|
|
@@ -145,12 +167,12 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
145
167
|
} );
|
|
146
168
|
|
|
147
169
|
result.push( {
|
|
148
|
-
name: 'core/edit-site/open-
|
|
149
|
-
label: __( '
|
|
150
|
-
icon:
|
|
170
|
+
name: 'core/edit-site/open-styles',
|
|
171
|
+
label: __( 'Styles' ),
|
|
172
|
+
icon: styles,
|
|
151
173
|
callback: ( { close } ) => {
|
|
152
174
|
const args = {
|
|
153
|
-
path: '/
|
|
175
|
+
path: '/wp_global_styles',
|
|
154
176
|
};
|
|
155
177
|
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
156
178
|
if ( isSiteEditor ) {
|
|
@@ -163,12 +185,12 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
163
185
|
} );
|
|
164
186
|
|
|
165
187
|
result.push( {
|
|
166
|
-
name: 'core/edit-site/open-
|
|
167
|
-
label: __( '
|
|
168
|
-
icon:
|
|
188
|
+
name: 'core/edit-site/open-pages',
|
|
189
|
+
label: __( 'Pages' ),
|
|
190
|
+
icon: page,
|
|
169
191
|
callback: ( { close } ) => {
|
|
170
192
|
const args = {
|
|
171
|
-
path: '/
|
|
193
|
+
path: '/page',
|
|
172
194
|
};
|
|
173
195
|
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
174
196
|
if ( isSiteEditor ) {
|
|
@@ -182,7 +204,7 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
182
204
|
|
|
183
205
|
result.push( {
|
|
184
206
|
name: 'core/edit-site/open-templates',
|
|
185
|
-
label: __( '
|
|
207
|
+
label: __( 'Templates' ),
|
|
186
208
|
icon: layout,
|
|
187
209
|
callback: ( { close } ) => {
|
|
188
210
|
const args = {
|
|
@@ -199,8 +221,8 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
199
221
|
} );
|
|
200
222
|
|
|
201
223
|
result.push( {
|
|
202
|
-
name: 'core/edit-site/open-
|
|
203
|
-
label: __( '
|
|
224
|
+
name: 'core/edit-site/open-patterns',
|
|
225
|
+
label: __( 'Patterns' ),
|
|
204
226
|
icon: symbol,
|
|
205
227
|
callback: ( { close } ) => {
|
|
206
228
|
const args = {
|
|
@@ -215,8 +237,9 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
215
237
|
close();
|
|
216
238
|
},
|
|
217
239
|
} );
|
|
240
|
+
|
|
218
241
|
return result;
|
|
219
|
-
}, [ history, isSiteEditor ] );
|
|
242
|
+
}, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] );
|
|
220
243
|
|
|
221
244
|
return {
|
|
222
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
|
+
}
|