@wordpress/fields 0.24.0 → 0.24.1-next.ff1cebbba.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 +1 -1
- package/build/actions/delete-post.js +168 -117
- package/build/actions/delete-post.js.map +7 -1
- package/build/actions/duplicate-pattern.js +42 -43
- package/build/actions/duplicate-pattern.js.map +7 -1
- package/build/actions/duplicate-post.js +104 -93
- package/build/actions/duplicate-post.js.map +7 -1
- package/build/actions/duplicate-template-part.js +71 -63
- package/build/actions/duplicate-template-part.js.map +7 -1
- package/build/actions/export-pattern.js +60 -45
- package/build/actions/export-pattern.js.map +7 -1
- package/build/actions/index.js +71 -94
- package/build/actions/index.js.map +7 -1
- package/build/actions/permanently-delete-post.js +161 -132
- package/build/actions/permanently-delete-post.js.map +7 -1
- package/build/actions/rename-post.js +77 -83
- package/build/actions/rename-post.js.map +7 -1
- package/build/actions/reorder-page.js +76 -73
- package/build/actions/reorder-page.js.map +7 -1
- package/build/actions/reset-post.js +214 -165
- package/build/actions/reset-post.js.map +7 -1
- package/build/actions/restore-post.js +91 -75
- package/build/actions/restore-post.js.map +7 -1
- package/build/actions/trash-post.js +167 -127
- package/build/actions/trash-post.js.map +7 -1
- package/build/actions/utils.js +48 -41
- package/build/actions/utils.js.map +7 -1
- package/build/actions/view-post-revisions.js +39 -35
- package/build/actions/view-post-revisions.js.map +7 -1
- package/build/actions/view-post.js +31 -28
- package/build/actions/view-post.js.map +7 -1
- package/build/components/create-template-part-modal/index.js +213 -169
- package/build/components/create-template-part-modal/index.js.map +7 -1
- package/build/components/create-template-part-modal/utils.js +48 -48
- package/build/components/create-template-part-modal/utils.js.map +7 -1
- package/build/fields/author/author-view.js +63 -69
- package/build/fields/author/author-view.js.map +7 -1
- package/build/fields/author/index.js +43 -29
- package/build/fields/author/index.js.map +7 -1
- package/build/fields/comment-status/index.js +42 -32
- package/build/fields/comment-status/index.js.map +7 -1
- package/build/fields/date/date-view.js +84 -58
- package/build/fields/date/date-view.js.map +7 -1
- package/build/fields/date/index.js +39 -25
- package/build/fields/date/index.js.map +7 -1
- package/build/fields/discussion/index.js +36 -32
- package/build/fields/discussion/index.js.map +7 -1
- package/build/fields/featured-image/featured-image-edit.js +115 -97
- package/build/fields/featured-image/featured-image-edit.js.map +7 -1
- package/build/fields/featured-image/featured-image-view.js +41 -34
- package/build/fields/featured-image/featured-image-view.js.map +7 -1
- package/build/fields/featured-image/index.js +31 -26
- package/build/fields/featured-image/index.js.map +7 -1
- package/build/fields/index.js +83 -118
- package/build/fields/index.js.map +7 -1
- package/build/fields/order/index.js +28 -23
- package/build/fields/order/index.js.map +7 -1
- package/build/fields/page-title/index.js +42 -30
- package/build/fields/page-title/index.js.map +7 -1
- package/build/fields/page-title/view.js +38 -41
- package/build/fields/page-title/view.js.map +7 -1
- package/build/fields/parent/index.js +31 -26
- package/build/fields/parent/index.js.map +7 -1
- package/build/fields/parent/parent-edit.js +200 -168
- package/build/fields/parent/parent-edit.js.map +7 -1
- package/build/fields/parent/parent-view.js +40 -31
- package/build/fields/parent/parent-view.js.map +7 -1
- package/build/fields/parent/utils.js +29 -16
- package/build/fields/parent/utils.js.map +7 -1
- package/build/fields/password/edit.js +67 -53
- package/build/fields/password/edit.js.map +7 -1
- package/build/fields/password/index.js +40 -26
- package/build/fields/password/index.js.map +7 -1
- package/build/fields/pattern-title/index.js +42 -30
- package/build/fields/pattern-title/index.js.map +7 -1
- package/build/fields/pattern-title/view.js +43 -41
- package/build/fields/pattern-title/view.js.map +7 -1
- package/build/fields/ping-status/index.js +66 -47
- package/build/fields/ping-status/index.js.map +7 -1
- package/build/fields/slug/index.js +41 -27
- package/build/fields/slug/index.js.map +7 -1
- package/build/fields/slug/slug-edit.js +116 -107
- package/build/fields/slug/slug-edit.js.map +7 -1
- package/build/fields/slug/slug-view.js +30 -23
- package/build/fields/slug/slug-view.js.map +7 -1
- package/build/fields/slug/utils.js +32 -20
- package/build/fields/slug/utils.js.map +7 -1
- package/build/fields/status/index.js +43 -29
- package/build/fields/status/index.js.map +7 -1
- package/build/fields/status/status-elements.js +58 -44
- package/build/fields/status/status-elements.js.map +7 -1
- package/build/fields/status/status-view.js +42 -36
- package/build/fields/status/status-view.js.map +7 -1
- package/build/fields/template/index.js +29 -24
- package/build/fields/template/index.js.map +7 -1
- package/build/fields/template/template-edit.js +167 -142
- package/build/fields/template/template-edit.js.map +7 -1
- package/build/fields/template-title/index.js +42 -30
- package/build/fields/template-title/index.js.map +7 -1
- package/build/fields/title/index.js +42 -32
- package/build/fields/title/index.js.map +7 -1
- package/build/fields/title/view.js +57 -39
- package/build/fields/title/view.js.map +7 -1
- package/build/index.js +39 -36
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/mutation/index.js +91 -76
- package/build/mutation/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build-module/actions/delete-post.js +155 -107
- package/build-module/actions/delete-post.js.map +7 -1
- package/build-module/actions/duplicate-pattern.js +24 -36
- package/build-module/actions/duplicate-pattern.js.map +7 -1
- package/build-module/actions/duplicate-post.js +87 -84
- package/build-module/actions/duplicate-post.js.map +7 -1
- package/build-module/actions/duplicate-template-part.js +51 -58
- package/build-module/actions/duplicate-template-part.js.map +7 -1
- package/build-module/actions/export-pattern.js +40 -39
- package/build-module/actions/export-pattern.js.map +7 -1
- package/build-module/actions/index.js +29 -14
- package/build-module/actions/index.js.map +7 -1
- package/build-module/actions/permanently-delete-post.js +146 -125
- package/build-module/actions/permanently-delete-post.js.map +7 -1
- package/build-module/actions/rename-post.js +63 -77
- package/build-module/actions/rename-post.js.map +7 -1
- package/build-module/actions/reorder-page.js +58 -65
- package/build-module/actions/reorder-page.js.map +7 -1
- package/build-module/actions/reset-post.js +185 -152
- package/build-module/actions/reset-post.js.map +7 -1
- package/build-module/actions/restore-post.js +72 -68
- package/build-module/actions/restore-post.js.map +7 -1
- package/build-module/actions/trash-post.js +152 -119
- package/build-module/actions/trash-post.js.map +7 -1
- package/build-module/actions/utils.js +23 -34
- package/build-module/actions/utils.js.map +7 -1
- package/build-module/actions/view-post-revisions.js +21 -31
- package/build-module/actions/view-post-revisions.js.map +7 -1
- package/build-module/actions/view-post.js +12 -23
- package/build-module/actions/view-post.js.map +7 -1
- package/build-module/components/create-template-part-modal/index.js +201 -154
- package/build-module/components/create-template-part-modal/index.js.map +7 -1
- package/build-module/components/create-template-part-modal/utils.js +26 -43
- package/build-module/components/create-template-part-modal/utils.js.map +7 -1
- package/build-module/fields/author/author-view.js +34 -62
- package/build-module/fields/author/author-view.js.map +7 -1
- package/build-module/fields/author/index.js +14 -24
- package/build-module/fields/author/index.js.map +7 -1
- package/build-module/fields/comment-status/index.js +24 -29
- package/build-module/fields/comment-status/index.js.map +7 -1
- package/build-module/fields/date/date-view.js +66 -53
- package/build-module/fields/date/date-view.js.map +7 -1
- package/build-module/fields/date/index.js +10 -20
- package/build-module/fields/date/index.js.map +7 -1
- package/build-module/fields/discussion/index.js +18 -29
- package/build-module/fields/discussion/index.js.map +7 -1
- package/build-module/fields/featured-image/featured-image-edit.js +93 -90
- package/build-module/fields/featured-image/featured-image-edit.js.map +7 -1
- package/build-module/fields/featured-image/featured-image-view.js +20 -29
- package/build-module/fields/featured-image/featured-image-view.js.map +7 -1
- package/build-module/fields/featured-image/index.js +11 -21
- package/build-module/fields/featured-image/index.js.map +7 -1
- package/build-module/fields/index.js +35 -17
- package/build-module/fields/index.js.map +7 -1
- package/build-module/fields/order/index.js +10 -20
- package/build-module/fields/order/index.js.map +7 -1
- package/build-module/fields/page-title/index.js +13 -25
- package/build-module/fields/page-title/index.js.map +7 -1
- package/build-module/fields/page-title/view.js +20 -37
- package/build-module/fields/page-title/view.js.map +7 -1
- package/build-module/fields/parent/index.js +11 -21
- package/build-module/fields/parent/index.js.map +7 -1
- package/build-module/fields/parent/parent-edit.js +172 -160
- package/build-module/fields/parent/parent-edit.js.map +7 -1
- package/build-module/fields/parent/parent-view.js +19 -27
- package/build-module/fields/parent/parent-view.js.map +7 -1
- package/build-module/fields/parent/utils.js +8 -13
- package/build-module/fields/parent/utils.js.map +7 -1
- package/build-module/fields/password/edit.js +53 -48
- package/build-module/fields/password/edit.js.map +7 -1
- package/build-module/fields/password/index.js +11 -21
- package/build-module/fields/password/index.js.map +7 -1
- package/build-module/fields/pattern-title/index.js +13 -25
- package/build-module/fields/pattern-title/index.js.map +7 -1
- package/build-module/fields/pattern-title/view.js +21 -34
- package/build-module/fields/pattern-title/view.js.map +7 -1
- package/build-module/fields/ping-status/index.js +48 -43
- package/build-module/fields/ping-status/index.js.map +7 -1
- package/build-module/fields/slug/index.js +11 -21
- package/build-module/fields/slug/index.js.map +7 -1
- package/build-module/fields/slug/slug-edit.js +101 -100
- package/build-module/fields/slug/slug-edit.js.map +7 -1
- package/build-module/fields/slug/slug-view.js +9 -16
- package/build-module/fields/slug/slug-view.js.map +7 -1
- package/build-module/fields/slug/utils.js +9 -13
- package/build-module/fields/slug/utils.js.map +7 -1
- package/build-module/fields/status/index.js +13 -23
- package/build-module/fields/status/index.js.map +7 -1
- package/build-module/fields/status/status-elements.js +47 -40
- package/build-module/fields/status/status-elements.js.map +7 -1
- package/build-module/fields/status/status-view.js +14 -31
- package/build-module/fields/status/status-view.js.map +7 -1
- package/build-module/fields/template/index.js +10 -18
- package/build-module/fields/template/index.js.map +7 -1
- package/build-module/fields/template/template-edit.js +147 -130
- package/build-module/fields/template/template-edit.js.map +7 -1
- package/build-module/fields/template-title/index.js +13 -25
- package/build-module/fields/template-title/index.js.map +7 -1
- package/build-module/fields/title/index.js +13 -27
- package/build-module/fields/title/index.js.map +7 -1
- package/build-module/fields/title/view.js +25 -32
- package/build-module/fields/title/view.js.map +7 -1
- package/build-module/index.js +7 -4
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/mutation/index.js +70 -72
- package/build-module/mutation/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-style/style-rtl.css +4 -139
- package/build-style/style.css +4 -139
- package/build-types/fields/author/author-view.d.ts.map +1 -1
- package/build-types/fields/discussion/index.d.ts.map +1 -1
- package/build-types/fields/featured-image/featured-image-edit.d.ts +2 -2
- package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -1
- package/build-types/fields/featured-image/featured-image-view.d.ts +5 -2
- package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -1
- package/build-types/fields/featured-image/index.d.ts +3 -3
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/types.d.ts +18 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +34 -27
- package/src/components/create-template-part-modal/style.scss +4 -0
- package/src/fields/author/author-view.tsx +3 -17
- package/src/fields/discussion/index.tsx +1 -0
- package/src/fields/featured-image/featured-image-edit.tsx +2 -2
- package/src/fields/featured-image/featured-image-view.tsx +3 -15
- package/src/fields/featured-image/index.ts +3 -3
- package/src/fields/featured-image/style.scss +3 -0
- package/src/fields/template/style.scss +4 -0
- package/src/fields/title/style.scss +1 -1
- package/src/style.scss +9 -8
- package/src/types.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/index.native.js +0 -2
- package/build/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -2
- package/build-module/index.native.js.map +0 -1
|
@@ -1,71 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var duplicate_post_exports = {};
|
|
20
|
+
__export(duplicate_post_exports, {
|
|
21
|
+
default: () => duplicate_post_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const fields = [_fields.titleField];
|
|
23
|
+
module.exports = __toCommonJS(duplicate_post_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_data = require("@wordpress/data");
|
|
26
|
+
var import_core_data = require("@wordpress/core-data");
|
|
27
|
+
var import_i18n = require("@wordpress/i18n");
|
|
28
|
+
var import_notices = require("@wordpress/notices");
|
|
29
|
+
var import_element = require("@wordpress/element");
|
|
30
|
+
var import_dataviews = require("@wordpress/dataviews");
|
|
31
|
+
var import_components = require("@wordpress/components");
|
|
32
|
+
var import_fields = require("../fields");
|
|
33
|
+
var import_utils = require("./utils");
|
|
34
|
+
const fields = [import_fields.titleField];
|
|
26
35
|
const formDuplicateAction = {
|
|
27
|
-
fields: [
|
|
36
|
+
fields: ["title"]
|
|
28
37
|
};
|
|
29
38
|
const duplicatePost = {
|
|
30
|
-
id:
|
|
31
|
-
label: (0,
|
|
32
|
-
isEligible({
|
|
33
|
-
status
|
|
34
|
-
}) {
|
|
35
|
-
return status !== 'trash';
|
|
39
|
+
id: "duplicate-post",
|
|
40
|
+
label: (0, import_i18n._x)("Duplicate", "action label"),
|
|
41
|
+
isEligible({ status }) {
|
|
42
|
+
return status !== "trash";
|
|
36
43
|
},
|
|
37
|
-
modalFocusOnMount:
|
|
38
|
-
RenderModal: ({
|
|
39
|
-
|
|
40
|
-
closeModal,
|
|
41
|
-
onActionPerformed
|
|
42
|
-
}) => {
|
|
43
|
-
const [item, setItem] = (0, _element.useState)({
|
|
44
|
+
modalFocusOnMount: "firstContentElement",
|
|
45
|
+
RenderModal: ({ items, closeModal, onActionPerformed }) => {
|
|
46
|
+
const [item, setItem] = (0, import_element.useState)({
|
|
44
47
|
...items[0],
|
|
45
|
-
title: (0,
|
|
46
|
-
|
|
48
|
+
title: (0, import_i18n.sprintf)(
|
|
49
|
+
/* translators: %s: Existing post title */
|
|
50
|
+
(0, import_i18n._x)("%s (Copy)", "post"),
|
|
51
|
+
(0, import_utils.getItemTitle)(items[0])
|
|
52
|
+
)
|
|
47
53
|
});
|
|
48
|
-
const [isCreatingPage, setIsCreatingPage] = (0,
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
} = (0, _data.useDispatch)(_coreData.store);
|
|
52
|
-
const {
|
|
53
|
-
createSuccessNotice,
|
|
54
|
-
createErrorNotice
|
|
55
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
54
|
+
const [isCreatingPage, setIsCreatingPage] = (0, import_element.useState)(false);
|
|
55
|
+
const { saveEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
|
|
56
|
+
const { createSuccessNotice, createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
56
57
|
async function createPage(event) {
|
|
57
58
|
event.preventDefault();
|
|
58
59
|
if (isCreatingPage) {
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
61
|
-
const isTemplate = item.type ===
|
|
62
|
+
const isTemplate = item.type === "wp_template" || item.type === "wp_registered_template";
|
|
62
63
|
const newItemObject = {
|
|
63
|
-
status: isTemplate ?
|
|
64
|
+
status: isTemplate ? "publish" : "draft",
|
|
64
65
|
title: item.title,
|
|
65
|
-
slug: isTemplate ? item.slug : item.title || (0,
|
|
66
|
+
slug: isTemplate ? item.slug : item.title || (0, import_i18n.__)("No title"),
|
|
66
67
|
comment_status: item.comment_status,
|
|
67
|
-
content: typeof item.content ===
|
|
68
|
-
excerpt: typeof item.excerpt ===
|
|
68
|
+
content: typeof item.content === "string" ? item.content : item.content.raw,
|
|
69
|
+
excerpt: typeof item.excerpt === "string" ? item.excerpt : item.excerpt?.raw,
|
|
69
70
|
meta: item.meta,
|
|
70
71
|
parent: item.parent,
|
|
71
72
|
password: item.password,
|
|
@@ -75,77 +76,87 @@ const duplicatePost = {
|
|
|
75
76
|
menu_order: item.menu_order,
|
|
76
77
|
ping_status: item.ping_status
|
|
77
78
|
};
|
|
78
|
-
const assignablePropertiesPrefix =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const assignablePropertiesPrefix = "wp:action-assign-";
|
|
80
|
+
const assignableProperties = Object.keys(item?._links || {}).filter(
|
|
81
|
+
(property) => property.startsWith(assignablePropertiesPrefix)
|
|
82
|
+
).map(
|
|
83
|
+
(property) => property.slice(assignablePropertiesPrefix.length)
|
|
84
|
+
);
|
|
85
|
+
assignableProperties.forEach((property) => {
|
|
83
86
|
if (item.hasOwnProperty(property)) {
|
|
84
|
-
// @ts-ignore
|
|
85
87
|
newItemObject[property] = item[property];
|
|
86
88
|
}
|
|
87
89
|
});
|
|
88
90
|
setIsCreatingPage(true);
|
|
89
91
|
try {
|
|
90
|
-
const newItem = await saveEntityRecord(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const newItem = await saveEntityRecord(
|
|
93
|
+
"postType",
|
|
94
|
+
item.type === "wp_registered_template" ? "wp_template" : item.type,
|
|
95
|
+
newItemObject,
|
|
96
|
+
{ throwOnError: true }
|
|
97
|
+
);
|
|
98
|
+
createSuccessNotice(
|
|
99
|
+
(0, import_i18n.sprintf)(
|
|
100
|
+
// translators: %s: Title of the created post, e.g: "Hello world".
|
|
101
|
+
(0, import_i18n.__)('"%s" successfully created.'),
|
|
102
|
+
(0, import_utils.getItemTitle)(newItem)
|
|
103
|
+
),
|
|
104
|
+
{
|
|
105
|
+
id: "duplicate-post-action",
|
|
106
|
+
type: "snackbar"
|
|
107
|
+
}
|
|
108
|
+
);
|
|
99
109
|
if (onActionPerformed) {
|
|
100
110
|
onActionPerformed([newItem]);
|
|
101
111
|
}
|
|
102
112
|
} catch (error) {
|
|
103
113
|
const typedError = error;
|
|
104
|
-
const errorMessage = typedError.message && typedError.code !==
|
|
114
|
+
const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : (0, import_i18n.__)("An error occurred while duplicating the page.");
|
|
105
115
|
createErrorNotice(errorMessage, {
|
|
106
|
-
type:
|
|
116
|
+
type: "snackbar"
|
|
107
117
|
});
|
|
108
118
|
} finally {
|
|
109
119
|
setIsCreatingPage(false);
|
|
110
120
|
closeModal?.();
|
|
111
121
|
}
|
|
112
122
|
}
|
|
113
|
-
return
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviews.DataForm, {
|
|
123
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("form", { onSubmit: createPage, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 3, children: [
|
|
124
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
|
+
import_dataviews.DataForm,
|
|
126
|
+
{
|
|
118
127
|
data: item,
|
|
119
|
-
fields
|
|
128
|
+
fields,
|
|
120
129
|
form: formDuplicateAction,
|
|
121
|
-
onChange: changes => setItem(prev => ({
|
|
130
|
+
onChange: (changes) => setItem((prev) => ({
|
|
122
131
|
...prev,
|
|
123
132
|
...changes
|
|
124
133
|
}))
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { spacing: 2, justify: "end", children: [
|
|
137
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
138
|
+
import_components.Button,
|
|
139
|
+
{
|
|
129
140
|
variant: "tertiary",
|
|
130
141
|
onClick: closeModal,
|
|
131
142
|
__next40pxDefaultSize: true,
|
|
132
|
-
children: (0,
|
|
133
|
-
}
|
|
143
|
+
children: (0, import_i18n.__)("Cancel")
|
|
144
|
+
}
|
|
145
|
+
),
|
|
146
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
147
|
+
import_components.Button,
|
|
148
|
+
{
|
|
134
149
|
variant: "primary",
|
|
135
150
|
type: "submit",
|
|
136
151
|
isBusy: isCreatingPage,
|
|
137
152
|
"aria-disabled": isCreatingPage,
|
|
138
153
|
__next40pxDefaultSize: true,
|
|
139
|
-
children: (0,
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
})
|
|
143
|
-
});
|
|
154
|
+
children: (0, import_i18n._x)("Duplicate", "action label")
|
|
155
|
+
}
|
|
156
|
+
)
|
|
157
|
+
] })
|
|
158
|
+
] }) });
|
|
144
159
|
}
|
|
145
160
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* Duplicate action for BasePost.
|
|
149
|
-
*/
|
|
150
|
-
var _default = exports.default = duplicatePost;
|
|
151
|
-
//# sourceMappingURL=duplicate-post.js.map
|
|
161
|
+
var duplicate_post_default = duplicatePost;
|
|
162
|
+
//# sourceMappingURL=duplicate-post.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_coreData","_i18n","_notices","_element","_dataviews","_components","_fields","_utils","_jsxRuntime","fields","titleField","formDuplicateAction","duplicatePost","id","label","_x","isEligible","status","modalFocusOnMount","RenderModal","items","closeModal","onActionPerformed","item","setItem","useState","title","sprintf","getItemTitle","isCreatingPage","setIsCreatingPage","saveEntityRecord","useDispatch","coreStore","createSuccessNotice","createErrorNotice","noticesStore","createPage","event","preventDefault","isTemplate","type","newItemObject","slug","__","comment_status","content","raw","excerpt","meta","parent","password","template","format","featured_media","menu_order","ping_status","assignablePropertiesPrefix","assignableProperties","Object","keys","_links","filter","property","startsWith","map","slice","length","forEach","hasOwnProperty","newItem","throwOnError","error","typedError","errorMessage","message","code","jsx","onSubmit","children","jsxs","__experimentalVStack","spacing","DataForm","data","form","onChange","changes","prev","__experimentalHStack","justify","Button","variant","onClick","__next40pxDefaultSize","isBusy","_default","exports","default"],"sources":["@wordpress/fields/src/actions/duplicate-post.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\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\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\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\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\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;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vE,WAAA,CAAAwE,IAAA,EAAC3E,WAAA,CAAA4E,oBAAM;QAACC,OAAO,EAAG,CAAG;QAAAH,QAAA,gBACpB,IAAAvE,WAAA,CAAAqE,GAAA,EAACzE,UAAA,CAAA+E,QAAQ;UACRC,IAAI,EAAG7D,IAAM;UACbd,MAAM,EAAGA,MAAQ;UACjB4E,IAAI,EAAG1E,mBAAqB;UAC5B2E,QAAQ,EAAKC,OAAO,IACnB/D,OAAO,CAAIgE,IAAI,KAAQ;YACtB,GAAGA,IAAI;YACP,GAAGD;UACJ,CAAC,CAAG;QACJ,CACD,CAAC,eACF,IAAA/E,WAAA,CAAAwE,IAAA,EAAC3E,WAAA,CAAAoF,oBAAM;UAACP,OAAO,EAAG,CAAG;UAACQ,OAAO,EAAC,KAAK;UAAAX,QAAA,gBAClC,IAAAvE,WAAA,CAAAqE,GAAA,EAACxE,WAAA,CAAAsF,MAAM;YACNC,OAAO,EAAC,UAAU;YAClBC,OAAO,EAAGxE,UAAY;YACtByE,qBAAqB;YAAAf,QAAA,EAEnB,IAAAnC,QAAE,EAAE,QAAS;UAAC,CACT,CAAC,eACT,IAAApC,WAAA,CAAAqE,GAAA,EAACxE,WAAA,CAAAsF,MAAM;YACNC,OAAO,EAAC,SAAS;YACjBnD,IAAI,EAAC,QAAQ;YACbsD,MAAM,EAAGlE,cAAgB;YACzB,iBAAgBA,cAAgB;YAChCiE,qBAAqB;YAAAf,QAAA,EAEnB,IAAAhE,QAAE,EAAE,WAAW,EAAE,cAAe;UAAC,CAC5B,CAAC;QAAA,CACF,CAAC;MAAA,CACF;IAAC,CACJ,CAAC;EAET;AACD,CAAC;;AAED;AACA;AACA;AAFA,IAAAiF,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGetF,aAAa","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/actions/duplicate-post.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf, _x } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { titleField } from '../fields';\nimport type { BasePost, CoreDataError } from '../types';\nimport { getItemTitle } from './utils';\n\nconst fields = [ titleField ];\nconst formDuplicateAction = {\n\tfields: [ 'title' ],\n};\n\nconst duplicatePost: Action< BasePost > = {\n\tid: 'duplicate-post',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ( { items, closeModal, onActionPerformed } ) => {\n\t\tconst [ item, setItem ] = useState< BasePost >( {\n\t\t\t...items[ 0 ],\n\t\t\ttitle: sprintf(\n\t\t\t\t/* translators: %s: Existing post title */\n\t\t\t\t_x( '%s (Copy)', 'post' ),\n\t\t\t\tgetItemTitle( items[ 0 ] )\n\t\t\t),\n\t\t} );\n\n\t\tconst [ isCreatingPage, setIsCreatingPage ] = useState( false );\n\t\tconst { saveEntityRecord } = useDispatch( coreStore );\n\t\tconst { createSuccessNotice, createErrorNotice } =\n\t\t\tuseDispatch( noticesStore );\n\n\t\tasync function createPage( event: React.FormEvent ) {\n\t\t\tevent.preventDefault();\n\n\t\t\tif ( isCreatingPage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isTemplate =\n\t\t\t\titem.type === 'wp_template' ||\n\t\t\t\titem.type === 'wp_registered_template';\n\n\t\t\tconst newItemObject = {\n\t\t\t\tstatus: isTemplate ? 'publish' : 'draft',\n\t\t\t\ttitle: item.title,\n\t\t\t\tslug: isTemplate ? item.slug : item.title || __( 'No title' ),\n\t\t\t\tcomment_status: item.comment_status,\n\t\t\t\tcontent:\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\texcerpt:\n\t\t\t\t\ttypeof item.excerpt === 'string'\n\t\t\t\t\t\t? item.excerpt\n\t\t\t\t\t\t: item.excerpt?.raw,\n\t\t\t\tmeta: item.meta,\n\t\t\t\tparent: item.parent,\n\t\t\t\tpassword: item.password,\n\t\t\t\ttemplate: item.template,\n\t\t\t\tformat: item.format,\n\t\t\t\tfeatured_media: item.featured_media,\n\t\t\t\tmenu_order: item.menu_order,\n\t\t\t\tping_status: item.ping_status,\n\t\t\t};\n\t\t\tconst assignablePropertiesPrefix = 'wp:action-assign-';\n\t\t\t// Get all the properties that the current user is able to assign normally author, categories, tags,\n\t\t\t// and custom taxonomies.\n\t\t\tconst assignableProperties = Object.keys( item?._links || {} )\n\t\t\t\t.filter( ( property ) =>\n\t\t\t\t\tproperty.startsWith( assignablePropertiesPrefix )\n\t\t\t\t)\n\t\t\t\t.map( ( property ) =>\n\t\t\t\t\tproperty.slice( assignablePropertiesPrefix.length )\n\t\t\t\t);\n\t\t\tassignableProperties.forEach( ( property ) => {\n\t\t\t\tif ( item.hasOwnProperty( property ) ) {\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tnewItemObject[ property ] = item[ property ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tsetIsCreatingPage( true );\n\t\t\ttry {\n\t\t\t\tconst newItem = await saveEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\titem.type === 'wp_registered_template'\n\t\t\t\t\t\t? 'wp_template'\n\t\t\t\t\t\t: item.type,\n\t\t\t\t\tnewItemObject,\n\t\t\t\t\t{ throwOnError: true }\n\t\t\t\t);\n\n\t\t\t\tcreateSuccessNotice(\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t// translators: %s: Title of the created post, e.g: \"Hello world\".\n\t\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\t\tgetItemTitle( newItem )\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'duplicate-post-action',\n\t\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif ( onActionPerformed ) {\n\t\t\t\t\tonActionPerformed( [ newItem ] );\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tconst typedError = error as CoreDataError;\n\t\t\t\tconst errorMessage =\n\t\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t\t? typedError.message\n\t\t\t\t\t\t: __( 'An error occurred while duplicating the page.' );\n\n\t\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t} );\n\t\t\t} finally {\n\t\t\t\tsetIsCreatingPage( false );\n\t\t\t\tcloseModal?.();\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<form onSubmit={ createPage }>\n\t\t\t\t<VStack spacing={ 3 }>\n\t\t\t\t\t<DataForm\n\t\t\t\t\t\tdata={ item }\n\t\t\t\t\t\tfields={ fields }\n\t\t\t\t\t\tform={ formDuplicateAction }\n\t\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\t\tsetItem( ( prev ) => ( {\n\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t\t} ) )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t\t<HStack spacing={ 2 } justify=\"end\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ closeModal }\n\t\t\t\t\t\t\t__next40pxDefaultSize\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\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\tisBusy={ isCreatingPage }\n\t\t\t\t\t\t\taria-disabled={ isCreatingPage }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ _x( 'Duplicate', 'action label' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</HStack>\n\t\t\t\t</VStack>\n\t\t\t</form>\n\t\t);\n\t},\n};\n\n/**\n * Duplicate action for BasePost.\n */\nexport default duplicatePost;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgJK;AA7IL,kBAA4B;AAC5B,uBAAmC;AACnC,kBAAgC;AAChC,qBAAsC;AACtC,qBAAyB;AACzB,uBAAyB;AACzB,wBAIO;AAMP,oBAA2B;AAE3B,mBAA6B;AAE7B,MAAM,SAAS,CAAE,wBAAW;AAC5B,MAAM,sBAAsB;AAAA,EAC3B,QAAQ,CAAE,OAAQ;AACnB;AAEA,MAAM,gBAAoC;AAAA,EACzC,IAAI;AAAA,EACJ,WAAO,gBAAI,aAAa,cAAe;AAAA,EACvC,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa,CAAE,EAAE,OAAO,YAAY,kBAAkB,MAAO;AAC5D,UAAM,CAAE,MAAM,OAAQ,QAAI,yBAAsB;AAAA,MAC/C,GAAG,MAAO,CAAE;AAAA,MACZ,WAAO;AAAA;AAAA,YAEN,gBAAI,aAAa,MAAO;AAAA,YACxB,2BAAc,MAAO,CAAE,CAAE;AAAA,MAC1B;AAAA,IACD,CAAE;AAEF,UAAM,CAAE,gBAAgB,iBAAkB,QAAI,yBAAU,KAAM;AAC9D,UAAM,EAAE,iBAAiB,QAAI,yBAAa,iBAAAA,KAAU;AACpD,UAAM,EAAE,qBAAqB,kBAAkB,QAC9C,yBAAa,eAAAC,KAAa;AAE3B,mBAA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IAAI;AAAA,YACJ,MAAM;AAAA,UACP;AAAA,QACD;AAEA,YAAK,mBAAoB;AACxB,4BAAmB,CAAE,OAAQ,CAAE;AAAA,QAChC;AAAA,MACD,SAAU,OAAQ;AACjB,cAAM,aAAa;AACnB,cAAM,eACL,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,cACX,gBAAI,+CAAgD;AAExD,0BAAmB,cAAc;AAAA,UAChC,MAAM;AAAA,QACP,CAAE;AAAA,MACH,UAAE;AACD,0BAAmB,KAAM;AACzB,qBAAa;AAAA,MACd;AAAA,IACD;AAEA,WACC,4CAAC,UAAK,UAAW,YAChB,uDAAC,kBAAAC,sBAAA,EAAO,SAAU,GACjB;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,MAAO;AAAA,UACP;AAAA,UACA,MAAO;AAAA,UACP,UAAW,CAAE,YACZ,QAAS,CAAE,UAAY;AAAA,YACtB,GAAG;AAAA,YACH,GAAG;AAAA,UACJ,EAAI;AAAA;AAAA,MAEN;AAAA,MACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAU,GAAI,SAAQ,OAC7B;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,SAAU;AAAA,YACV,uBAAqB;AAAA,YAEnB,8BAAI,QAAS;AAAA;AAAA,QAChB;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,SAAQ;AAAA,YACR,MAAK;AAAA,YACL,QAAS;AAAA,YACT,iBAAgB;AAAA,YAChB,uBAAqB;AAAA,YAEnB,8BAAI,aAAa,cAAe;AAAA;AAAA,QACnC;AAAA,SACD;AAAA,OACD,GACD;AAAA,EAEF;AACD;AAKA,IAAO,yBAAQ;",
|
|
6
|
+
"names": ["coreStore", "noticesStore", "VStack", "HStack"]
|
|
7
|
+
}
|
|
@@ -1,72 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var duplicate_template_part_exports = {};
|
|
20
|
+
__export(duplicate_template_part_exports, {
|
|
21
|
+
default: () => duplicate_template_part_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* This action is used to duplicate a template part.
|
|
27
|
-
*/const duplicateTemplatePart = {
|
|
28
|
-
id: 'duplicate-template-part',
|
|
29
|
-
label: (0, _i18n._x)('Duplicate', 'action label'),
|
|
30
|
-
isEligible: item => item.type === 'wp_template_part',
|
|
31
|
-
modalHeader: (0, _i18n._x)('Duplicate template part', 'action label'),
|
|
32
|
-
modalFocusOnMount: 'firstContentElement',
|
|
33
|
-
RenderModal: ({
|
|
34
|
-
items,
|
|
35
|
-
closeModal
|
|
36
|
-
}) => {
|
|
23
|
+
module.exports = __toCommonJS(duplicate_template_part_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_data = require("@wordpress/data");
|
|
26
|
+
var import_i18n = require("@wordpress/i18n");
|
|
27
|
+
var import_notices = require("@wordpress/notices");
|
|
28
|
+
var import_element = require("@wordpress/element");
|
|
29
|
+
var import_blocks = require("@wordpress/blocks");
|
|
30
|
+
var import_create_template_part_modal = require("../components/create-template-part-modal");
|
|
31
|
+
var import_utils = require("./utils");
|
|
32
|
+
const duplicateTemplatePart = {
|
|
33
|
+
id: "duplicate-template-part",
|
|
34
|
+
label: (0, import_i18n._x)("Duplicate", "action label"),
|
|
35
|
+
isEligible: (item) => item.type === "wp_template_part",
|
|
36
|
+
modalHeader: (0, import_i18n._x)("Duplicate template part", "action label"),
|
|
37
|
+
modalFocusOnMount: "firstContentElement",
|
|
38
|
+
RenderModal: ({ items, closeModal }) => {
|
|
37
39
|
const [item] = items;
|
|
38
|
-
const blocks = (0,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const blocks = (0, import_element.useMemo)(() => {
|
|
41
|
+
return item.blocks ?? (0, import_blocks.parse)(
|
|
42
|
+
typeof item.content === "string" ? item.content : item.content.raw,
|
|
43
|
+
{
|
|
44
|
+
__unstableSkipMigrationLogs: true
|
|
45
|
+
}
|
|
46
|
+
);
|
|
43
47
|
}, [item.content, item.blocks]);
|
|
44
|
-
const {
|
|
45
|
-
createSuccessNotice
|
|
46
|
-
} = (0, _data.useDispatch)(_notices.store);
|
|
48
|
+
const { createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
|
|
47
49
|
function onTemplatePartSuccess(templatePart) {
|
|
48
|
-
createSuccessNotice(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
createSuccessNotice(
|
|
51
|
+
(0, import_i18n.sprintf)(
|
|
52
|
+
// translators: %s: The new template part's title e.g. 'Call to action (copy)'.
|
|
53
|
+
(0, import_i18n._x)('"%s" duplicated.', "template part"),
|
|
54
|
+
(0, import_utils.getItemTitle)(templatePart)
|
|
55
|
+
),
|
|
56
|
+
{ type: "snackbar", id: "edit-site-patterns-success" }
|
|
57
|
+
);
|
|
54
58
|
closeModal?.();
|
|
55
59
|
}
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
61
|
+
import_create_template_part_modal.CreateTemplatePartModalContents,
|
|
62
|
+
{
|
|
63
|
+
blocks,
|
|
64
|
+
defaultArea: item.area,
|
|
65
|
+
defaultTitle: (0, import_i18n.sprintf)(
|
|
66
|
+
/* translators: %s: Existing template part title */
|
|
67
|
+
(0, import_i18n._x)("%s (Copy)", "template part"),
|
|
68
|
+
(0, import_utils.getItemTitle)(item)
|
|
69
|
+
),
|
|
70
|
+
onCreate: onTemplatePartSuccess,
|
|
71
|
+
onError: closeModal,
|
|
72
|
+
confirmLabel: (0, import_i18n._x)("Duplicate", "action label"),
|
|
73
|
+
closeModal: closeModal ?? (() => {
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
);
|
|
66
77
|
}
|
|
67
78
|
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*/
|
|
71
|
-
var _default = exports.default = duplicateTemplatePart;
|
|
72
|
-
//# sourceMappingURL=duplicate-template-part.js.map
|
|
79
|
+
var duplicate_template_part_default = duplicateTemplatePart;
|
|
80
|
+
//# sourceMappingURL=duplicate-template-part.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/actions/duplicate-template-part.tsx"],
|
|
4
|
+
"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 type { Post, TemplatePart } from '../types';\nimport { CreateTemplatePartModalContents } from '../components/create-template-part-modal';\nimport { getItemTitle } from './utils';\n\n/**\n * This action is used to duplicate a template part.\n */\nconst duplicateTemplatePart: Action< TemplatePart > = {\n\tid: 'duplicate-template-part',\n\tlabel: _x( 'Duplicate', 'action label' ),\n\tisEligible: ( item ) => item.type === 'wp_template_part',\n\tmodalHeader: _x( 'Duplicate template part', 'action label' ),\n\tmodalFocusOnMount: 'firstContentElement',\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( templatePart: Post ) {\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( templatePart )\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/**\n * Duplicate action for TemplatePart.\n */\nexport default duplicateTemplatePart;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuDG;AApDH,kBAA4B;AAC5B,kBAA4B;AAC5B,qBAAsC;AACtC,qBAAwB;AAExB,oBAAsB;AAOtB,wCAAgD;AAChD,mBAA6B;AAK7B,MAAM,wBAAgD;AAAA,EACrD,IAAI;AAAA,EACJ,WAAO,gBAAI,aAAa,cAAe;AAAA,EACvC,YAAY,CAAE,SAAU,KAAK,SAAS;AAAA,EACtC,iBAAa,gBAAI,2BAA2B,cAAe;AAAA,EAC3D,mBAAmB;AAAA,EACnB,aAAa,CAAE,EAAE,OAAO,WAAW,MAAO;AACzC,UAAM,CAAE,IAAK,IAAI;AACjB,UAAM,aAAS,wBAAS,MAAM;AAC7B,aACC,KAAK,cACL;AAAA,QACC,OAAO,KAAK,YAAY,WACrB,KAAK,UACL,KAAK,QAAQ;AAAA,QAChB;AAAA,UACC,6BAA6B;AAAA,QAC9B;AAAA,MACD;AAAA,IAEF,GAAG,CAAE,KAAK,SAAS,KAAK,MAAO,CAAE;AACjC,UAAM,EAAE,oBAAoB,QAAI,yBAAa,eAAAA,KAAa;AAC1D,aAAS,sBAAuB,cAAqB;AACpD;AAAA,YACC;AAAA;AAAA,cAEC,gBAAI,oBAAoB,eAAgB;AAAA,cACxC,2BAAc,YAAa;AAAA,QAC5B;AAAA,QACA,EAAE,MAAM,YAAY,IAAI,6BAA6B;AAAA,MACtD;AACA,mBAAa;AAAA,IACd;AACA,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,aAAc,KAAK;AAAA,QACnB,kBAAe;AAAA;AAAA,cAEd,gBAAI,aAAa,eAAgB;AAAA,cACjC,2BAAc,IAAK;AAAA,QACpB;AAAA,QACA,UAAW;AAAA,QACX,SAAU;AAAA,QACV,kBAAe,gBAAI,aAAa,cAAe;AAAA,QAC/C,YAAa,eAAgB,MAAM;AAAA,QAAC;AAAA;AAAA,IACrC;AAAA,EAEF;AACD;AAIA,IAAO,kCAAQ;",
|
|
6
|
+
"names": ["noticesStore"]
|
|
7
|
+
}
|
|
@@ -1,61 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var export_pattern_exports = {};
|
|
20
|
+
__export(export_pattern_exports, {
|
|
21
|
+
default: () => export_pattern_default
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
/**
|
|
14
|
-
* External dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* WordPress dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
|
|
23
|
+
module.exports = __toCommonJS(export_pattern_exports);
|
|
24
|
+
var import_change_case = require("change-case");
|
|
25
|
+
var import_client_zip = require("client-zip");
|
|
26
|
+
var import_blob = require("@wordpress/blob");
|
|
27
|
+
var import_i18n = require("@wordpress/i18n");
|
|
28
|
+
var import_icons = require("@wordpress/icons");
|
|
29
|
+
var import_utils = require("./utils");
|
|
25
30
|
function getJsonFromItem(item) {
|
|
26
|
-
return JSON.stringify(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
return JSON.stringify(
|
|
32
|
+
{
|
|
33
|
+
__file: item.type,
|
|
34
|
+
title: (0, import_utils.getItemTitle)(item),
|
|
35
|
+
content: typeof item.content === "string" ? item.content : item.content?.raw,
|
|
36
|
+
syncStatus: item.wp_pattern_sync_status
|
|
37
|
+
},
|
|
38
|
+
null,
|
|
39
|
+
2
|
|
40
|
+
);
|
|
32
41
|
}
|
|
33
42
|
const exportPattern = {
|
|
34
|
-
id:
|
|
35
|
-
label: (0,
|
|
36
|
-
icon:
|
|
43
|
+
id: "export-pattern",
|
|
44
|
+
label: (0, import_i18n.__)("Export as JSON"),
|
|
45
|
+
icon: import_icons.download,
|
|
37
46
|
supportsBulk: true,
|
|
38
|
-
isEligible: item => item.type ===
|
|
39
|
-
callback: async items => {
|
|
47
|
+
isEligible: (item) => item.type === "wp_block",
|
|
48
|
+
callback: async (items) => {
|
|
40
49
|
if (items.length === 1) {
|
|
41
|
-
return (0,
|
|
50
|
+
return (0, import_blob.downloadBlob)(
|
|
51
|
+
`${(0, import_change_case.paramCase)(
|
|
52
|
+
(0, import_utils.getItemTitle)(items[0]) || items[0].slug
|
|
53
|
+
)}.json`,
|
|
54
|
+
getJsonFromItem(items[0]),
|
|
55
|
+
"application/json"
|
|
56
|
+
);
|
|
42
57
|
}
|
|
43
58
|
const nameCount = {};
|
|
44
|
-
const filesToZip = items.map(item => {
|
|
45
|
-
const name = (0,
|
|
59
|
+
const filesToZip = items.map((item) => {
|
|
60
|
+
const name = (0, import_change_case.paramCase)((0, import_utils.getItemTitle)(item) || item.slug);
|
|
46
61
|
nameCount[name] = (nameCount[name] || 0) + 1;
|
|
47
62
|
return {
|
|
48
|
-
name: `${name + (nameCount[name] > 1 ?
|
|
49
|
-
lastModified: new Date(),
|
|
63
|
+
name: `${name + (nameCount[name] > 1 ? "-" + (nameCount[name] - 1) : "")}.json`,
|
|
64
|
+
lastModified: /* @__PURE__ */ new Date(),
|
|
50
65
|
input: getJsonFromItem(item)
|
|
51
66
|
};
|
|
52
67
|
});
|
|
53
|
-
return (0,
|
|
68
|
+
return (0, import_blob.downloadBlob)(
|
|
69
|
+
(0, import_i18n.__)("patterns-export") + ".zip",
|
|
70
|
+
await (0, import_client_zip.downloadZip)(filesToZip).blob(),
|
|
71
|
+
"application/zip"
|
|
72
|
+
);
|
|
54
73
|
}
|
|
55
74
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* Export action as JSON for Pattern.
|
|
59
|
-
*/
|
|
60
|
-
var _default = exports.default = exportPattern;
|
|
61
|
-
//# sourceMappingURL=export-pattern.js.map
|
|
75
|
+
var export_pattern_default = exportPattern;
|
|
76
|
+
//# sourceMappingURL=export-pattern.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/actions/export-pattern.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\nimport { downloadZip } from 'client-zip';\n\n/**\n * WordPress dependencies\n */\nimport { downloadBlob } from '@wordpress/blob';\nimport { __ } from '@wordpress/i18n';\nimport { download } from '@wordpress/icons';\nimport type { Action } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { Pattern } from '../types';\nimport { getItemTitle } from './utils';\n\nfunction getJsonFromItem( item: Pattern ) {\n\treturn JSON.stringify(\n\t\t{\n\t\t\t__file: item.type,\n\t\t\ttitle: getItemTitle( item ),\n\t\t\tcontent:\n\t\t\t\ttypeof item.content === 'string'\n\t\t\t\t\t? item.content\n\t\t\t\t\t: item.content?.raw,\n\t\t\tsyncStatus: item.wp_pattern_sync_status,\n\t\t},\n\t\tnull,\n\t\t2\n\t);\n}\n\nconst exportPattern: Action< Pattern > = {\n\tid: 'export-pattern',\n\tlabel: __( 'Export as JSON' ),\n\ticon: download,\n\tsupportsBulk: true,\n\tisEligible: ( item ) => item.type === 'wp_block',\n\tcallback: async ( items ) => {\n\t\tif ( items.length === 1 ) {\n\t\t\treturn downloadBlob(\n\t\t\t\t`${ kebabCase(\n\t\t\t\t\tgetItemTitle( items[ 0 ] ) || items[ 0 ].slug\n\t\t\t\t) }.json`,\n\t\t\t\tgetJsonFromItem( items[ 0 ] ),\n\t\t\t\t'application/json'\n\t\t\t);\n\t\t}\n\t\tconst nameCount: Record< string, number > = {};\n\t\tconst filesToZip = items.map( ( item ) => {\n\t\t\tconst name = kebabCase( getItemTitle( item ) || item.slug );\n\t\t\tnameCount[ name ] = ( nameCount[ name ] || 0 ) + 1;\n\t\t\treturn {\n\t\t\t\tname: `${\n\t\t\t\t\tname +\n\t\t\t\t\t( nameCount[ name ] > 1\n\t\t\t\t\t\t? '-' + ( nameCount[ name ] - 1 )\n\t\t\t\t\t\t: '' )\n\t\t\t\t}.json`,\n\t\t\t\tlastModified: new Date(),\n\t\t\t\tinput: getJsonFromItem( item ),\n\t\t\t};\n\t\t} );\n\t\treturn downloadBlob(\n\t\t\t__( 'patterns-export' ) + '.zip',\n\t\t\tawait downloadZip( filesToZip ).blob(),\n\t\t\t'application/zip'\n\t\t);\n\t},\n};\n\n/**\n * Export action as JSON for Pattern.\n */\nexport default exportPattern;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AACvC,wBAA4B;AAK5B,kBAA6B;AAC7B,kBAAmB;AACnB,mBAAyB;AAOzB,mBAA6B;AAE7B,SAAS,gBAAiB,MAAgB;AACzC,SAAO,KAAK;AAAA,IACX;AAAA,MACC,QAAQ,KAAK;AAAA,MACb,WAAO,2BAAc,IAAK;AAAA,MAC1B,SACC,OAAO,KAAK,YAAY,WACrB,KAAK,UACL,KAAK,SAAS;AAAA,MAClB,YAAY,KAAK;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEA,MAAM,gBAAmC;AAAA,EACxC,IAAI;AAAA,EACJ,WAAO,gBAAI,gBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,cAAc;AAAA,EACd,YAAY,CAAE,SAAU,KAAK,SAAS;AAAA,EACtC,UAAU,OAAQ,UAAW;AAC5B,QAAK,MAAM,WAAW,GAAI;AACzB,iBAAO;AAAA,QACN,OAAI,mBAAAA;AAAA,cACH,2BAAc,MAAO,CAAE,CAAE,KAAK,MAAO,CAAE,EAAE;AAAA,QAC1C,CAAE;AAAA,QACF,gBAAiB,MAAO,CAAE,CAAE;AAAA,QAC5B;AAAA,MACD;AAAA,IACD;AACA,UAAM,YAAsC,CAAC;AAC7C,UAAM,aAAa,MAAM,IAAK,CAAE,SAAU;AACzC,YAAM,WAAO,mBAAAA,eAAW,2BAAc,IAAK,KAAK,KAAK,IAAK;AAC1D,gBAAW,IAAK,KAAM,UAAW,IAAK,KAAK,KAAM;AACjD,aAAO;AAAA,QACN,MAAM,GACL,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