@wordpress/edit-site 4.10.0 → 4.12.1-next.d6164808d3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/add-new-template/add-custom-template-modal.js +26 -44
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build/components/add-new-template/new-template.js +45 -23
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +493 -242
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/index.js +1 -3
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +26 -12
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/global-styles/border-panel.js +3 -3
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +280 -20
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +4 -4
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +1 -1
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-colors.js +51 -7
- package/build/components/global-styles/screen-colors.js.map +1 -1
- package/build/components/global-styles/screen-heading-color.js +157 -0
- package/build/components/global-styles/screen-heading-color.js.map +1 -0
- 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 +5 -0
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +82 -14
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/typography-utils.js +217 -0
- package/build/components/global-styles/typography-utils.js.map +1 -0
- 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 +183 -52
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +85 -5
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/document-actions/index.js +1 -0
- package/build/components/header/document-actions/index.js.map +1 -1
- package/build/components/header/index.js +27 -12
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js +0 -4
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +13 -3
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/undo-redo/redo.js +2 -1
- package/build/components/header/undo-redo/redo.js.map +1 -1
- package/build/components/list/actions/index.js +1 -1
- package/build/components/list/actions/index.js.map +1 -1
- package/build/components/save-button/index.js +2 -3
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/sidebar/default-sidebar.js +11 -1
- package/build/components/sidebar/default-sidebar.js.map +1 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
- package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js +11 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/sidebar/template-card/template-actions.js +1 -1
- package/build/components/sidebar/template-card/template-actions.js.map +1 -1
- package/build/components/template-details/edit-template-title.js +1 -1
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +19 -9
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-details/template-areas.js +1 -1
- package/build/components/template-details/template-areas.js.map +1 -1
- package/build/components/template-details/template-part-area-selector.js +47 -0
- package/build/components/template-details/template-part-area-selector.js.map +1 -0
- package/build/components/template-part-converter/convert-to-template-part.js +4 -1
- package/build/components/template-part-converter/convert-to-template-part.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/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal.js +27 -45
- package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +45 -25
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +489 -230
- package/build-module/components/add-new-template/utils.js.map +1 -1
- 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/block-editor/resizable-editor.js +26 -12
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +3 -3
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +278 -22
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +4 -4
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +1 -1
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-colors.js +51 -7
- package/build-module/components/global-styles/screen-colors.js.map +1 -1
- package/build-module/components/global-styles/screen-heading-color.js +143 -0
- package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
- 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 +5 -0
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +83 -15
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/typography-utils.js +204 -0
- package/build-module/components/global-styles/typography-utils.js.map +1 -0
- 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 +182 -61
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +82 -5
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/document-actions/index.js +1 -0
- package/build-module/components/header/document-actions/index.js.map +1 -1
- package/build-module/components/header/index.js +30 -14
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js +0 -4
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +13 -3
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/undo-redo/redo.js +3 -2
- package/build-module/components/header/undo-redo/redo.js.map +1 -1
- package/build-module/components/list/actions/index.js +1 -1
- package/build-module/components/list/actions/index.js.map +1 -1
- package/build-module/components/save-button/index.js +3 -4
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/sidebar/default-sidebar.js +9 -1
- package/build-module/components/sidebar/default-sidebar.js.map +1 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js +1 -1
- package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
- package/build-module/components/template-details/edit-template-title.js +1 -1
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +19 -10
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-details/template-areas.js +1 -1
- package/build-module/components/template-details/template-areas.js.map +1 -1
- package/build-module/components/template-details/template-part-area-selector.js +35 -0
- package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
- package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
- package/build-module/components/template-part-converter/convert-to-template-part.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/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +40 -33
- package/build-style/style.css +40 -33
- package/package.json +29 -29
- package/src/components/add-new-template/add-custom-template-modal.js +39 -48
- package/src/components/add-new-template/new-template.js +50 -58
- package/src/components/add-new-template/style.scss +20 -8
- package/src/components/add-new-template/utils.js +529 -231
- package/src/components/block-editor/index.js +0 -2
- package/src/components/block-editor/resizable-editor.js +28 -18
- package/src/components/editor/style.scss +1 -0
- package/src/components/global-styles/border-panel.js +3 -3
- package/src/components/global-styles/dimensions-panel.js +344 -45
- package/src/components/global-styles/hooks.js +6 -3
- package/src/components/global-styles/screen-color-palette.js +1 -1
- package/src/components/global-styles/screen-colors.js +46 -4
- package/src/components/global-styles/screen-heading-color.js +201 -0
- package/src/components/global-styles/screen-typography-element.js +4 -0
- package/src/components/global-styles/screen-typography.js +6 -0
- package/src/components/global-styles/style.scss +14 -6
- package/src/components/global-styles/test/typography-utils.js +130 -0
- package/src/components/global-styles/test/use-global-styles-output.js +143 -4
- package/src/components/global-styles/test/utils.js +68 -8
- package/src/components/global-styles/typography-panel.js +119 -48
- package/src/components/global-styles/typography-utils.js +228 -0
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +203 -53
- package/src/components/global-styles/utils.js +70 -4
- package/src/components/header/document-actions/index.js +3 -0
- package/src/components/header/index.js +41 -14
- package/src/components/header/mode-switcher/index.js +0 -3
- package/src/components/header/more-menu/index.js +7 -2
- package/src/components/header/style.scss +5 -3
- package/src/components/header/undo-redo/redo.js +6 -2
- package/src/components/list/actions/index.js +3 -1
- package/src/components/save-button/index.js +10 -13
- package/src/components/sidebar/default-sidebar.js +12 -0
- package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
- package/src/components/sidebar/plugin-sidebar/index.js +12 -0
- package/src/components/sidebar/style.scss +4 -0
- package/src/components/sidebar/template-card/template-actions.js +3 -1
- package/src/components/template-details/edit-template-title.js +7 -3
- package/src/components/template-details/index.js +23 -8
- package/src/components/template-details/style.scss +0 -5
- package/src/components/template-details/template-areas.js +3 -1
- package/src/components/template-details/template-part-area-selector.js +38 -0
- package/src/components/template-part-converter/convert-to-template-part.js +3 -1
- package/src/hooks/index.js +1 -0
- package/src/hooks/template-part-edit.js +82 -0
- package/src/index.js +1 -1
- 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
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.mapToIHasNameAndId = void 0;
|
|
7
|
+
exports.useAuthorMenuItem = useAuthorMenuItem;
|
|
8
|
+
exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = exports.useExistingTemplates = exports.useDefaultTemplateTypes = void 0;
|
|
7
9
|
|
|
8
10
|
var _lodash = require("lodash");
|
|
9
11
|
|
|
@@ -55,76 +57,8 @@ const mapToIHasNameAndId = (entities, path) => {
|
|
|
55
57
|
* @property {number[]} existingEntitiesIds An array of the existing entities ids.
|
|
56
58
|
*/
|
|
57
59
|
|
|
58
|
-
/**
|
|
59
|
-
* @typedef {Object} EntityConfig
|
|
60
|
-
* @property {string} entityName The entity's name.
|
|
61
|
-
* @property {Function} getOrderBy Getter for an entity's `orderBy` query parameter, given the object
|
|
62
|
-
* {search} as argument.
|
|
63
|
-
* @property {Function} getIcon Getter function for returning an entity's icon for the menu item.
|
|
64
|
-
* @property {Function} getTitle Getter function for returning an entity's title for the menu item.
|
|
65
|
-
* @property {Function} getDescription Getter function for returning an entity's description for the menu item.
|
|
66
|
-
* @property {string} recordNamePath The path to an entity's properties to use as a `name`. If not provided
|
|
67
|
-
* is assumed that `name` property exists.
|
|
68
|
-
* @property {string} templatePrefix The template prefix to create new templates and check against existing
|
|
69
|
-
* templates. For example custom post types need a `single-` prefix to all
|
|
70
|
-
* templates(`single-post-hello`), whereas `pages` don't (`page-hello`).
|
|
71
|
-
* @property {string} templateSlug If this property is provided, it is going to be used for the creation of
|
|
72
|
-
* new templates and the check against existing templates in the place
|
|
73
|
-
* of the actual entity's `slug`. An example is `Tag` templates where the
|
|
74
|
-
* the Tag's taxonomy slug is `post_tag`, but template hierarchy is based
|
|
75
|
-
* on `tag` alias.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
60
|
|
|
79
61
|
exports.mapToIHasNameAndId = mapToIHasNameAndId;
|
|
80
|
-
const taxonomyBaseConfig = {
|
|
81
|
-
entityName: 'taxonomy',
|
|
82
|
-
getOrderBy: _ref => {
|
|
83
|
-
let {
|
|
84
|
-
search
|
|
85
|
-
} = _ref;
|
|
86
|
-
return search ? 'name' : 'count';
|
|
87
|
-
},
|
|
88
|
-
getIcon: () => _icons.blockMeta,
|
|
89
|
-
getTitle: labels => (0, _i18n.sprintf)( // translators: %s: Name of the taxonomy e.g: "Cagegory".
|
|
90
|
-
(0, _i18n.__)('Single taxonomy: %s'), labels.singular_name),
|
|
91
|
-
getDescription: labels => (0, _i18n.sprintf)( // translators: %s: Name of the taxonomy e.g: "Product Categories".
|
|
92
|
-
(0, _i18n.__)('Displays a single taxonomy: %s.'), labels.singular_name)
|
|
93
|
-
};
|
|
94
|
-
const postTypeBaseConfig = {
|
|
95
|
-
entityName: 'postType',
|
|
96
|
-
getOrderBy: _ref2 => {
|
|
97
|
-
let {
|
|
98
|
-
search
|
|
99
|
-
} = _ref2;
|
|
100
|
-
return search ? 'relevance' : 'modified';
|
|
101
|
-
},
|
|
102
|
-
recordNamePath: 'title.rendered',
|
|
103
|
-
// `icon` is the `menu_icon` property of a post type. We
|
|
104
|
-
// only handle `dashicons` for now, even if the `menu_icon`
|
|
105
|
-
// also supports urls and svg as values.
|
|
106
|
-
getIcon: _icon => _icon !== null && _icon !== void 0 && _icon.startsWith('dashicons-') ? _icon.slice(10) : _icons.post,
|
|
107
|
-
getTitle: labels => (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
108
|
-
(0, _i18n.__)('Single item: %s'), labels.singular_name),
|
|
109
|
-
getDescription: labels => (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
110
|
-
(0, _i18n.__)('Displays a single item: %s.'), labels.singular_name)
|
|
111
|
-
};
|
|
112
|
-
const entitiesConfig = {
|
|
113
|
-
postType: { ...postTypeBaseConfig,
|
|
114
|
-
templatePrefix: 'single-'
|
|
115
|
-
},
|
|
116
|
-
page: { ...postTypeBaseConfig
|
|
117
|
-
},
|
|
118
|
-
taxonomy: { ...taxonomyBaseConfig,
|
|
119
|
-
templatePrefix: 'taxonomy-'
|
|
120
|
-
},
|
|
121
|
-
category: { ...taxonomyBaseConfig
|
|
122
|
-
},
|
|
123
|
-
tag: { ...taxonomyBaseConfig,
|
|
124
|
-
templateSlug: 'tag'
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
exports.entitiesConfig = entitiesConfig;
|
|
128
62
|
|
|
129
63
|
const useExistingTemplates = () => {
|
|
130
64
|
return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template', {
|
|
@@ -146,246 +80,317 @@ const usePublicPostTypes = () => {
|
|
|
146
80
|
}), []);
|
|
147
81
|
return (0, _element.useMemo)(() => {
|
|
148
82
|
const excludedPostTypes = ['attachment'];
|
|
149
|
-
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(
|
|
83
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref => {
|
|
150
84
|
let {
|
|
151
85
|
viewable,
|
|
152
86
|
slug
|
|
153
|
-
} =
|
|
87
|
+
} = _ref;
|
|
154
88
|
return viewable && !excludedPostTypes.includes(slug);
|
|
155
89
|
});
|
|
156
90
|
}, [postTypes]);
|
|
157
|
-
}; // `page` post type is a special case in the template hierarchy,
|
|
158
|
-
// so we exclude it from the list of post types and we handle it
|
|
159
|
-
// separately.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const usePostTypes = () => {
|
|
163
|
-
const postTypes = usePublicPostTypes();
|
|
164
|
-
return (0, _element.useMemo)(() => {
|
|
165
|
-
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref4 => {
|
|
166
|
-
let {
|
|
167
|
-
slug
|
|
168
|
-
} = _ref4;
|
|
169
|
-
return slug !== 'page';
|
|
170
|
-
});
|
|
171
|
-
}, [postTypes]);
|
|
172
91
|
};
|
|
173
92
|
|
|
174
|
-
exports.usePostTypes = usePostTypes;
|
|
175
|
-
|
|
176
|
-
const usePostTypePage = () => {
|
|
177
|
-
const postTypes = usePublicPostTypes();
|
|
178
|
-
return (0, _element.useMemo)(() => {
|
|
179
|
-
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref5 => {
|
|
180
|
-
let {
|
|
181
|
-
slug
|
|
182
|
-
} = _ref5;
|
|
183
|
-
return slug === 'page';
|
|
184
|
-
});
|
|
185
|
-
}, [postTypes]);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
exports.usePostTypePage = usePostTypePage;
|
|
189
|
-
|
|
190
93
|
const usePublicTaxonomies = () => {
|
|
191
94
|
const taxonomies = (0, _data.useSelect)(select => select(_coreData.store).getTaxonomies({
|
|
192
95
|
per_page: -1
|
|
193
96
|
}), []);
|
|
194
97
|
return (0, _element.useMemo)(() => {
|
|
195
|
-
return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(
|
|
98
|
+
return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref2 => {
|
|
196
99
|
let {
|
|
197
100
|
visibility
|
|
198
|
-
} =
|
|
101
|
+
} = _ref2;
|
|
199
102
|
return visibility === null || visibility === void 0 ? void 0 : visibility.publicly_queryable;
|
|
200
103
|
});
|
|
201
104
|
}, [taxonomies]);
|
|
202
105
|
};
|
|
203
|
-
/**
|
|
204
|
-
* `category` and `post_tag` are handled specifically in template
|
|
205
|
-
* hierarchy so we need to differentiate them and return the rest,
|
|
206
|
-
* e.g. `category-$slug` and `taxonomy-$taxonomy-$term`.
|
|
207
|
-
*/
|
|
208
106
|
|
|
107
|
+
const usePostTypeMenuItems = onClickMenuItem => {
|
|
108
|
+
const publicPostTypes = usePublicPostTypes();
|
|
109
|
+
const existingTemplates = useExistingTemplates();
|
|
110
|
+
const defaultTemplateTypes = useDefaultTemplateTypes(); // `page`is a special case in template hierarchy.
|
|
209
111
|
|
|
210
|
-
const
|
|
211
|
-
const taxonomies = usePublicTaxonomies();
|
|
212
|
-
const specialTaxonomies = ['category', 'post_tag'];
|
|
213
|
-
return (0, _element.useMemo)(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref7 => {
|
|
112
|
+
const templatePrefixes = (0, _element.useMemo)(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
|
|
214
113
|
let {
|
|
215
114
|
slug
|
|
216
|
-
} =
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
115
|
+
} = _ref3;
|
|
116
|
+
let suffix = slug;
|
|
117
|
+
|
|
118
|
+
if (slug !== 'page') {
|
|
119
|
+
suffix = `single-${suffix}`;
|
|
120
|
+
}
|
|
220
121
|
|
|
221
|
-
|
|
122
|
+
accumulator[slug] = suffix;
|
|
123
|
+
return accumulator;
|
|
124
|
+
}, {}), [publicPostTypes]); // We need to keep track of naming conflicts. If a conflict
|
|
125
|
+
// occurs, we need to add slug.
|
|
222
126
|
|
|
223
|
-
const
|
|
224
|
-
const taxonomies = usePublicTaxonomies();
|
|
225
|
-
return (0, _element.useMemo)(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref8 => {
|
|
127
|
+
const postTypeLabels = publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref4) => {
|
|
226
128
|
let {
|
|
227
|
-
|
|
228
|
-
} =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
129
|
+
labels
|
|
130
|
+
} = _ref4;
|
|
131
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
132
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
133
|
+
return accumulator;
|
|
134
|
+
}, {});
|
|
232
135
|
|
|
233
|
-
|
|
136
|
+
const needsUniqueIdentifier = (labels, slug) => {
|
|
137
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
138
|
+
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
139
|
+
};
|
|
234
140
|
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
return (0, _element.useMemo)(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref9 => {
|
|
141
|
+
const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
|
|
142
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref5 => {
|
|
238
143
|
let {
|
|
239
144
|
slug
|
|
240
|
-
} =
|
|
241
|
-
return slug
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* Helper hook that returns information about an entity having
|
|
246
|
-
* records that we can create a specific template for.
|
|
247
|
-
*
|
|
248
|
-
* For example we can search for `terms` in `taxonomy` entity or
|
|
249
|
-
* `posts` in `postType` entity.
|
|
250
|
-
*
|
|
251
|
-
* First we need to find the existing records with an associated template,
|
|
252
|
-
* to query afterwards for any remaing record, by excluding them.
|
|
253
|
-
*
|
|
254
|
-
* @param {string[]} existingTemplates The existing templates.
|
|
255
|
-
* @param {Object[]} entities The array of entities we need to get extra information.
|
|
256
|
-
* @param {EntityConfig} entityConfig The entity config.
|
|
257
|
-
* @return {Record<string,EntitiesInfo>} An object with the `entities.slug` as `keys` and EntitiesInfo as values.
|
|
258
|
-
*/
|
|
145
|
+
} = _ref5;
|
|
146
|
+
return slug;
|
|
147
|
+
});
|
|
148
|
+
const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
|
|
149
|
+
var _postTypesInfo$slug;
|
|
259
150
|
|
|
151
|
+
const {
|
|
152
|
+
slug,
|
|
153
|
+
labels,
|
|
154
|
+
icon
|
|
155
|
+
} = postType; // We need to check if the general template is part of the
|
|
156
|
+
// defaultTemplateTypes. If it is, just use that info and
|
|
157
|
+
// augment it with the specific template functionality.
|
|
260
158
|
|
|
261
|
-
|
|
159
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
160
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref6 => {
|
|
161
|
+
let {
|
|
162
|
+
slug: _slug
|
|
163
|
+
} = _ref6;
|
|
164
|
+
return _slug === generalTemplateSlug;
|
|
165
|
+
});
|
|
166
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
262
167
|
|
|
263
|
-
const
|
|
264
|
-
let {
|
|
265
|
-
entityName,
|
|
266
|
-
templatePrefix,
|
|
267
|
-
templateSlug
|
|
268
|
-
} = _ref10;
|
|
269
|
-
const slugsToExcludePerEntity = (0, _element.useMemo)(() => {
|
|
270
|
-
return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, entity) => {
|
|
271
|
-
let _prefix = `${templateSlug || entity.slug}-`;
|
|
168
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(labels, slug);
|
|
272
169
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
170
|
+
let menuItemTitle = (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
171
|
+
(0, _i18n.__)('Single item: %s'), labels.singular_name);
|
|
276
172
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
173
|
+
if (_needsUniqueIdentifier) {
|
|
174
|
+
menuItemTitle = (0, _i18n.sprintf)( // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
|
|
175
|
+
(0, _i18n.__)('Single item: %1$s (%2$s)'), labels.singular_name, slug);
|
|
176
|
+
}
|
|
281
177
|
|
|
282
|
-
|
|
283
|
-
|
|
178
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType,
|
|
179
|
+
templatePrefix: templatePrefixes[slug]
|
|
180
|
+
} : {
|
|
181
|
+
slug: generalTemplateSlug,
|
|
182
|
+
title: menuItemTitle,
|
|
183
|
+
description: (0, _i18n.sprintf)( // translators: %s: Name of the post type e.g: "Post".
|
|
184
|
+
(0, _i18n.__)('Displays a single item: %s.'), labels.singular_name),
|
|
185
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
186
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
187
|
+
// also supports urls and svg as values.
|
|
188
|
+
icon: icon !== null && icon !== void 0 && icon.startsWith('dashicons-') ? icon.slice(10) : _icons.post,
|
|
189
|
+
templatePrefix: templatePrefixes[slug]
|
|
190
|
+
};
|
|
191
|
+
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.
|
|
284
192
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
193
|
+
if (hasEntities) {
|
|
194
|
+
menuItem.onClick = template => {
|
|
195
|
+
onClickMenuItem({
|
|
196
|
+
type: 'postType',
|
|
197
|
+
slug,
|
|
198
|
+
config: {
|
|
199
|
+
recordNamePath: 'title.rendered',
|
|
200
|
+
queryArgs: _ref7 => {
|
|
201
|
+
let {
|
|
202
|
+
search
|
|
203
|
+
} = _ref7;
|
|
204
|
+
return {
|
|
205
|
+
_fields: 'id,title,slug,link',
|
|
206
|
+
orderBy: search ? 'relevance' : 'modified',
|
|
207
|
+
exclude: postTypesInfo[slug].existingEntitiesIds
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
getSpecificTemplate: suggestion => {
|
|
211
|
+
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".
|
|
212
|
+
(0, _i18n.__)('%1$s: %2$s'), labels.singular_name, suggestion.name);
|
|
213
|
+
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"
|
|
214
|
+
(0, _i18n.__)('Template for %1$s'), title);
|
|
215
|
+
|
|
216
|
+
if (_needsUniqueIdentifier) {
|
|
217
|
+
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)"
|
|
218
|
+
(0, _i18n.__)('%1$s (%2$s)'), title, slug);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
title,
|
|
223
|
+
description,
|
|
224
|
+
slug: `${templatePrefixes[slug]}-${suggestion.slug}`,
|
|
225
|
+
templatePrefix: templatePrefixes[slug]
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
labels,
|
|
230
|
+
hasGeneralTemplate,
|
|
231
|
+
template
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
} // We don't need to add the menu item if there are no
|
|
235
|
+
// entities and the general template exists.
|
|
288
236
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
|
|
293
|
-
if (!slugsToExcludePerEntity) {
|
|
294
|
-
return;
|
|
237
|
+
|
|
238
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
239
|
+
accumulator.push(menuItem);
|
|
295
240
|
}
|
|
296
241
|
|
|
297
|
-
return
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
_fields: 'id',
|
|
301
|
-
context: 'view',
|
|
302
|
-
slug: slugsWithTemplates
|
|
303
|
-
});
|
|
242
|
+
return accumulator;
|
|
243
|
+
}, []); // Split menu items into two groups: one for the default post types
|
|
244
|
+
// and one for the rest.
|
|
304
245
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
246
|
+
const postTypesMenuItems = (0, _element.useMemo)(() => menuItems.reduce((accumulator, postType) => {
|
|
247
|
+
const {
|
|
248
|
+
slug
|
|
249
|
+
} = postType;
|
|
250
|
+
let key = 'postTypesMenuItems';
|
|
308
251
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const entitiesInfo = (0, _data.useSelect)(select => {
|
|
313
|
-
return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, _ref12) => {
|
|
314
|
-
var _recordsToExcludePerE, _select$getEntityReco;
|
|
252
|
+
if (slug === 'page') {
|
|
253
|
+
key = 'defaultPostTypesMenuItems';
|
|
254
|
+
}
|
|
315
255
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
return id;
|
|
324
|
-
})) || [];
|
|
325
|
-
accumulator[slug] = {
|
|
326
|
-
hasEntities: !!((_select$getEntityReco = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
327
|
-
per_page: 1,
|
|
328
|
-
_fields: 'id',
|
|
329
|
-
context: 'view',
|
|
330
|
-
exclude: existingEntitiesIds
|
|
331
|
-
})) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
|
|
332
|
-
existingEntitiesIds
|
|
333
|
-
};
|
|
334
|
-
return accumulator;
|
|
335
|
-
}, {});
|
|
336
|
-
}, [entities, recordsToExcludePerEntity]);
|
|
337
|
-
return entitiesInfo;
|
|
256
|
+
accumulator[key].push(postType);
|
|
257
|
+
return accumulator;
|
|
258
|
+
}, {
|
|
259
|
+
defaultPostTypesMenuItems: [],
|
|
260
|
+
postTypesMenuItems: []
|
|
261
|
+
}), [menuItems]);
|
|
262
|
+
return postTypesMenuItems;
|
|
338
263
|
};
|
|
339
264
|
|
|
340
|
-
|
|
265
|
+
exports.usePostTypeMenuItems = usePostTypeMenuItems;
|
|
266
|
+
|
|
267
|
+
const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
268
|
+
const publicTaxonomies = usePublicTaxonomies();
|
|
341
269
|
const existingTemplates = useExistingTemplates();
|
|
342
|
-
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
343
|
-
|
|
344
|
-
const
|
|
270
|
+
const defaultTemplateTypes = useDefaultTemplateTypes(); // `category` and `post_tag` are special cases in template hierarchy.
|
|
271
|
+
|
|
272
|
+
const templatePrefixes = (0, _element.useMemo)(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref8) => {
|
|
345
273
|
let {
|
|
346
274
|
slug
|
|
347
|
-
} =
|
|
275
|
+
} = _ref8;
|
|
276
|
+
let suffix = slug;
|
|
277
|
+
|
|
278
|
+
if (!['category', 'post_tag'].includes(slug)) {
|
|
279
|
+
suffix = `taxonomy-${suffix}`;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (slug === 'post_tag') {
|
|
283
|
+
suffix = `tag`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
accumulator[slug] = suffix;
|
|
287
|
+
return accumulator;
|
|
288
|
+
}, {}), [publicTaxonomies]); // We need to keep track of naming conflicts. If a conflict
|
|
289
|
+
// occurs, we need to add slug.
|
|
290
|
+
|
|
291
|
+
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
|
|
292
|
+
let {
|
|
293
|
+
labels
|
|
294
|
+
} = _ref9;
|
|
295
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
296
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
297
|
+
return accumulator;
|
|
298
|
+
}, {});
|
|
299
|
+
|
|
300
|
+
const needsUniqueIdentifier = (labels, slug) => {
|
|
301
|
+
if (['category', 'post_tag'].includes(slug)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
306
|
+
return taxonomyLabels[singularName] > 1 && singularName !== slug;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const taxonomiesInfo = useEntitiesInfo('taxonomy', templatePrefixes);
|
|
310
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref10 => {
|
|
311
|
+
let {
|
|
312
|
+
slug
|
|
313
|
+
} = _ref10;
|
|
348
314
|
return slug;
|
|
349
315
|
});
|
|
350
|
-
const
|
|
351
|
-
var
|
|
316
|
+
const menuItems = (publicTaxonomies || []).reduce((accumulator, taxonomy) => {
|
|
317
|
+
var _taxonomiesInfo$slug;
|
|
352
318
|
|
|
353
319
|
const {
|
|
354
320
|
slug,
|
|
355
|
-
labels
|
|
356
|
-
|
|
357
|
-
} = entity;
|
|
358
|
-
const slugForGeneralTemplate = entityConfig.templateSlug || slug; // We need to check if the general template is part of the
|
|
321
|
+
labels
|
|
322
|
+
} = taxonomy; // We need to check if the general template is part of the
|
|
359
323
|
// defaultTemplateTypes. If it is, just use that info and
|
|
360
324
|
// augment it with the specific template functionality.
|
|
361
325
|
|
|
362
|
-
const
|
|
326
|
+
const generalTemplateSlug = templatePrefixes[slug];
|
|
327
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref11 => {
|
|
363
328
|
let {
|
|
364
329
|
slug: _slug
|
|
365
|
-
} =
|
|
366
|
-
return _slug ===
|
|
330
|
+
} = _ref11;
|
|
331
|
+
return _slug === generalTemplateSlug;
|
|
367
332
|
});
|
|
368
|
-
const generalTemplateSlug = (defaultTemplateType === null || defaultTemplateType === void 0 ? void 0 : defaultTemplateType.slug) || `${entityConfig.templatePrefix}${slug}`;
|
|
369
333
|
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
370
|
-
|
|
334
|
+
|
|
335
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(labels, slug);
|
|
336
|
+
|
|
337
|
+
let menuItemTitle = labels.singular_name;
|
|
338
|
+
|
|
339
|
+
if (_needsUniqueIdentifier) {
|
|
340
|
+
menuItemTitle = (0, _i18n.sprintf)( // translators: %1s: Name of the taxonomy e.g: "Category"; %2s: Slug of the taxonomy e.g: "product_cat".
|
|
341
|
+
(0, _i18n.__)('%1$s (%2$s)'), labels.singular_name, slug);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType,
|
|
345
|
+
templatePrefix: templatePrefixes[slug]
|
|
371
346
|
} : {
|
|
372
347
|
slug: generalTemplateSlug,
|
|
373
|
-
title:
|
|
374
|
-
description:
|
|
375
|
-
|
|
348
|
+
title: menuItemTitle,
|
|
349
|
+
description: (0, _i18n.sprintf)( // translators: %s: Name of the taxonomy e.g: "Product Categories".
|
|
350
|
+
(0, _i18n.__)('Displays taxonomy: %s.'), labels.singular_name),
|
|
351
|
+
icon: _icons.blockMeta,
|
|
352
|
+
templatePrefix: templatePrefixes[slug]
|
|
376
353
|
};
|
|
377
|
-
const hasEntities =
|
|
354
|
+
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.
|
|
378
355
|
|
|
379
356
|
if (hasEntities) {
|
|
380
357
|
menuItem.onClick = template => {
|
|
381
358
|
onClickMenuItem({
|
|
382
|
-
type:
|
|
359
|
+
type: 'taxonomy',
|
|
383
360
|
slug,
|
|
384
|
-
config:
|
|
361
|
+
config: {
|
|
362
|
+
queryArgs: _ref12 => {
|
|
363
|
+
let {
|
|
364
|
+
search
|
|
365
|
+
} = _ref12;
|
|
366
|
+
return {
|
|
367
|
+
_fields: 'id,name,slug,link',
|
|
368
|
+
orderBy: search ? 'name' : 'count',
|
|
369
|
+
exclude: taxonomiesInfo[slug].existingEntitiesIds
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
getSpecificTemplate: suggestion => {
|
|
373
|
+
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".
|
|
374
|
+
(0, _i18n.__)('%1$s: %2$s'), labels.singular_name, suggestion.name);
|
|
375
|
+
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"
|
|
376
|
+
(0, _i18n.__)('Template for %1$s'), title);
|
|
377
|
+
|
|
378
|
+
if (_needsUniqueIdentifier) {
|
|
379
|
+
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)"
|
|
380
|
+
(0, _i18n.__)('%1$s (%2$s)'), title, slug);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
title,
|
|
385
|
+
description,
|
|
386
|
+
slug: `${templatePrefixes[slug]}-${suggestion.slug}`,
|
|
387
|
+
templatePrefix: templatePrefixes[slug]
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
},
|
|
385
391
|
labels,
|
|
386
392
|
hasGeneralTemplate,
|
|
387
|
-
template
|
|
388
|
-
postsToExclude: entitiesInfo[slug].existingEntitiesIds
|
|
393
|
+
template
|
|
389
394
|
});
|
|
390
395
|
};
|
|
391
396
|
} // We don't need to add the menu item if there are no
|
|
@@ -397,9 +402,255 @@ const useExtraTemplates = (entities, entityConfig, onClickMenuItem) => {
|
|
|
397
402
|
}
|
|
398
403
|
|
|
399
404
|
return accumulator;
|
|
400
|
-
}, []);
|
|
401
|
-
|
|
405
|
+
}, []); // Split menu items into two groups: one for the default taxonomies
|
|
406
|
+
// and one for the rest.
|
|
407
|
+
|
|
408
|
+
const taxonomiesMenuItems = (0, _element.useMemo)(() => menuItems.reduce((accumulator, taxonomy) => {
|
|
409
|
+
const {
|
|
410
|
+
slug
|
|
411
|
+
} = taxonomy;
|
|
412
|
+
let key = 'taxonomiesMenuItems';
|
|
413
|
+
|
|
414
|
+
if (['category', 'tag'].includes(slug)) {
|
|
415
|
+
key = 'defaultTaxonomiesMenuItems';
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
accumulator[key].push(taxonomy);
|
|
419
|
+
return accumulator;
|
|
420
|
+
}, {
|
|
421
|
+
defaultTaxonomiesMenuItems: [],
|
|
422
|
+
taxonomiesMenuItems: []
|
|
423
|
+
}), [menuItems]);
|
|
424
|
+
return taxonomiesMenuItems;
|
|
402
425
|
};
|
|
403
426
|
|
|
404
|
-
exports.
|
|
427
|
+
exports.useTaxonomiesMenuItems = useTaxonomiesMenuItems;
|
|
428
|
+
|
|
429
|
+
function useAuthorNeedsUniqueIndentifier() {
|
|
430
|
+
const authors = (0, _data.useSelect)(select => select(_coreData.store).getUsers({
|
|
431
|
+
who: 'authors',
|
|
432
|
+
per_page: -1
|
|
433
|
+
}), []);
|
|
434
|
+
const authorsCountByName = (0, _element.useMemo)(() => {
|
|
435
|
+
return (authors || []).reduce((authorsCount, _ref13) => {
|
|
436
|
+
let {
|
|
437
|
+
name
|
|
438
|
+
} = _ref13;
|
|
439
|
+
authorsCount[name] = (authorsCount[name] || 0) + 1;
|
|
440
|
+
return authorsCount;
|
|
441
|
+
}, {});
|
|
442
|
+
}, [authors]);
|
|
443
|
+
return (0, _element.useCallback)(name => {
|
|
444
|
+
return authorsCountByName[name] > 1;
|
|
445
|
+
}, [authorsCountByName]);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = {
|
|
449
|
+
user: 'author'
|
|
450
|
+
};
|
|
451
|
+
const USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = {
|
|
452
|
+
user: {
|
|
453
|
+
who: 'authors'
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
function useAuthorMenuItem(onClickMenuItem) {
|
|
458
|
+
var _authorInfo$user, _authorInfo$user2;
|
|
459
|
+
|
|
460
|
+
const existingTemplates = useExistingTemplates();
|
|
461
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
462
|
+
const authorInfo = useEntitiesInfo('root', USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX, USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS);
|
|
463
|
+
const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
|
|
464
|
+
let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref14 => {
|
|
465
|
+
let {
|
|
466
|
+
slug
|
|
467
|
+
} = _ref14;
|
|
468
|
+
return slug === 'author';
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
if (!authorMenuItem) {
|
|
472
|
+
authorMenuItem = {
|
|
473
|
+
description: (0, _i18n.__)('Displays latest posts written by a single author.'),
|
|
474
|
+
slug: 'author',
|
|
475
|
+
title: 'Author'
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref15 => {
|
|
480
|
+
let {
|
|
481
|
+
slug
|
|
482
|
+
} = _ref15;
|
|
483
|
+
return slug === 'author';
|
|
484
|
+
}));
|
|
485
|
+
|
|
486
|
+
if ((_authorInfo$user = authorInfo.user) !== null && _authorInfo$user !== void 0 && _authorInfo$user.hasEntities) {
|
|
487
|
+
authorMenuItem = { ...authorMenuItem,
|
|
488
|
+
templatePrefix: 'author'
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
authorMenuItem.onClick = template => {
|
|
492
|
+
onClickMenuItem({
|
|
493
|
+
type: 'root',
|
|
494
|
+
slug: 'user',
|
|
495
|
+
config: {
|
|
496
|
+
queryArgs: _ref16 => {
|
|
497
|
+
let {
|
|
498
|
+
search
|
|
499
|
+
} = _ref16;
|
|
500
|
+
return {
|
|
501
|
+
_fields: 'id,name,slug,link',
|
|
502
|
+
orderBy: search ? 'name' : 'registered_date',
|
|
503
|
+
exclude: authorInfo.user.existingEntitiesIds,
|
|
504
|
+
who: 'authors'
|
|
505
|
+
};
|
|
506
|
+
},
|
|
507
|
+
getSpecificTemplate: suggestion => {
|
|
508
|
+
const needsUniqueId = authorNeedsUniqueId(suggestion.name);
|
|
509
|
+
const title = needsUniqueId ? (0, _i18n.sprintf)( // translators: %1$s: Represents the name of an author e.g: "Jorge", %2$s: Represents the slug of an author e.g: "author-jorge-slug".
|
|
510
|
+
(0, _i18n.__)('Author: %1$s (%2$s)'), suggestion.name, suggestion.slug) : (0, _i18n.sprintf)( // translators: %s: Represents the name of an author e.g: "Jorge".
|
|
511
|
+
(0, _i18n.__)('Author: %s'), suggestion.name);
|
|
512
|
+
const description = (0, _i18n.sprintf)( // translators: %s: Represents the name of an author e.g: "Jorge".
|
|
513
|
+
(0, _i18n.__)('Template for Author: %s'), suggestion.name);
|
|
514
|
+
return {
|
|
515
|
+
title,
|
|
516
|
+
description,
|
|
517
|
+
slug: `author-${suggestion.slug}`,
|
|
518
|
+
templatePrefix: 'author'
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
labels: {
|
|
523
|
+
singular_name: (0, _i18n.__)('Author'),
|
|
524
|
+
search_items: (0, _i18n.__)('Search Authors'),
|
|
525
|
+
not_found: (0, _i18n.__)('No authors found.'),
|
|
526
|
+
all_items: (0, _i18n.__)('All Authors')
|
|
527
|
+
},
|
|
528
|
+
hasGeneralTemplate,
|
|
529
|
+
template
|
|
530
|
+
});
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (!hasGeneralTemplate || (_authorInfo$user2 = authorInfo.user) !== null && _authorInfo$user2 !== void 0 && _authorInfo$user2.hasEntities) {
|
|
535
|
+
return authorMenuItem;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Helper hook that filters all the existing templates by the given
|
|
540
|
+
* object with the entity's slug as key and the template prefix as value.
|
|
541
|
+
*
|
|
542
|
+
* Example:
|
|
543
|
+
* `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
|
|
544
|
+
* `templatePrefixes` is: { post_tag: 'tag' }
|
|
545
|
+
* It will return: { post_tag: ['apple'] }
|
|
546
|
+
*
|
|
547
|
+
* Note: We append the `-` to the given template prefix in this function for our checks.
|
|
548
|
+
*
|
|
549
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
550
|
+
* @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
|
|
551
|
+
*/
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
const useExistingTemplateSlugs = templatePrefixes => {
|
|
555
|
+
const existingTemplates = useExistingTemplates();
|
|
556
|
+
const existingSlugs = (0, _element.useMemo)(() => {
|
|
557
|
+
return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref17) => {
|
|
558
|
+
let [slug, prefix] = _ref17;
|
|
559
|
+
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
560
|
+
const _prefix = `${prefix}-`;
|
|
561
|
+
|
|
562
|
+
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
563
|
+
_accumulator.push(existingTemplate.slug.substring(_prefix.length));
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
return _accumulator;
|
|
567
|
+
}, []);
|
|
568
|
+
|
|
569
|
+
if (slugsWithTemplates.length) {
|
|
570
|
+
accumulator[slug] = slugsWithTemplates;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
return accumulator;
|
|
574
|
+
}, {});
|
|
575
|
+
}, [templatePrefixes, existingTemplates]);
|
|
576
|
+
return existingSlugs;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Helper hook that finds the existing records with an associated template,
|
|
580
|
+
* as they need to be excluded from the template suggestions.
|
|
581
|
+
*
|
|
582
|
+
* @param {string} entityName The entity's name.
|
|
583
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
584
|
+
* @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
|
|
585
|
+
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
|
|
586
|
+
*/
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
const useTemplatesToExclude = function (entityName, templatePrefixes) {
|
|
590
|
+
let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
591
|
+
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
592
|
+
const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
|
|
593
|
+
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref18) => {
|
|
594
|
+
let [slug, slugsWithTemplates] = _ref18;
|
|
595
|
+
const entitiesWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
596
|
+
_fields: 'id',
|
|
597
|
+
context: 'view',
|
|
598
|
+
slug: slugsWithTemplates,
|
|
599
|
+
...additionalQueryParameters[slug]
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
if (entitiesWithTemplates !== null && entitiesWithTemplates !== void 0 && entitiesWithTemplates.length) {
|
|
603
|
+
accumulator[slug] = entitiesWithTemplates;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return accumulator;
|
|
607
|
+
}, {});
|
|
608
|
+
}, [slugsToExcludePerEntity]);
|
|
609
|
+
return recordsToExcludePerEntity;
|
|
610
|
+
};
|
|
611
|
+
/**
|
|
612
|
+
* Helper hook that returns information about an entity having
|
|
613
|
+
* records that we can create a specific template for.
|
|
614
|
+
*
|
|
615
|
+
* For example we can search for `terms` in `taxonomy` entity or
|
|
616
|
+
* `posts` in `postType` entity.
|
|
617
|
+
*
|
|
618
|
+
* First we need to find the existing records with an associated template,
|
|
619
|
+
* to query afterwards for any remaining record, by excluding them.
|
|
620
|
+
*
|
|
621
|
+
* @param {string} entityName The entity's name.
|
|
622
|
+
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
623
|
+
* @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
|
|
624
|
+
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.
|
|
625
|
+
*/
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
const useEntitiesInfo = function (entityName, templatePrefixes) {
|
|
629
|
+
let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
630
|
+
const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes, additionalQueryParameters);
|
|
631
|
+
const entitiesInfo = (0, _data.useSelect)(select => {
|
|
632
|
+
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
633
|
+
var _recordsToExcludePerE, _select$getEntityReco;
|
|
634
|
+
|
|
635
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref19 => {
|
|
636
|
+
let {
|
|
637
|
+
id
|
|
638
|
+
} = _ref19;
|
|
639
|
+
return id;
|
|
640
|
+
})) || [];
|
|
641
|
+
accumulator[slug] = {
|
|
642
|
+
hasEntities: !!((_select$getEntityReco = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
643
|
+
per_page: 1,
|
|
644
|
+
_fields: 'id',
|
|
645
|
+
context: 'view',
|
|
646
|
+
exclude: existingEntitiesIds,
|
|
647
|
+
...additionalQueryParameters[slug]
|
|
648
|
+
})) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
|
|
649
|
+
existingEntitiesIds
|
|
650
|
+
};
|
|
651
|
+
return accumulator;
|
|
652
|
+
}, {});
|
|
653
|
+
}, [templatePrefixes, recordsToExcludePerEntity]);
|
|
654
|
+
return entitiesInfo;
|
|
655
|
+
};
|
|
405
656
|
//# sourceMappingURL=utils.js.map
|