@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,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { get } from 'lodash';
|
|
5
|
+
/**
|
|
6
|
+
* WordPress dependencies
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useSelect } from '@wordpress/data';
|
|
10
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
11
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
12
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
|
+
import { useMemo } from '@wordpress/element';
|
|
14
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
15
|
+
import { blockMeta, post } from '@wordpress/icons';
|
|
16
|
+
/**
|
|
17
|
+
* @typedef IHasNameAndId
|
|
18
|
+
* @property {string|number} id The entity's id.
|
|
19
|
+
* @property {string} name The entity's name.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Helper util to map records to add a `name` prop from a
|
|
24
|
+
* provided path, in order to handle all entities in the same
|
|
25
|
+
* fashion(implementing`IHasNameAndId` interface).
|
|
26
|
+
*
|
|
27
|
+
* @param {Object[]} entities The array of entities.
|
|
28
|
+
* @param {string} path The path to map a `name` property from the entity.
|
|
29
|
+
* @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export const mapToIHasNameAndId = (entities, path) => {
|
|
33
|
+
return (entities || []).map(entity => ({ ...entity,
|
|
34
|
+
name: decodeEntities(get(entity, path))
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {Object} EntitiesInfo
|
|
39
|
+
* @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).
|
|
40
|
+
* @property {number[]} existingEntitiesIds An array of the existing entities ids.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {Object} EntityConfig
|
|
45
|
+
* @property {string} entityName The entity's name.
|
|
46
|
+
* @property {Function} getOrderBy Getter for an entity's `orderBy` query parameter, given the object
|
|
47
|
+
* {search} as argument.
|
|
48
|
+
* @property {Function} getIcon Getter function for returning an entity's icon for the menu item.
|
|
49
|
+
* @property {Function} getTitle Getter function for returning an entity's title for the menu item.
|
|
50
|
+
* @property {Function} getDescription Getter function for returning an entity's description for the menu item.
|
|
51
|
+
* @property {string} recordNamePath The path to an entity's properties to use as a `name`. If not provided
|
|
52
|
+
* is assumed that `name` property exists.
|
|
53
|
+
* @property {string} templatePrefix The template prefix to create new templates and check against existing
|
|
54
|
+
* templates. For example custom post types need a `single-` prefix to all
|
|
55
|
+
* templates(`single-post-hello`), whereas `pages` don't (`page-hello`).
|
|
56
|
+
* @property {string} templateSlug If this property is provided, it is going to be used for the creation of
|
|
57
|
+
* new templates and the check against existing templates in the place
|
|
58
|
+
* of the actual entity's `slug`. An example is `Tag` templates where the
|
|
59
|
+
* the Tag's taxonomy slug is `post_tag`, but template hierarchy is based
|
|
60
|
+
* on `tag` alias.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
const taxonomyBaseConfig = {
|
|
64
|
+
entityName: 'taxonomy',
|
|
65
|
+
getOrderBy: _ref => {
|
|
66
|
+
let {
|
|
67
|
+
search
|
|
68
|
+
} = _ref;
|
|
69
|
+
return search ? 'name' : 'count';
|
|
70
|
+
},
|
|
71
|
+
getIcon: () => blockMeta,
|
|
72
|
+
getTitle: labels => sprintf( // translators: %s: Name of the taxonomy e.g: "Cagegory".
|
|
73
|
+
__('Single taxonomy: %s'), labels.singular_name),
|
|
74
|
+
getDescription: labels => sprintf( // translators: %s: Name of the taxonomy e.g: "Product Categories".
|
|
75
|
+
__('Displays a single taxonomy: %s.'), labels.singular_name)
|
|
76
|
+
};
|
|
77
|
+
const postTypeBaseConfig = {
|
|
78
|
+
entityName: 'postType',
|
|
79
|
+
getOrderBy: _ref2 => {
|
|
80
|
+
let {
|
|
81
|
+
search
|
|
82
|
+
} = _ref2;
|
|
83
|
+
return search ? 'relevance' : 'modified';
|
|
84
|
+
},
|
|
85
|
+
recordNamePath: 'title.rendered',
|
|
86
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
87
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
88
|
+
// also supports urls and svg as values.
|
|
89
|
+
getIcon: _icon => _icon !== null && _icon !== void 0 && _icon.startsWith('dashicons-') ? _icon.slice(10) : post,
|
|
90
|
+
getTitle: labels => sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
91
|
+
__('Single item: %s'), labels.singular_name),
|
|
92
|
+
getDescription: labels => sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
93
|
+
__('Displays a single item: %s.'), labels.singular_name)
|
|
94
|
+
};
|
|
95
|
+
export const entitiesConfig = {
|
|
96
|
+
postType: { ...postTypeBaseConfig,
|
|
97
|
+
templatePrefix: 'single-'
|
|
98
|
+
},
|
|
99
|
+
page: { ...postTypeBaseConfig
|
|
100
|
+
},
|
|
101
|
+
taxonomy: { ...taxonomyBaseConfig,
|
|
102
|
+
templatePrefix: 'taxonomy-'
|
|
103
|
+
},
|
|
104
|
+
category: { ...taxonomyBaseConfig
|
|
105
|
+
},
|
|
106
|
+
tag: { ...taxonomyBaseConfig,
|
|
107
|
+
templateSlug: 'tag'
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export const useExistingTemplates = () => {
|
|
111
|
+
return useSelect(select => select(coreStore).getEntityRecords('postType', 'wp_template', {
|
|
112
|
+
per_page: -1
|
|
113
|
+
}), []);
|
|
114
|
+
};
|
|
115
|
+
export const useDefaultTemplateTypes = () => {
|
|
116
|
+
return useSelect(select => select(editorStore).__experimentalGetDefaultTemplateTypes(), []);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const usePublicPostTypes = () => {
|
|
120
|
+
const postTypes = useSelect(select => select(coreStore).getPostTypes({
|
|
121
|
+
per_page: -1
|
|
122
|
+
}), []);
|
|
123
|
+
return useMemo(() => {
|
|
124
|
+
const excludedPostTypes = ['attachment'];
|
|
125
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref3 => {
|
|
126
|
+
let {
|
|
127
|
+
viewable,
|
|
128
|
+
slug
|
|
129
|
+
} = _ref3;
|
|
130
|
+
return viewable && !excludedPostTypes.includes(slug);
|
|
131
|
+
});
|
|
132
|
+
}, [postTypes]);
|
|
133
|
+
}; // `page` post type is a special case in the template hierarchy,
|
|
134
|
+
// so we exclude it from the list of post types and we handle it
|
|
135
|
+
// separately.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
export const usePostTypes = () => {
|
|
139
|
+
const postTypes = usePublicPostTypes();
|
|
140
|
+
return useMemo(() => {
|
|
141
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref4 => {
|
|
142
|
+
let {
|
|
143
|
+
slug
|
|
144
|
+
} = _ref4;
|
|
145
|
+
return slug !== 'page';
|
|
146
|
+
});
|
|
147
|
+
}, [postTypes]);
|
|
148
|
+
};
|
|
149
|
+
export const usePostTypePage = () => {
|
|
150
|
+
const postTypes = usePublicPostTypes();
|
|
151
|
+
return useMemo(() => {
|
|
152
|
+
return postTypes === null || postTypes === void 0 ? void 0 : postTypes.filter(_ref5 => {
|
|
153
|
+
let {
|
|
154
|
+
slug
|
|
155
|
+
} = _ref5;
|
|
156
|
+
return slug === 'page';
|
|
157
|
+
});
|
|
158
|
+
}, [postTypes]);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const usePublicTaxonomies = () => {
|
|
162
|
+
const taxonomies = useSelect(select => select(coreStore).getTaxonomies({
|
|
163
|
+
per_page: -1
|
|
164
|
+
}), []);
|
|
165
|
+
return useMemo(() => {
|
|
166
|
+
return taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref6 => {
|
|
167
|
+
let {
|
|
168
|
+
visibility
|
|
169
|
+
} = _ref6;
|
|
170
|
+
return visibility === null || visibility === void 0 ? void 0 : visibility.publicly_queryable;
|
|
171
|
+
});
|
|
172
|
+
}, [taxonomies]);
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* `category` and `post_tag` are handled specifically in template
|
|
176
|
+
* hierarchy so we need to differentiate them and return the rest,
|
|
177
|
+
* e.g. `category-$slug` and `taxonomy-$taxonomy-$term`.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
export const useTaxonomies = () => {
|
|
182
|
+
const taxonomies = usePublicTaxonomies();
|
|
183
|
+
const specialTaxonomies = ['category', 'post_tag'];
|
|
184
|
+
return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref7 => {
|
|
185
|
+
let {
|
|
186
|
+
slug
|
|
187
|
+
} = _ref7;
|
|
188
|
+
return !specialTaxonomies.includes(slug);
|
|
189
|
+
}), [taxonomies]);
|
|
190
|
+
};
|
|
191
|
+
export const useTaxonomyCategory = () => {
|
|
192
|
+
const taxonomies = usePublicTaxonomies();
|
|
193
|
+
return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref8 => {
|
|
194
|
+
let {
|
|
195
|
+
slug
|
|
196
|
+
} = _ref8;
|
|
197
|
+
return slug === 'category';
|
|
198
|
+
}), [taxonomies]);
|
|
199
|
+
};
|
|
200
|
+
export const useTaxonomyTag = () => {
|
|
201
|
+
const taxonomies = usePublicTaxonomies();
|
|
202
|
+
return useMemo(() => taxonomies === null || taxonomies === void 0 ? void 0 : taxonomies.filter(_ref9 => {
|
|
203
|
+
let {
|
|
204
|
+
slug
|
|
205
|
+
} = _ref9;
|
|
206
|
+
return slug === 'post_tag';
|
|
207
|
+
}), [taxonomies]);
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Helper hook that returns information about an entity having
|
|
211
|
+
* records that we can create a specific template for.
|
|
212
|
+
*
|
|
213
|
+
* For example we can search for `terms` in `taxonomy` entity or
|
|
214
|
+
* `posts` in `postType` entity.
|
|
215
|
+
*
|
|
216
|
+
* First we need to find the existing records with an associated template,
|
|
217
|
+
* to query afterwards for any remaing record, by excluding them.
|
|
218
|
+
*
|
|
219
|
+
* @param {string[]} existingTemplates The existing templates.
|
|
220
|
+
* @param {Object[]} entities The array of entities we need to get extra information.
|
|
221
|
+
* @param {EntityConfig} entityConfig The entity config.
|
|
222
|
+
* @return {Record<string,EntitiesInfo>} An object with the `entities.slug` as `keys` and EntitiesInfo as values.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
const useEntitiesInfo = (existingTemplates, entities, _ref10) => {
|
|
226
|
+
let {
|
|
227
|
+
entityName,
|
|
228
|
+
templatePrefix,
|
|
229
|
+
templateSlug
|
|
230
|
+
} = _ref10;
|
|
231
|
+
const slugsToExcludePerEntity = useMemo(() => {
|
|
232
|
+
return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, entity) => {
|
|
233
|
+
let _prefix = `${templateSlug || entity.slug}-`;
|
|
234
|
+
|
|
235
|
+
if (templatePrefix) {
|
|
236
|
+
_prefix = templatePrefix + _prefix;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
240
|
+
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
241
|
+
_accumulator.push(existingTemplate.slug.substring(_prefix.length));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return _accumulator;
|
|
245
|
+
}, []);
|
|
246
|
+
|
|
247
|
+
if (slugsWithTemplates.length) {
|
|
248
|
+
accumulator[entity.slug] = slugsWithTemplates;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return accumulator;
|
|
252
|
+
}, {});
|
|
253
|
+
}, [entities, existingTemplates]);
|
|
254
|
+
const recordsToExcludePerEntity = useSelect(select => {
|
|
255
|
+
if (!slugsToExcludePerEntity) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return Object.entries(slugsToExcludePerEntity).reduce((accumulator, _ref11) => {
|
|
260
|
+
let [slug, slugsWithTemplates] = _ref11;
|
|
261
|
+
const postsWithTemplates = select(coreStore).getEntityRecords(entityName, slug, {
|
|
262
|
+
_fields: 'id',
|
|
263
|
+
context: 'view',
|
|
264
|
+
slug: slugsWithTemplates
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
if (postsWithTemplates !== null && postsWithTemplates !== void 0 && postsWithTemplates.length) {
|
|
268
|
+
accumulator[slug] = postsWithTemplates;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return accumulator;
|
|
272
|
+
}, {});
|
|
273
|
+
}, [slugsToExcludePerEntity]);
|
|
274
|
+
const entitiesInfo = useSelect(select => {
|
|
275
|
+
return entities === null || entities === void 0 ? void 0 : entities.reduce((accumulator, _ref12) => {
|
|
276
|
+
var _recordsToExcludePerE, _select$getEntityReco;
|
|
277
|
+
|
|
278
|
+
let {
|
|
279
|
+
slug
|
|
280
|
+
} = _ref12;
|
|
281
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref13 => {
|
|
282
|
+
let {
|
|
283
|
+
id
|
|
284
|
+
} = _ref13;
|
|
285
|
+
return id;
|
|
286
|
+
})) || [];
|
|
287
|
+
accumulator[slug] = {
|
|
288
|
+
hasEntities: !!((_select$getEntityReco = select(coreStore).getEntityRecords(entityName, slug, {
|
|
289
|
+
per_page: 1,
|
|
290
|
+
_fields: 'id',
|
|
291
|
+
context: 'view',
|
|
292
|
+
exclude: existingEntitiesIds
|
|
293
|
+
})) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
|
|
294
|
+
existingEntitiesIds
|
|
295
|
+
};
|
|
296
|
+
return accumulator;
|
|
297
|
+
}, {});
|
|
298
|
+
}, [entities, recordsToExcludePerEntity]);
|
|
299
|
+
return entitiesInfo;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
export const useExtraTemplates = (entities, entityConfig, onClickMenuItem) => {
|
|
303
|
+
const existingTemplates = useExistingTemplates();
|
|
304
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
305
|
+
const entitiesInfo = useEntitiesInfo(existingTemplates, entities, entityConfig);
|
|
306
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref14 => {
|
|
307
|
+
let {
|
|
308
|
+
slug
|
|
309
|
+
} = _ref14;
|
|
310
|
+
return slug;
|
|
311
|
+
});
|
|
312
|
+
const extraTemplates = (entities || []).reduce((accumulator, entity) => {
|
|
313
|
+
var _entityConfig$getIcon, _entitiesInfo$slug;
|
|
314
|
+
|
|
315
|
+
const {
|
|
316
|
+
slug,
|
|
317
|
+
labels,
|
|
318
|
+
icon
|
|
319
|
+
} = entity;
|
|
320
|
+
const slugForGeneralTemplate = entityConfig.templateSlug || slug; // We need to check if the general template is part of the
|
|
321
|
+
// defaultTemplateTypes. If it is, just use that info and
|
|
322
|
+
// augment it with the specific template functionality.
|
|
323
|
+
|
|
324
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
|
|
325
|
+
let {
|
|
326
|
+
slug: _slug
|
|
327
|
+
} = _ref15;
|
|
328
|
+
return _slug === slugForGeneralTemplate;
|
|
329
|
+
});
|
|
330
|
+
const generalTemplateSlug = (defaultTemplateType === null || defaultTemplateType === void 0 ? void 0 : defaultTemplateType.slug) || `${entityConfig.templatePrefix}${slug}`;
|
|
331
|
+
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
332
|
+
const menuItem = defaultTemplateType ? { ...defaultTemplateType
|
|
333
|
+
} : {
|
|
334
|
+
slug: generalTemplateSlug,
|
|
335
|
+
title: entityConfig.getTitle(labels),
|
|
336
|
+
description: entityConfig.getDescription(labels),
|
|
337
|
+
icon: (_entityConfig$getIcon = entityConfig.getIcon) === null || _entityConfig$getIcon === void 0 ? void 0 : _entityConfig$getIcon.call(entityConfig, icon)
|
|
338
|
+
};
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
if (hasEntities) {
|
|
342
|
+
menuItem.onClick = template => {
|
|
343
|
+
onClickMenuItem({
|
|
344
|
+
type: entityConfig.entityName,
|
|
345
|
+
slug,
|
|
346
|
+
config: entityConfig,
|
|
347
|
+
labels,
|
|
348
|
+
hasGeneralTemplate,
|
|
349
|
+
template,
|
|
350
|
+
postsToExclude: entitiesInfo[slug].existingEntitiesIds
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
} // We don't need to add the menu item if there are no
|
|
354
|
+
// entities and the general template exists.
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
if (!hasGeneralTemplate || hasEntities) {
|
|
358
|
+
accumulator.push(menuItem);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return accumulator;
|
|
362
|
+
}, []);
|
|
363
|
+
return extraTemplates;
|
|
364
|
+
};
|
|
365
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/utils.js"],"names":["get","useSelect","store","coreStore","editorStore","decodeEntities","useMemo","__","sprintf","blockMeta","post","mapToIHasNameAndId","entities","path","map","entity","name","taxonomyBaseConfig","entityName","getOrderBy","search","getIcon","getTitle","labels","singular_name","getDescription","postTypeBaseConfig","recordNamePath","_icon","startsWith","slice","entitiesConfig","postType","templatePrefix","page","taxonomy","category","tag","templateSlug","useExistingTemplates","select","getEntityRecords","per_page","useDefaultTemplateTypes","__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":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAA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,MAAAA,QAAQ,CAACG,OAAT,GAAqBC,QAAF,IAAgB;AAClCf,QAAAA,eAAe,CAAE;AAChBgB,UAAAA,IAAI,EAAEjB,YAAY,CAACtE,UADH;AAEhBiC,UAAAA,IAFgB;AAGhBuD,UAAAA,MAAM,EAAElB,YAHQ;AAIhBjE,UAAAA,MAJgB;AAKhB4E,UAAAA,kBALgB;AAMhBK,UAAAA,QANgB;AAOhBG,UAAAA,cAAc,EACbzB,YAAY,CAAE/B,IAAF,CAAZ,CAAqBgC;AARN,SAAF,CAAf;AAUA,OAXD;AAYA,KArCyB,CAsC1B;AACA;;;AACA,QAAK,CAAEgB,kBAAF,IAAwBd,WAA7B,EAA2C;AAC1CjB,MAAAA,WAAW,CAACK,IAAZ,CAAkB2B,QAAlB;AACA;;AACD,WAAOhC,WAAP;AACA,GA7CqB,EA8CtB,EA9CsB,CAAvB;AAgDA,SAAOwB,cAAP;AACA,CAhEM","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useMemo } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { blockMeta, post } from '@wordpress/icons';\n\n/**\n * @typedef IHasNameAndId\n * @property {string|number} id The entity's id.\n * @property {string} name The entity's name.\n */\n\n/**\n * Helper util to map records to add a `name` prop from a\n * provided path, in order to handle all entities in the same\n * fashion(implementing`IHasNameAndId` interface).\n *\n * @param {Object[]} entities The array of entities.\n * @param {string} path The path to map a `name` property from the entity.\n * @return {IHasNameAndId[]} An array of enitities that now implement the `IHasNameAndId` interface.\n */\nexport const mapToIHasNameAndId = ( entities, path ) => {\n\treturn ( entities || [] ).map( ( entity ) => ( {\n\t\t...entity,\n\t\tname: decodeEntities( get( entity, path ) ),\n\t} ) );\n};\n\n/**\n * @typedef {Object} EntitiesInfo\n * @property {boolean} hasEntities If an entity has available records(posts, terms, etc..).\n * @property {number[]} existingEntitiesIds An array of the existing entities ids.\n */\n\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":["__","speak","MenuItem","useSelect","useDispatch","store","interfaceStore","keyboardShortcutsStore","editSiteStore","STORE_NAME","SIDEBAR_BLOCK","BlockInspectorButton","onClick","shortcut","isBlockInspectorOpen","select","getShortcutRepresentation","getActiveComplementaryArea","name","enableComplementaryArea","disableComplementaryArea","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,cAAlB,QAAwC,sBAAxC;AACA,SAASD,KAAK,IAAIE,sBAAlB,QAAgD,+BAAhD;AAEA;AACA;AACA;;AACA,SAASF,KAAK,IAAIG,aAAlB,QAAuC,aAAvC;AACA,SAASC,UAAT,QAA2B,uBAA3B;AACA,SAASC,aAAT,QAA8B,sBAA9B;AAEA,eAAe,SAASC,oBAAT,OAAwD;AAAA,MAAzB;AAAEC,IAAAA,OAAO,GAAG,MAAM,CAAE;AAApB,GAAyB;AACtE,QAAM;AAAEC,IAAAA,QAAF;AAAYC,IAAAA;AAAZ,MAAqCX,SAAS,CACjDY,MAAF,KAAgB;AACfF,IAAAA,QAAQ,EAAEE,MAAM,CACfR,sBADe,CAAN,CAERS,yBAFQ,CAGT,8CAHS,CADK;AAMfF,IAAAA,oBAAoB,EACnBC,MAAM,CAAET,cAAF,CAAN,CAAyBW,0BAAzB,CACCT,aAAa,CAACU,IADf,MAEMR;AATQ,GAAhB,CADmD,EAYnD,EAZmD,CAApD;AAcA,QAAM;AAAES,IAAAA,uBAAF;AAA2BC,IAAAA;AAA3B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/block-inspector-button.js"],"names":["__","speak","MenuItem","useSelect","useDispatch","store","interfaceStore","keyboardShortcutsStore","editSiteStore","STORE_NAME","SIDEBAR_BLOCK","BlockInspectorButton","onClick","shortcut","isBlockInspectorOpen","select","getShortcutRepresentation","getActiveComplementaryArea","name","enableComplementaryArea","disableComplementaryArea","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAT,QA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OAXc,CAYf;;;AACAY,MAAAA,OAAO;AACP,KAfF;AAgBC,IAAA,QAAQ,EAAGC;AAhBZ,KAkBGQ,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":["classnames","omit","unionBy","useSelect","useDispatch","useCallback","useMemo","useRef","Fragment","useEntityBlockEditor","store","coreStore","BlockList","BlockEditorProvider","__experimentalLinkControl","BlockInspector","BlockTools","__unstableBlockToolbarLastItem","__unstableBlockSettingsMenuFirstItem","__unstableUseTypingObserver","useTypingObserver","BlockEditorKeyboardShortcuts","blockEditorStore","__unstableBlockNameContext","useMergeRefs","useViewportMatch","ReusableBlocksMenuItems","listView","ToolbarButton","ToolbarGroup","__","interfaceStore","TemplatePartConverter","NavigateToLink","SidebarInspectorFill","editSiteStore","BlockInspectorButton","EditTemplatePartMenuButton","BackButton","ResizableEditor","LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","storedSettings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","settingsBlockPatterns","__experimentalAdditionalBlockPatterns","__experimentalBlockPatterns","settingsBlockPatternCategories","__experimentalAdditionalBlockPatternCategories","__experimentalBlockPatternCategories","restBlockPatterns","restBlockPatternCategories","getBlockPatterns","getBlockPatternCategories","blockPatterns","blockPatternCategories","settings","blocks","onInput","onChange","setPage","enableComplementaryArea","openNavigationSidebar","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","isTemplatePart","hasBlocks","length","NavMenuSidebarToggle","MaybeNavMenuSidebarToggle","process","env","IS_GUTENBERG_PLUGIN","fillProps","event","target","currentTarget","undefined","onClose","blockName"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,SAASC,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SAASC,SAAT,E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AEC,IAAA,oBAAoB,EAAGlC,MAFxB;AAGC,IAAA,cAAc,EACbqC,cAAc,IAAIC,SAAlB,GAA8B,KAA9B,GAAsCW;AAJxC,IAXD,CAdD,EAiCC,cAAC,oCAAD,QACG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WACD,cAAC,oBAAD;AAAsB,MAAA,OAAO,EAAGA;AAAhC,MADC;AAAA,GADH,CAjCD,EAsCC,cAAC,8BAAD,QACC,cAAC,0BAAD,CAA4B,QAA5B,QACKC,SAAF,IACDA,SAAS,KAAK,iBAAd,IACC,cAAC,yBAAD,OAHH,CADD,CAtCD,CAxBD,EAwEC,cAAC,uBAAD,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":["classnames","omit","unionBy","useSelect","useDispatch","useCallback","useMemo","useRef","Fragment","useEntityBlockEditor","store","coreStore","BlockList","BlockEditorProvider","__experimentalLinkControl","BlockInspector","BlockTools","__unstableBlockToolbarLastItem","__unstableBlockSettingsMenuFirstItem","__unstableUseTypingObserver","useTypingObserver","BlockEditorKeyboardShortcuts","blockEditorStore","__unstableBlockNameContext","useMergeRefs","useViewportMatch","ReusableBlocksMenuItems","listView","ToolbarButton","ToolbarGroup","__","interfaceStore","TemplatePartConverter","NavigateToLink","SidebarInspectorFill","editSiteStore","BlockInspectorButton","EditTemplatePartMenuButton","BackButton","ResizableEditor","LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","storedSettings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","settingsBlockPatterns","__experimentalAdditionalBlockPatterns","__experimentalBlockPatterns","settingsBlockPatternCategories","__experimentalAdditionalBlockPatternCategories","__experimentalBlockPatternCategories","restBlockPatterns","restBlockPatternCategories","getBlockPatterns","getBlockPatternCategories","blockPatterns","blockPatternCategories","settings","blocks","onInput","onChange","setPage","enableComplementaryArea","openNavigationSidebar","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","isTemplatePart","hasBlocks","length","NavMenuSidebarToggle","MaybeNavMenuSidebarToggle","process","env","IS_GUTENBERG_PLUGIN","fillProps","event","target","currentTarget","undefined","onClose","blockName"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA,SAASC,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,OAAtB,EAA+BC,MAA/B,EAAuCC,QAAvC,QAAuD,oBAAvD;AACA,SAASC,oBAAT,EAA+BC,KAAK,IAAIC,SAAxC,QAAyD,sBAAzD;AACA,SACCC,SADD,EAECC,mBAFD,EAGCC,yBAHD,EAICC,cAJD,EAKCC,UALD,EAMCC,8BAND,EAOCC,oCAPD,EAQCC,2BAA2B,IAAIC,iBARhC,EASCC,4BATD,EAUCX,KAAK,IAAIY,gBAVV,EAWCC,0BAXD,QAYO,yBAZP;AAaA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,oBAA/C;AACA,SAASC,uBAAT,QAAwC,4BAAxC;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,aAAT,EAAwBC,YAAxB,QAA4C,uBAA5C;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASpB,KAAK,IAAIqB,cAAlB,QAAwC,sBAAxC;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC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ACC,IAAA,SAAS,EAAGhD,UAAU,CAAE,yBAAF,EAA6B;AAClD,uBAAiB6E;AADiC,KAA7B,CADvB;AAIC,IAAA,oBAAoB,EAAGJ,UAJxB;AAKC,IAAA,OAAO,EAAKa,KAAF,IAAa;AACtB;AACA,UAAKA,KAAK,CAACC,MAAN,KAAiBD,KAAK,CAACE,aAA5B,EAA4C;AAC3CZ,QAAAA,kBAAkB;AAClB;AACD;AAVF,KAYC,cAAC,4BAAD,CAA8B,QAA9B,OAZD,EAaC,cAAC,UAAD,OAbD,EAcC,cAAC,eAAD,CACC;AADD;AAEC,IAAA,GAAG,EAAG7B,UAFP;AAGC,IAAA,cAAc,EACb8B,cAAc,IACd;AACA,KAAEF,gBANJ;AAQC,IAAA,QAAQ,EAAGT,QARZ;AASC,IAAA,UAAU,EAAGQ;AATd,KAWC,cAAC,SAAD;AACC,IAAA,SAAS,EAAC,mDADX;AAEC,IAAA,oBAAoB,EAAGlC,MAFxB;AAGC,IAAA,cAAc,EACbqC,cAAc,IAAIC,SAAlB,GAA8B,KAA9B,GAAsCW;AAJxC,IAXD,CAdD,EAiCC,cAAC,oCAAD,QACG;AAAA,QAAE;AAAEC,MAAAA;AAAF,KAAF;AAAA,WACD,cAAC,oBAAD;AAAsB,MAAA,OAAO,EAAGA;AAAhC,MADC;AAAA,GADH,CAjCD,EAsCC,cAAC,8BAAD,QACC,cAAC,0BAAD,CAA4B,QAA5B,QACKC,SAAF,IACDA,SAAS,KAAK,iBAAd,IACC,cAAC,yBAAD,OAHH,CADD,CAtCD,CAxBD,EAwEC,cAAC,uBAAD,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"]}
|
|
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
|
|
|
3
3
|
/**
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
|
-
import { parse } from '@wordpress/blocks';
|
|
6
|
+
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
7
7
|
import { useEntityBlockEditor, useEntityProp } from '@wordpress/core-data';
|
|
8
8
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
9
9
|
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
@@ -32,10 +32,23 @@ export default function CodeEditor() {
|
|
|
32
32
|
};
|
|
33
33
|
}, []);
|
|
34
34
|
const [contentStructure, setContent] = useEntityProp('postType', templateType, 'content');
|
|
35
|
-
const [blocks,, onChange] = useEntityBlockEditor('postType', templateType);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const [blocks,, onChange] = useEntityBlockEditor('postType', templateType); // Replicates the logic found in getEditedPostContent().
|
|
36
|
+
|
|
37
|
+
let content;
|
|
38
|
+
|
|
39
|
+
if (contentStructure instanceof Function) {
|
|
40
|
+
content = contentStructure({
|
|
41
|
+
blocks
|
|
42
|
+
});
|
|
43
|
+
} else if (blocks) {
|
|
44
|
+
// If we have parsed blocks already, they should be our source of truth.
|
|
45
|
+
// Parsing applies block deprecations and legacy block conversions that
|
|
46
|
+
// unparsed content will not have.
|
|
47
|
+
content = __unstableSerializeAndClean(blocks);
|
|
48
|
+
} else {
|
|
49
|
+
content = contentStructure;
|
|
50
|
+
}
|
|
51
|
+
|
|
39
52
|
const {
|
|
40
53
|
switchEditorMode
|
|
41
54
|
} = useDispatch(editSiteStore);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["parse","useEntityBlockEditor","useEntityProp","useSelect","useDispatch","store","keyboardShortcutsStore","__","Button","editSiteStore","CodeEditorTextArea","CodeEditor","templateType","shortcut","select","getEditedPostType","getShortcutRepresentation","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/code-editor/index.js"],"names":["parse","__unstableSerializeAndClean","useEntityBlockEditor","useEntityProp","useSelect","useDispatch","store","keyboardShortcutsStore","__","Button","editSiteStore","CodeEditorTextArea","CodeEditor","templateType","shortcut","select","getEditedPostType","getShortcutRepresentation","contentStructure","setContent","blocks","onChange","content","Function","switchEditorMode","newContent","selection","undefined"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,2BAAhB,QAAmD,mBAAnD;AACA,SAASC,oBAAT,EAA+BC,aAA/B,QAAoD,sBAApD;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,KAAK,IAAIC,sBAAlB,QAAgD,+BAAhD;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASH,KAAK,IAAII,aAAlB,QAAuC,aAAvC;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA,eAAe,SAASC,UAAT,GAAsB;AACpC,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6BV,SAAS,CAAIW,MAAF,IAAc;AAC3D,UAAM;AAAEC,MAAAA;AAAF,QAAwBD,MAAM,CAAEL,aAAF,CAApC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAgCF,MAAM,CAAER,sBAAF,CAA5C;AACA,WAAO;AACNM,MAAAA,YAAY,EAAEG,iBAAiB,EADzB;AAENF,MAAAA,QAAQ,EAAEG,yBAAyB,CAAE,4BAAF;AAF7B,KAAP;AAIA,GAP2C,EAOzC,EAPyC,CAA5C;AAQA,QAAM,CAAEC,gBAAF,EAAoBC,UAApB,IAAmChB,aAAa,CACrD,UADqD,EAErDU,YAFqD,EAGrD,SAHqD,CAAtD;AAKA,QAAM,CAAEO,MAAF,GAAYC,QAAZ,IAAyBnB,oBAAoB,CAClD,UADkD,EAElDW,YAFkD,CAAnD,CAdoC,CAmBpC;;AACA,MAAIS,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,GAAGrB,2BAA2B,CAAEmB,MAAF,CAArC;AACA,GALM,MAKA;AACNE,IAAAA,OAAO,GAAGJ,gBAAV;AACA;;AAED,QAAM;AAAEM,IAAAA;AAAF,MAAuBnB,WAAW,CAAEK,aAAF,CAAxC;AACA,SACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,0BAAMF,EAAE,CAAE,cAAF,CAAR,CADD,EAEC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,UADT;AAEC,IAAA,OAAO,EAAG,MAAMgB,gBAAgB,CAAE,QAAF,CAFjC;AAGC,IAAA,QAAQ,EAAGV;AAHZ,KAKGN,EAAE,CAAE,kBAAF,CALL,CAFD,CADD,EAWC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,kBAAD;AACC,IAAA,KAAK,EAAGc,OADT;AAEC,IAAA,QAAQ,EAAKG,UAAF,IAAkB;AAC5BJ,MAAAA,QAAQ,CAAErB,KAAK,CAAEyB,UAAF,CAAP,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":["useSelect","store","blockEditorStore","BlockSettingsMenuControls","coreStore","MenuItem","isTemplatePart","__","sprintf","useLocation","useLink","EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","getBlock","theme","slug","attributes","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,yBAFD,QAGO,yBAHP;AAIA,SAASF,KAAK,IAAIG,SAAlB,QAAmC,sBAAnC;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,WAA5B;AACA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,eAAe,SAASC,0BAAT,GAAsC;AACpD,SACC,cAAC,yBAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,cAAC,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,MAAaP,WAAW,EAA9B;AACA,QAAMQ,oBAAoB,GAAGjB,SAAS,CACnCkB,MAAF,IAAc;AACb,UAAMC,KAAK,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/edit-template-part-menu-button/index.js"],"names":["useSelect","store","blockEditorStore","BlockSettingsMenuControls","coreStore","MenuItem","isTemplatePart","__","sprintf","useLocation","useLink","EditTemplatePartMenuButton","selectedClientIds","onClose","EditTemplatePartMenuItem","selectedClientId","params","selectedTemplatePart","select","block","getBlock","theme","slug","attributes","getEntityRecord","linkProps","postId","id","postType","type","fromTemplateId","event","onClick"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,KAAK,IAAIC,gBADV,EAECC,yBAFD,QAGO,yBAHP;AAIA,SAASF,KAAK,IAAIG,SAAlB,QAAmC,sBAAnC;AACA,SAASC,QAAT,QAAyB,uBAAzB;AACA,SAASC,cAAT,QAA+B,mBAA/B;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,WAA5B;AACA,SAASC,OAAT,QAAwB,gBAAxB;AAEA,eAAe,SAASC,0BAAT,GAAsC;AACpD,SACC,cAAC,yBAAD,QACG;AAAA,QAAE;AAAEC,MAAAA,iBAAF;AAAqBC,MAAAA;AAArB,KAAF;AAAA,WACD,cAAC,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,MAAaP,WAAW,EAA9B;AACA,QAAMQ,oBAAoB,GAAGjB,SAAS,CACnCkB,MAAF,IAAc;AACb,UAAMC,KAAK,GACVD,MAAM,CAAEhB,gBAAF,CAAN,CAA2BkB,QAA3B,CAAqCL,gBAArC,CADD;;AAGA,QAAKI,KAAK,IAAIb,cAAc,CAAEa,KAAF,CAA5B,EAAwC;AACvC,YAAM;AAAEE,QAAAA,KAAF;AAASC,QAAAA;AAAT,UAAkBH,KAAK,CAACI,UAA9B;AAEA,aAAOL,MAAM,CAAEd,SAAF,CAAN,CAAoBoB,eAApB,CACN,UADM,EAEN,kBAFM,EAGN;AACC,SAAGH,KAAO,KAAKC,IAAM,EAJhB,CAAP;AAMA;AACD,GAfoC,EAgBrC,CAAEP,gBAAF,CAhBqC,CAAtC;AAmBA,QAAMU,SAAS,GAAGf,OAAO,CACxB;AACCgB,IAAAA,MAAM,EAAET,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEU,EAD/B;AAECC,IAAAA,QAAQ,EAAEX,oBAAF,aAAEA,oBAAF,uBAAEA,oBAAoB,CAAEY;AAFjC,GADwB,EAKxB;AACCC,IAAAA,cAAc,EAAEd,MAAM,CAACU;AADxB,GALwB,CAAzB;;AAUA,MAAK,CAAET,oBAAP,EAA8B;AAC7B,WAAO,IAAP;AACA;;AAED,SACC,cAAC,QAAD,eACMQ,SADN;AAEC,IAAA,OAAO,EAAKM,KAAF,IAAa;AACtBN,MAAAA,SAAS,CAACO,OAAV,CAAmBD,KAAnB;AACAlB,MAAAA,OAAO;AACP;AALF;AAQE;AACAL,EAAAA,OAAO,CAAED,EAAE,CAAE,SAAF,CAAJ,EAAmBU,oBAAoB,CAACK,IAAxC,CATT,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"]}
|
|
@@ -33,6 +33,22 @@ import { GlobalStylesRenderer } from './global-styles-renderer';
|
|
|
33
33
|
import { GlobalStylesProvider } from '../global-styles/global-styles-provider';
|
|
34
34
|
import useTitle from '../routes/use-title';
|
|
35
35
|
const interfaceLabels = {
|
|
36
|
+
/* translators: accessibility text for the editor top bar landmark region. */
|
|
37
|
+
header: __('Editor top bar'),
|
|
38
|
+
|
|
39
|
+
/* translators: accessibility text for the editor content landmark region. */
|
|
40
|
+
body: __('Editor content'),
|
|
41
|
+
|
|
42
|
+
/* translators: accessibility text for the editor settings landmark region. */
|
|
43
|
+
sidebar: __('Editor settings'),
|
|
44
|
+
|
|
45
|
+
/* translators: accessibility text for the editor publish landmark region. */
|
|
46
|
+
actions: __('Editor publish'),
|
|
47
|
+
|
|
48
|
+
/* translators: accessibility text for the editor footer landmark region. */
|
|
49
|
+
footer: __('Editor footer'),
|
|
50
|
+
|
|
51
|
+
/* translators: accessibility text for the navigation sidebar landmark region. */
|
|
36
52
|
drawer: __('Navigation Sidebar')
|
|
37
53
|
};
|
|
38
54
|
|