@wordpress/dataviews 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/constants.js +1 -26
  3. package/build/constants.js.map +1 -1
  4. package/build/dataviews.js +2 -1
  5. package/build/dataviews.js.map +1 -1
  6. package/build/filter-and-sort-data-view.js +72 -65
  7. package/build/filter-and-sort-data-view.js.map +1 -1
  8. package/build/index.js +2 -2
  9. package/build/index.js.map +1 -1
  10. package/build/layouts.js +38 -0
  11. package/build/layouts.js.map +1 -0
  12. package/build/normalize-fields.js +7 -2
  13. package/build/normalize-fields.js.map +1 -1
  14. package/build/types.js +6 -0
  15. package/build/types.js.map +1 -0
  16. package/build/view-actions.js +2 -1
  17. package/build/view-actions.js.map +1 -1
  18. package/build-module/constants.js +1 -25
  19. package/build-module/constants.js.map +1 -1
  20. package/build-module/dataviews.js +2 -1
  21. package/build-module/dataviews.js.map +1 -1
  22. package/build-module/filter-and-sort-data-view.js +72 -65
  23. package/build-module/filter-and-sort-data-view.js.map +1 -1
  24. package/build-module/index.js +1 -1
  25. package/build-module/index.js.map +1 -1
  26. package/build-module/layouts.js +30 -0
  27. package/build-module/layouts.js.map +1 -0
  28. package/build-module/normalize-fields.js +7 -2
  29. package/build-module/normalize-fields.js.map +1 -1
  30. package/build-module/types.js +2 -0
  31. package/build-module/types.js.map +1 -0
  32. package/build-module/view-actions.js +2 -1
  33. package/build-module/view-actions.js.map +1 -1
  34. package/build-style/style-rtl.css +20 -17
  35. package/build-style/style.css +20 -17
  36. package/build-types/constants.d.ts +45 -0
  37. package/build-types/constants.d.ts.map +1 -0
  38. package/build-types/filter-and-sort-data-view.d.ts +18 -0
  39. package/build-types/filter-and-sort-data-view.d.ts.map +1 -0
  40. package/build-types/normalize-fields.d.ts +12 -0
  41. package/build-types/normalize-fields.d.ts.map +1 -0
  42. package/build-types/types.d.ts +122 -0
  43. package/build-types/types.d.ts.map +1 -0
  44. package/package.json +11 -11
  45. package/src/{constants.js → constants.ts} +1 -35
  46. package/src/dataviews.js +2 -1
  47. package/src/filter-and-sort-data-view.ts +164 -0
  48. package/src/index.js +1 -1
  49. package/src/layouts.js +39 -0
  50. package/src/normalize-fields.ts +23 -0
  51. package/src/stories/fixtures.js +0 -2
  52. package/src/style.scss +23 -16
  53. package/src/types.ts +144 -0
  54. package/src/view-actions.js +2 -1
  55. package/tsconfig.json +20 -0
  56. package/tsconfig.tsbuildinfo +1 -0
  57. package/src/filter-and-sort-data-view.js +0 -154
  58. package/src/normalize-fields.js +0 -17
package/src/style.scss CHANGED
@@ -292,25 +292,26 @@
292
292
  }
293
293
 
294
294
  .dataviews-view-grid__card {
295
- border-radius: $radius-block-ui * 2;
296
- border: 1px solid $gray-200;
297
295
  height: 100%;
298
296
  justify-content: flex-start;
299
297
 
300
298
  .dataviews-view-grid__title-actions {
301
- padding: $grid-unit-05 $grid-unit $grid-unit-05 $grid-unit-05;
299
+ padding: $grid-unit-10 0 $grid-unit-05;
302
300
  }
303
301
 
304
302
  .dataviews-view-grid__primary-field {
305
- min-height: $grid-unit-50;
303
+ min-height: $grid-unit-40; // Preserve layout when there is no ellipsis button
306
304
  }
307
- &.is-selected {
308
- border-color: var(--wp-admin-theme-color);
309
- background-color: rgba(var(--wp-admin-theme-color--rgb), 0.04);
310
305
 
306
+ &.is-selected {
311
307
  .dataviews-view-grid__fields .dataviews-view-grid__field .dataviews-view-grid__field-value {
312
308
  color: $gray-900;
313
309
  }
310
+
311
+ .page-pages-preview-field__button::after {
312
+ box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
313
+ background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
314
+ }
314
315
  }
315
316
  }
316
317
 
@@ -318,15 +319,27 @@
318
319
  width: 100%;
319
320
  min-height: 200px;
320
321
  aspect-ratio: 1/1;
321
- border-bottom: 1px solid $gray-200;
322
322
  background-color: $gray-100;
323
- border-radius: 3px 3px 0 0;
323
+ border-radius: $grid-unit-05;
324
+ overflow: hidden;
325
+ position: relative;
324
326
 
325
327
  img {
326
328
  object-fit: cover;
327
329
  width: 100%;
328
330
  height: 100%;
329
331
  }
332
+
333
+ &::after {
334
+ content: "";
335
+ position: absolute;
336
+ top: 0;
337
+ left: 0;
338
+ width: 100%;
339
+ height: 100%;
340
+ box-shadow: inset 0 0 0 $border-width rgba(0, 0, 0, 0.1);
341
+ border-radius: $grid-unit-05;
342
+ }
330
343
  }
331
344
 
332
345
  .dataviews-view-grid__fields {
@@ -337,7 +350,6 @@
337
350
  &:not(:empty) {
338
351
  padding: $grid-unit-15 0;
339
352
  padding-top: 0;
340
- margin: 0 $grid-unit-15;
341
353
  }
342
354
 
343
355
  .dataviews-view-grid__field {
@@ -366,8 +378,7 @@
366
378
 
367
379
  .dataviews-view-grid__badge-fields {
368
380
  &:not(:empty) {
369
- padding: $grid-unit-15;
370
- padding-top: 0;
381
+ padding-bottom: $grid-unit-15;
371
382
  }
372
383
 
373
384
  .dataviews-view-grid__field-value {
@@ -555,10 +566,6 @@
555
566
  flex-shrink: 0;
556
567
  }
557
568
 
558
- .dataviews-view-grid__title-actions .dataviews-view-table-selection-checkbox {
559
- margin-left: $grid-unit-10;
560
- }
561
-
562
569
  .dataviews-filter-summary__popover {
563
570
  .components-popover__content {
564
571
  width: 230px;
package/src/types.ts ADDED
@@ -0,0 +1,144 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ReactNode } from 'react';
5
+
6
+ type Item = Record< string, any >;
7
+
8
+ interface Option {
9
+ value: any;
10
+ label: string;
11
+ }
12
+
13
+ interface filterByConfig {
14
+ operators?: Operator[];
15
+ isPrimary?: boolean;
16
+ }
17
+
18
+ type Operator = 'is' | 'isNot' | 'isAny' | 'isNone' | 'isAll' | 'isNotAll';
19
+
20
+ export interface Field {
21
+ /**
22
+ * The unique identifier of the field.
23
+ */
24
+ id: string;
25
+
26
+ /**
27
+ * The label of the field. Defaults to the id.
28
+ */
29
+ header?: string;
30
+
31
+ /**
32
+ * Callback used to retrieve the value of the field from the item.
33
+ * Defaults to `item[ field.id ]`.
34
+ */
35
+ getValue?: ( { item }: { item: Item } ) => any;
36
+
37
+ /**
38
+ * Callback used to render the field. Defaults to `field.getValue`.
39
+ */
40
+ render?: ( { item }: { item: Item } ) => ReactNode;
41
+
42
+ /**
43
+ * The width of the field column.
44
+ */
45
+ width: string | number | undefined;
46
+
47
+ /**
48
+ * The minimum width of the field column.
49
+ */
50
+ maxWidth: string | number | undefined;
51
+
52
+ /**
53
+ * The maximum width of the field column.
54
+ */
55
+ minWidth: string | number | undefined;
56
+
57
+ /**
58
+ * Whether the field is sortable.
59
+ */
60
+ enableSorting: boolean | undefined;
61
+
62
+ /**
63
+ * Whether the field is searchable.
64
+ */
65
+ enableGlobalSearch: boolean | undefined;
66
+
67
+ /**
68
+ * Whether the field is filterable.
69
+ */
70
+ enableHiding: boolean | undefined;
71
+
72
+ /**
73
+ * The list of options to pick from when using the field as a filter.
74
+ */
75
+ elements: Option[] | undefined;
76
+
77
+ /**
78
+ * Filter config for the field.
79
+ */
80
+ filterBy: filterByConfig | undefined;
81
+ }
82
+
83
+ export type NormalizedField = Required< Field >;
84
+
85
+ export type Data = Item[];
86
+
87
+ export interface Filter {
88
+ /**
89
+ * The field to filter by.
90
+ */
91
+ field: string;
92
+
93
+ /**
94
+ * The operator to use.
95
+ */
96
+ operator: Operator;
97
+
98
+ /**
99
+ * The value to filter by.
100
+ */
101
+ value: any;
102
+ }
103
+
104
+ export interface View {
105
+ /**
106
+ * The layout of the view.
107
+ */
108
+ type: string;
109
+
110
+ /**
111
+ * The global search term.
112
+ */
113
+ search?: string;
114
+
115
+ /**
116
+ * The filters to apply.
117
+ */
118
+ filters: Filter[];
119
+
120
+ /**
121
+ * The sorting configuration.
122
+ */
123
+ sort?: {
124
+ /**
125
+ * The field to sort by.
126
+ */
127
+ field: string;
128
+
129
+ /**
130
+ * The direction to sort by.
131
+ */
132
+ direction: string;
133
+ };
134
+
135
+ /**
136
+ * The active page
137
+ */
138
+ page?: number;
139
+
140
+ /**
141
+ * The number of items per page
142
+ */
143
+ perPage?: number;
144
+ }
@@ -13,7 +13,8 @@ import { settings } from '@wordpress/icons';
13
13
  * Internal dependencies
14
14
  */
15
15
  import { unlock } from './lock-unlock';
16
- import { VIEW_LAYOUTS, SORTING_DIRECTIONS } from './constants';
16
+ import { SORTING_DIRECTIONS } from './constants';
17
+ import { VIEW_LAYOUTS } from './layouts';
17
18
 
18
19
  const {
19
20
  DropdownMenuV2: DropdownMenu,
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig.json",
3
+ "extends": "../../tsconfig.base.json",
4
+ "compilerOptions": {
5
+ "rootDir": "src",
6
+ "declarationDir": "build-types"
7
+ },
8
+ "references": [
9
+ { "path": "../a11y" },
10
+ { "path": "../components" },
11
+ { "path": "../compose" },
12
+ { "path": "../element" },
13
+ { "path": "../i18n" },
14
+ { "path": "../icons" },
15
+ { "path": "../keycodes" },
16
+ { "path": "../primitives" },
17
+ { "path": "../private-apis" }
18
+ ],
19
+ "include": [ "src/**/*.ts", "src/**/*.tsx" ]
20
+ }
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2016.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.date.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.es2023.collection.d.ts","../../node_modules/typescript/lib/lib.esnext.collection.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.esnext.disposable.d.ts","../../node_modules/typescript/lib/lib.esnext.promise.d.ts","../../node_modules/typescript/lib/lib.esnext.decorators.d.ts","../../node_modules/typescript/lib/lib.esnext.object.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../i18n/build-types/sprintf.d.ts","../hooks/build-types/createAddHook.d.ts","../hooks/build-types/createRemoveHook.d.ts","../hooks/build-types/createHasHook.d.ts","../hooks/build-types/createDoingHook.d.ts","../hooks/build-types/createDidHook.d.ts","../hooks/build-types/index.d.ts","../hooks/build-types/createHooks.d.ts","../i18n/build-types/create-i18n.d.ts","../i18n/build-types/default-i18n.d.ts","../i18n/build-types/index.d.ts","./src/constants.ts","../../node_modules/remove-accents/index.d.ts","../../node_modules/@types/react/global.d.ts","../../node_modules/csstype/index.d.ts","../../node_modules/@types/prop-types/index.d.ts","../../node_modules/@types/scheduler/tracing.d.ts","../../node_modules/@types/react/index.d.ts","./src/types.ts","./src/normalize-fields.ts","./src/filter-and-sort-data-view.ts"],"fileInfos":[{"version":"824cb491a40f7e8fdeb56f1df5edf91b23f3e3ee6b4cde84d4a99be32338faee","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","1c0cdb8dc619bc549c3e5020643e7cf7ae7940058e8c7e5aefa5871b6d86f44b","886e50ef125efb7878f744e86908884c0133e7a6d9d80013f421b0cd8fb2af94",{"version":"87d693a4920d794a73384b3c779cadcb8548ac6945aa7a925832fe2418c9527a","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"b20fe0eca9a4e405f1a5ae24a2b3290b37cf7f21eba6cbe4fc3fab979237d4f3","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"8073890e29d2f46fdbc19b8d6d2eb9ea58db9a2052f8640af20baff9afbc8640","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"b1cb28af0c891c8c96b2d6b7be76bd394fddcfdb4709a20ba05a7c1605eea0f9","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"15b98a533864d324e5f57cd3cfc0579b231df58c1c0f6063ea0fcb13c3c74ff9","affectsGlobalScope":true},{"version":"ac77cb3e8c6d3565793eb90a8373ee8033146315a3dbead3bde8db5eaf5e5ec6","affectsGlobalScope":true},{"version":"d4b1d2c51d058fc21ec2629fff7a76249dec2e36e12960ea056e3ef89174080f","affectsGlobalScope":true},{"version":"2fef54945a13095fdb9b84f705f2b5994597640c46afeb2ce78352fab4cb3279","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"2f1fe46a7a4e25a4a414d5491c7b39b695a6f37e97a1bdfeb71d430f98c3ed10","faf78d76e0042f05c6ad2eb38ee410cd4ea2854e5f5aff14f9b328d0a8115d62","d238c17667e457cba3da40546d2ef06876c5e5828df09c6b8404f223f189bb7d","a9c883297d78a7255479719aa87fb89b716f10c8c8936642bcb95522de3ca774","4f8ff9897ced0fe4b19defefb2db74f9448f04bca3ded248202fcc1a7bf11f02","c02d9d4c463913d817b35147c866bdb14c8ccba6fd06255877317dace5258781","6110b1abe60e43633e27444dfd81bbc6b5a07468549a985500d0991106b1e998","b3920d0dae5ffb54b3b8a4b6c53ce29e38a67f06b9595fee369ef1e37a3b5db4","fe6d71e5f4b524eab952a9e3cbb0e54abb2d0335cb2b47d91b00095b1613bcff","0beaa0562c80cdd93e5ab0dc9d1b314921afddfa8ee3cb976153ac620c89983f","2a49b24214a9709c04c7d21d99f1473058bd3b4d1310655288347a4c8862da30",{"version":"cda04b900fe4736ed8cf237703f24333f2b117851e9473bfaaaebc009950d64d","signature":"4e32d43c4f79c6d95ba6940135f4ccf42b160182f11181550a3a624e9d4dc7d5"},"ddf9ae86061a50cb95914a7e59cca5737fae145d23bbcc0009d65bbd27b0df43",{"version":"bbdf156fea2fabed31a569445835aeedcc33643d404fcbaa54541f06c109df3f","affectsGlobalScope":true},"4c68749a564a6facdf675416d75789ee5a557afda8960e0803cf6711fa569288","f7b46d22a307739c145e5fddf537818038fdfffd580d79ed717f4d4d37249380","f5a8b384f182b3851cec3596ccc96cb7464f8d3469f48c74bf2befb782a19de5",{"version":"5917af4ff931b050dba49a1dedd9c00f15f7b3dc4345ad8491bfacd2ec68ed32","affectsGlobalScope":true},{"version":"daafd945fef17e0871e19abcea868140cc595c409aaeccb6a697f0db5b220aa8","signature":"ae71d2310d85ac6b59765af7bbd89faf1b7b59976266a461c8e320deac5f0a37"},{"version":"5e8430d57e4799215d1d303bd346836e045c6360f06f46cc6fc3089c6bceeffd","signature":"05891eb963d78902a71cf9dd3c20b6c93e1e6a66cb96a7b600636e129f3c7d03"},{"version":"dace3b195f6b99852123d8b2a8a8e9633cbdcbbbcb374ce19e978abdc68cffca","signature":"aafdcaa9ec6a60e3dc38c55da1d8afac98e98634f27e501ec63a33e3028d1f76"}],"root":[80,[87,89]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"checkJs":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":true,"target":99},"fileIdsList":[[82,83,84,85],[79],[80,81,87,88],[87],[86],[75],[70,71,72,73,74,75],[70,71,72,73,74,76],[75,76],[77],[69,77,78]],"referencedMap":[[86,1],[80,2],[89,3],[88,4],[87,5],[70,6],[74,6],[73,6],[72,6],[76,7],[71,6],[75,8],[77,9],[78,10],[79,11]],"exportedModulesMap":[[86,1],[89,4],[88,4],[87,5],[70,6],[74,6],[73,6],[72,6],[76,7],[71,6],[75,8],[77,9],[78,10],[79,11]],"semanticDiagnosticsPerFile":[84,82,86,85,83,81,67,68,12,14,13,2,15,16,17,18,19,20,21,22,3,23,4,24,28,25,26,27,29,30,31,5,32,33,34,35,6,39,36,37,38,40,7,41,46,47,42,43,44,45,8,51,48,49,50,52,9,53,54,55,58,56,57,59,60,10,1,61,11,65,63,62,66,64,80,89,88,87,70,74,73,72,76,71,75,77,78,79,69],"latestChangedDtsFile":"./build-types/filter-and-sort-data-view.d.ts"},"version":"5.4.5"}
@@ -1,154 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import removeAccents from 'remove-accents';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import {
10
- OPERATOR_IS,
11
- OPERATOR_IS_NOT,
12
- OPERATOR_IS_NONE,
13
- OPERATOR_IS_ANY,
14
- OPERATOR_IS_ALL,
15
- OPERATOR_IS_NOT_ALL,
16
- } from './constants';
17
- import { normalizeFields } from './normalize-fields';
18
-
19
- function normalizeSearchInput( input = '' ) {
20
- return removeAccents( input.trim().toLowerCase() );
21
- }
22
-
23
- const EMPTY_ARRAY = [];
24
-
25
- /**
26
- * Applies the filtering, sorting and pagination to the raw data based on the view configuration.
27
- *
28
- * @param {any[]} data Raw data.
29
- * @param {Object} view View config.
30
- * @param {Object[]} fields Fields config.
31
- *
32
- * @return {Object} { data: any[], paginationInfo: { totalItems: number, totalPages: number } }
33
- */
34
- export function filterSortAndPaginate( data, view, fields ) {
35
- if ( ! data ) {
36
- return {
37
- data: EMPTY_ARRAY,
38
- paginationInfo: { totalItems: 0, totalPages: 0 },
39
- };
40
- }
41
- const _fields = normalizeFields( fields );
42
- let filteredData = [ ...data ];
43
- // Handle global search.
44
- if ( view.search ) {
45
- const normalizedSearch = normalizeSearchInput( view.search );
46
- filteredData = filteredData.filter( ( item ) => {
47
- return _fields
48
- .filter( ( field ) => field.enableGlobalSearch )
49
- .map( ( field ) => {
50
- return normalizeSearchInput( field.getValue( { item } ) );
51
- } )
52
- .some( ( field ) => field.includes( normalizedSearch ) );
53
- } );
54
- }
55
-
56
- if ( view.filters.length > 0 ) {
57
- view.filters.forEach( ( filter ) => {
58
- const field = _fields.find(
59
- ( _field ) => _field.id === filter.field
60
- );
61
- if (
62
- filter.operator === OPERATOR_IS_ANY &&
63
- filter?.value?.length > 0
64
- ) {
65
- filteredData = filteredData.filter( ( item ) => {
66
- const fieldValue = field.getValue( { item } );
67
- if ( Array.isArray( fieldValue ) ) {
68
- return filter.value.some( ( filterValue ) =>
69
- fieldValue.includes( filterValue )
70
- );
71
- } else if ( typeof fieldValue === 'string' ) {
72
- return filter.value.includes( fieldValue );
73
- }
74
- return false;
75
- } );
76
- } else if (
77
- filter.operator === OPERATOR_IS_NONE &&
78
- filter?.value?.length > 0
79
- ) {
80
- filteredData = filteredData.filter( ( item ) => {
81
- const fieldValue = field.getValue( { item } );
82
- if ( Array.isArray( fieldValue ) ) {
83
- return ! filter.value.some( ( filterValue ) =>
84
- fieldValue.includes( filterValue )
85
- );
86
- } else if ( typeof fieldValue === 'string' ) {
87
- return ! filter.value.includes( fieldValue );
88
- }
89
- return false;
90
- } );
91
- } else if (
92
- filter.operator === OPERATOR_IS_ALL &&
93
- filter?.value?.length > 0
94
- ) {
95
- filteredData = filteredData.filter( ( item ) => {
96
- return filter.value.every( ( value ) => {
97
- return field.getValue( { item } ).includes( value );
98
- } );
99
- } );
100
- } else if (
101
- filter.operator === OPERATOR_IS_NOT_ALL &&
102
- filter?.value?.length > 0
103
- ) {
104
- filteredData = filteredData.filter( ( item ) => {
105
- return filter.value.every( ( value ) => {
106
- return ! field.getValue( { item } ).includes( value );
107
- } );
108
- } );
109
- } else if ( filter.operator === OPERATOR_IS ) {
110
- filteredData = filteredData.filter( ( item ) => {
111
- return filter.value === field.getValue( { item } );
112
- } );
113
- } else if ( filter.operator === OPERATOR_IS_NOT ) {
114
- filteredData = filteredData.filter( ( item ) => {
115
- return filter.value !== field.getValue( { item } );
116
- } );
117
- }
118
- } );
119
- }
120
-
121
- // Handle sorting.
122
- if ( view.sort ) {
123
- const fieldId = view.sort.field;
124
- const fieldToSort = _fields.find( ( field ) => {
125
- return field.id === fieldId;
126
- } );
127
- filteredData.sort( ( a, b ) => {
128
- const valueA = fieldToSort.getValue( { item: a } ) ?? '';
129
- const valueB = fieldToSort.getValue( { item: b } ) ?? '';
130
- return view.sort.direction === 'asc'
131
- ? valueA.localeCompare( valueB )
132
- : valueB.localeCompare( valueA );
133
- } );
134
- }
135
-
136
- // Handle pagination.
137
- const hasPagination = view.page && view.perPage;
138
- const start = hasPagination ? ( view.page - 1 ) * view.perPage : 0;
139
- const totalItems = filteredData?.length || 0;
140
- const totalPages = hasPagination
141
- ? Math.ceil( totalItems / view.perPage )
142
- : 1;
143
- filteredData = hasPagination
144
- ? filteredData?.slice( start, start + view.perPage )
145
- : filteredData;
146
-
147
- return {
148
- data: filteredData,
149
- paginationInfo: {
150
- totalItems,
151
- totalPages,
152
- },
153
- };
154
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Apply default values and normalize the fields config.
3
- *
4
- * @param {Object[]} fields Raw Fields.
5
- * @return {Object[]} Normalized fields.
6
- */
7
- export function normalizeFields( fields ) {
8
- return fields.map( ( field ) => {
9
- const getValue = field.getValue || ( ( { item } ) => item[ field.id ] );
10
-
11
- return {
12
- ...field,
13
- getValue,
14
- render: field.render || getValue,
15
- };
16
- } );
17
- }