@wordpress/edit-site 6.35.2-next.dc3f6d3c1.0 → 6.36.1-next.6deb34194.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 +1 -1
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +109 -0
- package/build/components/add-new-template-legacy/add-custom-generic-template-modal-content.js.map +7 -0
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.js +328 -0
- package/build/components/add-new-template-legacy/add-custom-template-modal-content.js.map +7 -0
- package/build/components/add-new-template-legacy/index.js +389 -0
- package/build/components/add-new-template-legacy/index.js.map +7 -0
- package/build/components/add-new-template-legacy/utils.js +620 -0
- package/build/components/add-new-template-legacy/utils.js.map +7 -0
- package/build/components/block-editor/use-site-editor-settings.js +3 -3
- package/build/components/block-editor/use-site-editor-settings.js.map +2 -2
- package/build/components/page-templates/fields.js +3 -1
- package/build/components/page-templates/fields.js.map +2 -2
- package/build/components/page-templates/index-legacy.js +185 -0
- package/build/components/page-templates/index-legacy.js.map +7 -0
- package/build/components/post-list/index.js +27 -4
- package/build/components/post-list/index.js.map +3 -3
- package/build/components/post-list/use-notes-count.js +56 -0
- package/build/components/post-list/use-notes-count.js.map +7 -0
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +2 -1
- package/build/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +2 -2
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.js +101 -0
- package/build/components/sidebar-navigation-screen-templates-browse/content-legacy.js.map +7 -0
- package/build/components/sidebar-navigation-screen-templates-browse/index.js +2 -1
- package/build/components/sidebar-navigation-screen-templates-browse/index.js.map +3 -3
- package/build/components/site-editor-routes/templates.js +10 -2
- package/build/components/site-editor-routes/templates.js.map +3 -3
- package/build/components/site-hub/index.js +1 -1
- package/build/components/site-hub/index.js.map +2 -2
- package/build/utils/constants.js +6 -0
- package/build/utils/constants.js.map +2 -2
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +93 -0
- package/build-module/components/add-new-template-legacy/add-custom-generic-template-modal-content.js.map +7 -0
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.js +316 -0
- package/build-module/components/add-new-template-legacy/add-custom-template-modal-content.js.map +7 -0
- package/build-module/components/add-new-template-legacy/index.js +390 -0
- package/build-module/components/add-new-template-legacy/index.js.map +7 -0
- package/build-module/components/add-new-template-legacy/utils.js +589 -0
- package/build-module/components/add-new-template-legacy/utils.js.map +7 -0
- package/build-module/components/block-editor/use-site-editor-settings.js +3 -3
- package/build-module/components/block-editor/use-site-editor-settings.js.map +2 -2
- package/build-module/components/page-templates/fields.js +3 -1
- package/build-module/components/page-templates/fields.js.map +2 -2
- package/build-module/components/page-templates/index-legacy.js +154 -0
- package/build-module/components/page-templates/index-legacy.js.map +7 -0
- package/build-module/components/post-list/index.js +29 -4
- package/build-module/components/post-list/index.js.map +2 -2
- package/build-module/components/post-list/use-notes-count.js +35 -0
- package/build-module/components/post-list/use-notes-count.js.map +7 -0
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +2 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-template-part-areas.js.map +2 -2
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.js +70 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/content-legacy.js.map +7 -0
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js +2 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/index.js.map +2 -2
- package/build-module/components/site-editor-routes/templates.js +10 -2
- package/build-module/components/site-editor-routes/templates.js.map +2 -2
- package/build-module/components/site-hub/index.js +1 -1
- package/build-module/components/site-hub/index.js.map +2 -2
- package/build-module/utils/constants.js +4 -0
- package/build-module/utils/constants.js.map +2 -2
- package/build-style/style-rtl.css +294 -147
- package/build-style/style.css +294 -147
- package/package.json +46 -46
- package/src/components/add-new-template-legacy/add-custom-generic-template-modal-content.js +94 -0
- package/src/components/add-new-template-legacy/add-custom-template-modal-content.js +314 -0
- package/src/components/add-new-template-legacy/index.js +454 -0
- package/src/components/add-new-template-legacy/utils.js +760 -0
- package/src/components/block-editor/use-site-editor-settings.js +3 -7
- package/src/components/page-templates/fields.js +13 -9
- package/src/components/page-templates/index-legacy.js +166 -0
- package/src/components/post-list/index.js +34 -4
- package/src/components/post-list/use-notes-count.js +48 -0
- package/src/components/sidebar-global-styles/style.scss +0 -8
- package/src/components/sidebar-navigation-screen-patterns/use-template-part-areas.js +1 -0
- package/src/components/sidebar-navigation-screen-templates-browse/content-legacy.js +79 -0
- package/src/components/sidebar-navigation-screen-templates-browse/index.js +8 -1
- package/src/components/site-editor-routes/templates.js +22 -3
- package/src/components/site-hub/index.js +1 -1
- package/src/utils/constants.js +2 -0
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/edit-site/src/components/add-new-template-legacy/utils.js
|
|
21
|
+
var utils_exports = {};
|
|
22
|
+
__export(utils_exports, {
|
|
23
|
+
mapToIHasNameAndId: () => mapToIHasNameAndId,
|
|
24
|
+
useAuthorMenuItem: () => useAuthorMenuItem,
|
|
25
|
+
useDefaultTemplateTypes: () => useDefaultTemplateTypes,
|
|
26
|
+
useExistingTemplates: () => useExistingTemplates,
|
|
27
|
+
usePostTypeArchiveMenuItems: () => usePostTypeArchiveMenuItems,
|
|
28
|
+
usePostTypeMenuItems: () => usePostTypeMenuItems,
|
|
29
|
+
useTaxonomiesMenuItems: () => useTaxonomiesMenuItems
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(utils_exports);
|
|
32
|
+
var import_data = require("@wordpress/data");
|
|
33
|
+
var import_core_data = require("@wordpress/core-data");
|
|
34
|
+
var import_html_entities = require("@wordpress/html-entities");
|
|
35
|
+
var import_element = require("@wordpress/element");
|
|
36
|
+
var import_i18n = require("@wordpress/i18n");
|
|
37
|
+
var import_icons = require("@wordpress/icons");
|
|
38
|
+
var import_url = require("@wordpress/url");
|
|
39
|
+
var import_constants = require("../../utils/constants");
|
|
40
|
+
var EMPTY_OBJECT = {};
|
|
41
|
+
var getValueFromObjectPath = (object, path) => {
|
|
42
|
+
let value = object;
|
|
43
|
+
path.split(".").forEach((fieldName) => {
|
|
44
|
+
value = value?.[fieldName];
|
|
45
|
+
});
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
function prefixSlug(prefix, slug) {
|
|
49
|
+
return `${prefix}-${(0, import_url.safeDecodeURI)(slug)}`;
|
|
50
|
+
}
|
|
51
|
+
var mapToIHasNameAndId = (entities, path) => {
|
|
52
|
+
return (entities || []).map((entity) => ({
|
|
53
|
+
...entity,
|
|
54
|
+
name: (0, import_html_entities.decodeEntities)(getValueFromObjectPath(entity, path))
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
var useExistingTemplates = () => {
|
|
58
|
+
return (0, import_data.useSelect)(
|
|
59
|
+
(select) => select(import_core_data.store).getEntityRecords(
|
|
60
|
+
"postType",
|
|
61
|
+
import_constants.TEMPLATE_POST_TYPE,
|
|
62
|
+
{
|
|
63
|
+
per_page: -1
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
[]
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
var useDefaultTemplateTypes = () => {
|
|
70
|
+
return (0, import_data.useSelect)(
|
|
71
|
+
(select) => select(import_core_data.store).getCurrentTheme()?.default_template_types || [],
|
|
72
|
+
[]
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
var usePublicPostTypes = () => {
|
|
76
|
+
const postTypes = (0, import_data.useSelect)(
|
|
77
|
+
(select) => select(import_core_data.store).getPostTypes({ per_page: -1 }),
|
|
78
|
+
[]
|
|
79
|
+
);
|
|
80
|
+
return (0, import_element.useMemo)(() => {
|
|
81
|
+
const excludedPostTypes = ["attachment"];
|
|
82
|
+
return postTypes?.filter(
|
|
83
|
+
({ viewable, slug }) => viewable && !excludedPostTypes.includes(slug)
|
|
84
|
+
).sort((a, b) => {
|
|
85
|
+
if (a.slug === "post" || b.slug === "post") {
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
return a.name.localeCompare(b.name);
|
|
89
|
+
});
|
|
90
|
+
}, [postTypes]);
|
|
91
|
+
};
|
|
92
|
+
var usePublicTaxonomies = () => {
|
|
93
|
+
const taxonomies = (0, import_data.useSelect)(
|
|
94
|
+
(select) => select(import_core_data.store).getTaxonomies({ per_page: -1 }),
|
|
95
|
+
[]
|
|
96
|
+
);
|
|
97
|
+
return (0, import_element.useMemo)(() => {
|
|
98
|
+
return taxonomies?.filter(
|
|
99
|
+
({ visibility }) => visibility?.publicly_queryable
|
|
100
|
+
);
|
|
101
|
+
}, [taxonomies]);
|
|
102
|
+
};
|
|
103
|
+
function usePostTypeArchiveMenuItems() {
|
|
104
|
+
const publicPostTypes = usePublicPostTypes();
|
|
105
|
+
const postTypesWithArchives = (0, import_element.useMemo)(
|
|
106
|
+
() => publicPostTypes?.filter((postType) => postType.has_archive),
|
|
107
|
+
[publicPostTypes]
|
|
108
|
+
);
|
|
109
|
+
const existingTemplates = useExistingTemplates();
|
|
110
|
+
const postTypeLabels = (0, import_element.useMemo)(
|
|
111
|
+
() => publicPostTypes?.reduce((accumulator, { labels }) => {
|
|
112
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
113
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
114
|
+
return accumulator;
|
|
115
|
+
}, {}),
|
|
116
|
+
[publicPostTypes]
|
|
117
|
+
);
|
|
118
|
+
const needsUniqueIdentifier = (0, import_element.useCallback)(
|
|
119
|
+
({ labels, slug }) => {
|
|
120
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
121
|
+
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
122
|
+
},
|
|
123
|
+
[postTypeLabels]
|
|
124
|
+
);
|
|
125
|
+
return (0, import_element.useMemo)(
|
|
126
|
+
() => postTypesWithArchives?.filter(
|
|
127
|
+
(postType) => !(existingTemplates || []).some(
|
|
128
|
+
(existingTemplate) => existingTemplate.slug === "archive-" + postType.slug
|
|
129
|
+
)
|
|
130
|
+
).map((postType) => {
|
|
131
|
+
let title;
|
|
132
|
+
if (needsUniqueIdentifier(postType)) {
|
|
133
|
+
title = (0, import_i18n.sprintf)(
|
|
134
|
+
// translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
|
|
135
|
+
(0, import_i18n.__)("Archive: %1$s (%2$s)"),
|
|
136
|
+
postType.labels.singular_name,
|
|
137
|
+
postType.slug
|
|
138
|
+
);
|
|
139
|
+
} else {
|
|
140
|
+
title = (0, import_i18n.sprintf)(
|
|
141
|
+
// translators: %s: Name of the post type e.g: "Post".
|
|
142
|
+
(0, import_i18n.__)("Archive: %s"),
|
|
143
|
+
postType.labels.singular_name
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
slug: "archive-" + postType.slug,
|
|
148
|
+
description: (0, import_i18n.sprintf)(
|
|
149
|
+
// translators: %s: Name of the post type e.g: "Post".
|
|
150
|
+
(0, import_i18n.__)(
|
|
151
|
+
"Displays an archive with the latest posts of type: %s."
|
|
152
|
+
),
|
|
153
|
+
postType.labels.singular_name
|
|
154
|
+
),
|
|
155
|
+
title,
|
|
156
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
157
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
158
|
+
// also supports urls and svg as values.
|
|
159
|
+
icon: typeof postType.icon === "string" && postType.icon.startsWith("dashicons-") ? postType.icon.slice(10) : import_icons.archive,
|
|
160
|
+
templatePrefix: "archive"
|
|
161
|
+
};
|
|
162
|
+
}) || [],
|
|
163
|
+
[postTypesWithArchives, existingTemplates, needsUniqueIdentifier]
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
var usePostTypeMenuItems = (onClickMenuItem) => {
|
|
167
|
+
const publicPostTypes = usePublicPostTypes();
|
|
168
|
+
const existingTemplates = useExistingTemplates();
|
|
169
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
170
|
+
const templateLabels = (0, import_element.useMemo)(
|
|
171
|
+
() => publicPostTypes?.reduce((accumulator, { labels }) => {
|
|
172
|
+
const templateName = (labels.template_name || labels.singular_name).toLowerCase();
|
|
173
|
+
accumulator[templateName] = (accumulator[templateName] || 0) + 1;
|
|
174
|
+
return accumulator;
|
|
175
|
+
}, {}),
|
|
176
|
+
[publicPostTypes]
|
|
177
|
+
);
|
|
178
|
+
const needsUniqueIdentifier = (0, import_element.useCallback)(
|
|
179
|
+
({ labels, slug }) => {
|
|
180
|
+
const templateName = (labels.template_name || labels.singular_name).toLowerCase();
|
|
181
|
+
return templateLabels[templateName] > 1 && templateName !== slug;
|
|
182
|
+
},
|
|
183
|
+
[templateLabels]
|
|
184
|
+
);
|
|
185
|
+
const templatePrefixes = (0, import_element.useMemo)(
|
|
186
|
+
() => publicPostTypes?.reduce((accumulator, { slug }) => {
|
|
187
|
+
let suffix = slug;
|
|
188
|
+
if (slug !== "page") {
|
|
189
|
+
suffix = `single-${suffix}`;
|
|
190
|
+
}
|
|
191
|
+
accumulator[slug] = suffix;
|
|
192
|
+
return accumulator;
|
|
193
|
+
}, {}),
|
|
194
|
+
[publicPostTypes]
|
|
195
|
+
);
|
|
196
|
+
const postTypesInfo = useEntitiesInfo("postType", templatePrefixes);
|
|
197
|
+
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
198
|
+
({ slug }) => slug
|
|
199
|
+
);
|
|
200
|
+
const menuItems = (publicPostTypes || []).reduce(
|
|
201
|
+
(accumulator, postType) => {
|
|
202
|
+
const { slug, labels, icon } = postType;
|
|
203
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
204
|
+
const defaultTemplateType = defaultTemplateTypes?.find(
|
|
205
|
+
({ slug: _slug }) => _slug === generalTemplateSlug
|
|
206
|
+
);
|
|
207
|
+
const hasGeneralTemplate = existingTemplateSlugs?.includes(generalTemplateSlug);
|
|
208
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
|
|
209
|
+
let menuItemTitle = labels.template_name || (0, import_i18n.sprintf)(
|
|
210
|
+
// translators: %s: Name of the post type e.g: "Post".
|
|
211
|
+
(0, import_i18n.__)("Single item: %s"),
|
|
212
|
+
labels.singular_name
|
|
213
|
+
);
|
|
214
|
+
if (_needsUniqueIdentifier) {
|
|
215
|
+
menuItemTitle = labels.template_name ? (0, import_i18n.sprintf)(
|
|
216
|
+
// translators: 1: Name of the template e.g: "Single Item: Post". 2: Slug of the post type e.g: "book".
|
|
217
|
+
(0, import_i18n._x)("%1$s (%2$s)", "post type menu label"),
|
|
218
|
+
labels.template_name,
|
|
219
|
+
slug
|
|
220
|
+
) : (0, import_i18n.sprintf)(
|
|
221
|
+
// translators: 1: Name of the post type e.g: "Post". 2: Slug of the post type e.g: "book".
|
|
222
|
+
(0, import_i18n._x)(
|
|
223
|
+
"Single item: %1$s (%2$s)",
|
|
224
|
+
"post type menu label"
|
|
225
|
+
),
|
|
226
|
+
labels.singular_name,
|
|
227
|
+
slug
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const menuItem = defaultTemplateType ? {
|
|
231
|
+
...defaultTemplateType,
|
|
232
|
+
templatePrefix: templatePrefixes[slug]
|
|
233
|
+
} : {
|
|
234
|
+
slug: generalTemplateSlug,
|
|
235
|
+
title: menuItemTitle,
|
|
236
|
+
description: (0, import_i18n.sprintf)(
|
|
237
|
+
// translators: %s: Name of the post type e.g: "Post".
|
|
238
|
+
(0, import_i18n.__)("Displays a single item: %s."),
|
|
239
|
+
labels.singular_name
|
|
240
|
+
),
|
|
241
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
242
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
243
|
+
// also supports urls and svg as values.
|
|
244
|
+
icon: typeof icon === "string" && icon.startsWith("dashicons-") ? icon.slice(10) : import_icons.post,
|
|
245
|
+
templatePrefix: templatePrefixes[slug]
|
|
246
|
+
};
|
|
247
|
+
const hasEntities = postTypesInfo?.[slug]?.hasEntities;
|
|
248
|
+
if (hasEntities) {
|
|
249
|
+
menuItem.onClick = (template) => {
|
|
250
|
+
onClickMenuItem({
|
|
251
|
+
type: "postType",
|
|
252
|
+
slug,
|
|
253
|
+
config: {
|
|
254
|
+
recordNamePath: "title.rendered",
|
|
255
|
+
queryArgs: ({ search }) => {
|
|
256
|
+
return {
|
|
257
|
+
_fields: "id,title,slug,link",
|
|
258
|
+
orderBy: search ? "relevance" : "modified",
|
|
259
|
+
exclude: postTypesInfo[slug].existingEntitiesIds
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
getSpecificTemplate: (suggestion) => {
|
|
263
|
+
const templateSlug = prefixSlug(
|
|
264
|
+
templatePrefixes[slug],
|
|
265
|
+
suggestion.slug
|
|
266
|
+
);
|
|
267
|
+
return {
|
|
268
|
+
title: templateSlug,
|
|
269
|
+
slug: templateSlug,
|
|
270
|
+
templatePrefix: templatePrefixes[slug]
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
labels,
|
|
275
|
+
hasGeneralTemplate,
|
|
276
|
+
template
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
281
|
+
accumulator.push(menuItem);
|
|
282
|
+
}
|
|
283
|
+
return accumulator;
|
|
284
|
+
},
|
|
285
|
+
[]
|
|
286
|
+
);
|
|
287
|
+
const postTypesMenuItems = (0, import_element.useMemo)(
|
|
288
|
+
() => menuItems.reduce(
|
|
289
|
+
(accumulator, postType) => {
|
|
290
|
+
const { slug } = postType;
|
|
291
|
+
let key = "postTypesMenuItems";
|
|
292
|
+
if (slug === "page") {
|
|
293
|
+
key = "defaultPostTypesMenuItems";
|
|
294
|
+
}
|
|
295
|
+
accumulator[key].push(postType);
|
|
296
|
+
return accumulator;
|
|
297
|
+
},
|
|
298
|
+
{ defaultPostTypesMenuItems: [], postTypesMenuItems: [] }
|
|
299
|
+
),
|
|
300
|
+
[menuItems]
|
|
301
|
+
);
|
|
302
|
+
return postTypesMenuItems;
|
|
303
|
+
};
|
|
304
|
+
var useTaxonomiesMenuItems = (onClickMenuItem) => {
|
|
305
|
+
const publicTaxonomies = usePublicTaxonomies();
|
|
306
|
+
const existingTemplates = useExistingTemplates();
|
|
307
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
308
|
+
const templatePrefixes = (0, import_element.useMemo)(
|
|
309
|
+
() => publicTaxonomies?.reduce((accumulator, { slug }) => {
|
|
310
|
+
let suffix = slug;
|
|
311
|
+
if (!["category", "post_tag"].includes(slug)) {
|
|
312
|
+
suffix = `taxonomy-${suffix}`;
|
|
313
|
+
}
|
|
314
|
+
if (slug === "post_tag") {
|
|
315
|
+
suffix = `tag`;
|
|
316
|
+
}
|
|
317
|
+
accumulator[slug] = suffix;
|
|
318
|
+
return accumulator;
|
|
319
|
+
}, {}),
|
|
320
|
+
[publicTaxonomies]
|
|
321
|
+
);
|
|
322
|
+
const taxonomyLabels = publicTaxonomies?.reduce(
|
|
323
|
+
(accumulator, { labels }) => {
|
|
324
|
+
const templateName = (labels.template_name || labels.singular_name).toLowerCase();
|
|
325
|
+
accumulator[templateName] = (accumulator[templateName] || 0) + 1;
|
|
326
|
+
return accumulator;
|
|
327
|
+
},
|
|
328
|
+
{}
|
|
329
|
+
);
|
|
330
|
+
const needsUniqueIdentifier = (labels, slug) => {
|
|
331
|
+
if (["category", "post_tag"].includes(slug)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
const templateName = (labels.template_name || labels.singular_name).toLowerCase();
|
|
335
|
+
return taxonomyLabels[templateName] > 1 && templateName !== slug;
|
|
336
|
+
};
|
|
337
|
+
const taxonomiesInfo = useEntitiesInfo("taxonomy", templatePrefixes);
|
|
338
|
+
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
339
|
+
({ slug }) => slug
|
|
340
|
+
);
|
|
341
|
+
const menuItems = (publicTaxonomies || []).reduce(
|
|
342
|
+
(accumulator, taxonomy) => {
|
|
343
|
+
const { slug, labels } = taxonomy;
|
|
344
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
345
|
+
const defaultTemplateType = defaultTemplateTypes?.find(
|
|
346
|
+
({ slug: _slug }) => _slug === generalTemplateSlug
|
|
347
|
+
);
|
|
348
|
+
const hasGeneralTemplate = existingTemplateSlugs?.includes(generalTemplateSlug);
|
|
349
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(
|
|
350
|
+
labels,
|
|
351
|
+
slug
|
|
352
|
+
);
|
|
353
|
+
let menuItemTitle = labels.template_name || labels.singular_name;
|
|
354
|
+
if (_needsUniqueIdentifier) {
|
|
355
|
+
menuItemTitle = labels.template_name ? (0, import_i18n.sprintf)(
|
|
356
|
+
// translators: 1: Name of the template e.g: "Products by Category". 2: Slug of the taxonomy e.g: "product_cat".
|
|
357
|
+
(0, import_i18n._x)("%1$s (%2$s)", "taxonomy template menu label"),
|
|
358
|
+
labels.template_name,
|
|
359
|
+
slug
|
|
360
|
+
) : (0, import_i18n.sprintf)(
|
|
361
|
+
// translators: 1: Name of the taxonomy e.g: "Category". 2: Slug of the taxonomy e.g: "product_cat".
|
|
362
|
+
(0, import_i18n._x)("%1$s (%2$s)", "taxonomy menu label"),
|
|
363
|
+
labels.singular_name,
|
|
364
|
+
slug
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
const menuItem = defaultTemplateType ? {
|
|
368
|
+
...defaultTemplateType,
|
|
369
|
+
templatePrefix: templatePrefixes[slug]
|
|
370
|
+
} : {
|
|
371
|
+
slug: generalTemplateSlug,
|
|
372
|
+
title: menuItemTitle,
|
|
373
|
+
description: (0, import_i18n.sprintf)(
|
|
374
|
+
// translators: %s: Name of the taxonomy e.g: "Product Categories".
|
|
375
|
+
(0, import_i18n.__)("Displays taxonomy: %s."),
|
|
376
|
+
labels.singular_name
|
|
377
|
+
),
|
|
378
|
+
icon: import_icons.blockMeta,
|
|
379
|
+
templatePrefix: templatePrefixes[slug]
|
|
380
|
+
};
|
|
381
|
+
const hasEntities = taxonomiesInfo?.[slug]?.hasEntities;
|
|
382
|
+
if (hasEntities) {
|
|
383
|
+
menuItem.onClick = (template) => {
|
|
384
|
+
onClickMenuItem({
|
|
385
|
+
type: "taxonomy",
|
|
386
|
+
slug,
|
|
387
|
+
config: {
|
|
388
|
+
queryArgs: ({ search }) => {
|
|
389
|
+
return {
|
|
390
|
+
_fields: "id,name,slug,link",
|
|
391
|
+
orderBy: search ? "name" : "count",
|
|
392
|
+
exclude: taxonomiesInfo[slug].existingEntitiesIds
|
|
393
|
+
};
|
|
394
|
+
},
|
|
395
|
+
getSpecificTemplate: (suggestion) => {
|
|
396
|
+
const templateSlug = prefixSlug(
|
|
397
|
+
templatePrefixes[slug],
|
|
398
|
+
suggestion.slug
|
|
399
|
+
);
|
|
400
|
+
return {
|
|
401
|
+
title: templateSlug,
|
|
402
|
+
slug: templateSlug,
|
|
403
|
+
templatePrefix: templatePrefixes[slug]
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
labels,
|
|
408
|
+
hasGeneralTemplate,
|
|
409
|
+
template
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
414
|
+
accumulator.push(menuItem);
|
|
415
|
+
}
|
|
416
|
+
return accumulator;
|
|
417
|
+
},
|
|
418
|
+
[]
|
|
419
|
+
);
|
|
420
|
+
const taxonomiesMenuItems = (0, import_element.useMemo)(
|
|
421
|
+
() => menuItems.reduce(
|
|
422
|
+
(accumulator, taxonomy) => {
|
|
423
|
+
const { slug } = taxonomy;
|
|
424
|
+
let key = "taxonomiesMenuItems";
|
|
425
|
+
if (["category", "tag"].includes(slug)) {
|
|
426
|
+
key = "defaultTaxonomiesMenuItems";
|
|
427
|
+
}
|
|
428
|
+
accumulator[key].push(taxonomy);
|
|
429
|
+
return accumulator;
|
|
430
|
+
},
|
|
431
|
+
{ defaultTaxonomiesMenuItems: [], taxonomiesMenuItems: [] }
|
|
432
|
+
),
|
|
433
|
+
[menuItems]
|
|
434
|
+
);
|
|
435
|
+
return taxonomiesMenuItems;
|
|
436
|
+
};
|
|
437
|
+
var USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = { user: "author" };
|
|
438
|
+
var USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = { user: { who: "authors" } };
|
|
439
|
+
function useAuthorMenuItem(onClickMenuItem) {
|
|
440
|
+
const existingTemplates = useExistingTemplates();
|
|
441
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
442
|
+
const authorInfo = useEntitiesInfo(
|
|
443
|
+
"root",
|
|
444
|
+
USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX,
|
|
445
|
+
USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS
|
|
446
|
+
);
|
|
447
|
+
let authorMenuItem = defaultTemplateTypes?.find(
|
|
448
|
+
({ slug }) => slug === "author"
|
|
449
|
+
);
|
|
450
|
+
if (!authorMenuItem) {
|
|
451
|
+
authorMenuItem = {
|
|
452
|
+
description: (0, import_i18n.__)(
|
|
453
|
+
"Displays latest posts written by a single author."
|
|
454
|
+
),
|
|
455
|
+
slug: "author",
|
|
456
|
+
title: "Author"
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const hasGeneralTemplate = !!existingTemplates?.find(
|
|
460
|
+
({ slug }) => slug === "author"
|
|
461
|
+
);
|
|
462
|
+
if (authorInfo.user?.hasEntities) {
|
|
463
|
+
authorMenuItem = { ...authorMenuItem, templatePrefix: "author" };
|
|
464
|
+
authorMenuItem.onClick = (template) => {
|
|
465
|
+
onClickMenuItem({
|
|
466
|
+
type: "root",
|
|
467
|
+
slug: "user",
|
|
468
|
+
config: {
|
|
469
|
+
queryArgs: ({ search }) => {
|
|
470
|
+
return {
|
|
471
|
+
_fields: "id,name,slug,link",
|
|
472
|
+
orderBy: search ? "name" : "registered_date",
|
|
473
|
+
exclude: authorInfo.user.existingEntitiesIds,
|
|
474
|
+
who: "authors"
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
getSpecificTemplate: (suggestion) => {
|
|
478
|
+
const templateSlug = prefixSlug(
|
|
479
|
+
"author",
|
|
480
|
+
suggestion.slug
|
|
481
|
+
);
|
|
482
|
+
return {
|
|
483
|
+
title: templateSlug,
|
|
484
|
+
slug: templateSlug,
|
|
485
|
+
templatePrefix: "author"
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
labels: {
|
|
490
|
+
singular_name: (0, import_i18n.__)("Author"),
|
|
491
|
+
search_items: (0, import_i18n.__)("Search Authors"),
|
|
492
|
+
not_found: (0, import_i18n.__)("No authors found."),
|
|
493
|
+
all_items: (0, import_i18n.__)("All Authors")
|
|
494
|
+
},
|
|
495
|
+
hasGeneralTemplate,
|
|
496
|
+
template
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
if (!hasGeneralTemplate || authorInfo.user?.hasEntities) {
|
|
501
|
+
return authorMenuItem;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
var useExistingTemplateSlugs = (templatePrefixes) => {
|
|
505
|
+
const existingTemplates = useExistingTemplates();
|
|
506
|
+
const existingSlugs = (0, import_element.useMemo)(() => {
|
|
507
|
+
return Object.entries(templatePrefixes || {}).reduce(
|
|
508
|
+
(accumulator, [slug, prefix]) => {
|
|
509
|
+
const slugsWithTemplates = (existingTemplates || []).reduce(
|
|
510
|
+
(_accumulator, existingTemplate) => {
|
|
511
|
+
const _prefix = `${prefix}-`;
|
|
512
|
+
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
513
|
+
_accumulator.push(
|
|
514
|
+
existingTemplate.slug.substring(
|
|
515
|
+
_prefix.length
|
|
516
|
+
)
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
return _accumulator;
|
|
520
|
+
},
|
|
521
|
+
[]
|
|
522
|
+
);
|
|
523
|
+
if (slugsWithTemplates.length) {
|
|
524
|
+
accumulator[slug] = slugsWithTemplates;
|
|
525
|
+
}
|
|
526
|
+
return accumulator;
|
|
527
|
+
},
|
|
528
|
+
{}
|
|
529
|
+
);
|
|
530
|
+
}, [templatePrefixes, existingTemplates]);
|
|
531
|
+
return existingSlugs;
|
|
532
|
+
};
|
|
533
|
+
var useTemplatesToExclude = (entityName, templatePrefixes, additionalQueryParameters = {}) => {
|
|
534
|
+
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
535
|
+
const recordsToExcludePerEntity = (0, import_data.useSelect)(
|
|
536
|
+
(select) => {
|
|
537
|
+
return Object.entries(slugsToExcludePerEntity || {}).reduce(
|
|
538
|
+
(accumulator, [slug, slugsWithTemplates]) => {
|
|
539
|
+
const entitiesWithTemplates = select(
|
|
540
|
+
import_core_data.store
|
|
541
|
+
).getEntityRecords(entityName, slug, {
|
|
542
|
+
_fields: "id",
|
|
543
|
+
context: "view",
|
|
544
|
+
slug: slugsWithTemplates,
|
|
545
|
+
...additionalQueryParameters[slug]
|
|
546
|
+
});
|
|
547
|
+
if (entitiesWithTemplates?.length) {
|
|
548
|
+
accumulator[slug] = entitiesWithTemplates;
|
|
549
|
+
}
|
|
550
|
+
return accumulator;
|
|
551
|
+
},
|
|
552
|
+
{}
|
|
553
|
+
);
|
|
554
|
+
},
|
|
555
|
+
[slugsToExcludePerEntity]
|
|
556
|
+
);
|
|
557
|
+
return recordsToExcludePerEntity;
|
|
558
|
+
};
|
|
559
|
+
var useEntitiesInfo = (entityName, templatePrefixes, additionalQueryParameters = EMPTY_OBJECT) => {
|
|
560
|
+
const recordsToExcludePerEntity = useTemplatesToExclude(
|
|
561
|
+
entityName,
|
|
562
|
+
templatePrefixes,
|
|
563
|
+
additionalQueryParameters
|
|
564
|
+
);
|
|
565
|
+
const entitiesHasRecords = (0, import_data.useSelect)(
|
|
566
|
+
(select) => {
|
|
567
|
+
return Object.keys(templatePrefixes || {}).reduce(
|
|
568
|
+
(accumulator, slug) => {
|
|
569
|
+
const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(
|
|
570
|
+
({ id }) => id
|
|
571
|
+
) || [];
|
|
572
|
+
accumulator[slug] = !!select(
|
|
573
|
+
import_core_data.store
|
|
574
|
+
).getEntityRecords(entityName, slug, {
|
|
575
|
+
per_page: 1,
|
|
576
|
+
_fields: "id",
|
|
577
|
+
context: "view",
|
|
578
|
+
exclude: existingEntitiesIds,
|
|
579
|
+
...additionalQueryParameters[slug]
|
|
580
|
+
})?.length;
|
|
581
|
+
return accumulator;
|
|
582
|
+
},
|
|
583
|
+
{}
|
|
584
|
+
);
|
|
585
|
+
},
|
|
586
|
+
[
|
|
587
|
+
templatePrefixes,
|
|
588
|
+
recordsToExcludePerEntity,
|
|
589
|
+
entityName,
|
|
590
|
+
additionalQueryParameters
|
|
591
|
+
]
|
|
592
|
+
);
|
|
593
|
+
const entitiesInfo = (0, import_element.useMemo)(() => {
|
|
594
|
+
return Object.keys(templatePrefixes || {}).reduce(
|
|
595
|
+
(accumulator, slug) => {
|
|
596
|
+
const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(
|
|
597
|
+
({ id }) => id
|
|
598
|
+
) || [];
|
|
599
|
+
accumulator[slug] = {
|
|
600
|
+
hasEntities: entitiesHasRecords[slug],
|
|
601
|
+
existingEntitiesIds
|
|
602
|
+
};
|
|
603
|
+
return accumulator;
|
|
604
|
+
},
|
|
605
|
+
{}
|
|
606
|
+
);
|
|
607
|
+
}, [templatePrefixes, recordsToExcludePerEntity, entitiesHasRecords]);
|
|
608
|
+
return entitiesInfo;
|
|
609
|
+
};
|
|
610
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
611
|
+
0 && (module.exports = {
|
|
612
|
+
mapToIHasNameAndId,
|
|
613
|
+
useAuthorMenuItem,
|
|
614
|
+
useDefaultTemplateTypes,
|
|
615
|
+
useExistingTemplates,
|
|
616
|
+
usePostTypeArchiveMenuItems,
|
|
617
|
+
usePostTypeMenuItems,
|
|
618
|
+
useTaxonomiesMenuItems
|
|
619
|
+
});
|
|
620
|
+
//# sourceMappingURL=utils.js.map
|