@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,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { store as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { orderField } from '../fields';
|
|
17
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useDispatch } from "@wordpress/data";
|
|
3
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
4
|
+
import { __ } from "@wordpress/i18n";
|
|
5
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
6
|
+
import { useState } from "@wordpress/element";
|
|
7
|
+
import { DataForm, isItemValid } from "@wordpress/dataviews";
|
|
8
|
+
import {
|
|
9
|
+
Button,
|
|
10
|
+
__experimentalHStack as HStack,
|
|
11
|
+
__experimentalVStack as VStack
|
|
12
|
+
} from "@wordpress/components";
|
|
13
|
+
import { orderField } from "../fields";
|
|
18
14
|
const fields = [orderField];
|
|
19
15
|
const formOrderAction = {
|
|
20
|
-
fields: [
|
|
16
|
+
fields: ["menu_order"]
|
|
21
17
|
};
|
|
22
18
|
function ReorderModal({
|
|
23
19
|
items,
|
|
@@ -26,90 +22,87 @@ function ReorderModal({
|
|
|
26
22
|
}) {
|
|
27
23
|
const [item, setItem] = useState(items[0]);
|
|
28
24
|
const orderInput = item.menu_order;
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
saveEditedEntityRecord
|
|
32
|
-
} = useDispatch(coreStore);
|
|
33
|
-
const {
|
|
34
|
-
createSuccessNotice,
|
|
35
|
-
createErrorNotice
|
|
36
|
-
} = useDispatch(noticesStore);
|
|
25
|
+
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
|
|
26
|
+
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
37
27
|
async function onOrder(event) {
|
|
38
28
|
event.preventDefault();
|
|
39
29
|
if (!isItemValid(item, fields, formOrderAction)) {
|
|
40
30
|
return;
|
|
41
31
|
}
|
|
42
32
|
try {
|
|
43
|
-
await editEntityRecord(
|
|
33
|
+
await editEntityRecord("postType", item.type, item.id, {
|
|
44
34
|
menu_order: orderInput
|
|
45
35
|
});
|
|
46
36
|
closeModal?.();
|
|
47
|
-
|
|
48
|
-
await saveEditedEntityRecord('postType', item.type, item.id, {
|
|
37
|
+
await saveEditedEntityRecord("postType", item.type, item.id, {
|
|
49
38
|
throwOnError: true
|
|
50
39
|
});
|
|
51
|
-
createSuccessNotice(__(
|
|
52
|
-
type:
|
|
40
|
+
createSuccessNotice(__("Order updated."), {
|
|
41
|
+
type: "snackbar"
|
|
53
42
|
});
|
|
54
43
|
onActionPerformed?.(items);
|
|
55
44
|
} catch (error) {
|
|
56
45
|
const typedError = error;
|
|
57
|
-
const errorMessage = typedError.message && typedError.code !==
|
|
46
|
+
const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : __("An error occurred while updating the order");
|
|
58
47
|
createErrorNotice(errorMessage, {
|
|
59
|
-
type:
|
|
48
|
+
type: "snackbar"
|
|
60
49
|
});
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
53
|
+
return /* @__PURE__ */ jsx("form", { onSubmit: onOrder, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
54
|
+
/* @__PURE__ */ jsx("div", { children: __(
|
|
55
|
+
"Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported."
|
|
56
|
+
) }),
|
|
57
|
+
/* @__PURE__ */ jsx(
|
|
58
|
+
DataForm,
|
|
59
|
+
{
|
|
71
60
|
data: item,
|
|
72
|
-
fields
|
|
61
|
+
fields,
|
|
73
62
|
form: formOrderAction,
|
|
74
|
-
onChange: changes => setItem({
|
|
63
|
+
onChange: (changes) => setItem({
|
|
75
64
|
...item,
|
|
76
65
|
...changes
|
|
77
66
|
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
70
|
+
/* @__PURE__ */ jsx(
|
|
71
|
+
Button,
|
|
72
|
+
{
|
|
81
73
|
__next40pxDefaultSize: true,
|
|
82
74
|
variant: "tertiary",
|
|
83
75
|
onClick: () => {
|
|
84
76
|
closeModal?.();
|
|
85
77
|
},
|
|
86
|
-
children: __(
|
|
87
|
-
}
|
|
78
|
+
children: __("Cancel")
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
/* @__PURE__ */ jsx(
|
|
82
|
+
Button,
|
|
83
|
+
{
|
|
88
84
|
__next40pxDefaultSize: true,
|
|
89
85
|
variant: "primary",
|
|
90
86
|
type: "submit",
|
|
91
87
|
accessibleWhenDisabled: true,
|
|
92
88
|
disabled: isSaveDisabled,
|
|
93
|
-
children: __(
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
});
|
|
89
|
+
children: __("Save")
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
] })
|
|
93
|
+
] }) });
|
|
98
94
|
}
|
|
99
95
|
const reorderPage = {
|
|
100
|
-
id:
|
|
101
|
-
label: __(
|
|
102
|
-
isEligible({
|
|
103
|
-
status
|
|
104
|
-
}) {
|
|
105
|
-
return status !== 'trash';
|
|
96
|
+
id: "order-pages",
|
|
97
|
+
label: __("Order"),
|
|
98
|
+
isEligible({ status }) {
|
|
99
|
+
return status !== "trash";
|
|
106
100
|
},
|
|
107
|
-
modalFocusOnMount:
|
|
101
|
+
modalFocusOnMount: "firstContentElement",
|
|
108
102
|
RenderModal: ReorderModal
|
|
109
103
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=reorder-page.js.map
|
|
104
|
+
var reorder_page_default = reorderPage;
|
|
105
|
+
export {
|
|
106
|
+
reorder_page_default as default
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=reorder-page.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/actions/reorder-page.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useState } from '@wordpress/element';\nimport { DataForm, isItemValid } from '@wordpress/dataviews';\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport type { Action, RenderModalProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { CoreDataError, BasePost } from '../types';\nimport { orderField } from '../fields';\n\nconst fields = [ orderField ];\nconst formOrderAction = {\n\tfields: [ 'menu_order' ],\n};\n\nfunction ReorderModal( {\n\titems,\n\tcloseModal,\n\tonActionPerformed,\n}: RenderModalProps< BasePost > ) {\n\tconst [ item, setItem ] = useState( items[ 0 ] );\n\tconst orderInput = item.menu_order;\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\n\tasync function onOrder( event: React.FormEvent ) {\n\t\tevent.preventDefault();\n\n\t\tif ( ! isItemValid( item, fields, formOrderAction ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait editEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tmenu_order: orderInput,\n\t\t\t} );\n\t\t\tcloseModal?.();\n\t\t\t// Persist edited entity.\n\t\t\tawait saveEditedEntityRecord( 'postType', item.type, item.id, {\n\t\t\t\tthrowOnError: true,\n\t\t\t} );\n\t\t\tcreateSuccessNotice( __( 'Order updated.' ), {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t\tonActionPerformed?.( items );\n\t\t} catch ( error ) {\n\t\t\tconst typedError = error as CoreDataError;\n\t\t\tconst errorMessage =\n\t\t\t\ttypedError.message && typedError.code !== 'unknown_error'\n\t\t\t\t\t? typedError.message\n\t\t\t\t\t: __( 'An error occurred while updating the order' );\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\tconst isSaveDisabled = ! isItemValid( item, fields, formOrderAction );\n\treturn (\n\t\t<form onSubmit={ onOrder }>\n\t\t\t<VStack spacing=\"5\">\n\t\t\t\t<div>\n\t\t\t\t\t{ __(\n\t\t\t\t\t\t'Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.'\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<DataForm\n\t\t\t\t\tdata={ item }\n\t\t\t\t\tfields={ fields }\n\t\t\t\t\tform={ formOrderAction }\n\t\t\t\t\tonChange={ ( changes ) =>\n\t\t\t\t\t\tsetItem( {\n\t\t\t\t\t\t\t...item,\n\t\t\t\t\t\t\t...changes,\n\t\t\t\t\t\t} )\n\t\t\t\t\t}\n\t\t\t\t/>\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\taccessibleWhenDisabled\n\t\t\t\t\t\tdisabled={ isSaveDisabled }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Save' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n\nconst reorderPage: Action< BasePost > = {\n\tid: 'order-pages',\n\tlabel: __( 'Order' ),\n\tisEligible( { status } ) {\n\t\treturn status !== 'trash';\n\t},\n\tmodalFocusOnMount: 'firstContentElement',\n\tRenderModal: ReorderModal,\n};\n\n/**\n * Reorder action for BasePost.\n */\nexport default reorderPage;\n"],
|
|
5
|
+
"mappings": "AA0EI,cAgBA,YAhBA;AAvEJ,SAAS,mBAAmB;AAC5B,SAAS,SAAS,iBAAiB;AACnC,SAAS,UAAU;AACnB,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AACzB,SAAS,UAAU,mBAAmB;AACtC;AAAA,EACC;AAAA,EACA,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,OAClB;AAOP,SAAS,kBAAkB;AAE3B,MAAM,SAAS,CAAE,UAAW;AAC5B,MAAM,kBAAkB;AAAA,EACvB,QAAQ,CAAE,YAAa;AACxB;AAEA,SAAS,aAAc;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,MAAO,CAAE,CAAE;AAC/C,QAAM,aAAa,KAAK;AACxB,QAAM,EAAE,kBAAkB,uBAAuB,IAChD,YAAa,SAAU;AACxB,QAAM,EAAE,qBAAqB,kBAAkB,IAC9C,YAAa,YAAa;AAE3B,iBAAe,QAAS,OAAyB;AAChD,UAAM,eAAe;AAErB,QAAK,CAAE,YAAa,MAAM,QAAQ,eAAgB,GAAI;AACrD;AAAA,IACD;AAEA,QAAI;AACH,YAAM,iBAAkB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QACvD,YAAY;AAAA,MACb,CAAE;AACF,mBAAa;AAEb,YAAM,uBAAwB,YAAY,KAAK,MAAM,KAAK,IAAI;AAAA,QAC7D,cAAc;AAAA,MACf,CAAE;AACF,0BAAqB,GAAI,gBAAiB,GAAG;AAAA,QAC5C,MAAM;AAAA,MACP,CAAE;AACF,0BAAqB,KAAM;AAAA,IAC5B,SAAU,OAAQ;AACjB,YAAM,aAAa;AACnB,YAAM,eACL,WAAW,WAAW,WAAW,SAAS,kBACvC,WAAW,UACX,GAAI,4CAA6C;AACrD,wBAAmB,cAAc;AAAA,QAChC,MAAM;AAAA,MACP,CAAE;AAAA,IACH;AAAA,EACD;AACA,QAAM,iBAAiB,CAAE,YAAa,MAAM,QAAQ,eAAgB;AACpE,SACC,oBAAC,UAAK,UAAW,SAChB,+BAAC,UAAO,SAAQ,KACf;AAAA,wBAAC,SACE;AAAA,MACD;AAAA,IACD,GACD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAO;AAAA,QACP;AAAA,QACA,MAAO;AAAA,QACP,UAAW,CAAE,YACZ,QAAS;AAAA,UACR,GAAG;AAAA,UACH,GAAG;AAAA,QACJ,CAAE;AAAA;AAAA,IAEJ;AAAA,IACA,qBAAC,UAAO,SAAQ,SACf;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,SAAU,MAAM;AACf,yBAAa;AAAA,UACd;AAAA,UAEE,aAAI,QAAS;AAAA;AAAA,MAChB;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,uBAAqB;AAAA,UACrB,SAAQ;AAAA,UACR,MAAK;AAAA,UACL,wBAAsB;AAAA,UACtB,UAAW;AAAA,UAET,aAAI,MAAO;AAAA;AAAA,MACd;AAAA,OACD;AAAA,KACD,GACD;AAEF;AAEA,MAAM,cAAkC;AAAA,EACvC,IAAI;AAAA,EACJ,OAAO,GAAI,OAAQ;AAAA,EACnB,WAAY,EAAE,OAAO,GAAI;AACxB,WAAO,WAAW;AAAA,EACnB;AAAA,EACA,mBAAmB;AAAA,EACnB,aAAa;AACd;AAKA,IAAO,uBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,202 +1,235 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { store as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import { getItemTitle, isTemplateOrTemplatePart } from './utils';
|
|
20
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
-
const isTemplateRevertable = templateOrTemplatePart => {
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { backup } from "@wordpress/icons";
|
|
3
|
+
import { dispatch, select, useDispatch } from "@wordpress/data";
|
|
4
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
5
|
+
import { __, sprintf } from "@wordpress/i18n";
|
|
6
|
+
import { store as noticesStore } from "@wordpress/notices";
|
|
7
|
+
import { useState } from "@wordpress/element";
|
|
8
|
+
import { parse, __unstableSerializeAndClean } from "@wordpress/blocks";
|
|
9
|
+
import {
|
|
10
|
+
Button,
|
|
11
|
+
__experimentalText as Text,
|
|
12
|
+
__experimentalHStack as HStack,
|
|
13
|
+
__experimentalVStack as VStack
|
|
14
|
+
} from "@wordpress/components";
|
|
15
|
+
import { addQueryArgs } from "@wordpress/url";
|
|
16
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
17
|
+
import { getItemTitle, isTemplateOrTemplatePart } from "./utils";
|
|
18
|
+
const isTemplateRevertable = (templateOrTemplatePart) => {
|
|
22
19
|
if (!templateOrTemplatePart) {
|
|
23
20
|
return false;
|
|
24
21
|
}
|
|
25
|
-
return templateOrTemplatePart.source ===
|
|
22
|
+
return templateOrTemplatePart.source === "custom" && (Boolean(templateOrTemplatePart?.plugin) || templateOrTemplatePart?.has_theme_file);
|
|
26
23
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* Copied - pasted from https://github.com/WordPress/gutenberg/blob/bf1462ad37d4637ebbf63270b9c244b23c69e2a8/packages/editor/src/store/private-actions.js#L233-L365
|
|
30
|
-
*
|
|
31
|
-
* @param {Object} template The template to revert.
|
|
32
|
-
* @param {Object} [options]
|
|
33
|
-
* @param {boolean} [options.allowUndo] Whether to allow the user to undo
|
|
34
|
-
* reverting the template. Default true.
|
|
35
|
-
*/
|
|
36
|
-
const revertTemplate = async (template, {
|
|
37
|
-
allowUndo = true
|
|
38
|
-
} = {}) => {
|
|
39
|
-
const noticeId = 'edit-site-template-reverted';
|
|
24
|
+
const revertTemplate = async (template, { allowUndo = true } = {}) => {
|
|
25
|
+
const noticeId = "edit-site-template-reverted";
|
|
40
26
|
dispatch(noticesStore).removeNotice(noticeId);
|
|
41
27
|
if (!isTemplateRevertable(template)) {
|
|
42
|
-
dispatch(noticesStore).createErrorNotice(
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
dispatch(noticesStore).createErrorNotice(
|
|
29
|
+
__("This template is not revertable."),
|
|
30
|
+
{
|
|
31
|
+
type: "snackbar"
|
|
32
|
+
}
|
|
33
|
+
);
|
|
45
34
|
return;
|
|
46
35
|
}
|
|
47
36
|
try {
|
|
48
|
-
const templateEntityConfig = select(coreStore).getEntityConfig(
|
|
37
|
+
const templateEntityConfig = select(coreStore).getEntityConfig(
|
|
38
|
+
"postType",
|
|
39
|
+
template.type
|
|
40
|
+
);
|
|
49
41
|
if (!templateEntityConfig) {
|
|
50
|
-
dispatch(noticesStore).createErrorNotice(
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
dispatch(noticesStore).createErrorNotice(
|
|
43
|
+
__(
|
|
44
|
+
"The editor has encountered an unexpected error. Please reload."
|
|
45
|
+
),
|
|
46
|
+
{ type: "snackbar" }
|
|
47
|
+
);
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
55
|
-
const fileTemplatePath = addQueryArgs(
|
|
56
|
-
|
|
57
|
-
source: template.origin
|
|
58
|
-
|
|
50
|
+
const fileTemplatePath = addQueryArgs(
|
|
51
|
+
`${templateEntityConfig.baseURL}/${template.id}`,
|
|
52
|
+
{ context: "edit", source: template.origin }
|
|
53
|
+
);
|
|
59
54
|
const fileTemplate = await apiFetch({
|
|
60
55
|
path: fileTemplatePath
|
|
61
56
|
});
|
|
62
57
|
if (!fileTemplate) {
|
|
63
|
-
dispatch(noticesStore).createErrorNotice(
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
dispatch(noticesStore).createErrorNotice(
|
|
59
|
+
__(
|
|
60
|
+
"The editor has encountered an unexpected error. Please reload."
|
|
61
|
+
),
|
|
62
|
+
{ type: "snackbar" }
|
|
63
|
+
);
|
|
66
64
|
return;
|
|
67
65
|
}
|
|
68
|
-
const serializeBlocks = ({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
66
|
+
const serializeBlocks = ({ blocks: blocksForSerialization = [] }) => __unstableSerializeAndClean(blocksForSerialization);
|
|
67
|
+
const edited = select(coreStore).getEditedEntityRecord(
|
|
68
|
+
"postType",
|
|
69
|
+
template.type,
|
|
70
|
+
template.id
|
|
71
|
+
);
|
|
72
|
+
dispatch(coreStore).editEntityRecord(
|
|
73
|
+
"postType",
|
|
74
|
+
template.type,
|
|
75
|
+
template.id,
|
|
76
|
+
{
|
|
77
|
+
content: serializeBlocks,
|
|
78
|
+
// Required to make the `undo` behave correctly.
|
|
79
|
+
blocks: edited.blocks,
|
|
80
|
+
// Required to revert the blocks in the editor.
|
|
81
|
+
source: "custom"
|
|
82
|
+
// required to avoid turning the editor into a dirty state
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
undoIgnore: true
|
|
86
|
+
// Required to merge this edit with the last undo level.
|
|
87
|
+
}
|
|
88
|
+
);
|
|
84
89
|
const blocks = parse(fileTemplate?.content?.raw);
|
|
85
|
-
dispatch(coreStore).editEntityRecord(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
dispatch(coreStore).editEntityRecord(
|
|
91
|
+
"postType",
|
|
92
|
+
template.type,
|
|
93
|
+
fileTemplate.id,
|
|
94
|
+
{
|
|
95
|
+
content: serializeBlocks,
|
|
96
|
+
blocks,
|
|
97
|
+
source: "theme"
|
|
98
|
+
}
|
|
99
|
+
);
|
|
90
100
|
if (allowUndo) {
|
|
91
101
|
const undoRevert = () => {
|
|
92
|
-
dispatch(coreStore).editEntityRecord(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
dispatch(coreStore).editEntityRecord(
|
|
103
|
+
"postType",
|
|
104
|
+
template.type,
|
|
105
|
+
edited.id,
|
|
106
|
+
{
|
|
107
|
+
content: serializeBlocks,
|
|
108
|
+
blocks: edited.blocks,
|
|
109
|
+
source: "custom"
|
|
110
|
+
}
|
|
111
|
+
);
|
|
97
112
|
};
|
|
98
|
-
dispatch(noticesStore).createSuccessNotice(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
113
|
+
dispatch(noticesStore).createSuccessNotice(
|
|
114
|
+
__("Template reset."),
|
|
115
|
+
{
|
|
116
|
+
type: "snackbar",
|
|
117
|
+
id: noticeId,
|
|
118
|
+
actions: [
|
|
119
|
+
{
|
|
120
|
+
label: __("Undo"),
|
|
121
|
+
onClick: undoRevert
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
);
|
|
106
126
|
}
|
|
107
127
|
} catch (error) {
|
|
108
|
-
const errorMessage = error.message && error.code !==
|
|
128
|
+
const errorMessage = error.message && error.code !== "unknown_error" ? error.message : __("Template revert failed. Please reload.");
|
|
109
129
|
dispatch(noticesStore).createErrorNotice(errorMessage, {
|
|
110
|
-
type:
|
|
130
|
+
type: "snackbar"
|
|
111
131
|
});
|
|
112
132
|
}
|
|
113
133
|
};
|
|
114
134
|
const resetPostAction = {
|
|
115
|
-
id:
|
|
116
|
-
label: __(
|
|
117
|
-
isEligible: item => {
|
|
118
|
-
return isTemplateOrTemplatePart(item) && item?.source ===
|
|
135
|
+
id: "reset-post",
|
|
136
|
+
label: __("Reset"),
|
|
137
|
+
isEligible: (item) => {
|
|
138
|
+
return isTemplateOrTemplatePart(item) && item?.source === "custom" && (Boolean(item.type === "wp_template" && item?.plugin) || item?.has_theme_file);
|
|
119
139
|
},
|
|
120
140
|
icon: backup,
|
|
121
141
|
supportsBulk: true,
|
|
122
142
|
hideModalHeader: true,
|
|
123
|
-
modalFocusOnMount:
|
|
124
|
-
RenderModal: ({
|
|
125
|
-
items,
|
|
126
|
-
closeModal,
|
|
127
|
-
onActionPerformed
|
|
128
|
-
}) => {
|
|
143
|
+
modalFocusOnMount: "firstContentElement",
|
|
144
|
+
RenderModal: ({ items, closeModal, onActionPerformed }) => {
|
|
129
145
|
const [isBusy, setIsBusy] = useState(false);
|
|
130
|
-
const {
|
|
131
|
-
|
|
132
|
-
} = useDispatch(coreStore);
|
|
133
|
-
const {
|
|
134
|
-
createSuccessNotice,
|
|
135
|
-
createErrorNotice
|
|
136
|
-
} = useDispatch(noticesStore);
|
|
146
|
+
const { saveEditedEntityRecord } = useDispatch(coreStore);
|
|
147
|
+
const { createSuccessNotice, createErrorNotice } = useDispatch(noticesStore);
|
|
137
148
|
const onConfirm = async () => {
|
|
138
149
|
try {
|
|
139
150
|
for (const template of items) {
|
|
140
151
|
await revertTemplate(template, {
|
|
141
152
|
allowUndo: false
|
|
142
153
|
});
|
|
143
|
-
await saveEditedEntityRecord(
|
|
154
|
+
await saveEditedEntityRecord(
|
|
155
|
+
"postType",
|
|
156
|
+
template.type,
|
|
157
|
+
template.id
|
|
158
|
+
);
|
|
144
159
|
}
|
|
145
|
-
createSuccessNotice(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
160
|
+
createSuccessNotice(
|
|
161
|
+
items.length > 1 ? sprintf(
|
|
162
|
+
/* translators: %d: The number of items. */
|
|
163
|
+
__("%d items reset."),
|
|
164
|
+
items.length
|
|
165
|
+
) : sprintf(
|
|
166
|
+
/* translators: %s: The template/part's name. */
|
|
167
|
+
__('"%s" reset.'),
|
|
168
|
+
getItemTitle(items[0])
|
|
169
|
+
),
|
|
170
|
+
{
|
|
171
|
+
type: "snackbar",
|
|
172
|
+
id: "revert-template-action"
|
|
173
|
+
}
|
|
174
|
+
);
|
|
151
175
|
} catch (error) {
|
|
152
176
|
let fallbackErrorMessage;
|
|
153
|
-
if (items[0].type ===
|
|
154
|
-
fallbackErrorMessage = items.length === 1 ? __(
|
|
177
|
+
if (items[0].type === "wp_template") {
|
|
178
|
+
fallbackErrorMessage = items.length === 1 ? __(
|
|
179
|
+
"An error occurred while reverting the template."
|
|
180
|
+
) : __(
|
|
181
|
+
"An error occurred while reverting the templates."
|
|
182
|
+
);
|
|
155
183
|
} else {
|
|
156
|
-
fallbackErrorMessage = items.length === 1 ? __(
|
|
184
|
+
fallbackErrorMessage = items.length === 1 ? __(
|
|
185
|
+
"An error occurred while reverting the template part."
|
|
186
|
+
) : __(
|
|
187
|
+
"An error occurred while reverting the template parts."
|
|
188
|
+
);
|
|
157
189
|
}
|
|
158
190
|
const typedError = error;
|
|
159
|
-
const errorMessage = typedError.message && typedError.code !==
|
|
160
|
-
createErrorNotice(errorMessage, {
|
|
161
|
-
type: 'snackbar'
|
|
162
|
-
});
|
|
191
|
+
const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : fallbackErrorMessage;
|
|
192
|
+
createErrorNotice(errorMessage, { type: "snackbar" });
|
|
163
193
|
}
|
|
164
194
|
};
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
return /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
|
|
196
|
+
/* @__PURE__ */ jsx(Text, { children: __("Reset to default and clear all customizations?") }),
|
|
197
|
+
/* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
Button,
|
|
200
|
+
{
|
|
201
|
+
__next40pxDefaultSize: true,
|
|
202
|
+
variant: "tertiary",
|
|
203
|
+
onClick: closeModal,
|
|
204
|
+
disabled: isBusy,
|
|
205
|
+
accessibleWhenDisabled: true,
|
|
206
|
+
children: __("Cancel")
|
|
207
|
+
}
|
|
208
|
+
),
|
|
209
|
+
/* @__PURE__ */ jsx(
|
|
210
|
+
Button,
|
|
211
|
+
{
|
|
212
|
+
__next40pxDefaultSize: true,
|
|
213
|
+
variant: "primary",
|
|
214
|
+
onClick: async () => {
|
|
215
|
+
setIsBusy(true);
|
|
216
|
+
await onConfirm();
|
|
217
|
+
onActionPerformed?.(items);
|
|
218
|
+
setIsBusy(false);
|
|
219
|
+
closeModal?.();
|
|
220
|
+
},
|
|
221
|
+
isBusy,
|
|
222
|
+
disabled: isBusy,
|
|
223
|
+
accessibleWhenDisabled: true,
|
|
224
|
+
children: __("Reset")
|
|
225
|
+
}
|
|
226
|
+
)
|
|
227
|
+
] })
|
|
228
|
+
] });
|
|
195
229
|
}
|
|
196
230
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
//# sourceMappingURL=reset-post.js.map
|
|
231
|
+
var reset_post_default = resetPostAction;
|
|
232
|
+
export {
|
|
233
|
+
reset_post_default as default
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=reset-post.js.map
|