@wordpress/dataviews 4.22.0 → 5.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 (343) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +147 -32
  3. package/build/components/dataviews/index.js +71 -37
  4. package/build/components/dataviews/index.js.map +1 -1
  5. package/build/components/dataviews-context/index.js +15 -1
  6. package/build/components/dataviews-context/index.js.map +1 -1
  7. package/build/components/dataviews-filters/{filter-summary.js → filter.js} +108 -17
  8. package/build/components/dataviews-filters/filter.js.map +1 -0
  9. package/build/components/dataviews-filters/index.js +21 -20
  10. package/build/components/dataviews-filters/index.js.map +1 -1
  11. package/build/components/dataviews-filters/input-widget.js +76 -0
  12. package/build/components/dataviews-filters/input-widget.js.map +1 -0
  13. package/build/components/dataviews-filters/search-widget.js +33 -39
  14. package/build/components/dataviews-filters/search-widget.js.map +1 -1
  15. package/build/components/dataviews-filters/utils.js +25 -0
  16. package/build/components/dataviews-filters/utils.js.map +1 -0
  17. package/build/components/dataviews-item-actions/index.js +1 -1
  18. package/build/components/dataviews-item-actions/index.js.map +1 -1
  19. package/build/components/dataviews-layout/index.js +7 -2
  20. package/build/components/dataviews-layout/index.js.map +1 -1
  21. package/build/components/dataviews-pagination/index.js +4 -3
  22. package/build/components/dataviews-pagination/index.js.map +1 -1
  23. package/build/components/dataviews-selection-checkbox/index.js.map +1 -1
  24. package/build/components/dataviews-view-config/index.js +10 -19
  25. package/build/components/dataviews-view-config/index.js.map +1 -1
  26. package/build/constants.js +83 -2
  27. package/build/constants.js.map +1 -1
  28. package/build/dataform-controls/boolean.js +42 -0
  29. package/build/dataform-controls/boolean.js.map +1 -0
  30. package/build/dataform-controls/checkbox.js +44 -0
  31. package/build/dataform-controls/checkbox.js.map +1 -0
  32. package/build/dataform-controls/datetime.js +96 -2
  33. package/build/dataform-controls/datetime.js.map +1 -1
  34. package/build/dataform-controls/email.js +48 -0
  35. package/build/dataform-controls/email.js.map +1 -0
  36. package/build/dataform-controls/index.js +9 -1
  37. package/build/dataform-controls/index.js.map +1 -1
  38. package/build/dataform-controls/integer.js +49 -1
  39. package/build/dataform-controls/integer.js.map +1 -1
  40. package/build/dataform-controls/select.js +1 -0
  41. package/build/dataform-controls/select.js.map +1 -1
  42. package/build/dataform-controls/text.js +3 -1
  43. package/build/dataform-controls/text.js.map +1 -1
  44. package/build/dataform-controls/toggle-group.js +52 -0
  45. package/build/dataform-controls/toggle-group.js.map +1 -0
  46. package/build/dataforms-layouts/data-form-layout.js +1 -1
  47. package/build/dataforms-layouts/data-form-layout.js.map +1 -1
  48. package/build/dataforms-layouts/panel/index.js +14 -5
  49. package/build/dataforms-layouts/panel/index.js.map +1 -1
  50. package/build/dataforms-layouts/regular/index.js +23 -4
  51. package/build/dataforms-layouts/regular/index.js.map +1 -1
  52. package/build/dataviews-layouts/grid/index.js +89 -27
  53. package/build/dataviews-layouts/grid/index.js.map +1 -1
  54. package/build/dataviews-layouts/list/index.js +11 -6
  55. package/build/dataviews-layouts/list/index.js.map +1 -1
  56. package/build/dataviews-layouts/table/column-header-menu.js +9 -7
  57. package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
  58. package/build/dataviews-layouts/table/column-primary.js +18 -13
  59. package/build/dataviews-layouts/table/column-primary.js.map +1 -1
  60. package/build/dataviews-layouts/table/index.js +46 -14
  61. package/build/dataviews-layouts/table/index.js.map +1 -1
  62. package/build/dataviews-layouts/table/use-is-horizontal-scroll-end.js +65 -0
  63. package/build/dataviews-layouts/table/use-is-horizontal-scroll-end.js.map +1 -0
  64. package/build/dataviews-layouts/utils/item-click-wrapper.js +77 -0
  65. package/build/dataviews-layouts/utils/item-click-wrapper.js.map +1 -0
  66. package/build/field-types/array.js +62 -0
  67. package/build/field-types/array.js.map +1 -0
  68. package/build/field-types/boolean.js +71 -0
  69. package/build/field-types/boolean.js.map +1 -0
  70. package/build/field-types/date.js +57 -0
  71. package/build/field-types/date.js.map +1 -0
  72. package/build/field-types/datetime.js +19 -1
  73. package/build/field-types/datetime.js.map +1 -1
  74. package/build/field-types/email.js +60 -0
  75. package/build/field-types/email.js.map +1 -0
  76. package/build/field-types/index.js +42 -1
  77. package/build/field-types/index.js.map +1 -1
  78. package/build/field-types/integer.js +23 -1
  79. package/build/field-types/integer.js.map +1 -1
  80. package/build/field-types/media.js +31 -0
  81. package/build/field-types/media.js.map +1 -0
  82. package/build/field-types/text.js +23 -1
  83. package/build/field-types/text.js.map +1 -1
  84. package/build/filter-and-sort-data-view.js +174 -11
  85. package/build/filter-and-sort-data-view.js.map +1 -1
  86. package/build/normalize-fields.js +72 -11
  87. package/build/normalize-fields.js.map +1 -1
  88. package/build/types.js.map +1 -1
  89. package/build/utils.js +11 -19
  90. package/build/utils.js.map +1 -1
  91. package/build-module/components/dataviews/index.js +74 -40
  92. package/build-module/components/dataviews/index.js.map +1 -1
  93. package/build-module/components/dataviews-context/index.js +16 -2
  94. package/build-module/components/dataviews-context/index.js.map +1 -1
  95. package/build-module/components/dataviews-filters/filter.js +309 -0
  96. package/build-module/components/dataviews-filters/filter.js.map +1 -0
  97. package/build-module/components/dataviews-filters/index.js +22 -21
  98. package/build-module/components/dataviews-filters/index.js.map +1 -1
  99. package/build-module/components/dataviews-filters/input-widget.js +69 -0
  100. package/build-module/components/dataviews-filters/input-widget.js.map +1 -0
  101. package/build-module/components/dataviews-filters/search-widget.js +31 -37
  102. package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
  103. package/build-module/components/dataviews-filters/utils.js +18 -0
  104. package/build-module/components/dataviews-filters/utils.js.map +1 -0
  105. package/build-module/components/dataviews-item-actions/index.js +1 -1
  106. package/build-module/components/dataviews-item-actions/index.js.map +1 -1
  107. package/build-module/components/dataviews-layout/index.js +7 -2
  108. package/build-module/components/dataviews-layout/index.js.map +1 -1
  109. package/build-module/components/dataviews-pagination/index.js +4 -4
  110. package/build-module/components/dataviews-pagination/index.js.map +1 -1
  111. package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -1
  112. package/build-module/components/dataviews-view-config/index.js +9 -20
  113. package/build-module/components/dataviews-view-config/index.js.map +1 -1
  114. package/build-module/constants.js +82 -1
  115. package/build-module/constants.js.map +1 -1
  116. package/build-module/dataform-controls/boolean.js +35 -0
  117. package/build-module/dataform-controls/boolean.js.map +1 -0
  118. package/build-module/dataform-controls/checkbox.js +37 -0
  119. package/build-module/dataform-controls/checkbox.js.map +1 -0
  120. package/build-module/dataform-controls/datetime.js +98 -3
  121. package/build-module/dataform-controls/datetime.js.map +1 -1
  122. package/build-module/dataform-controls/email.js +41 -0
  123. package/build-module/dataform-controls/email.js.map +1 -0
  124. package/build-module/dataform-controls/index.js +9 -1
  125. package/build-module/dataform-controls/index.js.map +1 -1
  126. package/build-module/dataform-controls/integer.js +51 -3
  127. package/build-module/dataform-controls/integer.js.map +1 -1
  128. package/build-module/dataform-controls/select.js +1 -0
  129. package/build-module/dataform-controls/select.js.map +1 -1
  130. package/build-module/dataform-controls/text.js +3 -1
  131. package/build-module/dataform-controls/text.js.map +1 -1
  132. package/build-module/dataform-controls/toggle-group.js +45 -0
  133. package/build-module/dataform-controls/toggle-group.js.map +1 -0
  134. package/build-module/dataforms-layouts/data-form-layout.js +1 -1
  135. package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
  136. package/build-module/dataforms-layouts/panel/index.js +14 -5
  137. package/build-module/dataforms-layouts/panel/index.js.map +1 -1
  138. package/build-module/dataforms-layouts/regular/index.js +23 -4
  139. package/build-module/dataforms-layouts/regular/index.js.map +1 -1
  140. package/build-module/dataviews-layouts/grid/index.js +90 -29
  141. package/build-module/dataviews-layouts/grid/index.js.map +1 -1
  142. package/build-module/dataviews-layouts/list/index.js +11 -6
  143. package/build-module/dataviews-layouts/list/index.js.map +1 -1
  144. package/build-module/dataviews-layouts/table/column-header-menu.js +9 -7
  145. package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
  146. package/build-module/dataviews-layouts/table/column-primary.js +18 -12
  147. package/build-module/dataviews-layouts/table/column-primary.js.map +1 -1
  148. package/build-module/dataviews-layouts/table/index.js +47 -16
  149. package/build-module/dataviews-layouts/table/index.js.map +1 -1
  150. package/build-module/dataviews-layouts/table/use-is-horizontal-scroll-end.js +58 -0
  151. package/build-module/dataviews-layouts/table/use-is-horizontal-scroll-end.js.map +1 -0
  152. package/build-module/dataviews-layouts/utils/item-click-wrapper.js +71 -0
  153. package/build-module/dataviews-layouts/utils/item-click-wrapper.js.map +1 -0
  154. package/build-module/field-types/array.js +57 -0
  155. package/build-module/field-types/array.js.map +1 -0
  156. package/build-module/field-types/boolean.js +65 -0
  157. package/build-module/field-types/boolean.js.map +1 -0
  158. package/build-module/field-types/date.js +51 -0
  159. package/build-module/field-types/date.js.map +1 -0
  160. package/build-module/field-types/datetime.js +19 -1
  161. package/build-module/field-types/datetime.js.map +1 -1
  162. package/build-module/field-types/email.js +54 -0
  163. package/build-module/field-types/email.js.map +1 -0
  164. package/build-module/field-types/index.js +42 -1
  165. package/build-module/field-types/index.js.map +1 -1
  166. package/build-module/field-types/integer.js +23 -1
  167. package/build-module/field-types/integer.js.map +1 -1
  168. package/build-module/field-types/media.js +25 -0
  169. package/build-module/field-types/media.js.map +1 -0
  170. package/build-module/field-types/text.js +23 -1
  171. package/build-module/field-types/text.js.map +1 -1
  172. package/build-module/filter-and-sort-data-view.js +175 -12
  173. package/build-module/filter-and-sort-data-view.js.map +1 -1
  174. package/build-module/normalize-fields.js +72 -11
  175. package/build-module/normalize-fields.js.map +1 -1
  176. package/build-module/types.js.map +1 -1
  177. package/build-module/utils.js +10 -17
  178. package/build-module/utils.js.map +1 -1
  179. package/build-style/style-rtl.css +315 -13
  180. package/build-style/style.css +315 -13
  181. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
  182. package/build-types/components/dataviews/index.d.ts +24 -3
  183. package/build-types/components/dataviews/index.d.ts.map +1 -1
  184. package/build-types/components/dataviews/stories/fixtures.d.ts +10 -1
  185. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
  186. package/build-types/components/dataviews/stories/index.story.d.ts +23 -4
  187. package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
  188. package/build-types/components/dataviews-context/index.d.ts +14 -1
  189. package/build-types/components/dataviews-context/index.d.ts.map +1 -1
  190. package/build-types/components/dataviews-filters/filter.d.ts +15 -0
  191. package/build-types/components/dataviews-filters/filter.d.ts.map +1 -0
  192. package/build-types/components/dataviews-filters/index.d.ts +3 -8
  193. package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
  194. package/build-types/components/dataviews-filters/input-widget.d.ts +13 -0
  195. package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -0
  196. package/build-types/components/dataviews-filters/search-widget.d.ts +4 -5
  197. package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
  198. package/build-types/components/dataviews-filters/utils.d.ts +6 -0
  199. package/build-types/components/dataviews-filters/utils.d.ts.map +1 -0
  200. package/build-types/components/dataviews-layout/index.d.ts +5 -1
  201. package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
  202. package/build-types/components/dataviews-pagination/index.d.ts +1 -1
  203. package/build-types/components/dataviews-pagination/index.d.ts.map +1 -1
  204. package/build-types/components/dataviews-selection-checkbox/index.d.ts +2 -2
  205. package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
  206. package/build-types/components/dataviews-view-config/index.d.ts +3 -4
  207. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  208. package/build-types/components/stories/index.story.d.ts +63 -0
  209. package/build-types/components/stories/index.story.d.ts.map +1 -0
  210. package/build-types/constants.d.ts +20 -3
  211. package/build-types/constants.d.ts.map +1 -1
  212. package/build-types/dataform-controls/boolean.d.ts +6 -0
  213. package/build-types/dataform-controls/boolean.d.ts.map +1 -0
  214. package/build-types/dataform-controls/checkbox.d.ts +6 -0
  215. package/build-types/dataform-controls/checkbox.d.ts.map +1 -0
  216. package/build-types/dataform-controls/datetime.d.ts +1 -1
  217. package/build-types/dataform-controls/datetime.d.ts.map +1 -1
  218. package/build-types/dataform-controls/email.d.ts +6 -0
  219. package/build-types/dataform-controls/email.d.ts.map +1 -0
  220. package/build-types/dataform-controls/index.d.ts +1 -1
  221. package/build-types/dataform-controls/index.d.ts.map +1 -1
  222. package/build-types/dataform-controls/integer.d.ts +1 -4
  223. package/build-types/dataform-controls/integer.d.ts.map +1 -1
  224. package/build-types/dataform-controls/select.d.ts.map +1 -1
  225. package/build-types/dataform-controls/text.d.ts.map +1 -1
  226. package/build-types/dataform-controls/toggle-group.d.ts +6 -0
  227. package/build-types/dataform-controls/toggle-group.d.ts.map +1 -0
  228. package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
  229. package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
  230. package/build-types/dataviews-layouts/grid/index.d.ts +2 -1
  231. package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
  232. package/build-types/dataviews-layouts/index.d.ts +3 -3
  233. package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
  234. package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
  235. package/build-types/dataviews-layouts/table/column-primary.d.ts +8 -1
  236. package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -1
  237. package/build-types/dataviews-layouts/table/index.d.ts +1 -1
  238. package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
  239. package/build-types/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts +19 -0
  240. package/build-types/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts.map +1 -0
  241. package/build-types/dataviews-layouts/utils/item-click-wrapper.d.ts +15 -0
  242. package/build-types/dataviews-layouts/utils/item-click-wrapper.d.ts.map +1 -0
  243. package/build-types/field-types/array.d.ts +7 -0
  244. package/build-types/field-types/array.d.ts.map +1 -0
  245. package/build-types/field-types/boolean.d.ts +19 -0
  246. package/build-types/field-types/boolean.d.ts.map +1 -0
  247. package/build-types/field-types/date.d.ts +16 -0
  248. package/build-types/field-types/date.d.ts.map +1 -0
  249. package/build-types/field-types/datetime.d.ts +7 -1
  250. package/build-types/field-types/datetime.d.ts.map +1 -1
  251. package/build-types/field-types/email.d.ts +19 -0
  252. package/build-types/field-types/email.d.ts.map +1 -0
  253. package/build-types/field-types/index.d.ts +2 -10
  254. package/build-types/field-types/index.d.ts.map +1 -1
  255. package/build-types/field-types/integer.d.ts +7 -1
  256. package/build-types/field-types/integer.d.ts.map +1 -1
  257. package/build-types/field-types/media.d.ts +16 -0
  258. package/build-types/field-types/media.d.ts.map +1 -0
  259. package/build-types/field-types/text.d.ts +7 -1
  260. package/build-types/field-types/text.d.ts.map +1 -1
  261. package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
  262. package/build-types/normalize-fields.d.ts.map +1 -1
  263. package/build-types/types.d.ts +74 -8
  264. package/build-types/types.d.ts.map +1 -1
  265. package/build-types/utils.d.ts +5 -2
  266. package/build-types/utils.d.ts.map +1 -1
  267. package/build-wp/index.js +3299 -1182
  268. package/package.json +18 -12
  269. package/src/components/dataform/stories/index.story.tsx +41 -20
  270. package/src/components/dataviews/index.tsx +108 -43
  271. package/src/components/dataviews/stories/fixtures.tsx +135 -69
  272. package/src/components/dataviews/stories/index.story.tsx +265 -7
  273. package/src/components/dataviews/stories/style.css +24 -3
  274. package/src/components/dataviews/style.scss +27 -0
  275. package/src/components/dataviews-context/index.ts +30 -2
  276. package/src/components/dataviews-filters/filter.tsx +603 -0
  277. package/src/components/dataviews-filters/index.tsx +23 -29
  278. package/src/components/dataviews-filters/input-widget.tsx +91 -0
  279. package/src/components/dataviews-filters/search-widget.tsx +51 -48
  280. package/src/components/dataviews-filters/style.scss +117 -14
  281. package/src/components/dataviews-filters/utils.ts +25 -0
  282. package/src/components/dataviews-item-actions/index.tsx +1 -1
  283. package/src/components/dataviews-layout/index.tsx +8 -1
  284. package/src/components/dataviews-pagination/index.tsx +4 -4
  285. package/src/components/dataviews-selection-checkbox/index.tsx +2 -2
  286. package/src/components/dataviews-view-config/index.tsx +10 -18
  287. package/src/components/stories/index.story.tsx +372 -0
  288. package/src/constants.ts +116 -1
  289. package/src/dataform-controls/boolean.tsx +30 -0
  290. package/src/dataform-controls/checkbox.tsx +31 -0
  291. package/src/dataform-controls/datetime.tsx +106 -2
  292. package/src/dataform-controls/email.tsx +42 -0
  293. package/src/dataform-controls/index.tsx +8 -0
  294. package/src/dataform-controls/integer.tsx +75 -1
  295. package/src/dataform-controls/select.tsx +1 -0
  296. package/src/dataform-controls/style.scss +5 -0
  297. package/src/dataform-controls/text.tsx +2 -1
  298. package/src/dataform-controls/toggle-group.tsx +59 -0
  299. package/src/dataforms-layouts/data-form-layout.tsx +1 -1
  300. package/src/dataforms-layouts/panel/index.tsx +19 -7
  301. package/src/dataforms-layouts/panel/style.scss +8 -1
  302. package/src/dataforms-layouts/regular/index.tsx +50 -17
  303. package/src/dataforms-layouts/regular/style.scss +4 -1
  304. package/src/dataviews-layouts/grid/index.tsx +180 -68
  305. package/src/dataviews-layouts/grid/style.scss +8 -0
  306. package/src/dataviews-layouts/list/index.tsx +12 -5
  307. package/src/dataviews-layouts/table/column-header-menu.tsx +10 -8
  308. package/src/dataviews-layouts/table/column-primary.tsx +26 -13
  309. package/src/dataviews-layouts/table/index.tsx +74 -10
  310. package/src/dataviews-layouts/table/style.scss +37 -1
  311. package/src/dataviews-layouts/table/use-is-horizontal-scroll-end.ts +82 -0
  312. package/src/dataviews-layouts/utils/item-click-wrapper.tsx +93 -0
  313. package/src/field-types/array.tsx +75 -0
  314. package/src/field-types/boolean.tsx +66 -0
  315. package/src/field-types/date.ts +56 -0
  316. package/src/field-types/datetime.tsx +46 -2
  317. package/src/field-types/email.tsx +79 -0
  318. package/src/field-types/index.tsx +50 -3
  319. package/src/field-types/integer.tsx +53 -2
  320. package/src/field-types/media.tsx +28 -0
  321. package/src/field-types/text.tsx +41 -2
  322. package/src/filter-and-sort-data-view.ts +270 -10
  323. package/src/normalize-fields.ts +116 -13
  324. package/src/test/dataviews.tsx +20 -2
  325. package/src/test/filter-and-sort-data-view.js +601 -25
  326. package/src/test/normalize-fields.ts +155 -0
  327. package/src/types.ts +112 -9
  328. package/src/utils.ts +10 -33
  329. package/tsconfig.json +2 -0
  330. package/tsconfig.tsbuildinfo +1 -1
  331. package/build/components/dataviews-filters/filter-summary.js.map +0 -1
  332. package/build/dataviews-layouts/utils/get-clickable-item-props.js +0 -36
  333. package/build/dataviews-layouts/utils/get-clickable-item-props.js.map +0 -1
  334. package/build-module/components/dataviews-filters/filter-summary.js +0 -218
  335. package/build-module/components/dataviews-filters/filter-summary.js.map +0 -1
  336. package/build-module/dataviews-layouts/utils/get-clickable-item-props.js +0 -30
  337. package/build-module/dataviews-layouts/utils/get-clickable-item-props.js.map +0 -1
  338. package/build-types/components/dataviews-filters/filter-summary.d.ts +0 -14
  339. package/build-types/components/dataviews-filters/filter-summary.d.ts.map +0 -1
  340. package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts +0 -19
  341. package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts.map +0 -1
  342. package/src/components/dataviews-filters/filter-summary.tsx +0 -338
  343. package/src/dataviews-layouts/utils/get-clickable-item-props.ts +0 -39
@@ -1,8 +1,13 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
1
5
  /**
2
6
  * Internal dependencies
3
7
  */
4
8
  import getFieldTypeDefinition from './field-types';
5
9
  import { getControl } from './dataform-controls';
10
+ import { ALL_OPERATORS, OPERATOR_BETWEEN, SINGLE_SELECTION_OPERATORS } from './constants';
6
11
  const getValueFromId = id => ({
7
12
  item
8
13
  }) => {
@@ -17,6 +22,61 @@ const getValueFromId = id => ({
17
22
  }
18
23
  return value;
19
24
  };
25
+ function getFilterBy(field, fieldTypeDefinition) {
26
+ if (field.filterBy === false) {
27
+ return false;
28
+ }
29
+ if (typeof field.filterBy === 'object') {
30
+ let operators = field.filterBy.operators;
31
+
32
+ // Assign default values if no operator was provided.
33
+ if (!operators || !Array.isArray(operators)) {
34
+ operators = !!fieldTypeDefinition.filterBy ? fieldTypeDefinition.filterBy.defaultOperators : [];
35
+ }
36
+
37
+ // Make sure only valid operators are included.
38
+ let validOperators = ALL_OPERATORS;
39
+ if (typeof fieldTypeDefinition.filterBy === 'object') {
40
+ validOperators = fieldTypeDefinition.filterBy.validOperators;
41
+ }
42
+ operators = operators.filter(operator => validOperators.includes(operator));
43
+
44
+ // The `between` operator is not supported when elements are provided.
45
+ if (field.elements && operators.includes(OPERATOR_BETWEEN)) {
46
+ operators = operators.filter(operator => operator !== OPERATOR_BETWEEN);
47
+ }
48
+
49
+ // Do not allow mixing single & multiselection operators.
50
+ // Remove multiselection operators if any of the single selection ones is present.
51
+ const hasSingleSelectionOperator = operators.some(operator => SINGLE_SELECTION_OPERATORS.includes(operator));
52
+ if (hasSingleSelectionOperator) {
53
+ operators = operators.filter(operator =>
54
+ // The 'Between' operator is unique as it can be combined with single selection operators.
55
+ [...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN].includes(operator));
56
+ }
57
+
58
+ // If no operators are left at this point,
59
+ // the filters should be disabled.
60
+ if (operators.length === 0) {
61
+ return false;
62
+ }
63
+ return {
64
+ isPrimary: !!field.filterBy.isPrimary,
65
+ operators
66
+ };
67
+ }
68
+ if (fieldTypeDefinition.filterBy === false) {
69
+ return false;
70
+ }
71
+ let defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;
72
+ // The `between` operator is not supported when elements are provided.
73
+ if (field.elements && defaultOperators.includes(OPERATOR_BETWEEN)) {
74
+ defaultOperators = defaultOperators.filter(operator => operator !== OPERATOR_BETWEEN);
75
+ }
76
+ return {
77
+ operators: defaultOperators
78
+ };
79
+ }
20
80
 
21
81
  /**
22
82
  * Apply default values and normalize the fields config.
@@ -26,7 +86,7 @@ const getValueFromId = id => ({
26
86
  */
27
87
  export function normalizeFields(fields) {
28
88
  return fields.map(field => {
29
- var _field$sort, _field$isValid, _field$enableHiding, _field$enableSorting;
89
+ var _field$sort, _field$isValid, _field$render, _field$enableHiding, _ref, _field$enableSorting, _ref2, _field$readOnly;
30
90
  const fieldTypeDefinition = getFieldTypeDefinition(field.type);
31
91
  const getValue = field.getValue || getValueFromId(field.id);
32
92
  const sort = (_field$sort = field.sort) !== null && _field$sort !== void 0 ? _field$sort : function sort(a, b, direction) {
@@ -42,17 +102,16 @@ export function normalizeFields(fields) {
42
102
  }), context);
43
103
  };
44
104
  const Edit = getControl(field, fieldTypeDefinition);
45
- const renderFromElements = ({
46
- item
47
- }) => {
48
- const value = getValue({
49
- item
50
- });
51
- return field?.elements?.find(element => element.value === value)?.label || getValue({
52
- item
105
+ const render = (_field$render = field.render) !== null && _field$render !== void 0 ? _field$render : function render({
106
+ item,
107
+ field: renderedField
108
+ }) {
109
+ return fieldTypeDefinition.render({
110
+ item,
111
+ field: renderedField
53
112
  });
54
113
  };
55
- const render = field.render || (field.elements ? renderFromElements : getValue);
114
+ const filterBy = getFilterBy(field, fieldTypeDefinition);
56
115
  return {
57
116
  ...field,
58
117
  label: field.label || field.id,
@@ -63,7 +122,9 @@ export function normalizeFields(fields) {
63
122
  isValid,
64
123
  Edit,
65
124
  enableHiding: (_field$enableHiding = field.enableHiding) !== null && _field$enableHiding !== void 0 ? _field$enableHiding : true,
66
- enableSorting: (_field$enableSorting = field.enableSorting) !== null && _field$enableSorting !== void 0 ? _field$enableSorting : true
125
+ enableSorting: (_ref = (_field$enableSorting = field.enableSorting) !== null && _field$enableSorting !== void 0 ? _field$enableSorting : fieldTypeDefinition.enableSorting) !== null && _ref !== void 0 ? _ref : true,
126
+ filterBy,
127
+ readOnly: (_ref2 = (_field$readOnly = field.readOnly) !== null && _field$readOnly !== void 0 ? _field$readOnly : fieldTypeDefinition.readOnly) !== null && _ref2 !== void 0 ? _ref2 : false
67
128
  };
68
129
  });
69
130
  }
@@ -1 +1 @@
1
- {"version":3,"names":["getFieldTypeDefinition","getControl","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","normalizeFields","fields","map","field","_field$sort","_field$isValid","_field$enableHiding","_field$enableSorting","fieldTypeDefinition","type","getValue","sort","a","b","direction","isValid","context","Edit","renderFromElements","elements","find","element","label","render","header","enableHiding","enableSorting"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type { Field, NormalizedField } from './types';\nimport { getControl } from './dataform-controls';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition( field.type );\n\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid =\n\t\t\tfield.isValid ??\n\t\t\tfunction isValid( item, context ) {\n\t\t\t\treturn fieldTypeDefinition.isValid(\n\t\t\t\t\tgetValue( { item } ),\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst renderFromElements = ( { item }: { item: Item } ) => {\n\t\t\tconst value = getValue( { item } );\n\t\t\treturn (\n\t\t\t\tfield?.elements?.find( ( element ) => element.value === value )\n\t\t\t\t\t?.label || getValue( { item } )\n\t\t\t);\n\t\t};\n\n\t\tconst render =\n\t\t\tfield.render || ( field.elements ? renderFromElements : getValue );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting: field.enableSorting ?? true,\n\t\t};\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,sBAAsB,MAAM,eAAe;AAElD,SAASC,UAAU,QAAQ,qBAAqB;AAEhD,MAAMC,cAAc,GACjBC,EAAU,IACZ,CAAE;EAAEC;AAAoB,CAAC,KAAM;EAC9B,MAAMC,IAAI,GAAGF,EAAE,CAACG,KAAK,CAAE,GAAI,CAAC;EAC5B,IAAIC,KAAK,GAAGH,IAAI;EAChB,KAAM,MAAMI,OAAO,IAAIH,IAAI,EAAG;IAC7B,IAAKE,KAAK,CAACE,cAAc,CAAED,OAAQ,CAAC,EAAG;MACtCD,KAAK,GAAGA,KAAK,CAAEC,OAAO,CAAE;IACzB,CAAC,MAAM;MACND,KAAK,GAAGG,SAAS;IAClB;EACD;EAEA,OAAOH,KAAK;AACb,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,eAAeA,CAC9BC,MAAuB,EACK;EAC5B,OAAOA,MAAM,CAACC,GAAG,CAAIC,KAAK,IAAM;IAAA,IAAAC,WAAA,EAAAC,cAAA,EAAAC,mBAAA,EAAAC,oBAAA;IAC/B,MAAMC,mBAAmB,GAAGnB,sBAAsB,CAAEc,KAAK,CAACM,IAAK,CAAC;IAEhE,MAAMC,QAAQ,GAAGP,KAAK,CAACO,QAAQ,IAAInB,cAAc,CAAEY,KAAK,CAACX,EAAG,CAAC;IAE7D,MAAMmB,IAAI,IAAAP,WAAA,GACTD,KAAK,CAACQ,IAAI,cAAAP,WAAA,cAAAA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I,OAAO;MACPE,IAAI;MACJQ,YAAY,GAAAnB,mBAAA,GAAEH,KAAK,CAACsB,YAAY,cAAAnB,mBAAA,cAAAA,mBAAA,GAAI,IAAI;MACxCoB,aAAa,GAAAnB,oBAAA,GAAEJ,KAAK,CAACuB,aAAa,cAAAnB,oBAAA,cAAAA,oBAAA,GAAI;IACvC,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["getFieldTypeDefinition","getControl","ALL_OPERATORS","OPERATOR_BETWEEN","SINGLE_SELECTION_OPERATORS","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","filter","operator","includes","elements","hasSingleSelectionOperator","some","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$isValid","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","type","getValue","sort","a","b","direction","isValid","context","Edit","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid =\n\t\t\tfield.isValid ??\n\t\t\tfunction isValid( item, context ) {\n\t\t\t\treturn fieldTypeDefinition.isValid(\n\t\t\t\t\tgetValue( { item } ),\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t};\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,OAAOA,sBAAsB,MAAM,eAAe;AAQlD,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SACCC,aAAa,EACbC,gBAAgB,EAChBC,0BAA0B,QACpB,aAAa;AAEpB,MAAMC,cAAc,GACjBC,EAAU,IACZ,CAAE;EAAEC;AAAoB,CAAC,KAAM;EAC9B,MAAMC,IAAI,GAAGF,EAAE,CAACG,KAAK,CAAE,GAAI,CAAC;EAC5B,IAAIC,KAAK,GAAGH,IAAI;EAChB,KAAM,MAAMI,OAAO,IAAIH,IAAI,EAAG;IAC7B,IAAKE,KAAK,CAACE,cAAc,CAAED,OAAQ,CAAC,EAAG;MACtCD,KAAK,GAAGA,KAAK,CAAEC,OAAO,CAAE;IACzB,CAAC,MAAM;MACND,KAAK,GAAGG,SAAS;IAClB;EACD;EAEA,OAAOH,KAAK;AACb,CAAC;AAEF,SAASI,WAAWA,CACnBC,KAAoB,EACpBC,mBAAgD,EACb;EACnC,IAAKD,KAAK,CAACE,QAAQ,KAAK,KAAK,EAAG;IAC/B,OAAO,KAAK;EACb;EAEA,IAAK,OAAOF,KAAK,CAACE,QAAQ,KAAK,QAAQ,EAAG;IACzC,IAAIC,SAAS,GAAGH,KAAK,CAACE,QAAQ,CAACC,SAAS;;IAExC;IACA,IAAK,CAAEA,SAAS,IAAI,CAAEC,KAAK,CAACC,OAAO,CAA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.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\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\ninterface 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\nexport type FieldType = 'text' | 'integer' | 'datetime' | 'media';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\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: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string;\n};\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?: FieldType;\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;\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?: ( item: Item, context?: ValidationContext ) => boolean;\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 is filterable.\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 * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | undefined;\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\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > >;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\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 * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: Array< FormField | string >;\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType, ComponentProps } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\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 interface NormalizedFilterByConfig {\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\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\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 FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'array';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\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: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string | null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | 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 * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\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?: FieldType;\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;\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?: ( item: Item, context?: ValidationContext ) => boolean;\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 is filterable.\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 * 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\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => 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};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\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 * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: Array< FormField | string >;\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1,23 +1,16 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { ALL_OPERATORS, OPERATOR_IS, OPERATOR_IS_NOT, OPERATOR_IS_ANY, OPERATOR_IS_NONE } from './constants';
5
- export function sanitizeOperators(field) {
6
- let operators = field.filterBy?.operators;
7
4
 
8
- // Assign default values.
9
- if (!operators || !Array.isArray(operators)) {
10
- operators = [OPERATOR_IS_ANY, OPERATOR_IS_NONE];
11
- }
12
-
13
- // Make sure only valid operators are used.
14
- operators = operators.filter(operator => ALL_OPERATORS.includes(operator));
15
-
16
- // Do not allow mixing single & multiselection operators.
17
- // Remove multiselection operators if any of the single selection ones is present.
18
- if (operators.includes(OPERATOR_IS) || operators.includes(OPERATOR_IS_NOT)) {
19
- operators = operators.filter(operator => [OPERATOR_IS, OPERATOR_IS_NOT].includes(operator));
20
- }
21
- return operators;
5
+ export function renderFromElements({
6
+ item,
7
+ field
8
+ }) {
9
+ const value = field.getValue({
10
+ item
11
+ });
12
+ return field?.elements?.find(element => element.value === value)?.label || field.getValue({
13
+ item
14
+ });
22
15
  }
23
16
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ALL_OPERATORS","OPERATOR_IS","OPERATOR_IS_NOT","OPERATOR_IS_ANY","OPERATOR_IS_NONE","sanitizeOperators","field","operators","filterBy","Array","isArray","filter","operator","includes"],"sources":["@wordpress/dataviews/src/utils.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\n} from './constants';\nimport type { NormalizedField } from './types';\n\nexport function sanitizeOperators< Item >( field: NormalizedField< Item > ) {\n\tlet operators = field.filterBy?.operators;\n\n\t// Assign default values.\n\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\toperators = [ OPERATOR_IS_ANY, OPERATOR_IS_NONE ];\n\t}\n\n\t// Make sure only valid operators are used.\n\toperators = operators.filter( ( operator ) =>\n\t\tALL_OPERATORS.includes( operator )\n\t);\n\n\t// Do not allow mixing single & multiselection operators.\n\t// Remove multiselection operators if any of the single selection ones is present.\n\tif (\n\t\toperators.includes( OPERATOR_IS ) ||\n\t\toperators.includes( OPERATOR_IS_NOT )\n\t) {\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\t[ OPERATOR_IS, OPERATOR_IS_NOT ].includes( operator )\n\t\t);\n\t}\n\n\treturn operators;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,aAAa,EACbC,WAAW,EACXC,eAAe,EACfC,eAAe,EACfC,gBAAgB,QACV,aAAa;AAGpB,OAAO,SAASC,iBAAiBA,CAAUC,KAA8B,EAAG;EAC3E,IAAIC,SAAS,GAAGD,KAAK,CAACE,QAAQ,EAAED,SAAS;;EAEzC;EACA,IAAK,CAAEA,SAAS,IAAI,CAAEE,KAAK,CAACC,OAAO,CAAEH,SAAU,CAAC,EAAG;IAClDA,SAAS,GAAG,CAAEJ,eAAe,EAAEC,gBAAgB,CAAE;EAClD;;EAEA;EACAG,SAAS,GAAGA,SAAS,CAACI,MAAM,CAAIC,QAAQ,IACvCZ,aAAa,CAACa,QAAQ,CAAED,QAAS,CAClC,CAAC;;EAED;EACA;EACA,IACCL,SAAS,CAACM,QAAQ,CAAEZ,WAAY,CAAC,IACjCM,SAAS,CAACM,QAAQ,CAAEX,eAAgB,CAAC,EACpC;IACDK,SAAS,GAAGA,SAAS,CAACI,MAAM,CAAIC,QAAQ,IACvC,CAAEX,WAAW,EAAEC,eAAe,CAAE,CAACW,QAAQ,CAAED,QAAS,CACrD,CAAC;EACF;EAEA,OAAOL,SAAS;AACjB","ignoreList":[]}
1
+ {"version":3,"names":["renderFromElements","item","field","value","getValue","elements","find","element","label"],"sources":["@wordpress/dataviews/src/utils.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { DataViewRenderFieldProps } from './types';\n\nexport function renderFromElements< Item >( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< Item > ) {\n\tconst value = field.getValue( { item } );\n\treturn (\n\t\tfield?.elements?.find( ( element ) => element.value === value )\n\t\t\t?.label || field.getValue( { item } )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA,OAAO,SAASA,kBAAkBA,CAAU;EAC3CC,IAAI;EACJC;AACiC,CAAC,EAAG;EACrC,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;IAAEH;EAAK,CAAE,CAAC;EACxC,OACCC,KAAK,EAAEG,QAAQ,EAAEC,IAAI,CAAIC,OAAO,IAAMA,OAAO,CAACJ,KAAK,KAAKA,KAAM,CAAC,EAC5DK,KAAK,IAAIN,KAAK,CAACE,QAAQ,CAAE;IAAEH;EAAK,CAAE,CAAC;AAExC","ignoreList":[]}