@wordpress/dataviews 4.1.0 → 4.3.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.
- package/CHANGELOG.md +19 -0
- package/README.md +77 -29
- package/build/components/dataviews/index.js +10 -14
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-bulk-actions/index.js +145 -141
- package/build/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build/components/dataviews-filters/add-filter.js +4 -6
- package/build/components/dataviews-filters/add-filter.js.map +1 -1
- package/build/components/dataviews-filters/index.js +3 -0
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/search-widget.js +30 -23
- package/build/components/dataviews-filters/search-widget.js.map +1 -1
- package/build/components/dataviews-footer/index.js +45 -0
- package/build/components/dataviews-footer/index.js.map +1 -0
- package/build/components/dataviews-item-actions/index.js +5 -8
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +27 -19
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +197 -41
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataform-controls/datetime.js +49 -0
- package/build/dataform-controls/datetime.js.map +1 -0
- package/build/dataform-controls/index.js +50 -0
- package/build/dataform-controls/index.js.map +1 -0
- package/build/dataform-controls/integer.js +45 -0
- package/build/dataform-controls/integer.js.map +1 -0
- package/build/dataform-controls/radio.js +45 -0
- package/build/dataform-controls/radio.js.map +1 -0
- package/build/dataform-controls/select.js +58 -0
- package/build/dataform-controls/select.js.map +1 -0
- package/build/dataform-controls/text.js +45 -0
- package/build/dataform-controls/text.js.map +1 -0
- package/build/dataforms-layouts/panel/index.js +10 -4
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +6 -3
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/density-picker.js +23 -52
- package/build/dataviews-layouts/grid/density-picker.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +1 -1
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/index.js +48 -2
- package/build/dataviews-layouts/index.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +124 -80
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +52 -57
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +7 -35
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/field-types/datetime.js +30 -0
- package/build/field-types/datetime.js.map +1 -0
- package/build/field-types/index.js +4 -0
- package/build/field-types/index.js.map +1 -1
- package/build/field-types/integer.js +1 -60
- package/build/field-types/integer.js.map +1 -1
- package/build/field-types/text.js +1 -60
- package/build/field-types/text.js.map +1 -1
- package/build/normalize-fields.js +10 -9
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews/index.js +10 -14
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-bulk-actions/index.js +145 -143
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build-module/components/dataviews-filters/add-filter.js +4 -6
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
- package/build-module/components/dataviews-filters/index.js +3 -0
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/search-widget.js +30 -23
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
- package/build-module/components/dataviews-footer/index.js +38 -0
- package/build-module/components/dataviews-footer/index.js.map +1 -0
- package/build-module/components/dataviews-item-actions/index.js +5 -8
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +28 -20
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +203 -47
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataform-controls/datetime.js +43 -0
- package/build-module/dataform-controls/datetime.js.map +1 -0
- package/build-module/dataform-controls/index.js +42 -0
- package/build-module/dataform-controls/index.js.map +1 -0
- package/build-module/dataform-controls/integer.js +38 -0
- package/build-module/dataform-controls/integer.js.map +1 -0
- package/build-module/dataform-controls/radio.js +38 -0
- package/build-module/dataform-controls/radio.js.map +1 -0
- package/build-module/dataform-controls/select.js +51 -0
- package/build-module/dataform-controls/select.js.map +1 -0
- package/build-module/dataform-controls/text.js +38 -0
- package/build-module/dataform-controls/text.js.map +1 -0
- package/build-module/dataforms-layouts/panel/index.js +10 -4
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +6 -3
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/density-picker.js +25 -56
- package/build-module/dataviews-layouts/grid/density-picker.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +1 -1
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/index.js +45 -1
- package/build-module/dataviews-layouts/index.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +125 -80
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +52 -57
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +9 -37
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/field-types/datetime.js +24 -0
- package/build-module/field-types/datetime.js.map +1 -0
- package/build-module/field-types/index.js +4 -0
- package/build-module/field-types/index.js.map +1 -1
- package/build-module/field-types/integer.js +2 -60
- package/build-module/field-types/integer.js.map +1 -1
- package/build-module/field-types/text.js +2 -60
- package/build-module/field-types/text.js.map +1 -1
- package/build-module/normalize-fields.js +11 -9
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +93 -80
- package/build-style/style.css +93 -80
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts +28 -113
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +12 -44
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts +11 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/index.d.ts +1 -1
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-footer/index.d.ts +2 -0
- package/build-types/components/dataviews-footer/index.d.ts.map +1 -0
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts +4 -3
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataform-controls/datetime.d.ts +6 -0
- package/build-types/dataform-controls/datetime.d.ts.map +1 -0
- package/build-types/dataform-controls/index.d.ts +11 -0
- package/build-types/dataform-controls/index.d.ts.map +1 -0
- package/build-types/dataform-controls/integer.d.ts +6 -0
- package/build-types/dataform-controls/integer.d.ts.map +1 -0
- package/build-types/dataform-controls/radio.d.ts +6 -0
- package/build-types/dataform-controls/radio.d.ts.map +1 -0
- package/build-types/dataform-controls/select.d.ts +6 -0
- package/build-types/dataform-controls/select.d.ts.map +1 -0
- package/build-types/dataform-controls/text.d.ts +6 -0
- package/build-types/dataform-controls/text.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/density-picker.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +4 -2
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/field-types/datetime.d.ts +13 -0
- package/build-types/field-types/datetime.d.ts.map +1 -0
- package/build-types/field-types/index.d.ts +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts +2 -3
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/text.d.ts +2 -3
- package/build-types/field-types/text.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +43 -21
- package/build-types/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/components/dataform/stories/index.story.tsx +43 -2
- package/src/components/dataviews/index.tsx +14 -18
- package/src/components/dataviews/stories/fixtures.tsx +690 -0
- package/src/components/dataviews/stories/index.story.tsx +164 -0
- package/src/components/dataviews/style.scss +2 -12
- package/src/components/dataviews-bulk-actions/index.tsx +264 -213
- package/src/components/dataviews-bulk-actions/style.scss +9 -4
- package/src/components/dataviews-filters/add-filter.tsx +7 -11
- package/src/components/dataviews-filters/index.tsx +3 -0
- package/src/components/dataviews-filters/search-widget.tsx +46 -25
- package/src/components/dataviews-filters/style.scss +13 -3
- package/src/components/dataviews-footer/index.tsx +50 -0
- package/src/components/dataviews-footer/style.scss +40 -0
- package/src/components/dataviews-item-actions/index.tsx +8 -14
- package/src/components/dataviews-pagination/index.tsx +40 -21
- package/src/components/dataviews-pagination/style.scss +7 -21
- package/src/components/dataviews-view-config/index.tsx +297 -69
- package/src/components/dataviews-view-config/style.scss +25 -0
- package/src/dataform-controls/datetime.tsx +43 -0
- package/src/dataform-controls/index.tsx +61 -0
- package/src/dataform-controls/integer.tsx +38 -0
- package/src/dataform-controls/radio.tsx +42 -0
- package/src/dataform-controls/select.tsx +52 -0
- package/src/dataform-controls/style.scss +4 -0
- package/src/dataform-controls/text.tsx +40 -0
- package/src/dataforms-layouts/panel/index.tsx +8 -2
- package/src/dataforms-layouts/regular/index.tsx +6 -2
- package/src/dataviews-layouts/grid/density-picker.tsx +33 -67
- package/src/dataviews-layouts/grid/index.tsx +1 -1
- package/src/dataviews-layouts/grid/style.scss +1 -5
- package/src/dataviews-layouts/index.ts +63 -2
- package/src/dataviews-layouts/list/index.tsx +199 -123
- package/src/dataviews-layouts/list/style.scss +10 -4
- package/src/dataviews-layouts/table/column-header-menu.tsx +86 -90
- package/src/dataviews-layouts/table/index.tsx +8 -65
- package/src/dataviews-layouts/table/style.scss +0 -5
- package/src/field-types/datetime.tsx +28 -0
- package/src/field-types/index.tsx +5 -0
- package/src/field-types/integer.tsx +2 -71
- package/src/field-types/text.tsx +2 -70
- package/src/normalize-fields.ts +10 -10
- package/src/style.scss +2 -1
- package/src/test/filter-and-sort-data-view.js +28 -0
- package/src/types.ts +56 -32
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/dataviews-bulk-actions-toolbar/index.js +0 -207
- package/build/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js +0 -201
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +0 -1
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +0 -2
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +0 -1
- package/src/components/dataviews/stories/fixtures.js +0 -222
- package/src/components/dataviews/stories/index.story.js +0 -65
- package/src/components/dataviews-bulk-actions-toolbar/index.tsx +0 -288
- package/src/components/dataviews-bulk-actions-toolbar/style.scss +0 -45
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 4.3.0 (2024-09-05)
|
|
6
|
+
|
|
7
|
+
## 4.2.0 (2024-08-21)
|
|
8
|
+
|
|
9
|
+
## New features
|
|
10
|
+
|
|
11
|
+
- Support using a component for field headers or names by providing a `header` property in the field object. The string `label` property (or `id`) is still mandatory. ([#64642](https://github.com/WordPress/gutenberg/pull/64642)).
|
|
12
|
+
|
|
13
|
+
## Internal
|
|
14
|
+
|
|
15
|
+
- The "move left/move right" controls in the table layout (popup displayed on cliking header) are always visible. ([#64646](https://github.com/WordPress/gutenberg/pull/64646)). Before this, its visibility depending on filters, enableSorting, and enableHiding.
|
|
16
|
+
- Filters no longer display the elements' description. ([#64674](https://github.com/WordPress/gutenberg/pull/64674))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## Enhancements
|
|
20
|
+
|
|
21
|
+
- Adjust layout of filter / actions row, increase width of search control when the container is narrower. ([#64681](https://github.com/WordPress/gutenberg/pull/64681)).
|
|
22
|
+
|
|
5
23
|
## 4.1.0 (2024-08-07)
|
|
6
24
|
|
|
7
25
|
## Internal
|
|
@@ -16,6 +34,7 @@
|
|
|
16
34
|
- `setSelection` prop has been removed. Please use `onChangeSelection` instead.
|
|
17
35
|
- `header` field property has been renamed to `label`.
|
|
18
36
|
- `DataForm`'s `visibleFields` prop has been renamed to `fields`.
|
|
37
|
+
- `DataForm`'s `onChange` prop has been update to receive as argument only the fields that have changed.
|
|
19
38
|
|
|
20
39
|
### New features
|
|
21
40
|
|
package/README.md
CHANGED
|
@@ -30,6 +30,8 @@ const Example = () => {
|
|
|
30
30
|
};
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
<div class="callout callout-info">At <a href="https://wordpress.github.io/gutenberg/">WordPress Gutenberg's Storybook</a> there's and <a href="https://wordpress.github.io/gutenberg/?path=/docs/dataviews-dataviews--docs">example implementation of the Dataviews component</a></div>
|
|
34
|
+
|
|
33
35
|
## Properties
|
|
34
36
|
|
|
35
37
|
### `data`: `Object[]`
|
|
@@ -72,62 +74,66 @@ const STATUSES = [
|
|
|
72
74
|
const fields = [
|
|
73
75
|
{
|
|
74
76
|
id: 'title',
|
|
75
|
-
|
|
77
|
+
label: 'Title',
|
|
76
78
|
enableHiding: false,
|
|
77
79
|
},
|
|
78
80
|
{
|
|
79
81
|
id: 'date',
|
|
80
|
-
|
|
82
|
+
label: 'Date',
|
|
81
83
|
render: ( { item } ) => {
|
|
82
|
-
return (
|
|
83
|
-
|
|
84
|
-
);
|
|
85
|
-
}
|
|
84
|
+
return <time>{ getFormattedDate( item.date ) }</time>;
|
|
85
|
+
},
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
id: 'author',
|
|
89
|
-
|
|
89
|
+
label: __( 'Author' ),
|
|
90
90
|
render: ( { item } ) => {
|
|
91
|
-
return
|
|
92
|
-
<a href="...">{ item.author }</a>
|
|
93
|
-
);
|
|
91
|
+
return <a href="...">{ item.author }</a>;
|
|
94
92
|
},
|
|
95
93
|
elements: [
|
|
96
94
|
{ value: 1, label: 'Admin' },
|
|
97
|
-
{ value: 2, label: 'User' }
|
|
95
|
+
{ value: 2, label: 'User' },
|
|
98
96
|
],
|
|
99
97
|
filterBy: {
|
|
100
|
-
operators: [ 'is', 'isNot' ]
|
|
98
|
+
operators: [ 'is', 'isNot' ],
|
|
101
99
|
},
|
|
102
|
-
enableSorting: false
|
|
100
|
+
enableSorting: false,
|
|
103
101
|
},
|
|
104
102
|
{
|
|
105
|
-
|
|
103
|
+
label: __( 'Status' ),
|
|
106
104
|
id: 'status',
|
|
107
105
|
getValue: ( { item } ) =>
|
|
108
|
-
STATUSES.find( ( { value } ) => value === item.status )
|
|
109
|
-
|
|
106
|
+
STATUSES.find( ( { value } ) => value === item.status )?.label ??
|
|
107
|
+
item.status,
|
|
110
108
|
elements: STATUSES,
|
|
111
109
|
filterBy: {
|
|
112
110
|
operators: [ 'isAny' ],
|
|
113
111
|
},
|
|
114
112
|
enableSorting: false,
|
|
115
113
|
},
|
|
116
|
-
]
|
|
114
|
+
];
|
|
117
115
|
```
|
|
118
116
|
|
|
119
117
|
Each field is an object with the following properties:
|
|
120
118
|
|
|
121
119
|
- `id`: identifier for the field. Unique.
|
|
122
|
-
- `
|
|
120
|
+
- `label`: the field's name to be shown in the UI.
|
|
123
121
|
- `getValue`: function that returns the value of the field, defaults to `field[id]`.
|
|
124
122
|
- `render`: function that renders the field. Optional, `getValue` will be used if `render` is not defined.
|
|
125
|
-
-
|
|
123
|
+
- <code id="fields-elements">elements</code>: The list of options to pick from when using the field as a filter or when editing (DataForm component). It expects an array of objects with the following properties:
|
|
124
|
+
|
|
125
|
+
- `value`: The id of the value to filter to (for internal use)
|
|
126
|
+
- `label`: The text that will be displayed in the UI for the item.
|
|
127
|
+
- `description`: A longer description that describes the element, to also be displayed. Optional.
|
|
128
|
+
|
|
129
|
+
To enable the filter by a field we just need to set a proper value to the `elements` property of the field we'd like to filter by.
|
|
130
|
+
|
|
126
131
|
- `type`: the type of the field. See "Field types".
|
|
127
132
|
- `enableSorting`: whether the data can be sorted by the given field. True by default.
|
|
128
133
|
- `enableHiding`: whether the field can be hidden. True by default.
|
|
129
|
-
- `
|
|
130
|
-
|
|
134
|
+
- `enableGlobalSearch`: whether the field is searchable. False by default.
|
|
135
|
+
- `filterBy`: configuration for the filters enabled by the `elements` property.
|
|
136
|
+
- `operators`: the list of [operators](#operators) supported by the field.
|
|
131
137
|
- `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.
|
|
132
138
|
|
|
133
139
|
### `view`: `object`
|
|
@@ -166,14 +172,23 @@ Properties:
|
|
|
166
172
|
- `perPage`: number of records to show per page.
|
|
167
173
|
- `page`: the page that is visible.
|
|
168
174
|
- `sort`:
|
|
175
|
+
|
|
169
176
|
- `field`: the field used for sorting the dataset.
|
|
170
177
|
- `direction`: the direction to use for sorting, one of `asc` or `desc`.
|
|
171
|
-
|
|
178
|
+
|
|
179
|
+
- `fields`: the `id` of the fields that are visible in the UI and the specific order in which they are displayed.
|
|
172
180
|
- `layout`: config that is specific to a particular layout type.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
181
|
+
|
|
182
|
+
#### Properties of `layout`
|
|
183
|
+
|
|
184
|
+
| Properties of `layout` | Table | Grid | List |
|
|
185
|
+
| --------------------------------------------------------------------------------------------------------------- | ----- | ---- | ---- |
|
|
186
|
+
| `primaryField`: the field's `id` to be highlighted in each layout. It's not hidable. | ✓ | ✓ | ✓ |
|
|
187
|
+
| `mediaField`: the field's `id` to be used for rendering each card's media. It's not hiddable. | | ✓ | ✓ |
|
|
188
|
+
| `columnFields`: a list of field's `id` to render vertically stacked instead of horizontally (the default). | | ✓ | |
|
|
189
|
+
| `badgeFields`: a list of field's `id` to render without label and styled as badges. | | ✓ | |
|
|
190
|
+
| `combinedFields`: a list of "virtual" fields that are made by combining others. See "Combining fields" section. | ✓ | | |
|
|
191
|
+
| `styles`: additional `width`, `maxWidth`, `minWidth` styles for each field column. | ✓ | | |
|
|
177
192
|
|
|
178
193
|
### `onChangeView`: `function`
|
|
179
194
|
|
|
@@ -255,6 +270,8 @@ Each action is an object with the following properties:
|
|
|
255
270
|
- `callback`: function, required unless `RenderModal` is provided. Callback function that takes the record as input and performs the required action.
|
|
256
271
|
- `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.
|
|
257
272
|
- `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.
|
|
273
|
+
- `supportsBulk`: Whether the action can be used as a bulk action. False by default.
|
|
274
|
+
- `disabled`: Whether the action is disabled. False by default.
|
|
258
275
|
|
|
259
276
|
### `paginationInfo`: `Object`
|
|
260
277
|
|
|
@@ -287,12 +304,14 @@ For example, this is how you'd enable only the table view type:
|
|
|
287
304
|
const defaultLayouts = {
|
|
288
305
|
table: {
|
|
289
306
|
layout: {
|
|
290
|
-
|
|
291
|
-
}
|
|
292
|
-
}
|
|
307
|
+
primaryField: 'my-key',
|
|
308
|
+
},
|
|
309
|
+
},
|
|
293
310
|
};
|
|
294
311
|
```
|
|
295
312
|
|
|
313
|
+
The `defaultLayouts` property should be an object that includes properties named `table`, `grid`, or `list`. Each of these properties should contain a `layout` property, which holds the configuration for each specific layout type. Check [here](#properties-of-layout) the full list of properties available for each layout's configuration
|
|
314
|
+
|
|
296
315
|
### `onChangeSelection`: `function`
|
|
297
316
|
|
|
298
317
|
Callback that signals the user selected one of more items, and takes them as parameter. So far, only the `list` view implements it.
|
|
@@ -309,6 +328,35 @@ Callback that signals the user selected one of more items, and takes them as par
|
|
|
309
328
|
|
|
310
329
|
> The `enumeration` type was removed as it was deemed redundant with the field.elements metadata. New types will be introduced soon.
|
|
311
330
|
|
|
331
|
+
## Combining fields
|
|
332
|
+
|
|
333
|
+
The `table` layout has the ability to create "virtual" fields that are made out by combining existing ones.
|
|
334
|
+
|
|
335
|
+
Each "virtual field", has to provide an `id` and `label` (optionally a `header` instead), which have the same meaning as any other field.
|
|
336
|
+
|
|
337
|
+
Additionally, they need to provide:
|
|
338
|
+
|
|
339
|
+
- `children`: a list of field's `id` to combine
|
|
340
|
+
- `direction`: how should they be stacked, `vertical` or `horizontal`
|
|
341
|
+
|
|
342
|
+
For example, this is how you'd define a `site` field which is a combination of a `title` and `description` fields, which are not displayed:
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
{
|
|
346
|
+
fields: [ 'site', 'status' ],
|
|
347
|
+
layout: {
|
|
348
|
+
combinedFields: [
|
|
349
|
+
{
|
|
350
|
+
id: 'site',
|
|
351
|
+
label: 'Site',
|
|
352
|
+
children: [ 'title', 'description' ],
|
|
353
|
+
direction: 'vertical',
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
312
360
|
### Operators
|
|
313
361
|
|
|
314
362
|
Allowed operators:
|
|
@@ -7,17 +7,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = DataViews;
|
|
8
8
|
var _components = require("@wordpress/components");
|
|
9
9
|
var _element = require("@wordpress/element");
|
|
10
|
-
var _dataviewsBulkActions = _interopRequireDefault(require("../dataviews-bulk-actions"));
|
|
11
|
-
var _dataviewsBulkActionsToolbar = _interopRequireDefault(require("../dataviews-bulk-actions-toolbar"));
|
|
12
10
|
var _dataviewsContext = _interopRequireDefault(require("../dataviews-context"));
|
|
13
11
|
var _dataviewsFilters = _interopRequireWildcard(require("../dataviews-filters"));
|
|
14
12
|
var _dataviewsLayout = _interopRequireDefault(require("../dataviews-layout"));
|
|
15
|
-
var
|
|
13
|
+
var _dataviewsFooter = _interopRequireDefault(require("../dataviews-footer"));
|
|
16
14
|
var _dataviewsSearch = _interopRequireDefault(require("../dataviews-search"));
|
|
17
15
|
var _dataviewsViewConfig = _interopRequireDefault(require("../dataviews-view-config"));
|
|
18
16
|
var _normalizeFields = require("../../normalize-fields");
|
|
19
|
-
var _densityPicker = _interopRequireDefault(require("../../dataviews-layouts/grid/density-picker"));
|
|
20
|
-
var _constants = require("../../constants");
|
|
21
17
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
18
|
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); }
|
|
23
19
|
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 && {}.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; }
|
|
@@ -52,7 +48,6 @@ function DataViews({
|
|
|
52
48
|
}) {
|
|
53
49
|
const [selectionState, setSelectionState] = (0, _element.useState)([]);
|
|
54
50
|
const [density, setDensity] = (0, _element.useState)(0);
|
|
55
|
-
const [isShowingFilter, setIsShowingFilter] = (0, _element.useState)(false);
|
|
56
51
|
const isUncontrolled = selectionProperty === undefined || onChangeSelection === undefined;
|
|
57
52
|
const selection = isUncontrolled ? selectionState : selectionProperty;
|
|
58
53
|
const [openedFilter, setOpenedFilter] = (0, _element.useState)(null);
|
|
@@ -70,6 +65,7 @@ function DataViews({
|
|
|
70
65
|
return selection.filter(id => data.some(item => getItemId(item) === id));
|
|
71
66
|
}, [selection, data, getItemId]);
|
|
72
67
|
const filters = (0, _dataviewsFilters.useFilters)(_fields, view);
|
|
68
|
+
const [isShowingFilter, setIsShowingFilter] = (0, _element.useState)(() => (filters || []).some(filter => filter.isPrimary));
|
|
73
69
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsContext.default.Provider, {
|
|
74
70
|
value: {
|
|
75
71
|
view,
|
|
@@ -90,12 +86,13 @@ function DataViews({
|
|
|
90
86
|
className: "dataviews-wrapper",
|
|
91
87
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
92
88
|
alignment: "top",
|
|
93
|
-
justify: "
|
|
89
|
+
justify: "space-between",
|
|
94
90
|
className: "dataviews__view-actions",
|
|
95
91
|
spacing: 1,
|
|
96
92
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
97
93
|
justify: "start",
|
|
98
|
-
|
|
94
|
+
expanded: false,
|
|
95
|
+
className: "dataviews__search",
|
|
99
96
|
children: [search && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsSearch.default, {
|
|
100
97
|
label: searchLabel
|
|
101
98
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFilters.FilterVisibilityToggle, {
|
|
@@ -106,20 +103,19 @@ function DataViews({
|
|
|
106
103
|
setIsShowingFilter: setIsShowingFilter,
|
|
107
104
|
isShowingFilter: isShowingFilter
|
|
108
105
|
})]
|
|
109
|
-
}),
|
|
110
|
-
density: density,
|
|
111
|
-
setDensity: setDensity
|
|
112
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsBulkActions.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
106
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
113
107
|
spacing: 1,
|
|
114
108
|
expanded: false,
|
|
115
109
|
style: {
|
|
116
110
|
flexShrink: 0
|
|
117
111
|
},
|
|
118
112
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsViewConfig.default, {
|
|
119
|
-
defaultLayouts: defaultLayouts
|
|
113
|
+
defaultLayouts: defaultLayouts,
|
|
114
|
+
density: density,
|
|
115
|
+
setDensity: setDensity
|
|
120
116
|
}), header]
|
|
121
117
|
})]
|
|
122
|
-
}), isShowingFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFilters.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsLayout.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
118
|
+
}), isShowingFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFilters.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsLayout.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFooter.default, {})]
|
|
123
119
|
})
|
|
124
120
|
});
|
|
125
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_dataviewsBulkActions","_interopRequireDefault","_dataviewsBulkActionsToolbar","_dataviewsContext","_dataviewsFilters","_interopRequireWildcard","_dataviewsLayout","_dataviewsPagination","_dataviewsSearch","_dataviewsViewConfig","_normalizeFields","_densityPicker","_constants","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultGetItemId","item","id","DataViews","view","onChangeView","fields","search","searchLabel","undefined","actions","data","getItemId","isLoading","paginationInfo","defaultLayouts","selection","selectionProperty","onChangeSelection","header","selectionState","setSelectionState","useState","density","setDensity","isShowingFilter","setIsShowingFilter","isUncontrolled","openedFilter","setOpenedFilter","setSelectionWithChange","value","newValue","_fields","useMemo","normalizeFields","_selection","filter","some","filters","useFilters","jsx","Provider","children","jsxs","className","__experimentalHStack","alignment","justify","spacing","wrap","label","FilterVisibilityToggle","type","LAYOUT_GRID","expanded","style","flexShrink"],"sources":["@wordpress/dataviews/src/components/dataviews/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { default as DataViewsBulkActions } from '../dataviews-bulk-actions';\nimport DataViewsBulkActionsToolbar from '../dataviews-bulk-actions-toolbar';\nimport DataViewsContext from '../dataviews-context';\nimport {\n\tdefault as DataViewsFilters,\n\tuseFilters,\n\tFilterVisibilityToggle,\n} from '../dataviews-filters';\nimport DataViewsLayout from '../dataviews-layout';\nimport DataviewsPagination from '../dataviews-pagination';\nimport DataViewsSearch from '../dataviews-search';\nimport DataViewsViewConfig from '../dataviews-view-config';\nimport { normalizeFields } from '../../normalize-fields';\nimport type { Action, Field, View, SupportedLayouts } from '../../types';\nimport type { SelectionOrUpdater } from '../../private-types';\nimport DensityPicker from '../../dataviews-layouts/grid/density-picker';\nimport { LAYOUT_GRID } from '../../constants';\n\ntype ItemWithId = { id: string };\n\ntype DataViewsProps< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: Field< Item >[];\n\tsearch?: boolean;\n\tsearchLabel?: string;\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tdefaultLayouts: SupportedLayouts;\n\tselection?: string[];\n\tonChangeSelection?: ( items: string[] ) => void;\n\theader?: ReactNode;\n} & ( Item extends ItemWithId\n\t? { getItemId?: ( item: Item ) => string }\n\t: { getItemId: ( item: Item ) => string } );\n\nconst defaultGetItemId = ( item: ItemWithId ) => item.id;\n\nexport default function DataViews< Item >( {\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\tdefaultLayouts,\n\tselection: selectionProperty,\n\tonChangeSelection,\n\theader,\n}: DataViewsProps< Item > ) {\n\tconst [ selectionState, setSelectionState ] = useState< string[] >( [] );\n\tconst [ density, setDensity ] = useState< number >( 0 );\n\tconst [ isShowingFilter, setIsShowingFilter ] =\n\t\tuseState< boolean >( false );\n\tconst isUncontrolled =\n\t\tselectionProperty === undefined || onChangeSelection === undefined;\n\tconst selection = isUncontrolled ? selectionState : selectionProperty;\n\tconst [ openedFilter, setOpenedFilter ] = useState< string | null >( null );\n\tfunction setSelectionWithChange( value: SelectionOrUpdater ) {\n\t\tconst newValue =\n\t\t\ttypeof value === 'function' ? value( selection ) : value;\n\t\tif ( isUncontrolled ) {\n\t\t\tsetSelectionState( newValue );\n\t\t}\n\t\tif ( onChangeSelection ) {\n\t\t\tonChangeSelection( newValue );\n\t\t}\n\t}\n\tconst _fields = useMemo( () => normalizeFields( fields ), [ fields ] );\n\tconst _selection = useMemo( () => {\n\t\treturn selection.filter( ( id ) =>\n\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t);\n\t}, [ selection, data, getItemId ] );\n\n\tconst filters = useFilters( _fields, view );\n\treturn (\n\t\t<DataViewsContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tview,\n\t\t\t\tonChangeView,\n\t\t\t\tfields: _fields,\n\t\t\t\tactions,\n\t\t\t\tdata,\n\t\t\t\tisLoading,\n\t\t\t\tpaginationInfo,\n\t\t\t\tselection: _selection,\n\t\t\t\tonChangeSelection: setSelectionWithChange,\n\t\t\t\topenedFilter,\n\t\t\t\tsetOpenedFilter,\n\t\t\t\tgetItemId,\n\t\t\t\tdensity,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-wrapper\">\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__view-actions\"\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t>\n\t\t\t\t\t<HStack justify=\"start\" wrap>\n\t\t\t\t\t\t{ search && <DataViewsSearch label={ searchLabel } /> }\n\t\t\t\t\t\t<FilterVisibilityToggle\n\t\t\t\t\t\t\tfilters={ filters }\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\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\tsetIsShowingFilter={ setIsShowingFilter }\n\t\t\t\t\t\t\tisShowingFilter={ isShowingFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t{ view.type === LAYOUT_GRID && (\n\t\t\t\t\t\t<DensityPicker\n\t\t\t\t\t\t\tdensity={ density }\n\t\t\t\t\t\t\tsetDensity={ setDensity }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<DataViewsBulkActions />\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\tstyle={ { flexShrink: 0 } }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DataViewsViewConfig\n\t\t\t\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ header }\n\t\t\t\t\t</HStack>\n\t\t\t\t</HStack>\n\t\t\t\t{ isShowingFilter && <DataViewsFilters /> }\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AAU,EAAE;UAAE,CAAG;UAAAd,QAAA,gBAE3B,IAAAhE,WAAA,CAAA8D,GAAA,EAAClE,oBAAA,CAAAW,OAAmB;YACnB6B,cAAc,EAAGA;UAAgB,CACjC,CAAC,EACAI,MAAM;QAAA,CACD,CAAC;MAAA,CACF,CAAC,EACPM,eAAe,iBAAI,IAAA9C,WAAA,CAAA8D,GAAA,EAACvE,iBAAA,CAAAgB,OAAgB,IAAE,CAAC,eACzC,IAAAP,WAAA,CAAA8D,GAAA,EAACrE,gBAAA,CAAAc,OAAe,IAAE,CAAC,eACnB,IAAAP,WAAA,CAAA8D,GAAA,EAACpE,oBAAA,CAAAa,OAAmB,IAAE,CAAC,eACvB,IAAAP,WAAA,CAAA8D,GAAA,EAACzE,4BAAA,CAAAkB,OAA2B,IAAE,CAAC;IAAA,CAC3B;EAAC,CACoB,CAAC;AAE9B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_dataviewsContext","_interopRequireDefault","_dataviewsFilters","_interopRequireWildcard","_dataviewsLayout","_dataviewsFooter","_dataviewsSearch","_dataviewsViewConfig","_normalizeFields","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","defaultGetItemId","item","id","DataViews","view","onChangeView","fields","search","searchLabel","undefined","actions","data","getItemId","isLoading","paginationInfo","defaultLayouts","selection","selectionProperty","onChangeSelection","header","selectionState","setSelectionState","useState","density","setDensity","isUncontrolled","openedFilter","setOpenedFilter","setSelectionWithChange","value","newValue","_fields","useMemo","normalizeFields","_selection","filter","some","filters","useFilters","isShowingFilter","setIsShowingFilter","isPrimary","jsx","Provider","children","jsxs","className","__experimentalHStack","alignment","justify","spacing","expanded","label","FilterVisibilityToggle","style","flexShrink"],"sources":["@wordpress/dataviews/src/components/dataviews/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { useMemo, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport {\n\tdefault as DataViewsFilters,\n\tuseFilters,\n\tFilterVisibilityToggle,\n} from '../dataviews-filters';\nimport DataViewsLayout from '../dataviews-layout';\nimport DataViewsFooter from '../dataviews-footer';\nimport DataViewsSearch from '../dataviews-search';\nimport DataViewsViewConfig from '../dataviews-view-config';\nimport { normalizeFields } from '../../normalize-fields';\nimport type { Action, Field, View, SupportedLayouts } from '../../types';\nimport type { SelectionOrUpdater } from '../../private-types';\n\ntype ItemWithId = { id: string };\n\ntype DataViewsProps< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: Field< Item >[];\n\tsearch?: boolean;\n\tsearchLabel?: string;\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tdefaultLayouts: SupportedLayouts;\n\tselection?: string[];\n\tonChangeSelection?: ( items: string[] ) => void;\n\theader?: ReactNode;\n} & ( Item extends ItemWithId\n\t? { getItemId?: ( item: Item ) => string }\n\t: { getItemId: ( item: Item ) => string } );\n\nconst defaultGetItemId = ( item: ItemWithId ) => item.id;\n\nexport default function DataViews< Item >( {\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\tdefaultLayouts,\n\tselection: selectionProperty,\n\tonChangeSelection,\n\theader,\n}: DataViewsProps< Item > ) {\n\tconst [ selectionState, setSelectionState ] = useState< string[] >( [] );\n\tconst [ density, setDensity ] = useState< number >( 0 );\n\tconst isUncontrolled =\n\t\tselectionProperty === undefined || onChangeSelection === undefined;\n\tconst selection = isUncontrolled ? selectionState : selectionProperty;\n\tconst [ openedFilter, setOpenedFilter ] = useState< string | null >( null );\n\tfunction setSelectionWithChange( value: SelectionOrUpdater ) {\n\t\tconst newValue =\n\t\t\ttypeof value === 'function' ? value( selection ) : value;\n\t\tif ( isUncontrolled ) {\n\t\t\tsetSelectionState( newValue );\n\t\t}\n\t\tif ( onChangeSelection ) {\n\t\t\tonChangeSelection( newValue );\n\t\t}\n\t}\n\tconst _fields = useMemo( () => normalizeFields( fields ), [ fields ] );\n\tconst _selection = useMemo( () => {\n\t\treturn selection.filter( ( id ) =>\n\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t);\n\t}, [ selection, data, getItemId ] );\n\n\tconst filters = useFilters( _fields, view );\n\tconst [ isShowingFilter, setIsShowingFilter ] = useState< boolean >( () =>\n\t\t( filters || [] ).some( ( filter ) => filter.isPrimary )\n\t);\n\n\treturn (\n\t\t<DataViewsContext.Provider\n\t\t\tvalue={ {\n\t\t\t\tview,\n\t\t\t\tonChangeView,\n\t\t\t\tfields: _fields,\n\t\t\t\tactions,\n\t\t\t\tdata,\n\t\t\t\tisLoading,\n\t\t\t\tpaginationInfo,\n\t\t\t\tselection: _selection,\n\t\t\t\tonChangeSelection: setSelectionWithChange,\n\t\t\t\topenedFilter,\n\t\t\t\tsetOpenedFilter,\n\t\t\t\tgetItemId,\n\t\t\t\tdensity,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-wrapper\">\n\t\t\t\t<HStack\n\t\t\t\t\talignment=\"top\"\n\t\t\t\t\tjustify=\"space-between\"\n\t\t\t\t\tclassName=\"dataviews__view-actions\"\n\t\t\t\t\tspacing={ 1 }\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\texpanded={ false }\n\t\t\t\t\t\tclassName=\"dataviews__search\"\n\t\t\t\t\t>\n\t\t\t\t\t\t{ search && <DataViewsSearch label={ searchLabel } /> }\n\t\t\t\t\t\t<FilterVisibilityToggle\n\t\t\t\t\t\t\tfilters={ filters }\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\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t\t\tsetIsShowingFilter={ setIsShowingFilter }\n\t\t\t\t\t\t\tisShowingFilter={ isShowingFilter }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</HStack>\n\t\t\t\t\t<HStack\n\t\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\t\texpanded={ false }\n\t\t\t\t\t\tstyle={ { flexShrink: 0 } }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DataViewsViewConfig\n\t\t\t\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\t\t\t\tdensity={ density }\n\t\t\t\t\t\t\tsetDensity={ setDensity }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ header }\n\t\t\t\t\t</HStack>\n\t\t\t\t</HStack>\n\t\t\t\t{ isShowingFilter && <DataViewsFilters /> }\n\t\t\t\t<DataViewsLayout />\n\t\t\t\t<DataViewsFooter />\n\t\t\t</div>\n\t\t</DataViewsContext.Provider>\n\t);\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,iBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAC,uBAAA,CAAAL,OAAA;AAKA,IAAAM,gBAAA,GAAAH,sBAAA,CAAAH,OAAA;AACA,IAAAO,gBAAA,GAAAJ,sBAAA,CAAAH,OAAA;AACA,IAAAQ,gBAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,oBAAA,GAAAN,sBAAA,CAAAH,OAAA;AACA,IAAAU,gBAAA,GAAAV,OAAA;AAAyD,IAAAW,WAAA,GAAAX,OAAA;AAAA,SAAAY,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,O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