@vaadin/hilla-react-crud 24.7.0-alpha9 → 24.7.0-beta1

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 (151) hide show
  1. package/autocrud-dialog.d.ts +0 -1
  2. package/autocrud-dialog.js +9 -23
  3. package/autocrud-dialog.js.map +1 -7
  4. package/autocrud-feature.d.ts +0 -1
  5. package/autocrud-feature.js +5 -8
  6. package/autocrud-feature.js.map +1 -7
  7. package/autocrud.d.ts +2 -64
  8. package/autocrud.js +43 -92
  9. package/autocrud.js.map +1 -7
  10. package/autocrud.obj.js +1 -6
  11. package/autoform-feature.d.ts +0 -1
  12. package/autoform-feature.js +5 -8
  13. package/autoform-feature.js.map +1 -7
  14. package/autoform-field.d.ts +0 -90
  15. package/autoform-field.js +87 -95
  16. package/autoform-field.js.map +1 -7
  17. package/autoform.d.ts +0 -190
  18. package/autoform.js +126 -184
  19. package/autoform.js.map +1 -7
  20. package/autoform.obj.js +1 -6
  21. package/autogrid-column-context.d.ts +1 -2
  22. package/autogrid-column-context.js +4 -8
  23. package/autogrid-column-context.js.map +1 -7
  24. package/autogrid-columns.d.ts +0 -1
  25. package/autogrid-columns.js +83 -99
  26. package/autogrid-columns.js.map +1 -7
  27. package/autogrid-feature.d.ts +0 -1
  28. package/autogrid-feature.js +5 -8
  29. package/autogrid-feature.js.map +1 -7
  30. package/autogrid-renderers.d.ts +0 -1
  31. package/autogrid-renderers.js +71 -80
  32. package/autogrid-renderers.js.map +1 -7
  33. package/autogrid.d.ts +1 -103
  34. package/autogrid.js +176 -234
  35. package/autogrid.js.map +1 -7
  36. package/autogrid.obj.js +1 -6
  37. package/crud.d.ts +7 -10
  38. package/data-provider.d.ts +37 -6
  39. package/data-provider.js +186 -121
  40. package/data-provider.js.map +1 -7
  41. package/header-filter.d.ts +1 -30
  42. package/header-filter.js +137 -244
  43. package/header-filter.js.map +1 -7
  44. package/header-sorter.d.ts +0 -1
  45. package/header-sorter.js +16 -27
  46. package/header-sorter.js.map +1 -7
  47. package/i18n.d.ts +0 -1
  48. package/i18n.js +2 -5
  49. package/i18n.js.map +1 -7
  50. package/index.d.ts +1 -2
  51. package/index.js +12 -16
  52. package/index.js.map +1 -7
  53. package/locale.d.ts +0 -1
  54. package/locale.js +100 -107
  55. package/locale.js.map +1 -7
  56. package/media-query.d.ts +0 -1
  57. package/media-query.js +12 -15
  58. package/media-query.js.map +1 -7
  59. package/model-info.d.ts +0 -1
  60. package/model-info.js +126 -127
  61. package/model-info.js.map +1 -7
  62. package/package.json +9 -33
  63. package/types/com/vaadin/hilla/crud/filter/AndFilter.d.ts +3 -4
  64. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts +0 -1
  65. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js +6 -9
  66. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js.map +1 -7
  67. package/types/com/vaadin/hilla/crud/filter/Filter.d.ts +1 -2
  68. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts +0 -1
  69. package/types/com/vaadin/hilla/crud/filter/FilterModel.js +3 -6
  70. package/types/com/vaadin/hilla/crud/filter/FilterModel.js.map +1 -7
  71. package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.ts +4 -2
  72. package/types/com/vaadin/hilla/crud/filter/OrFilter.d.ts +3 -4
  73. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts +0 -1
  74. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js +6 -9
  75. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js.map +1 -7
  76. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts +0 -1
  77. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js +9 -12
  78. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js.map +1 -7
  79. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts +0 -1
  80. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js +4 -7
  81. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js.map +1 -7
  82. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.ts +4 -5
  83. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts +0 -1
  84. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js +12 -15
  85. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js.map +1 -7
  86. package/types/com/vaadin/hilla/mappedtypes/Order.d.ts +3 -4
  87. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts +0 -1
  88. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js +15 -18
  89. package/types/com/vaadin/hilla/mappedtypes/OrderModel.js.map +1 -7
  90. package/types/com/vaadin/hilla/mappedtypes/Pageable.d.ts +1 -2
  91. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts +0 -1
  92. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js +12 -15
  93. package/types/com/vaadin/hilla/mappedtypes/PageableModel.js.map +1 -7
  94. package/types/com/vaadin/hilla/mappedtypes/Sort.d.ts +1 -2
  95. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts +0 -1
  96. package/types/com/vaadin/hilla/mappedtypes/SortModel.js +6 -9
  97. package/types/com/vaadin/hilla/mappedtypes/SortModel.js.map +1 -7
  98. package/types/org/springframework/data/domain/Sort/Direction.d.ts +0 -1
  99. package/types/org/springframework/data/domain/Sort/Direction.js +7 -10
  100. package/types/org/springframework/data/domain/Sort/Direction.js.map +1 -7
  101. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts +0 -1
  102. package/types/org/springframework/data/domain/Sort/DirectionModel.js +4 -7
  103. package/types/org/springframework/data/domain/Sort/DirectionModel.js.map +1 -7
  104. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts +0 -1
  105. package/types/org/springframework/data/domain/Sort/NullHandling.js +8 -11
  106. package/types/org/springframework/data/domain/Sort/NullHandling.js.map +1 -7
  107. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts +0 -1
  108. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js +4 -7
  109. package/types/org/springframework/data/domain/Sort/NullHandlingModel.js.map +1 -7
  110. package/types.d.ts +6 -9
  111. package/types.js +2 -0
  112. package/types.js.map +1 -0
  113. package/util.d.ts +1 -2
  114. package/util.js +42 -47
  115. package/util.js.map +1 -7
  116. package/autocrud-dialog.d.ts.map +0 -1
  117. package/autocrud-feature.d.ts.map +0 -1
  118. package/autocrud.d.ts.map +0 -1
  119. package/autocrud.obj.js.map +0 -7
  120. package/autoform-feature.d.ts.map +0 -1
  121. package/autoform-field.d.ts.map +0 -1
  122. package/autoform.d.ts.map +0 -1
  123. package/autoform.obj.js.map +0 -7
  124. package/autogrid-column-context.d.ts.map +0 -1
  125. package/autogrid-columns.d.ts.map +0 -1
  126. package/autogrid-feature.d.ts.map +0 -1
  127. package/autogrid-renderers.d.ts.map +0 -1
  128. package/autogrid.d.ts.map +0 -1
  129. package/autogrid.obj.js.map +0 -7
  130. package/data-provider.d.ts.map +0 -1
  131. package/header-filter.d.ts.map +0 -1
  132. package/header-sorter.d.ts.map +0 -1
  133. package/i18n.d.ts.map +0 -1
  134. package/index.d.ts.map +0 -1
  135. package/locale.d.ts.map +0 -1
  136. package/media-query.d.ts.map +0 -1
  137. package/model-info.d.ts.map +0 -1
  138. package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts.map +0 -1
  139. package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts.map +0 -1
  140. package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts.map +0 -1
  141. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts.map +0 -1
  142. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts.map +0 -1
  143. package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts.map +0 -1
  144. package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts.map +0 -1
  145. package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts.map +0 -1
  146. package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts.map +0 -1
  147. package/types/org/springframework/data/domain/Sort/Direction.d.ts.map +0 -1
  148. package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts.map +0 -1
  149. package/types/org/springframework/data/domain/Sort/NullHandling.d.ts.map +0 -1
  150. package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts.map +0 -1
  151. package/util.d.ts.map +0 -1
package/index.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../scripts/register.js", "src/index.ts"],
4
- "sourcesContent": ["export function __REGISTER__(feature, vaadinObj = (window.Vaadin ??= {})) {\n vaadinObj.registrations ??= [];\n vaadinObj.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';\nexport { useDataProvider } from './data-provider.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,YAAa,OAAO,WAAW,CAAC,GAAI;AACxE,YAAU,kBAAkB,CAAC;AAC7B,YAAU,cAAc,KAAK;AAAA,IAC3B,IAAI,UAAU,GAAG,0BAAQ,IAAI,OAAO,KAAK;AAAA,IACzC,SAAS;AAAA,EACX,CAAC;AACH;ACNA,cAAc;AAEd,cAAc;AACd,cAAc;AACd,SAAS,uBAAuB;AAIhC,aAAa;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AAEtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAInG,CAAC,CAAC,OAAO,EAAE,SAAS,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC,EAAE,EAAE;IAC/C,SAAS,CAAC,aAAa,KAAK,EAAE,CAAC;IAC/B,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC;QAC3B,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC,4BAA4B,OAAO,EAAE,CAAC,CAAC,CAAC,0BAA0B;QAChF,OAAO,EAAE,cAAc;KACxB,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC","sourcesContent":["export * from './autogrid-feature.js';\nexport type * from './crud.js';\nexport * from './autoform-feature.js';\nexport * from './autocrud-feature.js';\nexport { useDataProvider, useGridDataProvider, useComboBoxDataProvider } from './data-provider.js';\n\n// @ts-expect-error: esbuild injection\n// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n((feature, vaadinObj = (window.Vaadin ??= {})) => {\n vaadinObj.registrations ??= [];\n vaadinObj.registrations.push({\n is: feature ? `@vaadin/hilla-react-crud/${feature}` : '@vaadin/hilla-react-crud',\n version: '24.7.0-beta1',\n });\n})();\n"]}
package/locale.d.ts CHANGED
@@ -15,4 +15,3 @@ export declare class LocaleFormatter {
15
15
  export declare function useLocaleFormatter(): LocaleFormatter;
16
16
  export declare function useDatePickerI18n(): DatePickerI18n;
17
17
  export declare function useDateTimePickerI18n(): DateTimePickerI18n;
18
- //# sourceMappingURL=locale.d.ts.map
package/locale.js CHANGED
@@ -1,119 +1,112 @@
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);
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
+ export const LocaleContext = createContext(navigator.language);
5
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");
6
+ const sampleDate = new Date(1234, 5 - 1, 6);
7
+ const formattedSample = format.format(sampleDate);
8
+ const pattern = formattedSample
9
+ .replace('1234', '(?<year>\\d+)')
10
+ .replace('05', '(?<month>\\d+)')
11
+ .replace('5', '(?<month>\\d+)')
12
+ .replace('06', '(?<day>\\d+)')
13
+ .replace('6', '(?<day>\\d+)');
14
+ return new RegExp(pattern, 'u');
10
15
  }
11
16
  function tryFormatDate(formatter, value) {
12
- try {
13
- return value ? formatter.format(new Date(value)) : "";
14
- } catch (e) {
15
- return "";
16
- }
17
+ try {
18
+ return value ? formatter.format(new Date(value)) : '';
19
+ }
20
+ catch {
21
+ return '';
22
+ }
17
23
  }
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, month, day);
52
- return this.#date.format(date);
24
+ export class LocaleFormatter {
25
+ #date;
26
+ #localTime;
27
+ #localDateTime;
28
+ #integer;
29
+ #decimal;
30
+ #parsePattern;
31
+ constructor(locale) {
32
+ this.#date = new Intl.DateTimeFormat(locale);
33
+ this.#localTime = new Intl.DateTimeFormat(locale, {
34
+ hour: 'numeric',
35
+ minute: 'numeric',
36
+ });
37
+ this.#localDateTime = new Intl.DateTimeFormat(locale, {
38
+ day: 'numeric',
39
+ month: 'numeric',
40
+ year: 'numeric',
41
+ hour: 'numeric',
42
+ minute: 'numeric',
43
+ });
44
+ this.#integer = new Intl.NumberFormat(locale, {
45
+ maximumFractionDigits: 0,
46
+ });
47
+ this.#decimal = new Intl.NumberFormat(locale, {
48
+ maximumFractionDigits: 2,
49
+ minimumFractionDigits: 2,
50
+ });
51
+ this.#parsePattern = getFormatRegex(this.#date);
52
+ }
53
+ formatDate(value) {
54
+ if (typeof value === 'object') {
55
+ const { year, month, day } = value;
56
+ const date = new Date();
57
+ date.setFullYear(year, month, day);
58
+ return this.#date.format(date);
59
+ }
60
+ return tryFormatDate(this.#date, value);
61
+ }
62
+ formatLocalTime(value) {
63
+ return tryFormatDate(this.#localTime, `2000-01-01T${value}`);
64
+ }
65
+ formatLocalDateTime(value) {
66
+ return tryFormatDate(this.#localDateTime, value);
67
+ }
68
+ formatInteger(value) {
69
+ return value && Number.isFinite(value) ? this.#integer.format(value) : '';
70
+ }
71
+ formatDecimal(value) {
72
+ return value && Number.isFinite(value) ? this.#decimal.format(value) : '';
53
73
  }
54
- return tryFormatDate(this.#date, value);
55
- }
56
- formatLocalTime(value) {
57
- return tryFormatDate(this.#localTime, `2000-01-01T${value}`);
58
- }
59
- formatLocalDateTime(value) {
60
- return tryFormatDate(this.#localDateTime, value);
61
- }
62
- formatInteger(value) {
63
- return value && Number.isFinite(value) ? this.#integer.format(value) : "";
64
- }
65
- formatDecimal(value) {
66
- return value && Number.isFinite(value) ? this.#decimal.format(value) : "";
67
- }
68
- parse(dateString) {
69
- const match = this.#parsePattern.exec(dateString);
70
- const year = Number(match?.groups?.year);
71
- const month = Number(match?.groups?.month) - 1;
72
- const day = Number(match?.groups?.day);
73
- const dateInstance = /* @__PURE__ */ new Date();
74
- dateInstance.setFullYear(year, month, day);
75
- if (dateInstance.getFullYear() !== year || dateInstance.getMonth() !== month || dateInstance.getDate() !== day) {
76
- return void 0;
74
+ parse(dateString) {
75
+ const match = this.#parsePattern.exec(dateString);
76
+ const year = Number(match?.groups?.year);
77
+ const month = Number(match?.groups?.month) - 1;
78
+ const day = Number(match?.groups?.day);
79
+ const dateInstance = new Date();
80
+ dateInstance.setFullYear(year, month, day);
81
+ if (dateInstance.getFullYear() !== year || dateInstance.getMonth() !== month || dateInstance.getDate() !== day) {
82
+ return undefined;
83
+ }
84
+ return { year, month, day };
77
85
  }
78
- return { year, month, day };
79
- }
80
86
  }
81
- function useLocaleFormatter() {
82
- const locale = useContext(LocaleContext);
83
- return useMemo(() => new LocaleFormatter(locale), [locale]);
87
+ export function useLocaleFormatter() {
88
+ const locale = useContext(LocaleContext);
89
+ return useMemo(() => new LocaleFormatter(locale), [locale]);
84
90
  }
85
91
  const defaultDatePickerI18n = new DatePickerElement().i18n;
86
- function useDatePickerI18n() {
87
- const formatter = useLocaleFormatter();
88
- return useMemo(
89
- () => ({
90
- ...defaultDatePickerI18n,
91
- formatDate(value) {
92
- return formatter.formatDate(value);
93
- },
94
- parseDate(value) {
95
- return formatter.parse(value);
96
- }
97
- }),
98
- [formatter]
99
- );
92
+ export function useDatePickerI18n() {
93
+ const formatter = useLocaleFormatter();
94
+ return useMemo(() => ({
95
+ ...defaultDatePickerI18n,
96
+ formatDate(value) {
97
+ return formatter.formatDate(value);
98
+ },
99
+ parseDate(value) {
100
+ return formatter.parse(value);
101
+ },
102
+ }), [formatter]);
100
103
  }
101
104
  const defaultDateTimePickerI18n = new DateTimePickerElement().i18n;
102
- function useDateTimePickerI18n() {
103
- const datePickerI18n = useDatePickerI18n();
104
- return useMemo(
105
- () => ({
106
- ...defaultDateTimePickerI18n,
107
- ...datePickerI18n
108
- }),
109
- [datePickerI18n]
110
- );
105
+ export function useDateTimePickerI18n() {
106
+ const datePickerI18n = useDatePickerI18n();
107
+ return useMemo(() => ({
108
+ ...defaultDateTimePickerI18n,
109
+ ...datePickerI18n,
110
+ }), [datePickerI18n]);
111
111
  }
112
- export {
113
- LocaleContext,
114
- LocaleFormatter,
115
- useDatePickerI18n,
116
- useDateTimePickerI18n,
117
- useLocaleFormatter
118
- };
119
- //# sourceMappingURL=locale.js.map
112
+ //# sourceMappingURL=locale.js.map
package/locale.js.map CHANGED
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/locale.ts"],
4
- "sourcesContent": ["import { DatePickerElement, type DatePickerDate, type DatePickerI18n } from '@vaadin/react-components/DatePicker.js';\nimport { DateTimePickerElement, type DateTimePickerI18n } from '@vaadin/react-components/DateTimePicker.js';\nimport { createContext, useContext, useMemo } from 'react';\n\nexport const LocaleContext = createContext(navigator.language);\n\nfunction getFormatRegex(format: Intl.DateTimeFormat) {\n const sampleDate = new Date(1234, 5 - 1, 6);\n const formattedSample = format.format(sampleDate);\n const pattern = formattedSample\n .replace('1234', '(?<year>\\\\d+)')\n .replace('05', '(?<month>\\\\d+)')\n .replace('5', '(?<month>\\\\d+)')\n .replace('06', '(?<day>\\\\d+)')\n .replace('6', '(?<day>\\\\d+)');\n\n return new RegExp(pattern, 'u');\n}\n\nfunction tryFormatDate(formatter: Intl.DateTimeFormat, value?: string): string {\n try {\n return value ? formatter.format(new Date(value)) : '';\n } catch (e) {\n return '';\n }\n}\n\nexport class LocaleFormatter {\n readonly #date: Intl.DateTimeFormat;\n readonly #localTime: Intl.DateTimeFormat;\n readonly #localDateTime: Intl.DateTimeFormat;\n readonly #integer: Intl.NumberFormat;\n readonly #decimal: Intl.NumberFormat;\n readonly #parsePattern: RegExp;\n\n constructor(locale?: string) {\n this.#date = new Intl.DateTimeFormat(locale);\n\n this.#localTime = new Intl.DateTimeFormat(locale, {\n hour: 'numeric',\n minute: 'numeric',\n });\n\n this.#localDateTime = new Intl.DateTimeFormat(locale, {\n day: 'numeric',\n month: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n });\n\n this.#integer = new Intl.NumberFormat(locale, {\n maximumFractionDigits: 0,\n });\n\n this.#decimal = new Intl.NumberFormat(locale, {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n });\n\n this.#parsePattern = getFormatRegex(this.#date);\n }\n\n formatDate(value?: string): string;\n formatDate(value: DatePickerDate): string;\n formatDate(value?: DatePickerDate | string): string {\n if (typeof value === 'object') {\n const { year, month, day } = value;\n const date = new Date();\n date.setFullYear(year, month, day);\n return this.#date.format(date);\n }\n\n return tryFormatDate(this.#date, value);\n }\n\n formatLocalTime(value?: string): string {\n return tryFormatDate(this.#localTime, `2000-01-01T${value}`);\n }\n\n formatLocalDateTime(value?: string): string {\n return tryFormatDate(this.#localDateTime, value);\n }\n\n formatInteger(value?: number): string {\n return value && Number.isFinite(value) ? this.#integer.format(value) : '';\n }\n\n formatDecimal(value?: number): string {\n return value && Number.isFinite(value) ? this.#decimal.format(value) : '';\n }\n\n parse(dateString: string): DatePickerDate | undefined {\n const match = this.#parsePattern.exec(dateString);\n const year = Number(match?.groups?.year);\n const month = Number(match?.groups?.month) - 1;\n const day = Number(match?.groups?.day);\n\n // Verify that the parsed date is valid\n const dateInstance = new Date();\n dateInstance.setFullYear(year, month, day);\n\n if (dateInstance.getFullYear() !== year || dateInstance.getMonth() !== month || dateInstance.getDate() !== day) {\n return undefined;\n }\n\n return { year, month, day };\n }\n}\n\nexport function useLocaleFormatter(): LocaleFormatter {\n const locale = useContext(LocaleContext);\n return useMemo(() => new LocaleFormatter(locale), [locale]);\n}\n\nconst defaultDatePickerI18n = new DatePickerElement().i18n;\n\nexport function useDatePickerI18n(): DatePickerI18n {\n const formatter = useLocaleFormatter();\n\n return useMemo(\n () => ({\n ...defaultDatePickerI18n,\n formatDate(value) {\n return formatter.formatDate(value);\n },\n parseDate(value) {\n return formatter.parse(value);\n },\n }),\n [formatter],\n );\n}\n\nconst defaultDateTimePickerI18n = new DateTimePickerElement().i18n;\n\nexport function useDateTimePickerI18n(): DateTimePickerI18n {\n const datePickerI18n = useDatePickerI18n();\n\n return useMemo(\n () => ({\n ...defaultDateTimePickerI18n,\n ...datePickerI18n,\n }),\n [datePickerI18n],\n );\n}\n"],
5
- "mappings": "AAAA,SAAS,yBAAmE;AAC5E,SAAS,6BAAsD;AAC/D,SAAS,eAAe,YAAY,eAAe;AAE5C,MAAM,gBAAgB,cAAc,UAAU,QAAQ;AAE7D,SAAS,eAAe,QAA6B;AACnD,QAAM,aAAa,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAC1C,QAAM,kBAAkB,OAAO,OAAO,UAAU;AAChD,QAAM,UAAU,gBACb,QAAQ,QAAQ,eAAe,EAC/B,QAAQ,MAAM,gBAAgB,EAC9B,QAAQ,KAAK,gBAAgB,EAC7B,QAAQ,MAAM,cAAc,EAC5B,QAAQ,KAAK,cAAc;AAE9B,SAAO,IAAI,OAAO,SAAS,GAAG;AAChC;AAEA,SAAS,cAAc,WAAgC,OAAwB;AAC7E,MAAI;AACF,WAAO,QAAQ,UAAU,OAAO,IAAI,KAAK,KAAK,CAAC,IAAI;AAAA,EACrD,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;AAEO,MAAM,gBAAgB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,QAAiB;AAC3B,SAAK,QAAQ,IAAI,KAAK,eAAe,MAAM;AAE3C,SAAK,aAAa,IAAI,KAAK,eAAe,QAAQ;AAAA,MAChD,MAAM;AAAA,MACN,QAAQ;AAAA,IACV,CAAC;AAED,SAAK,iBAAiB,IAAI,KAAK,e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BAAiB,EAAE,CAAC,IAAI,CAAC;AAE3D,MAAM,UAAU,iBAAiB;IAC/B,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;IAEvC,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,qBAAqB;QACxB,UAAU,CAAC,KAAK;YACd,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QACD,SAAS,CAAC,KAAK;YACb,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;KACF,CAAC,EACF,CAAC,SAAS,CAAC,CACZ,CAAC;AACJ,CAAC;AAED,MAAM,yBAAyB,GAAG,IAAI,qBAAqB,EAAE,CAAC,IAAI,CAAC;AAEnE,MAAM,UAAU,qBAAqB;IACnC,MAAM,cAAc,GAAG,iBAAiB,EAAE,CAAC;IAE3C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,yBAAyB;QAC5B,GAAG,cAAc;KAClB,CAAC,EACF,CAAC,cAAc,CAAC,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import { DatePickerElement, type DatePickerDate, type DatePickerI18n } from '@vaadin/react-components/DatePicker.js';\nimport { DateTimePickerElement, type DateTimePickerI18n } from '@vaadin/react-components/DateTimePicker.js';\nimport { createContext, useContext, useMemo } from 'react';\n\nexport const LocaleContext = createContext(navigator.language);\n\nfunction getFormatRegex(format: Intl.DateTimeFormat) {\n const sampleDate = new Date(1234, 5 - 1, 6);\n const formattedSample = format.format(sampleDate);\n const pattern = formattedSample\n .replace('1234', '(?<year>\\\\d+)')\n .replace('05', '(?<month>\\\\d+)')\n .replace('5', '(?<month>\\\\d+)')\n .replace('06', '(?<day>\\\\d+)')\n .replace('6', '(?<day>\\\\d+)');\n\n return new RegExp(pattern, 'u');\n}\n\nfunction tryFormatDate(formatter: Intl.DateTimeFormat, value?: string): string {\n try {\n return value ? formatter.format(new Date(value)) : '';\n } catch {\n return '';\n }\n}\n\nexport class LocaleFormatter {\n readonly #date: Intl.DateTimeFormat;\n readonly #localTime: Intl.DateTimeFormat;\n readonly #localDateTime: Intl.DateTimeFormat;\n readonly #integer: Intl.NumberFormat;\n readonly #decimal: Intl.NumberFormat;\n readonly #parsePattern: RegExp;\n\n constructor(locale?: string) {\n this.#date = new Intl.DateTimeFormat(locale);\n\n this.#localTime = new Intl.DateTimeFormat(locale, {\n hour: 'numeric',\n minute: 'numeric',\n });\n\n this.#localDateTime = new Intl.DateTimeFormat(locale, {\n day: 'numeric',\n month: 'numeric',\n year: 'numeric',\n hour: 'numeric',\n minute: 'numeric',\n });\n\n this.#integer = new Intl.NumberFormat(locale, {\n maximumFractionDigits: 0,\n });\n\n this.#decimal = new Intl.NumberFormat(locale, {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n });\n\n this.#parsePattern = getFormatRegex(this.#date);\n }\n\n formatDate(value?: string): string;\n formatDate(value: DatePickerDate): string;\n formatDate(value?: DatePickerDate | string): string {\n if (typeof value === 'object') {\n const { year, month, day } = value;\n const date = new Date();\n date.setFullYear(year, month, day);\n return this.#date.format(date);\n }\n\n return tryFormatDate(this.#date, value);\n }\n\n formatLocalTime(value?: string): string {\n return tryFormatDate(this.#localTime, `2000-01-01T${value}`);\n }\n\n formatLocalDateTime(value?: string): string {\n return tryFormatDate(this.#localDateTime, value);\n }\n\n formatInteger(value?: number): string {\n return value && Number.isFinite(value) ? this.#integer.format(value) : '';\n }\n\n formatDecimal(value?: number): string {\n return value && Number.isFinite(value) ? this.#decimal.format(value) : '';\n }\n\n parse(dateString: string): DatePickerDate | undefined {\n const match = this.#parsePattern.exec(dateString);\n const year = Number(match?.groups?.year);\n const month = Number(match?.groups?.month) - 1;\n const day = Number(match?.groups?.day);\n\n // Verify that the parsed date is valid\n const dateInstance = new Date();\n dateInstance.setFullYear(year, month, day);\n\n if (dateInstance.getFullYear() !== year || dateInstance.getMonth() !== month || dateInstance.getDate() !== day) {\n return undefined;\n }\n\n return { year, month, day };\n }\n}\n\nexport function useLocaleFormatter(): LocaleFormatter {\n const locale = useContext(LocaleContext);\n return useMemo(() => new LocaleFormatter(locale), [locale]);\n}\n\nconst defaultDatePickerI18n = new DatePickerElement().i18n;\n\nexport function useDatePickerI18n(): DatePickerI18n {\n const formatter = useLocaleFormatter();\n\n return useMemo(\n () => ({\n ...defaultDatePickerI18n,\n formatDate(value) {\n return formatter.formatDate(value);\n },\n parseDate(value) {\n return formatter.parse(value);\n },\n }),\n [formatter],\n );\n}\n\nconst defaultDateTimePickerI18n = new DateTimePickerElement().i18n;\n\nexport function useDateTimePickerI18n(): DateTimePickerI18n {\n const datePickerI18n = useDatePickerI18n();\n\n return useMemo(\n () => ({\n ...defaultDateTimePickerI18n,\n ...datePickerI18n,\n }),\n [datePickerI18n],\n );\n}\n"]}
package/media-query.d.ts CHANGED
@@ -1,2 +1 @@
1
1
  export declare function useMediaQuery(query: string): boolean;
2
- //# sourceMappingURL=media-query.d.ts.map
package/media-query.js CHANGED
@@ -1,16 +1,13 @@
1
- import { useEffect, useState } from "react";
2
- function useMediaQuery(query) {
3
- const [matches, setMatches] = useState(() => window.matchMedia(query).matches);
4
- useEffect(() => {
5
- const listener = (e) => setMatches(e.matches);
6
- const mediaQuery = window.matchMedia(query);
7
- setMatches(mediaQuery.matches);
8
- mediaQuery.addEventListener("change", listener);
9
- return () => mediaQuery.removeEventListener("change", listener);
10
- }, [query]);
11
- return matches;
1
+ import { useEffect, useState } from 'react';
2
+ export function useMediaQuery(query) {
3
+ const [matches, setMatches] = useState(() => window.matchMedia(query).matches);
4
+ useEffect(() => {
5
+ const listener = (e) => setMatches(e.matches);
6
+ const mediaQuery = window.matchMedia(query);
7
+ setMatches(mediaQuery.matches);
8
+ mediaQuery.addEventListener('change', listener);
9
+ return () => mediaQuery.removeEventListener('change', listener);
10
+ }, [query]);
11
+ return matches;
12
12
  }
13
- export {
14
- useMediaQuery
15
- };
16
- //# sourceMappingURL=media-query.js.map
13
+ //# sourceMappingURL=media-query.js.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["src/media-query.ts"],
4
- "sourcesContent": ["import { useEffect, useState } from 'react';\n\nexport function useMediaQuery(query: string): boolean {\n const [matches, setMatches] = useState(() => window.matchMedia(query).matches);\n\n useEffect(() => {\n const listener = (e: MediaQueryListEvent) => setMatches(e.matches);\n const mediaQuery = window.matchMedia(query);\n setMatches(mediaQuery.matches);\n mediaQuery.addEventListener('change', listener);\n return () => mediaQuery.removeEventListener('change', listener);\n }, [query]);\n\n return matches;\n}\n"],
5
- "mappings": "AAAA,SAAS,WAAW,gBAAgB;AAE7B,SAAS,cAAc,OAAwB;AACpD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,MAAM,OAAO,WAAW,KAAK,EAAE,OAAO;AAE7E,YAAU,MAAM;AACd,UAAM,WAAW,CAAC,MAA2B,WAAW,EAAE,OAAO;AACjE,UAAM,aAAa,OAAO,WAAW,KAAK;AAC1C,eAAW,WAAW,OAAO;AAC7B,eAAW,iBAAiB,UAAU,QAAQ;AAC9C,WAAO,MAAM,WAAW,oBAAoB,UAAU,QAAQ;AAAA,EAChE,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO;AACT;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"media-query.js","sourceRoot":"","sources":["src/media-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IAE/E,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,CAAC,CAAsB,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACnE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC5C,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC/B,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAClE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { useEffect, useState } from 'react';\n\nexport function useMediaQuery(query: string): boolean {\n const [matches, setMatches] = useState(() => window.matchMedia(query).matches);\n\n useEffect(() => {\n const listener = (e: MediaQueryListEvent) => setMatches(e.matches);\n const mediaQuery = window.matchMedia(query);\n setMatches(mediaQuery.matches);\n mediaQuery.addEventListener('change', listener);\n return () => mediaQuery.removeEventListener('change', listener);\n }, [query]);\n\n return matches;\n}\n"]}
package/model-info.d.ts CHANGED
@@ -20,4 +20,3 @@ export declare class ModelInfo {
20
20
  getProperties(paths: string[]): PropertyInfo[];
21
21
  }
22
22
  export declare function getDefaultProperties(modelInfo: ModelInfo): PropertyInfo[];
23
- //# sourceMappingURL=model-info.d.ts.map
package/model-info.js CHANGED
@@ -1,142 +1,141 @@
1
- import {
2
- BooleanModel,
3
- NumberModel,
4
- StringModel,
5
- _meta,
6
- createDetachedModel,
7
- EnumModel,
8
- ObjectModel
9
- } from "@vaadin/hilla-lit-form";
1
+ import { BooleanModel, NumberModel, StringModel, _meta, createDetachedModel, EnumModel, ObjectModel, } from '@vaadin/hilla-lit-form';
10
2
  const javaTypeMap = {
11
- byte: "integer",
12
- "java.lang.Byte": "integer",
13
- short: "integer",
14
- "java.lang.Short": "integer",
15
- int: "integer",
16
- "java.lang.Integer": "integer",
17
- long: "integer",
18
- "java.lang.Long": "integer",
19
- float: "decimal",
20
- "java.lang.Float": "decimal",
21
- double: "decimal",
22
- "java.lang.Double": "decimal",
23
- "java.time.LocalDate": "date",
24
- "java.time.LocalTime": "time",
25
- "java.time.OffsetTime": "time",
26
- "java.time.LocalDateTime": "datetime",
27
- "java.time.OffsetDateTime": "datetime",
28
- "java.time.ZonedDateTime": "datetime",
29
- "java.util.Date": "datetime",
30
- "java.sql.Date": "datetime"
3
+ byte: 'integer',
4
+ 'java.lang.Byte': 'integer',
5
+ short: 'integer',
6
+ 'java.lang.Short': 'integer',
7
+ int: 'integer',
8
+ 'java.lang.Integer': 'integer',
9
+ long: 'integer',
10
+ 'java.lang.Long': 'integer',
11
+ float: 'decimal',
12
+ 'java.lang.Float': 'decimal',
13
+ double: 'decimal',
14
+ 'java.lang.Double': 'decimal',
15
+ 'java.time.LocalDate': 'date',
16
+ 'java.time.LocalTime': 'time',
17
+ 'java.time.OffsetTime': 'time',
18
+ 'java.time.LocalDateTime': 'datetime',
19
+ 'java.time.OffsetDateTime': 'datetime',
20
+ 'java.time.ZonedDateTime': 'datetime',
21
+ 'java.util.Date': 'datetime',
22
+ 'java.sql.Date': 'datetime',
31
23
  };
32
24
  function determinePropertyType(model) {
33
- const { javaType } = model[_meta];
34
- const propertyType = javaType ? javaTypeMap[javaType] : void 0;
35
- if (propertyType) {
36
- return propertyType;
37
- }
38
- if (model instanceof StringModel) {
39
- return "string";
40
- } else if (model instanceof NumberModel) {
41
- return "decimal";
42
- } else if (model instanceof BooleanModel) {
43
- return "boolean";
44
- } else if (model instanceof EnumModel) {
45
- return "enum";
46
- } else if (model instanceof ObjectModel) {
47
- return "object";
48
- }
49
- return void 0;
25
+ const { javaType } = model[_meta];
26
+ const propertyType = javaType ? javaTypeMap[javaType] : undefined;
27
+ if (propertyType) {
28
+ return propertyType;
29
+ }
30
+ if (model instanceof StringModel) {
31
+ return 'string';
32
+ }
33
+ else if (model instanceof NumberModel) {
34
+ return 'decimal';
35
+ }
36
+ else if (model instanceof BooleanModel) {
37
+ return 'boolean';
38
+ }
39
+ else if (model instanceof EnumModel) {
40
+ return 'enum';
41
+ }
42
+ else if (model instanceof ObjectModel) {
43
+ return 'object';
44
+ }
45
+ return undefined;
50
46
  }
51
- function hasAnnotation(meta, annotationName) {
52
- return meta.annotations?.some((annotation) => annotation.name === annotationName) ?? false;
47
+ export function hasAnnotation(meta, annotationName) {
48
+ return meta.annotations?.some((annotation) => annotation.name === annotationName) ?? false;
53
49
  }
54
- function _generateHeader(path) {
55
- return path.substring(path.lastIndexOf(".") + 1).replace(/([A-Z])/gu, "-$1").toLowerCase().replace(/-/gu, " ").replace(/^./u, (match) => match.toUpperCase());
50
+ export function _generateHeader(path) {
51
+ return path
52
+ .substring(path.lastIndexOf('.') + 1)
53
+ .replace(/([A-Z])/gu, '-$1')
54
+ .toLowerCase()
55
+ .replace(/-/gu, ' ')
56
+ .replace(/^./u, (match) => match.toUpperCase());
56
57
  }
57
58
  const getPropertyNames = (model) => {
58
- const propertyNames = [];
59
- for (let proto = model; proto !== ObjectModel; proto = Object.getPrototypeOf(proto)) {
60
- propertyNames.unshift(...Object.keys(Object.getOwnPropertyDescriptors(proto.prototype)).filter((p) => p !== "new"));
61
- }
62
- return propertyNames;
59
+ const propertyNames = [];
60
+ for (let proto = model; proto !== ObjectModel; proto = Object.getPrototypeOf(proto)) {
61
+ propertyNames.unshift(...Object.keys(Object.getOwnPropertyDescriptors(proto.prototype)).filter((p) => p !== 'new'));
62
+ }
63
+ return propertyNames;
63
64
  };
64
- class ModelInfo {
65
- modelInstance;
66
- idProperty;
67
- constructor(model, idPropertyName) {
68
- this.modelInstance = createDetachedModel(model);
69
- this.idProperty = ModelInfo.resolveIdProperty(this, idPropertyName);
70
- }
71
- static resolveIdProperty(modelInfo, idPropertyName) {
72
- if (idPropertyName) {
73
- return modelInfo.getProperty(idPropertyName);
65
+ export class ModelInfo {
66
+ modelInstance;
67
+ idProperty;
68
+ constructor(model, idPropertyName) {
69
+ this.modelInstance = createDetachedModel(model);
70
+ this.idProperty = ModelInfo.resolveIdProperty(this, idPropertyName);
74
71
  }
75
- const rootProperties = modelInfo.getRootProperties();
76
- let idProperty = rootProperties.find((propertyInfo) => hasAnnotation(propertyInfo.meta, "jakarta.persistence.Id"));
77
- if (!idProperty) {
78
- idProperty = rootProperties.find((propertyInfo) => propertyInfo.name === "id");
72
+ static resolveIdProperty(modelInfo, idPropertyName) {
73
+ if (idPropertyName) {
74
+ return modelInfo.getProperty(idPropertyName);
75
+ }
76
+ const rootProperties = modelInfo.getRootProperties();
77
+ let idProperty = rootProperties.find((propertyInfo) => hasAnnotation(propertyInfo.meta, 'jakarta.persistence.Id'));
78
+ if (!idProperty) {
79
+ idProperty = rootProperties.find((propertyInfo) => propertyInfo.name === 'id');
80
+ }
81
+ return idProperty;
79
82
  }
80
- return idProperty;
81
- }
82
- static resolvePropertyModel(modelInstance, path) {
83
- const parts = path.split(".");
84
- let currentModel = modelInstance;
85
- for (const part of parts) {
86
- if (!currentModel || !(currentModel instanceof ObjectModel)) {
87
- return void 0;
88
- }
89
- currentModel = currentModel[part];
83
+ static resolvePropertyModel(modelInstance, path) {
84
+ const parts = path.split('.');
85
+ let currentModel = modelInstance;
86
+ for (const part of parts) {
87
+ if (!currentModel || !(currentModel instanceof ObjectModel)) {
88
+ return undefined;
89
+ }
90
+ currentModel = currentModel[part];
91
+ }
92
+ return currentModel;
90
93
  }
91
- return currentModel;
92
- }
93
- getRootProperties(path) {
94
- const model = path ? ModelInfo.resolvePropertyModel(this.modelInstance, path) : this.modelInstance;
95
- if (!model) {
96
- return [];
94
+ getRootProperties(path) {
95
+ const model = path ? ModelInfo.resolvePropertyModel(this.modelInstance, path) : this.modelInstance;
96
+ if (!model) {
97
+ return [];
98
+ }
99
+ return getPropertyNames(model.constructor)
100
+ .map((name) => {
101
+ const effectivePath = path ? `${path}.${name}` : name;
102
+ return this.getProperty(effectivePath);
103
+ })
104
+ .filter(Boolean);
97
105
  }
98
- return getPropertyNames(model.constructor).map((name) => {
99
- const effectivePath = path ? `${path}.${name}` : name;
100
- return this.getProperty(effectivePath);
101
- }).filter(Boolean);
102
- }
103
- getProperty(path) {
104
- const propertyModel = ModelInfo.resolvePropertyModel(this.modelInstance, path);
105
- if (!propertyModel?.[_meta]) {
106
- return void 0;
106
+ getProperty(path) {
107
+ const propertyModel = ModelInfo.resolvePropertyModel(this.modelInstance, path);
108
+ if (!propertyModel?.[_meta]) {
109
+ return undefined;
110
+ }
111
+ const pathParts = path.split('.');
112
+ const name = pathParts[pathParts.length - 1];
113
+ const meta = propertyModel[_meta];
114
+ const humanReadableName = _generateHeader(name);
115
+ const type = determinePropertyType(propertyModel);
116
+ return {
117
+ name: path,
118
+ humanReadableName,
119
+ type,
120
+ meta,
121
+ model: propertyModel,
122
+ };
107
123
  }
108
- const pathParts = path.split(".");
109
- const name = pathParts[pathParts.length - 1];
110
- const meta = propertyModel[_meta];
111
- const humanReadableName = _generateHeader(name);
112
- const type = determinePropertyType(propertyModel);
113
- return {
114
- name: path,
115
- humanReadableName,
116
- type,
117
- meta,
118
- model: propertyModel
119
- };
120
- }
121
- getProperties(paths) {
122
- return paths.map((path) => this.getProperty(path)).filter(Boolean);
123
- }
124
- }
125
- function getDefaultProperties(modelInfo) {
126
- const properties = modelInfo.getRootProperties();
127
- return properties.flatMap((prop) => {
128
- if (hasAnnotation(prop.meta, "jakarta.persistence.OneToOne")) {
129
- return modelInfo.getRootProperties(prop.name);
124
+ getProperties(paths) {
125
+ return paths.map((path) => this.getProperty(path)).filter(Boolean);
130
126
  }
131
- return prop;
132
- }).filter(
133
- (prop) => !!prop.type && !(hasAnnotation(prop.meta, "jakarta.persistence.Id") || hasAnnotation(prop.meta, "jakarta.persistence.Version"))
134
- );
135
127
  }
136
- export {
137
- ModelInfo,
138
- _generateHeader,
139
- getDefaultProperties,
140
- hasAnnotation
141
- };
142
- //# sourceMappingURL=model-info.js.map
128
+ export function getDefaultProperties(modelInfo) {
129
+ const properties = modelInfo.getRootProperties();
130
+ return (properties
131
+ .flatMap((prop) => {
132
+ if (hasAnnotation(prop.meta, 'jakarta.persistence.OneToOne')) {
133
+ return modelInfo.getRootProperties(prop.name);
134
+ }
135
+ return prop;
136
+ })
137
+ .filter((prop) => !!prop.type &&
138
+ !(hasAnnotation(prop.meta, 'jakarta.persistence.Id') ||
139
+ hasAnnotation(prop.meta, 'jakarta.persistence.Version'))));
140
+ }
141
+ //# sourceMappingURL=model-info.js.map