@wordpress/dataviews 11.3.1-next.v.0 → 12.0.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 (444) hide show
  1. package/CHANGELOG.md +46 -1
  2. package/README.md +44 -2
  3. package/build/components/dataform-controls/adaptive-select.cjs +52 -0
  4. package/build/components/dataform-controls/adaptive-select.cjs.map +7 -0
  5. package/build/components/dataform-controls/array.cjs +2 -0
  6. package/build/components/dataform-controls/array.cjs.map +2 -2
  7. package/build/components/dataform-controls/checkbox.cjs +2 -0
  8. package/build/components/dataform-controls/checkbox.cjs.map +2 -2
  9. package/build/components/dataform-controls/color.cjs +21 -30
  10. package/build/components/dataform-controls/color.cjs.map +3 -3
  11. package/build/components/dataform-controls/combobox.cjs +80 -0
  12. package/build/components/dataform-controls/combobox.cjs.map +7 -0
  13. package/build/components/dataform-controls/date.cjs +58 -19
  14. package/build/components/dataform-controls/date.cjs.map +2 -2
  15. package/build/components/dataform-controls/datetime.cjs +11 -3
  16. package/build/components/dataform-controls/datetime.cjs.map +2 -2
  17. package/build/components/dataform-controls/email.cjs +2 -0
  18. package/build/components/dataform-controls/email.cjs.map +2 -2
  19. package/build/components/dataform-controls/index.cjs +5 -1
  20. package/build/components/dataform-controls/index.cjs.map +3 -3
  21. package/build/components/dataform-controls/password.cjs +2 -0
  22. package/build/components/dataform-controls/password.cjs.map +2 -2
  23. package/build/components/dataform-controls/radio.cjs +2 -0
  24. package/build/components/dataform-controls/radio.cjs.map +2 -2
  25. package/build/components/dataform-controls/select.cjs +2 -0
  26. package/build/components/dataform-controls/select.cjs.map +2 -2
  27. package/build/components/dataform-controls/telephone.cjs +2 -0
  28. package/build/components/dataform-controls/telephone.cjs.map +2 -2
  29. package/build/components/dataform-controls/text.cjs +2 -0
  30. package/build/components/dataform-controls/text.cjs.map +2 -2
  31. package/build/components/dataform-controls/textarea.cjs +2 -0
  32. package/build/components/dataform-controls/textarea.cjs.map +2 -2
  33. package/build/components/dataform-controls/toggle-group.cjs +2 -0
  34. package/build/components/dataform-controls/toggle-group.cjs.map +2 -2
  35. package/build/components/dataform-controls/toggle.cjs +2 -0
  36. package/build/components/dataform-controls/toggle.cjs.map +2 -2
  37. package/build/components/dataform-controls/url.cjs +2 -0
  38. package/build/components/dataform-controls/url.cjs.map +2 -2
  39. package/build/components/dataform-controls/utils/relative-date-control.cjs +1 -1
  40. package/build/components/dataform-controls/utils/relative-date-control.cjs.map +1 -1
  41. package/build/components/dataform-controls/utils/validated-input.cjs +2 -0
  42. package/build/components/dataform-controls/utils/validated-input.cjs.map +2 -2
  43. package/build/components/dataform-controls/utils/validated-number.cjs +2 -0
  44. package/build/components/dataform-controls/utils/validated-number.cjs.map +2 -2
  45. package/build/components/dataform-layouts/card/index.cjs +28 -3
  46. package/build/components/dataform-layouts/card/index.cjs.map +3 -3
  47. package/build/components/dataform-layouts/data-form-layout.cjs +11 -2
  48. package/build/components/dataform-layouts/data-form-layout.cjs.map +2 -2
  49. package/build/components/dataform-layouts/details/index.cjs +69 -12
  50. package/build/components/dataform-layouts/details/index.cjs.map +3 -3
  51. package/build/components/dataform-layouts/index.cjs +5 -5
  52. package/build/components/dataform-layouts/index.cjs.map +1 -1
  53. package/build/components/dataform-layouts/normalize-form.cjs +2 -1
  54. package/build/components/dataform-layouts/normalize-form.cjs.map +2 -2
  55. package/build/components/dataform-layouts/panel/dropdown.cjs +88 -63
  56. package/build/components/dataform-layouts/panel/dropdown.cjs.map +3 -3
  57. package/build/components/dataform-layouts/panel/index.cjs +13 -175
  58. package/build/components/dataform-layouts/panel/index.cjs.map +3 -3
  59. package/build/components/dataform-layouts/panel/modal.cjs +28 -18
  60. package/build/components/dataform-layouts/panel/modal.cjs.map +3 -3
  61. package/build/components/dataform-layouts/panel/summary-button.cjs +125 -56
  62. package/build/components/dataform-layouts/panel/summary-button.cjs.map +3 -3
  63. package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs +59 -0
  64. package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs.map +7 -0
  65. package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs +45 -0
  66. package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs.map +7 -0
  67. package/build/components/dataform-layouts/panel/utils/get-label-content.cjs +36 -0
  68. package/build/components/dataform-layouts/panel/utils/get-label-content.cjs.map +7 -0
  69. package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs +77 -0
  70. package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs.map +7 -0
  71. package/build/components/dataform-layouts/regular/index.cjs +6 -3
  72. package/build/components/dataform-layouts/regular/index.cjs.map +2 -2
  73. package/build/components/dataform-layouts/row/index.cjs +5 -2
  74. package/build/components/dataform-layouts/row/index.cjs.map +2 -2
  75. package/build/components/dataform-layouts/validation-badge.cjs +67 -0
  76. package/build/components/dataform-layouts/validation-badge.cjs.map +7 -0
  77. package/build/components/dataviews-bulk-actions/index.cjs +4 -4
  78. package/build/components/dataviews-bulk-actions/index.cjs.map +2 -2
  79. package/build/components/dataviews-context/index.cjs.map +2 -2
  80. package/build/components/dataviews-filters/filter.cjs +1 -1
  81. package/build/components/dataviews-filters/filter.cjs.map +1 -1
  82. package/build/components/dataviews-filters/filters.cjs +1 -1
  83. package/build/components/dataviews-filters/filters.cjs.map +1 -1
  84. package/build/components/dataviews-filters/search-widget.cjs +25 -11
  85. package/build/components/dataviews-filters/search-widget.cjs.map +2 -2
  86. package/build/components/dataviews-filters/toggle.cjs.map +1 -1
  87. package/build/components/dataviews-footer/index.cjs +1 -1
  88. package/build/components/dataviews-footer/index.cjs.map +1 -1
  89. package/build/components/dataviews-layouts/activity/activity-item.cjs +4 -4
  90. package/build/components/dataviews-layouts/activity/activity-item.cjs.map +1 -1
  91. package/build/components/dataviews-layouts/activity/index.cjs +1 -1
  92. package/build/components/dataviews-layouts/activity/index.cjs.map +1 -1
  93. package/build/components/dataviews-layouts/grid/composite-grid.cjs +27 -38
  94. package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
  95. package/build/components/dataviews-layouts/grid/index.cjs +2 -2
  96. package/build/components/dataviews-layouts/grid/index.cjs.map +1 -1
  97. package/build/components/dataviews-layouts/list/index.cjs +7 -8
  98. package/build/components/dataviews-layouts/list/index.cjs.map +2 -2
  99. package/build/components/dataviews-layouts/picker-grid/index.cjs +5 -5
  100. package/build/components/dataviews-layouts/picker-grid/index.cjs.map +2 -2
  101. package/build/components/dataviews-layouts/picker-table/index.cjs +1 -1
  102. package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
  103. package/build/components/dataviews-layouts/table/column-primary.cjs +1 -1
  104. package/build/components/dataviews-layouts/table/column-primary.cjs.map +1 -1
  105. package/build/components/dataviews-layouts/table/index.cjs +1 -1
  106. package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
  107. package/build/components/dataviews-layouts/utils/item-click-wrapper.cjs.map +2 -2
  108. package/build/components/dataviews-pagination/index.cjs +3 -3
  109. package/build/components/dataviews-pagination/index.cjs.map +2 -2
  110. package/build/components/dataviews-picker-footer/index.cjs +3 -3
  111. package/build/components/dataviews-picker-footer/index.cjs.map +2 -2
  112. package/build/components/dataviews-view-config/index.cjs +74 -57
  113. package/build/components/dataviews-view-config/index.cjs.map +3 -3
  114. package/build/components/dataviews-view-config/properties-section.cjs +1 -1
  115. package/build/components/dataviews-view-config/properties-section.cjs.map +1 -1
  116. package/build/dataviews/index.cjs +7 -5
  117. package/build/dataviews/index.cjs.map +2 -2
  118. package/build/dataviews-picker/index.cjs +3 -3
  119. package/build/dataviews-picker/index.cjs.map +2 -2
  120. package/build/hooks/use-form-validity.cjs +61 -28
  121. package/build/hooks/use-form-validity.cjs.map +2 -2
  122. package/build/hooks/use-report-validity.cjs +39 -0
  123. package/build/hooks/use-report-validity.cjs.map +7 -0
  124. package/build/types/dataform.cjs.map +1 -1
  125. package/build/types/field-api.cjs.map +1 -1
  126. package/build-module/components/dataform-controls/adaptive-select.mjs +21 -0
  127. package/build-module/components/dataform-controls/adaptive-select.mjs.map +7 -0
  128. package/build-module/components/dataform-controls/array.mjs +2 -0
  129. package/build-module/components/dataform-controls/array.mjs.map +2 -2
  130. package/build-module/components/dataform-controls/checkbox.mjs +2 -0
  131. package/build-module/components/dataform-controls/checkbox.mjs.map +2 -2
  132. package/build-module/components/dataform-controls/color.mjs +26 -31
  133. package/build-module/components/dataform-controls/color.mjs.map +2 -2
  134. package/build-module/components/dataform-controls/combobox.mjs +49 -0
  135. package/build-module/components/dataform-controls/combobox.mjs.map +7 -0
  136. package/build-module/components/dataform-controls/date.mjs +58 -19
  137. package/build-module/components/dataform-controls/date.mjs.map +2 -2
  138. package/build-module/components/dataform-controls/datetime.mjs +11 -3
  139. package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
  140. package/build-module/components/dataform-controls/email.mjs +2 -0
  141. package/build-module/components/dataform-controls/email.mjs.map +2 -2
  142. package/build-module/components/dataform-controls/index.mjs +5 -1
  143. package/build-module/components/dataform-controls/index.mjs.map +2 -2
  144. package/build-module/components/dataform-controls/password.mjs +2 -0
  145. package/build-module/components/dataform-controls/password.mjs.map +2 -2
  146. package/build-module/components/dataform-controls/radio.mjs +2 -0
  147. package/build-module/components/dataform-controls/radio.mjs.map +2 -2
  148. package/build-module/components/dataform-controls/select.mjs +2 -0
  149. package/build-module/components/dataform-controls/select.mjs.map +2 -2
  150. package/build-module/components/dataform-controls/telephone.mjs +2 -0
  151. package/build-module/components/dataform-controls/telephone.mjs.map +2 -2
  152. package/build-module/components/dataform-controls/text.mjs +2 -0
  153. package/build-module/components/dataform-controls/text.mjs.map +2 -2
  154. package/build-module/components/dataform-controls/textarea.mjs +2 -0
  155. package/build-module/components/dataform-controls/textarea.mjs.map +2 -2
  156. package/build-module/components/dataform-controls/toggle-group.mjs +2 -0
  157. package/build-module/components/dataform-controls/toggle-group.mjs.map +2 -2
  158. package/build-module/components/dataform-controls/toggle.mjs +2 -0
  159. package/build-module/components/dataform-controls/toggle.mjs.map +2 -2
  160. package/build-module/components/dataform-controls/url.mjs +2 -0
  161. package/build-module/components/dataform-controls/url.mjs.map +2 -2
  162. package/build-module/components/dataform-controls/utils/relative-date-control.mjs +1 -1
  163. package/build-module/components/dataform-controls/utils/relative-date-control.mjs.map +1 -1
  164. package/build-module/components/dataform-controls/utils/validated-input.mjs +2 -0
  165. package/build-module/components/dataform-controls/utils/validated-input.mjs.map +2 -2
  166. package/build-module/components/dataform-controls/utils/validated-number.mjs +2 -0
  167. package/build-module/components/dataform-controls/utils/validated-number.mjs.map +2 -2
  168. package/build-module/components/dataform-layouts/card/index.mjs +29 -3
  169. package/build-module/components/dataform-layouts/card/index.mjs.map +2 -2
  170. package/build-module/components/dataform-layouts/data-form-layout.mjs +12 -3
  171. package/build-module/components/dataform-layouts/data-form-layout.mjs.map +2 -2
  172. package/build-module/components/dataform-layouts/details/index.mjs +77 -13
  173. package/build-module/components/dataform-layouts/details/index.mjs.map +2 -2
  174. package/build-module/components/dataform-layouts/index.mjs +5 -5
  175. package/build-module/components/dataform-layouts/index.mjs.map +1 -1
  176. package/build-module/components/dataform-layouts/normalize-form.mjs +2 -1
  177. package/build-module/components/dataform-layouts/normalize-form.mjs.map +2 -2
  178. package/build-module/components/dataform-layouts/panel/dropdown.mjs +91 -66
  179. package/build-module/components/dataform-layouts/panel/dropdown.mjs.map +2 -2
  180. package/build-module/components/dataform-layouts/panel/index.mjs +14 -176
  181. package/build-module/components/dataform-layouts/panel/index.mjs.map +2 -2
  182. package/build-module/components/dataform-layouts/panel/modal.mjs +30 -20
  183. package/build-module/components/dataform-layouts/panel/modal.mjs.map +2 -2
  184. package/build-module/components/dataform-layouts/panel/summary-button.mjs +117 -58
  185. package/build-module/components/dataform-layouts/panel/summary-button.mjs.map +2 -2
  186. package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs +38 -0
  187. package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs.map +7 -0
  188. package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs +14 -0
  189. package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs.map +7 -0
  190. package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs +15 -0
  191. package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs.map +7 -0
  192. package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs +46 -0
  193. package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs.map +7 -0
  194. package/build-module/components/dataform-layouts/regular/index.mjs +6 -3
  195. package/build-module/components/dataform-layouts/regular/index.mjs.map +2 -2
  196. package/build-module/components/dataform-layouts/row/index.mjs +5 -2
  197. package/build-module/components/dataform-layouts/row/index.mjs.map +2 -2
  198. package/build-module/components/dataform-layouts/validation-badge.mjs +46 -0
  199. package/build-module/components/dataform-layouts/validation-badge.mjs.map +7 -0
  200. package/build-module/components/dataviews-bulk-actions/index.mjs +4 -4
  201. package/build-module/components/dataviews-bulk-actions/index.mjs.map +2 -2
  202. package/build-module/components/dataviews-context/index.mjs.map +2 -2
  203. package/build-module/components/dataviews-filters/filter.mjs +1 -1
  204. package/build-module/components/dataviews-filters/filter.mjs.map +1 -1
  205. package/build-module/components/dataviews-filters/filters.mjs +1 -1
  206. package/build-module/components/dataviews-filters/filters.mjs.map +1 -1
  207. package/build-module/components/dataviews-filters/search-widget.mjs +25 -11
  208. package/build-module/components/dataviews-filters/search-widget.mjs.map +2 -2
  209. package/build-module/components/dataviews-filters/toggle.mjs.map +1 -1
  210. package/build-module/components/dataviews-footer/index.mjs +1 -1
  211. package/build-module/components/dataviews-footer/index.mjs.map +1 -1
  212. package/build-module/components/dataviews-layouts/activity/activity-item.mjs +4 -4
  213. package/build-module/components/dataviews-layouts/activity/activity-item.mjs.map +1 -1
  214. package/build-module/components/dataviews-layouts/activity/index.mjs +1 -1
  215. package/build-module/components/dataviews-layouts/activity/index.mjs.map +1 -1
  216. package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +27 -38
  217. package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
  218. package/build-module/components/dataviews-layouts/grid/index.mjs +2 -2
  219. package/build-module/components/dataviews-layouts/grid/index.mjs.map +1 -1
  220. package/build-module/components/dataviews-layouts/list/index.mjs +7 -8
  221. package/build-module/components/dataviews-layouts/list/index.mjs.map +2 -2
  222. package/build-module/components/dataviews-layouts/picker-grid/index.mjs +5 -5
  223. package/build-module/components/dataviews-layouts/picker-grid/index.mjs.map +2 -2
  224. package/build-module/components/dataviews-layouts/picker-table/index.mjs +1 -1
  225. package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
  226. package/build-module/components/dataviews-layouts/table/column-primary.mjs +1 -1
  227. package/build-module/components/dataviews-layouts/table/column-primary.mjs.map +1 -1
  228. package/build-module/components/dataviews-layouts/table/index.mjs +1 -1
  229. package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
  230. package/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs.map +2 -2
  231. package/build-module/components/dataviews-pagination/index.mjs +3 -3
  232. package/build-module/components/dataviews-pagination/index.mjs.map +2 -2
  233. package/build-module/components/dataviews-picker-footer/index.mjs +3 -3
  234. package/build-module/components/dataviews-picker-footer/index.mjs.map +2 -2
  235. package/build-module/components/dataviews-view-config/index.mjs +74 -59
  236. package/build-module/components/dataviews-view-config/index.mjs.map +2 -2
  237. package/build-module/components/dataviews-view-config/properties-section.mjs +1 -1
  238. package/build-module/components/dataviews-view-config/properties-section.mjs.map +1 -1
  239. package/build-module/dataviews/index.mjs +7 -5
  240. package/build-module/dataviews/index.mjs.map +2 -2
  241. package/build-module/dataviews-picker/index.mjs +3 -3
  242. package/build-module/dataviews-picker/index.mjs.map +2 -2
  243. package/build-module/hooks/use-form-validity.mjs +61 -28
  244. package/build-module/hooks/use-form-validity.mjs.map +2 -2
  245. package/build-module/hooks/use-report-validity.mjs +18 -0
  246. package/build-module/hooks/use-report-validity.mjs.map +7 -0
  247. package/build-style/style-rtl.css +149 -217
  248. package/build-style/style.css +149 -217
  249. package/build-types/components/dataform-controls/adaptive-select.d.ts +6 -0
  250. package/build-types/components/dataform-controls/adaptive-select.d.ts.map +1 -0
  251. package/build-types/components/dataform-controls/array.d.ts +1 -1
  252. package/build-types/components/dataform-controls/array.d.ts.map +1 -1
  253. package/build-types/components/dataform-controls/checkbox.d.ts +1 -1
  254. package/build-types/components/dataform-controls/checkbox.d.ts.map +1 -1
  255. package/build-types/components/dataform-controls/color.d.ts +1 -1
  256. package/build-types/components/dataform-controls/color.d.ts.map +1 -1
  257. package/build-types/components/dataform-controls/combobox.d.ts +6 -0
  258. package/build-types/components/dataform-controls/combobox.d.ts.map +1 -0
  259. package/build-types/components/dataform-controls/date.d.ts +1 -1
  260. package/build-types/components/dataform-controls/date.d.ts.map +1 -1
  261. package/build-types/components/dataform-controls/datetime.d.ts +1 -1
  262. package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
  263. package/build-types/components/dataform-controls/email.d.ts +1 -1
  264. package/build-types/components/dataform-controls/email.d.ts.map +1 -1
  265. package/build-types/components/dataform-controls/index.d.ts.map +1 -1
  266. package/build-types/components/dataform-controls/password.d.ts +1 -1
  267. package/build-types/components/dataform-controls/password.d.ts.map +1 -1
  268. package/build-types/components/dataform-controls/radio.d.ts +1 -1
  269. package/build-types/components/dataform-controls/radio.d.ts.map +1 -1
  270. package/build-types/components/dataform-controls/select.d.ts +1 -1
  271. package/build-types/components/dataform-controls/select.d.ts.map +1 -1
  272. package/build-types/components/dataform-controls/telephone.d.ts +1 -1
  273. package/build-types/components/dataform-controls/telephone.d.ts.map +1 -1
  274. package/build-types/components/dataform-controls/text.d.ts +1 -1
  275. package/build-types/components/dataform-controls/text.d.ts.map +1 -1
  276. package/build-types/components/dataform-controls/textarea.d.ts +1 -1
  277. package/build-types/components/dataform-controls/textarea.d.ts.map +1 -1
  278. package/build-types/components/dataform-controls/toggle-group.d.ts +1 -1
  279. package/build-types/components/dataform-controls/toggle-group.d.ts.map +1 -1
  280. package/build-types/components/dataform-controls/toggle.d.ts +1 -1
  281. package/build-types/components/dataform-controls/toggle.d.ts.map +1 -1
  282. package/build-types/components/dataform-controls/url.d.ts +1 -1
  283. package/build-types/components/dataform-controls/url.d.ts.map +1 -1
  284. package/build-types/components/dataform-controls/utils/validated-input.d.ts +1 -1
  285. package/build-types/components/dataform-controls/utils/validated-input.d.ts.map +1 -1
  286. package/build-types/components/dataform-controls/utils/validated-number.d.ts +1 -1
  287. package/build-types/components/dataform-controls/utils/validated-number.d.ts.map +1 -1
  288. package/build-types/components/dataform-layouts/card/index.d.ts +3 -1
  289. package/build-types/components/dataform-layouts/card/index.d.ts.map +1 -1
  290. package/build-types/components/dataform-layouts/data-form-layout.d.ts +2 -1
  291. package/build-types/components/dataform-layouts/data-form-layout.d.ts.map +1 -1
  292. package/build-types/components/dataform-layouts/details/index.d.ts +1 -1
  293. package/build-types/components/dataform-layouts/details/index.d.ts.map +1 -1
  294. package/build-types/components/dataform-layouts/normalize-form.d.ts.map +1 -1
  295. package/build-types/components/dataform-layouts/panel/dropdown.d.ts +2 -12
  296. package/build-types/components/dataform-layouts/panel/dropdown.d.ts.map +1 -1
  297. package/build-types/components/dataform-layouts/panel/index.d.ts +1 -1
  298. package/build-types/components/dataform-layouts/panel/index.d.ts.map +1 -1
  299. package/build-types/components/dataform-layouts/panel/modal.d.ts +2 -10
  300. package/build-types/components/dataform-layouts/panel/modal.d.ts.map +1 -1
  301. package/build-types/components/dataform-layouts/panel/summary-button.d.ts +6 -5
  302. package/build-types/components/dataform-layouts/panel/summary-button.d.ts.map +1 -1
  303. package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts +4 -0
  304. package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts.map +1 -0
  305. package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts +4 -0
  306. package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts.map +1 -0
  307. package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts +3 -0
  308. package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts.map +1 -0
  309. package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts +23 -0
  310. package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts.map +1 -0
  311. package/build-types/components/dataform-layouts/regular/index.d.ts +1 -1
  312. package/build-types/components/dataform-layouts/regular/index.d.ts.map +1 -1
  313. package/build-types/components/dataform-layouts/row/index.d.ts +1 -1
  314. package/build-types/components/dataform-layouts/row/index.d.ts.map +1 -1
  315. package/build-types/components/dataform-layouts/validation-badge.d.ts +8 -0
  316. package/build-types/components/dataform-layouts/validation-badge.d.ts.map +1 -0
  317. package/build-types/components/dataviews-context/index.d.ts +1 -0
  318. package/build-types/components/dataviews-context/index.d.ts.map +1 -1
  319. package/build-types/components/dataviews-filters/filter.d.ts +1 -1
  320. package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
  321. package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
  322. package/build-types/components/dataviews-layouts/list/index.d.ts.map +1 -1
  323. package/build-types/components/dataviews-layouts/utils/item-click-wrapper.d.ts +1 -0
  324. package/build-types/components/dataviews-layouts/utils/item-click-wrapper.d.ts.map +1 -1
  325. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  326. package/build-types/dataform/stories/content.story.d.ts +14 -0
  327. package/build-types/dataform/stories/content.story.d.ts.map +1 -0
  328. package/build-types/dataform/stories/index.story.d.ts +10 -2
  329. package/build-types/dataform/stories/index.story.d.ts.map +1 -1
  330. package/build-types/dataform/stories/layout-panel.d.ts +3 -1
  331. package/build-types/dataform/stories/layout-panel.d.ts.map +1 -1
  332. package/build-types/dataform/stories/validation.d.ts +1 -1
  333. package/build-types/dataform/stories/validation.d.ts.map +1 -1
  334. package/build-types/dataviews/index.d.ts +2 -1
  335. package/build-types/dataviews/index.d.ts.map +1 -1
  336. package/build-types/dataviews/stories/fixtures.d.ts +1 -0
  337. package/build-types/dataviews/stories/fixtures.d.ts.map +1 -1
  338. package/build-types/dataviews/stories/index.story.d.ts +14 -2
  339. package/build-types/dataviews/stories/index.story.d.ts.map +1 -1
  340. package/build-types/dataviews/stories/layout-activity.d.ts +2 -1
  341. package/build-types/dataviews/stories/layout-activity.d.ts.map +1 -1
  342. package/build-types/dataviews/stories/layout-list.d.ts +2 -1
  343. package/build-types/dataviews/stories/layout-list.d.ts.map +1 -1
  344. package/build-types/field-types/stories/index.story.d.ts +42 -16
  345. package/build-types/field-types/stories/index.story.d.ts.map +1 -1
  346. package/build-types/hooks/use-form-validity.d.ts.map +1 -1
  347. package/build-types/hooks/use-report-validity.d.ts +14 -0
  348. package/build-types/hooks/use-report-validity.d.ts.map +1 -0
  349. package/build-types/types/dataform.d.ts +4 -0
  350. package/build-types/types/dataform.d.ts.map +1 -1
  351. package/build-types/types/field-api.d.ts +4 -0
  352. package/build-types/types/field-api.d.ts.map +1 -1
  353. package/build-wp/index.js +3749 -2632
  354. package/package.json +22 -21
  355. package/src/components/dataform-controls/adaptive-select.tsx +23 -0
  356. package/src/components/dataform-controls/array.tsx +2 -0
  357. package/src/components/dataform-controls/checkbox.tsx +2 -0
  358. package/src/components/dataform-controls/color.tsx +31 -36
  359. package/src/components/dataform-controls/combobox.tsx +58 -0
  360. package/src/components/dataform-controls/date.tsx +69 -26
  361. package/src/components/dataform-controls/datetime.tsx +16 -6
  362. package/src/components/dataform-controls/email.tsx +2 -0
  363. package/src/components/dataform-controls/index.tsx +5 -1
  364. package/src/components/dataform-controls/password.tsx +2 -0
  365. package/src/components/dataform-controls/radio.tsx +2 -0
  366. package/src/components/dataform-controls/select.tsx +2 -0
  367. package/src/components/dataform-controls/style.scss +4 -0
  368. package/src/components/dataform-controls/telephone.tsx +2 -0
  369. package/src/components/dataform-controls/text.tsx +2 -0
  370. package/src/components/dataform-controls/textarea.tsx +2 -0
  371. package/src/components/dataform-controls/toggle-group.tsx +2 -0
  372. package/src/components/dataform-controls/toggle.tsx +2 -0
  373. package/src/components/dataform-controls/url.tsx +2 -0
  374. package/src/components/dataform-controls/utils/relative-date-control.tsx +1 -1
  375. package/src/components/dataform-controls/utils/validated-input.tsx +2 -0
  376. package/src/components/dataform-controls/utils/validated-number.tsx +2 -0
  377. package/src/components/dataform-layouts/card/index.tsx +40 -3
  378. package/src/components/dataform-layouts/data-form-layout.tsx +18 -4
  379. package/src/components/dataform-layouts/details/index.tsx +66 -4
  380. package/src/components/dataform-layouts/details/style.scss +5 -0
  381. package/src/components/dataform-layouts/index.tsx +5 -5
  382. package/src/components/dataform-layouts/normalize-form.ts +1 -0
  383. package/src/components/dataform-layouts/panel/dropdown.tsx +110 -94
  384. package/src/components/dataform-layouts/panel/index.tsx +10 -243
  385. package/src/components/dataform-layouts/panel/modal.tsx +43 -29
  386. package/src/components/dataform-layouts/panel/style.scss +109 -27
  387. package/src/components/dataform-layouts/panel/summary-button.tsx +140 -62
  388. package/src/components/dataform-layouts/panel/utils/get-first-validation-error.ts +47 -0
  389. package/src/components/dataform-layouts/panel/utils/get-label-classname.ts +18 -0
  390. package/src/components/dataform-layouts/panel/utils/get-label-content.tsx +26 -0
  391. package/src/components/dataform-layouts/panel/utils/use-field-from-form-field.ts +78 -0
  392. package/src/components/dataform-layouts/regular/index.tsx +8 -3
  393. package/src/components/dataform-layouts/regular/style.scss +10 -0
  394. package/src/components/dataform-layouts/row/index.tsx +5 -2
  395. package/src/components/dataform-layouts/test/normalize-form.ts +5 -0
  396. package/src/components/dataform-layouts/validation-badge.tsx +63 -0
  397. package/src/components/dataviews-bulk-actions/index.tsx +4 -4
  398. package/src/components/dataviews-context/index.ts +1 -0
  399. package/src/components/dataviews-filters/filter.tsx +2 -2
  400. package/src/components/dataviews-filters/filters.tsx +1 -1
  401. package/src/components/dataviews-filters/search-widget.tsx +10 -2
  402. package/src/components/dataviews-filters/style.scss +8 -0
  403. package/src/components/dataviews-filters/toggle.tsx +1 -1
  404. package/src/components/dataviews-footer/index.tsx +1 -1
  405. package/src/components/dataviews-layouts/activity/activity-item.tsx +4 -4
  406. package/src/components/dataviews-layouts/activity/index.tsx +1 -1
  407. package/src/components/dataviews-layouts/grid/composite-grid.tsx +35 -35
  408. package/src/components/dataviews-layouts/grid/index.tsx +2 -2
  409. package/src/components/dataviews-layouts/grid/style.scss +15 -1
  410. package/src/components/dataviews-layouts/list/index.tsx +7 -8
  411. package/src/components/dataviews-layouts/list/style.scss +1 -0
  412. package/src/components/dataviews-layouts/picker-grid/index.tsx +5 -5
  413. package/src/components/dataviews-layouts/picker-table/index.tsx +1 -1
  414. package/src/components/dataviews-layouts/table/column-primary.tsx +1 -1
  415. package/src/components/dataviews-layouts/table/index.tsx +1 -1
  416. package/src/components/dataviews-layouts/utils/item-click-wrapper.tsx +1 -0
  417. package/src/components/dataviews-pagination/index.tsx +3 -3
  418. package/src/components/dataviews-picker-footer/index.tsx +3 -3
  419. package/src/components/dataviews-view-config/index.tsx +61 -50
  420. package/src/components/dataviews-view-config/properties-section.tsx +1 -1
  421. package/src/components/dataviews-view-config/style.scss +21 -0
  422. package/src/dataform/stories/content.story.mdx +159 -0
  423. package/src/dataform/stories/content.story.tsx +390 -0
  424. package/src/dataform/stories/index.story.tsx +14 -2
  425. package/src/dataform/stories/layout-panel.tsx +19 -2
  426. package/src/dataform/stories/validation.tsx +100 -7
  427. package/src/dataform/test/dataform.tsx +2 -2
  428. package/src/dataviews/index.tsx +7 -4
  429. package/src/dataviews/stories/empty.tsx +1 -1
  430. package/src/dataviews/stories/fixtures.tsx +93 -4
  431. package/src/dataviews/stories/free-composition.tsx +6 -6
  432. package/src/dataviews/stories/index.story.tsx +12 -0
  433. package/src/dataviews/stories/layout-activity.tsx +6 -3
  434. package/src/dataviews/stories/layout-list.tsx +3 -0
  435. package/src/dataviews-picker/index.tsx +4 -4
  436. package/src/dataviews-picker/stories/fixtures.tsx +2 -2
  437. package/src/dataviews-picker/stories/index.story.tsx +1 -1
  438. package/src/field-types/stories/index.story.tsx +101 -5
  439. package/src/hooks/test/use-form-validity.ts +303 -178
  440. package/src/hooks/use-form-validity.ts +85 -36
  441. package/src/hooks/use-report-validity.ts +32 -0
  442. package/src/style.scss +0 -2
  443. package/src/types/dataform.ts +5 -0
  444. package/src/types/field-api.ts +4 -0
@@ -6,14 +6,16 @@ import {
6
6
  Button
7
7
  } from "@wordpress/components";
8
8
  import { __ } from "@wordpress/i18n";
9
- import { useMemo } from "@wordpress/element";
9
+ import { useMemo, useRef, useState } from "@wordpress/element";
10
10
  import { closeSmall } from "@wordpress/icons";
11
- import { useFocusOnMount } from "@wordpress/compose";
11
+ import { __experimentalUseDialog as useDialog } from "@wordpress/compose";
12
12
  import { Stack } from "@wordpress/ui";
13
13
  import { DataFormLayout } from "../data-form-layout.mjs";
14
14
  import { DEFAULT_LAYOUT } from "../normalize-form.mjs";
15
15
  import SummaryButton from "./summary-button.mjs";
16
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ import useReportValidity from "../../../hooks/use-report-validity.mjs";
17
+ import useFieldFromFormField from "./utils/use-field-from-form-field.mjs";
18
+ import { jsx, jsxs } from "react/jsx-runtime";
17
19
  function DropdownHeader({
18
20
  title,
19
21
  onClose
@@ -23,8 +25,8 @@ function DropdownHeader({
23
25
  {
24
26
  direction: "column",
25
27
  className: "dataforms-layouts-panel__dropdown-header",
26
- gap: "md",
27
- children: /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: "xs", align: "center", children: [
28
+ gap: "lg",
29
+ children: /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: "sm", align: "center", children: [
28
30
  title && /* @__PURE__ */ jsx(Heading, { level: 2, size: 13, children: title }),
29
31
  /* @__PURE__ */ jsx(Spacer, { style: { flex: 1 } }),
30
32
  onClose && /* @__PURE__ */ jsx(
@@ -40,18 +42,38 @@ function DropdownHeader({
40
42
  }
41
43
  );
42
44
  }
45
+ function DropdownContentWithValidation({
46
+ touched,
47
+ children
48
+ }) {
49
+ const ref = useRef(null);
50
+ useReportValidity(ref, touched);
51
+ return /* @__PURE__ */ jsx("div", { ref, children });
52
+ }
43
53
  function PanelDropdown({
44
54
  data,
45
55
  field,
46
56
  onChange,
47
- validity,
48
- labelPosition = "side",
49
- summaryFields,
50
- fieldDefinition,
51
- popoverAnchor,
52
- onOpen
57
+ validity
53
58
  }) {
54
- const fieldLabel = !!field.children ? field.label : fieldDefinition?.label;
59
+ const [touched, setTouched] = useState(false);
60
+ const [popoverAnchor, setPopoverAnchor] = useState(
61
+ null
62
+ );
63
+ const popoverProps = useMemo(
64
+ () => ({
65
+ // Anchor the popover to the middle of the entire row so that it doesn't
66
+ // move around when the label changes.
67
+ anchor: popoverAnchor,
68
+ placement: "left-start",
69
+ offset: 36,
70
+ shift: true
71
+ }),
72
+ [popoverAnchor]
73
+ );
74
+ const [dialogRef, dialogProps] = useDialog({
75
+ focusOnMount: "firstInputElement"
76
+ });
55
77
  const form = useMemo(
56
78
  () => ({
57
79
  layout: DEFAULT_LAYOUT,
@@ -71,69 +93,72 @@ function PanelDropdown({
71
93
  }
72
94
  return { [field.id]: validity };
73
95
  }, [validity, field]);
74
- const popoverProps = useMemo(
75
- () => ({
76
- // Anchor the popover to the middle of the entire row so that it doesn't
77
- // move around when the label changes.
78
- anchor: popoverAnchor,
79
- placement: "left-start",
80
- offset: 36,
81
- shift: true
82
- }),
83
- [popoverAnchor]
84
- );
85
- const focusOnMountRef = useFocusOnMount("firstInputElement");
96
+ const { fieldDefinition, fieldLabel, summaryFields } = useFieldFromFormField(field);
97
+ if (!fieldDefinition) {
98
+ return null;
99
+ }
86
100
  return /* @__PURE__ */ jsx(
87
- Dropdown,
101
+ "div",
88
102
  {
89
- contentClassName: "dataforms-layouts-panel__field-dropdown",
90
- popoverProps,
91
- focusOnMount: false,
92
- toggleProps: {
93
- size: "compact",
94
- variant: "tertiary",
95
- tooltipPosition: "middle left"
96
- },
97
- renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ jsx(
98
- SummaryButton,
103
+ ref: setPopoverAnchor,
104
+ className: "dataforms-layouts-panel__field-dropdown-anchor",
105
+ children: /* @__PURE__ */ jsx(
106
+ Dropdown,
99
107
  {
100
- summaryFields,
101
- data,
102
- labelPosition,
103
- fieldLabel,
104
- disabled: fieldDefinition.readOnly === true,
105
- onClick: () => {
106
- if (!isOpen && onOpen) {
107
- onOpen();
108
+ contentClassName: "dataforms-layouts-panel__field-dropdown",
109
+ popoverProps,
110
+ focusOnMount: false,
111
+ onToggle: (willOpen) => {
112
+ if (!willOpen) {
113
+ setTouched(true);
108
114
  }
109
- onToggle();
110
115
  },
111
- "aria-expanded": isOpen
112
- }
113
- ),
114
- renderContent: ({ onClose }) => /* @__PURE__ */ jsxs(Fragment, { children: [
115
- /* @__PURE__ */ jsx(DropdownHeader, { title: fieldLabel, onClose }),
116
- /* @__PURE__ */ jsx("div", { ref: focusOnMountRef, children: /* @__PURE__ */ jsx(
117
- DataFormLayout,
118
- {
119
- data,
120
- form,
121
- onChange,
122
- validity: formValidity,
123
- children: (FieldLayout, childField, childFieldValidity) => /* @__PURE__ */ jsx(
124
- FieldLayout,
116
+ renderToggle: ({ isOpen, onToggle }) => /* @__PURE__ */ jsx(
117
+ SummaryButton,
118
+ {
119
+ data,
120
+ field,
121
+ fieldLabel,
122
+ summaryFields,
123
+ validity,
124
+ touched,
125
+ disabled: fieldDefinition.readOnly === true,
126
+ onClick: onToggle,
127
+ "aria-expanded": isOpen
128
+ }
129
+ ),
130
+ renderContent: ({ onClose }) => /* @__PURE__ */ jsx(DropdownContentWithValidation, { touched, children: /* @__PURE__ */ jsxs("div", { ref: dialogRef, ...dialogProps, children: [
131
+ /* @__PURE__ */ jsx(
132
+ DropdownHeader,
133
+ {
134
+ title: fieldLabel,
135
+ onClose
136
+ }
137
+ ),
138
+ /* @__PURE__ */ jsx(
139
+ DataFormLayout,
125
140
  {
126
141
  data,
127
- field: childField,
142
+ form,
128
143
  onChange,
129
- hideLabelFromVision: (form?.fields ?? []).length < 2,
130
- validity: childFieldValidity
131
- },
132
- childField.id
144
+ validity: formValidity,
145
+ children: (FieldLayout, childField, childFieldValidity, markWhenOptional) => /* @__PURE__ */ jsx(
146
+ FieldLayout,
147
+ {
148
+ data,
149
+ field: childField,
150
+ onChange,
151
+ hideLabelFromVision: (form?.fields ?? []).length < 2,
152
+ markWhenOptional,
153
+ validity: childFieldValidity
154
+ },
155
+ childField.id
156
+ )
157
+ }
133
158
  )
134
- }
135
- ) })
136
- ] })
159
+ ] }) })
160
+ }
161
+ )
137
162
  }
138
163
  );
139
164
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/dataform-layouts/panel/dropdown.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHeading as Heading,\n\t__experimentalSpacer as Spacer,\n\tDropdown,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { useFocusOnMount } from '@wordpress/compose';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldValidity,\n\tNormalizedForm,\n\tNormalizedFormField,\n\tFormValidity,\n\tNormalizedField,\n} from '../../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { DEFAULT_LAYOUT } from '../normalize-form';\nimport SummaryButton from './summary-button';\n\nfunction DropdownHeader( {\n\ttitle,\n\tonClose,\n}: {\n\ttitle?: string;\n\tonClose: () => void;\n} ) {\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tclassName=\"dataforms-layouts-panel__dropdown-header\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t<Stack direction=\"row\" gap=\"xs\" align=\"center\">\n\t\t\t\t{ title && (\n\t\t\t\t\t<Heading level={ 2 } size={ 13 }>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Heading>\n\t\t\t\t) }\n\t\t\t\t<Spacer style={ { flex: 1 } } />\n\t\t\t\t{ onClose && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n\nfunction PanelDropdown< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\tvalidity,\n\tlabelPosition = 'side',\n\tsummaryFields,\n\tfieldDefinition,\n\tpopoverAnchor,\n\tonOpen,\n}: {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tonChange: ( value: any ) => void;\n\tvalidity?: FieldValidity;\n\tlabelPosition: 'side' | 'top' | 'none';\n\tsummaryFields: NormalizedField< Item >[];\n\tfieldDefinition: NormalizedField< Item >;\n\tpopoverAnchor: HTMLElement | null;\n\tonOpen?: () => void;\n} ) {\n\tconst fieldLabel = !! field.children ? field.label : fieldDefinition?.label;\n\n\tconst form: NormalizedForm = useMemo(\n\t\t() => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: !! field.children\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id, layout: DEFAULT_LAYOUT } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\tconst formValidity = useMemo( (): FormValidity => {\n\t\tif ( validity === undefined ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( !! field.children ) {\n\t\t\treturn validity?.children;\n\t\t}\n\n\t\treturn { [ field.id ]: validity };\n\t}, [ validity, field ] );\n\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t\tplacement: 'left-start',\n\t\t\toffset: 36,\n\t\t\tshift: true,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\n\tconst focusOnMountRef = useFocusOnMount( 'firstInputElement' );\n\n\treturn (\n\t\t<Dropdown\n\t\t\tcontentClassName=\"dataforms-layouts-panel__field-dropdown\"\n\t\t\tpopoverProps={ popoverProps }\n\t\t\tfocusOnMount={ false }\n\t\t\ttoggleProps={ {\n\t\t\t\tsize: 'compact',\n\t\t\t\tvariant: 'tertiary',\n\t\t\t\ttooltipPosition: 'middle left',\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<SummaryButton\n\t\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t\t\tfieldLabel={ fieldLabel }\n\t\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( ! isOpen && onOpen ) {\n\t\t\t\t\t\t\tonOpen();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonToggle();\n\t\t\t\t\t} }\n\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t<>\n\t\t\t\t\t<DropdownHeader title={ fieldLabel } onClose={ onClose } />\n\t\t\t\t\t<div ref={ focusOnMountRef }>\n\t\t\t\t\t\t<DataFormLayout\n\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\tform={ form }\n\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\tvalidity={ formValidity }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ (\n\t\t\t\t\t\t\t\tFieldLayout,\n\t\t\t\t\t\t\t\tchildField,\n\t\t\t\t\t\t\t\tchildFieldValidity\n\t\t\t\t\t\t\t) => (\n\t\t\t\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\t\t\t\tkey={ childField.id }\n\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\tfield={ childField }\n\t\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tvalidity={ childFieldValidity }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</DataFormLayout>\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t) }\n\t\t/>\n\t);\n}\n\nexport default PanelDropdown;\n"],
5
- "mappings": ";AAGA;AAAA,EACC,yBAAyB;AAAA,EACzB,wBAAwB;AAAA,EACxB;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,aAAa;AAYtB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,OAAO,mBAAmB;AAevB,SA2GC,UAzGC,KAFF;AAbH,SAAS,eAAgB;AAAA,EACxB;AAAA,EACA;AACD,GAGI;AACH,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV,WAAU;AAAA,MACV,KAAI;AAAA,MAEJ,+BAAC,SAAM,WAAU,OAAM,KAAI,MAAK,OAAM,UACnC;AAAA,iBACD,oBAAC,WAAQ,OAAQ,GAAI,MAAO,IACzB,iBACH;AAAA,QAED,oBAAC,UAAO,OAAQ,EAAE,MAAM,EAAE,GAAI;AAAA,QAC5B,WACD;AAAA,UAAC;AAAA;AAAA,YACA,OAAQ,GAAI,OAAQ;AAAA,YACpB,MAAO;AAAA,YACP,SAAU;AAAA,YACV,MAAK;AAAA;AAAA,QACN;AAAA,SAEF;AAAA;AAAA,EACD;AAEF;AAEA,SAAS,cAAuB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAUI;AACH,Q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OAAQ,YAAa,SAAoB;AAAA,QACzD,oBAAC,SAAI,KAAM,iBACV;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,UAAW;AAAA,YAET,WACD,aACA,YACA,uBAEA;AAAA,cAAC;AAAA;AAAA,gBAEA;AAAA,gBACA,OAAQ;AAAA,gBACR;AAAA,gBACA,sBACG,MAAM,UAAU,CAAC,GAAI,SAAS;AAAA,gBAEjC,UAAW;AAAA;AAAA,cAPL,WAAW;AAAA,YAQlB;AAAA;AAAA,QAEF,GACD;AAAA,SACD;AAAA;AAAA,EAEF;AAEF;AAEA,IAAO,mBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalHeading as Heading,\n\t__experimentalSpacer as Spacer,\n\tDropdown,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useRef, useState } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { __experimentalUseDialog as useDialog } from '@wordpress/compose';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldLayoutProps,\n\tNormalizedForm,\n\tFormValidity,\n} from '../../../types';\nimport { DataFormLayout } from '../data-form-layout';\nimport { DEFAULT_LAYOUT } from '../normalize-form';\nimport SummaryButton from './summary-button';\nimport useReportValidity from '../../../hooks/use-report-validity';\nimport useFieldFromFormField from './utils/use-field-from-form-field';\n\nfunction DropdownHeader( {\n\ttitle,\n\tonClose,\n}: {\n\ttitle?: string;\n\tonClose: () => void;\n} ) {\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"column\"\n\t\t\tclassName=\"dataforms-layouts-panel__dropdown-header\"\n\t\t\tgap=\"lg\"\n\t\t>\n\t\t\t<Stack direction=\"row\" gap=\"sm\" align=\"center\">\n\t\t\t\t{ title && (\n\t\t\t\t\t<Heading level={ 2 } size={ 13 }>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Heading>\n\t\t\t\t) }\n\t\t\t\t<Spacer style={ { flex: 1 } } />\n\t\t\t\t{ onClose && (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tlabel={ __( 'Close' ) }\n\t\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</Stack>\n\t\t</Stack>\n\t);\n}\n\nfunction DropdownContentWithValidation( {\n\ttouched,\n\tchildren,\n}: {\n\ttouched: boolean;\n\tchildren: React.ReactNode;\n} ) {\n\tconst ref = useRef< HTMLDivElement >( null );\n\tuseReportValidity( ref, touched );\n\treturn <div ref={ ref }>{ children }</div>;\n}\n\nfunction PanelDropdown< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\tvalidity,\n}: FieldLayoutProps< Item > ) {\n\tconst [ touched, setTouched ] = useState( false );\n\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >(\n\t\tnull\n\t);\n\t// Memoize popoverProps to avoid returning a new object every time.\n\tconst popoverProps = useMemo(\n\t\t() => ( {\n\t\t\t// Anchor the popover to the middle of the entire row so that it doesn't\n\t\t\t// move around when the label changes.\n\t\t\tanchor: popoverAnchor,\n\t\t\tplacement: 'left-start',\n\t\t\toffset: 36,\n\t\t\tshift: true,\n\t\t} ),\n\t\t[ popoverAnchor ]\n\t);\n\tconst [ dialogRef, dialogProps ] = useDialog( {\n\t\tfocusOnMount: 'firstInputElement',\n\t} );\n\n\tconst form: NormalizedForm = useMemo(\n\t\t() => ( {\n\t\t\tlayout: DEFAULT_LAYOUT,\n\t\t\tfields: !! field.children\n\t\t\t\t? field.children\n\t\t\t\t: // If not explicit children return the field id itself.\n\t\t\t\t [ { id: field.id, layout: DEFAULT_LAYOUT } ],\n\t\t} ),\n\t\t[ field ]\n\t);\n\tconst formValidity = useMemo( (): FormValidity => {\n\t\tif ( validity === undefined ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( !! field.children ) {\n\t\t\treturn validity?.children;\n\t\t}\n\n\t\treturn { [ field.id ]: validity };\n\t}, [ validity, field ] );\n\n\tconst { fieldDefinition, fieldLabel, summaryFields } =\n\t\tuseFieldFromFormField( field );\n\tif ( ! fieldDefinition ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ setPopoverAnchor }\n\t\t\tclassName=\"dataforms-layouts-panel__field-dropdown-anchor\"\n\t\t>\n\t\t\t<Dropdown\n\t\t\t\tcontentClassName=\"dataforms-layouts-panel__field-dropdown\"\n\t\t\t\tpopoverProps={ popoverProps }\n\t\t\t\tfocusOnMount={ false }\n\t\t\t\tonToggle={ ( willOpen ) => {\n\t\t\t\t\tif ( ! willOpen ) {\n\t\t\t\t\t\tsetTouched( true );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t\t<SummaryButton\n\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\tfield={ field }\n\t\t\t\t\t\tfieldLabel={ fieldLabel }\n\t\t\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\t\t\tvalidity={ validity }\n\t\t\t\t\t\ttouched={ touched }\n\t\t\t\t\t\tdisabled={ fieldDefinition.readOnly === true }\n\t\t\t\t\t\tonClick={ onToggle }\n\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t\trenderContent={ ( { onClose } ) => (\n\t\t\t\t\t<DropdownContentWithValidation touched={ touched }>\n\t\t\t\t\t\t<div ref={ dialogRef } { ...dialogProps }>\n\t\t\t\t\t\t\t<DropdownHeader\n\t\t\t\t\t\t\t\ttitle={ fieldLabel }\n\t\t\t\t\t\t\t\tonClose={ onClose }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<DataFormLayout\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tform={ form }\n\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\tvalidity={ formValidity }\n\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\tFieldLayout,\n\t\t\t\t\t\t\t\t\tchildField,\n\t\t\t\t\t\t\t\t\tchildFieldValidity,\n\t\t\t\t\t\t\t\t\tmarkWhenOptional\n\t\t\t\t\t\t\t\t) => (\n\t\t\t\t\t\t\t\t\t<FieldLayout\n\t\t\t\t\t\t\t\t\t\tkey={ childField.id }\n\t\t\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\t\t\tfield={ childField }\n\t\t\t\t\t\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\t\t\t\t\t\thideLabelFromVision={\n\t\t\t\t\t\t\t\t\t\t\t( form?.fields ?? [] ).length < 2\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\t\t\t\t\t\t\t\tvalidity={ childFieldValidity }\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</DataFormLayout>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</DropdownContentWithValidation>\n\t\t\t\t) }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nexport default PanelDropdown;\n"],
5
+ "mappings": ";AAGA;AAAA,EACC,yBAAyB;AAAA,EACzB,wBAAwB;AAAA,EACxB;AAAA,EACA;AAAA,OACM;AACP,SAAS,UAAU;AACnB,SAAS,SAAS,QAAQ,gBAAgB;AAC1C,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B,iBAAiB;AACrD,SAAS,aAAa;AAUtB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,OAAO,mBAAmB;AAC1B,OAAO,uBAAuB;AAC9B,OAAO,2BAA2B;AAe/B,SAEE,KAFF;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oBACA,sBACG,MAAM,UAAU,CAAC,GAAI,SAAS;AAAA,oBAEjC;AAAA,oBACA,UAAW;AAAA;AAAA,kBARL,WAAW;AAAA,gBASlB;AAAA;AAAA,YAEF;AAAA,aACD,GACD;AAAA;AAAA,MAEF;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,mBAAQ;",
6
6
  "names": []
7
7
  }
@@ -1,194 +1,32 @@
1
1
  // packages/dataviews/src/components/dataform-layouts/panel/index.tsx
2
- import clsx from "clsx";
3
- import { Icon, Tooltip } from "@wordpress/components";
4
- import { useState, useContext } from "@wordpress/element";
5
- import { error as errorIcon } from "@wordpress/icons";
6
- import { Stack } from "@wordpress/ui";
7
- import DataFormContext from "../../dataform-context/index.mjs";
8
- import PanelDropdown from "./dropdown.mjs";
9
2
  import PanelModal from "./modal.mjs";
10
- import { getSummaryFields } from "../get-summary-fields.mjs";
11
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
- function getFirstValidationError(validity) {
13
- if (!validity) {
14
- return void 0;
15
- }
16
- const validityRules = Object.keys(validity).filter(
17
- (key) => key !== "children"
18
- );
19
- for (const key of validityRules) {
20
- const rule = validity[key];
21
- if (rule === void 0) {
22
- continue;
23
- }
24
- if (rule.type === "invalid") {
25
- if (rule.message) {
26
- return rule.message;
27
- }
28
- if (key === "required") {
29
- return "A required field is empty";
30
- }
31
- return "Unidentified validation error";
32
- }
33
- }
34
- if (validity.children) {
35
- for (const childValidity of Object.values(validity.children)) {
36
- const childError = getFirstValidationError(childValidity);
37
- if (childError) {
38
- return childError;
39
- }
40
- }
41
- }
42
- return void 0;
43
- }
44
- var getFieldDefinition = (field, fields) => {
45
- const fieldDefinition = fields.find((_field) => _field.id === field.id);
46
- if (!fieldDefinition) {
47
- return fields.find((_field) => {
48
- if (!!field.children) {
49
- const simpleChildren = field.children.filter(
50
- (child) => !child.children
51
- );
52
- if (simpleChildren.length === 0) {
53
- return false;
54
- }
55
- return _field.id === simpleChildren[0].id;
56
- }
57
- return _field.id === field.id;
58
- });
59
- }
60
- return fieldDefinition;
61
- };
62
- var getFieldDefinitionAndSummaryFields = (layout, field, fields) => {
63
- const summaryFields = getSummaryFields(layout.summary, fields);
64
- const fieldDefinition = getFieldDefinition(field, fields);
65
- if (summaryFields.length === 0) {
66
- return {
67
- summaryFields: fieldDefinition ? [fieldDefinition] : [],
68
- fieldDefinition
69
- };
70
- }
71
- return {
72
- summaryFields,
73
- fieldDefinition
74
- };
75
- };
3
+ import PanelDropdown from "./dropdown.mjs";
4
+ import { jsx } from "react/jsx-runtime";
76
5
  function FormPanelField({
77
6
  data,
78
7
  field,
79
8
  onChange,
80
9
  validity
81
10
  }) {
82
- const { fields } = useContext(DataFormContext);
83
11
  const layout = field.layout;
84
- const [popoverAnchor, setPopoverAnchor] = useState(
85
- null
86
- );
87
- const [touched, setTouched] = useState(false);
88
- const handleOpen = () => setTouched(true);
89
- const { fieldDefinition, summaryFields } = getFieldDefinitionAndSummaryFields(layout, field, fields);
90
- if (!fieldDefinition) {
91
- return null;
12
+ if (layout.openAs === "modal") {
13
+ return /* @__PURE__ */ jsx(
14
+ PanelModal,
15
+ {
16
+ data,
17
+ field,
18
+ onChange,
19
+ validity
20
+ }
21
+ );
92
22
  }
93
- const labelPosition = layout.labelPosition;
94
- const errorMessage = getFirstValidationError(validity);
95
- const showError = touched && !!errorMessage;
96
- const labelClassName = clsx(
97
- "dataforms-layouts-panel__field-label",
98
- `dataforms-layouts-panel__field-label--label-position-${labelPosition}`,
99
- { "has-error": showError }
100
- );
101
- const fieldLabel = !!field.children ? field.label : fieldDefinition?.label;
102
- const labelContent = showError ? /* @__PURE__ */ jsx(Tooltip, { text: errorMessage, placement: "top", children: /* @__PURE__ */ jsxs(
103
- Stack,
104
- {
105
- direction: "row",
106
- gap: "xs",
107
- className: "dataforms-layouts-panel__field-label-error-content",
108
- justify: "flex-start",
109
- children: [
110
- /* @__PURE__ */ jsx(Icon, { icon: errorIcon, size: 16 }),
111
- /* @__PURE__ */ jsx(Fragment, { children: fieldLabel })
112
- ]
113
- }
114
- ) }) : fieldLabel;
115
- const renderedControl = layout.openAs === "modal" ? /* @__PURE__ */ jsx(
116
- PanelModal,
117
- {
118
- data,
119
- field,
120
- onChange,
121
- labelPosition,
122
- summaryFields,
123
- fieldDefinition,
124
- onOpen: handleOpen
125
- }
126
- ) : /* @__PURE__ */ jsx(
23
+ return /* @__PURE__ */ jsx(
127
24
  PanelDropdown,
128
25
  {
129
26
  data,
130
27
  field,
131
28
  onChange,
132
- validity,
133
- labelPosition,
134
- summaryFields,
135
- fieldDefinition,
136
- popoverAnchor,
137
- onOpen: handleOpen
138
- }
139
- );
140
- if (labelPosition === "top") {
141
- return /* @__PURE__ */ jsxs(
142
- Stack,
143
- {
144
- direction: "column",
145
- className: "dataforms-layouts-panel__field",
146
- children: [
147
- /* @__PURE__ */ jsx(
148
- "div",
149
- {
150
- className: labelClassName,
151
- style: { paddingBottom: 0 },
152
- children: labelContent
153
- }
154
- ),
155
- /* @__PURE__ */ jsx("div", { className: "dataforms-layouts-panel__field-control", children: renderedControl })
156
- ]
157
- }
158
- );
159
- }
160
- if (labelPosition === "none") {
161
- return /* @__PURE__ */ jsxs(
162
- Stack,
163
- {
164
- direction: "row",
165
- gap: "xs",
166
- className: "dataforms-layouts-panel__field dataforms-layouts-panel__field--label-position-none",
167
- children: [
168
- showError && /* @__PURE__ */ jsx(Tooltip, { text: errorMessage, placement: "top", children: /* @__PURE__ */ jsx(
169
- Icon,
170
- {
171
- className: "dataforms-layouts-panel__field-label-error-content",
172
- icon: errorIcon,
173
- size: 16
174
- }
175
- ) }),
176
- /* @__PURE__ */ jsx("div", { className: "dataforms-layouts-panel__field-control", children: renderedControl })
177
- ]
178
- }
179
- );
180
- }
181
- return /* @__PURE__ */ jsxs(
182
- Stack,
183
- {
184
- direction: "row",
185
- gap: "xs",
186
- ref: setPopoverAnchor,
187
- className: "dataforms-layouts-panel__field",
188
- children: [
189
- /* @__PURE__ */ jsx("div", { className: labelClassName, children: labelContent }),
190
- /* @__PURE__ */ jsx("div", { className: "dataforms-layouts-panel__field-control", children: renderedControl })
191
- ]
29
+ validity
192
30
  }
193
31
  );
194
32
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/components/dataform-layouts/panel/index.tsx"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { Icon, Tooltip } from '@wordpress/components';\nimport { useState, useContext } from '@wordpress/element';\nimport { error as errorIcon } from '@wordpress/icons';\nimport { Stack } from '@wordpress/ui';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tFieldLayoutProps,\n\tFieldValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n\tNormalizedPanelLayout,\n} from '../../../types';\nimport DataFormContext from '../../dataform-context';\nimport PanelDropdown from './dropdown';\nimport PanelModal from './modal';\nimport { getSummaryFields } from '../get-summary-fields';\n\nfunction getFirstValidationError(\n\tvalidity: FieldValidity | undefined\n): string | undefined {\n\tif ( ! validity ) {\n\t\treturn undefined;\n\t}\n\n\tconst validityRules = Object.keys( validity ).filter(\n\t\t( key ) => key !== 'children'\n\t);\n\n\tfor ( const key of validityRules ) {\n\t\tconst rule = validity[ key as keyof Omit< FieldValidity, 'children' > ];\n\t\tif ( rule === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( rule.type === 'invalid' ) {\n\t\t\tif ( rule.message ) {\n\t\t\t\treturn rule.message;\n\t\t\t}\n\n\t\t\t// Provide default message for required validation (message is optional)\n\t\t\tif ( key === 'required' ) {\n\t\t\t\treturn 'A required field is empty';\n\t\t\t}\n\n\t\t\treturn 'Unidentified validation error';\n\t\t}\n\t}\n\n\t// Check children recursively\n\tif ( validity.children ) {\n\t\tfor ( const childValidity of Object.values( validity.children ) ) {\n\t\t\tconst childError = getFirstValidationError( childValidity );\n\t\t\tif ( childError ) {\n\t\t\t\treturn childError;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn undefined;\n}\n\nconst getFieldDefinition = < Item, >(\n\tfield: NormalizedFormField,\n\tfields: NormalizedField< Item >[]\n) => {\n\tconst fieldDefinition = fields.find( ( _field ) => _field.id === field.id );\n\n\tif ( ! fieldDefinition ) {\n\t\treturn fields.find( ( _field ) => {\n\t\t\tif ( !! field.children ) {\n\t\t\t\tconst simpleChildren = field.children.filter(\n\t\t\t\t\t( child ) => ! child.children\n\t\t\t\t);\n\n\t\t\t\tif ( simpleChildren.length === 0 ) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\treturn _field.id === simpleChildren[ 0 ].id;\n\t\t\t}\n\n\t\t\treturn _field.id === field.id;\n\t\t} );\n\t}\n\n\treturn fieldDefinition;\n};\n\n/**\n * Determines the field definition and summary fields for a panel layout.\n *\n * Summary fields are determined with the following priority:\n * 1. Use layout.summary fields if they exist\n * 2. Fall back to the field definition that matches the form field's id\n * 3. If the form field id doesn't exist, pick the first child field\n * 4. If no field definition is found, return empty summary fields\n *\n * @param layout - The normalized panel layout configuration\n * @param field - The form field to get definition for\n * @param fields - Array of normalized field definitions\n * @return Object containing fieldDefinition and summaryFields\n */\nconst getFieldDefinitionAndSummaryFields = < Item, >(\n\tlayout: NormalizedPanelLayout,\n\tfield: NormalizedFormField,\n\tfields: NormalizedField< Item >[]\n) => {\n\tconst summaryFields = getSummaryFields( layout.summary, fields );\n\tconst fieldDefinition = getFieldDefinition( field, fields );\n\n\tif ( summaryFields.length === 0 ) {\n\t\treturn {\n\t\t\tsummaryFields: fieldDefinition ? [ fieldDefinition ] : [],\n\t\t\tfieldDefinition,\n\t\t};\n\t}\n\n\treturn {\n\t\tsummaryFields,\n\t\tfieldDefinition,\n\t};\n};\n\nexport default function FormPanelField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\tvalidity,\n}: FieldLayoutProps< Item > ) {\n\tconst { fields } = useContext( DataFormContext );\n\tconst layout = field.layout as NormalizedPanelLayout;\n\n\t// Use internal state instead of a ref to make sure that the component\n\t// re-renders when the popover's anchor updates.\n\tconst [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >(\n\t\tnull\n\t);\n\n\t// Track if the panel has been opened (touched) to only show errors after interaction.\n\tconst [ touched, setTouched ] = useState( false );\n\tconst handleOpen = () => setTouched( true );\n\n\tconst { fieldDefinition, summaryFields } =\n\t\tgetFieldDefinitionAndSummaryFields( layout, field, fields );\n\n\tif ( ! fieldDefinition ) {\n\t\treturn null;\n\t}\n\n\tconst labelPosition = layout.labelPosition;\n\tconst errorMessage = getFirstValidationError( validity );\n\tconst showError = touched && !! errorMessage;\n\tconst labelClassName = clsx(\n\t\t'dataforms-layouts-panel__field-label',\n\t\t`dataforms-layouts-panel__field-label--label-position-${ labelPosition }`,\n\t\t{ 'has-error': showError }\n\t);\n\tconst fieldLabel = !! field.children ? field.label : fieldDefinition?.label;\n\n\tconst labelContent = showError ? (\n\t\t<Tooltip text={ errorMessage } placement=\"top\">\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"xs\"\n\t\t\t\tclassName=\"dataforms-layouts-panel__field-label-error-content\"\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t>\n\t\t\t\t<Icon icon={ errorIcon } size={ 16 } />\n\t\t\t\t<>{ fieldLabel }</>\n\t\t\t</Stack>\n\t\t</Tooltip>\n\t) : (\n\t\tfieldLabel\n\t);\n\n\tconst renderedControl =\n\t\tlayout.openAs === 'modal' ? (\n\t\t\t<PanelModal\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tfieldDefinition={ fieldDefinition }\n\t\t\t\tonOpen={ handleOpen }\n\t\t\t/>\n\t\t) : (\n\t\t\t<PanelDropdown\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalidity={ validity }\n\t\t\t\tlabelPosition={ labelPosition }\n\t\t\t\tsummaryFields={ summaryFields }\n\t\t\t\tfieldDefinition={ fieldDefinition }\n\t\t\t\tpopoverAnchor={ popoverAnchor }\n\t\t\t\tonOpen={ handleOpen }\n\t\t\t/>\n\t\t);\n\n\tif ( labelPosition === 'top' ) {\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tdirection=\"column\"\n\t\t\t\tclassName=\"dataforms-layouts-panel__field\"\n\t\t\t>\n\t\t\t\t<div\n\t\t\t\t\tclassName={ labelClassName }\n\t\t\t\t\tstyle={ { paddingBottom: 0 } }\n\t\t\t\t>\n\t\t\t\t\t{ labelContent }\n\t\t\t\t</div>\n\t\t\t\t<div className=\"dataforms-layouts-panel__field-control\">\n\t\t\t\t\t{ renderedControl }\n\t\t\t\t</div>\n\t\t\t</Stack>\n\t\t);\n\t}\n\n\tif ( labelPosition === 'none' ) {\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tdirection=\"row\"\n\t\t\t\tgap=\"xs\"\n\t\t\t\tclassName=\"dataforms-layouts-panel__field dataforms-layouts-panel__field--label-position-none\"\n\t\t\t>\n\t\t\t\t{ showError && (\n\t\t\t\t\t<Tooltip text={ errorMessage } placement=\"top\">\n\t\t\t\t\t\t<Icon\n\t\t\t\t\t\t\tclassName=\"dataforms-layouts-panel__field-label-error-content\"\n\t\t\t\t\t\t\ticon={ errorIcon }\n\t\t\t\t\t\t\tsize={ 16 }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t) }\n\t\t\t\t<div className=\"dataforms-layouts-panel__field-control\">\n\t\t\t\t\t{ renderedControl }\n\t\t\t\t</div>\n\t\t\t</Stack>\n\t\t);\n\t}\n\n\t// Defaults to label position side.\n\treturn (\n\t\t<Stack\n\t\t\tdirection=\"row\"\n\t\t\tgap=\"xs\"\n\t\t\tref={ setPopoverAnchor }\n\t\t\tclassName=\"dataforms-layouts-panel__field\"\n\t\t>\n\t\t\t<div className={ labelClassName }>{ labelContent }</div>\n\t\t\t<div className=\"dataforms-layouts-panel__field-control\">\n\t\t\t\t{ renderedControl }\n\t\t\t</div>\n\t\t</Stack>\n\t);\n}\n"],
5
- "mappings": ";AAGA,OAAO,UAAU;AAKjB,SAAS,MAAM,eAAe;AAC9B,SAAS,UAAU,kBAAkB;AACrC,SAAS,SAAS,iBAAiB;AACnC,SAAS,aAAa;AAYtB,OAAO,qBAAqB;AAC5B,OAAO,mBAAmB;AAC1B,OAAO,gBAAgB;AACvB,SAAS,wBAAwB;AAkJ9B,SAOC,UADA,KAND;AAhJH,SAAS,wBACR,UACqB;AACrB,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,gBAAgB,OAAO,KAAM,QAAS,EAAE;AAAA,IAC7C,CAAE,QAAS,QAAQ;AAAA,EACpB;AAEA,aAAY,OAAO,eAAgB;AAClC,UAAM,OAAO,SAAU,GAA+C;AACtE,QAAK,SAAS,QAAY;AACzB;AAAA,IACD;AAEA,QAAK,KAAK,SAAS,WAAY;AAC9B,UAAK,KAAK,SAAU;AACnB,eAAO,KAAK;AAAA,MACb;AAGA,UAAK,QAAQ,YAAa;AACzB,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AAGA,MAAK,SAAS,UAAW;AACxB,eAAY,iBAAiB,OAAO,OAAQ,SAAS,QAAS,GAAI;AACjE,YAAM,aAAa,wBAAyB,aAAc;AAC1D,UAAK,YAAa;AACjB,eAAO;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAM,qBAAqB,CAC1B,OACA,WACI;AACJ,QAAM,kBAAkB,OAAO,KAAM,CAAE,WAAY,OAAO,OAAO,MAAM,EAAG;AAE1E,MAAK,CAAE,iBAAkB;AACxB,WAAO,OAAO,KAAM,CAAE,WAAY;AACjC,UAAK,CAAC,CAAE,MAAM,UAAW;AACxB,cAAM,iBAAiB,MAAM,SAAS;AAAA,UACrC,CAAE,UAAW,C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;AAAA,MACN,WAAU;AAAA,MAEV;AAAA,4BAAC,SAAI,WAAY,gBAAmB,wBAAc;AAAA,QAClD,oBAAC,SAAI,WAAU,0CACZ,2BACH;AAAA;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { FieldLayoutProps, NormalizedPanelLayout } from '../../../types';\nimport PanelModal from './modal';\nimport PanelDropdown from './dropdown';\n\nexport default function FormPanelField< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\tvalidity,\n}: FieldLayoutProps< Item > ) {\n\tconst layout = field.layout as NormalizedPanelLayout;\n\n\tif ( layout.openAs === 'modal' ) {\n\t\treturn (\n\t\t\t<PanelModal\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\tonChange={ onChange }\n\t\t\t\tvalidity={ validity }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<PanelDropdown\n\t\t\tdata={ data }\n\t\t\tfield={ field }\n\t\t\tonChange={ onChange }\n\t\t\tvalidity={ validity }\n\t\t/>\n\t);\n}\n"],
5
+ "mappings": ";AAIA,OAAO,gBAAgB;AACvB,OAAO,mBAAmB;AAYvB;AAVY,SAAR,eAAyC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA8B;AAC7B,QAAM,SAAS,MAAM;AAErB,MAAK,OAAO,WAAW,SAAU;AAChC,WACC;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACD;AAAA,EAEF;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -6,21 +6,24 @@ import {
6
6
  Modal
7
7
  } from "@wordpress/components";
8
8
  import { __ } from "@wordpress/i18n";
9
- import { useContext, useState, useMemo } from "@wordpress/element";
10
- import { useFocusOnMount } from "@wordpress/compose";
9
+ import { useContext, useMemo, useRef, useState } from "@wordpress/element";
10
+ import { useFocusOnMount, useMergeRefs } from "@wordpress/compose";
11
11
  import { Stack } from "@wordpress/ui";
12
12
  import { DataFormLayout } from "../data-form-layout.mjs";
13
13
  import { DEFAULT_LAYOUT } from "../normalize-form.mjs";
14
14
  import SummaryButton from "./summary-button.mjs";
15
15
  import useFormValidity from "../../../hooks/use-form-validity.mjs";
16
+ import useReportValidity from "../../../hooks/use-report-validity.mjs";
16
17
  import DataFormContext from "../../dataform-context/index.mjs";
18
+ import useFieldFromFormField from "./utils/use-field-from-form-field.mjs";
17
19
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
18
20
  function ModalContent({
19
21
  data,
20
22
  field,
21
23
  onChange,
22
24
  fieldLabel,
23
- onClose
25
+ onClose,
26
+ touched
24
27
  }) {
25
28
  const { fields } = useContext(DataFormContext);
26
29
  const [changes, setChanges] = useState({});
@@ -65,6 +68,9 @@ function ModalContent({
65
68
  );
66
69
  };
67
70
  const focusOnMountRef = useFocusOnMount("firstInputElement");
71
+ const contentRef = useRef(null);
72
+ const mergedRef = useMergeRefs([focusOnMountRef, contentRef]);
73
+ useReportValidity(contentRef, touched);
68
74
  return /* @__PURE__ */ jsxs(
69
75
  Modal,
70
76
  {
@@ -74,20 +80,21 @@ function ModalContent({
74
80
  title: fieldLabel,
75
81
  size: "medium",
76
82
  children: [
77
- /* @__PURE__ */ jsx("div", { ref: focusOnMountRef, children: /* @__PURE__ */ jsx(
83
+ /* @__PURE__ */ jsx("div", { ref: mergedRef, children: /* @__PURE__ */ jsx(
78
84
  DataFormLayout,
79
85
  {
80
86
  data: modalData,
81
87
  form,
82
88
  onChange: handleOnChange,
83
89
  validity,
84
- children: (FieldLayout, childField, childFieldValidity) => /* @__PURE__ */ jsx(
90
+ children: (FieldLayout, childField, childFieldValidity, markWhenOptional) => /* @__PURE__ */ jsx(
85
91
  FieldLayout,
86
92
  {
87
93
  data: modalData,
88
94
  field: childField,
89
95
  onChange: handleOnChange,
90
96
  hideLabelFromVision: form.fields.length < 2,
97
+ markWhenOptional,
91
98
  validity: childFieldValidity
92
99
  },
93
100
  childField.id
@@ -99,7 +106,7 @@ function ModalContent({
99
106
  {
100
107
  direction: "row",
101
108
  className: "dataforms-layouts-panel__modal-footer",
102
- gap: "sm",
109
+ gap: "md",
103
110
  children: [
104
111
  /* @__PURE__ */ jsx(Spacer, { style: { flex: 1 } }),
105
112
  /* @__PURE__ */ jsx(
@@ -131,28 +138,30 @@ function PanelModal({
131
138
  data,
132
139
  field,
133
140
  onChange,
134
- labelPosition,
135
- summaryFields,
136
- fieldDefinition,
137
- onOpen
141
+ validity
138
142
  }) {
143
+ const [touched, setTouched] = useState(false);
139
144
  const [isOpen, setIsOpen] = useState(false);
140
- const fieldLabel = !!field.children ? field.label : fieldDefinition?.label;
145
+ const { fieldDefinition, fieldLabel, summaryFields } = useFieldFromFormField(field);
146
+ if (!fieldDefinition) {
147
+ return null;
148
+ }
149
+ const handleClose = () => {
150
+ setIsOpen(false);
151
+ setTouched(true);
152
+ };
141
153
  return /* @__PURE__ */ jsxs(Fragment, { children: [
142
154
  /* @__PURE__ */ jsx(
143
155
  SummaryButton,
144
156
  {
145
- summaryFields,
146
157
  data,
147
- labelPosition,
158
+ field,
148
159
  fieldLabel,
160
+ summaryFields,
161
+ validity,
162
+ touched,
149
163
  disabled: fieldDefinition.readOnly === true,
150
- onClick: () => {
151
- if (onOpen) {
152
- onOpen();
153
- }
154
- setIsOpen(true);
155
- },
164
+ onClick: () => setIsOpen(true),
156
165
  "aria-expanded": isOpen
157
166
  }
158
167
  ),
@@ -163,7 +172,8 @@ function PanelModal({
163
172
  field,
164
173
  onChange,
165
174
  fieldLabel: fieldLabel ?? "",
166
- onClose: () => setIsOpen(false)
175
+ onClose: handleClose,
176
+ touched
167
177
  }
168
178
  )
169
179
  ] });