UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

677 lines (676 loc) • 26.7 kB
"use strict"; var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), React = require("react"), icons = require("@sanity/icons"), dateFns = require("date-fns"), range = require("lodash/range.js"), styled = require("styled-components"), reactI18next = require("react-i18next"), reactIs = require("react-is"); function _interopDefaultCompat(e) { return e && typeof e == "object" && "default" in e ? e : { default: e }; } var range__default = /* @__PURE__ */ _interopDefaultCompat(range), styled__default = /* @__PURE__ */ _interopDefaultCompat(styled); function ConditionalWrapper({ children, condition, wrapper }) { return condition ? wrapper(children) : children; } const LARGE_BUTTON_PROPS = { space: 3, padding: 3 }, DEFAULT_BUTTON_PROPS = { space: 2, padding: 2 }, TooltipButtonWrapper = styled__default.default.span` display: inline-flex; `, Button = React.forwardRef(function({ size = "default", mode = "default", paddingY, tone = "default", tooltipProps, ...rest }, ref) { const renderWrapper = React.useCallback( (children) => /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { content: tooltipProps == null ? void 0 : tooltipProps.content, portal: !0, ...tooltipProps, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipButtonWrapper, { children }) }), [tooltipProps] ); return /* @__PURE__ */ jsxRuntime.jsx(ConditionalWrapper, { condition: !!tooltipProps, wrapper: renderWrapper, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...rest, ...size === "default" ? DEFAULT_BUTTON_PROPS : LARGE_BUTTON_PROPS, paddingY, ref, mode, tone }) }); }), Dialog = React.forwardRef(function({ bodyHeight, children, footer, padding = !0, ...props }, ref) { const { t } = reactI18next.useTranslation(); return /* @__PURE__ */ jsxRuntime.jsx( ui.Dialog, { ...props, animate: !0, ref, footer: ((footer == null ? void 0 : footer.confirmButton) || (footer == null ? void 0 : footer.cancelButton)) && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "full", gap: 3, justify: "flex-end", padding: 3, children: [ props.onClose && /* @__PURE__ */ jsxRuntime.jsx( ui.Button, { mode: "bleed", padding: 2, text: t("common.dialog.cancel-button.text"), tone: "default", onClick: props.onClose, ...footer.cancelButton } ), footer.confirmButton && /* @__PURE__ */ jsxRuntime.jsx( ui.Button, { mode: "default", padding: 2, text: t("common.dialog.confirm-button.text"), tone: "critical", ...footer.confirmButton } ) ] }), children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { height: bodyHeight, padding: padding ? 4 : 0, children }) } ); }), MenuButton = React.forwardRef(function(props, ref) { return /* @__PURE__ */ jsxRuntime.jsx( ui.MenuButton, { ...props, ref, popover: { ...props.popover, animate: !0 } } ); }), MenuGroup = (props) => /* @__PURE__ */ jsxRuntime.jsx(ui.MenuGroup, { ...props, fontSize: 1, padding: 3 }), FONT_SIZE = 1, SUBTITLE_FONT_SIZE = 0, SubtitleText = styled__default.default(ui.Text)` margin-top: 2px; `, PreviewWrapper = styled__default.default(ui.Box)` height: 25px; width: 25px; overflow: hidden; `, MenuItem = React.forwardRef(function({ badgeText, children: childrenProp, disabled, hotkeys, icon, iconRight, preview = null, renderMenuItem, text, tooltipProps, __unstable_subtitle, __unstable_space, ...rest }, ref) { const menuItemContent = React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 2, children: [ preview && /* @__PURE__ */ jsxRuntime.jsx( PreviewWrapper, { style: { opacity: disabled ? 0.25 : void 0 }, paddingRight: __unstable_space ? 1 : 0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", height: "fill", justify: "center", children: preview }) } ), icon && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingRight: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: FONT_SIZE, children: [ React.isValidElement(icon) && icon, reactIs.isValidElementType(icon) && React.createElement(icon) ] }) }), text && /* @__PURE__ */ jsxRuntime.jsxs( ui.Stack, { flex: 1, space: __unstable_subtitle ? 1 : 2, paddingLeft: __unstable_subtitle ? 1 : 0, children: [ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: FONT_SIZE, textOverflow: "ellipsis", weight: "medium", children: text }), __unstable_subtitle && /* @__PURE__ */ jsxRuntime.jsx(SubtitleText, { size: SUBTITLE_FONT_SIZE, textOverflow: "ellipsis", weight: "medium", muted: !0, children: __unstable_subtitle }) ] } ), (badgeText || hotkeys || iconRight) && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 3, marginLeft: 3, children: [ hotkeys && /* @__PURE__ */ jsxRuntime.jsx(ui.Hotkeys, { keys: hotkeys, style: { marginTop: -4, marginBottom: -4 } }), badgeText && /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { fontSize: 0, style: { marginTop: -4, marginBottom: -4 }, children: badgeText }), iconRight && /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: FONT_SIZE, children: [ React.isValidElement(iconRight) && iconRight, reactIs.isValidElementType(iconRight) && React.createElement(iconRight) ] }) ] }) ] }), [ preview, disabled, __unstable_space, icon, text, __unstable_subtitle, badgeText, hotkeys, iconRight ]), renderWrapper = React.useCallback( (children) => /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { content: tooltipProps == null ? void 0 : tooltipProps.content, portal: !0, ...tooltipProps, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children }) }), [tooltipProps] ); return /* @__PURE__ */ jsxRuntime.jsx(ConditionalWrapper, { condition: !!tooltipProps, wrapper: renderWrapper, children: /* @__PURE__ */ jsxRuntime.jsx( ui.MenuItem, { disabled, paddingLeft: preview ? 1 : 3, paddingRight: 3, paddingY: preview ? 1 : 3, ref, ...rest, children: typeof childrenProp > "u" && typeof renderMenuItem == "function" ? renderMenuItem(menuItemContent) : menuItemContent } ) }); }), Popover = React.forwardRef(function(props, ref) { return /* @__PURE__ */ jsxRuntime.jsx(ui.Popover, { ...props, animate: !0, ref }); }), Tab = React.forwardRef(function({ tone = "default", ...props }, ref) { return /* @__PURE__ */ jsxRuntime.jsx(ui.Tab, { ...props, muted: !0, padding: 2, ref, tone }); }), TOOLTIP_DELAY_PROPS = { open: 400 }, TOOLTIP_SHARED_PROPS = { animate: !0, arrow: !1, boundaryElement: null, delay: TOOLTIP_DELAY_PROPS, fallbackPlacements: ["bottom-start", "bottom-end", "top-start", "top-end"], placement: "bottom", portal: !0 }, Tooltip = React.forwardRef(function(props, ref) { const { content, hotkeys, ...rest } = props; return typeof content == "string" ? /* @__PURE__ */ jsxRuntime.jsx( ui.Tooltip, { ...TOOLTIP_SHARED_PROPS, content: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [ content && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, padding: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: content }) }), hotkeys && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Hotkeys, { keys: hotkeys }) }) ] }), padding: 1, ref, ...rest } ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { ...TOOLTIP_SHARED_PROPS, content, ref, ...rest }); }), TooltipDelayGroupProvider = (props) => /* @__PURE__ */ jsxRuntime.jsx(ui.TooltipDelayGroupProvider, { delay: TOOLTIP_DELAY_PROPS, children: props.children }), LocaleContext = React.createContext(void 0); function useCurrentLocale() { return useLocale().currentLocale; } function useLocale() { const context = React.useContext(LocaleContext); if (!context) throw new Error( "Sanity LocaleContext value missing. Is this hook being used outside LocaleContext.Provider?" ); return context; } function CalendarDay(props) { const { date, focused, isCurrentMonth, isToday, onSelect, selected } = props, handleClick = React.useCallback(() => { onSelect(date); }, [date, onSelect]); return /* @__PURE__ */ jsxRuntime.jsx("div", { "aria-selected": selected, "data-ui": "CalendarDay", children: /* @__PURE__ */ jsxRuntime.jsx( ui.Card, { "aria-label": date.toDateString(), "aria-pressed": selected, as: "button", __unstable_focusRing: !0, "data-weekday": !0, "data-focused": focused ? "true" : "", role: "button", tabIndex: -1, onClick: handleClick, padding: 2, radius: 2, selected, tone: isToday || selected ? "primary" : "default", children: /* @__PURE__ */ jsxRuntime.jsx( ui.Text, { muted: !selected && !isCurrentMonth, size: 1, style: { textAlign: "center" }, weight: isCurrentMonth ? "medium" : "regular", children: date.getDate() } ) } ) }); } const HOURS_24 = range__default.default(0, 24), ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"], TAIL_WEEKDAYS = [1, 2, 3, 4, 5, 6], getWeekStartsOfMonth = (date, weekStartsOn) => { const firstDay = dateFns.startOfMonth(date); return dateFns.eachWeekOfInterval( { start: firstDay, end: dateFns.lastDayOfMonth(firstDay) }, { weekStartsOn: weekStartsOn === 7 ? 0 : weekStartsOn } ); }, getWeekDaysFromWeekStarts = (weekStarts) => weekStarts.map((weekStart) => [ weekStart, ...TAIL_WEEKDAYS.map((d) => dateFns.addDays(weekStart, d)) ]), useWeeksOfMonth = (date) => { const { weekInfo } = useCurrentLocale(); return getWeekDaysFromWeekStarts(getWeekStartsOfMonth(date, weekInfo.firstDay)).map( (days) => ({ number: dateFns.getWeek(days[0]), days }) ); }; function CalendarMonth(props) { const { weekInfo: { firstDay: weekStartDay } } = useCurrentLocale(), weekDayNames = weekStartDay === 1 ? props.weekDayNames : [props.weekDayNames[6], ...props.weekDayNames.slice(0, 6)]; return /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { "aria-hidden": props.hidden || !1, "data-ui": "CalendarMonth", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Grid, { gap: 1, style: { gridTemplateColumns: "repeat(7, minmax(44px, 46px))" }, children: [ weekDayNames.map((weekday) => /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingY: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, weight: "medium", style: { textAlign: "center" }, children: weekday }) }, weekday)), useWeeksOfMonth(props.date).map( (week, weekIdx) => week.days.map((date, dayIdx) => { const focused = props.focused && dateFns.isSameDay(date, props.focused), selected = props.selected && dateFns.isSameDay(date, props.selected), isToday = dateFns.isSameDay(date, /* @__PURE__ */ new Date()), isCurrentMonth = props.focused && dateFns.isSameMonth(date, props.focused); return /* @__PURE__ */ jsxRuntime.jsx( CalendarDay, { date, focused, isCurrentMonth, isToday, onSelect: props.onSelect, selected }, `${weekIdx}-${dayIdx}` ); }) ) ] }) }); } const features = { dayPresets: !1, timePresets: !1 }, LazyTextInput = React.forwardRef(function({ onChange, onBlur, onKeyPress, value, ...rest }, forwardedRef) { const [inputValue, setInputValue] = React.useState(), handleChange = React.useCallback((event) => { setInputValue(event.currentTarget.value); }, []), checkEvent = React.useCallback( (event) => { event.currentTarget.value !== `${value}` && onChange && onChange(event), setInputValue(void 0); }, [onChange, value] ), handleBlur = React.useCallback( (e) => { checkEvent(e), onBlur && onBlur(e); }, [checkEvent, onBlur] ), handleKeyPress = React.useCallback( (e) => { e.key === "Enter" && checkEvent(e), onKeyPress && onKeyPress(e); }, [checkEvent, onKeyPress] ); return /* @__PURE__ */ jsxRuntime.jsx( ui.TextInput, { ...rest, "data-testid": "date-input", ref: forwardedRef, value: inputValue === void 0 ? value : inputValue, onChange: handleChange, onBlur: handleBlur, onKeyPress: handleKeyPress } ); }), YearInput = (props) => { const { onChange, ...restProps } = props, handleChange = React.useCallback( (event) => { const numericValue = parseInt(event.currentTarget.value, 10); isNaN(numericValue) || onChange(numericValue); }, [onChange] ); return /* @__PURE__ */ jsxRuntime.jsx( LazyTextInput, { ...restProps, fontSize: 1, onChange: handleChange, inputMode: "numeric", padding: 2, radius: 2 } ); }, PRESERVE_FOCUS_ELEMENT = /* @__PURE__ */ jsxRuntime.jsx( "span", { "data-preserve-focus": !0, style: { overflow: "hidden", position: "absolute", outline: "none" }, tabIndex: -1 } ), CALENDAR_ICON_BUTTON_PROPS = { padding: 2 }, Calendar = React.forwardRef(function(props, forwardedRef) { const { selectTime, onFocusedDateChange, selectedDate = /* @__PURE__ */ new Date(), focusedDate = selectedDate, timeStep = 1, onSelect, labels, ...restProps } = props, setFocusedDate = React.useCallback( (date) => onFocusedDateChange(date), [onFocusedDateChange] ), setFocusedDateMonth = React.useCallback( (month) => setFocusedDate(dateFns.setDate(dateFns.setMonth(focusedDate, month), 1)), [focusedDate, setFocusedDate] ), handleFocusedMonthChange = React.useCallback( (e) => setFocusedDateMonth(Number(e.currentTarget.value)), [setFocusedDateMonth] ), moveFocusedDate = React.useCallback( (by) => setFocusedDate(dateFns.addMonths(focusedDate, by)), [focusedDate, setFocusedDate] ), setFocusedDateYear = React.useCallback( (year) => setFocusedDate(dateFns.setYear(focusedDate, year)), [focusedDate, setFocusedDate] ), handleDateChange = React.useCallback( (date) => { onSelect(dateFns.setMinutes(dateFns.setHours(date, selectedDate.getHours()), selectedDate.getMinutes())); }, [onSelect, selectedDate] ), handleMinutesChange = React.useCallback( (event) => { const m = Number(event.currentTarget.value); onSelect(dateFns.setMinutes(selectedDate, m)); }, [onSelect, selectedDate] ), handleHoursChange = React.useCallback( (event) => { const m = Number(event.currentTarget.value); onSelect(dateFns.setHours(selectedDate, m)); }, [onSelect, selectedDate] ); React.useCallback( (hours, mins) => { onSelect(dateFns.setHours(dateFns.setMinutes(selectedDate, mins), hours)); }, [onSelect, selectedDate] ); const ref = ui.useForwardedRef(forwardedRef), focusCurrentWeekDay = React.useCallback(() => { var _a, _b; (_b = (_a = ref.current) == null ? void 0 : _a.querySelector('[data-focused="true"]')) == null || _b.focus(); }, [ref]), handleKeyDown = React.useCallback( (event) => { var _a, _b; if (!ARROW_KEYS.includes(event.key)) return; const target = event.currentTarget; if (event.preventDefault(), target.hasAttribute("data-calendar-grid")) { focusCurrentWeekDay(); return; } event.key === "ArrowUp" && onFocusedDateChange(dateFns.addDays(focusedDate, -7)), event.key === "ArrowDown" && onFocusedDateChange(dateFns.addDays(focusedDate, 7)), event.key === "ArrowLeft" && onFocusedDateChange(dateFns.addDays(focusedDate, -1)), event.key === "ArrowRight" && onFocusedDateChange(dateFns.addDays(focusedDate, 1)), (_b = (_a = ref.current) == null ? void 0 : _a.querySelector("[data-preserve-focus]")) == null || _b.focus(); }, [ref, focusCurrentWeekDay, onFocusedDateChange, focusedDate] ); React.useEffect(() => { focusCurrentWeekDay(); }, [focusCurrentWeekDay]), React.useEffect(() => { var _a; (_a = document.activeElement) != null && _a.matches( "[data-calendar-grid], [data-calendar-grid] [data-preserve-focus]" ) && focusCurrentWeekDay(); }, [ref, focusCurrentWeekDay, focusedDate]), React.useCallback( () => handleDateChange(dateFns.addDays(/* @__PURE__ */ new Date(), -1)), [handleDateChange] ), React.useCallback(() => handleDateChange(/* @__PURE__ */ new Date()), [handleDateChange]), React.useCallback( () => handleDateChange(dateFns.addDays(/* @__PURE__ */ new Date(), 1)), [handleDateChange] ); const handleNowClick = React.useCallback(() => onSelect(/* @__PURE__ */ new Date()), [onSelect]); return /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { "data-ui": "Calendar", ...restProps, ref, children: [ /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { padding: 2, children: [ features.dayPresets, /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx( CalendarMonthSelect, { onChange: handleFocusedMonthChange, monthNames: labels.monthNames, value: focusedDate == null ? void 0 : focusedDate.getMonth() } ) }), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx( CalendarYearSelect, { moveFocusedDate, labels: { goToNextYear: labels.goToNextYear, goToPreviousYear: labels.goToPreviousYear }, onChange: setFocusedDateYear, value: focusedDate.getFullYear() } ) }) ] }), /* @__PURE__ */ jsxRuntime.jsxs( ui.Box, { "data-calendar-grid": !0, onKeyDown: handleKeyDown, marginTop: 2, overflow: "hidden", tabIndex: 0, children: [ /* @__PURE__ */ jsxRuntime.jsx( CalendarMonth, { weekDayNames: labels.weekDayNamesShort, date: focusedDate, focused: focusedDate, onSelect: handleDateChange, selected: selectedDate } ), PRESERVE_FOCUS_ELEMENT ] } ) ] }), selectTime && /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { padding: 2, style: { borderTop: "1px solid var(--card-border-color)" }, children: [ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", flex: 1, children: [ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx( ui.Select, { "aria-label": labels.selectHour, fontSize: 1, padding: 2, radius: 2, value: selectedDate == null ? void 0 : selectedDate.getHours(), onChange: handleHoursChange, children: HOURS_24.map((h) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: h, children: `${h}`.padStart(2, "0") }, h)) } ) }), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { paddingX: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: ":" }) }), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx( ui.Select, { "aria-label": labels.selectMinute, fontSize: 1, padding: 2, radius: 2, value: selectedDate == null ? void 0 : selectedDate.getMinutes(), onChange: handleMinutesChange, children: range__default.default(0, 60, timeStep).map((m) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: m, children: `${m}`.padStart(2, "0") }, m)) } ) }) ] }), /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginLeft: 2, children: /* @__PURE__ */ jsxRuntime.jsx(Button, { text: labels.setToCurrentTime, mode: "bleed", onClick: handleNowClick }) }) ] }), features.timePresets ] }) ] }); }); function CalendarMonthSelect(props) { const { onChange, value, monthNames } = props; return /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { flex: 1, gap: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select, { fontSize: 1, radius: 2, value, onChange, padding: 2, children: monthNames.map((monthName, i) => ( // eslint-disable-next-line react/no-array-index-key /* @__PURE__ */ jsxRuntime.jsx("option", { value: i, children: monthName }, i) )) }) }) }); } function CalendarYearSelect(props) { const { moveFocusedDate, onChange, value, labels } = props, handlePrevYearClick = React.useCallback(() => moveFocusedDate(-12), [moveFocusedDate]), handleNextYearClick = React.useCallback(() => moveFocusedDate(12), [moveFocusedDate]); return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 1, children: [ /* @__PURE__ */ jsxRuntime.jsx( Button, { "aria-label": labels.goToPreviousYear, onClick: handlePrevYearClick, mode: "bleed", icon: icons.ChevronLeftIcon, tooltipProps: { content: "Previous year" }, ...CALENDAR_ICON_BUTTON_PROPS } ), /* @__PURE__ */ jsxRuntime.jsx(YearInput, { value, onChange, radius: 0, style: { width: 48 } }), /* @__PURE__ */ jsxRuntime.jsx( Button, { "aria-label": labels.goToNextYear, onClick: handleNextYearClick, mode: "bleed", icon: icons.ChevronRightIcon, tooltipProps: { content: "Next year" }, ...CALENDAR_ICON_BUTTON_PROPS } ) ] }); } const DatePicker = React.forwardRef(function(props, ref) { const { value = /* @__PURE__ */ new Date(), onChange, calendarLabels, ...rest } = props, [focusedDate, setFocusedDay] = React.useState(), handleSelect = React.useCallback( (nextDate) => { onChange(nextDate), setFocusedDay(void 0); }, [onChange] ); return /* @__PURE__ */ jsxRuntime.jsx( Calendar, { ...rest, labels: calendarLabels, ref, selectedDate: value, onSelect: handleSelect, focusedDate: focusedDate || value, onFocusedDateChange: setFocusedDay } ); }); function isValidDate(date) { return date instanceof Date && !isNaN(date.valueOf()); } function getCalendarLabels(t) { return { goToTomorrow: t("calendar.action.go-to-tomorrow"), goToToday: t("calendar.action.go-to-today"), goToYesterday: t("calendar.action.go-to-yesterday"), goToNextMonth: t("calendar.action.go-to-next-month"), goToPreviousMonth: t("calendar.action.go-to-previous-month"), goToNextYear: t("calendar.action.go-to-next-year"), goToPreviousYear: t("calendar.action.go-to-previous-year"), setToCurrentTime: t("calendar.action.set-to-current-time"), selectHour: t("calendar.action.select-hour"), selectMinute: t("calendar.action.select-minute"), monthNames: [ t("calendar.month-names.january"), t("calendar.month-names.february"), t("calendar.month-names.march"), t("calendar.month-names.april"), t("calendar.month-names.may"), t("calendar.month-names.june"), t("calendar.month-names.july"), t("calendar.month-names.august"), t("calendar.month-names.september"), t("calendar.month-names.october"), t("calendar.month-names.november"), t("calendar.month-names.december") ], weekDayNamesShort: [ t("calendar.weekday-names.short.monday"), t("calendar.weekday-names.short.tuesday"), t("calendar.weekday-names.short.wednesday"), t("calendar.weekday-names.short.thursday"), t("calendar.weekday-names.short.friday"), t("calendar.weekday-names.short.saturday"), t("calendar.weekday-names.short.sunday") ], setToTimePreset: (time, date) => t("calendar.action.set-to-time-preset", { time, date }) }; } async function getJsonStream(url, token) { const options = token ? { headers: { Authorization: `Bearer ${token}` } } : { credentials: "include" }, response = await fetch(url, options); return getStream(response); } function getStream(response) { const body = response.body; if (!body) throw new Error("Failed to read body from response"); let reader, cancelled = !1; return new ReadableStream({ start(controller) { reader = body.getReader(); const decoder = new TextDecoder(); let buffer = ""; reader.read().then(function processResult(result) { if (result.done) { if (cancelled) return; if (buffer = buffer.trim(), buffer.length === 0) { controller.close(); return; } controller.enqueue(JSON.parse(buffer)), controller.close(); return; } buffer += decoder.decode(result.value, { stream: !0 }); const lines = buffer.split(` `); for (let i = 0; i < lines.length - 1; ++i) { const line = lines[i].trim(); if (line.length !== 0) try { controller.enqueue(JSON.parse(line)); } catch (err) { controller.error(err), cancelled = !0, reader.cancel(); return; } } return buffer = lines[lines.length - 1], reader.read().then(processResult).catch((err) => controller.error(err)); }).catch((err) => controller.error(err)); }, cancel() { cancelled = !0, reader.cancel(); } }); } exports.Button = Button; exports.ConditionalWrapper = ConditionalWrapper; exports.DatePicker = DatePicker; exports.Dialog = Dialog; exports.LazyTextInput = LazyTextInput; exports.LocaleContext = LocaleContext; exports.MenuButton = MenuButton; exports.MenuGroup = MenuGroup; exports.MenuItem = MenuItem; exports.Popover = Popover; exports.Tab = Tab; exports.Tooltip = Tooltip; exports.TooltipDelayGroupProvider = TooltipDelayGroupProvider; exports.getCalendarLabels = getCalendarLabels; exports.getJsonStream = getJsonStream; exports.isValidDate = isValidDate; exports.useCurrentLocale = useCurrentLocale; exports.useLocale = useLocale; //# sourceMappingURL=getJsonStream.js.map