@wordpress/edit-site 4.12.1-next.d6164808d3.0 → 4.14.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/components/add-new-template/new-template.js +1 -1
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +90 -52
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +20 -10
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +8 -1
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/editor/index.js +9 -4
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +40 -23
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js +6 -2
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +5 -3
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/preview.js +2 -2
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +41 -29
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +41 -5
- package/build/components/header/index.js.map +1 -1
- package/build/components/list/header.js +15 -2
- package/build/components/list/header.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-panel/index.js +10 -4
- package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build/components/sidebar/index.js +8 -3
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +16 -0
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/index.js +4 -1
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +2 -2
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +87 -52
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/index.js +20 -9
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/resizable-editor.js +9 -2
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/editor/index.js +10 -5
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +40 -23
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js +6 -2
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +6 -4
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/preview.js +2 -2
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +42 -30
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +42 -7
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/list/header.js +14 -2
- package/build-module/components/list/header.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-panel/index.js +11 -5
- package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +7 -3
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +16 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/index.js +4 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +28 -16
- package/build-style/style.css +28 -16
- package/package.json +29 -29
- package/src/components/add-new-template/new-template.js +2 -0
- package/src/components/add-new-template/utils.js +82 -20
- package/src/components/block-editor/index.js +34 -16
- package/src/components/block-editor/resizable-editor.js +10 -3
- package/src/components/code-editor/style.scss +2 -3
- package/src/components/editor/index.js +12 -5
- package/src/components/global-styles/dimensions-panel.js +52 -31
- package/src/components/global-styles/gradients-palette-panel.js +25 -12
- package/src/components/global-styles/hooks.js +7 -7
- package/src/components/global-styles/preview.js +2 -2
- package/src/components/global-styles/use-global-styles-output.js +66 -57
- package/src/components/global-styles/utils.js +1 -1
- package/src/components/header/index.js +61 -21
- package/src/components/header/style.scss +9 -0
- package/src/components/list/header.js +15 -5
- package/src/components/navigation-sidebar/navigation-panel/index.js +30 -24
- package/src/components/sidebar/index.js +23 -20
- package/src/components/template-part-converter/convert-to-template-part.js +14 -1
- package/src/index.js +4 -0
- package/src/style.scss +1 -0
|
@@ -12,7 +12,7 @@ import { store as editorStore } from '@wordpress/editor';
|
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
13
|
import { useMemo, useCallback } from '@wordpress/element';
|
|
14
14
|
import { __, sprintf } from '@wordpress/i18n';
|
|
15
|
-
import { blockMeta, post } from '@wordpress/icons';
|
|
15
|
+
import { blockMeta, post, archive } from '@wordpress/icons';
|
|
16
16
|
/**
|
|
17
17
|
* @typedef IHasNameAndId
|
|
18
18
|
* @property {string|number} id The entity's id.
|
|
@@ -79,15 +79,66 @@ const usePublicTaxonomies = () => {
|
|
|
79
79
|
}, [taxonomies]);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
function usePostTypeNeedsUniqueIdentifier(publicPostTypes) {
|
|
83
|
+
const postTypeLabels = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
|
|
84
|
+
let {
|
|
85
|
+
labels
|
|
86
|
+
} = _ref3;
|
|
87
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
88
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
89
|
+
return accumulator;
|
|
90
|
+
}, {}));
|
|
91
|
+
return useCallback(_ref4 => {
|
|
92
|
+
let {
|
|
93
|
+
labels,
|
|
94
|
+
slug
|
|
95
|
+
} = _ref4;
|
|
96
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
97
|
+
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
98
|
+
}, [postTypeLabels]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function usePostTypeArchiveMenuItems() {
|
|
102
|
+
const publicPostTypes = usePublicPostTypes();
|
|
103
|
+
const postTypesWithArchives = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.filter(postType => postType.has_archive), [publicPostTypes]);
|
|
104
|
+
const existingTemplates = useExistingTemplates();
|
|
105
|
+
const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(postTypesWithArchives);
|
|
106
|
+
return useMemo(() => (postTypesWithArchives === null || postTypesWithArchives === void 0 ? void 0 : postTypesWithArchives.filter(postType => !(existingTemplates || []).some(existingTemplate => existingTemplate.slug === 'archive-' + postType.slug)).map(postType => {
|
|
107
|
+
var _postType$icon;
|
|
108
|
+
|
|
109
|
+
let title;
|
|
110
|
+
|
|
111
|
+
if (needsUniqueIdentifier(postType)) {
|
|
112
|
+
title = sprintf( // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
|
|
113
|
+
__('Archive: %1$s (%2$s)'), postType.labels.singular_name, postType.slug);
|
|
114
|
+
} else {
|
|
115
|
+
title = sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
116
|
+
__('Archive: %s'), postType.labels.singular_name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
slug: 'archive-' + postType.slug,
|
|
121
|
+
description: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
122
|
+
__('Displays an archive with the latests posts of type: %s.'), postType.labels.singular_name),
|
|
123
|
+
title,
|
|
124
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
125
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
126
|
+
// also supports urls and svg as values.
|
|
127
|
+
icon: (_postType$icon = postType.icon) !== null && _postType$icon !== void 0 && _postType$icon.startsWith('dashicons-') ? postType.icon.slice(10) : archive,
|
|
128
|
+
templatePrefix: 'archive'
|
|
129
|
+
};
|
|
130
|
+
})) || [], [postTypesWithArchives, existingTemplates, needsUniqueIdentifier]);
|
|
131
|
+
}
|
|
82
132
|
export const usePostTypeMenuItems = onClickMenuItem => {
|
|
83
133
|
const publicPostTypes = usePublicPostTypes();
|
|
84
134
|
const existingTemplates = useExistingTemplates();
|
|
85
|
-
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
135
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
136
|
+
const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(publicPostTypes); // `page`is a special case in template hierarchy.
|
|
86
137
|
|
|
87
|
-
const templatePrefixes = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator,
|
|
138
|
+
const templatePrefixes = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref5) => {
|
|
88
139
|
let {
|
|
89
140
|
slug
|
|
90
|
-
} =
|
|
141
|
+
} = _ref5;
|
|
91
142
|
let suffix = slug;
|
|
92
143
|
|
|
93
144
|
if (slug !== 'page') {
|
|
@@ -96,28 +147,12 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
96
147
|
|
|
97
148
|
accumulator[slug] = suffix;
|
|
98
149
|
return accumulator;
|
|
99
|
-
}, {}), [publicPostTypes]);
|
|
100
|
-
// occurs, we need to add slug.
|
|
101
|
-
|
|
102
|
-
const postTypeLabels = publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref4) => {
|
|
103
|
-
let {
|
|
104
|
-
labels
|
|
105
|
-
} = _ref4;
|
|
106
|
-
const singularName = labels.singular_name.toLowerCase();
|
|
107
|
-
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
108
|
-
return accumulator;
|
|
109
|
-
}, {});
|
|
110
|
-
|
|
111
|
-
const needsUniqueIdentifier = (labels, slug) => {
|
|
112
|
-
const singularName = labels.singular_name.toLowerCase();
|
|
113
|
-
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
114
|
-
};
|
|
115
|
-
|
|
150
|
+
}, {}), [publicPostTypes]);
|
|
116
151
|
const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
|
|
117
|
-
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
152
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref6 => {
|
|
118
153
|
let {
|
|
119
154
|
slug
|
|
120
|
-
} =
|
|
155
|
+
} = _ref6;
|
|
121
156
|
return slug;
|
|
122
157
|
});
|
|
123
158
|
const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
|
|
@@ -132,15 +167,15 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
132
167
|
// augment it with the specific template functionality.
|
|
133
168
|
|
|
134
169
|
const generalTemplateSlug = templatePrefixes[slug];
|
|
135
|
-
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
170
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref7 => {
|
|
136
171
|
let {
|
|
137
172
|
slug: _slug
|
|
138
|
-
} =
|
|
173
|
+
} = _ref7;
|
|
139
174
|
return _slug === generalTemplateSlug;
|
|
140
175
|
});
|
|
141
176
|
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
142
177
|
|
|
143
|
-
const _needsUniqueIdentifier = needsUniqueIdentifier(
|
|
178
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
|
|
144
179
|
|
|
145
180
|
let menuItemTitle = sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
146
181
|
__('Single item: %s'), labels.singular_name);
|
|
@@ -172,10 +207,10 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
172
207
|
slug,
|
|
173
208
|
config: {
|
|
174
209
|
recordNamePath: 'title.rendered',
|
|
175
|
-
queryArgs:
|
|
210
|
+
queryArgs: _ref8 => {
|
|
176
211
|
let {
|
|
177
212
|
search
|
|
178
|
-
} =
|
|
213
|
+
} = _ref8;
|
|
179
214
|
return {
|
|
180
215
|
_fields: 'id,title,slug,link',
|
|
181
216
|
orderBy: search ? 'relevance' : 'modified',
|
|
@@ -241,10 +276,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
241
276
|
const existingTemplates = useExistingTemplates();
|
|
242
277
|
const defaultTemplateTypes = useDefaultTemplateTypes(); // `category` and `post_tag` are special cases in template hierarchy.
|
|
243
278
|
|
|
244
|
-
const templatePrefixes = useMemo(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator,
|
|
279
|
+
const templatePrefixes = useMemo(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
|
|
245
280
|
let {
|
|
246
281
|
slug
|
|
247
|
-
} =
|
|
282
|
+
} = _ref9;
|
|
248
283
|
let suffix = slug;
|
|
249
284
|
|
|
250
285
|
if (!['category', 'post_tag'].includes(slug)) {
|
|
@@ -260,10 +295,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
260
295
|
}, {}), [publicTaxonomies]); // We need to keep track of naming conflicts. If a conflict
|
|
261
296
|
// occurs, we need to add slug.
|
|
262
297
|
|
|
263
|
-
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator,
|
|
298
|
+
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref10) => {
|
|
264
299
|
let {
|
|
265
300
|
labels
|
|
266
|
-
} =
|
|
301
|
+
} = _ref10;
|
|
267
302
|
const singularName = labels.singular_name.toLowerCase();
|
|
268
303
|
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
269
304
|
return accumulator;
|
|
@@ -279,10 +314,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
279
314
|
};
|
|
280
315
|
|
|
281
316
|
const taxonomiesInfo = useEntitiesInfo('taxonomy', templatePrefixes);
|
|
282
|
-
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
317
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref11 => {
|
|
283
318
|
let {
|
|
284
319
|
slug
|
|
285
|
-
} =
|
|
320
|
+
} = _ref11;
|
|
286
321
|
return slug;
|
|
287
322
|
});
|
|
288
323
|
const menuItems = (publicTaxonomies || []).reduce((accumulator, taxonomy) => {
|
|
@@ -296,10 +331,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
296
331
|
// augment it with the specific template functionality.
|
|
297
332
|
|
|
298
333
|
const generalTemplateSlug = templatePrefixes[slug];
|
|
299
|
-
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
334
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref12 => {
|
|
300
335
|
let {
|
|
301
336
|
slug: _slug
|
|
302
|
-
} =
|
|
337
|
+
} = _ref12;
|
|
303
338
|
return _slug === generalTemplateSlug;
|
|
304
339
|
});
|
|
305
340
|
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
@@ -331,10 +366,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
331
366
|
type: 'taxonomy',
|
|
332
367
|
slug,
|
|
333
368
|
config: {
|
|
334
|
-
queryArgs:
|
|
369
|
+
queryArgs: _ref13 => {
|
|
335
370
|
let {
|
|
336
371
|
search
|
|
337
|
-
} =
|
|
372
|
+
} = _ref13;
|
|
338
373
|
return {
|
|
339
374
|
_fields: 'id,name,slug,link',
|
|
340
375
|
orderBy: search ? 'name' : 'count',
|
|
@@ -402,10 +437,10 @@ function useAuthorNeedsUniqueIndentifier() {
|
|
|
402
437
|
per_page: -1
|
|
403
438
|
}), []);
|
|
404
439
|
const authorsCountByName = useMemo(() => {
|
|
405
|
-
return (authors || []).reduce((authorsCount,
|
|
440
|
+
return (authors || []).reduce((authorsCount, _ref14) => {
|
|
406
441
|
let {
|
|
407
442
|
name
|
|
408
|
-
} =
|
|
443
|
+
} = _ref14;
|
|
409
444
|
authorsCount[name] = (authorsCount[name] || 0) + 1;
|
|
410
445
|
return authorsCount;
|
|
411
446
|
}, {});
|
|
@@ -430,10 +465,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
430
465
|
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
431
466
|
const authorInfo = useEntitiesInfo('root', USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX, USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS);
|
|
432
467
|
const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
|
|
433
|
-
let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
468
|
+
let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
|
|
434
469
|
let {
|
|
435
470
|
slug
|
|
436
|
-
} =
|
|
471
|
+
} = _ref15;
|
|
437
472
|
return slug === 'author';
|
|
438
473
|
});
|
|
439
474
|
|
|
@@ -445,10 +480,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
445
480
|
};
|
|
446
481
|
}
|
|
447
482
|
|
|
448
|
-
const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(
|
|
483
|
+
const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref16 => {
|
|
449
484
|
let {
|
|
450
485
|
slug
|
|
451
|
-
} =
|
|
486
|
+
} = _ref16;
|
|
452
487
|
return slug === 'author';
|
|
453
488
|
}));
|
|
454
489
|
|
|
@@ -462,10 +497,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
462
497
|
type: 'root',
|
|
463
498
|
slug: 'user',
|
|
464
499
|
config: {
|
|
465
|
-
queryArgs:
|
|
500
|
+
queryArgs: _ref17 => {
|
|
466
501
|
let {
|
|
467
502
|
search
|
|
468
|
-
} =
|
|
503
|
+
} = _ref17;
|
|
469
504
|
return {
|
|
470
505
|
_fields: 'id,name,slug,link',
|
|
471
506
|
orderBy: search ? 'name' : 'registered_date',
|
|
@@ -522,8 +557,8 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
522
557
|
const useExistingTemplateSlugs = templatePrefixes => {
|
|
523
558
|
const existingTemplates = useExistingTemplates();
|
|
524
559
|
const existingSlugs = useMemo(() => {
|
|
525
|
-
return Object.entries(templatePrefixes || {}).reduce((accumulator,
|
|
526
|
-
let [slug, prefix] =
|
|
560
|
+
return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref18) => {
|
|
561
|
+
let [slug, prefix] = _ref18;
|
|
527
562
|
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
528
563
|
const _prefix = `${prefix}-`;
|
|
529
564
|
|
|
@@ -558,8 +593,8 @@ const useTemplatesToExclude = function (entityName, templatePrefixes) {
|
|
|
558
593
|
let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
559
594
|
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
560
595
|
const recordsToExcludePerEntity = useSelect(select => {
|
|
561
|
-
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator,
|
|
562
|
-
let [slug, slugsWithTemplates] =
|
|
596
|
+
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref19) => {
|
|
597
|
+
let [slug, slugsWithTemplates] = _ref19;
|
|
563
598
|
const entitiesWithTemplates = select(coreStore).getEntityRecords(entityName, slug, {
|
|
564
599
|
_fields: 'id',
|
|
565
600
|
context: 'view',
|
|
@@ -600,10 +635,10 @@ const useEntitiesInfo = function (entityName, templatePrefixes) {
|
|
|
600
635
|
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
601
636
|
var _recordsToExcludePerE, _select$getEntityReco;
|
|
602
637
|
|
|
603
|
-
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(
|
|
638
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref20 => {
|
|
604
639
|
let {
|
|
605
640
|
id
|
|
606
|
-
} =
|
|
641
|
+
} = _ref20;
|
|
607
642
|
return id;
|
|
608
643
|
})) || [];
|
|
609
644
|
accumulator[slug] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["get","useSelect","store","coreStore","editorStore","decodeEntities","useMemo","useCallback","__","sprintf","blockMeta","post","mapToIHasNameAndId","entities","path","map","entity","name","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeMenuItems","onClickMenuItem","publicPostTypes","existingTemplates","defaultTemplateTypes","templatePrefixes","reduce","accumulator","suffix","postTypeLabels","labels","singularName","singular_name","toLowerCase","needsUniqueIdentifier","postTypesInfo","useEntitiesInfo","existingTemplateSlugs","menuItems","postType","icon","generalTemplateSlug","defaultTemplateType","find","_slug","hasGeneralTemplate","_needsUniqueIdentifier","menuItemTitle","menuItem","templatePrefix","title","description","startsWith","slice","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","taxonomiesMenuItems","defaultTaxonomiesMenuItems","useAuthorNeedsUniqueIndentifier","authors","getUsers","who","authorsCountByName","authorsCount","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","useAuthorMenuItem","authorInfo","authorNeedsUniqueId","authorMenuItem","needsUniqueId","search_items","not_found","all_items","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","existingTemplate","_prefix","substring","length","useTemplatesToExclude","entityName","additionalQueryParameters","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","entitiesInfo","keys","id"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASD,KAAK,IAAIE,WAAlB,QAAqC,mBAArC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,OAAT,EAAkBC,WAAlB,QAAqC,oBAArC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,SAAT,EAAoBC,IAApB,QAAgC,kBAAhC;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,kBAAkB,GAAG,CAAEC,QAAF,EAAYC,IAAZ,KAAsB;AACvD,SAAO,CAAED,QAAQ,IAAI,EAAd,EAA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,EAAEC,mBAJV;AAKC,aAAG4C,yBAAyB,CAAEhG,IAAF;AAL7B,SAHe,CAAF,kDAAE,sBAUb6F,MAVW,CADO;AAYrBzC,QAAAA;AAZqB,OAAtB;AAcA,aAAOtC,WAAP;AACA,KArBK,EAsBN,EAtBM,CAAP;AAwBA,GA1B4B,EA2B7B,CAAEF,gBAAF,EAAoBsF,yBAApB,CA3B6B,CAA9B;AA6BA,SAAOG,YAAP;AACA,CAxCD","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\nexport const useExistingTemplates = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} ),\n\t\t[]\n\t);\n};\n\nexport const useDefaultTemplateTypes = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t[]\n\t);\n};\n\nconst usePublicPostTypes = () => {\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\tconst excludedPostTypes = [ 'attachment' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\nconst usePublicTaxonomies = () => {\n\tconst taxonomies = useSelect(\n\t\t( select ) => select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\treturn taxonomies?.filter(\n\t\t\t( { visibility } ) => visibility?.publicly_queryable\n\t\t);\n\t}, [ taxonomies ] );\n};\n\nexport const usePostTypeMenuItems = ( onClickMenuItem ) => {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `page`is a special case in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( slug !== 'page' ) {\n\t\t\t\t\tsuffix = `single-${ suffix }`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst postTypeLabels = publicPostTypes?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn postTypeLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicPostTypes || [] ).reduce(\n\t\t( accumulator, postType ) => {\n\t\t\tconst { slug, labels, icon } = postType;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\tlabels.singular_name\n\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t__( 'Single item: %1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\t\t\t\t\t\t: post,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = postTypesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'postType',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\trecordNamePath: 'title.rendered',\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,title,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'relevance' : 'modified',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\tpostTypesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. \"Page: Hello\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Page: Hello\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. \"Project: Hello (project_type)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default post types\n\t// and one for the rest.\n\tconst postTypesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, postType ) => {\n\t\t\t\t\tconst { slug } = postType;\n\t\t\t\t\tlet key = 'postTypesMenuItems';\n\t\t\t\t\tif ( slug === 'page' ) {\n\t\t\t\t\t\tkey = 'defaultPostTypesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( postType );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultPostTypesMenuItems: [], postTypesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn postTypesMenuItems;\n};\n\nexport const useTaxonomiesMenuItems = ( onClickMenuItem ) => {\n\tconst publicTaxonomies = usePublicTaxonomies();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `category` and `post_tag` are special cases in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicTaxonomies?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( ! [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\t\t\tsuffix = `taxonomy-${ suffix }`;\n\t\t\t\t}\n\t\t\t\tif ( slug === 'post_tag' ) {\n\t\t\t\t\tsuffix = `tag`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicTaxonomies ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst taxonomyLabels = publicTaxonomies?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tif ( [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn taxonomyLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst taxonomiesInfo = useEntitiesInfo( 'taxonomy', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicTaxonomies || [] ).reduce(\n\t\t( accumulator, taxonomy ) => {\n\t\t\tconst { slug, labels } = taxonomy;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the taxonomy e.g: \"Category\"; %2s: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t\t\t\t\t__( 'Displays taxonomy: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ticon: blockMeta,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = taxonomiesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'taxonomy',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'name' : 'count',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\ttaxonomiesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a taxonomy and %2$s is the name of the term, e.g. \"Category: shoes\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Category: shoes\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. \"Category: shoes (product_tag)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default taxonomies\n\t// and one for the rest.\n\tconst taxonomiesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, taxonomy ) => {\n\t\t\t\t\tconst { slug } = taxonomy;\n\t\t\t\t\tlet key = 'taxonomiesMenuItems';\n\t\t\t\t\tif ( [ 'category', 'tag' ].includes( slug ) ) {\n\t\t\t\t\t\tkey = 'defaultTaxonomiesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( taxonomy );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultTaxonomiesMenuItems: [], taxonomiesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn taxonomiesMenuItems;\n};\n\nfunction useAuthorNeedsUniqueIndentifier() {\n\tconst authors = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getUsers( { who: 'authors', per_page: -1 } ),\n\t\t[]\n\t);\n\tconst authorsCountByName = useMemo( () => {\n\t\treturn ( authors || [] ).reduce( ( authorsCount, { name } ) => {\n\t\t\tauthorsCount[ name ] = ( authorsCount[ name ] || 0 ) + 1;\n\t\t\treturn authorsCount;\n\t\t}, {} );\n\t}, [ authors ] );\n\treturn useCallback(\n\t\t( name ) => {\n\t\t\treturn authorsCountByName[ name ] > 1;\n\t\t},\n\t\t[ authorsCountByName ]\n\t);\n}\n\nconst USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: 'author' };\nconst USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: 'authors' } };\nexport function useAuthorMenuItem( onClickMenuItem ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst authorInfo = useEntitiesInfo(\n\t\t'root',\n\t\tUSE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,\n\t\tUSE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS\n\t);\n\tconst authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();\n\tlet authorMenuItem = defaultTemplateTypes?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( ! authorMenuItem ) {\n\t\tauthorMenuItem = {\n\t\t\tdescription: __(\n\t\t\t\t'Displays latest posts written by a single author.'\n\t\t\t),\n\t\t\tslug: 'author',\n\t\t\ttitle: 'Author',\n\t\t};\n\t}\n\tconst hasGeneralTemplate = !! existingTemplates?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( authorInfo.user?.hasEntities ) {\n\t\tauthorMenuItem = { ...authorMenuItem, templatePrefix: 'author' };\n\t\tauthorMenuItem.onClick = ( template ) => {\n\t\t\tonClickMenuItem( {\n\t\t\t\ttype: 'root',\n\t\t\t\tslug: 'user',\n\t\t\t\tconfig: {\n\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\torderBy: search ? 'name' : 'registered_date',\n\t\t\t\t\t\t\texclude: authorInfo.user.existingEntitiesIds,\n\t\t\t\t\t\t\twho: 'authors',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\tconst needsUniqueId = authorNeedsUniqueId(\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst title = needsUniqueId\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %1$s: Represents the name of an author e.g: \"Jorge\", %2$s: Represents the slug of an author e.g: \"author-jorge-slug\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name,\n\t\t\t\t\t\t\t\t\tsuggestion.slug\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %s' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t );\n\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t__( 'Template for Author: %s' ),\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tslug: `author-${ suggestion.slug }`,\n\t\t\t\t\t\t\ttemplatePrefix: 'author',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlabels: {\n\t\t\t\t\tsingular_name: __( 'Author' ),\n\t\t\t\t\tsearch_items: __( 'Search Authors' ),\n\t\t\t\t\tnot_found: __( 'No authors found.' ),\n\t\t\t\t\tall_items: __( 'All Authors' ),\n\t\t\t\t},\n\t\t\t\thasGeneralTemplate,\n\t\t\t\ttemplate,\n\t\t\t} );\n\t\t};\n\t}\n\tif ( ! hasGeneralTemplate || authorInfo.user?.hasEntities ) {\n\t\treturn authorMenuItem;\n\t}\n}\n\n/**\n * Helper hook that filters all the existing templates by the given\n * object with the entity's slug as key and the template prefix as value.\n *\n * Example:\n * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]\n * `templatePrefixes` is: { post_tag: 'tag' }\n * It will return: { post_tag: ['apple'] }\n *\n * Note: We append the `-` to the given template prefix in this function for our checks.\n *\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.\n */\nconst useExistingTemplateSlugs = ( templatePrefixes ) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst existingSlugs = useMemo( () => {\n\t\treturn Object.entries( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, [ slug, prefix ] ) => {\n\t\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\t\tconst _prefix = `${ prefix }-`;\n\t\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\t\texistingTemplate.slug.substring(\n\t\t\t\t\t\t\t\t\t_prefix.length\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn _accumulator;\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tif ( slugsWithTemplates.length ) {\n\t\t\t\t\taccumulator[ slug ] = slugsWithTemplates;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t}, [ templatePrefixes, existingTemplates ] );\n\treturn existingSlugs;\n};\n\n/**\n * Helper hook that finds the existing records with an associated template,\n * as they need to be excluded from the template suggestions.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.\n */\nconst useTemplatesToExclude = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst slugsToExcludePerEntity =\n\t\tuseExistingTemplateSlugs( templatePrefixes );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.entries( slugsToExcludePerEntity || {} ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst entitiesWithTemplates = select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\tslug: slugsWithTemplates,\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} );\n\t\t\t\t\tif ( entitiesWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = entitiesWithTemplates;\n\t\t\t\t\t}\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ slugsToExcludePerEntity ]\n\t);\n\treturn recordsToExcludePerEntity;\n};\n\n/**\n * Helper hook that returns information about an entity having\n * records that we can create a specific template for.\n *\n * For example we can search for `terms` in `taxonomy` entity or\n * `posts` in `postType` entity.\n *\n * First we need to find the existing records with an associated template,\n * to query afterwards for any remaining record, by excluding them.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.\n */\nconst useEntitiesInfo = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes,\n\t\tadditionalQueryParameters\n\t);\n\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t\t( accumulator, slug ) => {\n\t\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t\t) || [];\n\t\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\t\thasEntities: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t\tentityName,\n\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)?.length,\n\t\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t\t};\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ templatePrefixes, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["get","useSelect","store","coreStore","editorStore","decodeEntities","useMemo","useCallback","__","sprintf","blockMeta","post","archive","mapToIHasNameAndId","entities","path","map","entity","name","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","usePostTypeNeedsUniqueIdentifier","publicPostTypes","postTypeLabels","reduce","accumulator","labels","singularName","singular_name","toLowerCase","usePostTypeArchiveMenuItems","postTypesWithArchives","postType","has_archive","existingTemplates","needsUniqueIdentifier","some","existingTemplate","title","description","icon","startsWith","slice","templatePrefix","usePostTypeMenuItems","onClickMenuItem","defaultTemplateTypes","templatePrefixes","suffix","postTypesInfo","useEntitiesInfo","existingTemplateSlugs","menuItems","generalTemplateSlug","defaultTemplateType","find","_slug","hasGeneralTemplate","_needsUniqueIdentifier","menuItemTitle","menuItem","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","taxonomiesMenuItems","defaultTaxonomiesMenuItems","useAuthorNeedsUniqueIndentifier","authors","getUsers","who","authorsCountByName","authorsCount","USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX","user","USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS","useAuthorMenuItem","authorInfo","authorNeedsUniqueId","authorMenuItem","needsUniqueId","search_items","not_found","all_items","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","_prefix","substring","length","useTemplatesToExclude","entityName","additionalQueryParameters","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","ent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AACA,KArBK,EAsBN,EAtBM,CAAP;AAwBA,GA1B4B,EA2B7B,CAAEsB,gBAAF,EAAoBsE,yBAApB,CA3B6B,CAA9B;AA6BA,SAAOG,YAAP;AACA,CAxCD","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo, useCallback } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post, archive } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\nexport const useExistingTemplates = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\tper_page: -1,\n\t\t\t} ),\n\t\t[]\n\t);\n};\n\nexport const useDefaultTemplateTypes = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplateTypes(),\n\t\t[]\n\t);\n};\n\nconst usePublicPostTypes = () => {\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\tconst excludedPostTypes = [ 'attachment' ];\n\t\treturn postTypes?.filter(\n\t\t\t( { viewable, slug } ) =>\n\t\t\t\tviewable && ! excludedPostTypes.includes( slug )\n\t\t);\n\t}, [ postTypes ] );\n};\n\nconst usePublicTaxonomies = () => {\n\tconst taxonomies = useSelect(\n\t\t( select ) => select( coreStore ).getTaxonomies( { per_page: -1 } ),\n\t\t[]\n\t);\n\treturn useMemo( () => {\n\t\treturn taxonomies?.filter(\n\t\t\t( { visibility } ) => visibility?.publicly_queryable\n\t\t);\n\t}, [ taxonomies ] );\n};\n\nfunction usePostTypeNeedsUniqueIdentifier( publicPostTypes ) {\n\tconst postTypeLabels = useMemo( () =>\n\t\tpublicPostTypes?.reduce( ( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t}, {} )\n\t);\n\treturn useCallback(\n\t\t( { labels, slug } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\treturn postTypeLabels[ singularName ] > 1 && singularName !== slug;\n\t\t},\n\t\t[ postTypeLabels ]\n\t);\n}\n\nexport function usePostTypeArchiveMenuItems() {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst postTypesWithArchives = useMemo(\n\t\t() => publicPostTypes?.filter( ( postType ) => postType.has_archive ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst existingTemplates = useExistingTemplates();\n\tconst needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(\n\t\tpostTypesWithArchives\n\t);\n\treturn useMemo(\n\t\t() =>\n\t\t\tpostTypesWithArchives\n\t\t\t\t?.filter(\n\t\t\t\t\t( postType ) =>\n\t\t\t\t\t\t! ( existingTemplates || [] ).some(\n\t\t\t\t\t\t\t( existingTemplate ) =>\n\t\t\t\t\t\t\t\texistingTemplate.slug ===\n\t\t\t\t\t\t\t\t'archive-' + postType.slug\n\t\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.map( ( postType ) => {\n\t\t\t\t\tlet title;\n\t\t\t\t\tif ( needsUniqueIdentifier( postType ) ) {\n\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t\t\t__( 'Archive: %1$s (%2$s)' ),\n\t\t\t\t\t\t\tpostType.labels.singular_name,\n\t\t\t\t\t\t\tpostType.slug\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Archive: %s' ),\n\t\t\t\t\t\t\tpostType.labels.singular_name\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tslug: 'archive-' + postType.slug,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t'Displays an archive with the latests posts of type: %s.'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tpostType.labels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: postType.icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? postType.icon.slice( 10 )\n\t\t\t\t\t\t\t: archive,\n\t\t\t\t\t\ttemplatePrefix: 'archive',\n\t\t\t\t\t};\n\t\t\t\t} ) || [],\n\t\t[ postTypesWithArchives, existingTemplates, needsUniqueIdentifier ]\n\t);\n}\n\nexport const usePostTypeMenuItems = ( onClickMenuItem ) => {\n\tconst publicPostTypes = usePublicPostTypes();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst needsUniqueIdentifier =\n\t\tusePostTypeNeedsUniqueIdentifier( publicPostTypes );\n\t// `page`is a special case in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicPostTypes?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( slug !== 'page' ) {\n\t\t\t\t\tsuffix = `single-${ suffix }`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicPostTypes ]\n\t);\n\tconst postTypesInfo = useEntitiesInfo( 'postType', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicPostTypes || [] ).reduce(\n\t\t( accumulator, postType ) => {\n\t\t\tconst { slug, labels, icon } = postType;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier( postType );\n\t\t\tlet menuItemTitle = sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Single item: %s' ),\n\t\t\t\tlabels.singular_name\n\t\t\t);\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the post type e.g: \"Post\"; %2s: Slug of the post type e.g: \"book\".\n\t\t\t\t\t__( 'Single item: %1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\t// `icon` is the `menu_icon` property of a post type. We\n\t\t\t\t\t\t// only handle `dashicons` for now, even if the `menu_icon`\n\t\t\t\t\t\t// also supports urls and svg as values.\n\t\t\t\t\t\ticon: icon?.startsWith( 'dashicons-' )\n\t\t\t\t\t\t\t? icon.slice( 10 )\n\t\t\t\t\t\t\t: post,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = postTypesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'postType',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\trecordNamePath: 'title.rendered',\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,title,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'relevance' : 'modified',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\tpostTypesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a post type and %2$s is the name of the post, e.g. \"Page: Hello\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Page: Hello\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. \"Project: Hello (project_type)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default post types\n\t// and one for the rest.\n\tconst postTypesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, postType ) => {\n\t\t\t\t\tconst { slug } = postType;\n\t\t\t\t\tlet key = 'postTypesMenuItems';\n\t\t\t\t\tif ( slug === 'page' ) {\n\t\t\t\t\t\tkey = 'defaultPostTypesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( postType );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultPostTypesMenuItems: [], postTypesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn postTypesMenuItems;\n};\n\nexport const useTaxonomiesMenuItems = ( onClickMenuItem ) => {\n\tconst publicTaxonomies = usePublicTaxonomies();\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\t// `category` and `post_tag` are special cases in template hierarchy.\n\tconst templatePrefixes = useMemo(\n\t\t() =>\n\t\t\tpublicTaxonomies?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tlet suffix = slug;\n\t\t\t\tif ( ! [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\t\t\tsuffix = `taxonomy-${ suffix }`;\n\t\t\t\t}\n\t\t\t\tif ( slug === 'post_tag' ) {\n\t\t\t\t\tsuffix = `tag`;\n\t\t\t\t}\n\t\t\t\taccumulator[ slug ] = suffix;\n\t\t\t\treturn accumulator;\n\t\t\t}, {} ),\n\t\t[ publicTaxonomies ]\n\t);\n\t// We need to keep track of naming conflicts. If a conflict\n\t// occurs, we need to add slug.\n\tconst taxonomyLabels = publicTaxonomies?.reduce(\n\t\t( accumulator, { labels } ) => {\n\t\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\t\taccumulator[ singularName ] =\n\t\t\t\t( accumulator[ singularName ] || 0 ) + 1;\n\t\t\treturn accumulator;\n\t\t},\n\t\t{}\n\t);\n\tconst needsUniqueIdentifier = ( labels, slug ) => {\n\t\tif ( [ 'category', 'post_tag' ].includes( slug ) ) {\n\t\t\treturn false;\n\t\t}\n\t\tconst singularName = labels.singular_name.toLowerCase();\n\t\treturn taxonomyLabels[ singularName ] > 1 && singularName !== slug;\n\t};\n\tconst taxonomiesInfo = useEntitiesInfo( 'taxonomy', templatePrefixes );\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst menuItems = ( publicTaxonomies || [] ).reduce(\n\t\t( accumulator, taxonomy ) => {\n\t\t\tconst { slug, labels } = taxonomy;\n\t\t\t// We need to check if the general template is part of the\n\t\t\t// defaultTemplateTypes. If it is, just use that info and\n\t\t\t// augment it with the specific template functionality.\n\t\t\tconst generalTemplateSlug = templatePrefixes[ slug ];\n\t\t\tconst defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === generalTemplateSlug\n\t\t\t);\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\n\t\t\tconst _needsUniqueIdentifier = needsUniqueIdentifier(\n\t\t\t\tlabels,\n\t\t\t\tslug\n\t\t\t);\n\t\t\tlet menuItemTitle = labels.singular_name;\n\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\tmenuItemTitle = sprintf(\n\t\t\t\t\t// translators: %1s: Name of the taxonomy e.g: \"Category\"; %2s: Slug of the taxonomy e.g: \"product_cat\".\n\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\tslug\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst menuItem = defaultTemplateType\n\t\t\t\t? {\n\t\t\t\t\t\t...defaultTemplateType,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t }\n\t\t\t\t: {\n\t\t\t\t\t\tslug: generalTemplateSlug,\n\t\t\t\t\t\ttitle: menuItemTitle,\n\t\t\t\t\t\tdescription: sprintf(\n\t\t\t\t\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t\t\t\t\t__( 'Displays taxonomy: %s.' ),\n\t\t\t\t\t\t\tlabels.singular_name\n\t\t\t\t\t\t),\n\t\t\t\t\t\ticon: blockMeta,\n\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t };\n\t\t\tconst hasEntities = taxonomiesInfo?.[ slug ]?.hasEntities;\n\t\t\t// We have a different template creation flow only if they have entities.\n\t\t\tif ( hasEntities ) {\n\t\t\t\tmenuItem.onClick = ( template ) => {\n\t\t\t\t\tonClickMenuItem( {\n\t\t\t\t\t\ttype: 'taxonomy',\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: {\n\t\t\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\t\t\torderBy: search ? 'name' : 'count',\n\t\t\t\t\t\t\t\t\texclude:\n\t\t\t\t\t\t\t\t\t\ttaxonomiesInfo[ slug ]\n\t\t\t\t\t\t\t\t\t\t\t.existingEntitiesIds,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\t\t\tlet title = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the singular name of a taxonomy and %2$s is the name of the term, e.g. \"Category: shoes\".\n\t\t\t\t\t\t\t\t\t__( '%1$s: %2$s' ),\n\t\t\t\t\t\t\t\t\tlabels.singular_name,\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t\t\t// translators: Represents the description of a user's custom template in the Site Editor, e.g. \"Template for Category: shoes\"\n\t\t\t\t\t\t\t\t\t__( 'Template for %1$s' ),\n\t\t\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif ( _needsUniqueIdentifier ) {\n\t\t\t\t\t\t\t\t\ttitle = sprintf(\n\t\t\t\t\t\t\t\t\t\t// translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. \"Category: shoes (product_tag)\"\n\t\t\t\t\t\t\t\t\t\t__( '%1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tslug\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug: `${ templatePrefixes[ slug ] }-${ suggestion.slug }`,\n\t\t\t\t\t\t\t\t\ttemplatePrefix: templatePrefixes[ slug ],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlabels,\n\t\t\t\t\t\thasGeneralTemplate,\n\t\t\t\t\t\ttemplate,\n\t\t\t\t\t} );\n\t\t\t\t};\n\t\t\t}\n\t\t\t// We don't need to add the menu item if there are no\n\t\t\t// entities and the general template exists.\n\t\t\tif ( ! hasGeneralTemplate || hasEntities ) {\n\t\t\t\taccumulator.push( menuItem );\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t},\n\t\t[]\n\t);\n\t// Split menu items into two groups: one for the default taxonomies\n\t// and one for the rest.\n\tconst taxonomiesMenuItems = useMemo(\n\t\t() =>\n\t\t\tmenuItems.reduce(\n\t\t\t\t( accumulator, taxonomy ) => {\n\t\t\t\t\tconst { slug } = taxonomy;\n\t\t\t\t\tlet key = 'taxonomiesMenuItems';\n\t\t\t\t\tif ( [ 'category', 'tag' ].includes( slug ) ) {\n\t\t\t\t\t\tkey = 'defaultTaxonomiesMenuItems';\n\t\t\t\t\t}\n\t\t\t\t\taccumulator[ key ].push( taxonomy );\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{ defaultTaxonomiesMenuItems: [], taxonomiesMenuItems: [] }\n\t\t\t),\n\t\t[ menuItems ]\n\t);\n\treturn taxonomiesMenuItems;\n};\n\nfunction useAuthorNeedsUniqueIndentifier() {\n\tconst authors = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getUsers( { who: 'authors', per_page: -1 } ),\n\t\t[]\n\t);\n\tconst authorsCountByName = useMemo( () => {\n\t\treturn ( authors || [] ).reduce( ( authorsCount, { name } ) => {\n\t\t\tauthorsCount[ name ] = ( authorsCount[ name ] || 0 ) + 1;\n\t\t\treturn authorsCount;\n\t\t}, {} );\n\t}, [ authors ] );\n\treturn useCallback(\n\t\t( name ) => {\n\t\t\treturn authorsCountByName[ name ] > 1;\n\t\t},\n\t\t[ authorsCountByName ]\n\t);\n}\n\nconst USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: 'author' };\nconst USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: 'authors' } };\nexport function useAuthorMenuItem( onClickMenuItem ) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst authorInfo = useEntitiesInfo(\n\t\t'root',\n\t\tUSE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,\n\t\tUSE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS\n\t);\n\tconst authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();\n\tlet authorMenuItem = defaultTemplateTypes?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( ! authorMenuItem ) {\n\t\tauthorMenuItem = {\n\t\t\tdescription: __(\n\t\t\t\t'Displays latest posts written by a single author.'\n\t\t\t),\n\t\t\tslug: 'author',\n\t\t\ttitle: 'Author',\n\t\t};\n\t}\n\tconst hasGeneralTemplate = !! existingTemplates?.find(\n\t\t( { slug } ) => slug === 'author'\n\t);\n\tif ( authorInfo.user?.hasEntities ) {\n\t\tauthorMenuItem = { ...authorMenuItem, templatePrefix: 'author' };\n\t\tauthorMenuItem.onClick = ( template ) => {\n\t\t\tonClickMenuItem( {\n\t\t\t\ttype: 'root',\n\t\t\t\tslug: 'user',\n\t\t\t\tconfig: {\n\t\t\t\t\tqueryArgs: ( { search } ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t_fields: 'id,name,slug,link',\n\t\t\t\t\t\t\torderBy: search ? 'name' : 'registered_date',\n\t\t\t\t\t\t\texclude: authorInfo.user.existingEntitiesIds,\n\t\t\t\t\t\t\twho: 'authors',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t\tgetSpecificTemplate: ( suggestion ) => {\n\t\t\t\t\t\tconst needsUniqueId = authorNeedsUniqueId(\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst title = needsUniqueId\n\t\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %1$s: Represents the name of an author e.g: \"Jorge\", %2$s: Represents the slug of an author e.g: \"author-jorge-slug\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %1$s (%2$s)' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name,\n\t\t\t\t\t\t\t\t\tsuggestion.slug\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t\t\t__( 'Author: %s' ),\n\t\t\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t\t );\n\t\t\t\t\t\tconst description = sprintf(\n\t\t\t\t\t\t\t// translators: %s: Represents the name of an author e.g: \"Jorge\".\n\t\t\t\t\t\t\t__( 'Template for Author: %s' ),\n\t\t\t\t\t\t\tsuggestion.name\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tslug: `author-${ suggestion.slug }`,\n\t\t\t\t\t\t\ttemplatePrefix: 'author',\n\t\t\t\t\t\t};\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlabels: {\n\t\t\t\t\tsingular_name: __( 'Author' ),\n\t\t\t\t\tsearch_items: __( 'Search Authors' ),\n\t\t\t\t\tnot_found: __( 'No authors found.' ),\n\t\t\t\t\tall_items: __( 'All Authors' ),\n\t\t\t\t},\n\t\t\t\thasGeneralTemplate,\n\t\t\t\ttemplate,\n\t\t\t} );\n\t\t};\n\t}\n\tif ( ! hasGeneralTemplate || authorInfo.user?.hasEntities ) {\n\t\treturn authorMenuItem;\n\t}\n}\n\n/**\n * Helper hook that filters all the existing templates by the given\n * object with the entity's slug as key and the template prefix as value.\n *\n * Example:\n * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]\n * `templatePrefixes` is: { post_tag: 'tag' }\n * It will return: { post_tag: ['apple'] }\n *\n * Note: We append the `-` to the given template prefix in this function for our checks.\n *\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.\n */\nconst useExistingTemplateSlugs = ( templatePrefixes ) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst existingSlugs = useMemo( () => {\n\t\treturn Object.entries( templatePrefixes || {} ).reduce(\n\t\t\t( accumulator, [ slug, prefix ] ) => {\n\t\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\t\tconst _prefix = `${ prefix }-`;\n\t\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\t\texistingTemplate.slug.substring(\n\t\t\t\t\t\t\t\t\t_prefix.length\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn _accumulator;\n\t\t\t\t\t},\n\t\t\t\t\t[]\n\t\t\t\t);\n\t\t\t\tif ( slugsWithTemplates.length ) {\n\t\t\t\t\taccumulator[ slug ] = slugsWithTemplates;\n\t\t\t\t}\n\t\t\t\treturn accumulator;\n\t\t\t},\n\t\t\t{}\n\t\t);\n\t}, [ templatePrefixes, existingTemplates ] );\n\treturn existingSlugs;\n};\n\n/**\n * Helper hook that finds the existing records with an associated template,\n * as they need to be excluded from the template suggestions.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.\n */\nconst useTemplatesToExclude = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst slugsToExcludePerEntity =\n\t\tuseExistingTemplateSlugs( templatePrefixes );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.entries( slugsToExcludePerEntity || {} ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst entitiesWithTemplates = select(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords( entityName, slug, {\n\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\tslug: slugsWithTemplates,\n\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t} );\n\t\t\t\t\tif ( entitiesWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = entitiesWithTemplates;\n\t\t\t\t\t}\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ slugsToExcludePerEntity ]\n\t);\n\treturn recordsToExcludePerEntity;\n};\n\n/**\n * Helper hook that returns information about an entity having\n * records that we can create a specific template for.\n *\n * For example we can search for `terms` in `taxonomy` entity or\n * `posts` in `postType` entity.\n *\n * First we need to find the existing records with an associated template,\n * to query afterwards for any remaining record, by excluding them.\n *\n * @param {string} entityName The entity's name.\n * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.\n * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.\n * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.\n */\nconst useEntitiesInfo = (\n\tentityName,\n\ttemplatePrefixes,\n\tadditionalQueryParameters = {}\n) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes,\n\t\tadditionalQueryParameters\n\t);\n\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn Object.keys( templatePrefixes || {} ).reduce(\n\t\t\t\t( accumulator, slug ) => {\n\t\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t\t) || [];\n\t\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\t\thasEntities: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\t\tentityName,\n\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t\t\t...additionalQueryParameters[ slug ],\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t)?.length,\n\t\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t\t};\n\t\t\t\t\treturn accumulator;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t);\n\t\t},\n\t\t[ templatePrefixes, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n"]}
|
|
@@ -5,7 +5,6 @@ import { createElement } from "@wordpress/element";
|
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
7
|
import classnames from 'classnames';
|
|
8
|
-
import { omit, unionBy } from 'lodash';
|
|
9
8
|
/**
|
|
10
9
|
* WordPress dependencies
|
|
11
10
|
*/
|
|
@@ -74,12 +73,24 @@ export default function BlockEditor(_ref) {
|
|
|
74
73
|
restBlockPatterns: select(coreStore).getBlockPatterns(),
|
|
75
74
|
restBlockPatternCategories: select(coreStore).getBlockPatternCategories()
|
|
76
75
|
}), []);
|
|
77
|
-
const blockPatterns = useMemo(() =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}), [
|
|
76
|
+
const blockPatterns = useMemo(() => [...(settingsBlockPatterns || []), ...(restBlockPatterns || [])].filter((x, index, arr) => index === arr.findIndex(y => x.name === y.name)).filter(_ref2 => {
|
|
77
|
+
let {
|
|
78
|
+
postTypes
|
|
79
|
+
} = _ref2;
|
|
80
|
+
return !postTypes || Array.isArray(postTypes) && postTypes.includes(templateType);
|
|
81
|
+
}), [settingsBlockPatterns, restBlockPatterns, templateType]);
|
|
82
|
+
const blockPatternCategories = useMemo(() => [...(settingsBlockPatternCategories || []), ...(restBlockPatternCategories || [])].filter((x, index, arr) => index === arr.findIndex(y => x.name === y.name)), [settingsBlockPatternCategories, restBlockPatternCategories]);
|
|
83
|
+
const settings = useMemo(() => {
|
|
84
|
+
const {
|
|
85
|
+
__experimentalAdditionalBlockPatterns,
|
|
86
|
+
__experimentalAdditionalBlockPatternCategories,
|
|
87
|
+
...restStoredSettings
|
|
88
|
+
} = storedSettings;
|
|
89
|
+
return { ...restStoredSettings,
|
|
90
|
+
__experimentalBlockPatterns: blockPatterns,
|
|
91
|
+
__experimentalBlockPatternCategories: blockPatternCategories
|
|
92
|
+
};
|
|
93
|
+
}, [storedSettings, blockPatterns, blockPatternCategories]);
|
|
83
94
|
const [blocks, onInput, onChange] = useEntityBlockEditor('postType', templateType);
|
|
84
95
|
const {
|
|
85
96
|
setPage
|
|
@@ -146,10 +157,10 @@ export default function BlockEditor(_ref) {
|
|
|
146
157
|
className: "edit-site-block-editor__block-list wp-site-blocks",
|
|
147
158
|
__experimentalLayout: LAYOUT,
|
|
148
159
|
renderAppender: isTemplatePart && hasBlocks ? false : undefined
|
|
149
|
-
})), createElement(__unstableBlockSettingsMenuFirstItem, null,
|
|
160
|
+
})), createElement(__unstableBlockSettingsMenuFirstItem, null, _ref3 => {
|
|
150
161
|
let {
|
|
151
162
|
onClose
|
|
152
|
-
} =
|
|
163
|
+
} = _ref3;
|
|
153
164
|
return createElement(BlockInspectorButton, {
|
|
154
165
|
onClick: onClose
|
|
155
166
|
});
|