@wordpress/core-commands 0.26.0 → 0.27.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 +2 -0
- 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 +123 -73
- 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 +125 -75
- package/build-module/site-editor-navigation-commands.js.map +1 -1
- package/package.json +13 -13
- package/src/admin-navigation-commands.js +1 -42
- package/src/hooks.js +0 -7
- package/src/site-editor-navigation-commands.js +153 -92
|
@@ -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,
|
|
@@ -21,7 +22,7 @@ import { useDebounce } from '@wordpress/compose';
|
|
|
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
|
|
|
@@ -196,31 +197,67 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
|
|
|
196
197
|
) {
|
|
197
198
|
return [];
|
|
198
199
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
200
|
+
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
201
|
+
'site-editor.php'
|
|
202
|
+
);
|
|
203
|
+
const result = [];
|
|
204
|
+
result.push(
|
|
205
|
+
...orderedRecords.map( ( record ) => {
|
|
206
|
+
const extraArgs = isSiteEditor
|
|
207
|
+
? {
|
|
208
|
+
canvas: getQueryArg(
|
|
209
|
+
window.location.href,
|
|
210
|
+
'canvas'
|
|
211
|
+
),
|
|
212
|
+
}
|
|
213
|
+
: {};
|
|
206
214
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
215
|
+
return {
|
|
216
|
+
name: templateType + '-' + record.id,
|
|
217
|
+
searchLabel: record.title?.rendered + ' ' + record.id,
|
|
218
|
+
label: record.title?.rendered
|
|
219
|
+
? record.title?.rendered
|
|
220
|
+
: __( '(no title)' ),
|
|
221
|
+
icon: icons[ templateType ],
|
|
222
|
+
callback: ( { close } ) => {
|
|
223
|
+
const args = {
|
|
224
|
+
postType: templateType,
|
|
225
|
+
postId: record.id,
|
|
226
|
+
didAccessPatternsPage:
|
|
227
|
+
! isBlockBasedTheme &&
|
|
228
|
+
( isPatternsPage || didAccessPatternsPage )
|
|
229
|
+
? 1
|
|
230
|
+
: undefined,
|
|
231
|
+
...extraArgs,
|
|
232
|
+
};
|
|
233
|
+
const targetUrl = addQueryArgs(
|
|
234
|
+
'site-editor.php',
|
|
235
|
+
args
|
|
236
|
+
);
|
|
237
|
+
if ( isSiteEditor ) {
|
|
238
|
+
history.push( args );
|
|
239
|
+
} else {
|
|
240
|
+
document.location = targetUrl;
|
|
241
|
+
}
|
|
242
|
+
close();
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
} )
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
if (
|
|
249
|
+
orderedRecords?.length > 0 &&
|
|
250
|
+
templateType === 'wp_template_part'
|
|
251
|
+
) {
|
|
252
|
+
result.push( {
|
|
253
|
+
name: 'core/edit-site/open-template-parts',
|
|
254
|
+
label: __( 'Template parts' ),
|
|
255
|
+
icon: symbolFilled,
|
|
214
256
|
callback: ( { close } ) => {
|
|
215
257
|
const args = {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
! isBlockBasedTheme &&
|
|
220
|
-
( isPatternsPage || didAccessPatternsPage )
|
|
221
|
-
? 1
|
|
222
|
-
: undefined,
|
|
223
|
-
...extraArgs,
|
|
258
|
+
path: '/patterns',
|
|
259
|
+
categoryType: 'wp_template_part',
|
|
260
|
+
categoryId: 'all-parts',
|
|
224
261
|
};
|
|
225
262
|
const targetUrl = addQueryArgs(
|
|
226
263
|
'site-editor.php',
|
|
@@ -233,8 +270,9 @@ const getNavigationCommandLoaderPerTemplate = ( templateType ) =>
|
|
|
233
270
|
}
|
|
234
271
|
close();
|
|
235
272
|
},
|
|
236
|
-
};
|
|
237
|
-
}
|
|
273
|
+
} );
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
238
276
|
}, [ isBlockBasedTheme, orderedRecords, history ] );
|
|
239
277
|
|
|
240
278
|
return {
|
|
@@ -257,89 +295,112 @@ function useSiteEditorBasicNavigationCommands() {
|
|
|
257
295
|
const isSiteEditor = getPath( window.location.href )?.includes(
|
|
258
296
|
'site-editor.php'
|
|
259
297
|
);
|
|
260
|
-
const
|
|
298
|
+
const canCreateTemplate = useSelect( ( select ) => {
|
|
299
|
+
return select( coreStore ).canUser( 'create', 'templates' );
|
|
300
|
+
}, [] );
|
|
261
301
|
const isBlockBasedTheme = useIsBlockBasedTheme();
|
|
262
302
|
const commands = useMemo( () => {
|
|
263
303
|
const result = [];
|
|
264
304
|
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
305
|
+
if ( canCreateTemplate && isBlockBasedTheme ) {
|
|
306
|
+
result.push( {
|
|
307
|
+
name: 'core/edit-site/open-navigation',
|
|
308
|
+
label: __( 'Navigation' ),
|
|
309
|
+
icon: navigation,
|
|
310
|
+
callback: ( { close } ) => {
|
|
311
|
+
const args = {
|
|
312
|
+
path: '/navigation',
|
|
313
|
+
};
|
|
314
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
315
|
+
if ( isSiteEditor ) {
|
|
316
|
+
history.push( args );
|
|
317
|
+
} else {
|
|
318
|
+
document.location = targetUrl;
|
|
319
|
+
}
|
|
320
|
+
close();
|
|
321
|
+
},
|
|
322
|
+
} );
|
|
268
323
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
324
|
+
result.push( {
|
|
325
|
+
name: 'core/edit-site/open-styles',
|
|
326
|
+
label: __( 'Styles' ),
|
|
327
|
+
icon: styles,
|
|
328
|
+
callback: ( { close } ) => {
|
|
329
|
+
const args = {
|
|
330
|
+
path: '/wp_global_styles',
|
|
331
|
+
};
|
|
332
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
333
|
+
if ( isSiteEditor ) {
|
|
334
|
+
history.push( args );
|
|
335
|
+
} else {
|
|
336
|
+
document.location = targetUrl;
|
|
337
|
+
}
|
|
338
|
+
close();
|
|
339
|
+
},
|
|
340
|
+
} );
|
|
286
341
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
342
|
+
result.push( {
|
|
343
|
+
name: 'core/edit-site/open-pages',
|
|
344
|
+
label: __( 'Pages' ),
|
|
345
|
+
icon: page,
|
|
346
|
+
callback: ( { close } ) => {
|
|
347
|
+
const args = {
|
|
348
|
+
path: '/page',
|
|
349
|
+
};
|
|
350
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
351
|
+
if ( isSiteEditor ) {
|
|
352
|
+
history.push( args );
|
|
353
|
+
} else {
|
|
354
|
+
document.location = targetUrl;
|
|
355
|
+
}
|
|
356
|
+
close();
|
|
357
|
+
},
|
|
358
|
+
} );
|
|
304
359
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
360
|
+
result.push( {
|
|
361
|
+
name: 'core/edit-site/open-templates',
|
|
362
|
+
label: __( 'Templates' ),
|
|
363
|
+
icon: layout,
|
|
364
|
+
callback: ( { close } ) => {
|
|
365
|
+
const args = {
|
|
366
|
+
path: '/wp_template',
|
|
367
|
+
};
|
|
368
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
369
|
+
if ( isSiteEditor ) {
|
|
370
|
+
history.push( args );
|
|
371
|
+
} else {
|
|
372
|
+
document.location = targetUrl;
|
|
373
|
+
}
|
|
374
|
+
close();
|
|
375
|
+
},
|
|
376
|
+
} );
|
|
377
|
+
}
|
|
322
378
|
|
|
323
379
|
result.push( {
|
|
324
|
-
name: 'core/edit-site/open-
|
|
325
|
-
label: __( '
|
|
326
|
-
icon:
|
|
380
|
+
name: 'core/edit-site/open-patterns',
|
|
381
|
+
label: __( 'Patterns' ),
|
|
382
|
+
icon: symbol,
|
|
327
383
|
callback: ( { close } ) => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
384
|
+
if ( canCreateTemplate ) {
|
|
385
|
+
const args = {
|
|
386
|
+
path: '/patterns',
|
|
387
|
+
};
|
|
388
|
+
const targetUrl = addQueryArgs( 'site-editor.php', args );
|
|
389
|
+
if ( isSiteEditor ) {
|
|
390
|
+
history.push( args );
|
|
391
|
+
} else {
|
|
392
|
+
document.location = targetUrl;
|
|
393
|
+
}
|
|
394
|
+
close();
|
|
334
395
|
} else {
|
|
335
|
-
|
|
396
|
+
// If a user cannot access the site editor
|
|
397
|
+
document.location.href = 'edit.php?post_type=wp_block';
|
|
336
398
|
}
|
|
337
|
-
close();
|
|
338
399
|
},
|
|
339
400
|
} );
|
|
340
401
|
|
|
341
402
|
return result;
|
|
342
|
-
}, [ history, isSiteEditor,
|
|
403
|
+
}, [ history, isSiteEditor, canCreateTemplate, isBlockBasedTheme ] );
|
|
343
404
|
|
|
344
405
|
return {
|
|
345
406
|
commands,
|