@wordpress/fields 0.5.1-next.cd6172eb0.0 → 0.7.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 (267) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +1 -1
  3. package/README.md +32 -36
  4. package/build/actions/delete-post.js +5 -0
  5. package/build/actions/delete-post.js.map +1 -1
  6. package/build/actions/duplicate-pattern.js +4 -0
  7. package/build/actions/duplicate-pattern.js.map +1 -1
  8. package/build/actions/duplicate-post.js +8 -3
  9. package/build/actions/duplicate-post.js.map +1 -1
  10. package/build/actions/duplicate-template-part.js +3 -0
  11. package/build/actions/duplicate-template-part.js.map +1 -1
  12. package/build/actions/export-pattern.js +5 -0
  13. package/build/actions/export-pattern.js.map +1 -1
  14. package/build/actions/index.js +0 -21
  15. package/build/actions/index.js.map +1 -1
  16. package/build/actions/permanently-delete-post.js +109 -65
  17. package/build/actions/permanently-delete-post.js.map +1 -1
  18. package/build/actions/rename-post.js +4 -0
  19. package/build/actions/rename-post.js.map +1 -1
  20. package/build/actions/reorder-page.js +4 -0
  21. package/build/actions/reorder-page.js.map +1 -1
  22. package/build/actions/reset-post.js +4 -0
  23. package/build/actions/reset-post.js.map +1 -1
  24. package/build/actions/restore-post.js +5 -0
  25. package/build/actions/restore-post.js.map +1 -1
  26. package/build/actions/trash-post.js +5 -0
  27. package/build/actions/trash-post.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 +48 -52
  33. package/build/components/create-template-part-modal/index.js.map +1 -1
  34. package/build/components/create-template-part-modal/utils.js +1 -0
  35. package/build/components/create-template-part-modal/utils.js.map +1 -1
  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 +21 -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 +49 -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/parent/parent-edit.js +1 -0
  49. package/build/fields/parent/parent-edit.js.map +1 -1
  50. package/build/fields/password/index.js +1 -1
  51. package/build/fields/password/index.js.map +1 -1
  52. package/build/fields/pattern-title/index.js +36 -0
  53. package/build/fields/pattern-title/index.js.map +1 -0
  54. package/build/fields/pattern-title/view.js +45 -0
  55. package/build/fields/pattern-title/view.js.map +1 -0
  56. package/build/fields/slug/index.js +4 -0
  57. package/build/fields/slug/index.js.map +1 -1
  58. package/build/fields/status/status-view.js +1 -0
  59. package/build/fields/status/status-view.js.map +1 -1
  60. package/build/fields/template/index.js +4 -3
  61. package/build/fields/template/index.js.map +1 -1
  62. package/build/fields/template/template-edit.js +1 -0
  63. package/build/fields/template/template-edit.js.map +1 -1
  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.native.js +0 -26
  71. package/build/index.native.js.map +1 -1
  72. package/build/mutation/index.js +1 -0
  73. package/build/mutation/index.js.map +1 -1
  74. package/build-module/actions/delete-post.js +5 -0
  75. package/build-module/actions/delete-post.js.map +1 -1
  76. package/build-module/actions/duplicate-pattern.js +4 -0
  77. package/build-module/actions/duplicate-pattern.js.map +1 -1
  78. package/build-module/actions/duplicate-post.js +8 -3
  79. package/build-module/actions/duplicate-post.js.map +1 -1
  80. package/build-module/actions/duplicate-template-part.js +3 -0
  81. package/build-module/actions/duplicate-template-part.js.map +1 -1
  82. package/build-module/actions/export-pattern.js +5 -0
  83. package/build-module/actions/export-pattern.js.map +1 -1
  84. package/build-module/actions/index.js +0 -3
  85. package/build-module/actions/index.js.map +1 -1
  86. package/build-module/actions/permanently-delete-post.js +110 -66
  87. package/build-module/actions/permanently-delete-post.js.map +1 -1
  88. package/build-module/actions/rename-post.js +4 -0
  89. package/build-module/actions/rename-post.js.map +1 -1
  90. package/build-module/actions/reorder-page.js +4 -0
  91. package/build-module/actions/reorder-page.js.map +1 -1
  92. package/build-module/actions/reset-post.js +4 -0
  93. package/build-module/actions/reset-post.js.map +1 -1
  94. package/build-module/actions/restore-post.js +5 -0
  95. package/build-module/actions/restore-post.js.map +1 -1
  96. package/build-module/actions/trash-post.js +5 -0
  97. package/build-module/actions/trash-post.js.map +1 -1
  98. package/build-module/actions/view-post-revisions.js +4 -0
  99. package/build-module/actions/view-post-revisions.js.map +1 -1
  100. package/build-module/actions/view-post.js +4 -0
  101. package/build-module/actions/view-post.js.map +1 -1
  102. package/build-module/components/create-template-part-modal/index.js +49 -53
  103. package/build-module/components/create-template-part-modal/index.js.map +1 -1
  104. package/build-module/components/create-template-part-modal/utils.js +1 -0
  105. package/build-module/components/create-template-part-modal/utils.js.map +1 -1
  106. package/build-module/fields/featured-image/index.js +4 -0
  107. package/build-module/fields/featured-image/index.js.map +1 -1
  108. package/build-module/fields/index.js +3 -0
  109. package/build-module/fields/index.js.map +1 -1
  110. package/build-module/fields/order/index.js +4 -0
  111. package/build-module/fields/order/index.js.map +1 -1
  112. package/build-module/fields/page-title/index.js +30 -0
  113. package/build-module/fields/page-title/index.js.map +1 -0
  114. package/build-module/fields/page-title/view.js +43 -0
  115. package/build-module/fields/page-title/view.js.map +1 -0
  116. package/build-module/fields/parent/index.js +1 -1
  117. package/build-module/fields/parent/index.js.map +1 -1
  118. package/build-module/fields/parent/parent-edit.js +1 -0
  119. package/build-module/fields/parent/parent-edit.js.map +1 -1
  120. package/build-module/fields/password/index.js +1 -1
  121. package/build-module/fields/password/index.js.map +1 -1
  122. package/build-module/fields/pattern-title/index.js +30 -0
  123. package/build-module/fields/pattern-title/index.js.map +1 -0
  124. package/build-module/fields/pattern-title/view.js +36 -0
  125. package/build-module/fields/pattern-title/view.js.map +1 -0
  126. package/build-module/fields/slug/index.js +4 -0
  127. package/build-module/fields/slug/index.js.map +1 -1
  128. package/build-module/fields/status/status-view.js +1 -0
  129. package/build-module/fields/status/status-view.js.map +1 -1
  130. package/build-module/fields/template/index.js +4 -3
  131. package/build-module/fields/template/index.js.map +1 -1
  132. package/build-module/fields/template/template-edit.js +1 -0
  133. package/build-module/fields/template/template-edit.js.map +1 -1
  134. package/build-module/fields/template-title/index.js +30 -0
  135. package/build-module/fields/template-title/index.js.map +1 -0
  136. package/build-module/fields/title/index.js +9 -2
  137. package/build-module/fields/title/index.js.map +1 -1
  138. package/build-module/fields/title/view.js +39 -0
  139. package/build-module/fields/title/view.js.map +1 -0
  140. package/build-module/index.native.js +1 -2
  141. package/build-module/index.native.js.map +1 -1
  142. package/build-module/mutation/index.js +1 -0
  143. package/build-module/mutation/index.js.map +1 -1
  144. package/build-style/style-rtl.css +62 -32
  145. package/build-style/style.css +62 -32
  146. package/build-types/actions/delete-post.d.ts +3 -0
  147. package/build-types/actions/delete-post.d.ts.map +1 -1
  148. package/build-types/actions/duplicate-pattern.d.ts +3 -0
  149. package/build-types/actions/duplicate-pattern.d.ts.map +1 -1
  150. package/build-types/actions/duplicate-post.d.ts +3 -0
  151. package/build-types/actions/duplicate-post.d.ts.map +1 -1
  152. package/build-types/actions/duplicate-template-part.d.ts +3 -0
  153. package/build-types/actions/duplicate-template-part.d.ts.map +1 -1
  154. package/build-types/actions/export-pattern.d.ts +3 -0
  155. package/build-types/actions/export-pattern.d.ts.map +1 -1
  156. package/build-types/actions/index.d.ts +0 -3
  157. package/build-types/actions/index.d.ts.map +1 -1
  158. package/build-types/actions/permanently-delete-post.d.ts +3 -0
  159. package/build-types/actions/permanently-delete-post.d.ts.map +1 -1
  160. package/build-types/actions/rename-post.d.ts +3 -0
  161. package/build-types/actions/rename-post.d.ts.map +1 -1
  162. package/build-types/actions/reorder-page.d.ts +3 -0
  163. package/build-types/actions/reorder-page.d.ts.map +1 -1
  164. package/build-types/actions/reset-post.d.ts +3 -0
  165. package/build-types/actions/reset-post.d.ts.map +1 -1
  166. package/build-types/actions/restore-post.d.ts +3 -0
  167. package/build-types/actions/restore-post.d.ts.map +1 -1
  168. package/build-types/actions/trash-post.d.ts +3 -0
  169. package/build-types/actions/trash-post.d.ts.map +1 -1
  170. package/build-types/actions/view-post-revisions.d.ts +3 -0
  171. package/build-types/actions/view-post-revisions.d.ts.map +1 -1
  172. package/build-types/actions/view-post.d.ts +3 -0
  173. package/build-types/actions/view-post.d.ts.map +1 -1
  174. package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
  175. package/build-types/fields/featured-image/index.d.ts +3 -0
  176. package/build-types/fields/featured-image/index.d.ts.map +1 -1
  177. package/build-types/fields/index.d.ts +3 -0
  178. package/build-types/fields/index.d.ts.map +1 -1
  179. package/build-types/fields/order/index.d.ts +3 -0
  180. package/build-types/fields/order/index.d.ts.map +1 -1
  181. package/build-types/fields/page-title/index.d.ts +14 -0
  182. package/build-types/fields/page-title/index.d.ts.map +1 -0
  183. package/build-types/fields/page-title/view.d.ts +8 -0
  184. package/build-types/fields/page-title/view.d.ts.map +1 -0
  185. package/build-types/fields/parent/index.d.ts +1 -1
  186. package/build-types/fields/password/index.d.ts +1 -1
  187. package/build-types/fields/pattern-title/index.d.ts +14 -0
  188. package/build-types/fields/pattern-title/index.d.ts.map +1 -0
  189. package/build-types/fields/pattern-title/view.d.ts +9 -0
  190. package/build-types/fields/pattern-title/view.d.ts.map +1 -0
  191. package/build-types/fields/slug/index.d.ts +3 -0
  192. package/build-types/fields/slug/index.d.ts.map +1 -1
  193. package/build-types/fields/template/index.d.ts +3 -0
  194. package/build-types/fields/template/index.d.ts.map +1 -1
  195. package/build-types/fields/template-title/index.d.ts +14 -0
  196. package/build-types/fields/template-title/index.d.ts.map +1 -0
  197. package/build-types/fields/title/index.d.ts +7 -2
  198. package/build-types/fields/title/index.d.ts.map +1 -1
  199. package/build-types/fields/title/view.d.ts +14 -0
  200. package/build-types/fields/title/view.d.ts.map +1 -0
  201. package/build-types/index.native.d.ts +0 -2
  202. package/build-types/index.native.d.ts.map +1 -1
  203. package/package.json +25 -25
  204. package/src/actions/delete-post.tsx +3 -0
  205. package/src/actions/duplicate-pattern.tsx +3 -0
  206. package/src/actions/duplicate-post.tsx +6 -3
  207. package/src/actions/duplicate-template-part.tsx +3 -1
  208. package/src/actions/export-pattern.tsx +3 -0
  209. package/src/actions/index.ts +0 -3
  210. package/src/actions/permanently-delete-post.tsx +160 -86
  211. package/src/actions/rename-post.tsx +3 -0
  212. package/src/actions/reorder-page.tsx +3 -0
  213. package/src/actions/reset-post.tsx +3 -0
  214. package/src/actions/restore-post.tsx +3 -0
  215. package/src/actions/trash-post.tsx +3 -0
  216. package/src/actions/view-post-revisions.tsx +3 -0
  217. package/src/actions/view-post.tsx +3 -0
  218. package/src/components/create-template-part-modal/index.tsx +81 -66
  219. package/src/components/create-template-part-modal/style.scss +79 -54
  220. package/src/fields/featured-image/index.ts +3 -0
  221. package/src/fields/index.ts +3 -0
  222. package/src/fields/order/index.ts +3 -0
  223. package/src/fields/page-title/index.ts +28 -0
  224. package/src/fields/page-title/view.tsx +41 -0
  225. package/src/fields/parent/index.ts +1 -1
  226. package/src/fields/password/index.tsx +1 -1
  227. package/src/fields/pattern-title/index.ts +28 -0
  228. package/src/fields/pattern-title/style.scss +3 -0
  229. package/src/fields/pattern-title/view.tsx +32 -0
  230. package/src/fields/slug/index.ts +3 -0
  231. package/src/fields/template/index.ts +3 -1
  232. package/src/fields/template-title/index.ts +28 -0
  233. package/src/fields/title/index.ts +9 -3
  234. package/src/fields/title/style.scss +8 -0
  235. package/src/fields/title/view.tsx +43 -0
  236. package/src/index.native.ts +0 -2
  237. package/src/style.scss +2 -0
  238. package/tsconfig.json +1 -4
  239. package/tsconfig.tsbuildinfo +1 -1
  240. package/build/actions/duplicate-post.native.js +0 -9
  241. package/build/actions/duplicate-post.native.js.map +0 -1
  242. package/build/actions/export-pattern.native.js +0 -9
  243. package/build/actions/export-pattern.native.js.map +0 -1
  244. package/build/actions/reorder-page.native.js +0 -9
  245. package/build/actions/reorder-page.native.js.map +0 -1
  246. package/build/fields/title/title-view.js +0 -61
  247. package/build/fields/title/title-view.js.map +0 -1
  248. package/build-module/actions/duplicate-post.native.js +0 -3
  249. package/build-module/actions/duplicate-post.native.js.map +0 -1
  250. package/build-module/actions/export-pattern.native.js +0 -3
  251. package/build-module/actions/export-pattern.native.js.map +0 -1
  252. package/build-module/actions/reorder-page.native.js +0 -3
  253. package/build-module/actions/reorder-page.native.js.map +0 -1
  254. package/build-module/fields/title/title-view.js +0 -55
  255. package/build-module/fields/title/title-view.js.map +0 -1
  256. package/build-types/actions/duplicate-post.native.d.ts +0 -3
  257. package/build-types/actions/duplicate-post.native.d.ts.map +0 -1
  258. package/build-types/actions/export-pattern.native.d.ts +0 -3
  259. package/build-types/actions/export-pattern.native.d.ts.map +0 -1
  260. package/build-types/actions/reorder-page.native.d.ts +0 -3
  261. package/build-types/actions/reorder-page.native.d.ts.map +0 -1
  262. package/build-types/fields/title/title-view.d.ts +0 -9
  263. package/build-types/fields/title/title-view.d.ts.map +0 -1
  264. package/src/actions/duplicate-post.native.tsx +0 -3
  265. package/src/actions/export-pattern.native.tsx +0 -3
  266. package/src/actions/reorder-page.native.tsx +0 -3
  267. package/src/fields/title/title-view.tsx +0 -61
@@ -122,4 +122,7 @@ const reorderPage: Action< BasePost > = {
122
122
  RenderModal: ReorderModal,
123
123
  };
124
124
 
125
+ /**
126
+ * Reorder action for BasePost.
127
+ */
125
128
  export default reorderPage;
@@ -292,4 +292,7 @@ const resetPostAction: Action< Template | TemplatePart > = {
292
292
  },
293
293
  };
294
294
 
295
+ /**
296
+ * Reset action for Template and TemplatePart.
297
+ */
295
298
  export default resetPostAction;
@@ -131,4 +131,7 @@ const restorePost: Action< PostWithPermissions > = {
131
131
  },
132
132
  };
133
133
 
134
+ /**
135
+ * Restore action for PostWithPermissions.
136
+ */
134
137
  export default restorePost;
@@ -195,4 +195,7 @@ const trashPost: Action< PostWithPermissions > = {
195
195
  },
196
196
  };
197
197
 
198
+ /**
199
+ * Trash action for PostWithPermissions.
200
+ */
198
201
  export default trashPost;
@@ -44,4 +44,7 @@ const viewPostRevisions: Action< Post > = {
44
44
  },
45
45
  };
46
46
 
47
+ /**
48
+ * View post revisions action for Post.
49
+ */
47
50
  export default viewPostRevisions;
@@ -27,4 +27,7 @@ const viewPost: Action< BasePost > = {
27
27
  },
28
28
  };
29
29
 
30
+ /**
31
+ * View post action for BasePost.
32
+ */
30
33
  export default viewPost;
@@ -5,13 +5,8 @@ import {
5
5
  Icon,
6
6
  BaseControl,
7
7
  TextControl,
8
- Flex,
9
- FlexItem,
10
- FlexBlock,
11
8
  Button,
12
9
  Modal,
13
- __experimentalRadioGroup as RadioGroup,
14
- __experimentalRadio as Radio,
15
10
  __experimentalHStack as HStack,
16
11
  __experimentalVStack as VStack,
17
12
  } from '@wordpress/components';
@@ -28,7 +23,7 @@ import {
28
23
  symbolFilled as symbolFilledIcon,
29
24
  } from '@wordpress/icons';
30
25
  import { store as noticesStore } from '@wordpress/notices';
31
- // @ts-ignore
26
+ // @ts-expect-error serialize is not typed
32
27
  import { serialize } from '@wordpress/blocks';
33
28
 
34
29
  /**
@@ -40,6 +35,13 @@ import {
40
35
  useExistingTemplateParts,
41
36
  } from './utils';
42
37
 
38
+ function getAreaRadioId( value: string, instanceId: number ) {
39
+ return `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`;
40
+ }
41
+ function getAreaRadioDescriptionId( value: string, instanceId: number ) {
42
+ return `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`;
43
+ }
44
+
43
45
  type CreateTemplatePartModalContentsProps = {
44
46
  defaultArea?: string;
45
47
  blocks: any[];
@@ -50,6 +52,13 @@ type CreateTemplatePartModalContentsProps = {
50
52
  defaultTitle?: string;
51
53
  };
52
54
 
55
+ type TemplatePartArea = {
56
+ area: string;
57
+ label: string;
58
+ icon: string;
59
+ description: string;
60
+ };
61
+
53
62
  /**
54
63
  * 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.
55
64
  * This component should not live in this package, it should be moved to a dedicated package responsible for managing template.
@@ -64,7 +73,7 @@ export default function CreateTemplatePartModal( {
64
73
  } & CreateTemplatePartModalContentsProps ) {
65
74
  const defaultModalTitle = useSelect(
66
75
  ( select ) =>
67
- // @ts-ignore
76
+ // @ts-expect-error getPostType is not typed with 'wp_template_part' as argument.
68
77
  select( coreStore ).getPostType( 'wp_template_part' )?.labels
69
78
  ?.add_new_item,
70
79
  []
@@ -77,7 +86,6 @@ export default function CreateTemplatePartModal( {
77
86
  focusOnMount="firstContentElement"
78
87
  size="medium"
79
88
  >
80
- { /* @ts-ignore */ }
81
89
  <CreateTemplatePartModalContents { ...restProps } />
82
90
  </Modal>
83
91
  );
@@ -125,22 +133,14 @@ export function CreateTemplatePartModalContents( {
125
133
  const [ isSubmitting, setIsSubmitting ] = useState( false );
126
134
  const instanceId = useInstanceId( CreateTemplatePartModal );
127
135
 
128
- const defaultTemplatePartAreas = useSelect( ( select ) => {
129
- const areas =
136
+ const defaultTemplatePartAreas = useSelect(
137
+ ( select ) =>
130
138
  // @ts-expect-error getEntityRecord is not typed with unstableBase as argument.
131
139
  select( coreStore ).getEntityRecord< {
132
- default_template_part_areas: Array< {
133
- area: string;
134
- label: string;
135
- icon: string;
136
- description: string;
137
- } >;
138
- } >( 'root', '__unstableBase' )?.default_template_part_areas || [];
139
-
140
- return areas.map( ( item ) => {
141
- return { ...item, icon: getTemplatePartIcon( item.icon ) };
142
- } );
143
- }, [] );
140
+ default_template_part_areas: Array< TemplatePartArea >;
141
+ } >( 'root', '__unstableBase' )?.default_template_part_areas,
142
+ []
143
+ );
144
144
 
145
145
  async function createTemplatePart() {
146
146
  if ( ! title || isSubmitting ) {
@@ -203,51 +203,66 @@ export function CreateTemplatePartModalContents( {
203
203
  onChange={ setTitle }
204
204
  required
205
205
  />
206
- <BaseControl
207
- __nextHasNoMarginBottom
208
- label={ __( 'Area' ) }
209
- id={ `fields-create-template-part-modal__area-selection-${ instanceId }` }
210
- className="fields-create-template-part-modal__area-base-control"
211
- >
212
- <RadioGroup
213
- label={ __( 'Area' ) }
214
- className="fields-create-template-part-modal__area-radio-group"
215
- id={ `fields-create-template-part-modal__area-selection-${ instanceId }` }
216
- onChange={ ( value ) =>
217
- value && typeof value === 'string'
218
- ? setArea( value )
219
- : () => void 0
220
- }
221
- checked={ area }
222
- >
223
- { defaultTemplatePartAreas.map(
224
- ( { icon, label, area: value, description } ) => (
225
- <Radio
226
- __next40pxDefaultSize
227
- key={ label }
228
- value={ value }
229
- className="fields-create-template-part-modal__area-radio"
206
+ <fieldset>
207
+ <BaseControl.VisualLabel as="legend">
208
+ { __( 'Area' ) }
209
+ </BaseControl.VisualLabel>
210
+ <div className="fields-create-template-part-modal__area-radio-group">
211
+ { ( defaultTemplatePartAreas ?? [] ).map( ( item ) => {
212
+ const icon = getTemplatePartIcon( item.icon );
213
+ return (
214
+ <div
215
+ key={ item.area }
216
+ className="fields-create-template-part-modal__area-radio-wrapper"
230
217
  >
231
- <Flex align="start" justify="start">
232
- <FlexItem>
233
- <Icon icon={ icon } />
234
- </FlexItem>
235
- <FlexBlock className="fields-create-template-part-modal__option-label">
236
- { label }
237
- <div>{ description }</div>
238
- </FlexBlock>
239
-
240
- <FlexItem className="fields-create-template-part-modal__checkbox">
241
- { area === value && (
242
- <Icon icon={ check } />
243
- ) }
244
- </FlexItem>
245
- </Flex>
246
- </Radio>
247
- )
248
- ) }
249
- </RadioGroup>
250
- </BaseControl>
218
+ <input
219
+ type="radio"
220
+ id={ getAreaRadioId(
221
+ item.area,
222
+ instanceId
223
+ ) }
224
+ name={ `fields-create-template-part-modal__area-${ instanceId }` }
225
+ value={ item.area }
226
+ checked={ area === item.area }
227
+ onChange={ () => {
228
+ setArea( item.area );
229
+ } }
230
+ aria-describedby={ getAreaRadioDescriptionId(
231
+ item.area,
232
+ instanceId
233
+ ) }
234
+ />
235
+ <Icon
236
+ icon={ icon }
237
+ className="fields-create-template-part-modal__area-radio-icon"
238
+ />
239
+ <label
240
+ htmlFor={ getAreaRadioId(
241
+ item.area,
242
+ instanceId
243
+ ) }
244
+ className="fields-create-template-part-modal__area-radio-label"
245
+ >
246
+ { item.label }
247
+ </label>
248
+ <Icon
249
+ icon={ check }
250
+ className="fields-create-template-part-modal__area-radio-checkmark"
251
+ />
252
+ <p
253
+ className="fields-create-template-part-modal__area-radio-description"
254
+ id={ getAreaRadioDescriptionId(
255
+ item.area,
256
+ instanceId
257
+ ) }
258
+ >
259
+ { item.description }
260
+ </p>
261
+ </div>
262
+ );
263
+ } ) }
264
+ </div>
265
+ </fieldset>
251
266
  <HStack justify="right">
252
267
  <Button
253
268
  __next40pxDefaultSize
@@ -3,61 +3,86 @@
3
3
  }
4
4
 
5
5
  .fields-create-template-part-modal__area-radio-group {
6
- width: 100%;
7
- border: $border-width solid $gray-700;
6
+ border: $border-width solid $gray-600;
8
7
  border-radius: $radius-small;
8
+ }
9
+
10
+ .fields-create-template-part-modal__area-radio-wrapper {
11
+ position: relative;
12
+ padding: $grid-unit-15;
13
+
14
+ display: grid;
15
+ align-items: center;
16
+ grid-template-columns: min-content 1fr min-content;
17
+ grid-gap: $grid-unit-05 $grid-unit-10;
18
+
19
+ color: $gray-900;
20
+
21
+ & + & {
22
+ border-top: $border-width solid $gray-600;
23
+ }
24
+
25
+ input[type="radio"] {
26
+ position: absolute;
27
+ opacity: 0;
28
+ }
29
+
30
+ &:has(input[type="radio"]:checked) {
31
+ // This is needed to make sure that the focus ring always renders on top
32
+ // of the sibling radio "wrapper"'s borders.
33
+ z-index: 1;
34
+ }
35
+
36
+ &:has(input[type="radio"]:not(:checked)):hover {
37
+ color: var(--wp-admin-theme-color);
38
+ }
39
+
40
+ // Pass-through pointer events, so that the corresponding radio input
41
+ // gets checked when clicking on the underlying label
42
+ > *:not(.fields-create-template-part-modal__area-radio-label) {
43
+ pointer-events: none;
44
+ }
45
+ }
46
+
47
+ .fields-create-template-part-modal__area-radio-label {
48
+ // Capture pointer clicks for the whole radio wrapper
49
+ &::before {
50
+ content: "";
51
+ position: absolute;
52
+ inset: 0;
53
+ }
54
+
55
+ input[type="radio"]:not(:checked) ~ &::before {
56
+ cursor: pointer;
57
+ }
58
+
59
+ input[type="radio"]:focus-visible ~ &::before {
60
+ outline: 4px solid transparent;
61
+ box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
62
+ }
63
+ }
64
+
65
+ .fields-create-template-part-modal__area-radio-icon,
66
+ .fields-create-template-part-modal__area-radio-checkmark {
67
+ fill: currentColor;
68
+ }
69
+
70
+ .fields-create-template-part-modal__area-radio-checkmark {
71
+ input[type="radio"]:not(:checked) ~ & {
72
+ opacity: 0;
73
+ }
74
+ }
75
+
76
+ .fields-create-template-part-modal__area-radio-description {
77
+ grid-column: 2 / 3;
78
+ margin: 0;
79
+
80
+ color: $gray-700;
81
+ font-size: $helptext-font-size;
82
+ line-height: normal;
83
+ text-wrap: pretty;
9
84
 
10
- .components-button.fields-create-template-part-modal__area-radio {
11
- display: block;
12
- width: 100%;
13
- height: 100%;
14
- text-align: left;
15
- padding: $grid-unit-15;
16
-
17
- &,
18
- &.is-secondary:hover,
19
- &.is-primary:hover {
20
- margin: 0;
21
- background-color: inherit;
22
- border-bottom: $border-width solid $gray-700;
23
- border-radius: 0;
24
-
25
- &:not(:focus) {
26
- box-shadow: none;
27
- }
28
-
29
- &:focus {
30
- border-bottom: $border-width solid $white;
31
- }
32
-
33
- &:last-of-type {
34
- border-bottom: none;
35
- }
36
- }
37
-
38
- &:not(:hover),
39
- &[aria-checked="true"] {
40
- color: $gray-900;
41
- cursor: auto;
42
-
43
- .fields-create-template-part-modal__option-label div {
44
- color: $gray-600;
45
- }
46
- }
47
-
48
- .fields-create-template-part-modal__option-label {
49
- padding-top: $grid-unit-05;
50
- white-space: normal;
51
-
52
- div {
53
- padding-top: $grid-unit-05;
54
- font-size: $helptext-font-size;
55
- }
56
- }
57
-
58
- .fields-create-template-part-modal__checkbox {
59
- margin-left: auto;
60
- min-width: $grid-unit-30;
61
- }
85
+ input[type="radio"]:not(:checked):hover ~ & {
86
+ color: inherit;
62
87
  }
63
88
  }
@@ -20,4 +20,7 @@ const featuredImageField: Field< BasePost > = {
20
20
  enableSorting: false,
21
21
  };
22
22
 
23
+ /**
24
+ * Featured Image field for BasePost.
25
+ */
23
26
  export default featuredImageField;
@@ -1,5 +1,8 @@
1
1
  export { default as slugField } from './slug';
2
2
  export { default as titleField } from './title';
3
+ export { default as pageTitleField } from './page-title';
4
+ export { default as templateTitleField } from './template-title';
5
+ export { default as patternTitleField } from './pattern-title';
3
6
  export { default as orderField } from './order';
4
7
  export { default as featuredImageField } from './featured-image';
5
8
  export { default as templateField } from './template';
@@ -16,4 +16,7 @@ const orderField: Field< BasePost > = {
16
16
  description: __( 'Determines the order of pages.' ),
17
17
  };
18
18
 
19
+ /**
20
+ * Order field for BasePost.
21
+ */
19
22
  export default orderField;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePost } from '../../types';
11
+ import { getItemTitle } from '../../actions/utils';
12
+ import PageTitleView from './view';
13
+
14
+ const pageTitleField: Field< BasePost > = {
15
+ type: 'text',
16
+ id: 'title',
17
+ label: __( 'Title' ),
18
+ placeholder: __( 'No title' ),
19
+ getValue: ( { item } ) => getItemTitle( item ),
20
+ render: PageTitleView,
21
+ enableHiding: false,
22
+ enableGlobalSearch: true,
23
+ };
24
+
25
+ /**
26
+ * Title for the page entity.
27
+ */
28
+ export default pageTitleField;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { store as coreStore } from '@wordpress/core-data';
7
+ import type { Settings } from '@wordpress/core-data';
8
+ import { privateApis as componentsPrivateApis } from '@wordpress/components';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import type { CommonPost } from '../../types';
14
+ import { BaseTitleView } from '../title/view';
15
+ import { unlock } from '../../lock-unlock';
16
+ const { Badge } = unlock( componentsPrivateApis );
17
+
18
+ export default function PageTitleView( { item }: { item: CommonPost } ) {
19
+ const { frontPageId, postsPageId } = useSelect( ( select ) => {
20
+ const { getEntityRecord } = select( coreStore );
21
+ const siteSettings = getEntityRecord(
22
+ 'root',
23
+ 'site'
24
+ ) as Partial< Settings >;
25
+ return {
26
+ frontPageId: siteSettings?.page_on_front,
27
+ postsPageId: siteSettings?.page_for_posts,
28
+ };
29
+ }, [] );
30
+ return (
31
+ <BaseTitleView item={ item } className="fields-field__page-title">
32
+ { [ frontPageId, postsPageId ].includes( item.id as number ) && (
33
+ <Badge>
34
+ { item.id === frontPageId
35
+ ? __( 'Homepage' )
36
+ : __( 'Posts Page' ) }
37
+ </Badge>
38
+ ) }
39
+ </BaseTitleView>
40
+ );
41
+ }
@@ -21,6 +21,6 @@ const parentField: Field< BasePost > = {
21
21
  };
22
22
 
23
23
  /**
24
- * This field is used to display the post parent.
24
+ * Parent field for BasePost.
25
25
  */
26
26
  export default parentField;
@@ -19,6 +19,6 @@ const passwordField: Field< BasePost > = {
19
19
  };
20
20
 
21
21
  /**
22
- * This field is used to display the post password.
22
+ * Password field for BasePost.
23
23
  */
24
24
  export default passwordField;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { Pattern } from '../../types';
11
+ import { getItemTitle } from '../../actions/utils';
12
+ import PatternTitleView from './view';
13
+
14
+ const patternTitleField: Field< Pattern > = {
15
+ type: 'text',
16
+ id: 'title',
17
+ label: __( 'Title' ),
18
+ placeholder: __( 'No title' ),
19
+ getValue: ( { item } ) => getItemTitle( item ),
20
+ render: PatternTitleView,
21
+ enableHiding: false,
22
+ enableGlobalSearch: true,
23
+ };
24
+
25
+ /**
26
+ * Title for the pattern entity.
27
+ */
28
+ export default patternTitleField;
@@ -0,0 +1,3 @@
1
+ .fields-field__pattern-title span:first-child {
2
+ flex: 1;
3
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { Icon, lockSmall } from '@wordpress/icons';
6
+ import { Tooltip } from '@wordpress/components';
7
+ // @ts-ignore
8
+ import { privateApis as patternPrivateApis } from '@wordpress/patterns';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import type { CommonPost } from '../../types';
14
+ import { BaseTitleView } from '../title/view';
15
+ import { unlock } from '../../lock-unlock';
16
+
17
+ export const { PATTERN_TYPES } = unlock( patternPrivateApis );
18
+
19
+ export default function PatternTitleView( { item }: { item: CommonPost } ) {
20
+ return (
21
+ <BaseTitleView item={ item } className="fields-field__pattern-title">
22
+ { item.type === PATTERN_TYPES.theme && (
23
+ <Tooltip
24
+ placement="top"
25
+ text={ __( 'This pattern cannot be edited.' ) }
26
+ >
27
+ <Icon icon={ lockSmall } size={ 24 } />
28
+ </Tooltip>
29
+ ) }
30
+ </BaseTitleView>
31
+ );
32
+ }
@@ -19,4 +19,7 @@ const slugField: Field< BasePost > = {
19
19
  render: SlugView,
20
20
  };
21
21
 
22
+ /**
23
+ * Slug field for BasePost.
24
+ */
22
25
  export default slugField;
@@ -14,9 +14,11 @@ const templateField: Field< BasePost > = {
14
14
  id: 'template',
15
15
  type: 'text',
16
16
  label: __( 'Template' ),
17
- getValue: ( { item } ) => item.template,
18
17
  Edit: TemplateEdit,
19
18
  enableSorting: false,
20
19
  };
21
20
 
21
+ /**
22
+ * Template field for BasePost.
23
+ */
22
24
  export default templateField;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { Template } from '../../types';
11
+ import { getItemTitle } from '../../actions/utils';
12
+ import TitleView from '../title/view';
13
+
14
+ const templateTitleField: Field< Template > = {
15
+ type: 'text',
16
+ label: __( 'Template' ),
17
+ placeholder: __( 'No title' ),
18
+ id: 'title',
19
+ getValue: ( { item } ) => getItemTitle( item ),
20
+ render: TitleView,
21
+ enableHiding: false,
22
+ enableGlobalSearch: true,
23
+ };
24
+
25
+ /**
26
+ * Title for the template entity.
27
+ */
28
+ export default templateTitleField;
@@ -7,11 +7,11 @@ import { __ } from '@wordpress/i18n';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import type { BasePost } from '../../types';
10
+ import type { CommonPost } from '../../types';
11
11
  import { getItemTitle } from '../../actions/utils';
12
- import TitleView from './title-view';
12
+ import TitleView from './view';
13
13
 
14
- const titleField: Field< BasePost > = {
14
+ const titleField: Field< CommonPost > = {
15
15
  type: 'text',
16
16
  id: 'title',
17
17
  label: __( 'Title' ),
@@ -19,6 +19,12 @@ const titleField: Field< BasePost > = {
19
19
  getValue: ( { item } ) => getItemTitle( item ),
20
20
  render: TitleView,
21
21
  enableHiding: false,
22
+ enableGlobalSearch: true,
22
23
  };
23
24
 
25
+ /**
26
+ * Title for the any entity with a `title` property.
27
+ * For patterns, pages or templates you should use the respective field
28
+ * because there are some differences in the rendering, labels, etc.
29
+ */
24
30
  export default titleField;
@@ -0,0 +1,8 @@
1
+ .fields-field__title span:first-child {
2
+ text-overflow: ellipsis;
3
+ overflow: hidden;
4
+ text-decoration: none;
5
+ white-space: nowrap;
6
+ display: block;
7
+ flex-grow: 0;
8
+ }