@wordpress/dataviews 2.2.0 → 4.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 (298) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +23 -8
  3. package/build/components/dataform/index.js +78 -0
  4. package/build/components/dataform/index.js.map +1 -0
  5. package/build/components/dataviews/index.js +115 -0
  6. package/build/components/dataviews/index.js.map +1 -0
  7. package/build/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -16
  8. package/build/components/dataviews-bulk-actions/index.js.map +1 -0
  9. package/build/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +36 -20
  10. package/build/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
  11. package/build/components/dataviews-context/index.js +36 -0
  12. package/build/components/dataviews-context/index.js.map +1 -0
  13. package/build/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
  14. package/build/components/dataviews-filters/add-filter.js.map +1 -0
  15. package/build/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
  16. package/build/components/dataviews-filters/filter-summary.js.map +1 -0
  17. package/build/{filters.js → components/dataviews-filters/index.js} +15 -16
  18. package/build/components/dataviews-filters/index.js.map +1 -0
  19. package/build/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
  20. package/build/components/dataviews-filters/reset-filters.js.map +1 -0
  21. package/build/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
  22. package/build/components/dataviews-filters/search-widget.js.map +1 -0
  23. package/build/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
  24. package/build/components/dataviews-item-actions/index.js.map +1 -0
  25. package/build/components/dataviews-layout/index.js +53 -0
  26. package/build/components/dataviews-layout/index.js.map +1 -0
  27. package/build/{pagination.js → components/dataviews-pagination/index.js} +18 -15
  28. package/build/components/dataviews-pagination/index.js.map +1 -0
  29. package/build/{search.js → components/dataviews-search/index.js} +10 -6
  30. package/build/components/dataviews-search/index.js.map +1 -0
  31. package/build/components/dataviews-selection-checkbox/index.js +52 -0
  32. package/build/components/dataviews-selection-checkbox/index.js.map +1 -0
  33. package/build/{view-actions.js → components/dataviews-view-config/index.js} +94 -80
  34. package/build/components/dataviews-view-config/index.js.map +1 -0
  35. package/build/filter-and-sort-data-view.js +4 -1
  36. package/build/filter-and-sort-data-view.js.map +1 -1
  37. package/build/index.js +8 -1
  38. package/build/index.js.map +1 -1
  39. package/build/layouts/grid/density-picker.js +143 -0
  40. package/build/layouts/grid/density-picker.js.map +1 -0
  41. package/build/{view-grid.js → layouts/grid/index.js} +40 -53
  42. package/build/layouts/grid/index.js.map +1 -0
  43. package/build/layouts/index.js +52 -0
  44. package/build/layouts/index.js.map +1 -0
  45. package/build/{view-list.js → layouts/list/index.js} +31 -27
  46. package/build/layouts/list/index.js.map +1 -0
  47. package/build/layouts/table/column-header-menu.js +196 -0
  48. package/build/layouts/table/column-header-menu.js.map +1 -0
  49. package/build/layouts/table/index.js +350 -0
  50. package/build/layouts/table/index.js.map +1 -0
  51. package/build/normalize-fields.js +1 -1
  52. package/build/normalize-fields.js.map +1 -1
  53. package/build/private-types.js +6 -0
  54. package/build/private-types.js.map +1 -0
  55. package/build/types.js.map +1 -1
  56. package/build/utils.js.map +1 -1
  57. package/build-module/components/dataform/index.js +72 -0
  58. package/build-module/components/dataform/index.js.map +1 -0
  59. package/build-module/components/dataviews/index.js +108 -0
  60. package/build-module/components/dataviews/index.js.map +1 -0
  61. package/build-module/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -17
  62. package/build-module/components/dataviews-bulk-actions/index.js.map +1 -0
  63. package/build-module/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +35 -20
  64. package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
  65. package/build-module/components/dataviews-context/index.js +30 -0
  66. package/build-module/components/dataviews-context/index.js.map +1 -0
  67. package/build-module/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
  68. package/build-module/components/dataviews-filters/add-filter.js.map +1 -0
  69. package/build-module/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
  70. package/build-module/components/dataviews-filters/filter-summary.js.map +1 -0
  71. package/build-module/{filters.js → components/dataviews-filters/index.js} +16 -17
  72. package/build-module/components/dataviews-filters/index.js.map +1 -0
  73. package/build-module/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
  74. package/build-module/components/dataviews-filters/reset-filters.js.map +1 -0
  75. package/build-module/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
  76. package/build-module/components/dataviews-filters/search-widget.js.map +1 -0
  77. package/build-module/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
  78. package/build-module/components/dataviews-item-actions/index.js.map +1 -0
  79. package/build-module/components/dataviews-layout/index.js +45 -0
  80. package/build-module/components/dataviews-layout/index.js.map +1 -0
  81. package/build-module/{pagination.js → components/dataviews-pagination/index.js} +19 -17
  82. package/build-module/components/dataviews-pagination/index.js.map +1 -0
  83. package/build-module/{search.js → components/dataviews-search/index.js} +10 -7
  84. package/build-module/components/dataviews-search/index.js.map +1 -0
  85. package/build-module/components/dataviews-selection-checkbox/index.js +45 -0
  86. package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -0
  87. package/build-module/{view-actions.js → components/dataviews-view-config/index.js} +98 -84
  88. package/build-module/components/dataviews-view-config/index.js.map +1 -0
  89. package/build-module/filter-and-sort-data-view.js +4 -1
  90. package/build-module/filter-and-sort-data-view.js.map +1 -1
  91. package/build-module/index.js +2 -1
  92. package/build-module/index.js.map +1 -1
  93. package/build-module/layouts/grid/density-picker.js +138 -0
  94. package/build-module/layouts/grid/density-picker.js.map +1 -0
  95. package/build-module/{view-grid.js → layouts/grid/index.js} +37 -50
  96. package/build-module/layouts/grid/index.js.map +1 -0
  97. package/build-module/layouts/index.js +43 -0
  98. package/build-module/layouts/index.js.map +1 -0
  99. package/build-module/{view-list.js → layouts/list/index.js} +29 -25
  100. package/build-module/layouts/list/index.js.map +1 -0
  101. package/build-module/layouts/table/column-header-menu.js +190 -0
  102. package/build-module/layouts/table/column-header-menu.js.map +1 -0
  103. package/build-module/layouts/table/index.js +344 -0
  104. package/build-module/layouts/table/index.js.map +1 -0
  105. package/build-module/normalize-fields.js +1 -1
  106. package/build-module/normalize-fields.js.map +1 -1
  107. package/build-module/private-types.js +2 -0
  108. package/build-module/private-types.js.map +1 -0
  109. package/build-module/types.js.map +1 -1
  110. package/build-module/utils.js.map +1 -1
  111. package/build-style/style-rtl.css +607 -561
  112. package/build-style/style.css +607 -561
  113. package/build-types/components/dataform/index.d.ts +17 -0
  114. package/build-types/components/dataform/index.d.ts.map +1 -0
  115. package/build-types/components/dataform/stories/index.story.d.ts +11 -0
  116. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -0
  117. package/build-types/components/dataviews/index.d.ts +33 -0
  118. package/build-types/components/dataviews/index.d.ts.map +1 -0
  119. package/build-types/{stories → components/dataviews/stories}/fixtures.d.ts +18 -17
  120. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -0
  121. package/build-types/components/dataviews/stories/index.story.d.ts +46 -0
  122. package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -0
  123. package/build-types/components/dataviews-bulk-actions/index.d.ts +5 -0
  124. package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -0
  125. package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +2 -0
  126. package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +1 -0
  127. package/build-types/components/dataviews-context/index.d.ts +26 -0
  128. package/build-types/components/dataviews-context/index.d.ts.map +1 -0
  129. package/build-types/{add-filter.d.ts → components/dataviews-filters/add-filter.d.ts} +1 -2
  130. package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -0
  131. package/build-types/{filter-summary.d.ts → components/dataviews-filters/filter-summary.d.ts} +1 -1
  132. package/build-types/components/dataviews-filters/filter-summary.d.ts.map +1 -0
  133. package/build-types/components/dataviews-filters/index.d.ts +4 -0
  134. package/build-types/components/dataviews-filters/index.d.ts.map +1 -0
  135. package/build-types/{reset-filters.d.ts → components/dataviews-filters/reset-filters.d.ts} +1 -2
  136. package/build-types/components/dataviews-filters/reset-filters.d.ts.map +1 -0
  137. package/build-types/{search-widget.d.ts → components/dataviews-filters/search-widget.d.ts} +1 -2
  138. package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -0
  139. package/build-types/components/dataviews-item-actions/index.d.ts +35 -0
  140. package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -0
  141. package/build-types/components/dataviews-layout/index.d.ts +2 -0
  142. package/build-types/components/dataviews-layout/index.d.ts.map +1 -0
  143. package/build-types/components/dataviews-pagination/index.d.ts +4 -0
  144. package/build-types/components/dataviews-pagination/index.d.ts.map +1 -0
  145. package/build-types/components/dataviews-search/index.d.ts +6 -0
  146. package/build-types/components/dataviews-search/index.d.ts.map +1 -0
  147. package/build-types/components/dataviews-selection-checkbox/index.d.ts +16 -0
  148. package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -0
  149. package/build-types/components/dataviews-view-config/index.d.ts +8 -0
  150. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -0
  151. package/build-types/filter-and-sort-data-view.d.ts +2 -2
  152. package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
  153. package/build-types/index.d.ts +2 -1
  154. package/build-types/index.d.ts.map +1 -1
  155. package/build-types/layouts/grid/density-picker.d.ts +5 -0
  156. package/build-types/layouts/grid/density-picker.d.ts.map +1 -0
  157. package/build-types/layouts/grid/index.d.ts +3 -0
  158. package/build-types/layouts/grid/index.d.ts.map +1 -0
  159. package/build-types/{layouts.d.ts → layouts/index.d.ts} +6 -5
  160. package/build-types/layouts/index.d.ts.map +1 -0
  161. package/build-types/layouts/list/index.d.ts +3 -0
  162. package/build-types/layouts/list/index.d.ts.map +1 -0
  163. package/build-types/layouts/table/column-header-menu.d.ts +17 -0
  164. package/build-types/layouts/table/column-header-menu.d.ts.map +1 -0
  165. package/build-types/layouts/table/index.d.ts +4 -0
  166. package/build-types/layouts/table/index.d.ts.map +1 -0
  167. package/build-types/normalize-fields.d.ts +2 -2
  168. package/build-types/normalize-fields.d.ts.map +1 -1
  169. package/build-types/private-types.d.ts +3 -0
  170. package/build-types/private-types.d.ts.map +1 -0
  171. package/build-types/types.d.ts +106 -46
  172. package/build-types/types.d.ts.map +1 -1
  173. package/build-types/utils.d.ts +2 -2
  174. package/build-types/utils.d.ts.map +1 -1
  175. package/package.json +10 -10
  176. package/src/components/dataform/index.tsx +106 -0
  177. package/src/components/dataform/stories/index.story.tsx +42 -0
  178. package/src/components/dataviews/index.tsx +149 -0
  179. package/src/{stories → components/dataviews/stories}/fixtures.js +23 -11
  180. package/src/components/dataviews/stories/index.story.js +65 -0
  181. package/src/components/dataviews/style.scss +97 -0
  182. package/src/{bulk-actions.tsx → components/dataviews-bulk-actions/index.tsx} +58 -36
  183. package/src/components/dataviews-bulk-actions/style.scss +7 -0
  184. package/src/{bulk-actions-toolbar.tsx → components/dataviews-bulk-actions-toolbar/index.tsx} +48 -36
  185. package/src/components/dataviews-bulk-actions-toolbar/style.scss +45 -0
  186. package/src/components/dataviews-context/index.ts +49 -0
  187. package/src/{add-filter.tsx → components/dataviews-filters/add-filter.tsx} +4 -4
  188. package/src/{filter-summary.tsx → components/dataviews-filters/filter-summary.tsx} +36 -22
  189. package/src/{filters.tsx → components/dataviews-filters/index.tsx} +11 -25
  190. package/src/{reset-filters.tsx → components/dataviews-filters/reset-filters.tsx} +2 -2
  191. package/src/{search-widget.tsx → components/dataviews-filters/search-widget.tsx} +20 -20
  192. package/src/components/dataviews-filters/style.scss +252 -0
  193. package/src/{item-actions.tsx → components/dataviews-item-actions/index.tsx} +16 -17
  194. package/src/components/dataviews-item-actions/style.scss +3 -0
  195. package/src/components/dataviews-layout/index.tsx +51 -0
  196. package/src/{pagination.tsx → components/dataviews-pagination/index.tsx} +15 -23
  197. package/src/components/dataviews-pagination/style.scss +26 -0
  198. package/src/{search.tsx → components/dataviews-search/index.tsx} +5 -10
  199. package/src/components/dataviews-selection-checkbox/index.tsx +65 -0
  200. package/src/components/dataviews-selection-checkbox/style.scss +14 -0
  201. package/src/{view-actions.tsx → components/dataviews-view-config/index.tsx} +116 -119
  202. package/src/filter-and-sort-data-view.ts +13 -3
  203. package/src/index.ts +2 -1
  204. package/src/layouts/grid/density-picker.tsx +136 -0
  205. package/src/{view-grid.tsx → layouts/grid/index.tsx} +45 -63
  206. package/src/layouts/grid/style.scss +140 -0
  207. package/src/layouts/index.ts +66 -0
  208. package/src/{view-list.tsx → layouts/list/index.tsx} +40 -30
  209. package/src/layouts/list/style.scss +189 -0
  210. package/src/layouts/table/column-header-menu.tsx +268 -0
  211. package/src/layouts/table/index.tsx +471 -0
  212. package/src/layouts/table/style.scss +201 -0
  213. package/src/normalize-fields.ts +6 -4
  214. package/src/private-types.tsx +2 -0
  215. package/src/style.scss +11 -919
  216. package/src/test/filter-and-sort-data-view.js +17 -2
  217. package/src/types.ts +113 -55
  218. package/src/utils.ts +2 -4
  219. package/tsconfig.tsbuildinfo +1 -1
  220. package/build/add-filter.js.map +0 -1
  221. package/build/bulk-actions-toolbar.js.map +0 -1
  222. package/build/bulk-actions.js.map +0 -1
  223. package/build/dataviews.js +0 -136
  224. package/build/dataviews.js.map +0 -1
  225. package/build/filter-summary.js.map +0 -1
  226. package/build/filters.js.map +0 -1
  227. package/build/item-actions.js.map +0 -1
  228. package/build/layouts.js +0 -38
  229. package/build/layouts.js.map +0 -1
  230. package/build/pagination.js.map +0 -1
  231. package/build/reset-filters.js.map +0 -1
  232. package/build/search-widget.js.map +0 -1
  233. package/build/search.js.map +0 -1
  234. package/build/single-selection-checkbox.js +0 -63
  235. package/build/single-selection-checkbox.js.map +0 -1
  236. package/build/view-actions.js.map +0 -1
  237. package/build/view-grid.js.map +0 -1
  238. package/build/view-list.js.map +0 -1
  239. package/build/view-table.js +0 -409
  240. package/build/view-table.js.map +0 -1
  241. package/build-module/add-filter.js.map +0 -1
  242. package/build-module/bulk-actions-toolbar.js.map +0 -1
  243. package/build-module/bulk-actions.js.map +0 -1
  244. package/build-module/dataviews.js +0 -129
  245. package/build-module/dataviews.js.map +0 -1
  246. package/build-module/filter-summary.js.map +0 -1
  247. package/build-module/filters.js.map +0 -1
  248. package/build-module/item-actions.js.map +0 -1
  249. package/build-module/layouts.js +0 -30
  250. package/build-module/layouts.js.map +0 -1
  251. package/build-module/pagination.js.map +0 -1
  252. package/build-module/reset-filters.js.map +0 -1
  253. package/build-module/search-widget.js.map +0 -1
  254. package/build-module/search.js.map +0 -1
  255. package/build-module/single-selection-checkbox.js +0 -56
  256. package/build-module/single-selection-checkbox.js.map +0 -1
  257. package/build-module/view-actions.js.map +0 -1
  258. package/build-module/view-grid.js.map +0 -1
  259. package/build-module/view-list.js.map +0 -1
  260. package/build-module/view-table.js +0 -402
  261. package/build-module/view-table.js.map +0 -1
  262. package/build-types/add-filter.d.ts.map +0 -1
  263. package/build-types/bulk-actions-toolbar.d.ts +0 -12
  264. package/build-types/bulk-actions-toolbar.d.ts.map +0 -1
  265. package/build-types/bulk-actions.d.ts +0 -14
  266. package/build-types/bulk-actions.d.ts.map +0 -1
  267. package/build-types/dataviews.d.ts +0 -24
  268. package/build-types/dataviews.d.ts.map +0 -1
  269. package/build-types/filter-summary.d.ts.map +0 -1
  270. package/build-types/filters.d.ts +0 -13
  271. package/build-types/filters.d.ts.map +0 -1
  272. package/build-types/item-actions.d.ts +0 -35
  273. package/build-types/item-actions.d.ts.map +0 -1
  274. package/build-types/layouts.d.ts.map +0 -1
  275. package/build-types/pagination.d.ts +0 -16
  276. package/build-types/pagination.d.ts.map +0 -1
  277. package/build-types/reset-filters.d.ts.map +0 -1
  278. package/build-types/search-widget.d.ts.map +0 -1
  279. package/build-types/search.d.ts +0 -13
  280. package/build-types/search.d.ts.map +0 -1
  281. package/build-types/single-selection-checkbox.d.ts +0 -17
  282. package/build-types/single-selection-checkbox.d.ts.map +0 -1
  283. package/build-types/stories/fixtures.d.ts.map +0 -1
  284. package/build-types/stories/index.story.d.ts +0 -15
  285. package/build-types/stories/index.story.d.ts.map +0 -1
  286. package/build-types/view-actions.d.ts +0 -12
  287. package/build-types/view-actions.d.ts.map +0 -1
  288. package/build-types/view-grid.d.ts +0 -4
  289. package/build-types/view-grid.d.ts.map +0 -1
  290. package/build-types/view-list.d.ts +0 -4
  291. package/build-types/view-list.d.ts.map +0 -1
  292. package/build-types/view-table.d.ts +0 -5
  293. package/build-types/view-table.d.ts.map +0 -1
  294. package/src/dataviews.tsx +0 -189
  295. package/src/layouts.ts +0 -39
  296. package/src/single-selection-checkbox.tsx +0 -80
  297. package/src/stories/index.story.js +0 -64
  298. package/src/view-table.tsx +0 -603
@@ -2,7 +2,7 @@
2
2
  * Internal dependencies
3
3
  */
4
4
  import { filterSortAndPaginate } from '../filter-and-sort-data-view';
5
- import { data, fields } from '../stories/fixtures';
5
+ import { data, fields } from '../components/dataviews/stories/fixtures';
6
6
 
7
7
  describe( 'filters', () => {
8
8
  it( 'should return empty if the data is empty', () => {
@@ -233,7 +233,7 @@ describe( 'filters', () => {
233
233
  } );
234
234
 
235
235
  describe( 'sorting', () => {
236
- it( 'should sort', () => {
236
+ it( 'should sort by string', () => {
237
237
  const { data: result } = filterSortAndPaginate(
238
238
  data,
239
239
  {
@@ -252,6 +252,21 @@ describe( 'sorting', () => {
252
252
  expect( result[ 0 ].title ).toBe( 'Uranus' );
253
253
  expect( result[ 1 ].title ).toBe( 'Neptune' );
254
254
  } );
255
+
256
+ it( 'should sort by number', () => {
257
+ const { data: result } = filterSortAndPaginate(
258
+ data,
259
+ {
260
+ sort: { field: 'satellites', direction: 'desc' },
261
+ },
262
+ fields
263
+ );
264
+
265
+ expect( result ).toHaveLength( 11 );
266
+ expect( result[ 0 ].title ).toBe( 'Saturn' );
267
+ expect( result[ 1 ].title ).toBe( 'Jupiter' );
268
+ expect( result[ 2 ].title ).toBe( 'Uranus' );
269
+ } );
255
270
  } );
256
271
 
257
272
  describe( 'pagination', () => {
package/src/types.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import type { ReactElement, ReactNode } from 'react';
4
+ import type { ReactElement, ComponentType } from 'react';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import type { SetSelection } from './private-types';
5
10
 
6
11
  export type SortDirection = 'asc' | 'desc';
7
12
 
@@ -37,12 +42,19 @@ export type Operator =
37
42
  | 'isAll'
38
43
  | 'isNotAll';
39
44
 
40
- export type AnyItem = Record< string, any >;
45
+ export type ItemRecord = Record< string, unknown >;
46
+
47
+ export type FieldType = 'text';
41
48
 
42
49
  /**
43
50
  * A dataview field for a specific property of a data type.
44
51
  */
45
- export interface Field< Item extends AnyItem > {
52
+ export type Field< Item > = {
53
+ /**
54
+ * Type of the fields.
55
+ */
56
+ type?: FieldType;
57
+
46
58
  /**
47
59
  * The unique identifier of the field.
48
60
  */
@@ -51,33 +63,17 @@ export interface Field< Item extends AnyItem > {
51
63
  /**
52
64
  * The label of the field. Defaults to the id.
53
65
  */
54
- header?: string;
66
+ label?: string;
55
67
 
56
68
  /**
57
- * Callback used to retrieve the value of the field from the item.
58
- * Defaults to `item[ field.id ]`.
69
+ * Placeholder for the field.
59
70
  */
60
- getValue?: ( args: { item: Item } ) => any;
71
+ placeholder?: string;
61
72
 
62
73
  /**
63
74
  * Callback used to render the field. Defaults to `field.getValue`.
64
75
  */
65
- render?: ( args: { item: Item } ) => ReactNode;
66
-
67
- /**
68
- * The width of the field column.
69
- */
70
- width?: string | number;
71
-
72
- /**
73
- * The minimum width of the field column.
74
- */
75
- maxWidth?: string | number;
76
-
77
- /**
78
- * The maximum width of the field column.
79
- */
80
- minWidth?: string | number;
76
+ render?: ComponentType< { item: Item } >;
81
77
 
82
78
  /**
83
79
  * Whether the field is sortable.
@@ -103,17 +99,41 @@ export interface Field< Item extends AnyItem > {
103
99
  * Filter config for the field.
104
100
  */
105
101
  filterBy?: FilterByConfig | undefined;
106
- }
107
-
108
- export type NormalizedField< Item extends AnyItem > = Field< Item > &
109
- Required< Pick< Field< Item >, 'header' | 'getValue' | 'render' > >;
102
+ } & ( Item extends ItemRecord
103
+ ? {
104
+ /**
105
+ * Callback used to retrieve the value of the field from the item.
106
+ * Defaults to `item[ field.id ]`.
107
+ */
108
+ getValue?: ( args: { item: Item } ) => any;
109
+ }
110
+ : {
111
+ /**
112
+ * Callback used to retrieve the value of the field from the item.
113
+ * Defaults to `item[ field.id ]`.
114
+ */
115
+ getValue: ( args: { item: Item } ) => any;
116
+ } );
117
+
118
+ export type NormalizedField< Item > = Field< Item > & {
119
+ label: string;
120
+ getValue: ( args: { item: Item } ) => any;
121
+ render: ComponentType< { item: Item } >;
122
+ };
110
123
 
111
124
  /**
112
125
  * A collection of dataview fields for a data type.
113
126
  */
114
- export type Fields< Item extends AnyItem > = Field< Item >[];
127
+ export type Fields< Item > = Field< Item >[];
128
+
129
+ export type Data< Item > = Item[];
115
130
 
116
- export type Data< Item extends AnyItem > = Item[];
131
+ /**
132
+ * The form configuration.
133
+ */
134
+ export type Form = {
135
+ visibleFields?: string[];
136
+ };
117
137
 
118
138
  /**
119
139
  * The filters applied to the dataset.
@@ -186,7 +206,7 @@ interface ViewBase {
186
206
  /**
187
207
  * The filters to apply.
188
208
  */
189
- filters: Filter[];
209
+ filters?: Filter[];
190
210
 
191
211
  /**
192
212
  * The sorting configuration.
@@ -214,31 +234,69 @@ interface ViewBase {
214
234
  perPage?: number;
215
235
 
216
236
  /**
217
- * The hidden fields.
237
+ * The fields to render
218
238
  */
219
- hiddenFields: string[];
239
+ fields?: string[];
240
+ }
241
+
242
+ export interface CombinedField {
243
+ id: string;
244
+
245
+ label: string;
246
+
247
+ /**
248
+ * The fields to use as columns.
249
+ */
250
+ children: string[];
251
+
252
+ /**
253
+ * The direction of the stack.
254
+ */
255
+ direction: 'horizontal' | 'vertical';
256
+ }
257
+
258
+ export interface ColumnStyle {
259
+ /**
260
+ * The width of the field column.
261
+ */
262
+ width?: string | number;
263
+
264
+ /**
265
+ * The minimum width of the field column.
266
+ */
267
+ maxWidth?: string | number;
268
+
269
+ /**
270
+ * The maximum width of the field column.
271
+ */
272
+ minWidth?: string | number;
220
273
  }
221
274
 
222
275
  export interface ViewTable extends ViewBase {
223
276
  type: 'table';
224
277
 
225
- layout: {
278
+ layout?: {
226
279
  /**
227
280
  * The field to use as the primary field.
228
281
  */
229
282
  primaryField?: string;
230
283
 
231
284
  /**
232
- * The field to use as the media field.
285
+ * The fields to use as columns.
233
286
  */
234
- mediaField?: string;
287
+ combinedFields?: CombinedField[];
288
+
289
+ /**
290
+ * The styles for the columns.
291
+ */
292
+ styles?: Record< string, ColumnStyle >;
235
293
  };
236
294
  }
237
295
 
238
296
  export interface ViewList extends ViewBase {
239
297
  type: 'list';
240
298
 
241
- layout: {
299
+ layout?: {
242
300
  /**
243
301
  * The field to use as the primary field.
244
302
  */
@@ -254,7 +312,7 @@ export interface ViewList extends ViewBase {
254
312
  export interface ViewGrid extends ViewBase {
255
313
  type: 'grid';
256
314
 
257
- layout: {
315
+ layout?: {
258
316
  /**
259
317
  * The field to use as the primary field.
260
318
  */
@@ -279,7 +337,7 @@ export interface ViewGrid extends ViewBase {
279
337
 
280
338
  export type View = ViewList | ViewGrid | ViewTable;
281
339
 
282
- interface ActionBase< Item extends AnyItem > {
340
+ interface ActionBase< Item > {
283
341
  /**
284
342
  * The unique identifier of the action.
285
343
  */
@@ -325,8 +383,7 @@ interface ActionBase< Item extends AnyItem > {
325
383
  supportsBulk?: boolean;
326
384
  }
327
385
 
328
- export interface ActionModal< Item extends AnyItem >
329
- extends ActionBase< Item > {
386
+ export interface ActionModal< Item > extends ActionBase< Item > {
330
387
  /**
331
388
  * Modal to render when the action is triggered.
332
389
  */
@@ -351,8 +408,7 @@ export interface ActionModal< Item extends AnyItem >
351
408
  modalHeader?: string;
352
409
  }
353
410
 
354
- export interface ActionButton< Item extends AnyItem >
355
- extends ActionBase< AnyItem > {
411
+ export interface ActionButton< Item > extends ActionBase< Item > {
356
412
  /**
357
413
  * The callback to execute when the action is triggered.
358
414
  */
@@ -365,39 +421,41 @@ export interface ActionButton< Item extends AnyItem >
365
421
  ) => void;
366
422
  }
367
423
 
368
- export type Action< Item extends AnyItem > =
369
- | ActionModal< Item >
370
- | ActionButton< Item >;
424
+ export type Action< Item > = ActionModal< Item > | ActionButton< Item >;
371
425
 
372
- export interface ViewBaseProps< Item extends AnyItem > {
426
+ export interface ViewBaseProps< Item > {
373
427
  actions: Action< Item >[];
374
428
  data: Item[];
375
429
  fields: NormalizedField< Item >[];
376
430
  getItemId: ( item: Item ) => string;
377
431
  isLoading?: boolean;
378
- onChangeView( view: View ): void;
379
- onSelectionChange: ( items: Item[] ) => void;
432
+ onChangeView: ( view: View ) => void;
433
+ onChangeSelection: SetSelection;
380
434
  selection: string[];
381
435
  setOpenedFilter: ( fieldId: string ) => void;
382
436
  view: View;
437
+ density: number;
383
438
  }
384
439
 
385
- export interface ViewTableProps< Item extends AnyItem >
386
- extends ViewBaseProps< Item > {
440
+ export interface ViewTableProps< Item > extends ViewBaseProps< Item > {
387
441
  view: ViewTable;
388
442
  }
389
443
 
390
- export interface ViewListProps< Item extends AnyItem >
391
- extends ViewBaseProps< Item > {
444
+ export interface ViewListProps< Item > extends ViewBaseProps< Item > {
392
445
  view: ViewList;
393
446
  }
394
447
 
395
- export interface ViewGridProps< Item extends AnyItem >
396
- extends ViewBaseProps< Item > {
448
+ export interface ViewGridProps< Item > extends ViewBaseProps< Item > {
397
449
  view: ViewGrid;
398
450
  }
399
451
 
400
- export type ViewProps< Item extends AnyItem > =
452
+ export type ViewProps< Item > =
401
453
  | ViewTableProps< Item >
402
454
  | ViewGridProps< Item >
403
455
  | ViewListProps< Item >;
456
+
457
+ export interface SupportedLayouts {
458
+ list?: Omit< ViewList, 'type' >;
459
+ grid?: Omit< ViewGrid, 'type' >;
460
+ table?: Omit< ViewTable, 'type' >;
461
+ }
package/src/utils.ts CHANGED
@@ -8,11 +8,9 @@ import {
8
8
  OPERATOR_IS_ANY,
9
9
  OPERATOR_IS_NONE,
10
10
  } from './constants';
11
- import type { AnyItem, NormalizedField } from './types';
11
+ import type { NormalizedField } from './types';
12
12
 
13
- export function sanitizeOperators< Item extends AnyItem >(
14
- field: NormalizedField< Item >
15
- ) {
13
+ export function sanitizeOperators< Item >( field: NormalizedField< Item > ) {
16
14
  let operators = field.filterBy?.operators;
17
15
 
18
16
  // Assign default values.