@wordpress/dataviews 4.0.0 → 4.1.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 (214) hide show
  1. package/CHANGELOG.md +16 -5
  2. package/build/components/dataform/index.js +10 -61
  3. package/build/components/dataform/index.js.map +1 -1
  4. package/build/components/dataviews/index.js +16 -5
  5. package/build/components/dataviews/index.js.map +1 -1
  6. package/build/components/dataviews-bulk-actions/index.js +3 -0
  7. package/build/components/dataviews-bulk-actions/index.js.map +1 -1
  8. package/build/components/dataviews-filters/add-filter.js +34 -17
  9. package/build/components/dataviews-filters/add-filter.js.map +1 -1
  10. package/build/components/dataviews-filters/index.js +106 -43
  11. package/build/components/dataviews-filters/index.js.map +1 -1
  12. package/build/components/dataviews-layout/index.js +2 -2
  13. package/build/components/dataviews-layout/index.js.map +1 -1
  14. package/build/components/dataviews-search/index.js +8 -5
  15. package/build/components/dataviews-search/index.js.map +1 -1
  16. package/build/components/dataviews-view-config/index.js +225 -190
  17. package/build/components/dataviews-view-config/index.js.map +1 -1
  18. package/build/constants.js +6 -1
  19. package/build/constants.js.map +1 -1
  20. package/build/dataforms-layouts/index.js +24 -0
  21. package/build/dataforms-layouts/index.js.map +1 -0
  22. package/build/dataforms-layouts/panel/index.js +129 -0
  23. package/build/dataforms-layouts/panel/index.js.map +1 -0
  24. package/build/dataforms-layouts/regular/index.js +39 -0
  25. package/build/dataforms-layouts/regular/index.js.map +1 -0
  26. package/build/{layouts → dataviews-layouts}/grid/density-picker.js +1 -1
  27. package/build/dataviews-layouts/grid/density-picker.js.map +1 -0
  28. package/build/{layouts → dataviews-layouts}/grid/index.js +8 -8
  29. package/build/dataviews-layouts/grid/index.js.map +1 -0
  30. package/build/dataviews-layouts/index.js.map +1 -0
  31. package/build/dataviews-layouts/list/index.js.map +1 -0
  32. package/build/{layouts → dataviews-layouts}/table/column-header-menu.js +1 -1
  33. package/build/dataviews-layouts/table/column-header-menu.js.map +1 -0
  34. package/build/dataviews-layouts/table/index.js.map +1 -0
  35. package/build/field-types/index.js +46 -0
  36. package/build/field-types/index.js.map +1 -0
  37. package/build/field-types/integer.js +94 -0
  38. package/build/field-types/integer.js.map +1 -0
  39. package/build/field-types/text.js +87 -0
  40. package/build/field-types/text.js.map +1 -0
  41. package/build/filter-and-sort-data-view.js +2 -11
  42. package/build/filter-and-sort-data-view.js.map +1 -1
  43. package/build/index.js +9 -2
  44. package/build/index.js.map +1 -1
  45. package/build/normalize-fields.js +35 -1
  46. package/build/normalize-fields.js.map +1 -1
  47. package/build/types.js.map +1 -1
  48. package/build/validation.js +22 -0
  49. package/build/validation.js.map +1 -0
  50. package/build-module/components/dataform/index.js +10 -61
  51. package/build-module/components/dataform/index.js.map +1 -1
  52. package/build-module/components/dataviews/index.js +14 -5
  53. package/build-module/components/dataviews/index.js.map +1 -1
  54. package/build-module/components/dataviews-bulk-actions/index.js +3 -0
  55. package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
  56. package/build-module/components/dataviews-filters/add-filter.js +33 -17
  57. package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
  58. package/build-module/components/dataviews-filters/index.js +105 -45
  59. package/build-module/components/dataviews-filters/index.js.map +1 -1
  60. package/build-module/components/dataviews-layout/index.js +1 -1
  61. package/build-module/components/dataviews-layout/index.js.map +1 -1
  62. package/build-module/components/dataviews-search/index.js +8 -5
  63. package/build-module/components/dataviews-search/index.js.map +1 -1
  64. package/build-module/components/dataviews-view-config/index.js +228 -193
  65. package/build-module/components/dataviews-view-config/index.js.map +1 -1
  66. package/build-module/constants.js +5 -0
  67. package/build-module/constants.js.map +1 -1
  68. package/build-module/dataforms-layouts/index.js +16 -0
  69. package/build-module/dataforms-layouts/index.js.map +1 -0
  70. package/build-module/dataforms-layouts/panel/index.js +124 -0
  71. package/build-module/dataforms-layouts/panel/index.js.map +1 -0
  72. package/build-module/dataforms-layouts/regular/index.js +32 -0
  73. package/build-module/dataforms-layouts/regular/index.js.map +1 -0
  74. package/build-module/{layouts → dataviews-layouts}/grid/density-picker.js +2 -2
  75. package/build-module/dataviews-layouts/grid/density-picker.js.map +1 -0
  76. package/build-module/{layouts → dataviews-layouts}/grid/index.js +8 -8
  77. package/build-module/dataviews-layouts/grid/index.js.map +1 -0
  78. package/build-module/dataviews-layouts/index.js.map +1 -0
  79. package/build-module/dataviews-layouts/list/index.js.map +1 -0
  80. package/build-module/{layouts → dataviews-layouts}/table/column-header-menu.js +1 -1
  81. package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -0
  82. package/build-module/dataviews-layouts/table/index.js.map +1 -0
  83. package/build-module/field-types/index.js +40 -0
  84. package/build-module/field-types/index.js.map +1 -0
  85. package/build-module/field-types/integer.js +87 -0
  86. package/build-module/field-types/integer.js.map +1 -0
  87. package/build-module/field-types/text.js +80 -0
  88. package/build-module/field-types/text.js.map +1 -0
  89. package/build-module/filter-and-sort-data-view.js +2 -11
  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/normalize-fields.js +34 -2
  94. package/build-module/normalize-fields.js.map +1 -1
  95. package/build-module/types.js.map +1 -1
  96. package/build-module/validation.js +15 -0
  97. package/build-module/validation.js.map +1 -0
  98. package/build-style/style-rtl.css +175 -6
  99. package/build-style/style.css +175 -6
  100. package/build-types/components/dataform/index.d.ts +2 -13
  101. package/build-types/components/dataform/index.d.ts.map +1 -1
  102. package/build-types/components/dataform/stories/index.story.d.ts +12 -1
  103. package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
  104. package/build-types/components/dataviews/index.d.ts.map +1 -1
  105. package/build-types/components/dataviews/stories/fixtures.d.ts +6 -0
  106. package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
  107. package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
  108. package/build-types/components/dataviews-filters/add-filter.d.ts +3 -0
  109. package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
  110. package/build-types/components/dataviews-filters/index.d.ts +11 -1
  111. package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
  112. package/build-types/components/dataviews-search/index.d.ts.map +1 -1
  113. package/build-types/components/dataviews-view-config/index.d.ts +1 -1
  114. package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
  115. package/build-types/constants.d.ts +4 -0
  116. package/build-types/constants.d.ts.map +1 -1
  117. package/build-types/dataforms-layouts/index.d.ts +9 -0
  118. package/build-types/dataforms-layouts/index.d.ts.map +1 -0
  119. package/build-types/dataforms-layouts/panel/index.d.ts +3 -0
  120. package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -0
  121. package/build-types/dataforms-layouts/regular/index.d.ts +3 -0
  122. package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -0
  123. package/build-types/dataviews-layouts/grid/density-picker.d.ts.map +1 -0
  124. package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -0
  125. package/build-types/dataviews-layouts/index.d.ts.map +1 -0
  126. package/build-types/dataviews-layouts/list/index.d.ts.map +1 -0
  127. package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -0
  128. package/build-types/dataviews-layouts/table/index.d.ts.map +1 -0
  129. package/build-types/field-types/index.d.ts +20 -0
  130. package/build-types/field-types/index.d.ts.map +1 -0
  131. package/build-types/field-types/integer.d.ts +14 -0
  132. package/build-types/field-types/integer.d.ts.map +1 -0
  133. package/build-types/field-types/text.d.ts +14 -0
  134. package/build-types/field-types/text.d.ts.map +1 -0
  135. package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
  136. package/build-types/index.d.ts +2 -1
  137. package/build-types/index.d.ts.map +1 -1
  138. package/build-types/normalize-fields.d.ts +0 -3
  139. package/build-types/normalize-fields.d.ts.map +1 -1
  140. package/build-types/types.d.ts +38 -3
  141. package/build-types/types.d.ts.map +1 -1
  142. package/build-types/validation.d.ts +3 -0
  143. package/build-types/validation.d.ts.map +1 -0
  144. package/package.json +12 -11
  145. package/src/components/dataform/index.tsx +8 -97
  146. package/src/components/dataform/stories/index.story.tsx +40 -3
  147. package/src/components/dataviews/index.tsx +20 -8
  148. package/src/components/dataviews/stories/fixtures.js +1 -0
  149. package/src/components/dataviews/style.scss +5 -2
  150. package/src/components/dataviews-bulk-actions/index.tsx +5 -0
  151. package/src/components/dataviews-filters/add-filter.tsx +37 -21
  152. package/src/components/dataviews-filters/index.tsx +149 -61
  153. package/src/components/dataviews-filters/style.scss +30 -0
  154. package/src/components/dataviews-layout/index.tsx +1 -1
  155. package/src/components/dataviews-search/index.tsx +8 -5
  156. package/src/components/dataviews-view-config/index.tsx +272 -258
  157. package/src/components/dataviews-view-config/style.scss +44 -0
  158. package/src/constants.ts +5 -0
  159. package/src/dataforms-layouts/index.tsx +20 -0
  160. package/src/dataforms-layouts/panel/index.tsx +164 -0
  161. package/src/dataforms-layouts/panel/style.scss +59 -0
  162. package/src/dataforms-layouts/regular/index.tsx +41 -0
  163. package/src/{layouts → dataviews-layouts}/grid/density-picker.tsx +2 -2
  164. package/src/{layouts → dataviews-layouts}/grid/index.tsx +8 -8
  165. package/src/{layouts → dataviews-layouts}/grid/style.scss +29 -0
  166. package/src/{layouts → dataviews-layouts}/list/style.scss +4 -1
  167. package/src/{layouts → dataviews-layouts}/table/column-header-menu.tsx +1 -1
  168. package/src/field-types/index.tsx +45 -0
  169. package/src/field-types/integer.tsx +103 -0
  170. package/src/field-types/text.tsx +95 -0
  171. package/src/filter-and-sort-data-view.ts +1 -15
  172. package/src/index.ts +2 -1
  173. package/src/normalize-fields.ts +44 -3
  174. package/src/style.scss +6 -3
  175. package/src/test/filter-and-sort-data-view.js +46 -3
  176. package/src/test/validation.ts +131 -0
  177. package/src/types.ts +50 -3
  178. package/src/validation.ts +18 -0
  179. package/tsconfig.json +2 -1
  180. package/tsconfig.tsbuildinfo +1 -1
  181. package/build/layouts/grid/density-picker.js.map +0 -1
  182. package/build/layouts/grid/index.js.map +0 -1
  183. package/build/layouts/index.js.map +0 -1
  184. package/build/layouts/list/index.js.map +0 -1
  185. package/build/layouts/table/column-header-menu.js.map +0 -1
  186. package/build/layouts/table/index.js.map +0 -1
  187. package/build-module/layouts/grid/density-picker.js.map +0 -1
  188. package/build-module/layouts/grid/index.js.map +0 -1
  189. package/build-module/layouts/index.js.map +0 -1
  190. package/build-module/layouts/list/index.js.map +0 -1
  191. package/build-module/layouts/table/column-header-menu.js.map +0 -1
  192. package/build-module/layouts/table/index.js.map +0 -1
  193. package/build-types/layouts/grid/density-picker.d.ts.map +0 -1
  194. package/build-types/layouts/grid/index.d.ts.map +0 -1
  195. package/build-types/layouts/index.d.ts.map +0 -1
  196. package/build-types/layouts/list/index.d.ts.map +0 -1
  197. package/build-types/layouts/table/column-header-menu.d.ts.map +0 -1
  198. package/build-types/layouts/table/index.d.ts.map +0 -1
  199. /package/build/{layouts → dataviews-layouts}/index.js +0 -0
  200. /package/build/{layouts → dataviews-layouts}/list/index.js +0 -0
  201. /package/build/{layouts → dataviews-layouts}/table/index.js +0 -0
  202. /package/build-module/{layouts → dataviews-layouts}/index.js +0 -0
  203. /package/build-module/{layouts → dataviews-layouts}/list/index.js +0 -0
  204. /package/build-module/{layouts → dataviews-layouts}/table/index.js +0 -0
  205. /package/build-types/{layouts → dataviews-layouts}/grid/density-picker.d.ts +0 -0
  206. /package/build-types/{layouts → dataviews-layouts}/grid/index.d.ts +0 -0
  207. /package/build-types/{layouts → dataviews-layouts}/index.d.ts +0 -0
  208. /package/build-types/{layouts → dataviews-layouts}/list/index.d.ts +0 -0
  209. /package/build-types/{layouts → dataviews-layouts}/table/column-header-menu.d.ts +0 -0
  210. /package/build-types/{layouts → dataviews-layouts}/table/index.d.ts +0 -0
  211. /package/src/{layouts → dataviews-layouts}/index.ts +0 -0
  212. /package/src/{layouts → dataviews-layouts}/list/index.tsx +0 -0
  213. /package/src/{layouts → dataviews-layouts}/table/index.tsx +0 -0
  214. /package/src/{layouts → dataviews-layouts}/table/style.scss +0 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _components = require("@wordpress/components");
8
+ var _element = require("@wordpress/element");
9
+ var _i18n = require("@wordpress/i18n");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ function sort(a, b, direction) {
20
+ return direction === 'asc' ? a - b : b - a;
21
+ }
22
+ function isValid(value, context) {
23
+ // TODO: this implicitely means the value is required.
24
+ if (value === '') {
25
+ return false;
26
+ }
27
+ if (!Number.isInteger(Number(value))) {
28
+ return false;
29
+ }
30
+ if (context?.elements) {
31
+ const validValues = context?.elements.map(f => f.value);
32
+ if (!validValues.includes(Number(value))) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ }
38
+ function Edit({
39
+ data,
40
+ field,
41
+ onChange,
42
+ hideLabelFromVision
43
+ }) {
44
+ var _field$getValue;
45
+ const {
46
+ id,
47
+ label,
48
+ description
49
+ } = field;
50
+ const value = (_field$getValue = field.getValue({
51
+ item: data
52
+ })) !== null && _field$getValue !== void 0 ? _field$getValue : '';
53
+ const onChangeControl = (0, _element.useCallback)(newValue => onChange(prevItem => ({
54
+ ...prevItem,
55
+ [id]: newValue
56
+ })), [id, onChange]);
57
+ if (field.elements) {
58
+ const elements = [
59
+ /*
60
+ * Value can be undefined when:
61
+ *
62
+ * - the field is not required
63
+ * - in bulk editing
64
+ *
65
+ */
66
+ {
67
+ label: (0, _i18n.__)('Select item'),
68
+ value: ''
69
+ }, ...field.elements];
70
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SelectControl, {
71
+ label: label,
72
+ value: value,
73
+ options: elements,
74
+ onChange: onChangeControl,
75
+ __next40pxDefaultSize: true,
76
+ __nextHasNoMarginBottom: true,
77
+ hideLabelFromVision: hideLabelFromVision
78
+ });
79
+ }
80
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalNumberControl, {
81
+ label: label,
82
+ help: description,
83
+ value: value,
84
+ onChange: onChangeControl,
85
+ __next40pxDefaultSize: true,
86
+ hideLabelFromVision: hideLabelFromVision
87
+ });
88
+ }
89
+ var _default = exports.default = {
90
+ sort,
91
+ isValid,
92
+ Edit
93
+ };
94
+ //# sourceMappingURL=integer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_components","require","_element","_i18n","_jsxRuntime","sort","a","b","direction","isValid","value","context","Number","isInteger","elements","validValues","map","f","includes","Edit","data","field","onChange","hideLabelFromVision","_field$getValue","id","label","description","getValue","item","onChangeControl","useCallback","newValue","prevItem","__","jsx","SelectControl","options","__next40pxDefaultSize","__nextHasNoMarginBottom","__experimentalNumberControl","help","_default","exports","default"],"sources":["@wordpress/dataviews/src/field-types/integer.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalNumberControl as NumberControl,\n\tSelectControl,\n} from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tSortDirection,\n\tValidationContext,\n\tDataFormControlProps,\n} from '../types';\n\nfunction sort( a: any, b: any, direction: SortDirection ) {\n\treturn direction === 'asc' ? a - b : b - a;\n}\n\nfunction isValid( value: any, context?: ValidationContext ) {\n\t// TODO: this implicitely means the value is required.\n\tif ( value === '' ) {\n\t\treturn false;\n\t}\n\n\tif ( ! Number.isInteger( Number( value ) ) ) {\n\t\treturn false;\n\t}\n\n\tif ( context?.elements ) {\n\t\tconst validValues = context?.elements.map( ( f ) => f.value );\n\t\tif ( ! validValues.includes( Number( value ) ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\nfunction Edit< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, description } = field;\n\tconst value = field.getValue( { item: data } ) ?? '';\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string | undefined ) =>\n\t\t\tonChange( ( prevItem: Item ) => ( {\n\t\t\t\t...prevItem,\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ) ),\n\t\t[ id, onChange ]\n\t);\n\n\tif ( field.elements ) {\n\t\tconst elements = [\n\t\t\t/*\n\t\t\t * Value can be undefined when:\n\t\t\t *\n\t\t\t * - the field is not required\n\t\t\t * - in bulk editing\n\t\t\t *\n\t\t\t */\n\t\t\t{ label: __( 'Select item' ), value: '' },\n\t\t\t...field.elements,\n\t\t];\n\n\t\treturn (\n\t\t\t<SelectControl\n\t\t\t\tlabel={ label }\n\t\t\t\tvalue={ value }\n\t\t\t\toptions={ elements }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<NumberControl\n\t\t\tlabel={ label }\n\t\t\thelp={ description }\n\t\t\tvalue={ value }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t/>\n\t);\n}\n\nexport default {\n\tsort,\n\tisValid,\n\tEdit,\n};\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAAqC,IAAAG,WAAA,GAAAH,OAAA;AARrC;AACA;AACA;;AAQA;AACA;AACA;;AAOA,SAASI,IAAIA,CAAEC,CAAM,EAAEC,CAAM,EAAEC,SAAwB,EAAG;EACzD,OAAOA,SAAS,KAAK,KAAK,GAAGF,CAAC,GAAGC,CAAC,GAAGA,CAAC,GAAGD,CAAC;AAC3C;AAEA,SAASG,OAAOA,CAAEC,KAAU,EAAEC,OAA2B,EAAG;EAC3D;EACA,IAAKD,KAAK,KAAK,EAAE,EA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AK,EAAGA,KAAO;MACfhB,KAAK,EAAGA,KAAO;MACf2B,OAAO,EAAGvB,QAAU;MACpBQ,QAAQ,EAAGQ,eAAiB;MAC5BQ,qBAAqB;MACrBC,uBAAuB;MACvBhB,mBAAmB,EAAGA;IAAqB,CAC3C,CAAC;EAEJ;EAEA,oBACC,IAAAnB,WAAA,CAAA+B,GAAA,EAACnC,WAAA,CAAAwC,2BAAa;IACbd,KAAK,EAAGA,KAAO;IACfe,IAAI,EAAGd,WAAa;IACpBjB,KAAK,EAAGA,KAAO;IACfY,QAAQ,EAAGQ,eAAiB;IAC5BQ,qBAAqB;IACrBf,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ;AAAC,IAAAmB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACdvC,IAAI;EACJI,OAAO;EACPU;AACD,CAAC","ignoreList":[]}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _components = require("@wordpress/components");
8
+ var _element = require("@wordpress/element");
9
+ var _i18n = require("@wordpress/i18n");
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * WordPress dependencies
13
+ */
14
+
15
+ /**
16
+ * Internal dependencies
17
+ */
18
+
19
+ function sort(valueA, valueB, direction) {
20
+ return direction === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA);
21
+ }
22
+ function isValid(value, context) {
23
+ if (context?.elements) {
24
+ const validValues = context?.elements?.map(f => f.value);
25
+ if (!validValues.includes(value)) {
26
+ return false;
27
+ }
28
+ }
29
+ return true;
30
+ }
31
+ function Edit({
32
+ data,
33
+ field,
34
+ onChange,
35
+ hideLabelFromVision
36
+ }) {
37
+ const {
38
+ id,
39
+ label,
40
+ placeholder
41
+ } = field;
42
+ const value = field.getValue({
43
+ item: data
44
+ });
45
+ const onChangeControl = (0, _element.useCallback)(newValue => onChange(prevItem => ({
46
+ ...prevItem,
47
+ [id]: newValue
48
+ })), [id, onChange]);
49
+ if (field.elements) {
50
+ const elements = [
51
+ /*
52
+ * Value can be undefined when:
53
+ *
54
+ * - the field is not required
55
+ * - in bulk editing
56
+ *
57
+ */
58
+ {
59
+ label: (0, _i18n.__)('Select item'),
60
+ value: ''
61
+ }, ...field.elements];
62
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.SelectControl, {
63
+ label: label,
64
+ value: value,
65
+ options: elements,
66
+ onChange: onChangeControl,
67
+ __next40pxDefaultSize: true,
68
+ __nextHasNoMarginBottom: true,
69
+ hideLabelFromVision: hideLabelFromVision
70
+ });
71
+ }
72
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
73
+ label: label,
74
+ placeholder: placeholder,
75
+ value: value !== null && value !== void 0 ? value : '',
76
+ onChange: onChangeControl,
77
+ __next40pxDefaultSize: true,
78
+ __nextHasNoMarginBottom: true,
79
+ hideLabelFromVision: hideLabelFromVision
80
+ });
81
+ }
82
+ var _default = exports.default = {
83
+ sort,
84
+ isValid,
85
+ Edit
86
+ };
87
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_components","require","_element","_i18n","_jsxRuntime","sort","valueA","valueB","direction","localeCompare","isValid","value","context","elements","validValues","map","f","includes","Edit","data","field","onChange","hideLabelFromVision","id","label","placeholder","getValue","item","onChangeControl","useCallback","newValue","prevItem","__","jsx","SelectControl","options","__next40pxDefaultSize","__nextHasNoMarginBottom","TextControl","_default","exports","default"],"sources":["@wordpress/dataviews/src/field-types/text.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { SelectControl, TextControl } from '@wordpress/components';\nimport { useCallback } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tSortDirection,\n\tValidationContext,\n\tDataFormControlProps,\n} from '../types';\n\nfunction sort( valueA: any, valueB: any, direction: SortDirection ) {\n\treturn direction === 'asc'\n\t\t? valueA.localeCompare( valueB )\n\t\t: valueB.localeCompare( valueA );\n}\n\nfunction isValid( value: any, context?: ValidationContext ) {\n\tif ( context?.elements ) {\n\t\tconst validValues = context?.elements?.map( ( f ) => f.value );\n\t\tif ( ! validValues.includes( value ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\nfunction Edit< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n\thideLabelFromVision,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, placeholder } = field;\n\tconst value = field.getValue( { item: data } );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( ( prevItem: Item ) => ( {\n\t\t\t\t...prevItem,\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ) ),\n\t\t[ id, onChange ]\n\t);\n\n\tif ( field.elements ) {\n\t\tconst elements = [\n\t\t\t/*\n\t\t\t * Value can be undefined when:\n\t\t\t *\n\t\t\t * - the field is not required\n\t\t\t * - in bulk editing\n\t\t\t *\n\t\t\t */\n\t\t\t{ label: __( 'Select item' ), value: '' },\n\t\t\t...field.elements,\n\t\t];\n\n\t\treturn (\n\t\t\t<SelectControl\n\t\t\t\tlabel={ label }\n\t\t\t\tvalue={ value }\n\t\t\t\toptions={ elements }\n\t\t\t\tonChange={ onChangeControl }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<TextControl\n\t\t\tlabel={ label }\n\t\t\tplaceholder={ placeholder }\n\t\t\tvalue={ value ?? '' }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\thideLabelFromVision={ hideLabelFromVision }\n\t\t/>\n\t);\n}\n\nexport default {\n\tsort,\n\tisValid,\n\tEdit,\n};\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GA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AAE,EAAE,aAAc,CAAC;MAAErB,KAAK,EAAE;IAAG,CAAC,EACzC,GAAGS,KAAK,CAACP,QAAQ,CACjB;IAED,oBACC,IAAAT,WAAA,CAAA6B,GAAA,EAACjC,WAAA,CAAAkC,aAAa;MACbV,KAAK,EAAGA,KAAO;MACfb,KAAK,EAAGA,KAAO;MACfwB,OAAO,EAAGtB,QAAU;MACpBQ,QAAQ,EAAGO,eAAiB;MAC5BQ,qBAAqB;MACrBC,uBAAuB;MACvBf,mBAAmB,EAAGA;IAAqB,CAC3C,CAAC;EAEJ;EAEA,oBACC,IAAAlB,WAAA,CAAA6B,GAAA,EAACjC,WAAA,CAAAsC,WAAW;IACXd,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3Bd,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBU,QAAQ,EAAGO,eAAiB;IAC5BQ,qBAAqB;IACrBC,uBAAuB;IACvBf,mBAAmB,EAAGA;EAAqB,CAC3C,CAAC;AAEJ;AAAC,IAAAiB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc;EACdpC,IAAI;EACJK,OAAO;EACPQ;AACD,CAAC","ignoreList":[]}
@@ -122,17 +122,8 @@ function filterSortAndPaginate(data, view, fields) {
122
122
  });
123
123
  if (fieldToSort) {
124
124
  filteredData.sort((a, b) => {
125
- var _fieldToSort$getValue, _fieldToSort$getValue2;
126
- const valueA = (_fieldToSort$getValue = fieldToSort.getValue({
127
- item: a
128
- })) !== null && _fieldToSort$getValue !== void 0 ? _fieldToSort$getValue : '';
129
- const valueB = (_fieldToSort$getValue2 = fieldToSort.getValue({
130
- item: b
131
- })) !== null && _fieldToSort$getValue2 !== void 0 ? _fieldToSort$getValue2 : '';
132
- if (typeof valueA === 'number' && typeof valueB === 'number') {
133
- return view.sort?.direction === 'asc' ? valueA - valueB : valueB - valueA;
134
- }
135
- return view.sort?.direction === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA);
125
+ var _view$sort$direction;
126
+ return fieldToSort.sort(a, b, (_view$sort$direction = view.sort?.direction) !== null && _view$sort$direction !== void 0 ? _view$sort$direction : 'desc');
136
127
  });
137
128
  }
138
129
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_removeAccents","_interopRequireDefault","require","_constants","_normalizeFields","normalizeSearchInput","input","removeAccents","trim","toLowerCase","EMPTY_ARRAY","filterSortAndPaginate","data","view","fields","paginationInfo","totalItems","totalPages","_fields","normalizeFields","filteredData","search","normalizedSearch","filter","item","field","enableGlobalSearch","map","getValue","some","includes","filters","length","forEach","find","_field","id","operator","OPERATOR_IS_ANY","value","fieldValue","Array","isArray","filterValue","OPERATOR_IS_NONE","OPERATOR_IS_ALL","every","OPERATOR_IS_NOT_ALL","OPERATOR_IS","OPERATOR_IS_NOT","sort","fieldId","fieldToSort","a","b","_fieldToSort$getValue","_fieldToSort$getValue2","valueA","valueB","direction","localeCompare","page","undefined","perPage","start","Math","ceil","slice"],"sources":["@wordpress/dataviews/src/filter-and-sort-data-view.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n} from './constants';\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, View } from './types';\n\nfunction normalizeSearchInput( input = '' ) {\n\treturn removeAccents( input.trim().toLowerCase() );\n}\n\nconst EMPTY_ARRAY: [] = [];\n\n/**\n * Applies the filtering, sorting and pagination to the raw data based on the view configuration.\n *\n * @param data Raw data.\n * @param view View config.\n * @param fields Fields config.\n *\n * @return Filtered, sorted and paginated data.\n */\nexport function filterSortAndPaginate< Item >(\n\tdata: Item[],\n\tview: View,\n\tfields: Field< Item >[]\n): {\n\tdata: Item[];\n\tpaginationInfo: { totalItems: number; totalPages: number };\n} {\n\tif ( ! data ) {\n\t\treturn {\n\t\t\tdata: EMPTY_ARRAY,\n\t\t\tpaginationInfo: { totalItems: 0, totalPages: 0 },\n\t\t};\n\t}\n\tconst _fields = normalizeFields( fields );\n\tlet filteredData = [ ...data ];\n\t// Handle global search.\n\tif ( view.search ) {\n\t\tconst normalizedSearch = normalizeSearchInput( view.search );\n\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\treturn _fields\n\t\t\t\t.filter( ( field ) => field.enableGlobalSearch )\n\t\t\t\t.map( ( field ) => {\n\t\t\t\t\treturn normalizeSearchInput( field.getValue( { item } ) );\n\t\t\t\t} )\n\t\t\t\t.some( ( field ) => field.includes( normalizedSearch ) );\n\t\t} );\n\t}\n\n\tif ( view.filters && view.filters?.length > 0 ) {\n\t\tview.filters.forEach( ( filter ) => {\n\t\t\tconst field = _fields.find(\n\t\t\t\t( _field ) => _field.id === filter.field\n\t\t\t);\n\t\t\tif ( field ) {\n\t\t\t\tif (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ANY &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NONE &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn ! filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn ! filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NOT_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn ! field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value === field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS_NOT ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value !== field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t// Handle sorting.\n\tif ( view.sort ) {\n\t\tconst fieldId = view.sort.field;\n\t\tconst fieldToSort = _fields.find( ( field ) => {\n\t\t\treturn field.id === fieldId;\n\t\t} );\n\t\tif ( fieldToSort ) {\n\t\t\tfilteredData.sort( ( a, b ) => {\n\t\t\t\tconst valueA = fieldToSort.getValue( { item: a } ) ?? '';\n\t\t\t\tconst valueB = fieldToSort.getValue( { item: b } ) ?? '';\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof valueA === 'number' &&\n\t\t\t\t\ttypeof valueB === 'number'\n\t\t\t\t) {\n\t\t\t\t\treturn view.sort?.direction === 'asc'\n\t\t\t\t\t\t? valueA - valueB\n\t\t\t\t\t\t: valueB - valueA;\n\t\t\t\t}\n\n\t\t\t\treturn view.sort?.direction === 'asc'\n\t\t\t\t\t? valueA.localeCompare( valueB )\n\t\t\t\t\t: valueB.localeCompare( valueA );\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Handle pagination.\n\tlet totalItems = filteredData.length;\n\tlet totalPages = 1;\n\tif ( view.page !== undefined && view.perPage !== undefined ) {\n\t\tconst start = ( view.page - 1 ) * view.perPage;\n\t\ttotalItems = filteredData?.length || 0;\n\t\ttotalPages = Math.ceil( totalItems / view.perPage );\n\t\tfilteredData = filteredData?.slice( start, start + view.perPage );\n\t}\n\n\treturn {\n\t\tdata: filteredData,\n\t\tpaginationInfo: {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AAQA,IAAAE,gBAAA,GAAAF,OAAA;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA,SAASG,oBAAoBA,CAAEC,KAAK,GAAG,EAAE,EAAG;EAC3C,OAAO,IAAAC,sBAAa,EAAED,KAAK,CAACE,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,CAAC;AACnD;AAEA,MAAMC,W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kD,OAAO;IAC9C/C,UAAU,GAAGI,YAAY,EAAEY,MAAM,IAAI,CAAC;IACtCf,UAAU,GAAGgD,IAAI,CAACC,IAAI,CAAElD,UAAU,GAAGH,IAAI,CAACkD,OAAQ,CAAC;IACnD3C,YAAY,GAAGA,YAAY,EAAE+C,KAAK,CAAEH,KAAK,EAAEA,KAAK,GAAGnD,IAAI,CAACkD,OAAQ,CAAC;EAClE;EAEA,OAAO;IACNnD,IAAI,EAAEQ,YAAY;IAClBL,cAAc,EAAE;MACfC,UAAU;MACVC;IACD;EACD,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_removeAccents","_interopRequireDefault","require","_constants","_normalizeFields","normalizeSearchInput","input","removeAccents","trim","toLowerCase","EMPTY_ARRAY","filterSortAndPaginate","data","view","fields","paginationInfo","totalItems","totalPages","_fields","normalizeFields","filteredData","search","normalizedSearch","filter","item","field","enableGlobalSearch","map","getValue","some","includes","filters","length","forEach","find","_field","id","operator","OPERATOR_IS_ANY","value","fieldValue","Array","isArray","filterValue","OPERATOR_IS_NONE","OPERATOR_IS_ALL","every","OPERATOR_IS_NOT_ALL","OPERATOR_IS","OPERATOR_IS_NOT","sort","fieldId","fieldToSort","a","b","_view$sort$direction","direction","page","undefined","perPage","start","Math","ceil","slice"],"sources":["@wordpress/dataviews/src/filter-and-sort-data-view.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n} from './constants';\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, View } from './types';\n\nfunction normalizeSearchInput( input = '' ) {\n\treturn removeAccents( input.trim().toLowerCase() );\n}\n\nconst EMPTY_ARRAY: [] = [];\n\n/**\n * Applies the filtering, sorting and pagination to the raw data based on the view configuration.\n *\n * @param data Raw data.\n * @param view View config.\n * @param fields Fields config.\n *\n * @return Filtered, sorted and paginated data.\n */\nexport function filterSortAndPaginate< Item >(\n\tdata: Item[],\n\tview: View,\n\tfields: Field< Item >[]\n): {\n\tdata: Item[];\n\tpaginationInfo: { totalItems: number; totalPages: number };\n} {\n\tif ( ! data ) {\n\t\treturn {\n\t\t\tdata: EMPTY_ARRAY,\n\t\t\tpaginationInfo: { totalItems: 0, totalPages: 0 },\n\t\t};\n\t}\n\tconst _fields = normalizeFields( fields );\n\tlet filteredData = [ ...data ];\n\t// Handle global search.\n\tif ( view.search ) {\n\t\tconst normalizedSearch = normalizeSearchInput( view.search );\n\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\treturn _fields\n\t\t\t\t.filter( ( field ) => field.enableGlobalSearch )\n\t\t\t\t.map( ( field ) => {\n\t\t\t\t\treturn normalizeSearchInput( field.getValue( { item } ) );\n\t\t\t\t} )\n\t\t\t\t.some( ( field ) => field.includes( normalizedSearch ) );\n\t\t} );\n\t}\n\n\tif ( view.filters && view.filters?.length > 0 ) {\n\t\tview.filters.forEach( ( filter ) => {\n\t\t\tconst field = _fields.find(\n\t\t\t\t( _field ) => _field.id === filter.field\n\t\t\t);\n\t\t\tif ( field ) {\n\t\t\t\tif (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ANY &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NONE &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn ! filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn ! filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NOT_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn ! field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value === field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS_NOT ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value !== field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t// Handle sorting.\n\tif ( view.sort ) {\n\t\tconst fieldId = view.sort.field;\n\t\tconst fieldToSort = _fields.find( ( field ) => {\n\t\t\treturn field.id === fieldId;\n\t\t} );\n\t\tif ( fieldToSort ) {\n\t\t\tfilteredData.sort( ( a, b ) => {\n\t\t\t\treturn fieldToSort.sort( a, b, view.sort?.direction ?? 'desc' );\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Handle pagination.\n\tlet totalItems = filteredData.length;\n\tlet totalPages = 1;\n\tif ( view.page !== undefined && view.perPage !== undefined ) {\n\t\tconst start = ( view.page - 1 ) * view.perPage;\n\t\ttotalItems = filteredData?.length || 0;\n\t\ttotalPages = Math.ceil( totalItems / view.perPage );\n\t\tfilteredData = filteredData?.slice( start, start + view.perPage );\n\t}\n\n\treturn {\n\t\tdata: filteredData,\n\t\tpaginationInfo: {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AAQA,IAAAE,gBAAA,GAAAF,OAAA;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA,SAASG,oBAAoBA,CAAEC,KAAK,GAAG,EAAE,EAAG;EAC3C,OAAO,IAAAC,sBAAa,EAAED,KAAK,CAACE,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,CAAC;AACnD;AAEA,MAAMC,WAAe,GAAG,EAAE;;AAE1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CACpCC,IAAY,EACZC,IAAU,EACVC,MAAuB,EAItB;EACD,IAAK,CAAEF,IAAI,EA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O;IAC5B,CAAE,CAAC;IACH,IAAKC,WAAW,EAAG;MAClBhC,YAAY,CAAC8B,IAAI,CAAE,CAAEG,CAAC,EAAEC,CAAC,KAAM;QAAA,IAAAC,oBAAA;QAC9B,OAAOH,WAAW,CAACF,IAAI,CAAEG,CAAC,EAAEC,CAAC,GAAAC,oBAAA,GAAE1C,IAAI,CAACqC,IAAI,EAAEM,SAAS,cAAAD,oBAAA,cAAAA,oBAAA,GAAI,MAAO,CAAC;MAChE,CAAE,CAAC;IACJ;EACD;;EAEA;EACA,IAAIvC,UAAU,GAAGI,YAAY,CAACY,MAAM;EACpC,IAAIf,UAAU,GAAG,CAAC;EAClB,IAAKJ,IAAI,CAAC4C,IAAI,KAAKC,SAAS,IAAI7C,IAAI,CAAC8C,OAAO,KAAKD,SAAS,EAAG;IAC5D,MAAME,KAAK,GAAG,CAAE/C,IAAI,CAAC4C,IAAI,GAAG,CAAC,IAAK5C,IAAI,CAAC8C,OAAO;IAC9C3C,UAAU,GAAGI,YAAY,EAAEY,MAAM,IAAI,CAAC;IACtCf,UAAU,GAAG4C,IAAI,CAACC,IAAI,CAAE9C,UAAU,GAAGH,IAAI,CAAC8C,OAAQ,CAAC;IACnDvC,YAAY,GAAGA,YAAY,EAAE2C,KAAK,CAAEH,KAAK,EAAEA,KAAK,GAAG/C,IAAI,CAAC8C,OAAQ,CAAC;EAClE;EAEA,OAAO;IACN/C,IAAI,EAAEQ,YAAY;IAClBL,cAAc,EAAE;MACfC,UAAU;MACVC;IACD;EACD,CAAC;AACF","ignoreList":[]}
package/build/index.js CHANGED
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "DataViews", {
19
19
  Object.defineProperty(exports, "VIEW_LAYOUTS", {
20
20
  enumerable: true,
21
21
  get: function () {
22
- return _layouts.VIEW_LAYOUTS;
22
+ return _dataviewsLayouts.VIEW_LAYOUTS;
23
23
  }
24
24
  });
25
25
  Object.defineProperty(exports, "filterSortAndPaginate", {
@@ -28,8 +28,15 @@ Object.defineProperty(exports, "filterSortAndPaginate", {
28
28
  return _filterAndSortDataView.filterSortAndPaginate;
29
29
  }
30
30
  });
31
+ Object.defineProperty(exports, "isItemValid", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _validation.isItemValid;
35
+ }
36
+ });
31
37
  var _dataviews = _interopRequireDefault(require("./components/dataviews"));
32
38
  var _dataform = _interopRequireDefault(require("./components/dataform"));
33
- var _layouts = require("./layouts");
39
+ var _dataviewsLayouts = require("./dataviews-layouts");
34
40
  var _filterAndSortDataView = require("./filter-and-sort-data-view");
41
+ var _validation = require("./validation");
35
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_dataviews","_interopRequireDefault","require","_dataform","_layouts","_filterAndSortDataView"],"sources":["@wordpress/dataviews/src/index.ts"],"sourcesContent":["export { default as DataViews } from './components/dataviews';\nexport { default as DataForm } from './components/dataform';\nexport { VIEW_LAYOUTS } from './layouts';\nexport { filterSortAndPaginate } from './filter-and-sort-data-view';\nexport type * from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_dataviews","_interopRequireDefault","require","_dataform","_dataviewsLayouts","_filterAndSortDataView","_validation"],"sources":["@wordpress/dataviews/src/index.ts"],"sourcesContent":["export { default as DataViews } from './components/dataviews';\nexport { default as DataForm } from './components/dataform';\nexport { VIEW_LAYOUTS } from './dataviews-layouts';\nexport { filterSortAndPaginate } from './filter-and-sort-data-view';\nexport type * from './types';\nexport { isItemValid } from './validation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AACA,IAAAG,sBAAA,GAAAH,OAAA;AAEA,IAAAI,WAAA,GAAAJ,OAAA","ignoreList":[]}
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.normalizeFields = normalizeFields;
8
+ var _fieldTypes = _interopRequireDefault(require("./field-types"));
7
9
  /**
8
10
  * Internal dependencies
9
11
  */
@@ -16,14 +18,46 @@ exports.normalizeFields = normalizeFields;
16
18
  */
17
19
  function normalizeFields(fields) {
18
20
  return fields.map(field => {
21
+ var _field$sort, _field$isValid;
22
+ const fieldTypeDefinition = (0, _fieldTypes.default)(field.type);
19
23
  const getValue = field.getValue || (({
20
24
  item
21
25
  }) => item[field.id]);
26
+ const sort = (_field$sort = field.sort) !== null && _field$sort !== void 0 ? _field$sort : function sort(a, b, direction) {
27
+ return fieldTypeDefinition.sort(getValue({
28
+ item: a
29
+ }), getValue({
30
+ item: b
31
+ }), direction);
32
+ };
33
+ const isValid = (_field$isValid = field.isValid) !== null && _field$isValid !== void 0 ? _field$isValid : function isValid(item, context) {
34
+ return fieldTypeDefinition.isValid(getValue({
35
+ item
36
+ }), context);
37
+ };
38
+ const Edit = field.Edit || fieldTypeDefinition.Edit;
39
+ const renderFromElements = ({
40
+ item
41
+ }) => {
42
+ const value = getValue({
43
+ item
44
+ });
45
+ const label = field?.elements?.find(element => {
46
+ // Intentionally using == here to allow for type coercion.
47
+ // eslint-disable-next-line eqeqeq
48
+ return element.value == value;
49
+ })?.label;
50
+ return label || value;
51
+ };
52
+ const render = field.render || (field.elements ? renderFromElements : getValue);
22
53
  return {
23
54
  ...field,
24
55
  label: field.label || field.id,
25
56
  getValue,
26
- render: field.render || getValue
57
+ render,
58
+ sort,
59
+ isValid,
60
+ Edit
27
61
  };
28
62
  });
29
63
  }
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeFields","fields","map","field","getValue","item","id","label","render"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Field, NormalizedField, ItemRecord } from './types';\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 getValue =\n\t\t\tfield.getValue ||\n\t\t\t( ( { item }: { item: ItemRecord } ) => item[ field.id ] );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender: field.render || getValue,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAeA,CAC9BC,MAAuB,EACK;EAC5B,OAAOA,MAAM,CAACC,GAAG,CAAIC,KAAK,IAAM;IAC/B,MAAMC,QAAQ,GACbD,KAAK,CAACC,QAAQ,KACZ,CAAE;MAAEC;IAA2B,CAAC,KAAMA,IAAI,CAAEF,KAAK,CAACG,EAAE,CAAE,CAAE;IAE3D,OAAO;MACN,GAAGH,KAAK;MACRI,KAAK,EAAEJ,KAAK,CAACI,KAAK,IAAIJ,KAAK,CAACG,EAAE;MAC9BF,QAAQ;MACRI,MAAM,EAAEL,KAAK,CAACK,MAAM,IAAIJ;IACzB,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_fieldTypes","_interopRequireDefault","require","normalizeFields","fields","map","field","_field$sort","_field$isValid","fieldTypeDefinition","getFieldTypeDefinition","type","getValue","item","id","sort","a","b","direction","isValid","context","Edit","renderFromElements","value","label","elements","find","element","render"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type { Field, NormalizedField } from './types';\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 =\n\t\t\tfield.getValue ||\n\t\t\t( ( { item }: { item: Item } ) => item[ field.id as keyof Item ] );\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 = field.Edit || fieldTypeDefinition.Edit;\n\n\t\tconst renderFromElements = ( { item }: { item: Item } ) => {\n\t\t\tconst value = getValue( { item } );\n\t\t\tconst label = field?.elements?.find( ( element ) => {\n\t\t\t\t// Intentionally using == here to allow for type coercion.\n\t\t\t\t// eslint-disable-next-line eqeqeq\n\t\t\t\treturn element.value == value;\n\t\t\t} )?.label;\n\n\t\t\treturn label || value;\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\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA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IAAIA,KAAK;MAC9B,CAAE,CAAC,EAAEC,KAAK;MAEV,OAAOA,KAAK,IAAID,KAAK;IACtB,CAAC;IAED,MAAMK,MAAM,GACXtB,KAAK,CAACsB,MAAM,KAAMtB,KAAK,CAACmB,QAAQ,GAAGH,kBAAkB,GAAGV,QAAQ,CAAE;IAEnE,OAAO;MACN,GAAGN,KAAK;MACRkB,KAAK,EAAElB,KAAK,CAACkB,KAAK,IAAIlB,KAAK,CAACQ,EAAE;MAC9BF,QAAQ;MACRgB,MAAM;MACNb,IAAI;MACJI,OAAO;MACPE;IACD,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.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\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 ItemRecord = Record< string, unknown >;\n\nexport type FieldType = 'text';\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 * 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< { item: Item } >;\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} & ( Item extends ItemRecord\n\t? {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue?: ( args: { item: Item } ) => any;\n\t }\n\t: {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue: ( args: { item: Item } ) => any;\n\t } );\n\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< { item: Item } >;\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\n/**\n * The form configuration.\n */\nexport type Form = {\n\tvisibleFields?: string[];\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\nexport interface CombinedField {\n\tid: string;\n\n\tlabel: string;\n\n\t/**\n\t * The fields to use as columns.\n\t */\n\tchildren: string[];\n\n\t/**\n\t * The direction of the stack.\n\t */\n\tdirection: 'horizontal' | 'vertical';\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 interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcombinedFields?: CombinedField[];\n\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcolumnFields?: string[];\n\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\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\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}: {\n\t\titems: Item[];\n\t\tcloseModal?: () => void;\n\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t} ) => 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\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\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tview: View;\n\tdensity: number;\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"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tReactElement,\n\tComponentType,\n\tDispatch,\n\tSetStateAction,\n} from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\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 ItemRecord = Record< string, unknown >;\n\nexport type FieldType = 'text' | 'integer';\n\nexport type ValidationContext = {\n\telements?: Option[];\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 * 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< { item: Item } >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > >;\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 * 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} & ( Item extends ItemRecord\n\t? {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue?: ( args: { item: Item } ) => any;\n\t }\n\t: {\n\t\t\t/**\n\t\t\t * Callback used to retrieve the value of the field from the item.\n\t\t\t * Defaults to `item[ field.id ]`.\n\t\t\t */\n\t\t\tgetValue: ( args: { item: Item } ) => any;\n\t } );\n\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< { item: Item } >;\n\tEdit: ComponentType< DataFormControlProps< Item > >;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => 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\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: string[];\n};\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: Dispatch< SetStateAction< Item > >;\n\thideLabelFromVision?: boolean;\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\nexport interface CombinedField {\n\tid: string;\n\n\tlabel: string;\n\n\t/**\n\t * The fields to use as columns.\n\t */\n\tchildren: string[];\n\n\t/**\n\t * The direction of the stack.\n\t */\n\tdirection: 'horizontal' | 'vertical';\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 interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcombinedFields?: CombinedField[];\n\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\t};\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The field to use as the primary field.\n\t\t */\n\t\tprimaryField?: string;\n\n\t\t/**\n\t\t * The field to use as the media field.\n\t\t */\n\t\tmediaField?: string;\n\n\t\t/**\n\t\t * The fields to use as columns.\n\t\t */\n\t\tcolumnFields?: string[];\n\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\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\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}: {\n\t\titems: Item[];\n\t\tcloseModal?: () => void;\n\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t} ) => 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\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\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tview: View;\n\tdensity: number;\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 interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: Dispatch< SetStateAction< Item > >;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isItemValid = isItemValid;
7
+ var _normalizeFields = require("./normalize-fields");
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+
12
+ function isItemValid(item, fields, form) {
13
+ const _fields = (0, _normalizeFields.normalizeFields)(fields.filter(({
14
+ id
15
+ }) => !!form.fields?.includes(id)));
16
+ return _fields.every(field => {
17
+ return field.isValid(item, {
18
+ elements: field.elements
19
+ });
20
+ });
21
+ }
22
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_normalizeFields","require","isItemValid","item","fields","form","_fields","normalizeFields","filter","id","includes","every","field","isValid","elements"],"sources":["@wordpress/dataviews/src/validation.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, Form } from './types';\n\nexport function isItemValid< Item >(\n\titem: Item,\n\tfields: Field< Item >[],\n\tform: Form\n): boolean {\n\tconst _fields = normalizeFields(\n\t\tfields.filter( ( { id } ) => !! form.fields?.includes( id ) )\n\t);\n\treturn _fields.every( ( field ) => {\n\t\treturn field.isValid( item, { elements: field.elements } );\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAIO,SAASC,WAAWA,CAC1BC,IAAU,EACVC,MAAuB,EACvBC,IAAU,EACA;EACV,MAAMC,OAAO,GAAG,IAAAC,gCAAe,EAC9BH,MAAM,CAACI,MAAM,CAAE,CAAE;IAAEC;EAAG,CAAC,KAAM,CAAC,CAAEJ,IAAI,CAACD,MAAM,EAAEM,QAAQ,CAAED,EAAG,CAAE,CAC7D,CAAC;EACD,OAAOH,OAAO,CAACK,KAAK,CAAIC,KAAK,IAAM;IAClC,OAAOA,KAAK,CAACC,OAAO,CAAEV,IAAI,EAAE;MAAEW,QAAQ,EAAEF,KAAK,CAACE;IAAS,CAAE,CAAC;EAC3D,CAAE,CAAC;AACJ","ignoreList":[]}
@@ -1,72 +1,21 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- /**
6
- * WordPress dependencies
7
- */
8
- import { TextControl } from '@wordpress/components';
9
- import { useCallback, useMemo } from '@wordpress/element';
10
-
11
1
  /**
12
2
  * Internal dependencies
13
3
  */
14
4
 
15
- import { normalizeFields } from '../../normalize-fields';
5
+ import { getFormLayout } from '../../dataforms-layouts';
16
6
  import { jsx as _jsx } from "react/jsx-runtime";
17
- function DataFormTextControl({
18
- data,
19
- field,
20
- onChange
21
- }) {
22
- const {
23
- id,
24
- label,
25
- placeholder
26
- } = field;
27
- const value = field.getValue({
28
- item: data
29
- });
30
- const onChangeControl = useCallback(newValue => onChange(prevItem => ({
31
- ...prevItem,
32
- [id]: newValue
33
- })), [id, onChange]);
34
- return /*#__PURE__*/_jsx(TextControl, {
35
- label: label,
36
- placeholder: placeholder,
37
- value: value !== null && value !== void 0 ? value : '',
38
- onChange: onChangeControl,
39
- __next40pxDefaultSize: true
40
- });
41
- }
42
- const controls = {
43
- text: DataFormTextControl
44
- };
45
- function getControlForField(field) {
46
- if (!field.type) {
47
- return null;
48
- }
49
- if (!Object.keys(controls).includes(field.type)) {
50
- return null;
51
- }
52
- return controls[field.type];
53
- }
54
7
  export default function DataForm({
55
- data,
56
- fields,
57
8
  form,
58
- onChange
9
+ ...props
59
10
  }) {
60
- const visibleFields = useMemo(() => normalizeFields(fields.filter(({
61
- id
62
- }) => !!form.visibleFields?.includes(id))), [fields, form.visibleFields]);
63
- return visibleFields.map(field => {
64
- const DataFormControl = getControlForField(field);
65
- return DataFormControl ? /*#__PURE__*/_jsx(DataFormControl, {
66
- data: data,
67
- field: field,
68
- onChange: onChange
69
- }, field.id) : null;
11
+ var _form$type;
12
+ const layout = getFormLayout((_form$type = form.type) !== null && _form$type !== void 0 ? _form$type : 'regular');
13
+ if (!layout) {
14
+ return null;
15
+ }
16
+ return /*#__PURE__*/_jsx(layout.component, {
17
+ form: form,
18
+ ...props
70
19
  });
71
20
  }
72
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["TextControl","useCallback","useMemo","normalizeFields","jsx","_jsx","DataFormTextControl","data","field","onChange","id","label","placeholder","value","getValue","item","onChangeControl","newValue","prevItem","__next40pxDefaultSize","controls","text","getControlForField","type","Object","keys","includes","DataForm","fields","form","visibleFields","filter","map","DataFormControl"],"sources":["@wordpress/dataviews/src/components/dataform/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { Dispatch, SetStateAction } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { TextControl } from '@wordpress/components';\nimport { useCallback, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { Form, Field, NormalizedField } from '../../types';\nimport { normalizeFields } from '../../normalize-fields';\n\ntype DataFormProps< Item > = {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: Dispatch< SetStateAction< Item > >;\n};\n\ntype DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: Dispatch< SetStateAction< Item > >;\n};\n\nfunction DataFormTextControl< Item >( {\n\tdata,\n\tfield,\n\tonChange,\n}: DataFormControlProps< Item > ) {\n\tconst { id, label, placeholder } = field;\n\tconst value = field.getValue( { item: data } );\n\n\tconst onChangeControl = useCallback(\n\t\t( newValue: string ) =>\n\t\t\tonChange( ( prevItem: Item ) => ( {\n\t\t\t\t...prevItem,\n\t\t\t\t[ id ]: newValue,\n\t\t\t} ) ),\n\t\t[ id, onChange ]\n\t);\n\n\treturn (\n\t\t<TextControl\n\t\t\tlabel={ label }\n\t\t\tplaceholder={ placeholder }\n\t\t\tvalue={ value ?? '' }\n\t\t\tonChange={ onChangeControl }\n\t\t\t__next40pxDefaultSize\n\t\t/>\n\t);\n}\n\nconst controls: {\n\t[ key: string ]: < Item >(\n\t\tprops: DataFormControlProps< Item >\n\t) => JSX.Element;\n} = {\n\ttext: DataFormTextControl,\n};\n\nfunction getControlForField< Item >( field: NormalizedField< Item > ) {\n\tif ( ! field.type ) {\n\t\treturn null;\n\t}\n\n\tif ( ! Object.keys( controls ).includes( field.type ) ) {\n\t\treturn null;\n\t}\n\n\treturn controls[ field.type ];\n}\n\nexport default function DataForm< Item >( {\n\tdata,\n\tfields,\n\tform,\n\tonChange,\n}: DataFormProps< Item > ) {\n\tconst visibleFields = useMemo(\n\t\t() =>\n\t\t\tnormalizeFields(\n\t\t\t\tfields.filter(\n\t\t\t\t\t( { id } ) => !! form.visibleFields?.includes( id )\n\t\t\t\t)\n\t\t\t),\n\t\t[ fields, form.visibleFields ]\n\t);\n\n\treturn visibleFields.map( ( field ) => {\n\t\tconst DataFormControl = getControlForField( field );\n\t\treturn DataFormControl ? (\n\t\t\t<DataFormControl\n\t\t\t\tkey={ field.id }\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\tonChange={ onChange }\n\t\t\t/>\n\t\t) : null;\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,uBAAuB;AACnD,SAASC,WAAW,EAAEC,OAAO,QAAQ,oBAAoB;;AAEzD;AACA;AACA;;AAEA,SAASC,eAAe,QAAQ,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAezD,SAASC,mBAAmBA,CAAU;EACrCC,IAAI;EACJC,KAAK;EACLC;AAC6B,CAAC,EAAG;EACjC,MAAM;IAAEC,EAAE;IAAEC,KAAK;IAAEC;EAAY,CAAC,GAAGJ,KAAK;EACxC,MAAMK,KAAK,GAAGL,KAAK,CAACM,QAAQ,CAAE;IAAEC,IAAI,EAAER;EAAK,CAAE,CAAC;EAE9C,MAAMS,eAAe,GAAGf,WAAW,CAChCgB,QAAgB,IACjBR,QAAQ,CAAIS,QAAc,KAAQ;IACjC,GAAGA,QAAQ;IACX,CAAER,EAAE,GAAIO;EACT,CAAC,CAAG,CAAC,EACN,CAAEP,EAAE,EAAED,QAAQ,CACf,CAAC;EAED,oBACCJ,IAAA,CAACL,WAAW;IACXW,KAAK,EAAGA,KAAO;IACfC,WAAW,EAAGA,WAAa;IAC3BC,KAAK,EAAGA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,EAAI;IACrBJ,QAAQ,EAAGO,eAAiB;IAC5BG,qBAAqB;EAAA,CACrB,CAAC;AAEJ;AAEA,MAAMC,QAIL,GAAG;EACHC,IAAI,EAAEf;AACP,CAAC;AAED,SAASgB,kBAAkBA,CAAUd,KAA8B,EAAG;EACrE,IAAK,CAAEA,KAAK,CAACe,IAAI,EAAG;IACnB,OAAO,IAAI;EACZ;EAEA,IAAK,CAAEC,MAAM,CAACC,IAAI,CAAEL,QAAS,CAAC,CAACM,QAAQ,CAAElB,KAAK,CAACe,IAAK,CAAC,EAAG;IACvD,OAAO,IAAI;EACZ;EAEA,OAAOH,QAAQ,CAAEZ,KAAK,CAACe,IAAI,CAAE;AAC9B;AAEA,eAAe,SAASI,QAAQA,CAAU;EACzCpB,IAAI;EACJqB,MAAM;EACNC,IAAI;EACJpB;AACsB,CAAC,EAAG;EAC1B,MAAMqB,aAAa,GAAG5B,OAAO,CAC5B,MACCC,eAAe,CACdyB,MAAM,CAACG,MAAM,CACZ,CAAE;IAAErB;EAAG,CAAC,KAAM,CAAC,CAAEmB,IAAI,CAACC,aAAa,EAAEJ,QAAQ,CAAEhB,EAAG,CACnD,CACD,CAAC,EACF,CAAEkB,MAAM,EAAEC,IAAI,CAACC,aAAa,CAC7B,CAAC;EAED,OAAOA,aAAa,CAACE,GAAG,CAAIxB,KAAK,IAAM;IACtC,MAAMyB,eAAe,GAAGX,kBAAkB,CAAEd,KAAM,CAAC;IACnD,OAAOyB,eAAe,gBACrB5B,IAAA,CAAC4B,eAAe;MAEf1B,IAAI,EAAGA,IAAM;MACbC,KAAK,EAAGA,KAAO;MACfC,QAAQ,EAAGA;IAAU,GAHfD,KAAK,CAACE,EAIZ,CAAC,GACC,IAAI;EACT,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["getFormLayout","jsx","_jsx","DataForm","form","props","_form$type","layout","type","component"],"sources":["@wordpress/dataviews/src/components/dataform/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { DataFormProps } from '../../types';\nimport { getFormLayout } from '../../dataforms-layouts';\n\nexport default function DataForm< Item >( {\n\tform,\n\t...props\n}: DataFormProps< Item > ) {\n\tconst layout = getFormLayout( form.type ?? 'regular' );\n\tif ( ! layout ) {\n\t\treturn null;\n\t}\n\n\treturn <layout.component form={ form } { ...props } />;\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAExD,eAAe,SAASC,QAAQA,CAAU;EACzCC,IAAI;EACJ,GAAGC;AACmB,CAAC,EAAG;EAAA,IAAAC,UAAA;EAC1B,MAAMC,MAAM,GAAGP,aAAa,EAAAM,UAAA,GAAEF,IAAI,CAACI,IAAI,cAAAF,UAAA,cAAAA,UAAA,GAAI,SAAU,CAAC;EACtD,IAAK,CAAEC,MAAM,EAAG;IACf,OAAO,IAAI;EACZ;EAEA,oBAAOL,IAAA,CAACK,MAAM,CAACE,SAAS;IAACL,IAAI,EAAGA,IAAM;IAAA,GAAMC;EAAK,CAAI,CAAC;AACvD","ignoreList":[]}
@@ -14,13 +14,13 @@ import { useMemo, useState } from '@wordpress/element';
14
14
  import { default as DataViewsBulkActions } from '../dataviews-bulk-actions';
15
15
  import DataViewsBulkActionsToolbar from '../dataviews-bulk-actions-toolbar';
16
16
  import DataViewsContext from '../dataviews-context';
17
- import DataViewsFilters from '../dataviews-filters';
17
+ import { default as DataViewsFilters, useFilters, FilterVisibilityToggle } from '../dataviews-filters';
18
18
  import DataViewsLayout from '../dataviews-layout';
19
19
  import DataviewsPagination from '../dataviews-pagination';
20
20
  import DataViewsSearch from '../dataviews-search';
21
21
  import DataViewsViewConfig from '../dataviews-view-config';
22
22
  import { normalizeFields } from '../../normalize-fields';
23
- import DensityPicker from '../../layouts/grid/density-picker';
23
+ import DensityPicker from '../../dataviews-layouts/grid/density-picker';
24
24
  import { LAYOUT_GRID } from '../../constants';
25
25
  import { jsx as _jsx } from "react/jsx-runtime";
26
26
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -43,6 +43,7 @@ export default function DataViews({
43
43
  }) {
44
44
  const [selectionState, setSelectionState] = useState([]);
45
45
  const [density, setDensity] = useState(0);
46
+ const [isShowingFilter, setIsShowingFilter] = useState(false);
46
47
  const isUncontrolled = selectionProperty === undefined || onChangeSelection === undefined;
47
48
  const selection = isUncontrolled ? selectionState : selectionProperty;
48
49
  const [openedFilter, setOpenedFilter] = useState(null);
@@ -59,6 +60,7 @@ export default function DataViews({
59
60
  const _selection = useMemo(() => {
60
61
  return selection.filter(id => data.some(item => getItemId(item) === id));
61
62
  }, [selection, data, getItemId]);
63
+ const filters = useFilters(_fields, view);
62
64
  return /*#__PURE__*/_jsx(DataViewsContext.Provider, {
63
65
  value: {
64
66
  view,
@@ -81,13 +83,20 @@ export default function DataViews({
81
83
  alignment: "top",
82
84
  justify: "start",
83
85
  className: "dataviews__view-actions",
86
+ spacing: 1,
84
87
  children: [/*#__PURE__*/_jsxs(HStack, {
85
88
  justify: "start",
86
- className: "dataviews-filters__container",
87
89
  wrap: true,
88
90
  children: [search && /*#__PURE__*/_jsx(DataViewsSearch, {
89
91
  label: searchLabel
90
- }), /*#__PURE__*/_jsx(DataViewsFilters, {})]
92
+ }), /*#__PURE__*/_jsx(FilterVisibilityToggle, {
93
+ filters: filters,
94
+ view: view,
95
+ onChangeView: onChangeView,
96
+ setOpenedFilter: setOpenedFilter,
97
+ setIsShowingFilter: setIsShowingFilter,
98
+ isShowingFilter: isShowingFilter
99
+ })]
91
100
  }), view.type === LAYOUT_GRID && /*#__PURE__*/_jsx(DensityPicker, {
92
101
  density: density,
93
102
  setDensity: setDensity
@@ -101,7 +110,7 @@ export default function DataViews({
101
110
  defaultLayouts: defaultLayouts
102
111
  }), header]
103
112
  })]
104
- }), /*#__PURE__*/_jsx(DataViewsLayout, {}), /*#__PURE__*/_jsx(DataviewsPagination, {}), /*#__PURE__*/_jsx(DataViewsBulkActionsToolbar, {})]
113
+ }), isShowingFilter && /*#__PURE__*/_jsx(DataViewsFilters, {}), /*#__PURE__*/_jsx(DataViewsLayout, {}), /*#__PURE__*/_jsx(DataviewsPagination, {}), /*#__PURE__*/_jsx(DataViewsBulkActionsToolbar, {})]
105
114
  })
106
115
  });
107
116
  }