@wordpress/editor 14.13.0 → 14.13.1-next.cd6172eb0.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/README.md +8 -28
- package/build/bindings/post-meta.js +2 -3
- package/build/bindings/post-meta.js.map +1 -1
- package/build/components/autocompleters/user.js +1 -3
- package/build/components/autocompleters/user.js.map +1 -1
- package/build/components/collab-sidebar/constants.js +2 -1
- package/build/components/collab-sidebar/constants.js.map +1 -1
- package/build/components/collab-sidebar/index.js +108 -43
- package/build/components/collab-sidebar/index.js.map +1 -1
- package/build/components/collab-sidebar/utils.js +32 -0
- package/build/components/collab-sidebar/utils.js.map +1 -1
- package/build/components/entities-saved-states/index.js +6 -6
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/header/index.js +5 -2
- package/build/components/header/index.js.map +1 -1
- package/build/components/index.js +10 -26
- package/build/components/index.js.map +1 -1
- package/build/components/post-actions/actions.js +29 -2
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +1 -1
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-actions/set-as-homepage.js +170 -0
- package/build/components/post-actions/set-as-homepage.js.map +1 -0
- package/build/components/post-author/constants.js +1 -1
- package/build/components/post-author/constants.js.map +1 -1
- package/build/components/post-author/hook.js +1 -0
- package/build/components/post-author/hook.js.map +1 -1
- package/build/components/post-fields/index.js +3 -3
- package/build/components/post-fields/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +4 -2
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/post-publish-button-or-toggle.js +32 -37
- package/build/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build/components/post-publish-panel/maybe-upload-media.js +0 -1
- package/build/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build/components/post-publish-panel/media-util.js +0 -1
- package/build/components/post-publish-panel/media-util.js.map +1 -1
- package/build/components/post-publish-panel/postpublish.js +103 -117
- package/build/components/post-publish-panel/postpublish.js.map +1 -1
- package/build/components/post-trash/check.js +4 -4
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-url/index.js +2 -1
- package/build/components/post-url/index.js.map +1 -1
- package/build/components/provider/index.js +9 -1
- package/build/components/provider/index.js.map +1 -1
- package/build/components/save-publish-panels/index.js +3 -1
- package/build/components/save-publish-panels/index.js.map +1 -1
- package/build/components/template-part-menu-items/convert-to-template-part.js +2 -3
- package/build/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
- package/build/components/visual-editor/index.js +2 -1
- package/build/components/visual-editor/index.js.map +1 -1
- package/build/dataviews/store/private-actions.js +3 -8
- package/build/dataviews/store/private-actions.js.map +1 -1
- package/build/private-apis.js +2 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/constants.js +0 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/private-actions.js +0 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/selectors.js +1 -1
- package/build/store/selectors.js.map +1 -1
- package/build-module/bindings/post-meta.js +2 -3
- package/build-module/bindings/post-meta.js.map +1 -1
- package/build-module/components/autocompleters/user.js +1 -3
- package/build-module/components/autocompleters/user.js.map +1 -1
- package/build-module/components/collab-sidebar/constants.js +1 -0
- package/build-module/components/collab-sidebar/constants.js.map +1 -1
- package/build-module/components/collab-sidebar/index.js +111 -46
- package/build-module/components/collab-sidebar/index.js.map +1 -1
- package/build-module/components/collab-sidebar/utils.js +31 -0
- package/build-module/components/collab-sidebar/utils.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +6 -6
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/header/index.js +5 -2
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/index.js +0 -2
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/post-actions/actions.js +29 -2
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +1 -1
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-actions/set-as-homepage.js +162 -0
- package/build-module/components/post-actions/set-as-homepage.js.map +1 -0
- package/build-module/components/post-author/constants.js +1 -1
- package/build-module/components/post-author/constants.js.map +1 -1
- package/build-module/components/post-author/hook.js +1 -0
- package/build-module/components/post-author/hook.js.map +1 -1
- package/build-module/components/post-fields/index.js +3 -3
- package/build-module/components/post-fields/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +4 -2
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js +34 -38
- package/build-module/components/post-publish-button/post-publish-button-or-toggle.js.map +1 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js +0 -1
- package/build-module/components/post-publish-panel/maybe-upload-media.js.map +1 -1
- package/build-module/components/post-publish-panel/media-util.js +0 -1
- package/build-module/components/post-publish-panel/media-util.js.map +1 -1
- package/build-module/components/post-publish-panel/postpublish.js +104 -118
- package/build-module/components/post-publish-panel/postpublish.js.map +1 -1
- package/build-module/components/post-trash/check.js +4 -4
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-url/index.js +2 -1
- package/build-module/components/post-url/index.js.map +1 -1
- package/build-module/components/provider/index.js +10 -2
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/save-publish-panels/index.js +3 -1
- package/build-module/components/save-publish-panels/index.js.map +1 -1
- package/build-module/components/template-part-menu-items/convert-to-template-part.js +1 -1
- package/build-module/components/template-part-menu-items/convert-to-template-part.js.map +1 -1
- package/build-module/components/visual-editor/index.js +2 -1
- package/build-module/components/visual-editor/index.js.map +1 -1
- package/build-module/dataviews/store/private-actions.js +4 -9
- package/build-module/dataviews/store/private-actions.js.map +1 -1
- package/build-module/private-apis.js +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/constants.js +0 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/private-actions.js +0 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +31 -62
- package/build-style/style.css +31 -62
- package/build-types/bindings/post-meta.d.ts.map +1 -1
- package/build-types/components/autocompleters/user.d.ts +1 -3
- package/build-types/components/autocompleters/user.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/constants.d.ts +1 -0
- package/build-types/components/collab-sidebar/constants.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
- package/build-types/components/collab-sidebar/utils.d.ts +10 -0
- package/build-types/components/collab-sidebar/utils.d.ts.map +1 -1
- package/build-types/components/entities-saved-states/index.d.ts +5 -5
- package/build-types/components/entities-saved-states/index.d.ts.map +1 -1
- package/build-types/components/header/index.d.ts.map +1 -1
- package/build-types/components/index.d.ts +0 -2
- package/build-types/components/index.d.ts.map +1 -1
- package/build-types/components/post-actions/actions.d.ts +1 -1
- package/build-types/components/post-actions/actions.d.ts.map +1 -1
- package/build-types/components/post-actions/set-as-homepage.d.ts +10 -0
- package/build-types/components/post-actions/set-as-homepage.d.ts.map +1 -0
- package/build-types/components/post-author/hook.d.ts.map +1 -1
- package/build-types/components/post-fields/index.d.ts +3 -1
- package/build-types/components/post-fields/index.d.ts.map +1 -1
- package/build-types/components/post-publish-button/index.d.ts.map +1 -1
- package/build-types/components/post-publish-button/post-publish-button-or-toggle.d.ts +1 -13
- package/build-types/components/post-publish-button/post-publish-button-or-toggle.d.ts.map +1 -1
- package/build-types/components/post-publish-panel/postpublish.d.ts +4 -2
- package/build-types/components/post-publish-panel/postpublish.d.ts.map +1 -1
- package/build-types/components/post-trash/check.d.ts +6 -6
- package/build-types/components/post-trash/check.d.ts.map +1 -1
- package/build-types/components/post-url/index.d.ts +5 -2
- package/build-types/components/post-url/index.d.ts.map +1 -1
- package/build-types/components/provider/index.d.ts.map +1 -1
- package/build-types/components/save-publish-panels/index.d.ts.map +1 -1
- package/build-types/components/visual-editor/index.d.ts.map +1 -1
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -2
- package/build-types/store/selectors.d.ts +1 -1
- package/build-types/store/selectors.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/bindings/post-meta.js +2 -5
- package/src/components/autocompleters/user.js +1 -3
- package/src/components/collab-sidebar/constants.js +1 -0
- package/src/components/collab-sidebar/index.js +115 -47
- package/src/components/collab-sidebar/style.scss +13 -0
- package/src/components/collab-sidebar/utils.js +36 -0
- package/src/components/editor-interface/style.scss +2 -1
- package/src/components/entities-saved-states/index.js +6 -9
- package/src/components/header/index.js +17 -5
- package/src/components/header/style.scss +1 -1
- package/src/components/index.js +0 -2
- package/src/components/post-actions/actions.js +38 -2
- package/src/components/post-actions/index.js +1 -1
- package/src/components/post-actions/set-as-homepage.js +183 -0
- package/src/components/post-author/constants.js +1 -1
- package/src/components/post-author/hook.js +1 -0
- package/src/components/post-fields/index.ts +5 -3
- package/src/components/post-publish-button/index.js +2 -0
- package/src/components/post-publish-button/post-publish-button-or-toggle.js +38 -40
- package/src/components/post-publish-button/test/post-publish-button-or-toggle.js +24 -9
- package/src/components/post-publish-panel/postpublish.js +114 -124
- package/src/components/post-trash/check.js +4 -4
- package/src/components/post-url/index.js +2 -1
- package/src/components/provider/index.js +17 -3
- package/src/components/save-publish-panels/index.js +5 -1
- package/src/components/template-part-menu-items/convert-to-template-part.js +1 -1
- package/src/components/visual-editor/index.js +1 -0
- package/src/components/visual-editor/style.scss +29 -6
- package/src/dataviews/store/private-actions.ts +14 -13
- package/src/private-apis.js +1 -1
- package/src/store/selectors.js +1 -1
- package/src/style.scss +0 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/create-template-part-modal/index.js +0 -170
- package/build/components/create-template-part-modal/index.js.map +0 -1
- package/build/components/create-template-part-modal/utils.js +0 -64
- package/build/components/create-template-part-modal/utils.js.map +0 -1
- package/build/components/post-slug/check.js +0 -29
- package/build/components/post-slug/check.js.map +0 -1
- package/build/components/post-slug/index.js +0 -79
- package/build/components/post-slug/index.js.map +0 -1
- package/build/components/post-slug/panel.js +0 -30
- package/build/components/post-slug/panel.js.map +0 -1
- package/build/dataviews/actions/duplicate-template-part.js +0 -67
- package/build/dataviews/actions/duplicate-template-part.js.map +0 -1
- package/build/dataviews/actions/utils.js +0 -58
- package/build/dataviews/actions/utils.js.map +0 -1
- package/build/dataviews/types.js +0 -6
- package/build/dataviews/types.js.map +0 -1
- package/build-module/components/create-template-part-modal/index.js +0 -162
- package/build-module/components/create-template-part-modal/index.js.map +0 -1
- package/build-module/components/create-template-part-modal/utils.js +0 -54
- package/build-module/components/create-template-part-modal/utils.js.map +0 -1
- package/build-module/components/post-slug/check.js +0 -23
- package/build-module/components/post-slug/check.js.map +0 -1
- package/build-module/components/post-slug/index.js +0 -71
- package/build-module/components/post-slug/index.js.map +0 -1
- package/build-module/components/post-slug/panel.js +0 -21
- package/build-module/components/post-slug/panel.js.map +0 -1
- package/build-module/dataviews/actions/duplicate-template-part.js +0 -58
- package/build-module/dataviews/actions/duplicate-template-part.js.map +0 -1
- package/build-module/dataviews/actions/utils.js +0 -47
- package/build-module/dataviews/actions/utils.js.map +0 -1
- package/build-module/dataviews/types.js +0 -2
- package/build-module/dataviews/types.js.map +0 -1
- package/build-types/components/create-template-part-modal/index.d.ts +0 -14
- package/build-types/components/create-template-part-modal/index.d.ts.map +0 -1
- package/build-types/components/create-template-part-modal/utils.d.ts +0 -4
- package/build-types/components/create-template-part-modal/utils.d.ts.map +0 -1
- package/build-types/components/post-slug/check.d.ts +0 -12
- package/build-types/components/post-slug/check.d.ts.map +0 -1
- package/build-types/components/post-slug/index.d.ts +0 -7
- package/build-types/components/post-slug/index.d.ts.map +0 -1
- package/build-types/components/post-slug/panel.d.ts +0 -3
- package/build-types/components/post-slug/panel.d.ts.map +0 -1
- package/build-types/dataviews/actions/duplicate-template-part.d.ts +0 -5
- package/build-types/dataviews/actions/duplicate-template-part.d.ts.map +0 -1
- package/build-types/dataviews/actions/utils.d.ts +0 -13
- package/build-types/dataviews/actions/utils.d.ts.map +0 -1
- package/build-types/dataviews/types.d.ts +0 -92
- package/build-types/dataviews/types.d.ts.map +0 -1
- package/src/components/create-template-part-modal/index.js +0 -210
- package/src/components/create-template-part-modal/style.scss +0 -63
- package/src/components/create-template-part-modal/test/utils.js +0 -60
- package/src/components/create-template-part-modal/utils.js +0 -67
- package/src/components/post-slug/check.js +0 -20
- package/src/components/post-slug/index.js +0 -73
- package/src/components/post-slug/panel.js +0 -22
- package/src/components/post-slug/style.scss +0 -5
- package/src/components/post-slug/test/index.js +0 -53
- package/src/dataviews/actions/duplicate-template-part.tsx +0 -70
- package/src/dataviews/actions/utils.ts +0 -64
- package/src/dataviews/types.ts +0 -85
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CreateTemplatePartModalContents = CreateTemplatePartModalContents;
|
|
7
|
-
exports.default = CreateTemplatePartModal;
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _components = require("@wordpress/components");
|
|
10
|
-
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
var _element = require("@wordpress/element");
|
|
12
|
-
var _compose = require("@wordpress/compose");
|
|
13
|
-
var _notices = require("@wordpress/notices");
|
|
14
|
-
var _coreData = require("@wordpress/core-data");
|
|
15
|
-
var _icons = require("@wordpress/icons");
|
|
16
|
-
var _blocks = require("@wordpress/blocks");
|
|
17
|
-
var _constants = require("../../store/constants");
|
|
18
|
-
var _utils = require("./utils");
|
|
19
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
|
-
/**
|
|
21
|
-
* WordPress dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Internal dependencies
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
function CreateTemplatePartModal({
|
|
29
|
-
modalTitle,
|
|
30
|
-
...restProps
|
|
31
|
-
}) {
|
|
32
|
-
const defaultModalTitle = (0, _data.useSelect)(select => select(_coreData.store).getPostType(_constants.TEMPLATE_PART_POST_TYPE)?.labels?.add_new_item, []);
|
|
33
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
|
|
34
|
-
title: modalTitle || defaultModalTitle,
|
|
35
|
-
onRequestClose: restProps.closeModal,
|
|
36
|
-
overlayClassName: "editor-create-template-part-modal",
|
|
37
|
-
focusOnMount: "firstContentElement",
|
|
38
|
-
size: "medium",
|
|
39
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CreateTemplatePartModalContents, {
|
|
40
|
-
...restProps
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
function CreateTemplatePartModalContents({
|
|
45
|
-
defaultArea = _constants.TEMPLATE_PART_AREA_DEFAULT_CATEGORY,
|
|
46
|
-
blocks = [],
|
|
47
|
-
confirmLabel = (0, _i18n.__)('Add'),
|
|
48
|
-
closeModal,
|
|
49
|
-
onCreate,
|
|
50
|
-
onError,
|
|
51
|
-
defaultTitle = ''
|
|
52
|
-
}) {
|
|
53
|
-
const {
|
|
54
|
-
createErrorNotice
|
|
55
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
56
|
-
const {
|
|
57
|
-
saveEntityRecord
|
|
58
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
59
|
-
const existingTemplateParts = (0, _utils.useExistingTemplateParts)();
|
|
60
|
-
const [title, setTitle] = (0, _element.useState)(defaultTitle);
|
|
61
|
-
const [area, setArea] = (0, _element.useState)(defaultArea);
|
|
62
|
-
const [isSubmitting, setIsSubmitting] = (0, _element.useState)(false);
|
|
63
|
-
const instanceId = (0, _compose.useInstanceId)(CreateTemplatePartModal);
|
|
64
|
-
const templatePartAreas = (0, _data.useSelect)(select => select(_coreData.store).getEntityRecord('root', '__unstableBase')?.default_template_part_areas || [], []);
|
|
65
|
-
async function createTemplatePart() {
|
|
66
|
-
if (!title || isSubmitting) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
setIsSubmitting(true);
|
|
71
|
-
const uniqueTitle = (0, _utils.getUniqueTemplatePartTitle)(title, existingTemplateParts);
|
|
72
|
-
const cleanSlug = (0, _utils.getCleanTemplatePartSlug)(uniqueTitle);
|
|
73
|
-
const templatePart = await saveEntityRecord('postType', _constants.TEMPLATE_PART_POST_TYPE, {
|
|
74
|
-
slug: cleanSlug,
|
|
75
|
-
title: uniqueTitle,
|
|
76
|
-
content: (0, _blocks.serialize)(blocks),
|
|
77
|
-
area
|
|
78
|
-
}, {
|
|
79
|
-
throwOnError: true
|
|
80
|
-
});
|
|
81
|
-
await onCreate(templatePart);
|
|
82
|
-
|
|
83
|
-
// TODO: Add a success notice?
|
|
84
|
-
} catch (error) {
|
|
85
|
-
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while creating the template part.');
|
|
86
|
-
createErrorNotice(errorMessage, {
|
|
87
|
-
type: 'snackbar'
|
|
88
|
-
});
|
|
89
|
-
onError?.();
|
|
90
|
-
} finally {
|
|
91
|
-
setIsSubmitting(false);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
|
|
95
|
-
onSubmit: async event => {
|
|
96
|
-
event.preventDefault();
|
|
97
|
-
await createTemplatePart();
|
|
98
|
-
},
|
|
99
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
|
|
100
|
-
spacing: "4",
|
|
101
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
102
|
-
__next40pxDefaultSize: true,
|
|
103
|
-
__nextHasNoMarginBottom: true,
|
|
104
|
-
label: (0, _i18n.__)('Name'),
|
|
105
|
-
value: title,
|
|
106
|
-
onChange: setTitle,
|
|
107
|
-
required: true
|
|
108
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl, {
|
|
109
|
-
__nextHasNoMarginBottom: true,
|
|
110
|
-
label: (0, _i18n.__)('Area'),
|
|
111
|
-
id: `editor-create-template-part-modal__area-selection-${instanceId}`,
|
|
112
|
-
className: "editor-create-template-part-modal__area-base-control",
|
|
113
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalRadioGroup, {
|
|
114
|
-
label: (0, _i18n.__)('Area'),
|
|
115
|
-
className: "editor-create-template-part-modal__area-radio-group",
|
|
116
|
-
id: `editor-create-template-part-modal__area-selection-${instanceId}`,
|
|
117
|
-
onChange: setArea,
|
|
118
|
-
checked: area,
|
|
119
|
-
children: templatePartAreas.map(({
|
|
120
|
-
icon,
|
|
121
|
-
label,
|
|
122
|
-
area: value,
|
|
123
|
-
description
|
|
124
|
-
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalRadio, {
|
|
125
|
-
__next40pxDefaultSize: true,
|
|
126
|
-
value: value,
|
|
127
|
-
className: "editor-create-template-part-modal__area-radio",
|
|
128
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Flex, {
|
|
129
|
-
align: "start",
|
|
130
|
-
justify: "start",
|
|
131
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
|
|
132
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
133
|
-
icon: icon
|
|
134
|
-
})
|
|
135
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.FlexBlock, {
|
|
136
|
-
className: "editor-create-template-part-modal__option-label",
|
|
137
|
-
children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
138
|
-
children: description
|
|
139
|
-
})]
|
|
140
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
|
|
141
|
-
className: "editor-create-template-part-modal__checkbox",
|
|
142
|
-
children: area === value && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
143
|
-
icon: _icons.check
|
|
144
|
-
})
|
|
145
|
-
})]
|
|
146
|
-
})
|
|
147
|
-
}, label))
|
|
148
|
-
})
|
|
149
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
150
|
-
justify: "right",
|
|
151
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
152
|
-
__next40pxDefaultSize: true,
|
|
153
|
-
variant: "tertiary",
|
|
154
|
-
onClick: () => {
|
|
155
|
-
closeModal();
|
|
156
|
-
},
|
|
157
|
-
children: (0, _i18n.__)('Cancel')
|
|
158
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
|
|
159
|
-
__next40pxDefaultSize: true,
|
|
160
|
-
variant: "primary",
|
|
161
|
-
type: "submit",
|
|
162
|
-
"aria-disabled": !title || isSubmitting,
|
|
163
|
-
isBusy: isSubmitting,
|
|
164
|
-
children: confirmLabel
|
|
165
|
-
})]
|
|
166
|
-
})]
|
|
167
|
-
})
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_components","_i18n","_element","_compose","_notices","_coreData","_icons","_blocks","_constants","_utils","_jsxRuntime","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","useSelect","select","coreStore","getPostType","TEMPLATE_PART_POST_TYPE","labels","add_new_item","jsx","Modal","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","defaultArea","TEMPLATE_PART_AREA_DEFAULT_CATEGORY","blocks","confirmLabel","__","onCreate","onError","defaultTitle","createErrorNotice","useDispatch","noticesStore","saveEntityRecord","existingTemplateParts","useExistingTemplateParts","setTitle","useState","area","setArea","isSubmitting","setIsSubmitting","instanceId","useInstanceId","templatePartAreas","getEntityRecord","default_template_part_areas","createTemplatePart","uniqueTitle","getUniqueTemplatePartTitle","cleanSlug","getCleanTemplatePartSlug","templatePart","slug","content","serialize","throwOnError","error","errorMessage","message","code","type","onSubmit","event","preventDefault","jsxs","__experimentalVStack","spacing","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","value","onChange","required","BaseControl","id","className","__experimentalRadioGroup","checked","map","icon","description","__experimentalRadio","Flex","align","justify","FlexItem","Icon","FlexBlock","check","__experimentalHStack","Button","variant","onClick","isBusy"],"sources":["@wordpress/editor/src/components/create-template-part-modal/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } 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\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useInstanceId } from '@wordpress/compose';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { check } from '@wordpress/icons';\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tTEMPLATE_PART_POST_TYPE,\n\tTEMPLATE_PART_AREA_DEFAULT_CATEGORY,\n} from '../../store/constants';\nimport {\n\tuseExistingTemplateParts,\n\tgetUniqueTemplatePartTitle,\n\tgetCleanTemplatePartSlug,\n} from './utils';\n\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n} ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( TEMPLATE_PART_POST_TYPE )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"editor-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = TEMPLATE_PART_AREA_DEFAULT_CATEGORY,\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n} ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst templatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t\t?.default_template_part_areas || [],\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_PART_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\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\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\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\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\tid={ `editor-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\tclassName=\"editor-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=\"editor-create-template-part-modal__area-radio-group\"\n\t\t\t\t\t\tid={ `editor-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\t__next40pxDefaultSize\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=\"editor-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=\"editor-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=\"editor-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<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</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AET;QAAC,CACU;MAAC,CACD,CAAC,eACd,IAAAvE,WAAA,CAAAiE,IAAA,EAAC3E,WAAA,CAAAqG,oBAAM;QAACL,OAAO,EAAC,OAAO;QAAAlE,QAAA,gBACtB,IAAApB,WAAA,CAAAY,GAAA,EAACtB,WAAA,CAAAsG,MAAM;UACNvB,qBAAqB;UACrBwB,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;YACf9E,UAAU,CAAC,CAAC;UACb,CAAG;UAAAI,QAAA,EAED,IAAAM,QAAE,EAAE,QAAS;QAAC,CACT,CAAC,eACT,IAAA1B,WAAA,CAAAY,GAAA,EAACtB,WAAA,CAAAsG,MAAM;UACNvB,qBAAqB;UACrBwB,OAAO,EAAC,SAAS;UACjBhC,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAE/C,KAAK,IAAI0B,YAAc;UACzCuD,MAAM,EAAGvD,YAAc;UAAApB,QAAA,EAErBK;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useExistingTemplateParts = exports.getUniqueTemplatePartTitle = exports.getCleanTemplatePartSlug = void 0;
|
|
7
|
-
var _changeCase = require("change-case");
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _coreData = require("@wordpress/core-data");
|
|
10
|
-
var _constants = require("../../store/constants");
|
|
11
|
-
/**
|
|
12
|
-
* External dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* WordPress dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const useExistingTemplateParts = () => {
|
|
24
|
-
return (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', _constants.TEMPLATE_PART_POST_TYPE, {
|
|
25
|
-
per_page: -1
|
|
26
|
-
}), []);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Return a unique template part title based on
|
|
31
|
-
* the given title and existing template parts.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} title The original template part title.
|
|
34
|
-
* @param {Object} templateParts The array of template part entities.
|
|
35
|
-
* @return {string} A unique template part title.
|
|
36
|
-
*/
|
|
37
|
-
exports.useExistingTemplateParts = useExistingTemplateParts;
|
|
38
|
-
const getUniqueTemplatePartTitle = (title, templateParts) => {
|
|
39
|
-
const lowercaseTitle = title.toLowerCase();
|
|
40
|
-
const existingTitles = templateParts.map(templatePart => templatePart.title.rendered.toLowerCase());
|
|
41
|
-
if (!existingTitles.includes(lowercaseTitle)) {
|
|
42
|
-
return title;
|
|
43
|
-
}
|
|
44
|
-
let suffix = 2;
|
|
45
|
-
while (existingTitles.includes(`${lowercaseTitle} ${suffix}`)) {
|
|
46
|
-
suffix++;
|
|
47
|
-
}
|
|
48
|
-
return `${title} ${suffix}`;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Get a valid slug for a template part.
|
|
53
|
-
* Currently template parts only allow latin chars.
|
|
54
|
-
* The fallback slug will receive suffix by default.
|
|
55
|
-
*
|
|
56
|
-
* @param {string} title The template part title.
|
|
57
|
-
* @return {string} A valid template part slug.
|
|
58
|
-
*/
|
|
59
|
-
exports.getUniqueTemplatePartTitle = getUniqueTemplatePartTitle;
|
|
60
|
-
const getCleanTemplatePartSlug = title => {
|
|
61
|
-
return (0, _changeCase.paramCase)(title).replace(/[^\w-]+/g, '') || 'wp-custom-part';
|
|
62
|
-
};
|
|
63
|
-
exports.getCleanTemplatePartSlug = getCleanTemplatePartSlug;
|
|
64
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_changeCase","require","_data","_coreData","_constants","useExistingTemplateParts","useSelect","select","coreStore","getEntityRecords","TEMPLATE_PART_POST_TYPE","per_page","exports","getUniqueTemplatePartTitle","title","templateParts","lowercaseTitle","toLowerCase","existingTitles","map","templatePart","rendered","includes","suffix","getCleanTemplatePartSlug","kebabCase","replace"],"sources":["@wordpress/editor/src/components/create-template-part-modal/utils.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_PART_POST_TYPE } from '../../store/constants';\n\nexport const useExistingTemplateParts = () => {\n\treturn useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_PART_POST_TYPE,\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t),\n\t\t[]\n\t);\n};\n\n/**\n * Return a unique template part title based on\n * the given title and existing template parts.\n *\n * @param {string} title The original template part title.\n * @param {Object} templateParts The array of template part entities.\n * @return {string} A unique template part title.\n */\nexport const getUniqueTemplatePartTitle = ( title, templateParts ) => {\n\tconst lowercaseTitle = title.toLowerCase();\n\tconst existingTitles = templateParts.map( ( templatePart ) =>\n\t\ttemplatePart.title.rendered.toLowerCase()\n\t);\n\n\tif ( ! existingTitles.includes( lowercaseTitle ) ) {\n\t\treturn title;\n\t}\n\n\tlet suffix = 2;\n\twhile ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {\n\t\tsuffix++;\n\t}\n\n\treturn `${ title } ${ suffix }`;\n};\n\n/**\n * Get a valid slug for a template part.\n * Currently template parts only allow latin chars.\n * The fallback slug will receive suffix by default.\n *\n * @param {string} title The template part title.\n * @return {string} A valid template part slug.\n */\nexport const getCleanTemplatePartSlug = ( title ) => {\n\treturn k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EAAEX,KAAM,CAAC,CAACY,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,IAAI,gBAAgB;AACxE,CAAC;AAACd,OAAA,CAAAY,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = PostSlugCheck;
|
|
8
|
-
var _postTypeSupportCheck = _interopRequireDefault(require("../post-type-support-check"));
|
|
9
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Wrapper component that renders its children only if the post type supports the slug.
|
|
16
|
-
*
|
|
17
|
-
* @param {Object} props Props.
|
|
18
|
-
* @param {React.ReactNode} props.children Children to be rendered.
|
|
19
|
-
*
|
|
20
|
-
* @return {React.ReactNode} The rendered component.
|
|
21
|
-
*/function PostSlugCheck({
|
|
22
|
-
children
|
|
23
|
-
}) {
|
|
24
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_postTypeSupportCheck.default, {
|
|
25
|
-
supportKeys: "slug",
|
|
26
|
-
children: children
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=check.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_postTypeSupportCheck","_interopRequireDefault","require","_jsxRuntime","PostSlugCheck","children","jsx","default","supportKeys"],"sources":["@wordpress/editor/src/components/post-slug/check.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport PostTypeSupportCheck from '../post-type-support-check';\n\n/**\n * Wrapper component that renders its children only if the post type supports the slug.\n *\n * @param {Object} props Props.\n * @param {React.ReactNode} props.children Children to be rendered.\n *\n * @return {React.ReactNode} The rendered component.\n */\nexport default function PostSlugCheck( { children } ) {\n\treturn (\n\t\t<PostTypeSupportCheck supportKeys=\"slug\">\n\t\t\t{ children }\n\t\t</PostTypeSupportCheck>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,qBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA8D,IAAAC,WAAA,GAAAD,OAAA;AAH9D;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACe,SAASE,aAAaA,CAAE;EAAEC;AAAS,CAAC,EAAG;EACrD,oBACC,IAAAF,WAAA,CAAAG,GAAA,EAACN,qBAAA,CAAAO,OAAoB;IAACC,WAAW,EAAC,MAAM;IAAAH,QAAA,EACrCA;EAAQ,CACW,CAAC;AAEzB","ignoreList":[]}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = PostSlug;
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
var _element = require("@wordpress/element");
|
|
10
|
-
var _i18n = require("@wordpress/i18n");
|
|
11
|
-
var _url = require("@wordpress/url");
|
|
12
|
-
var _components = require("@wordpress/components");
|
|
13
|
-
var _check = _interopRequireDefault(require("./check"));
|
|
14
|
-
var _store = require("../../store");
|
|
15
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
/**
|
|
17
|
-
* WordPress dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Internal dependencies
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
function PostSlugControl() {
|
|
25
|
-
const postSlug = (0, _data.useSelect)(select => {
|
|
26
|
-
return (0, _url.safeDecodeURIComponent)(select(_store.store).getEditedPostSlug());
|
|
27
|
-
}, []);
|
|
28
|
-
const {
|
|
29
|
-
editPost
|
|
30
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
31
|
-
const [forceEmptyField, setForceEmptyField] = (0, _element.useState)(false);
|
|
32
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
|
|
33
|
-
__next40pxDefaultSize: true,
|
|
34
|
-
__nextHasNoMarginBottom: true,
|
|
35
|
-
label: (0, _i18n.__)('Slug'),
|
|
36
|
-
autoComplete: "off",
|
|
37
|
-
spellCheck: "false",
|
|
38
|
-
value: forceEmptyField ? '' : postSlug,
|
|
39
|
-
onChange: newValue => {
|
|
40
|
-
editPost({
|
|
41
|
-
slug: newValue
|
|
42
|
-
});
|
|
43
|
-
// When we delete the field the permalink gets
|
|
44
|
-
// reverted to the original value.
|
|
45
|
-
// The forceEmptyField logic allows the user to have
|
|
46
|
-
// the field temporarily empty while typing.
|
|
47
|
-
if (!newValue) {
|
|
48
|
-
if (!forceEmptyField) {
|
|
49
|
-
setForceEmptyField(true);
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (forceEmptyField) {
|
|
54
|
-
setForceEmptyField(false);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
onBlur: event => {
|
|
58
|
-
editPost({
|
|
59
|
-
slug: (0, _url.cleanForSlug)(event.target.value)
|
|
60
|
-
});
|
|
61
|
-
if (forceEmptyField) {
|
|
62
|
-
setForceEmptyField(false);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
className: "editor-post-slug"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Renders the PostSlug component. It provide a control for editing the post slug.
|
|
71
|
-
*
|
|
72
|
-
* @return {React.ReactNode} The rendered component.
|
|
73
|
-
*/
|
|
74
|
-
function PostSlug() {
|
|
75
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_check.default, {
|
|
76
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PostSlugControl, {})
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_element","_i18n","_url","_components","_check","_interopRequireDefault","_store","_jsxRuntime","PostSlugControl","postSlug","useSelect","select","safeDecodeURIComponent","editorStore","getEditedPostSlug","editPost","useDispatch","forceEmptyField","setForceEmptyField","useState","jsx","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","__","autoComplete","spellCheck","value","onChange","newValue","slug","onBlur","event","cleanForSlug","target","className","PostSlug","default","children"],"sources":["@wordpress/editor/src/components/post-slug/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { safeDecodeURIComponent, cleanForSlug } from '@wordpress/url';\nimport { TextControl } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport PostSlugCheck from './check';\nimport { store as editorStore } from '../../store';\n\nfunction PostSlugControl() {\n\tconst postSlug = useSelect( ( select ) => {\n\t\treturn safeDecodeURIComponent(\n\t\t\tselect( editorStore ).getEditedPostSlug()\n\t\t);\n\t}, [] );\n\tconst { editPost } = useDispatch( editorStore );\n\tconst [ forceEmptyField, setForceEmptyField ] = useState( false );\n\n\treturn (\n\t\t<TextControl\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Slug' ) }\n\t\t\tautoComplete=\"off\"\n\t\t\tspellCheck=\"false\"\n\t\t\tvalue={ forceEmptyField ? '' : postSlug }\n\t\t\tonChange={ ( newValue ) => {\n\t\t\t\teditPost( { slug: newValue } );\n\t\t\t\t// When we delete the field the permalink gets\n\t\t\t\t// reverted to the original value.\n\t\t\t\t// The forceEmptyField logic allows the user to have\n\t\t\t\t// the field temporarily empty while typing.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tif ( ! forceEmptyField ) {\n\t\t\t\t\t\tsetForceEmptyField( true );\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif ( forceEmptyField ) {\n\t\t\t\t\tsetForceEmptyField( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tonBlur={ ( event ) => {\n\t\t\t\teditPost( {\n\t\t\t\t\tslug: cleanForSlug( event.target.value ),\n\t\t\t\t} );\n\t\t\t\tif ( forceEmptyField ) {\n\t\t\t\t\tsetForceEmptyField( false );\n\t\t\t\t}\n\t\t\t} }\n\t\t\tclassName=\"editor-post-slug\"\n\t\t/>\n\t);\n}\n\n/**\n * Renders the PostSlug component. It provide a control for editing the post slug.\n *\n * @return {React.ReactNode} The rendered component.\n */\nexport default function PostSlug() {\n\treturn (\n\t\t<PostSlugCheck>\n\t\t\t<PostSlugControl />\n\t\t</PostSlugCheck>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,IAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAC,sBAAA,CAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAAmD,IAAAQ,WAAA,GAAAR,OAAA;AAbnD;AACA;AACA;;AAOA;AACA;AACA;;AAIA,SAASS,eAAeA,CAAA,EAAG;EAC1B,MAAMC,QAAQ,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IACzC,OAAO,IAAAC,2BAAsB,EAC5BD,MAAM,CAAEE,YAAY,CAAC,CAACC,iBAAiB,CAAC,CACzC,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,MAAM;IAAEC;EAAS,CAAC,GAAG,IAAAC,iBAAW,EAAEH,YAAY,CAAC;EAC/C,MAAM,CAAEI,eAAe,EAAEC,kBAAkB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAEjE,oBACC,IAAAZ,WAAA,CAAAa,GAAA,EAACjB,WAAA,CAAAkB,WAAW;IACXC,qBAAqB;IACrBC,uBAAuB;IACvBC,KAAK,EAAG,IAAAC,QAAE,EAAE,MAAO,CAAG;IACtBC,YAAY,EAAC,KAAK;IAClBC,UAAU,EAAC,OAAO;IAClBC,KAAK,EAAGX,eAAe,GAAG,EAAE,GAAGR,QAAU;IACzCoB,QAAQ,EAAKC,QAAQ,IAAM;MAC1Bf,QAAQ,CAAE;QAAEgB,IAAI,EAAED;MAAS,CAAE,CAAC;MAC9B;MACA;MACA;MACA;MACA,IAAK,CAAEA,QAAQ,EAAG;QACjB,IAAK,CAAEb,eAAe,EAAG;UACxBC,kBAAkB,CAAE,IAAK,CAAC;QAC3B;QACA;MACD;MACA,IAAKD,eAAe,EAAG;QACtBC,kBAAkB,CAAE,KAAM,CAAC;MAC5B;IACD,CAAG;IACHc,MAAM,EAAKC,KAAK,IAAM;MACrBlB,QAAQ,CAAE;QACTgB,IAAI,EAAE,IAAAG,iBAAY,EAAED,KAAK,CAACE,MAAM,CAACP,KAAM;MACxC,CAAE,CAAC;MACH,IAAKX,eAAe,EAAG;QACtBC,kBAAkB,CAAE,KAAM,CAAC;MAC5B;IACD,CAAG;IACHkB,SAAS,EAAC;EAAkB,CAC5B,CAAC;AAEJ;;AAEA;AACA;AACA;AACA;AACA;AACe,SAASC,QAAQA,CAAA,EAAG;EAClC,oBACC,IAAA9B,WAAA,CAAAa,GAAA,EAAChB,MAAA,CAAAkC,OAAa;IAAAC,QAAA,eACb,IAAAhC,WAAA,CAAAa,GAAA,EAACZ,eAAe,IAAE;EAAC,CACL,CAAC;AAElB","ignoreList":[]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.PostSlug = PostSlug;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _components = require("@wordpress/components");
|
|
10
|
-
var _ = _interopRequireDefault(require("./"));
|
|
11
|
-
var _check = _interopRequireDefault(require("./check"));
|
|
12
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
/**
|
|
14
|
-
* WordPress dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
function PostSlug() {
|
|
22
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_check.default, {
|
|
23
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.PanelRow, {
|
|
24
|
-
className: "editor-post-slug",
|
|
25
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_.default, {})
|
|
26
|
-
})
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
var _default = exports.default = PostSlug;
|
|
30
|
-
//# sourceMappingURL=panel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_","_interopRequireDefault","_check","_jsxRuntime","PostSlug","jsx","default","children","PanelRow","className","_default","exports"],"sources":["@wordpress/editor/src/components/post-slug/panel.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { PanelRow } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport PostSlugForm from './';\nimport PostSlugCheck from './check';\n\nexport function PostSlug() {\n\treturn (\n\t\t<PostSlugCheck>\n\t\t\t<PanelRow className=\"editor-post-slug\">\n\t\t\t\t<PostSlugForm />\n\t\t\t</PanelRow>\n\t\t</PostSlugCheck>\n\t);\n}\n\nexport default PostSlug;\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,CAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAD,sBAAA,CAAAF,OAAA;AAAoC,IAAAI,WAAA,GAAAJ,OAAA;AATpC;AACA;AACA;;AAGA;AACA;AACA;;AAIO,SAASK,QAAQA,CAAA,EAAG;EAC1B,oBACC,IAAAD,WAAA,CAAAE,GAAA,EAACH,MAAA,CAAAI,OAAa;IAAAC,QAAA,eACb,IAAAJ,WAAA,CAAAE,GAAA,EAACP,WAAA,CAAAU,QAAQ;MAACC,SAAS,EAAC,kBAAkB;MAAAF,QAAA,eACrC,IAAAJ,WAAA,CAAAE,GAAA,EAACL,CAAA,CAAAM,OAAY,IAAE;IAAC,CACP;EAAC,CACG,CAAC;AAElB;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAL,OAAA,GAEcF,QAAQ","ignoreList":[]}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _data = require("@wordpress/data");
|
|
8
|
-
var _i18n = require("@wordpress/i18n");
|
|
9
|
-
var _notices = require("@wordpress/notices");
|
|
10
|
-
var _element = require("@wordpress/element");
|
|
11
|
-
var _blocks = require("@wordpress/blocks");
|
|
12
|
-
var _constants = require("../../store/constants");
|
|
13
|
-
var _createTemplatePartModal = require("../../components/create-template-part-modal");
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
-
/**
|
|
17
|
-
* WordPress dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Internal dependencies
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const duplicateTemplatePart = {
|
|
27
|
-
id: 'duplicate-template-part',
|
|
28
|
-
label: (0, _i18n._x)('Duplicate', 'action label'),
|
|
29
|
-
isEligible: item => item.type === _constants.TEMPLATE_PART_POST_TYPE,
|
|
30
|
-
modalHeader: (0, _i18n._x)('Duplicate template part', 'action label'),
|
|
31
|
-
RenderModal: ({
|
|
32
|
-
items,
|
|
33
|
-
closeModal
|
|
34
|
-
}) => {
|
|
35
|
-
const [item] = items;
|
|
36
|
-
const blocks = (0, _element.useMemo)(() => {
|
|
37
|
-
var _item$blocks;
|
|
38
|
-
return (_item$blocks = item.blocks) !== null && _item$blocks !== void 0 ? _item$blocks : (0, _blocks.parse)(typeof item.content === 'string' ? item.content : item.content.raw, {
|
|
39
|
-
__unstableSkipMigrationLogs: true
|
|
40
|
-
});
|
|
41
|
-
}, [item.content, item.blocks]);
|
|
42
|
-
const {
|
|
43
|
-
createSuccessNotice
|
|
44
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
45
|
-
function onTemplatePartSuccess() {
|
|
46
|
-
createSuccessNotice((0, _i18n.sprintf)(
|
|
47
|
-
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
48
|
-
(0, _i18n._x)('"%s" duplicated.', 'template part'), (0, _utils.getItemTitle)(item)), {
|
|
49
|
-
type: 'snackbar',
|
|
50
|
-
id: 'edit-site-patterns-success'
|
|
51
|
-
});
|
|
52
|
-
closeModal?.();
|
|
53
|
-
}
|
|
54
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_createTemplatePartModal.CreateTemplatePartModalContents, {
|
|
55
|
-
blocks: blocks,
|
|
56
|
-
defaultArea: item.area,
|
|
57
|
-
defaultTitle: (0, _i18n.sprintf)(/* translators: %s: Existing template part title */
|
|
58
|
-
(0, _i18n._x)('%s (Copy)', 'template part'), (0, _utils.getItemTitle)(item)),
|
|
59
|
-
onCreate: onTemplatePartSuccess,
|
|
60
|
-
onError: closeModal,
|
|
61
|
-
confirmLabel: (0, _i18n._x)('Duplicate', 'action label'),
|
|
62
|
-
closeModal: closeModal
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
var _default = exports.default = duplicateTemplatePart;
|
|
67
|
-
//# sourceMappingURL=duplicate-template-part.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_i18n","_notices","_element","_blocks","_constants","_createTemplatePartModal","_utils","_jsxRuntime","duplicateTemplatePart","id","label","_x","isEligible","item","type","TEMPLATE_PART_POST_TYPE","modalHeader","RenderModal","items","closeModal","blocks","useMemo","_item$blocks","parse","content","raw","__unstableSkipMigrationLogs","createSuccessNotice","useDispatch","noticesStore","onTemplatePartSuccess","sprintf","getItemTitle","jsx","CreateTemplatePartModalContents","defaultArea","area","defaultTitle","onCreate","onError","confirmLabel","_default","exports","default"],"sources":["@wordpress/editor/src/dataviews/actions/duplicate-template-part.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { _x, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useMemo } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_PART_POST_TYPE } from '../../store/constants';\nimport { CreateTemplatePartModalContents } from '../../components/create-template-part-modal';\nimport { getItemTitle } from './utils';\nimport type { TemplatePart } from '../types';\n\nconst duplicateTemplatePart: Action< TemplatePart > = {\n\tid: 'duplicate-template-part',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible: ( item ) => item.type === TEMPLATE_PART_POST_TYPE,\n\tmodalHeader: _x( 'Duplicate template part', 'action label' ),\n\tRenderModal: ( { items, closeModal } ) => {\n\t\tconst [ item ] = items;\n\t\tconst blocks = useMemo( () => {\n\t\t\treturn (\n\t\t\t\titem.blocks ??\n\t\t\t\tparse(\n\t\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t\t? item.content\n\t\t\t\t\t\t: item.content.raw,\n\t\t\t\t\t{\n\t\t\t\t\t\t__unstableSkipMigrationLogs: true,\n\t\t\t\t\t}\n\t\t\t\t)\n\t\t\t);\n\t\t}, [ item.content, item.blocks ] );\n\t\tconst { createSuccessNotice } = useDispatch( noticesStore );\n\t\tfunction onTemplatePartSuccess() {\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: The new template part's title e.g. 'Call to action (copy)'.\n\t\t\t\t\t_x( '\"%s\" duplicated.', 'template part' ),\n\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t),\n\t\t\t\t{ type: 'snackbar', id: 'edit-site-patterns-success' }\n\t\t\t);\n\t\t\tcloseModal?.();\n\t\t}\n\t\treturn (\n\t\t\t<CreateTemplatePartModalContents\n\t\t\t\tblocks={ blocks }\n\t\t\t\tdefaultArea={ item.area }\n\t\t\t\tdefaultTitle={ sprintf(\n\t\t\t\t\t/* translators: %s: Existing template part title */\n\t\t\t\t\t_x( '%s (Copy)', 'template part' ),\n\t\t\t\t\tgetItemTitle( item )\n\t\t\t\t) }\n\t\t\t\tonCreate={ onTemplatePartSuccess }\n\t\t\t\tonError={ closeModal }\n\t\t\t\tconfirmLabel={ _x( 'Duplicate', 'action label' ) }\n\t\t\t\tcloseModal={ closeModal }\n\t\t\t/>\n\t\t);\n\t},\n};\n\nexport default duplicateTemplatePart;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,OAAA,GAAAJ,OAAA;AAMA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,wBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAAuC,IAAAQ,WAAA,GAAAR,OAAA;AAhBvC;AACA;AACA;;AAKA;;AAIA;AACA;AACA;;AAMA,MAAMS,qBAA6C,GAAG;EACrDC,EAAE,EAAE,yBAAyB;EAC7BC,KAAK,EAAE,IAAAC,QAAE,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B,CAAC,EAClC,IAAAqB,mBAAY,EAAEnB,IAAK,CACpB,CAAG;MACHyB,QAAQ,EAAGR,qBAAuB;MAClCS,OAAO,EAAGpB,UAAY;MACtBqB,YAAY,EAAG,IAAA7B,QAAE,EAAE,WAAW,EAAE,cAAe,CAAG;MAClDQ,UAAU,EAAGA;IAAY,CACzB,CAAC;EAEJ;AACD,CAAC;AAAC,IAAAsB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEanC,qBAAqB","ignoreList":[]}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getItemTitle = getItemTitle;
|
|
7
|
-
exports.isTemplate = isTemplate;
|
|
8
|
-
exports.isTemplateOrTemplatePart = isTemplateOrTemplatePart;
|
|
9
|
-
exports.isTemplatePart = isTemplatePart;
|
|
10
|
-
exports.isTemplateRemovable = isTemplateRemovable;
|
|
11
|
-
var _htmlEntities = require("@wordpress/html-entities");
|
|
12
|
-
var _constants = require("../../store/constants");
|
|
13
|
-
/**
|
|
14
|
-
* WordPress dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
function isTemplate(post) {
|
|
22
|
-
return post.type === _constants.TEMPLATE_POST_TYPE;
|
|
23
|
-
}
|
|
24
|
-
function isTemplatePart(post) {
|
|
25
|
-
return post.type === _constants.TEMPLATE_PART_POST_TYPE;
|
|
26
|
-
}
|
|
27
|
-
function isTemplateOrTemplatePart(p) {
|
|
28
|
-
return p.type === _constants.TEMPLATE_POST_TYPE || p.type === _constants.TEMPLATE_PART_POST_TYPE;
|
|
29
|
-
}
|
|
30
|
-
function getItemTitle(item) {
|
|
31
|
-
if (typeof item.title === 'string') {
|
|
32
|
-
return (0, _htmlEntities.decodeEntities)(item.title);
|
|
33
|
-
}
|
|
34
|
-
if ('rendered' in item.title) {
|
|
35
|
-
return (0, _htmlEntities.decodeEntities)(item.title.rendered);
|
|
36
|
-
}
|
|
37
|
-
if ('raw' in item.title) {
|
|
38
|
-
return (0, _htmlEntities.decodeEntities)(item.title.raw);
|
|
39
|
-
}
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Check if a template is removable.
|
|
45
|
-
*
|
|
46
|
-
* @param template The template entity to check.
|
|
47
|
-
* @return Whether the template is removable.
|
|
48
|
-
*/
|
|
49
|
-
function isTemplateRemovable(template) {
|
|
50
|
-
if (!template) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
// In patterns list page we map the templates parts to a different object
|
|
54
|
-
// than the one returned from the endpoint. This is why we need to check for
|
|
55
|
-
// two props whether is custom or has a theme file.
|
|
56
|
-
return [template.source, template.source].includes(_constants.TEMPLATE_ORIGINS.custom) && !Boolean(template.type === 'wp_template' && template?.plugin) && !template.has_theme_file;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_htmlEntities","require","_constants","isTemplate","post","type","TEMPLATE_POST_TYPE","isTemplatePart","TEMPLATE_PART_POST_TYPE","isTemplateOrTemplatePart","p","getItemTitle","item","title","decodeEntities","rendered","raw","isTemplateRemovable","template","source","includes","TEMPLATE_ORIGINS","custom","Boolean","plugin","has_theme_file"],"sources":["@wordpress/editor/src/dataviews/actions/utils.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { decodeEntities } from '@wordpress/html-entities';\n\n/**\n * Internal dependencies\n */\nimport {\n\tTEMPLATE_ORIGINS,\n\tTEMPLATE_PART_POST_TYPE,\n\tTEMPLATE_POST_TYPE,\n} from '../../store/constants';\n\nimport type { Post, TemplatePart, Template } from '../types';\n\nexport function isTemplate( post: Post ): post is Template {\n\treturn post.type === TEMPLATE_POST_TYPE;\n}\n\nexport function isTemplatePart( post: Post ): post is TemplatePart {\n\treturn post.type === TEMPLATE_PART_POST_TYPE;\n}\n\nexport function isTemplateOrTemplatePart(\n\tp: Post\n): p is Template | TemplatePart {\n\treturn p.type === TEMPLATE_POST_TYPE || p.type === TEMPLATE_PART_POST_TYPE;\n}\n\nexport function getItemTitle( item: Post ) {\n\tif ( typeof item.title === 'string' ) {\n\t\treturn decodeEntities( item.title );\n\t}\n\tif ( 'rendered' in item.title ) {\n\t\treturn decodeEntities( item.title.rendered );\n\t}\n\tif ( 'raw' in item.title ) {\n\t\treturn decodeEntities( item.title.raw );\n\t}\n\treturn '';\n}\n\n/**\n * Check if a template is removable.\n *\n * @param template The template entity to check.\n * @return Whether the template is removable.\n */\nexport function isTemplateRemovable( template: Template | TemplatePart ) {\n\tif ( ! template ) {\n\t\treturn false;\n\t}\n\t// In patterns list page we map the templates parts to a different object\n\t// than the one returned from the endpoint. This is why we need to check for\n\t// two props whether is custom or has a theme file.\n\treturn (\n\t\t[ template.source, template.source ].includes(\n\t\t\tTEMPLATE_ORIGINS.custom\n\t\t) &&\n\t\t! Boolean( template.type === 'wp_template' && template?.plugin ) &&\n\t\t! template.has_theme_file\n\t);\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,aAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AASO,SAASE,UAAUA,CAAEC,IAAU,EAAqB;EAC1D,OAAOA,IAAI,CAACC,IAAI,KAAKC,6BAAkB;AACxC;AAEO,SAASC,cAAcA,CAAEH,IAAU,EAAyB;EAClE,OAAOA,IAAI,CAACC,IAAI,KAAKG,kCAAuB;AAC7C;AAEO,SAASC,wBAAwBA,CACvCC,CAAO,EACwB;EAC/B,OAAOA,CAAC,CAACL,IAAI,KAAKC,6BAAkB,IAAII,CAAC,CAACL,IAAI,KAAKG,kCAAuB;AAC3E;AAEO,SAASG,YAAYA,CAAEC,IAAU,EAAG;EAC1C,IAAK,OAAOA,IAAI,CAACC,KAAK,KAAK,QAAQ,EAAG;IACrC,OAAO,IAAAC,4BAAc,EAAEF,IAAI,CAACC,KAAM,CAAC;EACpC;EACA,IAAK,UAAU,IAAID,IAAI,CAACC,KAAK,EAAG;IAC/B,OAAO,IAAAC,4BAAc,EAAEF,IAAI,CAACC,KAAK,CAACE,QAAS,CAAC;EAC7C;EACA,IAAK,KAAK,IAAIH,IAAI,CAACC,KAAK,EAAG;IAC1B,OAAO,IAAAC,4BAAc,EAAEF,IAAI,CAACC,KAAK,CAACG,GAAI,CAAC;EACxC;EACA,OAAO,EAAE;AACV;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,mBAAmBA,CAAEC,QAAiC,EAAG;EACxE,IAAK,CAAEA,QAAQ,EAAG;IACjB,OAAO,KAAK;EACb;EACA;EACA;EACA;EACA,OACC,CAAEA,QAAQ,CAACC,MAAM,EAAED,QAAQ,CAACC,MAAM,CAAE,CAACC,QAAQ,CAC5CC,2BAAgB,CAACC,MAClB,CAAC,IACD,CAAEC,OAAO,CAAEL,QAAQ,CAACb,IAAI,KAAK,aAAa,IAAIa,QAAQ,EAAEM,MAAO,CAAC,IAChE,CAAEN,QAAQ,CAACO,cAAc;AAE3B","ignoreList":[]}
|
package/build/dataviews/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/editor/src/dataviews/types.ts"],"sourcesContent":["type PostStatus =\n\t| 'published'\n\t| 'draft'\n\t| 'pending'\n\t| 'private'\n\t| 'future'\n\t| 'auto-draft'\n\t| 'trash';\n\nexport interface CommonPost {\n\tstatus?: PostStatus;\n\ttitle: string | { rendered: string } | { raw: string };\n\tcontent: string | { raw: string; rendered: string };\n\ttype: string;\n\tid: string | number;\n\tblocks?: Object[];\n\t_links?: Links;\n}\n\ninterface Links {\n\t'predecessor-version'?: { href: string; id: number }[];\n\t'version-history'?: { href: string; count: number }[];\n\t[ key: string ]: { href: string }[] | undefined;\n}\n\nexport interface BasePost extends CommonPost {\n\tcomment_status?: 'open' | 'closed';\n\texcerpt?: string | { raw: string; rendered: string };\n\tmeta?: Record< string, any >;\n\tparent?: number;\n\tpassword?: string;\n\ttemplate?: string;\n\tformat?: string;\n\tfeatured_media?: number;\n\tmenu_order?: number;\n\tping_status?: 'open' | 'closed';\n\tlink?: string;\n}\n\nexport interface Template extends CommonPost {\n\ttype: 'wp_template';\n\tis_custom: boolean;\n\tsource: string;\n\torigin: string;\n\tplugin?: string;\n\thas_theme_file: boolean;\n\tid: string;\n}\n\nexport interface TemplatePart extends CommonPost {\n\ttype: 'wp_template_part';\n\tsource: string;\n\torigin: string;\n\thas_theme_file: boolean;\n\tid: string;\n\tarea: string;\n}\n\nexport interface Pattern extends CommonPost {\n\tslug: string;\n\ttitle: { raw: string };\n\twp_pattern_sync_status: string;\n}\n\nexport type Post = Template | TemplatePart | Pattern | BasePost;\n\nexport type PostWithPermissions = Post & {\n\tpermissions: {\n\t\tdelete: boolean;\n\t\tupdate: boolean;\n\t};\n};\n\nexport interface PostType {\n\tslug: string;\n\tviewable: boolean;\n\tsupports?: {\n\t\t'page-attributes'?: boolean;\n\t\ttitle?: boolean;\n\t\trevisions?: boolean;\n\t};\n}\n\n// Will be unnecessary after typescript 5.0 upgrade.\nexport type CoreDataError = { message?: string; code?: string };\n"],"mappings":"","ignoreList":[]}
|