@fluentui/react-timepicker-compat 0.0.0-nightly-20240108-0406.1 → 0.0.2

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 (35) hide show
  1. package/CHANGELOG.md +9 -15
  2. package/dist/index.d.ts +147 -0
  3. package/lib/TimePicker.js +1 -0
  4. package/lib/TimePicker.js.map +1 -0
  5. package/lib/components/TimePicker/TimePicker.js +15 -0
  6. package/lib/components/TimePicker/TimePicker.js.map +1 -0
  7. package/lib/components/TimePicker/TimePicker.types.js +1 -0
  8. package/lib/components/TimePicker/TimePicker.types.js.map +1 -0
  9. package/lib/components/TimePicker/index.js +5 -0
  10. package/lib/components/TimePicker/index.js.map +1 -0
  11. package/lib/components/TimePicker/timeMath.js +169 -0
  12. package/lib/components/TimePicker/timeMath.js.map +1 -0
  13. package/lib/components/TimePicker/useTimePicker.js +193 -0
  14. package/lib/components/TimePicker/useTimePicker.js.map +1 -0
  15. package/lib/components/TimePicker/useTimePickerStyles.styles.js +32 -0
  16. package/lib/components/TimePicker/useTimePickerStyles.styles.js.map +1 -0
  17. package/lib/index.js +1 -0
  18. package/lib/index.js.map +1 -0
  19. package/lib-commonjs/TimePicker.js +6 -0
  20. package/lib-commonjs/TimePicker.js.map +1 -0
  21. package/lib-commonjs/components/TimePicker/TimePicker.js +24 -0
  22. package/lib-commonjs/components/TimePicker/TimePicker.js.map +1 -0
  23. package/lib-commonjs/components/TimePicker/TimePicker.types.js +6 -0
  24. package/lib-commonjs/components/TimePicker/TimePicker.types.js.map +1 -0
  25. package/lib-commonjs/components/TimePicker/index.js +16 -0
  26. package/lib-commonjs/components/TimePicker/index.js.map +1 -0
  27. package/lib-commonjs/components/TimePicker/timeMath.js +141 -0
  28. package/lib-commonjs/components/TimePicker/timeMath.js.map +1 -0
  29. package/lib-commonjs/components/TimePicker/useTimePicker.js +196 -0
  30. package/lib-commonjs/components/TimePicker/useTimePicker.js.map +1 -0
  31. package/lib-commonjs/components/TimePicker/useTimePickerStyles.styles.js +48 -0
  32. package/lib-commonjs/components/TimePicker/useTimePickerStyles.styles.js.map +1 -0
  33. package/lib-commonjs/index.js +28 -0
  34. package/lib-commonjs/index.js.map +1 -0
  35. package/package.json +16 -11
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useTimePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n elementContains,\n mergeCallbacks,\n useControllableState,\n useEventCallback,\n useId,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport type { Hour, TimePickerOption, TimePickerProps, TimePickerState, TimeSelectionData } from './TimePicker.types';\nimport { ComboboxProps, useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport {\n dateToKey,\n keyToDate,\n formatDateToTimeString as defaultFormatDateToTimeString,\n getDateStartAnchor,\n getDateEndAnchor,\n getTimesBetween,\n getDateFromTimeString,\n} from './timeMath';\n\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */\nexport const useTimePicker_unstable = (props: TimePickerProps, ref: React.Ref<HTMLInputElement>): TimePickerState => {\n const {\n dateAnchor: dateAnchorInProps,\n defaultSelectedTime: defaultSelectedTimeInProps,\n endHour = 24,\n formatDateToTimeString = defaultFormatDateToTimeString,\n hourCycle,\n increment = 30,\n onTimeChange,\n selectedTime: selectedTimeInProps,\n showSeconds = false,\n startHour = 0,\n parseTimeStringToDate: parseTimeStringToDateInProps,\n ...rest\n } = props;\n const { freeform = false } = rest;\n\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor(\n dateAnchorInProps ?? selectedTimeInProps ?? defaultSelectedTimeInProps,\n startHour,\n endHour,\n );\n\n const options: TimePickerOption[] = React.useMemo(\n () =>\n getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map(time => ({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, { showSeconds, hourCycle }),\n })),\n [dateEndAnchor, dateStartAnchor, formatDateToTimeString, hourCycle, increment, showSeconds],\n );\n\n const [selectedTime, setSelectedTime] = useControllableState<Date | null>({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null,\n });\n\n const [submittedText, setSubmittedText] = React.useState<string | undefined>(undefined);\n\n const selectTime: TimePickerProps['onTimeChange'] = useEventCallback((e, data) => {\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange?.(e, data);\n });\n\n const selectedOptions = React.useMemo(() => {\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find(date => date.key === selectedTimeKey);\n return selectedOption ? [selectedOption.key] : [];\n }, [options, selectedTime]);\n\n const handleOptionSelect: ComboboxProps['onOptionSelect'] = useEventCallback((e, data) => {\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n const timeSelectionData: TimeSelectionData = {\n selectedTime: keyToDate(data.optionValue ?? ''),\n selectedTimeText: data.optionText,\n errorType: undefined,\n };\n selectTime(e, timeSelectionData);\n });\n\n const baseState = useCombobox_unstable(\n {\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map(date => (\n <Option key={date.key} value={date.key}>\n {date.text}\n </Option>\n )),\n },\n ref,\n );\n\n const defaultParseTimeStringToDate = React.useCallback(\n (time: string | undefined) =>\n getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, { hourCycle, showSeconds }),\n [dateEndAnchor, dateStartAnchor, hourCycle, showSeconds],\n );\n\n const state: TimePickerState = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps ?? defaultParseTimeStringToDate,\n submittedText,\n };\n\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n\n return state;\n};\n\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */\nconst useStableDateAnchor = (providedDate: Date | undefined, startHour: Hour, endHour: Hour) => {\n const [fallbackDateAnchor] = React.useState(() => new Date());\n\n const providedDateKey = dateToKey(providedDate ?? null);\n\n return React.useMemo(() => {\n const dateAnchor = providedDate ?? fallbackDateAnchor;\n\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n\n return { dateStartAnchor, dateEndAnchor };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [endHour, fallbackDateAnchor, providedDateKey, startHour]);\n};\n\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */\nconst useSelectTimeFromValue = (state: TimePickerState, callback: TimePickerProps['onTimeChange']) => {\n const { activeOption, freeform, parseTimeStringToDate, submittedText, setActiveOption, value } = state;\n\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(() => {\n if (freeform && value) {\n setActiveOption(prevActiveOption => {\n if (prevActiveOption?.text && prevActiveOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0) {\n return prevActiveOption;\n }\n return undefined;\n });\n }\n }, [freeform, setActiveOption, value]);\n\n const selectTimeFromValue = useEventCallback(\n (e: React.KeyboardEvent<HTMLInputElement> | React.FocusEvent<HTMLInputElement>) => {\n if (!freeform) {\n return;\n }\n\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback?.(e, { selectedTime, selectedTimeText: value, errorType });\n }\n },\n );\n\n const handleKeyDown: ComboboxProps['onKeyDown'] = useEventCallback(e => {\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n\n const rootRef = React.useRef<HTMLDivElement>(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n\n const handleInputBlur = useEventCallback((e: React.FocusEvent<HTMLInputElement>) => {\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */\nconst useDefaultChevronIconLabel = (state: TimePickerState) => {\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n\n if (fieldContext?.labelId && state.expandIcon?.['aria-label'] === defaultLabelFromCombobox) {\n const chevronId = state.expandIcon.id ?? chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["React","elementContains","mergeCallbacks","useControllableState","useEventCallback","useId","useMergedRefs","Enter","useCombobox_unstable","Option","useFieldContext_unstable","useFieldContext","dateToKey","keyToDate","formatDateToTimeString","defaultFormatDateToTimeString","getDateStartAnchor","getDateEndAnchor","getTimesBetween","getDateFromTimeString","useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","useMemo","map","time","date","key","text","setSelectedTime","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","timeSelectionData","optionText","errorType","baseState","autoComplete","onOptionSelect","children","value","defaultParseTimeStringToDate","useCallback","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","callback","activeOption","setActiveOption","useEffect","prevActiveOption","toLowerCase","indexOf","selectTimeFromValue","handleKeyDown","root","onKeyDown","rootRef","useRef","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","current","input","onBlur","fieldContext","chevronDefaultId","defaultLabelFromCombobox","labelId","chevronId","id"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SACEC,eAAe,EACfC,cAAc,EACdC,oBAAoB,EACpBC,gBAAgB,EAChBC,KAAK,EACLC,aAAa,QACR,4BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAA0B;AAEhD,SAAwBC,oBAAoB,EAAEC,MAAM,QAAQ,2BAA2B;AACvF,SAASC,4BAA4BC,eAAe,QAAQ,wBAAwB;AACpF,SACEC,SAAS,EACTC,SAAS,EACTC,0BAA0BC,6BAA6B,EACvDC,kBAAkB,EAClBC,gBAAgB,EAChBC,eAAe,EACfC,qBAAqB,QAChB,aAAa;AAEpB;;;;;;;;CAQC,GACD,OAAO,MAAMC,yBAAyB,CAACC,OAAwBC;IAC7D,MAAM,EACJC,YAAYC,iBAAiB,EAC7BC,qBAAqBC,0BAA0B,EAC/CC,UAAU,EAAE,EACZb,yBAAyBC,6BAA6B,EACtDa,SAAS,EACTC,YAAY,EAAE,EACdC,YAAY,EACZC,cAAcC,mBAAmB,EACjCC,cAAc,KAAK,EACnBC,YAAY,CAAC,EACbC,uBAAuBC,4BAA4B,EACnD,GAAGC,MACJ,GAAGhB;I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pF;IAEA,IAAI/C,MAAMgD,UAAU,EAAE;QACpBhD,MAAMgD,UAAU,CAACD,QAAQ,GAAG,CAAC,GAAG,qDAAqD;IACvF;IAEA,MAAME,kBAAkB/F,iBAAiB,CAACsD;QACxC,MAAM0C,YAAY1C,EAAE2C,aAAa,GAAG,CAACpG,gBAAgB6F,QAAQQ,OAAO,EAAE5C,EAAE2C,aAAa,IAAI;QACzF,IAAID,WAAW;YACbV,oBAAoBhC;QACtB;IACF;IACAR,MAAMqD,KAAK,CAACC,MAAM,GAAGtG,eAAeiG,iBAAiBjD,MAAMqD,KAAK,CAACC,MAAM;AACzE;AAEA;;CAEC,GACD,MAAM3B,6BAA6B,CAAC3B;QAKLA;IAJ7B,MAAMuD,eAAe9F;IACrB,MAAM+F,mBAAmBrG,MAAM;IAC/B,MAAMsG,2BAA2B;IAEjC,IAAIF,CAAAA,yBAAAA,mCAAAA,aAAcG,OAAO,KAAI1D,EAAAA,oBAAAA,MAAMgD,UAAU,cAAhBhD,wCAAAA,iBAAkB,CAAC,aAAa,MAAKyD,0BAA0B;YACxEzD;QAAlB,MAAM2D,YAAY3D,CAAAA,uBAAAA,MAAMgD,UAAU,CAACY,EAAE,cAAnB5D,kCAAAA,uBAAuBwD;QACzCxD,MAAMgD,UAAU,CAAC,kBAAkB,GAAG,CAAC,EAAEW,UAAU,CAAC,EAAEJ,aAAaG,OAAO,CAAC,CAAC;IAC9E;AACF"}
@@ -0,0 +1,32 @@
1
+ import { __styles, mergeClasses } from '@griffel/react';
2
+ import { useComboboxStyles_unstable } from '@fluentui/react-combobox';
3
+ export const timePickerClassNames = {
4
+ root: 'fui-TimePicker',
5
+ input: 'fui-TimePicker__input',
6
+ expandIcon: 'fui-TimePicker__expandIcon',
7
+ listbox: 'fui-TimePicker__listbox'
8
+ };
9
+ const useStyles = /*#__PURE__*/__styles({
10
+ listbox: {
11
+ Bxyxcbc: "f1vfnyiv"
12
+ }
13
+ }, {
14
+ d: [".f1vfnyiv{max-height:min(80vh, 416px);}"]
15
+ });
16
+ /**
17
+ * Apply styling to the TimePicker slots based on the state
18
+ */
19
+ export const useTimePickerStyles_unstable = state => {
20
+ const styles = useStyles();
21
+ state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);
22
+ state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);
23
+ if (state.expandIcon) {
24
+ state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);
25
+ }
26
+ if (state.listbox) {
27
+ state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);
28
+ }
29
+ useComboboxStyles_unstable(state);
30
+ return state;
31
+ };
32
+ //# sourceMappingURL=useTimePickerStyles.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__styles","mergeClasses","useComboboxStyles_unstable","timePickerClassNames","root","input","expandIcon","listbox","useStyles","Bxyxcbc","d","useTimePickerStyles_unstable","state","styles","className"],"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = makeStyles({\n listbox: {\n maxHeight: 'min(80vh, 416px)'\n }\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */ export const useTimePickerStyles_unstable = (state)=>{\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n"],"mappings":"AAAA,SAAAA,QAAA,EAAqBC,YAAY,QAAQ,gBAAgB;AACzD,SAASC,0BAA0B,QAAQ,0BAA0B;AACrE,OAAO,MAAMC,oBAAoB,GAAG;EAChCC,IAAI,EAAE,gBAAgB;EACtBC,KAAK,EAAE,uBAAuB;EAC9BC,UAAU,EAAE,4BAA4B;EACxCC,OAAO,EAAE;AACb,CAAC;AACD,MAAMC,SAAS,gBAAGR,QAAA;EAAAO,OAAA;IAAAE,OAAA;EAAA;AAAA;EAAAC,CAAA;AAAA,CAIjB,CAAC;AACF;AACA;AACA;AAAI,OAAO,MAAMC,4BAA4B,GAAIC,KAAK,IAAG;EACrD,MAAMC,MAAM,GAAGL,SAAS,CAAC,CAAC;EAC1BI,KAAK,CAACR,IAAI,CAACU,SAAS,GAAGb,YAAY,CAACE,oBAAoB,CAACC,IAAI,EAAEQ,KAAK,CAACR,IAAI,CAACU,SAAS,CAAC;EACpFF,KAAK,CAACP,KAAK,CAACS,SAAS,GAAGb,YAAY,CAACE,oBAAoB,CAACE,KAAK,EAAEO,KAAK,CAACP,KAAK,CAACS,SAAS,CAAC;EACvF,IAAIF,KAAK,CAACN,UAAU,EAAE;IAClBM,KAAK,CAACN,UAAU,CAACQ,SAAS,GAAGb,YAAY,CAACE,oBAAoB,CAACG,UAAU,EAAEM,KAAK,CAACN,UAAU,CAACQ,SAAS,CAAC;EAC1G;EACA,IAAIF,KAAK,CAACL,OAAO,EAAE;IACfK,KAAK,CAACL,OAAO,CAACO,SAAS,GAAGb,YAAY,CAACE,oBAAoB,CAACI,OAAO,EAAEM,MAAM,CAACN,OAAO,EAAEK,KAAK,CAACL,OAAO,CAACO,SAAS,CAAC;EACjH;EACAZ,0BAA0B,CAACU,KAAK,CAAC;EACjC,OAAOA,KAAK;AAChB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export { TimePicker, timePickerClassNames, useTimePickerStyles_unstable, useTimePicker_unstable, formatDateToTimeString } from './TimePicker';
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"sourcesContent":["export {\n TimePicker,\n timePickerClassNames,\n useTimePickerStyles_unstable,\n useTimePicker_unstable,\n formatDateToTimeString,\n} from './TimePicker';\nexport type {\n TimePickerProps,\n TimePickerSlots,\n TimePickerState,\n TimeSelectionData,\n TimeSelectionEvents,\n TimePickerErrorType,\n} from './TimePicker';\n"],"names":["TimePicker","timePickerClassNames","useTimePickerStyles_unstable","useTimePicker_unstable","formatDateToTimeString"],"mappings":"AAAA,SACEA,UAAU,EACVC,oBAAoB,EACpBC,4BAA4B,EAC5BC,sBAAsB,EACtBC,sBAAsB,QACjB,eAAe"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _export_star = require("@swc/helpers/_/_export_star");
6
+ _export_star._(require("./components/TimePicker/index"), exports);
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TimePicker.js"],"sourcesContent":["export * from './components/TimePicker/index';\n"],"names":[],"mappings":";;;;;uBAAc"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "TimePicker", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return TimePicker;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _useTimePicker = require("./useTimePicker");
14
+ const _useTimePickerStylesstyles = require("./useTimePickerStyles.styles");
15
+ const _reactcombobox = require("@fluentui/react-combobox");
16
+ const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
17
+ const TimePicker = /*#__PURE__*/ _react.forwardRef((props, ref)=>{
18
+ const state = (0, _useTimePicker.useTimePicker_unstable)(props, ref);
19
+ const contextValues = (0, _reactcombobox.useComboboxContextValues)(state);
20
+ (0, _useTimePickerStylesstyles.useTimePickerStyles_unstable)(state);
21
+ (0, _reactsharedcontexts.useCustomStyleHook_unstable)('useTimePickerCompatStyles_unstable')(state);
22
+ return (0, _reactcombobox.renderCombobox_unstable)(state, contextValues);
23
+ });
24
+ TimePicker.displayName = 'TimePicker';
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TimePicker.js"],"sourcesContent":["import * as React from 'react';\nimport { useTimePicker_unstable } from './useTimePicker';\nimport { useTimePickerStyles_unstable } from './useTimePickerStyles.styles';\nimport { renderCombobox_unstable, useComboboxContextValues } from '@fluentui/react-combobox';\nimport { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts';\n/**\n * TimePicker Compat component\n */ export const TimePicker = /*#__PURE__*/ React.forwardRef((props, ref)=>{\n const state = useTimePicker_unstable(props, ref);\n const contextValues = useComboboxContextValues(state);\n useTimePickerStyles_unstable(state);\n useCustomStyleHook_unstable('useTimePickerCompatStyles_unstable')(state);\n return renderCombobox_unstable(state, contextValues);\n});\nTimePicker.displayName = 'TimePicker';\n"],"names":["TimePicker","React","forwardRef","props","ref","state","useTimePicker_unstable","contextValues","useComboboxContextValues","useTimePickerStyles_unstable","useCustomStyleHook_unstable","renderCombobox_unstable","displayName"],"mappings":";;;;+BAOiBA;;;eAAAA;;;;iEAPM;+BACgB;2CACM;+BACqB;qCACtB;AAGjC,MAAMA,aAAa,WAAW,GAAGC,OAAMC,UAAU,CAAC,CAACC,OAAOC;IACjE,MAAMC,QAAQC,IAAAA,qCAAsB,EAACH,OAAOC;IAC5C,MAAMG,gBAAgBC,IAAAA,uCAAwB,EAACH;IAC/CI,IAAAA,uDAA4B,EAACJ;IAC7BK,IAAAA,gDAA2B,EAAC,sCAAsCL;IAClE,OAAOM,IAAAA,sCAAuB,EAACN,OAAOE;AAC1C;AACAP,WAAWY,WAAW,GAAG"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
6
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["TimePicker.types.js"],"sourcesContent":["import * as React from 'react';\n"],"names":[],"mappings":";;;;;iEAAuB"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "formatDateToTimeString", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _timeMath.formatDateToTimeString;
9
+ }
10
+ });
11
+ const _export_star = require("@swc/helpers/_/_export_star");
12
+ _export_star._(require("./TimePicker"), exports);
13
+ _export_star._(require("./TimePicker.types"), exports);
14
+ _export_star._(require("./useTimePicker"), exports);
15
+ _export_star._(require("./useTimePickerStyles.styles"), exports);
16
+ const _timeMath = require("./timeMath");
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.js"],"sourcesContent":["export * from './TimePicker';\nexport * from './TimePicker.types';\nexport * from './useTimePicker';\nexport * from './useTimePickerStyles.styles';\nexport { formatDateToTimeString } from './timeMath';\n"],"names":["formatDateToTimeString"],"mappings":";;;;+BAISA;;;eAAAA,gCAAsB;;;;uBAJjB;uBACA;uBACA;uBACA;0BACyB"}
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ dateToKey: function() {
13
+ return dateToKey;
14
+ },
15
+ keyToDate: function() {
16
+ return keyToDate;
17
+ },
18
+ formatDateToTimeString: function() {
19
+ return formatDateToTimeString;
20
+ },
21
+ getDateStartAnchor: function() {
22
+ return getDateStartAnchor;
23
+ },
24
+ getDateEndAnchor: function() {
25
+ return getDateEndAnchor;
26
+ },
27
+ getTimesBetween: function() {
28
+ return getTimesBetween;
29
+ },
30
+ getDateFromTimeString: function() {
31
+ return getDateFromTimeString;
32
+ }
33
+ });
34
+ function isValidDate(date) {
35
+ return !isNaN(date.getTime());
36
+ }
37
+ function dateToKey(date) {
38
+ if (!date) {
39
+ return '';
40
+ }
41
+ if (!isValidDate(date)) {
42
+ return 'invalid';
43
+ }
44
+ return date.toISOString();
45
+ }
46
+ function keyToDate(key) {
47
+ if (key === '' || key === 'invalid') {
48
+ return null;
49
+ }
50
+ const date = new Date(key);
51
+ return isValidDate(date) ? date : null;
52
+ }
53
+ function formatDateToTimeString(date, { hourCycle, showSeconds } = {}) {
54
+ return date.toLocaleTimeString(undefined, {
55
+ hour: 'numeric',
56
+ hourCycle,
57
+ minute: '2-digit',
58
+ second: showSeconds ? '2-digit' : undefined
59
+ });
60
+ }
61
+ function getDateStartAnchor(dateAnchor, startHour) {
62
+ const startDate = new Date(dateAnchor);
63
+ startDate.setHours(startHour, 0, 0, 0);
64
+ return startDate;
65
+ }
66
+ function getDateEndAnchor(dateAnchor, startHour, endHour) {
67
+ const endDate = new Date(dateAnchor);
68
+ if (startHour > endHour || endHour === 24) {
69
+ endDate.setDate(endDate.getDate() + 1);
70
+ }
71
+ endDate.setHours(endHour === 24 ? 0 : endHour, 0, 0, 0);
72
+ return endDate;
73
+ }
74
+ function getTimesBetween(dateStartAnchor, dateEndAnchor, increment) {
75
+ if (increment <= 0) {
76
+ // eslint-disable-next-line no-console
77
+ console.error('Increment value should be a positive number.');
78
+ return [];
79
+ }
80
+ const result = [];
81
+ const startDate = new Date(dateStartAnchor);
82
+ while(startDate < dateEndAnchor){
83
+ result.push(new Date(startDate));
84
+ startDate.setMinutes(startDate.getMinutes() + increment);
85
+ }
86
+ return result;
87
+ }
88
+ const REGEX_SHOW_SECONDS_HOUR_12 = /^((1[0-2]|0?[0-9]):([0-5][0-9]):([0-5][0-9])\s([AaPp][Mm]))$/;
89
+ const REGEX_HIDE_SECONDS_HOUR_12 = /^((1[0-2]|0?[0-9]):[0-5][0-9]\s([AaPp][Mm]))$/;
90
+ const REGEX_SHOW_SECONDS_HOUR_24 = /^([0-1]?[0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9]$/;
91
+ const REGEX_HIDE_SECONDS_HOUR_24 = /^([0-1]?[0-9]|2[0-4]):[0-5][0-9]$/;
92
+ function getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, timeFormatOptions) {
93
+ if (!time) {
94
+ return {
95
+ date: null,
96
+ errorType: 'required-input'
97
+ };
98
+ }
99
+ const { hourCycle, showSeconds } = timeFormatOptions;
100
+ const hour12 = hourCycle === 'h11' || hourCycle === 'h12';
101
+ // Determine the regex based on format
102
+ const regex = hour12 ? showSeconds ? REGEX_SHOW_SECONDS_HOUR_12 : REGEX_HIDE_SECONDS_HOUR_12 : showSeconds ? REGEX_SHOW_SECONDS_HOUR_24 : REGEX_HIDE_SECONDS_HOUR_24;
103
+ if (!regex.test(time)) {
104
+ return {
105
+ date: null,
106
+ errorType: 'invalid-input'
107
+ };
108
+ }
109
+ const timeParts = /^(\d\d?):(\d\d):?(\d\d)? ?([ap]m)?/i.exec(time);
110
+ if (!timeParts) {
111
+ return {
112
+ date: null,
113
+ errorType: 'invalid-input'
114
+ };
115
+ }
116
+ const [, selectedHours, minutes, seconds, amPm] = timeParts;
117
+ let hours = selectedHours;
118
+ // Adjust for 12-hour time format if needed
119
+ if (hour12 && amPm) {
120
+ if (amPm.toLowerCase() === 'pm' && +hours !== 12) {
121
+ hours = (+hours + 12).toString();
122
+ } else if (amPm.toLowerCase() === 'am' && +hours === 12) {
123
+ hours = '0';
124
+ }
125
+ }
126
+ const adjustedDate = new Date(dateStartAnchor);
127
+ adjustedDate.setHours(+hours, +minutes, seconds ? +seconds : 0);
128
+ // Adjust to the next day if the selected time is before the anchor time
129
+ if (adjustedDate < dateStartAnchor) {
130
+ adjustedDate.setDate(adjustedDate.getDate() + 1);
131
+ }
132
+ if (adjustedDate >= dateEndAnchor) {
133
+ return {
134
+ date: adjustedDate,
135
+ errorType: 'out-of-bounds'
136
+ };
137
+ }
138
+ return {
139
+ date: adjustedDate
140
+ };
141
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["timeMath.js"],"sourcesContent":["function isValidDate(date) {\n return !isNaN(date.getTime());\n}\n/**\n * Converts a Date object to a string key.\n */ export function dateToKey(date) {\n if (!date) {\n return '';\n }\n if (!isValidDate(date)) {\n return 'invalid';\n }\n return date.toISOString();\n}\n/**\n * Converts a string key back to a Date object.\n * Returns undefined for keys that don't represent valid dates.\n */ export function keyToDate(key) {\n if (key === '' || key === 'invalid') {\n return null;\n }\n const date = new Date(key);\n return isValidDate(date) ? date : null;\n}\n/**\n * Formats a Date object into a time string based on provided options.\n *\n * @param date - The Date object to be formatted.\n * @param options - Formatting options. It has two properties:\n * 1. hourCycle (default: undefined): Determines if the time format should be 12-hour or 24-hour.\n * 2. showSeconds (default: false): Determines if the seconds should be included in the formatted string.\n * @returns Formatted time string based on the given options.\n *\n * @example\n * const date = new Date(2023, 9, 6, 23, 45, 12);\n * formatDateToTimeString(date); // Returns \"23:45\" in CET\n * formatDateToTimeString(date, \\{ showSeconds: true \\}); // Returns \"23:45:12\" in CET\n * formatDateToTimeString(date, \\{ hourCycle: 'h12', showSeconds: true \\}); // Returns \"11:45:12 PM\" in CET\n */ export function formatDateToTimeString(date, { hourCycle, showSeconds } = {}) {\n return date.toLocaleTimeString(undefined, {\n hour: 'numeric',\n hourCycle,\n minute: '2-digit',\n second: showSeconds ? '2-digit' : undefined\n });\n}\n/**\n * Get the start date anchor based on the provided parameters.\n * @example\n * const date = new Date(2023, 9, 6); // October 6, 2023\n * getStartAnchorDate(date, 5); // Returns a date for October 6, 2023, 05:00:00\n */ export function getDateStartAnchor(dateAnchor, startHour) {\n const startDate = new Date(dateAnchor);\n startDate.setHours(startHour, 0, 0, 0);\n return startDate;\n}\n/**\n * Get the end date anchor based on the provided parameters.\n * @example\n * const date = new Date(2023, 9, 6); // October 6, 2023\n * getEndAnchorDate(date, 5, 10); // Returns a date for October 6, 2023, 10:00:00\n * getEndAnchorDate(date, 10, 5); // Returns a date for October 7, 2023, 05:00:00 (next day due to hour conditions)\n */ export function getDateEndAnchor(dateAnchor, startHour, endHour) {\n const endDate = new Date(dateAnchor);\n if (startHour > endHour || endHour === 24) {\n endDate.setDate(endDate.getDate() + 1);\n }\n endDate.setHours(endHour === 24 ? 0 : endHour, 0, 0, 0);\n return endDate;\n}\n/**\n * Generates an array of Date objects between two given Date anchors.\n *\n * @param dateStartAnchor - The starting Date anchor.\n * @param dateEndAnchor - The ending Date anchor.\n * @param increment - The minute increment between each Date in the resulting array.\n * @returns - An array of Date objects.\n *\n * @example\n * const start = new Date(2023, 0, 1, 10, 0); // Jan 1, 2023 10:00:00 AM\n * const end = new Date(2023, 0, 1, 11, 0); // Jan 1, 2023 11:00:00 AM\n * getTimesBetween(start, end, 15); // Returns array with Dates [10:00, 10:15, 10:30, 10:45]\n */ export function getTimesBetween(dateStartAnchor, dateEndAnchor, increment) {\n if (increment <= 0) {\n // eslint-disable-next-line no-console\n console.error('Increment value should be a positive number.');\n return [];\n }\n const result = [];\n const startDate = new Date(dateStartAnchor);\n while(startDate < dateEndAnchor){\n result.push(new Date(startDate));\n startDate.setMinutes(startDate.getMinutes() + increment);\n }\n return result;\n}\nconst REGEX_SHOW_SECONDS_HOUR_12 = /^((1[0-2]|0?[0-9]):([0-5][0-9]):([0-5][0-9])\\s([AaPp][Mm]))$/;\nconst REGEX_HIDE_SECONDS_HOUR_12 = /^((1[0-2]|0?[0-9]):[0-5][0-9]\\s([AaPp][Mm]))$/;\nconst REGEX_SHOW_SECONDS_HOUR_24 = /^([0-1]?[0-9]|2[0-4]):[0-5][0-9]:[0-5][0-9]$/;\nconst REGEX_HIDE_SECONDS_HOUR_24 = /^([0-1]?[0-9]|2[0-4]):[0-5][0-9]$/;\n/**\n * Calculates a new date from the user-selected time string based on anchor dates.\n * Returns an object containing a date if the provided time string is valid, and an optional string indicating the type of error.\n *\n * @param time - The time string to be parsed (e.g., \"2:30 PM\", \"15:45:20\").\n * @param dateStartAnchor - The start anchor date.\n * @param dateEndAnchor - The end anchor date.\n * @param timeFormatOptions - format options for the provided time string.\n * @returns An object with either a 'date' or an 'errorType'.\n *\n * @example\n * Input: time=\"2:30 PM\", dateStartAnchor=2023-10-06T12:00:00Z, dateEndAnchor=2023-10-07T12:00:00Z, options={hourCycle: 'h12', showSeconds: false}\n * Output: { date: 2023-10-06T14:30:00Z }\n *\n * Input: time=\"25:30\"\n * Output: { errorType: 'invalid-input' }\n *\n * Input: time=\"1:30 AM\", dateStartAnchor=2023-10-06T03:00:00Z, dateEndAnchor=2023-10-07T03:00:00Z, options={hourCycle: 'h12', showSeconds: false}\n * Output: { date: 2023-10-07T01:30:00Z, errorType: 'out-of-bounds' }\n */ export function getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, timeFormatOptions) {\n if (!time) {\n return {\n date: null,\n errorType: 'required-input'\n };\n }\n const { hourCycle, showSeconds } = timeFormatOptions;\n const hour12 = hourCycle === 'h11' || hourCycle === 'h12';\n // Determine the regex based on format\n const regex = hour12 ? showSeconds ? REGEX_SHOW_SECONDS_HOUR_12 : REGEX_HIDE_SECONDS_HOUR_12 : showSeconds ? REGEX_SHOW_SECONDS_HOUR_24 : REGEX_HIDE_SECONDS_HOUR_24;\n if (!regex.test(time)) {\n return {\n date: null,\n errorType: 'invalid-input'\n };\n }\n const timeParts = /^(\\d\\d?):(\\d\\d):?(\\d\\d)? ?([ap]m)?/i.exec(time);\n if (!timeParts) {\n return {\n date: null,\n errorType: 'invalid-input'\n };\n }\n const [, selectedHours, minutes, seconds, amPm] = timeParts;\n let hours = selectedHours;\n // Adjust for 12-hour time format if needed\n if (hour12 && amPm) {\n if (amPm.toLowerCase() === 'pm' && +hours !== 12) {\n hours = (+hours + 12).toString();\n } else if (amPm.toLowerCase() === 'am' && +hours === 12) {\n hours = '0';\n }\n }\n const adjustedDate = new Date(dateStartAnchor);\n adjustedDate.setHours(+hours, +minutes, seconds ? +seconds : 0);\n // Adjust to the next day if the selected time is before the anchor time\n if (adjustedDate < dateStartAnchor) {\n adjustedDate.setDate(adjustedDate.getDate() + 1);\n }\n if (adjustedDate >= dateEndAnchor) {\n return {\n date: adjustedDate,\n errorType: 'out-of-bounds'\n };\n }\n return {\n date: adjustedDate\n };\n}\n"],"names":["dateToKey","keyToDate","formatDateToTimeString","getDateStartAnchor","getDateEndAnchor","getTimesBetween","getDateFromTimeString","isValidDate","date","isNaN","getTime","toISOString","key","Date","hourCycle","showSeconds","toLocaleTimeString","undefined","hour","minute","second","dateAnchor","startHour","startDate","setHours","endHour","endDate","setDate","getDate","dateStartAnchor","dateEndAnchor","increment","console","error","result","push","setMinutes","getMinutes","REGEX_SHOW_SECONDS_HOUR_12","REGEX_HIDE_SECONDS_HOUR_12","REGEX_SHOW_SECONDS_HOUR_24","REGEX_HIDE_SECONDS_HOUR_24","time","timeFormatOptions","errorType","hour12","regex","test","timeParts","exec","selectedHours","minutes","seconds","amPm","hours","toLowerCase","toString","adjustedDate"],"mappings":";;;;;;;;;;;IAKoBA,SAAS;eAATA;;IAYAC,SAAS;eAATA;;IAqBAC,sBAAsB;eAAtBA;;IAaAC,kBAAkB;eAAlBA;;IAWAC,gBAAgB;eAAhBA;;IAoBAC,eAAe;eAAfA;;IAqCAC,qBAAqB;eAArBA;;;AAvHpB,SAASC,YAAYC,IAAI;IACrB,OAAO,CAACC,MAAMD,KAAKE,OAAO;AAC9B;AAGW,SAASV,UAAUQ,IAAI;IAC9B,IAAI,CAACA,MAAM;QACP,OAAO;IACX;IACA,IAAI,CAACD,YAAYC,OAAO;QACpB,OAAO;IACX;IACA,OAAOA,KAAKG,WAAW;AAC3B;AAIW,SAASV,UAAUW,GAAG;IAC7B,IAAIA,QAAQ,MAAMA,QAAQ,WAAW;QACjC,OAAO;IACX;IACA,MAAMJ,OAAO,IAAIK,KAAKD;IACtB,OAAOL,YAAYC,QAAQA,OAAO;AACtC;AAeW,SAASN,uBAAuBM,IAAI,EAAE,EAAEM,SAAS,EAAEC,WAAW,EAAE,GAAG,CAAC,CAAC;IAC5E,OAAOP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BAA6BC,6BAA6BxB,cAAcyB,6BAA6BC;IAC1I,IAAI,CAACK,MAAMC,IAAI,CAACL,OAAO;QACnB,OAAO;YACHlC,MAAM;YACNoC,WAAW;QACf;IACJ;IACA,MAAMI,YAAY,sCAAsCC,IAAI,CAACP;IAC7D,IAAI,CAACM,WAAW;QACZ,OAAO;YACHxC,MAAM;YACNoC,WAAW;QACf;IACJ;IACA,MAAM,GAAGM,eAAeC,SAASC,SAASC,KAAK,GAAGL;IAClD,IAAIM,QAAQJ;IACZ,2CAA2C;IAC3C,IAAIL,UAAUQ,MAAM;QAChB,IAAIA,KAAKE,WAAW,OAAO,QAAQ,CAACD,UAAU,IAAI;YAC9CA,QAAQ,AAAC,CAAA,CAACA,QAAQ,EAAC,EAAGE,QAAQ;QAClC,OAAO,IAAIH,KAAKE,WAAW,OAAO,QAAQ,CAACD,UAAU,IAAI;YACrDA,QAAQ;QACZ;IACJ;IACA,MAAMG,eAAe,IAAI5C,KAAKgB;IAC9B4B,aAAajC,QAAQ,CAAC,CAAC8B,OAAO,CAACH,SAASC,UAAU,CAACA,UAAU;IAC7D,wEAAwE;IACxE,IAAIK,eAAe5B,iBAAiB;QAChC4B,aAAa9B,OAAO,CAAC8B,aAAa7B,OAAO,KAAK;IAClD;IACA,IAAI6B,gBAAgB3B,eAAe;QAC/B,OAAO;YACHtB,MAAMiD;YACNb,WAAW;QACf;IACJ;IACA,OAAO;QACHpC,MAAMiD;IACV;AACJ"}
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useTimePicker_unstable", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return useTimePicker_unstable;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
13
+ const _reactutilities = require("@fluentui/react-utilities");
14
+ const _keyboardkeys = require("@fluentui/keyboard-keys");
15
+ const _reactcombobox = require("@fluentui/react-combobox");
16
+ const _reactfield = require("@fluentui/react-field");
17
+ const _timeMath = require("./timeMath");
18
+ const useTimePicker_unstable = (props, ref)=>{
19
+ const { dateAnchor: dateAnchorInProps, defaultSelectedTime: defaultSelectedTimeInProps, endHour = 24, formatDateToTimeString = _timeMath.formatDateToTimeString, hourCycle, increment = 30, onTimeChange, selectedTime: selectedTimeInProps, showSeconds = false, startHour = 0, parseTimeStringToDate: parseTimeStringToDateInProps, ...rest } = props;
20
+ const { freeform = false } = rest;
21
+ var _ref;
22
+ const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor((_ref = dateAnchorInProps !== null && dateAnchorInProps !== void 0 ? dateAnchorInProps : selectedTimeInProps) !== null && _ref !== void 0 ? _ref : defaultSelectedTimeInProps, startHour, endHour);
23
+ const options = _react.useMemo(()=>(0, _timeMath.getTimesBetween)(dateStartAnchor, dateEndAnchor, increment).map((time)=>({
24
+ date: time,
25
+ key: (0, _timeMath.dateToKey)(time),
26
+ text: formatDateToTimeString(time, {
27
+ showSeconds,
28
+ hourCycle
29
+ })
30
+ })), [
31
+ dateEndAnchor,
32
+ dateStartAnchor,
33
+ formatDateToTimeString,
34
+ hourCycle,
35
+ increment,
36
+ showSeconds
37
+ ]);
38
+ const [selectedTime, setSelectedTime] = (0, _reactutilities.useControllableState)({
39
+ state: selectedTimeInProps,
40
+ defaultState: defaultSelectedTimeInProps,
41
+ initialState: null
42
+ });
43
+ const [submittedText, setSubmittedText] = _react.useState(undefined);
44
+ const selectTime = (0, _reactutilities.useEventCallback)((e, data)=>{
45
+ setSelectedTime(data.selectedTime);
46
+ setSubmittedText(data.selectedTimeText);
47
+ onTimeChange === null || onTimeChange === void 0 ? void 0 : onTimeChange(e, data);
48
+ });
49
+ const selectedOptions = _react.useMemo(()=>{
50
+ const selectedTimeKey = (0, _timeMath.dateToKey)(selectedTime);
51
+ const selectedOption = options.find((date)=>date.key === selectedTimeKey);
52
+ return selectedOption ? [
53
+ selectedOption.key
54
+ ] : [];
55
+ }, [
56
+ options,
57
+ selectedTime
58
+ ]);
59
+ const handleOptionSelect = (0, _reactutilities.useEventCallback)((e, data)=>{
60
+ if (freeform && data.optionValue === undefined) {
61
+ // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.
62
+ return;
63
+ }
64
+ var _data_optionValue;
65
+ const timeSelectionData = {
66
+ selectedTime: (0, _timeMath.keyToDate)((_data_optionValue = data.optionValue) !== null && _data_optionValue !== void 0 ? _data_optionValue : ''),
67
+ selectedTimeText: data.optionText,
68
+ errorType: undefined
69
+ };
70
+ selectTime(e, timeSelectionData);
71
+ });
72
+ const baseState = (0, _reactcombobox.useCombobox_unstable)({
73
+ autoComplete: 'off',
74
+ ...rest,
75
+ selectedOptions,
76
+ onOptionSelect: handleOptionSelect,
77
+ children: options.map((date)=>/*#__PURE__*/ _react.createElement(_reactcombobox.Option, {
78
+ key: date.key,
79
+ value: date.key
80
+ }, date.text))
81
+ }, ref);
82
+ const defaultParseTimeStringToDate = _react.useCallback((time)=>(0, _timeMath.getDateFromTimeString)(time, dateStartAnchor, dateEndAnchor, {
83
+ hourCycle,
84
+ showSeconds
85
+ }), [
86
+ dateEndAnchor,
87
+ dateStartAnchor,
88
+ hourCycle,
89
+ showSeconds
90
+ ]);
91
+ const state = {
92
+ ...baseState,
93
+ freeform,
94
+ parseTimeStringToDate: parseTimeStringToDateInProps !== null && parseTimeStringToDateInProps !== void 0 ? parseTimeStringToDateInProps : defaultParseTimeStringToDate,
95
+ submittedText
96
+ };
97
+ useDefaultChevronIconLabel(state);
98
+ useSelectTimeFromValue(state, selectTime);
99
+ return state;
100
+ };
101
+ /**
102
+ * Provides stable start and end date anchors based on the provided date and time parameters.
103
+ * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.
104
+ */ const useStableDateAnchor = (providedDate, startHour, endHour)=>{
105
+ const [fallbackDateAnchor] = _react.useState(()=>new Date());
106
+ const providedDateKey = (0, _timeMath.dateToKey)(providedDate !== null && providedDate !== void 0 ? providedDate : null);
107
+ return _react.useMemo(()=>{
108
+ const dateAnchor = providedDate !== null && providedDate !== void 0 ? providedDate : fallbackDateAnchor;
109
+ const dateStartAnchor = (0, _timeMath.getDateStartAnchor)(dateAnchor, startHour);
110
+ const dateEndAnchor = (0, _timeMath.getDateEndAnchor)(dateAnchor, startHour, endHour);
111
+ return {
112
+ dateStartAnchor,
113
+ dateEndAnchor
114
+ };
115
+ // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.
116
+ // eslint-disable-next-line react-hooks/exhaustive-deps
117
+ }, [
118
+ endHour,
119
+ fallbackDateAnchor,
120
+ providedDateKey,
121
+ startHour
122
+ ]);
123
+ };
124
+ /**
125
+ * Mimics the behavior of the browser's change event for a freeform TimePicker.
126
+ * The provided callback is called when input changed and:
127
+ * - Enter/Tab key is pressed on the input.
128
+ * - TimePicker loses focus, signifying a possible change.
129
+ */ const useSelectTimeFromValue = (state, callback)=>{
130
+ const { activeOption, freeform, parseTimeStringToDate, submittedText, setActiveOption, value } = state;
131
+ // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.
132
+ // This effect ensures that the activeOption is cleared when the input doesn't match any option.
133
+ // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.
134
+ _react.useEffect(()=>{
135
+ if (freeform && value) {
136
+ setActiveOption((prevActiveOption)=>{
137
+ if ((prevActiveOption === null || prevActiveOption === void 0 ? void 0 : prevActiveOption.text) && prevActiveOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0) {
138
+ return prevActiveOption;
139
+ }
140
+ return undefined;
141
+ });
142
+ }
143
+ }, [
144
+ freeform,
145
+ setActiveOption,
146
+ value
147
+ ]);
148
+ const selectTimeFromValue = (0, _reactutilities.useEventCallback)((e)=>{
149
+ if (!freeform) {
150
+ return;
151
+ }
152
+ const { date: selectedTime, errorType } = parseTimeStringToDate(value);
153
+ // Only triggers callback when the text in input has changed.
154
+ if (submittedText !== value) {
155
+ callback === null || callback === void 0 ? void 0 : callback(e, {
156
+ selectedTime,
157
+ selectedTimeText: value,
158
+ errorType
159
+ });
160
+ }
161
+ });
162
+ const handleKeyDown = (0, _reactutilities.useEventCallback)((e)=>{
163
+ if (!activeOption && e.key === _keyboardkeys.Enter) {
164
+ selectTimeFromValue(e);
165
+ }
166
+ });
167
+ state.root.onKeyDown = (0, _reactutilities.mergeCallbacks)(handleKeyDown, state.root.onKeyDown);
168
+ const rootRef = _react.useRef(null);
169
+ state.root.ref = (0, _reactutilities.useMergedRefs)(state.root.ref, rootRef);
170
+ if (state.listbox) {
171
+ state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.
172
+ }
173
+ if (state.expandIcon) {
174
+ state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.
175
+ }
176
+ const handleInputBlur = (0, _reactutilities.useEventCallback)((e)=>{
177
+ const isOutside = e.relatedTarget ? !(0, _reactutilities.elementContains)(rootRef.current, e.relatedTarget) : true;
178
+ if (isOutside) {
179
+ selectTimeFromValue(e);
180
+ }
181
+ });
182
+ state.input.onBlur = (0, _reactutilities.mergeCallbacks)(handleInputBlur, state.input.onBlur);
183
+ };
184
+ /**
185
+ * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.
186
+ */ const useDefaultChevronIconLabel = (state)=>{
187
+ var _state_expandIcon;
188
+ const fieldContext = (0, _reactfield.useFieldContext_unstable)();
189
+ const chevronDefaultId = (0, _reactutilities.useId)('timepicker-chevron-');
190
+ const defaultLabelFromCombobox = 'Open';
191
+ if ((fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.labelId) && ((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon['aria-label']) === defaultLabelFromCombobox) {
192
+ var _state_expandIcon_id;
193
+ const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : chevronDefaultId;
194
+ state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;
195
+ }
196
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useTimePicker.js"],"sourcesContent":["import * as React from 'react';\nimport { elementContains, mergeCallbacks, useControllableState, useEventCallback, useId, useMergedRefs } from '@fluentui/react-utilities';\nimport { Enter } from '@fluentui/keyboard-keys';\nimport { useCombobox_unstable, Option } from '@fluentui/react-combobox';\nimport { useFieldContext_unstable as useFieldContext } from '@fluentui/react-field';\nimport { dateToKey, keyToDate, formatDateToTimeString as defaultFormatDateToTimeString, getDateStartAnchor, getDateEndAnchor, getTimesBetween, getDateFromTimeString } from './timeMath';\n/**\n * Create the state required to render TimePicker.\n *\n * The returned state can be modified with hooks such as useTimePickerStyles_unstable,\n * before being passed to renderTimePicker_unstable.\n *\n * @param props - props from this instance of TimePicker\n * @param ref - reference to root HTMLElement of TimePicker\n */ export const useTimePicker_unstable = (props, ref)=>{\n const { dateAnchor: dateAnchorInProps, defaultSelectedTime: defaultSelectedTimeInProps, endHour = 24, formatDateToTimeString = defaultFormatDateToTimeString, hourCycle, increment = 30, onTimeChange, selectedTime: selectedTimeInProps, showSeconds = false, startHour = 0, parseTimeStringToDate: parseTimeStringToDateInProps, ...rest } = props;\n const { freeform = false } = rest;\n var _ref;\n const { dateStartAnchor, dateEndAnchor } = useStableDateAnchor((_ref = dateAnchorInProps !== null && dateAnchorInProps !== void 0 ? dateAnchorInProps : selectedTimeInProps) !== null && _ref !== void 0 ? _ref : defaultSelectedTimeInProps, startHour, endHour);\n const options = React.useMemo(()=>getTimesBetween(dateStartAnchor, dateEndAnchor, increment).map((time)=>({\n date: time,\n key: dateToKey(time),\n text: formatDateToTimeString(time, {\n showSeconds,\n hourCycle\n })\n })), [\n dateEndAnchor,\n dateStartAnchor,\n formatDateToTimeString,\n hourCycle,\n increment,\n showSeconds\n ]);\n const [selectedTime, setSelectedTime] = useControllableState({\n state: selectedTimeInProps,\n defaultState: defaultSelectedTimeInProps,\n initialState: null\n });\n const [submittedText, setSubmittedText] = React.useState(undefined);\n const selectTime = useEventCallback((e, data)=>{\n setSelectedTime(data.selectedTime);\n setSubmittedText(data.selectedTimeText);\n onTimeChange === null || onTimeChange === void 0 ? void 0 : onTimeChange(e, data);\n });\n const selectedOptions = React.useMemo(()=>{\n const selectedTimeKey = dateToKey(selectedTime);\n const selectedOption = options.find((date)=>date.key === selectedTimeKey);\n return selectedOption ? [\n selectedOption.key\n ] : [];\n }, [\n options,\n selectedTime\n ]);\n const handleOptionSelect = useEventCallback((e, data)=>{\n if (freeform && data.optionValue === undefined) {\n // Combobox clears selection when input value not matching any option; but we allow this case in freeform TimePicker.\n return;\n }\n var _data_optionValue;\n const timeSelectionData = {\n selectedTime: keyToDate((_data_optionValue = data.optionValue) !== null && _data_optionValue !== void 0 ? _data_optionValue : ''),\n selectedTimeText: data.optionText,\n errorType: undefined\n };\n selectTime(e, timeSelectionData);\n });\n const baseState = useCombobox_unstable({\n autoComplete: 'off',\n ...rest,\n selectedOptions,\n onOptionSelect: handleOptionSelect,\n children: options.map((date)=>/*#__PURE__*/ React.createElement(Option, {\n key: date.key,\n value: date.key\n }, date.text))\n }, ref);\n const defaultParseTimeStringToDate = React.useCallback((time)=>getDateFromTimeString(time, dateStartAnchor, dateEndAnchor, {\n hourCycle,\n showSeconds\n }), [\n dateEndAnchor,\n dateStartAnchor,\n hourCycle,\n showSeconds\n ]);\n const state = {\n ...baseState,\n freeform,\n parseTimeStringToDate: parseTimeStringToDateInProps !== null && parseTimeStringToDateInProps !== void 0 ? parseTimeStringToDateInProps : defaultParseTimeStringToDate,\n submittedText\n };\n useDefaultChevronIconLabel(state);\n useSelectTimeFromValue(state, selectTime);\n return state;\n};\n/**\n * Provides stable start and end date anchors based on the provided date and time parameters.\n * The hook ensures that the memoization remains consistent even if new Date objects representing the same date are provided.\n */ const useStableDateAnchor = (providedDate, startHour, endHour)=>{\n const [fallbackDateAnchor] = React.useState(()=>new Date());\n const providedDateKey = dateToKey(providedDate !== null && providedDate !== void 0 ? providedDate : null);\n return React.useMemo(()=>{\n const dateAnchor = providedDate !== null && providedDate !== void 0 ? providedDate : fallbackDateAnchor;\n const dateStartAnchor = getDateStartAnchor(dateAnchor, startHour);\n const dateEndAnchor = getDateEndAnchor(dateAnchor, startHour, endHour);\n return {\n dateStartAnchor,\n dateEndAnchor\n };\n // `providedDate`'s stable key representation is used as dependency instead of the Date object. This ensures that the memoization remains stable when a new Date object representing the same date is passed in.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n endHour,\n fallbackDateAnchor,\n providedDateKey,\n startHour\n ]);\n};\n/**\n * Mimics the behavior of the browser's change event for a freeform TimePicker.\n * The provided callback is called when input changed and:\n * - Enter/Tab key is pressed on the input.\n * - TimePicker loses focus, signifying a possible change.\n */ const useSelectTimeFromValue = (state, callback)=>{\n const { activeOption, freeform, parseTimeStringToDate, submittedText, setActiveOption, value } = state;\n // Base Combobox has activeOption default to first option in dropdown even if it doesn't match input value, and Enter key will select it.\n // This effect ensures that the activeOption is cleared when the input doesn't match any option.\n // This behavior is specific to a freeform TimePicker where the input value is treated as a valid time even if it's not in the dropdown.\n React.useEffect(()=>{\n if (freeform && value) {\n setActiveOption((prevActiveOption)=>{\n if ((prevActiveOption === null || prevActiveOption === void 0 ? void 0 : prevActiveOption.text) && prevActiveOption.text.toLowerCase().indexOf(value.toLowerCase()) === 0) {\n return prevActiveOption;\n }\n return undefined;\n });\n }\n }, [\n freeform,\n setActiveOption,\n value\n ]);\n const selectTimeFromValue = useEventCallback((e)=>{\n if (!freeform) {\n return;\n }\n const { date: selectedTime, errorType } = parseTimeStringToDate(value);\n // Only triggers callback when the text in input has changed.\n if (submittedText !== value) {\n callback === null || callback === void 0 ? void 0 : callback(e, {\n selectedTime,\n selectedTimeText: value,\n errorType\n });\n }\n });\n const handleKeyDown = useEventCallback((e)=>{\n if (!activeOption && e.key === Enter) {\n selectTimeFromValue(e);\n }\n });\n state.root.onKeyDown = mergeCallbacks(handleKeyDown, state.root.onKeyDown);\n const rootRef = React.useRef(null);\n state.root.ref = useMergedRefs(state.root.ref, rootRef);\n if (state.listbox) {\n state.listbox.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n if (state.expandIcon) {\n state.expandIcon.tabIndex = -1; // allows it to be the relatedTarget of a blur event.\n }\n const handleInputBlur = useEventCallback((e)=>{\n const isOutside = e.relatedTarget ? !elementContains(rootRef.current, e.relatedTarget) : true;\n if (isOutside) {\n selectTimeFromValue(e);\n }\n });\n state.input.onBlur = mergeCallbacks(handleInputBlur, state.input.onBlur);\n};\n/**\n * Provides a default aria-labelledby for the chevron icon if the TimePicker is wrapped in a Field.\n */ const useDefaultChevronIconLabel = (state)=>{\n var _state_expandIcon;\n const fieldContext = useFieldContext();\n const chevronDefaultId = useId('timepicker-chevron-');\n const defaultLabelFromCombobox = 'Open';\n if ((fieldContext === null || fieldContext === void 0 ? void 0 : fieldContext.labelId) && ((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon['aria-label']) === defaultLabelFromCombobox) {\n var _state_expandIcon_id;\n const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : chevronDefaultId;\n state.expandIcon['aria-labelledby'] = `${chevronId} ${fieldContext.labelId}`;\n }\n};\n"],"names":["useTimePicker_unstable","props","ref","dateAnchor","dateAnchorInProps","defaultSelectedTime","defaultSelectedTimeInProps","endHour","formatDateToTimeString","defaultFormatDateToTimeString","hourCycle","increment","onTimeChange","selectedTime","selectedTimeInProps","showSeconds","startHour","parseTimeStringToDate","parseTimeStringToDateInProps","rest","freeform","_ref","dateStartAnchor","dateEndAnchor","useStableDateAnchor","options","React","useMemo","getTimesBetween","map","time","date","key","dateToKey","text","setSelectedTime","useControllableState","state","defaultState","initialState","submittedText","setSubmittedText","useState","undefined","selectTime","useEventCallback","e","data","selectedTimeText","selectedOptions","selectedTimeKey","selectedOption","find","handleOptionSelect","optionValue","_data_optionValue","timeSelectionData","keyToDate","optionText","errorType","baseState","useCombobox_unstable","autoComplete","onOptionSelect","children","createElement","Option","value","defaultParseTimeStringToDate","useCallback","getDateFromTimeString","useDefaultChevronIconLabel","useSelectTimeFromValue","providedDate","fallbackDateAnchor","Date","providedDateKey","getDateStartAnchor","getDateEndAnchor","callback","activeOption","setActiveOption","useEffect","prevActiveOption","toLowerCase","indexOf","selectTimeFromValue","handleKeyDown","Enter","root","onKeyDown","mergeCallbacks","rootRef","useRef","useMergedRefs","listbox","tabIndex","expandIcon","handleInputBlur","isOutside","relatedTarget","elementContains","current","input","onBlur","_state_expandIcon","fieldContext","useFieldContext","chevronDefaultId","useId","defaultLabelFromCombobox","labelId","_state_expandIcon_id","chevronId","id"],"mappings":";;;;+BAciBA;;;eAAAA;;;;iEAdM;gCACuF;8BACxF;+BACuB;4BACe;0BACgH;AASjK,MAAMA,yBAAyB,CAACC,OAAOC;IAC9C,MAAM,EAAEC,YAAYC,iBAAiB,EAAEC,qBAAqBC,0BAA0B,EAAEC,UAAU,EAAE,EAAEC,yBAAyBC,gCAA6B,EAAEC,SAAS,EAAEC,YAAY,EAAE,EAAEC,YAAY,EAAEC,cAAcC,mBAAmB,EAAEC,cAAc,KAAK,EAAEC,YAAY,CAAC,EAAEC,uBAAuBC,4BAA4B,EAAE,GAAGC,MAAM,GAAGlB;IAC/U,MAAM,EAAEmB,WAAW,KAAK,EAAE,GAAGD;IAC7B,IAAIE;IACJ,MAAM,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGC,oBAAoB,AAACH,CAAAA,OAAOjB,sBAAsB,QAAQA,sBAAsB,KAAK,IAAIA,oBAAoBU,mBAAkB,MAAO,QAAQO,SAAS,KAAK,IAAIA,OAAOf,4BAA4BU,WAAWT;IACzP,MAAMkB,UAAUC,OAAMC,OAAO,CAAC,IAAIC,IAAAA,yBAAe,EAACN,iBAAiBC,eAAeZ,WAAWkB,G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) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ timePickerClassNames: function() {
13
+ return timePickerClassNames;
14
+ },
15
+ useTimePickerStyles_unstable: function() {
16
+ return useTimePickerStyles_unstable;
17
+ }
18
+ });
19
+ const _react = require("@griffel/react");
20
+ const _reactcombobox = require("@fluentui/react-combobox");
21
+ const timePickerClassNames = {
22
+ root: 'fui-TimePicker',
23
+ input: 'fui-TimePicker__input',
24
+ expandIcon: 'fui-TimePicker__expandIcon',
25
+ listbox: 'fui-TimePicker__listbox'
26
+ };
27
+ const useStyles = /*#__PURE__*/ (0, _react.__styles)({
28
+ listbox: {
29
+ Bxyxcbc: "f1vfnyiv"
30
+ }
31
+ }, {
32
+ d: [
33
+ ".f1vfnyiv{max-height:min(80vh, 416px);}"
34
+ ]
35
+ });
36
+ const useTimePickerStyles_unstable = (state)=>{
37
+ const styles = useStyles();
38
+ state.root.className = (0, _react.mergeClasses)(timePickerClassNames.root, state.root.className);
39
+ state.input.className = (0, _react.mergeClasses)(timePickerClassNames.input, state.input.className);
40
+ if (state.expandIcon) {
41
+ state.expandIcon.className = (0, _react.mergeClasses)(timePickerClassNames.expandIcon, state.expandIcon.className);
42
+ }
43
+ if (state.listbox) {
44
+ state.listbox.className = (0, _react.mergeClasses)(timePickerClassNames.listbox, styles.listbox, state.listbox.className);
45
+ }
46
+ (0, _reactcombobox.useComboboxStyles_unstable)(state);
47
+ return state;
48
+ }; //# sourceMappingURL=useTimePickerStyles.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useTimePickerStyles.styles.js"],"sourcesContent":["import { __styles, mergeClasses } from '@griffel/react';\nimport { useComboboxStyles_unstable } from '@fluentui/react-combobox';\nexport const timePickerClassNames = {\n root: 'fui-TimePicker',\n input: 'fui-TimePicker__input',\n expandIcon: 'fui-TimePicker__expandIcon',\n listbox: 'fui-TimePicker__listbox'\n};\nconst useStyles = /*#__PURE__*/__styles({\n listbox: {\n Bxyxcbc: \"f1vfnyiv\"\n }\n}, {\n d: [\".f1vfnyiv{max-height:min(80vh, 416px);}\"]\n});\n/**\n * Apply styling to the TimePicker slots based on the state\n */\nexport const useTimePickerStyles_unstable = state => {\n const styles = useStyles();\n state.root.className = mergeClasses(timePickerClassNames.root, state.root.className);\n state.input.className = mergeClasses(timePickerClassNames.input, state.input.className);\n if (state.expandIcon) {\n state.expandIcon.className = mergeClasses(timePickerClassNames.expandIcon, state.expandIcon.className);\n }\n if (state.listbox) {\n state.listbox.className = mergeClasses(timePickerClassNames.listbox, styles.listbox, state.listbox.className);\n }\n useComboboxStyles_unstable(state);\n return state;\n};\n//# sourceMappingURL=useTimePickerStyles.styles.js.map"],"names":["timePickerClassNames","useTimePickerStyles_unstable","root","input","expandIcon","listbox","useStyles","__styles","Bxyxcbc","d","state","styles","className","mergeClasses","useComboboxStyles_unstable"],"mappings":";;;;;;;;;;;IAEaA,oBAAoB;eAApBA;;IAgBAC,4BAA4B;eAA5BA;;;uBAlB0B;+BACI;AACpC,MAAMD,uBAAuB;IAClCE,MAAM;IACNC,OAAO;IACPC,YAAY;IACZC,SAAS;AACX;AACA,MAAMC,YAAY,WAAW,GAAEC,IAAAA,eAAQ,EAAC;IACtCF,SAAS;QACPG,SAAS;IACX;AACF,GAAG;IACDC,GAAG;QAAC;KAA0C;AAChD;AAIO,MAAMR,+BAA+BS,CAAAA;IAC1C,MAAMC,SAASL;IACfI,MAAMR,IAAI,CAACU,SAAS,GAAGC,IAAAA,mBAAY,EAACb,qBAAqBE,IAAI,EAAEQ,MAAMR,IAAI,CAACU,SAAS;IACnFF,MAAMP,KAAK,CAACS,SAAS,GAAGC,IAAAA,mBAAY,EAACb,qBAAqBG,KAAK,EAAEO,MAAMP,KAAK,CAACS,SAAS;IACtF,IAAIF,MAAMN,UAAU,EAAE;QACpBM,MAAMN,UAAU,CAACQ,SAAS,GAAGC,IAAAA,mBAAY,EAACb,qBAAqBI,UAAU,EAAEM,MAAMN,UAAU,CAACQ,SAAS;IACvG;IACA,IAAIF,MAAML,OAAO,EAAE;QACjBK,MAAML,OAAO,CAACO,SAAS,GAAGC,IAAAA,mBAAY,EAACb,qBAAqBK,OAAO,EAAEM,OAAON,OAAO,EAAEK,MAAML,OAAO,CAACO,SAAS;IAC9G;IACAE,IAAAA,yCAA0B,EAACJ;IAC3B,OAAOA;AACT,GACA,sDAAsD"}