@vaadin/hilla-react-crud 24.4.0-alpha1

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 (172) hide show
  1. package/.lintstagedrc.js +6 -0
  2. package/LICENSE +201 -0
  3. package/README.md +27 -0
  4. package/autocrud-dialog.d.ts +11 -0
  5. package/autocrud-dialog.d.ts.map +1 -0
  6. package/autocrud-dialog.js +24 -0
  7. package/autocrud-dialog.js.map +7 -0
  8. package/autocrud-feature.d.ts +4 -0
  9. package/autocrud-feature.d.ts.map +1 -0
  10. package/autocrud-feature.js +8 -0
  11. package/autocrud-feature.js.map +7 -0
  12. package/autocrud.d.ts +82 -0
  13. package/autocrud.d.ts.map +1 -0
  14. package/autocrud.js +94 -0
  15. package/autocrud.js.map +7 -0
  16. package/autocrud.obj.js +6 -0
  17. package/autocrud.obj.js.map +7 -0
  18. package/autoform-feature.d.ts +4 -0
  19. package/autoform-feature.d.ts.map +1 -0
  20. package/autoform-feature.js +8 -0
  21. package/autoform-feature.js.map +7 -0
  22. package/autoform-field.d.ts +122 -0
  23. package/autoform-field.d.ts.map +1 -0
  24. package/autoform-field.js +118 -0
  25. package/autoform-field.js.map +7 -0
  26. package/autoform.d.ts +228 -0
  27. package/autoform.d.ts.map +1 -0
  28. package/autoform.js +178 -0
  29. package/autoform.js.map +7 -0
  30. package/autoform.obj.js +6 -0
  31. package/autoform.obj.js.map +7 -0
  32. package/autogrid-column-context.d.ts +39 -0
  33. package/autogrid-column-context.d.ts.map +1 -0
  34. package/autogrid-column-context.js +8 -0
  35. package/autogrid-column-context.js.map +7 -0
  36. package/autogrid-columns.d.ts +6 -0
  37. package/autogrid-columns.d.ts.map +1 -0
  38. package/autogrid-columns.js +102 -0
  39. package/autogrid-columns.js.map +7 -0
  40. package/autogrid-feature.d.ts +4 -0
  41. package/autogrid-feature.d.ts.map +1 -0
  42. package/autogrid-feature.js +8 -0
  43. package/autogrid-feature.js.map +7 -0
  44. package/autogrid-renderers.d.ts +28 -0
  45. package/autogrid-renderers.d.ts.map +1 -0
  46. package/autogrid-renderers.js +92 -0
  47. package/autogrid-renderers.js.map +7 -0
  48. package/autogrid.d.ts +130 -0
  49. package/autogrid.d.ts.map +1 -0
  50. package/autogrid.js +234 -0
  51. package/autogrid.js.map +7 -0
  52. package/autogrid.obj.js +6 -0
  53. package/autogrid.obj.js.map +7 -0
  54. package/crud.d.js +1 -0
  55. package/crud.d.js.map +7 -0
  56. package/crud.d.ts +17 -0
  57. package/data-provider.d.ts +56 -0
  58. package/data-provider.d.ts.map +1 -0
  59. package/data-provider.js +121 -0
  60. package/data-provider.js.map +7 -0
  61. package/header-filter.d.ts +54 -0
  62. package/header-filter.d.ts.map +1 -0
  63. package/header-filter.js +258 -0
  64. package/header-filter.js.map +7 -0
  65. package/header-sorter.d.ts +3 -0
  66. package/header-sorter.d.ts.map +1 -0
  67. package/header-sorter.js +28 -0
  68. package/header-sorter.js.map +7 -0
  69. package/i18n.d.ts +2 -0
  70. package/i18n.d.ts.map +1 -0
  71. package/i18n.js +5 -0
  72. package/i18n.js.map +7 -0
  73. package/index.d.ts +5 -0
  74. package/index.d.ts.map +1 -0
  75. package/index.js +13 -0
  76. package/index.js.map +7 -0
  77. package/locale.d.ts +19 -0
  78. package/locale.d.ts.map +1 -0
  79. package/locale.js +123 -0
  80. package/locale.js.map +7 -0
  81. package/media-query.d.ts +2 -0
  82. package/media-query.d.ts.map +1 -0
  83. package/media-query.js +16 -0
  84. package/media-query.js.map +7 -0
  85. package/model-info.d.ts +23 -0
  86. package/model-info.d.ts.map +1 -0
  87. package/model-info.js +137 -0
  88. package/model-info.js.map +7 -0
  89. package/package.json +87 -0
  90. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.js +1 -0
  91. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.js.map +7 -0
  92. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.ts +6 -0
  93. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts +9 -0
  94. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts.map +1 -0
  95. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js +13 -0
  96. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js.map +7 -0
  97. package/types/com/vaadin/hilla/crud/filter/Filter.d.js +1 -0
  98. package/types/com/vaadin/hilla/crud/filter/Filter.d.js.map +7 -0
  99. package/types/com/vaadin/hilla/crud/filter/Filter.d.ts +3 -0
  100. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts +7 -0
  101. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts.map +1 -0
  102. package/types/com/vaadin/hilla/crud/filter/FilterModel.js +9 -0
  103. package/types/com/vaadin/hilla/crud/filter/FilterModel.js.map +7 -0
  104. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.js +1 -0
  105. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.js.map +7 -0
  106. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.ts +5 -0
  107. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.js +1 -0
  108. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.js.map +7 -0
  109. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.ts +6 -0
  110. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts +9 -0
  111. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts.map +1 -0
  112. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js +13 -0
  113. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js.map +7 -0
  114. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts +8 -0
  115. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts.map +1 -0
  116. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js +12 -0
  117. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js.map +7 -0
  118. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts +8 -0
  119. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts.map +1 -0
  120. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js +11 -0
  121. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js.map +7 -0
  122. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.js +1 -0
  123. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.js.map +7 -0
  124. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.ts +9 -0
  125. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts +12 -0
  126. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts.map +1 -0
  127. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js +20 -0
  128. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js.map +7 -0
  129. package/types/com/vaadin/hilla/mappedtypes/Order.d.js +1 -0
  130. package/types/com/vaadin/hilla/mappedtypes/Order.d.js.map +7 -0
  131. package/types/com/vaadin/hilla/mappedtypes/Order.d.ts +9 -0
  132. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts +13 -0
  133. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts.map +1 -0
  134. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js +23 -0
  135. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js.map +7 -0
  136. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.js +1 -0
  137. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.js.map +7 -0
  138. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.ts +7 -0
  139. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts +11 -0
  140. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts.map +1 -0
  141. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js +19 -0
  142. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js.map +7 -0
  143. package/types/com/vaadin/hilla/mappedtypes/Sort.d.js +1 -0
  144. package/types/com/vaadin/hilla/mappedtypes/Sort.d.js.map +7 -0
  145. package/types/com/vaadin/hilla/mappedtypes/Sort.d.ts +5 -0
  146. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts +9 -0
  147. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts.map +1 -0
  148. package/types/com/vaadin/hilla/mappedtypes/SortModel.js +13 -0
  149. package/types/com/vaadin/hilla/mappedtypes/SortModel.js.map +7 -0
  150. package/types/org/springframework/data/domain/Sort/Direction.d.ts +6 -0
  151. package/types/org/springframework/data/domain/Sort/Direction.d.ts.map +1 -0
  152. package/types/org/springframework/data/domain/Sort/Direction.js +10 -0
  153. package/types/org/springframework/data/domain/Sort/Direction.js.map +7 -0
  154. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts +8 -0
  155. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts.map +1 -0
  156. package/types/org/springframework/data/domain/Sort/DirectionModel.js +11 -0
  157. package/types/org/springframework/data/domain/Sort/DirectionModel.js.map +7 -0
  158. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts +7 -0
  159. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts.map +1 -0
  160. package/types/org/springframework/data/domain/Sort/NullHandling.js +11 -0
  161. package/types/org/springframework/data/domain/Sort/NullHandling.js.map +7 -0
  162. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts +8 -0
  163. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts.map +1 -0
  164. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js +11 -0
  165. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js.map +7 -0
  166. package/types.d.js +1 -0
  167. package/types.d.js.map +7 -0
  168. package/types.d.ts +12 -0
  169. package/util.d.ts +12 -0
  170. package/util.d.ts.map +1 -0
  171. package/util.js +55 -0
  172. package/util.js.map +7 -0
package/autogrid.d.ts ADDED
@@ -0,0 +1,130 @@
1
+ import type { AbstractModel, DetachedModelConstructor } from '@vaadin/hilla-lit-form';
2
+ import { type GridElement, type GridProps } from '@vaadin/react-components/Grid.js';
3
+ import { type ComponentType, type ForwardedRef, type JSX } from 'react';
4
+ import { type ColumnOptions } from './autogrid-columns.js';
5
+ import type { ListService } from './crud';
6
+ import { type ItemCounts } from './data-provider.js';
7
+ import { type HeaderFilterRendererProps } from './header-filter';
8
+ import type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion.js';
9
+ export interface AutoGridRef<TItem = any> {
10
+ /**
11
+ * The underlying vaadin-grid DOM element.
12
+ */
13
+ grid: GridElement<TItem> | null;
14
+ /**
15
+ * Refreshes the grid by reloading the data from the backend.
16
+ */
17
+ refresh(): void;
18
+ }
19
+ interface AutoGridOwnProps<TItem> {
20
+ /**
21
+ * The service to use for fetching the data. This must be a TypeScript service
22
+ * that has been generated by Hilla from a backend Java service that
23
+ * implements the `com.vaadin.hilla.crud.ListService` interface.
24
+ */
25
+ service: ListService<TItem>;
26
+ /**
27
+ * The entity model to use for the grid, which determines which columns to
28
+ * show and how to render them. This must be a Typescript model class that has
29
+ * been generated by Hilla from a backend Java class. The model must match
30
+ * with the type of the items returned by the service. For example, a
31
+ * `PersonModel` can be used with a service that returns `Person` instances.
32
+ *
33
+ * By default, the grid shows columns for all properties of the model which
34
+ * have a type that is supported. Use the `visibleColumns` option to customize
35
+ * which columns to show and in which order.
36
+ */
37
+ model: DetachedModelConstructor<AbstractModel<TItem>>;
38
+ /**
39
+ * The property to use to detect an item's ID. The item ID is used to keep
40
+ * the selection state when reloading the grid.
41
+ *
42
+ * By default, the component uses the property annotated with
43
+ * `jakarta.persistence.Id`, or a property named `id`, in that order.
44
+ * This option can be used to override the default behavior, or define the ID
45
+ * property in case a class doesn't have a property matching the defaults.
46
+ */
47
+ itemIdProperty?: string;
48
+ /**
49
+ * Allows to provide a filter that is applied when fetching data from the
50
+ * service. This can be used for implementing an external filter UI outside
51
+ * the grid. A custom filter is not compatible with header filters.
52
+ *
53
+ * **NOTE:** This is considered an experimental feature and the API may change
54
+ * in the future.
55
+ */
56
+ experimentalFilter?: FilterUnion;
57
+ /**
58
+ * Allows to customize which columns to show and in which order. This must be
59
+ * an array of property names that are defined in the model. Nested properties
60
+ * can be specified using dot notation, e.g. `address.street`.
61
+ */
62
+ visibleColumns?: string[];
63
+ /**
64
+ * Disables header filters, which are otherwise enabled by default.
65
+ */
66
+ noHeaderFilters?: boolean;
67
+ /**
68
+ * Allows to add custom columns to the grid. This must be an array of
69
+ * `GridColumn` component instances. Custom columns are added after the
70
+ * auto-generated columns.
71
+ */
72
+ customColumns?: JSX.Element[];
73
+ /**
74
+ * Allows to customize the props for individual columns. This is an object
75
+ * where the keys must be property names that are defined in the model, and
76
+ * the values are props that are accepted by the `GridColumn` component.
77
+ * Nested properties can be specified using dot notation, e.g.
78
+ * `address.street`.
79
+ */
80
+ columnOptions?: Record<string, ColumnOptions>;
81
+ /**
82
+ * When enabled, inserts a column with row numbers at the beginning of the
83
+ * grid.
84
+ */
85
+ rowNumbers?: boolean;
86
+ /**
87
+ * When enabled, shows the total count of items in the grid footer.
88
+ * This requires the provided service to implement the CountService interface,
89
+ * otherwise an error will be logged to the console, without any count being
90
+ * rendered.
91
+ */
92
+ totalCount?: boolean;
93
+ /**
94
+ * When enabled, shows the filtered item count in the grid footer.
95
+ * if totalCount is also enabled, it will show both totalCount and filteredCount.
96
+ * This requires the provided service to implement the CountService interface,
97
+ * otherwise an error will be logged to the console, without any count being
98
+ * rendered.
99
+ */
100
+ filteredCount?: boolean;
101
+ /**
102
+ * Allows to customize the grid footer with a custom renderer component for
103
+ * the total count and filtered item count.
104
+ * This requires the provided service to implement the CountService interface,
105
+ * See {@link AutoGrid#totalCount} and {@link AutoGrid#filteredCount}.
106
+ */
107
+ footerCountRenderer?: ComponentType<ItemCounts>;
108
+ }
109
+ export type AutoGridProps<TItem> = GridProps<TItem> & Readonly<AutoGridOwnProps<TItem>>;
110
+ declare function AutoGridInner<TItem>({ service, model, itemIdProperty, experimentalFilter, visibleColumns, noHeaderFilters, customColumns, columnOptions, rowNumbers, totalCount, filteredCount, footerCountRenderer, ...gridProps }: AutoGridProps<TItem>, ref: ForwardedRef<AutoGridRef<TItem>>): JSX.Element;
111
+ type AutoGrid = <TItem>(props: AutoGridProps<TItem> & {
112
+ ref?: ForwardedRef<AutoGridRef<TItem>>;
113
+ }) => ReturnType<typeof AutoGridInner>;
114
+ /**
115
+ * Auto Grid is a component for displaying tabular data based on a Java backend
116
+ * service. It automatically generates columns based on the properties of a
117
+ * Java class and provides features such as lazy-loading, sorting and filtering.
118
+ *
119
+ * Example usage:
120
+ * ```tsx
121
+ * import { AutoGrid } from '@hilla/react-crud';
122
+ * import PersonService from 'Frontend/generated/endpoints';
123
+ * import PersonModel from 'Frontend/generated/com/example/application/Person';
124
+ *
125
+ * <AutoGrid service={PersonService} model={PersonModel} />
126
+ * ```
127
+ */
128
+ export declare const AutoGrid: AutoGrid;
129
+ export type { ColumnOptions, HeaderFilterRendererProps };
130
+ //# sourceMappingURL=autogrid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autogrid.d.ts","sourceRoot":"","sources":["src/autogrid.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAQ,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAG1F,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,YAAY,EAEjB,KAAK,GAAG,EAMT,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,aAAa,EAAoB,MAAM,uBAAuB,CAAC;AAG7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAyD,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC5G,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AO,EACP,KAAK,EACL,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,aAAa,EACb,aAAa,EACb,UAAU,EACV,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,GAAG,SAAS,EACb,EAAE,aAAa,CAAC,KAAK,CAAC,EACvB,GAAG,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,GACpC,GAAG,CAAC,OAAO,CA0Gb;AAED,KAAK,QAAQ,GAAG,CAAC,KAAK,EACpB,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAA;CAAE,KACrE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAgD,CAAC;AAExE,YAAY,EAAE,aAAa,EAAE,yBAAyB,EAAE,CAAC"}
package/autogrid.js ADDED
@@ -0,0 +1,234 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Grid } from "@vaadin/react-components/Grid.js";
3
+ import { GridColumn } from "@vaadin/react-components/GridColumn.js";
4
+ import { GridColumnGroup } from "@vaadin/react-components/GridColumnGroup.js";
5
+ import {
6
+ cloneElement,
7
+ forwardRef,
8
+ useEffect,
9
+ useImperativeHandle,
10
+ useMemo,
11
+ useRef,
12
+ useState
13
+ } from "react";
14
+ import { ColumnContext, CustomColumnContext } from "./autogrid-column-context.js";
15
+ import { getColumnOptions } from "./autogrid-columns.js";
16
+ import { AutoGridFooterItemCountRenderer, AutoGridRowNumberRenderer, FooterContext } from "./autogrid-renderers.js";
17
+ import css from "./autogrid.obj.js";
18
+ import { createDataProvider, isCountService } from "./data-provider.js";
19
+ import { NoHeaderFilter, HeaderFilterWrapper } from "./header-filter";
20
+ import { HeaderSorter } from "./header-sorter";
21
+ import { getDefaultProperties, ModelInfo } from "./model-info.js";
22
+ import { isFilterEmpty, registerStylesheet } from "./util";
23
+ registerStylesheet(css);
24
+ function wrapCustomColumn(column, setColumnFilter, options) {
25
+ const key = column.key ?? "no-key";
26
+ const { header, headerRenderer } = column.props;
27
+ const customOptions = options.columnOptions?.[key];
28
+ const { header: customHeader, headerRenderer: customHeaderRenderer, headerFilterRenderer } = customOptions ?? {};
29
+ const columnWithoutHeader = cloneElement(column, {
30
+ header: null,
31
+ headerRenderer: HeaderFilterWrapper
32
+ });
33
+ return /* @__PURE__ */ jsx(
34
+ CustomColumnContext.Provider,
35
+ {
36
+ value: {
37
+ setColumnFilter,
38
+ headerFilterRenderer: headerFilterRenderer ?? NoHeaderFilter,
39
+ filterKey: key
40
+ },
41
+ children: /* @__PURE__ */ jsx(
42
+ GridColumnGroup,
43
+ {
44
+ header: customHeader ?? header,
45
+ headerRenderer: customHeaderRenderer ?? headerRenderer,
46
+ children: columnWithoutHeader
47
+ },
48
+ key
49
+ )
50
+ },
51
+ key
52
+ );
53
+ }
54
+ function addCustomColumns(columns, options, setColumnFilter) {
55
+ if (!options.customColumns) {
56
+ return columns;
57
+ }
58
+ const customColumns = options.noHeaderFilters ? options.customColumns : options.customColumns.map((column) => wrapCustomColumn(column, setColumnFilter, options));
59
+ if (options.visibleColumns) {
60
+ const columnMap = [...columns, ...customColumns].reduce((map, column) => {
61
+ const { key } = column;
62
+ if (key) {
63
+ map.set(key, column);
64
+ }
65
+ return map;
66
+ }, /* @__PURE__ */ new Map());
67
+ return options.visibleColumns.map((path) => columnMap.get(path)).filter(Boolean);
68
+ }
69
+ return [...columns, ...customColumns];
70
+ }
71
+ function useColumns(properties, setColumnFilter, options) {
72
+ const sortableProperties = properties.filter(
73
+ (propertyInfo) => options.columnOptions?.[propertyInfo.name]?.sortable !== false
74
+ );
75
+ const [sortState, setSortState] = useState(
76
+ sortableProperties.length > 0 ? { [sortableProperties[0].name]: { direction: "asc" } } : {}
77
+ );
78
+ let columns = properties.map((propertyInfo) => {
79
+ let column;
80
+ const customColumnOptions = options.columnOptions?.[propertyInfo.name];
81
+ const { headerFilterRenderer, ...columnProps } = getColumnOptions(propertyInfo, customColumnOptions);
82
+ if (!options.noHeaderFilters) {
83
+ column = /* @__PURE__ */ jsx(GridColumnGroup, { headerRenderer: HeaderSorter, children: /* @__PURE__ */ jsx(GridColumn, { path: propertyInfo.name, headerRenderer: HeaderFilterWrapper, ...columnProps }) });
84
+ } else {
85
+ column = /* @__PURE__ */ jsx(GridColumn, { path: propertyInfo.name, headerRenderer: HeaderSorter, ...columnProps });
86
+ }
87
+ return /* @__PURE__ */ jsx(
88
+ ColumnContext.Provider,
89
+ {
90
+ value: {
91
+ propertyInfo,
92
+ setColumnFilter,
93
+ sortState,
94
+ setSortState,
95
+ customColumnOptions,
96
+ headerFilterRenderer: headerFilterRenderer ?? NoHeaderFilter,
97
+ filterKey: propertyInfo.name
98
+ },
99
+ children: column
100
+ },
101
+ propertyInfo.name
102
+ );
103
+ });
104
+ columns = addCustomColumns(columns, options, setColumnFilter);
105
+ if (options.rowNumbers) {
106
+ columns = [
107
+ /* @__PURE__ */ jsx(GridColumn, { width: "4em", flexGrow: 0, renderer: AutoGridRowNumberRenderer }, "rownumbers"),
108
+ ...columns
109
+ ];
110
+ }
111
+ const { totalCount, filteredCount, itemCounts, footerCountRenderer } = options;
112
+ if (totalCount ?? filteredCount) {
113
+ const col = /* @__PURE__ */ jsx(
114
+ FooterContext.Provider,
115
+ {
116
+ value: {
117
+ totalCount,
118
+ filteredCount,
119
+ footerCountRenderer,
120
+ itemCounts
121
+ },
122
+ children: /* @__PURE__ */ jsx(GridColumnGroup, { footerRenderer: AutoGridFooterItemCountRenderer, children: columns })
123
+ },
124
+ "grid-footer"
125
+ );
126
+ columns = [col];
127
+ }
128
+ return columns;
129
+ }
130
+ function AutoGridInner({
131
+ service,
132
+ model,
133
+ itemIdProperty,
134
+ experimentalFilter,
135
+ visibleColumns,
136
+ noHeaderFilters,
137
+ customColumns,
138
+ columnOptions,
139
+ rowNumbers,
140
+ totalCount,
141
+ filteredCount,
142
+ footerCountRenderer,
143
+ ...gridProps
144
+ }, ref) {
145
+ const [internalFilter, setInternalFilter] = useState({ "@type": "and", children: [] });
146
+ const [itemCounts, setItemCounts] = useState();
147
+ const gridRef = useRef(null);
148
+ const dataProviderRef = useRef();
149
+ useImperativeHandle(
150
+ ref,
151
+ () => ({
152
+ get grid() {
153
+ return gridRef.current;
154
+ },
155
+ refresh() {
156
+ dataProviderRef.current?.refresh();
157
+ }
158
+ }),
159
+ []
160
+ );
161
+ const setHeaderFilter = (filter, filterKey) => {
162
+ let changed = false;
163
+ filter.key = filterKey;
164
+ const indexOfFilter = filterKey ? internalFilter.children.findIndex((f) => f.key === filterKey) : -1;
165
+ const isEmptyFilter = isFilterEmpty(filter);
166
+ if (indexOfFilter >= 0 && isEmptyFilter) {
167
+ internalFilter.children.splice(indexOfFilter, 1);
168
+ changed = true;
169
+ } else if (!isEmptyFilter) {
170
+ if (indexOfFilter >= 0) {
171
+ internalFilter.children[indexOfFilter] = filter;
172
+ changed = true;
173
+ } else {
174
+ internalFilter.children.push(filter);
175
+ changed = true;
176
+ }
177
+ }
178
+ if (changed) {
179
+ setInternalFilter({ ...internalFilter });
180
+ }
181
+ };
182
+ const modelInfo = useMemo(() => new ModelInfo(model, itemIdProperty), [model]);
183
+ const properties = visibleColumns ? modelInfo.getProperties(visibleColumns) : getDefaultProperties(modelInfo);
184
+ const children = useColumns(properties, setHeaderFilter, {
185
+ visibleColumns,
186
+ noHeaderFilters,
187
+ customColumns,
188
+ columnOptions,
189
+ rowNumbers,
190
+ totalCount,
191
+ filteredCount,
192
+ footerCountRenderer,
193
+ itemCounts
194
+ });
195
+ useEffect(() => {
196
+ if (noHeaderFilters) {
197
+ setInternalFilter({ "@type": "and", children: [] });
198
+ }
199
+ }, [noHeaderFilters]);
200
+ useEffect(() => {
201
+ const grid = gridRef.current;
202
+ if ((!isCountService(service) && totalCount) ?? filteredCount) {
203
+ console.error(
204
+ '"totalCount" and "filteredCount" props require the provided service to implement the CountService interface.'
205
+ );
206
+ }
207
+ setTimeout(() => {
208
+ let firstUpdate = true;
209
+ dataProviderRef.current = createDataProvider(grid, service, {
210
+ initialFilter: experimentalFilter ?? internalFilter,
211
+ loadTotalCount: totalCount,
212
+ afterLoad(newItemCounts) {
213
+ setItemCounts(newItemCounts);
214
+ if (firstUpdate) {
215
+ firstUpdate = false;
216
+ setTimeout(() => grid.recalculateColumnWidths(), 0);
217
+ }
218
+ }
219
+ });
220
+ }, 1);
221
+ }, [model, service]);
222
+ useEffect(() => {
223
+ const dataProvider = dataProviderRef.current;
224
+ if (dataProvider) {
225
+ dataProvider.setFilter(experimentalFilter ?? internalFilter);
226
+ }
227
+ }, [experimentalFilter, internalFilter]);
228
+ return /* @__PURE__ */ jsx(Grid, { itemIdPath: modelInfo.idProperty?.name, ...gridProps, ref: gridRef, children });
229
+ }
230
+ const AutoGrid = forwardRef(AutoGridInner);
231
+ export {
232
+ AutoGrid
233
+ };
234
+ //# sourceMappingURL=autogrid.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/autogrid.tsx"],
4
+ "sourcesContent": ["import type { AbstractModel, DetachedModelConstructor } from '@vaadin/hilla-lit-form';\nimport { Grid, type GridElement, type GridProps } from '@vaadin/react-components/Grid.js';\nimport { GridColumn } from '@vaadin/react-components/GridColumn.js';\nimport { GridColumnGroup } from '@vaadin/react-components/GridColumnGroup.js';\nimport {\n cloneElement,\n type ComponentType,\n type ForwardedRef,\n forwardRef,\n type JSX,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { ColumnContext, CustomColumnContext, type SortState } from './autogrid-column-context.js';\nimport { type ColumnOptions, getColumnOptions } from './autogrid-columns.js';\nimport { AutoGridFooterItemCountRenderer, AutoGridRowNumberRenderer, FooterContext } from './autogrid-renderers.js';\nimport css from './autogrid.obj.js';\nimport type { ListService } from './crud';\nimport { createDataProvider, type DataProvider, isCountService, type ItemCounts } from './data-provider.js';\nimport { type HeaderFilterRendererProps, NoHeaderFilter, HeaderFilterWrapper } from './header-filter';\nimport { HeaderSorter } from './header-sorter';\nimport { getDefaultProperties, ModelInfo, type PropertyInfo } from './model-info.js';\nimport type AndFilter from './types/com/vaadin/hilla/crud/filter/AndFilter.js';\nimport type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion.js';\nimport { isFilterEmpty, registerStylesheet } from './util';\n\nregisterStylesheet(css);\n\nexport interface AutoGridRef<TItem = any> {\n /**\n * The underlying vaadin-grid DOM element.\n */\n grid: GridElement<TItem> | null;\n\n /**\n * Refreshes the grid by reloading the data from the backend.\n */\n refresh(): void;\n}\n\ninterface AutoGridOwnProps<TItem> {\n /**\n * The service to use for fetching the data. This must be a TypeScript service\n * that has been generated by Hilla from a backend Java service that\n * implements the `com.vaadin.hilla.crud.ListService` interface.\n */\n service: ListService<TItem>;\n /**\n * The entity model to use for the grid, which determines which columns to\n * show and how to render them. This must be a Typescript model class that has\n * been generated by Hilla from a backend Java class. The model must match\n * with the type of the items returned by the service. For example, a\n * `PersonModel` can be used with a service that returns `Person` instances.\n *\n * By default, the grid shows columns for all properties of the model which\n * have a type that is supported. Use the `visibleColumns` option to customize\n * which columns to show and in which order.\n */\n model: DetachedModelConstructor<AbstractModel<TItem>>;\n /**\n * The property to use to detect an item's ID. The item ID is used to keep\n * the selection state when reloading the grid.\n *\n * By default, the component uses the property annotated with\n * `jakarta.persistence.Id`, or a property named `id`, in that order.\n * This option can be used to override the default behavior, or define the ID\n * property in case a class doesn't have a property matching the defaults.\n */\n itemIdProperty?: string;\n /**\n * Allows to provide a filter that is applied when fetching data from the\n * service. This can be used for implementing an external filter UI outside\n * the grid. A custom filter is not compatible with header filters.\n *\n * **NOTE:** This is considered an experimental feature and the API may change\n * in the future.\n */\n experimentalFilter?: FilterUnion;\n /**\n * Allows to customize which columns to show and in which order. This must be\n * an array of property names that are defined in the model. Nested properties\n * can be specified using dot notation, e.g. `address.street`.\n */\n visibleColumns?: string[];\n /**\n * Disables header filters, which are otherwise enabled by default.\n */\n noHeaderFilters?: boolean;\n /**\n * Allows to add custom columns to the grid. This must be an array of\n * `GridColumn` component instances. Custom columns are added after the\n * auto-generated columns.\n */\n customColumns?: JSX.Element[];\n /**\n * Allows to customize the props for individual columns. This is an object\n * where the keys must be property names that are defined in the model, and\n * the values are props that are accepted by the `GridColumn` component.\n * Nested properties can be specified using dot notation, e.g.\n * `address.street`.\n */\n columnOptions?: Record<string, ColumnOptions>;\n /**\n * When enabled, inserts a column with row numbers at the beginning of the\n * grid.\n */\n rowNumbers?: boolean;\n /**\n * When enabled, shows the total count of items in the grid footer.\n * This requires the provided service to implement the CountService interface,\n * otherwise an error will be logged to the console, without any count being\n * rendered.\n */\n totalCount?: boolean;\n /**\n * When enabled, shows the filtered item count in the grid footer.\n * if totalCount is also enabled, it will show both totalCount and filteredCount.\n * This requires the provided service to implement the CountService interface,\n * otherwise an error will be logged to the console, without any count being\n * rendered.\n */\n filteredCount?: boolean;\n /**\n * Allows to customize the grid footer with a custom renderer component for\n * the total count and filtered item count.\n * This requires the provided service to implement the CountService interface,\n * See {@link AutoGrid#totalCount} and {@link AutoGrid#filteredCount}.\n */\n footerCountRenderer?: ComponentType<ItemCounts>;\n}\n\nexport type AutoGridProps<TItem> = GridProps<TItem> & Readonly<AutoGridOwnProps<TItem>>;\n\ninterface ColumnConfigurationOptions {\n visibleColumns?: string[];\n noHeaderFilters?: boolean;\n customColumns?: JSX.Element[];\n columnOptions?: Record<string, ColumnOptions>;\n rowNumbers?: boolean;\n totalCount?: boolean;\n filteredCount?: boolean;\n footerCountRenderer?: ComponentType<ItemCounts>;\n itemCounts?: ItemCounts;\n}\n\nfunction wrapCustomColumn(\n column: JSX.Element,\n setColumnFilter: (filter: FilterUnion, filterKey: string) => void,\n options: ColumnConfigurationOptions,\n) {\n const key = column.key ?? 'no-key';\n const { header, headerRenderer } = column.props;\n const customOptions = options.columnOptions?.[key];\n const { header: customHeader, headerRenderer: customHeaderRenderer, headerFilterRenderer } = customOptions ?? {};\n const columnWithoutHeader = cloneElement(column, {\n header: null,\n headerRenderer: HeaderFilterWrapper,\n });\n return (\n <CustomColumnContext.Provider\n key={key}\n value={{\n setColumnFilter,\n headerFilterRenderer: headerFilterRenderer ?? NoHeaderFilter,\n filterKey: key,\n }}\n >\n <GridColumnGroup\n key={key}\n header={customHeader ?? header}\n headerRenderer={customHeaderRenderer ?? headerRenderer}\n >\n {columnWithoutHeader}\n </GridColumnGroup>\n </CustomColumnContext.Provider>\n );\n}\n\nfunction addCustomColumns(\n columns: JSX.Element[],\n options: ColumnConfigurationOptions,\n setColumnFilter: (filter: FilterUnion, filterKey: string) => void,\n): JSX.Element[] {\n if (!options.customColumns) {\n return columns;\n }\n\n // When using header filters, wrap custom columns into column groups and\n // move header text or renderer to group\n const customColumns = options.noHeaderFilters\n ? options.customColumns\n : options.customColumns.map((column) => wrapCustomColumn(column, setColumnFilter, options));\n\n // When using a custom column order, insert custom columns into auto-generated\n // ones using their `key`\n if (options.visibleColumns) {\n const columnMap = [...columns, ...customColumns].reduce((map, column) => {\n const { key } = column;\n if (key) {\n map.set(key, column);\n }\n return map;\n }, new Map<string, JSX.Element>());\n\n return options.visibleColumns.map((path) => columnMap.get(path)).filter(Boolean) as JSX.Element[];\n }\n\n // Otherwise just append custom columns at the end\n return [...columns, ...customColumns];\n}\n\nfunction useColumns(\n properties: PropertyInfo[],\n setColumnFilter: (filter: FilterUnion, filterKey: string) => void,\n options: ColumnConfigurationOptions,\n) {\n const sortableProperties = properties.filter(\n (propertyInfo) => options.columnOptions?.[propertyInfo.name]?.sortable !== false,\n );\n const [sortState, setSortState] = useState<SortState>(\n sortableProperties.length > 0 ? { [sortableProperties[0].name]: { direction: 'asc' } } : {},\n );\n let columns = properties.map((propertyInfo) => {\n let column;\n const customColumnOptions = options.columnOptions?.[propertyInfo.name];\n\n const { headerFilterRenderer, ...columnProps } = getColumnOptions(propertyInfo, customColumnOptions);\n\n if (!options.noHeaderFilters) {\n column = (\n <GridColumnGroup headerRenderer={HeaderSorter}>\n <GridColumn path={propertyInfo.name} headerRenderer={HeaderFilterWrapper} {...columnProps}></GridColumn>\n </GridColumnGroup>\n );\n } else {\n column = <GridColumn path={propertyInfo.name} headerRenderer={HeaderSorter} {...columnProps}></GridColumn>;\n }\n return (\n <ColumnContext.Provider\n key={propertyInfo.name}\n value={{\n propertyInfo,\n setColumnFilter,\n sortState,\n setSortState,\n customColumnOptions,\n headerFilterRenderer: headerFilterRenderer ?? NoHeaderFilter,\n filterKey: propertyInfo.name,\n }}\n >\n {column}\n </ColumnContext.Provider>\n );\n });\n\n columns = addCustomColumns(columns, options, setColumnFilter);\n\n if (options.rowNumbers) {\n columns = [\n <GridColumn key=\"rownumbers\" width=\"4em\" flexGrow={0} renderer={AutoGridRowNumberRenderer}></GridColumn>,\n ...columns,\n ];\n }\n const { totalCount, filteredCount, itemCounts, footerCountRenderer } = options;\n if (totalCount ?? filteredCount) {\n const col = (\n <FooterContext.Provider\n key=\"grid-footer\"\n value={{\n totalCount,\n filteredCount,\n footerCountRenderer,\n itemCounts,\n }}\n >\n <GridColumnGroup footerRenderer={AutoGridFooterItemCountRenderer}>{columns}</GridColumnGroup>\n </FooterContext.Provider>\n );\n columns = [col];\n }\n\n return columns;\n}\n\nfunction AutoGridInner<TItem>(\n {\n service,\n model,\n itemIdProperty,\n experimentalFilter,\n visibleColumns,\n noHeaderFilters,\n customColumns,\n columnOptions,\n rowNumbers,\n totalCount,\n filteredCount,\n footerCountRenderer,\n ...gridProps\n }: AutoGridProps<TItem>,\n ref: ForwardedRef<AutoGridRef<TItem>>,\n): JSX.Element {\n const [internalFilter, setInternalFilter] = useState<AndFilter>({ '@type': 'and', children: [] });\n const [itemCounts, setItemCounts] = useState<ItemCounts | undefined>();\n const gridRef = useRef<GridElement<TItem>>(null);\n const dataProviderRef = useRef<DataProvider<TItem>>();\n\n useImperativeHandle(\n ref,\n () => ({\n get grid() {\n return gridRef.current;\n },\n refresh() {\n dataProviderRef.current?.refresh();\n },\n }),\n [],\n );\n\n const setHeaderFilter = (filter: FilterUnion, filterKey: string) => {\n let changed = false;\n filter.key = filterKey;\n const indexOfFilter = filterKey\n ? internalFilter.children.findIndex((f) => (f as FilterUnion).key === filterKey)\n : -1;\n const isEmptyFilter = isFilterEmpty(filter);\n\n if (indexOfFilter >= 0 && isEmptyFilter) {\n internalFilter.children.splice(indexOfFilter, 1);\n changed = true;\n } else if (!isEmptyFilter) {\n if (indexOfFilter >= 0) {\n internalFilter.children[indexOfFilter] = filter;\n changed = true;\n } else {\n internalFilter.children.push(filter);\n changed = true;\n }\n }\n if (changed) {\n setInternalFilter({ ...internalFilter });\n }\n };\n\n const modelInfo = useMemo(() => new ModelInfo(model, itemIdProperty), [model]);\n const properties = visibleColumns ? modelInfo.getProperties(visibleColumns) : getDefaultProperties(modelInfo);\n const children = useColumns(properties, setHeaderFilter, {\n visibleColumns,\n noHeaderFilters,\n customColumns,\n columnOptions,\n rowNumbers,\n totalCount,\n filteredCount,\n footerCountRenderer,\n itemCounts,\n });\n\n useEffect(() => {\n // Remove all filtering if header filters are removed\n if (noHeaderFilters) {\n setInternalFilter({ '@type': 'and', children: [] });\n }\n }, [noHeaderFilters]);\n\n useEffect(() => {\n // Sets the data provider, should be done only once\n const grid = gridRef.current!;\n // Log an error if totalCount or filteredCount is enabled but the service doesn't implement CountService\n if ((!isCountService(service) && totalCount) ?? filteredCount) {\n console.error(\n '\"totalCount\" and \"filteredCount\" props require the provided service to implement the CountService interface.',\n );\n }\n // Wait for the sorting headers to be rendered so that the sorting state is correct for the first data provider call\n setTimeout(() => {\n let firstUpdate = true;\n dataProviderRef.current = createDataProvider(grid, service, {\n initialFilter: experimentalFilter ?? internalFilter,\n loadTotalCount: totalCount,\n afterLoad(newItemCounts: ItemCounts) {\n setItemCounts(newItemCounts);\n\n if (firstUpdate) {\n // Workaround for https://github.com/vaadin/react-components/issues/129\n firstUpdate = false;\n setTimeout(() => grid.recalculateColumnWidths(), 0);\n }\n },\n });\n }, 1);\n }, [model, service]);\n\n useEffect(() => {\n // Update the filtering, whenever the filter changes\n const dataProvider = dataProviderRef.current;\n if (dataProvider) {\n dataProvider.setFilter(experimentalFilter ?? internalFilter);\n }\n }, [experimentalFilter, internalFilter]);\n\n return (\n <Grid itemIdPath={modelInfo.idProperty?.name} {...gridProps} ref={gridRef}>\n {children}\n </Grid>\n );\n}\n\ntype AutoGrid = <TItem>(\n props: AutoGridProps<TItem> & { ref?: ForwardedRef<AutoGridRef<TItem>> },\n) => ReturnType<typeof AutoGridInner>;\n\n/**\n * Auto Grid is a component for displaying tabular data based on a Java backend\n * service. It automatically generates columns based on the properties of a\n * Java class and provides features such as lazy-loading, sorting and filtering.\n *\n * Example usage:\n * ```tsx\n * import { AutoGrid } from '@hilla/react-crud';\n * import PersonService from 'Frontend/generated/endpoints';\n * import PersonModel from 'Frontend/generated/com/example/application/Person';\n *\n * <AutoGrid service={PersonService} model={PersonModel} />\n * ```\n */\nexport const AutoGrid: AutoGrid = forwardRef(AutoGridInner) as AutoGrid;\n\nexport type { ColumnOptions, HeaderFilterRendererProps };\n"],
5
+ "mappings": "AA0KM;AAzKN,SAAS,YAA8C;AACvD,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EAGA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,2BAA2C;AACnE,SAA6B,wBAAwB;AACrD,SAAS,iCAAiC,2BAA2B,qBAAqB;AAC1F,OAAO,SAAS;AAEhB,SAAS,oBAAuC,sBAAuC;AACvF,SAAyC,gBAAgB,2BAA2B;AACpF,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB,iBAAoC;AAGnE,SAAS,eAAe,0BAA0B;AAElD,mBAAmB,GAAG;AAuHtB,SAAS,iBACP,QACA,iBACA,SACA;AACA,QAAM,MAAM,OAAO,OAAO;AAC1B,QAAM,EAA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
@@ -0,0 +1,6 @@
1
+ const css = new CSSStyleSheet();
2
+ css.replaceSync(`.auto-grid-comparation-selection{--vaadin-field-default-width:2em}.auto-grid-comparation-selection>vaadin-select-value-button{--_lumo-text-field-overflow-mask-image:none!important;color:var(--lumo-secondary-text-color)}.auto-grid-comparation-selection::part(toggle-button){display:none}.auto-grid-string-filter{display:flex}.auto-grid-string-filter vaadin-text-field{flex:1 1 0;width:100px}.auto-grid-boolean-filter{display:flex}.auto-grid-boolean-filter vaadin-select{flex:1 1 0;width:80px}.auto-grid-boolean-filter vaadin-select-item{font-size:14px}.auto-grid-number-filter{display:flex}.auto-grid-number-filter vaadin-number-field{flex:1 1 0;width:100px}.auto-grid-number-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-number-filter vaadin-number-field::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}.auto-grid-enum-filter{display:flex}.auto-grid-enum-filter vaadin-select{flex:1 1 0;width:120px}.auto-grid-enum-filter vaadin-select-item{font-size:14px}.auto-grid-date-filter{display:flex}.auto-grid-date-filter vaadin-date-picker{flex:1 1 0;width:120px}.auto-grid-date-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-date-filter vaadin-date-picker::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}.auto-grid-time-filter{display:flex}.auto-grid-time-filter vaadin-time-picker{flex:1 1 0;width:100px}.auto-grid-time-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-time-filter vaadin-time-picker::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}`);
3
+ export {
4
+ css as default
5
+ };
6
+ //# sourceMappingURL=autogrid.obj.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/autogrid.obj.css"],
4
+ "sourcesContent": ["const css = new CSSStyleSheet();css.replaceSync(`.auto-grid-comparation-selection{--vaadin-field-default-width:2em}.auto-grid-comparation-selection>vaadin-select-value-button{--_lumo-text-field-overflow-mask-image:none!important;color:var(--lumo-secondary-text-color)}.auto-grid-comparation-selection::part(toggle-button){display:none}.auto-grid-string-filter{display:flex}.auto-grid-string-filter vaadin-text-field{flex:1 1 0;width:100px}.auto-grid-boolean-filter{display:flex}.auto-grid-boolean-filter vaadin-select{flex:1 1 0;width:80px}.auto-grid-boolean-filter vaadin-select-item{font-size:14px}.auto-grid-number-filter{display:flex}.auto-grid-number-filter vaadin-number-field{flex:1 1 0;width:100px}.auto-grid-number-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-number-filter vaadin-number-field::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}.auto-grid-enum-filter{display:flex}.auto-grid-enum-filter vaadin-select{flex:1 1 0;width:120px}.auto-grid-enum-filter vaadin-select-item{font-size:14px}.auto-grid-date-filter{display:flex}.auto-grid-date-filter vaadin-date-picker{flex:1 1 0;width:120px}.auto-grid-date-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-date-filter vaadin-date-picker::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}.auto-grid-time-filter{display:flex}.auto-grid-time-filter vaadin-time-picker{flex:1 1 0;width:100px}.auto-grid-time-filter vaadin-select::part(input-field){border-bottom-right-radius:0;border-top-right-radius:0}.auto-grid-time-filter vaadin-time-picker::part(input-field){border-bottom-left-radius:0;border-top-left-radius:0}`);export { css as default };"],
5
+ "mappings": "AAAA,MAAM,MAAM,IAAI,cAAc;AAAE,IAAI,YAAY,8pDAA8pD;",
6
+ "names": []
7
+ }
package/crud.d.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=crud.d.js.map
package/crud.d.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/crud.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion.js';
2
+ import type Pageable from './types/com/vaadin/hilla/mappedtypes/Pageable';
3
+
4
+ export interface FormService<T> {
5
+ save(value: T): Promise<T | undefined>;
6
+ delete(id: any): Promise<void>;
7
+ }
8
+
9
+ export interface ListService<T> {
10
+ list(request: Pageable, filter: FilterUnion | undefined): Promise<T[]>;
11
+ }
12
+
13
+ export interface CountService<T> {
14
+ count(filter: FilterUnion | undefined): Promise<number>;
15
+ }
16
+
17
+ export interface CrudService<T> extends FormService<T>, ListService<T> {}
@@ -0,0 +1,56 @@
1
+ import type { GridDataProviderCallback, GridDataProviderParams, GridElement } from '@vaadin/react-components/Grid';
2
+ import type { CountService, ListService } from './crud';
3
+ import type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion';
4
+ import type Sort from './types/com/vaadin/hilla/mappedtypes/Sort';
5
+ type MaybeCountService<TItem> = Partial<CountService<TItem>>;
6
+ type ListAndMaybeCountService<TItem> = ListService<TItem> & MaybeCountService<TItem>;
7
+ type ListAndCountService<TItem> = CountService<TItem> & ListService<TItem>;
8
+ type PageRequest = {
9
+ pageNumber: number;
10
+ pageSize: number;
11
+ sort: Sort;
12
+ };
13
+ type DataPage<TItem> = {
14
+ items: TItem[];
15
+ pageRequest: PageRequest;
16
+ };
17
+ export type ItemCounts = {
18
+ totalCount?: number;
19
+ filteredCount?: number;
20
+ };
21
+ type AfterLoadCallback = (result: ItemCounts) => void;
22
+ type DataProviderOptions = {
23
+ initialFilter?: FilterUnion;
24
+ loadTotalCount?: boolean;
25
+ afterLoad?: AfterLoadCallback;
26
+ };
27
+ export declare function isCountService<TItem>(service: ListAndMaybeCountService<TItem>): service is ListAndCountService<TItem>;
28
+ export declare abstract class DataProvider<TItem> {
29
+ protected readonly grid: GridElement;
30
+ protected readonly service: ListAndMaybeCountService<TItem>;
31
+ protected readonly loadTotalCount?: boolean;
32
+ protected readonly afterLoadCallback?: AfterLoadCallback;
33
+ protected filter: FilterUnion | undefined;
34
+ protected totalCount: number | undefined;
35
+ protected filteredCount: number | undefined;
36
+ constructor(grid: GridElement, service: ListAndMaybeCountService<TItem>, options?: DataProviderOptions);
37
+ refresh(): void;
38
+ setFilter(filter: FilterUnion | undefined): void;
39
+ protected load(params: GridDataProviderParams<TItem>, callback: GridDataProviderCallback<TItem>): Promise<void>;
40
+ protected fetchPage(params: GridDataProviderParams<TItem>): Promise<DataPage<TItem>>;
41
+ protected abstract fetchTotalCount(page: DataPage<TItem>): Promise<number | undefined> | number | undefined;
42
+ protected abstract fetchFilteredCount(page: DataPage<TItem>): Promise<number | undefined> | number | undefined;
43
+ }
44
+ export declare class InfiniteDataProvider<TItem> extends DataProvider<TItem> {
45
+ protected fetchTotalCount(): undefined;
46
+ protected fetchFilteredCount(page: DataPage<TItem>): number | undefined;
47
+ }
48
+ export declare class FixedSizeDataProvider<TItem> extends DataProvider<TItem> {
49
+ service: ListAndCountService<TItem>;
50
+ constructor(grid: GridElement, service: ListAndMaybeCountService<TItem>, options?: DataProviderOptions);
51
+ protected fetchTotalCount(): Promise<number | undefined>;
52
+ protected fetchFilteredCount(): Promise<number | undefined>;
53
+ }
54
+ export declare function createDataProvider<TItem>(grid: GridElement, service: ListAndMaybeCountService<TItem>, options?: DataProviderOptions): DataProvider<TItem>;
55
+ export {};
56
+ //# sourceMappingURL=data-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-provider.d.ts","sourceRoot":"","sources":["src/data-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EAEtB,WAAW,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,WAAW,MAAM,kDAAkD,CAAC;AAChF,OAAO,KAAK,IAAI,MAAM,2CAA2C,CAAC;AAYlE,KAAK,iBAAiB,CAAC,KAAK,IAAI,OAAO,CAAC,YAAY,CAAC,K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AAE,WAAW,EAAE,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,EAAE,OAAO,GAAE,mBAAwB;cAO1F,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;cAQ9C,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CAOlE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EACtC,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,EACxC,OAAO,GAAE,mBAAwB,GAChC,YAAY,CAAC,KAAK,CAAC,CAKrB"}
@@ -0,0 +1,121 @@
1
+ import Direction from "./types/org/springframework/data/domain/Sort/Direction";
2
+ function createSort(params) {
3
+ return {
4
+ orders: params.sortOrders.filter((order) => order.direction != null).map((order) => ({
5
+ property: order.path,
6
+ direction: order.direction === "asc" ? Direction.ASC : Direction.DESC,
7
+ ignoreCase: false
8
+ }))
9
+ };
10
+ }
11
+ function isCountService(service) {
12
+ return !!service.count;
13
+ }
14
+ class DataProvider {
15
+ grid;
16
+ service;
17
+ loadTotalCount;
18
+ afterLoadCallback;
19
+ filter;
20
+ totalCount;
21
+ filteredCount;
22
+ constructor(grid, service, options = {}) {
23
+ this.grid = grid;
24
+ this.service = service;
25
+ this.filter = options.initialFilter;
26
+ this.loadTotalCount = options.loadTotalCount;
27
+ this.afterLoadCallback = options.afterLoad;
28
+ this.grid.dataProvider = this.load.bind(this);
29
+ }
30
+ refresh() {
31
+ this.totalCount = void 0;
32
+ this.filteredCount = void 0;
33
+ this.grid.clearCache();
34
+ }
35
+ setFilter(filter) {
36
+ this.filter = filter;
37
+ this.refresh();
38
+ }
39
+ async load(params, callback) {
40
+ const page = await this.fetchPage(params);
41
+ this.filteredCount = await this.fetchFilteredCount(page);
42
+ if (this.loadTotalCount) {
43
+ this.totalCount = await this.fetchTotalCount(page);
44
+ }
45
+ callback(page.items, this.filteredCount);
46
+ if (this.afterLoadCallback) {
47
+ this.afterLoadCallback({
48
+ totalCount: this.totalCount,
49
+ filteredCount: this.filteredCount
50
+ });
51
+ }
52
+ }
53
+ async fetchPage(params) {
54
+ const sort = createSort(params);
55
+ const pageNumber = params.page;
56
+ const { pageSize } = params;
57
+ const pageRequest = {
58
+ pageNumber,
59
+ pageSize,
60
+ sort
61
+ };
62
+ const items = await this.service.list(pageRequest, this.filter);
63
+ return { items, pageRequest };
64
+ }
65
+ }
66
+ class InfiniteDataProvider extends DataProvider {
67
+ // cannot be static, otherwise it does not implement superclass
68
+ // eslint-disable-next-line @typescript-eslint/class-methods-use-this
69
+ fetchTotalCount() {
70
+ return void 0;
71
+ }
72
+ fetchFilteredCount(page) {
73
+ const { items, pageRequest } = page;
74
+ const { pageNumber, pageSize } = pageRequest;
75
+ let infiniteScrollingSize;
76
+ if (items.length === pageSize) {
77
+ infiniteScrollingSize = (pageNumber + 1) * pageSize + 1;
78
+ const cacheSize = this.grid._dataProviderController.rootCache.size;
79
+ if (cacheSize !== void 0 && infiniteScrollingSize < cacheSize) {
80
+ infiniteScrollingSize = void 0;
81
+ }
82
+ } else {
83
+ infiniteScrollingSize = pageNumber * pageSize + items.length;
84
+ }
85
+ return infiniteScrollingSize;
86
+ }
87
+ }
88
+ class FixedSizeDataProvider extends DataProvider {
89
+ constructor(grid, service, options = {}) {
90
+ if (!isCountService(service)) {
91
+ throw new Error("The provided service does not implement the CountService interface.");
92
+ }
93
+ super(grid, service, options);
94
+ }
95
+ async fetchTotalCount() {
96
+ if (this.totalCount !== void 0) {
97
+ return this.totalCount;
98
+ }
99
+ return this.service.count(void 0);
100
+ }
101
+ async fetchFilteredCount() {
102
+ if (this.filteredCount !== void 0) {
103
+ return this.filteredCount;
104
+ }
105
+ return this.service.count(this.filter);
106
+ }
107
+ }
108
+ function createDataProvider(grid, service, options = {}) {
109
+ if (isCountService(service)) {
110
+ return new FixedSizeDataProvider(grid, service, options);
111
+ }
112
+ return new InfiniteDataProvider(grid, service, options);
113
+ }
114
+ export {
115
+ DataProvider,
116
+ FixedSizeDataProvider,
117
+ InfiniteDataProvider,
118
+ createDataProvider,
119
+ isCountService
120
+ };
121
+ //# sourceMappingURL=data-provider.js.map