@wordpress/dataviews 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +42 -14
- package/build/components/dataviews/index.js +38 -6
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +4 -1
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-item-actions/index.js +1 -10
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +1 -1
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +8 -5
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/components/dataviews-view-config/infinite-scroll-toggle.js +47 -0
- package/build/components/dataviews-view-config/infinite-scroll-toggle.js.map +1 -0
- package/build/dataform-controls/array.js +70 -0
- package/build/dataform-controls/array.js.map +1 -0
- package/build/dataform-controls/boolean.js +15 -7
- package/build/dataform-controls/boolean.js.map +1 -1
- package/build/dataform-controls/email.js +14 -7
- package/build/dataform-controls/email.js.map +1 -1
- package/build/dataform-controls/index.js +3 -1
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/integer.js +14 -7
- package/build/dataform-controls/integer.js.map +1 -1
- package/build/dataform-controls/text.js +14 -7
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataforms-layouts/card/index.js +137 -0
- package/build/dataforms-layouts/card/index.js.map +1 -0
- package/build/dataforms-layouts/data-form-layout.js +2 -2
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/index.js +4 -0
- package/build/dataforms-layouts/index.js.map +1 -1
- package/build/dataforms-layouts/panel/dropdown.js +124 -0
- package/build/dataforms-layouts/panel/dropdown.js.map +1 -0
- package/build/dataforms-layouts/panel/index.js +34 -149
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/panel/modal.js +125 -0
- package/build/dataforms-layouts/panel/modal.js.map +1 -0
- package/build/dataforms-layouts/regular/index.js +10 -21
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +24 -7
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/grid/preview-size-picker.js +11 -11
- package/build/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +45 -27
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +3 -0
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +23 -8
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/field-types/array.js +2 -2
- package/build/field-types/array.js.map +1 -1
- package/build/normalize-form-fields.js +52 -13
- package/build/normalize-form-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/components/dataviews/index.js +40 -8
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +4 -1
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-item-actions/index.js +1 -10
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +1 -1
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +8 -5
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.js +39 -0
- package/build-module/components/dataviews-view-config/infinite-scroll-toggle.js.map +1 -0
- package/build-module/dataform-controls/array.js +63 -0
- package/build-module/dataform-controls/array.js.map +1 -0
- package/build-module/dataform-controls/boolean.js +15 -7
- package/build-module/dataform-controls/boolean.js.map +1 -1
- package/build-module/dataform-controls/email.js +15 -8
- package/build-module/dataform-controls/email.js.map +1 -1
- package/build-module/dataform-controls/index.js +3 -1
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/integer.js +15 -8
- package/build-module/dataform-controls/integer.js.map +1 -1
- package/build-module/dataform-controls/text.js +15 -8
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataforms-layouts/card/index.js +128 -0
- package/build-module/dataforms-layouts/card/index.js.map +1 -0
- package/build-module/dataforms-layouts/data-form-layout.js +2 -2
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/index.js +4 -0
- package/build-module/dataforms-layouts/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/dropdown.js +118 -0
- package/build-module/dataforms-layouts/panel/dropdown.js.map +1 -0
- package/build-module/dataforms-layouts/panel/index.js +37 -152
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/modal.js +119 -0
- package/build-module/dataforms-layouts/panel/modal.js.map +1 -0
- package/build-module/dataforms-layouts/regular/index.js +10 -21
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +25 -8
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/preview-size-picker.js +11 -11
- package/build-module/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +47 -29
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +3 -0
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +23 -8
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/field-types/array.js +2 -2
- package/build-module/field-types/array.js.map +1 -1
- package/build-module/normalize-form-fields.js +50 -13
- package/build-module/normalize-form-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +53 -16
- package/build-style/style.css +53 -16
- package/build-types/components/dataform/stories/index.story.d.ts +41 -17
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts +5 -2
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +2 -1
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +4 -1
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts +2 -0
- package/build-types/components/dataviews-view-config/infinite-scroll-toggle.d.ts.map +1 -0
- package/build-types/dataform-controls/array.d.ts +6 -0
- package/build-types/dataform-controls/array.d.ts.map +1 -0
- package/build-types/dataform-controls/boolean.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts.map +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/integer.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataforms-layouts/card/index.d.ts +13 -0
- package/build-types/dataforms-layouts/card/index.d.ts.map +1 -0
- package/build-types/dataforms-layouts/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/dropdown.d.ts +14 -0
- package/build-types/dataforms-layouts/panel/dropdown.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/panel/modal.d.ts +13 -0
- package/build-types/dataforms-layouts/panel/modal.d.ts.map +1 -0
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.d.ts +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.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/boolean.d.ts +1 -1
- package/build-types/normalize-form-fields.d.ts +10 -3
- package/build-types/normalize-form-fields.d.ts.map +1 -1
- package/build-types/test/normalize-form-fields.d.ts +2 -0
- package/build-types/test/normalize-form-fields.d.ts.map +1 -0
- package/build-types/types.d.ts +54 -6
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +3062 -1147
- package/package.json +15 -15
- package/src/components/dataform/stories/index.story.tsx +478 -91
- package/src/components/dataviews/index.tsx +50 -14
- package/src/components/dataviews/stories/fixtures.tsx +98 -7
- package/src/components/dataviews/stories/index.story.tsx +137 -4
- package/src/components/dataviews/style.scss +4 -0
- package/src/components/dataviews-context/index.ts +6 -2
- package/src/components/dataviews-item-actions/index.tsx +7 -16
- package/src/components/dataviews-pagination/index.tsx +1 -1
- package/src/components/dataviews-view-config/index.tsx +13 -5
- package/src/components/dataviews-view-config/infinite-scroll-toggle.tsx +39 -0
- package/src/dataform-controls/array.tsx +85 -0
- package/src/dataform-controls/boolean.tsx +24 -10
- package/src/dataform-controls/email.tsx +24 -11
- package/src/dataform-controls/index.tsx +3 -1
- package/src/dataform-controls/integer.tsx +27 -13
- package/src/dataform-controls/text.tsx +24 -11
- package/src/dataforms-layouts/card/index.tsx +154 -0
- package/src/dataforms-layouts/card/style.scss +3 -0
- package/src/dataforms-layouts/data-form-layout.tsx +2 -2
- package/src/dataforms-layouts/index.tsx +5 -0
- package/src/dataforms-layouts/panel/dropdown.tsx +160 -0
- package/src/dataforms-layouts/panel/index.tsx +49 -189
- package/src/dataforms-layouts/panel/modal.tsx +165 -0
- package/src/dataforms-layouts/panel/style.scss +4 -0
- package/src/dataforms-layouts/regular/index.tsx +20 -23
- package/src/dataviews-layouts/grid/index.tsx +32 -5
- package/src/dataviews-layouts/grid/preview-size-picker.tsx +15 -13
- package/src/dataviews-layouts/grid/style.scss +3 -1
- package/src/dataviews-layouts/list/index.tsx +65 -31
- package/src/dataviews-layouts/list/style.scss +7 -3
- package/src/dataviews-layouts/table/column-header-menu.tsx +4 -0
- package/src/dataviews-layouts/table/index.tsx +27 -1
- package/src/field-types/array.tsx +1 -1
- package/src/normalize-form-fields.ts +63 -17
- package/src/test/dataform.tsx +181 -3
- package/src/test/dataviews.tsx +38 -0
- package/src/test/filter-and-sort-data-view.js +123 -64
- package/src/test/normalize-form-fields.ts +247 -0
- package/src/types.ts +72 -6
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 7.0.0 (2025-08-20)
|
|
6
|
+
|
|
7
|
+
### Breaking changes
|
|
8
|
+
|
|
9
|
+
- DataForm: introduce a new `card` layout. The `form.type` has been moved under a new `layout` object and it is now `form.layout.type`, check the README for details. [#71100](https://github.com/WordPress/gutenberg/pull/71100)
|
|
10
|
+
- Adds a new `config` prop to DataViews that allows hiding the view config control entirely. The `perPageSizes` prop has been moved to be part of this new prop. [#71173](https://github.com/WordPress/gutenberg/pull/71173)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- Introduce a new `array` DataForm Edit control that supports multi-selection. [#71136](https://github.com/WordPress/gutenberg/pull/71136)
|
|
15
|
+
- Add `enableMoving` option to the `table` layout to allow or disallow column moving left and right. [#71120](https://github.com/WordPress/gutenberg/pull/71120)
|
|
16
|
+
- Add infinite scroll support across all layout types (grid, list, table). Enable infinite scroll by providing an `infiniteScrollHandler` function in the `paginationInfo` prop and toggling the feature in the view configuration. ([#70955](https://github.com/WordPress/gutenberg/pull/70955))
|
|
17
|
+
- Add support for modal in DataForm panel layouts. [#71212](https://github.com/WordPress/gutenberg/pull/71212)
|
|
18
|
+
|
|
19
|
+
### Enhancements
|
|
20
|
+
|
|
21
|
+
- Update DataForm stories to better highlight the library's capabilities ([#71268](https://github.com/WordPress/gutenberg/pull/71268)).
|
|
22
|
+
- Add two smaller sizs to the grid layout ([#71077](https://github.com/WordPress/gutenberg/pull/71077)).
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
- Do not throw exception when `view.layout.previewSize` is smaller than the smallest available size. [#71218](https://github.com/WordPress/gutenberg/pull/71218)
|
|
27
|
+
- Fix actions horizontal layout consistency when all actions are primary. [#71274](https://github.com/WordPress/gutenberg/pull/71274)
|
|
28
|
+
|
|
5
29
|
## 6.0.0 (2025-08-07)
|
|
6
30
|
|
|
7
31
|
### Breaking changes
|
|
@@ -12,7 +36,7 @@
|
|
|
12
36
|
|
|
13
37
|
- Do not render an empty ` ` when the title field has level 0. [#71021](https://github.com/WordPress/gutenberg/pull/71021)
|
|
14
38
|
- When a field type is `array` and it has elements, the select control should allow multi-selection. [#71000](https://github.com/WordPress/gutenberg/pull/71000)
|
|
15
|
-
- Set minimum and maximum number of items in `
|
|
39
|
+
- Set minimum and maximum number of items in `perPageSizes`, so that the UI control is disabled when the list exceeds those limits. [#71004](https://github.com/WordPress/gutenberg/pull/71004)
|
|
16
40
|
- Fix `filterSortAndPaginate` to handle searching fields that have a type of `array` ([#70785](https://github.com/WordPress/gutenberg/pull/70785)).
|
|
17
41
|
- Fix user-input filters: empty value for text and integer filters means there's no value to search for (so it returns all items). It also fixes a type conversion where empty strings for integer were converted to 0 [#70956](https://github.com/WordPress/gutenberg/pull/70956/).
|
|
18
42
|
- Fix Table layout Title's column wrapping and min-width so that long descriptions can be visualized without scrolling. [#70983](https://github.com/WordPress/gutenberg/pull/70983)
|
package/README.md
CHANGED
|
@@ -416,9 +416,9 @@ The component receives the following props:
|
|
|
416
416
|
|
|
417
417
|
React component to be rendered next to the view config button.
|
|
418
418
|
|
|
419
|
-
#### `
|
|
419
|
+
#### `config`: false | { perPageSizes: number[] }
|
|
420
420
|
|
|
421
|
-
|
|
421
|
+
Optional. Set it to `false` to hide the view config control entirely. Pass an object with a list of `perPageSizes` to control the available item counts per page (defaults to `[10, 20, 50, 100]`). `perPageSizes` needs to have a minimum of 2 items and a maximum of 6, otherwise the UI component won't be displayed.
|
|
422
422
|
|
|
423
423
|
#### `empty`: React node
|
|
424
424
|
|
|
@@ -557,15 +557,17 @@ const fields = [
|
|
|
557
557
|
|
|
558
558
|
#### `form`: `Object[]`
|
|
559
559
|
|
|
560
|
-
- `
|
|
561
|
-
- `labelPosition`: either `side`, `top`, or `none`.
|
|
560
|
+
- `layout`: an object describing the layout used to render the top-level fields present in `fields`. See `layout` prop in "Form Field API".
|
|
562
561
|
- `fields`: a list of fields ids that should be rendered. Field ids can also be defined as an object and allow you to define a `layout`, `labelPosition` or `children` if displaying combined fields. See "Form Field API" for a description of every property.
|
|
563
562
|
|
|
564
563
|
Example:
|
|
565
564
|
|
|
566
565
|
```js
|
|
567
566
|
const form = {
|
|
568
|
-
|
|
567
|
+
layout: {
|
|
568
|
+
type: 'panel',
|
|
569
|
+
labelPosition: 'side'
|
|
570
|
+
},
|
|
569
571
|
fields: [
|
|
570
572
|
'title',
|
|
571
573
|
'data',
|
|
@@ -1301,31 +1303,57 @@ Example:
|
|
|
1301
1303
|
|
|
1302
1304
|
### `layout`
|
|
1303
1305
|
|
|
1304
|
-
|
|
1306
|
+
Represents the type of layout used to render the field. It'll be one of Regular, Panel, or Card. This prop is the same as the `form.layout` prop.
|
|
1305
1307
|
|
|
1306
|
-
|
|
1308
|
+
#### Regular
|
|
1307
1309
|
|
|
1308
|
-
|
|
1310
|
+
- `type`: `regular`. Required.
|
|
1311
|
+
- `labelPosition`: one of `side`, `top`, or `none`. Optional. `top` by default.
|
|
1312
|
+
|
|
1313
|
+
For example:
|
|
1309
1314
|
|
|
1310
1315
|
```js
|
|
1311
1316
|
{
|
|
1312
1317
|
id: 'field_id',
|
|
1313
|
-
layout:
|
|
1318
|
+
layout: {
|
|
1319
|
+
type: 'regular',
|
|
1320
|
+
labelPosition: 'side'
|
|
1321
|
+
},
|
|
1314
1322
|
}
|
|
1315
1323
|
```
|
|
1316
1324
|
|
|
1317
|
-
|
|
1325
|
+
#### Panel
|
|
1318
1326
|
|
|
1319
|
-
|
|
1327
|
+
- `type`: `panel`. Required.
|
|
1328
|
+
- `labelPosition`: one of `side`, `top`, or `none`. Optional. `top` by default.
|
|
1320
1329
|
|
|
1321
|
-
|
|
1330
|
+
For example:
|
|
1331
|
+
```js
|
|
1332
|
+
{
|
|
1333
|
+
id: 'field_id',
|
|
1334
|
+
layout: {
|
|
1335
|
+
type: 'panel',
|
|
1336
|
+
labelPosition: 'top'
|
|
1337
|
+
},
|
|
1338
|
+
}
|
|
1339
|
+
```
|
|
1322
1340
|
|
|
1323
|
-
|
|
1341
|
+
#### Card
|
|
1342
|
+
|
|
1343
|
+
- `type`: `card`. Required.
|
|
1344
|
+
- `isOpened`: boolean. Optional. `true` by default.
|
|
1345
|
+
- `withHeader`: boolean. Optional. `true` by default.
|
|
1346
|
+
|
|
1347
|
+
For example:
|
|
1324
1348
|
|
|
1325
1349
|
```js
|
|
1326
1350
|
{
|
|
1327
1351
|
id: 'field_id',
|
|
1328
|
-
|
|
1352
|
+
layout: {
|
|
1353
|
+
type: 'card',
|
|
1354
|
+
isOpened: false,
|
|
1355
|
+
withHeader: true,
|
|
1356
|
+
},
|
|
1329
1357
|
}
|
|
1330
1358
|
```
|
|
1331
1359
|
|
|
@@ -41,7 +41,8 @@ function DefaultUI({
|
|
|
41
41
|
searchLabel = undefined
|
|
42
42
|
}) {
|
|
43
43
|
const {
|
|
44
|
-
isShowingFilter
|
|
44
|
+
isShowingFilter,
|
|
45
|
+
config
|
|
45
46
|
} = (0, _element.useContext)(_dataviewsContext.default);
|
|
46
47
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
47
48
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
@@ -56,13 +57,13 @@ function DefaultUI({
|
|
|
56
57
|
children: [search && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsSearch.default, {
|
|
57
58
|
label: searchLabel
|
|
58
59
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFilters.FiltersToggle, {})]
|
|
59
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
60
|
+
}), (config || header) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
60
61
|
spacing: 1,
|
|
61
62
|
expanded: false,
|
|
62
63
|
style: {
|
|
63
64
|
flexShrink: 0
|
|
64
65
|
},
|
|
65
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsViewConfig.default, {}), header]
|
|
66
|
+
children: ["config && ", /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsViewConfig.default, {}), header]
|
|
66
67
|
})]
|
|
67
68
|
}), isShowingFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsFilters.default, {
|
|
68
69
|
className: "dataviews-filters__container"
|
|
@@ -89,9 +90,14 @@ function DataViews({
|
|
|
89
90
|
isItemClickable = defaultIsItemClickable,
|
|
90
91
|
header,
|
|
91
92
|
children,
|
|
92
|
-
|
|
93
|
+
config = {
|
|
94
|
+
perPageSizes: [10, 20, 50, 100]
|
|
95
|
+
},
|
|
93
96
|
empty
|
|
94
97
|
}) {
|
|
98
|
+
const {
|
|
99
|
+
infiniteScrollHandler
|
|
100
|
+
} = paginationInfo;
|
|
95
101
|
const containerRef = (0, _element.useRef)(null);
|
|
96
102
|
const [containerWidth, setContainerWidth] = (0, _element.useState)(0);
|
|
97
103
|
const resizeObserverRef = (0, _compose.useResizeObserver)(resizeObserverEntries => {
|
|
@@ -124,6 +130,31 @@ function DataViews({
|
|
|
124
130
|
setIsShowingFilter(true);
|
|
125
131
|
}
|
|
126
132
|
}, [hasPrimaryOrLockedFilters, isShowingFilter]);
|
|
133
|
+
|
|
134
|
+
// Attach scroll event listener for infinite scroll
|
|
135
|
+
(0, _element.useEffect)(() => {
|
|
136
|
+
if (!view.infiniteScrollEnabled || !containerRef.current) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const handleScroll = (0, _compose.throttle)(event => {
|
|
140
|
+
const target = event.target;
|
|
141
|
+
const scrollTop = target.scrollTop;
|
|
142
|
+
const scrollHeight = target.scrollHeight;
|
|
143
|
+
const clientHeight = target.clientHeight;
|
|
144
|
+
|
|
145
|
+
// Check if user has scrolled near the bottom
|
|
146
|
+
if (scrollTop + clientHeight >= scrollHeight - 100) {
|
|
147
|
+
infiniteScrollHandler?.();
|
|
148
|
+
}
|
|
149
|
+
}, 100); // Throttle to 100ms
|
|
150
|
+
|
|
151
|
+
const container = containerRef.current;
|
|
152
|
+
container.addEventListener('scroll', handleScroll);
|
|
153
|
+
return () => {
|
|
154
|
+
container.removeEventListener('scroll', handleScroll);
|
|
155
|
+
handleScroll.cancel(); // Cancel any pending throttled calls
|
|
156
|
+
};
|
|
157
|
+
}, [infiniteScrollHandler, view.infiniteScrollEnabled]);
|
|
127
158
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_dataviewsContext.default.Provider, {
|
|
128
159
|
value: {
|
|
129
160
|
view,
|
|
@@ -149,8 +180,9 @@ function DataViews({
|
|
|
149
180
|
filters,
|
|
150
181
|
isShowingFilter,
|
|
151
182
|
setIsShowingFilter,
|
|
152
|
-
|
|
153
|
-
empty
|
|
183
|
+
config,
|
|
184
|
+
empty,
|
|
185
|
+
hasInfiniteScrollHandler: !!infiniteScrollHandler
|
|
154
186
|
},
|
|
155
187
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
156
188
|
className: "dataviews-wrapper",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_compose","_dataviewsContext","_interopRequireDefault","_dataviewsFilters","_interopRequireWildcard","_dataviewsLayout","_dataviewsFooter","_dataviewsSearch","_dataviewsBulkActions","_dataviewsPagination","_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","defaultIsItemClickable","EMPTY_ARRAY","DefaultUI","header","search","searchLabel","undefined","isShowingFilter","useContext","DataViewsContext","jsxs","Fragment","children","__experimentalHStack","alignment","justify","className","spacing","expanded","jsx","label","FiltersToggle","style","flexShrink","DataViews","view","onChangeView","fields","actions","data","getItemId","getItemLevel","isLoading","paginationInfo","defaultLayouts","selection","selectionProperty","onChangeSelection","onClickItem","renderItemLink","isItemClickable","perPageSizes","empty","containerRef","useRef","containerWidth","setContainerWidth","useState","resizeObserverRef","useResizeObserver","resizeObserverEntries","borderBoxSize","inlineSize","box","selectionState","setSelectionState","isUncontrolled","openedFilter","setOpenedFilter","setSelectionWithChange","value","newValue","_fields","useMemo","normalizeFields","_selection","filter","some","filters","useFilters","hasPrimaryOrLockedFilters","isPrimary","isLocked","setIsShowingFilter","useEffect","Provider","ref","DataViewsSubComponents","BulkActionToolbar","BulkActionsFooter","Filters","DataViewsFilters","Layout","DataViewsLayout","LayoutSwitcher","ViewTypeMenu","Pagination","DataViewsPagination","Search","DataViewsSearch","ViewConfig","DataviewsViewConfigDropdown","_default","exports"],"sources":["@wordpress/dataviews/src/components/dataviews/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode, ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useResizeObserver } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport {\n\tdefault as DataViewsFilters,\n\tuseFilters,\n\tFiltersToggle,\n} from '../dataviews-filters';\nimport DataViewsLayout from '../dataviews-layout';\nimport DataViewsFooter from '../dataviews-footer';\nimport DataViewsSearch from '../dataviews-search';\nimport { BulkActionsFooter } from '../dataviews-bulk-actions';\nimport { DataViewsPagination } from '../dataviews-pagination';\nimport DataViewsViewConfig, {\n\tDataviewsViewConfigDropdown,\n\tViewTypeMenu,\n} from '../dataviews-view-config';\nimport { normalizeFields } from '../../normalize-fields';\nimport type { Action, Field, View, SupportedLayouts } from '../../types';\nimport type { SelectionOrUpdater } from '../../private-types';\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\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable?: ( item: Item ) => boolean;\n\theader?: ReactNode;\n\tgetItemLevel?: ( item: Item ) => number;\n\tchildren?: ReactNode;\n\tperPageSizes?: number[];\n\tempty?: ReactNode;\n} & ( Item extends ItemWithId\n\t? { getItemId?: ( item: Item ) => string }\n\t: { getItemId: ( item: Item ) => string } );\n\nconst defaultGetItemId = ( item: ItemWithId ) => item.id;\nconst defaultIsItemClickable = () => true;\nconst EMPTY_ARRAY: any[] = [];\n\ntype DefaultUIProps = Pick<\n\tDataViewsProps< any >,\n\t'header' | 'search' | 'searchLabel'\n>;\n\nfunction DefaultUI( {\n\theader,\n\tsearch = true,\n\tsearchLabel = undefined,\n}: DefaultUIProps ) {\n\tconst { isShowingFilter } = useContext( DataViewsContext );\n\treturn (\n\t\t<>\n\t\t\t<HStack\n\t\t\t\talignment=\"top\"\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews__view-actions\"\n\t\t\t\tspacing={ 1 }\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tclassName=\"dataviews__search\"\n\t\t\t\t>\n\t\t\t\t\t{ search && <DataViewsSearch label={ searchLabel } /> }\n\t\t\t\t\t<FiltersToggle />\n\t\t\t\t</HStack>\n\t\t\t\t<HStack\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tstyle={ { flexShrink: 0 } }\n\t\t\t\t>\n\t\t\t\t\t<DataViewsViewConfig />\n\t\t\t\t\t{ header }\n\t\t\t\t</HStack>\n\t\t\t</HStack>\n\t\t\t{ isShowingFilter && (\n\t\t\t\t<DataViewsFilters className=\"dataviews-filters__container\" />\n\t\t\t) }\n\t\t\t<DataViewsLayout />\n\t\t\t<DataViewsFooter />\n\t\t</>\n\t);\n}\n\nfunction DataViews< Item >( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions = EMPTY_ARRAY,\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tgetItemLevel,\n\tisLoading = false,\n\tpaginationInfo,\n\tdefaultLayouts,\n\tselection: selectionProperty,\n\tonChangeSelection,\n\tonClickItem,\n\trenderItemLink,\n\tisItemClickable = defaultIsItemClickable,\n\theader,\n\tchildren,\n\tperPageSizes = [ 10, 20, 50, 100 ],\n\tempty,\n}: DataViewsProps< Item > ) {\n\tconst containerRef = useRef< HTMLDivElement | null >( null );\n\tconst [ containerWidth, setContainerWidth ] = useState( 0 );\n\tconst resizeObserverRef = useResizeObserver(\n\t\t( resizeObserverEntries: any ) => {\n\t\t\tsetContainerWidth(\n\t\t\t\tresizeObserverEntries[ 0 ].borderBoxSize[ 0 ].inlineSize\n\t\t\t);\n\t\t},\n\t\t{ box: 'border-box' }\n\t);\n\tconst [ selectionState, setSelectionState ] = useState< string[] >( [] );\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 hasPrimaryOrLockedFilters = useMemo(\n\t\t() =>\n\t\t\t( filters || [] ).some(\n\t\t\t\t( filter ) => filter.isPrimary || filter.isLocked\n\t\t\t),\n\t\t[ filters ]\n\t);\n\tconst [ isShowingFilter, setIsShowingFilter ] = useState< boolean >(\n\t\thasPrimaryOrLockedFilters\n\t);\n\n\tuseEffect( () => {\n\t\tif ( hasPrimaryOrLockedFilters && ! isShowingFilter ) {\n\t\t\tsetIsShowingFilter( true );\n\t\t}\n\t}, [ hasPrimaryOrLockedFilters, isShowingFilter ] );\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\tgetItemLevel,\n\t\t\t\tisItemClickable,\n\t\t\t\tonClickItem,\n\t\t\t\trenderItemLink,\n\t\t\t\tcontainerWidth,\n\t\t\t\tcontainerRef,\n\t\t\t\tresizeObserverRef,\n\t\t\t\tdefaultLayouts,\n\t\t\t\tfilters,\n\t\t\t\tisShowingFilter,\n\t\t\t\tsetIsShowingFilter,\n\t\t\t\tperPageSizes,\n\t\t\t\tempty,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-wrapper\" ref={ containerRef }>\n\t\t\t\t{ children ?? (\n\t\t\t\t\t<DefaultUI\n\t\t\t\t\t\theader={ header }\n\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\tsearchLabel={ searchLabel }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</DataViewsContext.Provider>\n\t);\n}\n\n// Populate the DataViews sub components\nconst DataViewsSubComponents = DataViews as typeof DataViews & {\n\tBulkActionToolbar: typeof BulkActionsFooter;\n\tFilters: typeof DataViewsFilters;\n\tFiltersToggle: typeof FiltersToggle;\n\tLayout: typeof DataViewsLayout;\n\tLayoutSwitcher: typeof ViewTypeMenu;\n\tPagination: typeof DataViewsPagination;\n\tSearch: typeof DataViewsSearch;\n\tViewConfig: typeof DataviewsViewConfigDropdown;\n};\n\nDataViewsSubComponents.BulkActionToolbar = BulkActionsFooter;\nDataViewsSubComponents.Filters = DataViewsFilters;\nDataViewsSubComponents.FiltersToggle = FiltersToggle;\nDataViewsSubComponents.Layout = DataViewsLayout;\nDataViewsSubComponents.LayoutSwitcher = ViewTypeMenu;\nDataViewsSubComponents.Pagination = DataViewsPagination;\nDataViewsSubComponents.Search = DataViewsSearch;\nDataViewsSubComponents.ViewConfig = DataviewsViewConfigDropdown;\n\nexport default DataViewsSubComponents;\n"],"mappings":";;;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAOA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,iBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAC,uBAAA,CAAAN,OAAA;AAKA,IAAAO,gBAAA,GA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AACA,MAAMwE,sBAAsB,GAAGrD,SAS9B;AAEDqD,sBAAsB,CAACC,iBAAiB,GAAGC,uCAAiB;AAC5DF,sBAAsB,CAACG,OAAO,GAAGC,yBAAgB;AACjDJ,sBAAsB,CAACxD,aAAa,GAAGA,+BAAa;AACpDwD,sBAAsB,CAACK,MAAM,GAAGC,wBAAe;AAC/CN,sBAAsB,CAACO,cAAc,GAAGC,iCAAY;AACpDR,sBAAsB,CAACS,UAAU,GAAGC,wCAAmB;AACvDV,sBAAsB,CAACW,MAAM,GAAGC,wBAAe;AAC/CZ,sBAAsB,CAACa,UAAU,GAAGC,gDAA2B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA9G,OAAA,GAEjD8F,sBAAsB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_compose","_dataviewsContext","_interopRequireDefault","_dataviewsFilters","_interopRequireWildcard","_dataviewsLayout","_dataviewsFooter","_dataviewsSearch","_dataviewsBulkActions","_dataviewsPagination","_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","defaultIsItemClickable","EMPTY_ARRAY","DefaultUI","header","search","searchLabel","undefined","isShowingFilter","config","useContext","DataViewsContext","jsxs","Fragment","children","__experimentalHStack","alignment","justify","className","spacing","expanded","jsx","label","FiltersToggle","style","flexShrink","DataViews","view","onChangeView","fields","actions","data","getItemId","getItemLevel","isLoading","paginationInfo","defaultLayouts","selection","selectionProperty","onChangeSelection","onClickItem","renderItemLink","isItemClickable","perPageSizes","empty","infiniteScrollHandler","containerRef","useRef","containerWidth","setContainerWidth","useState","resizeObserverRef","useResizeObserver","resizeObserverEntries","borderBoxSize","inlineSize","box","selectionState","setSelectionState","isUncontrolled","openedFilter","setOpenedFilter","setSelectionWithChange","value","newValue","_fields","useMemo","normalizeFields","_selection","filter","some","filters","useFilters","hasPrimaryOrLockedFilters","isPrimary","isLocked","setIsShowingFilter","useEffect","infiniteScrollEnabled","current","handleScroll","throttle","event","target","scrollTop","scrollHeight","clientHeight","container","addEventListener","removeEventListener","cancel","Provider","hasInfiniteScrollHandler","ref","DataViewsSubComponents","BulkActionToolbar","BulkActionsFooter","Filters","DataViewsFilters","Layout","DataViewsLayout","LayoutSwitcher","ViewTypeMenu","Pagination","DataViewsPagination","Search","DataViewsSearch","ViewConfig","DataviewsViewConfigDropdown","_default","exports"],"sources":["@wordpress/dataviews/src/components/dataviews/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactNode, ComponentProps, ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport {\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\nimport { useResizeObserver, throttle } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\nimport {\n\tdefault as DataViewsFilters,\n\tuseFilters,\n\tFiltersToggle,\n} from '../dataviews-filters';\nimport DataViewsLayout from '../dataviews-layout';\nimport DataViewsFooter from '../dataviews-footer';\nimport DataViewsSearch from '../dataviews-search';\nimport { BulkActionsFooter } from '../dataviews-bulk-actions';\nimport { DataViewsPagination } from '../dataviews-pagination';\nimport DataViewsViewConfig, {\n\tDataviewsViewConfigDropdown,\n\tViewTypeMenu,\n} from '../dataviews-view-config';\nimport { normalizeFields } from '../../normalize-fields';\nimport type { Action, Field, View, SupportedLayouts } from '../../types';\nimport type { SelectionOrUpdater } from '../../private-types';\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\tinfiniteScrollHandler?: () => void;\n\t};\n\tdefaultLayouts: SupportedLayouts;\n\tselection?: string[];\n\tonChangeSelection?: ( items: string[] ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable?: ( item: Item ) => boolean;\n\theader?: ReactNode;\n\tgetItemLevel?: ( item: Item ) => number;\n\tchildren?: ReactNode;\n\tconfig?:\n\t\t| false\n\t\t| {\n\t\t\t\tperPageSizes: number[];\n\t\t };\n\tempty?: ReactNode;\n} & ( Item extends ItemWithId\n\t? { getItemId?: ( item: Item ) => string }\n\t: { getItemId: ( item: Item ) => string } );\n\nconst defaultGetItemId = ( item: ItemWithId ) => item.id;\nconst defaultIsItemClickable = () => true;\nconst EMPTY_ARRAY: any[] = [];\n\ntype DefaultUIProps = Pick<\n\tDataViewsProps< any >,\n\t'header' | 'search' | 'searchLabel'\n>;\n\nfunction DefaultUI( {\n\theader,\n\tsearch = true,\n\tsearchLabel = undefined,\n}: DefaultUIProps ) {\n\tconst { isShowingFilter, config } = useContext( DataViewsContext );\n\treturn (\n\t\t<>\n\t\t\t<HStack\n\t\t\t\talignment=\"top\"\n\t\t\t\tjustify=\"space-between\"\n\t\t\t\tclassName=\"dataviews__view-actions\"\n\t\t\t\tspacing={ 1 }\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tclassName=\"dataviews__search\"\n\t\t\t\t>\n\t\t\t\t\t{ search && <DataViewsSearch label={ searchLabel } /> }\n\t\t\t\t\t<FiltersToggle />\n\t\t\t\t</HStack>\n\t\t\t\t{ ( config || header ) && (\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\tconfig && <DataViewsViewConfig />\n\t\t\t\t\t\t{ header }\n\t\t\t\t\t</HStack>\n\t\t\t\t) }\n\t\t\t</HStack>\n\t\t\t{ isShowingFilter && (\n\t\t\t\t<DataViewsFilters className=\"dataviews-filters__container\" />\n\t\t\t) }\n\t\t\t<DataViewsLayout />\n\t\t\t<DataViewsFooter />\n\t\t</>\n\t);\n}\n\nfunction DataViews< Item >( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions = EMPTY_ARRAY,\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tgetItemLevel,\n\tisLoading = false,\n\tpaginationInfo,\n\tdefaultLayouts,\n\tselection: selectionProperty,\n\tonChangeSelection,\n\tonClickItem,\n\trenderItemLink,\n\tisItemClickable = defaultIsItemClickable,\n\theader,\n\tchildren,\n\tconfig = { perPageSizes: [ 10, 20, 50, 100 ] },\n\tempty,\n}: DataViewsProps< Item > ) {\n\tconst { infiniteScrollHandler } = paginationInfo;\n\tconst containerRef = useRef< HTMLDivElement | null >( null );\n\tconst [ containerWidth, setContainerWidth ] = useState( 0 );\n\tconst resizeObserverRef = useResizeObserver(\n\t\t( resizeObserverEntries: any ) => {\n\t\t\tsetContainerWidth(\n\t\t\t\tresizeObserverEntries[ 0 ].borderBoxSize[ 0 ].inlineSize\n\t\t\t);\n\t\t},\n\t\t{ box: 'border-box' }\n\t);\n\tconst [ selectionState, setSelectionState ] = useState< string[] >( [] );\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 hasPrimaryOrLockedFilters = useMemo(\n\t\t() =>\n\t\t\t( filters || [] ).some(\n\t\t\t\t( filter ) => filter.isPrimary || filter.isLocked\n\t\t\t),\n\t\t[ filters ]\n\t);\n\tconst [ isShowingFilter, setIsShowingFilter ] = useState< boolean >(\n\t\thasPrimaryOrLockedFilters\n\t);\n\n\tuseEffect( () => {\n\t\tif ( hasPrimaryOrLockedFilters && ! isShowingFilter ) {\n\t\t\tsetIsShowingFilter( true );\n\t\t}\n\t}, [ hasPrimaryOrLockedFilters, isShowingFilter ] );\n\n\t// Attach scroll event listener for infinite scroll\n\tuseEffect( () => {\n\t\tif ( ! view.infiniteScrollEnabled || ! containerRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst handleScroll = throttle( ( event: unknown ) => {\n\t\t\tconst target = ( event as Event ).target as HTMLElement;\n\t\t\tconst scrollTop = target.scrollTop;\n\t\t\tconst scrollHeight = target.scrollHeight;\n\t\t\tconst clientHeight = target.clientHeight;\n\n\t\t\t// Check if user has scrolled near the bottom\n\t\t\tif ( scrollTop + clientHeight >= scrollHeight - 100 ) {\n\t\t\t\tinfiniteScrollHandler?.();\n\t\t\t}\n\t\t}, 100 ); // Throttle to 100ms\n\n\t\tconst container = containerRef.current;\n\t\tcontainer.addEventListener( 'scroll', handleScroll );\n\n\t\treturn () => {\n\t\t\tcontainer.removeEventListener( 'scroll', handleScroll );\n\t\t\thandleScroll.cancel(); // Cancel any pending throttled calls\n\t\t};\n\t}, [ infiniteScrollHandler, view.infiniteScrollEnabled ] );\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\tgetItemLevel,\n\t\t\t\tisItemClickable,\n\t\t\t\tonClickItem,\n\t\t\t\trenderItemLink,\n\t\t\t\tcontainerWidth,\n\t\t\t\tcontainerRef,\n\t\t\t\tresizeObserverRef,\n\t\t\t\tdefaultLayouts,\n\t\t\t\tfilters,\n\t\t\t\tisShowingFilter,\n\t\t\t\tsetIsShowingFilter,\n\t\t\t\tconfig,\n\t\t\t\tempty,\n\t\t\t\thasInfiniteScrollHandler: !! infiniteScrollHandler,\n\t\t\t} }\n\t\t>\n\t\t\t<div className=\"dataviews-wrapper\" ref={ containerRef }>\n\t\t\t\t{ children ?? (\n\t\t\t\t\t<DefaultUI\n\t\t\t\t\t\theader={ header }\n\t\t\t\t\t\tsearch={ search }\n\t\t\t\t\t\tsearchLabel={ searchLabel }\n\t\t\t\t\t/>\n\t\t\t\t) }\n\t\t\t</div>\n\t\t</DataViewsContext.Provider>\n\t);\n}\n\n// Populate the DataViews sub components\nconst DataViewsSubComponents = DataViews as typeof DataViews & {\n\tBulkActionToolbar: typeof BulkActionsFooter;\n\tFilters: typeof DataViewsFilters;\n\tFiltersToggle: typeof FiltersToggle;\n\tLayout: typeof DataViewsLayout;\n\tLayoutSwitcher: typeof ViewTypeMenu;\n\tPagination: typeof DataViewsPagination;\n\tSearch: typeof DataViewsSearch;\n\tViewConfig: typeof DataviewsViewConfigDropdown;\n};\n\nDataViewsSubComponents.BulkActionToolbar = BulkActionsFooter;\nDataViewsSubComponents.Filters = DataViewsFilters;\nDataViewsSubComponents.FiltersToggle = FiltersToggle;\nDataViewsSubComponents.Layout = DataViewsLayout;\nDataViewsSubComponents.LayoutSwitcher = ViewTypeMenu;\nDataViewsSubComponents.Pagination = DataViewsPagination;\nDataViewsSubComponents.Search = DataViewsSearch;\nDataViewsSubComponents.ViewConfig = DataviewsViewConfigDropdown;\n\nexport default DataViewsSubComponents;\n"],"mappings":";;;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAOA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,iBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAC,uBAAA,CAAAN,OAAA;AAKA,IAAAO,gBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AACA,IAAAQ,gBAAA,GAAAJ,sBAAA,CAAAJ,OAAA;AACA,IAAAS,gBAAA,GAAAL,sBAAA,CAAAJ,OAAA;AACA,IAAAU,qBAAA,GAAAV,OAAA;AACA,IAAAW,oBAAA,GAAAX,OAAA;AACA,IAAAY,oBAAA,GAAAN,uBAAA,CAAAN,OAAA;AAIA,IAAAa,gBAAA,GAAAb,OAAA;AAAyD,IAAAc,WAAA,GAAAd,OAAA;AAAA,SAAAe,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAV,wBAAAU,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC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,gBACT,IAAArC,WAAA,CAAA4C,GAAA,EAAClB,SAAS;QACTC,MAAM,EAAGA,MAAQ;QACjBC,MAAM,EAAGA,MAAQ;QACjBC,WAAW,EAAGA;MAAa,CAC3B;IAAC,CAEC;EAAC,CACoB,CAAC;AAE9B;;AAEA;AACA,MAAMwF,sBAAsB,GAAGpE,SAS9B;AAEDoE,sBAAsB,CAACC,iBAAiB,GAAGC,uCAAiB;AAC5DF,sBAAsB,CAACG,OAAO,GAAGC,yBAAgB;AACjDJ,sBAAsB,CAACvE,aAAa,GAAGA,+BAAa;AACpDuE,sBAAsB,CAACK,MAAM,GAAGC,wBAAe;AAC/CN,sBAAsB,CAACO,cAAc,GAAGC,iCAAY;AACpDR,sBAAsB,CAACS,UAAU,GAAGC,wCAAmB;AACvDV,sBAAsB,CAACW,MAAM,GAAGC,wBAAe;AAC/CZ,sBAAsB,CAACa,UAAU,GAAGC,gDAA2B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA9H,OAAA,GAEjD8G,sBAAsB","ignoreList":[]}
|
|
@@ -47,7 +47,10 @@ const DataViewsContext = (0, _element.createContext)({
|
|
|
47
47
|
filters: [],
|
|
48
48
|
isShowingFilter: false,
|
|
49
49
|
setIsShowingFilter: () => {},
|
|
50
|
-
|
|
50
|
+
hasInfiniteScrollHandler: false,
|
|
51
|
+
config: {
|
|
52
|
+
perPageSizes: []
|
|
53
|
+
}
|
|
51
54
|
});
|
|
52
55
|
var _default = exports.default = DataViewsContext;
|
|
53
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_constants","DataViewsContext","createContext","view","type","LAYOUT_TABLE","onChangeView","fields","data","paginationInfo","totalItems","totalPages","selection","onChangeSelection","setOpenedFilter","openedFilter","getItemId","item","id","isItemClickable","renderItemLink","undefined","containerWidth","containerRef","createRef","resizeObserverRef","defaultLayouts","list","grid","table","filters","isShowingFilter","setIsShowingFilter","perPageSizes","_default","exports","default"],"sources":["@wordpress/dataviews/src/components/dataviews-context/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { createContext, createRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tAction,\n\tNormalizedField,\n\tSupportedLayouts,\n\tNormalizedFilter,\n} from '../../types';\nimport type { SetSelection } from '../../private-types';\nimport { LAYOUT_TABLE } from '../../constants';\n\ntype DataViewsContextType< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< Item >[];\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\topenedFilter: string | null;\n\tsetOpenedFilter: ( openedFilter: string | null ) => void;\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tcontainerWidth: number;\n\tcontainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tresizeObserverRef:\n\t\t| ( ( element?: HTMLDivElement | null ) => void )\n\t\t| React.RefObject< HTMLDivElement >;\n\tdefaultLayouts: SupportedLayouts;\n\tfilters: NormalizedFilter[];\n\tisShowingFilter: boolean;\n\tsetIsShowingFilter: ( value: boolean ) => void;\n\
|
|
1
|
+
{"version":3,"names":["_element","require","_constants","DataViewsContext","createContext","view","type","LAYOUT_TABLE","onChangeView","fields","data","paginationInfo","totalItems","totalPages","selection","onChangeSelection","setOpenedFilter","openedFilter","getItemId","item","id","isItemClickable","renderItemLink","undefined","containerWidth","containerRef","createRef","resizeObserverRef","defaultLayouts","list","grid","table","filters","isShowingFilter","setIsShowingFilter","hasInfiniteScrollHandler","config","perPageSizes","_default","exports","default"],"sources":["@wordpress/dataviews/src/components/dataviews-context/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ComponentProps, ReactElement, ReactNode } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { createContext, createRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tAction,\n\tNormalizedField,\n\tSupportedLayouts,\n\tNormalizedFilter,\n} from '../../types';\nimport type { SetSelection } from '../../private-types';\nimport { LAYOUT_TABLE } from '../../constants';\n\ntype DataViewsContextType< Item > = {\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< Item >[];\n\tactions?: Action< Item >[];\n\tdata: Item[];\n\tisLoading?: boolean;\n\tpaginationInfo: {\n\t\ttotalItems: number;\n\t\ttotalPages: number;\n\t};\n\tselection: string[];\n\tonChangeSelection: SetSelection;\n\topenedFilter: string | null;\n\tsetOpenedFilter: ( openedFilter: string | null ) => void;\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tcontainerWidth: number;\n\tcontainerRef: React.MutableRefObject< HTMLDivElement | null >;\n\tresizeObserverRef:\n\t\t| ( ( element?: HTMLDivElement | null ) => void )\n\t\t| React.RefObject< HTMLDivElement >;\n\tdefaultLayouts: SupportedLayouts;\n\tfilters: NormalizedFilter[];\n\tisShowingFilter: boolean;\n\tsetIsShowingFilter: ( value: boolean ) => void;\n\tconfig: false | { perPageSizes: number[] };\n\tempty?: ReactNode;\n\thasInfiniteScrollHandler: boolean;\n};\n\nconst DataViewsContext = createContext< DataViewsContextType< any > >( {\n\tview: { type: LAYOUT_TABLE },\n\tonChangeView: () => {},\n\tfields: [],\n\tdata: [],\n\tpaginationInfo: {\n\t\ttotalItems: 0,\n\t\ttotalPages: 0,\n\t},\n\tselection: [],\n\tonChangeSelection: () => {},\n\tsetOpenedFilter: () => {},\n\topenedFilter: null,\n\tgetItemId: ( item ) => item.id,\n\tisItemClickable: () => true,\n\trenderItemLink: undefined,\n\tcontainerWidth: 0,\n\tcontainerRef: createRef(),\n\tresizeObserverRef: () => {},\n\tdefaultLayouts: { list: {}, grid: {}, table: {} },\n\tfilters: [],\n\tisShowingFilter: false,\n\tsetIsShowingFilter: () => {},\n\thasInfiniteScrollHandler: false,\n\tconfig: {\n\t\tperPageSizes: [],\n\t},\n} );\n\nexport default DataViewsContext;\n"],"mappings":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAaA,IAAAC,UAAA,GAAAD,OAAA;AArBA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAiDA,MAAME,gBAAgB,GAAG,IAAAC,sBAAa,EAAiC;EACtEC,IAAI,EAAE;IAAEC,IAAI,EAAEC;EAAa,CAAC;EAC5BC,YAAY,EAAEA,CAAA,KAAM,CAAC,CAAC;EACtBC,MAAM,EAAE,EAAE;EACVC,IAAI,EAAE,EAAE;EACRC,cAAc,EAAE;IACfC,UAAU,EAAE,CAAC;IACbC,UAAU,EAAE;EACb,CAAC;EACDC,SAAS,EAAE,EAAE;EACbC,iBAAiB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC3BC,eAAe,EAAEA,CAAA,KAAM,CAAC,CAAC;EACzBC,YAAY,EAAE,IAAI;EAClBC,SAAS,EAAIC,IAAI,IAAMA,IAAI,CAACC,EAAE;EAC9BC,eAAe,EAAEA,CAAA,KAAM,IAAI;EAC3BC,cAAc,EAAEC,SAAS;EACzBC,cAAc,EAAE,CAAC;EACjBC,YAAY,EAAE,IAAAC,kBAAS,EAAC,CAAC;EACzBC,iBAAiB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC3BC,cAAc,EAAE;IAAEC,IAAI,EAAE,CAAC,CAAC;IAAEC,IAAI,EAAE,CAAC,CAAC;IAAEC,KAAK,EAAE,CAAC;EAAE,CAAC;EACjDC,OAAO,EAAE,EAAE;EACXC,eAAe,EAAE,KAAK;EACtBC,kBAAkB,EAAEA,CAAA,KAAM,CAAC,CAAC;EAC5BC,wBAAwB,EAAE,KAAK;EAC/BC,MAAM,EAAE;IACPC,YAAY,EAAE;EACf;AACD,CAAE,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEWrC,gBAAgB","ignoreList":[]}
|
|
@@ -128,15 +128,6 @@ function ItemActions({
|
|
|
128
128
|
registry: registry
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
// If all actions are primary, there is no need to render the dropdown.
|
|
133
|
-
if (primaryActions.length === eligibleActions.length) {
|
|
134
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PrimaryActions, {
|
|
135
|
-
item: item,
|
|
136
|
-
actions: primaryActions,
|
|
137
|
-
registry: registry
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
131
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
|
|
141
132
|
spacing: 1,
|
|
142
133
|
justify: "flex-end",
|
|
@@ -149,7 +140,7 @@ function ItemActions({
|
|
|
149
140
|
item: item,
|
|
150
141
|
actions: primaryActions,
|
|
151
142
|
registry: registry
|
|
152
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(CompactItemActions, {
|
|
143
|
+
}), primaryActions.length < eligibleActions.length && /*#__PURE__*/(0, _jsxRuntime.jsx)(CompactItemActions, {
|
|
153
144
|
item: item,
|
|
154
145
|
actions: eligibleActions,
|
|
155
146
|
registry: registry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_i18n","_element","_icons","_data","_lockUnlock","_jsxRuntime","Menu","kebabCase","unlock","componentsPrivateApis","ButtonTrigger","action","onClick","items","label","jsx","Button","icon","disabled","accessibleWhenDisabled","isDestructive","size","MenuItemTrigger","Item","children","ItemLabel","ActionModal","closeModal","_action$modalFocusOnM","Modal","title","modalHeader","__experimentalHideHeader","hideModalHeader","onRequestClose","focusOnMount","modalFocusOnMount","modalSize","overlayClassName","id","RenderModal","ActionsMenuGroup","actions","item","registry","setActiveModalAction","Group","map","callback","ItemActions","isCompact","useRegistry","primaryActions","eligibleActions","useMemo","_eligibleActions","filter","isEligible","_primaryActions","isPrimary","CompactItemActions","isSmall","length","PrimaryActions","jsxs","__experimentalHStack","spacing","justify","className","style","flexShrink","width","activeModalAction","useState","Fragment","placement","TriggerButton","render","moreVertical","__","Popover","Array","isArray"],"sources":["@wordpress/dataviews/src/components/dataviews-item-actions/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { MouseEventHandler } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport type { Action, ActionModal as ActionModalType } from '../../types';\n\nconst { Menu, kebabCase } = unlock( componentsPrivateApis );\n\nexport interface ActionTriggerProps< Item > {\n\taction: Action< Item >;\n\tonClick: MouseEventHandler;\n\tisBusy?: boolean;\n\titems: Item[];\n}\n\nexport interface ActionModalProps< Item > {\n\taction: ActionModalType< Item >;\n\titems: Item[];\n\tcloseModal: () => void;\n}\n\ninterface ActionsMenuGroupProps< Item > {\n\tactions: Action< Item >[];\n\titem: Item;\n\tregistry: ReturnType< typeof useRegistry >;\n\tsetActiveModalAction: ( action: ActionModalType< Item > | null ) => void;\n}\n\ninterface ItemActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tisCompact?: boolean;\n}\n\ninterface CompactItemActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tisSmall?: boolean;\n\tregistry: ReturnType< typeof useRegistry >;\n}\n\ninterface PrimaryActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tregistry: ReturnType< typeof useRegistry >;\n}\n\nfunction ButtonTrigger< Item >( {\n\taction,\n\tonClick,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Button\n\t\t\tlabel={ label }\n\t\t\ticon={ action.icon }\n\t\t\tdisabled={ !! action.disabled }\n\t\t\taccessibleWhenDisabled\n\t\t\tisDestructive={ action.isDestructive }\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t/>\n\t);\n}\n\nfunction MenuItemTrigger< Item >( {\n\taction,\n\tonClick,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Menu.Item disabled={ action.disabled } onClick={ onClick }>\n\t\t\t<Menu.ItemLabel>{ label }</Menu.ItemLabel>\n\t\t</Menu.Item>\n\t);\n}\n\nexport function ActionModal< Item >( {\n\taction,\n\titems,\n\tcloseModal,\n}: ActionModalProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ action.modalHeader || label }\n\t\t\t__experimentalHideHeader={ !! action.hideModalHeader }\n\t\t\tonRequestClose={ closeModal }\n\t\t\tfocusOnMount={ action.modalFocusOnMount ?? true }\n\t\t\tsize={ action.modalSize || 'medium' }\n\t\t\toverlayClassName={ `dataviews-action-modal dataviews-action-modal__${ kebabCase(\n\t\t\t\taction.id\n\t\t\t) }` }\n\t\t>\n\t\t\t<action.RenderModal items={ items } closeModal={ closeModal } />\n\t\t</Modal>\n\t);\n}\n\nexport function ActionsMenuGroup< Item >( {\n\tactions,\n\titem,\n\tregistry,\n\tsetActiveModalAction,\n}: ActionsMenuGroupProps< Item > ) {\n\treturn (\n\t\t<Menu.Group>\n\t\t\t{ actions.map( ( action ) => (\n\t\t\t\t<MenuItemTrigger\n\t\t\t\t\tkey={ action.id }\n\t\t\t\t\taction={ action }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\tsetActiveModalAction( action );\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\taction.callback( [ item ], { registry } );\n\t\t\t\t\t} }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Menu.Group>\n\t);\n}\n\nexport default function ItemActions< Item >( {\n\titem,\n\tactions,\n\tisCompact,\n}: ItemActionsProps< Item > ) {\n\tconst registry = useRegistry();\n\tconst { primaryActions, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary && !! action.icon\n\t\t);\n\t\treturn {\n\t\t\tprimaryActions: _primaryActions,\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tif ( isCompact ) {\n\t\treturn (\n\t\t\t<CompactItemActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ eligibleActions }\n\t\t\t\tisSmall\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t);\n\t}\n\n\t// If all actions are primary, there is no need to render the dropdown.\n\tif ( primaryActions.length === eligibleActions.length ) {\n\t\treturn (\n\t\t\t<PrimaryActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ primaryActions }\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<HStack\n\t\t\tspacing={ 1 }\n\t\t\tjustify=\"flex-end\"\n\t\t\tclassName=\"dataviews-item-actions\"\n\t\t\tstyle={ {\n\t\t\t\tflexShrink: 0,\n\t\t\t\twidth: 'auto',\n\t\t\t} }\n\t\t>\n\t\t\t<PrimaryActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ primaryActions }\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t\t<CompactItemActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ eligibleActions }\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t</HStack>\n\t);\n}\n\nfunction CompactItemActions< Item >( {\n\titem,\n\tactions,\n\tisSmall,\n\tregistry,\n}: CompactItemActionsProps< Item > ) {\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\treturn (\n\t\t<>\n\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tsize={ isSmall ? 'small' : 'compact' }\n\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\tclassName=\"dataviews-all-actions-button\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Menu.Popover>\n\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.Popover>\n\t\t\t</Menu>\n\t\t\t{ !! activeModalAction && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction PrimaryActions< Item >( {\n\titem,\n\tactions,\n\tregistry,\n}: PrimaryActionsProps< Item > ) {\n\tconst [ activeModalAction, setActiveModalAction ] = useState( null as any );\n\tif ( ! Array.isArray( actions ) || actions.length === 0 ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ actions.map( ( action ) => (\n\t\t\t\t<ButtonTrigger\n\t\t\t\t\tkey={ action.id }\n\t\t\t\t\taction={ action }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\tsetActiveModalAction( action );\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\taction.callback( [ item ], { registry } );\n\t\t\t\t\t} }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ !! activeModalAction && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,WAAA,GAAAL,OAAA;AAA2C,IAAAM,WAAA,GAAAN,OAAA;AAtB3C;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAIA,MAAM;EAAEO,IAAI;EAAEC;AAAU,CAAC,GAAG,IAAAC,kBAAM,EAAEC,uBAAsB,CAAC;AAyC3D,SAASC,aAAaA,CAAU;EAC/BC,MAAM;EACNC,OAAO;EACPC;AAC2B,CAAC,EAAG;EAC/B,MA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ACjD,CACD;EAAA,CACA,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_components","require","_i18n","_element","_icons","_data","_lockUnlock","_jsxRuntime","Menu","kebabCase","unlock","componentsPrivateApis","ButtonTrigger","action","onClick","items","label","jsx","Button","icon","disabled","accessibleWhenDisabled","isDestructive","size","MenuItemTrigger","Item","children","ItemLabel","ActionModal","closeModal","_action$modalFocusOnM","Modal","title","modalHeader","__experimentalHideHeader","hideModalHeader","onRequestClose","focusOnMount","modalFocusOnMount","modalSize","overlayClassName","id","RenderModal","ActionsMenuGroup","actions","item","registry","setActiveModalAction","Group","map","callback","ItemActions","isCompact","useRegistry","primaryActions","eligibleActions","useMemo","_eligibleActions","filter","isEligible","_primaryActions","isPrimary","CompactItemActions","isSmall","jsxs","__experimentalHStack","spacing","justify","className","style","flexShrink","width","PrimaryActions","length","activeModalAction","useState","Fragment","placement","TriggerButton","render","moreVertical","__","Popover","Array","isArray"],"sources":["@wordpress/dataviews/src/components/dataviews-item-actions/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { MouseEventHandler } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalHStack as HStack,\n\tprivateApis as componentsPrivateApis,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useMemo, useState } from '@wordpress/element';\nimport { moreVertical } from '@wordpress/icons';\nimport { useRegistry } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../lock-unlock';\nimport type { Action, ActionModal as ActionModalType } from '../../types';\n\nconst { Menu, kebabCase } = unlock( componentsPrivateApis );\n\nexport interface ActionTriggerProps< Item > {\n\taction: Action< Item >;\n\tonClick: MouseEventHandler;\n\tisBusy?: boolean;\n\titems: Item[];\n}\n\nexport interface ActionModalProps< Item > {\n\taction: ActionModalType< Item >;\n\titems: Item[];\n\tcloseModal: () => void;\n}\n\ninterface ActionsMenuGroupProps< Item > {\n\tactions: Action< Item >[];\n\titem: Item;\n\tregistry: ReturnType< typeof useRegistry >;\n\tsetActiveModalAction: ( action: ActionModalType< Item > | null ) => void;\n}\n\ninterface ItemActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tisCompact?: boolean;\n}\n\ninterface CompactItemActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tisSmall?: boolean;\n\tregistry: ReturnType< typeof useRegistry >;\n}\n\ninterface PrimaryActionsProps< Item > {\n\titem: Item;\n\tactions: Action< Item >[];\n\tregistry: ReturnType< typeof useRegistry >;\n}\n\nfunction ButtonTrigger< Item >( {\n\taction,\n\tonClick,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Button\n\t\t\tlabel={ label }\n\t\t\ticon={ action.icon }\n\t\t\tdisabled={ !! action.disabled }\n\t\t\taccessibleWhenDisabled\n\t\t\tisDestructive={ action.isDestructive }\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t/>\n\t);\n}\n\nfunction MenuItemTrigger< Item >( {\n\taction,\n\tonClick,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Menu.Item disabled={ action.disabled } onClick={ onClick }>\n\t\t\t<Menu.ItemLabel>{ label }</Menu.ItemLabel>\n\t\t</Menu.Item>\n\t);\n}\n\nexport function ActionModal< Item >( {\n\taction,\n\titems,\n\tcloseModal,\n}: ActionModalProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ action.modalHeader || label }\n\t\t\t__experimentalHideHeader={ !! action.hideModalHeader }\n\t\t\tonRequestClose={ closeModal }\n\t\t\tfocusOnMount={ action.modalFocusOnMount ?? true }\n\t\t\tsize={ action.modalSize || 'medium' }\n\t\t\toverlayClassName={ `dataviews-action-modal dataviews-action-modal__${ kebabCase(\n\t\t\t\taction.id\n\t\t\t) }` }\n\t\t>\n\t\t\t<action.RenderModal items={ items } closeModal={ closeModal } />\n\t\t</Modal>\n\t);\n}\n\nexport function ActionsMenuGroup< Item >( {\n\tactions,\n\titem,\n\tregistry,\n\tsetActiveModalAction,\n}: ActionsMenuGroupProps< Item > ) {\n\treturn (\n\t\t<Menu.Group>\n\t\t\t{ actions.map( ( action ) => (\n\t\t\t\t<MenuItemTrigger\n\t\t\t\t\tkey={ action.id }\n\t\t\t\t\taction={ action }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\tsetActiveModalAction( action );\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\taction.callback( [ item ], { registry } );\n\t\t\t\t\t} }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t</Menu.Group>\n\t);\n}\n\nexport default function ItemActions< Item >( {\n\titem,\n\tactions,\n\tisCompact,\n}: ItemActionsProps< Item > ) {\n\tconst registry = useRegistry();\n\tconst { primaryActions, eligibleActions } = useMemo( () => {\n\t\t// If an action is eligible for all items, doesn't need\n\t\t// to provide the `isEligible` function.\n\t\tconst _eligibleActions = actions.filter(\n\t\t\t( action ) => ! action.isEligible || action.isEligible( item )\n\t\t);\n\t\tconst _primaryActions = _eligibleActions.filter(\n\t\t\t( action ) => action.isPrimary && !! action.icon\n\t\t);\n\t\treturn {\n\t\t\tprimaryActions: _primaryActions,\n\t\t\teligibleActions: _eligibleActions,\n\t\t};\n\t}, [ actions, item ] );\n\n\tif ( isCompact ) {\n\t\treturn (\n\t\t\t<CompactItemActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ eligibleActions }\n\t\t\t\tisSmall\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<HStack\n\t\t\tspacing={ 1 }\n\t\t\tjustify=\"flex-end\"\n\t\t\tclassName=\"dataviews-item-actions\"\n\t\t\tstyle={ {\n\t\t\t\tflexShrink: 0,\n\t\t\t\twidth: 'auto',\n\t\t\t} }\n\t\t>\n\t\t\t<PrimaryActions\n\t\t\t\titem={ item }\n\t\t\t\tactions={ primaryActions }\n\t\t\t\tregistry={ registry }\n\t\t\t/>\n\t\t\t{ primaryActions.length < eligibleActions.length && (\n\t\t\t\t<CompactItemActions\n\t\t\t\t\titem={ item }\n\t\t\t\t\tactions={ eligibleActions }\n\t\t\t\t\tregistry={ registry }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</HStack>\n\t);\n}\n\nfunction CompactItemActions< Item >( {\n\titem,\n\tactions,\n\tisSmall,\n\tregistry,\n}: CompactItemActionsProps< Item > ) {\n\tconst [ activeModalAction, setActiveModalAction ] = useState(\n\t\tnull as ActionModalType< Item > | null\n\t);\n\treturn (\n\t\t<>\n\t\t\t<Menu placement=\"bottom-end\">\n\t\t\t\t<Menu.TriggerButton\n\t\t\t\t\trender={\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tsize={ isSmall ? 'small' : 'compact' }\n\t\t\t\t\t\t\ticon={ moreVertical }\n\t\t\t\t\t\t\tlabel={ __( 'Actions' ) }\n\t\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\t\tdisabled={ ! actions.length }\n\t\t\t\t\t\t\tclassName=\"dataviews-all-actions-button\"\n\t\t\t\t\t\t/>\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t\t<Menu.Popover>\n\t\t\t\t\t<ActionsMenuGroup\n\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\titem={ item }\n\t\t\t\t\t\tregistry={ registry }\n\t\t\t\t\t\tsetActiveModalAction={ setActiveModalAction }\n\t\t\t\t\t/>\n\t\t\t\t</Menu.Popover>\n\t\t\t</Menu>\n\t\t\t{ !! activeModalAction && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction PrimaryActions< Item >( {\n\titem,\n\tactions,\n\tregistry,\n}: PrimaryActionsProps< Item > ) {\n\tconst [ activeModalAction, setActiveModalAction ] = useState( null as any );\n\tif ( ! Array.isArray( actions ) || actions.length === 0 ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ actions.map( ( action ) => (\n\t\t\t\t<ButtonTrigger\n\t\t\t\t\tkey={ action.id }\n\t\t\t\t\taction={ action }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tif ( 'RenderModal' in action ) {\n\t\t\t\t\t\t\tsetActiveModalAction( action );\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\taction.callback( [ item ], { registry } );\n\t\t\t\t\t} }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t/>\n\t\t\t) ) }\n\t\t\t{ !! activeModalAction && (\n\t\t\t\t<ActionModal\n\t\t\t\t\taction={ activeModalAction }\n\t\t\t\t\titems={ [ item ] }\n\t\t\t\t\tcloseModal={ () => setActiveModalAction( null ) }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAKA,IAAAK,WAAA,GAAAL,OAAA;AAA2C,IAAAM,WAAA,GAAAN,OAAA;AAtB3C;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;;AAIA,MAAM;EAAEO,IAAI;EAAEC;AAAU,CAAC,GAAG,IAAAC,kBAAM,EAAEC,uBAAsB,CAAC;AAyC3D,SAASC,aAAaA,CAAU;EAC/B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31
|
}
|
|
32
32
|
} = (0, _element.useContext)(_dataviewsContext.default);
|
|
33
|
-
if (!totalItems || !totalPages) {
|
|
33
|
+
if (!totalItems || !totalPages || view.infiniteScrollEnabled) {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
const currentPage = (_view$page = view.page) !== null && _view$page !== void 0 ? _view$page : 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_i18n","_icons","_dataviewsContext","_interopRequireDefault","_jsxRuntime","DataViewsPagination","_view$page","view","onChangeView","paginationInfo","totalItems","totalPages","useContext","DataViewsContext","currentPage","page","pageSelectOptions","Array","from","map","_","i","value","toString","label","sprintf","__","jsxs","__experimentalHStack","expanded","className","justify","spacing","children","jsx","createInterpolateElement","_x","div","CurrentPage","SelectControl","options","onChange","newValue","size","__nextHasNoMarginBottom","variant","Button","onClick","disabled","accessibleWhenDisabled","icon","isRTL","next","previous","showTooltip","tooltipPosition","_default","exports","default","memo"],"sources":["@wordpress/dataviews/src/components/dataviews-pagination/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\tSelectControl,\n} from '@wordpress/components';\nimport { createInterpolateElement, memo, useContext } from '@wordpress/element';\nimport { sprintf, __, _x, isRTL } from '@wordpress/i18n';\nimport { next, previous } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\n\nexport function DataViewsPagination() {\n\tconst {\n\t\tview,\n\t\tonChangeView,\n\t\tpaginationInfo: { totalItems = 0, totalPages },\n\t} = useContext( DataViewsContext );\n\n\tif ( ! totalItems || ! totalPages ) {\n\t\treturn null;\n\t}\n\n\tconst currentPage = view.page ?? 1;\n\tconst pageSelectOptions = Array.from( Array( totalPages ) ).map(\n\t\t( _, i ) => {\n\t\t\tconst page = i + 1;\n\t\t\treturn {\n\t\t\t\tvalue: page.toString(),\n\t\t\t\tlabel: page.toString(),\n\t\t\t\t'aria-label':\n\t\t\t\t\tcurrentPage === page\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: 1: current page number. 2: total number of pages.\n\t\t\t\t\t\t\t\t__( 'Page %1$d of %2$d' ),\n\t\t\t\t\t\t\t\tcurrentPage,\n\t\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: page.toString(),\n\t\t\t};\n\t\t}\n\t);\n\n\treturn (\n\t\t!! totalItems &&\n\t\ttotalPages !== 1 && (\n\t\t\t<HStack\n\t\t\t\texpanded={ false }\n\t\t\t\tclassName=\"dataviews-pagination\"\n\t\t\t\tjustify=\"end\"\n\t\t\t\tspacing={ 6 }\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\tclassName=\"dataviews-pagination__page-select\"\n\t\t\t\t>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t// translators: 1: Current page number, 2: Total number of pages.\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'<div>Page</div>%1$s<div>of %2$d</div>',\n\t\t\t\t\t\t\t\t'paging'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t'<CurrentPage />',\n\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdiv: <div aria-hidden />,\n\t\t\t\t\t\t\tCurrentPage: (\n\t\t\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\t\t\taria-label={ __( 'Current page' ) }\n\t\t\t\t\t\t\t\t\tvalue={ currentPage.toString() }\n\t\t\t\t\t\t\t\t\toptions={ pageSelectOptions }\n\t\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t\tpage: +newValue,\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\tvariant=\"minimal\"\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</HStack>\n\t\t\t\t<HStack expanded={ false } spacing={ 1 }>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\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: currentPage - 1,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage === 1 }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Previous page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? next : previous }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tonChangeView( { ...view, page: currentPage + 1 } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage >= totalPages }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Next page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? previous : next }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t</HStack>\n\t\t)\n\t);\n}\n\nexport default memo( DataViewsPagination );\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAKA,IAAAI,iBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAAoD,IAAAM,WAAA,GAAAN,OAAA;AAfpD;AACA;AACA;;AAUA;AACA;AACA;;AAGO,SAASO,mBAAmBA,CAAA,EAAG;EAAA,IAAAC,UAAA;EACrC,MAAM;IACLC,IAAI;IACJC,YAAY;IACZC,cAAc,EAAE;MAAEC,UAAU,GAAG,CAAC;MAAEC;IAAW;EAC9C,CAAC,GAAG,IAAAC,mBAAU,EAAEC,yBAAiB,CAAC;EAElC,IAAK,CAAEH,UAAU,IAAI,CAAEC,UAAU,EAAG;
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_i18n","_icons","_dataviewsContext","_interopRequireDefault","_jsxRuntime","DataViewsPagination","_view$page","view","onChangeView","paginationInfo","totalItems","totalPages","useContext","DataViewsContext","infiniteScrollEnabled","currentPage","page","pageSelectOptions","Array","from","map","_","i","value","toString","label","sprintf","__","jsxs","__experimentalHStack","expanded","className","justify","spacing","children","jsx","createInterpolateElement","_x","div","CurrentPage","SelectControl","options","onChange","newValue","size","__nextHasNoMarginBottom","variant","Button","onClick","disabled","accessibleWhenDisabled","icon","isRTL","next","previous","showTooltip","tooltipPosition","_default","exports","default","memo"],"sources":["@wordpress/dataviews/src/components/dataviews-pagination/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__experimentalHStack as HStack,\n\tSelectControl,\n} from '@wordpress/components';\nimport { createInterpolateElement, memo, useContext } from '@wordpress/element';\nimport { sprintf, __, _x, isRTL } from '@wordpress/i18n';\nimport { next, previous } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport DataViewsContext from '../dataviews-context';\n\nexport function DataViewsPagination() {\n\tconst {\n\t\tview,\n\t\tonChangeView,\n\t\tpaginationInfo: { totalItems = 0, totalPages },\n\t} = useContext( DataViewsContext );\n\n\tif ( ! totalItems || ! totalPages || view.infiniteScrollEnabled ) {\n\t\treturn null;\n\t}\n\n\tconst currentPage = view.page ?? 1;\n\tconst pageSelectOptions = Array.from( Array( totalPages ) ).map(\n\t\t( _, i ) => {\n\t\t\tconst page = i + 1;\n\t\t\treturn {\n\t\t\t\tvalue: page.toString(),\n\t\t\t\tlabel: page.toString(),\n\t\t\t\t'aria-label':\n\t\t\t\t\tcurrentPage === page\n\t\t\t\t\t\t? sprintf(\n\t\t\t\t\t\t\t\t// translators: 1: current page number. 2: total number of pages.\n\t\t\t\t\t\t\t\t__( 'Page %1$d of %2$d' ),\n\t\t\t\t\t\t\t\tcurrentPage,\n\t\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t )\n\t\t\t\t\t\t: page.toString(),\n\t\t\t};\n\t\t}\n\t);\n\n\treturn (\n\t\t!! totalItems &&\n\t\ttotalPages !== 1 && (\n\t\t\t<HStack\n\t\t\t\texpanded={ false }\n\t\t\t\tclassName=\"dataviews-pagination\"\n\t\t\t\tjustify=\"end\"\n\t\t\t\tspacing={ 6 }\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"flex-start\"\n\t\t\t\t\texpanded={ false }\n\t\t\t\t\tspacing={ 1 }\n\t\t\t\t\tclassName=\"dataviews-pagination__page-select\"\n\t\t\t\t>\n\t\t\t\t\t{ createInterpolateElement(\n\t\t\t\t\t\tsprintf(\n\t\t\t\t\t\t\t// translators: 1: Current page number, 2: Total number of pages.\n\t\t\t\t\t\t\t_x(\n\t\t\t\t\t\t\t\t'<div>Page</div>%1$s<div>of %2$d</div>',\n\t\t\t\t\t\t\t\t'paging'\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t'<CurrentPage />',\n\t\t\t\t\t\t\ttotalPages\n\t\t\t\t\t\t),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdiv: <div aria-hidden />,\n\t\t\t\t\t\t\tCurrentPage: (\n\t\t\t\t\t\t\t\t<SelectControl\n\t\t\t\t\t\t\t\t\taria-label={ __( 'Current page' ) }\n\t\t\t\t\t\t\t\t\tvalue={ currentPage.toString() }\n\t\t\t\t\t\t\t\t\toptions={ pageSelectOptions }\n\t\t\t\t\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\t\tpage: +newValue,\n\t\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\t\t\t\t\tvariant=\"minimal\"\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</HStack>\n\t\t\t\t<HStack expanded={ false } spacing={ 1 }>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\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: currentPage - 1,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage === 1 }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Previous page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? next : previous }\n\t\t\t\t\t\tshowTooltip\n\t\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\t/>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tonChangeView( { ...view, page: currentPage + 1 } )\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdisabled={ currentPage >= totalPages }\n\t\t\t\t\t\taccessibleWhenDisabled\n\t\t\t\t\t\tlabel={ __( 'Next page' ) }\n\t\t\t\t\t\ticon={ isRTL() ? previous :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AO;MAACG,OAAO,EAAG,CAAG;MAAAC,QAAA,gBACvC,IAAA9B,WAAA,CAAA+B,GAAA,EAACtC,WAAA,CAAAkD,MAAM;QACNC,OAAO,EAAGA,CAAA,KACTxC,YAAY,CAAE;UACb,GAAGD,IAAI;UACPS,IAAI,EAAED,WAAW,GAAG;QACrB,CAAE,CACF;QACDkC,QAAQ,EAAGlC,WAAW,KAAK,CAAG;QAC9BmC,sBAAsB;QACtBzB,KAAK,EAAG,IAAAE,QAAE,EAAE,eAAgB,CAAG;QAC/BwB,IAAI,EAAG,IAAAC,WAAK,EAAC,CAAC,GAAGC,WAAI,GAAGC,eAAU;QAClCC,WAAW;QACXX,IAAI,EAAC,SAAS;QACdY,eAAe,EAAC;MAAK,CACrB,CAAC,eACF,IAAApD,WAAA,CAAA+B,GAAA,EAACtC,WAAA,CAAAkD,MAAM;QACNC,OAAO,EAAGA,CAAA,KACTxC,YAAY,CAAE;UAAE,GAAGD,IAAI;UAAES,IAAI,EAAED,WAAW,GAAG;QAAE,CAAE,CACjD;QACDkC,QAAQ,EAAGlC,WAAW,IAAIJ,UAAY;QACtCuC,sBAAsB;QACtBzB,KAAK,EAAG,IAAAE,QAAE,EAAE,WAAY,CAAG;QAC3BwB,IAAI,EAAG,IAAAC,WAAK,EAAC,CAAC,GAAGE,eAAQ,GAAGD,WAAM;QAClCE,WAAW;QACXX,IAAI,EAAC,SAAS;QACdY,eAAe,EAAC;MAAK,CACrB,CAAC;IAAA,CACK,CAAC;EAAA,CACF,CACR;AAEH;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAAC,aAAI,EAAEvD,mBAAoB,CAAC","ignoreList":[]}
|
|
@@ -17,6 +17,7 @@ var _compose = require("@wordpress/compose");
|
|
|
17
17
|
var _constants = require("../../constants");
|
|
18
18
|
var _dataviewsLayouts = require("../../dataviews-layouts");
|
|
19
19
|
var _dataviewsContext = _interopRequireDefault(require("../dataviews-context"));
|
|
20
|
+
var _infiniteScrollToggle = _interopRequireDefault(require("./infinite-scroll-toggle"));
|
|
20
21
|
var _lockUnlock = require("../../lock-unlock");
|
|
21
22
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
23
|
/**
|
|
@@ -79,7 +80,6 @@ function ViewTypeMenu() {
|
|
|
79
80
|
if ('layout' in viewWithoutLayout) {
|
|
80
81
|
delete viewWithoutLayout.layout;
|
|
81
82
|
}
|
|
82
|
-
// @ts-expect-error
|
|
83
83
|
return onChangeView({
|
|
84
84
|
...viewWithoutLayout,
|
|
85
85
|
type: e.target.value,
|
|
@@ -178,10 +178,13 @@ function SortDirectionControl() {
|
|
|
178
178
|
function ItemsPerPageControl() {
|
|
179
179
|
const {
|
|
180
180
|
view,
|
|
181
|
-
|
|
181
|
+
config,
|
|
182
182
|
onChangeView
|
|
183
183
|
} = (0, _element.useContext)(_dataviewsContext.default);
|
|
184
|
-
|
|
184
|
+
const {
|
|
185
|
+
infiniteScrollEnabled
|
|
186
|
+
} = view;
|
|
187
|
+
if (!config || !config.perPageSizes || config.perPageSizes.length < 2 || config.perPageSizes.length > 6 || infiniteScrollEnabled) {
|
|
185
188
|
return null;
|
|
186
189
|
}
|
|
187
190
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToggleGroupControl, {
|
|
@@ -199,7 +202,7 @@ function ItemsPerPageControl() {
|
|
|
199
202
|
page: 1
|
|
200
203
|
});
|
|
201
204
|
},
|
|
202
|
-
children: perPageSizes.map(value => {
|
|
205
|
+
children: config.perPageSizes.map(value => {
|
|
203
206
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToggleGroupControlOption, {
|
|
204
207
|
value: value,
|
|
205
208
|
label: value.toString()
|
|
@@ -604,7 +607,7 @@ function DataviewsViewConfigDropdown() {
|
|
|
604
607
|
expanded: true,
|
|
605
608
|
className: "is-divided-in-two",
|
|
606
609
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(SortFieldControl, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(SortDirectionControl, {})]
|
|
607
|
-
}), !!activeLayout?.viewConfigOptions && /*#__PURE__*/(0, _jsxRuntime.jsx)(activeLayout.viewConfigOptions, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemsPerPageControl, {})]
|
|
610
|
+
}), !!activeLayout?.viewConfigOptions && /*#__PURE__*/(0, _jsxRuntime.jsx)(activeLayout.viewConfigOptions, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_infiniteScrollToggle.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(ItemsPerPageControl, {})]
|
|
608
611
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(SettingsSection, {
|
|
609
612
|
title: (0, _i18n.__)('Properties'),
|
|
610
613
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(FieldControl, {})
|