@wordpress/edit-site 4.8.0 → 4.11.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 +6 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
- package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build/components/add-new-template/add-custom-template-modal.js +204 -0
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build/components/add-new-template/new-template.js +91 -33
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +532 -0
- package/build/components/add-new-template/utils.js.map +1 -0
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/code-editor/index.js +17 -4
- package/build/components/code-editor/index.js.map +1 -1
- package/build/components/editor/index.js +16 -0
- package/build/components/editor/index.js.map +1 -1
- package/build/components/error-boundary/index.js +6 -0
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/global-styles/context-menu.js +6 -3
- package/build/components/global-styles/context-menu.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +185 -19
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +4 -2
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/hooks.js +11 -2
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/palette.js +2 -1
- package/build/components/global-styles/palette.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +4 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-button-color.js +80 -0
- package/build/components/global-styles/screen-button-color.js.map +1 -0
- package/build/components/global-styles/screen-color-palette.js +13 -17
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +56 -8
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-link-color.js +48 -14
- package/build/components/global-styles/screen-link-color.js.map +1 -1
- package/build/components/global-styles/screen-root.js +4 -2
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/global-styles/screen-typography-element.js +4 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +9 -1
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/ui.js +11 -0
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +282 -35
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +35 -2
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +29 -10
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/more-menu/site-export.js +4 -1
- package/build/components/header/more-menu/site-export.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +13 -4
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/header/undo-redo/undo.js +13 -4
- package/build/components/header/undo-redo/undo.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/sidebar/template-card/index.js +19 -7
- package/build/components/sidebar/template-card/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-actions.js +64 -0
- package/build/components/sidebar/template-card/template-actions.js.map +1 -0
- package/build/components/template-details/edit-template-title.js +11 -3
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +1 -20
- package/build/components/template-details/index.js.map +1 -1
- package/build/hooks/index.js +2 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/template-part-edit.js +86 -0
- package/build/hooks/template-part-edit.js.map +1 -0
- package/build/store/selectors.js +4 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
- package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js +189 -0
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build-module/components/add-new-template/new-template.js +90 -34
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +503 -0
- package/build-module/components/add-new-template/utils.js.map +1 -0
- package/build-module/components/block-editor/index.js +1 -2
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/code-editor/index.js +18 -5
- package/build-module/components/code-editor/index.js.map +1 -1
- package/build-module/components/editor/index.js +16 -0
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/error-boundary/index.js +5 -0
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/global-styles/context-menu.js +6 -3
- package/build-module/components/global-styles/context-menu.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +185 -20
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +4 -2
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +11 -2
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/palette.js +2 -1
- package/build-module/components/global-styles/palette.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +4 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-button-color.js +67 -0
- package/build-module/components/global-styles/screen-button-color.js.map +1 -0
- package/build-module/components/global-styles/screen-color-palette.js +14 -19
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +57 -9
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-link-color.js +47 -14
- package/build-module/components/global-styles/screen-link-color.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +4 -2
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/global-styles/screen-typography-element.js +4 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +10 -2
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/ui.js +10 -0
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +280 -42
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +34 -3
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +31 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/more-menu/site-export.js +4 -1
- package/build-module/components/header/more-menu/site-export.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +9 -3
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/header/undo-redo/undo.js +9 -3
- package/build-module/components/header/undo-redo/undo.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js +17 -0
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/index.js +18 -7
- package/build-module/components/sidebar/template-card/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js +49 -0
- package/build-module/components/sidebar/template-card/template-actions.js.map +1 -0
- package/build-module/components/template-details/edit-template-title.js +12 -3
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +2 -21
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/template-part-edit.js +67 -0
- package/build-module/hooks/template-part-edit.js.map +1 -0
- package/build-module/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +198 -49
- package/build-style/style.css +198 -49
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
- package/src/components/add-new-template/add-custom-template-modal.js +247 -0
- package/src/components/add-new-template/new-template.js +158 -70
- package/src/components/add-new-template/style.scss +149 -0
- package/src/components/add-new-template/utils.js +538 -0
- package/src/components/block-editor/index.js +0 -2
- package/src/components/code-editor/index.js +15 -5
- package/src/components/editor/index.js +11 -0
- package/src/components/error-boundary/index.js +5 -0
- package/src/components/global-styles/context-menu.js +3 -0
- package/src/components/global-styles/dimensions-panel.js +209 -21
- package/src/components/global-styles/global-styles-provider.js +8 -9
- package/src/components/global-styles/hooks.js +18 -0
- package/src/components/global-styles/palette.js +4 -1
- package/src/components/global-styles/screen-block-list.js +10 -1
- package/src/components/global-styles/screen-button-color.js +102 -0
- package/src/components/global-styles/screen-color-palette.js +25 -27
- package/src/components/global-styles/screen-colors.js +58 -7
- package/src/components/global-styles/screen-link-color.js +65 -23
- package/src/components/global-styles/screen-root.js +8 -2
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +17 -2
- package/src/components/global-styles/style.scss +14 -8
- package/src/components/global-styles/test/use-global-styles-output.js +313 -16
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +344 -38
- package/src/components/global-styles/utils.js +36 -2
- package/src/components/header/index.js +42 -17
- package/src/components/header/more-menu/site-export.js +3 -0
- package/src/components/header/style.scss +58 -8
- package/src/components/header/undo-redo/redo.js +6 -1
- package/src/components/header/undo-redo/undo.js +6 -1
- package/src/components/keyboard-shortcut-help-modal/config.js +12 -0
- package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
- package/src/components/list/style.scss +0 -8
- package/src/components/sidebar/style.scss +4 -0
- package/src/components/sidebar/template-card/index.js +15 -6
- package/src/components/sidebar/template-card/style.scss +49 -35
- package/src/components/sidebar/template-card/template-actions.js +43 -0
- package/src/components/template-details/edit-template-title.js +10 -2
- package/src/components/template-details/index.js +4 -21
- package/src/components/test/error-boundary.js +38 -0
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/store/selectors.js +11 -5
- package/src/style.scss +0 -1
- package/build/components/edit-template-part-menu-button/index.js +0 -90
- package/build/components/edit-template-part-menu-button/index.js.map +0 -1
- package/build-module/components/edit-template-part-menu-button/index.js +0 -72
- package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
- package/src/components/edit-template-part-menu-button/index.js +0 -82
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = exports.useExistingTemplates = exports.useDefaultTemplateTypes = exports.mapToIHasNameAndId = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = require("lodash");
|
|
9
|
+
|
|
10
|
+
var _data = require("@wordpress/data");
|
|
11
|
+
|
|
12
|
+
var _coreData = require("@wordpress/core-data");
|
|
13
|
+
|
|
14
|
+
var _editor = require("@wordpress/editor");
|
|
15
|
+
|
|
16
|
+
var _htmlEntities = require("@wordpress/html-entities");
|
|
17
|
+
|
|
18
|
+
var _element = require("@wordpress/element");
|
|
19
|
+
|
|
20
|
+
var _i18n = require("@wordpress/i18n");
|
|
21
|
+
|
|
22
|
+
var _icons = require("@wordpress/icons");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* External dependencies
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* WordPress dependencies
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @typedef IHasNameAndId
|
|
34
|
+
* @property {string|number} id The entity's id.
|
|
35
|
+
* @property {string} name The entity's name.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper util to map records to add a `name` prop from a
|
|
40
|
+
* provided path, in order to handle all entities in the same
|
|
41
|
+
* fashion(implementing`IHasNameAndId` interface).
|
|
42
|
+
*
|
|
43
|
+
* @param {Object[]} entities The array of entities.
|
|
44
|
+
* @param {string} path The path to map a `name` property from the entity.
|
|
45
|
+
* @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.
|
|
46
|
+
*/
|
|
47
|
+
const mapToIHasNameAndId = (entities, path) => {
|
|
48
|
+
return (entities || []).map(entity => ({ ...entity,
|
|
49
|
+
name: (0, _htmlEntities.decodeEntities)((0, _lodash.get)(entity, path))
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {Object} EntitiesInfo
|
|
54
|
+
* @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).
|
|
55
|
+
* @property {number[]} existingEntitiesIds An array of the existing entities ids.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
exports.mapToIHasNameAndId = mapToIHasNameAndId;
|
|
60
|
+
|
|
61
|
+
const useExistingTemplates = () => {
|
|
62
|
+
return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template', {
|
|
63
|
+
per_page: -1
|
|
64
|
+
}), []);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
exports.useExistingTemplates = useExistingTemplates;
|
|
68
|
+
|
|
69
|
+
const useDefaultTemplateTypes = () => {
|
|
70
|
+
return (0, _data.useSelect)(select => select(_editor.store).__experimentalGetDefaultTemplateTypes(), []);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.useDefaultTemplateTypes = useDefaultTemplateTypes;
|
|
74
|
+
|
|
75
|
+
const usePublicPostTypes = () => {
|
|
76
|
+
const postTypes = (0, _data.useSelect)(select => select(_coreData.store).getPostTypes({
|
|
77
|
+
per_page: -1
|
|
78
|
+
}), []);
|
|
79
|
+
return (0, _element.useMemo)(() => {
|
|
80
|
+
const excludedPostTypes = ['attachment'];
|
|
81
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref => {
|
|
82
|
+
let {
|
|
83
|
+
viewable,
|
|
84
|
+
slug
|
|
85
|
+
} = _ref;
|
|
86
|
+
return viewable && !excludedPostTypes.includes(slug);
|
|
87
|
+
});
|
|
88
|
+
}, [postTypes]);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const usePublicTaxonomies = () => {
|
|
92
|
+
const taxonomies = (0, _data.useSelect)(select => select(_coreData.store).getTaxonomies({
|
|
93
|
+
per_page: -1
|
|
94
|
+
}), []);
|
|
95
|
+
return (0, _element.useMemo)(() => {
|
|
96
|
+
return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref2 => {
|
|
97
|
+
let {
|
|
98
|
+
visibility
|
|
99
|
+
} = _ref2;
|
|
100
|
+
return visibility === null || visibility === void 0 ? void 0 : visibility.publicly_queryable;
|
|
101
|
+
});
|
|
102
|
+
}, [taxonomies]);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const usePostTypeMenuItems = onClickMenuItem => {
|
|
106
|
+
const publicPostTypes = usePublicPostTypes();
|
|
107
|
+
const existingTemplates = useExistingTemplates();
|
|
108
|
+
const defaultTemplateTypes = useDefaultTemplateTypes(); // `page`is a special case in template hierarchy.
|
|
109
|
+
|
|
110
|
+
const templatePrefixes = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
|
|
111
|
+
let {
|
|
112
|
+
slug
|
|
113
|
+
} = _ref3;
|
|
114
|
+
let suffix = slug;
|
|
115
|
+
|
|
116
|
+
if (slug !== 'page') {
|
|
117
|
+
suffix = `single-${suffix}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
accumulator[slug] = suffix;
|
|
121
|
+
return accumulator;
|
|
122
|
+
}, {}), [publicPostTypes]); // We need to keep track of naming conflicts. If a conflict
|
|
123
|
+
// occurs, we need to add slug.
|
|
124
|
+
|
|
125
|
+
const postTypeLabels = publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref4) => {
|
|
126
|
+
let {
|
|
127
|
+
labels
|
|
128
|
+
} = _ref4;
|
|
129
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
130
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
131
|
+
return accumulator;
|
|
132
|
+
}, {});
|
|
133
|
+
|
|
134
|
+
const needsUniqueIdentifier = (labels, slug) => {
|
|
135
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
136
|
+
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
|
|
140
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref5 => {
|
|
141
|
+
let {
|
|
142
|
+
slug
|
|
143
|
+
} = _ref5;
|
|
144
|
+
return slug;
|
|
145
|
+
});
|
|
146
|
+
const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
|
|
147
|
+
var _postTypesInfo$slug;
|
|
148
|
+
|
|
149
|
+
const {
|
|
150
|
+
slug,
|
|
151
|
+
labels,
|
|
152
|
+
icon
|
|
153
|
+
} = postType; // We need to check if the general template is part of the
|
|
154
|
+
// defaultTemplateTypes. If it is, just use that info and
|
|
155
|
+
// augment it with the specific template functionality.
|
|
156
|
+
|
|
157
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
158
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref6 => {
|
|
159
|
+
let {
|
|
160
|
+
slug: _slug
|
|
161
|
+
} = _ref6;
|
|
162
|
+
return _slug === generalTemplateSlug;
|
|
163
|
+
});
|
|
164
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
165
|
+
|
|
166
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(labels, slug);
|
|
167
|
+
|
|
168
|
+
let menuItemTitle = (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
169
|
+
(0, _i18n.__)('Single item: %s'), labels.singular_name);
|
|
170
|
+
|
|
171
|
+
if (_needsUniqueIdentifier) {
|
|
172
|
+
menuItemTitle = (0, _i18n.sprintf)( // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
|
|
173
|
+
(0, _i18n.__)('Single item: %1$s (%2$s)'), labels.singular_name, slug);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType
|
|
177
|
+
} : {
|
|
178
|
+
slug: generalTemplateSlug,
|
|
179
|
+
title: menuItemTitle,
|
|
180
|
+
description: (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
181
|
+
(0, _i18n.__)('Displays a single item: %s.'), labels.singular_name),
|
|
182
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
183
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
184
|
+
// also supports urls and svg as values.
|
|
185
|
+
icon: icon !== null && icon !== void 0 && icon.startsWith('dashicons-') ? icon.slice(10) : _icons.post
|
|
186
|
+
};
|
|
187
|
+
const hasEntities = postTypesInfo === null || postTypesInfo === void 0 ? void 0 : (_postTypesInfo$slug = postTypesInfo[slug]) === null || _postTypesInfo$slug === void 0 ? void 0 : _postTypesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
|
|
188
|
+
|
|
189
|
+
if (hasEntities) {
|
|
190
|
+
menuItem.onClick = template => {
|
|
191
|
+
onClickMenuItem({
|
|
192
|
+
type: 'postType',
|
|
193
|
+
slug,
|
|
194
|
+
config: {
|
|
195
|
+
recordNamePath: 'title.rendered',
|
|
196
|
+
queryArgs: _ref7 => {
|
|
197
|
+
let {
|
|
198
|
+
search
|
|
199
|
+
} = _ref7;
|
|
200
|
+
return {
|
|
201
|
+
_fields: 'id,title,slug,link',
|
|
202
|
+
orderBy: search ? 'relevance' : 'modified',
|
|
203
|
+
exclude: postTypesInfo[slug].existingEntitiesIds
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
getSpecificTemplate: suggestion => {
|
|
207
|
+
let title = (0, _i18n.sprintf)( // 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".
|
|
208
|
+
(0, _i18n.__)('%1$s: %2$s'), labels.singular_name, suggestion.name);
|
|
209
|
+
const description = (0, _i18n.sprintf)( // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Page: Hello"
|
|
210
|
+
(0, _i18n.__)('Template for %1$s'), title);
|
|
211
|
+
|
|
212
|
+
if (_needsUniqueIdentifier) {
|
|
213
|
+
title = (0, _i18n.sprintf)( // 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)"
|
|
214
|
+
(0, _i18n.__)('%1$s %2$s'), title, `(${slug})`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
title,
|
|
219
|
+
description,
|
|
220
|
+
slug: `${templatePrefixes[slug]}-${suggestion.slug}`
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
labels,
|
|
225
|
+
hasGeneralTemplate,
|
|
226
|
+
template
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
} // We don't need to add the menu item if there are no
|
|
230
|
+
// entities and the general template exists.
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
234
|
+
accumulator.push(menuItem);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return accumulator;
|
|
238
|
+
}, []); // Split menu items into two groups: one for the default post types
|
|
239
|
+
// and one for the rest.
|
|
240
|
+
|
|
241
|
+
const postTypesMenuItems = (0, _element.useMemo)(() => menuItems.reduce((accumulator, postType) => {
|
|
242
|
+
const {
|
|
243
|
+
slug
|
|
244
|
+
} = postType;
|
|
245
|
+
let key = 'postTypesMenuItems';
|
|
246
|
+
|
|
247
|
+
if (slug === 'page') {
|
|
248
|
+
key = 'defaultPostTypesMenuItems';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
accumulator[key].push(postType);
|
|
252
|
+
return accumulator;
|
|
253
|
+
}, {
|
|
254
|
+
defaultPostTypesMenuItems: [],
|
|
255
|
+
postTypesMenuItems: []
|
|
256
|
+
}), [menuItems]);
|
|
257
|
+
return postTypesMenuItems;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
exports.usePostTypeMenuItems = usePostTypeMenuItems;
|
|
261
|
+
|
|
262
|
+
const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
263
|
+
const publicTaxonomies = usePublicTaxonomies();
|
|
264
|
+
const existingTemplates = useExistingTemplates();
|
|
265
|
+
const defaultTemplateTypes = useDefaultTemplateTypes(); // `category` and `post_tag` are special cases in template hierarchy.
|
|
266
|
+
|
|
267
|
+
const templatePrefixes = (0, _element.useMemo)(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref8) => {
|
|
268
|
+
let {
|
|
269
|
+
slug
|
|
270
|
+
} = _ref8;
|
|
271
|
+
let suffix = slug;
|
|
272
|
+
|
|
273
|
+
if (!['category', 'post_tag'].includes(slug)) {
|
|
274
|
+
suffix = `taxonomy-${suffix}`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (slug === 'post_tag') {
|
|
278
|
+
suffix = `tag`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
accumulator[slug] = suffix;
|
|
282
|
+
return accumulator;
|
|
283
|
+
}, {}), [publicTaxonomies]); // We need to keep track of naming conflicts. If a conflict
|
|
284
|
+
// occurs, we need to add slug.
|
|
285
|
+
|
|
286
|
+
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
|
|
287
|
+
let {
|
|
288
|
+
labels
|
|
289
|
+
} = _ref9;
|
|
290
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
291
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
292
|
+
return accumulator;
|
|
293
|
+
}, {});
|
|
294
|
+
|
|
295
|
+
const needsUniqueIdentifier = (labels, slug) => {
|
|
296
|
+
if (['category', 'post_tag'].includes(slug)) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
301
|
+
return taxonomyLabels[singularName] > 1 && singularName !== slug;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const taxonomiesInfo = useEntitiesInfo('taxonomy', templatePrefixes);
|
|
305
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref10 => {
|
|
306
|
+
let {
|
|
307
|
+
slug
|
|
308
|
+
} = _ref10;
|
|
309
|
+
return slug;
|
|
310
|
+
});
|
|
311
|
+
const menuItems = (publicTaxonomies || []).reduce((accumulator, taxonomy) => {
|
|
312
|
+
var _taxonomiesInfo$slug;
|
|
313
|
+
|
|
314
|
+
const {
|
|
315
|
+
slug,
|
|
316
|
+
labels
|
|
317
|
+
} = taxonomy; // We need to check if the general template is part of the
|
|
318
|
+
// defaultTemplateTypes. If it is, just use that info and
|
|
319
|
+
// augment it with the specific template functionality.
|
|
320
|
+
|
|
321
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
322
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref11 => {
|
|
323
|
+
let {
|
|
324
|
+
slug: _slug
|
|
325
|
+
} = _ref11;
|
|
326
|
+
return _slug === generalTemplateSlug;
|
|
327
|
+
});
|
|
328
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
329
|
+
|
|
330
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(labels, slug);
|
|
331
|
+
|
|
332
|
+
let menuItemTitle = labels.singular_name;
|
|
333
|
+
|
|
334
|
+
if (_needsUniqueIdentifier) {
|
|
335
|
+
menuItemTitle = (0, _i18n.sprintf)( // translators: %1s: Name of the taxonomy e.g: "Category"; %2s: Slug of the taxonomy e.g: "product_cat".
|
|
336
|
+
(0, _i18n.__)('%1$s (%2$s)'), labels.singular_name, slug);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType
|
|
340
|
+
} : {
|
|
341
|
+
slug: generalTemplateSlug,
|
|
342
|
+
title: menuItemTitle,
|
|
343
|
+
description: (0, _i18n.sprintf)( // translators: %s: Name of the taxonomy e.g: "Product Categories".
|
|
344
|
+
(0, _i18n.__)('Displays taxonomy: %s.'), labels.singular_name),
|
|
345
|
+
icon: _icons.blockMeta
|
|
346
|
+
};
|
|
347
|
+
const hasEntities = taxonomiesInfo === null || taxonomiesInfo === void 0 ? void 0 : (_taxonomiesInfo$slug = taxonomiesInfo[slug]) === null || _taxonomiesInfo$slug === void 0 ? void 0 : _taxonomiesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
|
|
348
|
+
|
|
349
|
+
if (hasEntities) {
|
|
350
|
+
menuItem.onClick = template => {
|
|
351
|
+
onClickMenuItem({
|
|
352
|
+
type: 'taxonomy',
|
|
353
|
+
slug,
|
|
354
|
+
config: {
|
|
355
|
+
queryArgs: _ref12 => {
|
|
356
|
+
let {
|
|
357
|
+
search
|
|
358
|
+
} = _ref12;
|
|
359
|
+
return {
|
|
360
|
+
_fields: 'id,name,slug,link',
|
|
361
|
+
orderBy: search ? 'name' : 'count',
|
|
362
|
+
exclude: taxonomiesInfo[slug].existingEntitiesIds
|
|
363
|
+
};
|
|
364
|
+
},
|
|
365
|
+
getSpecificTemplate: suggestion => {
|
|
366
|
+
let title = (0, _i18n.sprintf)( // 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".
|
|
367
|
+
(0, _i18n.__)('%1$s: %2$s'), labels.singular_name, suggestion.name);
|
|
368
|
+
const description = (0, _i18n.sprintf)( // translators: Represents the description of a user's custom template in the Site Editor, e.g. "Template for Category: shoes"
|
|
369
|
+
(0, _i18n.__)('Template for %1$s'), title);
|
|
370
|
+
|
|
371
|
+
if (_needsUniqueIdentifier) {
|
|
372
|
+
title = (0, _i18n.sprintf)( // 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)"
|
|
373
|
+
(0, _i18n.__)('%1$s %2$s'), title, `(${slug})`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return {
|
|
377
|
+
title,
|
|
378
|
+
description,
|
|
379
|
+
slug: `${templatePrefixes[slug]}-${suggestion.slug}`
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
labels,
|
|
384
|
+
hasGeneralTemplate,
|
|
385
|
+
template
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
} // We don't need to add the menu item if there are no
|
|
389
|
+
// entities and the general template exists.
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
393
|
+
accumulator.push(menuItem);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return accumulator;
|
|
397
|
+
}, []); // Split menu items into two groups: one for the default taxonomies
|
|
398
|
+
// and one for the rest.
|
|
399
|
+
|
|
400
|
+
const taxonomiesMenuItems = (0, _element.useMemo)(() => menuItems.reduce((accumulator, taxonomy) => {
|
|
401
|
+
const {
|
|
402
|
+
slug
|
|
403
|
+
} = taxonomy;
|
|
404
|
+
let key = 'taxonomiesMenuItems';
|
|
405
|
+
|
|
406
|
+
if (['category', 'tag'].includes(slug)) {
|
|
407
|
+
key = 'defaultTaxonomiesMenuItems';
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
accumulator[key].push(taxonomy);
|
|
411
|
+
return accumulator;
|
|
412
|
+
}, {
|
|
413
|
+
defaultTaxonomiesMenuItems: [],
|
|
414
|
+
taxonomiesMenuItems: []
|
|
415
|
+
}), [menuItems]);
|
|
416
|
+
return taxonomiesMenuItems;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* Helper hook that filters all the existing templates by the given
|
|
420
|
+
* object with the entity's slug as key and the template prefix as value.
|
|
421
|
+
*
|
|
422
|
+
* Example:
|
|
423
|
+
* `existingTemplates` is: [ { slug: tag-apple }, { slug: page-about }, { slug: tag } ]
|
|
424
|
+
* `templatePrefixes` is: { post_tag: 'tag' }
|
|
425
|
+
* It will return: { post_tag: [apple] }
|
|
426
|
+
*
|
|
427
|
+
* Note: We append the `-` to the given template prefix in this function for our checks.
|
|
428
|
+
*
|
|
429
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
430
|
+
* @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
exports.useTaxonomiesMenuItems = useTaxonomiesMenuItems;
|
|
435
|
+
|
|
436
|
+
const useExistingTemplateSlugs = templatePrefixes => {
|
|
437
|
+
const existingTemplates = useExistingTemplates();
|
|
438
|
+
const existingSlugs = (0, _element.useMemo)(() => {
|
|
439
|
+
return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref13) => {
|
|
440
|
+
let [slug, prefix] = _ref13;
|
|
441
|
+
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
442
|
+
const _prefix = `${prefix}-`;
|
|
443
|
+
|
|
444
|
+
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
445
|
+
_accumulator.push(existingTemplate.slug.substring(_prefix.length));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return _accumulator;
|
|
449
|
+
}, []);
|
|
450
|
+
|
|
451
|
+
if (slugsWithTemplates.length) {
|
|
452
|
+
accumulator[slug] = slugsWithTemplates;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return accumulator;
|
|
456
|
+
}, {});
|
|
457
|
+
}, [templatePrefixes, existingTemplates]);
|
|
458
|
+
return existingSlugs;
|
|
459
|
+
};
|
|
460
|
+
/**
|
|
461
|
+
* Helper hook that finds the existing records with an associated template,
|
|
462
|
+
* as they need to be excluded from the template suggestions.
|
|
463
|
+
*
|
|
464
|
+
* @param {string} entityName The entity's name.
|
|
465
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
466
|
+
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
|
|
467
|
+
*/
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
const useTemplatesToExclude = (entityName, templatePrefixes) => {
|
|
471
|
+
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
472
|
+
const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
|
|
473
|
+
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref14) => {
|
|
474
|
+
let [slug, slugsWithTemplates] = _ref14;
|
|
475
|
+
const entitiesWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
476
|
+
_fields: 'id',
|
|
477
|
+
context: 'view',
|
|
478
|
+
slug: slugsWithTemplates
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
if (entitiesWithTemplates !== null && entitiesWithTemplates !== void 0 && entitiesWithTemplates.length) {
|
|
482
|
+
accumulator[slug] = entitiesWithTemplates;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return accumulator;
|
|
486
|
+
}, {});
|
|
487
|
+
}, [slugsToExcludePerEntity]);
|
|
488
|
+
return recordsToExcludePerEntity;
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* Helper hook that returns information about an entity having
|
|
492
|
+
* records that we can create a specific template for.
|
|
493
|
+
*
|
|
494
|
+
* For example we can search for `terms` in `taxonomy` entity or
|
|
495
|
+
* `posts` in `postType` entity.
|
|
496
|
+
*
|
|
497
|
+
* First we need to find the existing records with an associated template,
|
|
498
|
+
* to query afterwards for any remaining record, by excluding them.
|
|
499
|
+
*
|
|
500
|
+
* @param {string} entityName The entity's name.
|
|
501
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
502
|
+
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.
|
|
503
|
+
*/
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
const useEntitiesInfo = (entityName, templatePrefixes) => {
|
|
507
|
+
const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes);
|
|
508
|
+
const entitiesInfo = (0, _data.useSelect)(select => {
|
|
509
|
+
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
510
|
+
var _recordsToExcludePerE, _select$getEntityReco;
|
|
511
|
+
|
|
512
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref15 => {
|
|
513
|
+
let {
|
|
514
|
+
id
|
|
515
|
+
} = _ref15;
|
|
516
|
+
return id;
|
|
517
|
+
})) || [];
|
|
518
|
+
accumulator[slug] = {
|
|
519
|
+
hasEntities: !!((_select$getEntityReco = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
520
|
+
per_page: 1,
|
|
521
|
+
_fields: 'id',
|
|
522
|
+
context: 'view',
|
|
523
|
+
exclude: existingEntitiesIds
|
|
524
|
+
})) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
|
|
525
|
+
existingEntitiesIds
|
|
526
|
+
};
|
|
527
|
+
return accumulator;
|
|
528
|
+
}, {});
|
|
529
|
+
}, [templatePrefixes, recordsToExcludePerEntity]);
|
|
530
|
+
return entitiesInfo;
|
|
531
|
+
};
|
|
532
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["mapToIHasNameAndId","entities","path","map","entity","name","useExistingTemplates","select","coreStore","getEntityRecords","per_page","useDefaultTemplateTypes","editorStore","__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","title","description","startsWith","slice","post","hasEntities","onClick","template","type","config","recordNamePath","queryArgs","search","_fields","orderBy","exclude","existingEntitiesIds","getSpecificTemplate","suggestion","push","postTypesMenuItems","key","defaultPostTypesMenuItems","useTaxonomiesMenuItems","publicTaxonomies","taxonomyLabels","taxonomiesInfo","taxonomy","blockMeta","taxonomiesMenuItems","defaultTaxonomiesMenuItems","useExistingTemplateSlugs","existingSlugs","Object","entries","prefix","slugsWithTemplates","_accumulator","existingTemplate","_prefix","substring","length","useTemplatesToExclude","entityName","slugsToExcludePerEntity","recordsToExcludePerEntity","entitiesWithTemplates","context","entitiesInfo","keys","id"],"mappings":";;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAAEC,QAAF,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ACgB,IAAP,CAAazE,gBAAgB,IAAI,EAAjC,EAAsCC,MAAtC,CACN,CAAEC,WAAF,EAAed,IAAf,KAAyB;AAAA;;AACxB,YAAMoD,mBAAmB,GACxB,CAAA6B,yBAAyB,SAAzB,IAAAA,yBAAyB,WAAzB,qCAAAA,yBAAyB,CAAIjF,IAAJ,CAAzB,gFAAqCjB,GAArC,CACC;AAAA,YAAE;AAAEuG,UAAAA;AAAF,SAAF;AAAA,eAAcA,EAAd;AAAA,OADD,MAEK,EAHN;AAIAxE,MAAAA,WAAW,CAAEd,IAAF,CAAX,GAAsB;AACrByC,QAAAA,WAAW,EAAE,CAAC,2BAAEtD,MAAM,CAAEC,eAAF,CAAN,CAAoBC,gBAApB,CACf0F,UADe,EAEf/E,IAFe,EAGf;AACCV,UAAAA,QAAQ,EAAE,CADX;AAEC2D,UAAAA,OAAO,EAAE,IAFV;AAGCkC,UAAAA,OAAO,EAAE,MAHV;AAIChC,UAAAA,OAAO,EAAEC;AAJV,SAHe,CAAF,kDAAE,sBASbyB,MATW,CADO;AAWrBzB,QAAAA;AAXqB,OAAtB;AAaA,aAAOtC,WAAP;AACA,KApBK,EAqBN,EArBM,CAAP;AAuBA,GAzBmB,EA0BpB,CAAEF,gBAAF,EAAoBqE,yBAApB,CA1BoB,CAArB;AA4BA,SAAOG,YAAP;AACA,CAlCD","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 } 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? { ...defaultTemplateType }\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 };\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\t`(${ slug })`\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};\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? { ...defaultTemplateType }\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 };\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\t`(${ slug })`\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};\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\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 * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.\n */\nconst useTemplatesToExclude = ( entityName, templatePrefixes ) => {\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} );\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 * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.\n */\nconst useEntitiesInfo = ( entityName, templatePrefixes ) => {\n\tconst recordsToExcludePerEntity = useTemplatesToExclude(\n\t\tentityName,\n\t\ttemplatePrefixes\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}\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"]}
|
|
@@ -43,8 +43,6 @@ var _store = require("../../store");
|
|
|
43
43
|
|
|
44
44
|
var _blockInspectorButton = _interopRequireDefault(require("./block-inspector-button"));
|
|
45
45
|
|
|
46
|
-
var _editTemplatePartMenuButton = _interopRequireDefault(require("../edit-template-part-menu-button"));
|
|
47
|
-
|
|
48
46
|
var _backButton = _interopRequireDefault(require("./back-button"));
|
|
49
47
|
|
|
50
48
|
var _resizableEditor = _interopRequireDefault(require("./resizable-editor"));
|
|
@@ -151,7 +149,7 @@ function BlockEditor(_ref) {
|
|
|
151
149
|
onInput: onInput,
|
|
152
150
|
onChange: onChange,
|
|
153
151
|
useSubRegistry: false
|
|
154
|
-
}, (0, _element.createElement)(
|
|
152
|
+
}, (0, _element.createElement)(_templatePartConverter.default, null), (0, _element.createElement)(_blockEditor.__experimentalLinkControl.ViewerFill, null, (0, _element.useCallback)(fillProps => (0, _element.createElement)(_navigateToLink.default, (0, _extends2.default)({}, fillProps, {
|
|
155
153
|
activePage: page,
|
|
156
154
|
onActivePageChange: setPage
|
|
157
155
|
})), [page])), (0, _element.createElement)(_sidebar.SidebarInspectorFill, null, (0, _element.createElement)(_blockEditor.BlockInspector, null)), (0, _element.createElement)(_blockEditor.BlockTools, {
|