@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
@@ -50,7 +50,7 @@ function isFormValid(formValidity) {
50
50
  if (key === "children" && validation && typeof validation === "object") {
51
51
  return isFormValid(validation);
52
52
  }
53
- return validation.type === "valid";
53
+ return validation.type !== "invalid" && validation.type !== "validating";
54
54
  }
55
55
  );
56
56
  });
@@ -114,6 +114,7 @@ function setValidityAtPath(formValidity, fieldValidity, path) {
114
114
  if (!current[segment]) {
115
115
  current[segment] = {};
116
116
  }
117
+ current[segment] = { ...current[segment] };
117
118
  current = current[segment];
118
119
  }
119
120
  const finalKey = path[path.length - 1];
@@ -123,6 +124,36 @@ function setValidityAtPath(formValidity, fieldValidity, path) {
123
124
  };
124
125
  return result;
125
126
  }
127
+ function removeValidationProperty(formValidity, path, property) {
128
+ if (!formValidity || path.length === 0) {
129
+ return formValidity;
130
+ }
131
+ const result = { ...formValidity };
132
+ let current = result;
133
+ for (let i = 0; i < path.length - 1; i++) {
134
+ const segment = path[i];
135
+ if (!current[segment]) {
136
+ return formValidity;
137
+ }
138
+ current[segment] = { ...current[segment] };
139
+ current = current[segment];
140
+ }
141
+ const finalKey = path[path.length - 1];
142
+ if (!current[finalKey]) {
143
+ return formValidity;
144
+ }
145
+ const fieldValidity = { ...current[finalKey] };
146
+ delete fieldValidity[property];
147
+ if (Object.keys(fieldValidity).length === 0) {
148
+ delete current[finalKey];
149
+ } else {
150
+ current[finalKey] = fieldValidity;
151
+ }
152
+ if (Object.keys(result).length === 0) {
153
+ return void 0;
154
+ }
155
+ return result;
156
+ }
126
157
  function handleElementsValidationAsync(promise, formField, promiseHandler) {
127
158
  const { elementsCounterRef, setFormValidity, path, item } = promiseHandler;
128
159
  const currentToken = (elementsCounterRef.current[formField.id] || 0) + 1;
@@ -166,6 +197,14 @@ function handleElementsValidationAsync(promise, formField, promiseHandler) {
166
197
  );
167
198
  return newFormValidity;
168
199
  });
200
+ } else {
201
+ setFormValidity((prev) => {
202
+ return removeValidationProperty(
203
+ prev,
204
+ [...path, formField.id],
205
+ "elements"
206
+ );
207
+ });
169
208
  }
170
209
  }).catch((error) => {
171
210
  if (currentToken !== elementsCounterRef.current[formField.id]) {
@@ -204,17 +243,11 @@ function handleCustomValidationAsync(promise, formField, promiseHandler) {
204
243
  }
205
244
  if (result === null) {
206
245
  setFormValidity((prev) => {
207
- const newFormValidity = setValidityAtPath(
246
+ return removeValidationProperty(
208
247
  prev,
209
- {
210
- custom: {
211
- type: "valid",
212
- message: (0, import_i18n.__)("Valid")
213
- }
214
- },
215
- [...path, formField.id]
248
+ [...path, formField.id],
249
+ "custom"
216
250
  );
217
- return newFormValidity;
218
251
  });
219
252
  return;
220
253
  }
@@ -328,19 +361,6 @@ function validateFormField(item, formField, promiseHandler) {
328
361
  }
329
362
  };
330
363
  }
331
- if (!!formField.field && formField.field.isValid.elements && formField.field.hasElements && typeof formField.field.getElements === "function") {
332
- handleElementsValidationAsync(
333
- formField.field.getElements(),
334
- formField,
335
- promiseHandler
336
- );
337
- return {
338
- elements: {
339
- type: "validating",
340
- message: (0, import_i18n.__)("Validating\u2026")
341
- }
342
- };
343
- }
344
364
  let customError;
345
365
  if (!!formField.field && formField.field.isValid.custom) {
346
366
  try {
@@ -378,15 +398,28 @@ function validateFormField(item, formField, promiseHandler) {
378
398
  }
379
399
  };
380
400
  }
401
+ const fieldValidity = {};
402
+ if (!!formField.field && formField.field.isValid.elements && formField.field.hasElements && typeof formField.field.getElements === "function") {
403
+ handleElementsValidationAsync(
404
+ formField.field.getElements(),
405
+ formField,
406
+ promiseHandler
407
+ );
408
+ fieldValidity.elements = {
409
+ type: "validating",
410
+ message: (0, import_i18n.__)("Validating\u2026")
411
+ };
412
+ }
381
413
  if (customError instanceof Promise) {
382
414
  handleCustomValidationAsync(customError, formField, promiseHandler);
383
- return {
384
- custom: {
385
- type: "validating",
386
- message: (0, import_i18n.__)("Validating\u2026")
387
- }
415
+ fieldValidity.custom = {
416
+ type: "validating",
417
+ message: (0, import_i18n.__)("Validating\u2026")
388
418
  };
389
419
  }
420
+ if (Object.keys(fieldValidity).length > 0) {
421
+ return fieldValidity;
422
+ }
390
423
  if (formField.children.length > 0) {
391
424
  const result = {};
392
425
  formField.children.forEach((child) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-form-validity.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport normalizeFields from '../field-types';\nimport normalizeForm from '../components/dataform-layouts/normalize-form';\nimport type {\n\tField,\n\tFieldValidity,\n\tForm,\n\tFormValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n} from '../types';\n\nfunction isFormValid( formValidity: FormValidity | undefined ): boolean {\n\tif ( ! formValidity ) {\n\t\treturn true;\n\t}\n\n\treturn Object.values( formValidity ).every( ( fieldValidation ) => {\n\t\treturn Object.entries( fieldValidation ).every(\n\t\t\t( [ key, validation ] ) => {\n\t\t\t\tif (\n\t\t\t\t\tkey === 'children' &&\n\t\t\t\t\tvalidation &&\n\t\t\t\t\ttypeof validation === 'object'\n\t\t\t\t) {\n\t\t\t\t\t// Recursively check children validations\n\t\t\t\t\treturn isFormValid( validation as FormValidity );\n\t\t\t\t}\n\t\t\t\treturn validation.type === 'valid';\n\t\t\t}\n\t\t);\n\t} );\n}\n\ntype FormFieldToValidate< Item > = {\n\tid: string;\n\tchildren: FormFieldToValidate< Item >[];\n\tfield?: NormalizedField< Item >;\n};\n\nfunction getFormFieldsToValidate< Item >(\n\tform: Form,\n\tfields: Field< Item >[]\n): FormFieldToValidate< Item >[] {\n\tconst normalizedForm = normalizeForm( form );\n\tif ( normalizedForm.fields.length === 0 ) {\n\t\treturn [];\n\t}\n\n\t// Create a map of field IDs to Field definitions for fast lookup\n\tconst fieldsMap = new Map< string, Field< Item > >();\n\tfields.forEach( ( field ) => {\n\t\tfieldsMap.set( field.id, field );\n\t} );\n\n\t// Recursive function to process form fields and their children\n\tfunction processFormField(\n\t\tformField: NormalizedFormField\n\t): FormFieldToValidate< Item > | null {\n\t\t// Handle combined fields (fields with children)\n\t\tif ( 'children' in formField && Array.isArray( formField.children ) ) {\n\t\t\tconst processedChildren = formField.children\n\t\t\t\t.map( processFormField )\n\t\t\t\t.filter( ( child ) => child !== null );\n\n\t\t\tif ( processedChildren.length === 0 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\t\tif ( fieldDef ) {\n\t\t\t\tconst [ normalizedField ] = normalizeFields< Item >( [\n\t\t\t\t\tfieldDef,\n\t\t\t\t] );\n\n\t\t\t\treturn {\n\t\t\t\t\tid: formField.id,\n\t\t\t\t\tchildren: processedChildren,\n\t\t\t\t\tfield: normalizedField,\n\t\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: formField.id,\n\t\t\t\tchildren: processedChildren,\n\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t}\n\n\t\t// Handle leaf fields (fields without children)\n\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\tif ( ! fieldDef ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst [ normalizedField ] = normalizeFields< Item >( [ fieldDef ] );\n\t\treturn {\n\t\t\tid: formField.id,\n\t\t\tchildren: [],\n\t\t\tfield: normalizedField,\n\t\t} as FormFieldToValidate< Item >;\n\t}\n\n\tconst toValidate = normalizedForm.fields\n\t\t.map( processFormField )\n\t\t.filter( ( field ) => field !== null );\n\n\treturn toValidate;\n}\n\nfunction setValidityAtPath(\n\tformValidity: FormValidity | undefined,\n\tfieldValidity: FieldValidity,\n\tpath: string[]\n): FormValidity {\n\t// Handle empty validity or empty path\n\tif ( ! formValidity ) {\n\t\tformValidity = {};\n\t}\n\n\tif ( path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\n\t// Clone the root to avoid mutations\n\tconst result = { ...formValidity };\n\n\t// Navigate through the result tree,\n\t// setting up empty paths if they don't exist.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t}\n\n\t\tcurrent = current[ segment ];\n\t}\n\n\t// At the final destination, merge the new validity with the existing.\n\tconst finalKey = path[ path.length - 1 ];\n\tcurrent[ finalKey ] = {\n\t\t...( current[ finalKey ] || {} ),\n\t\t...fieldValidity,\n\t};\n\n\treturn result;\n}\n\nfunction handleElementsValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { elementsCounterRef, setFormValidity, path, item } = promiseHandler;\n\tconst currentToken =\n\t\t( elementsCounterRef.current[ formField.id ] || 0 ) + 1;\n\telementsCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! Array.isArray( result ) ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __( 'Could not validate elements.' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tformField.field?.isValid.elements &&\n\t\t\t\t! formField.field.isValid.elements.validate( item, {\n\t\t\t\t\t...formField.field,\n\t\t\t\t\telements: result,\n\t\t\t\t} )\n\t\t\t) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t\t'Value must be one of the elements.'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t}\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running elements validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\nfunction handleCustomValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { customCounterRef, setFormValidity, path } = promiseHandler;\n\tconst currentToken = ( customCounterRef.current[ formField.id ] || 0 ) + 1;\n\tcustomCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( result === null ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\ttype: 'valid',\n\t\t\t\t\t\t\t\tmessage: __( 'Valid' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( typeof result === 'string' ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: result,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: __( 'Validation could not be processed.' ),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running custom validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\ntype PromiseHandler< Item > = {\n\tcustomCounterRef: React.MutableRefObject< Record< string, number > >;\n\telementsCounterRef: React.MutableRefObject< Record< string, number > >;\n\tsetFormValidity: React.Dispatch< React.SetStateAction< FormValidity > >;\n\tpath: string[];\n\titem: Item;\n};\n\nfunction validateFormField< Item >(\n\titem: Item,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n): FieldValidity | undefined {\n\t// Validate the field: isValid.required\n\tif (\n\t\tformField.field?.isValid.required &&\n\t\t! formField.field.isValid.required.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\trequired: { type: 'invalid' },\n\t\t};\n\t}\n\n\t// Validate the field: isValid.pattern\n\tif (\n\t\tformField.field?.isValid.pattern &&\n\t\t! formField.field.isValid.pattern.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tpattern: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value does not match the required pattern.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.min\n\tif (\n\t\tformField.field?.isValid.min &&\n\t\t! formField.field.isValid.min.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmin: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is below the minimum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.max\n\tif (\n\t\tformField.field?.isValid.max &&\n\t\t! formField.field.isValid.max.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmax: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is above the maximum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.minLength\n\tif (\n\t\tformField.field?.isValid.minLength &&\n\t\t! formField.field.isValid.minLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tminLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too short.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.maxLength\n\tif (\n\t\tformField.field?.isValid.maxLength &&\n\t\t! formField.field.isValid.maxLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmaxLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too long.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.elements (static)\n\tif (\n\t\tformField.field?.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\t! formField.field.getElements &&\n\t\tArray.isArray( formField.field.elements ) &&\n\t\t! formField.field.isValid.elements.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value must be one of the elements.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.elements (async)\n\tif (\n\t\t!! formField.field &&\n\t\tformField.field.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\ttypeof formField.field.getElements === 'function'\n\t) {\n\t\thandleElementsValidationAsync(\n\t\t\tformField.field.getElements(),\n\t\t\tformField,\n\t\t\tpromiseHandler\n\t\t);\n\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (sync)\n\tlet customError;\n\tif ( !! formField.field && formField.field.isValid.custom ) {\n\t\ttry {\n\t\t\tconst value = formField.field.getValue( { item } );\n\t\t\tcustomError = formField.field.isValid.custom(\n\t\t\t\tdeepMerge(\n\t\t\t\t\titem,\n\t\t\t\t\tformField.field.setValue( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tformField.field\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__( 'Unknown error when running custom validation.' );\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcustom: {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\tif ( typeof customError === 'string' ) {\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: customError,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'validating',\n\t\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate its children.\n\tif ( formField.children.length > 0 ) {\n\t\tconst result: Record< string, FieldValidity | undefined > = {};\n\t\tformField.children.forEach( ( child ) => {\n\t\t\tresult[ child.id ] = validateFormField( item, child, {\n\t\t\t\t...promiseHandler,\n\t\t\t\tpath: [ ...promiseHandler.path, formField.id, 'children' ],\n\t\t\t} );\n\t\t} );\n\n\t\tconst filteredResult: Record< string, FieldValidity > = {};\n\t\tObject.entries( result ).forEach( ( [ key, value ] ) => {\n\t\t\tif ( value !== undefined ) {\n\t\t\t\tfilteredResult[ key ] = value;\n\t\t\t}\n\t\t} );\n\n\t\tif ( Object.keys( filteredResult ).length === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tchildren: filteredResult,\n\t\t};\n\t}\n\n\t// No errors for this field or its children.\n\treturn undefined;\n}\n\nfunction getFormFieldValue< Item >(\n\tformField: FormFieldToValidate< Item >,\n\titem: Item\n): any {\n\tconst fieldValue = formField?.field?.getValue( { item } );\n\tif ( formField.children.length === 0 ) {\n\t\treturn fieldValue;\n\t}\n\n\tconst childrenValues = formField.children.map( ( child ) =>\n\t\tgetFormFieldValue( child, item )\n\t);\n\tif ( ! childrenValues ) {\n\t\treturn fieldValue;\n\t}\n\n\treturn {\n\t\tvalue: fieldValue,\n\t\tchildren: childrenValues,\n\t};\n}\n\n/**\n * Hook that validates a form item and returns an object with error messages for each field.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return Record of field IDs to error messages (undefined means no error).\n */\nexport function useFormValidity< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): { validity: FormValidity; isValid: boolean } {\n\tconst [ formValidity, setFormValidity ] = useState< FormValidity >();\n\tconst customCounterRef = useRef< Record< string, number > >( {} );\n\tconst elementsCounterRef = useRef< Record< string, number > >( {} );\n\tconst previousValuesRef = useRef< Record< string, any > >( {} );\n\n\tconst validate = useCallback( () => {\n\t\tconst promiseHandler = {\n\t\t\tcustomCounterRef,\n\t\t\telementsCounterRef,\n\t\t\tsetFormValidity,\n\t\t\tpath: [],\n\t\t\titem,\n\t\t};\n\n\t\tconst formFieldsToValidate = getFormFieldsToValidate( form, fields );\n\t\tif ( formFieldsToValidate.length === 0 ) {\n\t\t\tsetFormValidity( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tconst newFormValidity: FormValidity = {};\n\t\tconst untouchedFields: string[] = [];\n\t\tformFieldsToValidate.forEach( ( formField ) => {\n\t\t\t// Skip fields that did not change.\n\t\t\tconst value = getFormFieldValue< Item >( formField, item );\n\t\t\tif (\n\t\t\t\tpreviousValuesRef.current.hasOwnProperty( formField.id ) &&\n\t\t\t\tfastDeepEqual(\n\t\t\t\t\tpreviousValuesRef.current[ formField.id ],\n\t\t\t\t\tvalue\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tuntouchedFields.push( formField.id );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpreviousValuesRef.current[ formField.id ] = value;\n\n\t\t\t// Calculate validity for those fields that changed.\n\t\t\tconst fieldValidity = validateFormField(\n\t\t\t\titem,\n\t\t\t\tformField,\n\t\t\t\tpromiseHandler\n\t\t\t);\n\t\t\tif ( fieldValidity !== undefined ) {\n\t\t\t\tnewFormValidity[ formField.id ] = fieldValidity;\n\t\t\t}\n\t\t} );\n\n\t\tsetFormValidity( ( existingFormValidity ) => {\n\t\t\tlet validity: FormValidity = {\n\t\t\t\t...existingFormValidity,\n\t\t\t\t...newFormValidity,\n\t\t\t};\n\n\t\t\tconst fieldsToKeep = [\n\t\t\t\t...untouchedFields,\n\t\t\t\t...Object.keys( newFormValidity ),\n\t\t\t];\n\t\t\tObject.keys( validity ).forEach( ( key ) => {\n\t\t\t\tif ( validity && ! fieldsToKeep.includes( key ) ) {\n\t\t\t\t\tdelete validity[ key ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( Object.keys( validity ).length === 0 ) {\n\t\t\t\tvalidity = undefined;\n\t\t\t}\n\n\t\t\tconst areEqual = fastDeepEqual( existingFormValidity, validity );\n\t\t\tif ( areEqual ) {\n\t\t\t\treturn existingFormValidity;\n\t\t\t}\n\n\t\t\treturn validity;\n\t\t} );\n\t}, [ item, fields, form ] );\n\n\tuseEffect( () => {\n\t\tvalidate();\n\t}, [ validate ] );\n\n\treturn {\n\t\tvalidity: formValidity,\n\t\tisValid: isFormValid( formValidity ),\n\t};\n}\n\nexport default useFormValidity;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAsB;AACtB,iBAA0B;AAK1B,qBAAyD;AACzD,kBAAmB;AAKnB,yBAA4B;AAC5B,4BAA0B;AAU1B,SAAS,YAAa,cAAkD;AACvE,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,OAAQ,YAAa,EAAE,MAAO,CAAE,oBAAqB;AAClE,WAAO,OAAO,QAAS,eAAgB,EAAE;AAAA,MACxC,CAAE,CAAE,KAAK,UAAW,MAAO;AAC1B,YACC,QAAQ,cACR,cACA,OAAO,eAAe,UACrB;AAED,iBAAO,YAAa,UAA2B;AAAA,QAChD;AACA,eAAO,WAAW,SAAS;AAAA,MAC5B;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAQA,SAAS,wBACR,MACA,QACgC;AAChC,QAAM,qBAAiB,sBAAAA,SAAe,IAAK;AAC3C,MAAK,eAAe,OAAO,WAAW,GAAI;AACzC,WAAO,CAAC;AAAA,EACT;AAGA,QAAM,YAAY,oBAAI,IAA6B;AACnD,SAAO,QAAS,CAAE,UAAW;AAC5B,cAAU,IAAK,MAAM,IAAI,KAAM;AAAA,EAChC,CAAE;AAGF,WAAS,iBACR,WACqC;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AAQ,kBAA2B,WAAW,IAAK;AACzD,UACC,kBAAkB,QAAQ,eAAgB,UAAU,EAAG,SACvD,WAAAC;AAAA,QACC,kBAAkB,QAAS,UAAU,EAAG;AAAA,QACxC;AAAA,MACD,GACC;AACD,wBAAgB,KAAM,UAAU,EAAG;AACnC;AAAA,MACD;AACA,wBAAkB,QAAS,UAAU,EAAG,IAAI;AAG5C,YAAM,gBAAgB;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,UAAK,kBAAkB,QAAY;AAClC,wBAAiB,UAAU,EAAG,IAAI;AAAA,MACnC;AAAA,IACD,CAAE;AAEF,oBAAiB,CAAE,yBAA0B;AAC5C,UAAI,WAAyB;AAAA,QAC5B,GAAG;AAAA,QACH,GAAG;AAAA,MACJ;AAEA,YAAM,eAAe;AAAA,QACpB,GAAG;AAAA,QACH,GAAG,OAAO,KAAM,eAAgB;AAAA,MACjC;AACA,aAAO,KAAM,QAAS,EAAE,QAAS,CAAE,QAAS;AAC3C,YAAK,YAAY,CAAE,aAAa,SAAU,GAAI,GAAI;AACjD,iBAAO,SAAU,GAAI;AAAA,QACtB;AAAA,MACD,CAAE;AACF,UAAK,OAAO,KAAM,QAAS,EAAE,WAAW,GAAI;AAC3C,mBAAW;AAAA,MACZ;AAEA,YAAM,eAAW,WAAAA,SAAe,sBAAsB,QAAS;AAC/D,UAAK,UAAW;AACf,eAAO;AAAA,MACR;AAEA,aAAO;AAAA,IACR,CAAE;AAAA,EACH,GAAG,CAAE,MAAM,QAAQ,IAAK,CAAE;AAE1B,gCAAW,MAAM;AAChB,aAAS;AAAA,EACV,GAAG,CAAE,QAAS,CAAE;AAEhB,SAAO;AAAA,IACN,UAAU;AAAA,IACV,SAAS,YAAa,YAAa;AAAA,EACpC;AACD;AAEA,IAAO,4BAAQ;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport deepMerge from 'deepmerge';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport normalizeFields from '../field-types';\nimport normalizeForm from '../components/dataform-layouts/normalize-form';\nimport type {\n\tField,\n\tFieldValidity,\n\tForm,\n\tFormValidity,\n\tNormalizedField,\n\tNormalizedFormField,\n} from '../types';\n\nfunction isFormValid( formValidity: FormValidity | undefined ): boolean {\n\tif ( ! formValidity ) {\n\t\treturn true;\n\t}\n\n\treturn Object.values( formValidity ).every( ( fieldValidation ) => {\n\t\treturn Object.entries( fieldValidation ).every(\n\t\t\t( [ key, validation ] ) => {\n\t\t\t\tif (\n\t\t\t\t\tkey === 'children' &&\n\t\t\t\t\tvalidation &&\n\t\t\t\t\ttypeof validation === 'object'\n\t\t\t\t) {\n\t\t\t\t\t// Recursively check children validations\n\t\t\t\t\treturn isFormValid( validation as FormValidity );\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\tvalidation.type !== 'invalid' &&\n\t\t\t\t\tvalidation.type !== 'validating'\n\t\t\t\t);\n\t\t\t}\n\t\t);\n\t} );\n}\n\ntype FormFieldToValidate< Item > = {\n\tid: string;\n\tchildren: FormFieldToValidate< Item >[];\n\tfield?: NormalizedField< Item >;\n};\n\nfunction getFormFieldsToValidate< Item >(\n\tform: Form,\n\tfields: Field< Item >[]\n): FormFieldToValidate< Item >[] {\n\tconst normalizedForm = normalizeForm( form );\n\tif ( normalizedForm.fields.length === 0 ) {\n\t\treturn [];\n\t}\n\n\t// Create a map of field IDs to Field definitions for fast lookup\n\tconst fieldsMap = new Map< string, Field< Item > >();\n\tfields.forEach( ( field ) => {\n\t\tfieldsMap.set( field.id, field );\n\t} );\n\n\t// Recursive function to process form fields and their children\n\tfunction processFormField(\n\t\tformField: NormalizedFormField\n\t): FormFieldToValidate< Item > | null {\n\t\t// Handle combined fields (fields with children)\n\t\tif ( 'children' in formField && Array.isArray( formField.children ) ) {\n\t\t\tconst processedChildren = formField.children\n\t\t\t\t.map( processFormField )\n\t\t\t\t.filter( ( child ) => child !== null );\n\n\t\t\tif ( processedChildren.length === 0 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\t\tif ( fieldDef ) {\n\t\t\t\tconst [ normalizedField ] = normalizeFields< Item >( [\n\t\t\t\t\tfieldDef,\n\t\t\t\t] );\n\n\t\t\t\treturn {\n\t\t\t\t\tid: formField.id,\n\t\t\t\t\tchildren: processedChildren,\n\t\t\t\t\tfield: normalizedField,\n\t\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tid: formField.id,\n\t\t\t\tchildren: processedChildren,\n\t\t\t} satisfies FormFieldToValidate< Item >;\n\t\t}\n\n\t\t// Handle leaf fields (fields without children)\n\t\tconst fieldDef = fieldsMap.get( formField.id );\n\t\tif ( ! fieldDef ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst [ normalizedField ] = normalizeFields< Item >( [ fieldDef ] );\n\t\treturn {\n\t\t\tid: formField.id,\n\t\t\tchildren: [],\n\t\t\tfield: normalizedField,\n\t\t} as FormFieldToValidate< Item >;\n\t}\n\n\tconst toValidate = normalizedForm.fields\n\t\t.map( processFormField )\n\t\t.filter( ( field ) => field !== null );\n\n\treturn toValidate;\n}\n\nfunction setValidityAtPath(\n\tformValidity: FormValidity | undefined,\n\tfieldValidity: FieldValidity,\n\tpath: string[]\n): FormValidity {\n\t// Handle empty validity or empty path\n\tif ( ! formValidity ) {\n\t\tformValidity = {};\n\t}\n\n\tif ( path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\n\t// Clone the root to avoid mutations\n\tconst result = { ...formValidity };\n\n\t// Navigate through the result tree,\n\t// setting up empty paths if they don't exist.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\tcurrent[ segment ] = {};\n\t\t}\n\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\n\t// At the final destination, merge the new validity with the existing.\n\tconst finalKey = path[ path.length - 1 ];\n\tcurrent[ finalKey ] = {\n\t\t...( current[ finalKey ] || {} ),\n\t\t...fieldValidity,\n\t};\n\n\treturn result;\n}\n\nfunction removeValidationProperty(\n\tformValidity: FormValidity | undefined,\n\tpath: string[],\n\tproperty: keyof FieldValidity\n): FormValidity | undefined {\n\tif ( ! formValidity || path.length === 0 ) {\n\t\treturn formValidity;\n\t}\n\tconst result = { ...formValidity };\n\t// Navigate to parent of target.\n\tlet current: any = result;\n\tfor ( let i = 0; i < path.length - 1; i++ ) {\n\t\tconst segment = path[ i ];\n\t\tif ( ! current[ segment ] ) {\n\t\t\treturn formValidity; // Path doesn't exist\n\t\t}\n\t\tcurrent[ segment ] = { ...current[ segment ] };\n\t\tcurrent = current[ segment ];\n\t}\n\tconst finalKey = path[ path.length - 1 ];\n\tif ( ! current[ finalKey ] ) {\n\t\treturn formValidity;\n\t}\n\tconst fieldValidity = { ...current[ finalKey ] };\n\tdelete fieldValidity[ property ];\n\t// If field has no more validations, remove it entirely.\n\tif ( Object.keys( fieldValidity ).length === 0 ) {\n\t\tdelete current[ finalKey ];\n\t} else {\n\t\t// Keep the field if it has other validations (including children).\n\t\tcurrent[ finalKey ] = fieldValidity;\n\t}\n\t// If root is empty, return undefined\n\tif ( Object.keys( result ).length === 0 ) {\n\t\treturn undefined;\n\t}\n\treturn result;\n}\n\nfunction handleElementsValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { elementsCounterRef, setFormValidity, path, item } = promiseHandler;\n\tconst currentToken =\n\t\t( elementsCounterRef.current[ formField.id ] || 0 ) + 1;\n\telementsCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! Array.isArray( result ) ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __( 'Could not validate elements.' ),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tformField.field?.isValid.elements &&\n\t\t\t\t! formField.field.isValid.elements.validate( item, {\n\t\t\t\t\t...formField.field,\n\t\t\t\t\telements: result,\n\t\t\t\t} )\n\t\t\t) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: __(\n\t\t\t\t\t\t\t\t\t'Value must be one of the elements.'\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t} else {\n\t\t\t\t// Validation passed so we need to remove `elements` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'elements'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== elementsCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running elements validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\telements: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\nfunction handleCustomValidationAsync< Item >(\n\tpromise: Promise< any >,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n) {\n\tconst { customCounterRef, setFormValidity, path } = promiseHandler;\n\tconst currentToken = ( customCounterRef.current[ formField.id ] || 0 ) + 1;\n\tcustomCounterRef.current[ formField.id ] = currentToken;\n\n\tpromise\n\t\t.then( ( result ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( result === null ) {\n\t\t\t\t// Validation passed so we need to remove `custom` from validity.\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\treturn removeValidationProperty(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t[ ...path, formField.id ],\n\t\t\t\t\t\t'custom'\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( typeof result === 'string' ) {\n\t\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\t\tprev,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\t\tmessage: result,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t\t);\n\t\t\t\t\treturn newFormValidity;\n\t\t\t\t} );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: __( 'Validation could not be processed.' ),\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} )\n\t\t.catch( ( error ) => {\n\t\t\tif ( currentToken !== customCounterRef.current[ formField.id ] ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__(\n\t\t\t\t\t\t'Unknown error when running custom validation asynchronously.'\n\t\t\t\t\t);\n\t\t\t}\n\n\t\t\tsetFormValidity( ( prev ) => {\n\t\t\t\tconst newFormValidity = setValidityAtPath(\n\t\t\t\t\tprev,\n\t\t\t\t\t{\n\t\t\t\t\t\tcustom: {\n\t\t\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t[ ...path, formField.id ]\n\t\t\t\t);\n\t\t\t\treturn newFormValidity;\n\t\t\t} );\n\t\t} );\n}\n\ntype PromiseHandler< Item > = {\n\tcustomCounterRef: React.MutableRefObject< Record< string, number > >;\n\telementsCounterRef: React.MutableRefObject< Record< string, number > >;\n\tsetFormValidity: React.Dispatch< React.SetStateAction< FormValidity > >;\n\tpath: string[];\n\titem: Item;\n};\n\nfunction validateFormField< Item >(\n\titem: Item,\n\tformField: FormFieldToValidate< Item >,\n\tpromiseHandler: PromiseHandler< Item >\n): FieldValidity | undefined {\n\t// Validate the field: isValid.required\n\tif (\n\t\tformField.field?.isValid.required &&\n\t\t! formField.field.isValid.required.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\trequired: { type: 'invalid' },\n\t\t};\n\t}\n\n\t// Validate the field: isValid.pattern\n\tif (\n\t\tformField.field?.isValid.pattern &&\n\t\t! formField.field.isValid.pattern.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tpattern: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value does not match the required pattern.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.min\n\tif (\n\t\tformField.field?.isValid.min &&\n\t\t! formField.field.isValid.min.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmin: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is below the minimum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.max\n\tif (\n\t\tformField.field?.isValid.max &&\n\t\t! formField.field.isValid.max.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmax: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is above the maximum.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.minLength\n\tif (\n\t\tformField.field?.isValid.minLength &&\n\t\t! formField.field.isValid.minLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tminLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too short.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.maxLength\n\tif (\n\t\tformField.field?.isValid.maxLength &&\n\t\t! formField.field.isValid.maxLength.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\tmaxLength: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value is too long.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.elements (static)\n\tif (\n\t\tformField.field?.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\t! formField.field.getElements &&\n\t\tArray.isArray( formField.field.elements ) &&\n\t\t! formField.field.isValid.elements.validate( item, formField.field )\n\t) {\n\t\treturn {\n\t\t\telements: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: __( 'Value must be one of the elements.' ),\n\t\t\t},\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (sync)\n\tlet customError;\n\tif ( !! formField.field && formField.field.isValid.custom ) {\n\t\ttry {\n\t\t\tconst value = formField.field.getValue( { item } );\n\t\t\tcustomError = formField.field.isValid.custom(\n\t\t\t\tdeepMerge(\n\t\t\t\t\titem,\n\t\t\t\t\tformField.field.setValue( {\n\t\t\t\t\t\titem,\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t} ) as Partial< Item >\n\t\t\t\t),\n\t\t\t\tformField.field\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tlet errorMessage;\n\t\t\tif ( error instanceof Error ) {\n\t\t\t\terrorMessage = error.message;\n\t\t\t} else {\n\t\t\t\terrorMessage =\n\t\t\t\t\tString( error ) ||\n\t\t\t\t\t__( 'Unknown error when running custom validation.' );\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcustom: {\n\t\t\t\t\ttype: 'invalid',\n\t\t\t\t\tmessage: errorMessage,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t}\n\n\tif ( typeof customError === 'string' ) {\n\t\treturn {\n\t\t\tcustom: {\n\t\t\t\ttype: 'invalid',\n\t\t\t\tmessage: customError,\n\t\t\t},\n\t\t};\n\t}\n\n\t// Aggregate async validations (`elements` and `custom`).\n\tconst fieldValidity: FieldValidity = {};\n\t// Validate the field: isValid.elements (async)\n\tif (\n\t\t!! formField.field &&\n\t\tformField.field.isValid.elements &&\n\t\tformField.field.hasElements &&\n\t\ttypeof formField.field.getElements === 'function'\n\t) {\n\t\thandleElementsValidationAsync(\n\t\t\tformField.field.getElements(),\n\t\t\tformField,\n\t\t\tpromiseHandler\n\t\t);\n\t\tfieldValidity.elements = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Validate the field: isValid.custom (async)\n\tif ( customError instanceof Promise ) {\n\t\thandleCustomValidationAsync( customError, formField, promiseHandler );\n\n\t\tfieldValidity.custom = {\n\t\t\ttype: 'validating',\n\t\t\tmessage: __( 'Validating\u2026' ),\n\t\t};\n\t}\n\n\t// Return aggregated validations if any exist\n\tif ( Object.keys( fieldValidity ).length > 0 ) {\n\t\treturn fieldValidity;\n\t}\n\n\t// Validate its children.\n\tif ( formField.children.length > 0 ) {\n\t\tconst result: Record< string, FieldValidity | undefined > = {};\n\t\tformField.children.forEach( ( child ) => {\n\t\t\tresult[ child.id ] = validateFormField( item, child, {\n\t\t\t\t...promiseHandler,\n\t\t\t\tpath: [ ...promiseHandler.path, formField.id, 'children' ],\n\t\t\t} );\n\t\t} );\n\n\t\tconst filteredResult: Record< string, FieldValidity > = {};\n\t\tObject.entries( result ).forEach( ( [ key, value ] ) => {\n\t\t\tif ( value !== undefined ) {\n\t\t\t\tfilteredResult[ key ] = value;\n\t\t\t}\n\t\t} );\n\n\t\tif ( Object.keys( filteredResult ).length === 0 ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tchildren: filteredResult,\n\t\t};\n\t}\n\n\t// No errors for this field or its children.\n\treturn undefined;\n}\n\nfunction getFormFieldValue< Item >(\n\tformField: FormFieldToValidate< Item >,\n\titem: Item\n): any {\n\tconst fieldValue = formField?.field?.getValue( { item } );\n\tif ( formField.children.length === 0 ) {\n\t\treturn fieldValue;\n\t}\n\n\tconst childrenValues = formField.children.map( ( child ) =>\n\t\tgetFormFieldValue( child, item )\n\t);\n\tif ( ! childrenValues ) {\n\t\treturn fieldValue;\n\t}\n\n\treturn {\n\t\tvalue: fieldValue,\n\t\tchildren: childrenValues,\n\t};\n}\n\n/**\n * Hook that validates a form item and returns an object with error messages for each field.\n *\n * @param item The item to validate.\n * @param fields Fields config.\n * @param form Form config.\n *\n * @return Record of field IDs to error messages (undefined means no error).\n */\nexport function useFormValidity< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): { validity: FormValidity; isValid: boolean } {\n\tconst [ formValidity, setFormValidity ] = useState< FormValidity >();\n\tconst customCounterRef = useRef< Record< string, number > >( {} );\n\tconst elementsCounterRef = useRef< Record< string, number > >( {} );\n\tconst previousValuesRef = useRef< Record< string, any > >( {} );\n\n\tconst validate = useCallback( () => {\n\t\tconst promiseHandler = {\n\t\t\tcustomCounterRef,\n\t\t\telementsCounterRef,\n\t\t\tsetFormValidity,\n\t\t\tpath: [],\n\t\t\titem,\n\t\t};\n\n\t\tconst formFieldsToValidate = getFormFieldsToValidate( form, fields );\n\t\tif ( formFieldsToValidate.length === 0 ) {\n\t\t\tsetFormValidity( undefined );\n\t\t\treturn;\n\t\t}\n\n\t\tconst newFormValidity: FormValidity = {};\n\t\tconst untouchedFields: string[] = [];\n\t\tformFieldsToValidate.forEach( ( formField ) => {\n\t\t\t// Skip fields that did not change.\n\t\t\tconst value = getFormFieldValue< Item >( formField, item );\n\t\t\tif (\n\t\t\t\tpreviousValuesRef.current.hasOwnProperty( formField.id ) &&\n\t\t\t\tfastDeepEqual(\n\t\t\t\t\tpreviousValuesRef.current[ formField.id ],\n\t\t\t\t\tvalue\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tuntouchedFields.push( formField.id );\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tpreviousValuesRef.current[ formField.id ] = value;\n\n\t\t\t// Calculate validity for those fields that changed.\n\t\t\tconst fieldValidity = validateFormField(\n\t\t\t\titem,\n\t\t\t\tformField,\n\t\t\t\tpromiseHandler\n\t\t\t);\n\t\t\tif ( fieldValidity !== undefined ) {\n\t\t\t\tnewFormValidity[ formField.id ] = fieldValidity;\n\t\t\t}\n\t\t} );\n\n\t\tsetFormValidity( ( existingFormValidity ) => {\n\t\t\tlet validity: FormValidity = {\n\t\t\t\t...existingFormValidity,\n\t\t\t\t...newFormValidity,\n\t\t\t};\n\n\t\t\tconst fieldsToKeep = [\n\t\t\t\t...untouchedFields,\n\t\t\t\t...Object.keys( newFormValidity ),\n\t\t\t];\n\t\t\tObject.keys( validity ).forEach( ( key ) => {\n\t\t\t\tif ( validity && ! fieldsToKeep.includes( key ) ) {\n\t\t\t\t\tdelete validity[ key ];\n\t\t\t\t}\n\t\t\t} );\n\t\t\tif ( Object.keys( validity ).length === 0 ) {\n\t\t\t\tvalidity = undefined;\n\t\t\t}\n\n\t\t\tconst areEqual = fastDeepEqual( existingFormValidity, validity );\n\t\t\tif ( areEqual ) {\n\t\t\t\treturn existingFormValidity;\n\t\t\t}\n\n\t\t\treturn validity;\n\t\t} );\n\t}, [ item, fields, form ] );\n\n\tuseEffect( () => {\n\t\tvalidate();\n\t}, [ validate ] );\n\n\treturn {\n\t\tvalidity: formValidity,\n\t\tisValid: isFormValid( formValidity ),\n\t};\n}\n\nexport default useFormValidity;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAsB;AACtB,iBAA0B;AAK1B,qBAAyD;AACzD,kBAAmB;AAKnB,yBAA4B;AAC5B,4BAA0B;AAU1B,SAAS,YAAa,cAAkD;AACvE,MAAK,CAAE,cAAe;AACrB,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,OAAQ,YAAa,EAAE,MAAO,CAAE,oBAAqB;AAClE,WAAO,OAAO,QAAS,eAAgB,EAAE;AAAA,MACxC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;AAAA,IACN,UAAU;AAAA,IACV,SAAS,YAAa,YAAa;AAAA,EACpC;AACD;AAEA,IAAO,4BAAQ;",
6
6
  "names": ["normalizeForm", "fieldDef", "normalizedField", "normalizeFields", "deepMerge", "fastDeepEqual"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/types/dataform.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Field, FieldValidity } from './field-api';\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row' | 'details';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type PanelSummaryField = string | string[];\nexport type NormalizedPanelSummaryField = string[];\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n\tsummary?: PanelSummaryField;\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n\tsummary: NormalizedPanelSummaryField;\n};\n\nexport type CardSummaryField =\n\t| PanelSummaryField // Basic usage: string or string[]\n\t| Array<\n\t\t\t| string\n\t\t\t| {\n\t\t\t\t\tid: string;\n\t\t\t\t\tvisibility: 'always' | 'when-collapsed';\n\t\t\t }\n\t >;\n\nexport type NormalizedCardSummaryField = Array< {\n\tid: string;\n\tvisibility: 'always' | 'when-collapsed';\n} >;\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t\t\t// isCollapsible cannot be true if withHeader is false as well.\n\t\t\tisCollapsible?: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t\t\tsummary?: CardSummaryField;\n\t\t\tisCollapsible?: boolean | undefined;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t\t\t// Summary is an empty array\n\t\t\tsummary: [];\n\t\t\t// If no header, the card should not be collapsible.\n\t\t\tisCollapsible: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t\t\tsummary: NormalizedCardSummaryField;\n\t\t\tisCollapsible: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n\tstyles?: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n\tstyles: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\n\nexport type DetailsLayout = {\n\ttype: 'details';\n\tsummary?: string;\n};\nexport type NormalizedDetailsLayout = {\n\ttype: 'details';\n\tsummary: string;\n};\n\nexport type Layout =\n\t| RegularLayout\n\t| PanelLayout\n\t| CardLayout\n\t| RowLayout\n\t| DetailsLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout\n\t| NormalizedDetailsLayout;\n\nexport type NormalizedSummaryField =\n\t| NormalizedPanelSummaryField\n\t| NormalizedCardSummaryField;\n\nexport type FormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren?: Array< FormField | string >;\n};\nexport type NormalizedFormField = {\n\tid: string;\n\tlayout: NormalizedLayout;\n\tlabel?: string;\n\tdescription?: string;\n\tchildren?: NormalizedFormField[];\n};\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\nexport type NormalizedForm = {\n\tlayout: NormalizedLayout;\n\tfields: NormalizedFormField[];\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n\tvalidity?: FormValidity;\n}\n\nexport type FormValidity = Record< string, FieldValidity > | undefined;\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n\tvalidity?: FieldValidity;\n}\n"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Field, FieldValidity } from './field-api';\n\n/**\n * DataForm layouts.\n */\nexport type LayoutType = 'regular' | 'panel' | 'card' | 'row' | 'details';\nexport type LabelPosition = 'top' | 'side' | 'none';\n\nexport type PanelSummaryField = string | string[];\nexport type NormalizedPanelSummaryField = string[];\n\nexport type RegularLayout = {\n\ttype: 'regular';\n\tlabelPosition?: LabelPosition;\n};\nexport type NormalizedRegularLayout = {\n\ttype: 'regular';\n\tlabelPosition: LabelPosition;\n};\n\nexport type EditVisibility = 'always' | 'on-hover';\n\nexport type PanelLayout = {\n\ttype: 'panel';\n\tlabelPosition?: LabelPosition;\n\topenAs?: 'dropdown' | 'modal';\n\tsummary?: PanelSummaryField;\n\teditVisibility?: EditVisibility;\n};\nexport type NormalizedPanelLayout = {\n\ttype: 'panel';\n\tlabelPosition: LabelPosition;\n\topenAs: 'dropdown' | 'modal';\n\tsummary: NormalizedPanelSummaryField;\n\teditVisibility: EditVisibility;\n};\n\nexport type CardSummaryField =\n\t| PanelSummaryField // Basic usage: string or string[]\n\t| Array<\n\t\t\t| string\n\t\t\t| {\n\t\t\t\t\tid: string;\n\t\t\t\t\tvisibility: 'always' | 'when-collapsed';\n\t\t\t }\n\t >;\n\nexport type NormalizedCardSummaryField = Array< {\n\tid: string;\n\tvisibility: 'always' | 'when-collapsed';\n} >;\n\nexport type CardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened?: true;\n\t\t\t// isCollapsible cannot be true if withHeader is false as well.\n\t\t\tisCollapsible?: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader?: true | undefined;\n\t\t\tisOpened?: boolean;\n\t\t\tsummary?: CardSummaryField;\n\t\t\tisCollapsible?: boolean | undefined;\n\t };\nexport type NormalizedCardLayout =\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: false;\n\t\t\t// isOpened cannot be false if withHeader is false as well.\n\t\t\t// Otherwise, the card would not be visible.\n\t\t\tisOpened: true;\n\t\t\t// Summary is an empty array\n\t\t\tsummary: [];\n\t\t\t// If no header, the card should not be collapsible.\n\t\t\tisCollapsible: false;\n\t }\n\t| {\n\t\t\ttype: 'card';\n\t\t\twithHeader: true;\n\t\t\tisOpened: boolean;\n\t\t\tsummary: NormalizedCardSummaryField;\n\t\t\tisCollapsible: boolean;\n\t };\n\nexport type RowLayout = {\n\ttype: 'row';\n\talignment?: 'start' | 'center' | 'end';\n\tstyles?: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\nexport type NormalizedRowLayout = {\n\ttype: 'row';\n\talignment: 'start' | 'center' | 'end';\n\tstyles: Record< string, { flex?: React.CSSProperties[ 'flex' ] } >;\n};\n\nexport type DetailsLayout = {\n\ttype: 'details';\n\tsummary?: string;\n};\nexport type NormalizedDetailsLayout = {\n\ttype: 'details';\n\tsummary: string;\n};\n\nexport type Layout =\n\t| RegularLayout\n\t| PanelLayout\n\t| CardLayout\n\t| RowLayout\n\t| DetailsLayout;\nexport type NormalizedLayout =\n\t| NormalizedRegularLayout\n\t| NormalizedPanelLayout\n\t| NormalizedCardLayout\n\t| NormalizedRowLayout\n\t| NormalizedDetailsLayout;\n\nexport type NormalizedSummaryField =\n\t| NormalizedPanelSummaryField\n\t| NormalizedCardSummaryField;\n\nexport type FormField = {\n\tid: string;\n\tlabel?: string;\n\tdescription?: string;\n\tlayout?: Layout;\n\tchildren?: Array< FormField | string >;\n};\nexport type NormalizedFormField = {\n\tid: string;\n\tlayout: NormalizedLayout;\n\tlabel?: string;\n\tdescription?: string;\n\tchildren?: NormalizedFormField[];\n};\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\tlayout?: Layout;\n\tfields?: Array< FormField | string >;\n};\nexport type NormalizedForm = {\n\tlayout: NormalizedLayout;\n\tfields: NormalizedFormField[];\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n\tvalidity?: FormValidity;\n}\n\nexport type FormValidity = Record< string, FieldValidity > | undefined;\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: NormalizedFormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n\tmarkWhenOptional?: boolean;\n\tvalidity?: FieldValidity;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/types/field-api.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldTypeName =\n\t| 'text'\n\t| 'integer'\n\t| 'number'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\telements?: boolean;\n\tpattern?: string;\n\tminLength?: number;\n\tmaxLength?: number;\n\tmin?: number;\n\tmax?: number;\n\tcustom?:\n\t\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t\t| ( (\n\t\t\t\titem: Item,\n\t\t\t\tfield: NormalizedField< Item >\n\t\t ) => Promise< null | string > );\n};\n\nexport type Validator< Item > = (\n\titem: Item,\n\tfield: NormalizedField< Item >\n) => boolean;\n\nexport type CustomValidator< Item > =\n\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t| ( (\n\t\t\titem: Item,\n\t\t\tfield: NormalizedField< Item >\n\t ) => Promise< null | string > );\n\nexport type FilterOperator< Item > = (\n\titem: Item,\n\tfield: NormalizedField< Item >,\n\tfilterValue: any\n) => boolean;\n\nexport type FilterOperatorMap< Item > = Partial<\n\tRecord< Operator, FilterOperator< Item > >\n>;\n\ntype NormalizedRule< Item, ConstraintType > = {\n\tconstraint: ConstraintType;\n\tvalidate: Validator< Item >;\n};\n\nexport type NormalizedRules< Item > = {\n\trequired?: NormalizedRule< Item, boolean >;\n\telements?: NormalizedRule< Item, boolean >;\n\tpattern?: NormalizedRule< Item, string >;\n\tminLength?: NormalizedRule< Item, number >;\n\tmaxLength?: NormalizedRule< Item, number >;\n\tmin?: NormalizedRule< Item, number >;\n\tmax?: NormalizedRule< Item, number >;\n\tcustom?: CustomValidator< Item >;\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldTypeName, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldTypeName;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field can be hidden in the UI.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Retrieval function for elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\n\t/**\n\t * Display format configuration for fields.\n\t */\n\tformat?: FormatDatetime | FormatDate | FormatNumber | FormatInteger;\n\n\t/**\n\t * Callback used to format the value of the field for display.\n\t */\n\tgetValueFormatted?: ( {\n\t\titem,\n\t\tfield,\n\t}: {\n\t\titem: Item;\n\t\tfield: NormalizedField< Item >;\n\t} ) => string;\n};\n\n/**\n * Format for datetime fields:\n *\n * - datetime: the format string (e.g., \"M j, Y g:i a\" for \"Jan 1, 2021 2:30 pm\").\n * - weekStartsOn: to specify the first day of the week (0 for 'sunday', 1 for 'monday', etc.).\n *\n * If not provided, defaults to WordPress date format settings.\n */\nexport type FormatDatetime = {\n\tdatetime?: string;\n\tweekStartsOn?: DayNumber;\n};\n\n/**\n * Format for date fields:\n *\n * - date: the format string (e.g., 'F j, Y' for 'March 10, 2023')\n * - weekStartsOn: to specify the first day of the week (0 for 'sunday', 1 for 'monday', etc.).\n *\n * If not provided, defaults to WordPress date format settings.\n */\nexport type FormatDate = {\n\tdate?: string;\n\tweekStartsOn?: DayNumber;\n};\nexport type DayNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Format for number fields:\n *\n * - separatorThousand: character to use for thousand separators (e.g., ',')\n * - separatorDecimal: character to use for decimal point (e.g., '.')\n * - decimals: number of decimal places to display (e.g., 2)\n *\n * If not provided, defaults to ',' for thousands, '.' for decimal, 2 decimals.\n */\nexport type FormatNumber = {\n\tseparatorThousand?: string;\n\tseparatorDecimal?: string;\n\tdecimals?: number;\n};\n\n/**\n * Format for integer fields:\n *\n * - separatorThousand: character to use for thousand separators (e.g., ',')\n *\n * If not provided, defaults to ',' for thousands.\n */\nexport type FormatInteger = {\n\tseparatorThousand?: string;\n};\n\nexport type NormalizedField< Item > = Omit<\n\tField< Item >,\n\t'Edit' | 'isValid'\n> & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\tsetValue: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\thasElements: boolean;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: NormalizedRules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: Required< FilterByConfig > | false;\n\tfilter: FilterOperatorMap< Item >;\n\treadOnly: boolean;\n\tformat:\n\t\t| {}\n\t\t| Required< FormatDate >\n\t\t| Required< FormatInteger >\n\t\t| Required< FormatNumber >;\n\tgetValueFormatted: ( {\n\t\titem,\n\t\tfield,\n\t}: {\n\t\titem: Item;\n\t\tfield: NormalizedField< Item >;\n\t} ) => string;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type FieldValidity = {\n\trequired?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage?: string;\n\t};\n\tpattern?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmin?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmax?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tminLength?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmaxLength?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\telements?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tcustom?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tchildren?: Record< string, FieldValidity >;\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: DeepPartial< Item > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n\t/**\n\t * Validity information for the field, if any.\n\t */\n\tvalidity?: FieldValidity;\n\t/**\n\t * Configuration object for the control.\n\t */\n\tconfig?: {\n\t\tprefix?: React.ComponentType;\n\t\tsuffix?: React.ComponentType;\n\t\trows?: number;\n\t};\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Utility type that makes all properties of T optional recursively.\n * Used by field setValue functions to allow partial item updates.\n */\nexport type DeepPartial< T > = {\n\t[ P in keyof T ]?: T[ P ] extends object ? DeepPartial< T[ P ] > : T[ P ];\n};\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldTypeName =\n\t| 'text'\n\t| 'integer'\n\t| 'number'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'password'\n\t| 'telephone'\n\t| 'color'\n\t| 'url'\n\t| 'array';\n\nexport type Rules< Item > = {\n\trequired?: boolean;\n\telements?: boolean;\n\tpattern?: string;\n\tminLength?: number;\n\tmaxLength?: number;\n\tmin?: number;\n\tmax?: number;\n\tcustom?:\n\t\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t\t| ( (\n\t\t\t\titem: Item,\n\t\t\t\tfield: NormalizedField< Item >\n\t\t ) => Promise< null | string > );\n};\n\nexport type Validator< Item > = (\n\titem: Item,\n\tfield: NormalizedField< Item >\n) => boolean;\n\nexport type CustomValidator< Item > =\n\t| ( ( item: Item, field: NormalizedField< Item > ) => null | string )\n\t| ( (\n\t\t\titem: Item,\n\t\t\tfield: NormalizedField< Item >\n\t ) => Promise< null | string > );\n\nexport type FilterOperator< Item > = (\n\titem: Item,\n\tfield: NormalizedField< Item >,\n\tfilterValue: any\n) => boolean;\n\nexport type FilterOperatorMap< Item > = Partial<\n\tRecord< Operator, FilterOperator< Item > >\n>;\n\ntype NormalizedRule< Item, ConstraintType > = {\n\tconstraint: ConstraintType;\n\tvalidate: Validator< Item >;\n};\n\nexport type NormalizedRules< Item > = {\n\trequired?: NormalizedRule< Item, boolean >;\n\telements?: NormalizedRule< Item, boolean >;\n\tpattern?: NormalizedRule< Item, string >;\n\tminLength?: NormalizedRule< Item, number >;\n\tmaxLength?: NormalizedRule< Item, number >;\n\tmin?: NormalizedRule< Item, number >;\n\tmax?: NormalizedRule< Item, number >;\n\tcustom?: CustomValidator< Item >;\n};\n\n/**\n * Edit configuration for textarea controls.\n */\nexport type EditConfigTextarea = {\n\tcontrol: 'textarea';\n\t/**\n\t * Number of rows for the textarea.\n\t */\n\trows?: number;\n};\n\n/**\n * Edit configuration for text controls.\n */\nexport type EditConfigText = {\n\tcontrol: 'text';\n\t/**\n\t * Prefix component to display before the input.\n\t */\n\tprefix?: React.ComponentType;\n\t/**\n\t * Suffix component to display after the input.\n\t */\n\tsuffix?: React.ComponentType;\n};\n\n/**\n * Edit configuration for other control types (excluding 'text' and 'textarea').\n */\nexport type EditConfigGeneric = {\n\tcontrol: Exclude< FieldTypeName, 'text' | 'textarea' >;\n};\n\n/**\n * Edit configuration object with type-safe control options.\n * Each control type has its own specific configuration properties.\n */\nexport type EditConfig =\n\t| EditConfigTextarea\n\t| EditConfigText\n\t| EditConfigGeneric;\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldTypeName;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string | EditConfig;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: Rules< Item >;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field can be hidden in the UI.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Retrieval function for elements.\n\t */\n\tgetElements?: () => Promise< Option[] >;\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n\n\t/**\n\t * Callback used to set the value of the field on the item.\n\t * Used for editing operations to update field values.\n\t */\n\tsetValue?: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\n\t/**\n\t * Display format configuration for fields.\n\t */\n\tformat?: FormatDatetime | FormatDate | FormatNumber | FormatInteger;\n\n\t/**\n\t * Callback used to format the value of the field for display.\n\t */\n\tgetValueFormatted?: ( {\n\t\titem,\n\t\tfield,\n\t}: {\n\t\titem: Item;\n\t\tfield: NormalizedField< Item >;\n\t} ) => string;\n};\n\n/**\n * Format for datetime fields:\n *\n * - datetime: the format string (e.g., \"M j, Y g:i a\" for \"Jan 1, 2021 2:30 pm\").\n * - weekStartsOn: to specify the first day of the week (0 for 'sunday', 1 for 'monday', etc.).\n *\n * If not provided, defaults to WordPress date format settings.\n */\nexport type FormatDatetime = {\n\tdatetime?: string;\n\tweekStartsOn?: DayNumber;\n};\n\n/**\n * Format for date fields:\n *\n * - date: the format string (e.g., 'F j, Y' for 'March 10, 2023')\n * - weekStartsOn: to specify the first day of the week (0 for 'sunday', 1 for 'monday', etc.).\n *\n * If not provided, defaults to WordPress date format settings.\n */\nexport type FormatDate = {\n\tdate?: string;\n\tweekStartsOn?: DayNumber;\n};\nexport type DayNumber = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\n/**\n * Format for number fields:\n *\n * - separatorThousand: character to use for thousand separators (e.g., ',')\n * - separatorDecimal: character to use for decimal point (e.g., '.')\n * - decimals: number of decimal places to display (e.g., 2)\n *\n * If not provided, defaults to ',' for thousands, '.' for decimal, 2 decimals.\n */\nexport type FormatNumber = {\n\tseparatorThousand?: string;\n\tseparatorDecimal?: string;\n\tdecimals?: number;\n};\n\n/**\n * Format for integer fields:\n *\n * - separatorThousand: character to use for thousand separators (e.g., ',')\n *\n * If not provided, defaults to ',' for thousands.\n */\nexport type FormatInteger = {\n\tseparatorThousand?: string;\n};\n\nexport type NormalizedField< Item > = Omit<\n\tField< Item >,\n\t'Edit' | 'isValid'\n> & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\tsetValue: ( args: { item: Item; value: any } ) => DeepPartial< Item >;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\thasElements: boolean;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: NormalizedRules< Item >;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: Required< FilterByConfig > | false;\n\tfilter: FilterOperatorMap< Item >;\n\treadOnly: boolean;\n\tformat:\n\t\t| {}\n\t\t| Required< FormatDate >\n\t\t| Required< FormatInteger >\n\t\t| Required< FormatNumber >;\n\tgetValueFormatted: ( {\n\t\titem,\n\t\tfield,\n\t}: {\n\t\titem: Item;\n\t\tfield: NormalizedField< Item >;\n\t} ) => string;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type FieldValidity = {\n\trequired?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage?: string;\n\t};\n\tpattern?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmin?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmax?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tminLength?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tmaxLength?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\telements?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tcustom?: {\n\t\ttype: 'valid' | 'invalid' | 'validating';\n\t\tmessage: string;\n\t};\n\tchildren?: Record< string, FieldValidity >;\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: DeepPartial< Item > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * Label the control as \"optional\" when _not_ required, instead of showing \"required\".\n\t */\n\tmarkWhenOptional?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n\t/**\n\t * Validity information for the field, if any.\n\t */\n\tvalidity?: FieldValidity;\n\t/**\n\t * Configuration object for the control.\n\t */\n\tconfig?: {\n\t\tprefix?: React.ComponentType;\n\t\tsuffix?: React.ComponentType;\n\t\trows?: number;\n\t};\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n\tconfig?: {\n\t\tsizes: string;\n\t};\n};\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,21 @@
1
+ // packages/dataviews/src/components/dataform-controls/adaptive-select.tsx
2
+ import useElements from "../../hooks/use-elements.mjs";
3
+ import Combobox from "./combobox.mjs";
4
+ import Select from "./select.mjs";
5
+ import { jsx } from "react/jsx-runtime";
6
+ var ELEMENTS_THRESHOLD = 10;
7
+ function AdaptiveSelect(props) {
8
+ const { field } = props;
9
+ const { elements } = useElements({
10
+ elements: field.elements,
11
+ getElements: field.getElements
12
+ });
13
+ if (elements.length >= ELEMENTS_THRESHOLD) {
14
+ return /* @__PURE__ */ jsx(Combobox, { ...props });
15
+ }
16
+ return /* @__PURE__ */ jsx(Select, { ...props });
17
+ }
18
+ export {
19
+ AdaptiveSelect as default
20
+ };
21
+ //# sourceMappingURL=adaptive-select.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/dataform-controls/adaptive-select.tsx"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../../types';\nimport useElements from '../../hooks/use-elements';\nimport Combobox from './combobox';\nimport Select from './select';\n\nconst ELEMENTS_THRESHOLD = 10;\n\nexport default function AdaptiveSelect< Item >(\n\tprops: DataFormControlProps< Item >\n) {\n\tconst { field } = props;\n\tconst { elements } = useElements( {\n\t\telements: field.elements,\n\t\tgetElements: field.getElements,\n\t} );\n\tif ( elements.length >= ELEMENTS_THRESHOLD ) {\n\t\treturn <Combobox { ...props } />;\n\t}\n\treturn <Select { ...props } />;\n}\n"],
5
+ "mappings": ";AAIA,OAAO,iBAAiB;AACxB,OAAO,cAAc;AACrB,OAAO,YAAY;AAaV;AAXT,IAAM,qBAAqB;AAEZ,SAAR,eACN,OACC;AACD,QAAM,EAAE,MAAM,IAAI;AAClB,QAAM,EAAE,SAAS,IAAI,YAAa;AAAA,IACjC,UAAU,MAAM;AAAA,IAChB,aAAa,MAAM;AAAA,EACpB,CAAE;AACF,MAAK,SAAS,UAAU,oBAAqB;AAC5C,WAAO,oBAAC,YAAW,GAAG,OAAQ;AAAA,EAC/B;AACA,SAAO,oBAAC,UAAS,GAAG,OAAQ;AAC7B;",
6
+ "names": []
7
+ }
@@ -11,6 +11,7 @@ function ArrayControl({
11
11
  field,
12
12
  onChange,
13
13
  hideLabelFromVision,
14
+ markWhenOptional,
14
15
  validity
15
16
  }) {
16
17
  const { label, placeholder, getValue, setValue, isValid } = field;
@@ -47,6 +48,7 @@ function ArrayControl({
47
48
  ValidatedFormTokenField,
48
49
  {
49
50
  required: !!isValid?.required,
51
+ markWhenOptional,
50
52
  customValidity: getCustomValidity(isValid, validity),
51
53
  label: hideLabelFromVision ? void 0 : label,
52
54
  value: arrayValueAsElements,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/dataform-controls/array.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis, Spinner } from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../../types';\nimport { unlock } from '../../lock-unlock';\nimport getCustomValidity from './utils/get-custom-validity';\nimport useElements from '../../hooks/use-elements';\n\nconst { ValidatedFormTokenField } = unlock( privateApis );\n\nexport default function ArrayControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tvalidity,\n}: DataFormControlProps< Item > ) {\n\tconst { label, placeholder, getValue, setValue, isValid } = field;\n\tconst value = getValue( { item: data } );\n\n\tconst { elements, isLoading } = useElements( {\n\t\telements: field.elements,\n\t\tgetElements: field.getElements,\n\t} );\n\n\t// Convert stored values to element objects for the token field\n\tconst arrayValueAsElements = useMemo(\n\t\t() =>\n\t\t\tArray.isArray( value )\n\t\t\t\t? value.map( ( token ) => {\n\t\t\t\t\t\tconst element = elements?.find(\n\t\t\t\t\t\t\t( suggestion ) => suggestion.value === token\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn element || { value: token, label: token };\n\t\t\t\t } )\n\t\t\t\t: [],\n\t\t[ value, elements ]\n\t);\n\n\tconst onChangeControl = useCallback(\n\t\t( tokens: ( string | { value: string; label?: string } )[] ) => {\n\t\t\tconst valueTokens = tokens.map( ( token ) => {\n\t\t\t\tif ( typeof token === 'object' && 'value' in token ) {\n\t\t\t\t\treturn token.value;\n\t\t\t\t}\n\t\t\t\t// If it's a string, it's either a new suggestion value or user input\n\t\t\t\treturn token;\n\t\t\t} );\n\n\t\t\tonChange( setValue( { item: data, value: valueTokens } ) );\n\t\t},\n\t\t[ onChange, setValue, data ]\n\t);\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\treturn (\n\t\t<ValidatedFormTokenField\n\t\t\trequired={ !! isValid?.required }\n\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\tlabel={ hideLabelFromVision ? undefined : label }\n\t\t\tvalue={ arrayValueAsElements }\n\t\t\tonChange={ onChangeControl }\n\t\t\tplaceholder={ placeholder }\n\t\t\tsuggestions={ elements?.map( ( element ) => element.value ) }\n\t\t\t__experimentalValidateInput={ ( token: string ) => {\n\t\t\t\t// If elements validation is required, check if token is valid\n\t\t\t\tif ( field.isValid?.elements && elements ) {\n\t\t\t\t\treturn elements.some(\n\t\t\t\t\t\t( element ) =>\n\t\t\t\t\t\t\telement.value === token || element.label === token\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// For non-elements validation, allow all tokens\n\t\t\t\treturn true;\n\t\t\t} }\n\t\t\t__experimentalExpandOnFocus={ elements && elements.length > 0 }\n\t\t\t__experimentalShowHowTo={ ! field.isValid?.elements }\n\t\t\tdisplayTransform={ ( token: any ) => {\n\t\t\t\t// For existing tokens (element objects), display their label\n\t\t\t\tif ( typeof token === 'object' && 'label' in token ) {\n\t\t\t\t\treturn token.label;\n\t\t\t\t}\n\t\t\t\t// For suggestions (value strings), find the corresponding element and show its label\n\t\t\t\tif ( typeof token === 'string' && elements ) {\n\t\t\t\t\tconst element = elements.find(\n\t\t\t\t\t\t( el ) => el.value === token\n\t\t\t\t\t);\n\t\t\t\t\treturn element?.label || token;\n\t\t\t\t}\n\t\t\t\treturn token;\n\t\t\t} }\n\t\t\t__experimentalRenderItem={ ( { item }: { item: any } ) => {\n\t\t\t\t// Custom rendering for suggestion items (item is a value string)\n\t\t\t\tif ( typeof item === 'string' && elements ) {\n\t\t\t\t\tconst element = elements.find(\n\t\t\t\t\t\t( el ) => el.value === item\n\t\t\t\t\t);\n\t\t\t\t\treturn <span>{ element?.label || item }</span>;\n\t\t\t\t}\n\t\t\t\treturn <span>{ item }</span>;\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,eAAe;AAMrC,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AAiDf;AA/CT,IAAM,EAAE,wBAAwB,IAAI,OAAQ,WAAY;AAEzC,SAAR,aAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,EAAE,OAAO,aAAa,UAAU,UAAU,QAAQ,IAAI;AAC5D,QAAM,QAAQ,SAAU,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8B,YAAY,SAAS,SAAS;AAAA,MAC5D,yBAA0B,CAAE,MAAM,SAAS;AAAA,MAC3C,kBAAmB,CAAE,UAAgB;AAEpC,YAAK,OAAO,UAAU,YAAY,WAAW,OAAQ;AACpD,iBAAO,MAAM;AAAA,QACd;AAEA,YAAK,OAAO,UAAU,YAAY,UAAW;AAC5C,gBAAM,UAAU,SAAS;AAAA,YACxB,CAAE,OAAQ,GAAG,UAAU;AAAA,UACxB;AACA,iBAAO,SAAS,SAAS;AAAA,QAC1B;AACA,eAAO;AAAA,MACR;AAAA,MACA,0BAA2B,CAAE,EAAE,KAAK,MAAsB;AAEzD,YAAK,OAAO,SAAS,YAAY,UAAW;AAC3C,gBAAM,UAAU,SAAS;AAAA,YACxB,CAAE,OAAQ,GAAG,UAAU;AAAA,UACxB;AACA,iBAAO,oBAAC,UAAO,mBAAS,SAAS,MAAM;AAAA,QACxC;AACA,eAAO,oBAAC,UAAO,gBAAM;AAAA,MACtB;AAAA;AAAA,EACD;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis, Spinner } from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../../types';\nimport { unlock } from '../../lock-unlock';\nimport getCustomValidity from './utils/get-custom-validity';\nimport useElements from '../../hooks/use-elements';\n\nconst { ValidatedFormTokenField } = unlock( privateApis );\n\nexport default function ArrayControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n}: DataFormControlProps< Item > ) {\n\tconst { label, placeholder, getValue, setValue, isValid } = field;\n\tconst value = getValue( { item: data } );\n\n\tconst { elements, isLoading } = useElements( {\n\t\telements: field.elements,\n\t\tgetElements: field.getElements,\n\t} );\n\n\t// Convert stored values to element objects for the token field\n\tconst arrayValueAsElements = useMemo(\n\t\t() =>\n\t\t\tArray.isArray( value )\n\t\t\t\t? value.map( ( token ) => {\n\t\t\t\t\t\tconst element = elements?.find(\n\t\t\t\t\t\t\t( suggestion ) => suggestion.value === token\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn element || { value: token, label: token };\n\t\t\t\t } )\n\t\t\t\t: [],\n\t\t[ value, elements ]\n\t);\n\n\tconst onChangeControl = useCallback(\n\t\t( tokens: ( string | { value: string; label?: string } )[] ) => {\n\t\t\tconst valueTokens = tokens.map( ( token ) => {\n\t\t\t\tif ( typeof token === 'object' && 'value' in token ) {\n\t\t\t\t\treturn token.value;\n\t\t\t\t}\n\t\t\t\t// If it's a string, it's either a new suggestion value or user input\n\t\t\t\treturn token;\n\t\t\t} );\n\n\t\t\tonChange( setValue( { item: data, value: valueTokens } ) );\n\t\t},\n\t\t[ onChange, setValue, data ]\n\t);\n\n\tif ( isLoading ) {\n\t\treturn <Spinner />;\n\t}\n\n\treturn (\n\t\t<ValidatedFormTokenField\n\t\t\trequired={ !! isValid?.required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\tlabel={ hideLabelFromVision ? undefined : label }\n\t\t\tvalue={ arrayValueAsElements }\n\t\t\tonChange={ onChangeControl }\n\t\t\tplaceholder={ placeholder }\n\t\t\tsuggestions={ elements?.map( ( element ) => element.value ) }\n\t\t\t__experimentalValidateInput={ ( token: string ) => {\n\t\t\t\t// If elements validation is required, check if token is valid\n\t\t\t\tif ( field.isValid?.elements && elements ) {\n\t\t\t\t\treturn elements.some(\n\t\t\t\t\t\t( element ) =>\n\t\t\t\t\t\t\telement.value === token || element.label === token\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// For non-elements validation, allow all tokens\n\t\t\t\treturn true;\n\t\t\t} }\n\t\t\t__experimentalExpandOnFocus={ elements && elements.length > 0 }\n\t\t\t__experimentalShowHowTo={ ! field.isValid?.elements }\n\t\t\tdisplayTransform={ ( token: any ) => {\n\t\t\t\t// For existing tokens (element objects), display their label\n\t\t\t\tif ( typeof token === 'object' && 'label' in token ) {\n\t\t\t\t\treturn token.label;\n\t\t\t\t}\n\t\t\t\t// For suggestions (value strings), find the corresponding element and show its label\n\t\t\t\tif ( typeof token === 'string' && elements ) {\n\t\t\t\t\tconst element = elements.find(\n\t\t\t\t\t\t( el ) => el.value === token\n\t\t\t\t\t);\n\t\t\t\t\treturn element?.label || token;\n\t\t\t\t}\n\t\t\t\treturn token;\n\t\t\t} }\n\t\t\t__experimentalRenderItem={ ( { item }: { item: any } ) => {\n\t\t\t\t// Custom rendering for suggestion items (item is a value string)\n\t\t\t\tif ( typeof item === 'string' && elements ) {\n\t\t\t\t\tconst element = elements.find(\n\t\t\t\t\t\t( el ) => el.value === item\n\t\t\t\t\t);\n\t\t\t\t\treturn <span>{ element?.label || item }</span>;\n\t\t\t\t}\n\t\t\t\treturn <span>{ item }</span>;\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,eAAe;AAMrC,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAC9B,OAAO,iBAAiB;AAkDf;AAhDT,IAAM,EAAE,wBAAwB,IAAI,OAAQ,WAAY;AAEzC,SAAR,aAAuC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,EAAE,OAAO,aAAa,UAAU,UAAU,QAAQ,IAAI;AAC5D,QAAM,QAAQ,SAAU,EAAE,MAAM,KAAK,CAAE;AAEvC,QAAM,EAAE,UAAU,UAAU,IAAI,YAAa;AAAA,IAC5C,UAAU,MAAM;AAAA,IAChB,aAAa,MAAM;AAAA,EACpB,CAAE;AAGF,QAAM,uBAAuB;AAAA,IAC5B,MACC,MAAM,QAAS,KAAM,IAClB,MAAM,IAAK,CAAE,UAAW;AACxB,YAAM,UAAU,UAAU;AAAA,QACzB,CAAE,eAAgB,WAAW,UAAU;AAAA,MACxC;AACA,aAAO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,SAAS,SAAS;AAAA,QAC1B;AACA,eAAO;AAAA,MACR;AAAA,MACA,0BAA2B,CAAE,EAAE,KAAK,MAAsB;AAEzD,YAAK,OAAO,SAAS,YAAY,UAAW;AAC3C,gBAAM,UAAU,SAAS;AAAA,YACxB,CAAE,OAAQ,GAAG,UAAU;AAAA,UACxB;AACA,iBAAO,oBAAC,UAAO,mBAAS,SAAS,MAAM;AAAA,QACxC;AACA,eAAO,oBAAC,UAAO,gBAAM;AAAA,MACtB;AAAA;AAAA,EACD;AAEF;",
6
6
  "names": []
7
7
  }
@@ -10,6 +10,7 @@ function Checkbox({
10
10
  onChange,
11
11
  data,
12
12
  hideLabelFromVision,
13
+ markWhenOptional,
13
14
  validity
14
15
  }) {
15
16
  const { getValue, setValue, label, description, isValid } = field;
@@ -22,6 +23,7 @@ function Checkbox({
22
23
  ValidatedCheckboxControl,
23
24
  {
24
25
  required: !!field.isValid?.required,
26
+ markWhenOptional,
25
27
  customValidity: getCustomValidity(isValid, validity),
26
28
  hidden: hideLabelFromVision,
27
29
  label,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/dataform-controls/checkbox.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../../types';\nimport { unlock } from '../../lock-unlock';\nimport getCustomValidity from './utils/get-custom-validity';\n\nconst { ValidatedCheckboxControl } = unlock( privateApis );\n\nexport default function Checkbox< Item >( {\n\tfield,\n\tonChange,\n\tdata,\n\thideLabelFromVision,\n\tvalidity,\n}: DataFormControlProps< Item > ) {\n\tconst { getValue, setValue, label, description, isValid } = field;\n\n\tconst onChangeControl = useCallback( () => {\n\t\tonChange(\n\t\t\tsetValue( { item: data, value: ! getValue( { item: data } ) } )\n\t\t);\n\t}, [ data, getValue, onChange, setValue ] );\n\n\treturn (\n\t\t<ValidatedCheckboxControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\thidden={ hideLabelFromVision }\n\t\t\tlabel={ label }\n\t\t\thelp={ description }\n\t\t\tchecked={ getValue( { item: data } ) }\n\t\t\tonChange={ onChangeControl }\n\t\t/>\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAM5B,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAoB5B;AAlBF,IAAM,EAAE,yBAAyB,IAAI,OAAQ,WAAY;AAE1C,SAAR,SAAmC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,EAAE,UAAU,UAAU,OAAO,aAAa,QAAQ,IAAI;AAE5D,QAAM,kBAAkB,YAAa,MAAM;AAC1C;AAAA,MACC,SAAU,EAAE,MAAM,MAAM,OAAO,CAAE,SAAU,EAAE,MAAM,KAAK,CAAE,EAAE,CAAE;AAAA,IAC/D;AAAA,EACD,GAAG,CAAE,MAAM,UAAU,UAAU,QAAS,CAAE;AAE1C,SACC;AAAA,IAAC;AAAA;AAAA,MACA,UAAW,CAAC,CAAE,MAAM,SAAS;AAAA,MAC7B,gBAAiB,kBAAmB,SAAS,QAAS;AAAA,MACtD,QAAS;AAAA,MACT;AAAA,MACA,MAAO;AAAA,MACP,SAAU,SAAU,EAAE,MAAM,KAAK,CAAE;AAAA,MACnC,UAAW;AAAA;AAAA,EACZ;AAEF;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { privateApis } from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { DataFormControlProps } from '../../types';\nimport { unlock } from '../../lock-unlock';\nimport getCustomValidity from './utils/get-custom-validity';\n\nconst { ValidatedCheckboxControl } = unlock( privateApis );\n\nexport default function Checkbox< Item >( {\n\tfield,\n\tonChange,\n\tdata,\n\thideLabelFromVision,\n\tmarkWhenOptional,\n\tvalidity,\n}: DataFormControlProps< Item > ) {\n\tconst { getValue, setValue, label, description, isValid } = field;\n\n\tconst onChangeControl = useCallback( () => {\n\t\tonChange(\n\t\t\tsetValue( { item: data, value: ! getValue( { item: data } ) } )\n\t\t);\n\t}, [ data, getValue, onChange, setValue ] );\n\n\treturn (\n\t\t<ValidatedCheckboxControl\n\t\t\trequired={ !! field.isValid?.required }\n\t\t\tmarkWhenOptional={ markWhenOptional }\n\t\t\tcustomValidity={ getCustomValidity( isValid, validity ) }\n\t\t\thidden={ hideLabelFromVision }\n\t\t\tlabel={ label }\n\t\t\thelp={ description }\n\t\t\tchecked={ getValue( { item: data } ) }\n\t\t\tonChange={ onChangeControl }\n\t\t/>\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAM5B,SAAS,cAAc;AACvB,OAAO,uBAAuB;AAqB5B;AAnBF,IAAM,EAAE,yBAAyB,IAAI,OAAQ,WAAY;AAE1C,SAAR,SAAmC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAAkC;AACjC,QAAM,EAAE,UAAU,UAAU,OAAO,aAAa,QAAQ,IAAI;AAE5D,QAAM,kBAAkB,YAAa,MAAM;AAC1C;AAAA,MACC,SAAU,EAAE,MAAM,MAAM,OAAO,CAAE,SAAU,EAAE,MAAM,KAAK,CAAE,EAAE,CAAE;AAAA,IAC/D;AAAA,EACD,GAAG,CAAE,MAAM,UAAU,UAAU,QAAS,CAAE;AAE1C,SACC;AAAA,IAAC;AAAA;AAAA,MACA,UAAW,CAAC,CAAE,MAAM,SAAS;AAAA,MAC7B;AAAA,MACA,gBAAiB,kBAAmB,SAAS,QAAS;AAAA,MACtD,QAAS;AAAA,MACT;AAAA,MACA,MAAO;AAAA,MACP,SAAU,SAAU,EAAE,MAAM,KAAK,CAAE;AAAA,MACnC,UAAW;AAAA;AAAA,EACZ;AAEF;",
6
6
  "names": []
7
7
  }
@@ -1,16 +1,21 @@
1
1
  // packages/dataviews/src/components/dataform-controls/color.tsx
2
2
  import { colord } from "colord";
3
3
  import {
4
+ Button,
5
+ ColorIndicator,
6
+ ColorPicker,
4
7
  Dropdown,
5
8
  privateApis,
6
- __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper
9
+ __experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
10
+ __experimentalDropdownContentWrapper as DropdownContentWrapper
7
11
  } from "@wordpress/components";
8
12
  import { useCallback } from "@wordpress/element";
13
+ import { __ } from "@wordpress/i18n";
9
14
  import { unlock } from "../../lock-unlock.mjs";
10
15
  import getCustomValidity from "./utils/get-custom-validity.mjs";
11
16
  import { jsx } from "react/jsx-runtime";
12
- var { ValidatedInputControl, Picker } = unlock(privateApis);
13
- var ColorPicker = ({
17
+ var { ValidatedInputControl } = unlock(privateApis);
18
+ var ColorPickerDropdown = ({
14
19
  color,
15
20
  onColorChange
16
21
  }) => {
@@ -18,33 +23,21 @@ var ColorPicker = ({
18
23
  return /* @__PURE__ */ jsx(
19
24
  Dropdown,
20
25
  {
21
- renderToggle: ({ onToggle, isOpen }) => /* @__PURE__ */ jsx(InputControlPrefixWrapper, { variant: "icon", children: /* @__PURE__ */ jsx(
22
- "button",
26
+ className: "dataviews-controls__color-picker-dropdown",
27
+ popoverProps: { resize: false },
28
+ renderToggle: ({ onToggle }) => /* @__PURE__ */ jsx(
29
+ Button,
23
30
  {
24
- type: "button",
25
31
  onClick: onToggle,
26
- style: {
27
- width: "24px",
28
- height: "24px",
29
- borderRadius: "50%",
30
- backgroundColor: validColor,
31
- border: "1px solid #ddd",
32
- cursor: "pointer",
33
- outline: isOpen ? "2px solid #007cba" : "none",
34
- outlineOffset: "2px",
35
- display: "flex",
36
- alignItems: "center",
37
- justifyContent: "center",
38
- padding: 0,
39
- margin: 0
40
- },
41
- "aria-label": "Open color picker"
32
+ "aria-label": __("Open color picker"),
33
+ size: "small",
34
+ icon: () => /* @__PURE__ */ jsx(ColorIndicator, { colorValue: validColor })
42
35
  }
43
- ) }),
44
- renderContent: () => /* @__PURE__ */ jsx("div", { style: { padding: "16px" }, children: /* @__PURE__ */ jsx(
45
- Picker,
36
+ ),
37
+ renderContent: () => /* @__PURE__ */ jsx(DropdownContentWrapper, { paddingSize: "none", children: /* @__PURE__ */ jsx(
38
+ ColorPicker,
46
39
  {
47
- color: colord(validColor),
40
+ color: validColor,
48
41
  onChange: onColorChange,
49
42
  enableAlpha: true
50
43
  }
@@ -57,13 +50,14 @@ function Color({
57
50
  field,
58
51
  onChange,
59
52
  hideLabelFromVision,
53
+ markWhenOptional,
60
54
  validity
61
55
  }) {
62
56
  const { label, placeholder, description, setValue, isValid } = field;
63
57
  const value = field.getValue({ item: data }) || "";
64
58
  const handleColorChange = useCallback(
65
- (colorObject) => {
66
- onChange(setValue({ item: data, value: colorObject.toHex() }));
59
+ (newColor) => {
60
+ onChange(setValue({ item: data, value: newColor }));
67
61
  },
68
62
  [data, onChange, setValue]
69
63
  );
@@ -77,6 +71,7 @@ function Color({
77
71
  ValidatedInputControl,
78
72
  {
79
73
  required: !!field.isValid?.required,
74
+ markWhenOptional,
80
75
  customValidity: getCustomValidity(isValid, validity),
81
76
  label,
82
77
  placeholder,
@@ -85,13 +80,13 @@ function Color({
85
80
  onChange: handleInputChange,
86
81
  hideLabelFromVision,
87
82
  type: "text",
88
- prefix: /* @__PURE__ */ jsx(
89
- ColorPicker,
83
+ prefix: /* @__PURE__ */ jsx(InputControlPrefixWrapper, { variant: "control", children: /* @__PURE__ */ jsx(
84
+ ColorPickerDropdown,
90
85
  {
91
86
  color: value,
92
87
  onColorChange: handleColorChange
93
88
  }
94
- )
89
+ ) })
95
90
  }
96
91
  );
97
92
  }