@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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/data-provider.ts"],
4
+ "sourcesContent": ["import type {\n GridDataProviderCallback,\n GridDataProviderParams,\n GridDefaultItem,\n GridElement,\n} from '@vaadin/react-components/Grid';\nimport type { CountService, ListService } from './crud';\nimport type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion';\nimport type Sort from './types/com/vaadin/hilla/mappedtypes/Sort';\nimport Direction from './types/org/springframework/data/domain/Sort/Direction';\n\ntype GridElementWithInternalAPI<TItem = GridDefaultItem> = GridElement<TItem> &\n Readonly<{\n _dataProviderController: {\n rootCache: {\n size?: number;\n };\n };\n }>;\n\ntype MaybeCountService<TItem> = Partial<CountService<TItem>>;\ntype ListAndMaybeCountService<TItem> = ListService<TItem> & MaybeCountService<TItem>;\ntype ListAndCountService<TItem> = CountService<TItem> & ListService<TItem>;\n\ntype PageRequest = {\n pageNumber: number;\n pageSize: number;\n sort: Sort;\n};\n\ntype DataPage<TItem> = {\n items: TItem[];\n pageRequest: PageRequest;\n};\n\nexport type ItemCounts = {\n totalCount?: number;\n filteredCount?: number;\n};\n\ntype AfterLoadCallback = (result: ItemCounts) => void;\n\ntype DataProviderOptions = {\n initialFilter?: FilterUnion;\n loadTotalCount?: boolean;\n afterLoad?: AfterLoadCallback;\n};\n\nfunction createSort<TItem>(params: GridDataProviderParams<TItem>): Sort {\n return {\n orders: params.sortOrders\n .filter((order) => order.direction != null)\n .map((order) => ({\n property: order.path,\n direction: order.direction === 'asc' ? Direction.ASC : Direction.DESC,\n ignoreCase: false,\n })),\n };\n}\n\nexport function isCountService<TItem>(service: ListAndMaybeCountService<TItem>): service is ListAndCountService<TItem> {\n return !!service.count;\n}\n\nexport abstract class DataProvider<TItem> {\n protected readonly grid: GridElement;\n protected readonly service: ListAndMaybeCountService<TItem>;\n protected readonly loadTotalCount?: boolean;\n protected readonly afterLoadCallback?: AfterLoadCallback;\n\n protected filter: FilterUnion | undefined;\n protected totalCount: number | undefined;\n protected filteredCount: number | undefined;\n\n constructor(grid: GridElement, service: ListAndMaybeCountService<TItem>, options: DataProviderOptions = {}) {\n this.grid = grid;\n this.service = service;\n this.filter = options.initialFilter;\n this.loadTotalCount = options.loadTotalCount;\n this.afterLoadCallback = options.afterLoad;\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n this.grid.dataProvider = this.load.bind(this);\n }\n\n refresh(): void {\n this.totalCount = undefined;\n this.filteredCount = undefined;\n this.grid.clearCache();\n }\n\n setFilter(filter: FilterUnion | undefined): void {\n this.filter = filter;\n this.refresh();\n }\n\n protected async load(\n params: GridDataProviderParams<TItem>,\n callback: GridDataProviderCallback<TItem>,\n ): Promise<void> {\n // Fetch page and filtered count\n const page = await this.fetchPage(params);\n this.filteredCount = await this.fetchFilteredCount(page);\n // Only fetch total count if it's specific in options\n if (this.loadTotalCount) {\n this.totalCount = await this.fetchTotalCount(page);\n }\n\n // Pass results to grid\n callback(page.items, this.filteredCount);\n\n // Pass results to callback\n if (this.afterLoadCallback) {\n this.afterLoadCallback({\n totalCount: this.totalCount,\n filteredCount: this.filteredCount,\n });\n }\n }\n\n protected async fetchPage(params: GridDataProviderParams<TItem>): Promise<DataPage<TItem>> {\n const sort = createSort(params);\n const pageNumber = params.page;\n const { pageSize } = params;\n const pageRequest = {\n pageNumber,\n pageSize,\n sort,\n };\n const items = await this.service.list(pageRequest, this.filter);\n\n return { items, pageRequest };\n }\n\n protected abstract fetchTotalCount(page: DataPage<TItem>): Promise<number | undefined> | number | undefined;\n\n protected abstract fetchFilteredCount(page: DataPage<TItem>): Promise<number | undefined> | number | undefined;\n}\n\nexport class InfiniteDataProvider<TItem> extends DataProvider<TItem> {\n // cannot be static, otherwise it does not implement superclass\n // eslint-disable-next-line @typescript-eslint/class-methods-use-this\n protected fetchTotalCount(): undefined {\n return undefined;\n }\n\n protected fetchFilteredCount(page: DataPage<TItem>): number | undefined {\n const { items, pageRequest } = page;\n const { pageNumber, pageSize } = pageRequest;\n let infiniteScrollingSize;\n\n if (items.length === pageSize) {\n infiniteScrollingSize = (pageNumber + 1) * pageSize + 1;\n const cacheSize = (this.grid as GridElementWithInternalAPI<TItem>)._dataProviderController.rootCache.size;\n if (cacheSize !== undefined && infiniteScrollingSize < cacheSize) {\n // Only allow size to grow here to avoid shrinking the size when scrolled down and sorting\n infiniteScrollingSize = undefined;\n }\n } else {\n infiniteScrollingSize = pageNumber * pageSize + items.length;\n }\n\n return infiniteScrollingSize;\n }\n}\n\nexport class FixedSizeDataProvider<TItem> extends DataProvider<TItem> {\n declare service: ListAndCountService<TItem>;\n\n constructor(grid: GridElement, service: ListAndMaybeCountService<TItem>, options: DataProviderOptions = {}) {\n if (!isCountService(service)) {\n throw new Error('The provided service does not implement the CountService interface.');\n }\n super(grid, service, options);\n }\n\n protected async fetchTotalCount(): Promise<number | undefined> {\n // Use cached count if it's already known\n if (this.totalCount !== undefined) {\n return this.totalCount;\n }\n return this.service.count(undefined);\n }\n\n protected async fetchFilteredCount(): Promise<number | undefined> {\n // Use cached count if it's already known\n if (this.filteredCount !== undefined) {\n return this.filteredCount;\n }\n return this.service.count(this.filter);\n }\n}\n\nexport function createDataProvider<TItem>(\n grid: GridElement,\n service: ListAndMaybeCountService<TItem>,\n options: DataProviderOptions = {},\n): DataProvider<TItem> {\n if (isCountService(service)) {\n return new FixedSizeDataProvider(grid, service, options);\n }\n return new InfiniteDataProvider(grid, service, options);\n}\n"],
5
+ "mappings": "AASA,OAAO,eAAe;AAuCtB,SAAS,WAAkB,QAA6C;AACtE,SAAO;AAAA,IACL,QAAQ,OAAO,WACZ,OAAO,CAAC,UAAU,MAAM,aAAa,IAAI,EACzC,IAAI,CAAC,WAAW;AAAA,MACf,UAAU,MAAM;AAAA,MAChB,WAAW,MAAM,cAAc,QAAQ,UAAU,MAAM,UAAU;AAAA,MACjE,YAAY;AAAA,IACd,EAAE;AAAA,EACN;AACF;AAEO,SAAS,eAAsB,SAAiF;AACrH,SAAO,CAAC,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,EAGzD,kBAA6B;AACrC,WAAO;AAAA,EACT;AAAA,EAEU,mBAAmB,MAA2C;AACtE,UAAM,EAAE,OAAO,YAAY,IAAI;AAC/B,UAAM,EAAE,YAAY,SAAS,IAAI;AACjC,QAAI;AAEJ,QAAI,MAAM,WAAW,UAAU;AAC7B,+BAAyB,aAAa,KAAK,WAAW;AACtD,YAAM,YAAa,KAAK,KAA2C,wBAAwB,UAAU;AACrG,UAAI,cAAc,UAAa,wBAAwB,WAAW;AAEhE,gCAAwB;AAAA,MAC1B;AAAA,IACF,OAAO;AACL,8BAAwB,aAAa,WAAW,MAAM;AAAA,IACxD;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,8BAAqC,aAAoB;AAAA,EAGpE,YAAY,MAAmB,SAA0C,UAA+B,CAAC,GAAG;AAC1G,QAAI,CAAC,eAAe,OAAO,GAAG;AAC5B,YAAM,IAAI,MAAM,qEAAqE;AAAA,IACvF;AACA,UAAM,MAAM,SAAS,OAAO;AAAA,EAC9B;AAAA,EAEA,MAAgB,kBAA+C;AAE7D,QAAI,KAAK,eAAe,QAAW;AACjC,aAAO,KAAK;AAAA,IACd;AACA,WAAO,KAAK,QAAQ,MAAM,MAAS;AAAA,EACrC;AAAA,EAEA,MAAgB,qBAAkD;AAEhE,QAAI,KAAK,kBAAkB,QAAW;AACpC,aAAO,KAAK;AAAA,IACd;AACA,WAAO,KAAK,QAAQ,MAAM,KAAK,MAAM;AAAA,EACvC;AACF;AAEO,SAAS,mBACd,MACA,SACA,UAA+B,CAAC,GACX;AACrB,MAAI,eAAe,OAAO,GAAG;AAC3B,WAAO,IAAI,sBAAsB,MAAM,SAAS,OAAO;AAAA,EACzD;AACA,SAAO,IAAI,qBAAqB,MAAM,SAAS,OAAO;AACxD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,54 @@
1
+ import type { GridColumnProps } from '@vaadin/react-components/GridColumn.js';
2
+ import { type ComponentType, type JSX, type ReactElement } from 'react';
3
+ import type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion';
4
+ type ExtractComponentTypeProps<T extends ComponentType<any>> = T extends ComponentType<infer U> ? U : never;
5
+ export type HeaderRendererProps = ExtractComponentTypeProps<NonNullable<Required<GridColumnProps<unknown>>['headerRenderer']>>;
6
+ export type HeaderFilterRendererProps = HeaderRendererProps & {
7
+ /**
8
+ * Allows to set custom filters for the column.
9
+ * This is used by the header filter components.
10
+ * @param filter - The filter to set in the filter list.
11
+ */
12
+ setFilter(filter: FilterUnion): void;
13
+ };
14
+ export type HeaderFilterProps = Readonly<{
15
+ /**
16
+ * If true, the column can be sorted. This is useful to disable sorting for
17
+ * properties that are not sortable in the backend, or that require excessive processing.
18
+ */
19
+ sortable?: boolean;
20
+ /**
21
+ * If true, the column can be filtered. This is useful to disable filtering for
22
+ * properties that are not sortable in the backend, or that require excessive processing.
23
+ */
24
+ filterable?: boolean;
25
+ /**
26
+ * Placeholder text for the filter input.
27
+ * Only applies to string, number and date/time value filters.
28
+ */
29
+ filterPlaceholder?: string;
30
+ /**
31
+ * Debounce time for the filter input in milliseconds.
32
+ * Only applies to string value filters and number value filters.
33
+ */
34
+ filterDebounceTime?: number;
35
+ /**
36
+ * Minimum length for the filter input.
37
+ * Only applies to string value filters.
38
+ */
39
+ filterMinLength?: number;
40
+ /**
41
+ * Custom renderer for the filter in the header.
42
+ */
43
+ headerFilterRenderer?: ComponentType<HeaderFilterRendererProps>;
44
+ }>;
45
+ export declare function StringHeaderFilter(): ReactElement;
46
+ export declare function NumberHeaderFilter(): ReactElement;
47
+ export declare function EnumHeaderFilter(): ReactElement;
48
+ export declare function BooleanHeaderFilter(): ReactElement;
49
+ export declare function DateHeaderFilter(): ReactElement;
50
+ export declare function TimeHeaderFilter(): ReactElement;
51
+ export declare function NoHeaderFilter(): ReactElement;
52
+ export declare function HeaderFilterWrapper({ original }: HeaderRendererProps): JSX.Element | null;
53
+ export {};
54
+ //# sourceMappingURL=header-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {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AAED,wBAAgB,gBAAgB,IAAI,YAAY,CA6B/C;AAED,wBAAgB,gBAAgB,IAAI,YAAY,CA2B/C;AAED,wBAAgB,cAAc,IAAI,YAAY,CAE7C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,QAAQ,EAAE,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAUzF"}
@@ -0,0 +1,258 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { _enum } from "@vaadin/hilla-lit-form";
3
+ import { DatePicker } from "@vaadin/react-components/DatePicker.js";
4
+ import { Item } from "@vaadin/react-components/Item.js";
5
+ import { ListBox } from "@vaadin/react-components/ListBox.js";
6
+ import { NumberField } from "@vaadin/react-components/NumberField.js";
7
+ import { Select } from "@vaadin/react-components/Select.js";
8
+ import { TextField } from "@vaadin/react-components/TextField.js";
9
+ import { TimePicker } from "@vaadin/react-components/TimePicker.js";
10
+ import {
11
+ useContext,
12
+ useEffect,
13
+ useRef,
14
+ useState
15
+ } from "react";
16
+ import { ColumnContext, CustomColumnContext } from "./autogrid-column-context.js";
17
+ import { useDatePickerI18n } from "./locale.js";
18
+ import Matcher from "./types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js";
19
+ import { convertToTitleCase } from "./util";
20
+ function useFilterState(initialMatcher) {
21
+ const context = useContext(ColumnContext);
22
+ const [matcher, setMatcher] = useState(initialMatcher);
23
+ const [filterValue, setFilterValue] = useState("");
24
+ function updateFilter(newMatcher, newFilterValue) {
25
+ setFilterValue(newFilterValue);
26
+ setMatcher(newMatcher);
27
+ const filter = {
28
+ propertyId: context.propertyInfo.name,
29
+ filterValue: newFilterValue,
30
+ matcher: newMatcher,
31
+ "@type": "propertyString"
32
+ };
33
+ context.setColumnFilter(filter, context.filterKey);
34
+ }
35
+ return { matcher, filterValue, updateFilter };
36
+ }
37
+ function useSelectInitWorkaround(selectRef) {
38
+ useEffect(() => {
39
+ setTimeout(() => {
40
+ if (selectRef.current) {
41
+ selectRef.current.requestContentUpdate();
42
+ }
43
+ }, 1);
44
+ }, []);
45
+ }
46
+ function ComparationSelection({ onMatcherChanged, value, isDateTimeType }) {
47
+ const select = useRef(null);
48
+ useSelectInitWorkaround(select);
49
+ return /* @__PURE__ */ jsx(
50
+ Select,
51
+ {
52
+ theme: "small",
53
+ className: "auto-grid-comparation-selection",
54
+ ref: select,
55
+ value,
56
+ onValueChanged: ({ detail }) => {
57
+ onMatcherChanged(detail.value);
58
+ },
59
+ renderer: () => /* @__PURE__ */ jsxs(ListBox, { children: [
60
+ /* @__PURE__ */ jsx(Item, { value: Matcher.GREATER_THAN, ...{ label: ">" }, children: isDateTimeType ? "> After" : "> Greater than" }),
61
+ /* @__PURE__ */ jsx(Item, { value: Matcher.LESS_THAN, ...{ label: "<" }, children: isDateTimeType ? "< Before" : "< Less than" }),
62
+ /* @__PURE__ */ jsx(Item, { value: Matcher.EQUALS, ...{ label: "=" }, children: "= Equals" })
63
+ ] })
64
+ }
65
+ );
66
+ }
67
+ function StringHeaderFilter() {
68
+ const context = useContext(ColumnContext);
69
+ const { filterPlaceholder, filterDebounceTime, filterMinLength } = context.customColumnOptions ?? {};
70
+ const { updateFilter } = useFilterState(Matcher.CONTAINS);
71
+ const [inputValue, setInputValue] = useState("");
72
+ useEffect(() => {
73
+ if (filterMinLength && inputValue && inputValue.length < filterMinLength) {
74
+ updateFilter(Matcher.CONTAINS, "");
75
+ return () => {
76
+ };
77
+ }
78
+ const delayInputTimeoutId = setTimeout(() => {
79
+ updateFilter(Matcher.CONTAINS, inputValue);
80
+ }, filterDebounceTime ?? 200);
81
+ return () => clearTimeout(delayInputTimeoutId);
82
+ }, [inputValue]);
83
+ return /* @__PURE__ */ jsx("div", { className: "auto-grid-string-filter", children: /* @__PURE__ */ jsx(
84
+ TextField,
85
+ {
86
+ theme: "small",
87
+ placeholder: filterPlaceholder ?? "Filter...",
88
+ onInput: (e) => {
89
+ const fieldValue = e.target.value;
90
+ setInputValue(fieldValue);
91
+ }
92
+ }
93
+ ) });
94
+ }
95
+ function NumberHeaderFilter() {
96
+ const context = useContext(ColumnContext);
97
+ const { filterPlaceholder, filterDebounceTime } = context.customColumnOptions ?? {};
98
+ const [inputValue, setInputValue] = useState("");
99
+ const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);
100
+ const select = useRef(null);
101
+ useSelectInitWorkaround(select);
102
+ useEffect(() => {
103
+ const delayInputTimeoutId = setTimeout(() => {
104
+ updateFilter(matcher, inputValue);
105
+ }, filterDebounceTime ?? 200);
106
+ return () => clearTimeout(delayInputTimeoutId);
107
+ }, [inputValue]);
108
+ return /* @__PURE__ */ jsxs("div", { className: "auto-grid-number-filter", children: [
109
+ /* @__PURE__ */ jsx(ComparationSelection, { value: matcher, onMatcherChanged: (m) => updateFilter(m, filterValue) }),
110
+ /* @__PURE__ */ jsx(
111
+ NumberField,
112
+ {
113
+ theme: "small",
114
+ placeholder: filterPlaceholder ?? "Filter...",
115
+ onInput: (e) => {
116
+ const fieldValue = e.target.value;
117
+ setInputValue(fieldValue);
118
+ }
119
+ }
120
+ )
121
+ ] });
122
+ }
123
+ function EnumHeaderFilter() {
124
+ const { filterValue, updateFilter } = useFilterState(Matcher.EQUALS);
125
+ const context = useContext(ColumnContext);
126
+ const model = context.propertyInfo.model;
127
+ const options = [
128
+ {
129
+ value: "",
130
+ label: ""
131
+ },
132
+ ...Object.keys(model[_enum]).map((value) => ({
133
+ label: convertToTitleCase(value),
134
+ value
135
+ }))
136
+ ];
137
+ return /* @__PURE__ */ jsx("div", { className: "auto-grid-enum-filter", children: /* @__PURE__ */ jsx(
138
+ Select,
139
+ {
140
+ theme: "small",
141
+ items: options,
142
+ value: filterValue,
143
+ onValueChanged: (e) => {
144
+ const newFilterValue = e.detail.value;
145
+ updateFilter(Matcher.EQUALS, newFilterValue);
146
+ }
147
+ }
148
+ ) });
149
+ }
150
+ function BooleanHeaderFilter() {
151
+ const { filterValue, updateFilter } = useFilterState(Matcher.EQUALS);
152
+ const select = useRef(null);
153
+ useSelectInitWorkaround(select);
154
+ return /* @__PURE__ */ jsx("div", { className: "auto-grid-boolean-filter", children: /* @__PURE__ */ jsx(
155
+ Select,
156
+ {
157
+ theme: "small",
158
+ ref: select,
159
+ onValueChanged: (e) => {
160
+ const newFilterValue = e.detail.value;
161
+ updateFilter(Matcher.EQUALS, newFilterValue);
162
+ },
163
+ renderer: () => /* @__PURE__ */ jsxs(ListBox, { children: [
164
+ /* @__PURE__ */ jsx(Item, { value: "", ...{ label: "" } }),
165
+ /* @__PURE__ */ jsx(Item, { value: "True", ...{ label: "Yes" }, children: "Yes" }),
166
+ /* @__PURE__ */ jsx(Item, { value: "False", ...{ label: "No" }, children: "No" })
167
+ ] }),
168
+ value: filterValue
169
+ }
170
+ ) });
171
+ }
172
+ function DateHeaderFilter() {
173
+ const context = useContext(ColumnContext);
174
+ const i18n = useDatePickerI18n();
175
+ const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);
176
+ const [invalid, setInvalid] = useState(false);
177
+ return /* @__PURE__ */ jsxs("div", { className: "auto-grid-date-filter", children: [
178
+ /* @__PURE__ */ jsx(
179
+ ComparationSelection,
180
+ {
181
+ value: matcher,
182
+ onMatcherChanged: (m) => updateFilter(m, filterValue),
183
+ isDateTimeType: true
184
+ }
185
+ ),
186
+ /* @__PURE__ */ jsx(
187
+ DatePicker,
188
+ {
189
+ theme: "small",
190
+ value: filterValue,
191
+ placeholder: context.customColumnOptions?.filterPlaceholder ?? "Filter...",
192
+ i18n,
193
+ onInvalidChanged: ({ detail: { value } }) => {
194
+ setInvalid(value);
195
+ },
196
+ onValueChanged: ({ detail: { value } }) => {
197
+ if (!(invalid || value === filterValue)) {
198
+ updateFilter(matcher, value);
199
+ }
200
+ }
201
+ }
202
+ )
203
+ ] });
204
+ }
205
+ function TimeHeaderFilter() {
206
+ const context = useContext(ColumnContext);
207
+ const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);
208
+ const [invalid, setInvalid] = useState(false);
209
+ return /* @__PURE__ */ jsxs("div", { className: "auto-grid-time-filter", children: [
210
+ /* @__PURE__ */ jsx(
211
+ ComparationSelection,
212
+ {
213
+ value: matcher,
214
+ onMatcherChanged: (m) => updateFilter(m, filterValue),
215
+ isDateTimeType: true
216
+ }
217
+ ),
218
+ /* @__PURE__ */ jsx(
219
+ TimePicker,
220
+ {
221
+ theme: "small",
222
+ value: filterValue,
223
+ placeholder: context.customColumnOptions?.filterPlaceholder ?? "Filter...",
224
+ onInvalidChanged: ({ detail: { value } }) => {
225
+ setInvalid(value);
226
+ },
227
+ onValueChanged: ({ detail: { value } }) => {
228
+ if (!(invalid || value === filterValue)) {
229
+ updateFilter(matcher, value);
230
+ }
231
+ }
232
+ }
233
+ )
234
+ ] });
235
+ }
236
+ function NoHeaderFilter() {
237
+ return /* @__PURE__ */ jsx(Fragment, {});
238
+ }
239
+ function HeaderFilterWrapper({ original }) {
240
+ const context = useContext(ColumnContext);
241
+ const customContext = useContext(CustomColumnContext);
242
+ const { setColumnFilter, headerFilterRenderer: HeaderFilterRenderer, filterKey } = context ?? customContext;
243
+ function setFilter(filter) {
244
+ setColumnFilter(filter, filterKey);
245
+ }
246
+ return /* @__PURE__ */ jsx(HeaderFilterRenderer, { original, setFilter });
247
+ }
248
+ export {
249
+ BooleanHeaderFilter,
250
+ DateHeaderFilter,
251
+ EnumHeaderFilter,
252
+ HeaderFilterWrapper,
253
+ NoHeaderFilter,
254
+ NumberHeaderFilter,
255
+ StringHeaderFilter,
256
+ TimeHeaderFilter
257
+ };
258
+ //# sourceMappingURL=header-filter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/header-filter.tsx"],
4
+ "sourcesContent": ["import { _enum, type EnumModel } from '@vaadin/hilla-lit-form';\nimport { DatePicker } from '@vaadin/react-components/DatePicker.js';\nimport type { GridColumnProps } from '@vaadin/react-components/GridColumn.js';\nimport { Item } from '@vaadin/react-components/Item.js';\nimport { ListBox } from '@vaadin/react-components/ListBox.js';\nimport { NumberField } from '@vaadin/react-components/NumberField.js';\nimport { Select, type SelectElement } from '@vaadin/react-components/Select.js';\nimport { TextField, type TextFieldElement } from '@vaadin/react-components/TextField.js';\nimport { TimePicker } from '@vaadin/react-components/TimePicker.js';\nimport {\n type ComponentType,\n type JSX,\n type ReactElement,\n type RefObject,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport { ColumnContext, CustomColumnContext } from './autogrid-column-context.js';\nimport { useDatePickerI18n } from './locale.js';\nimport type FilterUnion from './types/com/vaadin/hilla/crud/filter/FilterUnion';\nimport type PropertyStringFilter from './types/com/vaadin/hilla/crud/filter/PropertyStringFilter';\nimport Matcher from './types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js';\nimport { convertToTitleCase } from './util';\n\ntype ExtractComponentTypeProps<T extends ComponentType<any>> = T extends ComponentType<infer U> ? U : never;\n\nexport type HeaderRendererProps = ExtractComponentTypeProps<\n NonNullable<Required<GridColumnProps<unknown>>['headerRenderer']>\n>;\n\nexport type HeaderFilterRendererProps = HeaderRendererProps & {\n /**\n * Allows to set custom filters for the column.\n * This is used by the header filter components.\n * @param filter - The filter to set in the filter list.\n */\n setFilter(filter: FilterUnion): void;\n};\n\nexport type HeaderFilterProps = Readonly<{\n /**\n * If true, the column can be sorted. This is useful to disable sorting for\n * properties that are not sortable in the backend, or that require excessive processing.\n */\n sortable?: boolean;\n /**\n * If true, the column can be filtered. This is useful to disable filtering for\n * properties that are not sortable in the backend, or that require excessive processing.\n */\n filterable?: boolean;\n /**\n * Placeholder text for the filter input.\n * Only applies to string, number and date/time value filters.\n */\n filterPlaceholder?: string;\n /**\n * Debounce time for the filter input in milliseconds.\n * Only applies to string value filters and number value filters.\n */\n filterDebounceTime?: number;\n /**\n * Minimum length for the filter input.\n * Only applies to string value filters.\n */\n filterMinLength?: number;\n\n /**\n * Custom renderer for the filter in the header.\n */\n headerFilterRenderer?: ComponentType<HeaderFilterRendererProps>;\n}>;\n\nfunction useFilterState(initialMatcher: Matcher) {\n const context = useContext(ColumnContext)!;\n const [matcher, setMatcher] = useState(initialMatcher);\n const [filterValue, setFilterValue] = useState('');\n\n function updateFilter(newMatcher: Matcher, newFilterValue: string) {\n setFilterValue(newFilterValue);\n setMatcher(newMatcher);\n\n const filter: PropertyStringFilter = {\n propertyId: context.propertyInfo.name,\n filterValue: newFilterValue,\n matcher: newMatcher,\n '@type': 'propertyString',\n };\n context.setColumnFilter(filter, context.filterKey);\n }\n\n return { matcher, filterValue, updateFilter };\n}\n\n// Workaround for https://github.com/vaadin/react-components/issues/148\nfunction useSelectInitWorkaround(selectRef: RefObject<SelectElement>) {\n useEffect(() => {\n setTimeout(() => {\n if (selectRef.current) {\n selectRef.current.requestContentUpdate();\n }\n }, 1);\n }, []);\n}\n\n// extracted component (and type) to avoid code duplication\ntype ComparationSelectionProps = Readonly<{\n value: Matcher;\n onMatcherChanged(matcher: Matcher): void;\n isDateTimeType?: boolean;\n}>;\n\nfunction ComparationSelection({ onMatcherChanged, value, isDateTimeType }: ComparationSelectionProps): ReactElement {\n const select = useRef<SelectElement>(null);\n\n useSelectInitWorkaround(select);\n\n return (\n <Select\n theme=\"small\"\n className=\"auto-grid-comparation-selection\"\n ref={select}\n value={value}\n onValueChanged={({ detail }) => {\n onMatcherChanged(detail.value as Matcher);\n }}\n renderer={() => (\n <ListBox>\n <Item value={Matcher.GREATER_THAN} {...{ label: '>' }}>\n {isDateTimeType ? '> After' : '> Greater than'}\n </Item>\n <Item value={Matcher.LESS_THAN} {...{ label: '<' }}>\n {isDateTimeType ? '< Before' : '< Less than'}\n </Item>\n <Item value={Matcher.EQUALS} {...{ label: '=' }}>\n = Equals\n </Item>\n </ListBox>\n )}\n ></Select>\n );\n}\n\nexport function StringHeaderFilter(): ReactElement {\n const context = useContext(ColumnContext)!;\n const { filterPlaceholder, filterDebounceTime, filterMinLength } = context.customColumnOptions ?? {};\n const { updateFilter } = useFilterState(Matcher.CONTAINS);\n const [inputValue, setInputValue] = useState('');\n\n useEffect(() => {\n if (filterMinLength && inputValue && inputValue.length < filterMinLength) {\n updateFilter(Matcher.CONTAINS, '');\n return () => {};\n }\n\n const delayInputTimeoutId = setTimeout(() => {\n updateFilter(Matcher.CONTAINS, inputValue);\n }, filterDebounceTime ?? 200);\n return () => clearTimeout(delayInputTimeoutId);\n }, [inputValue]);\n\n return (\n <div className=\"auto-grid-string-filter\">\n <TextField\n theme=\"small\"\n placeholder={filterPlaceholder ?? 'Filter...'}\n onInput={(e: any) => {\n const fieldValue = ((e as InputEvent).target as TextFieldElement).value;\n setInputValue(fieldValue);\n }}\n ></TextField>\n </div>\n );\n}\n\nexport function NumberHeaderFilter(): ReactElement {\n const context = useContext(ColumnContext)!;\n const { filterPlaceholder, filterDebounceTime } = context.customColumnOptions ?? {};\n const [inputValue, setInputValue] = useState('');\n const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);\n const select = useRef<SelectElement>(null);\n\n useSelectInitWorkaround(select);\n\n useEffect(() => {\n const delayInputTimeoutId = setTimeout(() => {\n updateFilter(matcher, inputValue);\n }, filterDebounceTime ?? 200);\n return () => clearTimeout(delayInputTimeoutId);\n }, [inputValue]);\n\n return (\n <div className=\"auto-grid-number-filter\">\n <ComparationSelection value={matcher} onMatcherChanged={(m) => updateFilter(m, filterValue)} />\n <NumberField\n theme=\"small\"\n placeholder={filterPlaceholder ?? 'Filter...'}\n onInput={(e) => {\n const fieldValue = ((e as InputEvent).target as TextFieldElement).value;\n setInputValue(fieldValue);\n }}\n />\n </div>\n );\n}\n\nexport function EnumHeaderFilter(): ReactElement {\n const { filterValue, updateFilter } = useFilterState(Matcher.EQUALS);\n const context = useContext(ColumnContext)!;\n const model = context.propertyInfo.model as EnumModel;\n const options = [\n {\n value: '',\n label: '',\n },\n ...Object.keys(model[_enum]).map((value) => ({\n label: convertToTitleCase(value),\n value,\n })),\n ];\n return (\n <div className=\"auto-grid-enum-filter\">\n <Select\n theme=\"small\"\n items={options}\n value={filterValue}\n onValueChanged={(e) => {\n const newFilterValue = e.detail.value;\n updateFilter(Matcher.EQUALS, newFilterValue);\n }}\n />\n </div>\n );\n}\n\nexport function BooleanHeaderFilter(): ReactElement {\n const { filterValue, updateFilter } = useFilterState(Matcher.EQUALS);\n const select = useRef<SelectElement>(null);\n\n useSelectInitWorkaround(select);\n\n return (\n <div className=\"auto-grid-boolean-filter\">\n <Select\n theme=\"small\"\n ref={select}\n onValueChanged={(e) => {\n const newFilterValue = e.detail.value;\n updateFilter(Matcher.EQUALS, newFilterValue);\n }}\n renderer={() => (\n <ListBox>\n <Item value={''} {...{ label: '' }}></Item>\n <Item value={'True'} {...{ label: 'Yes' }}>\n Yes\n </Item>\n <Item value={'False'} {...{ label: 'No' }}>\n No\n </Item>\n </ListBox>\n )}\n value={filterValue}\n ></Select>\n </div>\n );\n}\n\nexport function DateHeaderFilter(): ReactElement {\n const context = useContext(ColumnContext)!;\n const i18n = useDatePickerI18n();\n const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);\n const [invalid, setInvalid] = useState(false);\n\n return (\n <div className=\"auto-grid-date-filter\">\n <ComparationSelection\n value={matcher}\n onMatcherChanged={(m) => updateFilter(m, filterValue)}\n isDateTimeType={true}\n />\n <DatePicker\n theme=\"small\"\n value={filterValue}\n placeholder={context.customColumnOptions?.filterPlaceholder ?? 'Filter...'}\n i18n={i18n}\n onInvalidChanged={({ detail: { value } }) => {\n setInvalid(value);\n }}\n onValueChanged={({ detail: { value } }) => {\n if (!(invalid || value === filterValue)) {\n updateFilter(matcher, value);\n }\n }}\n />\n </div>\n );\n}\n\nexport function TimeHeaderFilter(): ReactElement {\n const context = useContext(ColumnContext)!;\n const { matcher, filterValue, updateFilter } = useFilterState(Matcher.GREATER_THAN);\n const [invalid, setInvalid] = useState(false);\n\n return (\n <div className=\"auto-grid-time-filter\">\n <ComparationSelection\n value={matcher}\n onMatcherChanged={(m) => updateFilter(m, filterValue)}\n isDateTimeType={true}\n />\n <TimePicker\n theme=\"small\"\n value={filterValue}\n placeholder={context.customColumnOptions?.filterPlaceholder ?? 'Filter...'}\n onInvalidChanged={({ detail: { value } }) => {\n setInvalid(value);\n }}\n onValueChanged={({ detail: { value } }) => {\n if (!(invalid || value === filterValue)) {\n updateFilter(matcher, value);\n }\n }}\n />\n </div>\n );\n}\n\nexport function NoHeaderFilter(): ReactElement {\n return <></>;\n}\n\nexport function HeaderFilterWrapper({ original }: HeaderRendererProps): JSX.Element | null {\n const context = useContext(ColumnContext);\n const customContext = useContext(CustomColumnContext);\n const { setColumnFilter, headerFilterRenderer: HeaderFilterRenderer, filterKey } = (context ?? customContext)!;\n\n function setFilter(filter: FilterUnion) {\n setColumnFilter(filter, filterKey);\n }\n\n return <HeaderFilterRenderer original={original} setFilter={setFilter} />;\n}\n"],
5
+ "mappings": "AAgIQ,SAyMC,UAxMC,KADF;AAhIR,SAAS,aAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,cAAkC;AAC3C,SAAS,iBAAwC;AACjD,SAAS,kBAAkB;AAC3B;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe,2BAA2B;AACnD,SAAS,yBAAyB;AAGlC,OAAO,aAAa;AACpB,SAAS,0BAA0B;AAkDnC,SAAS,eAAe,gBAAyB;AAC/C,QAAM,UAAU,WAAW,aAAa;AACxC,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,cAAc;AACrD,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,EAAE;AAEjD,WAAS,aAAa,YAAqB,gBAAwB;AACjE,mBAAe,cAAc;AAC7B,eAAW,UAAU;AAErB,UAAM,SAA+B;AAAA,MACnC,YAAY,QAAQ,aAAa;AAAA,MACjC,aAAa;AAAA,MACb,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AACA,YAAQ,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,QACA,gBAAgB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM;AACzC,cAAI,EAAE,WAAW,UAAU,cAAc;AACvC,yBAAa,SAAS,KAAK;AAAA,UAC7B;AAAA,QACF;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;AAEO,SAAS,iBAA+B;AAC7C,SAAO,gCAAE;AACX;AAEO,SAAS,oBAAoB,EAAE,SAAS,GAA4C;AACzF,QAAM,UAAU,WAAW,aAAa;AACxC,QAAM,gBAAgB,WAAW,mBAAmB;AACpD,QAAM,EAAE,iBAAiB,sBAAsB,sBAAsB,UAAU,IAAK,WAAW;AAE/F,WAAS,UAAU,QAAqB;AACtC,oBAAgB,QAAQ,SAAS;AAAA,EACnC;AAEA,SAAO,oBAAC,wBAAqB,UAAoB,WAAsB;AACzE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import { type ReactElement } from 'react';
2
+ export declare function HeaderSorter(): ReactElement;
3
+ //# sourceMappingURL=header-sorter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"header-sorter.d.ts","sourceRoot":"","sources":["src/header-sorter.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,YAAY,EAAE,MAAM,OAAO,CAAC;AAGtD,wBAAgB,YAAY,IAAI,YAAY,CAsB3C"}
@@ -0,0 +1,28 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ import { GridSorter } from "@vaadin/react-components/GridSorter.js";
3
+ import { useContext } from "react";
4
+ import { ColumnContext } from "./autogrid-column-context.js";
5
+ function HeaderSorter() {
6
+ const context = useContext(ColumnContext);
7
+ const sorterState = context.sortState[context.propertyInfo.name];
8
+ const direction = sorterState?.direction ?? null;
9
+ const headerLabel = context.customColumnOptions?.header ?? context.propertyInfo.humanReadableName;
10
+ return context.customColumnOptions?.sortable === false ? /* @__PURE__ */ jsx(Fragment, { children: headerLabel }) : /* @__PURE__ */ jsx(
11
+ GridSorter,
12
+ {
13
+ path: context.propertyInfo.name,
14
+ direction,
15
+ onDirectionChanged: (e) => {
16
+ context.setSortState((prevState) => {
17
+ const newSorterState = e.detail.value ? { direction: e.detail.value } : void 0;
18
+ return { ...prevState, [context.propertyInfo.name]: newSorterState };
19
+ });
20
+ },
21
+ children: headerLabel
22
+ }
23
+ );
24
+ }
25
+ export {
26
+ HeaderSorter
27
+ };
28
+ //# sourceMappingURL=header-sorter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/header-sorter.tsx"],
4
+ "sourcesContent": ["import { GridSorter } from '@vaadin/react-components/GridSorter.js';\nimport { useContext, type ReactElement } from 'react';\nimport { ColumnContext } from './autogrid-column-context.js';\n\nexport function HeaderSorter(): ReactElement {\n const context = useContext(ColumnContext)!;\n const sorterState = context.sortState[context.propertyInfo.name];\n const direction = sorterState?.direction ?? null;\n const headerLabel = context.customColumnOptions?.header ?? context.propertyInfo.humanReadableName;\n\n return context.customColumnOptions?.sortable === false ? (\n <>{headerLabel}</>\n ) : (\n <GridSorter\n path={context.propertyInfo.name}\n direction={direction}\n onDirectionChanged={(e) => {\n context.setSortState((prevState) => {\n const newSorterState = e.detail.value ? { direction: e.detail.value } : undefined;\n return { ...prevState, [context.propertyInfo.name]: newSorterState };\n });\n }}\n >\n {headerLabel}\n </GridSorter>\n );\n}\n"],
5
+ "mappings": "AAWI;AAXJ,SAAS,kBAAkB;AAC3B,SAAS,kBAAqC;AAC9C,SAAS,qBAAqB;AAEvB,SAAS,eAA6B;AAC3C,QAAM,UAAU,WAAW,aAAa;AACxC,QAAM,cAAc,QAAQ,UAAU,QAAQ,aAAa,IAAI;AAC/D,QAAM,YAAY,aAAa,aAAa;AAC5C,QAAM,cAAc,QAAQ,qBAAqB,UAAU,QAAQ,aAAa;AAEhF,SAAO,QAAQ,qBAAqB,aAAa,QAC/C,gCAAG,uBAAY,IAEf;AAAA,IAAC;AAAA;AAAA,MACC,MAAM,QAAQ,aAAa;AAAA,MAC3B;AAAA,MACA,oBAAoB,CAAC,MAAM;AACzB,gBAAQ,aAAa,CAAC,cAAc;AAClC,gBAAM,iBAAiB,EAAE,OAAO,QAAQ,EAAE,WAAW,EAAE,OAAO,MAAM,IAAI;AACxE,iBAAO,EAAE,GAAG,WAAW,CAAC,QAAQ,aAAa,IAAI,GAAG,eAAe;AAAA,QACrE,CAAC;AAAA,MACH;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;",
6
+ "names": []
7
+ }
package/i18n.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const defaultLocale: string | undefined;
2
+ //# sourceMappingURL=i18n.d.ts.map
package/i18n.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["src/i18n.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,EAAE,MAAM,GAAG,SAAqB,CAAC"}
package/i18n.js ADDED
@@ -0,0 +1,5 @@
1
+ const defaultLocale = void 0;
2
+ export {
3
+ defaultLocale
4
+ };
5
+ //# sourceMappingURL=i18n.js.map
package/i18n.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/i18n.ts"],
4
+ "sourcesContent": ["// The default locale to use for renderers, filter inputs, etc.\n// If undefined, the browser's locale will be used.\n// Allows to modify the locale for testing purposes.\nexport const defaultLocale: string | undefined = undefined;\n"],
5
+ "mappings": "AAGO,MAAM,gBAAoC;",
6
+ "names": []
7
+ }
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './autogrid-feature.js';
2
+ export type * from './crud.js';
3
+ export * from './autoform-feature.js';
4
+ export * from './autocrud-feature.js';
5
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,mBAAmB,WAAW,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
package/index.js ADDED
@@ -0,0 +1,13 @@
1
+ function __REGISTER__(feature) {
2
+ window.Vaadin ??= {};
3
+ window.Vaadin.registrations ??= [];
4
+ window.Vaadin.registrations.push({
5
+ is: feature ? `${"@vaadin/hilla-react-crud"}/${feature}` : "@vaadin/hilla-react-crud",
6
+ version: "24.4.0-alpha1"
7
+ });
8
+ }
9
+ export * from "./autogrid-feature.js";
10
+ export * from "./autoform-feature.js";
11
+ export * from "./autocrud-feature.js";
12
+ __REGISTER__();
13
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../scripts/register.js", "src/index.ts"],
4
+ "sourcesContent": ["export function __REGISTER__(feature) {\n window.Vaadin ??= {};\n window.Vaadin.registrations ??= [];\n window.Vaadin.registrations.push({\n is: feature ? `${__NAME__}/${feature}` : __NAME__,\n version: __VERSION__,\n });\n}\n", "export * from './autogrid-feature.js';\nexport type * from './crud.js';\nexport * from './autoform-feature.js';\nexport * from './autocrud-feature.js';\n\n// @ts-expect-error: esbuild injection\n// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n__REGISTER__();\n"],
5
+ "mappings": "AAAO,SAAS,aAAa,SAAS;AACpC,SAAO,WAAW,CAAC;AACnB,SAAO,OAAO,kBAAkB,CAAC;AACjC,SAAO,OAAO,cAAc,KAAK;AAAA,IAC/B,IAAI,UAAU,GAAG,0BAAQ,IAAI,OAAO,KAAK;AAAA,IACzC,SAAS;AAAA,EACX,CAAC;AACH;ACPA,cAAc;AAEd,cAAc;AACd,cAAc;AAId,aAAa;",
6
+ "names": []
7
+ }
package/locale.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import { type DatePickerDate, type DatePickerI18n } from '@vaadin/react-components/DatePicker.js';
3
+ import { type DateTimePickerI18n } from '@vaadin/react-components/DateTimePicker.js';
4
+ export declare const LocaleContext: import("react").Context<string>;
5
+ export declare class LocaleFormatter {
6
+ #private;
7
+ constructor(locale?: string);
8
+ formatDate(value?: string): string;
9
+ formatDate(value: DatePickerDate): string;
10
+ formatLocalTime(value?: string): string;
11
+ formatLocalDateTime(value?: string): string;
12
+ formatInteger(value?: number): string;
13
+ formatDecimal(value?: number): string;
14
+ parse(dateString: string): DatePickerDate | undefined;
15
+ }
16
+ export declare function useLocaleFormatter(): LocaleFormatter;
17
+ export declare function useDatePickerI18n(): DatePickerI18n;
18
+ export declare function useDateTimePickerI18n(): DateTimePickerI18n;
19
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["src/locale.ts"],"names":[],"mappings":";AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACrH,OAAO,EAAyB,KAAK,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAG5G,eAAO,MAAM,aAAa,iCAAoC,CAAC;AAuB/D,qBAAa,eAAe;;gBAQd,MAAM,CAAC,EAAE,MAAM;IA4B3B,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAClC,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM;IAczC,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAIvC,mBAAmB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAI3C,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrC,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;CAkBtD;AAED,wBAAgB,kBAAkB,IAAI,eAAe,CAGpD;AAID,wBAAgB,iBAAiB,IAAI,cAAc,CAelD;AAID,wBAAgB,qBAAqB,IAAI,kBAAkB,CAU1D"}
package/locale.js ADDED
@@ -0,0 +1,123 @@
1
+ import { DatePickerElement } from "@vaadin/react-components/DatePicker.js";
2
+ import { DateTimePickerElement } from "@vaadin/react-components/DateTimePicker.js";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ const LocaleContext = createContext(navigator.language);
5
+ function getFormatRegex(format) {
6
+ const sampleDate = new Date(1234, 5 - 1, 6);
7
+ const formattedSample = format.format(sampleDate);
8
+ const pattern = formattedSample.replace("1234", "(?<year>\\d+)").replace("05", "(?<month>\\d+)").replace("5", "(?<month>\\d+)").replace("06", "(?<day>\\d+)").replace("6", "(?<day>\\d+)");
9
+ return new RegExp(pattern, "u");
10
+ }
11
+ function tryFormatDate(formatter, value) {
12
+ try {
13
+ return value ? formatter.format(new Date(value)) : "";
14
+ } catch (e) {
15
+ return "";
16
+ }
17
+ }
18
+ class LocaleFormatter {
19
+ #date;
20
+ #localTime;
21
+ #localDateTime;
22
+ #integer;
23
+ #decimal;
24
+ #parsePattern;
25
+ constructor(locale) {
26
+ this.#date = new Intl.DateTimeFormat(locale);
27
+ this.#localTime = new Intl.DateTimeFormat(locale, {
28
+ hour: "numeric",
29
+ minute: "numeric"
30
+ });
31
+ this.#localDateTime = new Intl.DateTimeFormat(locale, {
32
+ day: "numeric",
33
+ month: "numeric",
34
+ year: "numeric",
35
+ hour: "numeric",
36
+ minute: "numeric"
37
+ });
38
+ this.#integer = new Intl.NumberFormat(locale, {
39
+ maximumFractionDigits: 0
40
+ });
41
+ this.#decimal = new Intl.NumberFormat(locale, {
42
+ maximumFractionDigits: 2,
43
+ minimumFractionDigits: 2
44
+ });
45
+ this.#parsePattern = getFormatRegex(this.#date);
46
+ }
47
+ formatDate(value) {
48
+ if (typeof value === "object") {
49
+ const { year, month, day } = value;
50
+ const date = /* @__PURE__ */ new Date();
51
+ date.setFullYear(year);
52
+ date.setMonth(month);
53
+ date.setDate(day);
54
+ return this.#date.format(date);
55
+ }
56
+ return tryFormatDate(this.#date, value);
57
+ }
58
+ formatLocalTime(value) {
59
+ return tryFormatDate(this.#localTime, `2000-01-01T${value}`);
60
+ }
61
+ formatLocalDateTime(value) {
62
+ return tryFormatDate(this.#localDateTime, value);
63
+ }
64
+ formatInteger(value) {
65
+ return value && Number.isFinite(value) ? this.#integer.format(value) : "";
66
+ }
67
+ formatDecimal(value) {
68
+ return value && Number.isFinite(value) ? this.#decimal.format(value) : "";
69
+ }
70
+ parse(dateString) {
71
+ const match = this.#parsePattern.exec(dateString);
72
+ const year = Number(match?.groups?.year);
73
+ const month = Number(match?.groups?.month) - 1;
74
+ const day = Number(match?.groups?.day);
75
+ const dateInstance = /* @__PURE__ */ new Date();
76
+ dateInstance.setFullYear(year);
77
+ dateInstance.setMonth(month);
78
+ dateInstance.setDate(day);
79
+ if (dateInstance.getFullYear() !== year || dateInstance.getMonth() !== month || dateInstance.getDate() !== day) {
80
+ return void 0;
81
+ }
82
+ return { year, month, day };
83
+ }
84
+ }
85
+ function useLocaleFormatter() {
86
+ const locale = useContext(LocaleContext);
87
+ return useMemo(() => new LocaleFormatter(locale), [locale]);
88
+ }
89
+ const defaultDatePickerI18n = new DatePickerElement().i18n;
90
+ function useDatePickerI18n() {
91
+ const formatter = useLocaleFormatter();
92
+ return useMemo(
93
+ () => ({
94
+ ...defaultDatePickerI18n,
95
+ formatDate(value) {
96
+ return formatter.formatDate(value);
97
+ },
98
+ parseDate(value) {
99
+ return formatter.parse(value);
100
+ }
101
+ }),
102
+ [formatter]
103
+ );
104
+ }
105
+ const defaultDateTimePickerI18n = new DateTimePickerElement().i18n;
106
+ function useDateTimePickerI18n() {
107
+ const datePickerI18n = useDatePickerI18n();
108
+ return useMemo(
109
+ () => ({
110
+ ...defaultDateTimePickerI18n,
111
+ ...datePickerI18n
112
+ }),
113
+ [datePickerI18n]
114
+ );
115
+ }
116
+ export {
117
+ LocaleContext,
118
+ LocaleFormatter,
119
+ useDatePickerI18n,
120
+ useDateTimePickerI18n,
121
+ useLocaleFormatter
122
+ };
123
+ //# sourceMappingURL=locale.js.map