@wordpress/edit-site 3.0.8 → 3.0.12
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/build/components/add-new-template/index.js +49 -0
- package/build/components/add-new-template/index.js.map +1 -0
- package/build/components/add-new-template/new-template-part.js +95 -0
- package/build/components/add-new-template/new-template-part.js.map +1 -0
- package/build/components/add-new-template/new-template.js +133 -0
- package/build/components/add-new-template/new-template.js.map +1 -0
- package/build/components/block-editor/index.js +3 -1
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +115 -0
- package/build/components/create-template-part-modal/index.js.map +1 -0
- package/build/components/editor/index.js +20 -16
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/color-palette-panel.js +29 -6
- package/build/components/global-styles/color-palette-panel.js.map +1 -1
- package/build/components/global-styles/global-styles-provider.js +9 -47
- package/build/components/global-styles/global-styles-provider.js.map +1 -1
- package/build/components/global-styles/gradients-palette-panel.js +56 -0
- package/build/components/global-styles/gradients-palette-panel.js.map +1 -0
- package/build/components/global-styles/hooks.js +29 -27
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/palette.js +11 -5
- package/build/components/global-styles/palette.js.map +1 -1
- package/build/components/global-styles/screen-background-color.js +2 -1
- package/build/components/global-styles/screen-background-color.js.map +1 -1
- package/build/components/global-styles/screen-block-list.js +9 -1
- package/build/components/global-styles/screen-block-list.js.map +1 -1
- package/build/components/global-styles/screen-color-palette.js +23 -3
- package/build/components/global-styles/screen-color-palette.js.map +1 -1
- package/build/components/global-styles/screen-link-color.js +2 -1
- package/build/components/global-styles/screen-link-color.js.map +1 -1
- package/build/components/global-styles/screen-text-color.js +2 -1
- package/build/components/global-styles/screen-text-color.js.map +1 -1
- package/build/components/global-styles/screen-typography-element.js +54 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -0
- package/build/components/global-styles/screen-typography.js +74 -6
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +28 -8
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/ui.js +12 -0
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +2 -2
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +1 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/index.js +1 -5
- package/build/components/header/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +26 -0
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/list/actions/index.js +104 -0
- package/build/components/list/actions/index.js.map +1 -0
- package/build/components/list/actions/rename-menu-item.js +112 -0
- package/build/components/list/actions/rename-menu-item.js.map +1 -0
- package/build/components/list/added-by.js +180 -0
- package/build/components/list/added-by.js.map +1 -0
- package/build/components/list/header.js +50 -0
- package/build/components/list/header.js.map +1 -0
- package/build/components/list/index.js +102 -0
- package/build/components/list/index.js.map +1 -0
- package/build/components/list/table.js +114 -0
- package/build/components/list/table.js.map +1 -0
- package/build/components/list/use-register-shortcuts.js +52 -0
- package/build/components/list/use-register-shortcuts.js.map +1 -0
- package/build/components/navigation-sidebar/index.js +26 -10
- package/build/components/navigation-sidebar/index.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-panel/index.js +42 -44
- package/build/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build/components/navigation-sidebar/navigation-toggle/index.js +5 -17
- package/build/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build/components/template-details/index.js +3 -2
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-part-converter/convert-to-template-part.js +20 -84
- package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build/components/welcome-guide/editor.js +58 -0
- package/build/components/welcome-guide/editor.js.map +1 -0
- package/build/components/welcome-guide/image.js +27 -0
- package/build/components/welcome-guide/image.js.map +1 -0
- package/build/components/welcome-guide/index.js +49 -0
- package/build/components/welcome-guide/index.js.map +1 -0
- package/build/components/welcome-guide/styles.js +83 -0
- package/build/components/welcome-guide/styles.js.map +1 -0
- package/build/index.js +36 -6
- package/build/index.js.map +1 -1
- package/build/plugins/index.js +4 -2
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/welcome-guide-menu-item.js +39 -0
- package/build/plugins/welcome-guide-menu-item.js.map +1 -0
- package/build/store/actions.js +50 -24
- package/build/store/actions.js.map +1 -1
- package/build/store/defaults.js +4 -1
- package/build/store/defaults.js.map +1 -1
- package/build/store/selectors.js +25 -5
- package/build/store/selectors.js.map +1 -1
- package/build/utils/is-template-removable.js +21 -0
- package/build/utils/is-template-removable.js.map +1 -0
- package/build-module/components/add-new-template/index.js +36 -0
- package/build-module/components/add-new-template/index.js.map +1 -0
- package/build-module/components/add-new-template/new-template-part.js +79 -0
- package/build-module/components/add-new-template/new-template-part.js.map +1 -0
- package/build-module/components/add-new-template/new-template.js +114 -0
- package/build-module/components/add-new-template/new-template.js.map +1 -0
- package/build-module/components/block-editor/index.js +2 -1
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +102 -0
- package/build-module/components/create-template-part-modal/index.js.map +1 -0
- package/build-module/components/editor/index.js +19 -17
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/color-palette-panel.js +29 -7
- package/build-module/components/global-styles/color-palette-panel.js.map +1 -1
- package/build-module/components/global-styles/global-styles-provider.js +10 -43
- package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
- package/build-module/components/global-styles/gradients-palette-panel.js +46 -0
- package/build-module/components/global-styles/gradients-palette-panel.js.map +1 -0
- package/build-module/components/global-styles/hooks.js +30 -28
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/palette.js +12 -5
- package/build-module/components/global-styles/palette.js.map +1 -1
- package/build-module/components/global-styles/screen-background-color.js +2 -1
- package/build-module/components/global-styles/screen-background-color.js.map +1 -1
- package/build-module/components/global-styles/screen-block-list.js +7 -1
- package/build-module/components/global-styles/screen-block-list.js.map +1 -1
- package/build-module/components/global-styles/screen-color-palette.js +22 -3
- package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
- package/build-module/components/global-styles/screen-link-color.js +2 -1
- package/build-module/components/global-styles/screen-link-color.js.map +1 -1
- package/build-module/components/global-styles/screen-text-color.js +2 -1
- package/build-module/components/global-styles/screen-text-color.js.map +1 -1
- package/build-module/components/global-styles/screen-typography-element.js +41 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -0
- package/build-module/components/global-styles/screen-typography.js +70 -6
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +28 -8
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/ui.js +11 -0
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +2 -2
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +1 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/index.js +1 -3
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +26 -0
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/list/actions/index.js +85 -0
- package/build-module/components/list/actions/index.js.map +1 -0
- package/build-module/components/list/actions/rename-menu-item.js +101 -0
- package/build-module/components/list/actions/rename-menu-item.js.map +1 -0
- package/build-module/components/list/added-by.js +166 -0
- package/build-module/components/list/added-by.js.map +1 -0
- package/build-module/components/list/header.js +37 -0
- package/build-module/components/list/header.js.map +1 -0
- package/build-module/components/list/index.js +81 -0
- package/build-module/components/list/index.js.map +1 -0
- package/build-module/components/list/table.js +98 -0
- package/build-module/components/list/table.js.map +1 -0
- package/build-module/components/list/use-register-shortcuts.js +41 -0
- package/build-module/components/list/use-register-shortcuts.js.map +1 -0
- package/build-module/components/navigation-sidebar/index.js +26 -10
- package/build-module/components/navigation-sidebar/index.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-panel/index.js +41 -44
- package/build-module/components/navigation-sidebar/navigation-panel/index.js.map +1 -1
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js +6 -18
- package/build-module/components/navigation-sidebar/navigation-toggle/index.js.map +1 -1
- package/build-module/components/template-details/index.js +3 -2
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-part-converter/convert-to-template-part.js +20 -84
- package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
- package/build-module/components/welcome-guide/editor.js +45 -0
- package/build-module/components/welcome-guide/editor.js.map +1 -0
- package/build-module/components/welcome-guide/image.js +19 -0
- package/build-module/components/welcome-guide/image.js.map +1 -0
- package/build-module/components/welcome-guide/index.js +35 -0
- package/build-module/components/welcome-guide/index.js.map +1 -0
- package/build-module/components/welcome-guide/styles.js +69 -0
- package/build-module/components/welcome-guide/styles.js.map +1 -0
- package/build-module/index.js +28 -3
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/index.js +3 -2
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/welcome-guide-menu-item.js +27 -0
- package/build-module/plugins/welcome-guide-menu-item.js.map +1 -0
- package/build-module/store/actions.js +51 -25
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/defaults.js +4 -1
- package/build-module/store/defaults.js.map +1 -1
- package/build-module/store/selectors.js +21 -3
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils/is-template-removable.js +14 -0
- package/build-module/utils/is-template-removable.js.map +1 -0
- package/build-style/style-rtl.css +468 -33
- package/build-style/style.css +468 -33
- package/package.json +10 -8
- package/src/components/add-new-template/index.js +30 -0
- package/src/components/add-new-template/new-template-part.js +81 -0
- package/src/components/add-new-template/new-template.js +136 -0
- package/src/components/add-new-template/style.scss +11 -0
- package/src/components/block-editor/index.js +2 -0
- package/src/components/create-template-part-modal/index.js +132 -0
- package/src/components/{template-part-converter → create-template-part-modal}/style.scss +9 -9
- package/src/components/editor/index.js +22 -15
- package/src/components/editor/style.scss +8 -0
- package/src/components/global-styles/color-palette-panel.js +64 -7
- package/src/components/global-styles/global-styles-provider.js +7 -36
- package/src/components/global-styles/gradients-palette-panel.js +79 -0
- package/src/components/global-styles/hooks.js +59 -27
- package/src/components/global-styles/palette.js +30 -10
- package/src/components/global-styles/screen-background-color.js +1 -0
- package/src/components/global-styles/screen-block-list.js +11 -1
- package/src/components/global-styles/screen-color-palette.js +30 -3
- package/src/components/global-styles/screen-link-color.js +1 -0
- package/src/components/global-styles/screen-text-color.js +1 -0
- package/src/components/global-styles/screen-typography-element.js +39 -0
- package/src/components/global-styles/screen-typography.js +84 -3
- package/src/components/global-styles/style.scss +33 -0
- package/src/components/global-styles/test/use-global-styles-output.js +3 -3
- package/src/components/global-styles/test/utils.js +1 -1
- package/src/components/global-styles/typography-panel.js +37 -7
- package/src/components/global-styles/ui.js +9 -0
- package/src/components/global-styles/use-global-styles-output.js +2 -2
- package/src/components/global-styles/utils.js +1 -1
- package/src/components/header/index.js +0 -6
- package/src/components/keyboard-shortcuts/index.js +32 -0
- package/src/components/list/actions/index.js +95 -0
- package/src/components/list/actions/rename-menu-item.js +134 -0
- package/src/components/list/added-by.js +179 -0
- package/src/components/list/header.js +34 -0
- package/src/components/list/index.js +96 -0
- package/src/components/list/style.scss +208 -0
- package/src/components/list/table.js +121 -0
- package/src/components/list/use-register-shortcuts.js +45 -0
- package/src/components/navigation-sidebar/index.js +24 -8
- package/src/components/navigation-sidebar/navigation-panel/index.js +57 -51
- package/src/components/navigation-sidebar/navigation-panel/style.scss +4 -2
- package/src/components/navigation-sidebar/navigation-toggle/index.js +24 -36
- package/src/components/navigation-sidebar/navigation-toggle/test/index.js +2 -0
- package/src/components/sidebar/style.scss +2 -1
- package/src/components/template-details/index.js +3 -2
- package/src/components/template-part-converter/convert-to-template-part.js +20 -140
- package/src/components/welcome-guide/editor.js +63 -0
- package/src/components/welcome-guide/image.js +11 -0
- package/src/components/welcome-guide/index.js +33 -0
- package/src/components/welcome-guide/style.scss +37 -0
- package/src/components/welcome-guide/styles.js +116 -0
- package/src/index.js +31 -3
- package/src/plugins/index.js +3 -1
- package/src/plugins/welcome-guide-menu-item.js +35 -0
- package/src/store/actions.js +85 -35
- package/src/store/defaults.js +4 -1
- package/src/store/selectors.js +22 -4
- package/src/store/test/actions.js +0 -30
- package/src/store/test/selectors.js +24 -0
- package/src/style.scss +9 -6
- package/src/utils/is-template-removable.js +13 -0
- package/build/components/header/navigation-link/index.js +0 -87
- package/build/components/header/navigation-link/index.js.map +0 -1
- package/build-module/components/header/navigation-link/index.js +0 -74
- package/build-module/components/header/navigation-link/index.js.map +0 -1
- package/src/components/header/navigation-link/index.js +0 -71
- package/src/components/header/navigation-link/style.scss +0 -69
package/build/store/selectors.js
CHANGED
|
@@ -15,7 +15,7 @@ exports.getNavigationPanelActiveMenu = getNavigationPanelActiveMenu;
|
|
|
15
15
|
exports.getPage = getPage;
|
|
16
16
|
exports.getPreviousEditedPostId = getPreviousEditedPostId;
|
|
17
17
|
exports.getPreviousEditedPostType = getPreviousEditedPostType;
|
|
18
|
-
exports.getSettings = void 0;
|
|
18
|
+
exports.getSettings = exports.getReusableBlocks = void 0;
|
|
19
19
|
exports.isFeatureActive = isFeatureActive;
|
|
20
20
|
exports.isInserterOpened = isInserterOpened;
|
|
21
21
|
exports.isListViewOpened = isListViewOpened;
|
|
@@ -33,6 +33,8 @@ var _mediaUtils = require("@wordpress/media-utils");
|
|
|
33
33
|
|
|
34
34
|
var _blocks = require("@wordpress/blocks");
|
|
35
35
|
|
|
36
|
+
var _element = require("@wordpress/element");
|
|
37
|
+
|
|
36
38
|
var _constants = require("../components/navigation-sidebar/navigation-panel/constants");
|
|
37
39
|
|
|
38
40
|
var _templateHierarchy = require("../components/navigation-sidebar/navigation-panel/template-hierarchy");
|
|
@@ -86,6 +88,21 @@ function __experimentalGetPreviewDeviceType(state) {
|
|
|
86
88
|
|
|
87
89
|
|
|
88
90
|
const getCanUserCreateMedia = (0, _data.createRegistrySelector)(select => () => select(_coreData.store).canUser('create', 'media'));
|
|
91
|
+
/**
|
|
92
|
+
* Returns any available Reusable blocks.
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} state Global application state.
|
|
95
|
+
*
|
|
96
|
+
* @return {Array} The available reusable blocks.
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
exports.getCanUserCreateMedia = getCanUserCreateMedia;
|
|
100
|
+
const getReusableBlocks = (0, _data.createRegistrySelector)(select => () => {
|
|
101
|
+
const isWeb = _element.Platform.OS === 'web';
|
|
102
|
+
return isWeb ? select(_coreData.store).getEntityRecords('postType', 'wp_block', {
|
|
103
|
+
per_page: -1
|
|
104
|
+
}) : [];
|
|
105
|
+
});
|
|
89
106
|
/**
|
|
90
107
|
* Returns the settings, taking into account active features and permissions.
|
|
91
108
|
*
|
|
@@ -95,13 +112,14 @@ const getCanUserCreateMedia = (0, _data.createRegistrySelector)(select => () =>
|
|
|
95
112
|
* @return {Object} Settings.
|
|
96
113
|
*/
|
|
97
114
|
|
|
98
|
-
exports.
|
|
115
|
+
exports.getReusableBlocks = getReusableBlocks;
|
|
99
116
|
const getSettings = (0, _rememo.default)((state, setIsInserterOpen) => {
|
|
100
117
|
const settings = { ...state.settings,
|
|
101
118
|
outlineMode: true,
|
|
102
119
|
focusMode: isFeatureActive(state, 'focusMode'),
|
|
103
120
|
hasFixedToolbar: isFeatureActive(state, 'fixedToolbar'),
|
|
104
|
-
__experimentalSetIsInserterOpened: setIsInserterOpen
|
|
121
|
+
__experimentalSetIsInserterOpened: setIsInserterOpen,
|
|
122
|
+
__experimentalReusableBlocks: getReusableBlocks(state)
|
|
105
123
|
};
|
|
106
124
|
const canUserCreateMedia = getCanUserCreateMedia(state);
|
|
107
125
|
|
|
@@ -127,7 +145,7 @@ const getSettings = (0, _rememo.default)((state, setIsInserterOpen) => {
|
|
|
127
145
|
};
|
|
128
146
|
|
|
129
147
|
return settings;
|
|
130
|
-
}, state => [getCanUserCreateMedia(state), state.settings, isFeatureActive(state, 'focusMode'), isFeatureActive(state, 'fixedToolbar')]);
|
|
148
|
+
}, state => [getCanUserCreateMedia(state), state.settings, isFeatureActive(state, 'focusMode'), isFeatureActive(state, 'fixedToolbar'), getReusableBlocks(state)]);
|
|
131
149
|
/**
|
|
132
150
|
* Returns the current home template ID.
|
|
133
151
|
*
|
|
@@ -327,7 +345,9 @@ const getCurrentTemplateTemplateParts = (0, _data.createRegistrySelector)(select
|
|
|
327
345
|
const templateType = getEditedPostType(state);
|
|
328
346
|
const templateId = getEditedPostId(state);
|
|
329
347
|
const template = select(_coreData.store).getEditedEntityRecord('postType', templateType, templateId);
|
|
330
|
-
const templateParts = select(_coreData.store).getEntityRecords('postType', 'wp_template_part'
|
|
348
|
+
const templateParts = select(_coreData.store).getEntityRecords('postType', 'wp_template_part', {
|
|
349
|
+
per_page: -1
|
|
350
|
+
});
|
|
331
351
|
const templatePartsById = (0, _lodash.keyBy)(templateParts, templatePart => templatePart.id);
|
|
332
352
|
return ((_template$blocks = template.blocks) !== null && _template$blocks !== void 0 ? _template$blocks : []).filter(block => (0, _blocks.isTemplatePart)(block)).map(block => {
|
|
333
353
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/store/selectors.js"],"names":["isFeatureActive","state","feature","preferences","features","__experimentalGetPreviewDeviceType","deviceType","getCanUserCreateMedia","select","coreDataStore","canUser","getSettings","setIsInserterOpen","settings","outlineMode","focusMode","hasFixedToolbar","__experimentalSetIsInserterOpened","canUserCreateMedia","mediaUpload","onError","rest","wpAllowedMimeTypes","allowedMimeTypes","message","getHomeTemplateId","homeTemplateId","getCurrentEditedPost","editedPost","length","getPreviousEditedPost","getEditedPostType","type","getEditedPostId","id","getPreviousEditedPostType","getPreviousEditedPostId","getPage","page","getNavigationPanelActiveMenu","navigationPanel","menu","getCurrentTemplateNavigationPanelSubMenu","templateType","templateId","template","getEntityRecord","MENU_ROOT","find","submenu","area","MENU_TEMPLATE_PARTS","templates","getEntityRecords","showOnFront","getEditedEntityRecord","show_on_front","slug","MENU_TEMPLATES_UNUSED","isNavigationOpened","isOpen","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","rootClientId","insertionIndex","filterValue","isListViewOpened","listViewPanel","getCurrentTemplateTemplateParts","templateParts","templatePartsById","templatePart","blocks","filter","block","map","attributes","theme","templatePartId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AAMA;;AAvBA;AACA;AACA;;AAIA;AACA;AACA;;AAMA;AACA;AACA;;AAYA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,KAA1B,EAAiCC,OAAjC,EAA2C;AACjD,SAAO,iBAAKD,KAAK,CAACE,WAAN,CAAkBC,QAAvB,EAAiC,CAAEF,OAAF,CAAjC,EAA8C,KAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,kCAAT,CAA6CJ,KAA7C,EAAqD;AAC3D,SAAOA,KAAK,CAACK,UAAb;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,qBAAqB,GAAG,kCAA0BC,MAAF,IAAc,MAC1EA,MAAM,CAAEC,eAAF,CAAN,CAAwBC,OAAxB,CAAiC,QAAjC,EAA2C,OAA3C,CADoC,CAA9B;AAIP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,WAAW,GAAG,qBAC1B,CAAEV,KAAF,EAASW,iBAAT,KAAgC;AAC/B,QAAMC,QAAQ,GAAG,EAChB,GAAGZ,KAAK,CAACY,QADO;AAEhBC,IAAAA,WAAW,EAAE,IAFG;AAGhBC,IAAAA,SAAS,EAAEf,eAAe,CAAEC,KAAF,EAAS,WAAT,CAHV;AAIhBe,IAAAA,eAAe,EAAEhB,eAAe,CAAEC,KAAF,EAAS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AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,+BAA+B,GAAG,kCAC5C7D,MAAF,IAAgBP,KAAF,IAAa;AAAA;;AAC1B,QAAM0C,YAAY,GAAGZ,iBAAiB,CAAE9B,KAAF,CAAtC;AACA,QAAM2C,UAAU,GAAGX,eAAe,CAAEhC,KAAF,CAAlC;AACA,QAAM4C,QAAQ,GAAGrC,MAAM,CAAEC,eAAF,CAAN,CAAwB8C,qBAAxB,CAChB,UADgB,EAEhBZ,YAFgB,EAGhBC,UAHgB,CAAjB;AAMA,QAAM0B,aAAa,GAAG9D,MAAM,CAAEC,eAAF,CAAN,CAAwB4C,gBAAxB,CACrB,UADqB,EAErB,kBAFqB,CAAtB;AAIA,QAAMkB,iBAAiB,GAAG,mBACzBD,aADyB,EAEvBE,YAAF,IAAoBA,YAAY,CAACtC,EAFR,CAA1B;AAKA,SAAO,qBAAEW,QAAQ,CAAC4B,MAAX,+DAAqB,EAArB,EACLC,MADK,CACKC,KAAF,IAAa,4BAAgBA,KAAhB,CADhB,EAELC,GAFK,CAEED,KAAF,IAAa;AAClB,UAAM;AACLE,MAAAA,UAAU,EAAE;AAAEC,QAAAA,KAAF;AAASrB,QAAAA;AAAT;AADP,QAEFkB,KAFJ;AAGA,UAAMI,cAAc,GAAI,GAAGD,KAAO,KAAKrB,IAAM,EAA7C;AACA,UAAMe,YAAY,GAAGD,iBAAiB,CAAEQ,cAAF,CAAtC;AAEA,WAAO;AACNP,MAAAA,YADM;AAENG,MAAAA;AAFM,KAAP;AAIA,GAbK,EAcLD,MAdK,CAcG;AAAA,QAAE;AAAEF,MAAAA;AAAF,KAAF;AAAA,WAAwB,CAAC,CAAEA,YAA3B;AAAA,GAdH,CAAP;AAeA,CAlC6C,CAAxC","sourcesContent":["/**\n * External dependencies\n */\nimport { get, map, keyBy } from 'lodash';\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { createRegistrySelector } from '@wordpress/data';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { isTemplatePart } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tMENU_ROOT,\n\tMENU_TEMPLATE_PARTS,\n\tMENU_TEMPLATES_UNUSED,\n\tTEMPLATE_PARTS_SUB_MENUS,\n} from '../components/navigation-sidebar/navigation-panel/constants';\nimport {\n\tgetTemplateLocation,\n\tisTemplateSuperseded,\n} from '../components/navigation-sidebar/navigation-panel/template-hierarchy';\n\n/**\n * @typedef {'template'|'template_type'} TemplateType Template type.\n */\n\n/**\n * Returns whether the given feature is enabled or not.\n *\n * @param {Object} state Global application state.\n * @param {string} feature Feature slug.\n *\n * @return {boolean} Is active.\n */\nexport function isFeatureActive( state, feature ) {\n\treturn get( state.preferences.features, [ feature ], false );\n}\n\n/**\n * Returns the current editing canvas device type.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} Device type.\n */\nexport function __experimentalGetPreviewDeviceType( state ) {\n\treturn state.deviceType;\n}\n\n/**\n * Returns whether the current user can create media or not.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Whether the current user can create media or not.\n */\nexport const getCanUserCreateMedia = createRegistrySelector( ( select ) => () =>\n\tselect( coreDataStore ).canUser( 'create', 'media' )\n);\n\n/**\n * Returns the settings, taking into account active features and permissions.\n *\n * @param {Object} state Global application state.\n * @param {Function} setIsInserterOpen Setter for the open state of the global inserter.\n *\n * @return {Object} Settings.\n */\nexport const getSettings = createSelector(\n\t( state, setIsInserterOpen ) => {\n\t\tconst settings = {\n\t\t\t...state.settings,\n\t\t\toutlineMode: true,\n\t\t\tfocusMode: isFeatureActive( state, 'focusMode' ),\n\t\t\thasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ),\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpen,\n\t\t};\n\n\t\tconst canUserCreateMedia = getCanUserCreateMedia( state );\n\t\tif ( ! canUserCreateMedia ) {\n\t\t\treturn settings;\n\t\t}\n\n\t\tsettings.mediaUpload = ( { onError, ...rest } ) => {\n\t\t\tuploadMedia( {\n\t\t\t\twpAllowedMimeTypes: state.settings.allowedMimeTypes,\n\t\t\t\tonError: ( { message } ) => onError( message ),\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t};\n\t\treturn settings;\n\t},\n\t( state ) => [\n\t\tgetCanUserCreateMedia( state ),\n\t\tstate.settings,\n\t\tisFeatureActive( state, 'focusMode' ),\n\t\tisFeatureActive( state, 'fixedToolbar' ),\n\t]\n);\n\n/**\n * Returns the current home template ID.\n *\n * @param {Object} state Global application state.\n *\n * @return {number?} Home template ID.\n */\nexport function getHomeTemplateId( state ) {\n\treturn state.homeTemplateId;\n}\n\nfunction getCurrentEditedPost( state ) {\n\treturn state.editedPost[ state.editedPost.length - 1 ] || {};\n}\n\nfunction getPreviousEditedPost( state ) {\n\treturn state.editedPost[ state.editedPost.length - 2 ] || {};\n}\n\n/**\n * Returns the current edited post type (wp_template or wp_template_part).\n *\n * @param {Object} state Global application state.\n *\n * @return {TemplateType?} Template type.\n */\nexport function getEditedPostType( state ) {\n\treturn getCurrentEditedPost( state ).type;\n}\n\n/**\n * Returns the ID of the currently edited template or template part.\n *\n * @param {Object} state Global application state.\n *\n * @return {string?} Post ID.\n */\nexport function getEditedPostId( state ) {\n\treturn getCurrentEditedPost( state ).id;\n}\n\n/**\n * Returns the previous edited post type (wp_template or wp_template_part).\n *\n * @param {Object} state Global application state.\n *\n * @return {TemplateType?} Template type.\n */\nexport function getPreviousEditedPostType( state ) {\n\treturn getPreviousEditedPost( state ).type;\n}\n\n/**\n * Returns the ID of the previous edited template or template part.\n *\n * @param {Object} state Global application state.\n *\n * @return {string?} Post ID.\n */\nexport function getPreviousEditedPostId( state ) {\n\treturn getPreviousEditedPost( state ).id;\n}\n\n/**\n * Returns the current page object.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Page.\n */\nexport function getPage( state ) {\n\treturn getCurrentEditedPost( state ).page;\n}\n\n/**\n * Returns the active menu in the navigation panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} Active menu.\n */\nexport function getNavigationPanelActiveMenu( state ) {\n\treturn state.navigationPanel.menu;\n}\n\n/**\n * Returns the current template or template part's corresponding\n * navigation panel's sub menu, to be used with `openNavigationPanelToMenu`.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} The current template or template part's sub menu.\n */\nexport const getCurrentTemplateNavigationPanelSubMenu = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst templateType = getEditedPostType( state );\n\t\tconst templateId = getEditedPostId( state );\n\t\tconst template = templateId\n\t\t\t? select( coreDataStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplateType,\n\t\t\t\t\ttemplateId\n\t\t\t )\n\t\t\t: null;\n\n\t\tif ( ! template ) {\n\t\t\treturn MENU_ROOT;\n\t\t}\n\n\t\tif ( 'wp_template_part' === templateType ) {\n\t\t\treturn (\n\t\t\t\tTEMPLATE_PARTS_SUB_MENUS.find(\n\t\t\t\t\t( submenu ) => submenu.area === template?.area\n\t\t\t\t)?.menu || MENU_TEMPLATE_PARTS\n\t\t\t);\n\t\t}\n\n\t\tconst templates = select( coreDataStore ).getEntityRecords(\n\t\t\t'postType',\n\t\t\t'wp_template'\n\t\t);\n\t\tconst showOnFront = select( coreDataStore ).getEditedEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t).show_on_front;\n\n\t\tif (\n\t\t\tisTemplateSuperseded(\n\t\t\t\ttemplate.slug,\n\t\t\t\tmap( templates, 'slug' ),\n\t\t\t\tshowOnFront\n\t\t\t)\n\t\t) {\n\t\t\treturn MENU_TEMPLATES_UNUSED;\n\t\t}\n\n\t\treturn getTemplateLocation( template.slug );\n\t}\n);\n\n/**\n * Returns the current opened/closed state of the navigation panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the navigation panel should be open; false if closed.\n */\nexport function isNavigationOpened( state ) {\n\treturn state.navigationPanel.isOpen;\n}\n\n/**\n * Returns the current opened/closed state of the inserter panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the inserter panel should be open; false if closed.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID, index to insert at and starting filter value.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tconst {\n\t\trootClientId,\n\t\tinsertionIndex,\n\t\tfilterValue,\n\t} = state.blockInserterPanel;\n\treturn { rootClientId, insertionIndex, filterValue };\n}\n\n/**\n * Returns the current opened/closed state of the list view panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the list view panel should be open; false if closed.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns the template parts and their blocks for the current edited template.\n *\n * @param {Object} state Global application state.\n * @return {Array} Template parts and their blocks in an array.\n */\nexport const getCurrentTemplateTemplateParts = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst templateType = getEditedPostType( state );\n\t\tconst templateId = getEditedPostId( state );\n\t\tconst template = select( coreDataStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplateType,\n\t\t\ttemplateId\n\t\t);\n\n\t\tconst templateParts = select( coreDataStore ).getEntityRecords(\n\t\t\t'postType',\n\t\t\t'wp_template_part'\n\t\t);\n\t\tconst templatePartsById = keyBy(\n\t\t\ttemplateParts,\n\t\t\t( templatePart ) => templatePart.id\n\t\t);\n\n\t\treturn ( template.blocks ?? [] )\n\t\t\t.filter( ( block ) => isTemplatePart( block ) )\n\t\t\t.map( ( block ) => {\n\t\t\t\tconst {\n\t\t\t\t\tattributes: { theme, slug },\n\t\t\t\t} = block;\n\t\t\t\tconst templatePartId = `${ theme }//${ slug }`;\n\t\t\t\tconst templatePart = templatePartsById[ templatePartId ];\n\n\t\t\t\treturn {\n\t\t\t\t\ttemplatePart,\n\t\t\t\t\tblock,\n\t\t\t\t};\n\t\t\t} )\n\t\t\t.filter( ( { templatePart } ) => !! templatePart );\n\t}\n);\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/store/selectors.js"],"names":["isFeatureActive","state","feature","preferences","features","__experimentalGetPreviewDeviceType","deviceType","getCanUserCreateMedia","select","coreDataStore","canUser","getReusableBlocks","isWeb","Platform","OS","getEntityRecords","per_page","getSettings","setIsInserterOpen","settings","outlineMode","focusMode","hasFixedToolbar","__experimentalSetIsInserterOpened","__experimentalReusableBlocks","canUserCreateMedia","mediaUpload","onError","rest","wpAllowedMimeTypes","allowedMimeTypes","message","getHomeTemplateId","homeTemplateId","getCurrentEditedPost","editedPost","length","getPreviousEditedPost","getEditedPostType","type","getEditedPostId","id","getPreviousEditedPostType","getPreviousEditedPostId","getPage","page","getNavigationPanelActiveMenu","navigationPanel","menu","getCurrentTemplateNavigationPanelSubMenu","templateType","templateId","template","getEntityRecord","MENU_ROOT","find","submenu","area","MENU_TEMPLATE_PARTS","templates","showOnFront","getEditedEntityRecord","show_on_front","slug","MENU_TEMPLATES_UNUSED","isNavigationOpened","isOpen","isInserterOpened","blockInserterPanel","__experimentalGetInsertionPoint","rootClientId","insertionIndex","filterValue","isListViewOpened","listViewPanel","getCurrentTemplateTemplateParts","templateParts","templatePartsById","templatePart","blocks","filter","block","map","attributes","theme","templatePartId"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AAMA;;AAxBA;AACA;AACA;;AAIA;AACA;AACA;;AAOA;AACA;AACA;;AAYA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,KAA1B,EAAiCC,OAAjC,EAA2C;AACjD,SAAO,iBAAKD,KAAK,CAACE,WAAN,CAAkBC,QAAvB,EAAiC,CAAEF,OAAF,CAAjC,EAA8C,KAA9C,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA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AlC;AACA,QAAMmD,QAAQ,GAAG5C,MAAM,CAAEC,eAAF,CAAN,CAAwBoD,qBAAxB,CAChB,UADgB,EAEhBX,YAFgB,EAGhBC,UAHgB,CAAjB;AAMA,QAAMyB,aAAa,GAAGpE,MAAM,CAC3BC,eAD2B,CAAN,CAEpBM,gBAFoB,CAEF,UAFE,EAEU,kBAFV,EAE8B;AAAEC,IAAAA,QAAQ,EAAE,CAAC;AAAb,GAF9B,CAAtB;AAGA,QAAM6D,iBAAiB,GAAG,mBACzBD,aADyB,EAEvBE,YAAF,IAAoBA,YAAY,CAACrC,EAFR,CAA1B;AAKA,SAAO,qBAAEW,QAAQ,CAAC2B,MAAX,+DAAqB,EAArB,EACLC,MADK,CACKC,KAAF,IAAa,4BAAgBA,KAAhB,CADhB,EAELC,GAFK,CAEED,KAAF,IAAa;AAClB,UAAM;AACLE,MAAAA,UAAU,EAAE;AAAEC,QAAAA,KAAF;AAASrB,QAAAA;AAAT;AADP,QAEFkB,KAFJ;AAGA,UAAMI,cAAc,GAAI,GAAGD,KAAO,KAAKrB,IAAM,EAA7C;AACA,UAAMe,YAAY,GAAGD,iBAAiB,CAAEQ,cAAF,CAAtC;AAEA,WAAO;AACNP,MAAAA,YADM;AAENG,MAAAA;AAFM,KAAP;AAIA,GAbK,EAcLD,MAdK,CAcG;AAAA,QAAE;AAAEF,MAAAA;AAAF,KAAF;AAAA,WAAwB,CAAC,CAAEA,YAA3B;AAAA,GAdH,CAAP;AAeA,CAjC6C,CAAxC","sourcesContent":["/**\n * External dependencies\n */\nimport { get, map, keyBy } from 'lodash';\nimport createSelector from 'rememo';\n\n/**\n * WordPress dependencies\n */\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport { createRegistrySelector } from '@wordpress/data';\nimport { uploadMedia } from '@wordpress/media-utils';\nimport { isTemplatePart } from '@wordpress/blocks';\nimport { Platform } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tMENU_ROOT,\n\tMENU_TEMPLATE_PARTS,\n\tMENU_TEMPLATES_UNUSED,\n\tTEMPLATE_PARTS_SUB_MENUS,\n} from '../components/navigation-sidebar/navigation-panel/constants';\nimport {\n\tgetTemplateLocation,\n\tisTemplateSuperseded,\n} from '../components/navigation-sidebar/navigation-panel/template-hierarchy';\n\n/**\n * @typedef {'template'|'template_type'} TemplateType Template type.\n */\n\n/**\n * Returns whether the given feature is enabled or not.\n *\n * @param {Object} state Global application state.\n * @param {string} feature Feature slug.\n *\n * @return {boolean} Is active.\n */\nexport function isFeatureActive( state, feature ) {\n\treturn get( state.preferences.features, [ feature ], false );\n}\n\n/**\n * Returns the current editing canvas device type.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} Device type.\n */\nexport function __experimentalGetPreviewDeviceType( state ) {\n\treturn state.deviceType;\n}\n\n/**\n * Returns whether the current user can create media or not.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Whether the current user can create media or not.\n */\nexport const getCanUserCreateMedia = createRegistrySelector( ( select ) => () =>\n\tselect( coreDataStore ).canUser( 'create', 'media' )\n);\n\n/**\n * Returns any available Reusable blocks.\n *\n * @param {Object} state Global application state.\n *\n * @return {Array} The available reusable blocks.\n */\nexport const getReusableBlocks = createRegistrySelector( ( select ) => () => {\n\tconst isWeb = Platform.OS === 'web';\n\treturn isWeb\n\t\t? select( coreDataStore ).getEntityRecords( 'postType', 'wp_block', {\n\t\t\t\tper_page: -1,\n\t\t } )\n\t\t: [];\n} );\n\n/**\n * Returns the settings, taking into account active features and permissions.\n *\n * @param {Object} state Global application state.\n * @param {Function} setIsInserterOpen Setter for the open state of the global inserter.\n *\n * @return {Object} Settings.\n */\nexport const getSettings = createSelector(\n\t( state, setIsInserterOpen ) => {\n\t\tconst settings = {\n\t\t\t...state.settings,\n\t\t\toutlineMode: true,\n\t\t\tfocusMode: isFeatureActive( state, 'focusMode' ),\n\t\t\thasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ),\n\t\t\t__experimentalSetIsInserterOpened: setIsInserterOpen,\n\t\t\t__experimentalReusableBlocks: getReusableBlocks( state ),\n\t\t};\n\n\t\tconst canUserCreateMedia = getCanUserCreateMedia( state );\n\t\tif ( ! canUserCreateMedia ) {\n\t\t\treturn settings;\n\t\t}\n\n\t\tsettings.mediaUpload = ( { onError, ...rest } ) => {\n\t\t\tuploadMedia( {\n\t\t\t\twpAllowedMimeTypes: state.settings.allowedMimeTypes,\n\t\t\t\tonError: ( { message } ) => onError( message ),\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t};\n\t\treturn settings;\n\t},\n\t( state ) => [\n\t\tgetCanUserCreateMedia( state ),\n\t\tstate.settings,\n\t\tisFeatureActive( state, 'focusMode' ),\n\t\tisFeatureActive( state, 'fixedToolbar' ),\n\t\tgetReusableBlocks( state ),\n\t]\n);\n\n/**\n * Returns the current home template ID.\n *\n * @param {Object} state Global application state.\n *\n * @return {number?} Home template ID.\n */\nexport function getHomeTemplateId( state ) {\n\treturn state.homeTemplateId;\n}\n\nfunction getCurrentEditedPost( state ) {\n\treturn state.editedPost[ state.editedPost.length - 1 ] || {};\n}\n\nfunction getPreviousEditedPost( state ) {\n\treturn state.editedPost[ state.editedPost.length - 2 ] || {};\n}\n\n/**\n * Returns the current edited post type (wp_template or wp_template_part).\n *\n * @param {Object} state Global application state.\n *\n * @return {TemplateType?} Template type.\n */\nexport function getEditedPostType( state ) {\n\treturn getCurrentEditedPost( state ).type;\n}\n\n/**\n * Returns the ID of the currently edited template or template part.\n *\n * @param {Object} state Global application state.\n *\n * @return {string?} Post ID.\n */\nexport function getEditedPostId( state ) {\n\treturn getCurrentEditedPost( state ).id;\n}\n\n/**\n * Returns the previous edited post type (wp_template or wp_template_part).\n *\n * @param {Object} state Global application state.\n *\n * @return {TemplateType?} Template type.\n */\nexport function getPreviousEditedPostType( state ) {\n\treturn getPreviousEditedPost( state ).type;\n}\n\n/**\n * Returns the ID of the previous edited template or template part.\n *\n * @param {Object} state Global application state.\n *\n * @return {string?} Post ID.\n */\nexport function getPreviousEditedPostId( state ) {\n\treturn getPreviousEditedPost( state ).id;\n}\n\n/**\n * Returns the current page object.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} Page.\n */\nexport function getPage( state ) {\n\treturn getCurrentEditedPost( state ).page;\n}\n\n/**\n * Returns the active menu in the navigation panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} Active menu.\n */\nexport function getNavigationPanelActiveMenu( state ) {\n\treturn state.navigationPanel.menu;\n}\n\n/**\n * Returns the current template or template part's corresponding\n * navigation panel's sub menu, to be used with `openNavigationPanelToMenu`.\n *\n * @param {Object} state Global application state.\n *\n * @return {string} The current template or template part's sub menu.\n */\nexport const getCurrentTemplateNavigationPanelSubMenu = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst templateType = getEditedPostType( state );\n\t\tconst templateId = getEditedPostId( state );\n\t\tconst template = templateId\n\t\t\t? select( coreDataStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplateType,\n\t\t\t\t\ttemplateId\n\t\t\t )\n\t\t\t: null;\n\n\t\tif ( ! template ) {\n\t\t\treturn MENU_ROOT;\n\t\t}\n\n\t\tif ( 'wp_template_part' === templateType ) {\n\t\t\treturn (\n\t\t\t\tTEMPLATE_PARTS_SUB_MENUS.find(\n\t\t\t\t\t( submenu ) => submenu.area === template?.area\n\t\t\t\t)?.menu || MENU_TEMPLATE_PARTS\n\t\t\t);\n\t\t}\n\n\t\tconst templates = select( coreDataStore ).getEntityRecords(\n\t\t\t'postType',\n\t\t\t'wp_template'\n\t\t);\n\t\tconst showOnFront = select( coreDataStore ).getEditedEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t).show_on_front;\n\n\t\tif (\n\t\t\tisTemplateSuperseded(\n\t\t\t\ttemplate.slug,\n\t\t\t\tmap( templates, 'slug' ),\n\t\t\t\tshowOnFront\n\t\t\t)\n\t\t) {\n\t\t\treturn MENU_TEMPLATES_UNUSED;\n\t\t}\n\n\t\treturn getTemplateLocation( template.slug );\n\t}\n);\n\n/**\n * Returns the current opened/closed state of the navigation panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the navigation panel should be open; false if closed.\n */\nexport function isNavigationOpened( state ) {\n\treturn state.navigationPanel.isOpen;\n}\n\n/**\n * Returns the current opened/closed state of the inserter panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the inserter panel should be open; false if closed.\n */\nexport function isInserterOpened( state ) {\n\treturn !! state.blockInserterPanel;\n}\n\n/**\n * Get the insertion point for the inserter.\n *\n * @param {Object} state Global application state.\n *\n * @return {Object} The root client ID, index to insert at and starting filter value.\n */\nexport function __experimentalGetInsertionPoint( state ) {\n\tconst {\n\t\trootClientId,\n\t\tinsertionIndex,\n\t\tfilterValue,\n\t} = state.blockInserterPanel;\n\treturn { rootClientId, insertionIndex, filterValue };\n}\n\n/**\n * Returns the current opened/closed state of the list view panel.\n *\n * @param {Object} state Global application state.\n *\n * @return {boolean} True if the list view panel should be open; false if closed.\n */\nexport function isListViewOpened( state ) {\n\treturn state.listViewPanel;\n}\n\n/**\n * Returns the template parts and their blocks for the current edited template.\n *\n * @param {Object} state Global application state.\n * @return {Array} Template parts and their blocks in an array.\n */\nexport const getCurrentTemplateTemplateParts = createRegistrySelector(\n\t( select ) => ( state ) => {\n\t\tconst templateType = getEditedPostType( state );\n\t\tconst templateId = getEditedPostId( state );\n\t\tconst template = select( coreDataStore ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\ttemplateType,\n\t\t\ttemplateId\n\t\t);\n\n\t\tconst templateParts = select(\n\t\t\tcoreDataStore\n\t\t).getEntityRecords( 'postType', 'wp_template_part', { per_page: -1 } );\n\t\tconst templatePartsById = keyBy(\n\t\t\ttemplateParts,\n\t\t\t( templatePart ) => templatePart.id\n\t\t);\n\n\t\treturn ( template.blocks ?? [] )\n\t\t\t.filter( ( block ) => isTemplatePart( block ) )\n\t\t\t.map( ( block ) => {\n\t\t\t\tconst {\n\t\t\t\t\tattributes: { theme, slug },\n\t\t\t\t} = block;\n\t\t\t\tconst templatePartId = `${ theme }//${ slug }`;\n\t\t\t\tconst templatePart = templatePartsById[ templatePartId ];\n\n\t\t\t\treturn {\n\t\t\t\t\ttemplatePart,\n\t\t\t\t\tblock,\n\t\t\t\t};\n\t\t\t} )\n\t\t\t.filter( ( { templatePart } ) => !! templatePart );\n\t}\n);\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isTemplateRemovable;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if a template is removable.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} template The template entity to check.
|
|
12
|
+
* @return {boolean} Whether the template is revertable.
|
|
13
|
+
*/
|
|
14
|
+
function isTemplateRemovable(template) {
|
|
15
|
+
if (!template) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return template.source === 'custom' && !template.has_theme_file;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=is-template-removable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/utils/is-template-removable.js"],"names":["isTemplateRemovable","template","source","has_theme_file"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,CAA8BC,QAA9B,EAAyC;AACvD,MAAK,CAAEA,QAAP,EAAkB;AACjB,WAAO,KAAP;AACA;;AAED,SAAOA,QAAQ,CAACC,MAAT,KAAoB,QAApB,IAAgC,CAAED,QAAQ,CAACE,cAAlD;AACA","sourcesContent":["/**\n * Check if a template is removable.\n *\n * @param {Object} template The template entity to check.\n * @return {boolean} Whether the template is revertable.\n */\nexport default function isTemplateRemovable( template ) {\n\tif ( ! template ) {\n\t\treturn false;\n\t}\n\n\treturn template.source === 'custom' && ! template.has_theme_file;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { useSelect } from '@wordpress/data';
|
|
7
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
8
|
+
/**
|
|
9
|
+
* Internal dependencies
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import NewTemplate from './new-template';
|
|
13
|
+
import NewTemplatePart from './new-template-part';
|
|
14
|
+
export default function AddNewTemplate(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
templateType = 'wp_template'
|
|
17
|
+
} = _ref;
|
|
18
|
+
const postType = useSelect(select => select(coreStore).getPostType(templateType), [templateType]);
|
|
19
|
+
|
|
20
|
+
if (!postType) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (templateType === 'wp_template') {
|
|
25
|
+
return createElement(NewTemplate, {
|
|
26
|
+
postType: postType
|
|
27
|
+
});
|
|
28
|
+
} else if (templateType === 'wp_template_part') {
|
|
29
|
+
return createElement(NewTemplatePart, {
|
|
30
|
+
postType: postType
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"names":["useSelect","store","coreStore","NewTemplate","NewTemplatePart","AddNewTemplate","templateType","postType","select","getPostType"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AACA,OAAOC,eAAP,MAA4B,qBAA5B;AAEA,eAAe,SAASC,cAAT,OAA4D;AAAA,MAAnC;AAAEC,IAAAA,YAAY,GAAG;AAAjB,GAAmC;AAC1E,QAAMC,QAAQ,GAAGP,SAAS,CACvBQ,MAAF,IAAcA,MAAM,CAAEN,SAAF,CAAN,CAAoBO,WAApB,CAAiCH,YAAjC,CADW,EAEzB,CAAEA,YAAF,CAFyB,CAA1B;;AAKA,MAAK,CAAEC,QAAP,EAAkB;AACjB,WAAO,IAAP;AACA;;AAED,MAAKD,YAAY,KAAK,aAAtB,EAAsC;AACrC,WAAO,cAAC,WAAD;AAAa,MAAA,QAAQ,EAAGC;AAAxB,MAAP;AACA,GAFD,MAEO,IAAKD,YAAY,KAAK,kBAAtB,EAA2C;AACjD,WAAO,cAAC,eAAD;AAAiB,MAAA,QAAQ,EAAGC;AAA5B,MAAP;AACA;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport NewTemplate from './new-template';\nimport NewTemplatePart from './new-template-part';\n\nexport default function AddNewTemplate( { templateType = 'wp_template' } ) {\n\tconst postType = useSelect(\n\t\t( select ) => select( coreStore ).getPostType( templateType ),\n\t\t[ templateType ]\n\t);\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\tif ( templateType === 'wp_template' ) {\n\t\treturn <NewTemplate postType={ postType } />;\n\t} else if ( templateType === 'wp_template_part' ) {\n\t\treturn <NewTemplatePart postType={ postType } />;\n\t}\n\n\treturn null;\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { kebabCase } from 'lodash';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useState } from '@wordpress/element';
|
|
12
|
+
import { useDispatch } from '@wordpress/data';
|
|
13
|
+
import { Button } from '@wordpress/components';
|
|
14
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
15
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
16
|
+
import { __ } from '@wordpress/i18n';
|
|
17
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
18
|
+
/**
|
|
19
|
+
* Internal dependencies
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import CreateTemplatePartModal from '../create-template-part-modal';
|
|
23
|
+
export default function NewTemplatePart(_ref) {
|
|
24
|
+
let {
|
|
25
|
+
postType
|
|
26
|
+
} = _ref;
|
|
27
|
+
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
28
|
+
const {
|
|
29
|
+
createErrorNotice
|
|
30
|
+
} = useDispatch(noticesStore);
|
|
31
|
+
|
|
32
|
+
async function createTemplatePart(_ref2) {
|
|
33
|
+
let {
|
|
34
|
+
title,
|
|
35
|
+
area
|
|
36
|
+
} = _ref2;
|
|
37
|
+
|
|
38
|
+
if (!title) {
|
|
39
|
+
createErrorNotice(__('Title is not defined.'), {
|
|
40
|
+
type: 'snackbar'
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const templatePart = await apiFetch({
|
|
47
|
+
path: '/wp/v2/template-parts',
|
|
48
|
+
method: 'POST',
|
|
49
|
+
data: {
|
|
50
|
+
slug: kebabCase(title),
|
|
51
|
+
title,
|
|
52
|
+
content: '',
|
|
53
|
+
area
|
|
54
|
+
}
|
|
55
|
+
}); // Navigate to the created template part editor.
|
|
56
|
+
|
|
57
|
+
window.location.href = addQueryArgs(window.location.href, {
|
|
58
|
+
postId: templatePart.id,
|
|
59
|
+
postType: 'wp_template_part'
|
|
60
|
+
});
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the template part.');
|
|
63
|
+
createErrorNotice(errorMessage, {
|
|
64
|
+
type: 'snackbar'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return createElement(Fragment, null, createElement(Button, {
|
|
70
|
+
variant: "primary",
|
|
71
|
+
onClick: () => {
|
|
72
|
+
setIsModalOpen(true);
|
|
73
|
+
}
|
|
74
|
+
}, postType.labels.add_new), isModalOpen && createElement(CreateTemplatePartModal, {
|
|
75
|
+
closeModal: () => setIsModalOpen(false),
|
|
76
|
+
onCreate: createTemplatePart
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=new-template-part.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template-part.js"],"names":["kebabCase","useState","useDispatch","Button","addQueryArgs","apiFetch","__","store","noticesStore","CreateTemplatePartModal","NewTemplatePart","postType","isModalOpen","setIsModalOpen","createErrorNotice","createTemplatePart","title","area","type","templatePart","path","method","data","slug","content","window","location","href","postId","id","error","errorMessage","message","code","labels","add_new"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,uBAAP,MAAoC,+BAApC;AAEA,eAAe,SAASC,eAAT,OAAyC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AACvD,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkCZ,QAAQ,CAAE,KAAF,CAAhD;AACA,QAAM;AAAEa,IAAAA;AAAF,MAAwBZ,WAAW,CAAEM,YAAF,CAAzC;;AAEA,iBAA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ACZ,cAAC,uBAAD;AACC,IAAA,UAAU,EAAG,MAAMC,cAAc,CAAE,KAAF,CADlC;AAEC,IAAA,QAAQ,EAAGE;AAFZ,IAVF,CADD;AAkBA","sourcesContent":["/**\n * External dependencies\n */\nimport { kebabCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { Button } from '@wordpress/components';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport CreateTemplatePartModal from '../create-template-part-modal';\n\nexport default function NewTemplatePart( { postType } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tasync function createTemplatePart( { title, area } ) {\n\t\tif ( ! title ) {\n\t\t\tcreateErrorNotice( __( 'Title is not defined.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst templatePart = await apiFetch( {\n\t\t\t\tpath: '/wp/v2/template-parts',\n\t\t\t\tmethod: 'POST',\n\t\t\t\tdata: {\n\t\t\t\t\tslug: kebabCase( title ),\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: '',\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Navigate to the created template part editor.\n\t\t\twindow.location.href = addQueryArgs( window.location.href, {\n\t\t\t\tpostId: templatePart.id,\n\t\t\t\tpostType: 'wp_template_part',\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => {\n\t\t\t\t\tsetIsModalOpen( true );\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new }\n\t\t\t</Button>\n\t\t\t{ isModalOpen && (\n\t\t\t\t<CreateTemplatePartModal\n\t\t\t\t\tcloseModal={ () => setIsModalOpen( false ) }\n\t\t\t\t\tonCreate={ createTemplatePart }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { filter, find, includes, map } from 'lodash';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { DropdownMenu, MenuGroup, MenuItem, NavigableMenu } from '@wordpress/components';
|
|
12
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
13
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
14
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
15
|
+
import { addQueryArgs } from '@wordpress/url';
|
|
16
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
17
|
+
import { __ } from '@wordpress/i18n';
|
|
18
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
19
|
+
const DEFAULT_TEMPLATE_SLUGS = ['front-page', 'single-post', 'page', 'archive', 'search', '404', 'index'];
|
|
20
|
+
export default function NewTemplate(_ref) {
|
|
21
|
+
let {
|
|
22
|
+
postType
|
|
23
|
+
} = _ref;
|
|
24
|
+
const {
|
|
25
|
+
templates,
|
|
26
|
+
defaultTemplateTypes
|
|
27
|
+
} = useSelect(select => ({
|
|
28
|
+
templates: select(coreStore).getEntityRecords('postType', 'wp_template', {
|
|
29
|
+
per_page: -1
|
|
30
|
+
}),
|
|
31
|
+
defaultTemplateTypes: select(editorStore).__experimentalGetDefaultTemplateTypes()
|
|
32
|
+
}), []);
|
|
33
|
+
const {
|
|
34
|
+
createErrorNotice
|
|
35
|
+
} = useDispatch(noticesStore);
|
|
36
|
+
|
|
37
|
+
async function createTemplate(_ref2) {
|
|
38
|
+
let {
|
|
39
|
+
slug
|
|
40
|
+
} = _ref2;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const {
|
|
44
|
+
title,
|
|
45
|
+
description
|
|
46
|
+
} = find(defaultTemplateTypes, {
|
|
47
|
+
slug
|
|
48
|
+
});
|
|
49
|
+
const template = await apiFetch({
|
|
50
|
+
path: '/wp/v2/templates',
|
|
51
|
+
method: 'POST',
|
|
52
|
+
data: {
|
|
53
|
+
excerpt: description,
|
|
54
|
+
// Slugs need to be strings, so this is for template `404`
|
|
55
|
+
slug: slug.toString(),
|
|
56
|
+
status: 'publish',
|
|
57
|
+
title
|
|
58
|
+
}
|
|
59
|
+
}); // Navigate to the created template editor.
|
|
60
|
+
|
|
61
|
+
window.location.href = addQueryArgs(window.location.href, {
|
|
62
|
+
postId: template.id,
|
|
63
|
+
postType: 'wp_template'
|
|
64
|
+
}); // Wait for async navigation to happen before closing the modal.
|
|
65
|
+
|
|
66
|
+
await new Promise(() => {});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the template.');
|
|
69
|
+
createErrorNotice(errorMessage, {
|
|
70
|
+
type: 'snackbar'
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const existingTemplateSlugs = map(templates, 'slug');
|
|
76
|
+
const missingTemplates = filter(defaultTemplateTypes, template => includes(DEFAULT_TEMPLATE_SLUGS, template.slug) && !includes(existingTemplateSlugs, template.slug));
|
|
77
|
+
|
|
78
|
+
if (!missingTemplates.length) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return createElement(DropdownMenu, {
|
|
83
|
+
className: "edit-site-new-template-dropdown",
|
|
84
|
+
icon: null,
|
|
85
|
+
text: postType.labels.add_new,
|
|
86
|
+
label: postType.labels.add_new_item,
|
|
87
|
+
popoverProps: {
|
|
88
|
+
noArrow: false
|
|
89
|
+
},
|
|
90
|
+
toggleProps: {
|
|
91
|
+
variant: 'primary'
|
|
92
|
+
}
|
|
93
|
+
}, () => createElement(NavigableMenu, {
|
|
94
|
+
className: "edit-site-new-template-dropdown__popover"
|
|
95
|
+
}, createElement(MenuGroup, {
|
|
96
|
+
label: postType.labels.add_new_item
|
|
97
|
+
}, map(missingTemplates, _ref3 => {
|
|
98
|
+
let {
|
|
99
|
+
title,
|
|
100
|
+
description,
|
|
101
|
+
slug
|
|
102
|
+
} = _ref3;
|
|
103
|
+
return createElement(MenuItem, {
|
|
104
|
+
info: description,
|
|
105
|
+
key: slug,
|
|
106
|
+
onClick: () => {
|
|
107
|
+
createTemplate({
|
|
108
|
+
slug
|
|
109
|
+
}); // We will be navigated way so no need to close the dropdown.
|
|
110
|
+
}
|
|
111
|
+
}, title);
|
|
112
|
+
}))));
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=new-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["filter","find","includes","map","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useSelect","useDispatch","store","coreStore","editorStore","addQueryArgs","apiFetch","__","noticesStore","DEFAULT_TEMPLATE_SLUGS","NewTemplate","postType","templates","defaultTemplateTypes","select","getEntityRecords","per_page","__experimentalGetDefaultTemplateTypes","createErrorNotice","createTemplate","slug","title","description","template","path","method","data","excerpt","toString","status","window","location","href","postId","id","Promise","error","errorMessage","message","code","type","existingTemplateSlugs","missingTemplates","length","labels","add_new","add_new_item","noArrow","variant"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,MAAT,EA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,MAAxB,EAAiC;AAChC,WAAO,IAAP;AACA;;AAED,SACC,cAAC,YAAD;AACC,IAAA,SAAS,EAAC,iCADX;AAEC,IAAA,IAAI,EAAG,IAFR;AAGC,IAAA,IAAI,EAAGhC,QAAQ,CAACiC,MAAT,CAAgBC,OAHxB;AAIC,IAAA,KAAK,EAAGlC,QAAQ,CAACiC,MAAT,CAAgBE,YAJzB;AAKC,IAAA,YAAY,EAAG;AACdC,MAAAA,OAAO,EAAE;AADK,KALhB;AAQC,IAAA,WAAW,EAAG;AACbC,MAAAA,OAAO,EAAE;AADI;AARf,KAYG,MACD,cAAC,aAAD;AAAe,IAAA,SAAS,EAAC;AAAzB,KACC,cAAC,SAAD;AAAW,IAAA,KAAK,EAAGrC,QAAQ,CAACiC,MAAT,CAAgBE;AAAnC,KACGnD,GAAG,CACJ+C,gBADI,EAEJ;AAAA,QAAE;AAAErB,MAAAA,KAAF;AAASC,MAAAA,WAAT;AAAsBF,MAAAA;AAAtB,KAAF;AAAA,WACC,cAAC,QAAD;AACC,MAAA,IAAI,EAAGE,WADR;AAEC,MAAA,GAAG,EAAGF,IAFP;AAGC,MAAA,OAAO,EAAG,MAAM;AACfD,QAAAA,cAAc,CAAE;AAAEC,UAAAA;AAAF,SAAF,CAAd,CADe,CAEf;AACA;AANF,OAQGC,KARH,CADD;AAAA,GAFI,CADN,CADD,CAbF,CADD;AAoCA","sourcesContent":["/**\n * External dependencies\n */\nimport { filter, find, includes, map } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single-post',\n\t'page',\n\t'archive',\n\t'search',\n\t'404',\n\t'index',\n];\n\nexport default function NewTemplate( { postType } ) {\n\tconst { templates, defaultTemplateTypes } = useSelect(\n\t\t( select ) => ( {\n\t\t\ttemplates: select( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{ per_page: -1 }\n\t\t\t),\n\t\t\tdefaultTemplateTypes: select(\n\t\t\t\teditorStore\n\t\t\t).__experimentalGetDefaultTemplateTypes(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tasync function createTemplate( { slug } ) {\n\t\ttry {\n\t\t\tconst { title, description } = find( defaultTemplateTypes, {\n\t\t\t\tslug,\n\t\t\t} );\n\n\t\t\tconst template = await apiFetch( {\n\t\t\t\tpath: '/wp/v2/templates',\n\t\t\t\tmethod: 'POST',\n\t\t\t\tdata: {\n\t\t\t\t\texcerpt: description,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\twindow.location.href = addQueryArgs( window.location.href, {\n\t\t\t\tpostId: template.id,\n\t\t\t\tpostType: 'wp_template',\n\t\t\t} );\n\n\t\t\t// Wait for async navigation to happen before closing the modal.\n\t\t\tawait new Promise( () => {} );\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst existingTemplateSlugs = map( templates, 'slug' );\n\n\tconst missingTemplates = filter(\n\t\tdefaultTemplateTypes,\n\t\t( template ) =>\n\t\t\tincludes( DEFAULT_TEMPLATE_SLUGS, template.slug ) &&\n\t\t\t! includes( existingTemplateSlugs, template.slug )\n\t);\n\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<DropdownMenu\n\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\ticon={ null }\n\t\t\ttext={ postType.labels.add_new }\n\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\tpopoverProps={ {\n\t\t\t\tnoArrow: false,\n\t\t\t} }\n\t\t\ttoggleProps={ {\n\t\t\t\tvariant: 'primary',\n\t\t\t} }\n\t\t>\n\t\t\t{ () => (\n\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t{ map(\n\t\t\t\t\t\t\tmissingTemplates,\n\t\t\t\t\t\t\t( { title, description, slug } ) => (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tcreateTemplate( { slug } );\n\t\t\t\t\t\t\t\t\t\t// We will be navigated way so no need to close the dropdown.\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t</NavigableMenu>\n\t\t\t) }\n\t\t</DropdownMenu>\n\t);\n}\n"]}
|
|
@@ -14,6 +14,7 @@ import { useCallback, useRef } from '@wordpress/element';
|
|
|
14
14
|
import { useEntityBlockEditor } from '@wordpress/core-data';
|
|
15
15
|
import { BlockList, BlockEditorProvider, __experimentalLinkControl, BlockInspector, BlockTools, __unstableBlockSettingsMenuFirstItem, __unstableUseTypingObserver as useTypingObserver, store as blockEditorStore } from '@wordpress/block-editor';
|
|
16
16
|
import { useMergeRefs, useViewportMatch } from '@wordpress/compose';
|
|
17
|
+
import { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';
|
|
17
18
|
/**
|
|
18
19
|
* Internal dependencies
|
|
19
20
|
*/
|
|
@@ -102,6 +103,6 @@ export default function BlockEditor(_ref) {
|
|
|
102
103
|
return createElement(BlockInspectorButton, {
|
|
103
104
|
onClick: onClose
|
|
104
105
|
});
|
|
105
|
-
})));
|
|
106
|
+
})), createElement(ReusableBlocksMenuItems, null));
|
|
106
107
|
}
|
|
107
108
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/index.js"],"names":["classnames","useSelect","useDispatch","useCallback","useRef","useEntityBlockEditor","BlockList","BlockEditorProvider","__experimentalLinkControl","BlockInspector","BlockTools","__unstableBlockSettingsMenuFirstItem","__unstableUseTypingObserver","useTypingObserver","store","blockEditorStore","useMergeRefs","useViewportMatch","TemplatePartConverter","NavigateToLink","SidebarInspectorFill","editSiteStore","BlockInspectorButton","EditTemplatePartMenuButton","BackButton","ResizableEditor","LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","settings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","blocks","onInput","onChange","setPage","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","isTemplatePart","fillProps","event","target","currentTarget","onClose"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,MAAtB,QAAoC,oBAApC;AACA,SAASC,oBAAT,QAAqC,sBAArC;AACA,SACCC,SADD,EAECC,mBAFD,EAGCC,yBAHD,EAICC,cAJD,EAKCC,UALD,EAMCC,oCAND,EAOCC,2BAA2B,IAAIC,iBAPhC,EAQCC,KAAK,IAAIC,gBARV,QASO,yBATP;AAUA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,oBAA/C;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,cAAP,MAA2B,qBAA3B;AACA,SAASC,oBAAT,QAAqC,YAArC;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/block-editor/index.js"],"names":["classnames","useSelect","useDispatch","useCallback","useRef","useEntityBlockEditor","BlockList","BlockEditorProvider","__experimentalLinkControl","BlockInspector","BlockTools","__unstableBlockSettingsMenuFirstItem","__unstableUseTypingObserver","useTypingObserver","store","blockEditorStore","useMergeRefs","useViewportMatch","ReusableBlocksMenuItems","TemplatePartConverter","NavigateToLink","SidebarInspectorFill","editSiteStore","BlockInspectorButton","EditTemplatePartMenuButton","BackButton","ResizableEditor","LAYOUT","type","alignments","BlockEditor","setIsInserterOpen","settings","templateType","templateId","page","select","getSettings","getEditedPostType","getEditedPostId","getPage","blocks","onInput","onChange","setPage","contentRef","mergedRefs","isMobileViewport","clearSelectedBlock","isTemplatePart","fillProps","event","target","currentTarget","onClose"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,iBAAvC;AACA,SAASC,WAAT,EAAsBC,MAAtB,QAAoC,oBAApC;AACA,SAASC,oBAAT,QAAqC,sBAArC;AACA,SACCC,SADD,EAECC,mBAFD,EAGCC,yBAHD,EAICC,cAJD,EAKCC,UALD,EAMCC,oCAND,EAOCC,2BAA2B,IAAIC,iBAPhC,EAQCC,KAAK,IAAIC,gBARV,QASO,yBATP;AAUA,SAASC,YAAT,EAAuBC,gBAAvB,QAA+C,oBAA/C;AACA,SAASC,uBAAT,QAAwC,4BAAxC;AAEA;AACA;AACA;;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,cAAP,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A+BC,cAAC,oCAAD,QACG;AAAA,QAAE;AAAE2B,MAAAA;AAAF,KAAF;AAAA,WACD,cAAC,oBAAD;AAAsB,MAAA,OAAO,EAAGA;AAAhC,MADC;AAAA,GADH,CA/BD,CAxBD,EA6DC,cAAC,uBAAD,OA7DD,CADD;AAiEA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useEntityBlockEditor } from '@wordpress/core-data';\nimport {\n\tBlockList,\n\tBlockEditorProvider,\n\t__experimentalLinkControl,\n\tBlockInspector,\n\tBlockTools,\n\t__unstableBlockSettingsMenuFirstItem,\n\t__unstableUseTypingObserver as useTypingObserver,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useMergeRefs, useViewportMatch } from '@wordpress/compose';\nimport { ReusableBlocksMenuItems } from '@wordpress/reusable-blocks';\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 { settings, 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\tsettings: 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\tconst [ blocks, onInput, onChange ] = useEntityBlockEditor(\n\t\t'postType',\n\t\ttemplateType\n\t);\n\tconst { setPage } = useDispatch( editSiteStore );\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\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<BackButton />\n\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/>\n\t\t\t\t</ResizableEditor>\n\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</BlockTools>\n\t\t\t<ReusableBlocksMenuItems />\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createElement } from "@wordpress/element";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WordPress dependencies
|
|
5
|
+
*/
|
|
6
|
+
import { useSelect } from '@wordpress/data';
|
|
7
|
+
import { Icon, BaseControl, TextControl, Flex, FlexItem, FlexBlock, Button, Modal, __experimentalRadioGroup as RadioGroup, __experimentalRadio as Radio } from '@wordpress/components';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
11
|
+
import { store as editorStore } from '@wordpress/editor';
|
|
12
|
+
import { check } from '@wordpress/icons';
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { TEMPLATE_PART_AREA_GENERAL } from '../../store/constants';
|
|
18
|
+
export default function CreateTemplatePartModal(_ref) {
|
|
19
|
+
let {
|
|
20
|
+
closeModal,
|
|
21
|
+
onCreate
|
|
22
|
+
} = _ref;
|
|
23
|
+
const [title, setTitle] = useState('');
|
|
24
|
+
const [area, setArea] = useState(TEMPLATE_PART_AREA_GENERAL);
|
|
25
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
26
|
+
const instanceId = useInstanceId(CreateTemplatePartModal);
|
|
27
|
+
const templatePartAreas = useSelect(select => select(editorStore).__experimentalGetDefaultTemplatePartAreas(), []);
|
|
28
|
+
return createElement(Modal, {
|
|
29
|
+
title: __('Create a template part'),
|
|
30
|
+
closeLabel: __('Close'),
|
|
31
|
+
onRequestClose: closeModal,
|
|
32
|
+
overlayClassName: "edit-site-create-template-part-modal"
|
|
33
|
+
}, createElement("form", {
|
|
34
|
+
onSubmit: async event => {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
|
|
37
|
+
if (!title) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setIsSubmitting(true);
|
|
42
|
+
await onCreate({
|
|
43
|
+
title,
|
|
44
|
+
area
|
|
45
|
+
});
|
|
46
|
+
setIsSubmitting(false);
|
|
47
|
+
closeModal();
|
|
48
|
+
}
|
|
49
|
+
}, createElement(TextControl, {
|
|
50
|
+
label: __('Name'),
|
|
51
|
+
value: title,
|
|
52
|
+
onChange: setTitle,
|
|
53
|
+
required: true
|
|
54
|
+
}), createElement(BaseControl, {
|
|
55
|
+
label: __('Area'),
|
|
56
|
+
id: `edit-site-create-template-part-modal__area-selection-${instanceId}`,
|
|
57
|
+
className: "edit-site-create-template-part-modal__area-base-control"
|
|
58
|
+
}, createElement(RadioGroup, {
|
|
59
|
+
label: __('Area'),
|
|
60
|
+
className: "edit-site-create-template-part-modal__area-radio-group",
|
|
61
|
+
id: `edit-site-create-template-part-modal__area-selection-${instanceId}`,
|
|
62
|
+
onChange: setArea,
|
|
63
|
+
checked: area
|
|
64
|
+
}, templatePartAreas.map(_ref2 => {
|
|
65
|
+
let {
|
|
66
|
+
icon,
|
|
67
|
+
label,
|
|
68
|
+
area: value,
|
|
69
|
+
description
|
|
70
|
+
} = _ref2;
|
|
71
|
+
return createElement(Radio, {
|
|
72
|
+
key: label,
|
|
73
|
+
value: value,
|
|
74
|
+
className: "edit-site-create-template-part-modal__area-radio"
|
|
75
|
+
}, createElement(Flex, {
|
|
76
|
+
align: "start",
|
|
77
|
+
justify: "start"
|
|
78
|
+
}, createElement(FlexItem, null, createElement(Icon, {
|
|
79
|
+
icon: icon
|
|
80
|
+
})), createElement(FlexBlock, {
|
|
81
|
+
className: "edit-site-create-template-part-modal__option-label"
|
|
82
|
+
}, label, createElement("div", null, description)), createElement(FlexItem, {
|
|
83
|
+
className: "edit-site-create-template-part-modal__checkbox"
|
|
84
|
+
}, area === value && createElement(Icon, {
|
|
85
|
+
icon: check
|
|
86
|
+
}))));
|
|
87
|
+
}))), createElement(Flex, {
|
|
88
|
+
className: "edit-site-create-template-part-modal__modal-actions",
|
|
89
|
+
justify: "flex-end"
|
|
90
|
+
}, createElement(FlexItem, null, createElement(Button, {
|
|
91
|
+
variant: "secondary",
|
|
92
|
+
onClick: () => {
|
|
93
|
+
closeModal();
|
|
94
|
+
}
|
|
95
|
+
}, __('Cancel'))), createElement(FlexItem, null, createElement(Button, {
|
|
96
|
+
variant: "primary",
|
|
97
|
+
type: "submit",
|
|
98
|
+
disabled: !title,
|
|
99
|
+
isBusy: isSubmitting
|
|
100
|
+
}, __('Create'))))));
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/create-template-part-modal/index.js"],"names":["useSelect","Icon","BaseControl","TextControl","Flex","FlexItem","FlexBlock","Button","Modal","__experimentalRadioGroup","RadioGroup","__experimentalRadio","Radio","__","useState","useInstanceId","store","editorStore","check","TEMPLATE_PART_AREA_GENERAL","CreateTemplatePartModal","closeModal","onCreate","title","setTitle","area","setArea","isSubmitting","setIsSubmitting","instanceId","templatePartAreas","select","__experimentalGetDefaultTemplatePartAreas","event","preventDefault","map","icon","label","value","description"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AACA,SACCC,IADD,EAECC,WAFD,EAGCC,WAHD,EAICC,IAJD,EAKCC,QALD,EAMCC,SAND,EAOCC,MAPD,EAQCC,KARD,EASCC,wBAAwB,IAAIC,UAT7B,EAUCC,mBAAmB,IAAIC,KAVxB,QAWO,uBAXP;AAYA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,aAAT,QAA8B,oBAA9B;AACA,SAASC,KAAK,IAAIC,WAAlB,QAAqC,mBAArC;AACA,SAASC,KAAT,QAAsB,kBAAtB;AAEA;AACA;AACA;;AACA,SAASC,0BAAT,QAA2C,uBAA3C;AAEA,eAAe,SAASC,uBAAT,OAA6D;AAAA,MAA3B;AAAEC,IAAAA,UAAF;AAAcC,IAAAA;AAAd,GAA2B;AAC3E,QAAM,CAAEC,KAAF,EAASC,QAAT,IAAsBV,QAAQ,CAAE,EAAF,CAApC;AACA,QAAM,CAAEW,IAAF,EAAQC,OAAR,IAAoBZ,QAAQ,CAAEK,0BAAF,CAAlC;AACA,QAAM,CAAEQ,YAAF,EAAgBC,eAAhB,IAAoCd,QAAQ,CAAE,KAAF,CAAlD;AACA,QAAMe,UAAU,GAAGd,aAAa,CAAEK,uBAAF,CAAhC;AAEA,QAAMU,iBAAiB,GAAG9B,SAAS,CAChC+B,MAAF,IACCA,MAAM,CAAEd,WAAF,CAAN,CAAsBe,yCAAtB,EAFiC,EAGlC,EAHkC,CAAnC;AAMA,SACC,cAAC,KAAD;AACC,IAAA,KAAK,EAAGnB,EAAE,CAAE,wBAAF,CADX;AAEC,IAAA,UAAU,EAAGA,EAAE,CAAE,OAAF,CAFhB;AAGC,IAAA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AC,QAAD,QACC,cAAC,IAAD;AAAM,MAAA,IAAI,EAAGF;AAAb,MADD,CADD,EAIC,cAAC,SAAD;AAAW,MAAA,SAAS,EAAC;AAArB,OACGC,KADH,EAEC,2BAAOE,WAAP,CAFD,CAJD,EASC,cAAC,QAAD;AAAU,MAAA,SAAS,EAAC;AAApB,OACGd,IAAI,KAAKa,KAAT,IACD,cAAC,IAAD;AAAM,MAAA,IAAI,EAAGpB;AAAb,MAFF,CATD,CALD,CADD;AAAA,GADC,CAPH,CALD,CAlBD,EAyDC,cAAC,IAAD;AACC,IAAA,SAAS,EAAC,qDADX;AAEC,IAAA,OAAO,EAAC;AAFT,KAIC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,WADT;AAEC,IAAA,OAAO,EAAG,MAAM;AACfG,MAAAA,UAAU;AACV;AAJF,KAMGR,EAAE,CAAE,QAAF,CANL,CADD,CAJD,EAcC,cAAC,QAAD,QACC,cAAC,MAAD;AACC,IAAA,OAAO,EAAC,SADT;AAEC,IAAA,IAAI,EAAC,QAFN;AAGC,IAAA,QAAQ,EAAG,CAAEU,KAHd;AAIC,IAAA,MAAM,EAAGI;AAJV,KAMGd,EAAE,CAAE,QAAF,CANL,CADD,CAdD,CAzDD,CAND,CADD;AA4FA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tFlex,\n\tFlexItem,\n\tFlexBlock,\n\tButton,\n\tModal,\n\t__experimentalRadioGroup as RadioGroup,\n\t__experimentalRadio as Radio,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { store as editorStore } from '@wordpress/editor';\nimport { check } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_PART_AREA_GENERAL } from '../../store/constants';\n\nexport default function CreateTemplatePartModal( { closeModal, onCreate } ) {\n\tconst [ title, setTitle ] = useState( '' );\n\tconst [ area, setArea ] = useState( TEMPLATE_PART_AREA_GENERAL );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst templatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editorStore ).__experimentalGetDefaultTemplatePartAreas(),\n\t\t[]\n\t);\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Create a template part' ) }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ closeModal }\n\t\t\toverlayClassName=\"edit-site-create-template-part-modal\"\n\t\t>\n\t\t\t<form\n\t\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tif ( ! title ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsetIsSubmitting( true );\n\t\t\t\t\tawait onCreate( { title, area } );\n\t\t\t\t\tsetIsSubmitting( false );\n\t\t\t\t\tcloseModal();\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t<TextControl\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<BaseControl\n\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\tid={ `edit-site-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\tclassName=\"edit-site-create-template-part-modal__area-base-control\"\n\t\t\t\t>\n\t\t\t\t\t<RadioGroup\n\t\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\t\tclassName=\"edit-site-create-template-part-modal__area-radio-group\"\n\t\t\t\t\t\tid={ `edit-site-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\t\tonChange={ setArea }\n\t\t\t\t\t\tchecked={ area }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ templatePartAreas.map(\n\t\t\t\t\t\t\t( { icon, label, area: value, description } ) => (\n\t\t\t\t\t\t\t\t<Radio\n\t\t\t\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-create-template-part-modal__area-radio\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Flex align=\"start\" justify=\"start\">\n\t\t\t\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t<FlexBlock className=\"edit-site-create-template-part-modal__option-label\">\n\t\t\t\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t\t\t\t\t<div>{ description }</div>\n\t\t\t\t\t\t\t\t\t\t</FlexBlock>\n\n\t\t\t\t\t\t\t\t\t\t<FlexItem className=\"edit-site-create-template-part-modal__checkbox\">\n\t\t\t\t\t\t\t\t\t\t\t{ area === value && (\n\t\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ check } />\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t</Flex>\n\t\t\t\t\t\t\t\t</Radio>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</RadioGroup>\n\t\t\t\t</BaseControl>\n\t\t\t\t<Flex\n\t\t\t\t\tclassName=\"edit-site-create-template-part-modal__modal-actions\"\n\t\t\t\t\tjustify=\"flex-end\"\n\t\t\t\t>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"secondary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\t\tdisabled={ ! title }\n\t\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Create' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</FlexItem>\n\t\t\t\t</Flex>\n\t\t\t</form>\n\t\t</Modal>\n\t);\n}\n"]}
|