@wordpress/dataviews 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +33 -30
  3. package/build/add-filter.js +30 -22
  4. package/build/add-filter.js.map +1 -1
  5. package/build/bulk-actions-toolbar.js +74 -69
  6. package/build/bulk-actions-toolbar.js.map +1 -1
  7. package/build/bulk-actions.js +69 -56
  8. package/build/bulk-actions.js.map +1 -1
  9. package/build/constants.js +17 -10
  10. package/build/constants.js.map +1 -1
  11. package/build/dataviews.js +63 -56
  12. package/build/dataviews.js.map +1 -1
  13. package/build/filter-summary.js +105 -95
  14. package/build/filter-summary.js.map +1 -1
  15. package/build/filters.js +18 -17
  16. package/build/filters.js.map +1 -1
  17. package/build/index.js.map +1 -1
  18. package/build/item-actions.js +78 -65
  19. package/build/item-actions.js.map +1 -1
  20. package/build/layouts.js.map +1 -1
  21. package/build/pagination.js +60 -57
  22. package/build/pagination.js.map +1 -1
  23. package/build/reset-filters.js +9 -4
  24. package/build/reset-filters.js.map +1 -1
  25. package/build/search-widget.js +108 -89
  26. package/build/search-widget.js.map +1 -1
  27. package/build/search.js +13 -6
  28. package/build/search.js.map +1 -1
  29. package/build/single-selection-checkbox.js +2 -2
  30. package/build/single-selection-checkbox.js.map +1 -1
  31. package/build/types.js.map +1 -1
  32. package/build/utils.js +3 -15
  33. package/build/utils.js.map +1 -1
  34. package/build/view-actions.js +168 -120
  35. package/build/view-actions.js.map +1 -1
  36. package/build/view-grid.js +113 -99
  37. package/build/view-grid.js.map +1 -1
  38. package/build/view-list.js +153 -132
  39. package/build/view-list.js.map +1 -1
  40. package/build/view-table.js +220 -192
  41. package/build/view-table.js.map +1 -1
  42. package/build-module/add-filter.js +30 -22
  43. package/build-module/add-filter.js.map +1 -1
  44. package/build-module/bulk-actions-toolbar.js +76 -69
  45. package/build-module/bulk-actions-toolbar.js.map +1 -1
  46. package/build-module/bulk-actions.js +71 -56
  47. package/build-module/bulk-actions.js.map +1 -1
  48. package/build-module/constants.js +16 -9
  49. package/build-module/constants.js.map +1 -1
  50. package/build-module/dataviews.js +64 -56
  51. package/build-module/dataviews.js.map +1 -1
  52. package/build-module/filter-summary.js +106 -96
  53. package/build-module/filter-summary.js.map +1 -1
  54. package/build-module/filters.js +18 -17
  55. package/build-module/filters.js.map +1 -1
  56. package/build-module/index.js.map +1 -1
  57. package/build-module/item-actions.js +80 -65
  58. package/build-module/item-actions.js.map +1 -1
  59. package/build-module/layouts.js.map +1 -1
  60. package/build-module/pagination.js +61 -58
  61. package/build-module/pagination.js.map +1 -1
  62. package/build-module/reset-filters.js +9 -4
  63. package/build-module/reset-filters.js.map +1 -1
  64. package/build-module/search-widget.js +109 -89
  65. package/build-module/search-widget.js.map +1 -1
  66. package/build-module/search.js +13 -6
  67. package/build-module/search.js.map +1 -1
  68. package/build-module/single-selection-checkbox.js +2 -3
  69. package/build-module/single-selection-checkbox.js.map +1 -1
  70. package/build-module/types.js.map +1 -1
  71. package/build-module/utils.js +2 -13
  72. package/build-module/utils.js.map +1 -1
  73. package/build-module/view-actions.js +170 -121
  74. package/build-module/view-actions.js.map +1 -1
  75. package/build-module/view-grid.js +115 -99
  76. package/build-module/view-grid.js.map +1 -1
  77. package/build-module/view-list.js +154 -132
  78. package/build-module/view-list.js.map +1 -1
  79. package/build-module/view-table.js +223 -194
  80. package/build-module/view-table.js.map +1 -1
  81. package/build-style/style-rtl.css +109 -20
  82. package/build-style/style.css +109 -20
  83. package/build-types/add-filter.d.ts +9 -6
  84. package/build-types/add-filter.d.ts.map +1 -1
  85. package/build-types/bulk-actions-toolbar.d.ts +11 -7
  86. package/build-types/bulk-actions-toolbar.d.ts.map +1 -1
  87. package/build-types/bulk-actions.d.ts.map +1 -1
  88. package/build-types/constants.d.ts +19 -32
  89. package/build-types/constants.d.ts.map +1 -1
  90. package/build-types/dataviews.d.ts +21 -14
  91. package/build-types/dataviews.d.ts.map +1 -1
  92. package/build-types/filter-summary.d.ts +13 -5
  93. package/build-types/filter-summary.d.ts.map +1 -1
  94. package/build-types/filters.d.ts +11 -1
  95. package/build-types/filters.d.ts.map +1 -1
  96. package/build-types/index.d.ts +3 -3
  97. package/build-types/index.d.ts.map +1 -1
  98. package/build-types/item-actions.d.ts +5 -7
  99. package/build-types/item-actions.d.ts.map +1 -1
  100. package/build-types/layouts.d.ts +8 -4
  101. package/build-types/layouts.d.ts.map +1 -1
  102. package/build-types/reset-filters.d.ts +12 -5
  103. package/build-types/reset-filters.d.ts.map +1 -1
  104. package/build-types/search-widget.d.ts +9 -1
  105. package/build-types/search-widget.d.ts.map +1 -1
  106. package/build-types/search.d.ts +11 -1
  107. package/build-types/search.d.ts.map +1 -1
  108. package/build-types/types.d.ts +78 -10
  109. package/build-types/types.d.ts.map +1 -1
  110. package/build-types/utils.d.ts +2 -1
  111. package/build-types/utils.d.ts.map +1 -1
  112. package/build-types/view-actions.d.ts +10 -1
  113. package/build-types/view-actions.d.ts.map +1 -1
  114. package/build-types/view-grid.d.ts +1 -12
  115. package/build-types/view-grid.d.ts.map +1 -1
  116. package/build-types/view-list.d.ts +2 -14
  117. package/build-types/view-list.d.ts.map +1 -1
  118. package/build-types/view-table.d.ts +3 -12
  119. package/build-types/view-table.d.ts.map +1 -1
  120. package/package.json +11 -12
  121. package/src/{add-filter.js → add-filter.tsx} +17 -1
  122. package/src/{bulk-actions-toolbar.js → bulk-actions-toolbar.tsx} +68 -40
  123. package/src/bulk-actions.tsx +5 -1
  124. package/src/constants.ts +12 -5
  125. package/src/{dataviews.js → dataviews.tsx} +41 -12
  126. package/src/{filter-summary.js → filter-summary.tsx} +35 -6
  127. package/src/{filters.js → filters.tsx} +18 -6
  128. package/src/item-actions.tsx +20 -15
  129. package/src/pagination.tsx +1 -1
  130. package/src/{reset-filters.js → reset-filters.tsx} +17 -2
  131. package/src/{search-widget.js → search-widget.tsx} +27 -7
  132. package/src/{search.js → search.tsx} +22 -5
  133. package/src/style.scss +97 -23
  134. package/src/types.ts +105 -10
  135. package/src/{utils.js → utils.ts} +5 -13
  136. package/src/{view-actions.js → view-actions.tsx} +105 -49
  137. package/src/view-grid.tsx +4 -20
  138. package/src/view-list.tsx +12 -23
  139. package/src/{view-table.js → view-table.tsx} +91 -32
  140. package/tsconfig.json +0 -3
  141. package/tsconfig.tsbuildinfo +1 -1
  142. package/build/dropdown-menu-helper.js +0 -71
  143. package/build/dropdown-menu-helper.js.map +0 -1
  144. package/build-module/dropdown-menu-helper.js +0 -64
  145. package/build-module/dropdown-menu-helper.js.map +0 -1
  146. package/build-types/dropdown-menu-helper.d.ts +0 -6
  147. package/build-types/dropdown-menu-helper.d.ts.map +0 -1
  148. package/src/dropdown-menu-helper.js +0 -61
  149. /package/src/{index.js → index.ts} +0 -0
  150. /package/src/{layouts.js → layouts.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.0.0 (2024-05-31)
6
+
7
+ ### Breaking Changes
8
+
9
+ - Legacy support for `in` and `notIn` operators introduced in 0.8 .0 has been removed and they no longer work. Please, convert them to `is` and `isNot` respectively.
10
+ - Variables like `process.env.IS_GUTENBERG_PLUGIN` have been replaced by `globalThis.IS_GUTENBERG_PLUGIN`. Build systems using `process.env` should be updated ([#61486](https://github.com/WordPress/gutenberg/pull/61486)).
11
+ - Increase the minimum required Node.js version to v18.12.0 matching long-term support releases ([#31270](https://github.com/WordPress/gutenberg/pull/61930)). Learn more about [Node.js releases](https://nodejs.org/en/about/previous-releases).
12
+
13
+ ### Internal
14
+
15
+ - Remove some unused dependencies ([#62010](https://github.com/WordPress/gutenberg/pull/62010)).
16
+
17
+ ### Enhancement
18
+
19
+ - `label` prop in Actions API can be either a `string` value or a `function`, in case we want to use information from the selected items. ([#61942](https://github.com/WordPress/gutenberg/pull/61942)).
20
+
5
21
  ## 1.2.0 (2024-05-16)
6
22
 
7
23
  ### Internal
package/README.md CHANGED
@@ -14,7 +14,6 @@ npm install @wordpress/dataviews --save
14
14
 
15
15
  ```jsx
16
16
  const Example = () => {
17
-
18
17
  // Declare data, fields, etc.
19
18
 
20
19
  return (
@@ -27,7 +26,7 @@ const Example = () => {
27
26
  paginationInfo={ paginationInfo }
28
27
  />
29
28
  );
30
- }
29
+ };
31
30
  ```
32
31
 
33
32
  ## Properties
@@ -42,12 +41,14 @@ Example:
42
41
  const data = [
43
42
  {
44
43
  id: 1,
45
- title: "Title",
46
- author: "Admin",
47
- date: "2012-04-23T18:25:43.511Z"
44
+ title: 'Title',
45
+ author: 'Admin',
46
+ date: '2012-04-23T18:25:43.511Z',
48
47
  },
49
- { /* ... */ }
50
- ]
48
+ {
49
+ /* ... */
50
+ },
51
+ ];
51
52
  ```
52
53
 
53
54
  By default, dataviews would use each record's `id` as an unique identifier. If it's not, the consumer should provide a `getItemId` function that returns one.
@@ -125,8 +126,8 @@ Each field is an object with the following properties:
125
126
  - `enableSorting`: whether the data can be sorted by the given field. True by default.
126
127
  - `enableHiding`: whether the field can be hidden. True by default.
127
128
  - `filterBy`: configuration for the filters.
128
- - `operators`: the list of operators supported by the field.
129
- - `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.
129
+ - `operators`: the list of operators supported by the field.
130
+ - `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.
130
131
 
131
132
  ### `view`: `object`
132
133
 
@@ -140,7 +141,7 @@ const view = {
140
141
  search: '',
141
142
  filters: [
142
143
  { field: 'author', operator: 'is', value: 2 },
143
- { field: 'status', operator: 'isAny', value: [ 'publish', 'draft'] }
144
+ { field: 'status', operator: 'isAny', value: [ 'publish', 'draft' ] },
144
145
  ],
145
146
  page: 1,
146
147
  perPage: 5,
@@ -150,7 +151,7 @@ const view = {
150
151
  },
151
152
  hiddenFields: [ 'date', 'featured-image' ],
152
153
  layout: {},
153
- }
154
+ };
154
155
  ```
155
156
 
156
157
  Properties:
@@ -164,8 +165,8 @@ Properties:
164
165
  - `perPage`: number of records to show per page.
165
166
  - `page`: the page that is visible.
166
167
  - `sort`:
167
- - `field`: the field used for sorting the dataset.
168
- - `direction`: the direction to use for sorting, one of `asc` or `desc`.
168
+ - `field`: the field used for sorting the dataset.
169
+ - `direction`: the direction to use for sorting, one of `asc` or `desc`.
169
170
  - `hiddenFields`: the `id` of the fields that are hidden in the UI.
170
171
  - `layout`: config that is specific to a particular layout type.
171
172
  - `mediaField`: used by the `grid` and `list` layouts. The `id` of the field to be used for rendering each card's media.
@@ -192,7 +193,11 @@ function MyCustomPageTable() {
192
193
  search: '',
193
194
  filters: [
194
195
  { field: 'author', operator: 'is', value: 2 },
195
- { field: 'status', operator: 'isAny', value: [ 'publish', 'draft' ] }
196
+ {
197
+ field: 'status',
198
+ operator: 'isAny',
199
+ value: [ 'publish', 'draft' ],
200
+ },
196
201
  ],
197
202
  hiddenFields: [ 'date', 'featured-image' ],
198
203
  layout: {},
@@ -219,9 +224,7 @@ function MyCustomPageTable() {
219
224
  };
220
225
  }, [ view ] );
221
226
 
222
- const {
223
- records
224
- } = useEntityRecords( 'postType', 'page', queryArgs );
227
+ const { records } = useEntityRecords( 'postType', 'page', queryArgs );
225
228
 
226
229
  return (
227
230
  <DataViews
@@ -241,7 +244,7 @@ Collection of operations that can be performed upon each record.
241
244
  Each action is an object with the following properties:
242
245
 
243
246
  - `id`: string, required. Unique identifier of the action. For example, `move-to-trash`.
244
- - `label`: string, required. User facing description of the action. For example, `Move to Trash`.
247
+ - `label`: string|function, required. User facing description of the action. For example, `Move to Trash`. In case we want to adjust the label based on the selected items, a function which accepts the selected records as input can be provided. This function should always return a `string` value.
245
248
  - `isPrimary`: boolean, optional. Whether the action should be listed inline (primary) or in hidden in the more actions menu (secondary).
246
249
  - `icon`: icon to show for primary actions. It's required for a primary action, otherwise the action would be considered secondary.
247
250
  - `isEligible`: function, optional. Whether the action can be performed for a given record. If not present, the action is considered to be eligible for all items. It takes the given record as input.
@@ -252,8 +255,8 @@ Each action is an object with the following properties:
252
255
 
253
256
  ### `paginationInfo`: `Object`
254
257
 
255
- - `totalItems`: the total number of items in the datasets.
256
- - `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
258
+ - `totalItems`: the total number of items in the datasets.
259
+ - `totalPages`: the total number of pages, taking into account the total items in the dataset and the number of items per page provided by the user.
257
260
 
258
261
  ### `search`: `boolean`
259
262
 
@@ -283,9 +286,9 @@ Callback that signals the user selected one of more items, and takes them as par
283
286
 
284
287
  ### Layouts
285
288
 
286
- - `table`: the view uses a table layout.
287
- - `grid`: the view uses a grid layout.
288
- - `list`: the view uses a list layout.
289
+ - `table`: the view uses a table layout.
290
+ - `grid`: the view uses a grid layout.
291
+ - `list`: the view uses a list layout.
289
292
 
290
293
  ### Fields
291
294
 
@@ -295,13 +298,13 @@ Callback that signals the user selected one of more items, and takes them as par
295
298
 
296
299
  Allowed operators:
297
300
 
298
- | Operator | Selection | Description | Example |
299
- | --- | --- | --- | --- |
300
- | `is` | Single item | `EQUAL TO`. The item's field is equal to a single value. | Author is Admin |
301
- | `isNot` | Single item | `NOT EQUAL TO`. The item's field is not equal to a single value. | Author is not Admin |
302
- | `isAny` | Multiple items | `OR`. The item's field is present in a list of values. | Author is any: Admin, Editor |
303
- | `isNone` | Multiple items | `NOT OR`. The item's field is not present in a list of values. | Author is none: Admin, Editor |
304
- | `isAll` | Multiple items | `AND`. The item's field has all of the values in the list. | Category is all: Book, Review, Science Fiction |
301
+ | Operator | Selection | Description | Example |
302
+ | ---------- | -------------- | ----------------------------------------------------------------------- | -------------------------------------------------- |
303
+ | `is` | Single item | `EQUAL TO`. The item's field is equal to a single value. | Author is Admin |
304
+ | `isNot` | Single item | `NOT EQUAL TO`. The item's field is not equal to a single value. | Author is not Admin |
305
+ | `isAny` | Multiple items | `OR`. The item's field is present in a list of values. | Author is any: Admin, Editor |
306
+ | `isNone` | Multiple items | `NOT OR`. The item's field is not present in a list of values. | Author is none: Admin, Editor |
307
+ | `isAll` | Multiple items | `AND`. The item's field has all of the values in the list. | Category is all: Book, Review, Science Fiction |
305
308
  | `isNotAll` | Multiple items | `NOT AND`. The item's field doesn't have all of the values in the list. | Category is not all: Book, Review, Science Fiction |
306
309
 
307
310
  `is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection. By default, a filter with no operators declared will support the `isAny` and `isNone` multi-selection operators. A filter cannot mix single-selection & multi-selection operators; if a single-selection operator is present in the list of valid operators, the multi-selection ones will be discarded and the filter won't allow selecting more than one item.
@@ -4,11 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _react = require("react");
8
7
  var _components = require("@wordpress/components");
9
8
  var _i18n = require("@wordpress/i18n");
10
9
  var _element = require("@wordpress/element");
11
10
  var _lockUnlock = require("./lock-unlock");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ /**
13
+ * External dependencies
14
+ */
15
+
12
16
  /**
13
17
  * WordPress dependencies
14
18
  */
@@ -34,32 +38,36 @@ function AddFilter({
34
38
  return null;
35
39
  }
36
40
  const inactiveFilters = filters.filter(filter => !filter.isVisible);
37
- return (0, _react.createElement)(DropdownMenu, {
38
- trigger: (0, _react.createElement)(_components.Button, {
41
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenu, {
42
+ trigger: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
39
43
  __experimentalIsFocusable: true,
40
44
  size: "compact",
41
45
  className: "dataviews-filters-button",
42
46
  variant: "tertiary",
43
47
  disabled: !inactiveFilters.length,
44
- ref: ref
45
- }, (0, _i18n.__)('Add filter'))
46
- }, inactiveFilters.map(filter => {
47
- return (0, _react.createElement)(DropdownMenuItem, {
48
- key: filter.field,
49
- onClick: () => {
50
- setOpenedFilter(filter.field);
51
- onChangeView({
52
- ...view,
53
- page: 1,
54
- filters: [...(view.filters || []), {
55
- field: filter.field,
56
- value: undefined,
57
- operator: filter.operators[0]
58
- }]
59
- });
60
- }
61
- }, (0, _react.createElement)(DropdownMenuItemLabel, null, filter.name));
62
- }));
48
+ ref: ref,
49
+ children: (0, _i18n.__)('Add filter')
50
+ }),
51
+ children: inactiveFilters.map(filter => {
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItem, {
53
+ onClick: () => {
54
+ setOpenedFilter(filter.field);
55
+ onChangeView({
56
+ ...view,
57
+ page: 1,
58
+ filters: [...(view.filters || []), {
59
+ field: filter.field,
60
+ value: undefined,
61
+ operator: filter.operators[0]
62
+ }]
63
+ });
64
+ },
65
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItemLabel, {
66
+ children: filter.name
67
+ })
68
+ }, filter.field);
69
+ })
70
+ });
63
71
  }
64
72
  var _default = exports.default = (0, _element.forwardRef)(AddFilter);
65
73
  //# sourceMappingURL=add-filter.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_i18n","_element","_lockUnlock","DropdownMenuV2","DropdownMenu","DropdownMenuItemV2","DropdownMenuItem","DropdownMenuItemLabelV2","DropdownMenuItemLabel","unlock","componentsPrivateApis","AddFilter","filters","view","onChangeView","setOpenedFilter","ref","length","every","isPrimary","inactiveFilters","filter","isVisible","_react","createElement","trigger","Button","__experimentalIsFocusable","size","className","variant","disabled","__","map","key","field","onClick","page","value","undefined","operator","operators","name","_default","exports","default","forwardRef"],"sources":["@wordpress/dataviews/src/add-filter.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as componentsPrivateApis,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\n\nconst {\n\tDropdownMenuV2: DropdownMenu,\n\tDropdownMenuItemV2: DropdownMenuItem,\n\tDropdownMenuItemLabelV2: DropdownMenuItemLabel,\n} = unlock( componentsPrivateApis );\n\nfunction AddFilter( { filters, view, onChangeView, setOpenedFilter }, ref ) {\n\tif ( ! filters.length || filters.every( ( { isPrimary } ) => isPrimary ) ) {\n\t\treturn null;\n\t}\n\tconst inactiveFilters = filters.filter( ( filter ) => ! filter.isVisible );\n\treturn (\n\t\t<DropdownMenu\n\t\t\ttrigger={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"dataviews-filters-button\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! inactiveFilters.length }\n\t\t\t\t\tref={ ref }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t</Button>\n\t\t\t}\n\t\t>\n\t\t\t{ inactiveFilters.map( ( filter ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenuItem\n\t\t\t\t\t\tkey={ filter.field }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetOpenedFilter( filter.field );\n\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\toperator: filter.operators[ 0 ],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DropdownMenuItemLabel>\n\t\t\t\t\t\t\t{ filter.name }\n\t\t\t\t\t\t</DropdownMenuItemLabel>\n\t\t\t\t\t</DropdownMenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\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eAAe,CAAEM,MAAM,CAACc,KAAM,CAAC;QAC/BrB,YAAY,CAAE;UACb,GAAGD,IAAI;UACPwB,IAAI,EAAE,CAAC;UACPzB,OAAO,EAAE,CACR,IAAKC,IAAI,CAACD,OAAO,IAAI,EAAE,CAAE,EACzB;YACCuB,KAAK,EAAEd,MAAM,CAACc,KAAK;YACnBG,KAAK,EAAEC,SAAS;YAChBC,QAAQ,EAAEnB,MAAM,CAACoB,SAAS,CAAE,CAAC;UAC9B,CAAC;QAEH,CAAE,CAAC;MACJ;IAAG,GAEH,IAAAlB,MAAA,CAAAC,aAAA,EAAChB,qBAAqB,QACnBa,MAAM,CAACqB,IACa,CACN,CAAC;EAErB,CAAE,CACW,CAAC;AAEjB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAAC,mBAAU,EAAEnC,SAAU,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_components","require","_i18n","_element","_lockUnlock","_jsxRuntime","DropdownMenuV2","DropdownMenu","DropdownMenuItemV2","DropdownMenuItem","DropdownMenuItemLabelV2","DropdownMenuItemLabel","unlock","componentsPrivateApis","AddFilter","filters","view","onChangeView","setOpenedFilter","ref","length","every","isPrimary","inactiveFilters","filter","isVisible","jsx","trigger","Button","__experimentalIsFocusable","size","className","variant","disabled","children","__","map","onClick","field","page","value","undefined","operator","operators","name","_default","exports","default","forwardRef"],"sources":["@wordpress/dataviews/src/add-filter.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { Ref } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tprivateApis as componentsPrivateApis,\n\tButton,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from './lock-unlock';\nimport type { NormalizedFilter, View } from './types';\n\nconst {\n\tDropdownMenuV2: DropdownMenu,\n\tDropdownMenuItemV2: DropdownMenuItem,\n\tDropdownMenuItemLabelV2: DropdownMenuItemLabel,\n} = unlock( componentsPrivateApis );\n\ninterface AddFilterProps {\n\tfilters: NormalizedFilter[];\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n\tsetOpenedFilter: ( filter: string | null ) => void;\n}\n\nfunction AddFilter(\n\t{ filters, view, onChangeView, setOpenedFilter }: AddFilterProps,\n\tref: Ref< HTMLButtonElement >\n) {\n\tif ( ! filters.length || filters.every( ( { isPrimary } ) => isPrimary ) ) {\n\t\treturn null;\n\t}\n\tconst inactiveFilters = filters.filter( ( filter ) => ! filter.isVisible );\n\treturn (\n\t\t<DropdownMenu\n\t\t\ttrigger={\n\t\t\t\t<Button\n\t\t\t\t\t__experimentalIsFocusable\n\t\t\t\t\tsize=\"compact\"\n\t\t\t\t\tclassName=\"dataviews-filters-button\"\n\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\tdisabled={ ! inactiveFilters.length }\n\t\t\t\t\tref={ ref }\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Add filter' ) }\n\t\t\t\t</Button>\n\t\t\t}\n\t\t>\n\t\t\t{ inactiveFilters.map( ( filter ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<DropdownMenuItem\n\t\t\t\t\t\tkey={ filter.field }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetOpenedFilter( filter.field );\n\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\tfilters: [\n\t\t\t\t\t\t\t\t\t...( view.filters || [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t\toperator: filter.operators[ 0 ],\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t>\n\t\t\t\t\t\t<DropdownMenuItemLabel>\n\t\t\t\t\t\t\t{ filter.name }\n\t\t\t\t\t\t</DropdownMenuItemLabel>\n\t\t\t\t\t</DropdownMenuItem>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t</DropdownMenu>\n\t);\n}\n\nexport default forwardRef( AddFilter );\n"],"mappings":";;;;;;AAQA,IAAAA,WAAA,GAAAC,OAAA;AAIA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,WAAA,GAAAH,OAAA;AAAuC,IAAAI,WAAA,GAAAJ,OAAA;AAlBvC;AACA;AACA;;AAGA;AACA;AACA;;AAQA;AACA;AACA;;AAIA,MAAM;EACLK,cAAc,EAAEC,YAAY;EAC5BC,kBAAkB,EAAEC,gBAAgB;EACpCC,uBAAuB,EAAEC;AAC1B,CAAC,GAAG,IAAAC,kBAAM,EAAEC,uBAAsB,CAAC;AASnC,SAASC,SAASA,CACjB;EAAEC,OAAO;EAAEC,IAAI;EAAEC,YAAY;EAAEC;AAAgC,CAAC,EAChEC,GAA6B,EAC5B;EACD,IAAK,CAAEJ,OAAO,CAACK,MAAM,IAAIL,OAAO,CAACM,KAAK,CAAE,CAAE;IAAEC;EAAU,CAAC,KAAMA,SAAU,CAAC,EAAG;IAC1E,OAAO,IAAI;EACZ;EACA,MAAMC,eAAe,GAAGR,OAAO,CAACS,MAAM,CAAIA,MAAM,IAAM,CAAEA,MAAM,CAACC,SAAU,CAAC;EAC1E,oBACC,IAAApB,WAAA,CAAAqB,GAAA,EAACnB,YAAY;IACZoB,OAAO,eACN,IAAAtB,WAAA,CAAAqB,GAAA,EAAC1B,WAAA,CAAA4B,MAAM;MACNC,yBAAyB;MACzBC,IAAI,EAAC,SAAS;MACdC,SAAS,EAAC,0BAA0B;MACpCC,OAAO,EAAC,UAAU;MAClBC,QAAQ,EAAG,CAAEV,eAAe,CAACH,MAAQ;MACrCD,GAAG,EAAGA,GAAK;MAAAe,QAAA,EAET,IAAAC,QAAE,EAAE,YAAa;IAAC,CACb,CACR;IAAAD,QAAA,EAECX,eAAe,CAACa,GAAG,CAAIZ,MAAM,IAAM;MACpC,oBACC,IAAAnB,WAAA,CAAAqB,GAAA,EAACjB,gBAAgB;QAEhB4B,OAAO,EAAGA,CAAA,KAAM;UACfnB,eAAe,CAAEM,MAAM,CAACc,KAAM,CAAC;UAC/BrB,YAAY,CAAE;YACb,GAAGD,IAAI;YACPuB,IAAI,EAAE,CAAC;YACPxB,OAAO,EAAE,CACR,IAAKC,IAAI,CAACD,OAAO,IAAI,EAAE,CAAE,EACzB;cACCuB,KAAK,EAAEd,MAAM,CAACc,KAAK;cACnBE,KAAK,EAAEC,SAAS;cAChBC,QAAQ,EAAElB,MAAM,CAACmB,SAAS,CAAE,CAAC;YAC9B,CAAC;UAEH,CAAE,CAAC;QACJ,CAAG;QAAAT,QAAA,eAEH,IAAA7B,WAAA,CAAAqB,GAAA,EAACf,qBAAqB;UAAAuB,QAAA,EACnBV,MAAM,CAACoB;QAAI,CACS;MAAC,GAnBlBpB,MAAM,CAACc,KAoBI,CAAC;IAErB,CAAE;EAAC,CACU,CAAC;AAEjB;AAAC,IAAAO,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc,IAAAC,mBAAU,EAAElC,SAAU,CAAC","ignoreList":[]}
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = BulkActionsToolbar;
7
- var _react = require("react");
8
7
  var _components = require("@wordpress/components");
9
8
  var _element = require("@wordpress/element");
10
9
  var _i18n = require("@wordpress/i18n");
11
10
  var _icons = require("@wordpress/icons");
12
11
  var _compose = require("@wordpress/compose");
13
12
  var _itemActions = require("./item-actions");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
14
  /**
15
15
  * WordPress dependencies
16
16
  */
@@ -48,11 +48,13 @@ const SNACKBAR_VARIANTS = {
48
48
  function ActionTrigger({
49
49
  action,
50
50
  onClick,
51
- isBusy
51
+ isBusy,
52
+ items
52
53
  }) {
53
- return (0, _react.createElement)(_components.ToolbarButton, {
54
+ const label = typeof action.label === 'string' ? action.label : action.label(items);
55
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
54
56
  disabled: isBusy,
55
- label: action.label,
57
+ label: label,
56
58
  icon: action.icon,
57
59
  isDestructive: action.isDestructive,
58
60
  size: "compact",
@@ -71,65 +73,63 @@ function ActionButton({
71
73
  }) {
72
74
  const selectedEligibleItems = (0, _element.useMemo)(() => {
73
75
  return selectedItems.filter(item => {
74
- return action.isEligible(item);
76
+ return !action.isEligible || action.isEligible(item);
75
77
  });
76
78
  }, [action, selectedItems]);
77
- if (!!action.RenderModal) {
78
- return (0, _react.createElement)(_itemActions.ActionWithModal, {
79
- key: action.id,
79
+ if ('RenderModal' in action) {
80
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_itemActions.ActionWithModal, {
80
81
  action: action,
81
82
  items: selectedEligibleItems,
82
- ActionTrigger: ActionTrigger,
83
- onActionStart: () => {
84
- setActionInProgress(action.id);
85
- },
86
- onActionPerformed: () => {
87
- setActionInProgress(null);
88
- }
89
- });
83
+ ActionTrigger: ActionTrigger
84
+ }, action.id);
90
85
  }
91
- return (0, _react.createElement)(ActionTrigger, {
92
- key: action.id,
86
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(ActionTrigger, {
93
87
  action: action,
94
- items: selectedItems,
95
88
  onClick: () => {
96
89
  setActionInProgress(action.id);
97
- action.callback(selectedItems, () => {
98
- setActionInProgress(action.id);
99
- });
90
+ action.callback(selectedItems);
100
91
  },
92
+ items: selectedEligibleItems,
101
93
  isBusy: actionInProgress === action.id
102
- });
94
+ }, action.id);
103
95
  }
104
- function renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, setSelection) {
105
- return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_components.ToolbarGroup, null, (0, _react.createElement)("div", {
106
- className: "dataviews-bulk-actions__selection-count"
107
- }, selection.length === 1 ? (0, _i18n.__)('1 item selected') : (0, _i18n.sprintf)(
108
- // translators: %s: Total number of selected items.
109
- (0, _i18n._n)('%s item selected', '%s items selected', selection.length), selection.length))), (0, _react.createElement)(_components.ToolbarGroup, null, actionsToShow.map(action => {
110
- return (0, _react.createElement)(ActionButton, {
111
- key: action.id,
112
- action: action,
113
- selectedItems: selectedItems,
114
- actionInProgress: actionInProgress,
115
- setActionInProgress: setActionInProgress
116
- });
117
- })), (0, _react.createElement)(_components.ToolbarGroup, null, (0, _react.createElement)(_components.ToolbarButton, {
118
- icon: _icons.closeSmall,
119
- showTooltip: true,
120
- tooltipPosition: "top",
121
- label: (0, _i18n.__)('Cancel'),
122
- disabled: !!actionInProgress,
123
- onClick: () => {
124
- setSelection(EMPTY_ARRAY);
125
- }
126
- })));
96
+ function renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onSelectionChange) {
97
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
98
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
99
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
100
+ className: "dataviews-bulk-actions__selection-count",
101
+ children: selection.length === 1 ? (0, _i18n.__)('1 item selected') : (0, _i18n.sprintf)(
102
+ // translators: %s: Total number of selected items.
103
+ (0, _i18n._n)('%s item selected', '%s items selected', selection.length), selection.length)
104
+ })
105
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
106
+ children: actionsToShow.map(action => {
107
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(ActionButton, {
108
+ action: action,
109
+ selectedItems: selectedItems,
110
+ actionInProgress: actionInProgress,
111
+ setActionInProgress: setActionInProgress
112
+ }, action.id);
113
+ })
114
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
115
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarButton, {
116
+ icon: _icons.closeSmall,
117
+ showTooltip: true,
118
+ tooltipPosition: "top",
119
+ label: (0, _i18n.__)('Cancel'),
120
+ disabled: !!actionInProgress,
121
+ onClick: () => {
122
+ onSelectionChange(EMPTY_ARRAY);
123
+ }
124
+ })
125
+ })]
126
+ });
127
127
  }
128
128
  function ToolbarContent({
129
129
  selection,
130
130
  actionsToShow,
131
131
  selectedItems,
132
- setSelection
132
+ onSelectionChange
133
133
  }) {
134
134
  const [actionInProgress, setActionInProgress] = (0, _element.useState)(null);
135
135
  const buttons = (0, _element.useRef)(null);
@@ -137,9 +137,9 @@ function ToolbarContent({
137
137
  if (buttons.current) {
138
138
  buttons.current = null;
139
139
  }
140
- return renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, setSelection);
140
+ return renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onSelectionChange);
141
141
  } else if (!buttons.current) {
142
- buttons.current = renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, setSelection);
142
+ buttons.current = renderToolbarContent(selection, actionsToShow, selectedItems, actionInProgress, setActionInProgress, onSelectionChange);
143
143
  }
144
144
  return buttons.current;
145
145
  }
@@ -147,7 +147,7 @@ function BulkActionsToolbar({
147
147
  data,
148
148
  selection,
149
149
  actions = EMPTY_ARRAY,
150
- setSelection,
150
+ onSelectionChange,
151
151
  getItemId
152
152
  }) {
153
153
  const isReducedMotion = (0, _compose.useReducedMotion)();
@@ -155,28 +155,33 @@ function BulkActionsToolbar({
155
155
  return data.filter(item => selection.includes(getItemId(item)));
156
156
  }, [selection, data, getItemId]);
157
157
  const actionsToShow = (0, _element.useMemo)(() => actions.filter(action => {
158
- return action.supportsBulk && action.icon && selectedItems.some(item => action.isEligible(item));
158
+ return action.supportsBulk && action.icon && selectedItems.some(item => !action.isEligible || action.isEligible(item));
159
159
  }), [actions, selectedItems]);
160
160
  if (selection && selection.length === 0 || actionsToShow.length === 0) {
161
161
  return null;
162
162
  }
163
- return (0, _react.createElement)(_components.__unstableAnimatePresence, null, (0, _react.createElement)(_components.__unstableMotion.div, {
164
- layout: !isReducedMotion // See https://www.framer.com/docs/animation/#layout-animations
165
- ,
166
- initial: 'init',
167
- animate: 'open',
168
- exit: 'exit',
169
- variants: isReducedMotion ? undefined : SNACKBAR_VARIANTS,
170
- className: "dataviews-bulk-actions"
171
- }, (0, _react.createElement)(_components.Toolbar, {
172
- label: (0, _i18n.__)('Bulk actions')
173
- }, (0, _react.createElement)("div", {
174
- className: "dataviews-bulk-actions-toolbar-wrapper"
175
- }, (0, _react.createElement)(ToolbarContent, {
176
- selection: selection,
177
- actionsToShow: actionsToShow,
178
- selectedItems: selectedItems,
179
- setSelection: setSelection
180
- })))));
163
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__unstableAnimatePresence, {
164
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__unstableMotion.div, {
165
+ layout: !isReducedMotion // See https://www.framer.com/docs/animation/#layout-animations
166
+ ,
167
+ initial: "init",
168
+ animate: "open",
169
+ exit: "exit",
170
+ variants: isReducedMotion ? undefined : SNACKBAR_VARIANTS,
171
+ className: "dataviews-bulk-actions",
172
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Toolbar, {
173
+ label: (0, _i18n.__)('Bulk actions'),
174
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
175
+ className: "dataviews-bulk-actions-toolbar-wrapper",
176
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ToolbarContent, {
177
+ selection: selection,
178
+ actionsToShow: actionsToShow,
179
+ selectedItems: selectedItems,
180
+ onSelectionChange: onSelectionChange
181
+ })
182
+ })
183
+ })
184
+ })
185
+ });
181
186
  }
182
187
  //# sourceMappingURL=bulk-actions-toolbar.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_components","require","_element","_i18n","_icons","_compose","_itemActions","SNACKBAR_VARIANTS","init","bottom","open","transition","type","duration","ease","exit","opacity","ActionTrigger","action","onClick","isBusy","_react","createElement","ToolbarButton","disabled","label","icon","isDestructive","size","__experimentalIsFocusable","tooltipPosition","EMPTY_ARRAY","ActionButton","selectedItems","actionInProgress","setActionInProgress","selectedEligibleItems","useMemo","filter","item","isEligible","RenderModal","ActionWithModal","key","id","items","onActionStart","onActionPerformed","callback","renderToolbarContent","selection","actionsToShow","setSelection","Fragment","ToolbarGroup","className","length","__","sprintf","_n","map","closeSmall","showTooltip","ToolbarContent","useState","buttons","useRef","current","BulkActionsToolbar","data","actions","getItemId","isReducedMotion","useReducedMotion","includes","supportsBulk","some","__unstableAnimatePresence","__unstableMotion","div","layout","initial","animate","variants","undefined","Toolbar"],"sources":["@wordpress/dataviews/src/bulk-actions-toolbar.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tToolbarButton,\n\tToolbar,\n\tToolbarGroup,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useMemo, useState, useRef } from '@wordpress/element';\nimport { _n, sprintf, __ } from '@wordpress/i18n';\nimport { closeSmall } from '@wordpress/icons';\nimport { useReducedMotion } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ActionWithModal } from './item-actions';\n\nconst SNACKBAR_VARIANTS = {\n\tinit: {\n\t\tbottom: -48,\n\t},\n\topen: {\n\t\tbottom: 24,\n\t\ttransition: {\n\t\t\tbottom: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },\n\t\t},\n\t},\n\texit: {\n\t\topacity: 0,\n\t\tbottom: 24,\n\t\ttransition: {\n\t\t\topacity: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },\n\t\t},\n\t},\n};\n\nfunction ActionTrigger( { action, onClick, isBusy } ) {\n\treturn (\n\t\t<ToolbarButton\n\t\t\tdisabled={ isBusy }\n\t\t\tlabel={ action.label }\n\t\t\ticon={ action.icon }\n\t\t\tisDestructive={ action.isDestructive }\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t\tisBusy={ isBusy }\n\t\t\t__experimentalIsFocusable\n\t\t\ttooltipPosition=\"top\"\n\t\t/>\n\t);\n}\n\nconst EMPTY_ARRAY = [];\n\nfunction ActionButton( {\n\taction,\n\tselectedItems,\n\tactionInProgress,\n\tsetActionInProgress,\n} ) {\n\tconst selectedEligibleItems = useMemo( () => {\n\t\treturn selectedItems.filter( ( item ) => {\n\t\t\treturn action.isEligible( item );\n\t\t} );\n\t}, [ action, selectedItems ] );\n\tif ( !! action.RenderModal ) {\n\t\treturn (\n\t\t\t<ActionWithModal\n\t\t\t\tkey={ action.id }\n\t\t\t\taction={ action }\n\t\t\t\titems={ selectedEligibleItems }\n\t\t\t\tActionTrigger={ ActionTrigger }\n\t\t\t\tonActionStart={ () => {\n\t\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\t} }\n\t\t\t\tonActionPerformed={ () => {\n\t\t\t\t\tsetActionInProgress( null );\n\t\t\t\t} }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<ActionTrigger\n\t\t\tkey={ action.id }\n\t\t\taction={ action }\n\t\t\titems={ selectedItems }\n\t\t\tonClick={ () => {\n\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\taction.callback( selectedItems, () => {\n\t\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\t} );\n\t\t\t} }\n\t\t\tisBusy={ actionInProgress === action.id }\n\t\t/>\n\t);\n}\n\nfunction renderToolbarContent(\n\tselection,\n\tactionsToShow,\n\tselectedItems,\n\tactionInProgress,\n\tsetActionInProgress,\n\tsetSelection\n) {\n\treturn (\n\t\t<>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<div className=\"dataviews-bulk-actions__selection-count\">\n\t\t\t\t\t{ selection.length === 1\n\t\t\t\t\t\t? __( '1 item selected' )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Total number of selected items.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'%s item selected',\n\t\t\t\t\t\t\t\t\t'%s items selected',\n\t\t\t\t\t\t\t\t\tselection.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tselection.length\n\t\t\t\t\t\t ) }\n\t\t\t\t</div>\n\t\t\t</ToolbarGroup>\n\t\t\t<ToolbarGroup>\n\t\t\t\t{ actionsToShow.map( ( action ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\taction={ action }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tactionInProgress={ actionInProgress }\n\t\t\t\t\t\t\tsetActionInProgress={ setActionInProgress }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ToolbarGroup>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\tlabel={ __( 'Cancel' ) }\n\t\t\t\t\tdisabled={ !! actionInProgress }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tsetSelection( EMPTY_ARRAY );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</ToolbarGroup>\n\t\t</>\n\t);\n}\n\nfunction ToolbarContent( {\n\tselection,\n\tactionsToShow,\n\tselectedItems,\n\tsetSelection,\n} ) {\n\tconst [ actionInProgress, setActionInProgress ] = useState( null );\n\tconst buttons = useRef( null );\n\tif ( ! actionInProgress ) {\n\t\tif ( buttons.current ) {\n\t\t\tbuttons.current = null;\n\t\t}\n\t\treturn renderToolbarContent(\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tsetSelection\n\t\t);\n\t} else if ( ! buttons.current ) {\n\t\tbuttons.current = renderToolbarContent(\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tsetSelection\n\t\t);\n\t}\n\treturn buttons.current;\n}\n\nexport default function BulkActionsToolbar( {\n\tdata,\n\tselection,\n\tactions = EMPTY_ARRAY,\n\tsetSelection,\n\tgetItemId,\n} ) {\n\tconst isReducedMotion = useReducedMotion();\n\tconst selectedItems = useMemo( () => {\n\t\treturn data.filter( ( item ) =>\n\t\t\tselection.includes( getItemId( item ) )\n\t\t);\n\t}, [ selection, data, getItemId ] );\n\n\tconst actionsToShow = useMemo(\n\t\t() =>\n\t\t\tactions.filter( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\taction.icon &&\n\t\t\t\t\tselectedItems.some( ( item ) => action.isEligible( item ) )\n\t\t\t\t);\n\t\t\t} ),\n\t\t[ actions, selectedItems ]\n\t);\n\n\tif (\n\t\t( selection && selection.length === 0 ) ||\n\t\tactionsToShow.length === 0\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<AnimatePresence>\n\t\t\t<motion.div\n\t\t\t\tlayout={ ! isReducedMotion } // See https://www.framer.com/docs/animation/#layout-animations\n\t\t\t\tinitial={ 'init' }\n\t\t\t\tanimate={ 'open' }\n\t\t\t\texit={ 'exit' }\n\t\t\t\tvariants={ isReducedMotion ? undefined : SNACKBAR_VARIANTS }\n\t\t\t\tclassName=\"dataviews-bulk-actions\"\n\t\t\t>\n\t\t\t\t<Toolbar label={ __( 'Bulk actions' ) }>\n\t\t\t\t\t<div className=\"dataviews-bulk-actions-toolbar-wrapper\">\n\t\t\t\t\t\t<ToolbarContent\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tactionsToShow={ actionsToShow }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tsetSelection={ setSelection }\n\t\t\t\t\t\t/>\n\t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d,gBAAO,EAC5B,MACCiC,OAAO,CAAChC,MAAM,CAAIpB,MAAM,IAAM;IAC7B,OACCA,MAAM,CAACyD,YAAY,IACnBzD,MAAM,CAACQ,IAAI,IACXO,aAAa,CAAC2C,IAAI,CAAIrC,IAAI,IAAMrB,MAAM,CAACsB,UAAU,CAAED,IAAK,CAAE,CAAC;EAE7D,CAAE,CAAC,EACJ,CAAE+B,OAAO,EAAErC,aAAa,CACzB,CAAC;EAED,IACGiB,SAAS,IAAIA,SAAS,CAACM,MAAM,KAAK,CAAC,IACrCL,aAAa,CAACK,MAAM,KAAK,CAAC,EACzB;IACD,OAAO,IAAI;EACZ;EAEA,OACC,IAAAnC,MAAA,CAAAC,aAAA,EAACtB,WAAA,CAAA6E,yBAAe,QACf,IAAAxD,MAAA,CAAAC,aAAA,EAACtB,WAAA,CAAA8E,gBAAM,CAACC,GAAG;IACVC,MAAM,EAAG,CAAER,eAAiB,CAAC;IAAA;IAC7BS,OAAO,EAAG,MAAQ;IAClBC,OAAO,EAAG,MAAQ;IAClBnE,IAAI,EAAG,MAAQ;IACfoE,QAAQ,EAAGX,eAAe,GAAGY,SAAS,GAAG7E,iBAAmB;IAC5DgD,SAAS,EAAC;EAAwB,GAElC,IAAAlC,MAAA,CAAAC,aAAA,EAACtB,WAAA,CAAAqF,OAAO;IAAC5D,KAAK,EAAG,IAAAgC,QAAE,EAAE,cAAe;EAAG,GACtC,IAAApC,MAAA,CAAAC,aAAA;IAAKiC,SAAS,EAAC;EAAwC,GACtD,IAAAlC,MAAA,CAAAC,aAAA,EAACyC,cAAc;IACdb,SAAS,EAAGA,SAAW;IACvBC,aAAa,EAAGA,aAAe;IAC/BlB,aAAa,EAAGA,aAAe;IAC/BmB,YAAY,EAAGA;EAAc,CAC7B,CACG,CACG,CACE,CACI,CAAC;AAEpB","ignoreList":[]}
1
+ {"version":3,"names":["_components","require","_element","_i18n","_icons","_compose","_itemActions","_jsxRuntime","SNACKBAR_VARIANTS","init","bottom","open","transition","type","duration","ease","exit","opacity","ActionTrigger","action","onClick","isBusy","items","label","jsx","ToolbarButton","disabled","icon","isDestructive","size","__experimentalIsFocusable","tooltipPosition","EMPTY_ARRAY","ActionButton","selectedItems","actionInProgress","setActionInProgress","selectedEligibleItems","useMemo","filter","item","isEligible","ActionWithModal","id","callback","renderToolbarContent","selection","actionsToShow","onSelectionChange","jsxs","Fragment","children","ToolbarGroup","className","length","__","sprintf","_n","map","closeSmall","showTooltip","ToolbarContent","useState","buttons","useRef","current","BulkActionsToolbar","data","actions","getItemId","isReducedMotion","useReducedMotion","includes","supportsBulk","some","__unstableAnimatePresence","__unstableMotion","div","layout","initial","animate","variants","undefined","Toolbar"],"sources":["@wordpress/dataviews/src/bulk-actions-toolbar.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tToolbarButton,\n\tToolbar,\n\tToolbarGroup,\n\t__unstableMotion as motion,\n\t__unstableAnimatePresence as AnimatePresence,\n} from '@wordpress/components';\nimport { useMemo, useState, useRef } from '@wordpress/element';\nimport { _n, sprintf, __ } from '@wordpress/i18n';\nimport { closeSmall } from '@wordpress/icons';\nimport { useReducedMotion } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { ActionWithModal } from './item-actions';\nimport type { Action, AnyItem } from './types';\nimport type { ActionTriggerProps } from './item-actions';\n\ninterface ActionButtonProps< Item extends AnyItem > {\n\taction: Action< Item >;\n\tselectedItems: Item[];\n\tactionInProgress: string | null;\n\tsetActionInProgress: ( actionId: string | null ) => void;\n}\n\ninterface ToolbarContentProps< Item extends AnyItem > {\n\tselection: string[];\n\tactionsToShow: Action< Item >[];\n\tselectedItems: Item[];\n\tonSelectionChange: ( selection: Item[] ) => void;\n}\n\ninterface BulkActionsToolbarProps< Item extends AnyItem > {\n\tdata: Item[];\n\tselection: string[];\n\tactions: Action< Item >[];\n\tonSelectionChange: ( selection: Item[] ) => void;\n\tgetItemId: ( item: Item ) => string;\n}\n\nconst SNACKBAR_VARIANTS = {\n\tinit: {\n\t\tbottom: -48,\n\t},\n\topen: {\n\t\tbottom: 24,\n\t\ttransition: {\n\t\t\tbottom: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },\n\t\t},\n\t},\n\texit: {\n\t\topacity: 0,\n\t\tbottom: 24,\n\t\ttransition: {\n\t\t\topacity: { type: 'tween', duration: 0.2, ease: [ 0, 0, 0.2, 1 ] },\n\t\t},\n\t},\n};\n\nfunction ActionTrigger< Item extends AnyItem >( {\n\taction,\n\tonClick,\n\tisBusy,\n\titems,\n}: ActionTriggerProps< Item > ) {\n\tconst label =\n\t\ttypeof action.label === 'string' ? action.label : action.label( items );\n\treturn (\n\t\t<ToolbarButton\n\t\t\tdisabled={ isBusy }\n\t\t\tlabel={ label }\n\t\t\ticon={ action.icon }\n\t\t\tisDestructive={ action.isDestructive }\n\t\t\tsize=\"compact\"\n\t\t\tonClick={ onClick }\n\t\t\tisBusy={ isBusy }\n\t\t\t__experimentalIsFocusable\n\t\t\ttooltipPosition=\"top\"\n\t\t/>\n\t);\n}\n\nconst EMPTY_ARRAY: [] = [];\n\nfunction ActionButton< Item extends AnyItem >( {\n\taction,\n\tselectedItems,\n\tactionInProgress,\n\tsetActionInProgress,\n}: ActionButtonProps< Item > ) {\n\tconst selectedEligibleItems = useMemo( () => {\n\t\treturn selectedItems.filter( ( item ) => {\n\t\t\treturn ! action.isEligible || action.isEligible( item );\n\t\t} );\n\t}, [ action, selectedItems ] );\n\tif ( 'RenderModal' in action ) {\n\t\treturn (\n\t\t\t<ActionWithModal\n\t\t\t\tkey={ action.id }\n\t\t\t\taction={ action }\n\t\t\t\titems={ selectedEligibleItems }\n\t\t\t\tActionTrigger={ ActionTrigger }\n\t\t\t/>\n\t\t);\n\t}\n\treturn (\n\t\t<ActionTrigger\n\t\t\tkey={ action.id }\n\t\t\taction={ action }\n\t\t\tonClick={ () => {\n\t\t\t\tsetActionInProgress( action.id );\n\t\t\t\taction.callback( selectedItems );\n\t\t\t} }\n\t\t\titems={ selectedEligibleItems }\n\t\t\tisBusy={ actionInProgress === action.id }\n\t\t/>\n\t);\n}\n\nfunction renderToolbarContent< Item extends AnyItem >(\n\tselection: string[],\n\tactionsToShow: Action< Item >[],\n\tselectedItems: Item[],\n\tactionInProgress: string | null,\n\tsetActionInProgress: ( actionId: string | null ) => void,\n\tonSelectionChange: ( selection: Item[] ) => void\n) {\n\treturn (\n\t\t<>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<div className=\"dataviews-bulk-actions__selection-count\">\n\t\t\t\t\t{ selection.length === 1\n\t\t\t\t\t\t? __( '1 item selected' )\n\t\t\t\t\t\t: sprintf(\n\t\t\t\t\t\t\t\t// translators: %s: Total number of selected items.\n\t\t\t\t\t\t\t\t_n(\n\t\t\t\t\t\t\t\t\t'%s item selected',\n\t\t\t\t\t\t\t\t\t'%s items selected',\n\t\t\t\t\t\t\t\t\tselection.length\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\tselection.length\n\t\t\t\t\t\t ) }\n\t\t\t\t</div>\n\t\t\t</ToolbarGroup>\n\t\t\t<ToolbarGroup>\n\t\t\t\t{ actionsToShow.map( ( action ) => {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<ActionButton\n\t\t\t\t\t\t\tkey={ action.id }\n\t\t\t\t\t\t\taction={ action }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tactionInProgress={ actionInProgress }\n\t\t\t\t\t\t\tsetActionInProgress={ setActionInProgress }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} ) }\n\t\t\t</ToolbarGroup>\n\t\t\t<ToolbarGroup>\n\t\t\t\t<ToolbarButton\n\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\tshowTooltip\n\t\t\t\t\ttooltipPosition=\"top\"\n\t\t\t\t\tlabel={ __( 'Cancel' ) }\n\t\t\t\t\tdisabled={ !! actionInProgress }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonSelectionChange( EMPTY_ARRAY );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</ToolbarGroup>\n\t\t</>\n\t);\n}\n\nfunction ToolbarContent< Item extends AnyItem >( {\n\tselection,\n\tactionsToShow,\n\tselectedItems,\n\tonSelectionChange,\n}: ToolbarContentProps< Item > ) {\n\tconst [ actionInProgress, setActionInProgress ] = useState< string | null >(\n\t\tnull\n\t);\n\tconst buttons = useRef< JSX.Element | null >( null );\n\tif ( ! actionInProgress ) {\n\t\tif ( buttons.current ) {\n\t\t\tbuttons.current = null;\n\t\t}\n\t\treturn renderToolbarContent(\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonSelectionChange\n\t\t);\n\t} else if ( ! buttons.current ) {\n\t\tbuttons.current = renderToolbarContent(\n\t\t\tselection,\n\t\t\tactionsToShow,\n\t\t\tselectedItems,\n\t\t\tactionInProgress,\n\t\t\tsetActionInProgress,\n\t\t\tonSelectionChange\n\t\t);\n\t}\n\treturn buttons.current;\n}\n\nexport default function BulkActionsToolbar< Item extends AnyItem >( {\n\tdata,\n\tselection,\n\tactions = EMPTY_ARRAY,\n\tonSelectionChange,\n\tgetItemId,\n}: BulkActionsToolbarProps< Item > ) {\n\tconst isReducedMotion = useReducedMotion();\n\tconst selectedItems = useMemo( () => {\n\t\treturn data.filter( ( item ) =>\n\t\t\tselection.includes( getItemId( item ) )\n\t\t);\n\t}, [ selection, data, getItemId ] );\n\n\tconst actionsToShow = useMemo(\n\t\t() =>\n\t\t\tactions.filter( ( action ) => {\n\t\t\t\treturn (\n\t\t\t\t\taction.supportsBulk &&\n\t\t\t\t\taction.icon &&\n\t\t\t\t\tselectedItems.some(\n\t\t\t\t\t\t( item ) =>\n\t\t\t\t\t\t\t! action.isEligible || action.isEligible( item )\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t} ),\n\t\t[ actions, selectedItems ]\n\t);\n\n\tif (\n\t\t( selection && selection.length === 0 ) ||\n\t\tactionsToShow.length === 0\n\t) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<AnimatePresence>\n\t\t\t<motion.div\n\t\t\t\tlayout={ ! isReducedMotion } // See https://www.framer.com/docs/animation/#layout-animations\n\t\t\t\tinitial=\"init\"\n\t\t\t\tanimate=\"open\"\n\t\t\t\texit=\"exit\"\n\t\t\t\tvariants={ isReducedMotion ? undefined : SNACKBAR_VARIANTS }\n\t\t\t\tclassName=\"dataviews-bulk-actions\"\n\t\t\t>\n\t\t\t\t<Toolbar label={ __( 'Bulk actions' ) }>\n\t\t\t\t\t<div className=\"dataviews-bulk-actions-toolbar-wrapper\">\n\t\t\t\t\t\t<ToolbarContent\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tactionsToShow={ actionsToShow }\n\t\t\t\t\t\t\tselectedItems={ selectedItems }\n\t\t\t\t\t\t\tonSelectionChange={ onSelectionChange }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t</Toolbar>\n\t\t\t</motion.div>\n\t\t</AnimatePresence>\n\t);\n}\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAKA,IAAAK,YAAA,GAAAL,OAAA;AAAiD,IAAAM,WAAA,GAAAN,OAAA;AAlBjD;AACA;AACA;;AAaA;AACA;AACA;;AA2BA,MAAMO,iBAAiB,GAAG;EACzBC,IAAI,EAAE;IACLC,MAAM,EAAE,CAAC;EACV,CAAC;EACDC,IAAI,EAAE;IACLD,MAAM,EAAE,EAAE;IACVE,UAAU,EAAE;MACXF,MAAM,EAAE;QAAEG,IAAI,EAAE,OAAO;QAAEC,QAAQ,EAAE,GAAG;QAAEC,IAAI,EAAE,CAAE,CAAC,EAAE,C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