@wordpress/edit-site 4.7.0 → 4.10.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 +224 -0
- package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
- package/build/components/add-new-template/new-template.js +94 -33
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +405 -0
- package/build/components/add-new-template/utils.js.map +1 -0
- package/build/components/block-editor/block-inspector-button.js.map +1 -1
- 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/edit-template-part-menu-button/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 +2 -6
- 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/gradients-palette-panel.js +3 -7
- package/build/components/global-styles/gradients-palette-panel.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-style-variations.js +9 -1
- package/build/components/global-styles/screen-style-variations.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 +199 -30
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +4 -2
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +28 -10
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/copy-content-menu-item.js +1 -1
- package/build/components/header/more-menu/copy-content-menu-item.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/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/list/actions/index.js.map +1 -1
- package/build/components/list/actions/rename-menu-item.js.map +1 -1
- package/build/components/list/added-by.js.map +1 -1
- package/build/components/navigation-sidebar/index.js.map +1 -1
- package/build/components/save-button/index.js.map +1 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/navigation-menu-sidebar/navigation-inspector.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/sidebar/template-card/template-areas.js.map +1 -1
- 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/components/template-details/template-areas.js.map +1 -1
- package/build/components/template-part-converter/index.js.map +1 -1
- package/build/components/url-query-controller/index.js.map +1 -1
- package/build/store/actions.js.map +1 -1
- 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 +209 -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 +93 -34
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +365 -0
- package/build-module/components/add-new-template/utils.js.map +1 -0
- package/build-module/components/block-editor/block-inspector-button.js.map +1 -1
- 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/edit-template-part-menu-button/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 +2 -6
- 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/gradients-palette-panel.js +3 -5
- package/build-module/components/global-styles/gradients-palette-panel.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-style-variations.js +9 -1
- package/build-module/components/global-styles/screen-style-variations.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 +198 -32
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +5 -3
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +29 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/copy-content-menu-item.js +1 -1
- package/build-module/components/header/more-menu/copy-content-menu-item.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/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/list/actions/index.js.map +1 -1
- package/build-module/components/list/actions/rename-menu-item.js.map +1 -1
- package/build-module/components/list/added-by.js.map +1 -1
- package/build-module/components/navigation-sidebar/index.js.map +1 -1
- package/build-module/components/save-button/index.js.map +1 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/navigation-menu-sidebar/navigation-inspector.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/sidebar/template-card/template-areas.js.map +1 -1
- 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/components/template-details/template-areas.js.map +1 -1
- package/build-module/components/template-part-converter/index.js.map +1 -1
- package/build-module/components/url-query-controller/index.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +5 -2
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +188 -42
- package/build-style/style.css +188 -42
- 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 +265 -0
- package/src/components/add-new-template/new-template.js +194 -70
- package/src/components/add-new-template/style.scss +137 -0
- package/src/components/add-new-template/utils.js +369 -0
- package/src/components/block-editor/block-inspector-button.js +2 -3
- package/src/components/block-editor/index.js +4 -9
- package/src/components/code-editor/index.js +15 -5
- package/src/components/edit-template-part-menu-button/index.js +2 -3
- package/src/components/editor/index.js +15 -5
- 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 +2 -7
- package/src/components/global-styles/global-styles-provider.js +12 -17
- package/src/components/global-styles/gradients-palette-panel.js +2 -5
- package/src/components/global-styles/hooks.js +20 -3
- package/src/components/global-styles/palette.js +4 -1
- package/src/components/global-styles/screen-block-list.js +14 -5
- 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 +12 -5
- package/src/components/global-styles/screen-style-variations.js +10 -4
- 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 +250 -16
- package/src/components/global-styles/ui.js +13 -0
- package/src/components/global-styles/use-global-styles-output.js +246 -32
- package/src/components/global-styles/utils.js +5 -2
- package/src/components/header/index.js +38 -13
- package/src/components/header/mode-switcher/index.js +4 -4
- package/src/components/header/more-menu/copy-content-menu-item.js +3 -4
- package/src/components/header/more-menu/site-export.js +5 -3
- package/src/components/header/style.scss +53 -5
- 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/keyboard-shortcuts/index.js +6 -10
- package/src/components/list/actions/index.js +2 -3
- package/src/components/list/actions/rename-menu-item.js +4 -6
- package/src/components/list/added-by.js +4 -3
- package/src/components/list/style.scss +0 -8
- package/src/components/navigation-sidebar/index.js +2 -4
- package/src/components/save-button/index.js +2 -4
- package/src/components/sidebar/index.js +6 -6
- package/src/components/sidebar/navigation-menu-sidebar/navigation-inspector.js +6 -9
- package/src/components/sidebar/template-card/index.js +17 -9
- package/src/components/sidebar/template-card/style.scss +49 -35
- package/src/components/sidebar/template-card/template-actions.js +43 -0
- package/src/components/sidebar/template-card/template-areas.js +6 -6
- package/src/components/template-details/edit-template-title.js +10 -2
- package/src/components/template-details/index.js +4 -21
- package/src/components/template-details/template-areas.js +6 -6
- package/src/components/template-part-converter/index.js +2 -3
- package/src/components/test/error-boundary.js +38 -0
- package/src/components/url-query-controller/index.js +2 -3
- package/src/store/actions.js +257 -233
- package/src/store/selectors.js +19 -14
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useTaxonomyTag = exports.useTaxonomyCategory = exports.useTaxonomies = exports.usePostTypes = exports.usePostTypePage = exports.useExtraTemplates = exports.useExistingTemplates = exports.useDefaultTemplateTypes = exports.mapToIHasNameAndId = exports.entitiesConfig = 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
|
+
* @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
|
+
|
|
79
|
+
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
|
+
|
|
129
|
+
const useExistingTemplates = () => {
|
|
130
|
+
return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template', {
|
|
131
|
+
per_page: -1
|
|
132
|
+
}), []);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
exports.useExistingTemplates = useExistingTemplates;
|
|
136
|
+
|
|
137
|
+
const useDefaultTemplateTypes = () => {
|
|
138
|
+
return (0, _data.useSelect)(select => select(_editor.store).__experimentalGetDefaultTemplateTypes(), []);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
exports.useDefaultTemplateTypes = useDefaultTemplateTypes;
|
|
142
|
+
|
|
143
|
+
const usePublicPostTypes = () => {
|
|
144
|
+
const postTypes = (0, _data.useSelect)(select => select(_coreData.store).getPostTypes({
|
|
145
|
+
per_page: -1
|
|
146
|
+
}), []);
|
|
147
|
+
return (0, _element.useMemo)(() => {
|
|
148
|
+
const excludedPostTypes = ['attachment'];
|
|
149
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref3 => {
|
|
150
|
+
let {
|
|
151
|
+
viewable,
|
|
152
|
+
slug
|
|
153
|
+
} = _ref3;
|
|
154
|
+
return viewable && !excludedPostTypes.includes(slug);
|
|
155
|
+
});
|
|
156
|
+
}, [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
|
+
};
|
|
173
|
+
|
|
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
|
+
const usePublicTaxonomies = () => {
|
|
191
|
+
const taxonomies = (0, _data.useSelect)(select => select(_coreData.store).getTaxonomies({
|
|
192
|
+
per_page: -1
|
|
193
|
+
}), []);
|
|
194
|
+
return (0, _element.useMemo)(() => {
|
|
195
|
+
return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref6 => {
|
|
196
|
+
let {
|
|
197
|
+
visibility
|
|
198
|
+
} = _ref6;
|
|
199
|
+
return visibility === null || visibility === void 0 ? void 0 : visibility.publicly_queryable;
|
|
200
|
+
});
|
|
201
|
+
}, [taxonomies]);
|
|
202
|
+
};
|
|
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
|
+
|
|
209
|
+
|
|
210
|
+
const useTaxonomies = () => {
|
|
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 => {
|
|
214
|
+
let {
|
|
215
|
+
slug
|
|
216
|
+
} = _ref7;
|
|
217
|
+
return !specialTaxonomies.includes(slug);
|
|
218
|
+
}), [taxonomies]);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
exports.useTaxonomies = useTaxonomies;
|
|
222
|
+
|
|
223
|
+
const useTaxonomyCategory = () => {
|
|
224
|
+
const taxonomies = usePublicTaxonomies();
|
|
225
|
+
return (0, _element.useMemo)(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref8 => {
|
|
226
|
+
let {
|
|
227
|
+
slug
|
|
228
|
+
} = _ref8;
|
|
229
|
+
return slug === 'category';
|
|
230
|
+
}), [taxonomies]);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
exports.useTaxonomyCategory = useTaxonomyCategory;
|
|
234
|
+
|
|
235
|
+
const useTaxonomyTag = () => {
|
|
236
|
+
const taxonomies = usePublicTaxonomies();
|
|
237
|
+
return (0, _element.useMemo)(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref9 => {
|
|
238
|
+
let {
|
|
239
|
+
slug
|
|
240
|
+
} = _ref9;
|
|
241
|
+
return slug === 'post_tag';
|
|
242
|
+
}), [taxonomies]);
|
|
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
|
+
*/
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
exports.useTaxonomyTag = useTaxonomyTag;
|
|
262
|
+
|
|
263
|
+
const useEntitiesInfo = (existingTemplates, entities, _ref10) => {
|
|
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}-`;
|
|
272
|
+
|
|
273
|
+
if (templatePrefix) {
|
|
274
|
+
_prefix = templatePrefix + _prefix;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
278
|
+
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
279
|
+
_accumulator.push(existingTemplate.slug.substring(_prefix.length));
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return _accumulator;
|
|
283
|
+
}, []);
|
|
284
|
+
|
|
285
|
+
if (slugsWithTemplates.length) {
|
|
286
|
+
accumulator[entity.slug] = slugsWithTemplates;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return accumulator;
|
|
290
|
+
}, {});
|
|
291
|
+
}, [entities, existingTemplates]);
|
|
292
|
+
const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
|
|
293
|
+
if (!slugsToExcludePerEntity) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return Object.entries(slugsToExcludePerEntity).reduce((accumulator, _ref11) => {
|
|
298
|
+
let [slug, slugsWithTemplates] = _ref11;
|
|
299
|
+
const postsWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
300
|
+
_fields: 'id',
|
|
301
|
+
context: 'view',
|
|
302
|
+
slug: slugsWithTemplates
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
if (postsWithTemplates !== null && postsWithTemplates !== void 0 && postsWithTemplates.length) {
|
|
306
|
+
accumulator[slug] = postsWithTemplates;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return accumulator;
|
|
310
|
+
}, {});
|
|
311
|
+
}, [slugsToExcludePerEntity]);
|
|
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;
|
|
315
|
+
|
|
316
|
+
let {
|
|
317
|
+
slug
|
|
318
|
+
} = _ref12;
|
|
319
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref13 => {
|
|
320
|
+
let {
|
|
321
|
+
id
|
|
322
|
+
} = _ref13;
|
|
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;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const useExtraTemplates = (entities, entityConfig, onClickMenuItem) => {
|
|
341
|
+
const existingTemplates = useExistingTemplates();
|
|
342
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
343
|
+
const entitiesInfo = useEntitiesInfo(existingTemplates, entities, entityConfig);
|
|
344
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref14 => {
|
|
345
|
+
let {
|
|
346
|
+
slug
|
|
347
|
+
} = _ref14;
|
|
348
|
+
return slug;
|
|
349
|
+
});
|
|
350
|
+
const extraTemplates = (entities || []).reduce((accumulator, entity) => {
|
|
351
|
+
var _entityConfig$getIcon, _entitiesInfo$slug;
|
|
352
|
+
|
|
353
|
+
const {
|
|
354
|
+
slug,
|
|
355
|
+
labels,
|
|
356
|
+
icon
|
|
357
|
+
} = entity;
|
|
358
|
+
const slugForGeneralTemplate = entityConfig.templateSlug || slug; // We need to check if the general template is part of the
|
|
359
|
+
// defaultTemplateTypes. If it is, just use that info and
|
|
360
|
+
// augment it with the specific template functionality.
|
|
361
|
+
|
|
362
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
|
|
363
|
+
let {
|
|
364
|
+
slug: _slug
|
|
365
|
+
} = _ref15;
|
|
366
|
+
return _slug === slugForGeneralTemplate;
|
|
367
|
+
});
|
|
368
|
+
const generalTemplateSlug = (defaultTemplateType === null || defaultTemplateType === void 0 ? void 0 : defaultTemplateType.slug) || `${entityConfig.templatePrefix}${slug}`;
|
|
369
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
370
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType
|
|
371
|
+
} : {
|
|
372
|
+
slug: generalTemplateSlug,
|
|
373
|
+
title: entityConfig.getTitle(labels),
|
|
374
|
+
description: entityConfig.getDescription(labels),
|
|
375
|
+
icon: (_entityConfig$getIcon = entityConfig.getIcon) === null || _entityConfig$getIcon === void 0 ? void 0 : _entityConfig$getIcon.call(entityConfig, icon)
|
|
376
|
+
};
|
|
377
|
+
const hasEntities = entitiesInfo === null || entitiesInfo === void 0 ? void 0 : (_entitiesInfo$slug = entitiesInfo[slug]) === null || _entitiesInfo$slug === void 0 ? void 0 : _entitiesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
|
|
378
|
+
|
|
379
|
+
if (hasEntities) {
|
|
380
|
+
menuItem.onClick = template => {
|
|
381
|
+
onClickMenuItem({
|
|
382
|
+
type: entityConfig.entityName,
|
|
383
|
+
slug,
|
|
384
|
+
config: entityConfig,
|
|
385
|
+
labels,
|
|
386
|
+
hasGeneralTemplate,
|
|
387
|
+
template,
|
|
388
|
+
postsToExclude: entitiesInfo[slug].existingEntitiesIds
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
} // We don't need to add the menu item if there are no
|
|
392
|
+
// entities and the general template exists.
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
396
|
+
accumulator.push(menuItem);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return accumulator;
|
|
400
|
+
}, []);
|
|
401
|
+
return extraTemplates;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
exports.useExtraTemplates = useExtraTemplates;
|
|
405
|
+
//# 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","taxonomyBaseConfig","entityName","getOrderBy","search","getIcon","blockMeta","getTitle","labels","singular_name","getDescription","postTypeBaseConfig","recordNamePath","_icon","startsWith","slice","post","entitiesConfig","postType","templatePrefix","page","taxonomy","category","tag","templateSlug","useExistingTemplates","select","coreStore","getEntityRecords","per_page","useDefaultTemplateTypes","editorStore","__experimentalGetDefaultTemplateTypes","usePublicPostTypes","postTypes","getPostTypes","excludedPostTypes","filter","viewable","slug","includes","usePostTypes","usePostTypePage","usePublicTaxonomies","taxonomies","getTaxonomies","visibility","publicly_queryable","useTaxonomies","specialTaxonomies","useTaxonomyCategory","useTaxonomyTag","useEntitiesInfo","existingTemplates","slugsToExcludePerEntity","reduce","accumulator","_prefix","slugsWithTemplates","_accumulator","existingTemplate","push","substring","length","recordsToExcludePerEntity","Object","entries","postsWithTemplates","_fields","context","entitiesInfo","existingEntitiesIds","id","hasEntities","exclude","useExtraTemplates","entityConfig","onClickMenuItem","defaultTemplateTypes","existingTemplateSlugs","extraTemplates","icon","slugForGeneralTemplate","defaultTemplateType","find","_slug","generalTemplateSlug","hasGeneralTemplate","menuItem","title","description","onClick","template","type","config","postsToExclude"],"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,EAAYC,IAAZ,KAAsB;AACvD,SAAO,C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ent":["/**\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\n/**\n * @typedef {Object} EntityConfig\n * @property {string} entityName The entity's name.\n * @property {Function} getOrderBy Getter for an entity's `orderBy` query parameter, given the object\n * {search} as argument.\n * @property {Function} getIcon Getter function for returning an entity's icon for the menu item.\n * @property {Function} getTitle Getter function for returning an entity's title for the menu item.\n * @property {Function} getDescription Getter function for returning an entity's description for the menu item.\n * @property {string} recordNamePath The path to an entity's properties to use as a `name`. If not provided\n * is assumed that `name` property exists.\n * @property {string} templatePrefix The template prefix to create new templates and check against existing\n * templates. For example custom post types need a `single-` prefix to all\n * templates(`single-post-hello`), whereas `pages` don't (`page-hello`).\n * @property {string} templateSlug If this property is provided, it is going to be used for the creation of\n * new templates and the check against existing templates in the place\n * of the actual entity's `slug`. An example is `Tag` templates where the\n * the Tag's taxonomy slug is `post_tag`, but template hierarchy is based\n * on `tag` alias.\n */\n\nconst taxonomyBaseConfig = {\n\tentityName: 'taxonomy',\n\tgetOrderBy: ( { search } ) => ( search ? 'name' : 'count' ),\n\tgetIcon: () => blockMeta,\n\tgetTitle: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the taxonomy e.g: \"Cagegory\".\n\t\t\t__( 'Single taxonomy: %s' ),\n\t\t\tlabels.singular_name\n\t\t),\n\tgetDescription: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the taxonomy e.g: \"Product Categories\".\n\t\t\t__( 'Displays a single taxonomy: %s.' ),\n\t\t\tlabels.singular_name\n\t\t),\n};\nconst postTypeBaseConfig = {\n\tentityName: 'postType',\n\tgetOrderBy: ( { search } ) => ( search ? 'relevance' : 'modified' ),\n\trecordNamePath: 'title.rendered',\n\t// `icon` is the `menu_icon` property of a post type. We\n\t// only handle `dashicons` for now, even if the `menu_icon`\n\t// also supports urls and svg as values.\n\tgetIcon: ( _icon ) =>\n\t\t_icon?.startsWith( 'dashicons-' ) ? _icon.slice( 10 ) : post,\n\tgetTitle: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Single item: %s' ),\n\t\t\tlabels.singular_name\n\t\t),\n\tgetDescription: ( labels ) =>\n\t\tsprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Displays a single item: %s.' ),\n\t\t\tlabels.singular_name\n\t\t),\n};\nexport const entitiesConfig = {\n\tpostType: {\n\t\t...postTypeBaseConfig,\n\t\ttemplatePrefix: 'single-',\n\t},\n\tpage: { ...postTypeBaseConfig },\n\ttaxonomy: {\n\t\t...taxonomyBaseConfig,\n\t\ttemplatePrefix: 'taxonomy-',\n\t},\n\tcategory: { ...taxonomyBaseConfig },\n\ttag: { ...taxonomyBaseConfig, templateSlug: 'tag' },\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\n// `page` post type is a special case in the template hierarchy,\n// so we exclude it from the list of post types and we handle it\n// separately.\nexport const usePostTypes = () => {\n\tconst postTypes = usePublicPostTypes();\n\treturn useMemo( () => {\n\t\treturn postTypes?.filter( ( { slug } ) => slug !== 'page' );\n\t}, [ postTypes ] );\n};\nexport const usePostTypePage = () => {\n\tconst postTypes = usePublicPostTypes();\n\treturn useMemo( () => {\n\t\treturn postTypes?.filter( ( { slug } ) => slug === 'page' );\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\n/**\n * `category` and `post_tag` are handled specifically in template\n * hierarchy so we need to differentiate them and return the rest,\n * e.g. `category-$slug` and `taxonomy-$taxonomy-$term`.\n */\nexport const useTaxonomies = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\tconst specialTaxonomies = [ 'category', 'post_tag' ];\n\treturn useMemo(\n\t\t() =>\n\t\t\ttaxonomies?.filter(\n\t\t\t\t( { slug } ) => ! specialTaxonomies.includes( slug )\n\t\t\t),\n\t\t[ taxonomies ]\n\t);\n};\n\nexport const useTaxonomyCategory = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\treturn useMemo(\n\t\t() => taxonomies?.filter( ( { slug } ) => slug === 'category' ),\n\t\t[ taxonomies ]\n\t);\n};\nexport const useTaxonomyTag = () => {\n\tconst taxonomies = usePublicTaxonomies();\n\treturn useMemo(\n\t\t() => taxonomies?.filter( ( { slug } ) => slug === 'post_tag' ),\n\t\t[ taxonomies ]\n\t);\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 remaing record, by excluding them.\n *\n * @param {string[]} existingTemplates The existing templates.\n * @param {Object[]} entities The array of entities we need to get extra information.\n * @param {EntityConfig} entityConfig The entity config.\n * @return {Record<string,EntitiesInfo>} An object with the `entities.slug` as `keys` and EntitiesInfo as values.\n */\nconst useEntitiesInfo = (\n\texistingTemplates,\n\tentities,\n\t{ entityName, templatePrefix, templateSlug }\n) => {\n\tconst slugsToExcludePerEntity = useMemo( () => {\n\t\treturn entities?.reduce( ( accumulator, entity ) => {\n\t\t\tlet _prefix = `${ templateSlug || entity.slug }-`;\n\t\t\tif ( templatePrefix ) {\n\t\t\t\t_prefix = templatePrefix + _prefix;\n\t\t\t}\n\t\t\tconst slugsWithTemplates = ( existingTemplates || [] ).reduce(\n\t\t\t\t( _accumulator, existingTemplate ) => {\n\t\t\t\t\tif ( existingTemplate.slug.startsWith( _prefix ) ) {\n\t\t\t\t\t\t_accumulator.push(\n\t\t\t\t\t\t\texistingTemplate.slug.substring( _prefix.length )\n\t\t\t\t\t\t);\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\tif ( slugsWithTemplates.length ) {\n\t\t\t\taccumulator[ entity.slug ] = slugsWithTemplates;\n\t\t\t}\n\t\t\treturn accumulator;\n\t\t}, {} );\n\t}, [ entities, existingTemplates ] );\n\tconst recordsToExcludePerEntity = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! slugsToExcludePerEntity ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn Object.entries( slugsToExcludePerEntity ).reduce(\n\t\t\t\t( accumulator, [ slug, slugsWithTemplates ] ) => {\n\t\t\t\t\tconst postsWithTemplates = 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 ( postsWithTemplates?.length ) {\n\t\t\t\t\t\taccumulator[ slug ] = postsWithTemplates;\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\tconst entitiesInfo = useSelect(\n\t\t( select ) => {\n\t\t\treturn entities?.reduce( ( accumulator, { slug } ) => {\n\t\t\t\tconst existingEntitiesIds =\n\t\t\t\t\trecordsToExcludePerEntity?.[ slug ]?.map(\n\t\t\t\t\t\t( { id } ) => id\n\t\t\t\t\t) || [];\n\t\t\t\taccumulator[ slug ] = {\n\t\t\t\t\thasEntities: !! select( coreStore ).getEntityRecords(\n\t\t\t\t\t\tentityName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tper_page: 1,\n\t\t\t\t\t\t\t_fields: 'id',\n\t\t\t\t\t\t\tcontext: 'view',\n\t\t\t\t\t\t\texclude: existingEntitiesIds,\n\t\t\t\t\t\t}\n\t\t\t\t\t)?.length,\n\t\t\t\t\texistingEntitiesIds,\n\t\t\t\t};\n\t\t\t\treturn accumulator;\n\t\t\t}, {} );\n\t\t},\n\t\t[ entities, recordsToExcludePerEntity ]\n\t);\n\treturn entitiesInfo;\n};\n\nexport const useExtraTemplates = (\n\tentities,\n\tentityConfig,\n\tonClickMenuItem\n) => {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst entitiesInfo = useEntitiesInfo(\n\t\texistingTemplates,\n\t\tentities,\n\t\tentityConfig\n\t);\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst extraTemplates = ( entities || [] ).reduce(\n\t\t( accumulator, entity ) => {\n\t\t\tconst { slug, labels, icon } = entity;\n\t\t\tconst slugForGeneralTemplate = entityConfig.templateSlug || slug;\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 defaultTemplateType = defaultTemplateTypes?.find(\n\t\t\t\t( { slug: _slug } ) => _slug === slugForGeneralTemplate\n\t\t\t);\n\t\t\tconst generalTemplateSlug =\n\t\t\t\tdefaultTemplateType?.slug ||\n\t\t\t\t`${ entityConfig.templatePrefix }${ slug }`;\n\t\t\tconst hasGeneralTemplate =\n\t\t\t\texistingTemplateSlugs?.includes( generalTemplateSlug );\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: entityConfig.getTitle( labels ),\n\t\t\t\t\t\tdescription: entityConfig.getDescription( labels ),\n\t\t\t\t\t\ticon: entityConfig.getIcon?.( icon ),\n\t\t\t\t };\n\t\t\tconst hasEntities = entitiesInfo?.[ 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: entityConfig.entityName,\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tconfig: entityConfig,\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\tpostsToExclude:\n\t\t\t\t\t\t\tentitiesInfo[ slug ].existingEntitiesIds,\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\treturn extraTemplates;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/block-inspector-button.js"],"names":["BlockInspectorButton","onClick","shortcut","isBlockInspectorOpen","select","keyboardShortcutsStore","getShortcutRepresentation","interfaceStore","getActiveComplementaryArea","editSiteStore","name","SIDEBAR_BLOCK","enableComplementaryArea","disableComplementaryArea","label","STORE_NAME"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAQA;AACA;AACA;AAKe,SAASA,oBAAT,OAAwD;AAAA,MAAzB;AAAEC,IAAAA,OAAO,GAAG,MAAM,CAAE;AAApB,GAAyB;AACtE,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAqC,qBACxCC,MAAF,KAAgB;AACfF,IAAAA,QAAQ,EAAEE,MAAM,CACfC,wBADe,CAAN,CAERC,yBAFQ,CAGT,8CAHS,CADK;AAMfH,IAAAA,oBAAoB,EACnBC,MAAM,CAAEG,gBAAF,CAAN,CAAyBC,0BAAzB,CACCC,aAAcC,IADf,MAEMC;AATQ,GAAhB,CAD0C,EAY1C,EAZ0C,CAA3C;AAcA,QAAM;AAAEC,IAAAA,uBAAF;AAA2BC,IAAAA;AAA3B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/block-inspector-button.js"],"names":["BlockInspectorButton","onClick","shortcut","isBlockInspectorOpen","select","keyboardShortcutsStore","getShortcutRepresentation","interfaceStore","getActiveComplementaryArea","editSiteStore","name","SIDEBAR_BLOCK","enableComplementaryArea","disableComplementaryArea","label","STORE_NAME"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAQA;AACA;AACA;AAKe,SAASA,oBAAT,OAAwD;AAAA,MAAzB;AAAEC,IAAAA,OAAO,GAAG,MAAM,CAAE;AAApB,GAAyB;AACtE,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAqC,qBACxCC,MAAF,KAAgB;AACfF,IAAAA,QAAQ,EAAEE,MAAM,CACfC,wBADe,CAAN,CAERC,yBAFQ,CAGT,8CAHS,CADK;AAMfH,IAAAA,oBAAoB,EACnBC,MAAM,CAAEG,gBAAF,CAAN,CAAyBC,0BAAzB,CACCC,aAAcC,IADf,MAEMC;AATQ,GAAhB,CAD0C,EAY1C,EAZ0C,CAA3C;AAcA,QAAM;AAAEC,IAAAA,uBAAF;AAA2BC,IAAAA;AAA3B,MACL,uBAAaN,gBAAb,CADD;AAGA,QAAMO,KAAK,GAAGX,oBAAoB,GAC/B,cAAI,oBAAJ,CAD+B,GAE/B,cAAI,oBAAJ,CAFH;AAIA,SACC,4BAAC,oBAAD;AACC,IAAA,OAAO,EAAG,MAAM;AACf,UAAKA,oBAAL,EAA4B;AAC3BU,QAAAA,wBAAwB,CAAEE,qBAAF,CAAxB;AACA,yBAAO,cAAI,uBAAJ,CAAP;AACA,OAHD,MAGO;AACNH,QAAAA,uBAAuB,CAAEG,qBAAF,EAAcJ,yBAAd,CAAvB;AACA,yBACC,cACC,4EADD,CADD;AAKA,OAXc,CAYf;;;AACAV,MAAAA,OAAO;AACP,KAfF;AAgBC,IAAA,QAAQ,EAAGC;AAhBZ,KAkBGY,KAlBH,CADD;AAsBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { speak } from '@wordpress/a11y';\nimport { MenuItem } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport { STORE_NAME } from '../../store/constants';\nimport { SIDEBAR_BLOCK } from '../sidebar/constants';\n\nexport default function BlockInspectorButton( { onClick = () => {} } ) {\n\tconst { shortcut, isBlockInspectorOpen } = useSelect(\n\t\t( select ) => ( {\n\t\t\tshortcut: select(\n\t\t\t\tkeyboardShortcutsStore\n\t\t\t).getShortcutRepresentation(\n\t\t\t\t'core/edit-site/toggle-block-settings-sidebar'\n\t\t\t),\n\t\t\tisBlockInspectorOpen:\n\t\t\t\tselect( interfaceStore ).getActiveComplementaryArea(\n\t\t\t\t\teditSiteStore.name\n\t\t\t\t) === SIDEBAR_BLOCK,\n\t\t} ),\n\t\t[]\n\t);\n\tconst { enableComplementaryArea, disableComplementaryArea } =\n\t\tuseDispatch( interfaceStore );\n\n\tconst label = isBlockInspectorOpen\n\t\t? __( 'Hide more settings' )\n\t\t: __( 'Show more settings' );\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\tif ( isBlockInspectorOpen ) {\n\t\t\t\t\tdisableComplementaryArea( STORE_NAME );\n\t\t\t\t\tspeak( __( 'Block settings closed' ) );\n\t\t\t\t} else {\n\t\t\t\t\tenableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK );\n\t\t\t\t\tspeak(\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'Additional settings are now available in the Editor block settings sidebar'\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Close dropdown menu.\n\t\t\t\tonClick();\n\t\t\t} }\n\t\t\tshortcut={ shortcut }\n\t\t>\n\t\t\t{ label }\n\t\t</MenuItem>\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/index.js"],"names":["LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","storedSettings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","editSiteStore","settingsBlockPatterns","__experimentalAdditionalBlockPatterns","__experimentalBlockPatterns","settingsBlockPatternCategories","__experimentalAdditionalBlockPatternCategories","__experimentalBlockPatternCategories","restBlockPatterns","restBlockPatternCategories","coreStore","getBlockPatterns","getBlockPatternCategories","blockPatterns","blockPatternCategories","settings","blocks","onInput","onChange","setPage","enableComplementaryArea","interfaceStore","openNavigationSidebar","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","blockEditorStore","isTemplatePart","hasBlocks","length","NavMenuSidebarToggle","listView","MaybeNavMenuSidebarToggle","Fragment","process","env","IS_GUTENBERG_PLUGIN","fillProps","event","target","currentTarget","undefined","onClose","blockName"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AACA;;AAKA;;AAEA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA1CA;AACA;AACA;;AAIA;AACA;AACA;;AAwBA;AACA;AACA;AAUA,MAAMA,MAAM,GAAG;AACdC,EAAAA,IAAI,EAAE,SADQ;AAEd;AACAC,EAAAA,UAAU,EAAE;AAHE,CAAf;;AAMe,SAASC,WAAT,OAA8C;AAAA;;AAAA,MAAxB;AAAEC,IAAAA;AAAF,GAAwB;AAC5D,QAAM;AAAEC,IAAAA,cAAF;AAAkBC,IAAAA,YAAlB;AAAgCC,IAAAA,UAAhC;AAA4CC,IAAAA;AAA5C,MAAqD,qBACxDC,MAAF,IAAc;AACb,UAAM;AACLC,MAAAA,WADK;AAELC,MAAAA,iBAFK;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AAA,WACD,4BAAC,6BAAD;AAAsB,MAAA,OAAO,EAAGA;AAAhC,MADC;AAAA,GADH,CAjCD,EAsCC,4BAAC,2CAAD,QACC,4BAAC,uCAAD,CAA4B,QAA5B,QACKC,SAAF,IACDA,SAAS,KAAK,iBAAd,IACC,4BAAC,yBAAD,OAHH,CADD,CAtCD,CAxBD,EAwEC,4BAAC,uCAAD,OAxED,CADD;AA4EA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { omit, unionBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useRef, Fragment } from '@wordpress/element';\nimport { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';\nimport {\n\tBlockList,\n\tBlockEditorProvider,\n\t__experimentalLinkControl,\n\tBlockInspector,\n\tBlockTools,\n\t__unstableBlockToolbarLastItem,\n\t__unstableBlockSettingsMenuFirstItem,\n\t__unstableUseTypingObserver as useTypingObserver,\n\tBlockEditorKeyboardShortcuts,\n\tstore as blockEditorStore,\n\t__unstableBlockNameContext,\n} from '@wordpress/block-editor';\nimport { useMergeRefs, useViewportMatch } from '@wordpress/compose';\nimport { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';\nimport { listView } from '@wordpress/icons';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartConverter from '../template-part-converter';\nimport NavigateToLink from '../navigate-to-link';\nimport { SidebarInspectorFill } from '../sidebar';\nimport { store as editSiteStore } from '../../store';\nimport BlockInspectorButton from './block-inspector-button';\nimport EditTemplatePartMenuButton from '../edit-template-part-menu-button';\nimport BackButton from './back-button';\nimport ResizableEditor from './resizable-editor';\n\nconst LAYOUT = {\n\ttype: 'default',\n\t// At the root level of the site editor, no alignments should be allowed.\n\talignments: [],\n};\n\nexport default function BlockEditor( { setIsInserterOpen } ) {\n\tconst { storedSettings, templateType, templateId, page } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetSettings,\n\t\t\t\tgetEditedPostType,\n\t\t\t\tgetEditedPostId,\n\t\t\t\tgetPage,\n\t\t\t} = select( editSiteStore );\n\n\t\t\treturn {\n\t\t\t\tstoredSettings: getSettings( setIsInserterOpen ),\n\t\t\t\ttemplateType: getEditedPostType(),\n\t\t\t\ttemplateId: getEditedPostId(),\n\t\t\t\tpage: getPage(),\n\t\t\t};\n\t\t},\n\t\t[ setIsInserterOpen ]\n\t);\n\n\tconst settingsBlockPatterns =\n\t\tstoredSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0\n\t\tstoredSettings.__experimentalBlockPatterns; // WP 5.9\n\tconst settingsBlockPatternCategories =\n\t\tstoredSettings.__experimentalAdditionalBlockPatternCategories ?? // WP 6.0\n\t\tstoredSettings.__experimentalBlockPatternCategories; // WP 5.9\n\n\tconst { restBlockPatterns, restBlockPatternCategories } = useSelect(\n\t\t( select ) => ( {\n\t\t\trestBlockPatterns: select( coreStore ).getBlockPatterns(),\n\t\t\trestBlockPatternCategories: select(\n\t\t\t\tcoreStore\n\t\t\t).getBlockPatternCategories(),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst blockPatterns = useMemo(\n\t\t() => unionBy( settingsBlockPatterns, restBlockPatterns, 'name' ),\n\t\t[ settingsBlockPatterns, restBlockPatterns ]\n\t);\n\n\tconst blockPatternCategories = useMemo(\n\t\t() =>\n\t\t\tunionBy(\n\t\t\t\tsettingsBlockPatternCategories,\n\t\t\t\trestBlockPatternCategories,\n\t\t\t\t'name'\n\t\t\t),\n\t\t[ settingsBlockPatternCategories, restBlockPatternCategories ]\n\t);\n\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...omit( storedSettings, [\n\t\t\t\t'__experimentalAdditionalBlockPatterns',\n\t\t\t\t'__experimentalAdditionalBlockPatternCategories',\n\t\t\t] ),\n\t\t\t__experimentalBlockPatterns: blockPatterns,\n\t\t\t__experimentalBlockPatternCategories: blockPatternCategories,\n\t\t} ),\n\t\t[ storedSettings, blockPatterns, blockPatternCategories ]\n\t);\n\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\tconst { setPage } = useDispatch( editSiteStore );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst openNavigationSidebar = useCallback( () => {\n\t\tenableComplementaryArea(\n\t\t\t'core/edit-site',\n\t\t\t'edit-site/navigation-menu'\n\t\t);\n\t}, [ enableComplementaryArea ] );\n\tconst contentRef = useRef();\n\tconst mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst { clearSelectedBlock } = useDispatch( blockEditorStore );\n\n\tconst isTemplatePart = templateType === 'wp_template_part';\n\tconst hasBlocks = blocks.length !== 0;\n\n\tconst NavMenuSidebarToggle = () => (\n\t\t<ToolbarGroup>\n\t\t\t<ToolbarButton\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ __( 'Open list view' ) }\n\t\t\t\tonClick={ openNavigationSidebar }\n\t\t\t\ticon={ listView }\n\t\t\t/>\n\t\t</ToolbarGroup>\n\t);\n\n\t// Conditionally include NavMenu sidebar in Plugin only.\n\t// Optimise for dead code elimination.\n\t// See https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/feature-flags.md#dead-code-elimination.\n\tlet MaybeNavMenuSidebarToggle = Fragment;\n\n\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\tMaybeNavMenuSidebarToggle = NavMenuSidebarToggle;\n\t}\n\n\treturn (\n\t\t<BlockEditorProvider\n\t\t\tsettings={ settings }\n\t\t\tvalue={ blocks }\n\t\t\tonInput={ onInput }\n\t\t\tonChange={ onChange }\n\t\t\tuseSubRegistry={ false }\n\t\t>\n\t\t\t<EditTemplatePartMenuButton />\n\t\t\t<TemplatePartConverter />\n\t\t\t<__experimentalLinkControl.ViewerFill>\n\t\t\t\t{ useCallback(\n\t\t\t\t\t( fillProps ) => (\n\t\t\t\t\t\t<NavigateToLink\n\t\t\t\t\t\t\t{ ...fillProps }\n\t\t\t\t\t\t\tactivePage={ page }\n\t\t\t\t\t\t\tonActivePageChange={ setPage }\n\t\t\t\t\t\t/>\n\t\t\t\t\t),\n\t\t\t\t\t[ page ]\n\t\t\t\t) }\n\t\t\t</__experimentalLinkControl.ViewerFill>\n\t\t\t<SidebarInspectorFill>\n\t\t\t\t<BlockInspector />\n\t\t\t</SidebarInspectorFill>\n\t\t\t<BlockTools\n\t\t\t\tclassName={ classnames( 'edit-site-visual-editor', {\n\t\t\t\t\t'is-focus-mode': isTemplatePart,\n\t\t\t\t} ) }\n\t\t\t\t__unstableContentRef={ contentRef }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t// Clear selected block when clicking on the gray background.\n\t\t\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<BlockEditorKeyboardShortcuts.Register />\n\t\t\t\t<BackButton />\n\t\t\t\t<ResizableEditor\n\t\t\t\t\t// Reinitialize the editor and reset the states when the template changes.\n\t\t\t\t\tkey={ templateId }\n\t\t\t\t\tenableResizing={\n\t\t\t\t\t\tisTemplatePart &&\n\t\t\t\t\t\t// Disable resizing in mobile viewport.\n\t\t\t\t\t\t! isMobileViewport\n\t\t\t\t\t}\n\t\t\t\t\tsettings={ settings }\n\t\t\t\t\tcontentRef={ mergedRefs }\n\t\t\t\t>\n\t\t\t\t\t<BlockList\n\t\t\t\t\t\tclassName=\"edit-site-block-editor__block-list wp-site-blocks\"\n\t\t\t\t\t\t__experimentalLayout={ LAYOUT }\n\t\t\t\t\t\trenderAppender={\n\t\t\t\t\t\t\tisTemplatePart && hasBlocks ? false : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ResizableEditor>\n\t\t\t\t<__unstableBlockSettingsMenuFirstItem>\n\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t<BlockInspectorButton onClick={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t</__unstableBlockSettingsMenuFirstItem>\n\t\t\t\t<__unstableBlockToolbarLastItem>\n\t\t\t\t\t<__unstableBlockNameContext.Consumer>\n\t\t\t\t\t\t{ ( blockName ) =>\n\t\t\t\t\t\t\tblockName === 'core/navigation' && (\n\t\t\t\t\t\t\t\t<MaybeNavMenuSidebarToggle />\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</__unstableBlockNameContext.Consumer>\n\t\t\t\t</__unstableBlockToolbarLastItem>\n\t\t\t</BlockTools>\n\t\t\t<ReusableBlocksMenuItems />\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/index.js"],"names":["LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","storedSettings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","editSiteStore","settingsBlockPatterns","__experimentalAdditionalBlockPatterns","__experimentalBlockPatterns","settingsBlockPatternCategories","__experimentalAdditionalBlockPatternCategories","__experimentalBlockPatternCategories","restBlockPatterns","restBlockPatternCategories","coreStore","getBlockPatterns","getBlockPatternCategories","blockPatterns","blockPatternCategories","settings","blocks","onInput","onChange","setPage","enableComplementaryArea","interfaceStore","openNavigationSidebar","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","blockEditorStore","isTemplatePart","hasBlocks","length","NavMenuSidebarToggle","listView","MaybeNavMenuSidebarToggle","Fragment","process","env","IS_GUTENBERG_PLUGIN","fillProps","event","target","currentTarget","undefined","onClose","blockName"],"mappings":";;;;;;;;;AAUA;;;;AAPA;;AACA;;AAKA;;AAEA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA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ZD,EAaC,4BAAC,mBAAD,OAbD,EAcC,4BAAC,wBAAD,CACC;AADD;AAEC,IAAA,GAAG,EAAGhC,UAFP;AAGC,IAAA,cAAc,EACbkC,cAAc,IACd;AACA,KAAEH,gBANJ;AAQC,IAAA,QAAQ,EAAGV,QARZ;AASC,IAAA,UAAU,EAAGS;AATd,KAWC,4BAAC,sBAAD;AACC,IAAA,SAAS,EAAC,mDADX;AAEC,IAAA,oBAAoB,EAAGrC,MAFxB;AAGC,IAAA,cAAc,EACbyC,cAAc,IAAIC,SAAlB,GAA8B,KAA9B,GAAsCa;AAJxC,IAXD,CAdD,EAiCC,4BAAC,iDAAD,QACG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WACD,4BAAC,6BAAD;AAAsB,MAAA,OAAO,EAAGA;AAAhC,MADC;AAAA,GADH,CAjCD,EAsCC,4BAAC,2CAAD,QACC,4BAAC,uCAAD,CAA4B,QAA5B,QACKC,SAAF,IACDA,SAAS,KAAK,iBAAd,IACC,4BAAC,yBAAD,OAHH,CADD,CAtCD,CAxBD,EAwEC,4BAAC,uCAAD,OAxED,CADD;AA4EA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\nimport { omit, unionBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useMemo, useRef, Fragment } from '@wordpress/element';\nimport { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';\nimport {\n\tBlockList,\n\tBlockEditorProvider,\n\t__experimentalLinkControl,\n\tBlockInspector,\n\tBlockTools,\n\t__unstableBlockToolbarLastItem,\n\t__unstableBlockSettingsMenuFirstItem,\n\t__unstableUseTypingObserver as useTypingObserver,\n\tBlockEditorKeyboardShortcuts,\n\tstore as blockEditorStore,\n\t__unstableBlockNameContext,\n} from '@wordpress/block-editor';\nimport { useMergeRefs, useViewportMatch } from '@wordpress/compose';\nimport { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';\nimport { listView } from '@wordpress/icons';\nimport { ToolbarButton, ToolbarGroup } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { store as interfaceStore } from '@wordpress/interface';\n\n/**\n * Internal dependencies\n */\nimport TemplatePartConverter from '../template-part-converter';\nimport NavigateToLink from '../navigate-to-link';\nimport { SidebarInspectorFill } from '../sidebar';\nimport { store as editSiteStore } from '../../store';\nimport BlockInspectorButton from './block-inspector-button';\nimport EditTemplatePartMenuButton from '../edit-template-part-menu-button';\nimport BackButton from './back-button';\nimport ResizableEditor from './resizable-editor';\n\nconst LAYOUT = {\n\ttype: 'default',\n\t// At the root level of the site editor, no alignments should be allowed.\n\talignments: [],\n};\n\nexport default function BlockEditor( { setIsInserterOpen } ) {\n\tconst { storedSettings, templateType, templateId, page } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getSettings, getEditedPostType, getEditedPostId, getPage } =\n\t\t\t\tselect( editSiteStore );\n\n\t\t\treturn {\n\t\t\t\tstoredSettings: getSettings( setIsInserterOpen ),\n\t\t\t\ttemplateType: getEditedPostType(),\n\t\t\t\ttemplateId: getEditedPostId(),\n\t\t\t\tpage: getPage(),\n\t\t\t};\n\t\t},\n\t\t[ setIsInserterOpen ]\n\t);\n\n\tconst settingsBlockPatterns =\n\t\tstoredSettings.__experimentalAdditionalBlockPatterns ?? // WP 6.0\n\t\tstoredSettings.__experimentalBlockPatterns; // WP 5.9\n\tconst settingsBlockPatternCategories =\n\t\tstoredSettings.__experimentalAdditionalBlockPatternCategories ?? // WP 6.0\n\t\tstoredSettings.__experimentalBlockPatternCategories; // WP 5.9\n\n\tconst { restBlockPatterns, restBlockPatternCategories } = useSelect(\n\t\t( select ) => ( {\n\t\t\trestBlockPatterns: select( coreStore ).getBlockPatterns(),\n\t\t\trestBlockPatternCategories:\n\t\t\t\tselect( coreStore ).getBlockPatternCategories(),\n\t\t} ),\n\t\t[]\n\t);\n\n\tconst blockPatterns = useMemo(\n\t\t() => unionBy( settingsBlockPatterns, restBlockPatterns, 'name' ),\n\t\t[ settingsBlockPatterns, restBlockPatterns ]\n\t);\n\n\tconst blockPatternCategories = useMemo(\n\t\t() =>\n\t\t\tunionBy(\n\t\t\t\tsettingsBlockPatternCategories,\n\t\t\t\trestBlockPatternCategories,\n\t\t\t\t'name'\n\t\t\t),\n\t\t[ settingsBlockPatternCategories, restBlockPatternCategories ]\n\t);\n\n\tconst settings = useMemo(\n\t\t() => ( {\n\t\t\t...omit( storedSettings, [\n\t\t\t\t'__experimentalAdditionalBlockPatterns',\n\t\t\t\t'__experimentalAdditionalBlockPatternCategories',\n\t\t\t] ),\n\t\t\t__experimentalBlockPatterns: blockPatterns,\n\t\t\t__experimentalBlockPatternCategories: blockPatternCategories,\n\t\t} ),\n\t\t[ storedSettings, blockPatterns, blockPatternCategories ]\n\t);\n\n\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\tconst { setPage } = useDispatch( editSiteStore );\n\tconst { enableComplementaryArea } = useDispatch( interfaceStore );\n\tconst openNavigationSidebar = useCallback( () => {\n\t\tenableComplementaryArea(\n\t\t\t'core/edit-site',\n\t\t\t'edit-site/navigation-menu'\n\t\t);\n\t}, [ enableComplementaryArea ] );\n\tconst contentRef = useRef();\n\tconst mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] );\n\tconst isMobileViewport = useViewportMatch( 'small', '<' );\n\tconst { clearSelectedBlock } = useDispatch( blockEditorStore );\n\n\tconst isTemplatePart = templateType === 'wp_template_part';\n\tconst hasBlocks = blocks.length !== 0;\n\n\tconst NavMenuSidebarToggle = () => (\n\t\t<ToolbarGroup>\n\t\t\t<ToolbarButton\n\t\t\t\tclassName=\"components-toolbar__control\"\n\t\t\t\tlabel={ __( 'Open list view' ) }\n\t\t\t\tonClick={ openNavigationSidebar }\n\t\t\t\ticon={ listView }\n\t\t\t/>\n\t\t</ToolbarGroup>\n\t);\n\n\t// Conditionally include NavMenu sidebar in Plugin only.\n\t// Optimise for dead code elimination.\n\t// See https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/feature-flags.md#dead-code-elimination.\n\tlet MaybeNavMenuSidebarToggle = Fragment;\n\n\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\tMaybeNavMenuSidebarToggle = NavMenuSidebarToggle;\n\t}\n\n\treturn (\n\t\t<BlockEditorProvider\n\t\t\tsettings={ settings }\n\t\t\tvalue={ blocks }\n\t\t\tonInput={ onInput }\n\t\t\tonChange={ onChange }\n\t\t\tuseSubRegistry={ false }\n\t\t>\n\t\t\t<EditTemplatePartMenuButton />\n\t\t\t<TemplatePartConverter />\n\t\t\t<__experimentalLinkControl.ViewerFill>\n\t\t\t\t{ useCallback(\n\t\t\t\t\t( fillProps ) => (\n\t\t\t\t\t\t<NavigateToLink\n\t\t\t\t\t\t\t{ ...fillProps }\n\t\t\t\t\t\t\tactivePage={ page }\n\t\t\t\t\t\t\tonActivePageChange={ setPage }\n\t\t\t\t\t\t/>\n\t\t\t\t\t),\n\t\t\t\t\t[ page ]\n\t\t\t\t) }\n\t\t\t</__experimentalLinkControl.ViewerFill>\n\t\t\t<SidebarInspectorFill>\n\t\t\t\t<BlockInspector />\n\t\t\t</SidebarInspectorFill>\n\t\t\t<BlockTools\n\t\t\t\tclassName={ classnames( 'edit-site-visual-editor', {\n\t\t\t\t\t'is-focus-mode': isTemplatePart,\n\t\t\t\t} ) }\n\t\t\t\t__unstableContentRef={ contentRef }\n\t\t\t\tonClick={ ( event ) => {\n\t\t\t\t\t// Clear selected block when clicking on the gray background.\n\t\t\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<BlockEditorKeyboardShortcuts.Register />\n\t\t\t\t<BackButton />\n\t\t\t\t<ResizableEditor\n\t\t\t\t\t// Reinitialize the editor and reset the states when the template changes.\n\t\t\t\t\tkey={ templateId }\n\t\t\t\t\tenableResizing={\n\t\t\t\t\t\tisTemplatePart &&\n\t\t\t\t\t\t// Disable resizing in mobile viewport.\n\t\t\t\t\t\t! isMobileViewport\n\t\t\t\t\t}\n\t\t\t\t\tsettings={ settings }\n\t\t\t\t\tcontentRef={ mergedRefs }\n\t\t\t\t>\n\t\t\t\t\t<BlockList\n\t\t\t\t\t\tclassName=\"edit-site-block-editor__block-list wp-site-blocks\"\n\t\t\t\t\t\t__experimentalLayout={ LAYOUT }\n\t\t\t\t\t\trenderAppender={\n\t\t\t\t\t\t\tisTemplatePart && hasBlocks ? false : undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ResizableEditor>\n\t\t\t\t<__unstableBlockSettingsMenuFirstItem>\n\t\t\t\t\t{ ( { onClose } ) => (\n\t\t\t\t\t\t<BlockInspectorButton onClick={ onClose } />\n\t\t\t\t\t) }\n\t\t\t\t</__unstableBlockSettingsMenuFirstItem>\n\t\t\t\t<__unstableBlockToolbarLastItem>\n\t\t\t\t\t<__unstableBlockNameContext.Consumer>\n\t\t\t\t\t\t{ ( blockName ) =>\n\t\t\t\t\t\t\tblockName === 'core/navigation' && (\n\t\t\t\t\t\t\t\t<MaybeNavMenuSidebarToggle />\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</__unstableBlockNameContext.Consumer>\n\t\t\t\t</__unstableBlockToolbarLastItem>\n\t\t\t</BlockTools>\n\t\t\t<ReusableBlocksMenuItems />\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
|
|
@@ -49,10 +49,23 @@ function CodeEditor() {
|
|
|
49
49
|
};
|
|
50
50
|
}, []);
|
|
51
51
|
const [contentStructure, setContent] = (0, _coreData.useEntityProp)('postType', templateType, 'content');
|
|
52
|
-
const [blocks,, onChange] = (0, _coreData.useEntityBlockEditor)('postType', templateType);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const [blocks,, onChange] = (0, _coreData.useEntityBlockEditor)('postType', templateType); // Replicates the logic found in getEditedPostContent().
|
|
53
|
+
|
|
54
|
+
let content;
|
|
55
|
+
|
|
56
|
+
if (contentStructure instanceof Function) {
|
|
57
|
+
content = contentStructure({
|
|
58
|
+
blocks
|
|
59
|
+
});
|
|
60
|
+
} else if (blocks) {
|
|
61
|
+
// If we have parsed blocks already, they should be our source of truth.
|
|
62
|
+
// Parsing applies block deprecations and legacy block conversions that
|
|
63
|
+
// unparsed content will not have.
|
|
64
|
+
content = (0, _blocks.__unstableSerializeAndClean)(blocks);
|
|
65
|
+
} else {
|
|
66
|
+
content = contentStructure;
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
const {
|
|
57
70
|
switchEditorMode
|
|
58
71
|
} = (0, _data.useDispatch)(_store.store);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["CodeEditor","templateType","shortcut","select","getEditedPostType","editSiteStore","getShortcutRepresentation","keyboardShortcutsStore","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAdA;AACA;AACA;;AAQA;AACA;AACA;AAIe,SAASA,UAAT,GAAsB;AACpC,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6B,qBAAaC,MAAF,IAAc;AAC3D,UAAM;AAAEC,MAAAA;AAAF,QAAwBD,MAAM,CAAEE,YAAF,CAApC;AACA,UAAM;AAAEC,MAAAA;AAAF,QAAgCH,MAAM,CAAEI,wBAAF,CAA5C;AACA,WAAO;AACNN,MAAAA,YAAY,EAAEG,iBAAiB,EADzB;AAENF,MAAAA,QAAQ,EAAEI,yBAAyB,CAAE,4BAAF;AAF7B,KAAP;AAIA,GAPkC,EAOhC,EAPgC,CAAnC;AAQA,QAAM,CAAEE,gBAAF,EAAoBC,UAApB,IAAmC,6BACxC,UADwC,EAExCR,YAFwC,EAGxC,SAHwC,CAAzC;AAKA,QAAM,CAAES,MAAF,GAAYC,QAAZ,IAAyB,oCAC9B,UAD8B,EAE9BV,YAF8B,CAA/B
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["CodeEditor","templateType","shortcut","select","getEditedPostType","editSiteStore","getShortcutRepresentation","keyboardShortcutsStore","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;;;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAdA;AACA;AACA;;AAQA;AACA;AACA;AAIe,SAASA,UAAT,GAAsB;AACpC,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6B,qBAAaC,MAAF,IAAc;AAC3D,UAAM;AAAEC,MAAAA;AAAF,QAAwBD,MAAM,CAAEE,YAAF,CAApC;AACA,UAAM;AAAEC,MAAAA;AAAF,QAAgCH,MAAM,CAAEI,wBAAF,CAA5C;AACA,WAAO;AACNN,MAAAA,YAAY,EAAEG,iBAAiB,EADzB;AAENF,MAAAA,QAAQ,EAAEI,yBAAyB,CAAE,4BAAF;AAF7B,KAAP;AAIA,GAPkC,EAOhC,EAPgC,CAAnC;AAQA,QAAM,CAAEE,gBAAF,EAAoBC,UAApB,IAAmC,6BACxC,UADwC,EAExCR,YAFwC,EAGxC,SAHwC,CAAzC;AAKA,QAAM,CAAES,MAAF,GAAYC,QAAZ,IAAyB,oCAC9B,UAD8B,EAE9BV,YAF8B,CAA/B,CAdoC,CAmBpC;;AACA,MAAIW,OAAJ;;AACA,MAAKJ,gBAAgB,YAAYK,QAAjC,EAA4C;AAC3CD,IAAAA,OAAO,GAAGJ,gBAAgB,CAAE;AAAEE,MAAAA;AAAF,KAAF,CAA1B;AACA,GAFD,MAEO,IAAKA,MAAL,EAAc;AACpB;AACA;AACA;AACAE,IAAAA,OAAO,GAAG,yCAA6BF,MAA7B,CAAV;AACA,GALM,MAKA;AACNE,IAAAA,OAAO,GAAGJ,gBAAV;AACA;;AAED,QAAM;AAAEM,IAAAA;AAAF,MAAuB,uBAAaT,YAAb,CAA7B;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,wCAAM,cAAI,cAAJ,CAAN,CADD,EAEC,4BAAC,kBAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAMS,gBAAgB,CAAE,QAAF,CAFjC;AAGC,IAAA,QAAQ,EAAGZ;AAHZ,KAKG,cAAI,kBAAJ,CALH,CAFD,CADD,EAWC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,4BAAC,2BAAD;AACC,IAAA,KAAK,EAAGU,OADT;AAEC,IAAA,QAAQ,EAAKG,UAAF,IAAkB;AAC5BJ,MAAAA,QAAQ,CAAE,mBAAOI,UAAP,CAAF,EAAuB;AAC9BC,QAAAA,SAAS,EAAEC;AADmB,OAAvB,CAAR;AAGA,KANF;AAOC,IAAA,OAAO,EAAGR;AAPX,IADD,CAXD,CADD;AAyBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { store as editSiteStore } from '../../store';\nimport CodeEditorTextArea from './code-editor-text-area';\n\nexport default function CodeEditor() {\n\tconst { templateType, shortcut } = useSelect( ( select ) => {\n\t\tconst { getEditedPostType } = select( editSiteStore );\n\t\tconst { getShortcutRepresentation } = select( keyboardShortcutsStore );\n\t\treturn {\n\t\t\ttemplateType: getEditedPostType(),\n\t\t\tshortcut: getShortcutRepresentation( 'core/edit-site/toggle-mode' ),\n\t\t};\n\t}, [] );\n\tconst [ contentStructure, setContent ] = useEntityProp(\n\t\t'postType',\n\t\ttemplateType,\n\t\t'content'\n\t);\n\tconst [ blocks, , onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\n\t// Replicates the logic found in getEditedPostContent().\n\tlet content;\n\tif ( contentStructure instanceof Function ) {\n\t\tcontent = contentStructure( { blocks } );\n\t} else if ( blocks ) {\n\t\t// If we have parsed blocks already, they should be our source of truth.\n\t\t// Parsing applies block deprecations and legacy block conversions that\n\t\t// unparsed content will not have.\n\t\tcontent = __unstableSerializeAndClean( blocks );\n\t} else {\n\t\tcontent = contentStructure;\n\t}\n\n\tconst { switchEditorMode } = useDispatch( editSiteStore );\n\treturn (\n\t\t<div className=\"edit-site-code-editor\">\n\t\t\t<div className=\"edit-site-code-editor__toolbar\">\n\t\t\t\t<h2>{ __( 'Editing code' ) }</h2>\n\t\t\t\t<Button\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tonClick={ () => switchEditorMode( 'visual' ) }\n\t\t\t\t\tshortcut={ shortcut }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Exit code editor' ) }\n\t\t\t\t</Button>\n\t\t\t</div>\n\t\t\t<div className=\"edit-site-code-editor__body\">\n\t\t\t\t<CodeEditorTextArea\n\t\t\t\t\tvalue={ content }\n\t\t\t\t\tonChange={ ( newContent ) => {\n\t\t\t\t\t\tonChange( parse( newContent ), {\n\t\t\t\t\t\t\tselection: undefined,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tonInput={ setContent }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/edit-template-part-menu-button/index.js"],"names":["EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","blockEditorStore","getBlock","theme","slug","attributes","coreStore","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIe,SAASA,0BAAT,GAAsC;AACpD,SACC,4BAAC,sCAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,4BAAC,wBAAD;AACC,MAAA,gBAAgB,EAAGD,iBAAiB,CAAE,CAAF,CADrC;AAEC,MAAA,OAAO,EAAGC;AAFX,MADC;AAAA,GADH,CADD;AAUA;;AAED,SAASC,wBAAT,QAAmE;AAAA,MAAhC;AAAEC,IAAAA,gBAAF;AAAoBF,IAAAA;AAApB,GAAgC;AAClE,QAAM;AAAEG,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,oBAAoB,GAAG,qBAC1BC,MAAF,IAAc;AACb,UAAMC,KAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/edit-template-part-menu-button/index.js"],"names":["EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","blockEditorStore","getBlock","theme","slug","attributes","coreStore","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;;;;;;;;;;;AAGA;;AACA;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAWA;AACA;AACA;AAIe,SAASA,0BAAT,GAAsC;AACpD,SACC,4BAAC,sCAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,4BAAC,wBAAD;AACC,MAAA,gBAAgB,EAAGD,iBAAiB,CAAE,CAAF,CADrC;AAEC,MAAA,OAAO,EAAGC;AAFX,MADC;AAAA,GADH,CADD;AAUA;;AAED,SAASC,wBAAT,QAAmE;AAAA,MAAhC;AAAEC,IAAAA,gBAAF;AAAoBF,IAAAA;AAApB,GAAgC;AAClE,QAAM;AAAEG,IAAAA;AAAF,MAAa,0BAAnB;AACA,QAAMC,oBAAoB,GAAG,qBAC1BC,MAAF,IAAc;AACb,UAAMC,KAAK,GACVD,MAAM,CAAEE,kBAAF,CAAN,CAA2BC,QAA3B,CAAqCN,gBAArC,CADD;;AAGA,QAAKI,KAAK,IAAI,4BAAgBA,KAAhB,CAAd,EAAwC;AACvC,YAAM;AAAEG,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAkBJ,KAAK,CAACK,UAA9B;AAEA,aAAON,MAAM,CAAEO,eAAF,CAAN,CAAoBC,eAApB,CACN,UADM,EAEN,kBAFM,EAGN;AACC,SAAGJ,KAAO,KAAKC,IAAM,EAJhB,CAAP;AAMA;AACD,GAf2B,EAgB5B,CAAER,gBAAF,CAhB4B,CAA7B;AAmBA,QAAMY,SAAS,GAAG,mBACjB;AACCC,IAAAA,MAAM,EAAEX,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEY,EAD/B;AAECC,IAAAA,QAAQ,EAAEb,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEc;AAFjC,GADiB,EAKjB;AACCC,IAAAA,cAAc,EAAEhB,MAAM,CAACY;AADxB,GALiB,CAAlB;;AAUA,MAAK,CAAEX,oBAAP,EAA8B;AAC7B,WAAO,IAAP;AACA;;AAED,SACC,4BAAC,oBAAD,6BACMU,SADN;AAEC,IAAA,OAAO,EAAKM,KAAF,IAAa;AACtBN,MAAAA,SAAS,CAACO,OAAV,CAAmBD,KAAnB;AACApB,MAAAA,OAAO;AACP;AALF;AAQE;AACA,qBAAS,cAAI,SAAJ,CAAT,EAA0BI,oBAAoB,CAACM,IAA/C,CATF,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tBlockSettingsMenuControls,\n} from '@wordpress/block-editor';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { MenuItem } from '@wordpress/components';\nimport { isTemplatePart } from '@wordpress/blocks';\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { useLocation } from '../routes';\nimport { useLink } from '../routes/link';\n\nexport default function EditTemplatePartMenuButton() {\n\treturn (\n\t\t<BlockSettingsMenuControls>\n\t\t\t{ ( { selectedClientIds, onClose } ) => (\n\t\t\t\t<EditTemplatePartMenuItem\n\t\t\t\t\tselectedClientId={ selectedClientIds[ 0 ] }\n\t\t\t\t\tonClose={ onClose }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</BlockSettingsMenuControls>\n\t);\n}\n\nfunction EditTemplatePartMenuItem( { selectedClientId, onClose } ) {\n\tconst { params } = useLocation();\n\tconst selectedTemplatePart = useSelect(\n\t\t( select ) => {\n\t\t\tconst block =\n\t\t\t\tselect( blockEditorStore ).getBlock( selectedClientId );\n\n\t\t\tif ( block && isTemplatePart( block ) ) {\n\t\t\t\tconst { theme, slug } = block.attributes;\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t// Ideally this should be an official public API.\n\t\t\t\t\t`${ theme }//${ slug }`\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ selectedClientId ]\n\t);\n\n\tconst linkProps = useLink(\n\t\t{\n\t\t\tpostId: selectedTemplatePart?.id,\n\t\t\tpostType: selectedTemplatePart?.type,\n\t\t},\n\t\t{\n\t\t\tfromTemplateId: params.postId,\n\t\t}\n\t);\n\n\tif ( ! selectedTemplatePart ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<MenuItem\n\t\t\t{ ...linkProps }\n\t\t\tonClick={ ( event ) => {\n\t\t\t\tlinkProps.onClick( event );\n\t\t\t\tonClose();\n\t\t\t} }\n\t\t>\n\t\t\t{\n\t\t\t\t/* translators: %s: template part title */\n\t\t\t\tsprintf( __( 'Edit %s' ), selectedTemplatePart.slug )\n\t\t\t}\n\t\t</MenuItem>\n\t);\n}\n"]}
|
|
@@ -65,6 +65,22 @@ var _useTitle = _interopRequireDefault(require("../routes/use-title"));
|
|
|
65
65
|
* Internal dependencies
|
|
66
66
|
*/
|
|
67
67
|
const interfaceLabels = {
|
|
68
|
+
/* translators: accessibility text for the editor top bar landmark region. */
|
|
69
|
+
header: (0, _i18n.__)('Editor top bar'),
|
|
70
|
+
|
|
71
|
+
/* translators: accessibility text for the editor content landmark region. */
|
|
72
|
+
body: (0, _i18n.__)('Editor content'),
|
|
73
|
+
|
|
74
|
+
/* translators: accessibility text for the editor settings landmark region. */
|
|
75
|
+
sidebar: (0, _i18n.__)('Editor settings'),
|
|
76
|
+
|
|
77
|
+
/* translators: accessibility text for the editor publish landmark region. */
|
|
78
|
+
actions: (0, _i18n.__)('Editor publish'),
|
|
79
|
+
|
|
80
|
+
/* translators: accessibility text for the editor footer landmark region. */
|
|
81
|
+
footer: (0, _i18n.__)('Editor footer'),
|
|
82
|
+
|
|
83
|
+
/* translators: accessibility text for the navigation sidebar landmark region. */
|
|
68
84
|
drawer: (0, _i18n.__)('Navigation Sidebar')
|
|
69
85
|
};
|
|
70
86
|
|