@plexui/ui 0.35.0 → 0.37.0

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":"useSidebarContext.js","sourceRoot":"","sources":["../../../../src/components/Sidebar/useSidebarContext.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,oBAAoB,GAErB,MAAM,OAAO,CAAA;AACd,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,CAAC,MAAM,sDAAsD,CAAA;AAEpE,YAAY;AACZ,MAAM,mBAAmB,GAAG,eAAe,CAAA;AAC3C,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA,CAAC,SAAS;AACzD,MAAM,aAAa,GAAG,OAAO,CAAA;AAC7B,MAAM,iBAAiB,GAAG,OAAO,CAAA;AACjC,MAAM,oBAAoB,GAAG,OAAO,CAAA;AACpC,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,yBAAyB,GAAG,GAAG,CAAA;AACrC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAoB7B,UAAU;AACV,MAAM,cAAc,GAAG,aAAa,CAA6B,IAAI,CAAC,CAAA;AAEtE,iCAAiC;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAwB,EAAE;IAClD,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAA;IAE1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAA;IACrE,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,2EAA2E;AAC3E,wEAAwE;AACxE,0EAA0E;AAC1E,MAAM,YAAY,GAAG,eAAe,iBAAiB,GAAG,CAAC,KAAK,CAAA;AAE9D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,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,EACtD,KAAK,EACH;gBACE,iBAAiB,EAAE,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,aAAa;gBACxE,wBAAwB,EAAE,oBAAoB;gBAC9C,sBAAsB,EAAE,kBAAkB;gBAC1C,GAAG,KAAK;aACc,kBAEZ,KAAK,sBACD,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,sBACjC,WAAW,YAE5B,QAAQ,GACL,GACkB,CAC3B,CAAA;AACH,CAAC,CAAA;AAED,uCAAuC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE,aAAa;IACpB,SAAS,EAAE,iBAAiB;IAC5B,YAAY,EAAE,oBAAoB;IAClC,UAAU,EAAE,kBAAkB;IAC9B,iBAAiB,EAAE,yBAAyB;IAC5C,iBAAiB;IACjB,WAAW,EAAE,mBAAmB;IAChC,cAAc,EAAE,sBAAsB;CAC9B,CAAA","sourcesContent":["\"use client\"\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from \"react\"\nimport clsx from \"clsx\"\nimport s from \"@plexui/styles/components/Sidebar/Sidebar.module.css\"\n\n// Constants\nconst SIDEBAR_COOKIE_NAME = \"sidebar:state\"\nconst SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7 // 7 days\nconst SIDEBAR_WIDTH = \"240px\"\nconst SIDEBAR_WIDTH_APP = \"260px\"\nconst SIDEBAR_WIDTH_MOBILE = \"288px\"\nconst SIDEBAR_WIDTH_ICON = \"64px\"\nconst SIDEBAR_KEYBOARD_SHORTCUT = \"b\"\nconst MOBILE_BREAKPOINT = 768\n\n// Types\nexport type SidebarState = \"expanded\" | \"collapsed\"\nexport type SidebarCollapsible = \"offcanvas\" | \"icon\" | \"none\"\nexport type SidebarSide = \"left\" | \"right\"\nexport type SidebarVariant = \"sidebar\" | \"docs\"\nexport type SidebarProviderVariant = \"sidebar\" | \"app\"\n\nexport type SidebarContextValue = {\n state: SidebarState\n open: boolean\n setOpen: (open: boolean) => void\n openMobile: boolean\n setOpenMobile: (open: boolean) => void\n isMobile: boolean\n collapsible: SidebarCollapsible\n toggleSidebar: () => void\n}\n\n// Context\nconst SidebarContext = createContext<SidebarContextValue | null>(null)\n\n// Hook to access sidebar context\nexport const useSidebar = (): SidebarContextValue => {\n const context = useContext(SidebarContext)\n\n if (!context) {\n throw new Error(\"useSidebar must be used within a SidebarProvider\")\n }\n\n return context\n}\n\n// Hook for mobile detection via matchMedia. Read during render, so a phone\n// gets the mobile layout on its first paint instead of one frame of the\n// desktop sidebar; the server (and hydration) renders the desktop layout.\nconst MOBILE_QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`\n\nconst subscribeToMobile = (onChange: () => void) => {\n const mql = window.matchMedia(MOBILE_QUERY)\n mql.addEventListener(\"change\", onChange)\n return () => mql.removeEventListener(\"change\", onChange)\n}\n\nconst getMobileSnapshot = () => window.matchMedia(MOBILE_QUERY).matches\nconst getServerMobileSnapshot = () => false\n\nfunction useIsMobile(): boolean {\n return useSyncExternalStore(subscribeToMobile, getMobileSnapshot, getServerMobileSnapshot)\n}\n\n// Provider props\nexport type SidebarProviderProps = {\n children: ReactNode\n /**\n * Default open state (uncontrolled)\n * @default true\n */\n defaultOpen?: boolean\n /**\n * Controlled open state\n */\n open?: boolean\n /**\n * Callback when open state changes\n */\n onOpenChange?: (open: boolean) => void\n /**\n * Collapsible mode\n * @default \"offcanvas\"\n */\n collapsible?: SidebarCollapsible\n /**\n * \"app\" is the shell of a product: a quiet rail, pill rows and on a phone a drawer under the page.\n * @default \"sidebar\"\n */\n variant?: SidebarProviderVariant\n /**\n * Custom CSS properties for the sidebar\n */\n style?: React.CSSProperties\n /**\n * Additional class name\n */\n className?: string\n}\n\n// Provider component\nexport const SidebarProvider = ({\n children,\n defaultOpen = true,\n open: openProp,\n onOpenChange: setOpenProp,\n collapsible = \"offcanvas\",\n variant = \"sidebar\",\n style,\n className,\n}: SidebarProviderProps) => {\n const isMobile = useIsMobile()\n const [openMobile, setOpenMobile] = useState(false)\n\n // Controlled vs uncontrolled state for desktop\n const [_open, _setOpen] = useState(defaultOpen)\n const open = openProp ?? _open\n\n const setOpen = useCallback(\n (value: boolean | ((prev: boolean) => boolean)) => {\n const openState = typeof value === \"function\" ? value(open) : value\n\n // Controlled only when `open` is passed; onOpenChange alone is a notification\n if (openProp === undefined) {\n _setOpen(openState)\n }\n setOpenProp?.(openState)\n\n // Persist state in cookie for SSR\n if (typeof document !== \"undefined\") {\n document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`\n }\n },\n [setOpenProp, openProp, open],\n )\n\n // Toggle function that handles both mobile and desktop\n const toggleSidebar = useCallback(() => {\n if (isMobile) {\n setOpenMobile((prev) => !prev)\n } else {\n setOpen((prev) => !prev)\n }\n }, [isMobile, setOpen])\n\n // Keyboard shortcut: Cmd/Ctrl + B\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n // Skip if collapsible is \"none\"\n if (collapsible === \"none\") return\n\n // Don't trigger when focus is in an editable element (input, textarea, contenteditable)\n const target = event.target as HTMLElement | null\n if (target?.closest?.(\"input, textarea\") || target?.isContentEditable) return\n\n // Check for Cmd (Mac) or Ctrl (Windows/Linux) + B\n if (\n event.key === SIDEBAR_KEYBOARD_SHORTCUT &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.shiftKey\n ) {\n event.preventDefault()\n toggleSidebar()\n }\n }\n\n window.addEventListener(\"keydown\", handleKeyDown)\n return () => window.removeEventListener(\"keydown\", handleKeyDown)\n }, [toggleSidebar, collapsible])\n\n // Close mobile menu on escape key\n useEffect(() => {\n if (!openMobile) return\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n setOpenMobile(false)\n }\n }\n\n window.addEventListener(\"keydown\", handleKeyDown)\n return () => window.removeEventListener(\"keydown\", handleKeyDown)\n }, [openMobile])\n\n // Derive state from open boolean\n const state: SidebarState = open ? \"expanded\" : \"collapsed\"\n\n // Context value\n const contextValue = useMemo<SidebarContextValue>(\n () => ({\n state,\n open,\n setOpen,\n openMobile,\n setOpenMobile,\n isMobile,\n collapsible,\n toggleSidebar,\n }),\n [state, open, setOpen, openMobile, isMobile, collapsible, toggleSidebar],\n )\n\n return (\n <SidebarContext.Provider value={contextValue}>\n <div\n className={clsx(variant === \"app\" && s.App, className)}\n style={\n {\n \"--sidebar-width\": variant === \"app\" ? SIDEBAR_WIDTH_APP : SIDEBAR_WIDTH,\n \"--sidebar-width-mobile\": SIDEBAR_WIDTH_MOBILE,\n \"--sidebar-width-icon\": SIDEBAR_WIDTH_ICON,\n ...style,\n } as React.CSSProperties\n }\n data-sidebar={state}\n data-mobile-menu={openMobile ? \"visible\" : \"hidden\"}\n data-collapsible={collapsible}\n >\n {children}\n </div>\n </SidebarContext.Provider>\n )\n}\n\n// Re-export constants for external use\nexport const SIDEBAR_CONSTANTS = {\n WIDTH: SIDEBAR_WIDTH,\n WIDTH_APP: SIDEBAR_WIDTH_APP,\n WIDTH_MOBILE: SIDEBAR_WIDTH_MOBILE,\n WIDTH_ICON: SIDEBAR_WIDTH_ICON,\n KEYBOARD_SHORTCUT: SIDEBAR_KEYBOARD_SHORTCUT,\n MOBILE_BREAKPOINT,\n COOKIE_NAME: SIDEBAR_COOKIE_NAME,\n COOKIE_MAX_AGE: SIDEBAR_COOKIE_MAX_AGE,\n} as const\n"]}
1
+ {"version":3,"file":"useSidebarContext.js","sourceRoot":"","sources":["../../../../src/components/Sidebar/useSidebarContext.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,oBAAoB,G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;gBAC9C,sBAAsB,EAAE,kBAAkB;gBAC1C,GAAG,KAAK;aACc,kBAEZ,KAAK,sBACD,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,sBACjC,WAAW,YAE5B,QAAQ,GACL,GACkB,CAC3B,CAAA;AACH,CAAC,CAAA;AAED,uCAAuC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE,aAAa;IACpB,SAAS,EAAE,iBAAiB;IAC5B,YAAY,EAAE,oBAAoB;IAClC,UAAU,EAAE,kBAAkB;IAC9B,iBAAiB,EAAE,yBAAyB;IAC5C,iBAAiB;IACjB,WAAW,EAAE,mBAAmB;IAChC,cAAc,EAAE,sBAAsB;CAC9B,CAAA","sourcesContent":["\"use client\"\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n useSyncExternalStore,\n type ReactNode,\n} from \"react\"\nimport clsx from \"clsx\"\nimport s from \"@plexui/styles/components/Sidebar/Sidebar.module.css\"\n\n// Constants\nconst SIDEBAR_COOKIE_NAME = \"sidebar:state\"\nconst SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7 // 7 days\nconst SIDEBAR_WIDTH = \"240px\"\nconst SIDEBAR_WIDTH_APP = \"260px\"\nconst SIDEBAR_WIDTH_MOBILE = \"288px\"\nconst SIDEBAR_WIDTH_ICON = \"64px\"\nconst SIDEBAR_KEYBOARD_SHORTCUT = \"b\"\nconst MOBILE_BREAKPOINT = 768\n\n// Types\nexport type SidebarState = \"expanded\" | \"collapsed\"\nexport type SidebarCollapsible = \"offcanvas\" | \"icon\" | \"none\"\nexport type SidebarSide = \"left\" | \"right\"\nexport type SidebarVariant = \"sidebar\" | \"docs\"\nexport type SidebarProviderVariant = \"sidebar\" | \"app\"\n\nexport type SidebarContextValue = {\n state: SidebarState\n open: boolean\n setOpen: (open: boolean) => void\n openMobile: boolean\n setOpenMobile: (open: boolean) => void\n isMobile: boolean\n collapsible: SidebarCollapsible\n toggleSidebar: () => void\n}\n\n// Context\nconst SidebarContext = createContext<SidebarContextValue | null>(null)\n\n// Hook to access sidebar context\nexport const useSidebar = (): SidebarContextValue => {\n const context = useContext(SidebarContext)\n\n if (!context) {\n throw new Error(\"useSidebar must be used within a SidebarProvider\")\n }\n\n return context\n}\n\n// Hook for mobile detection via matchMedia. Read during render, so a phone\n// gets the mobile layout on its first paint instead of one frame of the\n// desktop sidebar; the server (and hydration) renders the desktop layout.\nconst MOBILE_QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`\n\nconst subscribeToMobile = (onChange: () => void) => {\n const mql = window.matchMedia(MOBILE_QUERY)\n mql.addEventListener(\"change\", onChange)\n return () => mql.removeEventListener(\"change\", onChange)\n}\n\nconst getMobileSnapshot = () => window.matchMedia(MOBILE_QUERY).matches\nconst getServerMobileSnapshot = () => false\n\nfunction useIsMobile(): boolean {\n return useSyncExternalStore(subscribeToMobile, getMobileSnapshot, getServerMobileSnapshot)\n}\n\n// Provider props\nexport type SidebarProviderProps = {\n children: ReactNode\n /**\n * Default open state (uncontrolled)\n * @default true\n */\n defaultOpen?: boolean\n /**\n * Controlled open state\n */\n open?: boolean\n /**\n * Callback when open state changes\n */\n onOpenChange?: (open: boolean) => void\n /**\n * Controlled open state of the phone drawer (`SidebarMobile`)\n */\n openMobile?: boolean\n /**\n * Initial open state of the phone drawer (uncontrolled)\n * @default false\n */\n defaultOpenMobile?: boolean\n /**\n * Called when the phone drawer opens or closes: its menu button, its backdrop, Escape or a swipe\n */\n onOpenMobileChange?: (open: boolean) => void\n /**\n * Collapsible mode\n * @default \"offcanvas\"\n */\n collapsible?: SidebarCollapsible\n /**\n * \"app\" is the shell of a product: a quiet rail, pill rows and on a phone a drawer under the page.\n * @default \"sidebar\"\n */\n variant?: SidebarProviderVariant\n /**\n * Custom CSS properties for the sidebar\n */\n style?: React.CSSProperties\n /**\n * Additional class name\n */\n className?: string\n}\n\n// Provider component\nexport const SidebarProvider = ({\n children,\n defaultOpen = true,\n open: openProp,\n onOpenChange: setOpenProp,\n openMobile: openMobileProp,\n defaultOpenMobile = false,\n onOpenMobileChange,\n collapsible = \"offcanvas\",\n variant = \"sidebar\",\n style,\n className,\n}: SidebarProviderProps) => {\n const isMobile = useIsMobile()\n // Controlled vs uncontrolled state for the phone drawer\n const [_openMobile, _setOpenMobile] = useState(defaultOpenMobile)\n const openMobile = openMobileProp ?? _openMobile\n\n const setOpenMobile = useCallback(\n (value: boolean | ((prev: boolean) => boolean)) => {\n const next = typeof value === \"function\" ? value(openMobile) : value\n if (next === openMobile) return\n if (openMobileProp === undefined) _setOpenMobile(next)\n onOpenMobileChange?.(next)\n },\n [openMobile, openMobileProp, onOpenMobileChange],\n )\n\n // Controlled vs uncontrolled state for desktop\n const [_open, _setOpen] = useState(defaultOpen)\n const open = openProp ?? _open\n\n const setOpen = useCallback(\n (value: boolean | ((prev: boolean) => boolean)) => {\n const openState = typeof value === \"function\" ? value(open) : value\n\n // Controlled only when `open` is passed; onOpenChange alone is a notification\n if (openProp === undefined) {\n _setOpen(openState)\n }\n setOpenProp?.(openState)\n\n // Persist state in cookie for SSR\n if (typeof document !== \"undefined\") {\n document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`\n }\n },\n [setOpenProp, openProp, open],\n )\n\n // Toggle function that handles both mobile and desktop\n const toggleSidebar = useCallback(() => {\n if (isMobile) {\n setOpenMobile((prev) => !prev)\n } else {\n setOpen((prev) => !prev)\n }\n }, [isMobile, setOpen, setOpenMobile])\n\n // Keyboard shortcut: Cmd/Ctrl + B\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n // Skip if collapsible is \"none\"\n if (collapsible === \"none\") return\n\n // Don't trigger when focus is in an editable element (input, textarea, contenteditable)\n const target = event.target as HTMLElement | null\n if (target?.closest?.(\"input, textarea\") || target?.isContentEditable) return\n\n // Check for Cmd (Mac) or Ctrl (Windows/Linux) + B\n if (\n event.key === SIDEBAR_KEYBOARD_SHORTCUT &&\n (event.metaKey || event.ctrlKey) &&\n !event.altKey &&\n !event.shiftKey\n ) {\n event.preventDefault()\n toggleSidebar()\n }\n }\n\n window.addEventListener(\"keydown\", handleKeyDown)\n return () => window.removeEventListener(\"keydown\", handleKeyDown)\n }, [toggleSidebar, collapsible])\n\n // Escape closes the drawer from inside it (SidebarMobile), so a layer over it takes its own Escape first\n\n // Derive state from open boolean\n const state: SidebarState = open ? \"expanded\" : \"collapsed\"\n\n // Context value\n const contextValue = useMemo<SidebarContextValue>(\n () => ({\n state,\n open,\n setOpen,\n openMobile,\n setOpenMobile,\n isMobile,\n collapsible,\n toggleSidebar,\n }),\n [state, open, setOpen, openMobile, setOpenMobile, isMobile, collapsible, toggleSidebar],\n )\n\n return (\n <SidebarContext.Provider value={contextValue}>\n <div\n className={clsx(variant === \"app\" && s.App, className)}\n style={\n {\n \"--sidebar-width\": variant === \"app\" ? SIDEBAR_WIDTH_APP : SIDEBAR_WIDTH,\n \"--sidebar-width-mobile\": SIDEBAR_WIDTH_MOBILE,\n \"--sidebar-width-icon\": SIDEBAR_WIDTH_ICON,\n ...style,\n } as React.CSSProperties\n }\n data-sidebar={state}\n data-mobile-menu={openMobile ? \"visible\" : \"hidden\"}\n data-collapsible={collapsible}\n >\n {children}\n </div>\n </SidebarContext.Provider>\n )\n}\n\n// Re-export constants for external use\nexport const SIDEBAR_CONSTANTS = {\n WIDTH: SIDEBAR_WIDTH,\n WIDTH_APP: SIDEBAR_WIDTH_APP,\n WIDTH_MOBILE: SIDEBAR_WIDTH_MOBILE,\n WIDTH_ICON: SIDEBAR_WIDTH_ICON,\n KEYBOARD_SHORTCUT: SIDEBAR_KEYBOARD_SHORTCUT,\n MOBILE_BREAKPOINT,\n COOKIE_NAME: SIDEBAR_COOKIE_NAME,\n COOKIE_MAX_AGE: SIDEBAR_COOKIE_MAX_AGE,\n} as const\n"]}
@@ -0,0 +1,201 @@
1
+ import { maskitoParseTime, maskitoStringifyTime } from "@maskito/kit";
2
+ import { DateTime } from "luxon";
3
+ const MS_IN_HOUR = 3_600_000;
4
+ const MS_IN_MINUTE = 60_000;
5
+ const MS_IN_SECOND = 1_000;
6
+ const inZone = (zone) => (zone ? { zone } : undefined);
7
+ const pad = (value, length) => String(value).padStart(length, "0");
8
+ const zones = new Map();
9
+ /**
10
+ * The zone typed dates are made in: the value's own zone object (Luxon's default zone without a value). A zone rebuilt
11
+ * from its name can be another one: Luxon's system zone becomes the zone of its name, the zone named UTC becomes the
12
+ * fixed UTC offset, and a name like UTC+5:5 (a 5:05 offset) does not parse back. The same object for the same zone,
13
+ * so it keys a memo.
14
+ */
15
+ export const dateInputZone = (value) => {
16
+ if (!value?.isValid)
17
+ return undefined;
18
+ const { zone } = value;
19
+ const key = zone.isUniversal ? `${zone.type} ${zone.offset(0)}` : `${zone.type} ${zone.name}`;
20
+ const known = zones.get(key);
21
+ if (known)
22
+ return known;
23
+ zones.set(key, zone);
24
+ return zone;
25
+ };
26
+ /** The key a DateInput re-shows its value on: the instant and the zone. */
27
+ export const dateInputValueKey = (value) => value?.isValid ? `${value.toMillis()} ${value.zoneName}` : "";
28
+ // Maskito's own range: 0001-01-01 to 9999-12-31, end of day
29
+ const lowest = (zone) => DateTime.fromObject({ year: 1, month: 1, day: 1 }, inZone(zone));
30
+ const highest = (zone) => DateTime.fromObject({ year: 9999, month: 12, day: 31, hour: 23, minute: 59, second: 59, millisecond: 999 }, inZone(zone));
31
+ /**
32
+ * Within min and max, and within Maskito's own range when the mode has a year: a date typed without one is in
33
+ * year 0, which that range would turn into 0001-01-01.
34
+ */
35
+ const clampToRange = (value, format, zone) => {
36
+ const withYear = format.mode.includes("y");
37
+ const min = format.min ?? (withYear ? lowest(zone).toMillis() : undefined);
38
+ const max = format.max ?? (withYear ? highest(zone).toMillis() : undefined);
39
+ const millis = value.toMillis();
40
+ if (min !== undefined && millis < min)
41
+ return DateTime.fromMillis(min, inZone(zone));
42
+ if (max !== undefined && millis > max)
43
+ return DateTime.fromMillis(max, inZone(zone));
44
+ return value;
45
+ };
46
+ /** The value's wall clock in its own zone, in the format */
47
+ const wallText = (shown, format) => {
48
+ const date = format.mode
49
+ .replaceAll("/", format.separator)
50
+ .replace(/d+/, pad(shown.day, 2))
51
+ .replace(/m+/, pad(shown.month, 2))
52
+ .replace(/y+/, (year) => pad(shown.year, 4).slice(-year.length));
53
+ if (!format.timeMode)
54
+ return date;
55
+ const msOfDay = shown.hour * MS_IN_HOUR + shown.minute * MS_IN_MINUTE + shown.second * MS_IN_SECOND + shown.millisecond;
56
+ return date + format.dateTimeSeparator + maskitoStringifyTime(msOfDay, { mode: format.timeMode });
57
+ };
58
+ /** The text a DateInput shows for a value: its wall clock in its own zone, kept within min and max. */
59
+ export const formatDateInput = (value, format) => value?.isValid ? wallText(clampToRange(value, format, value.zone), format) : "";
60
+ const segment = (digits, letters, letter) => digits.slice(letters.indexOf(letter), letters.lastIndexOf(letter) + 1);
61
+ /**
62
+ * Each instant the fields show in the zone, earliest first: two in an hour the clocks repeat, one in a time they skip,
63
+ * moved forward as Luxon does. `[]` for a date that does not exist.
64
+ */
65
+ const passesAt = (fields, zone) => {
66
+ const parsed = DateTime.fromObject(fields, inZone(zone));
67
+ if (!parsed.isValid)
68
+ return [];
69
+ const passes = parsed.getPossibleOffsets().sort((a, b) => a.toMillis() - b.toMillis());
70
+ return passes.length ? passes : [parsed];
71
+ };
72
+ const withinBounds = (value, format) => (format.min === undefined || value.toMillis() >= format.min) && (format.max === undefined || value.toMillis() <= format.max);
73
+ /**
74
+ * Which instant a time the clocks show twice is. Luxon reads it with the offset in force today, so the same text would
75
+ * be one instant in summer and another in winter: it is the first pass, as the browser's Date reads it, or the second
76
+ * when only that one is within min and max. A text that is min's or max's own is that bound's pass, so a time kept at a
77
+ * bound reads back as the bound.
78
+ */
79
+ const pickPass = (passes, format) => {
80
+ const [first] = passes;
81
+ if (passes.length < 2)
82
+ return first;
83
+ const text = wallText(first, format);
84
+ for (const bound of [format.min, format.max]) {
85
+ if (bound === undefined)
86
+ continue;
87
+ const shown = DateTime.fromMillis(bound, inZone(format.zone));
88
+ const onBound = wallText(shown, format) === text && passes.find((pass) => pass.offset === shown.offset);
89
+ if (onBound)
90
+ return onBound;
91
+ }
92
+ return passes.find((pass) => withinBounds(pass, format)) ?? first;
93
+ };
94
+ /** The typed fields of a complete text as a DateTime in the format's zone, or `null` */
95
+ const readTyped = (text, format) => {
96
+ const dateLetters = format.mode.replaceAll(/[^dmy]/g, "");
97
+ const timeLetters = format.timeMode?.replaceAll(/[^HMS]/g, "") ?? "";
98
+ const digits = text.replaceAll(/\D+/g, "");
99
+ if (digits.length !== dateLetters.length + timeLetters.length)
100
+ return null;
101
+ const dateDigits = digits.slice(0, dateLetters.length);
102
+ const day = segment(dateDigits, dateLetters, "d");
103
+ const month = segment(dateDigits, dateLetters, "m");
104
+ const year = segment(dateDigits, dateLetters, "y");
105
+ let msOfDay = 0;
106
+ if (format.timeMode) {
107
+ // Everything after the date's digits: the time and an AM/PM
108
+ const dateEnd = new RegExp(String.raw `^(?:\D*\d){${dateLetters.length}}`).exec(text)?.[0].length ?? 0;
109
+ msOfDay = maskitoParseTime(text.slice(dateEnd), { mode: format.timeMode });
110
+ }
111
+ const passes = passesAt({
112
+ // Maskito's reading: a two-digit year is in the 2000s, a missing one is year 0
113
+ year: year.length === 2 ? 2000 + Number(year) : Number(year || 0),
114
+ month: Number(month || 1),
115
+ day: Number(day || 1),
116
+ hour: Math.trunc(msOfDay / MS_IN_HOUR),
117
+ minute: Math.trunc((msOfDay % MS_IN_HOUR) / MS_IN_MINUTE),
118
+ second: Math.trunc((msOfDay % MS_IN_MINUTE) / MS_IN_SECOND),
119
+ millisecond: msOfDay % MS_IN_SECOND,
120
+ }, format.zone);
121
+ return passes.length ? pickPass(passes, format) : null;
122
+ };
123
+ /**
124
+ * The value for a complete text, or `null` while it is not one. A typed
125
+ * date is made in the format's zone from the typed fields, so the time is
126
+ * the one typed on a daylight saving day too. A date that does not exist is
127
+ * `null`; a time skipped by a clock change moves forward, as Luxon does, and
128
+ * a time the clocks show twice is its first pass, as the browser's Date reads
129
+ * it, unless only the second is within min and max or the text is a bound's
130
+ * own. Kept within min and max when the mode has a year, as Maskito's reading is.
131
+ */
132
+ export const parseDateInput = (text, format) => {
133
+ const typed = readTyped(text, format);
134
+ if (!typed)
135
+ return null;
136
+ return format.mode.includes("y") ? clampToRange(typed, format, format.zone) : typed;
137
+ };
138
+ /**
139
+ * min or max for Maskito's mask, which builds the typed dates with the
140
+ * browser's Date from their fields: the same fields, read in the value's
141
+ * zone, so the mask compares wall clocks. Only its steps for a date not yet
142
+ * complete read them, as keepTypedValue takes over the rest.
143
+ */
144
+ export const maskDate = (millis, zone) => {
145
+ const shown = DateTime.fromMillis(millis, inZone(zone));
146
+ const date = new Date(shown.year, shown.month - 1, shown.day, shown.hour, shown.minute, shown.second, shown.millisecond);
147
+ // Years 0 to 99 would read as 1900 to 1999
148
+ date.setFullYear(shown.year);
149
+ return date;
150
+ };
151
+ const NO_BREAK_SPACE = "\u00A0";
152
+ /** A wall date made in UTC, where every day exists, to compare calendar dates */
153
+ const calendarDay = (value) => DateTime.fromObject({ year: value.year, month: value.month, day: value.day }, { zone: "UTC" });
154
+ /**
155
+ * A text whose date is complete but not its time: its date kept within the dates of min and max, as Maskito's step
156
+ * keeps it, on the calendar instead of the browser's Date. `null` for a date that does not exist, left to Maskito.
157
+ */
158
+ const keepTypedDay = (value, format) => {
159
+ const dateLetters = format.mode.replaceAll(/[^dmy]/g, "");
160
+ const dateText = new RegExp(String.raw `^(?:\D*\d){${dateLetters.length}}`).exec(value)?.[0];
161
+ const dayFormat = { ...format, timeMode: undefined, min: undefined, max: undefined, zone: "UTC" };
162
+ const typed = dateText ? readTyped(dateText, dayFormat) : null;
163
+ if (!dateText || !typed)
164
+ return null;
165
+ const bound = (millis) => (millis === undefined ? undefined : calendarDay(DateTime.fromMillis(millis, inZone(format.zone))));
166
+ const min = bound(format.min);
167
+ const max = bound(format.max);
168
+ const kept = min && typed.toMillis() < min.toMillis() ? min : max && typed.toMillis() > max.toMillis() ? max : typed;
169
+ return wallText(kept, dayFormat) + value.slice(dateText.length);
170
+ };
171
+ /**
172
+ * Maskito's date and date-and-time masks end with a step that rebuilds a complete date with the browser's Date to keep
173
+ * it within min and max: in a zone whose clocks skipped a whole day the date moved a day, in the hour the browser's
174
+ * clocks skip a time typed for a value in another zone moved an hour, and min and max held on the browser's clock.
175
+ * This step reads a complete text in the value's zone, as the value is read (a time the clocks skip moves forward, an
176
+ * hour they repeat is its first pass or the one within min and max), and shows it kept within min and max as instants,
177
+ * so the text is the value's. A date and time without its time yet keeps its date within the dates of min and max. A
178
+ * date that does not exist, or one not yet complete, stays with Maskito's step.
179
+ */
180
+ export const keepTypedValue = (options, format) => {
181
+ const postprocessors = [...(options.postprocessors ?? [])];
182
+ const maskitoRange = postprocessors.pop();
183
+ if (!maskitoRange)
184
+ return options;
185
+ const keep = (state, initial) => {
186
+ // Complete once the AM or PM is typed too, as for Maskito
187
+ const complete = !format.timeMode?.includes("AA") || /[AP]M$/.test(state.value);
188
+ const typed = complete ? readTyped(state.value, format) : null;
189
+ // The mask puts a no-break space before AM and PM
190
+ const value = typed
191
+ ? formatDateInput(typed, format).replace(/ (?=[AP]M$)/, NO_BREAK_SPACE)
192
+ : format.timeMode
193
+ ? keepTypedDay(state.value, format)
194
+ : null;
195
+ if (value === null)
196
+ return maskitoRange(state, initial);
197
+ return value === state.value ? state : { value, selection: state.selection };
198
+ };
199
+ return { ...options, postprocessors: [...postprocessors, keep] };
200
+ };
201
+ //# sourceMappingURL=dateInputText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dateInputText.js","sourceRoot":"","sources":["../../../src/lib/dateInputText.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAA8C,MAAM,cAAc,CAAA;AACjH,OAAO,EAAE,QAAQ,EAAa,MAAM,OAAO,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C;YACvE,CAAC,CAAC,MAAM,CAAC,QAAQ;gBACf,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC;gBACnC,CAAC,CAAC,IAAI,CAAA;QACV,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACvD,OAAO,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,CAAA;IAC9E,CAAC,CAAA;IACD,OAAO,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,CAAA;AAClE,CAAC,CAAA","sourcesContent":["import type { MaskitoOptions, MaskitoPostprocessor } from \"@maskito/core\"\nimport { maskitoParseTime, maskitoStringifyTime, type MaskitoDateMode, type MaskitoTimeMode } from \"@maskito/kit\"\nimport { DateTime, type Zone } from \"luxon\"\n\n// DateInput's text and value, converted through the Luxon DateTime's own\n// calendar fields in its own zone. Maskito's date helpers go through the\n// browser's local Date instead: they show the browser's wall clock for a\n// value in another zone, and the date and time helpers count the time from\n// local midnight, an hour off on a daylight saving day.\n\nexport type DateInputFormat = {\n mode: MaskitoDateMode\n separator: string\n /** Set for a date and time */\n timeMode?: MaskitoTimeMode\n dateTimeSeparator: string\n /** Earliest allowed instant, in milliseconds */\n min?: number\n /** Latest allowed instant, in milliseconds */\n max?: number\n /** Zone of the value (dateInputZone): typed dates are made in it. Luxon's default zone when not set */\n zone?: Zone | string\n}\n\nconst MS_IN_HOUR = 3_600_000\nconst MS_IN_MINUTE = 60_000\nconst MS_IN_SECOND = 1_000\n\nconst inZone = (zone: Zone | string | undefined) => (zone ? { zone } : undefined)\n\nconst pad = (value: number, length: number) => String(value).padStart(length, \"0\")\n\nconst zones = new Map<string, Zone>()\n\n/**\n * The zone typed dates are made in: the value's own zone object (Luxon's default zone without a value). A zone rebuilt\n * from its name can be another one: Luxon's system zone becomes the zone of its name, the zone named UTC becomes the\n * fixed UTC offset, and a name like UTC+5:5 (a 5:05 offset) does not parse back. The same object for the same zone,\n * so it keys a memo.\n */\nexport const dateInputZone = (value: DateTime | null | undefined): Zone | undefined => {\n if (!value?.isValid) return undefined\n const { zone } = value\n const key = zone.isUniversal ? `${zone.type} ${zone.offset(0)}` : `${zone.type} ${zone.name}`\n const known = zones.get(key)\n if (known) return known\n zones.set(key, zone)\n return zone\n}\n\n/** The key a DateInput re-shows its value on: the instant and the zone. */\nexport const dateInputValueKey = (value: DateTime | null | undefined) =>\n value?.isValid ? `${value.toMillis()} ${value.zoneName}` : \"\"\n\n// Maskito's own range: 0001-01-01 to 9999-12-31, end of day\nconst lowest = (zone: Zone | string | undefined) => DateTime.fromObject({ year: 1, month: 1, day: 1 }, inZone(zone))\nconst highest = (zone: Zone | string | undefined) =>\n DateTime.fromObject({ year: 9999, month: 12, day: 31, hour: 23, minute: 59, second: 59, millisecond: 999 }, inZone(zone))\n\n/**\n * Within min and max, and within Maskito's own range when the mode has a year: a date typed without one is in\n * year 0, which that range would turn into 0001-01-01.\n */\nconst clampToRange = (value: DateTime, format: DateInputFormat, zone: Zone | string | undefined) => {\n const withYear = format.mode.includes(\"y\")\n const min = format.min ?? (withYear ? lowest(zone).toMillis() : undefined)\n const max = format.max ?? (withYear ? highest(zone).toMillis() : undefined)\n const millis = value.toMillis()\n if (min !== undefined && millis < min) return DateTime.fromMillis(min, inZone(zone))\n if (max !== undefined && millis > max) return DateTime.fromMillis(max, inZone(zone))\n return value\n}\n\n/** The value's wall clock in its own zone, in the format */\nconst wallText = (shown: DateTime, format: DateInputFormat) => {\n const date = format.mode\n .replaceAll(\"/\", format.separator)\n .replace(/d+/, pad(shown.day, 2))\n .replace(/m+/, pad(shown.month, 2))\n .replace(/y+/, (year) => pad(shown.year, 4).slice(-year.length))\n if (!format.timeMode) return date\n const msOfDay = shown.hour * MS_IN_HOUR + shown.minute * MS_IN_MINUTE + shown.second * MS_IN_SECOND + shown.millisecond\n return date + format.dateTimeSeparator + maskitoStringifyTime(msOfDay, { mode: format.timeMode })\n}\n\n/** The text a DateInput shows for a value: its wall clock in its own zone, kept within min and max. */\nexport const formatDateInput = (value: DateTime | null, format: DateInputFormat) =>\n value?.isValid ? wallText(clampToRange(value, format, value.zone), format) : \"\"\n\nconst segment = (digits: string, letters: string, letter: string) =>\n digits.slice(letters.indexOf(letter), letters.lastIndexOf(letter) + 1)\n\ntype Fields = { year: number; month: number; day: number; hour: number; minute: number; second: number; millisecond: number }\n\n/**\n * Each instant the fields show in the zone, earliest first: two in an hour the clocks repeat, one in a time they skip,\n * moved forward as Luxon does. `[]` for a date that does not exist.\n */\nconst passesAt = (fields: Fields, zone: Zone | string | undefined) => {\n const parsed = DateTime.fromObject(fields, inZone(zone))\n if (!parsed.isValid) return []\n const passes = parsed.getPossibleOffsets().sort((a, b) => a.toMillis() - b.toMillis())\n return passes.length ? passes : [parsed]\n}\n\nconst withinBounds = (value: DateTime, format: DateInputFormat) =>\n (format.min === undefined || value.toMillis() >= format.min) && (format.max === undefined || value.toMillis() <= format.max)\n\n/**\n * Which instant a time the clocks show twice is. Luxon reads it with the offset in force today, so the same text would\n * be one instant in summer and another in winter: it is the first pass, as the browser's Date reads it, or the second\n * when only that one is within min and max. A text that is min's or max's own is that bound's pass, so a time kept at a\n * bound reads back as the bound.\n */\nconst pickPass = (passes: DateTime[], format: DateInputFormat) => {\n const [first] = passes\n if (passes.length < 2) return first\n const text = wallText(first, format)\n for (const bound of [format.min, format.max]) {\n if (bound === undefined) continue\n const shown = DateTime.fromMillis(bound, inZone(format.zone))\n const onBound = wallText(shown, format) === text && passes.find((pass) => pass.offset === shown.offset)\n if (onBound) return onBound\n }\n return passes.find((pass) => withinBounds(pass, format)) ?? first\n}\n\n/** The typed fields of a complete text as a DateTime in the format's zone, or `null` */\nconst readTyped = (text: string, format: DateInputFormat) => {\n const dateLetters = format.mode.replaceAll(/[^dmy]/g, \"\")\n const timeLetters = format.timeMode?.replaceAll(/[^HMS]/g, \"\") ?? \"\"\n const digits = text.replaceAll(/\\D+/g, \"\")\n if (digits.length !== dateLetters.length + timeLetters.length) return null\n\n const dateDigits = digits.slice(0, dateLetters.length)\n const day = segment(dateDigits, dateLetters, \"d\")\n const month = segment(dateDigits, dateLetters, \"m\")\n const year = segment(dateDigits, dateLetters, \"y\")\n\n let msOfDay = 0\n if (format.timeMode) {\n // Everything after the date's digits: the time and an AM/PM\n const dateEnd = new RegExp(String.raw`^(?:\\D*\\d){${dateLetters.length}}`).exec(text)?.[0].length ?? 0\n msOfDay = maskitoParseTime(text.slice(dateEnd), { mode: format.timeMode })\n }\n\n const passes = passesAt(\n {\n // Maskito's reading: a two-digit year is in the 2000s, a missing one is year 0\n year: year.length === 2 ? 2000 + Number(year) : Number(year || 0),\n month: Number(month || 1),\n day: Number(day || 1),\n hour: Math.trunc(msOfDay / MS_IN_HOUR),\n minute: Math.trunc((msOfDay % MS_IN_HOUR) / MS_IN_MINUTE),\n second: Math.trunc((msOfDay % MS_IN_MINUTE) / MS_IN_SECOND),\n millisecond: msOfDay % MS_IN_SECOND,\n },\n format.zone,\n )\n return passes.length ? pickPass(passes, format) : null\n}\n\n/**\n * The value for a complete text, or `null` while it is not one. A typed\n * date is made in the format's zone from the typed fields, so the time is\n * the one typed on a daylight saving day too. A date that does not exist is\n * `null`; a time skipped by a clock change moves forward, as Luxon does, and\n * a time the clocks show twice is its first pass, as the browser's Date reads\n * it, unless only the second is within min and max or the text is a bound's\n * own. Kept within min and max when the mode has a year, as Maskito's reading is.\n */\nexport const parseDateInput = (text: string, format: DateInputFormat) => {\n const typed = readTyped(text, format)\n if (!typed) return null\n return format.mode.includes(\"y\") ? clampToRange(typed, format, format.zone) : typed\n}\n\n/**\n * min or max for Maskito's mask, which builds the typed dates with the\n * browser's Date from their fields: the same fields, read in the value's\n * zone, so the mask compares wall clocks. Only its steps for a date not yet\n * complete read them, as keepTypedValue takes over the rest.\n */\nexport const maskDate = (millis: number, zone: Zone | string | undefined) => {\n const shown = DateTime.fromMillis(millis, inZone(zone))\n const date = new Date(shown.year, shown.month - 1, shown.day, shown.hour, shown.minute, shown.second, shown.millisecond)\n // Years 0 to 99 would read as 1900 to 1999\n date.setFullYear(shown.year)\n return date\n}\n\nconst NO_BREAK_SPACE = \"\\u00A0\"\n\n/** A wall date made in UTC, where every day exists, to compare calendar dates */\nconst calendarDay = (value: DateTime) => DateTime.fromObject({ year: value.year, month: value.month, day: value.day }, { zone: \"UTC\" })\n\n/**\n * A text whose date is complete but not its time: its date kept within the dates of min and max, as Maskito's step\n * keeps it, on the calendar instead of the browser's Date. `null` for a date that does not exist, left to Maskito.\n */\nconst keepTypedDay = (value: string, format: DateInputFormat) => {\n const dateLetters = format.mode.replaceAll(/[^dmy]/g, \"\")\n const dateText = new RegExp(String.raw`^(?:\\D*\\d){${dateLetters.length}}`).exec(value)?.[0]\n const dayFormat = { ...format, timeMode: undefined, min: undefined, max: undefined, zone: \"UTC\" }\n const typed = dateText ? readTyped(dateText, dayFormat) : null\n if (!dateText || !typed) return null\n const bound = (millis: number | undefined) => (millis === undefined ? undefined : calendarDay(DateTime.fromMillis(millis, inZone(format.zone))))\n const min = bound(format.min)\n const max = bound(format.max)\n const kept = min && typed.toMillis() < min.toMillis() ? min : max && typed.toMillis() > max.toMillis() ? max : typed\n return wallText(kept, dayFormat) + value.slice(dateText.length)\n}\n\n/**\n * Maskito's date and date-and-time masks end with a step that rebuilds a complete date with the browser's Date to keep\n * it within min and max: in a zone whose clocks skipped a whole day the date moved a day, in the hour the browser's\n * clocks skip a time typed for a value in another zone moved an hour, and min and max held on the browser's clock.\n * This step reads a complete text in the value's zone, as the value is read (a time the clocks skip moves forward, an\n * hour they repeat is its first pass or the one within min and max), and shows it kept within min and max as instants,\n * so the text is the value's. A date and time without its time yet keeps its date within the dates of min and max. A\n * date that does not exist, or one not yet complete, stays with Maskito's step.\n */\nexport const keepTypedValue = (options: MaskitoOptions, format: DateInputFormat): MaskitoOptions => {\n const postprocessors = [...(options.postprocessors ?? [])]\n const maskitoRange = postprocessors.pop()\n if (!maskitoRange) return options\n const keep: MaskitoPostprocessor = (state, initial) => {\n // Complete once the AM or PM is typed too, as for Maskito\n const complete = !format.timeMode?.includes(\"AA\") || /[AP]M$/.test(state.value)\n const typed = complete ? readTyped(state.value, format) : null\n // The mask puts a no-break space before AM and PM\n const value = typed\n ? formatDateInput(typed, format).replace(/ (?=[AP]M$)/, NO_BREAK_SPACE)\n : format.timeMode\n ? keepTypedDay(state.value, format)\n : null\n if (value === null) return maskitoRange(state, initial)\n return value === state.value ? state : { value, selection: state.selection }\n }\n return { ...options, postprocessors: [...postprocessors, keep] }\n}\n"]}
@@ -0,0 +1,234 @@
1
+ /**
2
+ * The phone drawer of Sidebar, shared by React and Vue (one copy per package, kept identical by lib-sync).
3
+ *
4
+ * - It follows the finger: a swipe in from the edge it lives behind opens it, a swipe back toward that edge closes
5
+ * it, and either finishes on release by how far and how fast the finger went. The drawer says its edge in
6
+ * `--sidebar-drawer-edge` (`left` or `right`). While a finger drags it, the root carries `data-mobile-dragging`
7
+ * and `--sidebar-drawer-progress` (0 closed to 1 open), and the styles place the drawer by them.
8
+ * - While it is open, Tab goes round its controls (the page behind is inert), and Escape closes it once every other
9
+ * listener has had the key, so a menu or dialog over the drawer takes its own Escape first.
10
+ */
11
+ /** How far in from its edge a swipe that opens the drawer may start */
12
+ export const DRAWER_EDGE_ZONE = 24;
13
+ /** How far a finger moves before the swipe is taken as horizontal or left to the page */
14
+ export const DRAWER_SWIPE_SLOP = 10;
15
+ /** A release faster than this, in px/ms, finishes the swipe in its direction whatever the distance */
16
+ export const DRAWER_SWIPE_VELOCITY = 0.3;
17
+ /** A finger held still this long, in ms, before it lifts lets go by distance alone */
18
+ export const DRAWER_SWIPE_HOLD = 100;
19
+ const edgeOf = (drawer) => getComputedStyle(drawer).getPropertyValue("--sidebar-drawer-edge").trim() === "left" ? "left" : "right";
20
+ /** The distance the drawer travels: its own width when it slides in beside the page, else its container's width */
21
+ const travelOf = (drawer, root, edge) => {
22
+ if (edge === "left")
23
+ return drawer.getBoundingClientRect().width || root.getBoundingClientRect().width;
24
+ const container = drawer.offsetParent instanceof HTMLElement ? drawer.offsetParent : null;
25
+ return container?.clientWidth || window.innerWidth;
26
+ };
27
+ /**
28
+ * A finger on a slider, on an element that takes horizontal touches itself (`touch-action` without `pan-x`, such
29
+ * as the Slider) or in a row that scrolls sideways moves that, not the drawer
30
+ */
31
+ const ownsHorizontalSwipe = (target, root) => {
32
+ for (let node = target instanceof Element ? target : null; node && node !== root; node = node.parentElement) {
33
+ if ((node instanceof HTMLInputElement && node.type === "range") || node.getAttribute("role") === "slider")
34
+ return true;
35
+ const style = getComputedStyle(node);
36
+ if (/^(none|pan-y|pinch-zoom)/.test(style.touchAction) && !style.touchAction.includes("pan-x"))
37
+ return true;
38
+ if (node.scrollWidth > node.clientWidth && /auto|scroll/.test(style.overflowX))
39
+ return true;
40
+ }
41
+ return false;
42
+ };
43
+ /**
44
+ * A popover or menu open over the drawer (the Radix and Reka popper wrappers) keeps the touch: swiping the drawer
45
+ * away from under it would leave it open on an inert trigger. A modal dialog's overlay already covers the drawer.
46
+ */
47
+ const layerOpen = (root) => root.ownerDocument.querySelector("[data-radix-popper-content-wrapper], [data-reka-popper-content-wrapper]") !== null;
48
+ /** Starts the gesture on `root`; returns the cleanup */
49
+ export function attachDrawerSwipe({ root, drawer, isOpen, setOpen, enabled = () => true }) {
50
+ let drag = null;
51
+ const setProgress = (progress) => {
52
+ root.style.setProperty("--sidebar-drawer-progress", String(progress));
53
+ };
54
+ const end = (commit, time = 0) => {
55
+ const current = drag;
56
+ drag = null;
57
+ if (!current || current.state !== "dragging")
58
+ return;
59
+ let next = current.open;
60
+ if (commit) {
61
+ // Velocity in the opening direction is positive; a finger that stopped before lifting has none
62
+ const velocity = time - current.lastTime > DRAWER_SWIPE_HOLD ? 0 : current.velocity;
63
+ const opening = current.edge === "left" ? velocity : -velocity;
64
+ next = opening > DRAWER_SWIPE_VELOCITY ? true : opening < -DRAWER_SWIPE_VELOCITY ? false : current.progress > 0.5;
65
+ }
66
+ if (next !== current.open)
67
+ setOpen(next);
68
+ // The drawer leaves the finger once the new state is on the page, so it animates from where it was let go
69
+ requestAnimationFrame(() => {
70
+ root.removeAttribute("data-mobile-dragging");
71
+ root.style.removeProperty("--sidebar-drawer-progress");
72
+ });
73
+ };
74
+ const onTouchStart = (event) => {
75
+ // A second finger cancels a swipe under way, and the drawer goes back to where it was
76
+ end(false);
77
+ if (event.touches.length !== 1 || !enabled() || layerOpen(root) || ownsHorizontalSwipe(event.target, root))
78
+ return;
79
+ const touch = event.touches[0];
80
+ const open = isOpen();
81
+ const edge = edgeOf(drawer);
82
+ if (!open) {
83
+ const bounds = root.getBoundingClientRect();
84
+ const fromEdge = edge === "left" ? touch.clientX - bounds.left : bounds.right - touch.clientX;
85
+ if (fromEdge < 0 || fromEdge > DRAWER_EDGE_ZONE)
86
+ return;
87
+ }
88
+ drag = {
89
+ x: touch.clientX,
90
+ y: touch.clientY,
91
+ lastX: touch.clientX,
92
+ lastTime: event.timeStamp,
93
+ velocity: 0,
94
+ open,
95
+ edge,
96
+ travel: Math.max(1, travelOf(drawer, root, edge)),
97
+ state: "pending",
98
+ progress: open ? 1 : 0,
99
+ };
100
+ };
101
+ const onTouchMove = (event) => {
102
+ if (!drag || drag.state === "ignored")
103
+ return;
104
+ // A second finger put down outside the root shows only here
105
+ if (event.touches.length !== 1) {
106
+ end(false);
107
+ return;
108
+ }
109
+ const touch = event.touches[0];
110
+ if (!touch)
111
+ return;
112
+ const dx = touch.clientX - drag.x;
113
+ const dy = touch.clientY - drag.y;
114
+ // Toward the open drawer is positive
115
+ const toward = drag.edge === "left" ? dx : -dx;
116
+ if (drag.state === "pending") {
117
+ if (Math.abs(dx) < DRAWER_SWIPE_SLOP && Math.abs(dy) < DRAWER_SWIPE_SLOP)
118
+ return;
119
+ const horizontal = Math.abs(dx) > Math.abs(dy);
120
+ if (!horizontal || (drag.open ? toward >= 0 : toward <= 0)) {
121
+ drag.state = "ignored";
122
+ return;
123
+ }
124
+ drag.state = "dragging";
125
+ root.setAttribute("data-mobile-dragging", "");
126
+ }
127
+ if (event.cancelable)
128
+ event.preventDefault();
129
+ const elapsed = event.timeStamp - drag.lastTime;
130
+ if (elapsed > 0)
131
+ drag.velocity = (touch.clientX - drag.lastX) / elapsed;
132
+ drag.lastX = touch.clientX;
133
+ drag.lastTime = event.timeStamp;
134
+ drag.progress = Math.min(1, Math.max(0, (drag.open ? 1 : 0) + toward / drag.travel));
135
+ setProgress(drag.progress);
136
+ };
137
+ // A finger lifted while another stays on the screen cancels the swipe
138
+ const onTouchEnd = (event) => end(event.touches.length === 0, event.timeStamp);
139
+ const onTouchCancel = () => end(false);
140
+ root.addEventListener("touchstart", onTouchStart, { passive: true });
141
+ root.addEventListener("touchmove", onTouchMove, { passive: false });
142
+ root.addEventListener("touchend", onTouchEnd);
143
+ root.addEventListener("touchcancel", onTouchCancel);
144
+ return () => {
145
+ root.removeEventListener("touchstart", onTouchStart);
146
+ root.removeEventListener("touchmove", onTouchMove);
147
+ root.removeEventListener("touchend", onTouchEnd);
148
+ root.removeEventListener("touchcancel", onTouchCancel);
149
+ root.removeAttribute("data-mobile-dragging");
150
+ root.style.removeProperty("--sidebar-drawer-progress");
151
+ };
152
+ }
153
+ const TABBABLE = 'a[href], area[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), iframe, [contenteditable]:not([contenteditable="false"]), [tabindex]';
154
+ /** The controls Tab reaches in the drawer, in order: not disabled (a disabled fieldset too), not in a closed submenu, not hidden */
155
+ export const drawerTabbables = (drawer) => Array.from(drawer.querySelectorAll(TABBABLE)).filter((element) => element.tabIndex >= 0 &&
156
+ !element.matches(":disabled") &&
157
+ !element.closest("[inert], [hidden]") &&
158
+ (typeof element.checkVisibility !== "function" || element.checkVisibility({ visibilityProperty: true })));
159
+ /** The first control of the open drawer, or the drawer itself */
160
+ export const drawerInitialFocus = (drawer) => drawerTabbables(drawer)[0] ?? drawer;
161
+ const MENU_BUTTON = "[data-sidebar-mobile-menu-button]";
162
+ const PROVIDER = "[data-mobile-menu]";
163
+ /** Focus can go there: connected, not disabled, not inert or hidden, visible */
164
+ const canTakeFocus = (element) => element instanceof HTMLElement &&
165
+ element.isConnected &&
166
+ !element.matches(":disabled") &&
167
+ !element.closest("[inert], [hidden]") &&
168
+ (typeof element.checkVisibility !== "function" || element.checkVisibility({ visibilityProperty: true }));
169
+ /**
170
+ * Focuses where focus goes when the drawer closes: the control that opened it, or, when that cannot take focus (it
171
+ * sat in another drawer that has closed since, it is gone, or it was the page itself), the menu button of this
172
+ * drawer's provider, then any menu button on the page. The first that takes focus; `null` when none does. A drawer
173
+ * that has already left the page has no provider around it, so `root` is the provider taken while it was open.
174
+ */
175
+ export const returnDrawerFocus = (opener, drawer, root = drawer.closest(PROVIDER)) => {
176
+ // The provider's own menu buttons, not those of a provider inside it
177
+ const own = [...(root?.querySelectorAll(MENU_BUTTON) ?? [])].filter((button) => button.closest(PROVIDER) === root);
178
+ const candidates = [opener, ...own, ...document.querySelectorAll(MENU_BUTTON)];
179
+ for (const candidate of candidates) {
180
+ if (!canTakeFocus(candidate) || drawer.contains(candidate) || candidate === candidate.ownerDocument.body)
181
+ continue;
182
+ candidate.focus({ preventScroll: true });
183
+ if (candidate.ownerDocument.activeElement === candidate)
184
+ return candidate;
185
+ }
186
+ return null;
187
+ };
188
+ /**
189
+ * Tab from the last control goes to the first and Shift+Tab from the first to the last, so focus stays in the open
190
+ * drawer. A layer over it in a portal (a menu, a dialog) keeps its own Tab.
191
+ */
192
+ export function loopDrawerFocus(event, drawer) {
193
+ if (event.key !== "Tab" || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey)
194
+ return;
195
+ if (!(event.target instanceof Node) || !drawer.contains(event.target))
196
+ return;
197
+ const items = drawerTabbables(drawer);
198
+ const active = drawer.ownerDocument.activeElement;
199
+ const first = items[0];
200
+ const last = items[items.length - 1];
201
+ if (!first || !last) {
202
+ event.preventDefault();
203
+ drawer.focus({ preventScroll: true });
204
+ }
205
+ else if (event.shiftKey && (active === first || active === drawer)) {
206
+ event.preventDefault();
207
+ last.focus({ preventScroll: true });
208
+ }
209
+ else if (!event.shiftKey && active === last) {
210
+ event.preventDefault();
211
+ first.focus({ preventScroll: true });
212
+ }
213
+ }
214
+ /**
215
+ * Escape pressed in the open drawer closes it when the key reaches the window unprevented: a menu, popover or dialog
216
+ * over the drawer has its listener on the way there and takes the key first, however it listens.
217
+ */
218
+ export function closeOnUnhandledEscape(event, drawer, close) {
219
+ if (event.key !== "Escape" || event.defaultPrevented)
220
+ return;
221
+ const view = drawer.ownerDocument.defaultView;
222
+ if (!view)
223
+ return;
224
+ const afterOthers = (late) => {
225
+ view.removeEventListener("keydown", afterOthers);
226
+ // A listener that stopped the key on its way leaves this one to the next key, which only removes it
227
+ if (late !== event || event.defaultPrevented)
228
+ return;
229
+ event.preventDefault();
230
+ close();
231
+ };
232
+ view.addEventListener("keydown", afterOthers);
233
+ }
234
+ //# sourceMappingURL=phoneDrawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phoneDrawer.js","sourceRoot":"","sources":["../../../src/lib/phoneDrawer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,uEAAuE;AACvE,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAClC,yFAAyF;AACzF,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AACnC,sGAAsG;AACtG,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAA;AACxC,sFAAsF;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAA;AA0BpC,MAAM,MAAM,GAAG,CAAC,MAAmB,EAAoB,EAAE,CACvD,gBAAgB,CAAC,MAAM,CAAC,CAAC,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,EAAE,CAAC;QACrE,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,IAAI,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IACrC,CAAC;SAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC9C,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,KAAK,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;IACtC,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAoB,EAAE,MAAmB,EAAE,KAAiB;IACjG,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,gBAAgB;QAAE,OAAM;IAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,WAAW,CAAA;IAC7C,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,MAAM,WAAW,GAAG,CAAC,IAAW,EAAE,EAAE;QAClC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;QAChD,oGAAoG;QACpG,IAAI,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,gBAAgB;YAAE,OAAM;QACpD,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,KAAK,EAAE,CAAA;IACT,CAAC,CAAA;IACD,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["/**\n * The phone drawer of Sidebar, shared by React and Vue (one copy per package, kept identical by lib-sync).\n *\n * - It follows the finger: a swipe in from the edge it lives behind opens it, a swipe back toward that edge closes\n * it, and either finishes on release by how far and how fast the finger went. The drawer says its edge in\n * `--sidebar-drawer-edge` (`left` or `right`). While a finger drags it, the root carries `data-mobile-dragging`\n * and `--sidebar-drawer-progress` (0 closed to 1 open), and the styles place the drawer by them.\n * - While it is open, Tab goes round its controls (the page behind is inert), and Escape closes it once every other\n * listener has had the key, so a menu or dialog over the drawer takes its own Escape first.\n */\n\n/** How far in from its edge a swipe that opens the drawer may start */\nexport const DRAWER_EDGE_ZONE = 24\n/** How far a finger moves before the swipe is taken as horizontal or left to the page */\nexport const DRAWER_SWIPE_SLOP = 10\n/** A release faster than this, in px/ms, finishes the swipe in its direction whatever the distance */\nexport const DRAWER_SWIPE_VELOCITY = 0.3\n/** A finger held still this long, in ms, before it lifts lets go by distance alone */\nexport const DRAWER_SWIPE_HOLD = 100\n\nexport type DrawerSwipeOptions = {\n /** The element that holds the drawer and the page, where the drag state is written */\n root: HTMLElement\n /** The drawer itself */\n drawer: HTMLElement\n isOpen: () => boolean\n setOpen: (open: boolean) => void\n /** False turns the gesture off (a wide layout) */\n enabled?: () => boolean\n}\n\ntype Drag = {\n x: number\n y: number\n lastX: number\n lastTime: number\n velocity: number\n open: boolean\n edge: \"left\" | \"right\"\n travel: number\n state: \"pending\" | \"dragging\" | \"ignored\"\n progress: number\n}\n\nconst edgeOf = (drawer: HTMLElement): \"left\" | \"right\" =>\n getComputedStyle(drawer).getPropertyValue(\"--sidebar-drawer-edge\").trim() === \"left\" ? \"left\" : \"right\"\n\n/** The distance the drawer travels: its own width when it slides in beside the page, else its container's width */\nconst travelOf = (drawer: HTMLElement, root: HTMLElement, edge: \"left\" | \"right\") => {\n if (edge === \"left\") return drawer.getBoundingClientRect().width || root.getBoundingClientRect().width\n const container = drawer.offsetParent instanceof HTMLElement ? drawer.offsetParent : null\n return container?.clientWidth || window.innerWidth\n}\n\n/**\n * A finger on a slider, on an element that takes horizontal touches itself (`touch-action` without `pan-x`, such\n * as the Slider) or in a row that scrolls sideways moves that, not the drawer\n */\nconst ownsHorizontalSwipe = (target: EventTarget | null, root: HTMLElement) => {\n for (let node = target instanceof Element ? target : null; node && node !== root; node = node.parentElement) {\n if ((node instanceof HTMLInputElement && node.type === \"range\") || node.getAttribute(\"role\") === \"slider\") return true\n const style = getComputedStyle(node)\n if (/^(none|pan-y|pinch-zoom)/.test(style.touchAction) && !style.touchAction.includes(\"pan-x\")) return true\n if (node.scrollWidth > node.clientWidth && /auto|scroll/.test(style.overflowX)) return true\n }\n return false\n}\n\n/**\n * A popover or menu open over the drawer (the Radix and Reka popper wrappers) keeps the touch: swiping the drawer\n * away from under it would leave it open on an inert trigger. A modal dialog's overlay already covers the drawer.\n */\nconst layerOpen = (root: HTMLElement) =>\n root.ownerDocument.querySelector(\"[data-radix-popper-content-wrapper], [data-reka-popper-content-wrapper]\") !== null\n\n/** Starts the gesture on `root`; returns the cleanup */\nexport function attachDrawerSwipe({ root, drawer, isOpen, setOpen, enabled = () => true }: DrawerSwipeOptions) {\n let drag: Drag | null = null\n\n const setProgress = (progress: number) => {\n root.style.setProperty(\"--sidebar-drawer-progress\", String(progress))\n }\n\n const end = (commit: boolean, time = 0) => {\n const current = drag\n drag = null\n if (!current || current.state !== \"dragging\") return\n let next = current.open\n if (commit) {\n // Velocity in the opening direction is positive; a finger that stopped before lifting has none\n const velocity = time - current.lastTime > DRAWER_SWIPE_HOLD ? 0 : current.velocity\n const opening = current.edge === \"left\" ? velocity : -velocity\n next = opening > DRAWER_SWIPE_VELOCITY ? true : opening < -DRAWER_SWIPE_VELOCITY ? false : current.progress > 0.5\n }\n if (next !== current.open) setOpen(next)\n // The drawer leaves the finger once the new state is on the page, so it animates from where it was let go\n requestAnimationFrame(() => {\n root.removeAttribute(\"data-mobile-dragging\")\n root.style.removeProperty(\"--sidebar-drawer-progress\")\n })\n }\n\n const onTouchStart = (event: TouchEvent) => {\n // A second finger cancels a swipe under way, and the drawer goes back to where it was\n end(false)\n if (event.touches.length !== 1 || !enabled() || layerOpen(root) || ownsHorizontalSwipe(event.target, root)) return\n const touch = event.touches[0]!\n const open = isOpen()\n const edge = edgeOf(drawer)\n if (!open) {\n const bounds = root.getBoundingClientRect()\n const fromEdge = edge === \"left\" ? touch.clientX - bounds.left : bounds.right - touch.clientX\n if (fromEdge < 0 || fromEdge > DRAWER_EDGE_ZONE) return\n }\n drag = {\n x: touch.clientX,\n y: touch.clientY,\n lastX: touch.clientX,\n lastTime: event.timeStamp,\n velocity: 0,\n open,\n edge,\n travel: Math.max(1, travelOf(drawer, root, edge)),\n state: \"pending\",\n progress: open ? 1 : 0,\n }\n }\n\n const onTouchMove = (event: TouchEvent) => {\n if (!drag || drag.state === \"ignored\") return\n // A second finger put down outside the root shows only here\n if (event.touches.length !== 1) {\n end(false)\n return\n }\n const touch = event.touches[0]\n if (!touch) return\n const dx = touch.clientX - drag.x\n const dy = touch.clientY - drag.y\n // Toward the open drawer is positive\n const toward = drag.edge === \"left\" ? dx : -dx\n if (drag.state === \"pending\") {\n if (Math.abs(dx) < DRAWER_SWIPE_SLOP && Math.abs(dy) < DRAWER_SWIPE_SLOP) return\n const horizontal = Math.abs(dx) > Math.abs(dy)\n if (!horizontal || (drag.open ? toward >= 0 : toward <= 0)) {\n drag.state = \"ignored\"\n return\n }\n drag.state = \"dragging\"\n root.setAttribute(\"data-mobile-dragging\", \"\")\n }\n if (event.cancelable) event.preventDefault()\n const elapsed = event.timeStamp - drag.lastTime\n if (elapsed > 0) drag.velocity = (touch.clientX - drag.lastX) / elapsed\n drag.lastX = touch.clientX\n drag.lastTime = event.timeStamp\n drag.progress = Math.min(1, Math.max(0, (drag.open ? 1 : 0) + toward / drag.travel))\n setProgress(drag.progress)\n }\n\n // A finger lifted while another stays on the screen cancels the swipe\n const onTouchEnd = (event: TouchEvent) => end(event.touches.length === 0, event.timeStamp)\n const onTouchCancel = () => end(false)\n\n root.addEventListener(\"touchstart\", onTouchStart, { passive: true })\n root.addEventListener(\"touchmove\", onTouchMove, { passive: false })\n root.addEventListener(\"touchend\", onTouchEnd)\n root.addEventListener(\"touchcancel\", onTouchCancel)\n return () => {\n root.removeEventListener(\"touchstart\", onTouchStart)\n root.removeEventListener(\"touchmove\", onTouchMove)\n root.removeEventListener(\"touchend\", onTouchEnd)\n root.removeEventListener(\"touchcancel\", onTouchCancel)\n root.removeAttribute(\"data-mobile-dragging\")\n root.style.removeProperty(\"--sidebar-drawer-progress\")\n }\n}\n\nconst TABBABLE =\n 'a[href], area[href], button:not([disabled]), input:not([disabled]):not([type=\"hidden\"]), select:not([disabled]), textarea:not([disabled]), iframe, [contenteditable]:not([contenteditable=\"false\"]), [tabindex]'\n\n/** The controls Tab reaches in the drawer, in order: not disabled (a disabled fieldset too), not in a closed submenu, not hidden */\nexport const drawerTabbables = (drawer: HTMLElement) =>\n Array.from(drawer.querySelectorAll<HTMLElement>(TABBABLE)).filter(\n (element) =>\n element.tabIndex >= 0 &&\n !element.matches(\":disabled\") &&\n !element.closest(\"[inert], [hidden]\") &&\n (typeof element.checkVisibility !== \"function\" || element.checkVisibility({ visibilityProperty: true })),\n )\n\n/** The first control of the open drawer, or the drawer itself */\nexport const drawerInitialFocus = (drawer: HTMLElement) => drawerTabbables(drawer)[0] ?? drawer\n\nconst MENU_BUTTON = \"[data-sidebar-mobile-menu-button]\"\nconst PROVIDER = \"[data-mobile-menu]\"\n\n/** Focus can go there: connected, not disabled, not inert or hidden, visible */\nconst canTakeFocus = (element: Element | null): element is HTMLElement =>\n element instanceof HTMLElement &&\n element.isConnected &&\n !element.matches(\":disabled\") &&\n !element.closest(\"[inert], [hidden]\") &&\n (typeof element.checkVisibility !== \"function\" || element.checkVisibility({ visibilityProperty: true }))\n\n/**\n * Focuses where focus goes when the drawer closes: the control that opened it, or, when that cannot take focus (it\n * sat in another drawer that has closed since, it is gone, or it was the page itself), the menu button of this\n * drawer's provider, then any menu button on the page. The first that takes focus; `null` when none does. A drawer\n * that has already left the page has no provider around it, so `root` is the provider taken while it was open.\n */\nexport const returnDrawerFocus = (\n opener: Element | null,\n drawer: HTMLElement,\n root: Element | null = drawer.closest(PROVIDER),\n): HTMLElement | null => {\n // The provider's own menu buttons, not those of a provider inside it\n const own = [...(root?.querySelectorAll(MENU_BUTTON) ?? [])].filter((button) => button.closest(PROVIDER) === root)\n const candidates = [opener, ...own, ...document.querySelectorAll(MENU_BUTTON)]\n for (const candidate of candidates) {\n if (!canTakeFocus(candidate) || drawer.contains(candidate) || candidate === candidate.ownerDocument.body) continue\n candidate.focus({ preventScroll: true })\n if (candidate.ownerDocument.activeElement === candidate) return candidate\n }\n return null\n}\n\n/**\n * Tab from the last control goes to the first and Shift+Tab from the first to the last, so focus stays in the open\n * drawer. A layer over it in a portal (a menu, a dialog) keeps its own Tab.\n */\nexport function loopDrawerFocus(event: KeyboardEvent, drawer: HTMLElement) {\n if (event.key !== \"Tab\" || event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey) return\n if (!(event.target instanceof Node) || !drawer.contains(event.target)) return\n const items = drawerTabbables(drawer)\n const active = drawer.ownerDocument.activeElement\n const first = items[0]\n const last = items[items.length - 1]\n if (!first || !last) {\n event.preventDefault()\n drawer.focus({ preventScroll: true })\n } else if (event.shiftKey && (active === first || active === drawer)) {\n event.preventDefault()\n last.focus({ preventScroll: true })\n } else if (!event.shiftKey && active === last) {\n event.preventDefault()\n first.focus({ preventScroll: true })\n }\n}\n\n/**\n * Escape pressed in the open drawer closes it when the key reaches the window unprevented: a menu, popover or dialog\n * over the drawer has its listener on the way there and takes the key first, however it listens.\n */\nexport function closeOnUnhandledEscape(event: KeyboardEvent, drawer: HTMLElement, close: () => void) {\n if (event.key !== \"Escape\" || event.defaultPrevented) return\n const view = drawer.ownerDocument.defaultView\n if (!view) return\n const afterOthers = (late: Event) => {\n view.removeEventListener(\"keydown\", afterOthers)\n // A listener that stopped the key on its way leaves this one to the next key, which only removes it\n if (late !== event || event.defaultPrevented) return\n event.preventDefault()\n close()\n }\n view.addEventListener(\"keydown\", afterOthers)\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { type MaskitoDateMode, type MaskitoTimeMode } from "@maskito/kit";
2
- import { DateTime } from "luxon";
2
+ import { type DateTime } from "luxon";
3
3
  import { type InputProps } from "../Input/index.js";
4
4
  export type DateInputProps = {
5
5
  value: DateTime | null;
@@ -145,7 +145,18 @@ export declare const SidebarMobileMenuButton: import("react").ForwardRefExoticCo
145
145
  export type SidebarMobileProps = ComponentProps<"div"> & {
146
146
  /** When true, drawer is positioned absolute instead of fixed (for contained demos) */
147
147
  contained?: boolean;
148
+ /**
149
+ * Rows that lead to another page end with a disclosure chevron, as in an iOS list. `false` leaves it out.
150
+ * @default true
151
+ */
152
+ disclosure?: boolean;
148
153
  };
154
+ /**
155
+ * The phone drawer: a modal dialog while it is open. Focus moves into it and Tab goes round its controls, the page
156
+ * behind is inert (SidebarInset), Escape inside it closes it after any layer over it has taken its own, and focus
157
+ * goes back to the control that opened it. A swipe in from the edge it slides from opens it and a swipe back closes
158
+ * it (lib/phoneDrawer).
159
+ */
149
160
  export declare const SidebarMobile: import("react").ForwardRefExoticComponent<Omit<SidebarMobileProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
150
161
  export type SidebarMobileHeaderProps = ComponentProps<"div">;
151
162
  export declare const SidebarMobileHeader: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;