@povio/ui 3.4.0-rc.39 → 3.4.0-rc.40

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.
@@ -463,6 +463,80 @@ const RangeCalendar = ({ className, leftCalendarState, rightCalendarState, calen
463
463
  });
464
464
  };
465
465
  //#endregion
466
+ //#region src/components/inputs/DateTime/DateRangePicker/dateRangePreset.utils.ts
467
+ const dateRangePresetValues = [
468
+ "thisWeek",
469
+ "lastWeek",
470
+ "thisAndLastWeek",
471
+ "thisMonth",
472
+ "thisAndLastMonth",
473
+ "thisYear",
474
+ "lastYear",
475
+ "thisAndLastYear",
476
+ "soFar"
477
+ ];
478
+ const isStoredRelativeDateRangeValue = (value) => typeof value === "object" && value !== null && typeof value.relativeValue === "string";
479
+ const isRelativeDateRangeValue = (value) => isStoredRelativeDateRangeValue(value) && typeof value.resolvedValue === "object";
480
+ const isDateRangePresetValue = (value) => dateRangePresetValues.some((preset) => preset === value);
481
+ const getDateRangePreset = (value, currentDate = today(getLocalTimeZone()), locale = "en-GB") => {
482
+ if (!isDateRangePresetValue(value)) return;
483
+ const previousYear = currentDate.subtract({ years: 1 });
484
+ switch (value) {
485
+ case "thisWeek": return {
486
+ start: startOfWeek(currentDate, locale),
487
+ end: endOfWeek(currentDate, locale)
488
+ };
489
+ case "lastWeek": {
490
+ const thisWeekStart = startOfWeek(currentDate, locale);
491
+ return {
492
+ start: thisWeekStart.subtract({ weeks: 1 }),
493
+ end: thisWeekStart.subtract({ days: 1 })
494
+ };
495
+ }
496
+ case "thisAndLastWeek": return {
497
+ start: startOfWeek(currentDate, locale).subtract({ weeks: 1 }),
498
+ end: endOfWeek(currentDate, locale)
499
+ };
500
+ case "thisMonth": return {
501
+ start: startOfMonth(currentDate),
502
+ end: endOfMonth(currentDate)
503
+ };
504
+ case "thisAndLastMonth": return {
505
+ start: startOfMonth(currentDate).subtract({ months: 1 }),
506
+ end: endOfMonth(currentDate)
507
+ };
508
+ case "thisYear":
509
+ case "soFar": return {
510
+ start: startOfYear(currentDate),
511
+ end: currentDate
512
+ };
513
+ case "lastYear": return {
514
+ start: startOfYear(previousYear),
515
+ end: endOfYear(previousYear)
516
+ };
517
+ case "thisAndLastYear": return {
518
+ start: startOfYear(previousYear),
519
+ end: currentDate
520
+ };
521
+ }
522
+ };
523
+ const resolveDateRangePreset = (value, currentDate = today(getLocalTimeZone()), locale = "en-GB") => {
524
+ const range = getDateRangePreset(value, currentDate, locale);
525
+ if (!range) return;
526
+ return {
527
+ start: DateTimeUtils.fromCalendarDateToUTCISO(range.start),
528
+ end: DateTimeUtils.fromCalendarDateToUTCISO(range.end, { endOfDay: true })
529
+ };
530
+ };
531
+ const hydrateRelativeDateRangeValue = (value, currentDate = today(getLocalTimeZone()), locale = "en-GB") => {
532
+ if (isRelativeDateRangeValue(value)) return value;
533
+ const resolvedValue = resolveDateRangePreset(value.relativeValue, currentDate, locale);
534
+ return resolvedValue ? {
535
+ relativeValue: value.relativeValue,
536
+ resolvedValue
537
+ } : void 0;
538
+ };
539
+ //#endregion
466
540
  //#region src/components/inputs/DateTime/DateRangePicker/DateRangePicker.tsx
467
541
  const DateRangePickerBase = (props) => {
468
542
  const ui = UIConfig.useConfig();
@@ -939,39 +1013,7 @@ const DateRangePickerBase = (props) => {
939
1013
  state.toggle();
940
1014
  };
941
1015
  const todayDate = today(effectiveTimeZone);
942
- const getThisWeekRange = () => {
943
- return {
944
- start: startOfWeek(todayDate, locale),
945
- end: endOfWeek(todayDate, locale)
946
- };
947
- };
948
- const getLastWeekRange = () => {
949
- const thisWeekStart = startOfWeek(todayDate, locale);
950
- return {
951
- start: thisWeekStart.subtract({ weeks: 1 }),
952
- end: thisWeekStart.subtract({ days: 1 })
953
- };
954
- };
955
- const getThisAndLastWeekRange = () => {
956
- const thisWeekEnd = endOfWeek(todayDate, locale);
957
- return {
958
- start: startOfWeek(todayDate, locale).subtract({ weeks: 1 }),
959
- end: thisWeekEnd
960
- };
961
- };
962
- const getThisMonthRange = () => {
963
- return {
964
- start: startOfMonth(todayDate),
965
- end: endOfMonth(todayDate)
966
- };
967
- };
968
- const getThisAndLastMonthRange = () => {
969
- const thisMonthEnd = endOfMonth(todayDate);
970
- return {
971
- start: startOfMonth(todayDate).subtract({ months: 1 }),
972
- end: thisMonthEnd
973
- };
974
- };
1016
+ const getPresetRange = (value) => () => getDateRangePreset(value, todayDate, locale);
975
1017
  const createPreset = (params) => {
976
1018
  let clampedValue = clampRangeToBounds(params.getValue());
977
1019
  let isDisabled = false;
@@ -1000,59 +1042,47 @@ const DateRangePickerBase = (props) => {
1000
1042
  createPreset({
1001
1043
  value: "thisWeek",
1002
1044
  label: t(($) => $.ui.datePicker.presets.thisWeek, { ns: "ui" }),
1003
- getValue: getThisWeekRange
1045
+ getValue: getPresetRange("thisWeek")
1004
1046
  }),
1005
1047
  createPreset({
1006
1048
  value: "lastWeek",
1007
1049
  label: t(($) => $.ui.datePicker.presets.lastWeek, { ns: "ui" }),
1008
- getValue: getLastWeekRange
1050
+ getValue: getPresetRange("lastWeek")
1009
1051
  }),
1010
1052
  createPreset({
1011
1053
  value: "thisAndLastWeek",
1012
1054
  label: t(($) => $.ui.datePicker.presets.thisAndLastWeek, { ns: "ui" }),
1013
- getValue: getThisAndLastWeekRange
1055
+ getValue: getPresetRange("thisAndLastWeek")
1014
1056
  }),
1015
1057
  createPreset({
1016
1058
  value: "thisMonth",
1017
1059
  label: t(($) => $.ui.datePicker.presets.thisMonth, { ns: "ui" }),
1018
- getValue: getThisMonthRange
1060
+ getValue: getPresetRange("thisMonth")
1019
1061
  }),
1020
1062
  createPreset({
1021
1063
  value: "thisAndLastMonth",
1022
1064
  label: t(($) => $.ui.datePicker.presets.thisAndLastMonth, { ns: "ui" }),
1023
- getValue: getThisAndLastMonthRange
1065
+ getValue: getPresetRange("thisAndLastMonth")
1024
1066
  }),
1025
1067
  createPreset({
1026
1068
  value: "thisYear",
1027
1069
  label: t(($) => $.ui.datePicker.presets.thisYear, { ns: "ui" }),
1028
- getValue: () => ({
1029
- start: startOfYear(todayDate),
1030
- end: todayDate
1031
- })
1070
+ getValue: getPresetRange("thisYear")
1032
1071
  }),
1033
1072
  createPreset({
1034
1073
  value: "lastYear",
1035
1074
  label: t(($) => $.ui.datePicker.presets.lastYear, { ns: "ui" }),
1036
- getValue: () => ({
1037
- start: startOfYear(todayDate.subtract({ years: 1 })),
1038
- end: endOfYear(todayDate.subtract({ years: 1 }))
1039
- })
1075
+ getValue: getPresetRange("lastYear")
1040
1076
  }),
1041
1077
  createPreset({
1042
1078
  value: "thisAndLastYear",
1043
1079
  label: t(($) => $.ui.datePicker.presets.thisAndLastYear, { ns: "ui" }),
1044
- getValue: () => ({
1045
- start: startOfYear(todayDate.subtract({ years: 1 })),
1046
- end: todayDate
1047
- })
1080
+ getValue: getPresetRange("thisAndLastYear")
1048
1081
  }),
1049
1082
  createPreset({
1050
1083
  value: "soFar",
1051
1084
  label: t(($) => $.ui.datePicker.presets.soFar, { ns: "ui" }),
1052
- getValue: () => ({
1053
- start: startOfYear(todayDate),
1054
- end: todayDate
1055
- }),
1085
+ getValue: getPresetRange("soFar"),
1056
1086
  keepEnabledUnlessFutureMin: true
1057
1087
  }),
1058
1088
  ...relativeOptions.map((option) => {
@@ -1470,4 +1500,4 @@ const DateRangePickerComponent = ({ fullIso = true, minValue, maxValue, renderSt
1470
1500
  };
1471
1501
  const DateRangePicker = memo(DateRangePickerComponent);
1472
1502
  //#endregion
1473
- export { DateRangePicker as t };
1503
+ export { isDateRangePresetValue as a, resolveDateRangePreset as c, hydrateRelativeDateRangeValue as i, dateRangePresetValues as n, isRelativeDateRangeValue as o, getDateRangePreset as r, isStoredRelativeDateRangeValue as s, DateRangePicker as t };
@@ -1,7 +1,7 @@
1
1
  import { t as PasswordInput } from "./PasswordInput-CMKZF3YS.js";
2
2
  import { t as Checkbox } from "./Checkbox-DUz32jLa.js";
3
3
  import { t as Slider } from "./Slider-BaPUnnLF.js";
4
- import { t as DateRangePicker } from "./DateRangePicker-DvRJMCFM.js";
4
+ import { t as DateRangePicker } from "./DateRangePicker-BEluwe3q.js";
5
5
  import { t as Toggle } from "./Toggle-JHUOY2Mh.js";
6
6
  import { t as TextArea } from "./TextArea-DGf6by6e.js";
7
7
  import { TextInput } from "./components/text-input.js";
@@ -1,4 +1,4 @@
1
- import { t as InputItem } from "./InputItem-BmdkOG5-.js";
1
+ import { t as InputItem } from "./InputItem-122JkDYJ.js";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  //#region src/components/inputs/Inputs/Inputs.tsx
4
4
  function Inputs({ form, inputDefs, children }) {
@@ -1,2 +1,27 @@
1
1
  import { a as DateRangeResolvedValue, i as DateRangeRelativeOption, n as DateRangePicker, r as DateRangePickerProps, t as ControlledDateRangePickerProps } from "../DateRangePicker-DLuRwuw1.js";
2
- export { type ControlledDateRangePickerProps, DateRangePicker, type DateRangePickerProps, type DateRangeRelativeOption, type DateRangeResolvedValue };
2
+ import { CalendarDate } from "@internationalized/date";
3
+ //#region src/components/inputs/DateTime/DateRangePicker/dateRangePreset.utils.d.ts
4
+ declare const dateRangePresetValues: readonly ["thisWeek", "lastWeek", "thisAndLastWeek", "thisMonth", "thisAndLastMonth", "thisYear", "lastYear", "thisAndLastYear", "soFar"];
5
+ type DateRangePresetValue = (typeof dateRangePresetValues)[number];
6
+ interface DateRangePreset {
7
+ start: CalendarDate;
8
+ end: CalendarDate;
9
+ }
10
+ interface ResolvedDateRangePreset {
11
+ start: string;
12
+ end: string;
13
+ }
14
+ interface StoredRelativeDateRangeValue {
15
+ relativeValue: string;
16
+ }
17
+ interface RelativeDateRangeValue extends StoredRelativeDateRangeValue {
18
+ resolvedValue: ResolvedDateRangePreset;
19
+ }
20
+ declare const isStoredRelativeDateRangeValue: (value: unknown) => value is StoredRelativeDateRangeValue;
21
+ declare const isRelativeDateRangeValue: (value: unknown) => value is RelativeDateRangeValue;
22
+ declare const isDateRangePresetValue: (value: string) => value is DateRangePresetValue;
23
+ declare const getDateRangePreset: (value: string, currentDate?: CalendarDate, locale?: string) => DateRangePreset | undefined;
24
+ declare const resolveDateRangePreset: (value: string, currentDate?: CalendarDate, locale?: string) => ResolvedDateRangePreset | undefined;
25
+ declare const hydrateRelativeDateRangeValue: (value: StoredRelativeDateRangeValue, currentDate?: CalendarDate, locale?: string) => RelativeDateRangeValue | undefined;
26
+ //#endregion
27
+ export { type ControlledDateRangePickerProps, DateRangePicker, type DateRangePickerProps, type DateRangePreset, type DateRangePresetValue, type DateRangeRelativeOption, type DateRangeResolvedValue, type RelativeDateRangeValue, type ResolvedDateRangePreset, type StoredRelativeDateRangeValue, dateRangePresetValues, getDateRangePreset, hydrateRelativeDateRangeValue, isDateRangePresetValue, isRelativeDateRangeValue, isStoredRelativeDateRangeValue, resolveDateRangePreset };
@@ -1,2 +1,2 @@
1
- import { t as DateRangePicker } from "../DateRangePicker-DvRJMCFM.js";
2
- export { DateRangePicker };
1
+ import { a as isDateRangePresetValue, c as resolveDateRangePreset, i as hydrateRelativeDateRangeValue, n as dateRangePresetValues, o as isRelativeDateRangeValue, r as getDateRangePreset, s as isStoredRelativeDateRangeValue, t as DateRangePicker } from "../DateRangePicker-BEluwe3q.js";
2
+ export { DateRangePicker, dateRangePresetValues, getDateRangePreset, hydrateRelativeDateRangeValue, isDateRangePresetValue, isRelativeDateRangeValue, isStoredRelativeDateRangeValue, resolveDateRangePreset };
@@ -1,4 +1,4 @@
1
- import { t as DateRangePicker$1 } from "../DateRangePicker-DvRJMCFM.js";
1
+ import { t as DateRangePicker$1 } from "../DateRangePicker-BEluwe3q.js";
2
2
  import { n as runtime, r as useFireBlurOnChange, t as renderRHFField } from "../fieldAdapter-C2YfWBmM.js";
3
3
  import { n as toCalendarDateRange } from "../date.transforms-DLg-eFcE.js";
4
4
  //#region src/entries/rhf/date-range-picker.ts
@@ -1,2 +1,2 @@
1
- import { t as DateRangePicker } from "../DateRangePicker-DvRJMCFM.js";
1
+ import { t as DateRangePicker } from "../DateRangePicker-BEluwe3q.js";
2
2
  export { DateRangePicker };
@@ -1,2 +1,2 @@
1
- import { i as useFormValue, n as useForm, o as Form, r as useFormState, t as useFormAutosave } from "../useFormAutosave-CBtT6V83.js";
1
+ import { i as useFormValue, n as useForm, o as Form, r as useFormState, t as useFormAutosave } from "../useFormAutosave-DTv1J6w2.js";
2
2
  export { Form, useForm, useFormAutosave, useFormState, useFormValue };
@@ -1,3 +1,3 @@
1
1
  import { t as dynamicInputs } from "../dynamicInputs-0GjoOaz5.js";
2
- import { t as Inputs } from "../Inputs-uXqCGqG4.js";
2
+ import { t as Inputs } from "../Inputs-BT0CNY2g.js";
3
3
  export { Inputs, dynamicInputs };
package/dist/tanstack.js CHANGED
@@ -14,7 +14,7 @@ import { a as breadcrumbSegmentDefinition, i as breadcrumbItemDefinition, n as b
14
14
  import { t as Checkbox } from "./Checkbox-DUz32jLa.js";
15
15
  import { t as Slider } from "./Slider-BaPUnnLF.js";
16
16
  import { n as useScrollableListBox } from "./Calendar-KJOP6Bcq.js";
17
- import { t as DateRangePicker } from "./DateRangePicker-DvRJMCFM.js";
17
+ import { t as DateRangePicker } from "./DateRangePicker-BEluwe3q.js";
18
18
  import { a as accordionHeadingSubtitleDefinition, c as accordionItemDefinition, d as accordionTriggerDefinition, i as accordionHeadingDefinition, l as accordionPanelContentDefinition, n as accordionChevronDefinition, o as accordionHeadingTitleDefinition, r as accordionDefinition, s as accordionIconDefinition, t as Accordion, u as accordionPanelDefinition } from "./Accordion-BKBl-2EO.js";
19
19
  import { i as radioDefinition, n as radioContentRowDefinition, r as radioContentWrapperDefinition, t as RadioGroup } from "./RadioGroup-oU2t4qb_.js";
20
20
  import { n as toggleDefinition, t as Toggle } from "./Toggle-JHUOY2Mh.js";
@@ -91,6 +91,6 @@ import { t as RoutingUtils } from "./routing.utils-UTQonIhB.js";
91
91
  import { t as useFilters } from "./useFilters-20jpzc29.js";
92
92
  import { n as useStateAndRef, t as DomUtils } from "./dom.utils-BOIN4YDz.js";
93
93
  import { n as ArrayUtils, t as QueriesUtils } from "./queries.utils-CmbhAoHU.js";
94
- import { a as useAutosave, i as useFormValue, n as useForm, o as Form, r as useFormState, t as useFormAutosave } from "./useFormAutosave-CBtT6V83.js";
95
- import { t as Inputs } from "./Inputs-uXqCGqG4.js";
94
+ import { a as useAutosave, i as useFormValue, n as useForm, o as Form, r as useFormState, t as useFormAutosave } from "./useFormAutosave-DTv1J6w2.js";
95
+ import { t as Inputs } from "./Inputs-BT0CNY2g.js";
96
96
  export { Accordion, ActionModal, Alert, ArrayUtils, Autocomplete, BottomSheet, Breadcrumbs, Button, CellText, Checkbox, CheckboxGroup, X as CloseIcon, ColumnConfigModal, Confirmation, DatePicker, DateRangePicker, DateTimePicker, DateTimeUtils, DateUtils, DomUtils, Drawer, FileUpload, FileUploadContainer, FileUtils, Form, FormField, HeaderText, IconButton, InfiniteTable, InlineIconButton, InputUpload, Inputs, IntlUtils, Link, LinkContext, Loader, Menu, MenuItem, MenuPopover, Modal, NumberInput, NumberRangeInput, ObjectUtils, PaginatedTable, Pagination, PaginationList, PasswordInput, Pill, PillButton, ProgressBar, QueriesUtils, QueryAutocomplete, QuerySelect, RadioGroup, ResponsivePopover, RoutingUtils, Segment, Select, Slider, SplitButton, Stepper, StringUtils, Table, Tag, TextArea, TextButton, TextInput, ThemeContext, TimePicker, Toast, ToastContainer, ToastProvider, Toggle, ToggleButton, Tooltip, TooltipEllipsis, Typography, UIConfig, UIOverrides, UIRouter, ZodUtils, accordionChevronDefinition, accordionDefinition, accordionHeadingDefinition, accordionHeadingSubtitleDefinition, accordionHeadingTitleDefinition, accordionIconDefinition, accordionItemDefinition, accordionPanelContentDefinition, accordionPanelDefinition, accordionTriggerDefinition, alertDefinition, breadcrumbChevronDefinition, breadcrumbIconDefinition, breadcrumbItemDefinition, breadcrumbSegmentDefinition, breadcrumbsDefinition, buttonContentDefinition, buttonDefinition, buttonIconSizeDefinition, buttonSizeDefinition, checkboxContentRowDefinition, checkboxContentWrapperDefinition, checkboxDefinition, checkboxGroupLabelDefinition, checkboxIconDefinition, compoundMapper, createKeyInteractionsHandler, datePickerInputContentRowDefinition, dynamicColumns, dynamicInputs, fileUploadDropZoneDefinition, formFieldErrorDefinition, formFieldHeaderDefinition, formFieldHelperDefinition, getKeyInteractionAction, inputBaseDefinition, inputClearClassDefinition, inputContentWrapperDefinition, inputSideDefinition, inputSizeDefinition, inputUploadButtonDefinition, inputUploadDropZoneDefinition, isEqual, labelDefinition, linkDefinition, loaderDefinition, loaderWrapperDefinition, logger, menuDefinition, menuItemDefinition, menuPopoverDefinition, menuPopoverWrapperDefinition, modalContentDefinition, modalMainDefinition, modalOverlayDefinition, ns, pillButtonContentDefinition, pillButtonDefinition, popoverDefinition, progressBarDefinition, progressBarFillDefinition, progressBarTrackDefinition, progressBarTrackWrapperDefinition, progressBarValueDefinition, radioContentRowDefinition, radioContentWrapperDefinition, radioDefinition, resources, segmentDefinition, segmentItemDefinition, selectInputTagsContentWrapperDefinition, selectListBoxItemDefinition, selectPopoverDefinition, statusIconDefinition, statusSeparatorDefinition, stepperDefinition, stepperIconDefinition, stepperItemDefinition, stepperNumberDefinition, stepperSeparatorDefinition, stepperSubtextDefinition, stepperTitleDefinition, tableCellTextDefinition, tableDataDefinition, tableHeadDataDefinition, tableHeadRowDefinition, tableHeaderTextDefinition, tableRowDefinition, tagDefinition, textAreaWrapperDefinition, toastDefinition, statusIconDefinition$1 as toastStatusIconDefinition, statusSeparatorDefinition$1 as toastStatusSeparatorDefinition, toggleDefinition, tooltipDefinition, tooltipPointerHorizontalDefinition, tooltipPointerVerticalDefinition, tooltipTextDefinition, tooltipWrapperTriggerDefinition, typographyDefinition, uiOutlineClass, useAutosave, useBreakpoint, useDebounceCallback, useDeepCompareEffect, useDeepCompareLayoutEffect, useDeepCompareMemo, useFilters, useForm, useFormAutosave, useFormState, useFormValue, useIntersectionObserver, useKeyInteractions, useLocalStorage, useLongPressRepeat, usePagination, useScrollableListBox, useSorting, useStateAndRef, useTableColumnConfig, useTableNav, useToast, useTranslationMemo };
@@ -2,7 +2,7 @@ import { a as isEqual, o as ObjectUtils } from "./uiConfig.context-BG4jfp9p.js";
2
2
  import { t as StringUtils } from "./string.utils-BPgv6QwA.js";
3
3
  import { t as ZodUtils } from "./zod.utils-DrrPDT9v.js";
4
4
  import { n as getDefaultInputComponentType } from "./dynamicInputs-0GjoOaz5.js";
5
- import { t as InputItem } from "./InputItem-BmdkOG5-.js";
5
+ import { t as InputItem } from "./InputItem-122JkDYJ.js";
6
6
  import { useCallback, useEffect, useMemo, useRef } from "react";
7
7
  import { c } from "react/compiler-runtime";
8
8
  import { jsx } from "react/jsx-runtime";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "3.4.0-rc.39",
3
+ "version": "3.4.0-rc.40",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",