@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,196 +1,243 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Icon, BaseControl, TextControl, Button, Modal, __experimentalHStack as HStack, __experimentalVStack as VStack } from '@wordpress/components';
5
- import { useInstanceId } from '@wordpress/compose';
6
- import { store as coreStore } from '@wordpress/core-data';
7
- import { useDispatch, useSelect } from '@wordpress/data';
8
- import { useState } from '@wordpress/element';
9
- import { __ } from '@wordpress/i18n';
10
- import { check, footer as footerIcon, header as headerIcon, sidebar as sidebarIcon, symbolFilled as symbolFilledIcon } from '@wordpress/icons';
11
- import { store as noticesStore } from '@wordpress/notices';
12
- // @ts-expect-error serialize is not typed
13
- import { serialize } from '@wordpress/blocks';
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
- import { getCleanTemplatePartSlug, getUniqueTemplatePartTitle, useExistingTemplateParts } from './utils';
19
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import {
3
+ Icon,
4
+ BaseControl,
5
+ TextControl,
6
+ Button,
7
+ Modal,
8
+ __experimentalHStack as HStack,
9
+ __experimentalVStack as VStack
10
+ } from "@wordpress/components";
11
+ import { useInstanceId } from "@wordpress/compose";
12
+ import { store as coreStore } from "@wordpress/core-data";
13
+ import { useDispatch, useSelect } from "@wordpress/data";
14
+ import { useState } from "@wordpress/element";
15
+ import { __ } from "@wordpress/i18n";
16
+ import {
17
+ check,
18
+ footer as footerIcon,
19
+ header as headerIcon,
20
+ sidebar as sidebarIcon,
21
+ symbolFilled as symbolFilledIcon
22
+ } from "@wordpress/icons";
23
+ import { store as noticesStore } from "@wordpress/notices";
24
+ import { serialize } from "@wordpress/blocks";
25
+ import {
26
+ getCleanTemplatePartSlug,
27
+ getUniqueTemplatePartTitle,
28
+ useExistingTemplateParts
29
+ } from "./utils";
20
30
  function getAreaRadioId(value, instanceId) {
21
31
  return `fields-create-template-part-modal__area-option-${value}-${instanceId}`;
22
32
  }
23
33
  function getAreaRadioDescriptionId(value, instanceId) {
24
34
  return `fields-create-template-part-modal__area-option-description-${value}-${instanceId}`;
25
35
  }
26
- /**
27
- * 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.
28
- * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
29
- * @param {Object} props The component props.
30
- * @param props.modalTitle
31
- */
32
- export default function CreateTemplatePartModal({
36
+ function CreateTemplatePartModal({
33
37
  modalTitle,
34
38
  ...restProps
35
39
  }) {
36
- const defaultModalTitle = useSelect(select => select(coreStore).getPostType('wp_template_part')?.labels?.add_new_item, []);
37
- return /*#__PURE__*/_jsx(Modal, {
38
- title: modalTitle || defaultModalTitle,
39
- onRequestClose: restProps.closeModal,
40
- overlayClassName: "fields-create-template-part-modal",
41
- focusOnMount: "firstContentElement",
42
- size: "medium",
43
- children: /*#__PURE__*/_jsx(CreateTemplatePartModalContents, {
44
- ...restProps
45
- })
46
- });
40
+ const defaultModalTitle = useSelect(
41
+ (select) => select(coreStore).getPostType("wp_template_part")?.labels?.add_new_item,
42
+ []
43
+ );
44
+ return /* @__PURE__ */ jsx(
45
+ Modal,
46
+ {
47
+ title: modalTitle || defaultModalTitle,
48
+ onRequestClose: restProps.closeModal,
49
+ overlayClassName: "fields-create-template-part-modal",
50
+ focusOnMount: "firstContentElement",
51
+ size: "medium",
52
+ children: /* @__PURE__ */ jsx(CreateTemplatePartModalContents, { ...restProps })
53
+ }
54
+ );
47
55
  }
48
- const getTemplatePartIcon = iconName => {
49
- if ('header' === iconName) {
56
+ const getTemplatePartIcon = (iconName) => {
57
+ if ("header" === iconName) {
50
58
  return headerIcon;
51
- } else if ('footer' === iconName) {
59
+ } else if ("footer" === iconName) {
52
60
  return footerIcon;
53
- } else if ('sidebar' === iconName) {
61
+ } else if ("sidebar" === iconName) {
54
62
  return sidebarIcon;
55
63
  }
56
64
  return symbolFilledIcon;
57
65
  };
58
-
59
- /**
60
- * A React component that renders the content of a model for creating a template part.
61
- * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.
62
- *
63
- * @param {Object} props - The component props.
64
- * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.
65
- * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.
66
- * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.
67
- * @param {Function} props.closeModal - Function to close the modal.
68
- * @param {Function} props.onCreate - Function to call when the template part is successfully created.
69
- * @param {Function} [props.onError] - Function to call when there is an error creating the template part.
70
- * @param {string} [props.defaultTitle=''] - The default title for the template part.
71
- */
72
- export function CreateTemplatePartModalContents({
73
- defaultArea = 'uncategorized',
66
+ function CreateTemplatePartModalContents({
67
+ defaultArea = "uncategorized",
74
68
  blocks = [],
75
- confirmLabel = __('Add'),
69
+ confirmLabel = __("Add"),
76
70
  closeModal,
77
71
  onCreate,
78
72
  onError,
79
- defaultTitle = ''
73
+ defaultTitle = ""
80
74
  }) {
81
- const {
82
- createErrorNotice
83
- } = useDispatch(noticesStore);
84
- const {
85
- saveEntityRecord
86
- } = useDispatch(coreStore);
75
+ const { createErrorNotice } = useDispatch(noticesStore);
76
+ const { saveEntityRecord } = useDispatch(coreStore);
87
77
  const existingTemplateParts = useExistingTemplateParts();
88
78
  const [title, setTitle] = useState(defaultTitle);
89
79
  const [area, setArea] = useState(defaultArea);
90
80
  const [isSubmitting, setIsSubmitting] = useState(false);
91
81
  const instanceId = useInstanceId(CreateTemplatePartModal);
92
- const defaultTemplatePartAreas = useSelect(select => select(coreStore).getCurrentTheme()?.default_template_part_areas, []);
82
+ const defaultTemplatePartAreas = useSelect(
83
+ (select) => select(coreStore).getCurrentTheme()?.default_template_part_areas,
84
+ []
85
+ );
93
86
  async function createTemplatePart() {
94
87
  if (!title || isSubmitting) {
95
88
  return;
96
89
  }
97
90
  try {
98
91
  setIsSubmitting(true);
99
- const uniqueTitle = getUniqueTemplatePartTitle(title, existingTemplateParts);
92
+ const uniqueTitle = getUniqueTemplatePartTitle(
93
+ title,
94
+ existingTemplateParts
95
+ );
100
96
  const cleanSlug = getCleanTemplatePartSlug(uniqueTitle);
101
- const templatePart = await saveEntityRecord('postType', 'wp_template_part', {
102
- slug: cleanSlug,
103
- title: uniqueTitle,
104
- content: serialize(blocks),
105
- area
106
- }, {
107
- throwOnError: true
108
- });
97
+ const templatePart = await saveEntityRecord(
98
+ "postType",
99
+ "wp_template_part",
100
+ {
101
+ slug: cleanSlug,
102
+ title: uniqueTitle,
103
+ content: serialize(blocks),
104
+ area
105
+ },
106
+ { throwOnError: true }
107
+ );
109
108
  await onCreate(templatePart);
110
-
111
- // TODO: Add a success notice?
112
109
  } catch (error) {
113
- const errorMessage = error instanceof Error && 'code' in error && error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the template part.');
114
- createErrorNotice(errorMessage, {
115
- type: 'snackbar'
116
- });
110
+ const errorMessage = error instanceof Error && "code" in error && error.message && error.code !== "unknown_error" ? error.message : __(
111
+ "An error occurred while creating the template part."
112
+ );
113
+ createErrorNotice(errorMessage, { type: "snackbar" });
117
114
  onError?.();
118
115
  } finally {
119
116
  setIsSubmitting(false);
120
117
  }
121
118
  }
122
- return /*#__PURE__*/_jsx("form", {
123
- onSubmit: async event => {
124
- event.preventDefault();
125
- await createTemplatePart();
126
- },
127
- children: /*#__PURE__*/_jsxs(VStack, {
128
- spacing: "4",
129
- children: [/*#__PURE__*/_jsx(TextControl, {
130
- __next40pxDefaultSize: true,
131
- __nextHasNoMarginBottom: true,
132
- label: __('Name'),
133
- value: title,
134
- onChange: setTitle,
135
- required: true
136
- }), /*#__PURE__*/_jsxs("fieldset", {
137
- className: "fields-create-template-part-modal__area-fieldset",
138
- children: [/*#__PURE__*/_jsx(BaseControl.VisualLabel, {
139
- as: "legend",
140
- children: __('Area')
141
- }), /*#__PURE__*/_jsx("div", {
142
- className: "fields-create-template-part-modal__area-radio-group",
143
- children: (defaultTemplatePartAreas !== null && defaultTemplatePartAreas !== void 0 ? defaultTemplatePartAreas : []).map(item => {
144
- const icon = getTemplatePartIcon(item.icon);
145
- return /*#__PURE__*/_jsxs("div", {
146
- className: "fields-create-template-part-modal__area-radio-wrapper",
147
- children: [/*#__PURE__*/_jsx("input", {
148
- type: "radio",
149
- id: getAreaRadioId(item.area, instanceId),
150
- name: `fields-create-template-part-modal__area-${instanceId}`,
151
- value: item.area,
152
- checked: area === item.area,
153
- onChange: () => {
154
- setArea(item.area);
119
+ return /* @__PURE__ */ jsx(
120
+ "form",
121
+ {
122
+ onSubmit: async (event) => {
123
+ event.preventDefault();
124
+ await createTemplatePart();
125
+ },
126
+ children: /* @__PURE__ */ jsxs(VStack, { spacing: "4", children: [
127
+ /* @__PURE__ */ jsx(
128
+ TextControl,
129
+ {
130
+ __next40pxDefaultSize: true,
131
+ __nextHasNoMarginBottom: true,
132
+ label: __("Name"),
133
+ value: title,
134
+ onChange: setTitle,
135
+ required: true
136
+ }
137
+ ),
138
+ /* @__PURE__ */ jsxs("fieldset", { className: "fields-create-template-part-modal__area-fieldset", children: [
139
+ /* @__PURE__ */ jsx(BaseControl.VisualLabel, { as: "legend", children: __("Area") }),
140
+ /* @__PURE__ */ jsx("div", { className: "fields-create-template-part-modal__area-radio-group", children: (defaultTemplatePartAreas ?? []).map(
141
+ (item) => {
142
+ const icon = getTemplatePartIcon(item.icon);
143
+ return /* @__PURE__ */ jsxs(
144
+ "div",
145
+ {
146
+ className: "fields-create-template-part-modal__area-radio-wrapper",
147
+ children: [
148
+ /* @__PURE__ */ jsx(
149
+ "input",
150
+ {
151
+ type: "radio",
152
+ id: getAreaRadioId(
153
+ item.area,
154
+ instanceId
155
+ ),
156
+ name: `fields-create-template-part-modal__area-${instanceId}`,
157
+ value: item.area,
158
+ checked: area === item.area,
159
+ onChange: () => {
160
+ setArea(item.area);
161
+ },
162
+ "aria-describedby": getAreaRadioDescriptionId(
163
+ item.area,
164
+ instanceId
165
+ )
166
+ }
167
+ ),
168
+ /* @__PURE__ */ jsx(
169
+ Icon,
170
+ {
171
+ icon,
172
+ className: "fields-create-template-part-modal__area-radio-icon"
173
+ }
174
+ ),
175
+ /* @__PURE__ */ jsx(
176
+ "label",
177
+ {
178
+ htmlFor: getAreaRadioId(
179
+ item.area,
180
+ instanceId
181
+ ),
182
+ className: "fields-create-template-part-modal__area-radio-label",
183
+ children: item.label
184
+ }
185
+ ),
186
+ /* @__PURE__ */ jsx(
187
+ Icon,
188
+ {
189
+ icon: check,
190
+ className: "fields-create-template-part-modal__area-radio-checkmark"
191
+ }
192
+ ),
193
+ /* @__PURE__ */ jsx(
194
+ "p",
195
+ {
196
+ className: "fields-create-template-part-modal__area-radio-description",
197
+ id: getAreaRadioDescriptionId(
198
+ item.area,
199
+ instanceId
200
+ ),
201
+ children: item.description
202
+ }
203
+ )
204
+ ]
155
205
  },
156
- "aria-describedby": getAreaRadioDescriptionId(item.area, instanceId)
157
- }), /*#__PURE__*/_jsx(Icon, {
158
- icon: icon,
159
- className: "fields-create-template-part-modal__area-radio-icon"
160
- }), /*#__PURE__*/_jsx("label", {
161
- htmlFor: getAreaRadioId(item.area, instanceId),
162
- className: "fields-create-template-part-modal__area-radio-label",
163
- children: item.label
164
- }), /*#__PURE__*/_jsx(Icon, {
165
- icon: check,
166
- className: "fields-create-template-part-modal__area-radio-checkmark"
167
- }), /*#__PURE__*/_jsx("p", {
168
- className: "fields-create-template-part-modal__area-radio-description",
169
- id: getAreaRadioDescriptionId(item.area, instanceId),
170
- children: item.description
171
- })]
172
- }, item.area);
173
- })
174
- })]
175
- }), /*#__PURE__*/_jsxs(HStack, {
176
- justify: "right",
177
- children: [/*#__PURE__*/_jsx(Button, {
178
- __next40pxDefaultSize: true,
179
- variant: "tertiary",
180
- onClick: () => {
181
- closeModal();
182
- },
183
- children: __('Cancel')
184
- }), /*#__PURE__*/_jsx(Button, {
185
- __next40pxDefaultSize: true,
186
- variant: "primary",
187
- type: "submit",
188
- "aria-disabled": !title || isSubmitting,
189
- isBusy: isSubmitting,
190
- children: confirmLabel
191
- })]
192
- })]
193
- })
194
- });
206
+ item.area
207
+ );
208
+ }
209
+ ) })
210
+ ] }),
211
+ /* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
212
+ /* @__PURE__ */ jsx(
213
+ Button,
214
+ {
215
+ __next40pxDefaultSize: true,
216
+ variant: "tertiary",
217
+ onClick: () => {
218
+ closeModal();
219
+ },
220
+ children: __("Cancel")
221
+ }
222
+ ),
223
+ /* @__PURE__ */ jsx(
224
+ Button,
225
+ {
226
+ __next40pxDefaultSize: true,
227
+ variant: "primary",
228
+ type: "submit",
229
+ "aria-disabled": !title || isSubmitting,
230
+ isBusy: isSubmitting,
231
+ children: confirmLabel
232
+ }
233
+ )
234
+ ] })
235
+ ] })
236
+ }
237
+ );
195
238
  }
196
- //# sourceMappingURL=index.js.map
239
+ export {
240
+ CreateTemplatePartModalContents,
241
+ CreateTemplatePartModal as default
242
+ };
243
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Icon","BaseControl","TextControl","Button","Modal","__experimentalHStack","HStack","__experimentalVStack","VStack","useInstanceId","store","coreStore","useDispatch","useSelect","useState","__","check","footer","footerIcon","header","headerIcon","sidebar","sidebarIcon","symbolFilled","symbolFilledIcon","noticesStore","serialize","getCleanTemplatePartSlug","getUniqueTemplatePartTitle","useExistingTemplateParts","jsx","_jsx","jsxs","_jsxs","getAreaRadioId","value","instanceId","getAreaRadioDescriptionId","CreateTemplatePartModal","modalTitle","restProps","defaultModalTitle","select","getPostType","labels","add_new_item","title","onRequestClose","closeModal","overlayClassName","focusOnMount","size","children","CreateTemplatePartModalContents","getTemplatePartIcon","iconName","defaultArea","blocks","confirmLabel","onCreate","onError","defaultTitle","createErrorNotice","saveEntityRecord","existingTemplateParts","setTitle","area","setArea","isSubmitting","setIsSubmitting","defaultTemplatePartAreas","getCurrentTheme","default_template_part_areas","createTemplatePart","uniqueTitle","cleanSlug","templatePart","slug","content","throwOnError","error","errorMessage","Error","message","code","type","onSubmit","event","preventDefault","spacing","__next40pxDefaultSize","__nextHasNoMarginBottom","label","onChange","required","className","VisualLabel","as","map","item","icon","id","name","checked","htmlFor","description","justify","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":"AAAA;AACA;AACA;AACA,SACCA,IAAI,EACJC,WAAW,EACXC,WAAW,EACXC,MAAM,EACNC,KAAK,EACLC,oBAAoB,IAAIC,MAAM,EAC9BC,oBAAoB,IAAIC,MAAM,QACxB,uBAAuB;AAC9B,SAASC,aAAa,QAAQ,oBAAoB;AAElD,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AACzD,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SACCC,KAAK,EACLC,MAAM,IAAIC,UAAU,EACpBC,MAAM,IAAIC,UAAU,EACpBC,OAAO,IAAIC,WAAW,EACtBC,YAAY,IAAIC,gBAAgB,QAC1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I,CAACjC,IAAI,EACT9B,UACD,CAAG;gBAAAgB,QAAA,EAED+C,IAAI,CAACM;cAAW,CAChB,CAAC;YAAA,GA7CEN,IAAI,CAACjC,IA8CP,CAAC;UAER,CACD;QAAC,CACG,CAAC;MAAA,CACG,CAAC,eACXjC,KAAA,CAAC3B,MAAM;QAACoG,OAAO,EAAC,OAAO;QAAAtD,QAAA,gBACtBrB,IAAA,CAAC5B,MAAM;UACNuF,qBAAqB;UACrBiB,OAAO,EAAC,UAAU;UAClBC,OAAO,EAAGA,CAAA,KAAM;YACf5D,UAAU,CAAC,CAAC;UACb,CAAG;UAAAI,QAAA,EAEDrC,EAAE,CAAE,QAAS;QAAC,CACT,CAAC,eACTgB,IAAA,CAAC5B,MAAM;UACNuF,qBAAqB;UACrBiB,OAAO,EAAC,SAAS;UACjBtB,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAEvC,KAAK,IAAIsB,YAAc;UACzCyC,MAAM,EAAGzC,YAAc;UAAAhB,QAAA,EAErBM;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
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": "AAiFG,cA2HM,YA3HN;AA9EH;AAAA,EACC;AAAA,EACA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AAAA;AAAA,oBACR;AAAA;AAAA;AAAA,gBA7CM,KAAK;AAAA,cA8CZ;AAAA,YAEF;AAAA,UACD,GACD;AAAA,WACD;AAAA,QACA,qBAAC,UAAO,SAAQ,SACf;AAAA;AAAA,YAAC;AAAA;AAAA,cACA,uBAAqB;AAAA,cACrB,SAAQ;AAAA,cACR,SAAU,MAAM;AACf,2BAAW;AAAA,cACZ;AAAA,cAEE,aAAI,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": []
7
+ }
@@ -1,36 +1,23 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { paramCase as kebabCase } from 'change-case';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { useSelect } from '@wordpress/data';
10
- import { store as coreStore } from '@wordpress/core-data';
11
-
12
- /**
13
- * Internal dependencies
14
- */
15
-
16
- export const useExistingTemplateParts = () => {
17
- var _useSelect;
18
- return (_useSelect = useSelect(select => select(coreStore).getEntityRecords('postType', 'wp_template_part', {
19
- per_page: -1
20
- }), [])) !== null && _useSelect !== void 0 ? _useSelect : [];
1
+ import { paramCase as kebabCase } from "change-case";
2
+ import { useSelect } from "@wordpress/data";
3
+ import { store as coreStore } from "@wordpress/core-data";
4
+ const useExistingTemplateParts = () => {
5
+ return useSelect(
6
+ (select) => select(coreStore).getEntityRecords(
7
+ "postType",
8
+ "wp_template_part",
9
+ {
10
+ per_page: -1
11
+ }
12
+ ),
13
+ []
14
+ ) ?? [];
21
15
  };
22
-
23
- /**
24
- * Return a unique template part title based on
25
- * the given title and existing template parts.
26
- *
27
- * @param {string} title The original template part title.
28
- * @param {Object} templateParts The array of template part entities.
29
- * @return {string} A unique template part title.
30
- */
31
- export const getUniqueTemplatePartTitle = (title, templateParts) => {
16
+ const getUniqueTemplatePartTitle = (title, templateParts) => {
32
17
  const lowercaseTitle = title.toLowerCase();
33
- const existingTitles = templateParts.map(templatePart => templatePart.title.rendered.toLowerCase());
18
+ const existingTitles = templateParts.map(
19
+ (templatePart) => templatePart.title.rendered.toLowerCase()
20
+ );
34
21
  if (!existingTitles.includes(lowercaseTitle)) {
35
22
  return title;
36
23
  }
@@ -40,16 +27,12 @@ export const getUniqueTemplatePartTitle = (title, templateParts) => {
40
27
  }
41
28
  return `${title} ${suffix}`;
42
29
  };
43
-
44
- /**
45
- * Get a valid slug for a template part.
46
- * Currently template parts only allow latin chars.
47
- * The fallback slug will receive suffix by default.
48
- *
49
- * @param {string} title The template part title.
50
- * @return {string} A valid template part slug.
51
- */
52
- export const getCleanTemplatePartSlug = title => {
53
- return kebabCase(title).replace(/[^\w-]+/g, '') || 'wp-custom-part';
30
+ const getCleanTemplatePartSlug = (title) => {
31
+ return kebabCase(title).replace(/[^\w-]+/g, "") || "wp-custom-part";
54
32
  };
55
- //# sourceMappingURL=utils.js.map
33
+ export {
34
+ getCleanTemplatePartSlug,
35
+ getUniqueTemplatePartTitle,
36
+ useExistingTemplateParts
37
+ };
38
+ //# sourceMappingURL=utils.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["paramCase","kebabCase","useSelect","store","coreStore","useExistingTemplateParts","_useSelect","select","getEntityRecords","per_page","getUniqueTemplatePartTitle","title","templateParts","lowercaseTitle","toLowerCase","existingTitles","map","templatePart","rendered","includes","suffix","getCleanTemplatePartSlug","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":"AAAA;AACA;AACA;AACA,SAASA,SAAS,IAAIC,SAAS,QAAQ,aAAa;;AAEpD;AACA;AACA;AACA,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;;AAEzD;AACA;AACA;;AAEA,OAAO,MAAMC,wBAAwB,GAAGA,CAAA,KAAM;EAAA,IAAAC,UAAA;EAC7C,QAAAA,UAAA,GACCJ,SAAS,CACNK,MAAM,IACPA,MAAM,CAAEH,SAAU,CAAC,CAACI,gBAAgB,CACnC,UAAU,EACV,kBAAkB,EAClB;IACCC,QAAQ,EAAE,CAAC;EACZ,CACD,CAAC,EACF,EACD,CAAC,cAAAH,UAAA,cAAAA,UAAA,GAAI,EAAE;AAET,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMI,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;AACA,OAAO,MAAMC,wBAAwB,GAAKV,KAAK,IAAM;EACpD,OAAOV,SAAS,CAAEU,KAAM,CAAC,CAACW,OAAO,CAAE,UAAU,EAAE,EAAG,CAAC,IAAI,gBAAgB;AACxE,CAAC","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": "AAGA,SAAS,aAAa,iBAAiB;AAKvC,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AAM5B,MAAM,2BAA2B,MAAM;AAC7C,SACC;AAAA,IACC,CAAE,WACD,OAAQ,SAAU,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,SAAO,UAAW,KAAM,EAAE,QAAS,YAAY,EAAG,KAAK;AACxD;",
6
+ "names": []
7
+ }