@wordpress/dataviews 11.4.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 (415) hide show
  1. package/CHANGELOG.md +34 -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/date.cjs +23 -9
  12. package/build/components/dataform-controls/date.cjs.map +2 -2
  13. package/build/components/dataform-controls/datetime.cjs +11 -3
  14. package/build/components/dataform-controls/datetime.cjs.map +2 -2
  15. package/build/components/dataform-controls/email.cjs +2 -0
  16. package/build/components/dataform-controls/email.cjs.map +2 -2
  17. package/build/components/dataform-controls/index.cjs +3 -1
  18. package/build/components/dataform-controls/index.cjs.map +3 -3
  19. package/build/components/dataform-controls/password.cjs +2 -0
  20. package/build/components/dataform-controls/password.cjs.map +2 -2
  21. package/build/components/dataform-controls/radio.cjs +2 -0
  22. package/build/components/dataform-controls/radio.cjs.map +2 -2
  23. package/build/components/dataform-controls/select.cjs +2 -0
  24. package/build/components/dataform-controls/select.cjs.map +2 -2
  25. package/build/components/dataform-controls/telephone.cjs +2 -0
  26. package/build/components/dataform-controls/telephone.cjs.map +2 -2
  27. package/build/components/dataform-controls/text.cjs +2 -0
  28. package/build/components/dataform-controls/text.cjs.map +2 -2
  29. package/build/components/dataform-controls/textarea.cjs +2 -0
  30. package/build/components/dataform-controls/textarea.cjs.map +2 -2
  31. package/build/components/dataform-controls/toggle-group.cjs +2 -0
  32. package/build/components/dataform-controls/toggle-group.cjs.map +2 -2
  33. package/build/components/dataform-controls/toggle.cjs +2 -0
  34. package/build/components/dataform-controls/toggle.cjs.map +2 -2
  35. package/build/components/dataform-controls/url.cjs +2 -0
  36. package/build/components/dataform-controls/url.cjs.map +2 -2
  37. package/build/components/dataform-controls/utils/relative-date-control.cjs +1 -1
  38. package/build/components/dataform-controls/utils/relative-date-control.cjs.map +1 -1
  39. package/build/components/dataform-controls/utils/validated-input.cjs +2 -0
  40. package/build/components/dataform-controls/utils/validated-input.cjs.map +2 -2
  41. package/build/components/dataform-controls/utils/validated-number.cjs +2 -0
  42. package/build/components/dataform-controls/utils/validated-number.cjs.map +2 -2
  43. package/build/components/dataform-layouts/card/index.cjs +2 -0
  44. package/build/components/dataform-layouts/card/index.cjs.map +2 -2
  45. package/build/components/dataform-layouts/data-form-layout.cjs +11 -2
  46. package/build/components/dataform-layouts/data-form-layout.cjs.map +2 -2
  47. package/build/components/dataform-layouts/details/index.cjs +1 -1
  48. package/build/components/dataform-layouts/details/index.cjs.map +1 -1
  49. package/build/components/dataform-layouts/index.cjs +5 -5
  50. package/build/components/dataform-layouts/index.cjs.map +1 -1
  51. package/build/components/dataform-layouts/normalize-form.cjs +2 -1
  52. package/build/components/dataform-layouts/normalize-form.cjs.map +2 -2
  53. package/build/components/dataform-layouts/panel/dropdown.cjs +81 -66
  54. package/build/components/dataform-layouts/panel/dropdown.cjs.map +3 -3
  55. package/build/components/dataform-layouts/panel/index.cjs +13 -177
  56. package/build/components/dataform-layouts/panel/index.cjs.map +3 -3
  57. package/build/components/dataform-layouts/panel/modal.cjs +15 -11
  58. package/build/components/dataform-layouts/panel/modal.cjs.map +3 -3
  59. package/build/components/dataform-layouts/panel/summary-button.cjs +125 -56
  60. package/build/components/dataform-layouts/panel/summary-button.cjs.map +3 -3
  61. package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs +59 -0
  62. package/build/components/dataform-layouts/panel/utils/get-first-validation-error.cjs.map +7 -0
  63. package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs +45 -0
  64. package/build/components/dataform-layouts/panel/utils/get-label-classname.cjs.map +7 -0
  65. package/build/components/dataform-layouts/panel/utils/get-label-content.cjs +36 -0
  66. package/build/components/dataform-layouts/panel/utils/get-label-content.cjs.map +7 -0
  67. package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs +77 -0
  68. package/build/components/dataform-layouts/panel/utils/use-field-from-form-field.cjs.map +7 -0
  69. package/build/components/dataform-layouts/regular/index.cjs +6 -3
  70. package/build/components/dataform-layouts/regular/index.cjs.map +2 -2
  71. package/build/components/dataform-layouts/row/index.cjs +5 -2
  72. package/build/components/dataform-layouts/row/index.cjs.map +2 -2
  73. package/build/components/dataviews-bulk-actions/index.cjs +4 -4
  74. package/build/components/dataviews-bulk-actions/index.cjs.map +2 -2
  75. package/build/components/dataviews-context/index.cjs.map +2 -2
  76. package/build/components/dataviews-filters/filter.cjs +1 -1
  77. package/build/components/dataviews-filters/filter.cjs.map +1 -1
  78. package/build/components/dataviews-filters/filters.cjs +1 -1
  79. package/build/components/dataviews-filters/filters.cjs.map +1 -1
  80. package/build/components/dataviews-filters/search-widget.cjs +25 -11
  81. package/build/components/dataviews-filters/search-widget.cjs.map +2 -2
  82. package/build/components/dataviews-filters/toggle.cjs.map +1 -1
  83. package/build/components/dataviews-footer/index.cjs +1 -1
  84. package/build/components/dataviews-footer/index.cjs.map +1 -1
  85. package/build/components/dataviews-layouts/activity/activity-item.cjs +4 -4
  86. package/build/components/dataviews-layouts/activity/activity-item.cjs.map +1 -1
  87. package/build/components/dataviews-layouts/activity/index.cjs +1 -1
  88. package/build/components/dataviews-layouts/activity/index.cjs.map +1 -1
  89. package/build/components/dataviews-layouts/grid/composite-grid.cjs +27 -38
  90. package/build/components/dataviews-layouts/grid/composite-grid.cjs.map +2 -2
  91. package/build/components/dataviews-layouts/grid/index.cjs +2 -2
  92. package/build/components/dataviews-layouts/grid/index.cjs.map +1 -1
  93. package/build/components/dataviews-layouts/list/index.cjs +7 -8
  94. package/build/components/dataviews-layouts/list/index.cjs.map +2 -2
  95. package/build/components/dataviews-layouts/picker-grid/index.cjs +5 -5
  96. package/build/components/dataviews-layouts/picker-grid/index.cjs.map +2 -2
  97. package/build/components/dataviews-layouts/picker-table/index.cjs +1 -1
  98. package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
  99. package/build/components/dataviews-layouts/table/column-primary.cjs +1 -1
  100. package/build/components/dataviews-layouts/table/column-primary.cjs.map +1 -1
  101. package/build/components/dataviews-layouts/table/index.cjs +1 -1
  102. package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
  103. package/build/components/dataviews-layouts/utils/item-click-wrapper.cjs.map +2 -2
  104. package/build/components/dataviews-pagination/index.cjs +3 -3
  105. package/build/components/dataviews-pagination/index.cjs.map +2 -2
  106. package/build/components/dataviews-picker-footer/index.cjs +3 -3
  107. package/build/components/dataviews-picker-footer/index.cjs.map +2 -2
  108. package/build/components/dataviews-view-config/index.cjs +74 -57
  109. package/build/components/dataviews-view-config/index.cjs.map +3 -3
  110. package/build/components/dataviews-view-config/properties-section.cjs +1 -1
  111. package/build/components/dataviews-view-config/properties-section.cjs.map +1 -1
  112. package/build/dataviews/index.cjs +7 -5
  113. package/build/dataviews/index.cjs.map +2 -2
  114. package/build/dataviews-picker/index.cjs +3 -3
  115. package/build/dataviews-picker/index.cjs.map +2 -2
  116. package/build/hooks/use-form-validity.cjs +61 -28
  117. package/build/hooks/use-form-validity.cjs.map +2 -2
  118. package/build/types/dataform.cjs.map +1 -1
  119. package/build/types/field-api.cjs.map +1 -1
  120. package/build-module/components/dataform-controls/adaptive-select.mjs +21 -0
  121. package/build-module/components/dataform-controls/adaptive-select.mjs.map +7 -0
  122. package/build-module/components/dataform-controls/array.mjs +2 -0
  123. package/build-module/components/dataform-controls/array.mjs.map +2 -2
  124. package/build-module/components/dataform-controls/checkbox.mjs +2 -0
  125. package/build-module/components/dataform-controls/checkbox.mjs.map +2 -2
  126. package/build-module/components/dataform-controls/color.mjs +26 -31
  127. package/build-module/components/dataform-controls/color.mjs.map +2 -2
  128. package/build-module/components/dataform-controls/date.mjs +23 -9
  129. package/build-module/components/dataform-controls/date.mjs.map +2 -2
  130. package/build-module/components/dataform-controls/datetime.mjs +11 -3
  131. package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
  132. package/build-module/components/dataform-controls/email.mjs +2 -0
  133. package/build-module/components/dataform-controls/email.mjs.map +2 -2
  134. package/build-module/components/dataform-controls/index.mjs +3 -1
  135. package/build-module/components/dataform-controls/index.mjs.map +2 -2
  136. package/build-module/components/dataform-controls/password.mjs +2 -0
  137. package/build-module/components/dataform-controls/password.mjs.map +2 -2
  138. package/build-module/components/dataform-controls/radio.mjs +2 -0
  139. package/build-module/components/dataform-controls/radio.mjs.map +2 -2
  140. package/build-module/components/dataform-controls/select.mjs +2 -0
  141. package/build-module/components/dataform-controls/select.mjs.map +2 -2
  142. package/build-module/components/dataform-controls/telephone.mjs +2 -0
  143. package/build-module/components/dataform-controls/telephone.mjs.map +2 -2
  144. package/build-module/components/dataform-controls/text.mjs +2 -0
  145. package/build-module/components/dataform-controls/text.mjs.map +2 -2
  146. package/build-module/components/dataform-controls/textarea.mjs +2 -0
  147. package/build-module/components/dataform-controls/textarea.mjs.map +2 -2
  148. package/build-module/components/dataform-controls/toggle-group.mjs +2 -0
  149. package/build-module/components/dataform-controls/toggle-group.mjs.map +2 -2
  150. package/build-module/components/dataform-controls/toggle.mjs +2 -0
  151. package/build-module/components/dataform-controls/toggle.mjs.map +2 -2
  152. package/build-module/components/dataform-controls/url.mjs +2 -0
  153. package/build-module/components/dataform-controls/url.mjs.map +2 -2
  154. package/build-module/components/dataform-controls/utils/relative-date-control.mjs +1 -1
  155. package/build-module/components/dataform-controls/utils/relative-date-control.mjs.map +1 -1
  156. package/build-module/components/dataform-controls/utils/validated-input.mjs +2 -0
  157. package/build-module/components/dataform-controls/utils/validated-input.mjs.map +2 -2
  158. package/build-module/components/dataform-controls/utils/validated-number.mjs +2 -0
  159. package/build-module/components/dataform-controls/utils/validated-number.mjs.map +2 -2
  160. package/build-module/components/dataform-layouts/card/index.mjs +2 -0
  161. package/build-module/components/dataform-layouts/card/index.mjs.map +2 -2
  162. package/build-module/components/dataform-layouts/data-form-layout.mjs +12 -3
  163. package/build-module/components/dataform-layouts/data-form-layout.mjs.map +2 -2
  164. package/build-module/components/dataform-layouts/details/index.mjs +1 -1
  165. package/build-module/components/dataform-layouts/details/index.mjs.map +1 -1
  166. package/build-module/components/dataform-layouts/index.mjs +5 -5
  167. package/build-module/components/dataform-layouts/index.mjs.map +1 -1
  168. package/build-module/components/dataform-layouts/normalize-form.mjs +2 -1
  169. package/build-module/components/dataform-layouts/normalize-form.mjs.map +2 -2
  170. package/build-module/components/dataform-layouts/panel/dropdown.mjs +83 -68
  171. package/build-module/components/dataform-layouts/panel/dropdown.mjs.map +2 -2
  172. package/build-module/components/dataform-layouts/panel/index.mjs +14 -178
  173. package/build-module/components/dataform-layouts/panel/index.mjs.map +2 -2
  174. package/build-module/components/dataform-layouts/panel/modal.mjs +15 -11
  175. package/build-module/components/dataform-layouts/panel/modal.mjs.map +2 -2
  176. package/build-module/components/dataform-layouts/panel/summary-button.mjs +117 -58
  177. package/build-module/components/dataform-layouts/panel/summary-button.mjs.map +2 -2
  178. package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs +38 -0
  179. package/build-module/components/dataform-layouts/panel/utils/get-first-validation-error.mjs.map +7 -0
  180. package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs +14 -0
  181. package/build-module/components/dataform-layouts/panel/utils/get-label-classname.mjs.map +7 -0
  182. package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs +15 -0
  183. package/build-module/components/dataform-layouts/panel/utils/get-label-content.mjs.map +7 -0
  184. package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs +46 -0
  185. package/build-module/components/dataform-layouts/panel/utils/use-field-from-form-field.mjs.map +7 -0
  186. package/build-module/components/dataform-layouts/regular/index.mjs +6 -3
  187. package/build-module/components/dataform-layouts/regular/index.mjs.map +2 -2
  188. package/build-module/components/dataform-layouts/row/index.mjs +5 -2
  189. package/build-module/components/dataform-layouts/row/index.mjs.map +2 -2
  190. package/build-module/components/dataviews-bulk-actions/index.mjs +4 -4
  191. package/build-module/components/dataviews-bulk-actions/index.mjs.map +2 -2
  192. package/build-module/components/dataviews-context/index.mjs.map +2 -2
  193. package/build-module/components/dataviews-filters/filter.mjs +1 -1
  194. package/build-module/components/dataviews-filters/filter.mjs.map +1 -1
  195. package/build-module/components/dataviews-filters/filters.mjs +1 -1
  196. package/build-module/components/dataviews-filters/filters.mjs.map +1 -1
  197. package/build-module/components/dataviews-filters/search-widget.mjs +25 -11
  198. package/build-module/components/dataviews-filters/search-widget.mjs.map +2 -2
  199. package/build-module/components/dataviews-filters/toggle.mjs.map +1 -1
  200. package/build-module/components/dataviews-footer/index.mjs +1 -1
  201. package/build-module/components/dataviews-footer/index.mjs.map +1 -1
  202. package/build-module/components/dataviews-layouts/activity/activity-item.mjs +4 -4
  203. package/build-module/components/dataviews-layouts/activity/activity-item.mjs.map +1 -1
  204. package/build-module/components/dataviews-layouts/activity/index.mjs +1 -1
  205. package/build-module/components/dataviews-layouts/activity/index.mjs.map +1 -1
  206. package/build-module/components/dataviews-layouts/grid/composite-grid.mjs +27 -38
  207. package/build-module/components/dataviews-layouts/grid/composite-grid.mjs.map +2 -2
  208. package/build-module/components/dataviews-layouts/grid/index.mjs +2 -2
  209. package/build-module/components/dataviews-layouts/grid/index.mjs.map +1 -1
  210. package/build-module/components/dataviews-layouts/list/index.mjs +7 -8
  211. package/build-module/components/dataviews-layouts/list/index.mjs.map +2 -2
  212. package/build-module/components/dataviews-layouts/picker-grid/index.mjs +5 -5
  213. package/build-module/components/dataviews-layouts/picker-grid/index.mjs.map +2 -2
  214. package/build-module/components/dataviews-layouts/picker-table/index.mjs +1 -1
  215. package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
  216. package/build-module/components/dataviews-layouts/table/column-primary.mjs +1 -1
  217. package/build-module/components/dataviews-layouts/table/column-primary.mjs.map +1 -1
  218. package/build-module/components/dataviews-layouts/table/index.mjs +1 -1
  219. package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
  220. package/build-module/components/dataviews-layouts/utils/item-click-wrapper.mjs.map +2 -2
  221. package/build-module/components/dataviews-pagination/index.mjs +3 -3
  222. package/build-module/components/dataviews-pagination/index.mjs.map +2 -2
  223. package/build-module/components/dataviews-picker-footer/index.mjs +3 -3
  224. package/build-module/components/dataviews-picker-footer/index.mjs.map +2 -2
  225. package/build-module/components/dataviews-view-config/index.mjs +74 -59
  226. package/build-module/components/dataviews-view-config/index.mjs.map +2 -2
  227. package/build-module/components/dataviews-view-config/properties-section.mjs +1 -1
  228. package/build-module/components/dataviews-view-config/properties-section.mjs.map +1 -1
  229. package/build-module/dataviews/index.mjs +7 -5
  230. package/build-module/dataviews/index.mjs.map +2 -2
  231. package/build-module/dataviews-picker/index.mjs +3 -3
  232. package/build-module/dataviews-picker/index.mjs.map +2 -2
  233. package/build-module/hooks/use-form-validity.mjs +61 -28
  234. package/build-module/hooks/use-form-validity.mjs.map +2 -2
  235. package/build-style/style-rtl.css +144 -217
  236. package/build-style/style.css +144 -217
  237. package/build-types/components/dataform-controls/adaptive-select.d.ts +6 -0
  238. package/build-types/components/dataform-controls/adaptive-select.d.ts.map +1 -0
  239. package/build-types/components/dataform-controls/array.d.ts +1 -1
  240. package/build-types/components/dataform-controls/array.d.ts.map +1 -1
  241. package/build-types/components/dataform-controls/checkbox.d.ts +1 -1
  242. package/build-types/components/dataform-controls/checkbox.d.ts.map +1 -1
  243. package/build-types/components/dataform-controls/color.d.ts +1 -1
  244. package/build-types/components/dataform-controls/color.d.ts.map +1 -1
  245. package/build-types/components/dataform-controls/date.d.ts +1 -1
  246. package/build-types/components/dataform-controls/date.d.ts.map +1 -1
  247. package/build-types/components/dataform-controls/datetime.d.ts +1 -1
  248. package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
  249. package/build-types/components/dataform-controls/email.d.ts +1 -1
  250. package/build-types/components/dataform-controls/email.d.ts.map +1 -1
  251. package/build-types/components/dataform-controls/index.d.ts.map +1 -1
  252. package/build-types/components/dataform-controls/password.d.ts +1 -1
  253. package/build-types/components/dataform-controls/password.d.ts.map +1 -1
  254. package/build-types/components/dataform-controls/radio.d.ts +1 -1
  255. package/build-types/components/dataform-controls/radio.d.ts.map +1 -1
  256. package/build-types/components/dataform-controls/select.d.ts +1 -1
  257. package/build-types/components/dataform-controls/select.d.ts.map +1 -1
  258. package/build-types/components/dataform-controls/telephone.d.ts +1 -1
  259. package/build-types/components/dataform-controls/telephone.d.ts.map +1 -1
  260. package/build-types/components/dataform-controls/text.d.ts +1 -1
  261. package/build-types/components/dataform-controls/text.d.ts.map +1 -1
  262. package/build-types/components/dataform-controls/textarea.d.ts +1 -1
  263. package/build-types/components/dataform-controls/textarea.d.ts.map +1 -1
  264. package/build-types/components/dataform-controls/toggle-group.d.ts +1 -1
  265. package/build-types/components/dataform-controls/toggle-group.d.ts.map +1 -1
  266. package/build-types/components/dataform-controls/toggle.d.ts +1 -1
  267. package/build-types/components/dataform-controls/toggle.d.ts.map +1 -1
  268. package/build-types/components/dataform-controls/url.d.ts +1 -1
  269. package/build-types/components/dataform-controls/url.d.ts.map +1 -1
  270. package/build-types/components/dataform-controls/utils/validated-input.d.ts +1 -1
  271. package/build-types/components/dataform-controls/utils/validated-input.d.ts.map +1 -1
  272. package/build-types/components/dataform-controls/utils/validated-number.d.ts +1 -1
  273. package/build-types/components/dataform-controls/utils/validated-number.d.ts.map +1 -1
  274. package/build-types/components/dataform-layouts/card/index.d.ts +1 -1
  275. package/build-types/components/dataform-layouts/card/index.d.ts.map +1 -1
  276. package/build-types/components/dataform-layouts/data-form-layout.d.ts +2 -1
  277. package/build-types/components/dataform-layouts/data-form-layout.d.ts.map +1 -1
  278. package/build-types/components/dataform-layouts/normalize-form.d.ts.map +1 -1
  279. package/build-types/components/dataform-layouts/panel/dropdown.d.ts +2 -13
  280. package/build-types/components/dataform-layouts/panel/dropdown.d.ts.map +1 -1
  281. package/build-types/components/dataform-layouts/panel/index.d.ts +1 -1
  282. package/build-types/components/dataform-layouts/panel/index.d.ts.map +1 -1
  283. package/build-types/components/dataform-layouts/panel/modal.d.ts +2 -11
  284. package/build-types/components/dataform-layouts/panel/modal.d.ts.map +1 -1
  285. package/build-types/components/dataform-layouts/panel/summary-button.d.ts +6 -5
  286. package/build-types/components/dataform-layouts/panel/summary-button.d.ts.map +1 -1
  287. package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts +4 -0
  288. package/build-types/components/dataform-layouts/panel/utils/get-first-validation-error.d.ts.map +1 -0
  289. package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts +4 -0
  290. package/build-types/components/dataform-layouts/panel/utils/get-label-classname.d.ts.map +1 -0
  291. package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts +3 -0
  292. package/build-types/components/dataform-layouts/panel/utils/get-label-content.d.ts.map +1 -0
  293. package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts +23 -0
  294. package/build-types/components/dataform-layouts/panel/utils/use-field-from-form-field.d.ts.map +1 -0
  295. package/build-types/components/dataform-layouts/regular/index.d.ts +1 -1
  296. package/build-types/components/dataform-layouts/regular/index.d.ts.map +1 -1
  297. package/build-types/components/dataform-layouts/row/index.d.ts +1 -1
  298. package/build-types/components/dataform-layouts/row/index.d.ts.map +1 -1
  299. package/build-types/components/dataviews-context/index.d.ts +1 -0
  300. package/build-types/components/dataviews-context/index.d.ts.map +1 -1
  301. package/build-types/components/dataviews-filters/filter.d.ts +1 -1
  302. package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
  303. package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
  304. package/build-types/components/dataviews-layouts/list/index.d.ts.map +1 -1
  305. package/build-types/components/dataviews-layouts/utils/item-click-wrapper.d.ts +1 -0
  306. package/build-types/components/dataviews-layouts/utils/item-click-wrapper.d.ts.map +1 -1
  307. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  308. package/build-types/dataform/stories/index.story.d.ts +9 -1
  309. package/build-types/dataform/stories/index.story.d.ts.map +1 -1
  310. package/build-types/dataform/stories/layout-panel.d.ts +3 -1
  311. package/build-types/dataform/stories/layout-panel.d.ts.map +1 -1
  312. package/build-types/dataviews/index.d.ts +2 -1
  313. package/build-types/dataviews/index.d.ts.map +1 -1
  314. package/build-types/dataviews/stories/fixtures.d.ts +1 -0
  315. package/build-types/dataviews/stories/fixtures.d.ts.map +1 -1
  316. package/build-types/dataviews/stories/index.story.d.ts +14 -2
  317. package/build-types/dataviews/stories/index.story.d.ts.map +1 -1
  318. package/build-types/dataviews/stories/layout-activity.d.ts +2 -1
  319. package/build-types/dataviews/stories/layout-activity.d.ts.map +1 -1
  320. package/build-types/dataviews/stories/layout-list.d.ts +2 -1
  321. package/build-types/dataviews/stories/layout-list.d.ts.map +1 -1
  322. package/build-types/field-types/stories/index.story.d.ts +42 -16
  323. package/build-types/field-types/stories/index.story.d.ts.map +1 -1
  324. package/build-types/hooks/use-form-validity.d.ts.map +1 -1
  325. package/build-types/types/dataform.d.ts +4 -0
  326. package/build-types/types/dataform.d.ts.map +1 -1
  327. package/build-types/types/field-api.d.ts +4 -0
  328. package/build-types/types/field-api.d.ts.map +1 -1
  329. package/build-wp/index.js +2689 -2167
  330. package/package.json +21 -21
  331. package/src/components/dataform-controls/adaptive-select.tsx +23 -0
  332. package/src/components/dataform-controls/array.tsx +2 -0
  333. package/src/components/dataform-controls/checkbox.tsx +2 -0
  334. package/src/components/dataform-controls/color.tsx +31 -36
  335. package/src/components/dataform-controls/date.tsx +24 -16
  336. package/src/components/dataform-controls/datetime.tsx +16 -6
  337. package/src/components/dataform-controls/email.tsx +2 -0
  338. package/src/components/dataform-controls/index.tsx +3 -1
  339. package/src/components/dataform-controls/password.tsx +2 -0
  340. package/src/components/dataform-controls/radio.tsx +2 -0
  341. package/src/components/dataform-controls/select.tsx +2 -0
  342. package/src/components/dataform-controls/style.scss +4 -0
  343. package/src/components/dataform-controls/telephone.tsx +2 -0
  344. package/src/components/dataform-controls/text.tsx +2 -0
  345. package/src/components/dataform-controls/textarea.tsx +2 -0
  346. package/src/components/dataform-controls/toggle-group.tsx +2 -0
  347. package/src/components/dataform-controls/toggle.tsx +2 -0
  348. package/src/components/dataform-controls/url.tsx +2 -0
  349. package/src/components/dataform-controls/utils/relative-date-control.tsx +1 -1
  350. package/src/components/dataform-controls/utils/validated-input.tsx +2 -0
  351. package/src/components/dataform-controls/utils/validated-number.tsx +2 -0
  352. package/src/components/dataform-layouts/card/index.tsx +2 -0
  353. package/src/components/dataform-layouts/data-form-layout.tsx +18 -4
  354. package/src/components/dataform-layouts/details/index.tsx +1 -1
  355. package/src/components/dataform-layouts/index.tsx +5 -5
  356. package/src/components/dataform-layouts/normalize-form.ts +1 -0
  357. package/src/components/dataform-layouts/panel/dropdown.tsx +97 -96
  358. package/src/components/dataform-layouts/panel/index.tsx +10 -245
  359. package/src/components/dataform-layouts/panel/modal.tsx +24 -22
  360. package/src/components/dataform-layouts/panel/style.scss +109 -27
  361. package/src/components/dataform-layouts/panel/summary-button.tsx +140 -62
  362. package/src/components/dataform-layouts/panel/utils/get-first-validation-error.ts +47 -0
  363. package/src/components/dataform-layouts/panel/utils/get-label-classname.ts +18 -0
  364. package/src/components/dataform-layouts/panel/utils/get-label-content.tsx +26 -0
  365. package/src/components/dataform-layouts/panel/utils/use-field-from-form-field.ts +78 -0
  366. package/src/components/dataform-layouts/regular/index.tsx +8 -3
  367. package/src/components/dataform-layouts/regular/style.scss +10 -0
  368. package/src/components/dataform-layouts/row/index.tsx +5 -2
  369. package/src/components/dataform-layouts/test/normalize-form.ts +5 -0
  370. package/src/components/dataviews-bulk-actions/index.tsx +4 -4
  371. package/src/components/dataviews-context/index.ts +1 -0
  372. package/src/components/dataviews-filters/filter.tsx +2 -2
  373. package/src/components/dataviews-filters/filters.tsx +1 -1
  374. package/src/components/dataviews-filters/search-widget.tsx +10 -2
  375. package/src/components/dataviews-filters/style.scss +8 -0
  376. package/src/components/dataviews-filters/toggle.tsx +1 -1
  377. package/src/components/dataviews-footer/index.tsx +1 -1
  378. package/src/components/dataviews-layouts/activity/activity-item.tsx +4 -4
  379. package/src/components/dataviews-layouts/activity/index.tsx +1 -1
  380. package/src/components/dataviews-layouts/grid/composite-grid.tsx +35 -35
  381. package/src/components/dataviews-layouts/grid/index.tsx +2 -2
  382. package/src/components/dataviews-layouts/grid/style.scss +15 -1
  383. package/src/components/dataviews-layouts/list/index.tsx +7 -8
  384. package/src/components/dataviews-layouts/list/style.scss +1 -0
  385. package/src/components/dataviews-layouts/picker-grid/index.tsx +5 -5
  386. package/src/components/dataviews-layouts/picker-table/index.tsx +1 -1
  387. package/src/components/dataviews-layouts/table/column-primary.tsx +1 -1
  388. package/src/components/dataviews-layouts/table/index.tsx +1 -1
  389. package/src/components/dataviews-layouts/utils/item-click-wrapper.tsx +1 -0
  390. package/src/components/dataviews-pagination/index.tsx +3 -3
  391. package/src/components/dataviews-picker-footer/index.tsx +3 -3
  392. package/src/components/dataviews-view-config/index.tsx +61 -50
  393. package/src/components/dataviews-view-config/properties-section.tsx +1 -1
  394. package/src/components/dataviews-view-config/style.scss +21 -0
  395. package/src/dataform/stories/content.story.tsx +5 -5
  396. package/src/dataform/stories/index.story.tsx +6 -1
  397. package/src/dataform/stories/layout-panel.tsx +19 -2
  398. package/src/dataform/stories/validation.tsx +2 -2
  399. package/src/dataform/test/dataform.tsx +2 -2
  400. package/src/dataviews/index.tsx +7 -4
  401. package/src/dataviews/stories/empty.tsx +1 -1
  402. package/src/dataviews/stories/fixtures.tsx +93 -4
  403. package/src/dataviews/stories/free-composition.tsx +6 -6
  404. package/src/dataviews/stories/index.story.tsx +12 -0
  405. package/src/dataviews/stories/layout-activity.tsx +6 -3
  406. package/src/dataviews/stories/layout-list.tsx +3 -0
  407. package/src/dataviews-picker/index.tsx +4 -4
  408. package/src/dataviews-picker/stories/fixtures.tsx +2 -2
  409. package/src/dataviews-picker/stories/index.story.tsx +1 -1
  410. package/src/field-types/stories/index.story.tsx +99 -5
  411. package/src/hooks/test/use-form-validity.ts +303 -178
  412. package/src/hooks/use-form-validity.ts +85 -36
  413. package/src/style.scss +0 -2
  414. package/src/types/dataform.ts +5 -0
  415. package/src/types/field-api.ts +4 -0
@@ -88,6 +88,7 @@ export default function ValidatedNumber< Item >( {
88
88
  field,
89
89
  onChange,
90
90
  hideLabelFromVision,
91
+ markWhenOptional,
91
92
  operator,
92
93
  validity,
93
94
  }: DataFormControlProps< Item > ) {
@@ -149,6 +150,7 @@ export default function ValidatedNumber< Item >( {
149
150
  return (
150
151
  <ValidatedNumberControl
151
152
  required={ !! isValid.required }
153
+ markWhenOptional={ markWhenOptional }
152
154
  customValidity={ getCustomValidity( isValid, validity ) }
153
155
  label={ label }
154
156
  help={ description }
@@ -183,6 +183,7 @@ export default function FormCardField< Item >( {
183
183
  field,
184
184
  onChange,
185
185
  hideLabelFromVision,
186
+ markWhenOptional,
186
187
  validity,
187
188
  }: FieldLayoutProps< Item > ) {
188
189
  const { fields } = useContext( DataFormContext );
@@ -347,6 +348,7 @@ export default function FormCardField< Item >( {
347
348
  hideLabelFromVision={
348
349
  hideLabelFromVision || withHeader
349
350
  }
351
+ markWhenOptional={ markWhenOptional }
350
352
  validity={ validity }
351
353
  />
352
354
  </CardBody>
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useContext } from '@wordpress/element';
4
+ import { useContext, useMemo } from '@wordpress/element';
5
5
  import { Stack } from '@wordpress/ui';
6
6
 
7
7
  /**
@@ -17,7 +17,7 @@ import { getFormFieldLayout } from './index';
17
17
  import DataFormContext from '../dataform-context';
18
18
 
19
19
  const DEFAULT_WRAPPER = ( { children }: { children: React.ReactNode } ) => (
20
- <Stack direction="column" className="dataforms-layouts__wrapper" gap="md">
20
+ <Stack direction="column" className="dataforms-layouts__wrapper" gap="lg">
21
21
  { children }
22
22
  </Stack>
23
23
  );
@@ -40,15 +40,27 @@ export function DataFormLayout< Item >( {
40
40
  field: NormalizedFormField;
41
41
  onChange: ( value: any ) => void;
42
42
  hideLabelFromVision?: boolean;
43
+ markWhenOptional?: boolean;
43
44
  validity?: FieldValidity;
44
45
  } ) => React.JSX.Element | null,
45
46
  childField: NormalizedFormField,
46
- childFieldValidity?: FieldValidity
47
+ childFieldValidity?: FieldValidity,
48
+ markWhenOptional?: boolean
47
49
  ) => React.JSX.Element;
48
50
  as?: React.ComponentType< { children: React.ReactNode } >;
49
51
  } ) {
50
52
  const { fields: fieldDefinitions } = useContext( DataFormContext );
51
53
 
54
+ // Auto-compute: mark the minority of fields
55
+ // When counts are equal, mark required fields
56
+ const markWhenOptional = useMemo( () => {
57
+ const requiredCount = fieldDefinitions.filter(
58
+ ( f ) => !! f.isValid?.required
59
+ ).length;
60
+ const optionalCount = fieldDefinitions.length - requiredCount;
61
+ return requiredCount > optionalCount;
62
+ }, [ fieldDefinitions ] );
63
+
52
64
  function getFieldDefinition( field: NormalizedFormField ) {
53
65
  return fieldDefinitions.find(
54
66
  ( fieldDefinition ) => fieldDefinition.id === field.id
@@ -86,7 +98,8 @@ export function DataFormLayout< Item >( {
86
98
  return children(
87
99
  FieldLayout,
88
100
  formField,
89
- validity?.[ formField.id ]
101
+ validity?.[ formField.id ],
102
+ markWhenOptional
90
103
  );
91
104
  }
92
105
 
@@ -96,6 +109,7 @@ export function DataFormLayout< Item >( {
96
109
  data={ data }
97
110
  field={ formField }
98
111
  onChange={ onChange }
112
+ markWhenOptional={ markWhenOptional }
99
113
  validity={ validity?.[ formField.id ] }
100
114
  />
101
115
  );
@@ -109,7 +109,7 @@ export default function FormDetailsField< Item >( {
109
109
  <Stack
110
110
  direction="row"
111
111
  align="center"
112
- gap="sm"
112
+ gap="md"
113
113
  className="dataforms-layouts-details__summary-content"
114
114
  >
115
115
  { summaryContent }
@@ -21,7 +21,7 @@ const FORM_FIELD_LAYOUTS = [
21
21
  <Stack
22
22
  direction="column"
23
23
  className="dataforms-layouts__wrapper"
24
- gap="md"
24
+ gap="lg"
25
25
  >
26
26
  { children }
27
27
  </Stack>
@@ -34,7 +34,7 @@ const FORM_FIELD_LAYOUTS = [
34
34
  <Stack
35
35
  direction="column"
36
36
  className="dataforms-layouts__wrapper"
37
- gap="xs"
37
+ gap="md"
38
38
  >
39
39
  { children }
40
40
  </Stack>
@@ -47,7 +47,7 @@ const FORM_FIELD_LAYOUTS = [
47
47
  <Stack
48
48
  direction="column"
49
49
  className="dataforms-layouts__wrapper"
50
- gap="lg"
50
+ gap="xl"
51
51
  >
52
52
  { children }
53
53
  </Stack>
@@ -66,12 +66,12 @@ const FORM_FIELD_LAYOUTS = [
66
66
  <Stack
67
67
  direction="column"
68
68
  className="dataforms-layouts__wrapper"
69
- gap="md"
69
+ gap="lg"
70
70
  >
71
71
  <div className="dataforms-layouts-row__field">
72
72
  <Stack
73
73
  direction="row"
74
- gap="md"
74
+ gap="lg"
75
75
  align={ ( layout as NormalizedRowLayout ).alignment }
76
76
  >
77
77
  { children }
@@ -60,6 +60,7 @@ function normalizeLayout( layout?: Layout ): NormalizedLayout {
60
60
  labelPosition: layout?.labelPosition ?? 'side',
61
61
  openAs: layout?.openAs ?? 'dropdown',
62
62
  summary: normalizedSummary,
63
+ editVisibility: layout?.editVisibility ?? 'on-hover',
63
64
  } satisfies NormalizedPanelLayout;
64
65
  } else if ( layout?.type === 'card' ) {
65
66
  if ( layout.withHeader === false ) {
@@ -8,25 +8,24 @@ import {
8
8
  Button,
9
9
  } from '@wordpress/components';
10
10
  import { __ } from '@wordpress/i18n';
11
- import { useMemo, useRef } from '@wordpress/element';
11
+ import { useMemo, useRef, useState } from '@wordpress/element';
12
12
  import { closeSmall } from '@wordpress/icons';
13
- import { useFocusOnMount } from '@wordpress/compose';
13
+ import { __experimentalUseDialog as useDialog } from '@wordpress/compose';
14
14
  import { Stack } from '@wordpress/ui';
15
15
 
16
16
  /**
17
17
  * Internal dependencies
18
18
  */
19
19
  import type {
20
- FieldValidity,
20
+ FieldLayoutProps,
21
21
  NormalizedForm,
22
- NormalizedFormField,
23
22
  FormValidity,
24
- NormalizedField,
25
23
  } from '../../../types';
26
24
  import { DataFormLayout } from '../data-form-layout';
27
25
  import { DEFAULT_LAYOUT } from '../normalize-form';
28
26
  import SummaryButton from './summary-button';
29
27
  import useReportValidity from '../../../hooks/use-report-validity';
28
+ import useFieldFromFormField from './utils/use-field-from-form-field';
30
29
 
31
30
  function DropdownHeader( {
32
31
  title,
@@ -39,9 +38,9 @@ function DropdownHeader( {
39
38
  <Stack
40
39
  direction="column"
41
40
  className="dataforms-layouts-panel__dropdown-header"
42
- gap="md"
41
+ gap="lg"
43
42
  >
44
- <Stack direction="row" gap="xs" align="center">
43
+ <Stack direction="row" gap="sm" align="center">
45
44
  { title && (
46
45
  <Heading level={ 2 } size={ 13 }>
47
46
  { title }
@@ -78,25 +77,29 @@ function PanelDropdown< Item >( {
78
77
  field,
79
78
  onChange,
80
79
  validity,
81
- labelPosition = 'side',
82
- summaryFields,
83
- fieldDefinition,
84
- popoverAnchor,
85
- onClose: onCloseCallback,
86
- touched,
87
- }: {
88
- data: Item;
89
- field: NormalizedFormField;
90
- onChange: ( value: any ) => void;
91
- validity?: FieldValidity;
92
- labelPosition: 'side' | 'top' | 'none';
93
- summaryFields: NormalizedField< Item >[];
94
- fieldDefinition: NormalizedField< Item >;
95
- popoverAnchor: HTMLElement | null;
96
- onClose?: () => void;
97
- touched: boolean;
98
- } ) {
99
- const fieldLabel = !! field.children ? field.label : fieldDefinition?.label;
80
+ }: FieldLayoutProps< Item > ) {
81
+ const [ touched, setTouched ] = useState( false );
82
+
83
+ // Use internal state instead of a ref to make sure that the component
84
+ // re-renders when the popover's anchor updates.
85
+ const [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >(
86
+ null
87
+ );
88
+ // Memoize popoverProps to avoid returning a new object every time.
89
+ const popoverProps = useMemo(
90
+ () => ( {
91
+ // Anchor the popover to the middle of the entire row so that it doesn't
92
+ // move around when the label changes.
93
+ anchor: popoverAnchor,
94
+ placement: 'left-start',
95
+ offset: 36,
96
+ shift: true,
97
+ } ),
98
+ [ popoverAnchor ]
99
+ );
100
+ const [ dialogRef, dialogProps ] = useDialog( {
101
+ focusOnMount: 'firstInputElement',
102
+ } );
100
103
 
101
104
  const form: NormalizedForm = useMemo(
102
105
  () => ( {
@@ -120,78 +123,76 @@ function PanelDropdown< Item >( {
120
123
  return { [ field.id ]: validity };
121
124
  }, [ validity, field ] );
122
125
 
123
- // Memoize popoverProps to avoid returning a new object every time.
124
- const popoverProps = useMemo(
125
- () => ( {
126
- // Anchor the popover to the middle of the entire row so that it doesn't
127
- // move around when the label changes.
128
- anchor: popoverAnchor,
129
- placement: 'left-start',
130
- offset: 36,
131
- shift: true,
132
- } ),
133
- [ popoverAnchor ]
134
- );
135
-
136
- const focusOnMountRef = useFocusOnMount( 'firstInputElement' );
126
+ const { fieldDefinition, fieldLabel, summaryFields } =
127
+ useFieldFromFormField( field );
128
+ if ( ! fieldDefinition ) {
129
+ return null;
130
+ }
137
131
 
138
132
  return (
139
- <Dropdown
140
- contentClassName="dataforms-layouts-panel__field-dropdown"
141
- popoverProps={ popoverProps }
142
- focusOnMount={ false }
143
- onToggle={ ( willOpen ) => {
144
- if ( ! willOpen ) {
145
- onCloseCallback?.();
146
- }
147
- } }
148
- toggleProps={ {
149
- size: 'compact',
150
- variant: 'tertiary',
151
- tooltipPosition: 'middle left',
152
- } }
153
- renderToggle={ ( { isOpen, onToggle } ) => (
154
- <SummaryButton
155
- summaryFields={ summaryFields }
156
- data={ data }
157
- labelPosition={ labelPosition }
158
- fieldLabel={ fieldLabel }
159
- disabled={ fieldDefinition.readOnly === true }
160
- onClick={ onToggle }
161
- aria-expanded={ isOpen }
162
- />
163
- ) }
164
- renderContent={ ( { onClose } ) => (
165
- <DropdownContentWithValidation touched={ touched }>
166
- <DropdownHeader title={ fieldLabel } onClose={ onClose } />
167
- <div ref={ focusOnMountRef }>
168
- <DataFormLayout
169
- data={ data }
170
- form={ form }
171
- onChange={ onChange }
172
- validity={ formValidity }
173
- >
174
- { (
175
- FieldLayout,
176
- childField,
177
- childFieldValidity
178
- ) => (
179
- <FieldLayout
180
- key={ childField.id }
181
- data={ data }
182
- field={ childField }
183
- onChange={ onChange }
184
- hideLabelFromVision={
185
- ( form?.fields ?? [] ).length < 2
186
- }
187
- validity={ childFieldValidity }
188
- />
189
- ) }
190
- </DataFormLayout>
191
- </div>
192
- </DropdownContentWithValidation>
193
- ) }
194
- />
133
+ <div
134
+ ref={ setPopoverAnchor }
135
+ className="dataforms-layouts-panel__field-dropdown-anchor"
136
+ >
137
+ <Dropdown
138
+ contentClassName="dataforms-layouts-panel__field-dropdown"
139
+ popoverProps={ popoverProps }
140
+ focusOnMount={ false }
141
+ onToggle={ ( willOpen ) => {
142
+ if ( ! willOpen ) {
143
+ setTouched( true );
144
+ }
145
+ } }
146
+ renderToggle={ ( { isOpen, onToggle } ) => (
147
+ <SummaryButton
148
+ data={ data }
149
+ field={ field }
150
+ fieldLabel={ fieldLabel }
151
+ summaryFields={ summaryFields }
152
+ validity={ validity }
153
+ touched={ touched }
154
+ disabled={ fieldDefinition.readOnly === true }
155
+ onClick={ onToggle }
156
+ aria-expanded={ isOpen }
157
+ />
158
+ ) }
159
+ renderContent={ ( { onClose } ) => (
160
+ <DropdownContentWithValidation touched={ touched }>
161
+ <div ref={ dialogRef } { ...dialogProps }>
162
+ <DropdownHeader
163
+ title={ fieldLabel }
164
+ onClose={ onClose }
165
+ />
166
+ <DataFormLayout
167
+ data={ data }
168
+ form={ form }
169
+ onChange={ onChange }
170
+ validity={ formValidity }
171
+ >
172
+ { (
173
+ FieldLayout,
174
+ childField,
175
+ childFieldValidity,
176
+ markWhenOptional
177
+ ) => (
178
+ <FieldLayout
179
+ key={ childField.id }
180
+ data={ data }
181
+ field={ childField }
182
+ onChange={ onChange }
183
+ hideLabelFromVision={
184
+ ( form?.fields ?? [] ).length < 2
185
+ }
186
+ markWhenOptional={ markWhenOptional }
187
+ validity={ childFieldValidity }
188
+ />
189
+ ) }
190
+ </DataFormLayout>
191
+ </div>
192
+ </DropdownContentWithValidation>
193
+ ) }
194
+ />
195
+ </div>
195
196
  );
196
197
  }
197
198
 
@@ -1,136 +1,9 @@
1
- /**
2
- * External dependencies
3
- */
4
- import clsx from 'clsx';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { Icon, Tooltip } from '@wordpress/components';
10
- import { useState, useContext } from '@wordpress/element';
11
- import { error as errorIcon } from '@wordpress/icons';
12
- import { Stack } from '@wordpress/ui';
13
-
14
1
  /**
15
2
  * Internal dependencies
16
3
  */
17
- import type {
18
- FieldLayoutProps,
19
- FieldValidity,
20
- NormalizedField,
21
- NormalizedFormField,
22
- NormalizedPanelLayout,
23
- } from '../../../types';
24
- import DataFormContext from '../../dataform-context';
25
- import PanelDropdown from './dropdown';
4
+ import type { FieldLayoutProps, NormalizedPanelLayout } from '../../../types';
26
5
  import PanelModal from './modal';
27
- import { getSummaryFields } from '../get-summary-fields';
28
-
29
- function getFirstValidationError(
30
- validity: FieldValidity | undefined
31
- ): string | undefined {
32
- if ( ! validity ) {
33
- return undefined;
34
- }
35
-
36
- const validityRules = Object.keys( validity ).filter(
37
- ( key ) => key !== 'children'
38
- );
39
-
40
- for ( const key of validityRules ) {
41
- const rule = validity[ key as keyof Omit< FieldValidity, 'children' > ];
42
- if ( rule === undefined ) {
43
- continue;
44
- }
45
-
46
- if ( rule.type === 'invalid' ) {
47
- if ( rule.message ) {
48
- return rule.message;
49
- }
50
-
51
- // Provide default message for required validation (message is optional)
52
- if ( key === 'required' ) {
53
- return 'A required field is empty';
54
- }
55
-
56
- return 'Unidentified validation error';
57
- }
58
- }
59
-
60
- // Check children recursively
61
- if ( validity.children ) {
62
- for ( const childValidity of Object.values( validity.children ) ) {
63
- const childError = getFirstValidationError( childValidity );
64
- if ( childError ) {
65
- return childError;
66
- }
67
- }
68
- }
69
-
70
- return undefined;
71
- }
72
-
73
- const getFieldDefinition = < Item, >(
74
- field: NormalizedFormField,
75
- fields: NormalizedField< Item >[]
76
- ) => {
77
- const fieldDefinition = fields.find( ( _field ) => _field.id === field.id );
78
-
79
- if ( ! fieldDefinition ) {
80
- return fields.find( ( _field ) => {
81
- if ( !! field.children ) {
82
- const simpleChildren = field.children.filter(
83
- ( child ) => ! child.children
84
- );
85
-
86
- if ( simpleChildren.length === 0 ) {
87
- return false;
88
- }
89
-
90
- return _field.id === simpleChildren[ 0 ].id;
91
- }
92
-
93
- return _field.id === field.id;
94
- } );
95
- }
96
-
97
- return fieldDefinition;
98
- };
99
-
100
- /**
101
- * Determines the field definition and summary fields for a panel layout.
102
- *
103
- * Summary fields are determined with the following priority:
104
- * 1. Use layout.summary fields if they exist
105
- * 2. Fall back to the field definition that matches the form field's id
106
- * 3. If the form field id doesn't exist, pick the first child field
107
- * 4. If no field definition is found, return empty summary fields
108
- *
109
- * @param layout - The normalized panel layout configuration
110
- * @param field - The form field to get definition for
111
- * @param fields - Array of normalized field definitions
112
- * @return Object containing fieldDefinition and summaryFields
113
- */
114
- const getFieldDefinitionAndSummaryFields = < Item, >(
115
- layout: NormalizedPanelLayout,
116
- field: NormalizedFormField,
117
- fields: NormalizedField< Item >[]
118
- ) => {
119
- const summaryFields = getSummaryFields( layout.summary, fields );
120
- const fieldDefinition = getFieldDefinition( field, fields );
121
-
122
- if ( summaryFields.length === 0 ) {
123
- return {
124
- summaryFields: fieldDefinition ? [ fieldDefinition ] : [],
125
- fieldDefinition,
126
- };
127
- }
128
-
129
- return {
130
- summaryFields,
131
- fieldDefinition,
132
- };
133
- };
6
+ import PanelDropdown from './dropdown';
134
7
 
135
8
  export default function FormPanelField< Item >( {
136
9
  data,
@@ -138,133 +11,25 @@ export default function FormPanelField< Item >( {
138
11
  onChange,
139
12
  validity,
140
13
  }: FieldLayoutProps< Item > ) {
141
- const { fields } = useContext( DataFormContext );
142
14
  const layout = field.layout as NormalizedPanelLayout;
143
15
 
144
- // Use internal state instead of a ref to make sure that the component
145
- // re-renders when the popover's anchor updates.
146
- const [ popoverAnchor, setPopoverAnchor ] = useState< HTMLElement | null >(
147
- null
148
- );
149
-
150
- // Track if the panel has been closed (touched) to only show errors after interaction.
151
- const [ touched, setTouched ] = useState( false );
152
- const handleClose = () => setTouched( true );
153
-
154
- const { fieldDefinition, summaryFields } =
155
- getFieldDefinitionAndSummaryFields( layout, field, fields );
156
-
157
- if ( ! fieldDefinition ) {
158
- return null;
159
- }
160
-
161
- const labelPosition = layout.labelPosition;
162
- const errorMessage = getFirstValidationError( validity );
163
- const showError = touched && !! errorMessage;
164
- const labelClassName = clsx(
165
- 'dataforms-layouts-panel__field-label',
166
- `dataforms-layouts-panel__field-label--label-position-${ labelPosition }`,
167
- { 'has-error': showError }
168
- );
169
- const fieldLabel = !! field.children ? field.label : fieldDefinition?.label;
170
-
171
- const labelContent = showError ? (
172
- <Tooltip text={ errorMessage } placement="top">
173
- <Stack
174
- direction="row"
175
- gap="xs"
176
- className="dataforms-layouts-panel__field-label-error-content"
177
- justify="flex-start"
178
- >
179
- <Icon icon={ errorIcon } size={ 16 } />
180
- <>{ fieldLabel }</>
181
- </Stack>
182
- </Tooltip>
183
- ) : (
184
- fieldLabel
185
- );
186
-
187
- const renderedControl =
188
- layout.openAs === 'modal' ? (
16
+ if ( layout.openAs === 'modal' ) {
17
+ return (
189
18
  <PanelModal
190
- data={ data }
191
- field={ field }
192
- onChange={ onChange }
193
- labelPosition={ labelPosition }
194
- summaryFields={ summaryFields }
195
- fieldDefinition={ fieldDefinition }
196
- onClose={ handleClose }
197
- touched={ touched }
198
- />
199
- ) : (
200
- <PanelDropdown
201
19
  data={ data }
202
20
  field={ field }
203
21
  onChange={ onChange }
204
22
  validity={ validity }
205
- labelPosition={ labelPosition }
206
- summaryFields={ summaryFields }
207
- fieldDefinition={ fieldDefinition }
208
- popoverAnchor={ popoverAnchor }
209
- onClose={ handleClose }
210
- touched={ touched }
211
23
  />
212
24
  );
213
-
214
- if ( labelPosition === 'top' ) {
215
- return (
216
- <Stack
217
- direction="column"
218
- className="dataforms-layouts-panel__field"
219
- >
220
- <div
221
- className={ labelClassName }
222
- style={ { paddingBottom: 0 } }
223
- >
224
- { labelContent }
225
- </div>
226
- <div className="dataforms-layouts-panel__field-control">
227
- { renderedControl }
228
- </div>
229
- </Stack>
230
- );
231
- }
232
-
233
- if ( labelPosition === 'none' ) {
234
- return (
235
- <Stack
236
- direction="row"
237
- gap="xs"
238
- className="dataforms-layouts-panel__field dataforms-layouts-panel__field--label-position-none"
239
- >
240
- { showError && (
241
- <Tooltip text={ errorMessage } placement="top">
242
- <Icon
243
- className="dataforms-layouts-panel__field-label-error-content"
244
- icon={ errorIcon }
245
- size={ 16 }
246
- />
247
- </Tooltip>
248
- ) }
249
- <div className="dataforms-layouts-panel__field-control">
250
- { renderedControl }
251
- </div>
252
- </Stack>
253
- );
254
25
  }
255
26
 
256
- // Defaults to label position side.
257
27
  return (
258
- <Stack
259
- direction="row"
260
- gap="xs"
261
- ref={ setPopoverAnchor }
262
- className="dataforms-layouts-panel__field"
263
- >
264
- <div className={ labelClassName }>{ labelContent }</div>
265
- <div className="dataforms-layouts-panel__field-control">
266
- { renderedControl }
267
- </div>
268
- </Stack>
28
+ <PanelDropdown
29
+ data={ data }
30
+ field={ field }
31
+ onChange={ onChange }
32
+ validity={ validity }
33
+ />
269
34
  );
270
35
  }