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

254 lines (253 loc) • 15.3 kB
"use strict"; var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), React = require("react"), _singletons = require("../_singletons.js"), reactCompilerRuntime = require("react-compiler-runtime"), reactIs = require("react-is"), styledComponents = require("styled-components"), reactI18next = require("react-i18next"); 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 = styledComponents.styled.span` display: inline-flex; `, Button = React.forwardRef(function(t0, ref) { const $ = reactCompilerRuntime.c(20); let paddingY, rest, t1, t2, t3, tooltipProps; $[0] !== t0 ? ({ size: t1, mode: t2, paddingY, tone: t3, tooltipProps, ...rest } = t0, $[0] = t0, $[1] = paddingY, $[2] = rest, $[3] = t1, $[4] = t2, $[5] = t3, $[6] = tooltipProps) : (paddingY = $[1], rest = $[2], t1 = $[3], t2 = $[4], t3 = $[5], tooltipProps = $[6]); const size = t1 === void 0 ? "default" : t1, mode = t2 === void 0 ? "default" : t2, tone = t3 === void 0 ? "default" : t3; let t4; $[7] !== tooltipProps ? (t4 = (children) => /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { content: tooltipProps?.content, portal: !0, ...tooltipProps, children: /* @__PURE__ */ jsxRuntime.jsx(TooltipButtonWrapper, { children }) }), $[7] = tooltipProps, $[8] = t4) : t4 = $[8]; const renderWrapper = t4, sizeProps = size === "default" ? DEFAULT_BUTTON_PROPS : LARGE_BUTTON_PROPS, t5 = !!tooltipProps; let t6; $[9] !== mode || $[10] !== paddingY || $[11] !== ref || $[12] !== rest || $[13] !== sizeProps || $[14] !== tone ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...rest, ...sizeProps, paddingY, ref, mode, tone }), $[9] = mode, $[10] = paddingY, $[11] = ref, $[12] = rest, $[13] = sizeProps, $[14] = tone, $[15] = t6) : t6 = $[15]; let t7; return $[16] !== renderWrapper || $[17] !== t5 || $[18] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(ConditionalWrapper, { condition: t5, wrapper: renderWrapper, children: t6 }), $[16] = renderWrapper, $[17] = t5, $[18] = t6, $[19] = t7) : t7 = $[19], t7; }), Dialog = React.forwardRef(function(t0, ref) { const $ = reactCompilerRuntime.c(21); let bodyHeight, children, footer, props, t1, zOffset; $[0] !== t0 ? ({ bodyHeight, children, footer, padding: t1, zOffset, ...props } = t0, $[0] = t0, $[1] = bodyHeight, $[2] = children, $[3] = footer, $[4] = props, $[5] = t1, $[6] = zOffset) : (bodyHeight = $[1], children = $[2], footer = $[3], props = $[4], t1 = $[5], zOffset = $[6]); const padding = t1 === void 0 ? !0 : t1, { t } = reactI18next.useTranslation(); let t2; $[7] !== footer || $[8] !== props || $[9] !== t ? (t2 = (footer?.confirmButton || footer?.cancelButton) && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { width: "full", gap: 3, justify: "flex-end", padding: 3, align: "center", children: [ footer?.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, paddingLeft: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, children: footer.description }) }), props.onClose && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { mode: "bleed", padding: 2, text: t("common.dialog.cancel-button.text"), tone: "default", onClick: props.onClose, "data-testid": "cancel-button", ...footer.cancelButton }), footer.confirmButton && /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { mode: "default", padding: 2, text: t("common.dialog.confirm-button.text"), tone: "critical", "data-testid": "confirm-button", ...footer.confirmButton }) ] }), $[7] = footer, $[8] = props, $[9] = t, $[10] = t2) : t2 = $[10]; const t3 = padding ? 4 : 0; let t4; $[11] !== bodyHeight || $[12] !== children || $[13] !== t3 ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { height: bodyHeight, padding: t3, children }), $[11] = bodyHeight, $[12] = children, $[13] = t3, $[14] = t4) : t4 = $[14]; let t5; return $[15] !== props || $[16] !== ref || $[17] !== t2 || $[18] !== t4 || $[19] !== zOffset ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(ui.Dialog, { ...props, animate: !0, zOffset, ref, footer: t2, children: t4 }), $[15] = props, $[16] = ref, $[17] = t2, $[18] = t4, $[19] = zOffset, $[20] = t5) : t5 = $[20], t5; }); function ErrorBoundary({ onCatch, ...rest }) { const source = React.useContext(_singletons.SourceContext), handleCatch = React.useCallback(({ error: caughtError, info: caughtInfo }) => { try { source?.onUncaughtError?.(caughtError, caughtInfo); } catch (e) { e.message = `Encountered an additional error when calling custom "onUncaughtError()": ${e.message}`, console.error(e); } onCatch?.({ error: caughtError, info: caughtInfo }); }, [source, onCatch]); return /* @__PURE__ */ jsxRuntime.jsx(ui.ErrorBoundary, { ...rest, onCatch: handleCatch }); } const MenuButton = React.forwardRef(function(props, ref) { const $ = reactCompilerRuntime.c(6); let t0; $[0] !== props.popover ? (t0 = { ...props.popover, animate: !0 }, $[0] = props.popover, $[1] = t0) : t0 = $[1]; let t1; return $[2] !== props || $[3] !== ref || $[4] !== t0 ? (t1 = /* @__PURE__ */ jsxRuntime.jsx(ui.MenuButton, { ...props, ref, popover: t0 }), $[2] = props, $[3] = ref, $[4] = t0, $[5] = t1) : t1 = $[5], t1; }); function Hotkeys(t0) { const $ = reactCompilerRuntime.c(12); let props, t1, t2; $[0] !== t0 ? ({ makePlatformAware: t1, keys: t2, ...props } = t0, $[0] = t0, $[1] = props, $[2] = t1, $[3] = t2) : (props = $[1], t1 = $[2], t2 = $[3]); const makePlatformAware = t1 === void 0 ? !0 : t1; let t3; $[4] !== t2 ? (t3 = t2 === void 0 ? [] : t2, $[4] = t2, $[5] = t3) : t3 = $[5]; const hotKeys = t3; let t4; $[6] !== hotKeys || $[7] !== makePlatformAware ? (t4 = makePlatformAware ? hotKeys.map(platformifyKey) : hotKeys, $[6] = hotKeys, $[7] = makePlatformAware, $[8] = t4) : t4 = $[8]; const keys = t4; let t5; return $[9] !== keys || $[10] !== props ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(ui.Hotkeys, { ...props, keys }), $[9] = keys, $[10] = props, $[11] = t5) : t5 = $[11], t5; } const IS_APPLE_DEVICE = typeof navigator > "u" || typeof navigator.platform != "string" ? !1 : /Mac|iPod|iPhone|iPad/.test(navigator.platform || ""); function platformifyKey(key) { const lowerKey = key.toLowerCase(); return lowerKey === "alt" && IS_APPLE_DEVICE ? matchCase(key, "option") : lowerKey === "option" && !IS_APPLE_DEVICE ? matchCase(key, "alt") : key; } function matchCase(original, target) { const orgLength = original.length; return target.replace(/./g, (char, i) => i < orgLength && original[i] === original[i].toUpperCase() ? char.toUpperCase() : char); } const 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 $ = reactCompilerRuntime.c(19); let content, hotkeys, rest; if ($[0] !== props ? ({ content, hotkeys, ...rest } = props, $[0] = props, $[1] = content, $[2] = hotkeys, $[3] = rest) : (content = $[1], hotkeys = $[2], rest = $[3]), typeof content == "string") { let t02; $[4] !== content ? (t02 = content && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, padding: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, children: content }) }), $[4] = content, $[5] = t02) : t02 = $[5]; let t1; $[6] !== hotkeys ? (t1 = hotkeys && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", children: /* @__PURE__ */ jsxRuntime.jsx(Hotkeys, { keys: hotkeys }) }), $[6] = hotkeys, $[7] = t1) : t1 = $[7]; let t2; $[8] !== t02 || $[9] !== t1 ? (t2 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", children: [ t02, t1 ] }), $[8] = t02, $[9] = t1, $[10] = t2) : t2 = $[10]; let t3; return $[11] !== ref || $[12] !== rest || $[13] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { ...TOOLTIP_SHARED_PROPS, content: t2, padding: 1, ref, ...rest }), $[11] = ref, $[12] = rest, $[13] = t2, $[14] = t3) : t3 = $[14], t3; } let t0; return $[15] !== content || $[16] !== ref || $[17] !== rest ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { ...TOOLTIP_SHARED_PROPS, content, ref, ...rest }), $[15] = content, $[16] = ref, $[17] = rest, $[18] = t0) : t0 = $[18], t0; }), FONT_SIZE = 1, SUBTITLE_FONT_SIZE = 0, SubtitleText = styledComponents.styled(ui.Text)` margin-top: 2px; `, PreviewWrapper = styledComponents.styled(ui.Box)` height: 25px; width: 25px; overflow: hidden; `, MenuItem = React.forwardRef(function(t0, ref) { const $ = reactCompilerRuntime.c(49); let Icon, IconRight, __unstable_space, __unstable_subtitle, badgeText, childrenProp, disabled, hotkeys, renderMenuItem, rest, t1, text, tooltipProps; $[0] !== t0 ? ({ badgeText, children: childrenProp, disabled, hotkeys, icon: Icon, iconRight: IconRight, preview: t1, renderMenuItem, text, tooltipProps, __unstable_subtitle, __unstable_space, ...rest } = t0, $[0] = t0, $[1] = Icon, $[2] = IconRight, $[3] = __unstable_space, $[4] = __unstable_subtitle, $[5] = badgeText, $[6] = childrenProp, $[7] = disabled, $[8] = hotkeys, $[9] = renderMenuItem, $[10] = rest, $[11] = t1, $[12] = text, $[13] = tooltipProps) : (Icon = $[1], IconRight = $[2], __unstable_space = $[3], __unstable_subtitle = $[4], badgeText = $[5], childrenProp = $[6], disabled = $[7], hotkeys = $[8], renderMenuItem = $[9], rest = $[10], t1 = $[11], text = $[12], tooltipProps = $[13]); const preview = t1 === void 0 ? null : t1; let t2, t3; $[14] !== __unstable_space || $[15] !== disabled || $[16] !== preview ? (t3 = 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 }) }), $[14] = __unstable_space, $[15] = disabled, $[16] = preview, $[17] = t3) : t3 = $[17]; let t4; $[18] !== Icon ? (t4 = 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) && /* @__PURE__ */ jsxRuntime.jsx(Icon, {}) ] }) }), $[18] = Icon, $[19] = t4) : t4 = $[19]; let t5; $[20] !== __unstable_subtitle || $[21] !== text ? (t5 = 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 }) ] }), $[20] = __unstable_subtitle, $[21] = text, $[22] = t5) : t5 = $[22]; let t6; $[23] !== IconRight || $[24] !== badgeText || $[25] !== hotkeys ? (t6 = (badgeText || hotkeys || IconRight) && /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 3, marginLeft: 3, children: [ hotkeys && /* @__PURE__ */ jsxRuntime.jsx(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) && /* @__PURE__ */ jsxRuntime.jsx(IconRight, {}) ] }) ] }), $[23] = IconRight, $[24] = badgeText, $[25] = hotkeys, $[26] = t6) : t6 = $[26]; let t7; $[27] !== t3 || $[28] !== t4 || $[29] !== t5 || $[30] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", gap: 2, children: [ t3, t4, t5, t6 ] }), $[27] = t3, $[28] = t4, $[29] = t5, $[30] = t6, $[31] = t7) : t7 = $[31], t2 = t7; const menuItemContent = t2; let t8; $[32] !== tooltipProps ? (t8 = (children) => /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { content: tooltipProps?.content, portal: !0, ...tooltipProps, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children }) }), $[32] = tooltipProps, $[33] = t8) : t8 = $[33]; const renderWrapper = t8, t9 = !!tooltipProps, t10 = preview ? 1 : 3, t11 = preview ? 1 : 3; let t12; $[34] !== childrenProp || $[35] !== menuItemContent || $[36] !== renderMenuItem ? (t12 = typeof childrenProp > "u" && typeof renderMenuItem == "function" ? renderMenuItem(menuItemContent) : menuItemContent, $[34] = childrenProp, $[35] = menuItemContent, $[36] = renderMenuItem, $[37] = t12) : t12 = $[37]; let t13; $[38] !== disabled || $[39] !== ref || $[40] !== rest || $[41] !== t10 || $[42] !== t11 || $[43] !== t12 ? (t13 = /* @__PURE__ */ jsxRuntime.jsx(ui.MenuItem, { disabled, paddingLeft: t10, paddingRight: 3, paddingY: t11, ref, ...rest, children: t12 }), $[38] = disabled, $[39] = ref, $[40] = rest, $[41] = t10, $[42] = t11, $[43] = t12, $[44] = t13) : t13 = $[44]; let t14; return $[45] !== renderWrapper || $[46] !== t13 || $[47] !== t9 ? (t14 = /* @__PURE__ */ jsxRuntime.jsx(ConditionalWrapper, { condition: t9, wrapper: renderWrapper, children: t13 }), $[45] = renderWrapper, $[46] = t13, $[47] = t9, $[48] = t14) : t14 = $[48], t14; }), Popover = React.forwardRef(function(props, ref) { const $ = reactCompilerRuntime.c(3); let t0; return $[0] !== props || $[1] !== ref ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(ui.Popover, { ...props, animate: !0, ref }), $[0] = props, $[1] = ref, $[2] = t0) : t0 = $[2], t0; }), Tab = React.forwardRef(function(t0, ref) { const $ = reactCompilerRuntime.c(7); let props, t1; $[0] !== t0 ? ({ tone: t1, ...props } = t0, $[0] = t0, $[1] = props, $[2] = t1) : (props = $[1], t1 = $[2]); const tone = t1 === void 0 ? "default" : t1; let t2; return $[3] !== props || $[4] !== ref || $[5] !== tone ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(ui.Tab, { ...props, muted: !0, padding: 2, ref, tone }), $[3] = props, $[4] = ref, $[5] = tone, $[6] = t2) : t2 = $[6], t2; }), TooltipDelayGroupProvider = (props) => { const $ = reactCompilerRuntime.c(2); let t0; return $[0] !== props.children ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(ui.TooltipDelayGroupProvider, { delay: TOOLTIP_DELAY_PROPS, children: props.children }), $[0] = props.children, $[1] = t0) : t0 = $[1], t0; }; exports.Button = Button; exports.ConditionalWrapper = ConditionalWrapper; exports.Dialog = Dialog; exports.ErrorBoundary = ErrorBoundary; exports.Hotkeys = Hotkeys; exports.MenuButton = MenuButton; exports.MenuItem = MenuItem; exports.Popover = Popover; exports.Tab = Tab; exports.Tooltip = Tooltip; exports.TooltipDelayGroupProvider = TooltipDelayGroupProvider; //# sourceMappingURL=TooltipDelayGroupProvider.js.map