@wordpress/core-commands 0.26.0 → 1.0.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 +9 -1
- package/build/admin-navigation-commands.js +0 -40
- package/build/admin-navigation-commands.js.map +1 -1
- package/build/hooks.js +0 -4
- package/build/hooks.js.map +1 -1
- package/build/site-editor-navigation-commands.js +125 -87
- package/build/site-editor-navigation-commands.js.map +1 -1
- package/build-module/admin-navigation-commands.js +1 -41
- package/build-module/admin-navigation-commands.js.map +1 -1
- package/build-module/hooks.js +0 -3
- package/build-module/hooks.js.map +1 -1
- package/build-module/site-editor-navigation-commands.js +128 -90
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/package.json +15 -14
- package/src/admin-navigation-commands.js +1 -42
- package/src/hooks.js +0 -7
- package/src/site-editor-navigation-commands.js +141 -111
|
@@ -10,22 +10,23 @@ import {
|
|
|
10
10
|
post,
|
|
11
11
|
page,
|
|
12
12
|
layout,
|
|
13
|
+
symbol,
|
|
13
14
|
symbolFilled,
|
|
14
15
|
styles,
|
|
15
16
|
navigation,
|
|
16
17
|
} from '@wordpress/icons';
|
|
17
18
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
18
|
-
import {
|
|
19
|
+
import { addQueryArgs, getPath } from '@wordpress/url';
|
|
19
20
|
import { useDebounce } from '@wordpress/compose';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Internal dependencies
|
|
23
24
|
*/
|
|
24
|
-
import {
|
|
25
|
+
import { useIsBlockBasedTheme } from './hooks';
|
|
25
26
|
import { unlock } from './lock-unlock';
|
|
26
27
|
import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search';
|
|
27
28
|
|
|
28
|
-
const { useHistory
|
|
29
|
+
const { useHistory } = unlock( routerPrivateApis );
|
|
29
30
|
|
|
30
31
|
const icons = {
|
|
31
32
|
post,
|
|
@@ -118,14 +119,6 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
|
|
|
118
119
|
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
119
120
|
'site-editor.php'
|
|
120
121
|
);
|
|
121
|
-
const extraArgs = isSiteEditor
|
|
122
|
-
? {
|
|
123
|
-
canvas: getQueryArg(
|
|
124
|
-
window.location.href,
|
|
125
|
-
'canvas'
|
|
126
|
-
),
|
|
127
|
-
}
|
|
128
|
-
: {};
|
|
129
122
|
|
|
130
123
|
return {
|
|
131
124
|
...command,
|
|
@@ -133,7 +126,7 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
|
|
|
133
126
|
const args = {
|
|
134
127
|
postType,
|
|
135
128
|
postId: record.id,
|
|
136
|
-
|
|
129
|
+
canvas: 'edit',
|
|
137
130
|
};
|
|
138
131
|
const targetUrl = addQueryArgs(
|
|
139
132
|
'site-editor.php',
|
|
@@ -159,14 +152,6 @@ const getNavigationCommandLoaderPerPostType = ( postType ) =>
|
|
|
159
152
|
const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
|
|
160
153
|
function useNavigationCommandLoader( { search } ) {
|
|
161
154
|
const history = useHistory();
|
|
162
|
-
const location = useLocation();
|
|
163
|
-
|
|
164
|
-
const isPatternsPage =
|
|
165
|
-
location?.params?.path === '/patterns' ||
|
|
166
|
-
location?.params?.postType === 'wp_block';
|
|
167
|
-
const didAccessPatternsPage =
|
|
168
|
-
!! location?.params?.didAccessPatternsPage;
|
|
169
|
-
|
|
170
155
|
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
171
156
|
const { records, isLoading } = useSelect( ( select ) => {
|
|
172
157
|
const { getEntityRecords } = select( coreStore );
|
|
@@ -196,31 +181,52 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
|
|
|
196
181
|
) {
|
|
197
182
|
return [];
|
|
198
183
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
184
|
+
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
185
|
+
'site-editor.php'
|
|
186
|
+
);
|
|
187
|
+
const result = [];
|
|
188
|
+
result.push(
|
|
189
|
+
...orderedRecords.map( ( record ) => {
|
|
190
|
+
return {
|
|
191
|
+
name: templateType + '-' + record.id,
|
|
192
|
+
searchLabel: record.title?.rendered + ' ' + record.id,
|
|
193
|
+
label: record.title?.rendered
|
|
194
|
+
? record.title?.rendered
|
|
195
|
+
: __( '(no title)' ),
|
|
196
|
+
icon: icons[ templateType ],
|
|
197
|
+
callback: ( { close } ) => {
|
|
198
|
+
const args = {
|
|
199
|
+
postType: templateType,
|
|
200
|
+
postId: record.id,
|
|
201
|
+
canvas: 'edit',
|
|
202
|
+
};
|
|
203
|
+
const targetUrl = addQueryArgs(
|
|
204
|
+
'site-editor.php',
|
|
205
|
+
args
|
|
206
|
+
);
|
|
207
|
+
if ( isSiteEditor ) {
|
|
208
|
+
history.push( args );
|
|
209
|
+
} else {
|
|
210
|
+
document.location = targetUrl;
|
|
211
|
+
}
|
|
212
|
+
close();
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
} )
|
|
216
|
+
);
|
|
206
217
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
218
|
+
if (
|
|
219
|
+
orderedRecords?.length > 0 &&
|
|
220
|
+
templateType === 'wp_template_part'
|
|
221
|
+
) {
|
|
222
|
+
result.push( {
|
|
223
|
+
name: 'core/edit-site/open-template-parts',
|
|
224
|
+
label: __( 'Template parts' ),
|
|
225
|
+
icon: symbolFilled,
|
|
214
226
|
callback: ( { close } ) => {
|
|
215
227
|
const args = {
|
|
216
|
-
postType:
|
|
217
|
-
|
|
218
|
-
didAccessPatternsPage:
|
|
219
|
-
! isBlockBasedTheme &&
|
|
220
|
-
( isPatternsPage || didAccessPatternsPage )
|
|
221
|
-
? 1
|
|
222
|
-
: undefined,
|
|
223
|
-
...extraArgs,
|
|
228
|
+
postType: 'wp_template_part',
|
|
229
|
+
categoryId: 'all-parts',
|
|
224
230
|
};
|
|
225
231
|
const targetUrl = addQueryArgs(
|
|
226
232
|
'site-editor.php',
|
|
@@ -233,8 +239,9 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
|
|
|
233
239
|
}
|
|
234
240
|
close();
|
|
235
241
|
},
|
|
236
|
-
};
|
|
237
|
-
}
|
|
242
|
+
} );
|
|
243
|
+
}
|
|
244
|
+
return result;
|
|
238
245
|
}, [ isBlockBasedTheme, orderedRecords, history ] );
|
|
239
246
|
|
|
240
247
|
return {
|
|
@@ -257,89 +264,112 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
257
264
|
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
258
265
|
'site-editor.php'
|
|
259
266
|
);
|
|
260
|
-
const
|
|
267
|
+
const canCreateTemplate = useSelect( ( select ) => {
|
|
268
|
+
return select( coreStore ).canUser( 'create', 'templates' );
|
|
269
|
+
}, [] );
|
|
261
270
|
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
262
271
|
const commands = useMemo( () => {
|
|
263
272
|
const result = [];
|
|
264
273
|
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
274
|
+
if ( canCreateTemplate && isBlockBasedTheme ) {
|
|
275
|
+
result.push( {
|
|
276
|
+
name: 'core/edit-site/open-navigation',
|
|
277
|
+
label: __( 'Navigation' ),
|
|
278
|
+
icon: navigation,
|
|
279
|
+
callback: ( { close } ) => {
|
|
280
|
+
const args = {
|
|
281
|
+
postType: 'wp_navigation',
|
|
282
|
+
};
|
|
283
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
284
|
+
if ( isSiteEditor ) {
|
|
285
|
+
history.push( args );
|
|
286
|
+
} else {
|
|
287
|
+
document.location = targetUrl;
|
|
288
|
+
}
|
|
289
|
+
close();
|
|
290
|
+
},
|
|
291
|
+
} );
|
|
268
292
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
293
|
+
result.push( {
|
|
294
|
+
name: 'core/edit-site/open-styles',
|
|
295
|
+
label: __( 'Styles' ),
|
|
296
|
+
icon: styles,
|
|
297
|
+
callback: ( { close } ) => {
|
|
298
|
+
const args = {
|
|
299
|
+
path: '/wp_global_styles',
|
|
300
|
+
};
|
|
301
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
302
|
+
if ( isSiteEditor ) {
|
|
303
|
+
history.push( args );
|
|
304
|
+
} else {
|
|
305
|
+
document.location = targetUrl;
|
|
306
|
+
}
|
|
307
|
+
close();
|
|
308
|
+
},
|
|
309
|
+
} );
|
|
286
310
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
311
|
+
result.push( {
|
|
312
|
+
name: 'core/edit-site/open-pages',
|
|
313
|
+
label: __( 'Pages' ),
|
|
314
|
+
icon: page,
|
|
315
|
+
callback: ( { close } ) => {
|
|
316
|
+
const args = {
|
|
317
|
+
post_type: 'page',
|
|
318
|
+
};
|
|
319
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
320
|
+
if ( isSiteEditor ) {
|
|
321
|
+
history.push( args );
|
|
322
|
+
} else {
|
|
323
|
+
document.location = targetUrl;
|
|
324
|
+
}
|
|
325
|
+
close();
|
|
326
|
+
},
|
|
327
|
+
} );
|
|
304
328
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
329
|
+
result.push( {
|
|
330
|
+
name: 'core/edit-site/open-templates',
|
|
331
|
+
label: __( 'Templates' ),
|
|
332
|
+
icon: layout,
|
|
333
|
+
callback: ( { close } ) => {
|
|
334
|
+
const args = {
|
|
335
|
+
postType: 'wp_template',
|
|
336
|
+
};
|
|
337
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
338
|
+
if ( isSiteEditor ) {
|
|
339
|
+
history.push( args );
|
|
340
|
+
} else {
|
|
341
|
+
document.location = targetUrl;
|
|
342
|
+
}
|
|
343
|
+
close();
|
|
344
|
+
},
|
|
345
|
+
} );
|
|
346
|
+
}
|
|
322
347
|
|
|
323
348
|
result.push( {
|
|
324
|
-
name: 'core/edit-site/open-
|
|
325
|
-
label: __( '
|
|
326
|
-
icon:
|
|
349
|
+
name: 'core/edit-site/open-patterns',
|
|
350
|
+
label: __( 'Patterns' ),
|
|
351
|
+
icon: symbol,
|
|
327
352
|
callback: ( { close } ) => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
353
|
+
if ( canCreateTemplate ) {
|
|
354
|
+
const args = {
|
|
355
|
+
postType: 'wp_block',
|
|
356
|
+
};
|
|
357
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
358
|
+
if ( isSiteEditor ) {
|
|
359
|
+
history.push( args );
|
|
360
|
+
} else {
|
|
361
|
+
document.location = targetUrl;
|
|
362
|
+
}
|
|
363
|
+
close();
|
|
334
364
|
} else {
|
|
335
|
-
|
|
365
|
+
// If a user cannot access the site editor
|
|
366
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
336
367
|
}
|
|
337
|
-
close();
|
|
338
368
|
},
|
|
339
369
|
} );
|
|
340
370
|
|
|
341
371
|
return result;
|
|
342
|
-
}, [ history, isSiteEditor,
|
|
372
|
+
}, [ history, isSiteEditor, canCreateTemplate, isBlockBasedTheme ] );
|
|
343
373
|
|
|
344
374
|
return {
|
|
345
375
|
commands,
|