@povio/ui 2.2.9-rc.9 → 2.2.10

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 (88) hide show
  1. package/dist/components/buttons/Button/Button.d.ts +2 -2
  2. package/dist/components/buttons/Button/Button.js +1 -1
  3. package/dist/components/buttons/PillButton/PillButton.d.ts +2 -2
  4. package/dist/components/buttons/PillButton/PillButton.js +1 -1
  5. package/dist/components/buttons/TextButton/TextButton.d.ts +2 -1
  6. package/dist/components/buttons/ToggleButton/ToggleButton.d.ts +2 -1
  7. package/dist/components/buttons/shared/ButtonContent.d.ts +3 -3
  8. package/dist/components/buttons/shared/ButtonContent.js +2 -2
  9. package/dist/components/inputs/Checkbox/Checkbox.js +1 -6
  10. package/dist/components/inputs/Checkbox/checkbox.cva.d.ts +0 -3
  11. package/dist/components/inputs/Checkbox/checkbox.cva.js +1 -2
  12. package/dist/components/inputs/DateTime/DatePicker/DatePicker.d.ts +8 -8
  13. package/dist/components/inputs/DateTime/DatePicker/DatePicker.js +59 -33
  14. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.d.ts +4 -7
  15. package/dist/components/inputs/DateTime/DateRangePicker/DateRangePicker.js +4 -14
  16. package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.d.ts +7 -7
  17. package/dist/components/inputs/DateTime/DateTimePicker/DateTimePicker.js +40 -22
  18. package/dist/components/inputs/DateTime/TimePicker/TimePicker.d.ts +3 -3
  19. package/dist/components/inputs/DateTime/TimePicker/TimePicker.js +13 -20
  20. package/dist/components/inputs/DateTime/shared/Calendar.d.ts +4 -1
  21. package/dist/components/inputs/DateTime/shared/Calendar.js +75 -12
  22. package/dist/components/inputs/DateTime/shared/CalendarHeader.d.ts +2 -1
  23. package/dist/components/inputs/DateTime/shared/CalendarHeader.js +28 -4
  24. package/dist/components/inputs/DateTime/shared/DateField.d.ts +3 -1
  25. package/dist/components/inputs/DateTime/shared/DateField.js +41 -7
  26. package/dist/components/inputs/DateTime/shared/DatePickerInput.d.ts +6 -5
  27. package/dist/components/inputs/DateTime/shared/DatePickerInput.js +16 -18
  28. package/dist/components/inputs/DateTime/shared/MonthPicker.d.ts +3 -1
  29. package/dist/components/inputs/DateTime/shared/MonthPicker.js +4 -3
  30. package/dist/components/inputs/DateTime/shared/TimePickerInput.d.ts +1 -2
  31. package/dist/components/inputs/DateTime/shared/TimePickerInput.js +2 -7
  32. package/dist/components/inputs/DateTime/shared/YearPicker.d.ts +3 -1
  33. package/dist/components/inputs/DateTime/shared/YearPicker.js +4 -3
  34. package/dist/components/inputs/FormField/FormFieldHeader.js +1 -3
  35. package/dist/components/inputs/Input/NumberInput/NumberInput.js +0 -1
  36. package/dist/components/inputs/Input/TextInput/TextInput.js +0 -3
  37. package/dist/components/inputs/Inputs/InputItem.d.ts +16 -10
  38. package/dist/components/inputs/Inputs/InputItem.js +0 -4
  39. package/dist/components/inputs/RadioGroup/RadioGroup.js +1 -6
  40. package/dist/components/inputs/RadioGroup/radio.cva.d.ts +0 -3
  41. package/dist/components/inputs/RadioGroup/radio.cva.js +1 -2
  42. package/dist/components/inputs/Selection/Autocomplete/Autocomplete.d.ts +1 -3
  43. package/dist/components/inputs/Selection/Autocomplete/Autocomplete.js +3 -4
  44. package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.d.ts +18 -3
  45. package/dist/components/inputs/Selection/Autocomplete/QueryAutocomplete.js +7 -23
  46. package/dist/components/inputs/Selection/Select/Select.d.ts +2 -4
  47. package/dist/components/inputs/Selection/Select/Select.js +3 -4
  48. package/dist/components/inputs/Selection/shared/SelectBase.d.ts +1 -8
  49. package/dist/components/inputs/Selection/shared/SelectBase.js +1 -3
  50. package/dist/components/inputs/Selection/shared/SelectDesktop.d.ts +1 -1
  51. package/dist/components/inputs/Selection/shared/SelectDesktop.js +2 -8
  52. package/dist/components/inputs/Selection/shared/SelectInput.d.ts +2 -2
  53. package/dist/components/inputs/Selection/shared/SelectInput.js +3 -23
  54. package/dist/components/inputs/Selection/shared/SelectMobile.d.ts +1 -1
  55. package/dist/components/inputs/Selection/shared/SelectMobile.js +5 -10
  56. package/dist/components/inputs/Selection/shared/select.context.d.ts +2 -3
  57. package/dist/components/inputs/Selection/shared/select.context.js +4 -22
  58. package/dist/components/inputs/Selection/shared/select.types.d.ts +2 -2
  59. package/dist/components/inputs/TextEditor/TextEditor.d.ts +0 -1
  60. package/dist/components/inputs/TextEditor/TextEditor.js +3 -7
  61. package/dist/components/inputs/Toggle/Toggle.js +1 -6
  62. package/dist/components/inputs/Toggle/toggle.cva.d.ts +0 -3
  63. package/dist/components/inputs/Toggle/toggle.cva.js +1 -2
  64. package/dist/components/inputs/shared/CheckContent.d.ts +1 -2
  65. package/dist/components/inputs/shared/CheckContent.js +4 -3
  66. package/dist/components/overlays/BottomSheet/BottomSheet.js +1 -2
  67. package/dist/components/overlays/Tooltip/TooltipEllipsis.d.ts +2 -2
  68. package/dist/config/link.context.js +4 -2
  69. package/dist/config/uiConfig.context.d.ts +2 -8
  70. package/dist/config/uiConfig.context.js +3 -5
  71. package/dist/config/uiStyle.context.d.ts +1 -6
  72. package/dist/helpers/dynamicInputs.d.ts +5 -5
  73. package/dist/helpers/dynamicInputs.js +0 -3
  74. package/dist/index.d.ts +0 -4
  75. package/dist/index.js +3 -4
  76. package/dist/utils/date-time.utils.d.ts +7 -6
  77. package/dist/utils/date-time.utils.js +66 -16
  78. package/package.json +1 -1
  79. package/dist/components/inputs/DateTime/shared/datePicker.types.d.ts +0 -3
  80. package/dist/components/inputs/FormField/formFieldHeader.cva.d.ts +0 -6
  81. package/dist/components/inputs/FormField/formFieldHeader.cva.js +0 -11
  82. package/dist/components/inputs/Selection/Autocomplete/queryAutocomplete.types.d.ts +0 -30
  83. package/dist/components/inputs/Selection/Select/QuerySelect.d.ts +0 -14
  84. package/dist/components/inputs/Selection/Select/QuerySelect.js +0 -56
  85. package/dist/components/inputs/Selection/shared/querySelect.utils.d.ts +0 -6
  86. package/dist/components/inputs/Selection/shared/querySelect.utils.js +0 -13
  87. package/dist/hooks/useQueryAutocomplete.d.ts +0 -25
  88. package/dist/hooks/useQueryAutocomplete.js +0 -41
@@ -1,14 +1,15 @@
1
1
  import { CalendarDate, CalendarDateTime, DateValue, ZonedDateTime } from '@internationalized/date';
2
2
  export declare namespace DateTimeUtils {
3
- function fromISOtoZonedDateTime(isoString: string): ZonedDateTime;
4
- function fromDateValueToISO(dateValue: DateValue): string;
5
- function fromLocalToZonedDateTime(date: Date): ZonedDateTime;
6
- function fromDateValueToLocal(dateValue: DateValue): Date;
3
+ function fromISOtoZonedDateTime(isoString: string, timeZone?: string): ZonedDateTime;
4
+ function fromDateValueToISO(dateValue: DateValue, timeZone?: string): string;
5
+ function fromDateValueToOffsetISO(dateValue: DateValue, timeZone?: string): string;
6
+ function fromLocalToZonedDateTime(date: Date, timeZone?: string): ZonedDateTime;
7
+ function fromDateValueToLocal(dateValue: DateValue, timeZone?: string): Date;
7
8
  function fromCalendarDateToUTCISO(calendarDate: CalendarDate, options?: {
8
9
  endOfDay?: boolean;
9
10
  }): string;
10
11
  function fromUTCISOToCalendarDate(isoString: string): CalendarDate;
11
12
  function fromCalendarDateTimeToUTCISO(calendarDateTime: CalendarDateTime): string;
12
- function fromUTCISOToCalendarDateTime(isoString: string): CalendarDateTime;
13
- function formatTextDateToCalendarDateTime(textDate: string | null): CalendarDateTime | null;
13
+ function fromUTCISOToCalendarDateTime(isoString: string, timeZone?: string): CalendarDateTime;
14
+ function formatTextDateToCalendarDateTime(textDate: string | null, timeZone?: string, locale?: string): CalendarDateTime | null;
14
15
  }
@@ -1,21 +1,61 @@
1
- import { CalendarDate, CalendarDateTime, fromDate, getLocalTimeZone, parseAbsolute, parseAbsoluteToLocal } from "@internationalized/date";
1
+ import { CalendarDate, CalendarDateTime, fromDate, getLocalTimeZone, parseAbsolute } from "@internationalized/date";
2
+ import { DateTime } from "luxon";
2
3
  //#region src/utils/date-time.utils.ts
3
4
  var DateTimeUtils;
4
5
  (function(_DateTimeUtils) {
5
- function fromISOtoZonedDateTime(isoString) {
6
- return parseAbsoluteToLocal(isoString);
6
+ function getLocaleDateFormat(locale) {
7
+ const parts = new Intl.DateTimeFormat(locale, {
8
+ day: "2-digit",
9
+ month: "2-digit",
10
+ year: "numeric"
11
+ }).formatToParts(new Date(2001, 10, 23));
12
+ let format = "";
13
+ for (const part of parts) {
14
+ if (part.type === "day") {
15
+ format += "dd";
16
+ continue;
17
+ }
18
+ if (part.type === "month") {
19
+ format += "MM";
20
+ continue;
21
+ }
22
+ if (part.type === "year") {
23
+ format += "yyyy";
24
+ continue;
25
+ }
26
+ if (part.type === "literal") format += part.value;
27
+ }
28
+ if (!format.includes("dd") || !format.includes("MM") || !format.includes("yyyy")) return "dd/MM/yyyy";
29
+ return format;
30
+ }
31
+ function resolveTimeZone(timeZone) {
32
+ if (timeZone) return timeZone;
33
+ return getLocalTimeZone();
34
+ }
35
+ function fromISOtoZonedDateTime(isoString, timeZone) {
36
+ return parseAbsolute(isoString, resolveTimeZone(timeZone));
7
37
  }
8
38
  _DateTimeUtils.fromISOtoZonedDateTime = fromISOtoZonedDateTime;
9
- function fromDateValueToISO(dateValue) {
10
- return dateValue.toDate(getLocalTimeZone()).toISOString();
39
+ function fromDateValueToISO(dateValue, timeZone) {
40
+ const resolvedTimeZone = resolveTimeZone(timeZone);
41
+ return dateValue.toDate(resolvedTimeZone).toISOString();
11
42
  }
12
43
  _DateTimeUtils.fromDateValueToISO = fromDateValueToISO;
13
- function fromLocalToZonedDateTime(date) {
14
- return fromDate(date, getLocalTimeZone());
44
+ function fromDateValueToOffsetISO(dateValue, timeZone) {
45
+ const resolvedTimeZone = resolveTimeZone(timeZone);
46
+ const date = dateValue.toDate(resolvedTimeZone);
47
+ const isoString = DateTime.fromJSDate(date, { zone: resolvedTimeZone }).toISO({ includeOffset: true });
48
+ if (isoString) return isoString;
49
+ return date.toISOString();
50
+ }
51
+ _DateTimeUtils.fromDateValueToOffsetISO = fromDateValueToOffsetISO;
52
+ function fromLocalToZonedDateTime(date, timeZone) {
53
+ return fromDate(date, resolveTimeZone(timeZone));
15
54
  }
16
55
  _DateTimeUtils.fromLocalToZonedDateTime = fromLocalToZonedDateTime;
17
- function fromDateValueToLocal(dateValue) {
18
- return dateValue.toDate(getLocalTimeZone());
56
+ function fromDateValueToLocal(dateValue, timeZone) {
57
+ const resolvedTimeZone = resolveTimeZone(timeZone);
58
+ return dateValue.toDate(resolvedTimeZone);
19
59
  }
20
60
  _DateTimeUtils.fromDateValueToLocal = fromDateValueToLocal;
21
61
  function fromCalendarDateToUTCISO(calendarDate, options = {}) {
@@ -32,19 +72,29 @@ var DateTimeUtils;
32
72
  return calendarDateTime.toDate("UTC").toISOString();
33
73
  }
34
74
  _DateTimeUtils.fromCalendarDateTimeToUTCISO = fromCalendarDateTimeToUTCISO;
35
- function fromUTCISOToCalendarDateTime(isoString) {
36
- const zonedDateTime = parseAbsolute(isoString, "UTC");
75
+ function fromUTCISOToCalendarDateTime(isoString, timeZone = "UTC") {
76
+ const zonedDateTime = parseAbsolute(isoString, timeZone);
37
77
  return new CalendarDateTime(zonedDateTime.year, zonedDateTime.month, zonedDateTime.day, zonedDateTime.hour, zonedDateTime.minute, zonedDateTime.second, zonedDateTime.millisecond);
38
78
  }
39
79
  _DateTimeUtils.fromUTCISOToCalendarDateTime = fromUTCISOToCalendarDateTime;
40
- function formatTextDateToCalendarDateTime(textDate) {
80
+ function formatTextDateToCalendarDateTime(textDate, timeZone, locale) {
41
81
  if (!textDate?.includes("hh")) return null;
42
82
  const datePart = textDate.split(",").at(0)?.trim();
43
83
  if (!datePart) return null;
44
- const date = new Date(datePart);
45
- if (!date || date.toString() === "Invalid Date") return null;
46
- const zonedDateTime = fromDate(date, getLocalTimeZone());
47
- return new CalendarDateTime(zonedDateTime.year, zonedDateTime.month, zonedDateTime.day, 0, 0, 0, 0);
84
+ const resolvedTimeZone = resolveTimeZone(timeZone);
85
+ const resolvedLocale = locale || Intl.DateTimeFormat().resolvedOptions().locale;
86
+ const localeDateFormat = getLocaleDateFormat(resolvedLocale);
87
+ const parseOptions = {
88
+ zone: resolvedTimeZone,
89
+ locale: resolvedLocale
90
+ };
91
+ let parsedDateTime = DateTime.fromFormat(datePart, localeDateFormat, parseOptions);
92
+ if (!parsedDateTime.isValid && localeDateFormat.includes("yyyy")) {
93
+ const shortYearFormat = localeDateFormat.replace("yyyy", "yy");
94
+ parsedDateTime = DateTime.fromFormat(datePart, shortYearFormat, parseOptions);
95
+ }
96
+ if (!parsedDateTime.isValid) return null;
97
+ return new CalendarDateTime(parsedDateTime.year, parsedDateTime.month, parsedDateTime.day, 0, 0, 0, 0);
48
98
  }
49
99
  _DateTimeUtils.formatTextDateToCalendarDateTime = formatTextDateToCalendarDateTime;
50
100
  })(DateTimeUtils || (DateTimeUtils = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "2.2.9-rc.9",
3
+ "version": "2.2.10",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,3 +0,0 @@
1
- import { IconButtonProps } from '../../../buttons/IconButton/IconButton';
2
- export type DatePickerTodayIcon = boolean | IconButtonProps["icon"];
3
- export type DatePickerTodayIconButtonSize = IconButtonProps["size"];
@@ -1,6 +0,0 @@
1
- import { VariantProps } from 'class-variance-authority';
2
- export declare const formFieldHeader: (props?: ({
3
- visible?: boolean | null | undefined;
4
- } & import('class-variance-authority/types').ClassProp) | undefined) => string;
5
- export interface FormFieldHeaderVariantProps extends VariantProps<typeof formFieldHeader> {
6
- }
@@ -1,11 +0,0 @@
1
- import { cva } from "class-variance-authority";
2
- //#region src/components/inputs/FormField/formFieldHeader.cva.ts
3
- var formFieldHeader = cva("", {
4
- variants: { visible: {
5
- true: "mb-1",
6
- false: "sr-only"
7
- } },
8
- defaultVariants: { visible: true }
9
- });
10
- //#endregion
11
- export { formFieldHeader };
@@ -1,30 +0,0 @@
1
- import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
2
- import { Key } from 'react-aria-components';
3
- import { FieldValues } from 'react-hook-form';
4
- import { AutocompleteProps } from './Autocomplete';
5
- import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
6
- import { OmitDiscriminatedUnion } from '../../../../types/common';
7
- export interface QueryAutocompleteInfinitePage<TSelectItem extends SelectItem = SelectItem> {
8
- items: Array<TSelectItem>;
9
- totalItems?: number;
10
- }
11
- export type QueryResult<TSelectItem extends SelectItem = SelectItem> = UseQueryResult<Array<TSelectItem>> | UseInfiniteQueryResult<QueryAutocompleteInfinitePage<TSelectItem>>;
12
- export type QueryFn<TSelectItem extends SelectItem = SelectItem> = (...args: any[]) => QueryResult<TSelectItem>;
13
- export type QueryAutocompleteExtractedData<TSelectItem extends SelectItem = SelectItem> = Array<TSelectItem>;
14
- export type QueryAutocompleteProps<TFieldValues extends FieldValues, TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>> = OmitDiscriminatedUnion<AutocompleteProps<TSelectItem["id"]>, "items" | "onSearchChange" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TSelectItem["id"]> & {
15
- query: Parameters<TQueryFn>[0] extends {
16
- search?: string;
17
- } ? TQueryFn : never;
18
- queryParams?: Omit<Parameters<TQueryFn>[0], "search">;
19
- queryOptions?: Parameters<TQueryFn>[1];
20
- queryMap?: (data: QueryAutocompleteExtractedData<TSelectItem>) => SelectItem<TSelectItem["id"]>[];
21
- isInitialQueryDisabled?: boolean;
22
- };
23
- export interface UseQueryAutocompleteOptions<TSelectItem extends SelectItem<any>, TQueryFn extends QueryFn<TSelectItem>, TKey extends Key = QueryAutocompleteExtractedData<TSelectItem>[number]["id"]> {
24
- query: TQueryFn;
25
- queryParams?: Parameters<TQueryFn>[0];
26
- queryOptions?: Parameters<TQueryFn>[1];
27
- queryMap?: (data: QueryAutocompleteExtractedData<TSelectItem>) => SelectItem<TKey>[];
28
- initialQueryState?: boolean;
29
- search: string;
30
- }
@@ -1,14 +0,0 @@
1
- import { GroupedSelectControlProps, GroupedSelectProps, SelectItem } from '../shared/select.types';
2
- import { SelectBaseProps } from '../shared/SelectBase';
3
- import { QueryDataType, QueryFn } from '../shared/querySelect.utils';
4
- import { OmitDiscriminatedUnion } from '../../../../types/common';
5
- import { Key } from 'react-aria-components';
6
- import { FieldValues } from 'react-hook-form';
7
- export type QuerySelectProps<TFieldValues extends FieldValues, TQueryFn extends QueryFn, TKey extends Key = Key> = OmitDiscriminatedUnion<SelectBaseProps<TKey>, "items" | "isLoading" | keyof GroupedSelectProps> & GroupedSelectControlProps<TFieldValues, TKey> & {
8
- query: TQueryFn;
9
- queryParams?: Parameters<TQueryFn>[0];
10
- queryOptions?: Parameters<TQueryFn>[1];
11
- queryMap?: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[];
12
- isInitialQueryDisabled?: boolean;
13
- };
14
- export declare const QuerySelect: <TFieldValues extends FieldValues, TQueryFn extends QueryFn, TKey extends Key = Key>({ query, queryParams, queryOptions, queryMap, ...props }: QuerySelectProps<TFieldValues, TQueryFn, TKey>) => import("react/jsx-runtime").JSX.Element;
@@ -1,56 +0,0 @@
1
- import { UIConfig } from "../../../../config/uiConfig.context.js";
2
- import { SelectBase } from "../shared/SelectBase.js";
3
- import { useQueryAutocomplete } from "../../../../hooks/useQueryAutocomplete.js";
4
- import { getQueryItems } from "../shared/querySelect.utils.js";
5
- import { jsx } from "react/jsx-runtime";
6
- import { mergeRefs } from "@react-aria/utils";
7
- import { Controller } from "react-hook-form";
8
- //#region src/components/inputs/Selection/Select/QuerySelect.tsx
9
- var QuerySelect = ({ query, queryParams, queryOptions, queryMap, ...props }) => {
10
- const ui = UIConfig.useConfig();
11
- const { items, isLoading, handleEnableQuery, hasNextPage, fetchNextPage } = useQueryAutocomplete({
12
- query,
13
- queryParams,
14
- queryOptions,
15
- mapItems: (data) => getQueryItems(data, queryMap),
16
- initialQueryState: props.isInitialQueryDisabled ?? ui.querySelect?.isInitialQueryDisabled
17
- });
18
- if ("formControl" in props && props.formControl) {
19
- const { formControl, ref, isInitialQueryDisabled: _, ...innerProps } = props;
20
- return /* @__PURE__ */ jsx(Controller, {
21
- control: formControl.control,
22
- name: formControl.name,
23
- render: ({ field, fieldState: { error, isDirty } }) => /* @__PURE__ */ jsx(SelectBase, {
24
- ...innerProps,
25
- ref: mergeRefs(ref, field.ref),
26
- items,
27
- isLoading,
28
- hasLoadMore: hasNextPage,
29
- onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0,
30
- value: field.value,
31
- onChange: (value) => {
32
- field.onChange(value);
33
- field.onBlur?.();
34
- },
35
- onBlur: field.onBlur,
36
- isDirty,
37
- isDisabled: field.disabled || props.isDisabled,
38
- error: props.error ?? error?.message,
39
- onMouseEnter: handleEnableQuery,
40
- onFocusCapture: handleEnableQuery
41
- })
42
- });
43
- }
44
- const { isInitialQueryDisabled: _, ...restProps } = props;
45
- return /* @__PURE__ */ jsx(SelectBase, {
46
- ...restProps,
47
- items,
48
- isLoading,
49
- hasLoadMore: hasNextPage,
50
- onLoadMore: fetchNextPage ? () => void fetchNextPage() : void 0,
51
- onMouseEnter: handleEnableQuery,
52
- onFocusCapture: handleEnableQuery
53
- });
54
- };
55
- //#endregion
56
- export { QuerySelect };
@@ -1,6 +0,0 @@
1
- import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
2
- import { Key } from 'react-aria-components';
3
- import { SelectItem } from './select.types';
4
- export type QueryFn<TData = any> = (...args: any[]) => UseQueryResult<TData> | UseInfiniteQueryResult<TData>;
5
- export type QueryDataType<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>;
6
- export declare const getQueryItems: <TQueryFn extends QueryFn, TKey extends Key = Key>(data: QueryDataType<TQueryFn> | undefined, queryMap?: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[]) => SelectItem<TKey>[];
@@ -1,13 +0,0 @@
1
- //#region src/components/inputs/Selection/shared/querySelect.utils.ts
2
- var getQueryItems = (data, queryMap) => {
3
- if (!data) return [];
4
- if (queryMap) return queryMap(data);
5
- if (Array.isArray(data)) return data;
6
- if (typeof data === "object" && data !== null) {
7
- if ("items" in data && Array.isArray(data.items)) return data.items;
8
- if ("pages" in data && Array.isArray(data.pages)) return data.pages.flatMap((page) => page && typeof page === "object" && "items" in page && Array.isArray(page.items) ? page.items : []);
9
- }
10
- return [];
11
- };
12
- //#endregion
13
- export { getQueryItems };
@@ -1,25 +0,0 @@
1
- import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
2
- import { Key } from 'react-aria-components';
3
- import { SelectItem } from '../components/inputs/Selection/shared/select.types';
4
- type QueryResult<TData = any> = UseQueryResult<TData> | UseInfiniteQueryResult<TData>;
5
- type QueryFn<TData = any> = (...args: any[]) => QueryResult<TData>;
6
- type QueryDataType<TQueryFn extends QueryFn> = Exclude<ReturnType<TQueryFn>["data"], undefined>;
7
- interface UseQueryAutocompleteOptions<TQueryFn extends QueryFn, TKey extends Key = Key> {
8
- query: TQueryFn;
9
- queryParams?: Parameters<TQueryFn>[0];
10
- queryOptions?: Parameters<TQueryFn>[1];
11
- mapItems: (data: QueryDataType<TQueryFn>) => SelectItem<TKey>[];
12
- initialQueryState?: boolean;
13
- search?: string;
14
- }
15
- export declare const useQueryAutocomplete: <TQueryFn extends QueryFn, TKey extends Key = Key>({ query, queryParams, queryOptions, mapItems, initialQueryState, search, }: UseQueryAutocompleteOptions<TQueryFn, TKey>) => {
16
- data: any;
17
- isLoading: boolean;
18
- isQueryEnabled: boolean;
19
- handleEnableQuery: () => void;
20
- items: SelectItem<TKey>[];
21
- hasNextPage: boolean;
22
- fetchNextPage: (() => Promise<unknown>) | ((options?: import('@tanstack/react-query').FetchNextPageOptions) => Promise<import('@tanstack/react-query').InfiniteQueryObserverResult<any, Error>>) | undefined;
23
- isFetchingNextPage: boolean;
24
- };
25
- export {};
@@ -1,41 +0,0 @@
1
- import { useMemo, useState } from "react";
2
- //#region src/hooks/useQueryAutocomplete.ts
3
- var useQueryAutocomplete = ({ query, queryParams, queryOptions, mapItems, initialQueryState, search }) => {
4
- const [isQueryEnabled, setIsQueryEnabled] = useState(!initialQueryState);
5
- const queryResult = query(search === void 0 ? queryParams : {
6
- search,
7
- ...queryParams
8
- }, {
9
- ...queryOptions,
10
- enabled: isQueryEnabled && (queryOptions?.enabled ?? true)
11
- });
12
- const data = queryResult.data;
13
- const isLoading = queryResult.isLoading;
14
- const isInfiniteQueryResult = (result) => {
15
- return "hasNextPage" in result && "fetchNextPage" in result;
16
- };
17
- const isInfiniteQuery = isInfiniteQueryResult(queryResult);
18
- const handleEnableQuery = () => {
19
- setIsQueryEnabled(true);
20
- };
21
- const infiniteQueryResult = isInfiniteQuery ? queryResult : void 0;
22
- const hasNextPage = infiniteQueryResult?.hasNextPage ?? false;
23
- const fetchNextPage = infiniteQueryResult?.fetchNextPage;
24
- const isFetchingNextPage = infiniteQueryResult?.isFetchingNextPage ?? false;
25
- const items = useMemo(() => {
26
- if (!data) return [];
27
- return mapItems(data);
28
- }, [data, mapItems]);
29
- return {
30
- data,
31
- isLoading: isLoading || isFetchingNextPage,
32
- isQueryEnabled,
33
- handleEnableQuery,
34
- items,
35
- hasNextPage,
36
- fetchNextPage,
37
- isFetchingNextPage
38
- };
39
- };
40
- //#endregion
41
- export { useQueryAutocomplete };