@umamichi-ui/common-components 0.1.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.
Files changed (98) hide show
  1. package/README.md +112 -0
  2. package/dist/dialog/AboutDialog.d.ts +27 -0
  3. package/dist/dialog/AboutDialog.d.ts.map +1 -0
  4. package/dist/dialog/AboutDialog.js +61 -0
  5. package/dist/dialog/AboutDialog.js.map +1 -0
  6. package/dist/dialog/ConfirmDialog.d.ts +17 -0
  7. package/dist/dialog/ConfirmDialog.d.ts.map +1 -0
  8. package/dist/dialog/ConfirmDialog.js +38 -0
  9. package/dist/dialog/ConfirmDialog.js.map +1 -0
  10. package/dist/dialog/ConfirmDialogOverlay.d.ts +13 -0
  11. package/dist/dialog/ConfirmDialogOverlay.d.ts.map +1 -0
  12. package/dist/dialog/ConfirmDialogOverlay.js +28 -0
  13. package/dist/dialog/ConfirmDialogOverlay.js.map +1 -0
  14. package/dist/dialog/index.d.ts +4 -0
  15. package/dist/dialog/index.d.ts.map +1 -0
  16. package/dist/dialog/index.js +9 -0
  17. package/dist/dialog/index.js.map +1 -0
  18. package/dist/icons/ChevronIcons.d.ts +6 -0
  19. package/dist/icons/ChevronIcons.d.ts.map +1 -0
  20. package/dist/icons/ChevronIcons.js +19 -0
  21. package/dist/icons/ChevronIcons.js.map +1 -0
  22. package/dist/icons/DropdownMenuChevron.d.ts +6 -0
  23. package/dist/icons/DropdownMenuChevron.d.ts.map +1 -0
  24. package/dist/icons/DropdownMenuChevron.js +20 -0
  25. package/dist/icons/DropdownMenuChevron.js.map +1 -0
  26. package/dist/icons/InfoCircleIcon.d.ts +5 -0
  27. package/dist/icons/InfoCircleIcon.d.ts.map +1 -0
  28. package/dist/icons/InfoCircleIcon.js +17 -0
  29. package/dist/icons/InfoCircleIcon.js.map +1 -0
  30. package/dist/icons/index.d.ts +4 -0
  31. package/dist/icons/index.d.ts.map +1 -0
  32. package/dist/icons/index.js +10 -0
  33. package/dist/icons/index.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +45 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/menu/FloatingMenu.d.ts +28 -0
  39. package/dist/menu/FloatingMenu.d.ts.map +1 -0
  40. package/dist/menu/FloatingMenu.js +125 -0
  41. package/dist/menu/FloatingMenu.js.map +1 -0
  42. package/dist/menu/MobileActionSheet.d.ts +9 -0
  43. package/dist/menu/MobileActionSheet.d.ts.map +1 -0
  44. package/dist/menu/MobileActionSheet.js +10 -0
  45. package/dist/menu/MobileActionSheet.js.map +1 -0
  46. package/dist/menu/MobileActionSheetContent.d.ts +31 -0
  47. package/dist/menu/MobileActionSheetContent.d.ts.map +1 -0
  48. package/dist/menu/MobileActionSheetContent.js +123 -0
  49. package/dist/menu/MobileActionSheetContent.js.map +1 -0
  50. package/dist/menu/computeFloatingMenuGeometry.d.ts +12 -0
  51. package/dist/menu/computeFloatingMenuGeometry.d.ts.map +1 -0
  52. package/dist/menu/computeFloatingMenuGeometry.js +30 -0
  53. package/dist/menu/computeFloatingMenuGeometry.js.map +1 -0
  54. package/dist/menu/index.d.ts +6 -0
  55. package/dist/menu/index.d.ts.map +1 -0
  56. package/dist/menu/index.js +13 -0
  57. package/dist/menu/index.js.map +1 -0
  58. package/dist/menu/useFloatingMenuGeometry.d.ts +13 -0
  59. package/dist/menu/useFloatingMenuGeometry.d.ts.map +1 -0
  60. package/dist/menu/useFloatingMenuGeometry.js +50 -0
  61. package/dist/menu/useFloatingMenuGeometry.js.map +1 -0
  62. package/dist/overlay/OverlayStackProvider.d.ts +17 -0
  63. package/dist/overlay/OverlayStackProvider.d.ts.map +1 -0
  64. package/dist/overlay/OverlayStackProvider.js +120 -0
  65. package/dist/overlay/OverlayStackProvider.js.map +1 -0
  66. package/dist/overlay/SiteOverlayBackdrop.d.ts +13 -0
  67. package/dist/overlay/SiteOverlayBackdrop.d.ts.map +1 -0
  68. package/dist/overlay/SiteOverlayBackdrop.js +62 -0
  69. package/dist/overlay/SiteOverlayBackdrop.js.map +1 -0
  70. package/dist/overlay/index.d.ts +6 -0
  71. package/dist/overlay/index.d.ts.map +1 -0
  72. package/dist/overlay/index.js +18 -0
  73. package/dist/overlay/index.js.map +1 -0
  74. package/dist/overlay/overlayHistory.d.ts +8 -0
  75. package/dist/overlay/overlayHistory.d.ts.map +1 -0
  76. package/dist/overlay/overlayHistory.js +14 -0
  77. package/dist/overlay/overlayHistory.js.map +1 -0
  78. package/dist/overlay/overlayStackTypes.d.ts +10 -0
  79. package/dist/overlay/overlayStackTypes.d.ts.map +1 -0
  80. package/dist/overlay/overlayStackTypes.js +9 -0
  81. package/dist/overlay/overlayStackTypes.js.map +1 -0
  82. package/dist/overlay/useOverlayStackEntry.d.ts +11 -0
  83. package/dist/overlay/useOverlayStackEntry.d.ts.map +1 -0
  84. package/dist/overlay/useOverlayStackEntry.js +55 -0
  85. package/dist/overlay/useOverlayStackEntry.js.map +1 -0
  86. package/dist/presence/index.d.ts +2 -0
  87. package/dist/presence/index.d.ts.map +1 -0
  88. package/dist/presence/index.js +7 -0
  89. package/dist/presence/index.js.map +1 -0
  90. package/dist/presence/useOverlayPresence.d.ts +10 -0
  91. package/dist/presence/useOverlayPresence.d.ts.map +1 -0
  92. package/dist/presence/useOverlayPresence.js +119 -0
  93. package/dist/presence/useOverlayPresence.js.map +1 -0
  94. package/package.json +81 -0
  95. package/src/styles/about-dialog.css +117 -0
  96. package/src/styles/index.css +3 -0
  97. package/src/styles/mobile-action-sheet.css +166 -0
  98. package/src/styles/overlay.css +61 -0
@@ -0,0 +1,125 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useRef, useId, useState, useEffect } from "react";
3
+ import { createPortal } from "react-dom";
4
+ import { useOverlayPresence, withOverlayOpen, mergeOverlayRefs } from "../presence/useOverlayPresence.js";
5
+ import { DropdownMenuChevron } from "../icons/DropdownMenuChevron.js";
6
+ import { useFloatingMenuGeometry } from "./useFloatingMenuGeometry.js";
7
+ function IconDropdownTriggerContent({ icon }) {
8
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
9
+ icon,
10
+ /* @__PURE__ */ jsx("span", { className: "dropdown-menu-trigger-caret", "aria-hidden": "true", children: /* @__PURE__ */ jsx(DropdownMenuChevron, {}) })
11
+ ] });
12
+ }
13
+ function FloatingMenu({
14
+ menuAriaLabel,
15
+ items,
16
+ triggerLabel,
17
+ triggerIcon,
18
+ triggerVariant = "labeled",
19
+ triggerClassName,
20
+ triggerAriaLabel,
21
+ scrollRootSelector,
22
+ wrapClassName = "dropdown-menu"
23
+ }) {
24
+ const wrapRef = useRef(null);
25
+ const menuId = useId();
26
+ const [menuOpen, setMenuOpen] = useState(false);
27
+ const { mounted: menuMounted, isOpen: menuShown, overlayRef: menuOverlayRef } = useOverlayPresence(menuOpen);
28
+ const { menuPanelRef, triggerRef, menuGeometry } = useFloatingMenuGeometry({
29
+ menuOpen,
30
+ menuMounted,
31
+ scrollRootSelector
32
+ });
33
+ useEffect(() => {
34
+ if (!menuOpen) {
35
+ return;
36
+ }
37
+ const onDocumentMouseDown = (event) => {
38
+ const target = event.target;
39
+ if (wrapRef.current?.contains(target) || menuPanelRef.current?.contains(target)) {
40
+ return;
41
+ }
42
+ setMenuOpen(false);
43
+ };
44
+ document.addEventListener("mousedown", onDocumentMouseDown);
45
+ return () => document.removeEventListener("mousedown", onDocumentMouseDown);
46
+ }, [menuOpen, menuPanelRef]);
47
+ useEffect(() => {
48
+ if (!menuOpen) {
49
+ return;
50
+ }
51
+ const onKeyDown = (event) => {
52
+ if (event.key === "Escape") {
53
+ event.stopPropagation();
54
+ setMenuOpen(false);
55
+ }
56
+ };
57
+ window.addEventListener("keydown", onKeyDown, true);
58
+ return () => window.removeEventListener("keydown", onKeyDown, true);
59
+ }, [menuOpen]);
60
+ const menuPanel = menuMounted ? /* @__PURE__ */ jsx(
61
+ "ul",
62
+ {
63
+ ref: mergeOverlayRefs(menuOverlayRef, menuPanelRef),
64
+ id: menuId,
65
+ className: withOverlayOpen("dropdown-menu-panel", menuShown && menuGeometry !== null),
66
+ role: "menu",
67
+ "aria-label": menuAriaLabel,
68
+ style: {
69
+ top: menuGeometry?.top ?? -9999,
70
+ left: menuGeometry?.left ?? -9999,
71
+ maxHeight: menuGeometry?.maxHeight,
72
+ overflowY: menuGeometry?.maxHeight ? "auto" : void 0
73
+ },
74
+ children: items.map((entry) => {
75
+ if (entry.kind === "separator") {
76
+ return /* @__PURE__ */ jsx("li", { className: "dropdown-menu-separator", role: "separator", "aria-orientation": "horizontal" }, entry.id);
77
+ }
78
+ return /* @__PURE__ */ jsx("li", { role: "none", children: /* @__PURE__ */ jsx(
79
+ "button",
80
+ {
81
+ type: "button",
82
+ className: "dropdown-menu-item",
83
+ role: "menuitem",
84
+ disabled: entry.disabled,
85
+ title: entry.title,
86
+ onClick: () => {
87
+ if (entry.disabled) {
88
+ return;
89
+ }
90
+ entry.onSelect();
91
+ setMenuOpen(false);
92
+ },
93
+ children: entry.label
94
+ }
95
+ ) }, entry.id);
96
+ })
97
+ }
98
+ ) : null;
99
+ const resolvedTriggerClassName = triggerClassName ?? (triggerVariant === "icon" ? "icon-button dropdown-menu-trigger dropdown-menu-trigger--icon" : "secondary-button dropdown-menu-trigger");
100
+ return /* @__PURE__ */ jsxs("div", { className: wrapClassName, ref: wrapRef, children: [
101
+ /* @__PURE__ */ jsx(
102
+ "button",
103
+ {
104
+ ref: triggerRef,
105
+ type: "button",
106
+ className: resolvedTriggerClassName,
107
+ "aria-label": triggerAriaLabel ?? (triggerVariant === "icon" ? menuAriaLabel : void 0),
108
+ "aria-expanded": menuOpen,
109
+ "aria-haspopup": "menu",
110
+ "aria-controls": menuId,
111
+ onClick: () => setMenuOpen((open) => !open),
112
+ children: triggerVariant === "icon" ? /* @__PURE__ */ jsx(IconDropdownTriggerContent, { icon: triggerIcon }) : /* @__PURE__ */ jsxs(Fragment, { children: [
113
+ triggerLabel,
114
+ " ",
115
+ /* @__PURE__ */ jsx(DropdownMenuChevron, {})
116
+ ] })
117
+ }
118
+ ),
119
+ menuPanel ? createPortal(menuPanel, document.body) : null
120
+ ] });
121
+ }
122
+ export {
123
+ FloatingMenu
124
+ };
125
+ //# sourceMappingURL=FloatingMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FloatingMenu.js","sources":["../../src/menu/FloatingMenu.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState, type ReactNode } from 'react';\nimport { createPortal } from 'react-dom';\nimport { mergeOverlayRefs, useOverlayPresence, withOverlayOpen } from '../presence/useOverlayPresence';\nimport { DropdownMenuChevron } from '../icons/DropdownMenuChevron';\nimport { useFloatingMenuGeometry } from './useFloatingMenuGeometry';\n\nexport type FloatingMenuItem = {\n kind: 'item';\n id: string;\n label: ReactNode;\n disabled?: boolean;\n title?: string;\n onSelect: () => void;\n};\n\nexport type FloatingMenuSeparator = {\n kind: 'separator';\n id: string;\n};\n\nexport type FloatingMenuEntry = FloatingMenuItem | FloatingMenuSeparator;\n\nexport type FloatingMenuTriggerVariant = 'labeled' | 'icon';\n\nexport type FloatingMenuProps = {\n menuAriaLabel: string;\n items: FloatingMenuEntry[];\n triggerLabel?: ReactNode;\n triggerIcon?: ReactNode;\n triggerVariant?: FloatingMenuTriggerVariant;\n triggerClassName?: string;\n triggerAriaLabel?: string;\n scrollRootSelector?: string;\n wrapClassName?: string;\n};\n\nfunction IconDropdownTriggerContent({ icon }: { icon: ReactNode }) {\n return (\n <>\n {icon}\n <span className=\"dropdown-menu-trigger-caret\" aria-hidden=\"true\">\n <DropdownMenuChevron />\n </span>\n </>\n );\n}\n\nexport function FloatingMenu({\n menuAriaLabel,\n items,\n triggerLabel,\n triggerIcon,\n triggerVariant = 'labeled',\n triggerClassName,\n triggerAriaLabel,\n scrollRootSelector,\n wrapClassName = 'dropdown-menu',\n}: FloatingMenuProps) {\n const wrapRef = useRef<HTMLDivElement | null>(null);\n const menuId = useId();\n const [menuOpen, setMenuOpen] = useState(false);\n const { mounted: menuMounted, isOpen: menuShown, overlayRef: menuOverlayRef } =\n useOverlayPresence<HTMLUListElement>(menuOpen);\n const { menuPanelRef, triggerRef, menuGeometry } = useFloatingMenuGeometry({\n menuOpen,\n menuMounted,\n scrollRootSelector,\n });\n\n useEffect(() => {\n if (!menuOpen) {\n return;\n }\n const onDocumentMouseDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (wrapRef.current?.contains(target) || menuPanelRef.current?.contains(target)) {\n return;\n }\n setMenuOpen(false);\n };\n document.addEventListener('mousedown', onDocumentMouseDown);\n return () => document.removeEventListener('mousedown', onDocumentMouseDown);\n }, [menuOpen, menuPanelRef]);\n\n useEffect(() => {\n if (!menuOpen) {\n return;\n }\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n event.stopPropagation();\n setMenuOpen(false);\n }\n };\n window.addEventListener('keydown', onKeyDown, true);\n return () => window.removeEventListener('keydown', onKeyDown, true);\n }, [menuOpen]);\n\n const menuPanel = menuMounted ? (\n <ul\n ref={mergeOverlayRefs(menuOverlayRef, menuPanelRef)}\n id={menuId}\n className={withOverlayOpen('dropdown-menu-panel', menuShown && menuGeometry !== null)}\n role=\"menu\"\n aria-label={menuAriaLabel}\n style={{\n top: menuGeometry?.top ?? -9999,\n left: menuGeometry?.left ?? -9999,\n maxHeight: menuGeometry?.maxHeight,\n overflowY: menuGeometry?.maxHeight ? 'auto' : undefined,\n }}\n >\n {items.map((entry) => {\n if (entry.kind === 'separator') {\n return (\n <li key={entry.id} className=\"dropdown-menu-separator\" role=\"separator\" aria-orientation=\"horizontal\" />\n );\n }\n\n return (\n <li key={entry.id} role=\"none\">\n <button\n type=\"button\"\n className=\"dropdown-menu-item\"\n role=\"menuitem\"\n disabled={entry.disabled}\n title={entry.title}\n onClick={() => {\n if (entry.disabled) {\n return;\n }\n entry.onSelect();\n setMenuOpen(false);\n }}\n >\n {entry.label}\n </button>\n </li>\n );\n })}\n </ul>\n ) : null;\n\n const resolvedTriggerClassName =\n triggerClassName ??\n (triggerVariant === 'icon'\n ? 'icon-button dropdown-menu-trigger dropdown-menu-trigger--icon'\n : 'secondary-button dropdown-menu-trigger');\n\n return (\n <div className={wrapClassName} ref={wrapRef}>\n <button\n ref={triggerRef}\n type=\"button\"\n className={resolvedTriggerClassName}\n aria-label={triggerAriaLabel ?? (triggerVariant === 'icon' ? menuAriaLabel : undefined)}\n aria-expanded={menuOpen}\n aria-haspopup=\"menu\"\n aria-controls={menuId}\n onClick={() => setMenuOpen((open) => !open)}\n >\n {triggerVariant === 'icon' ? (\n <IconDropdownTriggerContent icon={triggerIcon} />\n ) : (\n <>\n {triggerLabel}\n {' '}\n <DropdownMenuChevron />\n </>\n )}\n </button>\n {menuPanel ? createPortal(menuPanel, document.body) : null}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAoCA,SAAS,2BAA2B,EAAE,QAA6B;AACjE,SACE,qBAAA,UAAA,EACG,UAAA;AAAA,IAAA;AAAA,IACD,oBAAC,UAAK,WAAU,+BAA8B,eAAY,QACxD,UAAA,oBAAC,uBAAoB,EAAA,CACvB;AAAA,EAAA,GACF;AAEJ;AAEO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAClB,GAAsB;AACpB,QAAM,UAAU,OAA8B,IAAI;AAClD,QAAM,SAAS,MAAA;AACf,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK;AAC9C,QAAM,EAAE,SAAS,aAAa,QAAQ,WAAW,YAAY,eAAA,IAC3D,mBAAqC,QAAQ;AAC/C,QAAM,EAAE,cAAc,YAAY,aAAA,IAAiB,wBAAwB;AAAA,IACzE;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,YAAU,MAAM;AACd,QAAI,CAAC,UAAU;AACb;AAAA,IACF;AACA,UAAM,sBAAsB,CAAC,UAA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ACL,UAAU,MAAM;AAAA,YAChB,OAAO,MAAM;AAAA,YACb,SAAS,MAAM;AACb,kBAAI,MAAM,UAAU;AAClB;AAAA,cACF;AACA,oBAAM,SAAA;AACN,0BAAY,KAAK;AAAA,YACnB;AAAA,YAEC,UAAA,MAAM;AAAA,UAAA;AAAA,QAAA,EACT,GAhBO,MAAM,EAiBf;AAAA,MAEJ,CAAC;AAAA,IAAA;AAAA,EAAA,IAED;AAEJ,QAAM,2BACJ,qBACC,mBAAmB,SAChB,kEACA;AAEN,SACE,qBAAC,OAAA,EAAI,WAAW,eAAe,KAAK,SAClC,UAAA;AAAA,IAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,KAAK;AAAA,QACL,MAAK;AAAA,QACL,WAAW;AAAA,QACX,cAAY,qBAAqB,mBAAmB,SAAS,gBAAgB;AAAA,QAC7E,iBAAe;AAAA,QACf,iBAAc;AAAA,QACd,iBAAe;AAAA,QACf,SAAS,MAAM,YAAY,CAAC,SAAS,CAAC,IAAI;AAAA,QAEzC,6BAAmB,SAClB,oBAAC,8BAA2B,MAAM,YAAA,CAAa,IAE/C,qBAAA,UAAA,EACG,UAAA;AAAA,UAAA;AAAA,UACA;AAAA,8BACA,qBAAA,CAAA,CAAoB;AAAA,QAAA,EAAA,CACvB;AAAA,MAAA;AAAA,IAAA;AAAA,IAGH,YAAY,aAAa,WAAW,SAAS,IAAI,IAAI;AAAA,EAAA,GACxD;AAEJ;"}
@@ -0,0 +1,9 @@
1
+ import { type MobileActionSheetContentProps, type MobileActionSheetEntry } from './MobileActionSheetContent';
2
+ export type MobileActionSheetProps = {
3
+ open: boolean;
4
+ overlayId: string;
5
+ onDismiss: () => void;
6
+ } & Omit<MobileActionSheetContentProps, 'onRequestDismiss' | 'open'>;
7
+ export declare function MobileActionSheet({ open, overlayId, onDismiss, ...contentProps }: MobileActionSheetProps): import("react/jsx-runtime").JSX.Element;
8
+ export type { MobileActionSheetEntry };
9
+ //# sourceMappingURL=MobileActionSheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileActionSheet.d.ts","sourceRoot":"","sources":["../../src/menu/MobileActionSheet.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC5B,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB,GAAG,IAAI,CAAC,6BAA6B,EAAE,kBAAkB,GAAG,MAAM,CAAC,CAAC;AAErE,wBAAgB,iBAAiB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,YAAY,EAAE,EAAE,sBAAsB,2CAMxG;AAED,YAAY,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { SiteOverlayBackdrop } from "../overlay/SiteOverlayBackdrop.js";
3
+ import { MobileActionSheetContent } from "./MobileActionSheetContent.js";
4
+ function MobileActionSheet({ open, overlayId, onDismiss, ...contentProps }) {
5
+ return /* @__PURE__ */ jsx(SiteOverlayBackdrop, { open, overlayId, align: "bottom", onDismiss, children: /* @__PURE__ */ jsx(MobileActionSheetContent, { ...contentProps, open, onRequestDismiss: onDismiss }) });
6
+ }
7
+ export {
8
+ MobileActionSheet
9
+ };
10
+ //# sourceMappingURL=MobileActionSheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileActionSheet.js","sources":["../../src/menu/MobileActionSheet.tsx"],"sourcesContent":["import { SiteOverlayBackdrop } from '../overlay/SiteOverlayBackdrop';\nimport {\n MobileActionSheetContent,\n type MobileActionSheetContentProps,\n type MobileActionSheetEntry,\n} from './MobileActionSheetContent';\n\nexport type MobileActionSheetProps = {\n open: boolean;\n overlayId: string;\n onDismiss: () => void;\n} & Omit<MobileActionSheetContentProps, 'onRequestDismiss' | 'open'>;\n\nexport function MobileActionSheet({ open, overlayId, onDismiss, ...contentProps }: MobileActionSheetProps) {\n return (\n <SiteOverlayBackdrop open={open} overlayId={overlayId} align=\"bottom\" onDismiss={onDismiss}>\n <MobileActionSheetContent {...contentProps} open={open} onRequestDismiss={onDismiss} />\n </SiteOverlayBackdrop>\n );\n}\n\nexport type { MobileActionSheetEntry };\n"],"names":[],"mappings":";;;AAaO,SAAS,kBAAkB,EAAE,MAAM,WAAW,WAAW,GAAG,gBAAwC;AACzG,SACE,oBAAC,qBAAA,EAAoB,MAAY,WAAsB,OAAM,UAAS,WACpE,UAAA,oBAAC,0BAAA,EAA0B,GAAG,cAAc,MAAY,kBAAkB,WAAW,GACvF;AAEJ;"}
@@ -0,0 +1,31 @@
1
+ import { type ReactNode } from 'react';
2
+ export type MobileActionSheetActionItem = {
3
+ kind: 'item';
4
+ id: string;
5
+ label: string;
6
+ icon?: ReactNode;
7
+ disabled?: boolean;
8
+ title?: string;
9
+ onSelect: () => void;
10
+ };
11
+ export type MobileActionSheetSubmenuItem = {
12
+ kind: 'submenu';
13
+ id: string;
14
+ label: string;
15
+ icon: ReactNode;
16
+ items: MobileActionSheetActionItem[];
17
+ };
18
+ export type MobileActionSheetSeparatorItem = {
19
+ kind: 'separator';
20
+ id: string;
21
+ };
22
+ export type MobileActionSheetEntry = MobileActionSheetActionItem | MobileActionSheetSubmenuItem | MobileActionSheetSeparatorItem;
23
+ export type MobileActionSheetContentProps = {
24
+ ariaLabel: string;
25
+ entries: MobileActionSheetEntry[];
26
+ open: boolean;
27
+ onRequestDismiss: () => void;
28
+ backAriaLabel?: string;
29
+ };
30
+ export declare function MobileActionSheetContent({ ariaLabel, entries, open, onRequestDismiss, backAriaLabel, }: MobileActionSheetContentProps): import("react/jsx-runtime").JSX.Element;
31
+ //# sourceMappingURL=MobileActionSheetContent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileActionSheetContent.d.ts","sourceRoot":"","sources":["../../src/menu/MobileActionSheetContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAG5D,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,2BAA2B,EAAE,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAC9B,2BAA2B,GAC3B,4BAA4B,GAC5B,8BAA8B,CAAC;AAEnC,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB,EAAE,MAAM,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAIF,wBAAgB,wBAAwB,CAAC,EACvC,SAAS,EACT,OAAO,EACP,IAAI,EACJ,gBAAgB,EAChB,aAAoB,GACrB,EAAE,6BAA6B,2CAqI/B"}
@@ -0,0 +1,123 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { useState, useEffect } from "react";
3
+ import { ChevronRightIcon, ChevronLeftIcon } from "../icons/ChevronIcons.js";
4
+ const ROOT_PANEL = "root";
5
+ function MobileActionSheetContent({
6
+ ariaLabel,
7
+ entries,
8
+ open,
9
+ onRequestDismiss,
10
+ backAriaLabel = "返回"
11
+ }) {
12
+ const [activePanel, setActivePanel] = useState(ROOT_PANEL);
13
+ useEffect(() => {
14
+ if (!open) {
15
+ setActivePanel(ROOT_PANEL);
16
+ }
17
+ }, [open]);
18
+ const handleDismiss = () => {
19
+ setActivePanel(ROOT_PANEL);
20
+ onRequestDismiss();
21
+ };
22
+ const submenuById = new Map(
23
+ entries.filter((e) => e.kind === "submenu").map((e) => [e.id, e])
24
+ );
25
+ const activeSubmenu = activePanel === ROOT_PANEL ? null : submenuById.get(activePanel);
26
+ const renderActionItem = (item, closeOnSelect) => /* @__PURE__ */ jsx("li", { className: "mobile-action-sheet-list-item", role: "none", children: /* @__PURE__ */ jsxs(
27
+ "button",
28
+ {
29
+ type: "button",
30
+ className: "mobile-action-sheet-item",
31
+ role: "menuitem",
32
+ disabled: item.disabled,
33
+ title: item.title,
34
+ onClick: () => {
35
+ if (item.disabled) {
36
+ return;
37
+ }
38
+ item.onSelect();
39
+ {
40
+ handleDismiss();
41
+ }
42
+ },
43
+ children: [
44
+ item.icon ? /* @__PURE__ */ jsx("span", { className: "mobile-action-sheet-item-icon", "aria-hidden": "true", children: item.icon }) : null,
45
+ /* @__PURE__ */ jsx("span", { className: "mobile-action-sheet-item-label", children: item.label })
46
+ ]
47
+ }
48
+ ) }, item.id);
49
+ const rootPanel = /* @__PURE__ */ jsx("div", { className: "mobile-action-sheet-panel", role: "menu", "aria-label": ariaLabel, children: /* @__PURE__ */ jsx("ul", { className: "mobile-action-sheet-list", children: entries.map((entry) => {
50
+ if (entry.kind === "separator") {
51
+ return /* @__PURE__ */ jsx("li", { className: "mobile-action-sheet-list-item", role: "none", children: /* @__PURE__ */ jsx("div", { className: "mobile-action-sheet-separator", role: "separator" }) }, entry.id);
52
+ }
53
+ if (entry.kind === "submenu") {
54
+ return /* @__PURE__ */ jsx("li", { className: "mobile-action-sheet-list-item", role: "none", children: /* @__PURE__ */ jsxs(
55
+ "button",
56
+ {
57
+ type: "button",
58
+ className: "mobile-action-sheet-item mobile-action-sheet-item--submenu",
59
+ role: "menuitem",
60
+ "aria-haspopup": "menu",
61
+ onClick: () => setActivePanel(entry.id),
62
+ children: [
63
+ /* @__PURE__ */ jsx("span", { className: "mobile-action-sheet-item-icon", "aria-hidden": "true", children: entry.icon }),
64
+ /* @__PURE__ */ jsx("span", { className: "mobile-action-sheet-item-label", children: entry.label }),
65
+ /* @__PURE__ */ jsx(ChevronRightIcon, { className: "mobile-action-sheet-item-chevron" })
66
+ ]
67
+ }
68
+ ) }, entry.id);
69
+ }
70
+ return renderActionItem(entry);
71
+ }) }) });
72
+ const hasSubmenus = entries.some((e) => e.kind === "submenu");
73
+ const onSubmenu = activeSubmenu !== null && activeSubmenu !== void 0;
74
+ return /* @__PURE__ */ jsx(
75
+ "div",
76
+ {
77
+ className: "mobile-action-sheet",
78
+ role: "dialog",
79
+ "aria-modal": "true",
80
+ "aria-label": ariaLabel,
81
+ onClick: (event) => event.stopPropagation(),
82
+ children: /* @__PURE__ */ jsxs(
83
+ "div",
84
+ {
85
+ className: hasSubmenus ? "mobile-action-sheet-panels mobile-action-sheet-panels--slide" : "mobile-action-sheet-panels",
86
+ style: hasSubmenus ? { transform: onSubmenu ? "translateX(-50%)" : "none" } : void 0,
87
+ children: [
88
+ rootPanel,
89
+ hasSubmenus ? /* @__PURE__ */ jsx(
90
+ "div",
91
+ {
92
+ className: "mobile-action-sheet-panel",
93
+ role: "menu",
94
+ "aria-label": activeSubmenu?.label,
95
+ "aria-hidden": !onSubmenu,
96
+ children: activeSubmenu ? /* @__PURE__ */ jsxs(Fragment, { children: [
97
+ /* @__PURE__ */ jsxs("div", { className: "mobile-action-sheet-subheader", children: [
98
+ /* @__PURE__ */ jsx(
99
+ "button",
100
+ {
101
+ type: "button",
102
+ className: "mobile-action-sheet-back",
103
+ "aria-label": backAriaLabel,
104
+ onClick: () => setActivePanel(ROOT_PANEL),
105
+ children: /* @__PURE__ */ jsx(ChevronLeftIcon, { className: "mobile-action-sheet-back-chevron" })
106
+ }
107
+ ),
108
+ /* @__PURE__ */ jsx("span", { className: "mobile-action-sheet-subheader-title", children: activeSubmenu.label })
109
+ ] }),
110
+ /* @__PURE__ */ jsx("ul", { className: "mobile-action-sheet-list", children: activeSubmenu.items.map((item) => renderActionItem(item)) })
111
+ ] }) : null
112
+ }
113
+ ) : null
114
+ ]
115
+ }
116
+ )
117
+ }
118
+ );
119
+ }
120
+ export {
121
+ MobileActionSheetContent
122
+ };
123
+ //# sourceMappingURL=MobileActionSheetContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MobileActionSheetContent.js","sources":["../../src/menu/MobileActionSheetContent.tsx"],"sourcesContent":["import { useEffect, useState, type ReactNode } from 'react';\nimport { ChevronLeftIcon, ChevronRightIcon } from '../icons/ChevronIcons';\n\nexport type MobileActionSheetActionItem = {\n kind: 'item';\n id: string;\n label: string;\n icon?: ReactNode;\n disabled?: boolean;\n title?: string;\n onSelect: () => void;\n};\n\nexport type MobileActionSheetSubmenuItem = {\n kind: 'submenu';\n id: string;\n label: string;\n icon: ReactNode;\n items: MobileActionSheetActionItem[];\n};\n\nexport type MobileActionSheetSeparatorItem = {\n kind: 'separator';\n id: string;\n};\n\nexport type MobileActionSheetEntry =\n | MobileActionSheetActionItem\n | MobileActionSheetSubmenuItem\n | MobileActionSheetSeparatorItem;\n\nexport type MobileActionSheetContentProps = {\n ariaLabel: string;\n entries: MobileActionSheetEntry[];\n open: boolean;\n onRequestDismiss: () => void;\n backAriaLabel?: string;\n};\n\nconst ROOT_PANEL = 'root';\n\nexport function MobileActionSheetContent({\n ariaLabel,\n entries,\n open,\n onRequestDismiss,\n backAriaLabel = '返回',\n}: MobileActionSheetContentProps) {\n const [activePanel, setActivePanel] = useState(ROOT_PANEL);\n\n useEffect(() => {\n if (!open) {\n setActivePanel(ROOT_PANEL);\n }\n }, [open]);\n\n const handleDismiss = () => {\n setActivePanel(ROOT_PANEL);\n onRequestDismiss();\n };\n\n const submenuById = new Map(\n entries.filter((e): e is MobileActionSheetSubmenuItem => e.kind === 'submenu').map((e) => [e.id, e]),\n );\n const activeSubmenu = activePanel === ROOT_PANEL ? null : submenuById.get(activePanel);\n\n const renderActionItem = (item: MobileActionSheetActionItem, closeOnSelect: boolean) => (\n <li key={item.id} className=\"mobile-action-sheet-list-item\" role=\"none\">\n <button\n type=\"button\"\n className=\"mobile-action-sheet-item\"\n role=\"menuitem\"\n disabled={item.disabled}\n title={item.title}\n onClick={() => {\n if (item.disabled) {\n return;\n }\n item.onSelect();\n if (closeOnSelect) {\n handleDismiss();\n }\n }}\n >\n {item.icon ? (\n <span className=\"mobile-action-sheet-item-icon\" aria-hidden=\"true\">\n {item.icon}\n </span>\n ) : null}\n <span className=\"mobile-action-sheet-item-label\">{item.label}</span>\n </button>\n </li>\n );\n\n const rootPanel = (\n <div className=\"mobile-action-sheet-panel\" role=\"menu\" aria-label={ariaLabel}>\n <ul className=\"mobile-action-sheet-list\">\n {entries.map((entry) => {\n if (entry.kind === 'separator') {\n return (\n <li key={entry.id} className=\"mobile-action-sheet-list-item\" role=\"none\">\n <div className=\"mobile-action-sheet-separator\" role=\"separator\" />\n </li>\n );\n }\n\n if (entry.kind === 'submenu') {\n return (\n <li key={entry.id} className=\"mobile-action-sheet-list-item\" role=\"none\">\n <button\n type=\"button\"\n className=\"mobile-action-sheet-item mobile-action-sheet-item--submenu\"\n role=\"menuitem\"\n aria-haspopup=\"menu\"\n onClick={() => setActivePanel(entry.id)}\n >\n <span className=\"mobile-action-sheet-item-icon\" aria-hidden=\"true\">\n {entry.icon}\n </span>\n <span className=\"mobile-action-sheet-item-label\">{entry.label}</span>\n <ChevronRightIcon className=\"mobile-action-sheet-item-chevron\" />\n </button>\n </li>\n );\n }\n\n return renderActionItem(entry, true);\n })}\n </ul>\n </div>\n );\n\n const hasSubmenus = entries.some((e) => e.kind === 'submenu');\n const onSubmenu = activeSubmenu !== null && activeSubmenu !== undefined;\n\n return (\n <div\n className=\"mobile-action-sheet\"\n role=\"dialog\"\n aria-modal=\"true\"\n aria-label={ariaLabel}\n onClick={(event) => event.stopPropagation()}\n >\n <div\n className={\n hasSubmenus ? 'mobile-action-sheet-panels mobile-action-sheet-panels--slide' : 'mobile-action-sheet-panels'\n }\n style={hasSubmenus ? { transform: onSubmenu ? 'translateX(-50%)' : 'none' } : undefined}\n >\n {rootPanel}\n {hasSubmenus ? (\n <div\n className=\"mobile-action-sheet-panel\"\n role=\"menu\"\n aria-label={activeSubmenu?.label}\n aria-hidden={!onSubmenu}\n >\n {activeSubmenu ? (\n <>\n <div className=\"mobile-action-sheet-subheader\">\n <button\n type=\"button\"\n className=\"mobile-action-sheet-back\"\n aria-label={backAriaLabel}\n onClick={() => setActivePanel(ROOT_PANEL)}\n >\n <ChevronLeftIcon className=\"mobile-action-sheet-back-chevron\" />\n </button>\n <span className=\"mobile-action-sheet-subheader-title\">{activeSubmenu.label}</span>\n </div>\n <ul className=\"mobile-action-sheet-list\">\n {activeSubmenu.items.map((item) => renderActionItem(item, true))}\n </ul>\n </>\n ) : null}\n </div>\n ) : null}\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;AAuCA,MAAM,aAAa;AAEZ,SAAS,yBAAyB;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,gBAAgB;AAClB,GAAkC;AAChC,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,UAAU;AAEzD,YAAU,MAAM;AACd,QAAI,CAAC,MAAM;AACT,qBAAe,UAAU;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AAET,QAAM,gBAAgB,MAAM;AAC1B,mBAAe,UAAU;AACzB,qBAAA;AAAA,EACF;AAEA,QAAM,cAAc,IAAI;AAAA,IACtB,QAAQ,OAAO,CAAC,MAAyC,EAAE,SAAS,SAAS,EAAE,IAAI,CAA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CAAM;AAAA,kBAAA,GAC7E;AAAA,kBACA,oBAAC,MAAA,EAAG,WAAU,4BACX,UAAA,cAAc,MAAM,IAAI,CAAC,SAAS,iBAAiB,IAAU,CAAC,EAAA,CACjE;AAAA,gBAAA,EAAA,CACF,IACE;AAAA,cAAA;AAAA,YAAA,IAEJ;AAAA,UAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACN;AAAA,EAAA;AAGN;"}
@@ -0,0 +1,12 @@
1
+ export type FloatingMenuGeometry = {
2
+ top: number;
3
+ left: number;
4
+ maxHeight?: number;
5
+ };
6
+ export type ComputeFloatingMenuGeometryOptions = {
7
+ pad?: number;
8
+ gap?: number;
9
+ minScrollHeight?: number;
10
+ };
11
+ export declare function computeFloatingMenuGeometry(trigger: HTMLElement, menu: HTMLElement, options?: ComputeFloatingMenuGeometryOptions): FloatingMenuGeometry;
12
+ //# sourceMappingURL=computeFloatingMenuGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeFloatingMenuGeometry.d.ts","sourceRoot":"","sources":["../../src/menu/computeFloatingMenuGeometry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,kCAAuC,GAC/C,oBAAoB,CA2BtB"}
@@ -0,0 +1,30 @@
1
+ function computeFloatingMenuGeometry(trigger, menu, options = {}) {
2
+ const pad = options.pad ?? 8;
3
+ const gap = options.gap ?? 4;
4
+ const minScrollHeight = options.minScrollHeight ?? 120;
5
+ const rect = trigger.getBoundingClientRect();
6
+ const vw = window.innerWidth;
7
+ const vh = window.innerHeight;
8
+ const menuWidth = menu.offsetWidth;
9
+ const menuHeight = menu.offsetHeight;
10
+ let left = rect.right - menuWidth;
11
+ if (left < pad) {
12
+ left = rect.left;
13
+ }
14
+ left = Math.max(pad, Math.min(left, vw - menuWidth - pad));
15
+ let top = rect.bottom + gap;
16
+ let maxHeight;
17
+ if (top + menuHeight > vh - pad) {
18
+ const topIfAbove = rect.top - gap - menuHeight;
19
+ if (topIfAbove >= pad) {
20
+ top = topIfAbove;
21
+ } else {
22
+ maxHeight = Math.max(minScrollHeight, vh - pad - top);
23
+ }
24
+ }
25
+ return { top, left, maxHeight };
26
+ }
27
+ export {
28
+ computeFloatingMenuGeometry
29
+ };
30
+ //# sourceMappingURL=computeFloatingMenuGeometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeFloatingMenuGeometry.js","sources":["../../src/menu/computeFloatingMenuGeometry.ts"],"sourcesContent":["export type FloatingMenuGeometry = {\n top: number;\n left: number;\n maxHeight?: number;\n};\n\nexport type ComputeFloatingMenuGeometryOptions = {\n pad?: number;\n gap?: number;\n minScrollHeight?: number;\n};\n\nexport function computeFloatingMenuGeometry(\n trigger: HTMLElement,\n menu: HTMLElement,\n options: ComputeFloatingMenuGeometryOptions = {},\n): FloatingMenuGeometry {\n const pad = options.pad ?? 8;\n const gap = options.gap ?? 4;\n const minScrollHeight = options.minScrollHeight ?? 120;\n const rect = trigger.getBoundingClientRect();\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const menuWidth = menu.offsetWidth;\n const menuHeight = menu.offsetHeight;\n\n let left = rect.right - menuWidth;\n if (left < pad) {\n left = rect.left;\n }\n left = Math.max(pad, Math.min(left, vw - menuWidth - pad));\n\n let top = rect.bottom + gap;\n let maxHeight: number | undefined;\n if (top + menuHeight > vh - pad) {\n const topIfAbove = rect.top - gap - menuHeight;\n if (topIfAbove >= pad) {\n top = topIfAbove;\n } else {\n maxHeight = Math.max(minScrollHeight, vh - pad - top);\n }\n }\n return { top, left, maxHeight };\n}\n"],"names":[],"mappings":"AAYO,SAAS,4BACd,SACA,MACA,UAA8C,CAAA,GACxB;AACtB,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,MAAM,QAAQ,OAAO;AAC3B,QAAM,kBAAkB,QAAQ,mBAAmB;AACnD,QAAM,OAAO,QAAQ,sBAAA;AACrB,QAAM,KAAK,OAAO;AAClB,QAAM,KAAK,OAAO;AAClB,QAAM,YAAY,KAAK;AACvB,QAAM,aAAa,KAAK;AAExB,MAAI,OAAO,KAAK,QAAQ;AACxB,MAAI,OAAO,KAAK;AACd,WAAO,KAAK;AAAA,EACd;AACA,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,MAAM,KAAK,YAAY,GAAG,CAAC;AAEzD,MAAI,MAAM,KAAK,SAAS;AACxB,MAAI;AACJ,MAAI,MAAM,aAAa,KAAK,KAAK;AAC/B,UAAM,aAAa,KAAK,MAAM,MAAM;AACpC,QAAI,cAAc,KAAK;AACrB,YAAM;AAAA,IACR,OAAO;AACL,kBAAY,KAAK,IAAI,iBAAiB,KAAK,MAAM,GAAG;AAAA,IACtD;AAAA,EACF;AACA,SAAO,EAAE,KAAK,MAAM,UAAA;AACtB;"}
@@ -0,0 +1,6 @@
1
+ export { computeFloatingMenuGeometry, type ComputeFloatingMenuGeometryOptions, type FloatingMenuGeometry, } from './computeFloatingMenuGeometry';
2
+ export { FloatingMenu, type FloatingMenuEntry, type FloatingMenuItem, type FloatingMenuProps } from './FloatingMenu';
3
+ export { MobileActionSheet, type MobileActionSheetEntry, type MobileActionSheetProps, } from './MobileActionSheet';
4
+ export { MobileActionSheetContent, type MobileActionSheetActionItem, type MobileActionSheetContentProps, type MobileActionSheetSeparatorItem, type MobileActionSheetSubmenuItem, } from './MobileActionSheetContent';
5
+ export { useFloatingMenuGeometry, type UseFloatingMenuGeometryOptions } from './useFloatingMenuGeometry';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/menu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,KAAK,kCAAkC,EACvC,KAAK,oBAAoB,GAC1B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrH,OAAO,EACL,iBAAiB,EACjB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,wBAAwB,EACxB,KAAK,2BAA2B,EAChC,KAAK,6BAA6B,EAClC,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,GAClC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,KAAK,8BAA8B,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { computeFloatingMenuGeometry } from "./computeFloatingMenuGeometry.js";
2
+ import { FloatingMenu } from "./FloatingMenu.js";
3
+ import { MobileActionSheet } from "./MobileActionSheet.js";
4
+ import { MobileActionSheetContent } from "./MobileActionSheetContent.js";
5
+ import { useFloatingMenuGeometry } from "./useFloatingMenuGeometry.js";
6
+ export {
7
+ FloatingMenu,
8
+ MobileActionSheet,
9
+ MobileActionSheetContent,
10
+ computeFloatingMenuGeometry,
11
+ useFloatingMenuGeometry
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,13 @@
1
+ import { type FloatingMenuGeometry } from './computeFloatingMenuGeometry';
2
+ export type UseFloatingMenuGeometryOptions = {
3
+ menuOpen: boolean;
4
+ menuMounted: boolean;
5
+ /** 额外监听 scroll 的容器选择器(如 `.app-main`) */
6
+ scrollRootSelector?: string;
7
+ };
8
+ export declare function useFloatingMenuGeometry({ menuOpen, menuMounted, scrollRootSelector, }: UseFloatingMenuGeometryOptions): {
9
+ menuPanelRef: import("react").RefObject<HTMLUListElement | null>;
10
+ triggerRef: import("react").RefObject<HTMLButtonElement | null>;
11
+ menuGeometry: FloatingMenuGeometry | null;
12
+ };
13
+ //# sourceMappingURL=useFloatingMenuGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFloatingMenuGeometry.d.ts","sourceRoot":"","sources":["../../src/menu/useFloatingMenuGeometry.ts"],"names":[],"mappings":"AACA,OAAO,EAA+B,KAAK,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAEvG,MAAM,MAAM,8BAA8B,GAAG;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,wCAAwC;IACxC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAgB,uBAAuB,CAAC,EACtC,QAAQ,EACR,WAAW,EACX,kBAAkB,GACnB,EAAE,8BAA8B;;;;EA8ChC"}
@@ -0,0 +1,50 @@
1
+ import { useRef, useState, useLayoutEffect } from "react";
2
+ import { computeFloatingMenuGeometry } from "./computeFloatingMenuGeometry.js";
3
+ function useFloatingMenuGeometry({
4
+ menuOpen,
5
+ menuMounted,
6
+ scrollRootSelector
7
+ }) {
8
+ const menuPanelRef = useRef(null);
9
+ const triggerRef = useRef(null);
10
+ const [menuGeometry, setMenuGeometry] = useState(null);
11
+ useLayoutEffect(() => {
12
+ if (!menuOpen || !menuMounted) {
13
+ setMenuGeometry(null);
14
+ return;
15
+ }
16
+ const update = () => {
17
+ const trigger = triggerRef.current;
18
+ const menu = menuPanelRef.current;
19
+ if (!trigger || !menu) {
20
+ return;
21
+ }
22
+ setMenuGeometry(computeFloatingMenuGeometry(trigger, menu));
23
+ };
24
+ update();
25
+ const scrollRoots = [];
26
+ if (scrollRootSelector) {
27
+ const root = document.querySelector(scrollRootSelector);
28
+ if (root) {
29
+ scrollRoots.push(root);
30
+ }
31
+ }
32
+ window.addEventListener("resize", update);
33
+ window.addEventListener("scroll", update, true);
34
+ for (const root of scrollRoots) {
35
+ root.addEventListener("scroll", update, { passive: true });
36
+ }
37
+ return () => {
38
+ window.removeEventListener("resize", update);
39
+ window.removeEventListener("scroll", update, true);
40
+ for (const root of scrollRoots) {
41
+ root.removeEventListener("scroll", update);
42
+ }
43
+ };
44
+ }, [menuOpen, menuMounted, scrollRootSelector]);
45
+ return { menuPanelRef, triggerRef, menuGeometry };
46
+ }
47
+ export {
48
+ useFloatingMenuGeometry
49
+ };
50
+ //# sourceMappingURL=useFloatingMenuGeometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFloatingMenuGeometry.js","sources":["../../src/menu/useFloatingMenuGeometry.ts"],"sourcesContent":["import { useLayoutEffect, useRef, useState } from 'react';\nimport { computeFloatingMenuGeometry, type FloatingMenuGeometry } from './computeFloatingMenuGeometry';\n\nexport type UseFloatingMenuGeometryOptions = {\n menuOpen: boolean;\n menuMounted: boolean;\n /** 额外监听 scroll 的容器选择器(如 `.app-main`) */\n scrollRootSelector?: string;\n};\n\nexport function useFloatingMenuGeometry({\n menuOpen,\n menuMounted,\n scrollRootSelector,\n}: UseFloatingMenuGeometryOptions) {\n const menuPanelRef = useRef<HTMLUListElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const [menuGeometry, setMenuGeometry] = useState<FloatingMenuGeometry | null>(null);\n\n useLayoutEffect(() => {\n if (!menuOpen || !menuMounted) {\n setMenuGeometry(null);\n return;\n }\n\n const update = () => {\n const trigger = triggerRef.current;\n const menu = menuPanelRef.current;\n if (!trigger || !menu) {\n return;\n }\n setMenuGeometry(computeFloatingMenuGeometry(trigger, menu));\n };\n\n update();\n\n const scrollRoots: HTMLElement[] = [];\n if (scrollRootSelector) {\n const root = document.querySelector<HTMLElement>(scrollRootSelector);\n if (root) {\n scrollRoots.push(root);\n }\n }\n\n window.addEventListener('resize', update);\n window.addEventListener('scroll', update, true);\n for (const root of scrollRoots) {\n root.addEventListener('scroll', update, { passive: true });\n }\n\n return () => {\n window.removeEventListener('resize', update);\n window.removeEventListener('scroll', update, true);\n for (const root of scrollRoots) {\n root.removeEventListener('scroll', update);\n }\n };\n }, [menuOpen, menuMounted, scrollRootSelector]);\n\n return { menuPanelRef, triggerRef, menuGeometry };\n}\n"],"names":[],"mappings":";;AAUO,SAAS,wBAAwB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AACF,GAAmC;AACjC,QAAM,eAAe,OAAgC,IAAI;AACzD,QAAM,aAAa,OAAiC,IAAI;AACxD,QAAM,CAAC,cAAc,eAAe,IAAI,SAAsC,IAAI;AAElF,kBAAgB,MAAM;AACpB,QAAI,CAAC,YAAY,CAAC,aAAa;AAC7B,sBAAgB,IAAI;AACpB;AAAA,IACF;AAEA,UAAM,SAAS,MAAM;AACnB,YAAM,UAAU,WAAW;AAC3B,YAAM,OAAO,aAAa;AAC1B,UAAI,CAAC,WAAW,CAAC,MAAM;AACrB;AAAA,MACF;AACA,sBAAgB,4BAA4B,SAAS,IAAI,CAAC;AAAA,IAC5D;AAEA,WAAA;AAEA,UAAM,cAA6B,CAAA;AACnC,QAAI,oBAAoB;AACtB,YAAM,OAAO,SAAS,cAA2B,kBAAkB;AACnE,UAAI,MAAM;AACR,oBAAY,KAAK,IAAI;AAAA,MACvB;AAAA,IACF;AAEA,WAAO,iBAAiB,UAAU,MAAM;AACxC,WAAO,iBAAiB,UAAU,QAAQ,IAAI;AAC9C,eAAW,QAAQ,aAAa;AAC9B,WAAK,iBAAiB,UAAU,QAAQ,EAAE,SAAS,MAAM;AAAA,IAC3D;AAEA,WAAO,MAAM;AACX,aAAO,oBAAoB,UAAU,MAAM;AAC3C,aAAO,oBAAoB,UAAU,QAAQ,IAAI;AACjD,iBAAW,QAAQ,aAAa;AAC9B,aAAK,oBAAoB,UAAU,MAAM;AAAA,MAC3C;AAAA,IACF;AAAA,EACF,GAAG,CAAC,UAAU,aAAa,kBAAkB,CAAC;AAE9C,SAAO,EAAE,cAAc,YAAY,aAAA;AACrC;"}
@@ -0,0 +1,17 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type OverlayStackEntry } from './overlayStackTypes';
3
+ type OverlayStackContextValue = {
4
+ register: (entry: OverlayStackEntry) => void;
5
+ unregister: (id: string) => void;
6
+ isTop: (id: string) => boolean;
7
+ getZIndex: (id: string) => number;
8
+ pushOverlayHistory: (id: string) => void;
9
+ syncOverlayHistoryOnUiClose: (id: string) => void;
10
+ acknowledgeOverlayHistoryPop: (id: string) => void;
11
+ };
12
+ export declare function OverlayStackProvider({ children }: {
13
+ children: ReactNode;
14
+ }): import("react/jsx-runtime").JSX.Element;
15
+ export declare function useOverlayStack(): OverlayStackContextValue;
16
+ export {};
17
+ //# sourceMappingURL=OverlayStackProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OverlayStackProvider.d.ts","sourceRoot":"","sources":["../../src/overlay/OverlayStackProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAwB,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEnF,KAAK,wBAAwB,GAAG;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC7C,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/B,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,kBAAkB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,2BAA2B,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,4BAA4B,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD,CAAC;AAiBF,wBAAgB,oBAAoB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAuHzE;AAED,wBAAgB,eAAe,6BAQ9B"}