@superdispatch/dates 0.16.0-alpha.0 → 0.16.0-alpha.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-web/index.js CHANGED
@@ -2,7 +2,7 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
3
3
  import { Typography, IconButton, Grid, Hidden, Divider, ListItem, List, Popover, TextField, InputAdornment, SvgIcon, Autocomplete } from '@mui/material';
4
4
  import { makeStyles } from '@mui/styles';
5
- import { Color, v5, renderChildren, useUID as useUID$1, mergeRefs as mergeRefs$1 } from '@superdispatch/ui';
5
+ import { Color, useUID, mergeRefs, renderChildren } from '@superdispatch/ui';
6
6
  import { Settings, FixedOffsetZone, DateTime } from 'luxon';
7
7
  import { useMemo, useContext, createContext, forwardRef, useRef, useState, useImperativeHandle, useEffect } from 'react';
8
8
  import DayPicker from 'react-day-picker';
@@ -10,10 +10,6 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import { ChevronLeft, ChevronRight, Clear } from '@mui/icons-material';
11
11
  import { mdiCalendarMonth } from '@mdi/js';
12
12
  import { useValueObserver } from '@superdispatch/hooks';
13
- import { Typography as Typography$1, IconButton as IconButton$1, Grid as Grid$1, Hidden as Hidden$1, Divider as Divider$1, ListItem as ListItem$1, List as List$1, Popover as Popover$1, TextField as TextField$1, InputAdornment as InputAdornment$1, SvgIcon as SvgIcon$1 } from '@material-ui/core';
14
- import { makeStyles as makeStyles$1 } from '@material-ui/styles';
15
- import { ChevronLeft as ChevronLeft$1, ChevronRight as ChevronRight$1, Clear as Clear$1 } from '@material-ui/icons';
16
- import { Autocomplete as Autocomplete$1 } from '@material-ui/lab';
17
13
 
18
14
  function setDefaultTimeZone(offset) {
19
15
  if (offset === 'local') {
@@ -799,10 +795,6 @@ var CalendarQuickSelection = /*#__PURE__*/forwardRef((_ref2, ref) => {
799
795
  if (process.env.NODE_ENV !== "production") CalendarQuickSelection.displayName = "CalendarQuickSelection";
800
796
 
801
797
  var _excluded$1 = ["id", "api", "onClear", "onClick", "onClose", "onKeyDown", "disabled", "children", "enableClearable", "inputRef", "InputProps"];
802
- var {
803
- mergeRefs,
804
- useUID
805
- } = v5;
806
798
  var BaseDatePicker = /*#__PURE__*/forwardRef((_ref, ref) => {
807
799
  var {
808
800
  id,
@@ -1680,1710 +1672,5 @@ var TimeField = /*#__PURE__*/forwardRef((_ref2, ref) => {
1680
1672
  });
1681
1673
  if (process.env.NODE_ENV !== "production") TimeField.displayName = "TimeField";
1682
1674
 
1683
-
1684
-
1685
- var index = /*#__PURE__*/Object.freeze({
1686
- __proto__: null,
1687
- Calendar: Calendar,
1688
- CalendarQuickSelectionItem: CalendarQuickSelectionItem,
1689
- CalendarQuickSelection: CalendarQuickSelection,
1690
- setDefaultTimeZone: setDefaultTimeZone,
1691
- useDefaultTimeZone: useDefaultTimeZone,
1692
- defaultDateConfig: defaultDateConfig,
1693
- useDateConfig: useDateConfig,
1694
- DateConfigProvider: DateConfigProvider,
1695
- DateField: DateField,
1696
- DateRangeField: DateRangeField,
1697
- toPrimitiveDateInput: toPrimitiveDateInput,
1698
- parseDate: parseDate,
1699
- stringifyDate: stringifyDate,
1700
- formatDate: formatDate,
1701
- formatRelativeTime: formatRelativeTime,
1702
- toDatePayload: toDatePayload,
1703
- toPrimitiveDateRangeInput: toPrimitiveDateRangeInput,
1704
- parseDateRange: parseDateRange,
1705
- stringifyDateRange: stringifyDateRange,
1706
- formatDateRange: formatDateRange,
1707
- toDateRangePayload: toDateRangePayload,
1708
- isDate: isDate,
1709
- isDateLike: isDateLike,
1710
- isValidDate: isValidDate,
1711
- isDateRange: isDateRange,
1712
- isDateRangeLike: isDateRangeLike,
1713
- isValidDateRange: isValidDateRange,
1714
- toDate: toDate,
1715
- toDateRange: toDateRange,
1716
- DateUtils: DateUtils,
1717
- useDateUtils: useDateUtils,
1718
- useFormattedDate: useFormattedDate,
1719
- FormattedDate: FormattedDate,
1720
- useFormattedRelativeTime: useFormattedRelativeTime,
1721
- FormattedRelativeTime: FormattedRelativeTime,
1722
- TimeField: TimeField,
1723
- useDateTimeRange: useDateTimeRange,
1724
- useDateTime: useDateTime
1725
- });
1726
-
1727
- function setDefaultTimeZone$1(offset) {
1728
- if (offset === 'local') {
1729
- Settings.defaultZoneName = offset;
1730
- } else {
1731
- var zone = FixedOffsetZone.instance(offset);
1732
-
1733
- if (zone.isValid) {
1734
- Settings.defaultZoneName = zone.name;
1735
- }
1736
- }
1737
-
1738
- return Settings.defaultZoneName;
1739
- }
1740
- function useDefaultTimeZone$1(offset) {
1741
- return useMemo(() => setDefaultTimeZone$1(offset), [offset]);
1742
- }
1743
- var defaultDateConfig$1 = {
1744
- format: 'DateTimeISO'
1745
- };
1746
- var Context$1 = /*#__PURE__*/createContext(defaultDateConfig$1);
1747
- function useDateConfig$1() {
1748
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1749
- var config = useContext(Context$1);
1750
- var {
1751
- format = config.format
1752
- } = options;
1753
- return useMemo(() => ({
1754
- format
1755
- }), [format]);
1756
- }
1757
- function DateConfigProvider$1(_ref) {
1758
- var {
1759
- format,
1760
- children
1761
- } = _ref;
1762
- var prev = useDateConfig$1();
1763
- var ctx = useMemo(() => ({
1764
- format: format || prev.format
1765
- }), [format, prev.format]);
1766
- return /*#__PURE__*/jsx(Context$1.Provider, {
1767
- value: ctx,
1768
- children: children
1769
- });
1770
- }
1771
-
1772
- // Config
1773
- //
1774
-
1775
- var DATE_FORMATS$1 = {
1776
- DateISO: '',
1777
- DateTimeISO: '',
1778
- JodaISO: "yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"
1779
- };
1780
- var DATE_DISPLAY_VARIANTS$1 = {
1781
- Date: {
1782
- day: '2-digit',
1783
- month: 'short',
1784
- year: 'numeric'
1785
- },
1786
- ShortDate: {
1787
- day: '2-digit',
1788
- month: 'short'
1789
- },
1790
- Time: {
1791
- hour: 'numeric',
1792
- minute: 'numeric'
1793
- },
1794
- DateTime: {
1795
- day: '2-digit',
1796
- month: 'short',
1797
- year: 'numeric',
1798
- hour: 'numeric',
1799
- minute: 'numeric'
1800
- }
1801
- }; //
1802
- // Date Utils
1803
- //
1804
-
1805
- function toPrimitiveDateInput$1(input) {
1806
- if (typeof input == 'number' || typeof input == 'string') {
1807
- return input;
1808
- }
1809
-
1810
- if (input instanceof Date || input instanceof DateTime) {
1811
- return input.valueOf();
1812
- }
1813
-
1814
- return NaN;
1815
- }
1816
- function parseDate$1(input) {
1817
- var {
1818
- format
1819
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1820
-
1821
- if (input instanceof DateTime) {
1822
- var {
1823
- defaultZone
1824
- } = Settings;
1825
-
1826
- if (!defaultZone.equals(input.zone)) {
1827
- return input.setZone(defaultZone);
1828
- }
1829
-
1830
- return input;
1831
- }
1832
-
1833
- if (input instanceof Date) {
1834
- return DateTime.fromJSDate(input);
1835
- }
1836
-
1837
- if (typeof input === 'number') {
1838
- return DateTime.fromMillis(input);
1839
- }
1840
-
1841
- if (typeof input == 'string') {
1842
- switch (format) {
1843
- case 'DateISO':
1844
- case 'DateTimeISO':
1845
- return DateTime.fromISO(input);
1846
-
1847
- default:
1848
- return DateTime.fromFormat(input, DATE_FORMATS$1[format]);
1849
- }
1850
- }
1851
-
1852
- return DateTime.invalid('invalid input');
1853
- }
1854
- function stringifyDate$1(input) {
1855
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1856
- var date = parseDate$1(input, config);
1857
-
1858
- if (date.isValid) {
1859
- var {
1860
- format
1861
- } = config;
1862
-
1863
- switch (format) {
1864
- case 'DateISO':
1865
- return date.toISODate();
1866
-
1867
- case 'DateTimeISO':
1868
- return date.toISO();
1869
-
1870
- default:
1871
- return date.toFormat(DATE_FORMATS$1[format]);
1872
- }
1873
- }
1874
-
1875
- return null;
1876
- }
1877
- function formatDate$1(input, _ref) {
1878
- var {
1879
- variant,
1880
- fallback = 'Invalid Date'
1881
- } = _ref;
1882
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1883
- var date = parseDate$1(input, config);
1884
-
1885
- if (!date.isValid) {
1886
- return fallback;
1887
- }
1888
-
1889
- return date.toLocaleString(DATE_DISPLAY_VARIANTS$1[variant]);
1890
- }
1891
-
1892
- function formatUnit$1(unit) {
1893
- switch (unit) {
1894
- case 'months':
1895
- return 'mo';
1896
-
1897
- default:
1898
- return unit.charAt(0);
1899
- }
1900
- }
1901
-
1902
- function formatRelativeTime$1(input) {
1903
- var {
1904
- round = true,
1905
- unit: unitOption,
1906
- base: baseOption,
1907
- padding: paddingOption,
1908
- fallback = 'Invalid Date'
1909
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1910
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1911
- var base = baseOption == null ? DateTime.now() : parseDate$1(baseOption, config);
1912
- var date = parseDate$1(input, config);
1913
- var padding = paddingOption ? date < base ? -paddingOption : paddingOption : 0;
1914
-
1915
- function format(value, unit) {
1916
- var isPast = Object.is(value, -0) || value < 0;
1917
- var diff = Math.abs(!round ? value : Math.trunc(value));
1918
- var formattedUnit = formatUnit$1(unit);
1919
- return isPast ? "".concat(diff).concat(formattedUnit, " ago") : "in ".concat(diff).concat(formattedUnit);
1920
- }
1921
-
1922
- function differ(unit) {
1923
- return date.plus(padding).diff(base, unit).get(unit);
1924
- }
1925
-
1926
- if (date.isValid && base.isValid) {
1927
- var units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
1928
-
1929
- if (unitOption) {
1930
- return format(differ(unitOption), unitOption);
1931
- }
1932
-
1933
- for (var unit of units) {
1934
- var diff = differ(unit);
1935
-
1936
- if (Math.abs(diff) >= 1) {
1937
- return format(diff, unit);
1938
- }
1939
- }
1940
-
1941
- return format(0, 'seconds');
1942
- }
1943
-
1944
- return fallback;
1945
- }
1946
- function toDatePayload$1(input) {
1947
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
1948
- var dateValue = parseDate$1(input, config);
1949
- return {
1950
- config,
1951
- dateValue,
1952
- stringValue: stringifyDate$1(dateValue, config)
1953
- };
1954
- } //
1955
- // Date Range Utils
1956
- //
1957
-
1958
- function toPrimitiveDateRangeInput$1(input) {
1959
- if (!Array.isArray(input)) {
1960
- return [undefined, undefined];
1961
- }
1962
-
1963
- return [toPrimitiveDateInput$1(input[0]), toPrimitiveDateInput$1(input[1])];
1964
- }
1965
- function parseDateRange$1(input, config) {
1966
- var start = null;
1967
- var finish = null;
1968
-
1969
- if (Array.isArray(input)) {
1970
- [start = null, finish = null] = input.map(value => parseDate$1(value, config)).filter(date => date.isValid).sort((a, b) => a.valueOf() - b.valueOf());
1971
- }
1972
-
1973
- return [start, finish];
1974
- }
1975
- function stringifyDateRange$1(input, config) {
1976
- var [start, finish] = parseDateRange$1(input, config);
1977
- return [stringifyDate$1(start, config), stringifyDate$1(finish, config)];
1978
- }
1979
- function formatDateRange$1(input, _ref2) {
1980
- var {
1981
- fallback = 'Invalid Date Range'
1982
- } = _ref2;
1983
- var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig$1;
1984
- var [start, finish] = parseDateRange$1(input, config);
1985
-
1986
- if (!start) {
1987
- return fallback;
1988
- }
1989
-
1990
- var startVariant = !(finish !== null && finish !== void 0 && finish.hasSame(start, 'year')) ? 'Date' : 'ShortDate';
1991
- var startText = formatDate$1(start, {
1992
- variant: startVariant
1993
- }, config);
1994
- var finishText = !finish ? '…' : formatDate$1(finish, {
1995
- variant: 'Date'
1996
- });
1997
- return "".concat(startText, " - ").concat(finishText);
1998
- }
1999
- function toDateRangePayload$1(input) {
2000
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig$1;
2001
- var dateValue = parseDateRange$1(input, config);
2002
- return {
2003
- config,
2004
- dateValue,
2005
- stringValue: stringifyDateRange$1(dateValue, config)
2006
- };
2007
- }
2008
-
2009
- function useDateTime$1(input, options) {
2010
- var config = useDateConfig$1(options);
2011
- var primitiveInput = toPrimitiveDateInput$1(input);
2012
- return useMemo(() => {
2013
- var date = parseDate$1(primitiveInput, config);
2014
-
2015
- if (process.env.NODE_ENV !== 'production') {
2016
- if (!date.isValid && typeof primitiveInput === 'string') {
2017
- // eslint-disable-next-line no-console
2018
- console.error("[useDateTime] Failed to parse \"".concat(primitiveInput, "\" string with \"").concat(config.format, "\" format."));
2019
- }
2020
- }
2021
-
2022
- return date;
2023
- }, [config, primitiveInput]);
2024
- }
2025
-
2026
- function CalendarCaption$1(_ref) {
2027
- var {
2028
- date,
2029
- localeUtils,
2030
- classNames,
2031
- onClick
2032
- } = _ref;
2033
- return /*#__PURE__*/jsx(Typography$1, {
2034
- variant: "h4",
2035
- onClick: onClick,
2036
- className: classNames.caption,
2037
- children: localeUtils.formatMonthTitle(date)
2038
- });
2039
- }
2040
- function CalendarNavbar$1(_ref2) {
2041
- var {
2042
- labels,
2043
- classNames,
2044
- onNextClick,
2045
- onPreviousClick,
2046
- showNextButton,
2047
- showPreviousButton
2048
- } = _ref2;
2049
- return /*#__PURE__*/jsxs(Fragment, {
2050
- children: [/*#__PURE__*/jsx(IconButton$1, {
2051
- size: "small",
2052
- color: "primary",
2053
- disabled: !showPreviousButton,
2054
- onClick: () => {
2055
- onPreviousClick();
2056
- },
2057
- "aria-label": labels.previousMonth,
2058
- className: classNames.navButtonPrev,
2059
- children: /*#__PURE__*/jsx(ChevronLeft$1, {
2060
- color: "action"
2061
- })
2062
- }), /*#__PURE__*/jsx(IconButton$1, {
2063
- size: "small",
2064
- color: "primary",
2065
- disabled: !showNextButton,
2066
- onClick: () => {
2067
- onNextClick();
2068
- },
2069
- "aria-label": labels.nextMonth,
2070
- className: classNames.navButtonNext,
2071
- children: /*#__PURE__*/jsx(ChevronRight$1, {
2072
- color: "action"
2073
- })
2074
- })]
2075
- });
2076
- }
2077
- var SHORT_WEEKDAYS$1 = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
2078
- function CalendarWeekDay$1(_ref3) {
2079
- var {
2080
- weekday,
2081
- className,
2082
- localeUtils
2083
- } = _ref3;
2084
- return /*#__PURE__*/jsx(Typography$1, {
2085
- variant: "h5",
2086
- component: "abbr",
2087
- className: className,
2088
- title: localeUtils.formatWeekdayLong(weekday),
2089
- children: SHORT_WEEKDAYS$1[weekday]
2090
- });
2091
- }
2092
-
2093
- var _excluded$7 = ["footer", "classes", "direction", "quickSelection", "selectedDays", "disabledDays", "onDayClick", "onDayKeyDown", "onDayMouseEnter", "onDayMouseLeave", "onDayMouseDown", "onDayMouseUp", "onDayTouchEnd", "onDayTouchStart", "modifiers", "highlightedDays", "format", "initialTime", "initialMonth"];
2094
- var useStyles$2 = /*#__PURE__*/makeStyles$1(theme => ({
2095
- container: {
2096
- display: 'inline-block'
2097
- },
2098
- wrapper: {
2099
- userSelect: 'none',
2100
- position: 'relative',
2101
- flexDirection: 'row',
2102
- paddingBottom: theme.spacing(2),
2103
- '&:focus': {
2104
- outline: 'none'
2105
- }
2106
- },
2107
- interactionDisabled: {},
2108
- navBar: {},
2109
- navButtonPrev: {
2110
- position: 'absolute',
2111
- top: theme.spacing(1.5),
2112
- left: theme.spacing(1.5)
2113
- },
2114
- navButtonNext: {
2115
- position: 'absolute',
2116
- top: theme.spacing(1.5),
2117
- right: theme.spacing(1.5)
2118
- },
2119
- navButtonInteractionDisabled: {},
2120
- months: {
2121
- display: 'flex',
2122
- flexWrap: 'wrap',
2123
- justifyContent: 'center'
2124
- },
2125
- month: {
2126
- userSelect: 'none',
2127
- margin: theme.spacing(2, 2, 0, 2)
2128
- },
2129
- caption: {
2130
- textAlign: 'center',
2131
- display: 'table-caption',
2132
- marginBottom: theme.spacing(1),
2133
- padding: theme.spacing(0, 1)
2134
- },
2135
- weekdays: {
2136
- display: 'table-header-group'
2137
- },
2138
- weekdaysRow: {
2139
- display: 'flex',
2140
- margin: theme.spacing(1, 0)
2141
- },
2142
- weekday: {
2143
- margin: '1px',
2144
- display: 'flex',
2145
- alignItems: 'center',
2146
- justifyContent: 'center',
2147
- textDecoration: 'none',
2148
- color: Color.Dark300,
2149
- width: theme.spacing(5),
2150
- height: theme.spacing(5)
2151
- },
2152
- weekNumber: {},
2153
- body: {
2154
- display: 'flex',
2155
- flexDirection: 'column'
2156
- },
2157
- week: {
2158
- display: 'flex'
2159
- },
2160
- // Day modifiers.
2161
- today: {},
2162
- outside: {},
2163
- selected: {},
2164
- disabled: {},
2165
- firstDayOfMonth: {},
2166
- lastDayOfMonth: {},
2167
- blue: {},
2168
- green: {},
2169
- purple: {},
2170
- red: {},
2171
- teal: {},
2172
- yellow: {},
2173
- day: {
2174
- zIndex: 1,
2175
- margin: '1px',
2176
- width: theme.spacing(5),
2177
- height: theme.spacing(5),
2178
- borderRadius: theme.spacing(0.5),
2179
- position: 'relative',
2180
- display: 'flex',
2181
- alignItems: 'center',
2182
- justifyContent: 'center',
2183
- transition: theme.transitions.create(['color', 'background-color']),
2184
- '&:before': {
2185
- content: '""',
2186
- top: 0,
2187
- left: -1,
2188
- right: -1,
2189
- bottom: 0,
2190
- zIndex: -1,
2191
- position: 'absolute',
2192
- backgroundColor: Color.Transparent,
2193
- transition: theme.transitions.create('background-color')
2194
- },
2195
- '&:first-child, &$firstDayOfMonth': {
2196
- '&:before': {
2197
- borderRadius: theme.spacing(0.5, 0, 0, 0.5)
2198
- }
2199
- },
2200
- '&:last-child, &$lastDayOfMonth': {
2201
- '&:before': {
2202
- borderRadius: theme.spacing(0, 0.5, 0.5, 0)
2203
- }
2204
- },
2205
- '&:after': {
2206
- content: '""',
2207
- borderRadius: theme.spacing(0.5),
2208
- top: 0,
2209
- left: 0,
2210
- right: 0,
2211
- bottom: 0,
2212
- zIndex: -1,
2213
- position: 'absolute',
2214
- backgroundColor: Color.Transparent,
2215
- transition: theme.transitions.create('background-color')
2216
- },
2217
- '&:hover, &:focus': {
2218
- outline: 'none'
2219
- },
2220
- '&$disabled': {
2221
- color: Color.Dark100,
2222
- '&$selected:not($outside):after': {
2223
- backgroundColor: Color.Silver300
2224
- }
2225
- },
2226
- '&:not($outside):not($disabled)': {
2227
- cursor: 'pointer',
2228
- color: Color.Dark500,
2229
- '&:not($selected):not(:active)': {
2230
- '&$today': {
2231
- color: Color.Blue300
2232
- },
2233
- '&:hover, &:focus': {
2234
- backgroundColor: Color.Silver100
2235
- },
2236
- '&$blue': {
2237
- color: Color.Blue500,
2238
- '&': {
2239
- backgroundColor: Color.Blue50
2240
- }
2241
- },
2242
- '&$green': {
2243
- color: Color.Green500,
2244
- '&': {
2245
- backgroundColor: Color.Green50
2246
- }
2247
- },
2248
- '&$purple': {
2249
- color: Color.Purple500,
2250
- '&': {
2251
- backgroundColor: Color.Purple50
2252
- }
2253
- },
2254
- '&$red': {
2255
- color: Color.Red500,
2256
- '&': {
2257
- backgroundColor: Color.Red50
2258
- }
2259
- },
2260
- '&$teal': {
2261
- color: Color.Teal500,
2262
- '&': {
2263
- backgroundColor: Color.Teal50
2264
- }
2265
- },
2266
- '&$yellow': {
2267
- color: Color.Yellow500,
2268
- '&': {
2269
- backgroundColor: Color.Yellow50
2270
- }
2271
- }
2272
- },
2273
- '&:active, &$selected': {
2274
- color: Color.White,
2275
- '&:after': {
2276
- backgroundColor: Color.Blue300
2277
- }
2278
- }
2279
- }
2280
- },
2281
- footer: {
2282
- padding: theme.spacing(2)
2283
- },
2284
- todayButton: {}
2285
- }), {
2286
- name: 'SD-Calendar'
2287
- }); //
2288
- // Utility Types
2289
- //
2290
-
2291
- //
2292
- // Internal Utils
2293
- //
2294
- function toDayPickerModifier$1(config, modifier) {
2295
- if (!modifier) {
2296
- return undefined;
2297
- }
2298
-
2299
- return localDate => {
2300
- var dateValue = DateTime.fromObject({
2301
- year: localDate.getFullYear(),
2302
- month: localDate.getMonth() + 1,
2303
- day: localDate.getDate(),
2304
- hour: localDate.getHours(),
2305
- minute: localDate.getMinutes(),
2306
- second: localDate.getSeconds(),
2307
- millisecond: localDate.getMilliseconds()
2308
- });
2309
- return modifier({
2310
- config,
2311
- dateValue,
2312
- stringValue: stringifyDate$1(dateValue, config)
2313
- });
2314
- };
2315
- }
2316
-
2317
- function toDayPickerHandler$1(config, classes, initialTime, handler) {
2318
- if (!handler) {
2319
- return undefined;
2320
- }
2321
-
2322
- return (localDate, modifiers) => {
2323
- var dateValue = DateTime.fromObject({
2324
- year: localDate.getFullYear(),
2325
- month: localDate.getMonth() + 1,
2326
- day: localDate.getDate(),
2327
- hour: initialTime.hour,
2328
- minute: initialTime.minute,
2329
- second: initialTime.second,
2330
- millisecond: initialTime.millisecond
2331
- });
2332
- handler({
2333
- disabled: !!modifiers[classes.disabled],
2334
- selected: !!modifiers[classes.selected],
2335
- config,
2336
- dateValue,
2337
- stringValue: stringifyDate$1(dateValue, config)
2338
- });
2339
- };
2340
- } //
2341
- // Calendar
2342
- //
2343
-
2344
-
2345
- var Calendar$1 = /*#__PURE__*/forwardRef((_ref, ref) => {
2346
- var {
2347
- footer,
2348
- classes,
2349
- direction,
2350
- quickSelection,
2351
- selectedDays,
2352
- disabledDays,
2353
- onDayClick,
2354
- onDayKeyDown,
2355
- onDayMouseEnter,
2356
- onDayMouseLeave,
2357
- onDayMouseDown,
2358
- onDayMouseUp,
2359
- onDayTouchEnd,
2360
- onDayTouchStart,
2361
- modifiers,
2362
- highlightedDays,
2363
- format: formatProp,
2364
- initialTime: initialTimeInputProp,
2365
- initialMonth: initialMonthInputProp
2366
- } = _ref,
2367
- dayPickerProps = _objectWithoutProperties(_ref, _excluded$7);
2368
-
2369
- var styles = useStyles$2({
2370
- classes
2371
- });
2372
- var config = useDateConfig$1({
2373
- format: formatProp
2374
- });
2375
- var initialTimeInput = useDateTime$1(initialTimeInputProp, config);
2376
- var initialMonthInput = useDateTime$1(initialMonthInputProp, config);
2377
- var [initialTime, initialMonth] = useMemo(() => {
2378
- var time = initialTimeInput;
2379
- var month = initialMonthInput;
2380
-
2381
- if (!month.isValid) {
2382
- month = DateTime.local().startOf('month');
2383
- }
2384
-
2385
- if (!time.isValid) {
2386
- time = month;
2387
- }
2388
-
2389
- return [time, new Date(month.year, month.month - 1, month.day, month.hour, month.minute, month.second, month.millisecond)];
2390
- }, [initialTimeInput, initialMonthInput]);
2391
- var wrapModifier = toDayPickerModifier$1.bind(null, config);
2392
- var wrapHandler = toDayPickerHandler$1.bind(null, config, styles, initialTime);
2393
- var dayPickerModifiers = {
2394
- [styles.firstDayOfMonth]: wrapModifier(_ref2 => {
2395
- var {
2396
- dateValue
2397
- } = _ref2;
2398
- return dateValue.day === 1;
2399
- }),
2400
- [styles.lastDayOfMonth]: wrapModifier(_ref3 => {
2401
- var {
2402
- dateValue
2403
- } = _ref3;
2404
- return dateValue.day === dateValue.daysInMonth;
2405
- })
2406
- };
2407
-
2408
- if (modifiers) {
2409
- for (var [key, modifier] of Object.entries(modifiers)) {
2410
- dayPickerModifiers[key] = wrapModifier(modifier);
2411
- }
2412
- }
2413
-
2414
- if (highlightedDays) {
2415
- for (var [_key, _modifier] of Object.entries(highlightedDays)) {
2416
- dayPickerModifiers[styles[_key]] = wrapModifier(_modifier);
2417
- }
2418
- }
2419
-
2420
- return /*#__PURE__*/jsxs(Grid$1, {
2421
- ref: ref,
2422
- container: true,
2423
- direction: direction,
2424
- children: [!!quickSelection && /*#__PURE__*/jsxs(Fragment, {
2425
- children: [/*#__PURE__*/jsx(Grid$1, {
2426
- item: true,
2427
- xs: 12,
2428
- sm: "auto",
2429
- children: quickSelection
2430
- }), /*#__PURE__*/jsx(Hidden$1, {
2431
- xsDown: true,
2432
- children: /*#__PURE__*/jsx(Grid$1, {
2433
- item: true,
2434
- sm: "auto",
2435
- children: /*#__PURE__*/jsx(Divider$1, {
2436
- orientation: "vertical"
2437
- })
2438
- })
2439
- }), /*#__PURE__*/jsx(Hidden$1, {
2440
- smUp: true,
2441
- children: /*#__PURE__*/jsx(Grid$1, {
2442
- item: true,
2443
- xs: 12,
2444
- children: /*#__PURE__*/jsx(Divider$1, {
2445
- orientation: "horizontal"
2446
- })
2447
- })
2448
- })]
2449
- }), /*#__PURE__*/jsxs(Grid$1, {
2450
- item: true,
2451
- xs: 12,
2452
- sm: "auto",
2453
- children: [/*#__PURE__*/jsx(DayPicker, _objectSpread(_objectSpread({}, dayPickerProps), {}, {
2454
- classNames: styles,
2455
- navbarElement: CalendarNavbar$1,
2456
- captionElement: CalendarCaption$1,
2457
- weekdayElement: CalendarWeekDay$1,
2458
- initialMonth: initialMonth,
2459
- modifiers: dayPickerModifiers,
2460
- selectedDays: wrapModifier(selectedDays),
2461
- disabledDays: wrapModifier(disabledDays),
2462
- onDayClick: wrapHandler(onDayClick),
2463
- onDayKeyDown: wrapHandler(onDayKeyDown),
2464
- onDayMouseEnter: wrapHandler(onDayMouseEnter),
2465
- onDayMouseLeave: wrapHandler(onDayMouseLeave),
2466
- onDayMouseDown: wrapHandler(onDayMouseDown),
2467
- onDayMouseUp: wrapHandler(onDayMouseUp),
2468
- onDayTouchEnd: wrapHandler(onDayTouchEnd),
2469
- onDayTouchStart: wrapHandler(onDayTouchStart)
2470
- })), !!footer && /*#__PURE__*/jsx("div", {
2471
- className: styles.footer,
2472
- children: footer
2473
- })]
2474
- })]
2475
- });
2476
- });
2477
- if (process.env.NODE_ENV !== "production") Calendar$1.displayName = "Calendar";
2478
-
2479
- var CalendarQuickSelectionItem$1 = /*#__PURE__*/forwardRef((_ref, ref) => {
2480
- var {
2481
- onClick,
2482
- selected,
2483
- children
2484
- } = _ref;
2485
- return /*#__PURE__*/jsx(ListItem$1, {
2486
- ref: ref,
2487
- button: true,
2488
- selected: selected,
2489
- onClick: onClick,
2490
- children: children
2491
- });
2492
- });
2493
- if (process.env.NODE_ENV !== "production") CalendarQuickSelectionItem$1.displayName = "CalendarQuickSelectionItem";
2494
- var CalendarQuickSelection$1 = /*#__PURE__*/forwardRef((_ref2, ref) => {
2495
- var {
2496
- children
2497
- } = _ref2;
2498
- return /*#__PURE__*/jsxs(List$1, {
2499
- ref: ref,
2500
- children: [/*#__PURE__*/jsx(ListItem$1, {
2501
- children: /*#__PURE__*/jsx(Typography$1, {
2502
- variant: "h4",
2503
- children: "Quick Selection"
2504
- })
2505
- }), children]
2506
- });
2507
- });
2508
- if (process.env.NODE_ENV !== "production") CalendarQuickSelection$1.displayName = "CalendarQuickSelection";
2509
-
2510
- var _excluded$8 = ["id", "api", "onClear", "onClick", "onClose", "onKeyDown", "disabled", "children", "enableClearable", "inputRef", "InputProps"];
2511
- var BaseDatePicker$1 = /*#__PURE__*/forwardRef((_ref, ref) => {
2512
- var {
2513
- id,
2514
- api,
2515
- onClear,
2516
- onClick: _onClick,
2517
- onClose,
2518
- onKeyDown: _onKeyDown,
2519
- disabled,
2520
- children,
2521
- enableClearable,
2522
- inputRef: inputRefProp,
2523
- InputProps: inputProps
2524
- } = _ref,
2525
- textFieldProps = _objectWithoutProperties(_ref, _excluded$8);
2526
-
2527
- var uid = useUID$1(id);
2528
- var labelID = "".concat(uid, "-label");
2529
- var clearIconID = "".concat(uid, "-clear-icon");
2530
- var inputRef = useRef(null);
2531
- var textFieldRef = useRef(null);
2532
- var [popoverAnchor, setPopoverAnchor] = useState(null);
2533
-
2534
- function handleOpen() {
2535
- if (!disabled && textFieldRef.current) {
2536
- setPopoverAnchor(textFieldRef.current);
2537
- }
2538
- }
2539
-
2540
- function handleClose() {
2541
- setPopoverAnchor(null);
2542
- }
2543
-
2544
- useImperativeHandle(api, () => ({
2545
- close: handleClose
2546
- })); // We want to trigger close event only when UI will be ready after updates.
2547
-
2548
- useValueObserver(popoverAnchor, () => {
2549
- if (!popoverAnchor) {
2550
- onClose === null || onClose === void 0 ? void 0 : onClose();
2551
- }
2552
- });
2553
- return /*#__PURE__*/jsxs(Fragment, {
2554
- children: [/*#__PURE__*/jsx(Popover$1, {
2555
- open: !!popoverAnchor,
2556
- onClose: handleClose,
2557
- anchorEl: popoverAnchor,
2558
- anchorOrigin: {
2559
- vertical: 'bottom',
2560
- horizontal: 'left'
2561
- },
2562
- transformOrigin: {
2563
- vertical: 'top',
2564
- horizontal: 'left'
2565
- },
2566
- children: children
2567
- }), /*#__PURE__*/jsx(TextField$1, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2568
- id: uid,
2569
- ref: mergeRefs$1(ref, textFieldRef),
2570
- disabled: disabled,
2571
- inputRef: mergeRefs$1(inputRef, inputRefProp),
2572
- onClick: event => {
2573
- _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
2574
-
2575
- if (!event.defaultPrevented) {
2576
- handleOpen();
2577
- }
2578
- },
2579
- onKeyDown: event => {
2580
- _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
2581
-
2582
- if (!event.defaultPrevented && (event.key === ' ' || event.key === 'Enter')) {
2583
- handleOpen();
2584
- }
2585
- },
2586
- inputProps: {
2587
- readOnly: true
2588
- },
2589
- InputProps: _objectSpread(_objectSpread({}, inputProps), {}, {
2590
- endAdornment: /*#__PURE__*/jsx(InputAdornment$1, {
2591
- position: "end",
2592
- children: enableClearable ? /*#__PURE__*/jsx(IconButton$1, {
2593
- disabled: disabled,
2594
- "aria-labelledby": "".concat(clearIconID, " ").concat(labelID),
2595
- onClick: event => {
2596
- // Do not bubble up clicks.
2597
- event.stopPropagation();
2598
- onClear === null || onClear === void 0 ? void 0 : onClear();
2599
- },
2600
- children: /*#__PURE__*/jsx(Clear$1, {
2601
- id: clearIconID,
2602
- "aria-label": "clear"
2603
- })
2604
- }) : /*#__PURE__*/jsx(IconButton$1, {
2605
- disabled: disabled,
2606
- children: /*#__PURE__*/jsx(SvgIcon$1, {
2607
- children: /*#__PURE__*/jsx("path", {
2608
- d: mdiCalendarMonth
2609
- })
2610
- })
2611
- })
2612
- })
2613
- })
2614
- }))]
2615
- });
2616
- });
2617
- if (process.env.NODE_ENV !== "production") BaseDatePicker$1.displayName = "BaseDatePicker";
2618
-
2619
- var _excluded$9 = ["variant", "fallback"],
2620
- _excluded2$4 = ["date", "fallback"];
2621
- function useFormattedDate$1(input, _ref) {
2622
- var {
2623
- variant,
2624
- fallback
2625
- } = _ref,
2626
- dateConfig = _objectWithoutProperties(_ref, _excluded$9);
2627
-
2628
- var config = useDateConfig$1(dateConfig);
2629
- var date = useDateTime$1(input, config);
2630
- return useMemo(() => formatDate$1(date, {
2631
- variant,
2632
- fallback
2633
- }, config), [date, config, variant, fallback]);
2634
- }
2635
- function FormattedDate$1(_ref2) {
2636
- var {
2637
- date,
2638
- fallback = 'Invalid Date'
2639
- } = _ref2,
2640
- options = _objectWithoutProperties(_ref2, _excluded2$4);
2641
-
2642
- var formatted = useFormattedDate$1(date, _objectSpread(_objectSpread({}, options), {}, {
2643
- fallback: ''
2644
- }));
2645
- return renderChildren(formatted || fallback);
2646
- }
2647
-
2648
- var _excluded$a = ["onDayClick"],
2649
- _excluded2$5 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
2650
- var DateField$1 = /*#__PURE__*/forwardRef((_ref, ref) => {
2651
- var {
2652
- onBlur,
2653
- onFocus,
2654
- onChange,
2655
- renderFooter,
2656
- renderQuickSelection,
2657
- value: valueProp,
2658
- format: formatProp,
2659
- fallback = '',
2660
- variant = 'Date',
2661
- enableClearable,
2662
- disableCloseOnSelect,
2663
- CalendarProps: {
2664
- onDayClick: _onDayClick
2665
- } = {}
2666
- } = _ref,
2667
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$a),
2668
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$5);
2669
-
2670
- var config = useDateConfig$1({
2671
- format: formatProp
2672
- });
2673
- var apiRef = useRef(null);
2674
- var date = useDateTime$1(valueProp, config);
2675
- var displayValue = useFormattedDate$1(date, _objectSpread({
2676
- variant,
2677
- fallback
2678
- }, config));
2679
- var dateString = useMemo(() => stringifyDate$1(date, config), [date, config]);
2680
-
2681
- function handleClose() {
2682
- var _apiRef$current;
2683
-
2684
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
2685
- }
2686
-
2687
- function handleChange(nextInput) {
2688
- if (onChange) {
2689
- onChange(toDatePayload$1(nextInput, config));
2690
- }
2691
-
2692
- if (!disableCloseOnSelect) {
2693
- handleClose();
2694
- }
2695
- }
2696
-
2697
- var api = {
2698
- config,
2699
- dateValue: date,
2700
- stringValue: dateString,
2701
- close: handleClose,
2702
- change: handleChange
2703
- };
2704
- return /*#__PURE__*/jsx(BaseDatePicker$1, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2705
- ref: ref,
2706
- api: apiRef,
2707
- onClose: onBlur,
2708
- value: displayValue || fallback,
2709
- enableClearable: enableClearable && date.isValid,
2710
- onClear: () => {
2711
- handleChange(undefined);
2712
- },
2713
- children: /*#__PURE__*/jsx(Calendar$1, _objectSpread(_objectSpread({}, calendarProps), {}, {
2714
- initialMonth: date,
2715
- footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
2716
- quickSelection: renderQuickSelection === null || renderQuickSelection === void 0 ? void 0 : renderQuickSelection(api),
2717
- selectedDays: _ref2 => {
2718
- var {
2719
- dateValue
2720
- } = _ref2;
2721
- return date.hasSame(dateValue, 'day');
2722
- },
2723
- onDayClick: event => {
2724
- _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
2725
-
2726
- if (!event.disabled) {
2727
- handleChange(event.dateValue);
2728
- }
2729
- }
2730
- }))
2731
- }));
2732
- });
2733
- if (process.env.NODE_ENV !== "production") DateField$1.displayName = "DateField";
2734
-
2735
- function useDateTimeRange$1(input, options) {
2736
- var config = useDateConfig$1(options);
2737
- var [startInput, finishInput] = toPrimitiveDateRangeInput$1(input);
2738
- var startDate = useDateTime$1(startInput, config);
2739
- var finishDate = useDateTime$1(finishInput, config);
2740
- return useMemo(() => parseDateRange$1([startDate, finishDate], config), [config, startDate, finishDate]);
2741
- }
2742
-
2743
- var _excluded$b = ["modifiers", "onDayClick", "onDayMouseEnter"],
2744
- _excluded2$6 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
2745
- _excluded3$1 = ["rangeStart", "rangeFinish"];
2746
- var useStyles$3 = /*#__PURE__*/makeStyles$1(theme => ({
2747
- rangeStart: {},
2748
- rangeFinish: {},
2749
- outside: {},
2750
- disabled: {},
2751
- selected: {},
2752
- day: {
2753
- '&$selected:not($outside)': {
2754
- '&$rangeStart:before': {
2755
- left: theme.spacing(0.5)
2756
- },
2757
- '&$rangeFinish:before': {
2758
- right: theme.spacing(0.5)
2759
- },
2760
- '&:not($rangeStart):not($rangeFinish)': {
2761
- '&:after': {
2762
- backgroundColor: Color.Transparent
2763
- },
2764
- '&$disabled': {
2765
- '&:before': {
2766
- backgroundColor: Color.Silver100
2767
- }
2768
- },
2769
- '&:not($disabled)': {
2770
- color: Color.Blue500,
2771
- '&:before': {
2772
- backgroundColor: Color.Blue50
2773
- }
2774
- }
2775
- }
2776
- }
2777
- }
2778
- }), {
2779
- name: 'SD-DateRangeField'
2780
- });
2781
- var DateRangeField$1 = /*#__PURE__*/forwardRef((_ref, ref) => {
2782
- var {
2783
- onBlur,
2784
- onFocus,
2785
- onChange,
2786
- renderFooter,
2787
- renderQuickSelection,
2788
- value: valueProp,
2789
- format: formatProp,
2790
- fallback = '',
2791
- enableClearable,
2792
- disableCloseOnSelect,
2793
- CalendarProps: {
2794
- modifiers,
2795
- onDayClick: _onDayClick,
2796
- onDayMouseEnter: _onDayMouseEnter
2797
- } = {}
2798
- } = _ref,
2799
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$b),
2800
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$6);
2801
-
2802
- var apiRef = useRef(null);
2803
-
2804
- var _useStyles = useStyles$3({}),
2805
- {
2806
- rangeStart,
2807
- rangeFinish
2808
- } = _useStyles,
2809
- styles = _objectWithoutProperties(_useStyles, _excluded3$1);
2810
-
2811
- var config = useDateConfig$1({
2812
- format: formatProp
2813
- });
2814
- var [startDate, finishDate] = useDateTimeRange$1(valueProp, config);
2815
- var [startDateString, finishDateString] = useMemo(() => stringifyDateRange$1([startDate, finishDate], config), [config, startDate, finishDate]);
2816
- var displayValue = useMemo(() => formatDateRange$1([startDate, finishDate], {
2817
- fallback
2818
- }, config), [config, fallback, startDate, finishDate]);
2819
- var [hoveredDate, setHoveredDate] = useState();
2820
- var [calendarStartDate, calendarFinishDate] = useMemo(() => {
2821
- var [nextCalendarStartDate, nextCalendarFinishDate] = parseDateRange$1([startDate, finishDate || hoveredDate], config);
2822
- return [nextCalendarStartDate === null || nextCalendarStartDate === void 0 ? void 0 : nextCalendarStartDate.startOf('day'), nextCalendarFinishDate === null || nextCalendarFinishDate === void 0 ? void 0 : nextCalendarFinishDate.endOf('day')];
2823
- }, [config, startDate, finishDate, hoveredDate]);
2824
-
2825
- function handleClose() {
2826
- var _apiRef$current;
2827
-
2828
- (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
2829
- }
2830
-
2831
- function handleChange(nextValue) {
2832
- var _nextFinishDate;
2833
-
2834
- var [nextStartDate, nextFinishDate] = parseDateRange$1(nextValue, config);
2835
-
2836
- if (onChange) {
2837
- if (nextStartDate) {
2838
- if (startDate) {
2839
- nextStartDate = nextStartDate.set({
2840
- hour: startDate.hour,
2841
- minute: startDate.minute,
2842
- second: startDate.second,
2843
- millisecond: startDate.millisecond
2844
- });
2845
- } else {
2846
- nextStartDate = nextStartDate.startOf('day');
2847
- }
2848
- }
2849
-
2850
- if (nextFinishDate) {
2851
- nextFinishDate = nextFinishDate.endOf('day');
2852
- }
2853
-
2854
- onChange(toDateRangePayload$1([nextStartDate, nextFinishDate], config));
2855
- }
2856
-
2857
- if (!disableCloseOnSelect && (_nextFinishDate = nextFinishDate) !== null && _nextFinishDate !== void 0 && _nextFinishDate.isValid) {
2858
- handleClose();
2859
- }
2860
- }
2861
-
2862
- var api = {
2863
- config,
2864
- close: handleClose,
2865
- change: handleChange,
2866
- dateValue: [startDate, finishDate],
2867
- stringValue: [startDateString, finishDateString]
2868
- };
2869
- return /*#__PURE__*/jsx(BaseDatePicker$1, _objectSpread(_objectSpread({}, textFieldProps), {}, {
2870
- ref: ref,
2871
- api: apiRef,
2872
- value: displayValue || fallback,
2873
- enableClearable: enableClearable && !!startDate && !!finishDate,
2874
- onClear: () => {
2875
- handleChange([undefined, undefined]);
2876
- },
2877
- onClose: () => {
2878
- onBlur === null || onBlur === void 0 ? void 0 : onBlur();
2879
- setHoveredDate(undefined);
2880
- },
2881
- children: /*#__PURE__*/jsx(Calendar$1, _objectSpread(_objectSpread({
2882
- numberOfMonths: 2
2883
- }, calendarProps), {}, {
2884
- classes: styles,
2885
- initialMonth: startDateString,
2886
- modifiers: _objectSpread(_objectSpread({}, modifiers), {}, {
2887
- [rangeStart]: _ref2 => {
2888
- var {
2889
- dateValue
2890
- } = _ref2;
2891
- return !!(calendarStartDate !== null && calendarStartDate !== void 0 && calendarStartDate.hasSame(dateValue, 'day'));
2892
- },
2893
- [rangeFinish]: _ref3 => {
2894
- var {
2895
- dateValue
2896
- } = _ref3;
2897
- return !!(calendarFinishDate !== null && calendarFinishDate !== void 0 && calendarFinishDate.hasSame(dateValue, 'day'));
2898
- }
2899
- }),
2900
- selectedDays: _ref4 => {
2901
- var {
2902
- dateValue
2903
- } = _ref4;
2904
-
2905
- if (calendarStartDate) {
2906
- if (!calendarFinishDate) {
2907
- return calendarStartDate.hasSame(dateValue, 'day');
2908
- }
2909
-
2910
- return calendarStartDate <= dateValue && dateValue <= calendarFinishDate;
2911
- }
2912
-
2913
- return false;
2914
- },
2915
- footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
2916
- quickSelection: renderQuickSelection === null || renderQuickSelection === void 0 ? void 0 : renderQuickSelection(api),
2917
- onDayMouseEnter: event => {
2918
- _onDayMouseEnter === null || _onDayMouseEnter === void 0 ? void 0 : _onDayMouseEnter(event);
2919
- setHoveredDate(!event.disabled ? event.dateValue.valueOf() : undefined);
2920
- },
2921
- onDayClick: event => {
2922
- _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
2923
-
2924
- if (!event.disabled) {
2925
- if (startDate && !finishDate) {
2926
- handleChange([startDateString, event.stringValue]);
2927
- } else {
2928
- handleChange([event.stringValue, undefined]);
2929
- }
2930
- }
2931
- }
2932
- }))
2933
- }));
2934
- });
2935
- if (process.env.NODE_ENV !== "production") DateRangeField$1.displayName = "DateRangeField";
2936
-
2937
- /** @deprecated */
2938
-
2939
- /** @deprecated */
2940
- function toDateTime$1(value) {
2941
- return typeof value === 'number' ? DateTime.fromMillis(value) : DateTime.fromJSDate(value);
2942
- }
2943
- /** @deprecated */
2944
-
2945
-
2946
- function isDate$1(value) {
2947
- return value != null && value instanceof Date;
2948
- }
2949
- /** @deprecated */
2950
-
2951
- function isDateLike$1(value) {
2952
- return isDate$1(value) || typeof value === 'number' && Number.isInteger(value);
2953
- }
2954
- /** @deprecated */
2955
-
2956
- function isValidDate$1(value) {
2957
- return isDate$1(value) && Number.isFinite(value.getTime());
2958
- }
2959
- /** @deprecated */
2960
-
2961
- function checkRange$1(range, validator) {
2962
- if (!Array.isArray(range) || range.length > 2) {
2963
- return false;
2964
- }
2965
-
2966
- var [start, finish] = range;
2967
- return (start == null || validator(start)) && (finish == null || validator(finish));
2968
- }
2969
- /** @deprecated */
2970
-
2971
-
2972
- function isDateRange$1(range) {
2973
- return checkRange$1(range, isDate$1);
2974
- }
2975
- /** @deprecated */
2976
-
2977
- function isDateRangeLike$1(range) {
2978
- return checkRange$1(range, isDateLike$1);
2979
- }
2980
- /** @deprecated */
2981
-
2982
- function isValidDateRange$1(range) {
2983
- return checkRange$1(range, isValidDate$1);
2984
- }
2985
- /** @deprecated */
2986
-
2987
- function toDate$1(value) {
2988
- return !isDateLike$1(value) ? new Date(NaN) : new Date(value);
2989
- }
2990
- /** @deprecated */
2991
-
2992
- function toDateRange$1(range) {
2993
- if (range == null || !isDateRangeLike$1(range)) {
2994
- return [];
2995
- }
2996
-
2997
- return range.filter(x => x != null).map(x => x == null ? undefined : toDate$1(x)).sort((a, b) => !isValidDate$1(a) ? -1 : !isValidDate$1(b) ? 1 : a.valueOf() - b.valueOf());
2998
- }
2999
- /** @deprecated */
3000
-
3001
- /** @deprecated */
3002
- class DateUtils$1 {
3003
- /** @deprecated */
3004
- toObject(value) {
3005
- var {
3006
- year = NaN,
3007
- month = NaN,
3008
- day = NaN,
3009
- hour = NaN,
3010
- minute = NaN,
3011
- second = NaN,
3012
- millisecond = NaN
3013
- } = toDateTime$1(value).toObject({
3014
- includeConfig: false
3015
- });
3016
- return {
3017
- year,
3018
- month,
3019
- day,
3020
- hour,
3021
- minute,
3022
- second,
3023
- millisecond
3024
- };
3025
- }
3026
- /** @deprecated */
3027
-
3028
-
3029
- fromObject(_ref) {
3030
- var {
3031
- year = 0,
3032
- month = 1,
3033
- day = 1,
3034
- hour = 0,
3035
- minute = 0,
3036
- second = 0,
3037
- millisecond = 0
3038
- } = _ref;
3039
-
3040
- if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day) || Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
3041
- return new Date(NaN);
3042
- }
3043
-
3044
- return DateTime.fromObject({
3045
- year,
3046
- month,
3047
- day,
3048
- hour,
3049
- minute,
3050
- second,
3051
- millisecond
3052
- }).toJSDate();
3053
- }
3054
- /** @deprecated */
3055
-
3056
-
3057
- update(value, values) {
3058
- return toDateTime$1(value).set(values).toJSDate();
3059
- }
3060
- /** @deprecated */
3061
-
3062
-
3063
- mergeDateAndTime(date, time) {
3064
- var {
3065
- hour,
3066
- minute,
3067
- second,
3068
- millisecond
3069
- } = this.toObject(time);
3070
-
3071
- if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
3072
- return new Date(NaN);
3073
- }
3074
-
3075
- return this.update(date, {
3076
- hour,
3077
- minute,
3078
- second,
3079
- millisecond
3080
- });
3081
- }
3082
- /** @deprecated */
3083
-
3084
-
3085
- startOf(value, unit) {
3086
- return toDateTime$1(value).startOf(unit).toJSDate();
3087
- }
3088
- /** @deprecated */
3089
-
3090
-
3091
- endOf(value, unit) {
3092
- return toDateTime$1(value).endOf(unit).toJSDate();
3093
- }
3094
- /** @deprecated */
3095
-
3096
-
3097
- plus(value, values) {
3098
- return toDateTime$1(value).plus(values).toJSDate();
3099
- }
3100
- /** @deprecated */
3101
-
3102
-
3103
- minus(value, values) {
3104
- return toDateTime$1(value).minus(values).toJSDate();
3105
- }
3106
- /** @deprecated */
3107
-
3108
-
3109
- isSameDate(value, compare) {
3110
- var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'millisecond';
3111
-
3112
- if (value == null && compare == null) {
3113
- return true;
3114
- }
3115
-
3116
- if (value == null || compare == null) {
3117
- return false;
3118
- }
3119
-
3120
- var dateTimeValue = toDateTime$1(value);
3121
- var dateTimeCompare = toDateTime$1(compare);
3122
- return dateTimeValue.isValid && dateTimeCompare.isValid && dateTimeValue.startOf(unit).equals(dateTimeCompare.startOf(unit));
3123
- }
3124
- /** @deprecated */
3125
-
3126
-
3127
- isSameDateRange(value, compare, unit) {
3128
- var range1 = toDateRange$1(value);
3129
- var range2 = toDateRange$1(compare);
3130
- return !range1.some((date, idx) => !this.isSameDate(date, range2[idx], unit));
3131
- }
3132
- /** @deprecated */
3133
-
3134
-
3135
- diff(value, compare, unit) {
3136
- var valueDateTime = toDateTime$1(value);
3137
- var compareDateTime = toDateTime$1(compare);
3138
- return valueDateTime.diff(compareDateTime, unit).as(unit);
3139
- }
3140
- /** @deprecated */
3141
-
3142
-
3143
- toLocaleString(value, options) {
3144
- return toDateTime$1(value).toLocaleString(options);
3145
- }
3146
- /** @deprecated */
3147
-
3148
-
3149
- format(value, variant) {
3150
- return this.toLocaleString(value, variant === 'date' ? {
3151
- day: '2-digit',
3152
- month: 'short',
3153
- year: 'numeric'
3154
- } : variant === 'shortDate' ? {
3155
- day: '2-digit',
3156
- month: 'short'
3157
- } : variant === 'time' ? {
3158
- hour: 'numeric',
3159
- minute: 'numeric'
3160
- } : {
3161
- day: '2-digit',
3162
- month: 'short',
3163
- year: 'numeric',
3164
- hour: 'numeric',
3165
- minute: 'numeric'
3166
- });
3167
- }
3168
- /** @deprecated */
3169
-
3170
-
3171
- formatRange(value) {
3172
- var emptyText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
3173
- var range = toDateRange$1(value);
3174
-
3175
- if (!isValidDateRange$1(range)) {
3176
- return 'Invalid Date Range';
3177
- }
3178
-
3179
- var [start, finish] = range;
3180
-
3181
- if (!start) {
3182
- return emptyText;
3183
- }
3184
-
3185
- var startText = this.format(start, !this.isSameDate(start, finish, 'year') ? 'date' : 'shortDate');
3186
- var finishText = !finish ? '…' : this.format(finish, 'date');
3187
- return "".concat(startText, " - ").concat(finishText);
3188
- }
3189
- /** @deprecated */
3190
-
3191
-
3192
- formatRelativeTime(value) {
3193
- var {
3194
- style = 'long',
3195
- compare = Date.now()
3196
- } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3197
- var valueDateTime = toDateTime$1(value);
3198
- var compareDateTime = toDateTime$1(compare);
3199
- return valueDateTime.toRelative({
3200
- style,
3201
- base: compareDateTime
3202
- });
3203
- }
3204
-
3205
- }
3206
- function useDateUtils$1() {
3207
- return useMemo(() => new DateUtils$1(), []);
3208
- }
3209
-
3210
- var _excluded$c = ["unit", "round", "padding", "fallback", "base"],
3211
- _excluded2$7 = ["date", "fallback"];
3212
- function useFormattedRelativeTime$1(input) {
3213
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
3214
- {
3215
- unit,
3216
- round,
3217
- padding,
3218
- fallback,
3219
- base: baseOption
3220
- } = _ref,
3221
- dateConfig = _objectWithoutProperties(_ref, _excluded$c);
3222
-
3223
- var config = useDateConfig$1(dateConfig);
3224
- var date = useDateTime$1(input, config);
3225
- var baseOptionDate = useDateTime$1(baseOption, config);
3226
- var base = baseOption == null ? undefined : baseOptionDate;
3227
- return useMemo(() => formatRelativeTime$1(date, {
3228
- base,
3229
- unit,
3230
- round,
3231
- padding,
3232
- fallback
3233
- }, config), [base, date, unit, round, config, padding, fallback]);
3234
- }
3235
- function FormattedRelativeTime$1(_ref2) {
3236
- var {
3237
- date,
3238
- fallback = 'Invalid Date'
3239
- } = _ref2,
3240
- options = _objectWithoutProperties(_ref2, _excluded2$7);
3241
-
3242
- var formatted = useFormattedRelativeTime$1(date, _objectSpread(_objectSpread({}, options), {}, {
3243
- fallback: ''
3244
- }));
3245
- return renderChildren(formatted || fallback);
3246
- }
3247
-
3248
- var _excluded$d = ["disabled", "onChange", "value", "format"];
3249
- var TIME_MATCH_FORMATS$1 = ['h:mm a', 'h:mma', 'H:mm', 'h:mm', 'hmm', 'Hmm', 'h', 'H'];
3250
-
3251
- function toTimeFieldOption$1(date, config) {
3252
- return {
3253
- value: date.valueOf(),
3254
- label: formatDate$1(date, {
3255
- variant: 'Time'
3256
- }, config),
3257
- pattern: new RegExp("^(".concat(TIME_MATCH_FORMATS$1.map(format => date.toFormat(format)).join('|'), ")"), 'i')
3258
- };
3259
- }
3260
-
3261
- function normalizeInputValue$1(inputValue) {
3262
- return inputValue.replace(/[\s]/g, '').toLowerCase();
3263
- }
3264
-
3265
- function makeOptions$1(config) {
3266
- var options = [];
3267
- var now = DateTime.local().startOf('day');
3268
-
3269
- for (var i = 0; i < 96; i++) {
3270
- options.push(toTimeFieldOption$1(now.set({
3271
- minute: i * 15
3272
- }), config));
3273
- }
3274
-
3275
- var cache = new Map();
3276
- return [options, (_, _ref) => {
3277
- var {
3278
- inputValue
3279
- } = _ref;
3280
- var query = normalizeInputValue$1(inputValue);
3281
-
3282
- if (!query) {
3283
- return options;
3284
- }
3285
-
3286
- var filtered = cache.get(query);
3287
-
3288
- if (!filtered) {
3289
- filtered = options.filter(option => option.pattern.test(query));
3290
- cache.set(query, filtered);
3291
- }
3292
-
3293
- return filtered;
3294
- }];
3295
- }
3296
-
3297
- var TimeField$1 = /*#__PURE__*/forwardRef((_ref2, ref) => {
3298
- var {
3299
- disabled,
3300
- onChange,
3301
- value: valueProp,
3302
- format: formatProp
3303
- } = _ref2,
3304
- props = _objectWithoutProperties(_ref2, _excluded$d);
3305
-
3306
- var config = useDateConfig$1({
3307
- format: formatProp
3308
- });
3309
- var date = useDateTime$1(valueProp, config);
3310
- var selectedOption = useMemo(() => !date.isValid ? undefined : toTimeFieldOption$1(date, config), [date, config]);
3311
- var [options, filterOptions] = useMemo(() => makeOptions$1(config), [config]);
3312
- var [inputValue, setInputValue] = useState('');
3313
-
3314
- function handleChange(nextValue) {
3315
- if (onChange) {
3316
- onChange(toDatePayload$1(nextValue, config));
3317
- }
3318
- }
3319
-
3320
- function handleType(text) {
3321
- text = normalizeInputValue$1(text);
3322
-
3323
- for (var timeFormat of TIME_MATCH_FORMATS$1) {
3324
- var nextDate = DateTime.fromFormat(text, timeFormat);
3325
-
3326
- if (nextDate.isValid) {
3327
- if (onChange) {
3328
- if (date.isValid) {
3329
- nextDate = nextDate.set({
3330
- year: date.year,
3331
- month: date.month,
3332
- day: date.day
3333
- });
3334
- }
3335
-
3336
- onChange(toDatePayload$1(nextDate, config));
3337
- }
3338
-
3339
- return;
3340
- }
3341
- }
3342
-
3343
- setInputValue((selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || '');
3344
- }
3345
-
3346
- useEffect(() => {
3347
- if (!date.isValid) {
3348
- setInputValue('');
3349
- } else {
3350
- setInputValue(formatDate$1(date, {
3351
- variant: 'Time'
3352
- }, config));
3353
- }
3354
- }, [date, config]);
3355
- return /*#__PURE__*/jsx(Autocomplete$1, {
3356
- ref: ref,
3357
- disabled: disabled,
3358
- freeSolo: true,
3359
- autoComplete: true,
3360
- value: selectedOption,
3361
- inputValue: inputValue,
3362
- options: options,
3363
- includeInputInList: true,
3364
- filterOptions: filterOptions,
3365
- getOptionLabel: option => typeof option === 'string' ? option : option.label,
3366
- onBlur: event => {
3367
- handleType(event.target.value);
3368
- },
3369
- onChange: (_, nextValue) => {
3370
- if (typeof nextValue === 'string') {
3371
- handleType(nextValue);
3372
- } else {
3373
- handleChange(nextValue === null || nextValue === void 0 ? void 0 : nextValue.value);
3374
- }
3375
- },
3376
- onInputChange: (_, nextInputValue) => {
3377
- setInputValue(nextInputValue);
3378
- },
3379
- renderInput: params => /*#__PURE__*/jsx(TextField$1, _objectSpread(_objectSpread(_objectSpread({
3380
- variant: "outlined"
3381
- }, props), params), {}, {
3382
- InputProps: params.InputProps
3383
- }))
3384
- });
3385
- });
3386
- if (process.env.NODE_ENV !== "production") TimeField$1.displayName = "TimeField";
3387
-
3388
- export { Calendar$1 as Calendar, CalendarQuickSelection$1 as CalendarQuickSelection, CalendarQuickSelectionItem$1 as CalendarQuickSelectionItem, DateConfigProvider$1 as DateConfigProvider, DateField$1 as DateField, DateRangeField$1 as DateRangeField, DateUtils$1 as DateUtils, FormattedDate$1 as FormattedDate, FormattedRelativeTime$1 as FormattedRelativeTime, TimeField$1 as TimeField, defaultDateConfig$1 as defaultDateConfig, formatDate$1 as formatDate, formatDateRange$1 as formatDateRange, formatRelativeTime$1 as formatRelativeTime, isDate$1 as isDate, isDateLike$1 as isDateLike, isDateRange$1 as isDateRange, isDateRangeLike$1 as isDateRangeLike, isValidDate$1 as isValidDate, isValidDateRange$1 as isValidDateRange, parseDate$1 as parseDate, parseDateRange$1 as parseDateRange, setDefaultTimeZone$1 as setDefaultTimeZone, stringifyDate$1 as stringifyDate, stringifyDateRange$1 as stringifyDateRange, toDate$1 as toDate, toDatePayload$1 as toDatePayload, toDateRange$1 as toDateRange, toDateRangePayload$1 as toDateRangePayload, toPrimitiveDateInput$1 as toPrimitiveDateInput, toPrimitiveDateRangeInput$1 as toPrimitiveDateRangeInput, useDateConfig$1 as useDateConfig, useDateTime$1 as useDateTime, useDateTimeRange$1 as useDateTimeRange, useDateUtils$1 as useDateUtils, useDefaultTimeZone$1 as useDefaultTimeZone, useFormattedDate$1 as useFormattedDate, useFormattedRelativeTime$1 as useFormattedRelativeTime, index as v5 };
1675
+ export { Calendar, CalendarQuickSelection, CalendarQuickSelectionItem, DateConfigProvider, DateField, DateRangeField, DateUtils, FormattedDate, FormattedRelativeTime, TimeField, defaultDateConfig, formatDate, formatDateRange, formatRelativeTime, isDate, isDateLike, isDateRange, isDateRangeLike, isValidDate, isValidDateRange, parseDate, parseDateRange, setDefaultTimeZone, stringifyDate, stringifyDateRange, toDate, toDatePayload, toDateRange, toDateRangePayload, toPrimitiveDateInput, toPrimitiveDateRangeInput, useDateConfig, useDateTime, useDateTimeRange, useDateUtils, useDefaultTimeZone, useFormattedDate, useFormattedRelativeTime };
3389
1676
  //# sourceMappingURL=index.js.map