@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,205 +1,249 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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 create_template_part_modal_exports = {};
20
+ __export(create_template_part_modal_exports, {
21
+ CreateTemplatePartModalContents: () => CreateTemplatePartModalContents,
22
+ default: () => CreateTemplatePartModal
5
23
  });
6
- exports.CreateTemplatePartModalContents = CreateTemplatePartModalContents;
7
- exports.default = CreateTemplatePartModal;
8
- var _components = require("@wordpress/components");
9
- var _compose = require("@wordpress/compose");
10
- var _coreData = require("@wordpress/core-data");
11
- var _data = require("@wordpress/data");
12
- var _element = require("@wordpress/element");
13
- var _i18n = require("@wordpress/i18n");
14
- var _icons = require("@wordpress/icons");
15
- var _notices = require("@wordpress/notices");
16
- var _blocks = require("@wordpress/blocks");
17
- var _utils = require("./utils");
18
- var _jsxRuntime = require("react/jsx-runtime");
19
- /**
20
- * WordPress dependencies
21
- */
22
-
23
- // @ts-expect-error serialize is not typed
24
-
25
- /**
26
- * Internal dependencies
27
- */
28
-
24
+ module.exports = __toCommonJS(create_template_part_modal_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var import_components = require("@wordpress/components");
27
+ var import_compose = require("@wordpress/compose");
28
+ var import_core_data = require("@wordpress/core-data");
29
+ var import_data = require("@wordpress/data");
30
+ var import_element = require("@wordpress/element");
31
+ var import_i18n = require("@wordpress/i18n");
32
+ var import_icons = require("@wordpress/icons");
33
+ var import_notices = require("@wordpress/notices");
34
+ var import_blocks = require("@wordpress/blocks");
35
+ var import_utils = require("./utils");
29
36
  function getAreaRadioId(value, instanceId) {
30
37
  return `fields-create-template-part-modal__area-option-${value}-${instanceId}`;
31
38
  }
32
39
  function getAreaRadioDescriptionId(value, instanceId) {
33
40
  return `fields-create-template-part-modal__area-option-description-${value}-${instanceId}`;
34
41
  }
35
- /**
36
- * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.
37
- * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
38
- * @param {Object} props The component props.
39
- * @param props.modalTitle
40
- */
41
42
  function CreateTemplatePartModal({
42
43
  modalTitle,
43
44
  ...restProps
44
45
  }) {
45
- const defaultModalTitle = (0, _data.useSelect)(select => select(_coreData.store).getPostType('wp_template_part')?.labels?.add_new_item, []);
46
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
47
- title: modalTitle || defaultModalTitle,
48
- onRequestClose: restProps.closeModal,
49
- overlayClassName: "fields-create-template-part-modal",
50
- focusOnMount: "firstContentElement",
51
- size: "medium",
52
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CreateTemplatePartModalContents, {
53
- ...restProps
54
- })
55
- });
46
+ const defaultModalTitle = (0, import_data.useSelect)(
47
+ (select) => select(import_core_data.store).getPostType("wp_template_part")?.labels?.add_new_item,
48
+ []
49
+ );
50
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
51
+ import_components.Modal,
52
+ {
53
+ title: modalTitle || defaultModalTitle,
54
+ onRequestClose: restProps.closeModal,
55
+ overlayClassName: "fields-create-template-part-modal",
56
+ focusOnMount: "firstContentElement",
57
+ size: "medium",
58
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CreateTemplatePartModalContents, { ...restProps })
59
+ }
60
+ );
56
61
  }
57
- const getTemplatePartIcon = iconName => {
58
- if ('header' === iconName) {
59
- return _icons.header;
60
- } else if ('footer' === iconName) {
61
- return _icons.footer;
62
- } else if ('sidebar' === iconName) {
63
- return _icons.sidebar;
62
+ const getTemplatePartIcon = (iconName) => {
63
+ if ("header" === iconName) {
64
+ return import_icons.header;
65
+ } else if ("footer" === iconName) {
66
+ return import_icons.footer;
67
+ } else if ("sidebar" === iconName) {
68
+ return import_icons.sidebar;
64
69
  }
65
- return _icons.symbolFilled;
70
+ return import_icons.symbolFilled;
66
71
  };
67
-
68
- /**
69
- * A React component that renders the content of a model for creating a template part.
70
- * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.
71
- *
72
- * @param {Object} props - The component props.
73
- * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.
74
- * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.
75
- * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.
76
- * @param {Function} props.closeModal - Function to close the modal.
77
- * @param {Function} props.onCreate - Function to call when the template part is successfully created.
78
- * @param {Function} [props.onError] - Function to call when there is an error creating the template part.
79
- * @param {string} [props.defaultTitle=''] - The default title for the template part.
80
- */
81
72
  function CreateTemplatePartModalContents({
82
- defaultArea = 'uncategorized',
73
+ defaultArea = "uncategorized",
83
74
  blocks = [],
84
- confirmLabel = (0, _i18n.__)('Add'),
75
+ confirmLabel = (0, import_i18n.__)("Add"),
85
76
  closeModal,
86
77
  onCreate,
87
78
  onError,
88
- defaultTitle = ''
79
+ defaultTitle = ""
89
80
  }) {
90
- const {
91
- createErrorNotice
92
- } = (0, _data.useDispatch)(_notices.store);
93
- const {
94
- saveEntityRecord
95
- } = (0, _data.useDispatch)(_coreData.store);
96
- const existingTemplateParts = (0, _utils.useExistingTemplateParts)();
97
- const [title, setTitle] = (0, _element.useState)(defaultTitle);
98
- const [area, setArea] = (0, _element.useState)(defaultArea);
99
- const [isSubmitting, setIsSubmitting] = (0, _element.useState)(false);
100
- const instanceId = (0, _compose.useInstanceId)(CreateTemplatePartModal);
101
- const defaultTemplatePartAreas = (0, _data.useSelect)(select => select(_coreData.store).getCurrentTheme()?.default_template_part_areas, []);
81
+ const { createErrorNotice } = (0, import_data.useDispatch)(import_notices.store);
82
+ const { saveEntityRecord } = (0, import_data.useDispatch)(import_core_data.store);
83
+ const existingTemplateParts = (0, import_utils.useExistingTemplateParts)();
84
+ const [title, setTitle] = (0, import_element.useState)(defaultTitle);
85
+ const [area, setArea] = (0, import_element.useState)(defaultArea);
86
+ const [isSubmitting, setIsSubmitting] = (0, import_element.useState)(false);
87
+ const instanceId = (0, import_compose.useInstanceId)(CreateTemplatePartModal);
88
+ const defaultTemplatePartAreas = (0, import_data.useSelect)(
89
+ (select) => select(import_core_data.store).getCurrentTheme()?.default_template_part_areas,
90
+ []
91
+ );
102
92
  async function createTemplatePart() {
103
93
  if (!title || isSubmitting) {
104
94
  return;
105
95
  }
106
96
  try {
107
97
  setIsSubmitting(true);
108
- const uniqueTitle = (0, _utils.getUniqueTemplatePartTitle)(title, existingTemplateParts);
109
- const cleanSlug = (0, _utils.getCleanTemplatePartSlug)(uniqueTitle);
110
- const templatePart = await saveEntityRecord('postType', 'wp_template_part', {
111
- slug: cleanSlug,
112
- title: uniqueTitle,
113
- content: (0, _blocks.serialize)(blocks),
114
- area
115
- }, {
116
- throwOnError: true
117
- });
98
+ const uniqueTitle = (0, import_utils.getUniqueTemplatePartTitle)(
99
+ title,
100
+ existingTemplateParts
101
+ );
102
+ const cleanSlug = (0, import_utils.getCleanTemplatePartSlug)(uniqueTitle);
103
+ const templatePart = await saveEntityRecord(
104
+ "postType",
105
+ "wp_template_part",
106
+ {
107
+ slug: cleanSlug,
108
+ title: uniqueTitle,
109
+ content: (0, import_blocks.serialize)(blocks),
110
+ area
111
+ },
112
+ { throwOnError: true }
113
+ );
118
114
  await onCreate(templatePart);
119
-
120
- // TODO: Add a success notice?
121
115
  } catch (error) {
122
- const errorMessage = error instanceof Error && 'code' in error && error.message && error.code !== 'unknown_error' ? error.message : (0, _i18n.__)('An error occurred while creating the template part.');
123
- createErrorNotice(errorMessage, {
124
- type: 'snackbar'
125
- });
116
+ const errorMessage = error instanceof Error && "code" in error && error.message && error.code !== "unknown_error" ? error.message : (0, import_i18n.__)(
117
+ "An error occurred while creating the template part."
118
+ );
119
+ createErrorNotice(errorMessage, { type: "snackbar" });
126
120
  onError?.();
127
121
  } finally {
128
122
  setIsSubmitting(false);
129
123
  }
130
124
  }
131
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
132
- onSubmit: async event => {
133
- event.preventDefault();
134
- await createTemplatePart();
135
- },
136
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
137
- spacing: "4",
138
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
139
- __next40pxDefaultSize: true,
140
- __nextHasNoMarginBottom: true,
141
- label: (0, _i18n.__)('Name'),
142
- value: title,
143
- onChange: setTitle,
144
- required: true
145
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("fieldset", {
146
- className: "fields-create-template-part-modal__area-fieldset",
147
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl.VisualLabel, {
148
- as: "legend",
149
- children: (0, _i18n.__)('Area')
150
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
151
- className: "fields-create-template-part-modal__area-radio-group",
152
- children: (defaultTemplatePartAreas !== null && defaultTemplatePartAreas !== void 0 ? defaultTemplatePartAreas : []).map(item => {
153
- const icon = getTemplatePartIcon(item.icon);
154
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
155
- className: "fields-create-template-part-modal__area-radio-wrapper",
156
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
157
- type: "radio",
158
- id: getAreaRadioId(item.area, instanceId),
159
- name: `fields-create-template-part-modal__area-${instanceId}`,
160
- value: item.area,
161
- checked: area === item.area,
162
- onChange: () => {
163
- setArea(item.area);
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
126
+ "form",
127
+ {
128
+ onSubmit: async (event) => {
129
+ event.preventDefault();
130
+ await createTemplatePart();
131
+ },
132
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: "4", children: [
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
134
+ import_components.TextControl,
135
+ {
136
+ __next40pxDefaultSize: true,
137
+ __nextHasNoMarginBottom: true,
138
+ label: (0, import_i18n.__)("Name"),
139
+ value: title,
140
+ onChange: setTitle,
141
+ required: true
142
+ }
143
+ ),
144
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { className: "fields-create-template-part-modal__area-fieldset", children: [
145
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.BaseControl.VisualLabel, { as: "legend", children: (0, import_i18n.__)("Area") }),
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "fields-create-template-part-modal__area-radio-group", children: (defaultTemplatePartAreas ?? []).map(
147
+ (item) => {
148
+ const icon = getTemplatePartIcon(item.icon);
149
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
150
+ "div",
151
+ {
152
+ className: "fields-create-template-part-modal__area-radio-wrapper",
153
+ children: [
154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
+ "input",
156
+ {
157
+ type: "radio",
158
+ id: getAreaRadioId(
159
+ item.area,
160
+ instanceId
161
+ ),
162
+ name: `fields-create-template-part-modal__area-${instanceId}`,
163
+ value: item.area,
164
+ checked: area === item.area,
165
+ onChange: () => {
166
+ setArea(item.area);
167
+ },
168
+ "aria-describedby": getAreaRadioDescriptionId(
169
+ item.area,
170
+ instanceId
171
+ )
172
+ }
173
+ ),
174
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
175
+ import_components.Icon,
176
+ {
177
+ icon,
178
+ className: "fields-create-template-part-modal__area-radio-icon"
179
+ }
180
+ ),
181
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
182
+ "label",
183
+ {
184
+ htmlFor: getAreaRadioId(
185
+ item.area,
186
+ instanceId
187
+ ),
188
+ className: "fields-create-template-part-modal__area-radio-label",
189
+ children: item.label
190
+ }
191
+ ),
192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
193
+ import_components.Icon,
194
+ {
195
+ icon: import_icons.check,
196
+ className: "fields-create-template-part-modal__area-radio-checkmark"
197
+ }
198
+ ),
199
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
200
+ "p",
201
+ {
202
+ className: "fields-create-template-part-modal__area-radio-description",
203
+ id: getAreaRadioDescriptionId(
204
+ item.area,
205
+ instanceId
206
+ ),
207
+ children: item.description
208
+ }
209
+ )
210
+ ]
164
211
  },
165
- "aria-describedby": getAreaRadioDescriptionId(item.area, instanceId)
166
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
167
- icon: icon,
168
- className: "fields-create-template-part-modal__area-radio-icon"
169
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
170
- htmlFor: getAreaRadioId(item.area, instanceId),
171
- className: "fields-create-template-part-modal__area-radio-label",
172
- children: item.label
173
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
174
- icon: _icons.check,
175
- className: "fields-create-template-part-modal__area-radio-checkmark"
176
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
177
- className: "fields-create-template-part-modal__area-radio-description",
178
- id: getAreaRadioDescriptionId(item.area, instanceId),
179
- children: item.description
180
- })]
181
- }, item.area);
182
- })
183
- })]
184
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
185
- justify: "right",
186
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
187
- __next40pxDefaultSize: true,
188
- variant: "tertiary",
189
- onClick: () => {
190
- closeModal();
191
- },
192
- children: (0, _i18n.__)('Cancel')
193
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
194
- __next40pxDefaultSize: true,
195
- variant: "primary",
196
- type: "submit",
197
- "aria-disabled": !title || isSubmitting,
198
- isBusy: isSubmitting,
199
- children: confirmLabel
200
- })]
201
- })]
202
- })
203
- });
212
+ item.area
213
+ );
214
+ }
215
+ ) })
216
+ ] }),
217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { justify: "right", children: [
218
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
219
+ import_components.Button,
220
+ {
221
+ __next40pxDefaultSize: true,
222
+ variant: "tertiary",
223
+ onClick: () => {
224
+ closeModal();
225
+ },
226
+ children: (0, import_i18n.__)("Cancel")
227
+ }
228
+ ),
229
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
230
+ import_components.Button,
231
+ {
232
+ __next40pxDefaultSize: true,
233
+ variant: "primary",
234
+ type: "submit",
235
+ "aria-disabled": !title || isSubmitting,
236
+ isBusy: isSubmitting,
237
+ children: confirmLabel
238
+ }
239
+ )
240
+ ] })
241
+ ] })
242
+ }
243
+ );
204
244
  }
205
- //# sourceMappingURL=index.js.map
245
+ // Annotate the CommonJS export names for ESM import in node:
246
+ 0 && (module.exports = {
247
+ CreateTemplatePartModalContents
248
+ });
249
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_components","require","_compose","_coreData","_data","_element","_i18n","_icons","_notices","_blocks","_utils","_jsxRuntime","getAreaRadioId","value","instanceId","getAreaRadioDescriptionId","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","useSelect","select","coreStore","getPostType","labels","add_new_item","jsx","Modal","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","headerIcon","footerIcon","sidebarIcon","symbolFilledIcon","defaultArea","blocks","confirmLabel","__","onCreate","onError","defaultTitle","createErrorNotice","useDispatch","noticesStore","saveEntityRecord","existingTemplateParts","useExistingTemplateParts","setTitle","useState","area","setArea","isSubmitting","setIsSubmitting","useInstanceId","defaultTemplatePartAreas","getCurrentTheme","default_template_part_areas","createTemplatePart","uniqueTitle","getUniqueTemplatePartTitle","cleanSlug","getCleanTemplatePartSlug","templatePart","slug","content","serialize","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","jsxs","__experimentalVStack","spacing","TextControl","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","required","className","BaseControl","VisualLabel","as","map","item","icon","id","name","checked","Icon","htmlFor","check","description","__experimentalHStack","justify","Button","variant","onClick","isBusy"],"sources":["@wordpress/fields/src/components/create-template-part-modal/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param {Object} props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nconst getTemplatePartIcon = ( iconName: string ) => {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getCurrentTheme()?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset className=\"fields-create-template-part-modal__area-fieldset\">\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map(\n\t\t\t\t\t\t\t( item: TemplatePartArea ) => {\n\t\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.description }\n\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AASA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,G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oreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/create-template-part-modal/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tIcon,\n\tBaseControl,\n\tTextControl,\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\nimport type { TemplatePartArea } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tcheck,\n\tfooter as footerIcon,\n\theader as headerIcon,\n\tsidebar as sidebarIcon,\n\tsymbolFilled as symbolFilledIcon,\n} from '@wordpress/icons';\nimport { store as noticesStore } from '@wordpress/notices';\n// @ts-expect-error serialize is not typed\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\n\nfunction getAreaRadioId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;\n}\nfunction getAreaRadioDescriptionId( value: string, instanceId: number ) {\n\treturn `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;\n}\n\ntype CreateTemplatePartModalContentsProps = {\n\tdefaultArea?: string;\n\tblocks: any[];\n\tconfirmLabel?: string;\n\tcloseModal: () => void;\n\tonCreate: ( templatePart: any ) => void;\n\tonError?: () => void;\n\tdefaultTitle?: string;\n};\n\n/**\n * A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part.\n * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.\n * @param {Object} props The component props.\n * @param props.modalTitle\n */\nexport default function CreateTemplatePartModal( {\n\tmodalTitle,\n\t...restProps\n}: {\n\tmodalTitle: string;\n} & CreateTemplatePartModalContentsProps ) {\n\tconst defaultModalTitle = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getPostType( 'wp_template_part' )?.labels\n\t\t\t\t?.add_new_item,\n\t\t[]\n\t);\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle || defaultModalTitle }\n\t\t\tonRequestClose={ restProps.closeModal }\n\t\t\toverlayClassName=\"fields-create-template-part-modal\"\n\t\t\tfocusOnMount=\"firstContentElement\"\n\t\t\tsize=\"medium\"\n\t\t>\n\t\t\t<CreateTemplatePartModalContents { ...restProps } />\n\t\t</Modal>\n\t);\n}\n\nconst getTemplatePartIcon = ( iconName: string ) => {\n\tif ( 'header' === iconName ) {\n\t\treturn headerIcon;\n\t} else if ( 'footer' === iconName ) {\n\t\treturn footerIcon;\n\t} else if ( 'sidebar' === iconName ) {\n\t\treturn sidebarIcon;\n\t}\n\treturn symbolFilledIcon;\n};\n\n/**\n * A React component that renders the content of a model for creating a template part.\n * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.\n *\n * @param {Object} props - The component props.\n * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.\n * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.\n * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.\n * @param {Function} props.closeModal - Function to close the modal.\n * @param {Function} props.onCreate - Function to call when the template part is successfully created.\n * @param {Function} [props.onError] - Function to call when there is an error creating the template part.\n * @param {string} [props.defaultTitle=''] - The default title for the template part.\n */\nexport function CreateTemplatePartModalContents( {\n\tdefaultArea = 'uncategorized',\n\tblocks = [],\n\tconfirmLabel = __( 'Add' ),\n\tcloseModal,\n\tonCreate,\n\tonError,\n\tdefaultTitle = '',\n}: CreateTemplatePartModalContentsProps ) {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst existingTemplateParts = useExistingTemplateParts();\n\n\tconst [ title, setTitle ] = useState( defaultTitle );\n\tconst [ area, setArea ] = useState( defaultArea );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst instanceId = useInstanceId( CreateTemplatePartModal );\n\n\tconst defaultTemplatePartAreas = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getCurrentTheme()?.default_template_part_areas,\n\t\t[]\n\t);\n\n\tasync function createTemplatePart() {\n\t\tif ( ! title || isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tsetIsSubmitting( true );\n\t\t\tconst uniqueTitle = getUniqueTemplatePartTitle(\n\t\t\t\ttitle,\n\t\t\t\texistingTemplateParts\n\t\t\t);\n\t\t\tconst cleanSlug = getCleanTemplatePartSlug( uniqueTitle );\n\n\t\t\tconst templatePart = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template_part',\n\t\t\t\t{\n\t\t\t\t\tslug: cleanSlug,\n\t\t\t\t\ttitle: uniqueTitle,\n\t\t\t\t\tcontent: serialize( blocks ),\n\t\t\t\t\tarea,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tawait onCreate( templatePart );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror instanceof Error &&\n\t\t\t\t'code' in error &&\n\t\t\t\terror.message &&\n\t\t\t\terror.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'An error occurred while creating the template part.'\n\t\t\t\t\t );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\n\t\t\tonError?.();\n\t\t} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\treturn (\n\t\t<form\n\t\t\tonSubmit={ async ( event ) => {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tawait createTemplatePart();\n\t\t\t} }\n\t\t>\n\t\t\t<VStack spacing=\"4\">\n\t\t\t\t<TextControl\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Name' ) }\n\t\t\t\t\tvalue={ title }\n\t\t\t\t\tonChange={ setTitle }\n\t\t\t\t\trequired\n\t\t\t\t/>\n\t\t\t\t<fieldset className=\"fields-create-template-part-modal__area-fieldset\">\n\t\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t\t{ __( 'Area' ) }\n\t\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t\t<div className=\"fields-create-template-part-modal__area-radio-group\">\n\t\t\t\t\t\t{ ( defaultTemplatePartAreas ?? [] ).map(\n\t\t\t\t\t\t\t( item: TemplatePartArea ) => {\n\t\t\t\t\t\t\t\tconst icon = getTemplatePartIcon( item.icon );\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tkey={ item.area }\n\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-wrapper\"\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tname={ `fields-create-template-part-modal__area-${ instanceId }` }\n\t\t\t\t\t\t\t\t\t\t\tvalue={ item.area }\n\t\t\t\t\t\t\t\t\t\t\tchecked={ area === item.area }\n\t\t\t\t\t\t\t\t\t\t\tonChange={ () => {\n\t\t\t\t\t\t\t\t\t\t\t\tsetArea( item.area );\n\t\t\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\t\t\taria-describedby={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ icon }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-icon\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<label\n\t\t\t\t\t\t\t\t\t\t\thtmlFor={ getAreaRadioId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-label\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.label }\n\t\t\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\t\t\t\t\ticon={ check }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-checkmark\"\n\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t<p\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-description\"\n\t\t\t\t\t\t\t\t\t\t\tid={ getAreaRadioDescriptionId(\n\t\t\t\t\t\t\t\t\t\t\t\titem.area,\n\t\t\t\t\t\t\t\t\t\t\t\tinstanceId\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ item.description }\n\t\t\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t) }\n\t\t\t\t\t</div>\n\t\t\t\t</fieldset>\n\t\t\t\t<HStack justify=\"right\">\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tcloseModal();\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t\t</Button>\n\t\t\t\t\t<Button\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\ttype=\"submit\"\n\t\t\t\t\t\taria-disabled={ ! title || isSubmitting }\n\t\t\t\t\t\tisBusy={ isSubmitting }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ confirmLabel }\n\t\t\t\t\t</Button>\n\t\t\t\t</HStack>\n\t\t\t</VStack>\n\t\t</form>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiFG;AA9EH,wBAQO;AACP,qBAA8B;AAE9B,uBAAmC;AACnC,kBAAuC;AACvC,qBAAyB;AACzB,kBAAmB;AACnB,mBAMO;AACP,qBAAsC;AAEtC,oBAA0B;AAK1B,mBAIO;AAEP,SAAS,eAAgB,OAAe,YAAqB;AAC5D,SAAO,kDAAmD,KAAM,IAAK,UAAW;AACjF;AACA,SAAS,0BAA2B,OAAe,YAAqB;AACvE,SAAO,8DAA+D,KAAM,IAAK,UAAW;AAC7F;AAkBe,SAAR,wBAA0C;AAAA,EAChD;AAAA,EACA,GAAG;AACJ,GAE2C;AAC1C,QAAM,wBAAoB;AAAA,IACzB,CAAE,WACD,OAAQ,iBAAAA,KAAU,EAAE,YAAa,kBAAmB,GAAG,QACpD;AAAA,IACJ,CAAC;AAAA,EACF;AACA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAQ,cAAc;AAAA,MACtB,gBAAiB,UAAU;AAAA,MAC3B,kBAAiB;AAAA,MACjB,cAAa;AAAA,MACb,MAAK;AAAA,MAEL,sDAAC,mCAAkC,GAAG,WAAY;AAAA;AAAA,EAC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;AAAA,wBACA,WAAU;AAAA;AAAA,oBACX;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,SAAU;AAAA,0BACT,KAAK;AAAA,0BACL;AAAA,wBACD;AAAA,wBACA,WAAU;AAAA,wBAER,eAAK;AAAA;AAAA,oBACR;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,MAAO;AAAA,wBACP,WAAU;AAAA;AAAA,oBACX;AAAA,oBACA;AAAA,sBAAC;AAAA;AAAA,wBACA,WAAU;AAAA,wBACV,IAAK;AAAA,0BACJ,KAAK;AAAA,0BACL;AAAA,wBACD;AAAA,wBAEE,eAAK;AAAA;AAAA,oBACR;AAAA;AAAA;AAAA,gBA7CM,KAAK;AAAA,cA8CZ;AAAA,YAEF;AAAA,UACD,GACD;AAAA,WACD;AAAA,QACA,6CAAC,kBAAAC,sBAAA,EAAO,SAAQ,SACf;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,SAAU,MAAM;AACf,2BAAW;AAAA,cACZ;AAAA,cAEE,8BAAI,QAAS;AAAA;AAAA,UAChB;AAAA,UACA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,iBAAgB,CAAE,SAAS;AAAA,cAC3B,QAAS;AAAA,cAEP;AAAA;AAAA,UACH;AAAA,WACD;AAAA,SACD;AAAA;AAAA,EACD;AAEF;",
6
+ "names": ["coreStore", "headerIcon", "footerIcon", "sidebarIcon", "symbolFilledIcon", "noticesStore", "VStack", "HStack"]
7
+ }
@@ -1,43 +1,48 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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 utils_exports = {};
20
+ __export(utils_exports, {
21
+ getCleanTemplatePartSlug: () => getCleanTemplatePartSlug,
22
+ getUniqueTemplatePartTitle: () => getUniqueTemplatePartTitle,
23
+ useExistingTemplateParts: () => useExistingTemplateParts
5
24
  });
6
- exports.useExistingTemplateParts = exports.getUniqueTemplatePartTitle = exports.getCleanTemplatePartSlug = void 0;
7
- var _changeCase = require("change-case");
8
- var _data = require("@wordpress/data");
9
- var _coreData = require("@wordpress/core-data");
10
- /**
11
- * External dependencies
12
- */
13
-
14
- /**
15
- * WordPress dependencies
16
- */
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
-
25
+ module.exports = __toCommonJS(utils_exports);
26
+ var import_change_case = require("change-case");
27
+ var import_data = require("@wordpress/data");
28
+ var import_core_data = require("@wordpress/core-data");
22
29
  const useExistingTemplateParts = () => {
23
- var _useSelect;
24
- return (_useSelect = (0, _data.useSelect)(select => select(_coreData.store).getEntityRecords('postType', 'wp_template_part', {
25
- per_page: -1
26
- }), [])) !== null && _useSelect !== void 0 ? _useSelect : [];
30
+ return (0, import_data.useSelect)(
31
+ (select) => select(import_core_data.store).getEntityRecords(
32
+ "postType",
33
+ "wp_template_part",
34
+ {
35
+ per_page: -1
36
+ }
37
+ ),
38
+ []
39
+ ) ?? [];
27
40
  };
28
-
29
- /**
30
- * Return a unique template part title based on
31
- * the given title and existing template parts.
32
- *
33
- * @param {string} title The original template part title.
34
- * @param {Object} templateParts The array of template part entities.
35
- * @return {string} A unique template part title.
36
- */
37
- exports.useExistingTemplateParts = useExistingTemplateParts;
38
41
  const getUniqueTemplatePartTitle = (title, templateParts) => {
39
42
  const lowercaseTitle = title.toLowerCase();
40
- const existingTitles = templateParts.map(templatePart => templatePart.title.rendered.toLowerCase());
43
+ const existingTitles = templateParts.map(
44
+ (templatePart) => templatePart.title.rendered.toLowerCase()
45
+ );
41
46
  if (!existingTitles.includes(lowercaseTitle)) {
42
47
  return title;
43
48
  }
@@ -47,18 +52,13 @@ const getUniqueTemplatePartTitle = (title, templateParts) => {
47
52
  }
48
53
  return `${title} ${suffix}`;
49
54
  };
50
-
51
- /**
52
- * Get a valid slug for a template part.
53
- * Currently template parts only allow latin chars.
54
- * The fallback slug will receive suffix by default.
55
- *
56
- * @param {string} title The template part title.
57
- * @return {string} A valid template part slug.
58
- */
59
- exports.getUniqueTemplatePartTitle = getUniqueTemplatePartTitle;
60
- const getCleanTemplatePartSlug = title => {
61
- return (0, _changeCase.paramCase)(title).replace(/[^\w-]+/g, '') || 'wp-custom-part';
55
+ const getCleanTemplatePartSlug = (title) => {
56
+ return (0, import_change_case.paramCase)(title).replace(/[^\w-]+/g, "") || "wp-custom-part";
62
57
  };
63
- exports.getCleanTemplatePartSlug = getCleanTemplatePartSlug;
64
- //# sourceMappingURL=utils.js.map
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getCleanTemplatePartSlug,
61
+ getUniqueTemplatePartTitle,
62
+ useExistingTemplateParts
63
+ });
64
+ //# sourceMappingURL=utils.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_changeCase","require","_data","_coreData","useExistingTemplateParts","_useSelect","useSelect","select","coreStore","getEntityRecords","per_page","exports","getUniqueTemplatePartTitle","title","templateParts","lowercaseTitle","toLowerCase","existingTitles","map","templatePart","rendered","includes","suffix","getCleanTemplatePartSlug","kebabCase","replace"],"sources":["@wordpress/fields/src/components/create-template-part-modal/utils.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\n\nexport const useExistingTemplateParts = () => {\n\treturn (\n\t\tuseSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t[]\n\t\t) ?? []\n\t);\n};\n\n/**\n * Return a unique template part title based on\n * the given title and existing template parts.\n *\n * @param {string} title The original template part title.\n * @param {Object} templateParts The array of template part entities.\n * @return {string} A unique template part title.\n */\nexport const getUniqueTemplatePartTitle = ( title, templateParts ) => {\n\tconst lowercaseTitle = title.toLowerCase();\n\tconst existingTitles = templateParts.map( ( templatePart ) =>\n\t\ttemplatePart.title.rendered.toLowerCase()\n\t);\n\n\tif ( ! existingTitles.includes( lowercaseTitle ) ) {\n\t\treturn title;\n\t}\n\n\tlet suffix = 2;\n\twhile ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {\n\t\tsuffix++;\n\t}\n\n\treturn `${ title } ${ suffix }`;\n};\n\n/**\n * Get a valid slug for a template part.\n * Currently template parts only allow latin chars.\n * The fallback slug will receive suffix by default.\n *\n * @param {string} title The template part title.\n * @return {string} A valid template part slug.\n */\nexport const getCleanTemplatePartSlug = ( title ) => {\n\treturn kebabCase( title ).replace( /[^\\w-]+/g, '' ) || 'wp-custom-part';\n};\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAEO,MAAMG,wBAAwB,GAAGA,CAAA,KAAM;EAAA,IAAAC,UAAA;EAC7C,QAAAA,UAAA,GACC,IAAAC,eAAS,EACNC,MAAM,IACPA,MAAM,CAAEC,eAAU,CAAC,CAACC,gBAAgB,CACnC,UAAU,EACV,kBAAkB,EAClB;IACCC,QAAQ,EAAE,CAAC;EACZ,CACD,CAAC,EACF,EACD,CAAC,cAAAL,UAAA,cAAAA,UAAA,GAAI,EAAE;AAET,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAM,OAAA,CAAAP,wBAAA,GAAAA,wBAAA;AAQO,MAAMQ,0BAA0B,GAAGA,CAAEC,KAAK,EAAEC,aAAa,KAAM;EACrE,MAAMC,cAAc,GAAGF,KAAK,CAACG,WAAW,CAAC,CAAC;EAC1C,MAAMC,cAAc,GAAGH,aAAa,CAACI,GAAG,CAAIC,YAAY,IACvDA,YAAY,CAACN,KAAK,CAACO,QAAQ,CAACJ,WAAW,CAAC,CACzC,CAAC;EAED,IAAK,CAAEC,cAAc,CAACI,QAAQ,CAAEN,cAAe,CAAC,EAAG;IAClD,OAAOF,KAAK;EACb;EAEA,IAAIS,MAAM,GAAG,CAAC;EACd,OAAQL,cAAc,CAACI,QAAQ,CAAE,GAAIN,cAAc,IAAMO,MAAM,EAAI,CAAC,EAAG;IACtEA,MAAM,EAAE;EACT;EAEA,OAAO,GAAIT,KAAK,IAAMS,MAAM,EAAG;AAChC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAX,OAAA,CAAAC,0BAAA,GAAAA,0BAAA;AAQO,MAAMW,wBAAwB,GAAKV,KAAK,IAAM;EACpD,OAAO,IAAAW,qBAAS,EAAEX,KAAM,CAAC,CAACY,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,IAAI,gBAAgB;AACxE,CAAC;AAACd,OAAA,CAAAY,wBAAA,GAAAA,wBAAA","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/create-template-part-modal/utils.js"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { paramCase as kebabCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\n\nexport const useExistingTemplateParts = () => {\n\treturn (\n\t\tuseSelect(\n\t\t\t( select ) =>\n\t\t\t\tselect( coreStore ).getEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template_part',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t}\n\t\t\t\t),\n\t\t\t[]\n\t\t) ?? []\n\t);\n};\n\n/**\n * Return a unique template part title based on\n * the given title and existing template parts.\n *\n * @param {string} title The original template part title.\n * @param {Object} templateParts The array of template part entities.\n * @return {string} A unique template part title.\n */\nexport const getUniqueTemplatePartTitle = ( title, templateParts ) => {\n\tconst lowercaseTitle = title.toLowerCase();\n\tconst existingTitles = templateParts.map( ( templatePart ) =>\n\t\ttemplatePart.title.rendered.toLowerCase()\n\t);\n\n\tif ( ! existingTitles.includes( lowercaseTitle ) ) {\n\t\treturn title;\n\t}\n\n\tlet suffix = 2;\n\twhile ( existingTitles.includes( `${ lowercaseTitle } ${ suffix }` ) ) {\n\t\tsuffix++;\n\t}\n\n\treturn `${ title } ${ suffix }`;\n};\n\n/**\n * Get a valid slug for a template part.\n * Currently template parts only allow latin chars.\n * The fallback slug will receive suffix by default.\n *\n * @param {string} title The template part title.\n * @return {string} A valid template part slug.\n */\nexport const getCleanTemplatePartSlug = ( title ) => {\n\treturn kebabCase( title ).replace( /[^\\w-]+/g, '' ) || 'wp-custom-part';\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAAuC;AAKvC,kBAA0B;AAC1B,uBAAmC;AAM5B,MAAM,2BAA2B,MAAM;AAC7C,aACC;AAAA,IACC,CAAE,WACD,OAAQ,iBAAAA,KAAU,EAAE;AAAA,MACnB;AAAA,MACA;AAAA,MACA;AAAA,QACC,UAAU;AAAA,MACX;AAAA,IACD;AAAA,IACD,CAAC;AAAA,EACF,KAAK,CAAC;AAER;AAUO,MAAM,6BAA6B,CAAE,OAAO,kBAAmB;AACrE,QAAM,iBAAiB,MAAM,YAAY;AACzC,QAAM,iBAAiB,cAAc;AAAA,IAAK,CAAE,iBAC3C,aAAa,MAAM,SAAS,YAAY;AAAA,EACzC;AAEA,MAAK,CAAE,eAAe,SAAU,cAAe,GAAI;AAClD,WAAO;AAAA,EACR;AAEA,MAAI,SAAS;AACb,SAAQ,eAAe,SAAU,GAAI,cAAe,IAAK,MAAO,EAAG,GAAI;AACtE;AAAA,EACD;AAEA,SAAO,GAAI,KAAM,IAAK,MAAO;AAC9B;AAUO,MAAM,2BAA2B,CAAE,UAAW;AACpD,aAAO,mBAAAC,WAAW,KAAM,EAAE,QAAS,YAAY,EAAG,KAAK;AACxD;",
6
+ "names": ["coreStore", "kebabCase"]
7
+ }