@povio/ui 2.2.12 → 2.3.0-rc.1
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/dist/components/buttons/InlineIconButton/InlineIconButton.d.ts +2 -1
- package/dist/components/buttons/InlineIconButton/InlineIconButton.js +2 -2
- package/dist/components/inputs/Checkbox/Checkbox.js +6 -1
- package/dist/components/inputs/Checkbox/checkbox.cva.d.ts +3 -0
- package/dist/components/inputs/Checkbox/checkbox.cva.js +2 -1
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +10 -5
- package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +89 -9
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +10 -5
- package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +95 -7
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +11 -5
- package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +95 -9
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +5 -3
- package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +77 -7
- package/dist/components/inputs/DateTime/shared/Calendar.d.ts +5 -2
- package/dist/components/inputs/DateTime/shared/Calendar.js +23 -6
- package/dist/components/inputs/DateTime/shared/CalendarCell.d.ts +1 -1
- package/dist/components/inputs/DateTime/shared/CalendarCell.js +3 -3
- package/dist/components/inputs/DateTime/shared/CalendarGrid.d.ts +1 -1
- package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +6 -3
- package/dist/components/inputs/DateTime/shared/DatePickerInput.js +78 -61
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.d.ts +14 -0
- package/dist/components/inputs/DateTime/shared/DateSegmentItem.js +19 -6
- package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +2 -1
- package/dist/components/inputs/DateTime/shared/TimePickerInput.js +11 -4
- package/dist/components/inputs/DateTime/shared/datePicker.types.d.ts +4 -0
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.d.ts +7 -0
- package/dist/components/inputs/DateTime/shared/datePickerInput.cva.js +13 -0
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.d.ts +6 -0
- package/dist/components/inputs/DateTime/shared/datePickerTodayIcon.js +21 -0
- package/dist/components/inputs/DateTime/shared/dateSegment.utils.d.ts +2 -0
- package/dist/components/inputs/DateTime/shared/dateSegment.utils.spec.d.ts +1 -0
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.d.ts +35 -0
- package/dist/components/inputs/DateTime/shared/staticDateTimeSegments.js +80 -0
- package/dist/components/inputs/File/FileUpload.js +1 -0
- package/dist/components/inputs/File/shared/InputUploadContent.js +1 -0
- package/dist/components/inputs/FormField/FormField.d.ts +3 -3
- package/dist/components/inputs/FormField/FormFieldHeader.d.ts +2 -2
- package/dist/components/inputs/FormField/FormFieldHeader.js +3 -1
- package/dist/components/inputs/FormField/FormFieldLabel.d.ts +2 -2
- package/dist/components/inputs/FormField/formFieldHeader.cva.d.ts +6 -0
- package/dist/components/inputs/FormField/formFieldHeader.cva.js +11 -0
- package/dist/components/inputs/Input/NumberInput/NumberInput.d.ts +5 -2
- package/dist/components/inputs/Input/NumberInput/NumberInput.js +81 -7
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeField.d.ts +45 -0
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeField.js +146 -0
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.d.ts +35 -0
- package/dist/components/inputs/Input/NumberRangeInput/NumberRangeInput.js +235 -0
- package/dist/components/inputs/Input/TextArea/TextArea.cva.d.ts +4 -0
- package/dist/components/inputs/Input/TextArea/TextArea.cva.js +5 -0
- package/dist/components/inputs/Input/TextArea/TextArea.js +3 -1
- package/dist/components/inputs/Input/TextInput/TextInput.d.ts +3 -1
- package/dist/components/inputs/Input/TextInput/TextInput.js +82 -7
- package/dist/components/inputs/Input/shared/InputContent.js +7 -6
- package/dist/components/inputs/Input/shared/numberStatic.utils.d.ts +1 -0
- package/dist/components/inputs/Input/shared/numberStatic.utils.js +7 -0
- package/dist/components/inputs/Inputs/InputItem.d.ts +16 -21
- package/dist/components/inputs/Inputs/InputItem.js +6 -0
- package/dist/components/inputs/RadioGroup/RadioGroup.d.ts +2 -1
- package/dist/components/inputs/RadioGroup/RadioGroup.js +106 -25
- package/dist/components/inputs/RadioGroup/radio.cva.d.ts +17 -0
- package/dist/components/inputs/RadioGroup/radio.cva.js +42 -1
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +6 -2
- package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +102 -7
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +3 -18
- package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +33 -8
- package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +36 -0
- package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +14 -0
- package/dist/components/inputs/Selection/Select/QuerySelect.js +42 -0
- package/dist/components/inputs/Selection/Select/Select.d.ts +7 -3
- package/dist/components/inputs/Selection/Select/Select.js +115 -5
- package/dist/components/inputs/Selection/shared/SelectBase.d.ts +8 -1
- package/dist/components/inputs/Selection/shared/SelectBase.js +4 -2
- package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectDesktop.js +11 -3
- package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectInput.js +27 -4
- package/dist/components/inputs/Selection/shared/SelectListBox.d.ts +2 -2
- package/dist/components/inputs/Selection/shared/SelectListBox.js +3 -3
- package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
- package/dist/components/inputs/Selection/shared/SelectMobile.js +9 -3
- package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +6 -0
- package/dist/components/inputs/Selection/shared/querySelect.utils.js +13 -0
- package/dist/components/inputs/Selection/shared/select.context.d.ts +3 -2
- package/dist/components/inputs/Selection/shared/select.context.js +27 -4
- package/dist/components/inputs/Selection/shared/select.types.d.ts +3 -2
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.d.ts +3 -0
- package/dist/components/inputs/Selection/shared/selectDesktop.cva.js +5 -0
- package/dist/components/inputs/Selection/shared/staticSelect.utils.d.ts +23 -0
- package/dist/components/inputs/Selection/shared/staticSelect.utils.js +37 -0
- package/dist/components/inputs/Selection/shared/staticSelect.utils.spec.d.ts +1 -0
- package/dist/components/inputs/Skeleton/InputFrame.d.ts +77 -0
- package/dist/components/inputs/Skeleton/InputFrame.js +200 -0
- package/dist/components/inputs/TextEditor/TextEditor.d.ts +1 -0
- package/dist/components/inputs/TextEditor/TextEditor.js +8 -3
- package/dist/components/inputs/Toggle/Toggle.js +6 -1
- package/dist/components/inputs/Toggle/toggle.cva.d.ts +3 -0
- package/dist/components/inputs/Toggle/toggle.cva.js +2 -1
- package/dist/components/inputs/shared/CheckContent.d.ts +2 -1
- package/dist/components/inputs/shared/CheckContent.js +3 -4
- package/dist/components/inputs/shared/InputClear.d.ts +2 -1
- package/dist/components/inputs/shared/InputClear.js +13 -1
- package/dist/components/inputs/shared/StaticInput.d.ts +38 -0
- package/dist/components/inputs/shared/TooltipWrapper.js +5 -1
- package/dist/components/inputs/shared/input.cva.d.ts +10 -0
- package/dist/components/inputs/shared/input.cva.js +19 -1
- package/dist/components/inputs/shared/tooltipWrapper.cva.d.ts +4 -0
- package/dist/components/inputs/shared/tooltipWrapper.cva.js +5 -0
- package/dist/components/inputs/shared/useStaticInputHandoff.d.ts +13 -0
- package/dist/components/inputs/shared/useStaticInputHandoff.js +47 -0
- package/dist/config/router.context.d.ts +3 -4
- package/dist/config/router.context.js +1 -3
- package/dist/config/uiConfig.context.d.ts +15 -3
- package/dist/config/uiConfig.context.js +16 -3
- package/dist/config/uiStyle.context.d.ts +27 -4
- package/dist/helpers/dynamicInputs.d.ts +5 -5
- package/dist/helpers/dynamicInputs.js +3 -0
- package/dist/hooks/useFilters.js +27 -23
- package/dist/hooks/useIntersectionObserver.d.ts +1 -1
- package/dist/hooks/useIntersectionObserver.js +27 -14
- package/dist/hooks/usePagination.js +8 -4
- package/dist/hooks/useQueryAutocomplete.d.ts +14 -0
- package/dist/hooks/useQueryAutocomplete.js +56 -0
- package/dist/hooks/useSorting.js +7 -4
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -3
- package/dist/tw-ui-plugin.js +2 -0
- package/dist/utils/date-time.utils.d.ts +31 -10
- package/dist/utils/date-time.utils.js +123 -22
- package/dist/utils/query.utils.d.ts +4 -0
- package/dist/utils/query.utils.js +8 -0
- package/dist/utils/routing.utils.d.ts +1 -0
- package/dist/utils/routing.utils.js +14 -0
- package/package.json +2 -2
package/dist/hooks/useFilters.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UIRouter } from "../config/router.context.js";
|
|
2
|
+
import { RoutingUtils } from "../utils/routing.utils.js";
|
|
2
3
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
//#region src/hooks/useFilters.ts
|
|
@@ -18,43 +19,47 @@ var serializeFiltersToQuery = (filterData, prefix) => {
|
|
|
18
19
|
for (const [key, value] of Object.entries(filterData)) {
|
|
19
20
|
if (value === null || value === void 0) continue;
|
|
20
21
|
const filterKey = `filter[${prefix && `${prefix}-`}${key}]`;
|
|
21
|
-
|
|
22
|
-
else if (typeof value === "boolean") query[filterKey] = value ? "true" : "false";
|
|
23
|
-
else query[filterKey] = value.toString();
|
|
22
|
+
query[filterKey] = value;
|
|
24
23
|
}
|
|
25
24
|
return query;
|
|
26
25
|
};
|
|
26
|
+
function normalizeBooleanQueryValue(value) {
|
|
27
|
+
if (value === "\"true\"") return "true";
|
|
28
|
+
if (value === "\"false\"") return "false";
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
27
31
|
var parseFilterFromQuery = (searchParams, schema) => {
|
|
28
32
|
const filter = {};
|
|
29
33
|
for (const [key, value] of searchParams.entries()) {
|
|
34
|
+
const normalizedValue = normalizeBooleanQueryValue(value);
|
|
30
35
|
const match = /^filter\[(.+?)\]$/.exec(key);
|
|
31
36
|
if (!match) continue;
|
|
32
37
|
const filterKey = match[1];
|
|
33
|
-
const isArray =
|
|
34
|
-
const isObject =
|
|
35
|
-
const isNumber = !Number.isNaN(Number(
|
|
36
|
-
const isBoolean = ["true", "false"].includes(
|
|
37
|
-
if (isArray || isObject || isNumber) filter[filterKey] = JSON.parse(
|
|
38
|
-
else if (isBoolean) filter[filterKey] =
|
|
38
|
+
const isArray = normalizedValue.startsWith("[") && normalizedValue.endsWith("]");
|
|
39
|
+
const isObject = normalizedValue.startsWith("{") && normalizedValue.endsWith("}");
|
|
40
|
+
const isNumber = !Number.isNaN(Number(normalizedValue)) && normalizedValue !== "";
|
|
41
|
+
const isBoolean = ["true", "false"].includes(normalizedValue);
|
|
42
|
+
if (isArray || isObject || isNumber) filter[filterKey] = JSON.parse(normalizedValue);
|
|
43
|
+
else if (isBoolean) filter[filterKey] = normalizedValue === "true";
|
|
39
44
|
else {
|
|
40
45
|
const expectedType = getFieldType(schema, filterKey);
|
|
41
|
-
if (expectedType === "number" && !Number.isNaN(Number(
|
|
42
|
-
else if (expectedType === "boolean" && ["true", "false"].includes(
|
|
43
|
-
else filter[filterKey] =
|
|
46
|
+
if (expectedType === "number" && !Number.isNaN(Number(normalizedValue)) && normalizedValue !== "" && normalizedValue !== null) filter[filterKey] = Number(normalizedValue);
|
|
47
|
+
else if (expectedType === "boolean" && ["true", "false"].includes(normalizedValue)) filter[filterKey] = normalizedValue === "true";
|
|
48
|
+
else filter[filterKey] = normalizedValue;
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
return filter;
|
|
47
52
|
};
|
|
48
53
|
var useFilters = (defaultFilterValues, prefix = "", schema) => {
|
|
49
|
-
const { searchParams,
|
|
54
|
+
const { searchParams, replace } = UIRouter.useUIRouter();
|
|
50
55
|
const [filterData, setFilterData] = useState(() => parseFilterFromQuery(searchParams, schema));
|
|
51
56
|
useEffect(() => {
|
|
52
57
|
const setUrlToDefaultFilters = () => {
|
|
53
58
|
const flatFilterQuery = serializeFiltersToQuery(defaultFilterValues, prefix);
|
|
54
|
-
replace(
|
|
55
|
-
...
|
|
59
|
+
replace(".", {
|
|
60
|
+
...RoutingUtils.toRouterSearch(searchParams),
|
|
56
61
|
...flatFilterQuery
|
|
57
|
-
})
|
|
62
|
+
});
|
|
58
63
|
};
|
|
59
64
|
const currentFilters = parseFilterFromQuery(searchParams, schema);
|
|
60
65
|
const hasFiltersSet = Object.keys(currentFilters).length > 0;
|
|
@@ -77,20 +82,19 @@ var useFilters = (defaultFilterValues, prefix = "", schema) => {
|
|
|
77
82
|
else newFilters[key] = value;
|
|
78
83
|
});
|
|
79
84
|
const prefixPart = prefix ? `${prefix}-` : "";
|
|
80
|
-
const cleanedQuery =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
85
|
+
const cleanedQuery = RoutingUtils.toRouterSearch(searchParams);
|
|
86
|
+
Object.keys(cleanedQuery).forEach((key) => {
|
|
87
|
+
if (key.startsWith(`filter[${prefixPart}`)) delete cleanedQuery[key];
|
|
88
|
+
});
|
|
84
89
|
const flatFilterQuery = serializeFiltersToQuery(newFilters, prefix);
|
|
85
|
-
replace(
|
|
90
|
+
replace(".", {
|
|
86
91
|
...cleanedQuery,
|
|
87
92
|
...flatFilterQuery
|
|
88
|
-
})
|
|
93
|
+
});
|
|
89
94
|
setFilterData(newFilters);
|
|
90
95
|
}, [
|
|
91
96
|
filterData,
|
|
92
97
|
prefix,
|
|
93
|
-
pathname,
|
|
94
98
|
replace,
|
|
95
99
|
defaultFilterValues,
|
|
96
100
|
searchParams
|
|
@@ -3,6 +3,6 @@ type UseIntersectionObserverProps = {
|
|
|
3
3
|
onIntersectionChange?: (entry: IntersectionObserverEntry) => void;
|
|
4
4
|
} & IntersectionObserverInit;
|
|
5
5
|
export declare const useIntersectionObserver: <T extends HTMLElement>({ onIntersection, onIntersectionChange, root, rootMargin, threshold, }: UseIntersectionObserverProps) => {
|
|
6
|
-
ref: (
|
|
6
|
+
ref: (element: T | null) => void;
|
|
7
7
|
};
|
|
8
8
|
export {};
|
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
import { useCallback, useEffect,
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
//#region src/hooks/useIntersectionObserver.ts
|
|
3
3
|
var useIntersectionObserver = ({ onIntersection, onIntersectionChange, root, rootMargin, threshold }) => {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const elementRef = useRef(null);
|
|
5
|
+
const observerRef = useRef(null);
|
|
6
|
+
const onIntersectionRef = useRef(onIntersection);
|
|
7
|
+
const onIntersectionChangeRef = useRef(onIntersectionChange);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
onIntersectionRef.current = onIntersection;
|
|
10
|
+
}, [onIntersection]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
onIntersectionChangeRef.current = onIntersectionChange;
|
|
13
|
+
}, [onIntersectionChange]);
|
|
8
14
|
useEffect(() => {
|
|
9
|
-
if (!element) return;
|
|
10
15
|
const observer = new IntersectionObserver((entries) => {
|
|
11
|
-
if (entries.some((entry) => entry.isIntersecting))
|
|
12
|
-
|
|
16
|
+
if (entries.some((entry) => entry.isIntersecting)) onIntersectionRef.current?.();
|
|
17
|
+
onIntersectionChangeRef.current?.(entries[0]);
|
|
13
18
|
}, {
|
|
14
19
|
root,
|
|
15
20
|
rootMargin,
|
|
16
21
|
threshold
|
|
17
22
|
});
|
|
18
|
-
observer
|
|
19
|
-
|
|
23
|
+
observerRef.current = observer;
|
|
24
|
+
if (elementRef.current) observer.observe(elementRef.current);
|
|
25
|
+
return () => {
|
|
26
|
+
if (elementRef.current) observer.unobserve(elementRef.current);
|
|
27
|
+
observer.disconnect();
|
|
28
|
+
observerRef.current = null;
|
|
29
|
+
};
|
|
20
30
|
}, [
|
|
21
|
-
element,
|
|
22
31
|
root,
|
|
23
|
-
onIntersection,
|
|
24
|
-
onIntersectionChange,
|
|
25
32
|
rootMargin,
|
|
26
33
|
threshold
|
|
27
34
|
]);
|
|
28
|
-
|
|
35
|
+
const ref = useCallback((element) => {
|
|
36
|
+
if (elementRef.current === element) return;
|
|
37
|
+
if (observerRef.current && elementRef.current) observerRef.current.unobserve(elementRef.current);
|
|
38
|
+
elementRef.current = element;
|
|
39
|
+
if (observerRef.current && elementRef.current) observerRef.current.observe(elementRef.current);
|
|
40
|
+
}, []);
|
|
41
|
+
return useMemo(() => ({ ref }), [ref]);
|
|
29
42
|
};
|
|
30
43
|
//#endregion
|
|
31
44
|
export { useIntersectionObserver };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UIRouter } from "../config/router.context.js";
|
|
2
|
+
import { RoutingUtils } from "../utils/routing.utils.js";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
4
|
//#region src/hooks/usePagination.ts
|
|
4
5
|
var DEFAULT_STATE = {
|
|
@@ -6,16 +7,19 @@ var DEFAULT_STATE = {
|
|
|
6
7
|
pageSize: 20
|
|
7
8
|
};
|
|
8
9
|
function usePagination(defaultPagination) {
|
|
9
|
-
const {
|
|
10
|
+
const { replace, searchParams } = UIRouter.useUIRouter();
|
|
10
11
|
const [pagination, setPagination] = useState(defaultPagination ?? {
|
|
11
12
|
pageIndex: searchParams.has("page") ? Number.parseInt(searchParams.get("page") ?? "", 10) : DEFAULT_STATE.pageIndex,
|
|
12
13
|
pageSize: searchParams.has("size") ? Number.parseInt(searchParams.get("size") ?? "", 10) : DEFAULT_STATE.pageSize
|
|
13
14
|
});
|
|
14
15
|
useEffect(() => {
|
|
15
16
|
const params = new URLSearchParams(searchParams);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
params.delete("size");
|
|
18
|
+
params.delete("page");
|
|
19
|
+
if (pagination.pageSize !== DEFAULT_STATE.pageSize) params.set("size", pagination.pageSize.toString());
|
|
20
|
+
if (pagination.pageIndex !== DEFAULT_STATE.pageIndex) params.set("page", pagination.pageIndex.toString());
|
|
21
|
+
if (params.toString() === searchParams.toString()) return;
|
|
22
|
+
replace(".", RoutingUtils.toRouterSearch(params));
|
|
19
23
|
}, [pagination]);
|
|
20
24
|
return {
|
|
21
25
|
pagination,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InfiniteData } from '@tanstack/react-query';
|
|
2
|
+
import { Key } from 'react-aria-components';
|
|
3
|
+
import { InfiniteQueryPage, QueryFn, UseQueryAutocompleteOptions } from '../components/inputs/Selection/Autocomplete/queryAutocomplete.types';
|
|
4
|
+
export declare const useQueryAutocomplete: <TQueryFn extends QueryFn, TKey extends Key = Key>({ query, queryParams, queryOptions, mapItems, initialQueryState, search, }: UseQueryAutocompleteOptions<TQueryFn, TKey>) => {
|
|
5
|
+
data: any;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
isQueryEnabled: boolean;
|
|
8
|
+
handleEnableQuery: () => void;
|
|
9
|
+
items: import('..').SelectItem<TKey>[];
|
|
10
|
+
totalItems: number | undefined;
|
|
11
|
+
hasNextPage: boolean;
|
|
12
|
+
fetchNextPage: ((options?: import('@tanstack/react-query').FetchNextPageOptions) => Promise<import('@tanstack/react-query').InfiniteQueryObserverResult<InfiniteData<InfiniteQueryPage<TKey>, unknown>, Error>>) | undefined;
|
|
13
|
+
isFetchingNextPage: boolean;
|
|
14
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ApiQueryUtils } from "../utils/query.utils.js";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
//#region src/hooks/useQueryAutocomplete.ts
|
|
4
|
+
var isFilterSearchParams = (params) => {
|
|
5
|
+
return typeof params === "object" && params !== null && "filter" in params;
|
|
6
|
+
};
|
|
7
|
+
var useQueryAutocomplete = ({ query, queryParams, queryOptions, mapItems, initialQueryState, search }) => {
|
|
8
|
+
const [isQueryEnabled, setIsQueryEnabled] = useState(!initialQueryState);
|
|
9
|
+
const queryResult = query(search === void 0 ? queryParams : {
|
|
10
|
+
...queryParams,
|
|
11
|
+
limit: queryParams?.limit ?? ApiQueryUtils.DEFAULT_LIMIT,
|
|
12
|
+
search,
|
|
13
|
+
filter: {
|
|
14
|
+
...isFilterSearchParams(queryParams) ? queryParams.filter : {},
|
|
15
|
+
search
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
...queryOptions,
|
|
19
|
+
enabled: isQueryEnabled && (queryOptions?.enabled ?? true)
|
|
20
|
+
});
|
|
21
|
+
const data = queryResult.data;
|
|
22
|
+
const isLoading = queryResult.isLoading;
|
|
23
|
+
const isInfiniteQueryResult = (result) => {
|
|
24
|
+
return "hasNextPage" in result && "fetchNextPage" in result;
|
|
25
|
+
};
|
|
26
|
+
const handleEnableQuery = () => {
|
|
27
|
+
setIsQueryEnabled(true);
|
|
28
|
+
};
|
|
29
|
+
const infiniteQueryResult = isInfiniteQueryResult(queryResult) ? queryResult : void 0;
|
|
30
|
+
const isInfiniteQuery = infiniteQueryResult !== void 0;
|
|
31
|
+
const hasNextPage = infiniteQueryResult?.hasNextPage ?? false;
|
|
32
|
+
const fetchNextPage = infiniteQueryResult?.fetchNextPage;
|
|
33
|
+
const isFetchingNextPage = infiniteQueryResult?.isFetchingNextPage ?? false;
|
|
34
|
+
const totalItems = infiniteQueryResult?.data?.pages?.[0]?.totalItems;
|
|
35
|
+
const items = useMemo(() => {
|
|
36
|
+
if (!data) return [];
|
|
37
|
+
return mapItems(isInfiniteQuery ? data.pages?.flatMap((page) => page?.items ?? []) : data);
|
|
38
|
+
}, [
|
|
39
|
+
data,
|
|
40
|
+
isInfiniteQuery,
|
|
41
|
+
mapItems
|
|
42
|
+
]);
|
|
43
|
+
return {
|
|
44
|
+
data,
|
|
45
|
+
isLoading: isLoading || isFetchingNextPage,
|
|
46
|
+
isQueryEnabled,
|
|
47
|
+
handleEnableQuery,
|
|
48
|
+
items,
|
|
49
|
+
totalItems,
|
|
50
|
+
hasNextPage,
|
|
51
|
+
fetchNextPage,
|
|
52
|
+
isFetchingNextPage
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { useQueryAutocomplete };
|
package/dist/hooks/useSorting.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UIRouter } from "../config/router.context.js";
|
|
2
|
+
import { RoutingUtils } from "../utils/routing.utils.js";
|
|
2
3
|
import { useEffect, useMemo, useState } from "react";
|
|
3
4
|
//#region src/hooks/useSorting.ts
|
|
4
5
|
function useSorting(defaultSorting, prefix = "") {
|
|
5
|
-
const {
|
|
6
|
+
const { replace, searchParams } = UIRouter.useUIRouter();
|
|
6
7
|
const [sorting, setSorting] = useState(defaultSorting ?? searchParams.get(`order${prefix && `-${prefix}`}`)?.split(",").map((item) => {
|
|
7
8
|
if (item.startsWith("-")) return {
|
|
8
9
|
id: item.slice(1),
|
|
@@ -22,9 +23,11 @@ function useSorting(defaultSorting, prefix = "") {
|
|
|
22
23
|
}, [sorting]);
|
|
23
24
|
useEffect(() => {
|
|
24
25
|
const params = new URLSearchParams(searchParams);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const orderKey = prefix ? `order-${prefix}` : "order";
|
|
27
|
+
params.delete(orderKey);
|
|
28
|
+
if (order) params.set(orderKey, order);
|
|
29
|
+
if (params.toString() === searchParams.toString()) return;
|
|
30
|
+
replace(".", RoutingUtils.toRouterSearch(params));
|
|
28
31
|
}, [order]);
|
|
29
32
|
return {
|
|
30
33
|
sorting,
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,8 @@ export type { FormFieldProps } from './components/inputs/FormField/FormField';
|
|
|
78
78
|
export { FormField } from './components/inputs/FormField/FormField';
|
|
79
79
|
export type { ControlledNumberInputProps, NumberInputProps } from './components/inputs/Input/NumberInput/NumberInput';
|
|
80
80
|
export { NumberInput } from './components/inputs/Input/NumberInput/NumberInput';
|
|
81
|
+
export type { ControlledNumberRangeInputProps, NumberRangeInputProps, NumberRangeValue, } from './components/inputs/Input/NumberRangeInput/NumberRangeInput';
|
|
82
|
+
export { NumberRangeInput } from './components/inputs/Input/NumberRangeInput/NumberRangeInput';
|
|
81
83
|
export type { ControlledPasswordInputProps, PasswordInputProps, } from './components/inputs/Input/PasswordInput/PasswordInput';
|
|
82
84
|
export { PasswordInput } from './components/inputs/Input/PasswordInput/PasswordInput';
|
|
83
85
|
export type { ControlledTextAreaProps, TextAreaProps } from './components/inputs/Input/TextArea/TextArea';
|
|
@@ -94,11 +96,16 @@ export type { RadioVariantProps } from './components/inputs/RadioGroup/radio.cva
|
|
|
94
96
|
export type { AutocompleteProps, ControlledAutocompleteProps, } from './components/inputs/Selection/Autocomplete/Autocomplete';
|
|
95
97
|
export { Autocomplete } from './components/inputs/Selection/Autocomplete/Autocomplete';
|
|
96
98
|
export { QueryAutocomplete } from './components/inputs/Selection/Autocomplete/QueryAutocomplete';
|
|
99
|
+
export type { SelectBaseProps } from './components/inputs/Selection/shared/SelectBase';
|
|
100
|
+
export type { DefaultInitialSelectItem, SelectAsyncProps, SelectItem, } from './components/inputs/Selection/shared/select.types';
|
|
101
|
+
export type { QuerySelectProps } from './components/inputs/Selection/Select/QuerySelect';
|
|
102
|
+
export { QuerySelect } from './components/inputs/Selection/Select/QuerySelect';
|
|
97
103
|
export type { ControlledSelectProps, SelectProps } from './components/inputs/Selection/Select/Select';
|
|
98
104
|
export { Select } from './components/inputs/Selection/Select/Select';
|
|
99
105
|
export type { ControlledSliderProps, SliderProps } from './components/inputs/Slider/Slider';
|
|
100
106
|
export { Slider } from './components/inputs/Slider/Slider';
|
|
101
107
|
export type { InputVariantProps } from './components/inputs/shared/input.cva';
|
|
108
|
+
export type { TooltipWrapperTriggerVariantProps } from './components/inputs/shared/tooltipWrapper.cva';
|
|
102
109
|
export type { ControlledToggleProps, ToggleProps } from './components/inputs/Toggle/Toggle';
|
|
103
110
|
export { Toggle } from './components/inputs/Toggle/Toggle';
|
|
104
111
|
export type { MenuProps } from './components/Menu/Menu';
|
package/dist/index.js
CHANGED
|
@@ -85,6 +85,7 @@ import { FileUpload } from "./components/inputs/File/FileUpload.js";
|
|
|
85
85
|
import { FileUploadContainer } from "./components/inputs/File/FileUploadContainer.js";
|
|
86
86
|
import { InputUpload } from "./components/inputs/File/InputUpload.js";
|
|
87
87
|
import { NumberInput } from "./components/inputs/Input/NumberInput/NumberInput.js";
|
|
88
|
+
import { NumberRangeInput } from "./components/inputs/Input/NumberRangeInput/NumberRangeInput.js";
|
|
88
89
|
import { PasswordInput } from "./components/inputs/Input/PasswordInput/PasswordInput.js";
|
|
89
90
|
import { TextArea } from "./components/inputs/Input/TextArea/TextArea.js";
|
|
90
91
|
import { Autocomplete } from "./components/inputs/Selection/Autocomplete/Autocomplete.js";
|
|
@@ -92,6 +93,8 @@ import { QueryAutocomplete } from "./components/inputs/Selection/Autocomplete/Qu
|
|
|
92
93
|
import { Slider } from "./components/inputs/Slider/Slider.js";
|
|
93
94
|
import { Toggle } from "./components/inputs/Toggle/Toggle.js";
|
|
94
95
|
import { Segment } from "./components/segment/Segment.js";
|
|
96
|
+
import { QuerySelect } from "./components/inputs/Selection/Select/QuerySelect.js";
|
|
97
|
+
import { ResponsivePopover } from "./components/overlays/ResponsivePopover/ResponsivePopover.js";
|
|
95
98
|
import { StringUtils } from "./utils/string.utils.js";
|
|
96
99
|
import { dynamicInputs } from "./helpers/dynamicInputs.js";
|
|
97
100
|
import { Form } from "./components/inputs/Inputs/Form.js";
|
|
@@ -102,7 +105,6 @@ import { Stepper } from "./components/navigation/Stepper/Stepper.js";
|
|
|
102
105
|
import { Modal } from "./components/overlays/Modal/Modal.js";
|
|
103
106
|
import { ActionModal } from "./components/overlays/ActionModal/ActionModal.js";
|
|
104
107
|
import { Drawer } from "./components/overlays/Drawer/Drawer.js";
|
|
105
|
-
import { ResponsivePopover } from "./components/overlays/ResponsivePopover/ResponsivePopover.js";
|
|
106
108
|
import { TooltipEllipsis } from "./components/overlays/Tooltip/TooltipEllipsis.js";
|
|
107
109
|
import { PaginationList } from "./components/shared/pagination/PaginationList.js";
|
|
108
110
|
import { Pagination } from "./components/shared/pagination/Pagination.js";
|
|
@@ -126,6 +128,7 @@ import { ThemeContext } from "./config/theme.context.js";
|
|
|
126
128
|
import { DateUtils } from "./utils/date.utils.js";
|
|
127
129
|
import { dynamicColumns } from "./helpers/dynamicColumns.js";
|
|
128
130
|
import { useAutosave } from "./hooks/useAutosave.js";
|
|
131
|
+
import { RoutingUtils } from "./utils/routing.utils.js";
|
|
129
132
|
import { useFilters } from "./hooks/useFilters.js";
|
|
130
133
|
import { useForm } from "./hooks/useForm.js";
|
|
131
134
|
import { useFormAutosave } from "./hooks/useFormAutosave.js";
|
|
@@ -134,5 +137,4 @@ import { useSorting } from "./hooks/useSorting.js";
|
|
|
134
137
|
import { useTableColumnConfig } from "./hooks/useTableColumnConfig.js";
|
|
135
138
|
import { ArrayUtils } from "./utils/array.utils.js";
|
|
136
139
|
import { QueriesUtils } from "./utils/queries.utils.js";
|
|
137
|
-
|
|
138
|
-
export { Accordion, ActionModal, Alert, AlignCenterIcon, AlignLeftIcon, AlignLeftRightIcon, AlignRightIcon, ArrayUtils, ArrowDropDownIcon, ArrowDropUpIcon, ArrowLeftIcon, ArrowRightIcon, Autocomplete, BoldIcon, BottomSheet, Breadcrumbs, BulletedListIcon, Button, CalendarIcon, CellText, CheckIcon, Checkbox, CheckboxCheckmarkIcon, CheckboxIndeterminateIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ClockIcon, CloseIcon, ColumnConfigModal, Confirmation, DatePicker, DateRangePicker, DateTimeIcon, DateTimePicker, DateTimeUtils, DateUtils, DomUtils, Drawer, FileUpload, FileUploadContainer, FileUtils, Form, FormField, HeaderText, HighlightIcon, HighlightOnIcon, HomeIcon, IconButton, InfiniteTable, InfoIcon, InlineIconButton, InputUpload, Inputs, ItalicIcon, Link, LinkContext, LinkIcon, Loader, Menu, MenuIcon, MenuItem, MenuPopover, Modal, NumberInput, NumberedListIcon, ObjectUtils, PaginatedTable, Pagination, PaginationList, PasswordInput, PillButton, PointerHorizontalIcon, PointerVerticalIcon, ProgressBar, QueriesUtils, QueryAutocomplete, RadioGroup, ResponsivePopover, RestUtils, RoutingUtils, Segment, Select, SendIcon, Slider, SplitButton, Stepper, StrikethroughIcon, StringUtils, Table, Tag, TextArea, TextButton, TextColorIcon, TextInput, ThemeContext, TimePicker, Toast, ToastContainer, Toggle, ToggleButton, Tooltip, TooltipEllipsis, Typography, UIConfig, UIRouter, UIStyle, UnderlinedIcon, VisibilityIcon, VisibilityOffIcon, compoundMapper, dynamicColumns, dynamicInputs, isEqual, logger, ns, resources, uiOutlineClass, useAutosave, useBreakpoint, useDebounceCallback, useDeepCompareEffect, useDeepCompareLayoutEffect, useDeepCompareMemo, useFilters, useForm, useFormAutosave, useIntersectionObserver, useLocalStorage, useLongPressRepeat, usePagination, useScrollableListBox, useSorting, useStateAndRef, useTableColumnConfig, useTableNav, useToast, useTranslationMemo };
|
|
140
|
+
export { Accordion, ActionModal, Alert, AlignCenterIcon, AlignLeftIcon, AlignLeftRightIcon, AlignRightIcon, ArrayUtils, ArrowDropDownIcon, ArrowDropUpIcon, ArrowLeftIcon, ArrowRightIcon, Autocomplete, BoldIcon, BottomSheet, Breadcrumbs, BulletedListIcon, Button, CalendarIcon, CellText, CheckIcon, Checkbox, CheckboxCheckmarkIcon, CheckboxIndeterminateIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ClockIcon, CloseIcon, ColumnConfigModal, Confirmation, DatePicker, DateRangePicker, DateTimeIcon, DateTimePicker, DateTimeUtils, DateUtils, DomUtils, Drawer, FileUpload, FileUploadContainer, FileUtils, Form, FormField, HeaderText, HighlightIcon, HighlightOnIcon, HomeIcon, IconButton, InfiniteTable, InfoIcon, InlineIconButton, InputUpload, Inputs, ItalicIcon, Link, LinkContext, LinkIcon, Loader, Menu, MenuIcon, MenuItem, MenuPopover, Modal, NumberInput, NumberRangeInput, NumberedListIcon, ObjectUtils, PaginatedTable, Pagination, PaginationList, PasswordInput, PillButton, PointerHorizontalIcon, PointerVerticalIcon, ProgressBar, QueriesUtils, QueryAutocomplete, QuerySelect, RadioGroup, ResponsivePopover, RestUtils, RoutingUtils, Segment, Select, SendIcon, Slider, SplitButton, Stepper, StrikethroughIcon, StringUtils, Table, Tag, TextArea, TextButton, TextColorIcon, TextInput, ThemeContext, TimePicker, Toast, ToastContainer, Toggle, ToggleButton, Tooltip, TooltipEllipsis, Typography, UIConfig, UIRouter, UIStyle, UnderlinedIcon, VisibilityIcon, VisibilityOffIcon, compoundMapper, dynamicColumns, dynamicInputs, isEqual, logger, ns, resources, uiOutlineClass, useAutosave, useBreakpoint, useDebounceCallback, useDeepCompareEffect, useDeepCompareLayoutEffect, useDeepCompareMemo, useFilters, useForm, useFormAutosave, useIntersectionObserver, useLocalStorage, useLongPressRepeat, usePagination, useScrollableListBox, useSorting, useStateAndRef, useTableColumnConfig, useTableNav, useToast, useTranslationMemo };
|
package/dist/tw-ui-plugin.js
CHANGED
|
@@ -7,6 +7,7 @@ var uiPlugin = plugin(({ addVariant }) => {
|
|
|
7
7
|
"&:is(:where(.group\\/select-content)[data-has-selection] *)",
|
|
8
8
|
"&:is(:where(.group\\/select-content)[data-has-search] *)",
|
|
9
9
|
"&:is(:where(.group\\/select-content)[data-searchable-focus-within] *)",
|
|
10
|
+
"&:is(:where(.group\\/radio-group-content)[data-radio-group-content] *)",
|
|
10
11
|
"&:is(:where(.group\\/date-picker-content)[data-has-selection] *)",
|
|
11
12
|
"&:is(:where(.group\\/date-picker-content)[data-focus-within] *)"
|
|
12
13
|
].join(", "));
|
|
@@ -14,6 +15,7 @@ var uiPlugin = plugin(({ addVariant }) => {
|
|
|
14
15
|
"&:is(:where(.group\\/input-content):has(*:is(input:disabled)) *)",
|
|
15
16
|
"&:is(:where(.group\\/select-content)[data-disabled] *)",
|
|
16
17
|
"&:is(:where(.group\\/select-content):has(*:is(input:disabled)) *)",
|
|
18
|
+
"&:is(:where(.group\\/radio-group-content)[data-disabled] *)",
|
|
17
19
|
"&:is(:where(.group\\/text-area):has(*:is(textarea:disabled)) *)",
|
|
18
20
|
"&:is(:where(.group\\/text-editor):where([data-rac])[data-disabled] *)",
|
|
19
21
|
"&:is(:where(.group\\/date-picker-content):where([data-rac])[data-disabled] *)"
|
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
import { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from '@internationalized/date';
|
|
2
2
|
export declare namespace DateTimeUtils {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
interface LocalizedDateFormatOptions {
|
|
4
|
+
shouldForceLeadingZeros?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface LocalizedDatePart {
|
|
7
|
+
type: Intl.DateTimeFormatPartTypes;
|
|
8
|
+
value: string;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
isPlaceholder: boolean;
|
|
11
|
+
}
|
|
12
|
+
export function getDatePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
13
|
+
export function getTimePlaceholder(locale?: string): string;
|
|
14
|
+
export function getDateTimePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
15
|
+
export function getDateRangePlaceholder(locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
16
|
+
export function formatCalendarDateLocalized(calendarDate: CalendarDate, locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
17
|
+
export function formatCalendarDatePartsLocalized(calendarDate?: CalendarDate | null, locale?: string, options?: LocalizedDateFormatOptions): LocalizedDatePart[];
|
|
18
|
+
export function formatTimeLocalized(timeValue: {
|
|
19
|
+
hour: number;
|
|
20
|
+
minute: number;
|
|
21
|
+
}, locale?: string): string;
|
|
22
|
+
export function formatCalendarDateTimeLocalized(calendarDateTime: Pick<CalendarDateTime, "day" | "month" | "year" | "hour" | "minute">, locale?: string, options?: LocalizedDateFormatOptions): string;
|
|
23
|
+
export function fromISOtoZonedDateTime(isoString: string, timeZone?: string): ZonedDateTime;
|
|
24
|
+
export function fromDateValueToISO(dateValue: DateValue, timeZone?: string): string;
|
|
25
|
+
export function fromDateValueToOffsetISO(dateValue: DateValue, timeZone?: string): string;
|
|
26
|
+
export function fromLocalToZonedDateTime(date: Date, timeZone?: string): ZonedDateTime;
|
|
27
|
+
export function fromDateValueToLocal(dateValue: DateValue, timeZone?: string): Date;
|
|
28
|
+
export function fromCalendarDateToUTCISO(calendarDate: CalendarDate, options?: {
|
|
9
29
|
endOfDay?: boolean;
|
|
10
30
|
}): string;
|
|
11
|
-
function fromUTCISOToCalendarDate(isoString: string): CalendarDate;
|
|
12
|
-
function fromCalendarDateTimeToUTCISO(calendarDateTime: CalendarDateTime): string;
|
|
13
|
-
function fromUTCISOToCalendarDateTime(isoString: string, timeZone?: string): CalendarDateTime;
|
|
14
|
-
function formatTextDateToCalendarDateTime(textDate: string | null, timeZone?: string, locale?: string): CalendarDateTime | null;
|
|
31
|
+
export function fromUTCISOToCalendarDate(isoString: string): CalendarDate;
|
|
32
|
+
export function fromCalendarDateTimeToUTCISO(calendarDateTime: CalendarDateTime): string;
|
|
33
|
+
export function fromUTCISOToCalendarDateTime(isoString: string, timeZone?: string): CalendarDateTime;
|
|
34
|
+
export function formatTextDateToCalendarDateTime(textDate: string | null, timeZone?: string, locale?: string): CalendarDateTime | null;
|
|
35
|
+
export {};
|
|
15
36
|
}
|
|
@@ -1,33 +1,134 @@
|
|
|
1
|
-
import { CalendarDate, CalendarDateTime, fromDate, getLocalTimeZone, parseAbsolute } from "@internationalized/date";
|
|
1
|
+
import { CalendarDate, CalendarDateTime, DateFormatter, fromDate, getLocalTimeZone, parseAbsolute } from "@internationalized/date";
|
|
2
2
|
import { DateTime } from "luxon";
|
|
3
3
|
//#region src/utils/date-time.utils.ts
|
|
4
4
|
var DateTimeUtils;
|
|
5
5
|
(function(_DateTimeUtils) {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const DATE_SAMPLE_DATE_UTC = new Date(Date.UTC(2e3, 10, 22));
|
|
7
|
+
const TIME_SAMPLE_DATE_UTC = new Date(Date.UTC(2e3, 10, 22, 13, 45));
|
|
8
|
+
const getDayMonthFormat = (shouldForceLeadingZeros = false) => shouldForceLeadingZeros ? "2-digit" : "numeric";
|
|
9
|
+
const getDatePlaceholderFormatter = (locale, options) => new Intl.DateTimeFormat(locale, {
|
|
10
|
+
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
11
|
+
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
12
|
+
year: "numeric"
|
|
13
|
+
});
|
|
14
|
+
const getTimePlaceholderFormatter = (locale) => new Intl.DateTimeFormat(locale, {
|
|
15
|
+
hour: "2-digit",
|
|
16
|
+
minute: "2-digit",
|
|
17
|
+
hourCycle: "h23"
|
|
18
|
+
});
|
|
19
|
+
const getResolvedLocale = (locale) => {
|
|
20
|
+
if (locale) return locale;
|
|
21
|
+
return new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
22
|
+
};
|
|
23
|
+
const getDateFormatter = (locale, options) => new Intl.DateTimeFormat(getResolvedLocale(locale), {
|
|
24
|
+
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
25
|
+
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
26
|
+
year: "numeric",
|
|
27
|
+
timeZone: "UTC"
|
|
28
|
+
});
|
|
29
|
+
const getTimeFormatter = (locale) => new DateFormatter(getResolvedLocale(locale), {
|
|
30
|
+
hour: "2-digit",
|
|
31
|
+
minute: "2-digit",
|
|
32
|
+
hourCycle: "h23",
|
|
33
|
+
timeZone: "UTC"
|
|
34
|
+
});
|
|
35
|
+
const getDateTimeFormatter = (locale, options) => new Intl.DateTimeFormat(getResolvedLocale(locale), {
|
|
36
|
+
day: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
37
|
+
month: getDayMonthFormat(options?.shouldForceLeadingZeros),
|
|
38
|
+
year: "numeric",
|
|
39
|
+
hour: "2-digit",
|
|
40
|
+
minute: "2-digit",
|
|
41
|
+
hourCycle: "h23",
|
|
42
|
+
timeZone: "UTC"
|
|
43
|
+
});
|
|
44
|
+
const getLocaleDateFormat = (locale) => {
|
|
45
|
+
const sampleDate = new Date(Date.UTC(2e3, 10, 22));
|
|
46
|
+
return new Intl.DateTimeFormat(locale, {
|
|
8
47
|
day: "2-digit",
|
|
9
48
|
month: "2-digit",
|
|
10
|
-
year: "numeric"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (part.type === "
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
49
|
+
year: "numeric",
|
|
50
|
+
timeZone: "UTC"
|
|
51
|
+
}).formatToParts(sampleDate).map((part) => {
|
|
52
|
+
if (part.type === "day") return "dd";
|
|
53
|
+
if (part.type === "month") return "MM";
|
|
54
|
+
if (part.type === "year") return "yyyy";
|
|
55
|
+
return part.value;
|
|
56
|
+
}).join("");
|
|
57
|
+
};
|
|
58
|
+
const repeatLocalizedFieldLabel = (type, length, locale) => {
|
|
59
|
+
const placeholderChar = new Intl.DisplayNames(getResolvedLocale(locale), { type: "dateTimeField" }).of(type)?.trim().charAt(0).toLocaleLowerCase(getResolvedLocale(locale));
|
|
60
|
+
if (!placeholderChar) return null;
|
|
61
|
+
return placeholderChar.repeat(length);
|
|
62
|
+
};
|
|
63
|
+
const mapTypeToPlaceholder = (type, locale) => {
|
|
64
|
+
switch (type) {
|
|
65
|
+
case "day": return repeatLocalizedFieldLabel(type, 2, locale);
|
|
66
|
+
case "month": return repeatLocalizedFieldLabel(type, 2, locale);
|
|
67
|
+
case "year": return repeatLocalizedFieldLabel(type, 4, locale);
|
|
68
|
+
case "hour": return "hh";
|
|
69
|
+
case "minute": return "mm";
|
|
70
|
+
default: return null;
|
|
27
71
|
}
|
|
28
|
-
|
|
29
|
-
|
|
72
|
+
};
|
|
73
|
+
const formatPlaceholder = (formatter, sampleDate) => {
|
|
74
|
+
return formatter.formatToParts(sampleDate).map((part) => mapTypeToPlaceholder(part.type, formatter.resolvedOptions().locale) ?? part.value.replace(/\s+/gu, "")).join("");
|
|
75
|
+
};
|
|
76
|
+
const removeLeadingZero = (value) => value.replace(/^0+(?=\d)/u, "");
|
|
77
|
+
const removeDateSeparatorSpacing = (value) => value.replace(/([./-])\s+(?=\d)/gu, "$1");
|
|
78
|
+
const formatLocalizedDateParts = (formatter, date, options) => {
|
|
79
|
+
if (options?.shouldForceLeadingZeros !== false) return removeDateSeparatorSpacing(formatter.format(date));
|
|
80
|
+
return removeDateSeparatorSpacing(formatter.formatToParts(date).map((part) => {
|
|
81
|
+
if (part.type === "day" || part.type === "month") return removeLeadingZero(part.value);
|
|
82
|
+
return part.value;
|
|
83
|
+
}).join(""));
|
|
84
|
+
};
|
|
85
|
+
const formatLocalizedDatePartList = (formatter, date, isPlaceholder, options) => {
|
|
86
|
+
const locale = formatter.resolvedOptions().locale;
|
|
87
|
+
return formatter.formatToParts(date).map((part) => {
|
|
88
|
+
const value = options?.shouldForceLeadingZeros === false && (part.type === "day" || part.type === "month") ? removeLeadingZero(part.value) : part.value.replace(/\s+/gu, "");
|
|
89
|
+
return {
|
|
90
|
+
type: part.type,
|
|
91
|
+
value,
|
|
92
|
+
placeholder: mapTypeToPlaceholder(part.type, locale) ?? part.value.replace(/\s+/gu, ""),
|
|
93
|
+
isPlaceholder
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
function getDatePlaceholder(locale, options) {
|
|
98
|
+
return formatPlaceholder(getDatePlaceholderFormatter(locale, options), DATE_SAMPLE_DATE_UTC);
|
|
30
99
|
}
|
|
100
|
+
_DateTimeUtils.getDatePlaceholder = getDatePlaceholder;
|
|
101
|
+
function getTimePlaceholder(locale) {
|
|
102
|
+
return formatPlaceholder(getTimePlaceholderFormatter(locale), TIME_SAMPLE_DATE_UTC);
|
|
103
|
+
}
|
|
104
|
+
_DateTimeUtils.getTimePlaceholder = getTimePlaceholder;
|
|
105
|
+
function getDateTimePlaceholder(locale, options) {
|
|
106
|
+
return `${getDatePlaceholder(locale, options)}, ${getTimePlaceholder(locale)}`;
|
|
107
|
+
}
|
|
108
|
+
_DateTimeUtils.getDateTimePlaceholder = getDateTimePlaceholder;
|
|
109
|
+
function getDateRangePlaceholder(locale, options) {
|
|
110
|
+
const datePlaceholder = getDatePlaceholder(locale, options);
|
|
111
|
+
return `${datePlaceholder} – ${datePlaceholder}`;
|
|
112
|
+
}
|
|
113
|
+
_DateTimeUtils.getDateRangePlaceholder = getDateRangePlaceholder;
|
|
114
|
+
function formatCalendarDateLocalized(calendarDate, locale, options) {
|
|
115
|
+
return formatLocalizedDateParts(getDateFormatter(locale, options), calendarDate.toDate("UTC"), options);
|
|
116
|
+
}
|
|
117
|
+
_DateTimeUtils.formatCalendarDateLocalized = formatCalendarDateLocalized;
|
|
118
|
+
function formatCalendarDatePartsLocalized(calendarDate, locale, options) {
|
|
119
|
+
return formatLocalizedDatePartList(getDateFormatter(locale, options), calendarDate?.toDate("UTC") ?? DATE_SAMPLE_DATE_UTC, !calendarDate, options);
|
|
120
|
+
}
|
|
121
|
+
_DateTimeUtils.formatCalendarDatePartsLocalized = formatCalendarDatePartsLocalized;
|
|
122
|
+
function formatTimeLocalized(timeValue, locale) {
|
|
123
|
+
const dateTime = new CalendarDateTime(2e3, 11, 22, timeValue.hour, timeValue.minute);
|
|
124
|
+
return getTimeFormatter(locale).format(dateTime.toDate("UTC"));
|
|
125
|
+
}
|
|
126
|
+
_DateTimeUtils.formatTimeLocalized = formatTimeLocalized;
|
|
127
|
+
function formatCalendarDateTimeLocalized(calendarDateTime, locale, options) {
|
|
128
|
+
const normalizedValue = new CalendarDateTime(calendarDateTime.year, calendarDateTime.month, calendarDateTime.day, calendarDateTime.hour, calendarDateTime.minute);
|
|
129
|
+
return formatLocalizedDateParts(getDateTimeFormatter(locale, options), normalizedValue.toDate("UTC"), options);
|
|
130
|
+
}
|
|
131
|
+
_DateTimeUtils.formatCalendarDateTimeLocalized = formatCalendarDateTimeLocalized;
|
|
31
132
|
function resolveTimeZone(timeZone) {
|
|
32
133
|
if (timeZone) return timeZone;
|
|
33
134
|
return getLocalTimeZone();
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
//#region src/utils/routing.utils.ts
|
|
2
2
|
var RoutingUtils;
|
|
3
3
|
(function(_RoutingUtils) {
|
|
4
|
+
const isNumericString = (value) => {
|
|
5
|
+
return /^-?(0|[1-9]\d*)(\.\d+)?$/.test(value);
|
|
6
|
+
};
|
|
7
|
+
const coerceQueryValue = (value) => {
|
|
8
|
+
if (value === "true") return true;
|
|
9
|
+
if (value === "false") return false;
|
|
10
|
+
if (isNumericString(value)) return Number(value);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
_RoutingUtils.toRouterSearch = (params) => {
|
|
14
|
+
const search = {};
|
|
15
|
+
for (const [key, value] of params.entries()) search[key] = coerceQueryValue(value);
|
|
16
|
+
return search;
|
|
17
|
+
};
|
|
4
18
|
_RoutingUtils.addQueryParams = (path, params) => {
|
|
5
19
|
const sParams = new URLSearchParams();
|
|
6
20
|
for (const [key, value] of Object.entries(params)) if (value) sParams.append(key, value.toString());
|