@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 +1,7 @@
1
- {"version":3,"names":["__","TemplateEdit","templateField","id","type","label","Edit","enableSorting","filterBy"],"sources":["@wordpress/fields/src/fields/template/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport type { BasePost } from '../../types';\nimport { TemplateEdit } from './template-edit';\n\nconst templateField: Field< BasePost > = {\n\tid: 'template',\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tEdit: TemplateEdit,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\n/**\n * Template field for BasePost.\n */\nexport default templateField;\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,EAAE,QAAQ,iBAAiB;AAEpC,SAASC,YAAY,QAAQ,iBAAiB;AAE9C,MAAMC,aAAgC,GAAG;EACxCC,EAAE,EAAE,UAAU;EACdC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAEL,EAAE,CAAE,UAAW,CAAC;EACvBM,IAAI,EAAEL,YAAY;EAClBM,aAAa,EAAE,KAAK;EACpBC,QAAQ,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA,eAAeN,aAAa","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/fields/template/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport type { BasePost } from '../../types';\nimport { TemplateEdit } from './template-edit';\n\nconst templateField: Field< BasePost > = {\n\tid: 'template',\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tEdit: TemplateEdit,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\n/**\n * Template field for BasePost.\n */\nexport default templateField;\n"],
5
+ "mappings": "AAQA,SAAS,UAAU;AAEnB,SAAS,oBAAoB;AAE7B,MAAM,gBAAmC;AAAA,EACxC,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,MAAM;AAAA,EACN,eAAe;AAAA,EACf,UAAU;AACX;AAKA,IAAO,mBAAQ;",
6
+ "names": []
7
+ }
@@ -1,63 +1,62 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useCallback, useMemo, useState } from '@wordpress/element';
5
- // @ts-ignore
6
- import { parse } from '@wordpress/blocks';
7
- import { store as coreStore } from '@wordpress/core-data';
8
- /**
9
- * Internal dependencies
10
- */
11
- // @ts-expect-error block-editor is not typed correctly.
12
- import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
13
- import { Button, Dropdown, MenuGroup, MenuItem, Modal } from '@wordpress/components';
14
- import { useAsyncList } from '@wordpress/compose';
15
- import { useSelect } from '@wordpress/data';
16
- import { decodeEntities } from '@wordpress/html-entities';
17
- import { __ } from '@wordpress/i18n';
18
- import { getItemTitle } from '../../actions/utils';
19
- import { unlock } from '../../lock-unlock';
20
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useMemo, useState } from "@wordpress/element";
3
+ import { parse } from "@wordpress/blocks";
4
+ import { store as coreStore } from "@wordpress/core-data";
5
+ import { __experimentalBlockPatternsList as BlockPatternsList } from "@wordpress/block-editor";
6
+ import {
7
+ Button,
8
+ Dropdown,
9
+ MenuGroup,
10
+ MenuItem,
11
+ Modal
12
+ } from "@wordpress/components";
13
+ import { useAsyncList } from "@wordpress/compose";
14
+ import { useSelect } from "@wordpress/data";
15
+ import { decodeEntities } from "@wordpress/html-entities";
16
+ import { __ } from "@wordpress/i18n";
17
+ import { getItemTitle } from "../../actions/utils";
18
+ import { unlock } from "../../lock-unlock";
21
19
  const EMPTY_ARRAY = [];
22
- export const TemplateEdit = ({
20
+ const TemplateEdit = ({
23
21
  data,
24
22
  field,
25
23
  onChange
26
24
  }) => {
27
- const {
28
- id
29
- } = field;
25
+ const { id } = field;
30
26
  const postType = data.type;
31
- const postId = typeof data.id === 'number' ? data.id : parseInt(data.id, 10);
27
+ const postId = typeof data.id === "number" ? data.id : parseInt(data.id, 10);
32
28
  const slug = data.slug;
33
- const {
34
- canSwitchTemplate,
35
- templates
36
- } = useSelect(select => {
37
- var _select$getEntityReco;
38
- const allTemplates = (_select$getEntityReco = select(coreStore).getEntityRecords('postType', 'wp_template', {
39
- per_page: -1,
40
- post_type: postType
41
- })) !== null && _select$getEntityReco !== void 0 ? _select$getEntityReco : EMPTY_ARRAY;
42
- const {
43
- getHomePage,
44
- getPostsPageId
45
- } = unlock(select(coreStore));
46
- const isPostsPage = getPostsPageId() === +postId;
47
- const isFrontPage = postType === 'page' && getHomePage()?.postId === +postId;
48
- const allowSwitchingTemplate = !isPostsPage && !isFrontPage;
49
- return {
50
- templates: allTemplates,
51
- canSwitchTemplate: allowSwitchingTemplate
52
- };
53
- }, [postId, postType]);
29
+ const { canSwitchTemplate, templates } = useSelect(
30
+ (select) => {
31
+ const allTemplates = select(coreStore).getEntityRecords(
32
+ "postType",
33
+ "wp_template",
34
+ {
35
+ per_page: -1,
36
+ post_type: postType
37
+ }
38
+ ) ?? EMPTY_ARRAY;
39
+ const { getHomePage, getPostsPageId } = unlock(
40
+ select(coreStore)
41
+ );
42
+ const isPostsPage = getPostsPageId() === +postId;
43
+ const isFrontPage = postType === "page" && getHomePage()?.postId === +postId;
44
+ const allowSwitchingTemplate = !isPostsPage && !isFrontPage;
45
+ return {
46
+ templates: allTemplates,
47
+ canSwitchTemplate: allowSwitchingTemplate
48
+ };
49
+ },
50
+ [postId, postType]
51
+ );
54
52
  const templatesAsPatterns = useMemo(() => {
55
53
  if (!canSwitchTemplate) {
56
54
  return [];
57
55
  }
58
- return templates.filter(template => template.is_custom && template.slug !== data.template &&
59
- // Skip empty templates.
60
- !!template.content.raw).map(template => ({
56
+ return templates.filter(
57
+ (template) => template.is_custom && template.slug !== data.template && // Skip empty templates.
58
+ !!template.content.raw
59
+ ).map((template) => ({
61
60
  name: template.slug,
62
61
  blocks: parse(template.content.raw),
63
62
  title: decodeEntities(template.title.rendered),
@@ -65,87 +64,105 @@ export const TemplateEdit = ({
65
64
  }));
66
65
  }, [canSwitchTemplate, data.template, templates]);
67
66
  const shownTemplates = useAsyncList(templatesAsPatterns);
68
- const value = field.getValue({
69
- item: data
70
- });
71
- const foundTemplate = templates.find(template => template.slug === value);
72
- const currentTemplate = useSelect(select => {
73
- if (foundTemplate) {
74
- return foundTemplate;
75
- }
76
- let slugToCheck;
77
- // In `draft` status we might not have a slug available, so we use the `single`
78
- // post type templates slug(ex page, single-post, single-product etc..).
79
- // Pages do not need the `single` prefix in the slug to be prioritized
80
- // through template hierarchy.
81
- if (slug) {
82
- slugToCheck = postType === 'page' ? `${postType}-${slug}` : `single-${postType}-${slug}`;
83
- } else {
84
- slugToCheck = postType === 'page' ? 'page' : `single-${postType}`;
85
- }
86
- if (postType) {
87
- const templateId = select(coreStore).getDefaultTemplateId({
88
- slug: slugToCheck
89
- });
90
- return select(coreStore).getEntityRecord('postType', 'wp_template', templateId);
91
- }
92
- }, [foundTemplate, postType, slug]);
67
+ const value = field.getValue({ item: data });
68
+ const foundTemplate = templates.find(
69
+ (template) => template.slug === value
70
+ );
71
+ const currentTemplate = useSelect(
72
+ (select) => {
73
+ if (foundTemplate) {
74
+ return foundTemplate;
75
+ }
76
+ let slugToCheck;
77
+ if (slug) {
78
+ slugToCheck = postType === "page" ? `${postType}-${slug}` : `single-${postType}-${slug}`;
79
+ } else {
80
+ slugToCheck = postType === "page" ? "page" : `single-${postType}`;
81
+ }
82
+ if (postType) {
83
+ const templateId = select(coreStore).getDefaultTemplateId({
84
+ slug: slugToCheck
85
+ });
86
+ return select(coreStore).getEntityRecord(
87
+ "postType",
88
+ "wp_template",
89
+ templateId
90
+ );
91
+ }
92
+ },
93
+ [foundTemplate, postType, slug]
94
+ );
93
95
  const [showModal, setShowModal] = useState(false);
94
- const onChangeControl = useCallback(newValue => onChange({
95
- [id]: newValue
96
- }), [id, onChange]);
97
- return /*#__PURE__*/_jsxs("fieldset", {
98
- className: "fields-controls__template",
99
- children: [/*#__PURE__*/_jsx(Dropdown, {
100
- popoverProps: {
101
- placement: 'bottom-start'
102
- },
103
- renderToggle: ({
104
- onToggle
105
- }) => /*#__PURE__*/_jsx(Button, {
106
- __next40pxDefaultSize: true,
107
- variant: "tertiary",
108
- size: "compact",
109
- onClick: onToggle,
110
- children: currentTemplate ? getItemTitle(currentTemplate) : ''
111
- }),
112
- renderContent: ({
113
- onToggle
114
- }) => /*#__PURE__*/_jsxs(MenuGroup, {
115
- children: [/*#__PURE__*/_jsx(MenuItem, {
116
- onClick: () => {
117
- setShowModal(true);
118
- onToggle();
119
- },
120
- children: __('Change template')
121
- }),
122
- // The default template in a post is indicated by an empty string
123
- value !== '' && /*#__PURE__*/_jsx(MenuItem, {
124
- onClick: () => {
125
- onChangeControl('');
126
- onToggle();
127
- },
128
- children: __('Use default template')
129
- })]
130
- })
131
- }), showModal && /*#__PURE__*/_jsx(Modal, {
132
- title: __('Choose a template'),
133
- onRequestClose: () => setShowModal(false),
134
- overlayClassName: "fields-controls__template-modal",
135
- isFullScreen: true,
136
- children: /*#__PURE__*/_jsx("div", {
137
- className: "fields-controls__template-content",
138
- children: /*#__PURE__*/_jsx(BlockPatternsList, {
139
- label: __('Templates'),
140
- blockPatterns: templatesAsPatterns,
141
- shownPatterns: shownTemplates,
142
- onClickPattern: template => {
143
- onChangeControl(template.name);
144
- setShowModal(false);
96
+ const onChangeControl = useCallback(
97
+ (newValue) => onChange({
98
+ [id]: newValue
99
+ }),
100
+ [id, onChange]
101
+ );
102
+ return /* @__PURE__ */ jsxs("fieldset", { className: "fields-controls__template", children: [
103
+ /* @__PURE__ */ jsx(
104
+ Dropdown,
105
+ {
106
+ popoverProps: { placement: "bottom-start" },
107
+ renderToggle: ({ onToggle }) => /* @__PURE__ */ jsx(
108
+ Button,
109
+ {
110
+ __next40pxDefaultSize: true,
111
+ variant: "tertiary",
112
+ size: "compact",
113
+ onClick: onToggle,
114
+ children: currentTemplate ? getItemTitle(currentTemplate) : ""
145
115
  }
146
- })
147
- })
148
- })]
149
- });
116
+ ),
117
+ renderContent: ({ onToggle }) => /* @__PURE__ */ jsxs(MenuGroup, { children: [
118
+ /* @__PURE__ */ jsx(
119
+ MenuItem,
120
+ {
121
+ onClick: () => {
122
+ setShowModal(true);
123
+ onToggle();
124
+ },
125
+ children: __("Change template")
126
+ }
127
+ ),
128
+ // The default template in a post is indicated by an empty string
129
+ value !== "" && /* @__PURE__ */ jsx(
130
+ MenuItem,
131
+ {
132
+ onClick: () => {
133
+ onChangeControl("");
134
+ onToggle();
135
+ },
136
+ children: __("Use default template")
137
+ }
138
+ )
139
+ ] })
140
+ }
141
+ ),
142
+ showModal && /* @__PURE__ */ jsx(
143
+ Modal,
144
+ {
145
+ title: __("Choose a template"),
146
+ onRequestClose: () => setShowModal(false),
147
+ overlayClassName: "fields-controls__template-modal",
148
+ isFullScreen: true,
149
+ children: /* @__PURE__ */ jsx("div", { className: "fields-controls__template-content", children: /* @__PURE__ */ jsx(
150
+ BlockPatternsList,
151
+ {
152
+ label: __("Templates"),
153
+ blockPatterns: templatesAsPatterns,
154
+ shownPatterns: shownTemplates,
155
+ onClickPattern: (template) => {
156
+ onChangeControl(template.name);
157
+ setShowModal(false);
158
+ }
159
+ }
160
+ ) })
161
+ }
162
+ )
163
+ ] });
164
+ };
165
+ export {
166
+ TemplateEdit
150
167
  };
151
- //# sourceMappingURL=template-edit.js.map
168
+ //# sourceMappingURL=template-edit.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useCallback","useMemo","useState","parse","store","coreStore","__experimentalBlockPatternsList","BlockPatternsList","Button","Dropdown","MenuGroup","MenuItem","Modal","useAsyncList","useSelect","decodeEntities","__","getItemTitle","unlock","jsx","_jsx","jsxs","_jsxs","EMPTY_ARRAY","TemplateEdit","data","field","onChange","id","postType","type","postId","parseInt","slug","canSwitchTemplate","templates","select","_select$getEntityReco","allTemplates","getEntityRecords","per_page","post_type","getHomePage","getPostsPageId","isPostsPage","isFrontPage","allowSwitchingTemplate","templatesAsPatterns","filter","template","is_custom","content","raw","map","name","blocks","title","rendered","shownTemplates","value","getValue","item","foundTemplate","find","currentTemplate","slugToCheck","templateId","getDefaultTemplateId","getEntityRecord","showModal","setShowModal","onChangeControl","newValue","className","children","popoverProps","placement","renderToggle","onToggle","__next40pxDefaultSize","variant","size","onClick","renderContent","onRequestClose","overlayClassName","isFullScreen","label","blockPatterns","shownPatterns","onClickPattern"],"sources":["@wordpress/fields/src/fields/template/template-edit.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_ARRAY: [] = [];\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { canSwitchTemplate, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: allowSwitchingTemplate,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo( () => {\n\t\tif ( ! canSwitchTemplate ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn templates\n\t\t\t.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t// Skip empty templates.\n\t\t\t\t\t!! template.content.raw\n\t\t\t)\n\t\t\t.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) );\n\t}, [ canSwitchTemplate, data.template, templates ] );\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\tconst foundTemplate = templates.find(\n\t\t( template ) => template.slug === value\n\t);\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ foundTemplate, postType, slug ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\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\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Change template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 ]\n\t\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\t\tonChangeControl( template.name );\n\t\t\t\t\t\t\t\tsetShowModal( false );\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</Modal>\n\t\t\t) }\n\t\t</fieldset>\n\t);\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE;AACA,SAASC,KAAK,QAAQ,mBAAmB;AAEzC,SAASC,KAAK,IAAIC,SAAS,QAAQ,sBAAsB;AAGzD;AACA;AACA;AACA;AACA,SAASC,+BAA+B,IAAIC,iBAAiB,QAAQ,yBAAyB;AAC9F,SACCC,MAAM,EACNC,QAAQ,EACRC,SAAS,EACTC,QAAQ,EACRC,KAAK,QACC,uBAAuB;AAC9B,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,YAAY,QAAQ,qBAAqB;AAElD,SAASC,MAAM,QAAQ,mBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE3C,MAAMC,WAAe,GAAG,EAAE;AAE1B,OAAO,MAAMC,YAAY,GAAGA,CAAE;EAC7BC,IAAI;EACJC,KAAK;EACLC;AACiC,CAAC,KAAM;EACxC,MAAM;IAAEC;EAAG,CAAC,GAAGF,KAAK;EACpB,MAAMG,QAAQ,GAAGJ,IAAI,CAACK,IAAI;EAC1B,MAAMC,MAAM,GACX,OAAON,IAAI,CAACG,EAAE,KAAK,QAAQ,GAAGH,IAAI,CAACG,EAAE,GAAGI,QAAQ,CAAEP,IAAI,CAACG,EAAE,EAAE,EAAG,CAAC;EAChE,MAAM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oB,CAAG;MACnCoE,cAAc,EAAGA,CAAA,KAAMd,YAAY,CAAE,KAAM,CAAG;MAC9Ce,gBAAgB,EAAC,iCAAiC;MAClDC,YAAY;MAAAZ,QAAA,eAEZtD,IAAA;QAAKqD,SAAS,EAAC,mCAAmC;QAAAC,QAAA,eACjDtD,IAAA,CAACb,iBAAiB;UACjBgF,KAAK,EAAGvE,EAAE,CAAE,WAAY,CAAG;UAC3BwE,aAAa,EAAGzC,mBAAqB;UACrC0C,aAAa,EAAG/B,cAAgB;UAChCgC,cAAc,EACbzC,QAA6C,IACzC;YACJsB,eAAe,CAAEtB,QAAQ,CAACK,IAAK,CAAC;YAChCgB,YAAY,CAAE,KAAM,CAAC;UACtB;QAAG,CACH;MAAC,CACE;IAAC,CACA,CACP;EAAA,CACQ,CAAC;AAEb,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/fields/template/template-edit.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo, useState } from '@wordpress/element';\n// @ts-ignore\nimport { parse } from '@wordpress/blocks';\nimport type { WpTemplate } from '@wordpress/core-data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\n// @ts-expect-error block-editor is not typed correctly.\nimport { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';\nimport {\n\tButton,\n\tDropdown,\n\tMenuGroup,\n\tMenuItem,\n\tModal,\n} from '@wordpress/components';\nimport { useAsyncList } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\nimport { getItemTitle } from '../../actions/utils';\nimport type { BasePost } from '../../types';\nimport { unlock } from '../../lock-unlock';\n\nconst EMPTY_ARRAY: [] = [];\n\nexport const TemplateEdit = ( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< BasePost > ) => {\n\tconst { id } = field;\n\tconst postType = data.type;\n\tconst postId =\n\t\ttypeof data.id === 'number' ? data.id : parseInt( data.id, 10 );\n\tconst slug = data.slug;\n\n\tconst { canSwitchTemplate, templates } = useSelect(\n\t\t( select ) => {\n\t\t\tconst allTemplates =\n\t\t\t\tselect( coreStore ).getEntityRecords< WpTemplate >(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tpost_type: postType,\n\t\t\t\t\t}\n\t\t\t\t) ?? EMPTY_ARRAY;\n\n\t\t\tconst { getHomePage, getPostsPageId } = unlock(\n\t\t\t\tselect( coreStore )\n\t\t\t);\n\n\t\t\tconst isPostsPage = getPostsPageId() === +postId;\n\t\t\tconst isFrontPage =\n\t\t\t\tpostType === 'page' && getHomePage()?.postId === +postId;\n\n\t\t\tconst allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;\n\n\t\t\treturn {\n\t\t\t\ttemplates: allTemplates,\n\t\t\t\tcanSwitchTemplate: allowSwitchingTemplate,\n\t\t\t};\n\t\t},\n\t\t[ postId, postType ]\n\t);\n\n\tconst templatesAsPatterns = useMemo( () => {\n\t\tif ( ! canSwitchTemplate ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn templates\n\t\t\t.filter(\n\t\t\t\t( template ) =>\n\t\t\t\t\ttemplate.is_custom &&\n\t\t\t\t\ttemplate.slug !== data.template &&\n\t\t\t\t\t// Skip empty templates.\n\t\t\t\t\t!! template.content.raw\n\t\t\t)\n\t\t\t.map( ( template ) => ( {\n\t\t\t\tname: template.slug,\n\t\t\t\tblocks: parse( template.content.raw ),\n\t\t\t\ttitle: decodeEntities( template.title.rendered ),\n\t\t\t\tid: template.id,\n\t\t\t} ) );\n\t}, [ canSwitchTemplate, data.template, templates ] );\n\n\tconst shownTemplates = useAsyncList( templatesAsPatterns );\n\n\tconst value = field.getValue( { item: data } );\n\tconst foundTemplate = templates.find(\n\t\t( template ) => template.slug === value\n\t);\n\n\tconst currentTemplate = useSelect(\n\t\t( select ) => {\n\t\t\tif ( foundTemplate ) {\n\t\t\t\treturn foundTemplate;\n\t\t\t}\n\n\t\t\tlet slugToCheck;\n\t\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t\t// through template hierarchy.\n\t\t\tif ( slug ) {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page'\n\t\t\t\t\t\t? `${ postType }-${ slug }`\n\t\t\t\t\t\t: `single-${ postType }-${ slug }`;\n\t\t\t} else {\n\t\t\t\tslugToCheck =\n\t\t\t\t\tpostType === 'page' ? 'page' : `single-${ postType }`;\n\t\t\t}\n\n\t\t\tif ( postType ) {\n\t\t\t\tconst templateId = select( coreStore ).getDefaultTemplateId( {\n\t\t\t\t\tslug: slugToCheck,\n\t\t\t\t} );\n\n\t\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t\t'postType',\n\t\t\t\t\t'wp_template',\n\t\t\t\t\ttemplateId\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t\t[ foundTemplate, postType, slug ]\n\t);\n\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( {\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<fieldset className=\"fields-controls__template\">\n\t\t\t<Dropdown\n\t\t\t\tpopoverProps={ { placement: 'bottom-start' } }\n\t\t\t\trenderToggle={ ( { onToggle } ) => (\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\tsize=\"compact\"\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ currentTemplate\n\t\t\t\t\t\t\t? getItemTitle( currentTemplate )\n\t\t\t\t\t\t\t: '' }\n\t\t\t\t\t</Button>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onToggle } ) => (\n\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowModal( true );\n\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Change template' ) }\n\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// The default template in a post is indicated by an empty string\n\t\t\t\t\t\t\tvalue !== '' && (\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\t\tonChangeControl( '' );\n\t\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Use default template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t</MenuGroup>\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ showModal && (\n\t\t\t\t<Modal\n\t\t\t\t\ttitle={ __( 'Choose a template' ) }\n\t\t\t\t\tonRequestClose={ () => setShowModal( false ) }\n\t\t\t\t\toverlayClassName=\"fields-controls__template-modal\"\n\t\t\t\t\tisFullScreen\n\t\t\t\t>\n\t\t\t\t\t<div className=\"fields-controls__template-content\">\n\t\t\t\t\t\t<BlockPatternsList\n\t\t\t\t\t\t\tlabel={ __( 'Templates' ) }\n\t\t\t\t\t\t\tblockPatterns={ templatesAsPatterns }\n\t\t\t\t\t\t\tshownPatterns={ shownTemplates }\n\t\t\t\t\t\t\tonClickPattern={ (\n\t\t\t\t\t\t\t\ttemplate: ( typeof templatesAsPatterns )[ 0 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 "names": []
7
+ }
@@ -1,31 +1,19 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
-
5
- import { __ } from '@wordpress/i18n';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
-
11
- import { getItemTitle } from '../../actions/utils';
12
- import TitleView from '../title/view';
1
+ import { __ } from "@wordpress/i18n";
2
+ import { getItemTitle } from "../../actions/utils";
3
+ import TitleView from "../title/view";
13
4
  const templateTitleField = {
14
- type: 'text',
15
- label: __('Template'),
16
- placeholder: __('No title'),
17
- id: 'title',
18
- getValue: ({
19
- item
20
- }) => getItemTitle(item),
5
+ type: "text",
6
+ label: __("Template"),
7
+ placeholder: __("No title"),
8
+ id: "title",
9
+ getValue: ({ item }) => getItemTitle(item),
21
10
  render: TitleView,
22
11
  enableHiding: false,
23
12
  enableGlobalSearch: true,
24
13
  filterBy: false
25
14
  };
26
-
27
- /**
28
- * Title for the template entity.
29
- */
30
- export default templateTitleField;
31
- //# sourceMappingURL=index.js.map
15
+ var template_title_default = templateTitleField;
16
+ export {
17
+ template_title_default as default
18
+ };
19
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["__","getItemTitle","TitleView","templateTitleField","type","label","placeholder","id","getValue","item","render","enableHiding","enableGlobalSearch","filterBy"],"sources":["@wordpress/fields/src/fields/template-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 { Template } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from '../title/view';\n\nconst templateTitleField: Field< Template > = {\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tplaceholder: __( 'No title' ),\n\tid: 'title',\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: false,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the template entity.\n */\nexport default templateTitleField;\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAEA,SAASC,YAAY,QAAQ,qBAAqB;AAClD,OAAOC,SAAS,MAAM,eAAe;AAErC,MAAMC,kBAAqC,GAAG;EAC7CC,IAAI,EAAE,MAAM;EACZC,KAAK,EAAEL,EAAE,CAAE,UAAW,CAAC;EACvBM,WAAW,EAAEN,EAAE,CAAE,UAAW,CAAC;EAC7BO,EAAE,EAAE,OAAO;EACXC,QAAQ,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAMR,YAAY,CAAEQ,IAAK,CAAC;EAC9CC,MAAM,EAAER,SAAS;EACjBS,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,IAAI;EACxBC,QAAQ,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA,eAAeV,kBAAkB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/fields/template-title/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { Template } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from '../title/view';\n\nconst templateTitleField: Field< Template > = {\n\ttype: 'text',\n\tlabel: __( 'Template' ),\n\tplaceholder: __( 'No title' ),\n\tid: 'title',\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: false,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the template entity.\n */\nexport default templateTitleField;\n"],
5
+ "mappings": "AAIA,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAC7B,OAAO,eAAe;AAEtB,MAAM,qBAAwC;AAAA,EAC7C,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,aAAa,GAAI,UAAW;AAAA,EAC5B,IAAI;AAAA,EACJ,UAAU,CAAE,EAAE,KAAK,MAAO,aAAc,IAAK;AAAA,EAC7C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,UAAU;AACX;AAKA,IAAO,yBAAQ;",
6
+ "names": []
7
+ }
@@ -1,33 +1,19 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
-
5
- import { __ } from '@wordpress/i18n';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
-
11
- import { getItemTitle } from '../../actions/utils';
12
- import TitleView from './view';
1
+ import { __ } from "@wordpress/i18n";
2
+ import { getItemTitle } from "../../actions/utils";
3
+ import TitleView from "./view";
13
4
  const titleField = {
14
- type: 'text',
15
- id: 'title',
16
- label: __('Title'),
17
- placeholder: __('No title'),
18
- getValue: ({
19
- item
20
- }) => getItemTitle(item),
5
+ type: "text",
6
+ id: "title",
7
+ label: __("Title"),
8
+ placeholder: __("No title"),
9
+ getValue: ({ item }) => getItemTitle(item),
21
10
  render: TitleView,
22
11
  enableHiding: true,
23
12
  enableGlobalSearch: true,
24
13
  filterBy: false
25
14
  };
26
-
27
- /**
28
- * Title for the any entity with a `title` property.
29
- * For patterns, pages or templates you should use the respective field
30
- * because there are some differences in the rendering, labels, etc.
31
- */
32
- export default titleField;
33
- //# sourceMappingURL=index.js.map
15
+ var title_default = titleField;
16
+ export {
17
+ title_default as default
18
+ };
19
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["__","getItemTitle","TitleView","titleField","type","id","label","placeholder","getValue","item","render","enableHiding","enableGlobalSearch","filterBy"],"sources":["@wordpress/fields/src/fields/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 { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from './view';\n\nconst titleField: Field< CommonPost > = {\n\ttype: 'text',\n\tid: 'title',\n\tlabel: __( 'Title' ),\n\tplaceholder: __( 'No title' ),\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: true,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the any entity with a `title` property.\n * For patterns, pages or templates you should use the respective field\n * because there are some differences in the rendering, labels, etc.\n */\nexport default titleField;\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAEA,SAASC,YAAY,QAAQ,qBAAqB;AAClD,OAAOC,SAAS,MAAM,QAAQ;AAE9B,MAAMC,UAA+B,GAAG;EACvCC,IAAI,EAAE,MAAM;EACZC,EAAE,EAAE,OAAO;EACXC,KAAK,EAAEN,EAAE,CAAE,OAAQ,CAAC;EACpBO,WAAW,EAAEP,EAAE,CAAE,UAAW,CAAC;EAC7BQ,QAAQ,EAAEA,CAAE;IAAEC;EAAK,CAAC,KAAMR,YAAY,CAAEQ,IAAK,CAAC;EAC9CC,MAAM,EAAER,SAAS;EACjBS,YAAY,EAAE,IAAI;EAClBC,kBAAkB,EAAE,IAAI;EACxBC,QAAQ,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,eAAeV,UAAU","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/fields/title/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\nimport TitleView from './view';\n\nconst titleField: Field< CommonPost > = {\n\ttype: 'text',\n\tid: 'title',\n\tlabel: __( 'Title' ),\n\tplaceholder: __( 'No title' ),\n\tgetValue: ( { item } ) => getItemTitle( item ),\n\trender: TitleView,\n\tenableHiding: true,\n\tenableGlobalSearch: true,\n\tfilterBy: false,\n};\n\n/**\n * Title for the any entity with a `title` property.\n * For patterns, pages or templates you should use the respective field\n * because there are some differences in the rendering, labels, etc.\n */\nexport default titleField;\n"],
5
+ "mappings": "AAIA,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAC7B,OAAO,eAAe;AAEtB,MAAM,aAAkC;AAAA,EACvC,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,OAAO,GAAI,OAAQ;AAAA,EACnB,aAAa,GAAI,UAAW;AAAA,EAC5B,UAAU,CAAE,EAAE,KAAK,MAAO,aAAc,IAAK;AAAA,EAC7C,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,oBAAoB;AAAA,EACpB,UAAU;AACX;AAOA,IAAO,gBAAQ;",
6
+ "names": []
7
+ }
@@ -1,39 +1,32 @@
1
- /**
2
- * External dependencies
3
- */
4
- import clsx from 'clsx';
5
- /**
6
- * WordPress dependencies
7
- */
8
- import { __experimentalHStack as HStack } from '@wordpress/components';
9
- import { __ } from '@wordpress/i18n';
10
-
11
- /**
12
- * Internal dependencies
13
- */
14
-
15
- import { getItemTitle } from '../../actions/utils';
16
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
- export function BaseTitleView({
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import clsx from "clsx";
3
+ import { __experimentalHStack as HStack } from "@wordpress/components";
4
+ import { __ } from "@wordpress/i18n";
5
+ import { getItemTitle } from "../../actions/utils";
6
+ function BaseTitleView({
18
7
  item,
19
8
  className,
20
9
  children
21
10
  }) {
22
11
  const renderedTitle = getItemTitle(item);
23
- return /*#__PURE__*/_jsxs(HStack, {
24
- className: clsx('fields-field__title', className),
25
- alignment: "center",
26
- justify: "flex-start",
27
- children: [/*#__PURE__*/_jsx("span", {
28
- children: renderedTitle || __('(no title)')
29
- }), children]
30
- });
12
+ return /* @__PURE__ */ jsxs(
13
+ HStack,
14
+ {
15
+ className: clsx("fields-field__title", className),
16
+ alignment: "center",
17
+ justify: "flex-start",
18
+ children: [
19
+ /* @__PURE__ */ jsx("span", { children: renderedTitle || __("(no title)") }),
20
+ children
21
+ ]
22
+ }
23
+ );
31
24
  }
32
- export default function TitleView({
33
- item
34
- }) {
35
- return /*#__PURE__*/_jsx(BaseTitleView, {
36
- item: item
37
- });
25
+ function TitleView({ item }) {
26
+ return /* @__PURE__ */ jsx(BaseTitleView, { item });
38
27
  }
39
- //# sourceMappingURL=view.js.map
28
+ export {
29
+ BaseTitleView,
30
+ TitleView as default
31
+ };
32
+ //# sourceMappingURL=view.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["clsx","__experimentalHStack","HStack","__","getItemTitle","jsx","_jsx","jsxs","_jsxs","BaseTitleView","item","className","children","renderedTitle","alignment","justify","TitleView"],"sources":["@wordpress/fields/src/fields/title/view.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\n\nexport function BaseTitleView( {\n\titem,\n\tclassName,\n\tchildren,\n}: {\n\titem: CommonPost;\n\tclassName?: string;\n\tchildren?: ReactNode;\n} ) {\n\tconst renderedTitle = getItemTitle( item );\n\treturn (\n\t\t<HStack\n\t\t\tclassName={ clsx( 'fields-field__title', className ) }\n\t\t\talignment=\"center\"\n\t\t\tjustify=\"flex-start\"\n\t\t>\n\t\t\t<span>{ renderedTitle || __( '(no title)' ) }</span>\n\t\t\t{ children }\n\t\t</HStack>\n\t);\n}\n\nexport default function TitleView( { item }: { item: CommonPost } ) {\n\treturn <BaseTitleView item={ item } />;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;AAGvB;AACA;AACA;AACA,SAASC,oBAAoB,IAAIC,MAAM,QAAQ,uBAAuB;AACtE,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;;AAEA,SAASC,YAAY,QAAQ,qBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAEnD,OAAO,SAASC,aAAaA,CAAE;EAC9BC,IAAI;EACJC,SAAS;EACTC;AAKD,CAAC,EAAG;EACH,MAAMC,aAAa,GAAGT,YAAY,CAAEM,IAAK,CAAC;EAC1C,oBACCF,KAAA,CAACN,MAAM;IACNS,SAAS,EAAGX,IAAI,CAAE,qBAAqB,EAAEW,SAAU,CAAG;IACtDG,SAAS,EAAC,QAAQ;IAClBC,OAAO,EAAC,YAAY;IAAAH,QAAA,gBAEpBN,IAAA;MAAAM,QAAA,EAAQC,aAAa,IAAIV,EAAE,CAAE,YAAa;IAAC,CAAQ,CAAC,EAClDS,QAAQ;EAAA,CACH,CAAC;AAEX;AAEA,eAAe,SAASI,SAASA,CAAE;EAAEN;AAA2B,CAAC,EAAG;EACnE,oBAAOJ,IAAA,CAACG,aAAa;IAACC,IAAI,EAAGA;EAAM,CAAE,CAAC;AACvC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/fields/title/view.tsx"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { CommonPost } from '../../types';\nimport { getItemTitle } from '../../actions/utils';\n\nexport function BaseTitleView( {\n\titem,\n\tclassName,\n\tchildren,\n}: {\n\titem: CommonPost;\n\tclassName?: string;\n\tchildren?: ReactNode;\n} ) {\n\tconst renderedTitle = getItemTitle( item );\n\treturn (\n\t\t<HStack\n\t\t\tclassName={ clsx( 'fields-field__title', className ) }\n\t\t\talignment=\"center\"\n\t\t\tjustify=\"flex-start\"\n\t\t>\n\t\t\t<span>{ renderedTitle || __( '(no title)' ) }</span>\n\t\t\t{ children }\n\t\t</HStack>\n\t);\n}\n\nexport default function TitleView( { item }: { item: CommonPost } ) {\n\treturn <BaseTitleView item={ item } />;\n}\n"],
5
+ "mappings": "AA6BE,SAKC,KALD;AA1BF,OAAO,UAAU;AAMjB,SAAS,wBAAwB,cAAc;AAC/C,SAAS,UAAU;AAMnB,SAAS,oBAAoB;AAEtB,SAAS,cAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,GAII;AACH,QAAM,gBAAgB,aAAc,IAAK;AACzC,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAY,KAAM,uBAAuB,SAAU;AAAA,MACnD,WAAU;AAAA,MACV,SAAQ;AAAA,MAER;AAAA,4BAAC,UAAO,2BAAiB,GAAI,YAAa,GAAG;AAAA,QAC3C;AAAA;AAAA;AAAA,EACH;AAEF;AAEe,SAAR,UAA4B,EAAE,KAAK,GAA0B;AACnE,SAAO,oBAAC,iBAAc,MAAc;AACrC;",
6
+ "names": []
7
+ }
@@ -1,4 +1,7 @@
1
- export * from './fields';
2
- export * from './actions';
3
- export { default as CreateTemplatePartModal } from './components/create-template-part-modal';
4
- //# sourceMappingURL=index.js.map
1
+ export * from "./fields";
2
+ export * from "./actions";
3
+ import { default as default2 } from "./components/create-template-part-modal";
4
+ export {
5
+ default2 as CreateTemplatePartModal
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["default","CreateTemplatePartModal"],"sources":["@wordpress/fields/src/index.ts"],"sourcesContent":["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type { BasePostWithEmbeddedAuthor, BasePost, PostType } from './types';\n"],"mappings":"AAAA,cAAc,UAAU;AACxB,cAAc,WAAW;AACzB,SAASA,OAAO,IAAIC,uBAAuB,QAAQ,yCAAyC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from './fields';\nexport * from './actions';\nexport { default as CreateTemplatePartModal } from './components/create-template-part-modal';\nexport type { BasePostWithEmbeddedAuthor, BasePost, PostType } from './types';\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA0C;",
6
+ "names": ["default"]
7
+ }
@@ -1,9 +1,10 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
5
- export const {
1
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
2
+ const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
3
+ "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
4
+ "@wordpress/fields"
5
+ );
6
+ export {
6
7
  lock,
7
8
  unlock
8
- } = __dangerousOptInToUnstableAPIsOnlyForCoreModules('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/fields');
9
- //# sourceMappingURL=lock-unlock.js.map
9
+ };
10
+ //# sourceMappingURL=lock-unlock.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["__dangerousOptInToUnstableAPIsOnlyForCoreModules","lock","unlock"],"sources":["@wordpress/fields/src/lock-unlock.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/fields'\n\t);\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gDAAgD,QAAQ,yBAAyB;AAC1F,OAAO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5BF,gDAAgD,CAC/C,+HAA+H,EAC/H,mBACD,CAAC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lock-unlock.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/fields'\n\t);\n"],
5
+ "mappings": "AAGA,SAAS,wDAAwD;AAC1D,MAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
6
+ "names": []
7
+ }