@wordpress/fields 0.5.0 → 0.5.1-next.a9f418477.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 (299) hide show
  1. package/README.md +52 -27
  2. package/build/actions/delete-post.js +4 -0
  3. package/build/actions/delete-post.js.map +1 -1
  4. package/build/actions/duplicate-pattern.js +4 -0
  5. package/build/actions/duplicate-pattern.js.map +1 -1
  6. package/build/actions/duplicate-post.js +7 -3
  7. package/build/actions/duplicate-post.js.map +1 -1
  8. package/build/actions/duplicate-template-part.js +71 -0
  9. package/build/actions/duplicate-template-part.js.map +1 -0
  10. package/build/actions/export-pattern.js +4 -0
  11. package/build/actions/export-pattern.js.map +1 -1
  12. package/build/actions/index.js +3 -17
  13. package/build/actions/index.js.map +1 -1
  14. package/build/actions/permanently-delete-post.js +4 -1
  15. package/build/actions/permanently-delete-post.js.map +1 -1
  16. package/build/actions/rename-post.js +6 -2
  17. package/build/actions/rename-post.js.map +1 -1
  18. package/build/actions/reorder-page.js +4 -0
  19. package/build/actions/reorder-page.js.map +1 -1
  20. package/build/actions/reset-post.js +7 -3
  21. package/build/actions/reset-post.js.map +1 -1
  22. package/build/actions/restore-post.js +4 -1
  23. package/build/actions/restore-post.js.map +1 -1
  24. package/build/actions/trash-post.js +4 -1
  25. package/build/actions/trash-post.js.map +1 -1
  26. package/build/actions/utils.js +4 -12
  27. package/build/actions/utils.js.map +1 -1
  28. package/build/actions/view-post-revisions.js +4 -0
  29. package/build/actions/view-post-revisions.js.map +1 -1
  30. package/build/actions/view-post.js +4 -0
  31. package/build/actions/view-post.js.map +1 -1
  32. package/build/components/create-template-part-modal/index.js +213 -0
  33. package/build/components/create-template-part-modal/index.js.map +1 -0
  34. package/build/components/create-template-part-modal/utils.js +64 -0
  35. package/build/components/create-template-part-modal/utils.js.map +1 -0
  36. package/build/fields/featured-image/index.js +4 -0
  37. package/build/fields/featured-image/index.js.map +1 -1
  38. package/build/fields/index.js +28 -0
  39. package/build/fields/index.js.map +1 -1
  40. package/build/fields/order/index.js +4 -0
  41. package/build/fields/order/index.js.map +1 -1
  42. package/build/fields/page-title/index.js +36 -0
  43. package/build/fields/page-title/index.js.map +1 -0
  44. package/build/fields/page-title/view.js +45 -0
  45. package/build/fields/page-title/view.js.map +1 -0
  46. package/build/fields/parent/index.js +1 -1
  47. package/build/fields/parent/index.js.map +1 -1
  48. package/build/fields/password/index.js +1 -1
  49. package/build/fields/password/index.js.map +1 -1
  50. package/build/fields/pattern-title/index.js +36 -0
  51. package/build/fields/pattern-title/index.js.map +1 -0
  52. package/build/fields/pattern-title/view.js +45 -0
  53. package/build/fields/pattern-title/view.js.map +1 -0
  54. package/build/fields/slug/index.js +4 -0
  55. package/build/fields/slug/index.js.map +1 -1
  56. package/build/fields/slug/slug-view.js +1 -1
  57. package/build/fields/slug/slug-view.js.map +1 -1
  58. package/build/fields/slug/utils.js +3 -0
  59. package/build/fields/slug/utils.js.map +1 -1
  60. package/build/fields/template/index.js +29 -0
  61. package/build/fields/template/index.js.map +1 -0
  62. package/build/fields/template/template-edit.js +154 -0
  63. package/build/fields/template/template-edit.js.map +1 -0
  64. package/build/fields/template-title/index.js +36 -0
  65. package/build/fields/template-title/index.js.map +1 -0
  66. package/build/fields/title/index.js +10 -3
  67. package/build/fields/title/index.js.map +1 -1
  68. package/build/fields/title/view.js +48 -0
  69. package/build/fields/title/view.js.map +1 -0
  70. package/build/index.js +13 -0
  71. package/build/index.js.map +1 -1
  72. package/build/index.native.js +0 -26
  73. package/build/index.native.js.map +1 -1
  74. package/build/mutation/index.js +0 -1
  75. package/build/mutation/index.js.map +1 -1
  76. package/build/types.js.map +1 -1
  77. package/build-module/actions/delete-post.js +4 -0
  78. package/build-module/actions/delete-post.js.map +1 -1
  79. package/build-module/actions/duplicate-pattern.js +4 -0
  80. package/build-module/actions/duplicate-pattern.js.map +1 -1
  81. package/build-module/actions/duplicate-post.js +7 -3
  82. package/build-module/actions/duplicate-post.js.map +1 -1
  83. package/build-module/actions/duplicate-template-part.js +66 -0
  84. package/build-module/actions/duplicate-template-part.js.map +1 -0
  85. package/build-module/actions/export-pattern.js +4 -0
  86. package/build-module/actions/export-pattern.js.map +1 -1
  87. package/build-module/actions/index.js +1 -3
  88. package/build-module/actions/index.js.map +1 -1
  89. package/build-module/actions/permanently-delete-post.js +4 -1
  90. package/build-module/actions/permanently-delete-post.js.map +1 -1
  91. package/build-module/actions/rename-post.js +7 -3
  92. package/build-module/actions/rename-post.js.map +1 -1
  93. package/build-module/actions/reorder-page.js +4 -0
  94. package/build-module/actions/reorder-page.js.map +1 -1
  95. package/build-module/actions/reset-post.js +8 -4
  96. package/build-module/actions/reset-post.js.map +1 -1
  97. package/build-module/actions/restore-post.js +4 -1
  98. package/build-module/actions/restore-post.js.map +1 -1
  99. package/build-module/actions/trash-post.js +4 -1
  100. package/build-module/actions/trash-post.js.map +1 -1
  101. package/build-module/actions/utils.js +4 -11
  102. package/build-module/actions/utils.js.map +1 -1
  103. package/build-module/actions/view-post-revisions.js +4 -0
  104. package/build-module/actions/view-post-revisions.js.map +1 -1
  105. package/build-module/actions/view-post.js +4 -0
  106. package/build-module/actions/view-post.js.map +1 -1
  107. package/build-module/components/create-template-part-modal/index.js +204 -0
  108. package/build-module/components/create-template-part-modal/index.js.map +1 -0
  109. package/build-module/components/create-template-part-modal/utils.js +55 -0
  110. package/build-module/components/create-template-part-modal/utils.js.map +1 -0
  111. package/build-module/fields/featured-image/index.js +4 -0
  112. package/build-module/fields/featured-image/index.js.map +1 -1
  113. package/build-module/fields/index.js +4 -0
  114. package/build-module/fields/index.js.map +1 -1
  115. package/build-module/fields/order/index.js +4 -0
  116. package/build-module/fields/order/index.js.map +1 -1
  117. package/build-module/fields/page-title/index.js +30 -0
  118. package/build-module/fields/page-title/index.js.map +1 -0
  119. package/build-module/fields/page-title/view.js +39 -0
  120. package/build-module/fields/page-title/view.js.map +1 -0
  121. package/build-module/fields/parent/index.js +1 -1
  122. package/build-module/fields/parent/index.js.map +1 -1
  123. package/build-module/fields/password/index.js +1 -1
  124. package/build-module/fields/password/index.js.map +1 -1
  125. package/build-module/fields/pattern-title/index.js +30 -0
  126. package/build-module/fields/pattern-title/index.js.map +1 -0
  127. package/build-module/fields/pattern-title/view.js +36 -0
  128. package/build-module/fields/pattern-title/view.js.map +1 -0
  129. package/build-module/fields/slug/index.js +4 -0
  130. package/build-module/fields/slug/index.js.map +1 -1
  131. package/build-module/fields/slug/slug-view.js +1 -1
  132. package/build-module/fields/slug/slug-view.js.map +1 -1
  133. package/build-module/fields/slug/utils.js +3 -0
  134. package/build-module/fields/slug/utils.js.map +1 -1
  135. package/build-module/fields/template/index.js +22 -0
  136. package/build-module/fields/template/index.js.map +1 -0
  137. package/build-module/fields/template/template-edit.js +144 -0
  138. package/build-module/fields/template/template-edit.js.map +1 -0
  139. package/build-module/fields/template-title/index.js +30 -0
  140. package/build-module/fields/template-title/index.js.map +1 -0
  141. package/build-module/fields/title/index.js +9 -2
  142. package/build-module/fields/title/index.js.map +1 -1
  143. package/build-module/fields/title/view.js +39 -0
  144. package/build-module/fields/title/view.js.map +1 -0
  145. package/build-module/index.js +1 -0
  146. package/build-module/index.js.map +1 -1
  147. package/build-module/index.native.js +1 -2
  148. package/build-module/index.native.js.map +1 -1
  149. package/build-module/mutation/index.js +0 -1
  150. package/build-module/mutation/index.js.map +1 -1
  151. package/build-module/types.js.map +1 -1
  152. package/build-style/style-rtl.css +98 -0
  153. package/build-style/style.css +98 -0
  154. package/build-types/actions/delete-post.d.ts +3 -0
  155. package/build-types/actions/delete-post.d.ts.map +1 -1
  156. package/build-types/actions/duplicate-pattern.d.ts +3 -0
  157. package/build-types/actions/duplicate-pattern.d.ts.map +1 -1
  158. package/build-types/actions/duplicate-post.d.ts +3 -0
  159. package/build-types/actions/duplicate-post.d.ts.map +1 -1
  160. package/build-types/actions/duplicate-template-part.d.ts +14 -0
  161. package/build-types/actions/duplicate-template-part.d.ts.map +1 -0
  162. package/build-types/actions/export-pattern.d.ts +3 -0
  163. package/build-types/actions/export-pattern.d.ts.map +1 -1
  164. package/build-types/actions/index.d.ts +1 -3
  165. package/build-types/actions/index.d.ts.map +1 -1
  166. package/build-types/actions/permanently-delete-post.d.ts +3 -0
  167. package/build-types/actions/permanently-delete-post.d.ts.map +1 -1
  168. package/build-types/actions/rename-post.d.ts +3 -0
  169. package/build-types/actions/rename-post.d.ts.map +1 -1
  170. package/build-types/actions/reorder-page.d.ts +3 -0
  171. package/build-types/actions/reorder-page.d.ts.map +1 -1
  172. package/build-types/actions/reset-post.d.ts +3 -0
  173. package/build-types/actions/reset-post.d.ts.map +1 -1
  174. package/build-types/actions/restore-post.d.ts +3 -0
  175. package/build-types/actions/restore-post.d.ts.map +1 -1
  176. package/build-types/actions/trash-post.d.ts +3 -0
  177. package/build-types/actions/trash-post.d.ts.map +1 -1
  178. package/build-types/actions/utils.d.ts +7 -8
  179. package/build-types/actions/utils.d.ts.map +1 -1
  180. package/build-types/actions/view-post-revisions.d.ts +3 -0
  181. package/build-types/actions/view-post-revisions.d.ts.map +1 -1
  182. package/build-types/actions/view-post.d.ts +3 -0
  183. package/build-types/actions/view-post.d.ts.map +1 -1
  184. package/build-types/components/create-template-part-modal/index.d.ts +34 -0
  185. package/build-types/components/create-template-part-modal/index.d.ts.map +1 -0
  186. package/build-types/components/create-template-part-modal/utils.d.ts +4 -0
  187. package/build-types/components/create-template-part-modal/utils.d.ts.map +1 -0
  188. package/build-types/fields/featured-image/index.d.ts +3 -0
  189. package/build-types/fields/featured-image/index.d.ts.map +1 -1
  190. package/build-types/fields/index.d.ts +4 -0
  191. package/build-types/fields/index.d.ts.map +1 -1
  192. package/build-types/fields/order/index.d.ts +3 -0
  193. package/build-types/fields/order/index.d.ts.map +1 -1
  194. package/build-types/fields/page-title/index.d.ts +14 -0
  195. package/build-types/fields/page-title/index.d.ts.map +1 -0
  196. package/build-types/fields/page-title/view.d.ts +8 -0
  197. package/build-types/fields/page-title/view.d.ts.map +1 -0
  198. package/build-types/fields/parent/index.d.ts +1 -1
  199. package/build-types/fields/password/index.d.ts +1 -1
  200. package/build-types/fields/pattern-title/index.d.ts +14 -0
  201. package/build-types/fields/pattern-title/index.d.ts.map +1 -0
  202. package/build-types/fields/pattern-title/view.d.ts +9 -0
  203. package/build-types/fields/pattern-title/view.d.ts.map +1 -0
  204. package/build-types/fields/slug/index.d.ts +3 -0
  205. package/build-types/fields/slug/index.d.ts.map +1 -1
  206. package/build-types/fields/slug/utils.d.ts.map +1 -1
  207. package/build-types/fields/template/index.d.ts +11 -0
  208. package/build-types/fields/template/index.d.ts.map +1 -0
  209. package/build-types/fields/template/template-edit.d.ts +4 -0
  210. package/build-types/fields/template/template-edit.d.ts.map +1 -0
  211. package/build-types/fields/template-title/index.d.ts +14 -0
  212. package/build-types/fields/template-title/index.d.ts.map +1 -0
  213. package/build-types/fields/title/index.d.ts +7 -2
  214. package/build-types/fields/title/index.d.ts.map +1 -1
  215. package/build-types/fields/title/view.d.ts +14 -0
  216. package/build-types/fields/title/view.d.ts.map +1 -0
  217. package/build-types/index.d.ts +2 -1
  218. package/build-types/index.d.ts.map +1 -1
  219. package/build-types/index.native.d.ts +0 -2
  220. package/build-types/index.native.d.ts.map +1 -1
  221. package/build-types/lock-unlock.d.ts +1 -1
  222. package/build-types/lock-unlock.d.ts.map +1 -1
  223. package/build-types/types.d.ts +3 -0
  224. package/build-types/types.d.ts.map +1 -1
  225. package/package.json +24 -23
  226. package/src/actions/delete-post.tsx +3 -0
  227. package/src/actions/duplicate-pattern.tsx +3 -0
  228. package/src/actions/duplicate-post.tsx +6 -3
  229. package/src/actions/duplicate-template-part.tsx +74 -0
  230. package/src/actions/export-pattern.tsx +3 -0
  231. package/src/actions/index.ts +1 -3
  232. package/src/actions/permanently-delete-post.tsx +3 -0
  233. package/src/actions/rename-post.tsx +6 -6
  234. package/src/actions/reorder-page.tsx +3 -0
  235. package/src/actions/reset-post.tsx +7 -9
  236. package/src/actions/restore-post.tsx +3 -0
  237. package/src/actions/trash-post.tsx +3 -0
  238. package/src/actions/utils.ts +7 -15
  239. package/src/actions/view-post-revisions.tsx +3 -0
  240. package/src/actions/view-post.tsx +3 -0
  241. package/src/components/create-template-part-modal/index.tsx +274 -0
  242. package/src/components/create-template-part-modal/style.scss +63 -0
  243. package/src/components/create-template-part-modal/test/utils.js +60 -0
  244. package/src/components/create-template-part-modal/utils.js +68 -0
  245. package/src/fields/featured-image/index.ts +3 -0
  246. package/src/fields/index.ts +4 -0
  247. package/src/fields/order/index.ts +3 -0
  248. package/src/fields/page-title/index.ts +28 -0
  249. package/src/fields/page-title/style.scss +10 -0
  250. package/src/fields/page-title/view.tsx +38 -0
  251. package/src/fields/parent/index.ts +1 -1
  252. package/src/fields/password/index.tsx +1 -1
  253. package/src/fields/pattern-title/index.ts +28 -0
  254. package/src/fields/pattern-title/style.scss +3 -0
  255. package/src/fields/pattern-title/view.tsx +32 -0
  256. package/src/fields/slug/index.ts +3 -0
  257. package/src/fields/slug/slug-view.tsx +1 -1
  258. package/src/fields/slug/utils.ts +4 -0
  259. package/src/fields/template/index.ts +24 -0
  260. package/src/fields/template/style.scss +23 -0
  261. package/src/fields/template/template-edit.tsx +210 -0
  262. package/src/fields/template-title/index.ts +28 -0
  263. package/src/fields/title/index.ts +9 -3
  264. package/src/fields/title/style.scss +8 -0
  265. package/src/fields/title/view.tsx +43 -0
  266. package/src/index.native.ts +0 -2
  267. package/src/index.ts +2 -1
  268. package/src/style.scss +5 -0
  269. package/src/types.ts +3 -0
  270. package/tsconfig.json +2 -0
  271. package/tsconfig.tsbuildinfo +1 -1
  272. package/build/actions/duplicate-post.native.js +0 -9
  273. package/build/actions/duplicate-post.native.js.map +0 -1
  274. package/build/actions/export-pattern.native.js +0 -9
  275. package/build/actions/export-pattern.native.js.map +0 -1
  276. package/build/actions/reorder-page.native.js +0 -9
  277. package/build/actions/reorder-page.native.js.map +0 -1
  278. package/build/fields/title/title-view.js +0 -61
  279. package/build/fields/title/title-view.js.map +0 -1
  280. package/build-module/actions/duplicate-post.native.js +0 -3
  281. package/build-module/actions/duplicate-post.native.js.map +0 -1
  282. package/build-module/actions/export-pattern.native.js +0 -3
  283. package/build-module/actions/export-pattern.native.js.map +0 -1
  284. package/build-module/actions/reorder-page.native.js +0 -3
  285. package/build-module/actions/reorder-page.native.js.map +0 -1
  286. package/build-module/fields/title/title-view.js +0 -55
  287. package/build-module/fields/title/title-view.js.map +0 -1
  288. package/build-types/actions/duplicate-post.native.d.ts +0 -3
  289. package/build-types/actions/duplicate-post.native.d.ts.map +0 -1
  290. package/build-types/actions/export-pattern.native.d.ts +0 -3
  291. package/build-types/actions/export-pattern.native.d.ts.map +0 -1
  292. package/build-types/actions/reorder-page.native.d.ts +0 -3
  293. package/build-types/actions/reorder-page.native.d.ts.map +0 -1
  294. package/build-types/fields/title/title-view.d.ts +0 -9
  295. package/build-types/fields/title/title-view.d.ts.map +0 -1
  296. package/src/actions/duplicate-post.native.tsx +0 -3
  297. package/src/actions/export-pattern.native.tsx +0 -3
  298. package/src/actions/reorder-page.native.tsx +0 -3
  299. package/src/fields/title/title-view.tsx +0 -62
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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-ignore
24
+
25
+ /**
26
+ * Internal dependencies
27
+ */
28
+
29
+ /**
30
+ * 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.
31
+ * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
32
+ * @param {Object} props The component props.
33
+ * @param props.modalTitle
34
+ */
35
+ function CreateTemplatePartModal({
36
+ modalTitle,
37
+ ...restProps
38
+ }) {
39
+ const defaultModalTitle = (0, _data.useSelect)(select =>
40
+ // @ts-ignore
41
+ select(_coreData.store).getPostType('wp_template_part')?.labels?.add_new_item, []);
42
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
43
+ title: modalTitle || defaultModalTitle,
44
+ onRequestClose: restProps.closeModal,
45
+ overlayClassName: "fields-create-template-part-modal",
46
+ focusOnMount: "firstContentElement",
47
+ size: "medium",
48
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(CreateTemplatePartModalContents, {
49
+ ...restProps
50
+ })
51
+ });
52
+ }
53
+ const getTemplatePartIcon = iconName => {
54
+ if ('header' === iconName) {
55
+ return _icons.header;
56
+ } else if ('footer' === iconName) {
57
+ return _icons.footer;
58
+ } else if ('sidebar' === iconName) {
59
+ return _icons.sidebar;
60
+ }
61
+ return _icons.symbolFilled;
62
+ };
63
+
64
+ /**
65
+ * A React component that renders the content of a model for creating a template part.
66
+ * This component should not live in this package; it should be moved to a dedicated package responsible for managing template.
67
+ *
68
+ * @param {Object} props - The component props.
69
+ * @param {string} [props.defaultArea=uncategorized] - The default area for the template part.
70
+ * @param {Array} [props.blocks=[]] - The blocks to be included in the template part.
71
+ * @param {string} [props.confirmLabel='Add'] - The label for the confirm button.
72
+ * @param {Function} props.closeModal - Function to close the modal.
73
+ * @param {Function} props.onCreate - Function to call when the template part is successfully created.
74
+ * @param {Function} [props.onError] - Function to call when there is an error creating the template part.
75
+ * @param {string} [props.defaultTitle=''] - The default title for the template part.
76
+ */
77
+ function CreateTemplatePartModalContents({
78
+ defaultArea = 'uncategorized',
79
+ blocks = [],
80
+ confirmLabel = (0, _i18n.__)('Add'),
81
+ closeModal,
82
+ onCreate,
83
+ onError,
84
+ defaultTitle = ''
85
+ }) {
86
+ const {
87
+ createErrorNotice
88
+ } = (0, _data.useDispatch)(_notices.store);
89
+ const {
90
+ saveEntityRecord
91
+ } = (0, _data.useDispatch)(_coreData.store);
92
+ const existingTemplateParts = (0, _utils.useExistingTemplateParts)();
93
+ const [title, setTitle] = (0, _element.useState)(defaultTitle);
94
+ const [area, setArea] = (0, _element.useState)(defaultArea);
95
+ const [isSubmitting, setIsSubmitting] = (0, _element.useState)(false);
96
+ const instanceId = (0, _compose.useInstanceId)(CreateTemplatePartModal);
97
+ const defaultTemplatePartAreas = (0, _data.useSelect)(select => {
98
+ const areas =
99
+ // @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
100
+ select(_coreData.store).getEntityRecord('root', '__unstableBase')?.default_template_part_areas || [];
101
+ return areas.map(item => {
102
+ return {
103
+ ...item,
104
+ icon: getTemplatePartIcon(item.icon)
105
+ };
106
+ });
107
+ }, []);
108
+ async function createTemplatePart() {
109
+ if (!title || isSubmitting) {
110
+ return;
111
+ }
112
+ try {
113
+ setIsSubmitting(true);
114
+ const uniqueTitle = (0, _utils.getUniqueTemplatePartTitle)(title, existingTemplateParts);
115
+ const cleanSlug = (0, _utils.getCleanTemplatePartSlug)(uniqueTitle);
116
+ const templatePart = await saveEntityRecord('postType', 'wp_template_part', {
117
+ slug: cleanSlug,
118
+ title: uniqueTitle,
119
+ content: (0, _blocks.serialize)(blocks),
120
+ area
121
+ }, {
122
+ throwOnError: true
123
+ });
124
+ await onCreate(templatePart);
125
+
126
+ // TODO: Add a success notice?
127
+ } catch (error) {
128
+ 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.');
129
+ createErrorNotice(errorMessage, {
130
+ type: 'snackbar'
131
+ });
132
+ onError?.();
133
+ } finally {
134
+ setIsSubmitting(false);
135
+ }
136
+ }
137
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
138
+ onSubmit: async event => {
139
+ event.preventDefault();
140
+ await createTemplatePart();
141
+ },
142
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
143
+ spacing: "4",
144
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
145
+ __next40pxDefaultSize: true,
146
+ __nextHasNoMarginBottom: true,
147
+ label: (0, _i18n.__)('Name'),
148
+ value: title,
149
+ onChange: setTitle,
150
+ required: true
151
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.BaseControl, {
152
+ __nextHasNoMarginBottom: true,
153
+ label: (0, _i18n.__)('Area'),
154
+ id: `fields-create-template-part-modal__area-selection-${instanceId}`,
155
+ className: "fields-create-template-part-modal__area-base-control",
156
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalRadioGroup, {
157
+ label: (0, _i18n.__)('Area'),
158
+ className: "fields-create-template-part-modal__area-radio-group",
159
+ id: `fields-create-template-part-modal__area-selection-${instanceId}`,
160
+ onChange: value => value && typeof value === 'string' ? setArea(value) : () => void 0,
161
+ checked: area,
162
+ children: defaultTemplatePartAreas.map(({
163
+ icon,
164
+ label,
165
+ area: value,
166
+ description
167
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalRadio, {
168
+ __next40pxDefaultSize: true,
169
+ value: value,
170
+ className: "fields-create-template-part-modal__area-radio",
171
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Flex, {
172
+ align: "start",
173
+ justify: "start",
174
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
175
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
176
+ icon: icon
177
+ })
178
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.FlexBlock, {
179
+ className: "fields-create-template-part-modal__option-label",
180
+ children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
181
+ children: description
182
+ })]
183
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.FlexItem, {
184
+ className: "fields-create-template-part-modal__checkbox",
185
+ children: area === value && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
186
+ icon: _icons.check
187
+ })
188
+ })]
189
+ })
190
+ }, label))
191
+ })
192
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
193
+ justify: "right",
194
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
195
+ __next40pxDefaultSize: true,
196
+ variant: "tertiary",
197
+ onClick: () => {
198
+ closeModal();
199
+ },
200
+ children: (0, _i18n.__)('Cancel')
201
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
202
+ __next40pxDefaultSize: true,
203
+ variant: "primary",
204
+ type: "submit",
205
+ "aria-disabled": !title || isSubmitting,
206
+ isBusy: isSubmitting,
207
+ children: confirmLabel
208
+ })]
209
+ })]
210
+ })
211
+ });
212
+ }
213
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_components","require","_compose","_coreData","_data","_element","_i18n","_icons","_notices","_blocks","_utils","_jsxRuntime","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","instanceId","useInstanceId","defaultTemplatePartAreas","areas","getEntityRecord","default_template_part_areas","map","item","icon","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","value","onChange","required","BaseControl","id","className","__experimentalRadioGroup","checked","description","__experimentalRadio","Flex","align","justify","FlexItem","Icon","FlexBlock","check","__experimentalHStack","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\tFlex,\n\tFlexItem,\n\tFlexBlock,\n\tButton,\n\tModal,\n\t__experimentalRadioGroup as RadioGroup,\n\t__experimentalRadio as Radio,\n\t__experimentalHStack as HStack,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useInstanceId } from '@wordpress/compose';\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-ignore\nimport { serialize } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport {\n\tgetCleanTemplatePartSlug,\n\tgetUniqueTemplatePartTitle,\n\tuseExistingTemplateParts,\n} from './utils';\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\t// @ts-ignore\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{ /* @ts-ignore */ }\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( ( select ) => {\n\t\tconst areas =\n\t\t\t// @ts-expect-error getEntityRecord is not typed with unstableBase as argument.\n\t\t\tselect( coreStore ).getEntityRecord< {\n\t\t\t\tdefault_template_part_areas: Array< {\n\t\t\t\t\tarea: string;\n\t\t\t\t\tlabel: string;\n\t\t\t\t\ticon: string;\n\t\t\t\t\tdescription: string;\n\t\t\t\t} >;\n\t\t\t} >( 'root', '__unstableBase' )?.default_template_part_areas || [];\n\n\t\treturn areas.map( ( item ) => {\n\t\t\treturn { ...item, icon: getTemplatePartIcon( item.icon ) };\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<BaseControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\tid={ `fields-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-base-control\"\n\t\t\t\t>\n\t\t\t\t\t<RadioGroup\n\t\t\t\t\t\tlabel={ __( 'Area' ) }\n\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio-group\"\n\t\t\t\t\t\tid={ `fields-create-template-part-modal__area-selection-${ instanceId }` }\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tvalue && typeof value === 'string'\n\t\t\t\t\t\t\t\t? setArea( value )\n\t\t\t\t\t\t\t\t: () => void 0\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchecked={ area }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ defaultTemplatePartAreas.map(\n\t\t\t\t\t\t\t( { icon, label, area: value, description } ) => (\n\t\t\t\t\t\t\t\t<Radio\n\t\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\t\tkey={ label }\n\t\t\t\t\t\t\t\t\tvalue={ value }\n\t\t\t\t\t\t\t\t\tclassName=\"fields-create-template-part-modal__area-radio\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Flex align=\"start\" justify=\"start\">\n\t\t\t\t\t\t\t\t\t\t<FlexItem>\n\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t\t<FlexBlock className=\"fields-create-template-part-modal__option-label\">\n\t\t\t\t\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t\t\t\t\t\t<div>{ description }</div>\n\t\t\t\t\t\t\t\t\t\t</FlexBlock>\n\n\t\t\t\t\t\t\t\t\t\t<FlexItem className=\"fields-create-template-part-modal__checkbox\">\n\t\t\t\t\t\t\t\t\t\t\t{ area === value && (\n\t\t\t\t\t\t\t\t\t\t\t\t<Icon icon={ check } />\n\t\t\t\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t\t\t\t</Flex>\n\t\t\t\t\t\t\t\t</Radio>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) }\n\t\t\t\t\t</RadioGroup>\n\t\t\t\t</BaseControl>\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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B,IAAI,EAAC,QAAQ;UACb,iBAAgB,CAAEzD,KAAK,IAAI+B,YAAc;UACzC0D,MAAM,EAAG1D,YAAc;UAAAzB,QAAA,EAErBU;QAAY,CACP,CAAC;MAAA,CACF,CAAC;IAAA,CACF;EAAC,CACJ,CAAC;AAET","ignoreList":[]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
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
+
22
+ 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 : [];
27
+ };
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
+ const getUniqueTemplatePartTitle = (title, templateParts) => {
39
+ const lowercaseTitle = title.toLowerCase();
40
+ const existingTitles = templateParts.map(templatePart => templatePart.title.rendered.toLowerCase());
41
+ if (!existingTitles.includes(lowercaseTitle)) {
42
+ return title;
43
+ }
44
+ let suffix = 2;
45
+ while (existingTitles.includes(`${lowercaseTitle} ${suffix}`)) {
46
+ suffix++;
47
+ }
48
+ return `${title} ${suffix}`;
49
+ };
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';
62
+ };
63
+ exports.getCleanTemplatePartSlug = getCleanTemplatePartSlug;
64
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
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":[]}
@@ -23,5 +23,9 @@ const featuredImageField = {
23
23
  render: _featuredImageView.FeaturedImageView,
24
24
  enableSorting: false
25
25
  };
26
+
27
+ /**
28
+ * Featured Image field for BasePost.
29
+ */
26
30
  var _default = exports.default = featuredImageField;
27
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","_featuredImageEdit","_featuredImageView","featuredImageField","id","type","label","__","Edit","FeaturedImageEdit","render","FeaturedImageView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/featured-image/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { FeaturedImageEdit } from './featured-image-edit';\nimport { FeaturedImageView } from './featured-image-view';\n\nconst featuredImageField: Field< BasePost > = {\n\tid: 'featured_media',\n\ttype: 'text',\n\tlabel: __( 'Featured Image' ),\n\tEdit: FeaturedImageEdit,\n\trender: FeaturedImageView,\n\tenableSorting: false,\n};\n\nexport default featuredImageField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMG,kBAAqC,GAAG;EAC7CC,EAAE,EAAE,gBAAgB;EACpBC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,IAAAC,QAAE,EAAE,gBAAiB,CAAC;EAC7BC,IAAI,EAAEC,oCAAiB;EACvBC,MAAM,EAAEC,oCAAiB;EACzBC,aAAa,EAAE;AAChB,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaZ,kBAAkB","ignoreList":[]}
1
+ {"version":3,"names":["_i18n","require","_featuredImageEdit","_featuredImageView","featuredImageField","id","type","label","__","Edit","FeaturedImageEdit","render","FeaturedImageView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/featured-image/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { FeaturedImageEdit } from './featured-image-edit';\nimport { FeaturedImageView } from './featured-image-view';\n\nconst featuredImageField: Field< BasePost > = {\n\tid: 'featured_media',\n\ttype: 'text',\n\tlabel: __( 'Featured Image' ),\n\tEdit: FeaturedImageEdit,\n\trender: FeaturedImageView,\n\tenableSorting: false,\n};\n\n/**\n * Featured Image field for BasePost.\n */\nexport default featuredImageField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMG,kBAAqC,GAAG;EAC7CC,EAAE,EAAE,gBAAgB;EACpBC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,IAAAC,QAAE,EAAE,gBAAiB,CAAC;EAC7BC,IAAI,EAAEC,oCAAiB;EACvBC,MAAM,EAAEC,oCAAiB;EACzBC,aAAa,EAAE;AAChB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,kBAAkB","ignoreList":[]}
@@ -34,6 +34,12 @@ Object.defineProperty(exports, "orderField", {
34
34
  return _order.default;
35
35
  }
36
36
  });
37
+ Object.defineProperty(exports, "pageTitleField", {
38
+ enumerable: true,
39
+ get: function () {
40
+ return _pageTitle.default;
41
+ }
42
+ });
37
43
  Object.defineProperty(exports, "parentField", {
38
44
  enumerable: true,
39
45
  get: function () {
@@ -46,6 +52,12 @@ Object.defineProperty(exports, "passwordField", {
46
52
  return _password.default;
47
53
  }
48
54
  });
55
+ Object.defineProperty(exports, "patternTitleField", {
56
+ enumerable: true,
57
+ get: function () {
58
+ return _patternTitle.default;
59
+ }
60
+ });
49
61
  Object.defineProperty(exports, "slugField", {
50
62
  enumerable: true,
51
63
  get: function () {
@@ -58,6 +70,18 @@ Object.defineProperty(exports, "statusField", {
58
70
  return _status.default;
59
71
  }
60
72
  });
73
+ Object.defineProperty(exports, "templateField", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _template.default;
77
+ }
78
+ });
79
+ Object.defineProperty(exports, "templateTitleField", {
80
+ enumerable: true,
81
+ get: function () {
82
+ return _templateTitle.default;
83
+ }
84
+ });
61
85
  Object.defineProperty(exports, "titleField", {
62
86
  enumerable: true,
63
87
  get: function () {
@@ -66,8 +90,12 @@ Object.defineProperty(exports, "titleField", {
66
90
  });
67
91
  var _slug = _interopRequireDefault(require("./slug"));
68
92
  var _title = _interopRequireDefault(require("./title"));
93
+ var _pageTitle = _interopRequireDefault(require("./page-title"));
94
+ var _templateTitle = _interopRequireDefault(require("./template-title"));
95
+ var _patternTitle = _interopRequireDefault(require("./pattern-title"));
69
96
  var _order = _interopRequireDefault(require("./order"));
70
97
  var _featuredImage = _interopRequireDefault(require("./featured-image"));
98
+ var _template = _interopRequireDefault(require("./template"));
71
99
  var _parent = _interopRequireDefault(require("./parent"));
72
100
  var _password = _interopRequireDefault(require("./password"));
73
101
  var _status = _interopRequireDefault(require("./status"));
@@ -1 +1 @@
1
- {"version":3,"names":["_slug","_interopRequireDefault","require","_title","_order","_featuredImage","_parent","_password","_status","_commentStatus","_date","_author"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\nexport { default as authorField } from './author';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,SAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,cAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,KAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,OAAA,GAAAV,sBAAA,CAAAC,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_slug","_interopRequireDefault","require","_title","_pageTitle","_templateTitle","_patternTitle","_order","_featuredImage","_template","_parent","_password","_status","_commentStatus","_date","_author"],"sources":["@wordpress/fields/src/fields/index.ts"],"sourcesContent":["export { default as slugField } from './slug';\nexport { default as titleField } from './title';\nexport { default as pageTitleField } from './page-title';\nexport { default as templateTitleField } from './template-title';\nexport { default as patternTitleField } from './pattern-title';\nexport { default as orderField } from './order';\nexport { default as featuredImageField } from './featured-image';\nexport { default as templateField } from './template';\nexport { default as parentField } from './parent';\nexport { default as passwordField } from './password';\nexport { default as statusField } from './status';\nexport { default as commentStatusField } from './comment-status';\nexport { default as dateField } from './date';\nexport { default as authorField } from './author';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,aAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,MAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,cAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,SAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,OAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,SAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,OAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,cAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY,KAAA,GAAAb,sBAAA,CAAAC,OAAA;AACA,IAAAa,OAAA,GAAAd,sBAAA,CAAAC,OAAA","ignoreList":[]}
@@ -19,5 +19,9 @@ const orderField = {
19
19
  label: (0, _i18n.__)('Order'),
20
20
  description: (0, _i18n.__)('Determines the order of pages.')
21
21
  };
22
+
23
+ /**
24
+ * Order field for BasePost.
25
+ */
22
26
  var _default = exports.default = orderField;
23
27
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","orderField","id","type","label","__","description","_default","exports","default"],"sources":["@wordpress/fields/src/fields/order/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nconst orderField: Field< BasePost > = {\n\tid: 'menu_order',\n\ttype: 'integer',\n\tlabel: __( 'Order' ),\n\tdescription: __( 'Determines the order of pages.' ),\n};\n\nexport default orderField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMC,UAA6B,GAAG;EACrCC,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,SAAS;EACfC,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;EACpBC,WAAW,EAAE,IAAAD,QAAE,EAAE,gCAAiC;AACnD,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaR,UAAU","ignoreList":[]}
1
+ {"version":3,"names":["_i18n","require","orderField","id","type","label","__","description","_default","exports","default"],"sources":["@wordpress/fields/src/fields/order/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\n\nconst orderField: Field< BasePost > = {\n\tid: 'menu_order',\n\ttype: 'integer',\n\tlabel: __( 'Order' ),\n\tdescription: __( 'Determines the order of pages.' ),\n};\n\n/**\n * Order field for BasePost.\n */\nexport default orderField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;;AAGA,MAAMC,UAA6B,GAAG;EACrCC,EAAE,EAAE,YAAY;EAChBC,IAAI,EAAE,SAAS;EACfC,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;EACpBC,WAAW,EAAE,IAAAD,QAAE,EAAE,gCAAiC;AACnD,CAAC;;AAED;AACA;AACA;AAFA,IAAAE,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeR,UAAU","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _utils = require("../../actions/utils");
10
+ var _view = _interopRequireDefault(require("./view"));
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ const pageTitleField = {
20
+ type: 'text',
21
+ id: 'title',
22
+ label: (0, _i18n.__)('Title'),
23
+ placeholder: (0, _i18n.__)('No title'),
24
+ getValue: ({
25
+ item
26
+ }) => (0, _utils.getItemTitle)(item),
27
+ render: _view.default,
28
+ enableHiding: false,
29
+ enableGlobalSearch: true
30
+ };
31
+
32
+ /**
33
+ * Title for the page entity.
34
+ */
35
+ var _default = exports.default = pageTitleField;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_utils","_view","_interopRequireDefault","pageTitleField","type","id","label","__","placeholder","getValue","item","getItemTitle","render","PageTitleView","enableHiding","enableGlobalSearch","_default","exports","default"],"sources":["@wordpress/fields/src/fields/page-title/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport PageTitleView from './view';\n\nconst pageTitleField: Field< BasePost > = {\n\ttype: 'text',\n\tid: 'title',\n\tlabel: __( 'Title' ),\n\tplaceholder: __( 'No title' ),\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: PageTitleView,\n\tenableHiding: false,\n\tenableGlobalSearch: true,\n};\n\n/**\n * Title for the page entity.\n */\nexport default pageTitleField;\n"],"mappings":";;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMI,cAAiC,GAAG;EACzCC,IAAI,EAAE,MAAM;EACZC,EAAE,EAAE,OAAO;EACXC,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;EACpBC,WAAW,EAAE,IAAAD,QAAE,EAAE,UAAW,CAAC;EAC7BE,QAAQ,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAM,IAAAC,mBAAY,EAAED,IAAK,CAAC;EAC9CE,MAAM,EAAEC,aAAa;EACrBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE;AACrB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGef,cAAc","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = PageTitleView;
7
+ var _i18n = require("@wordpress/i18n");
8
+ var _data = require("@wordpress/data");
9
+ var _coreData = require("@wordpress/core-data");
10
+ var _view = require("../title/view");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ /**
13
+ * WordPress dependencies
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+
20
+ function PageTitleView({
21
+ item
22
+ }) {
23
+ const {
24
+ frontPageId,
25
+ postsPageId
26
+ } = (0, _data.useSelect)(select => {
27
+ const {
28
+ getEntityRecord
29
+ } = select(_coreData.store);
30
+ const siteSettings = getEntityRecord('root', 'site');
31
+ return {
32
+ frontPageId: siteSettings?.page_on_front,
33
+ postsPageId: siteSettings?.page_for_posts
34
+ };
35
+ }, []);
36
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_view.BaseTitleView, {
37
+ item: item,
38
+ className: "fields-field__page-title",
39
+ children: [frontPageId, postsPageId].includes(item.id) && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
40
+ className: "fields-field__page-title__badge",
41
+ children: item.id === frontPageId ? (0, _i18n.__)('Homepage') : (0, _i18n.__)('Posts Page')
42
+ })
43
+ });
44
+ }
45
+ //# sourceMappingURL=view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_data","_coreData","_view","_jsxRuntime","PageTitleView","item","frontPageId","postsPageId","useSelect","select","getEntityRecord","coreStore","siteSettings","page_on_front","page_for_posts","jsx","BaseTitleView","className","children","includes","id","__"],"sources":["@wordpress/fields/src/fields/page-title/view.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { Settings } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { BaseTitleView } from '../title/view';\n\nexport default function PageTitleView( { item }: { item: CommonPost } ) {\n\tconst { frontPageId, postsPageId } = useSelect( ( select ) => {\n\t\tconst { getEntityRecord } = select( coreStore );\n\t\tconst siteSettings = getEntityRecord(\n\t\t\t'root',\n\t\t\t'site'\n\t\t) as Partial< Settings >;\n\t\treturn {\n\t\t\tfrontPageId: siteSettings?.page_on_front,\n\t\t\tpostsPageId: siteSettings?.page_for_posts,\n\t\t};\n\t}, [] );\n\treturn (\n\t\t<BaseTitleView item={ item } className=\"fields-field__page-title\">\n\t\t\t{ [ frontPageId, postsPageId ].includes( item.id as number ) && (\n\t\t\t\t<span className=\"fields-field__page-title__badge\">\n\t\t\t\t\t{ item.id === frontPageId\n\t\t\t\t\t\t? __( 'Homepage' )\n\t\t\t\t\t\t: __( 'Posts Page' ) }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</BaseTitleView>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAOA,IAAAG,KAAA,GAAAH,OAAA;AAA8C,IAAAI,WAAA,GAAAJ,OAAA;AAZ9C;AACA;AACA;;AAMA;AACA;AACA;;AAIe,SAASK,aAAaA,CAAE;EAAEC;AAA2B,CAAC,EAAG;EACvE,MAAM;IAAEC,WAAW;IAAEC;EAAY,CAAC,GAAG,IAAAC,eAAS,EAAIC,MAAM,IAAM;IAC7D,MAAM;MAAEC;IAAgB,CAAC,GAAGD,MAAM,CAAEE,eAAU,CAAC;IAC/C,MAAMC,YAAY,GAAGF,eAAe,CACnC,MAAM,EACN,MACD,CAAwB;IACxB,OAAO;MACNJ,WAAW,EAAEM,YAAY,EAAEC,aAAa;MACxCN,WAAW,EAAEK,YAAY,EAAEE;IAC5B,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;EACP,oBACC,IAAAX,WAAA,CAAAY,GAAA,EAACb,KAAA,CAAAc,aAAa;IAACX,IAAI,EAAGA,IAAM;IAACY,SAAS,EAAC,0BAA0B;IAAAC,QAAA,EAC9D,CAAEZ,WAAW,EAAEC,WAAW,CAAE,CAACY,QAAQ,CAAEd,IAAI,CAACe,EAAa,CAAC,iBAC3D,IAAAjB,WAAA,CAAAY,GAAA;MAAME,SAAS,EAAC,iCAAiC;MAAAC,QAAA,EAC9Cb,IAAI,CAACe,EAAE,KAAKd,WAAW,GACtB,IAAAe,QAAE,EAAE,UAAW,CAAC,GAChB,IAAAA,QAAE,EAAE,YAAa;IAAC,CAChB;EACN,CACa,CAAC;AAElB","ignoreList":[]}
@@ -25,7 +25,7 @@ const parentField = {
25
25
  };
26
26
 
27
27
  /**
28
- * This field is used to display the post parent.
28
+ * Parent field for BasePost.
29
29
  */
30
30
  var _default = exports.default = parentField;
31
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_i18n","require","_parentEdit","_parentView","parentField","id","type","label","__","Edit","ParentEdit","render","ParentView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/parent/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { ParentEdit } from './parent-edit';\nimport { ParentView } from './parent-view';\n\nconst parentField: Field< BasePost > = {\n\tid: 'parent',\n\ttype: 'text',\n\tlabel: __( 'Parent' ),\n\tEdit: ParentEdit,\n\trender: ParentView,\n\tenableSorting: true,\n};\n\n/**\n * This field is used to display the post parent.\n */\nexport default parentField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMG,WAA8B,GAAG;EACtCC,EAAE,EAAE,QAAQ;EACZC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,IAAI,EAAEC,sBAAU;EAChBC,MAAM,EAAEC,sBAAU;EAClBC,aAAa,EAAE;AAChB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,WAAW","ignoreList":[]}
1
+ {"version":3,"names":["_i18n","require","_parentEdit","_parentView","parentField","id","type","label","__","Edit","ParentEdit","render","ParentView","enableSorting","_default","exports","default"],"sources":["@wordpress/fields/src/fields/parent/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport { ParentEdit } from './parent-edit';\nimport { ParentView } from './parent-view';\n\nconst parentField: Field< BasePost > = {\n\tid: 'parent',\n\ttype: 'text',\n\tlabel: __( 'Parent' ),\n\tEdit: ParentEdit,\n\trender: ParentView,\n\tenableSorting: true,\n};\n\n/**\n * Parent field for BasePost.\n */\nexport default parentField;\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMG,WAA8B,GAAG;EACtCC,EAAE,EAAE,QAAQ;EACZC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS,CAAC;EACrBC,IAAI,EAAEC,sBAAU;EAChBC,MAAM,EAAEC,sBAAU;EAClBC,aAAa,EAAE;AAChB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,WAAW","ignoreList":[]}
@@ -24,7 +24,7 @@ const passwordField = {
24
24
  };
25
25
 
26
26
  /**
27
- * This field is used to display the post password.
27
+ * Password field for BasePost.
28
28
  */
29
29
  var _default = exports.default = passwordField;
30
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_edit","_interopRequireDefault","require","passwordField","id","type","Edit","PasswordEdit","enableSorting","enableHiding","isVisible","item","status","_default","exports","default"],"sources":["@wordpress/fields/src/fields/password/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport PasswordEdit from './edit';\n\nconst passwordField: Field< BasePost > = {\n\tid: 'password',\n\ttype: 'text',\n\tEdit: PasswordEdit,\n\tenableSorting: false,\n\tenableHiding: false,\n\tisVisible: ( item ) => item.status !== 'private',\n};\n\n/**\n * This field is used to display the post password.\n */\nexport default passwordField;\n"],"mappings":";;;;;;;AASA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMC,aAAgC,GAAG;EACxCC,EAAE,EAAE,UAAU;EACdC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAEC,aAAY;EAClBC,aAAa,EAAE,KAAK;EACpBC,YAAY,EAAE,KAAK;EACnBC,SAAS,EAAIC,IAAI,IAAMA,IAAI,CAACC,MAAM,KAAK;AACxC,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["_edit","_interopRequireDefault","require","passwordField","id","type","Edit","PasswordEdit","enableSorting","enableHiding","isVisible","item","status","_default","exports","default"],"sources":["@wordpress/fields/src/fields/password/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../types';\nimport PasswordEdit from './edit';\n\nconst passwordField: Field< BasePost > = {\n\tid: 'password',\n\ttype: 'text',\n\tEdit: PasswordEdit,\n\tenableSorting: false,\n\tenableHiding: false,\n\tisVisible: ( item ) => item.status !== 'private',\n};\n\n/**\n * Password field for BasePost.\n */\nexport default passwordField;\n"],"mappings":";;;;;;;AASA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA,MAAMC,aAAgC,GAAG;EACxCC,EAAE,EAAE,UAAU;EACdC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAEC,aAAY;EAClBC,aAAa,EAAE,KAAK;EACpBC,YAAY,EAAE,KAAK;EACnBC,SAAS,EAAIC,IAAI,IAAMA,IAAI,CAACC,MAAM,KAAK;AACxC,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGeZ,aAAa","ignoreList":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _i18n = require("@wordpress/i18n");
9
+ var _utils = require("../../actions/utils");
10
+ var _view = _interopRequireDefault(require("./view"));
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ const patternTitleField = {
20
+ type: 'text',
21
+ id: 'title',
22
+ label: (0, _i18n.__)('Title'),
23
+ placeholder: (0, _i18n.__)('No title'),
24
+ getValue: ({
25
+ item
26
+ }) => (0, _utils.getItemTitle)(item),
27
+ render: _view.default,
28
+ enableHiding: false,
29
+ enableGlobalSearch: true
30
+ };
31
+
32
+ /**
33
+ * Title for the pattern entity.
34
+ */
35
+ var _default = exports.default = patternTitleField;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_i18n","require","_utils","_view","_interopRequireDefault","patternTitleField","type","id","label","__","placeholder","getValue","item","getItemTitle","render","PatternTitleView","enableHiding","enableGlobalSearch","_default","exports","default"],"sources":["@wordpress/fields/src/fields/pattern-title/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { Pattern } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport PatternTitleView from './view';\n\nconst patternTitleField: Field< Pattern > = {\n\ttype: 'text',\n\tid: 'title',\n\tlabel: __( 'Title' ),\n\tplaceholder: __( 'No title' ),\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: PatternTitleView,\n\tenableHiding: false,\n\tenableGlobalSearch: true,\n};\n\n/**\n * Title for the pattern entity.\n */\nexport default patternTitleField;\n"],"mappings":";;;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAC,sBAAA,CAAAH,OAAA;AAXA;AACA;AACA;;AAIA;AACA;AACA;;AAKA,MAAMI,iBAAmC,GAAG;EAC3CC,IAAI,EAAE,MAAM;EACZC,EAAE,EAAE,OAAO;EACXC,KAAK,EAAE,IAAAC,QAAE,EAAE,OAAQ,CAAC;EACpBC,WAAW,EAAE,IAAAD,QAAE,EAAE,UAAW,CAAC;EAC7BE,QAAQ,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAM,IAAAC,mBAAY,EAAED,IAAK,CAAC;EAC9CE,MAAM,EAAEC,aAAgB;EACxBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE;AACrB,CAAC;;AAED;AACA;AACA;AAFA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAGef,iBAAiB","ignoreList":[]}