@vaadin/hilla-react-crud 24.7.0-alpha8 → 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.
- package/autocrud-dialog.d.ts +0 -1
- package/autocrud-dialog.js +9 -23
- package/autocrud-dialog.js.map +1 -7
- package/autocrud-feature.d.ts +0 -1
- package/autocrud-feature.js +5 -8
- package/autocrud-feature.js.map +1 -7
- package/autocrud.d.ts +2 -64
- package/autocrud.js +43 -92
- package/autocrud.js.map +1 -7
- package/autocrud.obj.js +1 -6
- package/autoform-feature.d.ts +0 -1
- package/autoform-feature.js +5 -8
- package/autoform-feature.js.map +1 -7
- package/autoform-field.d.ts +0 -90
- package/autoform-field.js +87 -95
- package/autoform-field.js.map +1 -7
- package/autoform.d.ts +0 -190
- package/autoform.js +126 -184
- package/autoform.js.map +1 -7
- package/autoform.obj.js +1 -6
- package/autogrid-column-context.d.ts +1 -2
- package/autogrid-column-context.js +4 -8
- package/autogrid-column-context.js.map +1 -7
- package/autogrid-columns.d.ts +0 -1
- package/autogrid-columns.js +83 -99
- package/autogrid-columns.js.map +1 -7
- package/autogrid-feature.d.ts +0 -1
- package/autogrid-feature.js +5 -8
- package/autogrid-feature.js.map +1 -7
- package/autogrid-renderers.d.ts +0 -1
- package/autogrid-renderers.js +71 -80
- package/autogrid-renderers.js.map +1 -7
- package/autogrid.d.ts +1 -103
- package/autogrid.js +176 -234
- package/autogrid.js.map +1 -7
- package/autogrid.obj.js +1 -6
- package/crud.d.ts +7 -10
- package/data-provider.d.ts +37 -6
- package/data-provider.js +186 -121
- package/data-provider.js.map +1 -7
- package/header-filter.d.ts +1 -30
- package/header-filter.js +137 -244
- package/header-filter.js.map +1 -7
- package/header-sorter.d.ts +0 -1
- package/header-sorter.js +16 -27
- package/header-sorter.js.map +1 -7
- package/i18n.d.ts +0 -1
- package/i18n.js +2 -5
- package/i18n.js.map +1 -7
- package/index.d.ts +1 -2
- package/index.js +12 -16
- package/index.js.map +1 -7
- package/locale.d.ts +0 -1
- package/locale.js +100 -107
- package/locale.js.map +1 -7
- package/media-query.d.ts +0 -1
- package/media-query.js +12 -15
- package/media-query.js.map +1 -7
- package/model-info.d.ts +0 -1
- package/model-info.js +126 -127
- package/model-info.js.map +1 -7
- package/package.json +9 -33
- package/types/com/vaadin/hilla/crud/filter/AndFilter.d.ts +3 -4
- package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js +6 -9
- package/types/com/vaadin/hilla/crud/filter/AndFilterModel.js.map +1 -7
- package/types/com/vaadin/hilla/crud/filter/Filter.d.ts +1 -2
- package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/FilterModel.js +3 -6
- package/types/com/vaadin/hilla/crud/filter/FilterModel.js.map +1 -7
- package/types/com/vaadin/hilla/crud/filter/FilterUnion.d.ts +4 -2
- package/types/com/vaadin/hilla/crud/filter/OrFilter.d.ts +3 -4
- package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js +6 -9
- package/types/com/vaadin/hilla/crud/filter/OrFilterModel.js.map +1 -7
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js +9 -12
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.js.map +1 -7
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js +4 -7
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.js.map +1 -7
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter.d.ts +4 -5
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js +12 -15
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.js.map +1 -7
- package/types/com/vaadin/hilla/mappedtypes/Order.d.ts +3 -4
- package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts +0 -1
- package/types/com/vaadin/hilla/mappedtypes/OrderModel.js +15 -18
- package/types/com/vaadin/hilla/mappedtypes/OrderModel.js.map +1 -7
- package/types/com/vaadin/hilla/mappedtypes/Pageable.d.ts +1 -2
- package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts +0 -1
- package/types/com/vaadin/hilla/mappedtypes/PageableModel.js +12 -15
- package/types/com/vaadin/hilla/mappedtypes/PageableModel.js.map +1 -7
- package/types/com/vaadin/hilla/mappedtypes/Sort.d.ts +1 -2
- package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts +0 -1
- package/types/com/vaadin/hilla/mappedtypes/SortModel.js +6 -9
- package/types/com/vaadin/hilla/mappedtypes/SortModel.js.map +1 -7
- package/types/org/springframework/data/domain/Sort/Direction.d.ts +0 -1
- package/types/org/springframework/data/domain/Sort/Direction.js +7 -10
- package/types/org/springframework/data/domain/Sort/Direction.js.map +1 -7
- package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts +0 -1
- package/types/org/springframework/data/domain/Sort/DirectionModel.js +4 -7
- package/types/org/springframework/data/domain/Sort/DirectionModel.js.map +1 -7
- package/types/org/springframework/data/domain/Sort/NullHandling.d.ts +0 -1
- package/types/org/springframework/data/domain/Sort/NullHandling.js +8 -11
- package/types/org/springframework/data/domain/Sort/NullHandling.js.map +1 -7
- package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts +0 -1
- package/types/org/springframework/data/domain/Sort/NullHandlingModel.js +4 -7
- package/types/org/springframework/data/domain/Sort/NullHandlingModel.js.map +1 -7
- package/types.d.ts +6 -9
- package/types.js +2 -0
- package/types.js.map +1 -0
- package/util.d.ts +1 -2
- package/util.js +42 -47
- package/util.js.map +1 -7
- package/autocrud-dialog.d.ts.map +0 -1
- package/autocrud-feature.d.ts.map +0 -1
- package/autocrud.d.ts.map +0 -1
- package/autocrud.obj.js.map +0 -7
- package/autoform-feature.d.ts.map +0 -1
- package/autoform-field.d.ts.map +0 -1
- package/autoform.d.ts.map +0 -1
- package/autoform.obj.js.map +0 -7
- package/autogrid-column-context.d.ts.map +0 -1
- package/autogrid-columns.d.ts.map +0 -1
- package/autogrid-feature.d.ts.map +0 -1
- package/autogrid-renderers.d.ts.map +0 -1
- package/autogrid.d.ts.map +0 -1
- package/autogrid.obj.js.map +0 -7
- package/data-provider.d.ts.map +0 -1
- package/header-filter.d.ts.map +0 -1
- package/header-sorter.d.ts.map +0 -1
- package/i18n.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/locale.d.ts.map +0 -1
- package/media-query.d.ts.map +0 -1
- package/model-info.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/AndFilterModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/FilterModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/OrFilterModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/Matcher.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilter/MatcherModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/crud/filter/PropertyStringFilterModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/mappedtypes/OrderModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/mappedtypes/PageableModel.d.ts.map +0 -1
- package/types/com/vaadin/hilla/mappedtypes/SortModel.d.ts.map +0 -1
- package/types/org/springframework/data/domain/Sort/Direction.d.ts.map +0 -1
- package/types/org/springframework/data/domain/Sort/DirectionModel.d.ts.map +0 -1
- package/types/org/springframework/data/domain/Sort/NullHandling.d.ts.map +0 -1
- package/types/org/springframework/data/domain/Sort/NullHandlingModel.d.ts.map +0 -1
- 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
|
|
2
|
-
import { DateTimePickerElement } from
|
|
3
|
-
import { createContext, useContext, useMemo } from
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
try {
|
|
18
|
+
return value ? formatter.format(new Date(value)) : '';
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
|
-
class LocaleFormatter {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}),
|
|
109
|
-
[datePickerI18n]
|
|
110
|
-
);
|
|
105
|
+
export function useDateTimePickerI18n() {
|
|
106
|
+
const datePickerI18n = useDatePickerI18n();
|
|
107
|
+
return useMemo(() => ({
|
|
108
|
+
...defaultDateTimePickerI18n,
|
|
109
|
+
...datePickerI18n,
|
|
110
|
+
}), [datePickerI18n]);
|
|
111
111
|
}
|
|
112
|
-
|
|
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;A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AAE,CAAC;YAC/G,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,UAAU,kBAAkB;IAChC,MAAM,MAAM,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,qBAAqB,GAAG,IAAI,iBAAiB,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
package/media-query.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { useEffect, useState } from
|
|
2
|
-
function useMediaQuery(query) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
14
|
-
useMediaQuery
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=media-query.js.map
|
|
13
|
+
//# sourceMappingURL=media-query.js.map
|
package/media-query.js.map
CHANGED
|
@@ -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
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
47
|
+
export function hasAnnotation(meta, annotationName) {
|
|
48
|
+
return meta.annotations?.some((annotation) => annotation.name === annotationName) ?? false;
|
|
53
49
|
}
|
|
54
|
-
function _generateHeader(path) {
|
|
55
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
109
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|