@wordpress/dataviews 0.5.5 → 0.7.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 (45) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +156 -111
  3. package/build/add-filter.js +0 -2
  4. package/build/add-filter.js.map +1 -1
  5. package/build/dataviews.js +1 -4
  6. package/build/dataviews.js.map +1 -1
  7. package/build/reset-filters.js +2 -1
  8. package/build/reset-filters.js.map +1 -1
  9. package/build/search-widget.js +89 -4
  10. package/build/search-widget.js.map +1 -1
  11. package/build/view-actions.js.map +1 -1
  12. package/build/view-grid.js +5 -12
  13. package/build/view-grid.js.map +1 -1
  14. package/build/view-list.js +1 -1
  15. package/build/view-list.js.map +1 -1
  16. package/build/view-table.js +2 -4
  17. package/build/view-table.js.map +1 -1
  18. package/build-module/add-filter.js +0 -2
  19. package/build-module/add-filter.js.map +1 -1
  20. package/build-module/dataviews.js +2 -5
  21. package/build-module/dataviews.js.map +1 -1
  22. package/build-module/reset-filters.js +2 -1
  23. package/build-module/reset-filters.js.map +1 -1
  24. package/build-module/search-widget.js +91 -6
  25. package/build-module/search-widget.js.map +1 -1
  26. package/build-module/view-actions.js.map +1 -1
  27. package/build-module/view-grid.js +6 -13
  28. package/build-module/view-grid.js.map +1 -1
  29. package/build-module/view-list.js +2 -2
  30. package/build-module/view-list.js.map +1 -1
  31. package/build-module/view-table.js +3 -5
  32. package/build-module/view-table.js.map +1 -1
  33. package/build-style/style-rtl.css +47 -33
  34. package/build-style/style.css +47 -33
  35. package/package.json +11 -11
  36. package/src/add-filter.js +0 -2
  37. package/src/dataviews.js +47 -52
  38. package/src/reset-filters.js +2 -1
  39. package/src/search-widget.js +131 -6
  40. package/src/stories/index.story.js +12 -16
  41. package/src/style.scss +81 -61
  42. package/src/view-actions.js +1 -1
  43. package/src/view-grid.js +5 -11
  44. package/src/view-list.js +2 -1
  45. package/src/view-table.js +4 -3
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.7.0 (2024-03-06)
6
+
7
+ ## 0.6.0 (2024-02-21)
8
+
5
9
  ## 0.5.0 (2024-02-09)
6
10
 
7
11
  ## 0.4.0 (2024-01-24)
package/README.md CHANGED
@@ -12,85 +12,147 @@ npm install @wordpress/dataviews --save
12
12
 
13
13
  ## Usage
14
14
 
15
- ```js
16
- <DataViews
17
- data={ data }
18
- paginationInfo={ { totalItems, totalPages } }
19
- view={ view }
20
- onChangeView={ onChangeView }
21
- fields={ fields }
22
- actions={ [ trashPostAction ] }
23
- search={ false }
24
- searchLabel="Filter list"
25
- getItemId={ ( item ) => item.id }
26
- isLoading={ isLoadingData }
27
- supportedLayouts={ [ 'table' ] }
28
- deferredRendering={ true }
29
- onSelectionChange={ ( items ) => { /* ... */ } }
30
- />
15
+ ```jsx
16
+ const Example = () => {
17
+
18
+ // Declare data, fields, etc.
19
+
20
+ return (
21
+ <DataViews
22
+ data={ data }
23
+ fields={ fields }
24
+ view={ view }
25
+ onChangeView={ onChangeView }
26
+ actions={ actions }
27
+ paginationInfo={ paginationInfo }
28
+ />
29
+ );
30
+ }
31
31
  ```
32
32
 
33
- ## Data
33
+ ## Properties
34
+
35
+ ### `data`: `Object[]`
34
36
 
35
37
  The dataset to work with, represented as a one-dimensional array.
36
38
 
37
39
  Example:
38
40
 
39
41
  ```js
40
- [
41
- { id: 1, title: "Title", ... },
42
- { ... }
42
+ const data = [
43
+ {
44
+ id: 1,
45
+ title: "Title",
46
+ author: "Admin",
47
+ date: "2012-04-23T18:25:43.511Z"
48
+ },
49
+ { /* ... */ }
43
50
  ]
44
51
  ```
45
52
 
46
- By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one. See "Other props" section.
53
+ By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one.
47
54
 
48
- ## Pagination Info
55
+ ### `fields`: `Object[]`
49
56
 
50
- - `totalItems`: the total number of items in the datasets.
51
- - `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
57
+ The fields describe the visible items for each record in the dataset.
52
58
 
53
- ## View
59
+ Example:
60
+
61
+ ```js
62
+ const fields = [
63
+ {
64
+ id: 'title',
65
+ header: 'Title',
66
+ getValue: ({ item }) => item.title,
67
+ enableHiding: false,
68
+ },
69
+ {
70
+ id: 'date',
71
+ header: 'Date',
72
+ getValue: ( { item } ) => item.date,
73
+ render: ( { item } ) => {
74
+ return (
75
+ <time>{ getFormattedDate( item.date ) }</time>
76
+ );
77
+ }
78
+ },
79
+ {
80
+ id: 'author',
81
+ header: __( 'Author' ),
82
+ getValue: ( { item } ) => item.author,
83
+ render: ( { item } ) => {
84
+ return (
85
+ <a href="...">{ item.author }</a>
86
+ );
87
+ },
88
+ type: 'enumeration',
89
+ elements: [
90
+ { value: 1, label: 'Admin' }
91
+ { value: 2, label: 'User' }
92
+ ]
93
+ enableSorting: false
94
+ }
95
+ ]
96
+ ```
97
+
98
+ Each field is an object with the following properties:
99
+
100
+ - `id`: identifier for the field. Unique.
101
+ - `header`: the field's name to be shown in the UI.
102
+ - `getValue`: function that returns the value of the field.
103
+ - `render`: function that renders the field. Optional, `getValue` will be used if `render` is not defined.
104
+ - `elements`: the set of valid values for the field's value.
105
+ - `type`: the type of the field. Used to generate the proper filters. Only `enumeration` available at the moment. See "Field types".
106
+ - `enableSorting`: whether the data can be sorted by the given field. True by default.
107
+ - `enableHiding`: whether the field can be hidden. True by default.
108
+ - `filterBy`: configuration for the filters.
109
+ - `operators`: the list of operators supported by the field.
110
+ - `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter.
111
+
112
+ ### `view`: `object`
54
113
 
55
114
  The view object configures how the dataset is visible to the user.
56
115
 
57
116
  Example:
58
117
 
59
118
  ```js
60
- {
119
+ const view = {
61
120
  type: 'table',
62
- perPage: 5,
63
- page: 1,
64
- sort: {
65
- field: 'date',
66
- direction: 'desc',
67
- },
68
121
  search: '',
69
122
  filters: [
70
123
  { field: 'author', operator: 'in', value: 2 },
71
124
  { field: 'status', operator: 'in', value: 'publish,draft' }
72
125
  ],
126
+ page: 1,
127
+ perPage: 5,
128
+ sort: {
129
+ field: 'date',
130
+ direction: 'desc',
131
+ },
73
132
  hiddenFields: [ 'date', 'featured-image' ],
74
133
  layout: {},
75
134
  }
76
135
  ```
77
136
 
78
- - `type`: view type, one of `table`, `grid`, `list`. See "View types".
79
- - `perPage`: number of records to show per page.
80
- - `page`: the page that is visible.
81
- - `sort.field`: field used for sorting the dataset.
82
- - `sort.direction`: the direction to use for sorting, one of `asc` or `desc`.
137
+ Properties:
138
+
139
+ - `type`: view type, one of `table`, `grid`, `list`. See "Layout types".
83
140
  - `search`: the text search applied to the dataset.
84
141
  - `filters`: the filters applied to the dataset. Each item describes:
85
142
  - `field`: which field this filter is bound to.
86
143
  - `operator`: which type of filter it is. One of `in`, `notIn`. See "Operator types".
87
144
  - `value`: the actual value selected by the user.
145
+ - `perPage`: number of records to show per page.
146
+ - `page`: the page that is visible.
147
+ - `sort`:
148
+ - `field`: the field used for sorting the dataset.
149
+ - `direction`: the direction to use for sorting, one of `asc` or `desc`.
88
150
  - `hiddenFields`: the `id` of the fields that are hidden in the UI.
89
151
  - `layout`: config that is specific to a particular layout type.
90
152
  - `mediaField`: used by the `grid` and `list` layouts. The `id` of the field to be used for rendering each card's media.
91
- - `primaryField`: used by the `grid` and `list` layouts. The `id` of the field to be highlighted in each card/list item.
153
+ - `primaryField`: used by the `table`, `grid` and `list` layouts. The `id` of the field to be highlighted in each row/card/item.
92
154
 
93
- ### onChangeView: syncing view and data
155
+ ### `onChangeView`: `function`
94
156
 
95
157
  The view is a representation of the visible state of the dataset: what type of layout is used to display it (table, grid, etc.), how the dataset is filtered, how it is sorted or paginated.
96
158
 
@@ -147,65 +209,17 @@ function MyCustomPageTable() {
147
209
  data={ records }
148
210
  view={ view }
149
211
  onChangeView={ setView }
150
- "..."
212
+ // ...
151
213
  />
152
214
  );
153
215
  }
154
216
  ```
155
217
 
156
- ## Fields
157
-
158
- The fields describe the visible items for each record in the dataset.
159
-
160
- Example:
161
-
162
- ```js
163
- [
164
- {
165
- id: 'date',
166
- header: __( 'Date' ),
167
- getValue: ( { item } ) => item.date,
168
- render: ( { item } ) => {
169
- return (
170
- <time>{ getFormattedDate( item.date ) }</time>
171
- );
172
- },
173
- enableHiding: false
174
- },
175
- {
176
- id: 'author',
177
- header: __( 'Author' ),
178
- getValue: ( { item } ) => item.author,
179
- render: ( { item } ) => {
180
- return (
181
- <a href="...">{ item.author }</a>
182
- );
183
- },
184
- type: 'enumeration',
185
- elements: [
186
- { value: 1, label: 'Admin' }
187
- { value: 2, label: 'User' }
188
- ]
189
- enableSorting: false
190
- }
191
- ]
192
- ```
193
-
194
- - `id`: identifier for the field. Unique.
195
- - `header`: the field's name to be shown in the UI.
196
- - `getValue`: function that returns the value of the field.
197
- - `render`: function that renders the field.
198
- - `elements`: the set of valid values for the field's value.
199
- - `type`: the type of the field. Used to generate the proper filters. Only `enumeration` available at the moment. See "Field types".
200
- - `enableSorting`: whether the data can be sorted by the given field. True by default.
201
- - `enableHiding`: whether the field can be hidden. True by default.
202
- - `filterBy`: configuration for the filters.
203
- - `operators`: the list of operators supported by the field.
204
- - `isPrimary`: whether it is a primary filter. A primary filter is always visible and is not listed in the "Add filter" component, except for the list layout where it behaves like a secondary filter.
218
+ ### `actions`: `Object[]`
205
219
 
206
- ## Actions
220
+ Collection of operations that can be performed upon each record.
207
221
 
208
- Array of operations that can be performed upon each record. Each action is an object with the following properties:
222
+ Each action is an object with the following properties:
209
223
 
210
224
  - `id`: string, required. Unique identifier of the action. For example, `move-to-trash`.
211
225
  - `label`: string, required. User facing description of the action. For example, `Move to Trash`.
@@ -217,28 +231,59 @@ Array of operations that can be performed upon each record. Each action is an ob
217
231
  - `RenderModal`: ReactElement, optional. If an action requires that some UI be rendered in a modal, it can provide a component which takes as props the record as `item` and a `closeModal` function. When this prop is provided, the `callback` property is ignored.
218
232
  - `hideModalHeader`: boolean, optional. This property is used in combination with `RenderModal` and controls the visibility of the modal's header. If the action renders a modal and doesn't hide the header, the action's label is going to be used in the modal's header.
219
233
 
234
+ ### `paginationInfo`: `Object`
235
+
236
+ - `totalItems`: the total number of items in the datasets.
237
+ - `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
238
+
239
+ ### `search`: `boolean`
240
+
241
+ Whether the search input is enabled. `true` by default.
242
+
243
+ ### `searchLabel`: `string`
244
+
245
+ What text to show in the search input. "Search" by default.
246
+
247
+ ### `getItemId`: `function`
248
+
249
+ Function that receives an item and returns an unique identifier for it. By default, it uses the `id` of the item as unique identifier. If it's not, the consumer should provide their own.
250
+
251
+ ### `isLoading`: `boolean`
252
+
253
+ Whether the data is loading. `false` by default.
254
+
255
+ ### `supportedLayouts`: `String[]`
256
+
257
+ Array of layouts supported. By default, all are: `table`, `grid`, `list`.
258
+
259
+ ### `deferredRendering`: `boolean`
260
+
261
+ Whether the items should be rendered asynchronously. Useful when there's a field that takes a lot of time (e.g.: previews). `false` by default.
262
+
263
+ ### `onSelectionChange`: `function`
264
+
265
+ Callback that signals the user selected one of more items, and takes them as parameter. So far, only the `list` view implements it.
266
+
267
+ ### `onDetailsChange`: `function`
268
+
269
+ Callback that signals the user triggered the details for one of more items, and takes them as paremeter. So far, only the `list` view implements it.
270
+
220
271
  ## Types
221
272
 
222
- - Layout types:
223
- - `table`: the view uses a table layout.
224
- - `grid`: the view uses a grid layout.
225
- - `list`: the view uses a list layout.
226
- - Field types:
227
- - `enumeration`: the field value should be taken and can be filtered from a closed list of elements.
228
- - Operator types:
229
- - `in`: operator to be used in filters for fields of type `enumeration`.
230
- - `notIn`: operator to be used in filters for fields of type `enumeration`.
231
-
232
- ## Other properties
233
-
234
- - `search`: whether the search input is enabled. `true` by default.
235
- - `searchLabel`: what text to show in the search input. "Filter list" by default.
236
- - `getItemId`: function that receives an item and returns an unique identifier for it. By default, it uses the `id` of the item as unique identifier. If it's not, the consumer should provide their own.
237
- - `isLoading`: whether the data is loading. `false` by default.
238
- - `supportedLayouts`: array of layouts supported. By default, all are: `table`, `grid`, `list`.
239
- - `deferredRendering`: whether the items should be rendered asynchronously. Useful when there's a field that takes a lot of time (e.g.: previews). `false` by default.
240
- - `onSelectionChange`: callback that signals the user selected one of more items, and takes them as parameter. So far, only the `list` view implements it.
241
- - `onDetailsChange`: callback that signals the user triggered the details for one of more items, and takes them as paremeter. So far, only the `list` view implements it.
273
+ ### Layouts
274
+
275
+ - `table`: the view uses a table layout.
276
+ - `grid`: the view uses a grid layout.
277
+ - `list`: the view uses a list layout.
278
+
279
+ ### Fields
280
+
281
+ - `enumeration`: the field value should be taken and can be filtered from a closed list of elements.
282
+
283
+ ### Operators
284
+
285
+ - `in`: operator to be used in filters for fields of type `enumeration`.
286
+ - `notIn`: operator to be used in filters for fields of type `enumeration`.
242
287
 
243
288
  ## Contributing to this package
244
289
 
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
8
  var _components = require("@wordpress/components");
9
- var _icons = require("@wordpress/icons");
10
9
  var _i18n = require("@wordpress/i18n");
11
10
  var _element = require("@wordpress/element");
12
11
  var _lockUnlock = require("./lock-unlock");
@@ -39,7 +38,6 @@ function AddFilter({
39
38
  trigger: (0, _react.createElement)(_components.Button, {
40
39
  __experimentalIsFocusable: true,
41
40
  size: "compact",
42
- icon: _icons.plus,
43
41
  className: "dataviews-filters-button",
44
42
  variant: "tertiary",
45
43
  disabled: !inactiveFilters.length,
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_icons","_i18n","_element","_lockUnlock","DropdownMenuV2","DropdownMenu","DropdownMenuItemV2","DropdownMenuItem","DropdownMenuItemLabelV2","DropdownMenuItemLabel","unlock","componentsPrivateApis","AddFilter","filters","view","onChangeView","setOpenedFilter","ref","length","every","isPrimary","inactiveFilters","filter","isVisible","_react","createElement","trigger","Button","__experimentalIsFocusable","size","icon","plus","className","variant","disabled","__","map","key","field","onClick","page","value","undefined","operator","operators","name","_default","exports","default","forwardRef"],"sources":["@wordpress/dataviews/src/add-filter.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as componentsPrivateApis,\n\tButton,\n} from '@wordpress/components';\nimport { plus } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst {\n\tDropdownMenuV2: DropdownMenu,\n\tDropdownMenuItemV2: DropdownMenuItem,\n\tDropdownMenuItemLabelV2: DropdownMenuItemLabel,\n} = unlock( componentsPrivateApis );\n\nfunction AddFilter( { filters, view, onChangeView, setOpenedFilter }, ref ) {\n\tif ( ! filters.length || filters.every( ( { isPrimary } ) => isPrimary ) ) {\n\t\treturn null;\n\t}\n\tconst inactiveFilters = filters.filter( ( filter ) => ! filter.isVisible );\n\treturn (\n\t\t<DropdownMenu\n\t\t\ttrigger={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\ticon={ plus }\n\t\t\t\t\tclassName=\"dataviews-filters-button\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! inactiveFilters.length }\n\t\t\t\t\tref={ ref }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t</Button>\n\t\t\t}\n\t\t>\n\t\t\t{ inactiveFilters.map( ( filter ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenuItem\n\t\t\t\t\t\tkey={ filter.field }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetOpenedFilter( filter.field );\n\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\toperator: filter.operators[ 0 ],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DropdownMenuItemLabel>\n\t\t\t\t\t\t\t{ filter.name }\n\t\t\t\t\t\t</DropdownMenuItemLabel>\n\t\t\t\t\t</DropdownMenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</DropdownMenu>\n\t);\n}\n\nexport default forwardRef( AddFilter );\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,WAAA,GAAAJ,OAAA;AAdA;AACA;AACA;;AASA;AACA;AACA;;AAGA,MAAM;EACLK,cAAc,EAAEC,YAAY;EAC5BC,kBAAkB,EAAEC,gBAAgB;EACpCC,uBAAuB,EAAEC;AAC1B,CAAC,GAAG,IAAAC,kBAAM,EAAEC,uBAAsB,CAAC;AAEnC,SAASC,SAASA,CAAE;EAAEC,OAAO;EAAEC,IAAI;EAAEC,YAAY;EAAEC;AAAgB,CAAC,EAAEC,GAAG,EAAG;EAC3E,IAAK,CAAEJ,OAAO,CAACK,MAAM,IAAIL,OAAO,CAACM,KAAK,CAAE,CAAE;IAAEC;EAAU,CAAC,KAAMA,SAAU,CAAC,EAAG;IAC1E,OAAO,IAAI;EACZ;EACA,MAAMC,eAAe,GAAGR,OAAO,CAACS,MAAM,CAAIA,MAAM,IAAM,CAAEA,MAAM,CAACC,SAAU,CAAC;EAC1E,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACpB,YAAY;IACZqB,OAAO,EACN,IAAAF,MAAA,CAAAC,aAAA,EAAC3B,WAAA,CAAA6B,MAAM;MACNC,yBAAyB;MACzBC,IAAI,EAAC,SAAS;MACdC,IAAI,EAAGC,WAAM;MACbC,SAAS,EAAC,0BAA0B;MACpCC,OAAO,EAAC,UAAU;MAClBC,QAAQ,EAAG,CAAEb,eAAe,CAACH,MAAQ;MACrCD,GAAG,EAAGA;IAAK,GAET,IAAAkB,QAAE,EAAE,YAAa,CACZ;EACR,GAECd,eAAe,CAACe,GAAG,CAAId,MAAM,IAAM;IACpC,OACC,IAAAE,MAAA,CAAAC,aAAA,EAAClB,gBAAgB;MAChB8B,GAAG,EAAGf,MAAM,CAACgB,KAAO;MACpBC,OAAO,EAAGA,CAAA,KAAM;QACfvB,eAAe,CAAEM,MAAM,CAACgB,KAAM,CAAC;QAC/BvB,YAAY,CAAE;UACb,GAAGD,IAAI;UACP0B,IAAI,EAAE,CAAC;UACP3B,OAAO,EAAE,CACR,IAAKC,IAAI,CAACD,OAAO,IAAI,EAAE,CAAE,EACzB;YACCyB,KAAK,EAAEhB,MAAM,CAACgB,KAAK;YACnBG,KAAK,EAAEC,SAAS;YAChBC,QAAQ,EAAErB,MAAM,CAACsB,SAAS,CAAE,CAAC;UAC9B,CAAC;QAEH,CAAE,CAAC;MACJ;IAAG,GAEH,IAAApB,MAAA,CAAAC,aAAA,EAAChB,qBAAqB,QACnBa,MAAM,CAACuB,IACa,CACN,CAAC;EAErB,CAAE,CACW,CAAC;AAEjB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAAC,mBAAU,EAAErC,SAAU,CAAC"}
1
+ {"version":3,"names":["_components","require","_i18n","_element","_lockUnlock","DropdownMenuV2","DropdownMenu","DropdownMenuItemV2","DropdownMenuItem","DropdownMenuItemLabelV2","DropdownMenuItemLabel","unlock","componentsPrivateApis","AddFilter","filters","view","onChangeView","setOpenedFilter","ref","length","every","isPrimary","inactiveFilters","filter","isVisible","_react","createElement","trigger","Button","__experimentalIsFocusable","size","className","variant","disabled","__","map","key","field","onClick","page","value","undefined","operator","operators","name","_default","exports","default","forwardRef"],"sources":["@wordpress/dataviews/src/add-filter.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as componentsPrivateApis,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst {\n\tDropdownMenuV2: DropdownMenu,\n\tDropdownMenuItemV2: DropdownMenuItem,\n\tDropdownMenuItemLabelV2: DropdownMenuItemLabel,\n} = unlock( componentsPrivateApis );\n\nfunction AddFilter( { filters, view, onChangeView, setOpenedFilter }, ref ) {\n\tif ( ! filters.length || filters.every( ( { isPrimary } ) => isPrimary ) ) {\n\t\treturn null;\n\t}\n\tconst inactiveFilters = filters.filter( ( filter ) => ! filter.isVisible );\n\treturn (\n\t\t<DropdownMenu\n\t\t\ttrigger={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"dataviews-filters-button\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! inactiveFilters.length }\n\t\t\t\t\tref={ ref }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t</Button>\n\t\t\t}\n\t\t>\n\t\t\t{ inactiveFilters.map( ( filter ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenuItem\n\t\t\t\t\t\tkey={ filter.field }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetOpenedFilter( filter.field );\n\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\toperator: filter.operators[ 0 ],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DropdownMenuItemLabel>\n\t\t\t\t\t\t\t{ filter.name }\n\t\t\t\t\t\t</DropdownMenuItemLabel>\n\t\t\t\t\t</DropdownMenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</DropdownMenu>\n\t);\n}\n\nexport default forwardRef( AddFilter );\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AAbA;AACA;AACA;;AAQA;AACA;AACA;;AAGA,MAAM;EACLI,cAAc,EAAEC,YAAY;EAC5BC,kBAAkB,EAAEC,gBAAgB;EACpCC,uBAAuB,EAAEC;AAC1B,CAAC,GAAG,IAAAC,kBAAM,EAAEC,uBAAsB,CAAC;AAEnC,SAASC,SAASA,CAAE;EAAEC,OAAO;EAAEC,IAAI;EAAEC,YAAY;EAAEC;AAAgB,CAAC,EAAEC,GAAG,EAAG;EAC3E,IAAK,CAAEJ,OAAO,CAACK,MAAM,IAAIL,OAAO,CAACM,KAAK,CAAE,CAAE;IAAEC;EAAU,CAAC,KAAMA,SAAU,CAAC,EAAG;IAC1E,OAAO,IAAI;EACZ;EACA,MAAMC,eAAe,GAAGR,OAAO,CAACS,MAAM,CAAIA,MAAM,IAAM,CAAEA,MAAM,CAACC,SAAU,CAAC;EAC1E,OACC,IAAAC,MAAA,CAAAC,aAAA,EAACpB,YAAY;IACZqB,OAAO,EACN,IAAAF,MAAA,CAAAC,aAAA,EAAC1B,WAAA,CAAA4B,MAAM;MACNC,yBAAyB;MACzBC,IAAI,EAAC,SAAS;MACdC,SAAS,EAAC,0BAA0B;MACpCC,OAAO,EAAC,UAAU;MAClBC,QAAQ,EAAG,CAAEX,eAAe,CAACH,MAAQ;MACrCD,GAAG,EAAGA;IAAK,GAET,IAAAgB,QAAE,EAAE,YAAa,CACZ;EACR,GAECZ,eAAe,CAACa,GAAG,CAAIZ,MAAM,IAAM;IACpC,OACC,IAAAE,MAAA,CAAAC,aAAA,EAAClB,gBAAgB;MAChB4B,GAAG,EAAGb,MAAM,CAACc,KAAO;MACpBC,OAAO,EAAGA,CAAA,KAAM;QACfrB,eAAe,CAAEM,MAAM,CAACc,KAAM,CAAC;QAC/BrB,YAAY,CAAE;UACb,GAAGD,IAAI;UACPwB,IAAI,EAAE,CAAC;UACPzB,OAAO,EAAE,CACR,IAAKC,IAAI,CAACD,OAAO,IAAI,EAAE,CAAE,EACzB;YACCuB,KAAK,EAAEd,MAAM,CAACc,KAAK;YACnBG,KAAK,EAAEC,SAAS;YAChBC,QAAQ,EAAEnB,MAAM,CAACoB,SAAS,CAAE,CAAC;UAC9B,CAAC;QAEH,CAAE,CAAC;MACJ;IAAG,GAEH,IAAAlB,MAAA,CAAAC,aAAA,EAAChB,qBAAqB,QACnBa,MAAM,CAACqB,IACa,CACN,CAAC;EAErB,CAAE,CACW,CAAC;AAEjB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAAC,mBAAU,EAAEnC,SAAU,CAAC"}
@@ -72,9 +72,6 @@ function DataViews({
72
72
  const hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(actions, data);
73
73
  return (0, _react.createElement)("div", {
74
74
  className: "dataviews-wrapper"
75
- }, (0, _react.createElement)(_components.__experimentalVStack, {
76
- spacing: 3,
77
- justify: "flex-start"
78
75
  }, (0, _react.createElement)(_components.__experimentalHStack, {
79
76
  alignment: "top",
80
77
  justify: "start",
@@ -121,6 +118,6 @@ function DataViews({
121
118
  view: view,
122
119
  onChangeView: onChangeView,
123
120
  paginationInfo: paginationInfo
124
- })));
121
+ }));
125
122
  }
126
123
  //# sourceMappingURL=dataviews.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_element","_pagination","_interopRequireDefault","_viewActions","_filters","_search","_constants","_bulkActions","defaultGetItemId","item","id","defaultOnSelectionChange","useSomeItemHasAPossibleBulkAction","actions","data","useMemo","some","action","supportsBulk","isEligible","DataViews","view","onChangeView","fields","search","searchLabel","undefined","getItemId","isLoading","paginationInfo","supportedLayouts","onSelectionChange","onDetailsChange","deferredRendering","selection","setSelection","useState","openedFilter","setOpenedFilter","useEffect","length","newSelection","filter","includes","onSetSelection","useCallback","items","map","ViewComponent","VIEW_LAYOUTS","find","v","type","component","_fields","field","render","getValue","hasPossibleBulkAction","_react","createElement","className","__experimentalVStack","spacing","justify","__experimentalHStack","alignment","wrap","default","label","LAYOUT_TABLE","LAYOUT_GRID"],"sources":["@wordpress/dataviews/src/dataviews.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { useMemo, useState, useCallback, useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Pagination from './pagination';\nimport ViewActions from './view-actions';\nimport Filters from './filters';\nimport Search from './search';\nimport { VIEW_LAYOUTS, LAYOUT_TABLE, LAYOUT_GRID } from './constants';\nimport BulkActions from './bulk-actions';\n\nconst defaultGetItemId = ( item ) => item.id;\nconst defaultOnSelectionChange = () => {};\n\nfunction useSomeItemHasAPossibleBulkAction( actions, data ) {\n\treturn useMemo( () => {\n\t\treturn data.some( ( item ) => {\n\t\t\treturn actions.some( ( action ) => {\n\t\t\t\treturn action.supportsBulk && action.isEligible( item );\n\t\t\t} );\n\t\t} );\n\t}, [ actions, data ] );\n}\n\nexport default function DataViews( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions,\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tisLoading = false,\n\tpaginationInfo,\n\tsupportedLayouts,\n\tonSelectionChange = defaultOnSelectionChange,\n\tonDetailsChange = null,\n\tdeferredRendering = false,\n} ) {\n\tconst [ selection, setSelection ] = useState( [] );\n\tconst [ openedFilter, setOpenedFilter ] = useState( null );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tselection.length > 0 &&\n\t\t\tselection.some(\n\t\t\t\t( id ) => ! data.some( ( item ) => getItemId( item ) === id )\n\t\t\t)\n\t\t) {\n\t\t\tconst newSelection = selection.filter( ( id ) =>\n\t\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t\t);\n\t\t\tsetSelection( newSelection );\n\t\t\tonSelectionChange(\n\t\t\t\tdata.filter( ( item ) =>\n\t\t\t\t\tnewSelection.includes( getItemId( item ) )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selection, data, getItemId, onSelectionChange ] );\n\n\tconst onSetSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items.map( ( item ) => getItemId( item ) ) );\n\t\t\tonSelectionChange( items );\n\t\t},\n\t\t[ setSelection, getItemId, onSelectionChange ]\n\t);\n\n\tconst ViewComponent = VIEW_LAYOUTS.find(\n\t\t( v ) => v.type === view.type\n\t).component;\n\tconst _fields = useMemo( () => {\n\t\treturn fields.map( ( field ) => ( {\n\t\t\t...field,\n\t\t\trender: field.render || field.getValue,\n\t\t} ) );\n\t}, [ fields ] );\n\n\tconst hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(\n\t\tactions,\n\t\tdata\n\t);\n\treturn (\n\t\t<div className=\"dataviews-wrapper\">\n\t\t\t<VStack spacing={ 3 } justify=\"flex-start\">\n\t\t\t\t<HStack\n\t\t\t\t\talignment=\"top\"\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\tclassName=\"dataviews-filters__view-actions\"\n\t\t\t\t>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\t\tclassName=\"dataviews-filters__container\"\n\t\t\t\t\t\twrap\n\t\t\t\t\t>\n\t\t\t\t\t\t{ search && (\n\t\t\t\t\t\t\t<Search\n\t\t\t\t\t\t\t\tlabel={ searchLabel }\n\t\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<Filters\n\t\t\t\t\t\t\tfields={ _fields }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t\topenedFilter={ openedFilter }\n\t\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t{ [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) &&\n\t\t\t\t\t\thasPossibleBulkAction && (\n\t\t\t\t\t\t\t<BulkActions\n\t\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) }\n\t\t\t\t\t<ViewActions\n\t\t\t\t\t\tfields={ _fields }\n\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\tsupportedLayouts={ supportedLayouts }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t<ViewComponent\n\t\t\t\t\tfields={ _fields }\n\t\t\t\t\tview={ view }\n\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\tactions={ actions }\n\t\t\t\t\tdata={ data }\n\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\tisLoading={ isLoading }\n\t\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\t\tonDetailsChange={ onDetailsChange }\n\t\t\t\t\tselection={ selection }\n\t\t\t\t\tdeferredRendering={ deferredRendering }\n\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t/>\n\t\t\t\t<Pagination\n\t\t\t\t\tview={ view }\n\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\t/>\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,OAAA,GAAAH,sBAAA,CAAAH,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAL,sBAAA,CAAAH,OAAA;AAjBA;AACA;AACA;;AAOA;AACA;AACA;;AAQA,MAAMS,gBAAgB,GAAKC,IAAI,IAAMA,IAAI,CAACC,EAAE;AAC5C,MAAMC,wBAAwB,GAAGA,CAAA,KAAM,CAAC,CAAC;AAEzC,SAASC,iCAAiCA,CAAEC,OAAO,EAAEC,IAAI,EAAG;EAC3D,OAAO,IAAAC,gBAAO,EAAE,MAAM;IACrB,OAAOD,IAAI,CAACE,IAAI,CAAIP,IAAI,IAAM;MAC7B,OAAOI,OAAO,CAACG,IAAI,CAAIC,MAAM,IAAM;QAClC,OAAOA,MAAM,CAACC,YAAY,IAAID,MAAM,CAACE,UAAU,CAAEV,IAAK,CAAC;MACxD,CAAE,CAAC;IACJ,CAAE,CAAC;EACJ,CAAC,EAAE,CAAEI,OAAO,EAAEC,IAAI,CAAG,CAAC;AACvB;AAEe,SAASM,SAASA,CAAE;EAClCC,IAAI;EACJC,YA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+ {"version":3,"names":["_components","require","_element","_pagination","_interopRequireDefault","_viewActions","_filters","_search","_constants","_bulkActions","defaultGetItemId","item","id","defaultOnSelectionChange","useSomeItemHasAPossibleBulkAction","actions","data","useMemo","some","action","supportsBulk","isEligible","DataViews","view","onChangeView","fields","search","searchLabel","undefined","getItemId","isLoading","paginationInfo","supportedLayouts","onSelectionChange","onDetailsChange","deferredRendering","selection","setSelection","useState","openedFilter","setOpenedFilter","useEffect","length","newSelection","filter","includes","onSetSelection","useCallback","items","map","ViewComponent","VIEW_LAYOUTS","find","v","type","component","_fields","field","render","getValue","hasPossibleBulkAction","_react","createElement","className","__experimentalHStack","alignment","justify","wrap","default","label","LAYOUT_TABLE","LAYOUT_GRID"],"sources":["@wordpress/dataviews/src/dataviews.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { useMemo, useState, useCallback, useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Pagination from './pagination';\nimport ViewActions from './view-actions';\nimport Filters from './filters';\nimport Search from './search';\nimport { VIEW_LAYOUTS, LAYOUT_TABLE, LAYOUT_GRID } from './constants';\nimport BulkActions from './bulk-actions';\n\nconst defaultGetItemId = ( item ) => item.id;\nconst defaultOnSelectionChange = () => {};\n\nfunction useSomeItemHasAPossibleBulkAction( actions, data ) {\n\treturn useMemo( () => {\n\t\treturn data.some( ( item ) => {\n\t\t\treturn actions.some( ( action ) => {\n\t\t\t\treturn action.supportsBulk && action.isEligible( item );\n\t\t\t} );\n\t\t} );\n\t}, [ actions, data ] );\n}\n\nexport default function DataViews( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions,\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tisLoading = false,\n\tpaginationInfo,\n\tsupportedLayouts,\n\tonSelectionChange = defaultOnSelectionChange,\n\tonDetailsChange = null,\n\tdeferredRendering = false,\n} ) {\n\tconst [ selection, setSelection ] = useState( [] );\n\tconst [ openedFilter, setOpenedFilter ] = useState( null );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tselection.length > 0 &&\n\t\t\tselection.some(\n\t\t\t\t( id ) => ! data.some( ( item ) => getItemId( item ) === id )\n\t\t\t)\n\t\t) {\n\t\t\tconst newSelection = selection.filter( ( id ) =>\n\t\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t\t);\n\t\t\tsetSelection( newSelection );\n\t\t\tonSelectionChange(\n\t\t\t\tdata.filter( ( item ) =>\n\t\t\t\t\tnewSelection.includes( getItemId( item ) )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selection, data, getItemId, onSelectionChange ] );\n\n\tconst onSetSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items.map( ( item ) => getItemId( item ) ) );\n\t\t\tonSelectionChange( items );\n\t\t},\n\t\t[ setSelection, getItemId, onSelectionChange ]\n\t);\n\n\tconst ViewComponent = VIEW_LAYOUTS.find(\n\t\t( v ) => v.type === view.type\n\t).component;\n\tconst _fields = useMemo( () => {\n\t\treturn fields.map( ( field ) => ( {\n\t\t\t...field,\n\t\t\trender: field.render || field.getValue,\n\t\t} ) );\n\t}, [ fields ] );\n\n\tconst hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(\n\t\tactions,\n\t\tdata\n\t);\n\treturn (\n\t\t<div className=\"dataviews-wrapper\">\n\t\t\t<HStack\n\t\t\t\talignment=\"top\"\n\t\t\t\tjustify=\"start\"\n\t\t\t\tclassName=\"dataviews-filters__view-actions\"\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\tclassName=\"dataviews-filters__container\"\n\t\t\t\t\twrap\n\t\t\t\t>\n\t\t\t\t\t{ search && (\n\t\t\t\t\t\t<Search\n\t\t\t\t\t\t\tlabel={ searchLabel }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<Filters\n\t\t\t\t\t\tfields={ _fields }\n\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\topenedFilter={ openedFilter }\n\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t{ [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) &&\n\t\t\t\t\thasPossibleBulkAction && (\n\t\t\t\t\t\t<BulkActions\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t<ViewActions\n\t\t\t\t\tfields={ _fields }\n\t\t\t\t\tview={ view }\n\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\tsupportedLayouts={ supportedLayouts }\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t\t<ViewComponent\n\t\t\t\tfields={ _fields }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\tonDetailsChange={ onDetailsChange }\n\t\t\t\tselection={ selection }\n\t\t\t\tdeferredRendering={ deferredRendering }\n\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t/>\n\t\t\t<Pagination\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAA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,aAAA,EAACzD,YAAA,CAAA+D,OAAW;IACX3C,MAAM,EAAG+B,OAAS;IAClBjC,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BQ,gBAAgB,EAAGA;EAAkB,CACrC,CACM,CAAC,EACT,IAAA6B,MAAA,CAAAC,aAAA,EAACZ,aAAa;IACbzB,MAAM,EAAG+B,OAAS;IAClBjC,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BT,OAAO,EAAGA,OAAS;IACnBC,IAAI,EAAGA,IAAM;IACba,SAAS,EAAGA,SAAW;IACvBC,SAAS,EAAGA,SAAW;IACvBG,iBAAiB,EAAGa,cAAgB;IACpCZ,eAAe,EAAGA,eAAiB;IACnCE,SAAS,EAAGA,SAAW;IACvBD,iBAAiB,EAAGA,iBAAmB;IACvCK,eAAe,EAAGA;EAAiB,CACnC,CAAC,EACF,IAAAqB,MAAA,CAAAC,aAAA,EAAC3D,WAAA,CAAAiE,OAAU;IACV7C,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BO,cAAc,EAAGA;EAAgB,CACjC,CACG,CAAC;AAER"}
@@ -23,6 +23,7 @@ function ResetFilter({
23
23
  __experimentalIsFocusable: true,
24
24
  size: "compact",
25
25
  variant: "tertiary",
26
+ className: "dataviews-filters__reset-button",
26
27
  onClick: () => {
27
28
  onChangeView({
28
29
  ...view,
@@ -31,6 +32,6 @@ function ResetFilter({
31
32
  filters: []
32
33
  });
33
34
  }
34
- }, (0, _i18n.__)('Reset filters'));
35
+ }, (0, _i18n.__)('Reset'));
35
36
  }
36
37
  //# sourceMappingURL=reset-filters.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_i18n","ResetFilter","filters","view","onChangeView","isPrimary","field","some","_filter","isDisabled","search","value","undefined","_react","createElement","Button","disabled","__experimentalIsFocusable","size","variant","onClick","page","__"],"sources":["@wordpress/dataviews/src/reset-filters.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport default function ResetFilter( { filters, view, onChangeView } ) {\n\tconst isPrimary = ( field ) =>\n\t\tfilters.some(\n\t\t\t( _filter ) => _filter.field === field && _filter.isPrimary\n\t\t);\n\tconst isDisabled =\n\t\t! view.search &&\n\t\t! view.filters?.some(\n\t\t\t( _filter ) =>\n\t\t\t\t_filter.value !== undefined || ! isPrimary( _filter.field )\n\t\t);\n\treturn (\n\t\t<Button\n\t\t\tdisabled={ isDisabled }\n\t\t\t__experimentalIsFocusable\n\t\t\tsize=\"compact\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tonClick={ () => {\n\t\t\t\tonChangeView( {\n\t\t\t\t\t...view,\n\t\t\t\t\tpage: 1,\n\t\t\t\t\tsearch: '',\n\t\t\t\t\tfilters: [],\n\t\t\t\t} );\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Reset filters' ) }\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIe,SAASE,WAAWA,CAAE;EAAEC,OAAO;EAAEC,IAAI;EAAEC;AAAa,CAAC,EAAG;EACtE,MAAMC,SAAS,GAAKC,KAAK,IACxBJ,OAAO,CAACK,IAAI,CACTC,OAAO,IAAMA,OAAO,CAACF,KAAK,KAAKA,KAAK,IAAIE,OAAO,CAACH,SACnD,CAAC;EACF,MAAMI,UAAU,GACf,CAAEN,IAAI,CAACO,MAAM,IACb,CAAEP,IAAI,CAACD,OAAO,EAAEK,IAAI,CACjBC,OAAO,IACRA,OAAO,CAACG,KAAK,KAAKC,SAAS,IAAI,CAAEP,SAAS,CAAEG,OAAO,CAACF,KAAM,CAC5D,CAAC;EACF,OACC,IAAAO,MAAA,CAAAC,aAAA,EAAChB,WAAA,CAAAiB,MAAM;IACNC,QAAQ,EAAGP,UAAY;IACvBQ,yBAAyB;IACzBC,IAAI,EAAC,SAAS;IACdC,OAAO,EAAC,UAAU;IAClBC,OAAO,EAAGA,CAAA,KAAM;MACfhB,YAAY,CAAE;QACb,GAAGD,IAAI;QACPkB,IAAI,EAAE,CAAC;QACPX,MAAM,EAAE,EAAE;QACVR,OAAO,EAAE;MACV,CAAE,CAAC;IACJ;EAAG,GAED,IAAAoB,QAAE,EAAE,eAAgB,CACf,CAAC;AAEX"}
1
+ {"version":3,"names":["_components","require","_i18n","ResetFilter","filters","view","onChangeView","isPrimary","field","some","_filter","isDisabled","search","value","undefined","_react","createElement","Button","disabled","__experimentalIsFocusable","size","variant","className","onClick","page","__"],"sources":["@wordpress/dataviews/src/reset-filters.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Button } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\nexport default function ResetFilter( { filters, view, onChangeView } ) {\n\tconst isPrimary = ( field ) =>\n\t\tfilters.some(\n\t\t\t( _filter ) => _filter.field === field && _filter.isPrimary\n\t\t);\n\tconst isDisabled =\n\t\t! view.search &&\n\t\t! view.filters?.some(\n\t\t\t( _filter ) =>\n\t\t\t\t_filter.value !== undefined || ! isPrimary( _filter.field )\n\t\t);\n\treturn (\n\t\t<Button\n\t\t\tdisabled={ isDisabled }\n\t\t\t__experimentalIsFocusable\n\t\t\tsize=\"compact\"\n\t\t\tvariant=\"tertiary\"\n\t\t\tclassName=\"dataviews-filters__reset-button\"\n\t\t\tonClick={ () => {\n\t\t\t\tonChangeView( {\n\t\t\t\t\t...view,\n\t\t\t\t\tpage: 1,\n\t\t\t\t\tsearch: '',\n\t\t\t\t\tfilters: [],\n\t\t\t\t} );\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Reset' ) }\n\t\t</Button>\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAIe,SAASE,WAAWA,CAAE;EAAEC,OAAO;EAAEC,IAAI;EAAEC;AAAa,CAAC,EAAG;EACtE,MAAMC,SAAS,GAAKC,KAAK,IACxBJ,OAAO,CAACK,IAAI,CACTC,OAAO,IAAMA,OAAO,CAACF,KAAK,KAAKA,KAAK,IAAIE,OAAO,CAACH,SACnD,CAAC;EACF,MAAMI,UAAU,GACf,CAAEN,IAAI,CAACO,MAAM,IACb,CAAEP,IAAI,CAACD,OAAO,EAAEK,IAAI,CACjBC,OAAO,IACRA,OAAO,CAACG,KAAK,KAAKC,SAAS,IAAI,CAAEP,SAAS,CAAEG,OAAO,CAACF,KAAM,CAC5D,CAAC;EACF,OACC,IAAAO,MAAA,CAAAC,aAAA,EAAChB,WAAA,CAAAiB,MAAM;IACNC,QAAQ,EAAGP,UAAY;IACvBQ,yBAAyB;IACzBC,IAAI,EAAC,SAAS;IACdC,OAAO,EAAC,UAAU;IAClBC,SAAS,EAAC,iCAAiC;IAC3CC,OAAO,EAAGA,CAAA,KAAM;MACfjB,YAAY,CAAE;QACb,GAAGD,IAAI;QACPmB,IAAI,EAAE,CAAC;QACPZ,MAAM,EAAE,EAAE;QACVR,OAAO,EAAE;MACV,CAAE,CAAC;IACJ;EAAG,GAED,IAAAqB,QAAE,EAAE,OAAQ,CACP,CAAC;AAEX"}
@@ -13,6 +13,7 @@ var _element = require("@wordpress/element");
13
13
  var _components = require("@wordpress/components");
14
14
  var _icons = require("@wordpress/icons");
15
15
  var _primitives = require("@wordpress/primitives");
16
+ var _lockUnlock = require("./lock-unlock");
16
17
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
18
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
19
  /**
@@ -24,6 +25,15 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
24
25
  * WordPress dependencies
25
26
  */
26
27
 
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+
32
+ const {
33
+ CompositeV2: Composite,
34
+ CompositeItemV2: CompositeItem,
35
+ useCompositeStoreV2: useCompositeStore
36
+ } = (0, _lockUnlock.unlock)(_components.privateApis);
27
37
  const radioCheck = (0, _react.createElement)(_primitives.SVG, {
28
38
  xmlns: "http://www.w3.org/2000/svg",
29
39
  viewBox: "0 0 24 24"
@@ -35,9 +45,78 @@ const radioCheck = (0, _react.createElement)(_primitives.SVG, {
35
45
  function normalizeSearchInput(input = '') {
36
46
  return (0, _removeAccents.default)(input.trim().toLowerCase());
37
47
  }
38
- function SearchWidget({
48
+ function ListBox({
49
+ view,
39
50
  filter,
51
+ onChangeView
52
+ }) {
53
+ const compositeStore = useCompositeStore({
54
+ virtualFocus: true,
55
+ focusLoop: true,
56
+ // When we have no or just one operators, we can set the first item as active.
57
+ // We do that by passing `undefined` to `defaultActiveId`. Otherwise, we set it to `null`,
58
+ // so the first item is not selected, since the focus is on the operators control.
59
+ defaultActiveId: filter.operators?.length === 1 ? undefined : null
60
+ });
61
+ const selectedFilter = view.filters.find(_filter => _filter.field === filter.field);
62
+ const selectedValues = selectedFilter?.value;
63
+ return (0, _react.createElement)(Composite, {
64
+ store: compositeStore,
65
+ role: "listbox",
66
+ className: "dataviews-search-widget-listbox",
67
+ "aria-label": (0, _i18n.sprintf)( /* translators: List of items for a filter. 1: Filter name. e.g.: "List of: Author". */
68
+ (0, _i18n.__)('List of: %1$s'), filter.name),
69
+ onFocusVisible: () => {
70
+ if (!compositeStore.getState().activeId) {
71
+ compositeStore.move(compositeStore.first());
72
+ }
73
+ },
74
+ render: (0, _react.createElement)(Ariakit.CompositeTypeahead, {
75
+ store: compositeStore
76
+ })
77
+ }, filter.elements.map(element => (0, _react.createElement)(Ariakit.CompositeHover, {
78
+ store: compositeStore,
79
+ key: element.value,
80
+ render: (0, _react.createElement)(CompositeItem, {
81
+ render: (0, _react.createElement)("div", {
82
+ "aria-label": element.label,
83
+ role: "option",
84
+ className: "dataviews-search-widget-listitem"
85
+ }),
86
+ onClick: () => {
87
+ const currentFilter = view.filters.find(_filter => _filter.field === filter.field);
88
+ const newFilters = currentFilter ? [...view.filters.map(_filter => {
89
+ if (_filter.field === filter.field) {
90
+ return {
91
+ ..._filter,
92
+ operator: currentFilter.operator || filter.operators[0],
93
+ value: element.value
94
+ };
95
+ }
96
+ return _filter;
97
+ })] : [...view.filters, {
98
+ field: filter.field,
99
+ operator: filter.operators[0],
100
+ value: element.value
101
+ }];
102
+ onChangeView({
103
+ ...view,
104
+ page: 1,
105
+ filters: newFilters
106
+ });
107
+ }
108
+ })
109
+ }, (0, _react.createElement)("span", {
110
+ className: "dataviews-search-widget-listitem-check"
111
+ }, selectedValues === element.value && (0, _react.createElement)(_components.Icon, {
112
+ icon: radioCheck
113
+ })), (0, _react.createElement)("span", null, element.label, !!element.description && (0, _react.createElement)("span", {
114
+ className: "dataviews-search-widget-listitem-description"
115
+ }, element.description)))));
116
+ }
117
+ function ComboboxList({
40
118
  view,
119
+ filter,
41
120
  onChangeView
42
121
  }) {
43
122
  const [searchValue, setSearchValue] = (0, _element.useState)('');
@@ -92,20 +171,26 @@ function SearchWidget({
92
171
  return (0, _react.createElement)(Ariakit.ComboboxItem, {
93
172
  key: element.value,
94
173
  value: element.value,
95
- className: "dataviews-search-widget-filter-combobox-item",
174
+ className: "dataviews-search-widget-listitem",
96
175
  hideOnClick: false,
97
176
  setValueOnClick: false,
98
177
  focusOnHover: true
99
178
  }, (0, _react.createElement)("span", {
100
- className: "dataviews-search-widget-filter-combobox-item-check"
179
+ className: "dataviews-search-widget-listitem-check"
101
180
  }, selectedValues === element.value && (0, _react.createElement)(_components.Icon, {
102
181
  icon: radioCheck
103
182
  })), (0, _react.createElement)("span", null, (0, _react.createElement)(Ariakit.ComboboxItemValue, {
104
183
  className: "dataviews-search-widget-filter-combobox-item-value",
105
184
  value: element.label
106
185
  }), !!element.description && (0, _react.createElement)("span", {
107
- className: "dataviews-search-widget-filter-combobox-item-description"
186
+ className: "dataviews-search-widget-listitem-description"
108
187
  }, element.description)));
109
188
  }), !matches.length && (0, _react.createElement)("p", null, (0, _i18n.__)('No results found'))));
110
189
  }
190
+ function SearchWidget(props) {
191
+ const Widget = props.filter.elements.length > 10 ? ComboboxList : ListBox;
192
+ return (0, _react.createElement)(Widget, {
193
+ ...props
194
+ });
195
+ }
111
196
  //# sourceMappingURL=search-widget.js.map