@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.
Files changed (250) hide show
  1. package/README.md +1 -1
  2. package/build/actions/delete-post.js +168 -117
  3. package/build/actions/delete-post.js.map +7 -1
  4. package/build/actions/duplicate-pattern.js +42 -43
  5. package/build/actions/duplicate-pattern.js.map +7 -1
  6. package/build/actions/duplicate-post.js +104 -93
  7. package/build/actions/duplicate-post.js.map +7 -1
  8. package/build/actions/duplicate-template-part.js +71 -63
  9. package/build/actions/duplicate-template-part.js.map +7 -1
  10. package/build/actions/export-pattern.js +60 -45
  11. package/build/actions/export-pattern.js.map +7 -1
  12. package/build/actions/index.js +71 -94
  13. package/build/actions/index.js.map +7 -1
  14. package/build/actions/permanently-delete-post.js +161 -132
  15. package/build/actions/permanently-delete-post.js.map +7 -1
  16. package/build/actions/rename-post.js +77 -83
  17. package/build/actions/rename-post.js.map +7 -1
  18. package/build/actions/reorder-page.js +76 -73
  19. package/build/actions/reorder-page.js.map +7 -1
  20. package/build/actions/reset-post.js +214 -165
  21. package/build/actions/reset-post.js.map +7 -1
  22. package/build/actions/restore-post.js +91 -75
  23. package/build/actions/restore-post.js.map +7 -1
  24. package/build/actions/trash-post.js +167 -127
  25. package/build/actions/trash-post.js.map +7 -1
  26. package/build/actions/utils.js +48 -41
  27. package/build/actions/utils.js.map +7 -1
  28. package/build/actions/view-post-revisions.js +39 -35
  29. package/build/actions/view-post-revisions.js.map +7 -1
  30. package/build/actions/view-post.js +31 -28
  31. package/build/actions/view-post.js.map +7 -1
  32. package/build/components/create-template-part-modal/index.js +213 -169
  33. package/build/components/create-template-part-modal/index.js.map +7 -1
  34. package/build/components/create-template-part-modal/utils.js +48 -48
  35. package/build/components/create-template-part-modal/utils.js.map +7 -1
  36. package/build/fields/author/author-view.js +63 -69
  37. package/build/fields/author/author-view.js.map +7 -1
  38. package/build/fields/author/index.js +43 -29
  39. package/build/fields/author/index.js.map +7 -1
  40. package/build/fields/comment-status/index.js +42 -32
  41. package/build/fields/comment-status/index.js.map +7 -1
  42. package/build/fields/date/date-view.js +84 -58
  43. package/build/fields/date/date-view.js.map +7 -1
  44. package/build/fields/date/index.js +39 -25
  45. package/build/fields/date/index.js.map +7 -1
  46. package/build/fields/discussion/index.js +36 -32
  47. package/build/fields/discussion/index.js.map +7 -1
  48. package/build/fields/featured-image/featured-image-edit.js +115 -97
  49. package/build/fields/featured-image/featured-image-edit.js.map +7 -1
  50. package/build/fields/featured-image/featured-image-view.js +41 -34
  51. package/build/fields/featured-image/featured-image-view.js.map +7 -1
  52. package/build/fields/featured-image/index.js +31 -26
  53. package/build/fields/featured-image/index.js.map +7 -1
  54. package/build/fields/index.js +83 -118
  55. package/build/fields/index.js.map +7 -1
  56. package/build/fields/order/index.js +28 -23
  57. package/build/fields/order/index.js.map +7 -1
  58. package/build/fields/page-title/index.js +42 -30
  59. package/build/fields/page-title/index.js.map +7 -1
  60. package/build/fields/page-title/view.js +38 -41
  61. package/build/fields/page-title/view.js.map +7 -1
  62. package/build/fields/parent/index.js +31 -26
  63. package/build/fields/parent/index.js.map +7 -1
  64. package/build/fields/parent/parent-edit.js +200 -168
  65. package/build/fields/parent/parent-edit.js.map +7 -1
  66. package/build/fields/parent/parent-view.js +40 -31
  67. package/build/fields/parent/parent-view.js.map +7 -1
  68. package/build/fields/parent/utils.js +29 -16
  69. package/build/fields/parent/utils.js.map +7 -1
  70. package/build/fields/password/edit.js +67 -53
  71. package/build/fields/password/edit.js.map +7 -1
  72. package/build/fields/password/index.js +40 -26
  73. package/build/fields/password/index.js.map +7 -1
  74. package/build/fields/pattern-title/index.js +42 -30
  75. package/build/fields/pattern-title/index.js.map +7 -1
  76. package/build/fields/pattern-title/view.js +43 -41
  77. package/build/fields/pattern-title/view.js.map +7 -1
  78. package/build/fields/ping-status/index.js +66 -47
  79. package/build/fields/ping-status/index.js.map +7 -1
  80. package/build/fields/slug/index.js +41 -27
  81. package/build/fields/slug/index.js.map +7 -1
  82. package/build/fields/slug/slug-edit.js +116 -107
  83. package/build/fields/slug/slug-edit.js.map +7 -1
  84. package/build/fields/slug/slug-view.js +30 -23
  85. package/build/fields/slug/slug-view.js.map +7 -1
  86. package/build/fields/slug/utils.js +32 -20
  87. package/build/fields/slug/utils.js.map +7 -1
  88. package/build/fields/status/index.js +43 -29
  89. package/build/fields/status/index.js.map +7 -1
  90. package/build/fields/status/status-elements.js +58 -44
  91. package/build/fields/status/status-elements.js.map +7 -1
  92. package/build/fields/status/status-view.js +42 -36
  93. package/build/fields/status/status-view.js.map +7 -1
  94. package/build/fields/template/index.js +29 -24
  95. package/build/fields/template/index.js.map +7 -1
  96. package/build/fields/template/template-edit.js +167 -142
  97. package/build/fields/template/template-edit.js.map +7 -1
  98. package/build/fields/template-title/index.js +42 -30
  99. package/build/fields/template-title/index.js.map +7 -1
  100. package/build/fields/title/index.js +42 -32
  101. package/build/fields/title/index.js.map +7 -1
  102. package/build/fields/title/view.js +57 -39
  103. package/build/fields/title/view.js.map +7 -1
  104. package/build/index.js +39 -36
  105. package/build/index.js.map +7 -1
  106. package/build/lock-unlock.js +31 -14
  107. package/build/lock-unlock.js.map +7 -1
  108. package/build/mutation/index.js +91 -76
  109. package/build/mutation/index.js.map +7 -1
  110. package/build/types.js +16 -5
  111. package/build/types.js.map +7 -1
  112. package/build-module/actions/delete-post.js +155 -107
  113. package/build-module/actions/delete-post.js.map +7 -1
  114. package/build-module/actions/duplicate-pattern.js +24 -36
  115. package/build-module/actions/duplicate-pattern.js.map +7 -1
  116. package/build-module/actions/duplicate-post.js +87 -84
  117. package/build-module/actions/duplicate-post.js.map +7 -1
  118. package/build-module/actions/duplicate-template-part.js +51 -58
  119. package/build-module/actions/duplicate-template-part.js.map +7 -1
  120. package/build-module/actions/export-pattern.js +40 -39
  121. package/build-module/actions/export-pattern.js.map +7 -1
  122. package/build-module/actions/index.js +29 -14
  123. package/build-module/actions/index.js.map +7 -1
  124. package/build-module/actions/permanently-delete-post.js +146 -125
  125. package/build-module/actions/permanently-delete-post.js.map +7 -1
  126. package/build-module/actions/rename-post.js +63 -77
  127. package/build-module/actions/rename-post.js.map +7 -1
  128. package/build-module/actions/reorder-page.js +58 -65
  129. package/build-module/actions/reorder-page.js.map +7 -1
  130. package/build-module/actions/reset-post.js +185 -152
  131. package/build-module/actions/reset-post.js.map +7 -1
  132. package/build-module/actions/restore-post.js +72 -68
  133. package/build-module/actions/restore-post.js.map +7 -1
  134. package/build-module/actions/trash-post.js +152 -119
  135. package/build-module/actions/trash-post.js.map +7 -1
  136. package/build-module/actions/utils.js +23 -34
  137. package/build-module/actions/utils.js.map +7 -1
  138. package/build-module/actions/view-post-revisions.js +21 -31
  139. package/build-module/actions/view-post-revisions.js.map +7 -1
  140. package/build-module/actions/view-post.js +12 -23
  141. package/build-module/actions/view-post.js.map +7 -1
  142. package/build-module/components/create-template-part-modal/index.js +201 -154
  143. package/build-module/components/create-template-part-modal/index.js.map +7 -1
  144. package/build-module/components/create-template-part-modal/utils.js +26 -43
  145. package/build-module/components/create-template-part-modal/utils.js.map +7 -1
  146. package/build-module/fields/author/author-view.js +34 -62
  147. package/build-module/fields/author/author-view.js.map +7 -1
  148. package/build-module/fields/author/index.js +14 -24
  149. package/build-module/fields/author/index.js.map +7 -1
  150. package/build-module/fields/comment-status/index.js +24 -29
  151. package/build-module/fields/comment-status/index.js.map +7 -1
  152. package/build-module/fields/date/date-view.js +66 -53
  153. package/build-module/fields/date/date-view.js.map +7 -1
  154. package/build-module/fields/date/index.js +10 -20
  155. package/build-module/fields/date/index.js.map +7 -1
  156. package/build-module/fields/discussion/index.js +18 -29
  157. package/build-module/fields/discussion/index.js.map +7 -1
  158. package/build-module/fields/featured-image/featured-image-edit.js +93 -90
  159. package/build-module/fields/featured-image/featured-image-edit.js.map +7 -1
  160. package/build-module/fields/featured-image/featured-image-view.js +20 -29
  161. package/build-module/fields/featured-image/featured-image-view.js.map +7 -1
  162. package/build-module/fields/featured-image/index.js +11 -21
  163. package/build-module/fields/featured-image/index.js.map +7 -1
  164. package/build-module/fields/index.js +35 -17
  165. package/build-module/fields/index.js.map +7 -1
  166. package/build-module/fields/order/index.js +10 -20
  167. package/build-module/fields/order/index.js.map +7 -1
  168. package/build-module/fields/page-title/index.js +13 -25
  169. package/build-module/fields/page-title/index.js.map +7 -1
  170. package/build-module/fields/page-title/view.js +20 -37
  171. package/build-module/fields/page-title/view.js.map +7 -1
  172. package/build-module/fields/parent/index.js +11 -21
  173. package/build-module/fields/parent/index.js.map +7 -1
  174. package/build-module/fields/parent/parent-edit.js +172 -160
  175. package/build-module/fields/parent/parent-edit.js.map +7 -1
  176. package/build-module/fields/parent/parent-view.js +19 -27
  177. package/build-module/fields/parent/parent-view.js.map +7 -1
  178. package/build-module/fields/parent/utils.js +8 -13
  179. package/build-module/fields/parent/utils.js.map +7 -1
  180. package/build-module/fields/password/edit.js +53 -48
  181. package/build-module/fields/password/edit.js.map +7 -1
  182. package/build-module/fields/password/index.js +11 -21
  183. package/build-module/fields/password/index.js.map +7 -1
  184. package/build-module/fields/pattern-title/index.js +13 -25
  185. package/build-module/fields/pattern-title/index.js.map +7 -1
  186. package/build-module/fields/pattern-title/view.js +21 -34
  187. package/build-module/fields/pattern-title/view.js.map +7 -1
  188. package/build-module/fields/ping-status/index.js +48 -43
  189. package/build-module/fields/ping-status/index.js.map +7 -1
  190. package/build-module/fields/slug/index.js +11 -21
  191. package/build-module/fields/slug/index.js.map +7 -1
  192. package/build-module/fields/slug/slug-edit.js +101 -100
  193. package/build-module/fields/slug/slug-edit.js.map +7 -1
  194. package/build-module/fields/slug/slug-view.js +9 -16
  195. package/build-module/fields/slug/slug-view.js.map +7 -1
  196. package/build-module/fields/slug/utils.js +9 -13
  197. package/build-module/fields/slug/utils.js.map +7 -1
  198. package/build-module/fields/status/index.js +13 -23
  199. package/build-module/fields/status/index.js.map +7 -1
  200. package/build-module/fields/status/status-elements.js +47 -40
  201. package/build-module/fields/status/status-elements.js.map +7 -1
  202. package/build-module/fields/status/status-view.js +14 -31
  203. package/build-module/fields/status/status-view.js.map +7 -1
  204. package/build-module/fields/template/index.js +10 -18
  205. package/build-module/fields/template/index.js.map +7 -1
  206. package/build-module/fields/template/template-edit.js +147 -130
  207. package/build-module/fields/template/template-edit.js.map +7 -1
  208. package/build-module/fields/template-title/index.js +13 -25
  209. package/build-module/fields/template-title/index.js.map +7 -1
  210. package/build-module/fields/title/index.js +13 -27
  211. package/build-module/fields/title/index.js.map +7 -1
  212. package/build-module/fields/title/view.js +25 -32
  213. package/build-module/fields/title/view.js.map +7 -1
  214. package/build-module/index.js +7 -4
  215. package/build-module/index.js.map +7 -1
  216. package/build-module/lock-unlock.js +8 -7
  217. package/build-module/lock-unlock.js.map +7 -1
  218. package/build-module/mutation/index.js +70 -72
  219. package/build-module/mutation/index.js.map +7 -1
  220. package/build-module/types.js +1 -2
  221. package/build-module/types.js.map +7 -1
  222. package/build-style/style-rtl.css +4 -139
  223. package/build-style/style.css +4 -139
  224. package/build-types/fields/author/author-view.d.ts.map +1 -1
  225. package/build-types/fields/discussion/index.d.ts.map +1 -1
  226. package/build-types/fields/featured-image/featured-image-edit.d.ts +2 -2
  227. package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -1
  228. package/build-types/fields/featured-image/featured-image-view.d.ts +5 -2
  229. package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -1
  230. package/build-types/fields/featured-image/index.d.ts +3 -3
  231. package/build-types/fields/featured-image/index.d.ts.map +1 -1
  232. package/build-types/types.d.ts +18 -0
  233. package/build-types/types.d.ts.map +1 -1
  234. package/package.json +34 -27
  235. package/src/components/create-template-part-modal/style.scss +4 -0
  236. package/src/fields/author/author-view.tsx +3 -17
  237. package/src/fields/discussion/index.tsx +1 -0
  238. package/src/fields/featured-image/featured-image-edit.tsx +2 -2
  239. package/src/fields/featured-image/featured-image-view.tsx +3 -15
  240. package/src/fields/featured-image/index.ts +3 -3
  241. package/src/fields/featured-image/style.scss +3 -0
  242. package/src/fields/template/style.scss +4 -0
  243. package/src/fields/title/style.scss +1 -1
  244. package/src/style.scss +9 -8
  245. package/src/types.ts +18 -0
  246. package/tsconfig.tsbuildinfo +1 -1
  247. package/build/index.native.js +0 -2
  248. package/build/index.native.js.map +0 -1
  249. package/build-module/index.native.js +0 -2
  250. package/build-module/index.native.js.map +0 -1
@@ -1,23 +1,19 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useDispatch } from '@wordpress/data';
5
- import { store as coreStore } from '@wordpress/core-data';
6
- import { __ } from '@wordpress/i18n';
7
- import { store as noticesStore } from '@wordpress/notices';
8
- import { useState } from '@wordpress/element';
9
- import { DataForm, isItemValid } from '@wordpress/dataviews';
10
- import { Button, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
11
-
12
- /**
13
- * Internal dependencies
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: ['menu_order']
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
- editEntityRecord,
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('postType', item.type, item.id, {
33
+ await editEntityRecord("postType", item.type, item.id, {
44
34
  menu_order: orderInput
45
35
  });
46
36
  closeModal?.();
47
- // Persist edited entity.
48
- await saveEditedEntityRecord('postType', item.type, item.id, {
37
+ await saveEditedEntityRecord("postType", item.type, item.id, {
49
38
  throwOnError: true
50
39
  });
51
- createSuccessNotice(__('Order updated.'), {
52
- type: 'snackbar'
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 !== 'unknown_error' ? typedError.message : __('An error occurred while updating the order');
46
+ const errorMessage = typedError.message && typedError.code !== "unknown_error" ? typedError.message : __("An error occurred while updating the order");
58
47
  createErrorNotice(errorMessage, {
59
- type: 'snackbar'
48
+ type: "snackbar"
60
49
  });
61
50
  }
62
51
  }
63
52
  const isSaveDisabled = !isItemValid(item, fields, formOrderAction);
64
- return /*#__PURE__*/_jsx("form", {
65
- onSubmit: onOrder,
66
- children: /*#__PURE__*/_jsxs(VStack, {
67
- spacing: "5",
68
- children: [/*#__PURE__*/_jsx("div", {
69
- children: __('Determines the order of pages. Pages with the same order value are sorted alphabetically. Negative order values are supported.')
70
- }), /*#__PURE__*/_jsx(DataForm, {
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: fields,
61
+ fields,
73
62
  form: formOrderAction,
74
- onChange: changes => setItem({
63
+ onChange: (changes) => setItem({
75
64
  ...item,
76
65
  ...changes
77
66
  })
78
- }), /*#__PURE__*/_jsxs(HStack, {
79
- justify: "right",
80
- children: [/*#__PURE__*/_jsx(Button, {
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: __('Cancel')
87
- }), /*#__PURE__*/_jsx(Button, {
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: __('Save')
94
- })]
95
- })]
96
- })
97
- });
89
+ children: __("Save")
90
+ }
91
+ )
92
+ ] })
93
+ ] }) });
98
94
  }
99
95
  const reorderPage = {
100
- id: 'order-pages',
101
- label: __('Order'),
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: 'firstContentElement',
101
+ modalFocusOnMount: "firstContentElement",
108
102
  RenderModal: ReorderModal
109
103
  };
110
-
111
- /**
112
- * Reorder action for BasePost.
113
- */
114
- export default reorderPage;
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
- {"version":3,"names":["useDispatch","store","coreStore","__","noticesStore","useState","DataForm","isItemValid","Button","__experimentalHStack","HStack","__experimentalVStack","VStack","orderField","jsx","_jsx","jsxs","_jsxs","fields","formOrderAction","ReorderModal","items","closeModal","onActionPerformed","item","setItem","orderInput","menu_order","editEntityRecord","saveEditedEntityRecord","createSuccessNotice","createErrorNotice","onOrder","event","preventDefault","type","id","throwOnError","error","typedError","errorMessage","message","code","isSaveDisabled","onSubmit","children","spacing","data","form","onChange","changes","justify","__next40pxDefaultSize","variant","onClick","accessibleWhenDisabled","disabled","reorderPage","label","isEligible","status","modalFocusOnMount","RenderModal"],"sources":["@wordpress/fields/src/actions/reorder-page.tsx"],"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"],"mappings":"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","ignoreList":[]}
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
- * WordPress dependencies
3
- */
4
- import { backup } from '@wordpress/icons';
5
- import { dispatch, select, useDispatch } from '@wordpress/data';
6
- import { store as coreStore } from '@wordpress/core-data';
7
- import { __, sprintf } from '@wordpress/i18n';
8
- import { store as noticesStore } from '@wordpress/notices';
9
- import { useState } from '@wordpress/element';
10
- // @ts-ignore
11
- import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
12
- import { Button, __experimentalText as Text, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
13
- import { addQueryArgs } from '@wordpress/url';
14
- import apiFetch from '@wordpress/api-fetch';
15
-
16
- /**
17
- * Internal dependencies
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 === 'custom' && (Boolean(templateOrTemplatePart?.plugin) || templateOrTemplatePart?.has_theme_file);
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(__('This template is not revertable.'), {
43
- type: 'snackbar'
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('postType', template.type);
37
+ const templateEntityConfig = select(coreStore).getEntityConfig(
38
+ "postType",
39
+ template.type
40
+ );
49
41
  if (!templateEntityConfig) {
50
- dispatch(noticesStore).createErrorNotice(__('The editor has encountered an unexpected error. Please reload.'), {
51
- type: 'snackbar'
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(`${templateEntityConfig.baseURL}/${template.id}`, {
56
- context: 'edit',
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(__('The editor has encountered an unexpected error. Please reload.'), {
64
- type: 'snackbar'
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
- blocks: blocksForSerialization = []
70
- }) => __unstableSerializeAndClean(blocksForSerialization);
71
- const edited = select(coreStore).getEditedEntityRecord('postType', template.type, template.id);
72
-
73
- // We are fixing up the undo level here to make sure we can undo
74
- // the revert in the header toolbar correctly.
75
- dispatch(coreStore).editEntityRecord('postType', template.type, template.id, {
76
- content: serializeBlocks,
77
- // Required to make the `undo` behave correctly.
78
- blocks: edited.blocks,
79
- // Required to revert the blocks in the editor.
80
- source: 'custom' // required to avoid turning the editor into a dirty state
81
- }, {
82
- undoIgnore: true // Required to merge this edit with the last undo level.
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('postType', template.type, fileTemplate.id, {
86
- content: serializeBlocks,
87
- blocks,
88
- source: 'theme'
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('postType', template.type, edited.id, {
93
- content: serializeBlocks,
94
- blocks: edited.blocks,
95
- source: 'custom'
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(__('Template reset.'), {
99
- type: 'snackbar',
100
- id: noticeId,
101
- actions: [{
102
- label: __('Undo'),
103
- onClick: undoRevert
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 !== 'unknown_error' ? error.message : __('Template revert failed. Please reload.');
128
+ const errorMessage = error.message && error.code !== "unknown_error" ? error.message : __("Template revert failed. Please reload.");
109
129
  dispatch(noticesStore).createErrorNotice(errorMessage, {
110
- type: 'snackbar'
130
+ type: "snackbar"
111
131
  });
112
132
  }
113
133
  };
114
134
  const resetPostAction = {
115
- id: 'reset-post',
116
- label: __('Reset'),
117
- isEligible: item => {
118
- return isTemplateOrTemplatePart(item) && item?.source === 'custom' && (Boolean(item.type === 'wp_template' && item?.plugin) || item?.has_theme_file);
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: 'firstContentElement',
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
- saveEditedEntityRecord
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('postType', template.type, template.id);
154
+ await saveEditedEntityRecord(
155
+ "postType",
156
+ template.type,
157
+ template.id
158
+ );
144
159
  }
145
- createSuccessNotice(items.length > 1 ? sprintf(/* translators: %d: The number of items. */
146
- __('%d items reset.'), items.length) : sprintf(/* translators: %s: The template/part's name. */
147
- __('"%s" reset.'), getItemTitle(items[0])), {
148
- type: 'snackbar',
149
- id: 'revert-template-action'
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 === 'wp_template') {
154
- fallbackErrorMessage = items.length === 1 ? __('An error occurred while reverting the template.') : __('An error occurred while reverting the templates.');
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 ? __('An error occurred while reverting the template part.') : __('An error occurred while reverting the template parts.');
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 !== 'unknown_error' ? typedError.message : fallbackErrorMessage;
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 /*#__PURE__*/_jsxs(VStack, {
166
- spacing: "5",
167
- children: [/*#__PURE__*/_jsx(Text, {
168
- children: __('Reset to default and clear all customizations?')
169
- }), /*#__PURE__*/_jsxs(HStack, {
170
- justify: "right",
171
- children: [/*#__PURE__*/_jsx(Button, {
172
- __next40pxDefaultSize: true,
173
- variant: "tertiary",
174
- onClick: closeModal,
175
- disabled: isBusy,
176
- accessibleWhenDisabled: true,
177
- children: __('Cancel')
178
- }), /*#__PURE__*/_jsx(Button, {
179
- __next40pxDefaultSize: true,
180
- variant: "primary",
181
- onClick: async () => {
182
- setIsBusy(true);
183
- await onConfirm();
184
- onActionPerformed?.(items);
185
- setIsBusy(false);
186
- closeModal?.();
187
- },
188
- isBusy: isBusy,
189
- disabled: isBusy,
190
- accessibleWhenDisabled: true,
191
- children: __('Reset')
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
- * Reset action for Template and TemplatePart.
200
- */
201
- export default resetPostAction;
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