@stackone/malachite 2.67.0 → 2.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"Popover.js","sources":["../../src/components/Popover.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { ShadowRootWrapper } from '../ShadowRootWrapper';\nimport {\n PopoverAction,\n PopoverEmpty,\n PopoverHeader,\n PopoverList,\n PopoverSection,\n} from './PopoverParts';\nimport { getDeepActiveElement } from './activeElement';\nimport { chainHandler, composeRefs, elementRef } from './composeRefs';\nimport { pushEscapeLayer } from './escapeLayers';\nimport {\n type FloatingOffset,\n type FloatingPlacement,\n MENU_VIEWPORT_PADDING_PX,\n} from './floatingMenuGeometry';\nimport { firstTabStopIn } from './overlayBehaviour';\nimport { usePopupLayer } from './overlayLayers';\nimport { PopoverShownContext, PopoverTreeContext } from './popoverTree';\nimport { useHoverClose } from './useHoverClose';\nimport { useLatestRef } from './useLatestRef';\nimport { usePopoverPosition } from './usePopoverPosition';\nimport { usePopoverTree } from './usePopoverTree';\n\nexport type PopoverPlacement = FloatingPlacement;\n\nexport type PopoverInitialFocus =\n | React.RefObject<HTMLElement | null>\n | (() => HTMLElement | null | undefined);\n\ninterface PopoverBaseProps {\n trigger: React.ReactElement;\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n placement?: PopoverPlacement;\n openOn?: 'click' | 'hover';\n width?: 'content' | 'trigger';\n padding?: 'none' | 'small' | 'medium';\n anchorRef?: React.RefObject<HTMLElement | null>;\n offset?: FloatingOffset;\n elevation?: 'default' | 'raised';\n /** A click panel also opens, focus inside, on the arrow key its placement points at. */\n openOnArrowKey?: boolean;\n role?: 'dialog' | 'menu' | 'listbox';\n className?: string;\n}\n\ntype PopoverName =\n | { 'aria-label': string; 'aria-labelledby'?: string }\n | { 'aria-label'?: string; 'aria-labelledby': string };\n\ntype PopoverFocusSource =\n | {\n /**\n * What takes focus when the panel is shown, in place of its first tab stop. Re-read as the\n * content changes, so focus follows late content but never leaves where the user moved it.\n */\n initialFocus?: PopoverInitialFocus;\n initialFocusRef?: never;\n }\n | {\n initialFocus?: never;\n /** @deprecated Use `initialFocus`, which takes the same ref and also follows late content. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n };\n\nexport type PopoverProps = PopoverBaseProps & PopoverName & PopoverFocusSource;\n\nconst PANEL =\n 'font-sans box-border overflow-auto outline-none rounded-[var(--malachite-radius-xl,12px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-text-primary,rgb(10,10,10))]';\n\nconst ELEVATION: Record<NonNullable<PopoverBaseProps['elevation']>, string> = {\n default: '[box-shadow:0px_4px_10px_0px_var(--malachite-card-shadow,rgba(0,0,0,0.1))]',\n raised: '[box-shadow:0px_8px_24px_0px_var(--malachite-card-shadow,rgba(0,0,0,0.1))]',\n};\n\nconst PADDING: Record<NonNullable<PopoverBaseProps['padding']>, string> = {\n none: 'p-0',\n small: 'p-1',\n medium: 'p-2',\n};\n\nconst pathHits = (path: EventTarget[], nodes: Iterable<Element | null | undefined>): boolean => {\n for (const node of nodes) {\n if (node && path.includes(node)) {\n return true;\n }\n }\n return false;\n};\n\nconst KEYBOARD_OPEN_KEY: Record<string, string> = {\n bottom: 'ArrowDown',\n top: 'ArrowUp',\n right: 'ArrowRight',\n left: 'ArrowLeft',\n};\n\nconst isTextEntry = (target: EventTarget): boolean =>\n target instanceof HTMLElement &&\n (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));\n\nconst composedPathOf = (node: EventTarget | null): Node[] => {\n if (!(node instanceof Node)) {\n return [];\n }\n const root = node.getRootNode();\n return [node, ...(root instanceof ShadowRoot ? composedPathOf(root.host) : [])];\n};\n\nconst subscribeToNothing = () => () => undefined;\nconst onClient = () => true;\nconst onServer = () => false;\n\nconst focusTarget = (panel: HTMLElement, initial: HTMLElement | null | undefined): HTMLElement =>\n initial ?? firstTabStopIn(panel) ?? panel;\n\nconst resolveFocus = (source: PopoverInitialFocus | undefined): HTMLElement | null | undefined =>\n typeof source === 'function' ? source() : source?.current;\n\n// Some engines keep a removed element as `activeElement`, and a shadow host with nothing\n// focused inside it holds focus for no one.\nconst focusIsLost = (active: HTMLElement | null, host: HTMLElement | null): boolean =>\n !active || active === document.body || !active.isConnected || active === host;\n\n/** An anchored, non-modal panel; nested Popovers count as inside their parent. */\nconst PopoverRoot: React.FC<PopoverProps> = ({\n trigger,\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n placement = 'bottom-start',\n openOn = 'click',\n width = 'content',\n padding = 'small',\n anchorRef,\n offset = 'small',\n elevation = 'default',\n initialFocus,\n initialFocusRef,\n openOnArrowKey = false,\n role = 'dialog',\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}) => {\n const parent = useContext(PopoverTreeContext);\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const isOpen = controlledOpen ?? uncontrolledOpen;\n const isClient = useSyncExternalStore(subscribeToNothing, onClient, onServer);\n\n const triggerRef = useRef<HTMLElement | null>(null);\n const hostRef = useRef<HTMLDivElement | null>(null);\n const popupIdentity = usePopupLayer('popover', isOpen, hostRef);\n const [panel, setPanel] = useState<HTMLDivElement | null>(null);\n const heldByChildren = useRef(0);\n const focusOnOpen = useRef(false);\n const returningFocus = useRef(false);\n const pointerPressedTrigger = useRef(false);\n const placedFocus = useRef<HTMLElement | null>(null);\n const heldFocus = useRef<HTMLElement | null>(null);\n\n const isOpenRef = useLatestRef(isOpen);\n const controlledRef = useLatestRef(controlledOpen);\n const onOpenChangeRef = useLatestRef(onOpenChange);\n const initialFocusSource = useLatestRef(initialFocus);\n const followsContent = initialFocus !== undefined;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (next === isOpenRef.current) {\n return;\n }\n if (controlledRef.current === undefined) {\n setUncontrolledOpen(next);\n }\n onOpenChangeRef.current?.(next);\n },\n [isOpenRef, controlledRef, onOpenChangeRef],\n );\n\n const { pointerInside, focusInside, triggerFocused, cancelClose, scheduleClose } =\n useHoverClose({\n isOpenRef,\n heldByChildren,\n setOpen,\n });\n\n const { tree, ownedSources } = usePopoverTree({\n parent,\n isOpen,\n openOn,\n isOpenRef,\n heldByChildren,\n cancelClose,\n scheduleClose,\n });\n\n const geometry = usePopoverPosition({\n isOpen,\n panel,\n hostRef,\n triggerRef,\n anchorRef,\n placement,\n width,\n offset,\n });\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const closeOnOutsidePress = (event: MouseEvent) => {\n const path = event.composedPath();\n const inside = pathHits(path, [\n triggerRef.current,\n hostRef.current,\n ...[...ownedSources.current].map((source) => source()),\n ]);\n if (!inside) {\n setOpen(false);\n }\n };\n document.addEventListener('mousedown', closeOnOutsidePress, true);\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n return () => {\n document.removeEventListener('mousedown', closeOnOutsidePress, true);\n popEscapeLayer();\n pointerInside.current = false;\n const active = getDeepActiveElement();\n if (focusInside.current && (!active || active === document.body)) {\n returningFocus.current = true;\n triggerRef.current?.focus({ preventScroll: true });\n returningFocus.current = false;\n }\n focusInside.current = false;\n placedFocus.current = null;\n heldFocus.current = null;\n };\n }, [isOpen, setOpen, ownedSources, pointerInside, focusInside]);\n\n const shown = isOpen && panel !== null && geometry !== null;\n\n const placeFocus = useCallback((target: HTMLElement) => {\n placedFocus.current = target;\n target.focus({ preventScroll: true });\n }, []);\n\n useEffect(() => {\n const shouldFocus = openOn === 'click' || focusOnOpen.current;\n if (!shown || !panel || !shouldFocus) {\n return;\n }\n focusOnOpen.current = false;\n const initial = followsContent\n ? resolveFocus(initialFocusSource.current)\n : initialFocusRef?.current;\n placeFocus(focusTarget(panel, initial));\n }, [shown, panel, openOn, followsContent, initialFocusRef, initialFocusSource, placeFocus]);\n\n useEffect(() => {\n if (!shown || !panel || !followsContent) {\n return;\n }\n const followContent = () => {\n const active = getDeepActiveElement();\n if (focusIsLost(active, hostRef.current)) {\n if (heldFocus.current && !heldFocus.current.isConnected) {\n placeFocus(focusTarget(panel, resolveFocus(initialFocusSource.current)));\n }\n return;\n }\n if (active !== placedFocus.current) {\n return;\n }\n const next =\n resolveFocus(initialFocusSource.current) ??\n (active === panel ? firstTabStopIn(panel) : null);\n if (next && next !== active && next.isConnected) {\n placeFocus(next);\n }\n };\n const observer = new MutationObserver(followContent);\n observer.observe(panel, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, [shown, panel, followsContent, initialFocusSource, placeFocus]);\n\n const openWithFocus = () => {\n cancelClose();\n if (isOpen && panel) {\n const initial = followsContent\n ? resolveFocus(initialFocusSource.current)\n : initialFocusRef?.current;\n placeFocus(focusTarget(panel, initial));\n return;\n }\n focusOnOpen.current = true;\n setOpen(true);\n };\n\n const isInside = (node: EventTarget | null): boolean => {\n const containers = [\n triggerRef.current,\n hostRef.current,\n panel,\n ...[...ownedSources.current].map((source) => source()),\n ];\n return composedPathOf(node).some((step) =>\n containers.some((container) => container?.contains(step)),\n );\n };\n\n const closeIfFocusLeft = (next: EventTarget | null) => {\n if (!next) {\n return;\n }\n queueMicrotask(() => {\n if (!isInside(next) && !isInside(getDeepActiveElement())) {\n setOpen(false);\n }\n });\n };\n\n const hoverHandlers =\n openOn === 'hover'\n ? {\n onMouseEnter: () => {\n pointerInside.current = true;\n cancelClose();\n setOpen(true);\n },\n onMouseLeave: () => {\n pointerInside.current = false;\n scheduleClose();\n },\n onPanelMouseOver: () => {\n pointerInside.current = true;\n cancelClose();\n },\n }\n : null;\n\n const triggerProps = trigger.props as Record<string, unknown>;\n type Handler<E extends React.SyntheticEvent> = ((event: E) => void) | undefined;\n\n const ownTriggerRef = elementRef<HTMLElement>(trigger);\n const composedTriggerRef = useMemo(\n () => composeRefs(ownTriggerRef, triggerRef),\n [ownTriggerRef],\n );\n const openKey = KEYBOARD_OPEN_KEY[placement.split('-')[0]];\n\n const clonedTrigger = React.cloneElement(trigger, {\n ref: composedTriggerRef,\n 'aria-haspopup': role,\n 'aria-expanded': isOpen,\n onClick: chainHandler(\n triggerProps.onClick as Handler<React.MouseEvent>,\n (event: React.MouseEvent) => {\n if (openOn !== 'hover') {\n setOpen(!isOpen);\n return;\n }\n const fromKeyboard = event.detail === 0;\n if (fromKeyboard) {\n openWithFocus();\n return;\n }\n cancelClose();\n setOpen(true);\n },\n ),\n ...(hoverHandlers\n ? {\n onMouseEnter: chainHandler(\n triggerProps.onMouseEnter as Handler<React.MouseEvent>,\n hoverHandlers.onMouseEnter,\n ),\n onMouseLeave: chainHandler(\n triggerProps.onMouseLeave as Handler<React.MouseEvent>,\n hoverHandlers.onMouseLeave,\n ),\n onMouseDown: chainHandler(\n triggerProps.onMouseDown as Handler<React.MouseEvent>,\n () => {\n pointerPressedTrigger.current = true;\n setTimeout(() => {\n pointerPressedTrigger.current = false;\n });\n },\n ),\n onFocus: chainHandler(triggerProps.onFocus as Handler<React.FocusEvent>, () => {\n const fromPointer = pointerPressedTrigger.current;\n pointerPressedTrigger.current = false;\n triggerFocused.current = !fromPointer && !returningFocus.current;\n if (returningFocus.current) {\n return;\n }\n cancelClose();\n setOpen(true);\n }),\n onKeyDown: chainHandler(\n triggerProps.onKeyDown as Handler<React.KeyboardEvent>,\n (event: React.KeyboardEvent) => {\n if (event.key !== openKey) {\n return;\n }\n event.preventDefault();\n openWithFocus();\n },\n ),\n }\n : openOnArrowKey\n ? {\n onKeyDown: chainHandler(\n triggerProps.onKeyDown as Handler<React.KeyboardEvent>,\n (event: React.KeyboardEvent) => {\n if (event.key !== openKey || isTextEntry(event.target)) {\n return;\n }\n event.preventDefault();\n openWithFocus();\n },\n ),\n }\n : {}),\n onBlur: chainHandler(\n triggerProps.onBlur as Handler<React.FocusEvent>,\n (event: React.FocusEvent) => {\n triggerFocused.current = false;\n if (!isOpen || isInside(event.relatedTarget)) {\n return;\n }\n if (openOn === 'hover') {\n scheduleClose();\n return;\n }\n closeIfFocusLeft(event.relatedTarget);\n },\n ),\n } as Record<string, unknown>);\n\n const panelStyle: React.CSSProperties = {\n maxHeight: geometry?.maxHeight,\n maxWidth: `calc(100vw - ${MENU_VIEWPORT_PADDING_PX * 2}px)`,\n visibility: geometry ? 'visible' : 'hidden',\n };\n\n return (\n <>\n {clonedTrigger}\n {isOpen &&\n isClient &&\n createPortal(\n <PopoverTreeContext.Provider value={tree}>\n <ShadowRootWrapper\n hostRef={hostRef}\n hostProps={popupIdentity}\n hostStyle={{\n position: 'fixed',\n top: geometry?.top ?? 0,\n left: geometry?.left ?? 0,\n }}\n >\n <div\n ref={setPanel}\n role={role}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n data-side={geometry?.side}\n tabIndex={-1}\n className={`${PANEL} ${ELEVATION[elevation]} ${PADDING[padding]} ${className}`.trim()}\n style={panelStyle}\n // React's mouseenter stops at the shadow host, so the panel listens for mouseover.\n onMouseOver={hoverHandlers?.onPanelMouseOver}\n onMouseLeave={hoverHandlers?.onMouseLeave}\n onFocus={(event) => {\n focusInside.current = true;\n if (event.target !== placedFocus.current) {\n placedFocus.current = null;\n }\n if (\n event.target instanceof HTMLElement &&\n panel?.contains(event.target)\n ) {\n heldFocus.current = event.target;\n }\n cancelClose();\n }}\n onBlur={(event) => {\n if (isInside(event.relatedTarget)) {\n return;\n }\n if (event.relatedTarget) {\n heldFocus.current = null;\n }\n focusInside.current = false;\n if (openOn === 'hover') {\n scheduleClose();\n return;\n }\n closeIfFocusLeft(event.relatedTarget);\n }}\n >\n <PopoverShownContext.Provider value={shown}>\n {children}\n </PopoverShownContext.Provider>\n </div>\n </ShadowRootWrapper>\n </PopoverTreeContext.Provider>,\n document.body,\n )}\n </>\n );\n};\n\nexport const Popover = Object.assign(PopoverRoot, {\n Header: PopoverHeader,\n Action: PopoverAction,\n List: PopoverList,\n Section: PopoverSection,\n Empty: PopoverEmpty,\n});\n\nexport default Popover;\n"],"names":["PANEL","ELEVATION","PADDING","pathHits","path","nodes","node","KEYBOARD_OPEN_KEY","isTextEntry","target","composedPathOf","root","subscribeToNothing","onClient","onServer","focusTarget","panel","initial","firstTabStopIn","resolveFocus","source","focusIsLost","active","host","PopoverRoot","trigger","children","controlledOpen","defaultOpen","onOpenChange","placement","openOn","width","padding","anchorRef","offset","elevation","initialFocus","initialFocusRef","openOnArrowKey","role","ariaLabel","ariaLabelledBy","className","parent","useContext","PopoverTreeContext","uncontrolledOpen","setUncontrolledOpen","useState","isOpen","isClient","useSyncExternalStore","triggerRef","useRef","hostRef","popupIdentity","usePopupLayer","setPanel","heldByChildren","focusOnOpen","returningFocus","pointerPressedTrigger","placedFocus","heldFocus","isOpenRef","useLatestRef","controlledRef","onOpenChangeRef","initialFocusSource","followsContent","setOpen","useCallback","next","_a","pointerInside","focusInside","triggerFocused","cancelClose","scheduleClose","useHoverClose","tree","ownedSources","usePopoverTree","geometry","usePopoverPosition","useEffect","closeOnOutsidePress","event","popEscapeLayer","pushEscapeLayer","getDeepActiveElement","shown","placeFocus","shouldFocus","followContent","observer","openWithFocus","isInside","containers","step","container","closeIfFocusLeft","hoverHandlers","triggerProps","ownTriggerRef","elementRef","composedTriggerRef","useMemo","composeRefs","openKey","clonedTrigger","React","chainHandler","fromPointer","panelStyle","MENU_VIEWPORT_PADDING_PX","jsxs","Fragment","createPortal","jsx","ShadowRootWrapper","PopoverShownContext","Popover","PopoverHeader","PopoverAction","PopoverList","PopoverSection","PopoverEmpty"],"mappings":";;;;;;;;;;;;;;;;AAgFA,MAAMA,KACF,kRAEEC,KAAwE;AAAA,EAC1E,SAAS;AAAA,EACT,QAAQ;AACZ,GAEMC,KAAoE;AAAA,EACtE,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ,GAEMC,KAAW,CAACC,GAAqBC,MAAyD;AAC5F,aAAW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,YAC7BA,EAAY,UAAU,OAGtByB,EAAM,kBAAkB,gBACxBxE,KAAA,QAAAA,EAAO,SAASwE,EAAM,aAEtBxB,EAAU,UAAUwB,EAAM,SAE9BV,EAAA;AAAA,cACJ;AAAA,cACA,QAAQ,CAACU,MAAU;AACf,oBAAI,CAAAU,EAASV,EAAM,aAAa,GAOhC;AAAA,sBAJIA,EAAM,kBACNxB,EAAU,UAAU,OAExBY,EAAY,UAAU,IAClB7C,MAAW,SAAS;AACpB,oBAAAgD,EAAA;AACA;AAAA,kBACJ;AACA,kBAAAuB,EAAiBd,EAAM,aAAa;AAAA;AAAA,cACxC;AAAA,cAEA,4BAACkC,GAAoB,UAApB,EAA6B,OAAO9B,GAChC,UAAAlE,EAAA,CACL;AAAA,YAAA;AAAA,UAAA;AAAA,QACJ;AAAA,MAAA,GAER;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER,GAEaiG,KAAU,OAAO,OAAOnG,IAAa;AAAA,EAC9C,QAAQoG;AAAA,EACR,QAAQC;AAAA,EACR,MAAMC;AAAA,EACN,SAASC;AAAA,EACT,OAAOC;AACX,CAAC;"}
1
+ {"version":3,"file":"Popover.js","sources":["../../src/components/Popover.tsx"],"sourcesContent":["import React, {\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { ShadowRootWrapper } from '../ShadowRootWrapper';\nimport {\n PopoverAction,\n PopoverEmpty,\n PopoverHeader,\n PopoverList,\n PopoverNote,\n PopoverSearch,\n PopoverSection,\n PopoverStatus,\n} from './PopoverParts';\nimport { getDeepActiveElement } from './activeElement';\nimport { chainHandler, composeRefs, elementRef } from './composeRefs';\nimport { pushEscapeLayer } from './escapeLayers';\nimport {\n type FloatingOffset,\n type FloatingPlacement,\n MENU_VIEWPORT_PADDING_PX,\n} from './floatingMenuGeometry';\nimport { firstTabStopIn } from './overlayBehaviour';\nimport { usePopupLayer } from './overlayLayers';\nimport { PopoverShownContext, PopoverTreeContext } from './popoverTree';\nimport { useHoverClose } from './useHoverClose';\nimport { useLatestRef } from './useLatestRef';\nimport { usePopoverPosition } from './usePopoverPosition';\nimport { usePopoverTree } from './usePopoverTree';\n\nexport type PopoverPlacement = FloatingPlacement;\n\nexport type PopoverInitialFocus =\n | React.RefObject<HTMLElement | null>\n | (() => HTMLElement | null | undefined);\n\ninterface PopoverBaseProps {\n trigger: React.ReactElement;\n children?: React.ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n placement?: PopoverPlacement;\n openOn?: 'click' | 'hover';\n width?: 'content' | 'trigger';\n padding?: 'none' | 'small' | 'medium';\n anchorRef?: React.RefObject<HTMLElement | null>;\n offset?: FloatingOffset;\n elevation?: 'default' | 'raised';\n /** A click panel also opens, focus inside, on the arrow key its placement points at. */\n openOnArrowKey?: boolean;\n role?: 'dialog' | 'menu' | 'listbox';\n className?: string;\n}\n\ntype PopoverName =\n | { 'aria-label': string; 'aria-labelledby'?: string }\n | { 'aria-label'?: string; 'aria-labelledby': string };\n\ntype PopoverFocusSource =\n | {\n /**\n * What takes focus when the panel is shown, in place of its first tab stop. Re-read as the\n * content changes, so focus follows late content but never leaves where the user moved it.\n */\n initialFocus?: PopoverInitialFocus;\n initialFocusRef?: never;\n }\n | {\n initialFocus?: never;\n /** @deprecated Use `initialFocus`, which takes the same ref and also follows late content. */\n initialFocusRef?: React.RefObject<HTMLElement | null>;\n };\n\nexport type PopoverProps = PopoverBaseProps & PopoverName & PopoverFocusSource;\n\nconst PANEL =\n 'font-sans box-border overflow-auto outline-none rounded-[var(--malachite-radius-xl,12px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] text-[var(--malachite-text-primary,rgb(10,10,10))]';\n\nconst ELEVATION: Record<NonNullable<PopoverBaseProps['elevation']>, string> = {\n default: '[box-shadow:0px_4px_10px_0px_var(--malachite-card-shadow,rgba(0,0,0,0.1))]',\n raised: '[box-shadow:0px_8px_24px_0px_var(--malachite-card-shadow,rgba(0,0,0,0.1))]',\n};\n\nconst PADDING: Record<NonNullable<PopoverBaseProps['padding']>, string> = {\n none: 'p-0',\n small: 'p-1',\n medium: 'p-2',\n};\n\nconst pathHits = (path: EventTarget[], nodes: Iterable<Element | null | undefined>): boolean => {\n for (const node of nodes) {\n if (node && path.includes(node)) {\n return true;\n }\n }\n return false;\n};\n\nconst KEYBOARD_OPEN_KEY: Record<string, string> = {\n bottom: 'ArrowDown',\n top: 'ArrowUp',\n right: 'ArrowRight',\n left: 'ArrowLeft',\n};\n\nconst isTextEntry = (target: EventTarget): boolean =>\n target instanceof HTMLElement &&\n (target.isContentEditable || ['INPUT', 'TEXTAREA', 'SELECT'].includes(target.tagName));\n\nconst composedPathOf = (node: EventTarget | null): Node[] => {\n if (!(node instanceof Node)) {\n return [];\n }\n const root = node.getRootNode();\n return [node, ...(root instanceof ShadowRoot ? composedPathOf(root.host) : [])];\n};\n\nconst subscribeToNothing = () => () => undefined;\nconst onClient = () => true;\nconst onServer = () => false;\n\nconst focusTarget = (panel: HTMLElement, initial: HTMLElement | null | undefined): HTMLElement =>\n initial ?? firstTabStopIn(panel) ?? panel;\n\nconst resolveFocus = (source: PopoverInitialFocus | undefined): HTMLElement | null | undefined =>\n typeof source === 'function' ? source() : source?.current;\n\n// Some engines keep a removed element as `activeElement`, and a shadow host with nothing\n// focused inside it holds focus for no one.\nconst focusIsLost = (active: HTMLElement | null, host: HTMLElement | null): boolean =>\n !active || active === document.body || !active.isConnected || active === host;\n\n/** An anchored, non-modal panel; nested Popovers count as inside their parent. */\nconst PopoverRoot: React.FC<PopoverProps> = ({\n trigger,\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n placement = 'bottom-start',\n openOn = 'click',\n width = 'content',\n padding = 'small',\n anchorRef,\n offset = 'small',\n elevation = 'default',\n initialFocus,\n initialFocusRef,\n openOnArrowKey = false,\n role = 'dialog',\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}) => {\n const parent = useContext(PopoverTreeContext);\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const isOpen = controlledOpen ?? uncontrolledOpen;\n const isClient = useSyncExternalStore(subscribeToNothing, onClient, onServer);\n\n const triggerRef = useRef<HTMLElement | null>(null);\n const hostRef = useRef<HTMLDivElement | null>(null);\n const popupIdentity = usePopupLayer('popover', isOpen, hostRef);\n const [panel, setPanel] = useState<HTMLDivElement | null>(null);\n const heldByChildren = useRef(0);\n const focusOnOpen = useRef(false);\n const returningFocus = useRef(false);\n const pointerPressedTrigger = useRef(false);\n const placedFocus = useRef<HTMLElement | null>(null);\n const heldFocus = useRef<HTMLElement | null>(null);\n\n const isOpenRef = useLatestRef(isOpen);\n const controlledRef = useLatestRef(controlledOpen);\n const onOpenChangeRef = useLatestRef(onOpenChange);\n const initialFocusSource = useLatestRef(initialFocus);\n const followsContent = initialFocus !== undefined;\n\n const setOpen = useCallback(\n (next: boolean) => {\n if (next === isOpenRef.current) {\n return;\n }\n if (controlledRef.current === undefined) {\n setUncontrolledOpen(next);\n }\n onOpenChangeRef.current?.(next);\n },\n [isOpenRef, controlledRef, onOpenChangeRef],\n );\n\n const { pointerInside, focusInside, triggerFocused, cancelClose, scheduleClose } =\n useHoverClose({\n isOpenRef,\n heldByChildren,\n setOpen,\n });\n\n const { tree, ownedSources } = usePopoverTree({\n parent,\n isOpen,\n openOn,\n isOpenRef,\n heldByChildren,\n cancelClose,\n scheduleClose,\n });\n\n const geometry = usePopoverPosition({\n isOpen,\n panel,\n hostRef,\n triggerRef,\n anchorRef,\n placement,\n width,\n offset,\n });\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const closeOnOutsidePress = (event: MouseEvent) => {\n const path = event.composedPath();\n const inside = pathHits(path, [\n triggerRef.current,\n hostRef.current,\n ...[...ownedSources.current].map((source) => source()),\n ]);\n if (!inside) {\n setOpen(false);\n }\n };\n document.addEventListener('mousedown', closeOnOutsidePress, true);\n const popEscapeLayer = pushEscapeLayer(() => setOpen(false));\n return () => {\n document.removeEventListener('mousedown', closeOnOutsidePress, true);\n popEscapeLayer();\n pointerInside.current = false;\n const active = getDeepActiveElement();\n if (focusInside.current && (!active || active === document.body)) {\n returningFocus.current = true;\n triggerRef.current?.focus({ preventScroll: true });\n returningFocus.current = false;\n }\n focusInside.current = false;\n placedFocus.current = null;\n heldFocus.current = null;\n };\n }, [isOpen, setOpen, ownedSources, pointerInside, focusInside]);\n\n const shown = isOpen && panel !== null && geometry !== null;\n\n const placeFocus = useCallback((target: HTMLElement) => {\n placedFocus.current = target;\n target.focus({ preventScroll: true });\n }, []);\n\n useEffect(() => {\n const shouldFocus = openOn === 'click' || focusOnOpen.current;\n if (!shown || !panel || !shouldFocus) {\n return;\n }\n focusOnOpen.current = false;\n const initial = followsContent\n ? resolveFocus(initialFocusSource.current)\n : initialFocusRef?.current;\n placeFocus(focusTarget(panel, initial));\n }, [shown, panel, openOn, followsContent, initialFocusRef, initialFocusSource, placeFocus]);\n\n useEffect(() => {\n if (!shown || !panel || !followsContent) {\n return;\n }\n const followContent = () => {\n const active = getDeepActiveElement();\n if (focusIsLost(active, hostRef.current)) {\n if (heldFocus.current && !heldFocus.current.isConnected) {\n placeFocus(focusTarget(panel, resolveFocus(initialFocusSource.current)));\n }\n return;\n }\n if (active !== placedFocus.current) {\n return;\n }\n const next =\n resolveFocus(initialFocusSource.current) ??\n (active === panel ? firstTabStopIn(panel) : null);\n if (next && next !== active && next.isConnected) {\n placeFocus(next);\n }\n };\n const observer = new MutationObserver(followContent);\n observer.observe(panel, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, [shown, panel, followsContent, initialFocusSource, placeFocus]);\n\n const openWithFocus = () => {\n cancelClose();\n if (isOpen && panel) {\n const initial = followsContent\n ? resolveFocus(initialFocusSource.current)\n : initialFocusRef?.current;\n placeFocus(focusTarget(panel, initial));\n return;\n }\n focusOnOpen.current = true;\n setOpen(true);\n };\n\n const isInside = (node: EventTarget | null): boolean => {\n const containers = [\n triggerRef.current,\n hostRef.current,\n panel,\n ...[...ownedSources.current].map((source) => source()),\n ];\n return composedPathOf(node).some((step) =>\n containers.some((container) => container?.contains(step)),\n );\n };\n\n const closeIfFocusLeft = (next: EventTarget | null) => {\n if (!next) {\n return;\n }\n queueMicrotask(() => {\n if (!isInside(next) && !isInside(getDeepActiveElement())) {\n setOpen(false);\n }\n });\n };\n\n const hoverHandlers =\n openOn === 'hover'\n ? {\n onMouseEnter: () => {\n pointerInside.current = true;\n cancelClose();\n setOpen(true);\n },\n onMouseLeave: () => {\n pointerInside.current = false;\n scheduleClose();\n },\n onPanelMouseOver: () => {\n pointerInside.current = true;\n cancelClose();\n },\n }\n : null;\n\n const triggerProps = trigger.props as Record<string, unknown>;\n type Handler<E extends React.SyntheticEvent> = ((event: E) => void) | undefined;\n\n const ownTriggerRef = elementRef<HTMLElement>(trigger);\n const composedTriggerRef = useMemo(\n () => composeRefs(ownTriggerRef, triggerRef),\n [ownTriggerRef],\n );\n const openKey = KEYBOARD_OPEN_KEY[placement.split('-')[0]];\n\n const clonedTrigger = React.cloneElement(trigger, {\n ref: composedTriggerRef,\n 'aria-haspopup': role,\n 'aria-expanded': isOpen,\n onClick: chainHandler(\n triggerProps.onClick as Handler<React.MouseEvent>,\n (event: React.MouseEvent) => {\n if (openOn !== 'hover') {\n setOpen(!isOpen);\n return;\n }\n const fromKeyboard = event.detail === 0;\n if (fromKeyboard) {\n openWithFocus();\n return;\n }\n cancelClose();\n setOpen(true);\n },\n ),\n ...(hoverHandlers\n ? {\n onMouseEnter: chainHandler(\n triggerProps.onMouseEnter as Handler<React.MouseEvent>,\n hoverHandlers.onMouseEnter,\n ),\n onMouseLeave: chainHandler(\n triggerProps.onMouseLeave as Handler<React.MouseEvent>,\n hoverHandlers.onMouseLeave,\n ),\n onMouseDown: chainHandler(\n triggerProps.onMouseDown as Handler<React.MouseEvent>,\n () => {\n pointerPressedTrigger.current = true;\n setTimeout(() => {\n pointerPressedTrigger.current = false;\n });\n },\n ),\n onFocus: chainHandler(triggerProps.onFocus as Handler<React.FocusEvent>, () => {\n const fromPointer = pointerPressedTrigger.current;\n pointerPressedTrigger.current = false;\n triggerFocused.current = !fromPointer && !returningFocus.current;\n if (returningFocus.current) {\n return;\n }\n cancelClose();\n setOpen(true);\n }),\n onKeyDown: chainHandler(\n triggerProps.onKeyDown as Handler<React.KeyboardEvent>,\n (event: React.KeyboardEvent) => {\n if (event.key !== openKey) {\n return;\n }\n event.preventDefault();\n openWithFocus();\n },\n ),\n }\n : openOnArrowKey\n ? {\n onKeyDown: chainHandler(\n triggerProps.onKeyDown as Handler<React.KeyboardEvent>,\n (event: React.KeyboardEvent) => {\n if (event.key !== openKey || isTextEntry(event.target)) {\n return;\n }\n event.preventDefault();\n openWithFocus();\n },\n ),\n }\n : {}),\n onBlur: chainHandler(\n triggerProps.onBlur as Handler<React.FocusEvent>,\n (event: React.FocusEvent) => {\n triggerFocused.current = false;\n if (!isOpen || isInside(event.relatedTarget)) {\n return;\n }\n if (openOn === 'hover') {\n scheduleClose();\n return;\n }\n closeIfFocusLeft(event.relatedTarget);\n },\n ),\n } as Record<string, unknown>);\n\n const panelStyle: React.CSSProperties = {\n maxHeight: geometry?.maxHeight,\n maxWidth: `calc(100vw - ${MENU_VIEWPORT_PADDING_PX * 2}px)`,\n visibility: geometry ? 'visible' : 'hidden',\n };\n\n return (\n <>\n {clonedTrigger}\n {isOpen &&\n isClient &&\n createPortal(\n <PopoverTreeContext.Provider value={tree}>\n <ShadowRootWrapper\n hostRef={hostRef}\n hostProps={popupIdentity}\n hostStyle={{\n position: 'fixed',\n top: geometry?.top ?? 0,\n left: geometry?.left ?? 0,\n }}\n >\n <div\n ref={setPanel}\n role={role}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n data-side={geometry?.side}\n tabIndex={-1}\n className={`${PANEL} ${ELEVATION[elevation]} ${PADDING[padding]} ${className}`.trim()}\n style={panelStyle}\n // React's mouseenter stops at the shadow host, so the panel listens for mouseover.\n onMouseOver={hoverHandlers?.onPanelMouseOver}\n onMouseLeave={hoverHandlers?.onMouseLeave}\n onFocus={(event) => {\n focusInside.current = true;\n if (event.target !== placedFocus.current) {\n placedFocus.current = null;\n }\n if (\n event.target instanceof HTMLElement &&\n panel?.contains(event.target)\n ) {\n heldFocus.current = event.target;\n }\n cancelClose();\n }}\n onBlur={(event) => {\n if (isInside(event.relatedTarget)) {\n return;\n }\n if (event.relatedTarget) {\n heldFocus.current = null;\n }\n focusInside.current = false;\n if (openOn === 'hover') {\n scheduleClose();\n return;\n }\n closeIfFocusLeft(event.relatedTarget);\n }}\n >\n <PopoverShownContext.Provider value={shown}>\n {children}\n </PopoverShownContext.Provider>\n </div>\n </ShadowRootWrapper>\n </PopoverTreeContext.Provider>,\n document.body,\n )}\n </>\n );\n};\n\nexport const Popover = Object.assign(PopoverRoot, {\n Header: PopoverHeader,\n Action: PopoverAction,\n List: PopoverList,\n Section: PopoverSection,\n Empty: PopoverEmpty,\n Search: PopoverSearch,\n Status: PopoverStatus,\n Note: PopoverNote,\n});\n\nexport default Popover;\n"],"names":["PANEL","ELEVATION","PADDING","pathHits","path","nodes","node","KEYBOARD_OPEN_KEY","isTextEntry","target","composedPathOf","root","subscribeToNothing","onClient","onServer","focusTarget","panel","initial","firstTabStopIn","resolveFocus","source","focusIsLost","active","host","PopoverRoot","trigger","children","controlledOpen","defaultOpen","onOpenChange","placement","openOn","width","padding","anchorRef","offset","elevation","initialFocus","initialFocusRef","openOnArrowKey","role","ariaLabel","ariaLabelledBy","className","parent","useContext","PopoverTreeContext","uncontrolledOpen","setUncontrolledOpen","useState","isOpen","isClient","useSyncExternalStore","triggerRef","useRef","hostRef","popupIdentity","usePopupLayer","setPanel","heldByChildren","focusOnOpen","returningFocus","pointerPressedTrigger","placedFocus","heldFocus","isOpenRef","useLatestRef","controlledRef","onOpenChangeRef","initialFocusSource","followsContent","setOpen","useCallback","next","_a","pointerInside","focusInside","triggerFocused","cancelClose","scheduleClose","useHoverClose","tree","ownedSources","usePopoverTree","geometry","usePopoverPosition","useEffect","closeOnOutsidePress","event","popEscapeLayer","pushEscapeLayer","getDeepActiveElement","shown","placeFocus","shouldFocus","followContent","observer","openWithFocus","isInside","containers","step","container","closeIfFocusLeft","hoverHandlers","triggerProps","ownTriggerRef","elementRef","composedTriggerRef","useMemo","composeRefs","openKey","clonedTrigger","React","chainHandler","fromPointer","panelStyle","MENU_VIEWPORT_PADDING_PX","jsxs","Fragment","createPortal","jsx","ShadowRootWrapper","PopoverShownContext","Popover","PopoverHeader","PopoverAction","PopoverList","PopoverSection","PopoverEmpty","PopoverSearch","PopoverStatus","PopoverNote"],"mappings":";;;;;;;;;;;;;;;;AAmFA,MAAMA,KACF,kRAEEC,KAAwE;AAAA,EAC1E,SAAS;AAAA,EACT,QAAQ;AACZ,GAEMC,KAAoE;AAAA,EACtE,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AACZ,GAEMC,KAAW,CAACC,GAAqBC,MAAyD;AAC5F,aAAWC,KAAQD;AACf,QAAIC,KAAQF,EAAK,SAASE,CAAI;AAC1B,aAAO;AAGf,SAAO;AACX,GAEMC,KAA4C;AAAA,EAC9C,QAAQ;AAAA,EACR,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM;AACV,GAEMC,KAAc,CAACC,MACjBA,aAAkB,gBACjBA,EAAO,qBAAqB,CAAC,SAAS,YAAY,QAAQ,EAAE,SAASA,EAAO,OAAO,IAElFC,KAAiB,CAACJ,MAAqC;AACzD,MAAI,EAAEA,aAAgB;AAClB,WAAO,CAAA;AAEX,QAAMK,IAAOL,EAAK,YAAA;AAClB,SAAO,CAACA,GAAM,GAAIK,aAAgB,aAAaD,GAAeC,EAAK,IAAI,IAAI,EAAG;AAClF,GAEMC,KAAqB,MAAM,MAAA;AAAA,GAC3BC,KAAW,MAAM,IACjBC,KAAW,MAAM,IAE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AA,IAAA;AAAA,EACb,GACR;AAER,GAEaiG,KAAU,OAAO,OAAOnG,IAAa;AAAA,EAC9C,QAAQoG;AAAA,EACR,QAAQC;AAAA,EACR,MAAMC;AAAA,EACN,SAASC;AAAA,EACT,OAAOC;AAAA,EACP,QAAQC;AAAA,EACR,QAAQC;AAAA,EACR,MAAMC;AACV,CAAC;"}
@@ -1,68 +1,112 @@
1
- import { jsx as n, jsxs as u } from "react/jsx-runtime";
2
- import { forwardRef as f, useContext as v, useRef as x, useLayoutEffect as b } from "react";
3
- import h from "./Tooltip.js";
4
- import { BORDER as m, NO_SCROLLBAR as g } from "./chromeStyles.js";
5
- import { FOCUS_RING_INSET as T } from "./focusRing.js";
6
- import { isPlainClick as R } from "./linkClick.js";
1
+ import { jsx as n, jsxs as u, Fragment as f } from "react/jsx-runtime";
2
+ import { forwardRef as v, useContext as x, useRef as h, useLayoutEffect as b } from "react";
3
+ import { Button as g } from "./Button.js";
4
+ import T from "./Tooltip.js";
5
+ import { BORDER as c, NO_SCROLLBAR as N } from "./chromeStyles.js";
6
+ import { FOCUS_RING_INSET as y } from "./focusRing.js";
7
+ import { isPlainClick as S } from "./linkClick.js";
7
8
  import { PopoverShownContext as w } from "./popoverTree.js";
8
- import { safeHref as y } from "./safeHref.js";
9
- const j = ({ title: e, action: t }) => /* @__PURE__ */ u(
9
+ import { safeHref as R } from "./safeHref.js";
10
+ const F = ({ title: e, action: t }) => /* @__PURE__ */ u(
10
11
  "div",
11
12
  {
12
- className: `flex items-center justify-between border-0 border-b border-solid ${m} px-5 py-4 text-[12px] leading-[15px] font-normal text-[var(--malachite-text-dimmed,rgb(161,161,161))]`,
13
+ className: `flex items-center justify-between border-0 border-b border-solid ${c} px-5 py-4 text-[12px] leading-[15px] font-normal text-[var(--malachite-text-dimmed,rgb(161,161,161))]`,
13
14
  children: [
14
15
  /* @__PURE__ */ n("span", { children: e }),
15
16
  t
16
17
  ]
17
18
  }
18
- ), N = '[aria-current]:not([aria-current="false"]):not([aria-current=""]), [aria-selected="true"], [role="radio"][aria-checked="true"]', E = ["aria-current", "aria-selected", "aria-checked"], d = (e) => {
19
- const t = e.querySelector(N);
19
+ ), E = '[aria-current]:not([aria-current="false"]):not([aria-current=""]), [aria-selected="true"], [role="radio"][aria-checked="true"]', P = ["aria-current", "aria-selected", "aria-checked"], m = (e) => {
20
+ const t = e.querySelector(E);
20
21
  if (!t)
21
22
  return !1;
22
- const o = e.getBoundingClientRect().top + e.clientTop, { top: i, bottom: r } = t.getBoundingClientRect(), a = i - o + e.scrollTop, c = r - o + e.scrollTop;
23
- return a < e.scrollTop ? e.scrollTop = a : c > e.scrollTop + e.clientHeight && (e.scrollTop = c - e.clientHeight), !0;
24
- }, k = ({ children: e, scrollToSelected: t = !1 }) => {
25
- const o = v(w), i = x(null);
23
+ const r = e.getBoundingClientRect().top + e.clientTop, { top: l, bottom: o } = t.getBoundingClientRect(), a = l - r + e.scrollTop, i = o - r + e.scrollTop;
24
+ return a < e.scrollTop ? e.scrollTop = a : i > e.scrollTop + e.clientHeight && (e.scrollTop = i - e.clientHeight), !0;
25
+ }, U = ({ children: e, scrollToSelected: t = !1 }) => {
26
+ const r = x(w), l = h(null);
26
27
  return b(() => {
27
- const r = i.current;
28
- if (!t || !o || !r || d(r))
28
+ const o = l.current;
29
+ if (!t || !r || !o || m(o))
29
30
  return;
30
31
  const a = new MutationObserver(() => {
31
- d(r) && a.disconnect();
32
+ m(o) && a.disconnect();
32
33
  });
33
- return a.observe(r, {
34
+ return a.observe(o, {
34
35
  childList: !0,
35
36
  subtree: !0,
36
37
  attributes: !0,
37
- attributeFilter: E
38
+ attributeFilter: P
38
39
  }), () => a.disconnect();
39
- }, [t, o]), /* @__PURE__ */ n(
40
+ }, [t, r]), /* @__PURE__ */ n(
40
41
  "div",
41
42
  {
42
- ref: i,
43
- className: `flex max-h-80 flex-col gap-[2px] overflow-y-auto p-2 ${g}`,
43
+ ref: l,
44
+ className: `flex max-h-80 flex-col gap-[2px] overflow-y-auto p-2 ${N}`,
44
45
  children: e
45
46
  }
46
47
  );
47
- }, S = f(
48
- ({ children: e }, t) => /* @__PURE__ */ n("div", { ref: t, className: `border-0 border-t border-solid ${m} p-2`, children: e })
48
+ }, C = v(
49
+ ({ children: e }, t) => /* @__PURE__ */ n("div", { ref: t, className: `border-0 border-t border-solid ${c} p-2`, children: e })
49
50
  );
50
- S.displayName = "Popover.Section";
51
- const H = ({ children: e }) => /* @__PURE__ */ n("div", { className: "px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] text-[var(--malachite-text-dimmed,rgb(161,161,161))] select-none", children: e }), z = ({
51
+ C.displayName = "Popover.Section";
52
+ const M = ({ children: e }) => /* @__PURE__ */ n("div", { className: "px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] text-[var(--malachite-text-dimmed,rgb(161,161,161))] select-none", children: e }), q = ({ children: e }) => /* @__PURE__ */ n("div", { className: "px-2 pt-2", children: e }), G = ({ children: e }) => /* @__PURE__ */ n(
53
+ "div",
54
+ {
55
+ className: `border-0 border-t border-solid ${c} px-5 py-3 text-[length:var(--malachite-font-size-xsmall,11px)] leading-4 text-[var(--malachite-text-secondary,rgb(123,123,123))]`,
56
+ children: e
57
+ }
58
+ ), O = {
59
+ default: "text-[var(--malachite-text-secondary,rgb(123,123,123))]",
60
+ error: "text-[var(--malachite-text-error,rgb(237,53,54))]"
61
+ }, _ = (e) => e != null && e !== !1 && e !== "", $ = v(
62
+ ({ message: e, tone: t = "default", action: r, focusable: l = !1 }, o) => {
63
+ const a = _(e);
64
+ return /* @__PURE__ */ u(f, { children: [
65
+ /* @__PURE__ */ n(
66
+ "div",
67
+ {
68
+ ref: o,
69
+ role: "status",
70
+ tabIndex: l ? -1 : void 0,
71
+ className: a ? "outline-none" : "sr-only",
72
+ children: a && /* @__PURE__ */ n(
73
+ "div",
74
+ {
75
+ className: `px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] ${O[t]}`,
76
+ children: e
77
+ }
78
+ )
79
+ }
80
+ ),
81
+ a && r && /* @__PURE__ */ n("div", { className: "px-3 pb-2", children: /* @__PURE__ */ n(
82
+ g,
83
+ {
84
+ variant: "outline",
85
+ size: "small",
86
+ loading: r.pending,
87
+ onClick: r.onClick,
88
+ children: r.label
89
+ }
90
+ ) })
91
+ ] });
92
+ }
93
+ );
94
+ $.displayName = "Popover.Status";
95
+ const V = ({
52
96
  icon: e,
53
97
  "aria-label": t,
54
- onClick: o,
55
- href: i,
56
- disabled: r = !1,
98
+ onClick: r,
99
+ href: l,
100
+ disabled: o = !1,
57
101
  tooltip: a
58
102
  }) => {
59
- const c = r ? void 0 : y(i), s = `m-0 inline-flex size-5 items-center justify-center rounded-[var(--malachite-radius-sm,4px)] border-0 bg-transparent p-0 transition-colors duration-150 [&_svg]:size-3! ${r ? "cursor-not-allowed text-[var(--malachite-text-placeholder,rgb(187,187,187))] opacity-50" : "cursor-pointer text-[var(--malachite-text-placeholder,rgb(187,187,187))] hover:bg-[var(--malachite-pillbutton-background,rgb(241,241,241))] hover:text-[var(--malachite-text-secondary,rgb(123,123,123))]"} ${T}`, l = c !== void 0 ? /* @__PURE__ */ n(
103
+ const i = o ? void 0 : R(l), s = `m-0 inline-flex size-5 items-center justify-center rounded-[var(--malachite-radius-sm,4px)] border-0 bg-transparent p-0 transition-colors duration-150 [&_svg]:size-3! ${o ? "cursor-not-allowed text-[var(--malachite-text-placeholder,rgb(187,187,187))] opacity-50" : "cursor-pointer text-[var(--malachite-text-placeholder,rgb(187,187,187))] hover:bg-[var(--malachite-pillbutton-background,rgb(241,241,241))] hover:text-[var(--malachite-text-secondary,rgb(123,123,123))]"} ${y}`, d = i !== void 0 ? /* @__PURE__ */ n(
60
104
  "a",
61
105
  {
62
- href: c,
106
+ href: i,
63
107
  "aria-label": t,
64
108
  onClick: (p) => {
65
- R(p) && o && (p.preventDefault(), o());
109
+ S(p) && r && (p.preventDefault(), r());
66
110
  },
67
111
  className: `no-underline ${s}`,
68
112
  children: e
@@ -72,19 +116,22 @@ const H = ({ children: e }) => /* @__PURE__ */ n("div", { className: "px-3 py-2
72
116
  {
73
117
  type: "button",
74
118
  "aria-label": t,
75
- "aria-disabled": r || void 0,
76
- onClick: r ? void 0 : o,
119
+ "aria-disabled": o || void 0,
120
+ onClick: o ? void 0 : r,
77
121
  className: s,
78
122
  children: e
79
123
  }
80
124
  );
81
- return a ? /* @__PURE__ */ n(h, { text: a, children: l }) : l;
125
+ return a ? /* @__PURE__ */ n(T, { text: a, children: d }) : d;
82
126
  };
83
127
  export {
84
- z as PopoverAction,
85
- H as PopoverEmpty,
86
- j as PopoverHeader,
87
- k as PopoverList,
88
- S as PopoverSection
128
+ V as PopoverAction,
129
+ M as PopoverEmpty,
130
+ F as PopoverHeader,
131
+ U as PopoverList,
132
+ G as PopoverNote,
133
+ q as PopoverSearch,
134
+ C as PopoverSection,
135
+ $ as PopoverStatus
89
136
  };
90
137
  //# sourceMappingURL=PopoverParts.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PopoverParts.js","sources":["../../src/components/PopoverParts.tsx"],"sourcesContent":["import React, { forwardRef, useContext, useLayoutEffect, useRef } from 'react';\nimport Tooltip from './Tooltip';\nimport { BORDER, NO_SCROLLBAR } from './chromeStyles';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isPlainClick } from './linkClick';\nimport { PopoverShownContext } from './popoverTree';\nimport { safeHref } from './safeHref';\n\nexport interface PopoverHeaderProps {\n title: string;\n action?: React.ReactNode;\n}\n\nexport const PopoverHeader: React.FC<PopoverHeaderProps> = ({ title, action }) => (\n <div\n className={`flex items-center justify-between border-0 border-b border-solid ${BORDER} px-5 py-4 text-[12px] leading-[15px] font-normal text-[var(--malachite-text-dimmed,rgb(161,161,161))]`}\n >\n <span>{title}</span>\n {action}\n </div>\n);\n\nconst SELECTED_ROW =\n '[aria-current]:not([aria-current=\"false\"]):not([aria-current=\"\"]), [aria-selected=\"true\"], [role=\"radio\"][aria-checked=\"true\"]';\nconst SELECTION_ATTRIBUTES = ['aria-current', 'aria-selected', 'aria-checked'];\n\n// Not `scrollIntoView`: that also scrolls every scrollable ancestor, the page included.\nconst scrollSelectedRowIntoView = (list: HTMLElement): boolean => {\n const row = list.querySelector<HTMLElement>(SELECTED_ROW);\n if (!row) {\n return false;\n }\n const listTop = list.getBoundingClientRect().top + list.clientTop;\n const { top, bottom } = row.getBoundingClientRect();\n const rowTop = top - listTop + list.scrollTop;\n const rowBottom = bottom - listTop + list.scrollTop;\n if (rowTop < list.scrollTop) {\n list.scrollTop = rowTop;\n } else if (rowBottom > list.scrollTop + list.clientHeight) {\n list.scrollTop = rowBottom - list.clientHeight;\n }\n return true;\n};\n\nexport interface PopoverListProps {\n children: React.ReactNode;\n /**\n * Scrolls the list to its selected row (`aria-current`, `aria-selected` or a checked radio)\n * each time the popover is shown, once that row mounts. Only the list scrolls.\n */\n scrollToSelected?: boolean;\n}\n\nexport const PopoverList: React.FC<PopoverListProps> = ({ children, scrollToSelected = false }) => {\n const shown = useContext(PopoverShownContext);\n const listRef = useRef<HTMLDivElement>(null);\n\n // Before paint, so a shown panel never draws a frame at the top and then jumps.\n useLayoutEffect(() => {\n const list = listRef.current;\n if (!scrollToSelected || !shown || !list || scrollSelectedRowIntoView(list)) {\n return;\n }\n const observer = new MutationObserver(() => {\n if (scrollSelectedRowIntoView(list)) {\n observer.disconnect();\n }\n });\n observer.observe(list, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: SELECTION_ATTRIBUTES,\n });\n return () => observer.disconnect();\n }, [scrollToSelected, shown]);\n\n return (\n <div\n ref={listRef}\n className={`flex max-h-80 flex-col gap-[2px] overflow-y-auto p-2 ${NO_SCROLLBAR}`}\n >\n {children}\n </div>\n );\n};\n\nexport const PopoverSection = forwardRef<HTMLDivElement, { children: React.ReactNode }>(\n ({ children }, ref) => (\n <div ref={ref} className={`border-0 border-t border-solid ${BORDER} p-2`}>\n {children}\n </div>\n ),\n);\nPopoverSection.displayName = 'Popover.Section';\n\nexport const PopoverEmpty: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <div className=\"px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] text-[var(--malachite-text-dimmed,rgb(161,161,161))] select-none\">\n {children}\n </div>\n);\n\nexport interface PopoverActionProps {\n icon: React.ReactNode;\n 'aria-label': string;\n onClick?: () => void;\n /** Renders a link; a plain click runs `onClick` instead of following it, when one is given. */\n href?: string;\n disabled?: boolean;\n tooltip?: string;\n}\n\nexport const PopoverAction: React.FC<PopoverActionProps> = ({\n icon,\n 'aria-label': ariaLabel,\n onClick,\n href: rawHref,\n disabled = false,\n tooltip,\n}) => {\n const href = disabled ? undefined : safeHref(rawHref);\n const className = `m-0 inline-flex size-5 items-center justify-center rounded-[var(--malachite-radius-sm,4px)] border-0 bg-transparent p-0 transition-colors duration-150 [&_svg]:size-3! ${disabled ? 'cursor-not-allowed text-[var(--malachite-text-placeholder,rgb(187,187,187))] opacity-50' : `cursor-pointer text-[var(--malachite-text-placeholder,rgb(187,187,187))] hover:bg-[var(--malachite-pillbutton-background,rgb(241,241,241))] hover:text-[var(--malachite-text-secondary,rgb(123,123,123))]`} ${FOCUS_RING_INSET}`;\n const button =\n href !== undefined ? (\n <a\n href={href}\n aria-label={ariaLabel}\n onClick={(event) => {\n if (isPlainClick(event) && onClick) {\n event.preventDefault();\n onClick();\n }\n }}\n className={`no-underline ${className}`}\n >\n {icon}\n </a>\n ) : (\n <button\n type=\"button\"\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n onClick={disabled ? undefined : onClick}\n className={className}\n >\n {icon}\n </button>\n );\n return tooltip ? <Tooltip text={tooltip}>{button}</Tooltip> : button;\n};\n"],"names":["PopoverHeader","title","action","jsxs","BORDER","jsx","SELECTED_ROW","SELECTION_ATTRIBUTES","scrollSelectedRowIntoView","list","row","listTop","top","bottom","rowTop","rowBottom","PopoverList","children","scrollToSelected","shown","useContext","PopoverShownContext","listRef","useRef","useLayoutEffect","observer","NO_SCROLLBAR","PopoverSection","forwardRef","ref","PopoverEmpty","PopoverAction","icon","ariaLabel","onClick","rawHref","disabled","tooltip","href","safeHref","className","FOCUS_RING_INSET","button","event","isPlainClick","Tooltip"],"mappings":";;;;;;;;AAaO,MAAMA,IAA8C,CAAC,EAAE,OAAAC,GAAO,QAAAC,QACjE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAW,oEAAoEC,CAAM;AAAA,IAErF,UAAA;AAAA,MAAA,gBAAAC,EAAC,UAAM,UAAAJ,EAAA,CAAM;AAAA,MACZC;AAAA,IAAA;AAAA,EAAA;AACL,GAGEI,IACF,kIACEC,IAAuB,CAAC,gBAAgB,iBAAiB,cAAc,GAGvEC,IAA4B,CAACC,MAA+B;AAC9D,QAAMC,IAAMD,EAAK,cAA2BH,CAAY;AACxD,MAAI,CAACI;AACD,WAAO;AAEX,QAAMC,IAAUF,EAAK,sBAAA,EAAwB,MAAMA,EAAK,WAClD,EAAE,KAAAG,GAAK,QAAAC,MAAWH,EAAI,sBAAA,GACtBI,IAASF,IAAMD,IAAUF,EAAK,WAC9BM,IAAYF,IAASF,IAAUF,EAAK;AAC1C,SAAIK,IAASL,EAAK,YACdA,EAAK,YAAYK,IACVC,IAAYN,EAAK,YAAYA,EAAK,iBACzCA,EAAK,YAAYM,IAAYN,EAAK,eAE/B;AACX,GAWaO,IAA0C,CAAC,EAAE,UAAAC,GAAU,kBAAAC,IAAmB,SAAY;AAC/F,QAAMC,IAAQC,EAAWC,CAAmB,GACtCC,IAAUC,EAAuB,IAAI;AAG3C,SAAAC,EAAgB,MAAM;AAClB,UAAMf,IAAOa,EAAQ;AACrB,QAAI,CAACJ,KAAoB,CAACC,KAAS,CAACV,KAAQD,EAA0BC,CAAI;AACtE;AAEJ,UAAMgB,IAAW,IAAI,iBAAiB,MAAM;AACxC,MAAIjB,EAA0BC,CAAI,KAC9BgB,EAAS,WAAA;AAAA,IAEjB,CAAC;AACD,WAAAA,EAAS,QAAQhB,GAAM;AAAA,MACnB,WAAW;AAAA,MACX,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AAA,MAChC,WAAAM;AAAA,MAEC,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGb,SAAOK,IAAU,gBAAAhC,EAACwC,GAAA,EAAQ,MAAMR,GAAU,aAAO,IAAaK;AAClE;"}
1
+ {"version":3,"file":"PopoverParts.js","sources":["../../src/components/PopoverParts.tsx"],"sourcesContent":["import React, { forwardRef, useContext, useLayoutEffect, useRef } from 'react';\nimport Button from './Button';\nimport Tooltip from './Tooltip';\nimport { BORDER, NO_SCROLLBAR } from './chromeStyles';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isPlainClick } from './linkClick';\nimport { PopoverShownContext } from './popoverTree';\nimport { safeHref } from './safeHref';\n\nexport interface PopoverHeaderProps {\n title: string;\n action?: React.ReactNode;\n}\n\nexport const PopoverHeader: React.FC<PopoverHeaderProps> = ({ title, action }) => (\n <div\n className={`flex items-center justify-between border-0 border-b border-solid ${BORDER} px-5 py-4 text-[12px] leading-[15px] font-normal text-[var(--malachite-text-dimmed,rgb(161,161,161))]`}\n >\n <span>{title}</span>\n {action}\n </div>\n);\n\nconst SELECTED_ROW =\n '[aria-current]:not([aria-current=\"false\"]):not([aria-current=\"\"]), [aria-selected=\"true\"], [role=\"radio\"][aria-checked=\"true\"]';\nconst SELECTION_ATTRIBUTES = ['aria-current', 'aria-selected', 'aria-checked'];\n\n// Not `scrollIntoView`: that also scrolls every scrollable ancestor, the page included.\nconst scrollSelectedRowIntoView = (list: HTMLElement): boolean => {\n const row = list.querySelector<HTMLElement>(SELECTED_ROW);\n if (!row) {\n return false;\n }\n const listTop = list.getBoundingClientRect().top + list.clientTop;\n const { top, bottom } = row.getBoundingClientRect();\n const rowTop = top - listTop + list.scrollTop;\n const rowBottom = bottom - listTop + list.scrollTop;\n if (rowTop < list.scrollTop) {\n list.scrollTop = rowTop;\n } else if (rowBottom > list.scrollTop + list.clientHeight) {\n list.scrollTop = rowBottom - list.clientHeight;\n }\n return true;\n};\n\nexport interface PopoverListProps {\n children: React.ReactNode;\n /**\n * Scrolls the list to its selected row (`aria-current`, `aria-selected` or a checked radio)\n * each time the popover is shown, once that row mounts. Only the list scrolls.\n */\n scrollToSelected?: boolean;\n}\n\nexport const PopoverList: React.FC<PopoverListProps> = ({ children, scrollToSelected = false }) => {\n const shown = useContext(PopoverShownContext);\n const listRef = useRef<HTMLDivElement>(null);\n\n // Before paint, so a shown panel never draws a frame at the top and then jumps.\n useLayoutEffect(() => {\n const list = listRef.current;\n if (!scrollToSelected || !shown || !list || scrollSelectedRowIntoView(list)) {\n return;\n }\n const observer = new MutationObserver(() => {\n if (scrollSelectedRowIntoView(list)) {\n observer.disconnect();\n }\n });\n observer.observe(list, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: SELECTION_ATTRIBUTES,\n });\n return () => observer.disconnect();\n }, [scrollToSelected, shown]);\n\n return (\n <div\n ref={listRef}\n className={`flex max-h-80 flex-col gap-[2px] overflow-y-auto p-2 ${NO_SCROLLBAR}`}\n >\n {children}\n </div>\n );\n};\n\nexport const PopoverSection = forwardRef<HTMLDivElement, { children: React.ReactNode }>(\n ({ children }, ref) => (\n <div ref={ref} className={`border-0 border-t border-solid ${BORDER} p-2`}>\n {children}\n </div>\n ),\n);\nPopoverSection.displayName = 'Popover.Section';\n\nexport const PopoverEmpty: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <div className=\"px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] text-[var(--malachite-text-dimmed,rgb(161,161,161))] select-none\">\n {children}\n </div>\n);\n\nexport const PopoverSearch: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <div className=\"px-2 pt-2\">{children}</div>\n);\n\nexport const PopoverNote: React.FC<{ children: React.ReactNode }> = ({ children }) => (\n <div\n className={`border-0 border-t border-solid ${BORDER} px-5 py-3 text-[length:var(--malachite-font-size-xsmall,11px)] leading-4 text-[var(--malachite-text-secondary,rgb(123,123,123))]`}\n >\n {children}\n </div>\n);\n\nexport type PopoverStatusTone = 'default' | 'error';\n\nexport interface PopoverStatusAction {\n label: string;\n onClick: () => void;\n /** Shows the button's spinner and ignores clicks, e.g. while a retry is in flight. */\n pending?: boolean;\n}\n\nexport interface PopoverStatusProps {\n /**\n * What the panel is waiting on, or why it is empty. Clear it rather than unmount the part:\n * only a region already in the tree announces a new message.\n */\n message?: React.ReactNode;\n tone?: PopoverStatusTone;\n /** A button under the message that resolves it, such as Retry. Shown only with a message. */\n action?: PopoverStatusAction;\n /** Lets the region take focus from script (`tabIndex={-1}`), e.g. from `initialFocus`. */\n focusable?: boolean;\n}\n\nconst STATUS_TONE_TEXT: Record<PopoverStatusTone, string> = {\n default: 'text-[var(--malachite-text-secondary,rgb(123,123,123))]',\n error: 'text-[var(--malachite-text-error,rgb(237,53,54))]',\n};\n\nconst hasMessage = (message: React.ReactNode): boolean =>\n message !== undefined && message !== null && message !== false && message !== '';\n\nexport const PopoverStatus = forwardRef<HTMLDivElement, PopoverStatusProps>(\n ({ message, tone = 'default', action, focusable = false }, ref) => {\n const shown = hasMessage(message);\n return (\n <>\n {/* Stays `status` while empty and for errors: a role or aria-hidden changed with the\n text is not reliably announced. No ring: a focus target, not a control. */}\n <div\n ref={ref}\n role=\"status\"\n tabIndex={focusable ? -1 : undefined}\n className={shown ? 'outline-none' : 'sr-only'}\n >\n {shown && (\n <div\n className={`px-3 py-2 text-[length:var(--malachite-font-size-small,13px)] ${STATUS_TONE_TEXT[tone]}`}\n >\n {message}\n </div>\n )}\n </div>\n {shown && action && (\n <div className=\"px-3 pb-2\">\n <Button\n variant=\"outline\"\n size=\"small\"\n loading={action.pending}\n onClick={action.onClick}\n >\n {action.label}\n </Button>\n </div>\n )}\n </>\n );\n },\n);\nPopoverStatus.displayName = 'Popover.Status';\n\nexport interface PopoverActionProps {\n icon: React.ReactNode;\n 'aria-label': string;\n onClick?: () => void;\n /** Renders a link; a plain click runs `onClick` instead of following it, when one is given. */\n href?: string;\n disabled?: boolean;\n tooltip?: string;\n}\n\nexport const PopoverAction: React.FC<PopoverActionProps> = ({\n icon,\n 'aria-label': ariaLabel,\n onClick,\n href: rawHref,\n disabled = false,\n tooltip,\n}) => {\n const href = disabled ? undefined : safeHref(rawHref);\n const className = `m-0 inline-flex size-5 items-center justify-center rounded-[var(--malachite-radius-sm,4px)] border-0 bg-transparent p-0 transition-colors duration-150 [&_svg]:size-3! ${disabled ? 'cursor-not-allowed text-[var(--malachite-text-placeholder,rgb(187,187,187))] opacity-50' : `cursor-pointer text-[var(--malachite-text-placeholder,rgb(187,187,187))] hover:bg-[var(--malachite-pillbutton-background,rgb(241,241,241))] hover:text-[var(--malachite-text-secondary,rgb(123,123,123))]`} ${FOCUS_RING_INSET}`;\n const button =\n href !== undefined ? (\n <a\n href={href}\n aria-label={ariaLabel}\n onClick={(event) => {\n if (isPlainClick(event) && onClick) {\n event.preventDefault();\n onClick();\n }\n }}\n className={`no-underline ${className}`}\n >\n {icon}\n </a>\n ) : (\n <button\n type=\"button\"\n aria-label={ariaLabel}\n aria-disabled={disabled || undefined}\n onClick={disabled ? undefined : onClick}\n className={className}\n >\n {icon}\n </button>\n );\n return tooltip ? <Tooltip text={tooltip}>{button}</Tooltip> : button;\n};\n"],"names":["PopoverHeader","title","action","jsxs","BORDER","jsx","SELECTED_ROW","SELECTION_ATTRIBUTES","scrollSelectedRowIntoView","list","row","listTop","top","bottom","rowTop","rowBottom","PopoverList","children","scrollToSelected","shown","useContext","PopoverShownContext","listRef","useRef","useLayoutEffect","observer","NO_SCROLLBAR","PopoverSection","forwardRef","ref","PopoverEmpty","PopoverSearch","PopoverNote","STATUS_TONE_TEXT","hasMessage","message","PopoverStatus","tone","focusable","Fragment","Button","PopoverAction","icon","ariaLabel","onClick","rawHref","disabled","tooltip","href","safeHref","className","FOCUS_RING_INSET","button","event","isPlainClick","Tooltip"],"mappings":";;;;;;;;;AAcO,MAAMA,IAA8C,CAAC,EAAE,OAAAC,GAAO,QAAAC,QACjE,gBAAAC;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAW,oEAAo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12
  "Nov",
13
13
  "Dec"
14
- ], F = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], E = [
14
+ ], F = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], C = [
15
15
  "Sunday",
16
16
  "Monday",
17
17
  "Tuesday",
@@ -19,7 +19,7 @@ const M = [
19
19
  "Thursday",
20
20
  "Friday",
21
21
  "Saturday"
22
- ], g = (t, e) => e === "utc" ? {
22
+ ], i = (t, e) => e === "utc" ? {
23
23
  year: t.getUTCFullYear(),
24
24
  month: t.getUTCMonth(),
25
25
  day: t.getUTCDate(),
@@ -34,37 +34,37 @@ const M = [
34
34
  minutes: t.getMinutes(),
35
35
  seconds: t.getSeconds()
36
36
  };
37
- const a = ({ year: t, month: e, day: n, hours: s = 0, minutes: o = 0, seconds: m = 0 }, c, r = 0) => {
37
+ const a = ({ year: t, month: e, day: n, hours: s = 0, minutes: o = 0, seconds: r = 0 }, c, g = 0) => {
38
38
  const u = t >= 0 && t < 100 ? 400 : 0;
39
39
  if (c === "utc") {
40
- const y = new Date(
41
- Date.UTC(t + u, e, n, s, o, m, r)
40
+ const d = new Date(
41
+ Date.UTC(t + u, e, n, s, o, r, g)
42
42
  );
43
- return u && y.setUTCFullYear(y.getUTCFullYear() - u), y;
43
+ return u && d.setUTCFullYear(d.getUTCFullYear() - u), d;
44
44
  }
45
- const d = new Date(t + u, e, n, s, o, m, r);
46
- return u && d.setFullYear(d.getFullYear() - u), d;
45
+ const m = new Date(t + u, e, n, s, o, r, g);
46
+ return u && m.setFullYear(m.getFullYear() - u), m;
47
47
  }, h = (t, e) => {
48
- const { year: n, month: s, day: o } = g(t, e);
48
+ const { year: n, month: s, day: o } = i(t, e);
49
49
  return { year: n, month: s, day: o };
50
- }, Y = (t, e) => t.year - e.year || t.month - e.month || t.day - e.day, b = (t, e) => !!t && !!e && Y(t, e) === 0, I = ({ year: t, month: e, day: n }) => `${t}-${String(e + 1).padStart(2, "0")}-${String(n).padStart(2, "0")}`, k = ({ year: t, month: e, day: n }, s) => a({ year: t, month: e, day: n }, s), _ = ({ year: t, month: e, day: n }, s) => a({ year: t, month: e, day: n, hours: 23, minutes: 59, seconds: 59 }, s, 999), l = (t, e) => h(a({ year: t.year, month: t.month, day: t.day + e }, "utc"), "utc"), N = ({ year: t, month: e }) => h(a({ year: t, month: e + 1, day: 0 }, "utc"), "utc").day, p = ({ year: t, month: e }, n) => {
50
+ }, E = (t, e) => t.year - e.year || t.month - e.month || t.day - e.day, Y = (t, e) => !!t && !!e && E(t, e) === 0, I = ({ year: t, month: e, day: n }) => `${t}-${String(e + 1).padStart(2, "0")}-${String(n).padStart(2, "0")}`, b = ({ year: t, month: e, day: n }, s) => a({ year: t, month: e, day: n }, s), k = ({ year: t, month: e, day: n }, s) => a({ year: t, month: e, day: n, hours: 23, minutes: 59, seconds: 59 }, s, 999), f = (t, e) => h(a({ year: t.year, month: t.month, day: t.day + e }, "utc"), "utc"), _ = ({ year: t, month: e }) => h(a({ year: t, month: e + 1, day: 0 }, "utc"), "utc").day, p = ({ year: t, month: e }, n) => {
51
51
  const s = t * 12 + e + n;
52
52
  return { year: Math.floor(s / 12), month: (s % 12 + 12) % 12 };
53
53
  }, W = (t, e) => {
54
54
  const n = p(t, e);
55
- return { ...n, day: Math.min(t.day, N(n)) };
56
- }, U = (t) => a(t, "utc").getUTCDay(), f = { sunday: 0, monday: 1 }, R = (t) => Array.from({ length: 7 }, (e, n) => {
57
- const s = (n + f[t]) % 7;
58
- return { short: F[s], long: E[s] };
55
+ return { ...n, day: Math.min(t.day, _(n)) };
56
+ }, M = (t) => a(t, "utc").getUTCDay(), l = { sunday: 0, monday: 1 }, R = (t) => Array.from({ length: 7 }, (e, n) => {
57
+ const s = (n + l[t]) % 7;
58
+ return { short: F[s], long: C[s] };
59
59
  }), K = (t, e) => {
60
- const n = { ...t, day: 1 }, s = (U(n) - f[e] + 7) % 7, o = Math.ceil((s + N(t)) / 7) * 7, m = l(n, -s), c = [];
61
- for (let r = 0; r < o; r++)
62
- r % 7 === 0 && c.push([]), c[c.length - 1].push(l(m, r));
63
- return c;
64
- }, L = (t, e) => l(t, -((U(t) - f[e] + 7) % 7)), J = ({ year: t, month: e }) => `${M[e]} ${t}`, i = (t) => String(t).padStart(2, "0"), w = (t, e) => e === "second" ? `${i(t.hours)}:${i(t.minutes)}:${i(t.seconds)}` : `${i(t.hours)}:${i(t.minutes)}`, O = (t) => t === "utc" ? " UTC" : "", Z = (t, e, n) => {
65
- const s = g(t, e), o = `${M[s.month]} ${s.day} ${s.year}`;
66
- return n === "day" ? o : `${o}, ${w(s, n)}${O(e)}`;
67
- }, x = (t, e, n) => `${t ? w(g(t, e), n) : n === "second" ? "--:--:--" : "--:--"}${O(e)}`;
60
+ const n = { ...t, day: 1 }, s = (M(n) - l[e] + 7) % 7, o = f(n, -s), r = [];
61
+ for (let c = 0; c < 42; c++)
62
+ c % 7 === 0 && r.push([]), r[r.length - 1].push(f(o, c));
63
+ return r;
64
+ }, L = (t, e) => f(t, -((M(t) - l[e] + 7) % 7)), J = ({ year: t, month: e }) => `${N[e]} ${t}`, T = (t) => String(t).padStart(2, "0"), w = (t, e) => e === "second" ? `${T(t.hours)}:${T(t.minutes)}:${T(t.seconds)}` : `${T(t.hours)}:${T(t.minutes)}`, U = (t) => t === "utc" ? " UTC" : "", Z = (t, e, n) => {
65
+ const s = i(t, e), o = `${N[s.month]} ${s.day} ${s.year}`;
66
+ return n === "day" ? o : `${o}, ${w(s, n)}${U(e)}`;
67
+ }, x = (t, e, n) => `${t ? w(i(t, e), n) : n === "second" ? "--:--:--" : "--:--"}${U(e)}`;
68
68
  let $;
69
69
  const B = (t) => ($ ?? ($ = new Intl.DateTimeFormat("en-US", {
70
70
  weekday: "long",
@@ -77,18 +77,18 @@ const B = (t) => ($ ?? ($ = new Intl.DateTimeFormat("en-US", {
77
77
  return null;
78
78
  const n = typeof t == "string" ? H.exec(t) : null;
79
79
  if (n) {
80
- const [, o, m, c, r = "0", u = "0", d = "0", y = ""] = n, T = {
80
+ const [, o, r, c, g = "0", u = "0", m = "0", d = ""] = n, y = {
81
81
  year: Number(o),
82
- month: Number(m) - 1,
82
+ month: Number(r) - 1,
83
83
  day: Number(c),
84
- hours: Number(r),
84
+ hours: Number(g),
85
85
  minutes: Number(u),
86
- seconds: Number(d)
86
+ seconds: Number(m)
87
87
  };
88
- if (T.hours > 23 || T.minutes > 59 || T.seconds > 59)
88
+ if (y.hours > 23 || y.minutes > 59 || y.seconds > 59)
89
89
  return null;
90
- const S = a(T, e, Number(y.padEnd(3, "0")));
91
- return b(h(S, e), T) ? S : null;
90
+ const S = a(y, e, Number(d.padEnd(3, "0")));
91
+ return Y(h(S, e), y) ? S : null;
92
92
  }
93
93
  const s = t instanceof Date ? t : new Date(t);
94
94
  return A(s) ? s : null;
@@ -105,32 +105,32 @@ const B = (t) => ($ ?? ($ = new Intl.DateTimeFormat("en-US", {
105
105
  ), D = {
106
106
  minute: 6e4,
107
107
  second: 1e3
108
- }, C = (t, e, n) => {
108
+ }, O = (t, e, n) => {
109
109
  if (n === "day")
110
- return k(g(t, e), e);
110
+ return b(i(t, e), e);
111
111
  if (e === "local" && !Number.isInteger(t.getTimezoneOffset())) {
112
- const o = g(t, e);
112
+ const o = i(t, e);
113
113
  return a({ ...o, seconds: n === "second" ? o.seconds : 0 }, e);
114
114
  }
115
115
  const s = D[n];
116
116
  return new Date(Math.floor(t.getTime() / s) * s);
117
- }, j = (t, e, n) => n === "day" ? _(h(t, e), e) : new Date(C(t, e, n).getTime() + D[n] - 1), q = (t, e, n) => {
117
+ }, j = (t, e, n) => n === "day" ? k(h(t, e), e) : new Date(O(t, e, n).getTime() + D[n] - 1), q = (t, e, n) => {
118
118
  if (n === "day")
119
119
  return t;
120
- const s = C(t, e, n);
120
+ const s = O(t, e, n);
121
121
  return s.getTime() < t.getTime() ? new Date(s.getTime() + D[n]) : s;
122
122
  };
123
123
  export {
124
- l as addDays,
124
+ f as addDays,
125
125
  p as addMonths,
126
126
  W as addMonthsToDay,
127
127
  q as ceilTo,
128
128
  G as clampDate,
129
- Y as compareDays,
129
+ E as compareDays,
130
130
  h as dayKeyOf,
131
131
  I as dayKeyString,
132
- N as daysInMonth,
133
- _ as endOfDay,
132
+ _ as daysInMonth,
133
+ k as endOfDay,
134
134
  j as endOfUnit,
135
135
  Z as formatDate,
136
136
  w as formatTime,
@@ -139,15 +139,15 @@ export {
139
139
  J as monthLabel,
140
140
  K as monthWeeks,
141
141
  P as overlapsBounds,
142
- g as partsOf,
143
- b as sameDay,
142
+ i as partsOf,
143
+ Y as sameDay,
144
144
  B as spokenDay,
145
- k as startOfDay,
145
+ b as startOfDay,
146
146
  L as startOfWeek,
147
147
  V as toDate,
148
- C as truncateTo,
148
+ O as truncateTo,
149
149
  R as weekdayLabels,
150
- U as weekdayOf,
150
+ M as weekdayOf,
151
151
  X as withTime
152
152
  };
153
153
  //# sourceMappingURL=dateMath.js.map