@aloudata/aloudata-design 3.1.0 → 3.1.2

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 (196) hide show
  1. package/dist/AProgress/index.js +10 -0
  2. package/dist/AProgress/index.js.map +1 -1
  3. package/dist/Alert/index.js +3 -1
  4. package/dist/Alert/index.js.map +1 -1
  5. package/dist/Badge/index.js +37 -11
  6. package/dist/Badge/index.js.map +1 -1
  7. package/dist/Breadcrumb/index.js +12 -2
  8. package/dist/Breadcrumb/index.js.map +1 -1
  9. package/dist/Button/index.d.ts +1 -1
  10. package/dist/Button/index.js +20 -6
  11. package/dist/Button/index.js.map +1 -1
  12. package/dist/Card/index.js +1 -1
  13. package/dist/Card/index.js.map +1 -1
  14. package/dist/Carousel/index.js +9 -1
  15. package/dist/Carousel/index.js.map +1 -1
  16. package/dist/Checkbox/index.js +17 -2
  17. package/dist/Checkbox/index.js.map +1 -1
  18. package/dist/Checkbox/type.d.ts +10 -2
  19. package/dist/ColorPicker/index.js +112 -46
  20. package/dist/ColorPicker/index.js.map +1 -1
  21. package/dist/DataPreviewTable/components/Body/Cell.d.ts +2 -0
  22. package/dist/DataPreviewTable/components/Body/Cell.js +9 -1
  23. package/dist/DataPreviewTable/components/Body/Cell.js.map +1 -1
  24. package/dist/DataPreviewTable/components/Body/index.d.ts +1 -0
  25. package/dist/DataPreviewTable/components/Body/index.js +35 -23
  26. package/dist/DataPreviewTable/components/Body/index.js.map +1 -1
  27. package/dist/DataPreviewTable/components/Header/index.d.ts +1 -0
  28. package/dist/DataPreviewTable/components/Header/index.js +36 -28
  29. package/dist/DataPreviewTable/components/Header/index.js.map +1 -1
  30. package/dist/DataPreviewTable/index.js +19 -2
  31. package/dist/DataPreviewTable/index.js.map +1 -1
  32. package/dist/Drawer/index.d.ts +4 -0
  33. package/dist/Drawer/index.js +93 -79
  34. package/dist/Drawer/index.js.map +1 -1
  35. package/dist/Dropdown/index.d.ts +1 -1
  36. package/dist/Dropdown/index.js +64 -13
  37. package/dist/Dropdown/index.js.map +1 -1
  38. package/dist/Form/FormItemContext.d.ts +1 -1
  39. package/dist/Form/FormItemContext.js.map +1 -1
  40. package/dist/Form/index.js +50 -7
  41. package/dist/Form/index.js.map +1 -1
  42. package/dist/IconButton/index.d.ts +2 -2
  43. package/dist/IconButton/index.js +9 -3
  44. package/dist/IconButton/index.js.map +1 -1
  45. package/dist/Input/components/Input/index.js +18 -8
  46. package/dist/Input/components/Input/index.js.map +1 -1
  47. package/dist/Input/components/TextArea/index.js +18 -7
  48. package/dist/Input/components/TextArea/index.js.map +1 -1
  49. package/dist/Input/privateSemanticOwner.d.ts +2 -0
  50. package/dist/Input/privateSemanticOwner.js +1 -0
  51. package/dist/InputNumber/index.js +16 -9
  52. package/dist/InputNumber/index.js.map +1 -1
  53. package/dist/InputNumber/type.d.ts +2 -2
  54. package/dist/LogicTree/components/LogicItem/index.d.ts +2 -1
  55. package/dist/LogicTree/components/LogicItem/index.js +13 -2
  56. package/dist/LogicTree/components/LogicItem/index.js.map +1 -1
  57. package/dist/LogicTree/index.js +2 -0
  58. package/dist/LogicTree/index.js.map +1 -1
  59. package/dist/MemberPicker/components/MemberSelection.d.ts +2 -0
  60. package/dist/MemberPicker/components/MemberSelection.js +15 -13
  61. package/dist/MemberPicker/components/MemberSelection.js.map +1 -1
  62. package/dist/MemberPicker/components/MultipleOption.js +12 -0
  63. package/dist/MemberPicker/components/MultipleOption.js.map +1 -1
  64. package/dist/MemberPicker/components/Panel.d.ts +2 -0
  65. package/dist/MemberPicker/components/Panel.js +11 -1
  66. package/dist/MemberPicker/components/Panel.js.map +1 -1
  67. package/dist/MemberPicker/components/PanelWrapper.js +2 -0
  68. package/dist/MemberPicker/components/PanelWrapper.js.map +1 -1
  69. package/dist/MemberPicker/components/SelectedMemberTags.js +14 -6
  70. package/dist/MemberPicker/components/SelectedMemberTags.js.map +1 -1
  71. package/dist/MemberPicker/components/SingleOption.js +12 -0
  72. package/dist/MemberPicker/components/SingleOption.js.map +1 -1
  73. package/dist/MemberPicker/components/UserGroupSelection.d.ts +3 -1
  74. package/dist/MemberPicker/components/UserGroupSelection.js +65 -42
  75. package/dist/MemberPicker/components/UserGroupSelection.js.map +1 -1
  76. package/dist/MemberPicker/index.js +134 -108
  77. package/dist/MemberPicker/index.js.map +1 -1
  78. package/dist/Menu/index.d.ts +8 -0
  79. package/dist/Menu/index.js +33 -3
  80. package/dist/Menu/index.js.map +1 -1
  81. package/dist/Modal/index.d.ts +4 -0
  82. package/dist/Modal/index.js +55 -66
  83. package/dist/Modal/index.js.map +1 -1
  84. package/dist/OverflowCount/index.js +10 -0
  85. package/dist/OverflowCount/index.js.map +1 -1
  86. package/dist/Pagination/index.js +1 -0
  87. package/dist/Pagination/index.js.map +1 -1
  88. package/dist/Popconfirm/index.js +9 -1
  89. package/dist/Popconfirm/index.js.map +1 -1
  90. package/dist/Popover/index.js +52 -1
  91. package/dist/Popover/index.js.map +1 -1
  92. package/dist/Progress/index.js +4 -0
  93. package/dist/Progress/index.js.map +1 -1
  94. package/dist/Radio/components/Group/index.d.ts +5 -1
  95. package/dist/Radio/components/Group/index.js +7 -2
  96. package/dist/Radio/components/Group/index.js.map +1 -1
  97. package/dist/Radio/components/Radio/index.js +26 -0
  98. package/dist/Radio/components/Radio/index.js.map +1 -1
  99. package/dist/Radio/interface/radio.d.ts +7 -0
  100. package/dist/Radio/interface/radioGroup.d.ts +2 -0
  101. package/dist/RenameInput/index.js +11 -0
  102. package/dist/RenameInput/index.js.map +1 -1
  103. package/dist/Select/BaseSelect.d.ts +3 -0
  104. package/dist/Select/BaseSelect.js +229 -32
  105. package/dist/Select/BaseSelect.js.map +1 -1
  106. package/dist/Select/SelectTrigger.d.ts +2 -0
  107. package/dist/Select/SelectTrigger.js +13 -5
  108. package/dist/Select/SelectTrigger.js.map +1 -1
  109. package/dist/Select/components/OptionCollection.d.ts +41 -0
  110. package/dist/Select/components/OptionCollection.js +124 -0
  111. package/dist/Select/components/OptionCollection.js.map +1 -0
  112. package/dist/Select/index.js +45 -3
  113. package/dist/Select/index.js.map +1 -1
  114. package/dist/Select/interface.d.ts +1 -1
  115. package/dist/Skeleton/index.js +1 -1
  116. package/dist/Skeleton/index.js.map +1 -1
  117. package/dist/Spin/index.d.ts +1 -1
  118. package/dist/Spin/index.js +22 -7
  119. package/dist/Spin/index.js.map +1 -1
  120. package/dist/Switch/index.d.ts +5 -0
  121. package/dist/Switch/index.js +15 -5
  122. package/dist/Switch/index.js.map +1 -1
  123. package/dist/Table/components/Header.js +0 -1
  124. package/dist/Table/components/Header.js.map +1 -1
  125. package/dist/Table/index.js +42 -27
  126. package/dist/Table/index.js.map +1 -1
  127. package/dist/Tabs/index.js +1 -0
  128. package/dist/Tabs/index.js.map +1 -1
  129. package/dist/Tag/index.js +20 -1
  130. package/dist/Tag/index.js.map +1 -1
  131. package/dist/Tooltip/index.js +34 -5
  132. package/dist/Tooltip/index.js.map +1 -1
  133. package/dist/Tour/index.js +13 -1
  134. package/dist/Tour/index.js.map +1 -1
  135. package/dist/Tree/Tree2.js +2 -0
  136. package/dist/Tree/Tree2.js.map +1 -1
  137. package/dist/_utils/dialogAccessibility.d.ts +17 -0
  138. package/dist/_utils/dialogAccessibility.js +110 -0
  139. package/dist/_utils/dialogAccessibility.js.map +1 -0
  140. package/dist/_utils/formControlSemanticOwner.d.ts +3 -0
  141. package/dist/_utils/formControlSemanticOwner.js +17 -0
  142. package/dist/_utils/formControlSemanticOwner.js.map +1 -0
  143. package/dist/_utils/overlayCoordinator.js +1 -11
  144. package/dist/_utils/overlayCoordinator.js.map +1 -1
  145. package/dist/aloudata-design.css +1 -1
  146. package/dist/governance/semantic.d.ts +1 -0
  147. package/dist/governance/semantic.js +2 -0
  148. package/dist/governance/semantic.json +1737 -0
  149. package/dist/theme/contract/baselineResolvedTokenValueManifest.d.ts +1 -1
  150. package/dist/theme/contract/darkResolvedTokenValueManifest.d.ts +1 -1
  151. package/dist/theme/contract/tokenOutputContract.js +1 -0
  152. package/dist/theme/contract/tokenOutputContract.js.map +1 -1
  153. package/dist/theme/generator/acceptedColorValues.d.ts +2 -1
  154. package/dist/theme/generator/baselineTokenValueDelivery.d.ts +9 -1
  155. package/dist/theme/generator/minimalAcceptedColorValues.d.ts +2 -2
  156. package/dist/theme/generator/neutralSourceResolver.d.ts +28 -0
  157. package/dist/theme/generator/neutralSourceResolver.js +2 -0
  158. package/dist/theme/generator/neutralSourceValues.d.ts +28 -0
  159. package/dist/theme/generator/neutralSourceValues.js +2 -0
  160. package/dist/theme/governance/semanticGovernanceContract.d.ts +91 -0
  161. package/dist/theme/governance/semanticGovernanceContract.js +342 -0
  162. package/dist/theme/governance/semanticGovernanceContract.js.map +1 -0
  163. package/dist/theme/index.d.ts +2 -0
  164. package/dist/theme/index.js +1 -0
  165. package/dist/theme/neutralSourceContract.d.ts +3 -0
  166. package/dist/theme/neutralSourceContract.js +11 -0
  167. package/dist/theme/neutralSourceContract.js.map +1 -0
  168. package/dist/theme/runtime/colorValueMode/generated/darkBaselineDeclarations.d.ts +1 -1
  169. package/dist/theme/runtime/colorValueMode/generated/darkBaselineDeclarations.js +46 -45
  170. package/dist/theme/runtime/colorValueMode/generated/darkBaselineDeclarations.js.map +1 -1
  171. package/dist/theme/runtime/colorValueMode/generated/slateDarkDeclarations.d.ts +3 -0
  172. package/dist/theme/runtime/colorValueMode/generated/slateDarkDeclarations.js +2 -0
  173. package/dist/theme/runtime/colorValueMode/generated/slateLightDeclarations.d.ts +3 -0
  174. package/dist/theme/runtime/colorValueMode/generated/slateLightDeclarations.js +2 -0
  175. package/dist/theme/runtime/colorValueMode/generated/stoneDarkDeclarations.d.ts +3 -0
  176. package/dist/theme/runtime/colorValueMode/generated/stoneDarkDeclarations.js +2 -0
  177. package/dist/theme/runtime/colorValueMode/generated/stoneLightDeclarations.d.ts +3 -0
  178. package/dist/theme/runtime/colorValueMode/generated/stoneLightDeclarations.js +2 -0
  179. package/dist/theme/runtime/colorValueMode/generated/v3BaselineDeclarations.d.ts +1 -1
  180. package/dist/theme/runtime/colorValueMode/generated/v3BaselineDeclarations.js +42 -41
  181. package/dist/theme/runtime/colorValueMode/generated/v3BaselineDeclarations.js.map +1 -1
  182. package/dist/theme/runtime/colorValueMode/index.js +2 -12
  183. package/dist/theme/runtime/colorValueMode/index.js.map +1 -1
  184. package/dist/theme/runtime/colorValueMode/legacyNeutralCompatibility.d.ts +2 -0
  185. package/dist/theme/runtime/colorValueMode/legacyNeutralCompatibility.js +48 -0
  186. package/dist/theme/runtime/colorValueMode/legacyNeutralCompatibility.js.map +1 -0
  187. package/dist/theme/runtime/colorValueMode/registry.d.ts +1 -1
  188. package/dist/theme/runtime/colorValueMode/registry.js +2 -1
  189. package/dist/theme/runtime/colorValueMode/registry.js.map +1 -1
  190. package/dist/theme/runtime/initAldTheme.js +1 -3
  191. package/dist/theme/runtime/initAldTheme.js.map +1 -1
  192. package/dist/theme/runtime/neutralSource/index.d.ts +6 -0
  193. package/dist/theme/runtime/neutralSource/index.js +11 -0
  194. package/dist/theme/runtime/neutralSource/index.js.map +1 -0
  195. package/dist/theme/runtime/neutralSource.d.ts +2 -0
  196. package/package.json +12 -2
@@ -53,24 +53,51 @@ function usePortalContainer(getPopupContainer, getTooltipContainer) {
53
53
  function ClickTooltip({ children, title, open, onOpenChange, placement = "top", overlayClassName, zIndex, container, triggerRef }) {
54
54
  const side = sideMap[placement] || "top";
55
55
  const align = alignMap[placement] || "center";
56
+ const idBase = React.useId().replace(/:/g, "");
57
+ const contentId = `ald-popover-tooltip-${idBase}`;
58
+ const titleId = `ald-popover-tooltip-title-${idBase}`;
59
+ const contentRef = React.useRef(null);
60
+ const trigger = React.isValidElement(children) ? React.cloneElement(children, {
61
+ ref: triggerRef,
62
+ "aria-controls": contentId,
63
+ "aria-haspopup": false
64
+ }) : /* @__PURE__ */ jsx("span", {
65
+ ref: triggerRef,
66
+ "aria-controls": contentId,
67
+ "aria-haspopup": false,
68
+ children
69
+ });
56
70
  return /* @__PURE__ */ jsxs(PopoverPrimitive.Root, {
57
71
  open,
58
72
  onOpenChange,
73
+ modal: false,
59
74
  children: [/* @__PURE__ */ jsx(PopoverPrimitive.Trigger, {
60
75
  asChild: true,
61
- children: React.isValidElement(children) ? React.cloneElement(children, { ref: triggerRef }) : /* @__PURE__ */ jsx("span", {
62
- ref: triggerRef,
63
- children
64
- })
76
+ children: trigger
65
77
  }), /* @__PURE__ */ jsx(PopoverPrimitive.Portal, {
66
78
  container,
67
79
  children: /* @__PURE__ */ jsxs(PopoverPrimitive.Content, {
80
+ id: contentId,
81
+ ref: contentRef,
82
+ role: "region",
83
+ "aria-labelledby": title ? titleId : void 0,
68
84
  side,
69
85
  align,
70
86
  sideOffset: 4,
71
87
  className: cn(contentClasses, overlayClassName),
72
88
  style: { zIndex },
73
- children: [title, /* @__PURE__ */ jsx(PopoverPrimitive.Arrow, { className: "tw-fill-[var(--background-inverted)]" })]
89
+ onOpenAutoFocus: (event) => {
90
+ event.preventDefault();
91
+ contentRef.current?.querySelector("a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])")?.focus();
92
+ },
93
+ onCloseAutoFocus: (event) => {
94
+ event.preventDefault();
95
+ if (triggerRef.current?.isConnected) triggerRef.current.focus();
96
+ },
97
+ children: [title && /* @__PURE__ */ jsx("div", {
98
+ id: titleId,
99
+ children: title
100
+ }), /* @__PURE__ */ jsx(PopoverPrimitive.Arrow, { className: "tw-fill-[var(--background-inverted)]" })]
74
101
  })
75
102
  })]
76
103
  });
@@ -79,6 +106,7 @@ function Tooltip(props) {
79
106
  const { children, title, content, open, onOpenChange, placement = "top", mouseEnterDelay = 0, mouseLeaveDelay = 0, overlayClassName, trigger, getPopupContainer, getTooltipContainer, zIndex } = props;
80
107
  const { triggerRef, container } = usePortalContainer(getPopupContainer, getTooltipContainer);
81
108
  const resolvedZIndex = useFloatingPopupZIndex(zIndex);
109
+ const tooltipIdBase = React.useId().replace(/:/g, "");
82
110
  const mergedTitle = title ?? content;
83
111
  if (!mergedTitle && mergedTitle !== 0) return /* @__PURE__ */ jsx(Fragment, { children });
84
112
  if (isTriggerDisabled(trigger)) return /* @__PURE__ */ jsx(Fragment, { children });
@@ -110,6 +138,7 @@ function Tooltip(props) {
110
138
  }), /* @__PURE__ */ jsx(TooltipPrimitive.Portal, {
111
139
  container,
112
140
  children: /* @__PURE__ */ jsxs(TooltipPrimitive.Content, {
141
+ id: `ald-tooltip-${tooltipIdBase}`,
113
142
  side,
114
143
  align,
115
144
  sideOffset: 4,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/Tooltip/index.tsx"],"sourcesContent":["import * as PopoverPrimitive from '@radix-ui/react-popover';\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip';\nimport React from 'react';\nimport { useFloatingPopupZIndex } from '../_utils/floatingLayer';\nimport { cn } from '../lib/utils';\n\nexport type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';\n\nexport interface ITooltipProps {\n title?: React.ReactNode;\n /** Alias for title, for Popover-style usage */\n content?: React.ReactNode;\n destroyTooltipOnHide?: boolean;\n getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;\n mouseEnterDelay?: number;\n mouseLeaveDelay?: number;\n placement?:\n | 'top'\n | 'left'\n | 'right'\n | 'bottom'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'leftTop'\n | 'leftBottom'\n | 'rightTop'\n | 'rightBottom';\n trigger?: ActionType | ActionType[];\n zIndex?: number;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n overlayClassName?: string;\n /** Custom class for the root element */\n rootClassName?: string;\n getTooltipContainer?: (node: HTMLElement) => HTMLElement;\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst sideMap: Record<string, 'top' | 'bottom' | 'left' | 'right'> = {\n top: 'top',\n bottom: 'bottom',\n left: 'left',\n right: 'right',\n topLeft: 'top',\n topRight: 'top',\n bottomLeft: 'bottom',\n bottomRight: 'bottom',\n leftTop: 'left',\n leftBottom: 'left',\n rightTop: 'right',\n rightBottom: 'right',\n};\n\nconst alignMap: Record<string, 'start' | 'end' | 'center'> = {\n topLeft: 'start',\n topRight: 'end',\n bottomLeft: 'start',\n bottomRight: 'end',\n leftTop: 'start',\n leftBottom: 'end',\n rightTop: 'start',\n rightBottom: 'end',\n};\n\nfunction isClickTrigger(trigger?: ActionType | ActionType[]): boolean {\n if (!trigger) return false;\n if (Array.isArray(trigger)) return trigger.includes('click');\n return trigger === 'click';\n}\n\nfunction isTriggerDisabled(trigger?: ActionType | ActionType[]): boolean {\n return Array.isArray(trigger) && trigger.length === 0;\n}\n\nconst contentClasses =\n 'ald-tooltip-overlay tw-z-50 tw-min-h-[28px] tw-rounded-r-50 tw-px-2 tw-py-1.5 tw-text-xs tw-leading-4 tw-bg-[var(--background-inverted)] tw-text-[var(--content-inverted-primary)] tw-animate-in tw-fade-in-0 tw-zoom-in-95';\n\nfunction usePortalContainer(\n getPopupContainer?: (node: HTMLElement) => HTMLElement,\n getTooltipContainer?: (node: HTMLElement) => HTMLElement,\n) {\n const triggerRef = React.useRef<HTMLElement | null>(null);\n const [container, setContainer] = React.useState<HTMLElement | undefined>(\n undefined,\n );\n\n React.useEffect(() => {\n const getter = getPopupContainer || getTooltipContainer;\n if (getter && triggerRef.current) {\n setContainer(getter(triggerRef.current));\n }\n }, [getPopupContainer, getTooltipContainer]);\n\n return { triggerRef, container };\n}\n\nfunction ClickTooltip({\n children,\n title,\n open,\n onOpenChange,\n placement = 'top',\n overlayClassName,\n zIndex,\n container,\n triggerRef,\n}: Pick<\n ITooltipProps,\n | 'children'\n | 'title'\n | 'open'\n | 'onOpenChange'\n | 'placement'\n | 'overlayClassName'\n | 'zIndex'\n> & {\n container?: HTMLElement;\n triggerRef: React.RefObject<HTMLElement | null>;\n}) {\n const side = sideMap[placement] || 'top';\n const align = alignMap[placement] || 'center';\n\n return (\n <PopoverPrimitive.Root open={open} onOpenChange={onOpenChange}>\n <PopoverPrimitive.Trigger asChild>\n {React.isValidElement(children) ? (\n React.cloneElement(children as React.ReactElement, {\n ref: triggerRef,\n })\n ) : (\n <span ref={triggerRef as React.RefObject<HTMLSpanElement>}>\n {children}\n </span>\n )}\n </PopoverPrimitive.Trigger>\n <PopoverPrimitive.Portal container={container}>\n <PopoverPrimitive.Content\n side={side}\n align={align}\n sideOffset={4}\n className={cn(contentClasses, overlayClassName)}\n style={{ zIndex }}\n >\n {title}\n <PopoverPrimitive.Arrow className=\"tw-fill-[var(--background-inverted)]\" />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n );\n}\n\nexport default function Tooltip(props: ITooltipProps) {\n const {\n children,\n title,\n content,\n open,\n onOpenChange,\n placement = 'top',\n mouseEnterDelay = 0,\n mouseLeaveDelay = 0,\n overlayClassName,\n trigger,\n getPopupContainer,\n getTooltipContainer,\n zIndex,\n } = props;\n\n const { triggerRef, container } = usePortalContainer(\n getPopupContainer,\n getTooltipContainer,\n );\n const resolvedZIndex = useFloatingPopupZIndex(zIndex);\n const mergedTitle = title ?? content;\n\n if (!mergedTitle && mergedTitle !== 0) {\n return <>{children}</>;\n }\n\n if (isTriggerDisabled(trigger)) {\n return <>{children}</>;\n }\n\n if (isClickTrigger(trigger)) {\n return (\n <ClickTooltip\n title={mergedTitle}\n open={open}\n onOpenChange={onOpenChange}\n placement={placement}\n overlayClassName={overlayClassName}\n zIndex={resolvedZIndex}\n container={container}\n triggerRef={triggerRef}\n >\n {children}\n </ClickTooltip>\n );\n }\n\n const side = sideMap[placement] || 'top';\n const align = alignMap[placement] || 'center';\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={mouseEnterDelay * 1000}\n skipDelayDuration={mouseLeaveDelay * 1000}\n >\n <TooltipPrimitive.Root open={open} onOpenChange={onOpenChange}>\n <TooltipPrimitive.Trigger asChild>\n {React.isValidElement(children) ? (\n React.cloneElement(children as React.ReactElement, {\n ref: triggerRef,\n })\n ) : (\n <span ref={triggerRef as React.RefObject<HTMLSpanElement>}>\n {children}\n </span>\n )}\n </TooltipPrimitive.Trigger>\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n side={side}\n align={align}\n sideOffset={4}\n className={cn(contentClasses, overlayClassName)}\n style={{ zIndex: resolvedZIndex }}\n >\n {mergedTitle}\n <TooltipPrimitive.Arrow className=\"tw-fill-[var(--background-inverted)]\" />\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n </TooltipPrimitive.Provider>\n );\n}\n"],"mappings":";;;;;;;AA0CA,IAAM,UAA+D;CACnE,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACP,SAAS;CACT,UAAU;CACV,YAAY;CACZ,aAAa;CACb,SAAS;CACT,YAAY;CACZ,UAAU;CACV,aAAa;CACd;AAED,IAAM,WAAuD;CAC3D,SAAS;CACT,UAAU;CACV,YAAY;CACZ,aAAa;CACb,SAAS;CACT,YAAY;CACZ,UAAU;CACV,aAAa;CACd;AAED,SAAS,eAAe,SAA8C;AACpE,KAAI,CAAC,QAAS,QAAO;AACrB,KAAI,MAAM,QAAQ,QAAQ,CAAE,QAAO,QAAQ,SAAS,QAAQ;AAC5D,QAAO,YAAY;;AAGrB,SAAS,kBAAkB,SAA8C;AACvE,QAAO,MAAM,QAAQ,QAAQ,IAAI,QAAQ,WAAW;;AAGtD,IAAM,iBACJ;AAEF,SAAS,mBACP,mBACA,qBACA;CACA,MAAM,aAAa,MAAM,OAA2B,KAAK;CACzD,MAAM,CAAC,WAAW,gBAAgB,MAAM,SACtC,OACD;AAED,OAAM,gBAAgB;EACpB,MAAM,SAAS,qBAAqB;AACpC,MAAI,UAAU,WAAW,QACvB,cAAa,OAAO,WAAW,QAAQ,CAAC;IAEzC,CAAC,mBAAmB,oBAAoB,CAAC;AAE5C,QAAO;EAAE;EAAY;EAAW;;AAGlC,SAAS,aAA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ACjC,mBAAmB,kBAAkB;YAErC,qBAAC,iBAAiB,MAAlB;GAA6B;GAAoB;aAAjD,CACE,oBAAC,iBAAiB,SAAlB;IAA0B,SAAA;cACvB,MAAM,eAAe,SAAS,GAC7B,MAAM,aAAa,UAAgC,EACjD,KAAK,YACN,CAAC,GAEF,oBAAC,QAAD;KAAM,KAAK;KACR;KACI,CAAA;IAEgB,CAAA,EAC3B,oBAAC,iBAAiB,QAAlB;IAAoC;cAClC,qBAAC,iBAAiB,SAAlB;KACQ;KACC;KACP,YAAY;KACZ,WAAW,GAAG,gBAAgB,iBAAiB;KAC/C,OAAO,EAAE,QAAQ,gBAAgB;eALnC,CAOG,aACD,oBAAC,iBAAiB,OAAlB,EAAwB,WAAU,wCAAyC,CAAA,CAClD;;IACH,CAAA,CACJ;;EACE,CAAA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/Tooltip/index.tsx"],"sourcesContent":["import * as PopoverPrimitive from '@radix-ui/react-popover';\nimport * as TooltipPrimitive from '@radix-ui/react-tooltip';\nimport React from 'react';\nimport { useFloatingPopupZIndex } from '../_utils/floatingLayer';\nimport { cn } from '../lib/utils';\n\nexport type ActionType = 'hover' | 'focus' | 'click' | 'contextMenu';\n\nexport interface ITooltipProps {\n title?: React.ReactNode;\n /** Alias for title, for Popover-style usage */\n content?: React.ReactNode;\n destroyTooltipOnHide?: boolean;\n getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;\n mouseEnterDelay?: number;\n mouseLeaveDelay?: number;\n placement?:\n | 'top'\n | 'left'\n | 'right'\n | 'bottom'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight'\n | 'leftTop'\n | 'leftBottom'\n | 'rightTop'\n | 'rightBottom';\n trigger?: ActionType | ActionType[];\n zIndex?: number;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n overlayClassName?: string;\n /** Custom class for the root element */\n rootClassName?: string;\n getTooltipContainer?: (node: HTMLElement) => HTMLElement;\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst sideMap: Record<string, 'top' | 'bottom' | 'left' | 'right'> = {\n top: 'top',\n bottom: 'bottom',\n left: 'left',\n right: 'right',\n topLeft: 'top',\n topRight: 'top',\n bottomLeft: 'bottom',\n bottomRight: 'bottom',\n leftTop: 'left',\n leftBottom: 'left',\n rightTop: 'right',\n rightBottom: 'right',\n};\n\nconst alignMap: Record<string, 'start' | 'end' | 'center'> = {\n topLeft: 'start',\n topRight: 'end',\n bottomLeft: 'start',\n bottomRight: 'end',\n leftTop: 'start',\n leftBottom: 'end',\n rightTop: 'start',\n rightBottom: 'end',\n};\n\nfunction isClickTrigger(trigger?: ActionType | ActionType[]): boolean {\n if (!trigger) return false;\n if (Array.isArray(trigger)) return trigger.includes('click');\n return trigger === 'click';\n}\n\nfunction isTriggerDisabled(trigger?: ActionType | ActionType[]): boolean {\n return Array.isArray(trigger) && trigger.length === 0;\n}\n\nconst contentClasses =\n 'ald-tooltip-overlay tw-z-50 tw-min-h-[28px] tw-rounded-r-50 tw-px-2 tw-py-1.5 tw-text-xs tw-leading-4 tw-bg-[var(--background-inverted)] tw-text-[var(--content-inverted-primary)] tw-animate-in tw-fade-in-0 tw-zoom-in-95';\n\nfunction usePortalContainer(\n getPopupContainer?: (node: HTMLElement) => HTMLElement,\n getTooltipContainer?: (node: HTMLElement) => HTMLElement,\n) {\n const triggerRef = React.useRef<HTMLElement | null>(null);\n const [container, setContainer] = React.useState<HTMLElement | undefined>(\n undefined,\n );\n\n React.useEffect(() => {\n const getter = getPopupContainer || getTooltipContainer;\n if (getter && triggerRef.current) {\n setContainer(getter(triggerRef.current));\n }\n }, [getPopupContainer, getTooltipContainer]);\n\n return { triggerRef, container };\n}\n\nfunction ClickTooltip({\n children,\n title,\n open,\n onOpenChange,\n placement = 'top',\n overlayClassName,\n zIndex,\n container,\n triggerRef,\n}: Pick<\n ITooltipProps,\n | 'children'\n | 'title'\n | 'open'\n | 'onOpenChange'\n | 'placement'\n | 'overlayClassName'\n | 'zIndex'\n> & {\n container?: HTMLElement;\n triggerRef: React.RefObject<HTMLElement | null>;\n}) {\n const side = sideMap[placement] || 'top';\n const align = alignMap[placement] || 'center';\n const idBase = React.useId().replace(/:/g, '');\n const contentId = `ald-popover-tooltip-${idBase}`;\n const titleId = `ald-popover-tooltip-title-${idBase}`;\n const contentRef = React.useRef<HTMLDivElement>(null);\n\n const trigger = React.isValidElement(children) ? (\n React.cloneElement(children as React.ReactElement, {\n ref: triggerRef,\n 'aria-controls': contentId,\n 'aria-haspopup': false,\n })\n ) : (\n <span\n ref={triggerRef as React.RefObject<HTMLSpanElement>}\n aria-controls={contentId}\n aria-haspopup={false}\n >\n {children}\n </span>\n );\n\n return (\n <PopoverPrimitive.Root\n open={open}\n onOpenChange={onOpenChange}\n modal={false}\n >\n <PopoverPrimitive.Trigger asChild>{trigger}</PopoverPrimitive.Trigger>\n <PopoverPrimitive.Portal container={container}>\n <PopoverPrimitive.Content\n id={contentId}\n ref={contentRef}\n role=\"region\"\n aria-labelledby={title ? titleId : undefined}\n side={side}\n align={align}\n sideOffset={4}\n className={cn(contentClasses, overlayClassName)}\n style={{ zIndex }}\n onOpenAutoFocus={(event) => {\n event.preventDefault();\n contentRef.current\n ?.querySelector<HTMLElement>(\n 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex=\"-1\"])',\n )\n ?.focus();\n }}\n onCloseAutoFocus={(event) => {\n event.preventDefault();\n if (triggerRef.current?.isConnected) {\n triggerRef.current.focus();\n }\n }}\n >\n {title && <div id={titleId}>{title}</div>}\n <PopoverPrimitive.Arrow className=\"tw-fill-[var(--background-inverted)]\" />\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </PopoverPrimitive.Root>\n );\n}\n\nexport default function Tooltip(props: ITooltipProps) {\n const {\n children,\n title,\n content,\n open,\n onOpenChange,\n placement = 'top',\n mouseEnterDelay = 0,\n mouseLeaveDelay = 0,\n overlayClassName,\n trigger,\n getPopupContainer,\n getTooltipContainer,\n zIndex,\n } = props;\n\n const { triggerRef, container } = usePortalContainer(\n getPopupContainer,\n getTooltipContainer,\n );\n const resolvedZIndex = useFloatingPopupZIndex(zIndex);\n const tooltipIdBase = React.useId().replace(/:/g, '');\n const mergedTitle = title ?? content;\n\n if (!mergedTitle && mergedTitle !== 0) {\n return <>{children}</>;\n }\n\n if (isTriggerDisabled(trigger)) {\n return <>{children}</>;\n }\n\n if (isClickTrigger(trigger)) {\n return (\n <ClickTooltip\n title={mergedTitle}\n open={open}\n onOpenChange={onOpenChange}\n placement={placement}\n overlayClassName={overlayClassName}\n zIndex={resolvedZIndex}\n container={container}\n triggerRef={triggerRef}\n >\n {children}\n </ClickTooltip>\n );\n }\n\n const side = sideMap[placement] || 'top';\n const align = alignMap[placement] || 'center';\n\n return (\n <TooltipPrimitive.Provider\n delayDuration={mouseEnterDelay * 1000}\n skipDelayDuration={mouseLeaveDelay * 1000}\n >\n <TooltipPrimitive.Root open={open} onOpenChange={onOpenChange}>\n <TooltipPrimitive.Trigger asChild>\n {React.isValidElement(children) ? (\n React.cloneElement(children as React.ReactElement, {\n ref: triggerRef,\n })\n ) : (\n <span ref={triggerRef as React.RefObject<HTMLSpanElement>}>\n {children}\n </span>\n )}\n </TooltipPrimitive.Trigger>\n <TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content\n id={`ald-tooltip-${tooltipIdBase}`}\n side={side}\n align={align}\n sideOffset={4}\n className={cn(contentClasses, overlayClassName)}\n style={{ zIndex: resolvedZIndex }}\n >\n {mergedTitle}\n <TooltipPrimitive.Arrow className=\"tw-fill-[var(--background-inverted)]\" />\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>\n </TooltipPrimitive.Root>\n </TooltipPrimitive.Provider>\n );\n}\n"],"mappings":";;;;;;;AA0CA,IAAM,UAA+D;CACnE,KAAK;CACL,QAAQ;CACR,MAAM;CACN,OAAO;CACP,SAAS;CACT,UAAU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MAAM,QAAQ,SAAS,cAAc;AAErC,QACE,oBAAC,iBAAiB,UAAlB;EACE,eAAe,kBAAkB;EACjC,mBAAmB,kBAAkB;YAErC,qBAAC,iBAAiB,MAAlB;GAA6B;GAAoB;aAAjD,CACE,oBAAC,iBAAiB,SAAlB;IAA0B,SAAA;cACvB,MAAM,eAAe,SAAS,GAC7B,MAAM,aAAa,UAAgC,EACjD,KAAK,YACN,CAAC,GAEF,oBAAC,QAAD;KAAM,KAAK;KACR;KACI,CAAA;IAEgB,CAAA,EAC3B,oBAAC,iBAAiB,QAAlB;IAAoC;cAClC,qBAAC,iBAAiB,SAAlB;KACE,IAAI,eAAe;KACb;KACC;KACP,YAAY;KACZ,WAAW,GAAG,gBAAgB,iBAAiB;KAC/C,OAAO,EAAE,QAAQ,gBAAgB;eANnC,CAQG,aACD,oBAAC,iBAAiB,OAAlB,EAAwB,WAAU,wCAAyC,CAAA,CAClD;;IACH,CAAA,CACJ;;EACE,CAAA"}
@@ -15,6 +15,8 @@ function Tour(props) {
15
15
  if (!open || steps.length === 0) return null;
16
16
  const step = steps[current];
17
17
  const isLast = current === steps.length - 1;
18
+ const titleId = `ald-tour-title-${current}`;
19
+ const descriptionId = `ald-tour-description-${current}`;
18
20
  const goNext = () => {
19
21
  if (isLast) {
20
22
  onFinish?.();
@@ -35,11 +37,19 @@ function Tour(props) {
35
37
  style: { zIndex: maskZIndex },
36
38
  onClick: onClose
37
39
  }), /* @__PURE__ */ jsx("div", {
38
- className: cn("ald-tour tw-fixed tw-z-[1001] tw-max-w-sm tw-rounded-r-100 tw-bg-[var(--background-default)] tw-p-6 tw-shadow-xl", "tw-left-1/2 tw-top-1/2 tw--translate-x-1/2 tw--translate-y-1/2", className),
40
+ className: cn("ald-tour tw-fixed tw-z-[1001] tw-max-w-sm tw-rounded-r-100 tw-bg-[var(--background-default)] tw-p-6 tw-shadow-[var(--elevation-bottom-bottom-xl)]", "tw-left-1/2 tw-top-1/2 tw--translate-x-1/2 tw--translate-y-1/2", className),
39
41
  style: {
40
42
  zIndex: contentZIndex,
41
43
  ...step?.style
42
44
  },
45
+ role: "dialog",
46
+ "aria-modal": "false",
47
+ "aria-labelledby": step?.title ? titleId : void 0,
48
+ "aria-describedby": step?.description ? descriptionId : void 0,
49
+ tabIndex: -1,
50
+ onKeyDown: (event) => {
51
+ if (event.key === "Escape") onClose?.();
52
+ },
43
53
  children: /* @__PURE__ */ jsxs(FloatingLayerProvider, {
44
54
  value: nextLevel,
45
55
  children: [
@@ -48,10 +58,12 @@ function Tour(props) {
48
58
  children: step.cover
49
59
  }),
50
60
  step?.title && /* @__PURE__ */ jsx("div", {
61
+ id: titleId,
51
62
  className: "ald-tour-title tw-mb-2 tw-text-base tw-font-semibold tw-text-[var(--content-primary)]",
52
63
  children: step.title
53
64
  }),
54
65
  step?.description && /* @__PURE__ */ jsx("div", {
66
+ id: descriptionId,
55
67
  className: "ald-tour-description tw-mb-4 tw-text-sm tw-text-[var(--content-secondary)]",
56
68
  children: step.description
57
69
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/Tour/index.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport Button from '../Button';\nimport {\n FloatingLayerProvider,\n useFloatingLayer,\n} from '../_utils/floatingLayer';\nimport { cn } from '../lib/utils';\n\nexport interface TourStepProps {\n title?: React.ReactNode;\n description?: React.ReactNode;\n cover?: React.ReactNode;\n target?: (() => HTMLElement | null) | null;\n placement?:\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight';\n mask?: boolean;\n className?: string;\n style?: React.CSSProperties;\n nextButtonProps?: { children?: React.ReactNode };\n prevButtonProps?: { children?: React.ReactNode };\n}\n\nexport interface TourProps {\n open?: boolean;\n onClose?: () => void;\n steps?: TourStepProps[];\n current?: number;\n onChange?: (current: number) => void;\n mask?: boolean;\n type?: 'default' | 'primary';\n className?: string;\n onFinish?: () => void;\n}\n\nfunction Tour(props: TourProps) {\n const {\n open = false,\n onClose,\n steps = [],\n current: controlledCurrent,\n onChange,\n mask = true,\n className,\n onFinish,\n } = props;\n\n const [innerCurrent, setInnerCurrent] = useState(0);\n const current = controlledCurrent ?? innerCurrent;\n\n useEffect(() => {\n if (!open) setInnerCurrent(0);\n }, [open]);\n\n const { maskZIndex, contentZIndex, nextLevel } = useFloatingLayer();\n\n if (!open || steps.length === 0) return null;\n\n const step = steps[current];\n const isLast = current === steps.length - 1;\n\n const goNext = () => {\n if (isLast) {\n onFinish?.();\n onClose?.();\n } else {\n const next = current + 1;\n if (controlledCurrent === undefined) setInnerCurrent(next);\n onChange?.(next);\n }\n };\n\n const goPrev = () => {\n const prev = Math.max(0, current - 1);\n if (controlledCurrent === undefined) setInnerCurrent(prev);\n onChange?.(prev);\n };\n\n return (\n <>\n {mask && (\n <div\n className=\"ald-tour-mask tw-fixed tw-inset-0 tw-z-[1000] tw-bg-[var(--background-inverted)] tw-opacity-45\"\n style={{ zIndex: maskZIndex }}\n onClick={onClose}\n />\n )}\n <div\n className={cn(\n 'ald-tour tw-fixed tw-z-[1001] tw-max-w-sm tw-rounded-r-100 tw-bg-[var(--background-default)] tw-p-6 tw-shadow-xl',\n 'tw-left-1/2 tw-top-1/2 tw--translate-x-1/2 tw--translate-y-1/2',\n className,\n )}\n style={{ zIndex: contentZIndex, ...step?.style }}\n >\n <FloatingLayerProvider value={nextLevel}>\n {step?.cover && (\n <div className=\"ald-tour-cover tw-mb-4\">{step.cover}</div>\n )}\n {step?.title && (\n <div className=\"ald-tour-title tw-mb-2 tw-text-base tw-font-semibold tw-text-[var(--content-primary)]\">\n {step.title}\n </div>\n )}\n {step?.description && (\n <div className=\"ald-tour-description tw-mb-4 tw-text-sm tw-text-[var(--content-secondary)]\">\n {step.description}\n </div>\n )}\n <div className=\"ald-tour-footer tw-flex tw-items-center tw-justify-between\">\n <span className=\"tw-text-xs tw-text-[var(--content-tertiary)]\">\n {current + 1}/{steps.length}\n </span>\n <div className=\"tw-flex tw-gap-2\">\n {current > 0 && (\n <Button type=\"secondary\" size=\"small\" onClick={goPrev}>\n {step?.prevButtonProps?.children || 'Prev'}\n </Button>\n )}\n <Button type=\"primary\" size=\"small\" onClick={goNext}>\n {step?.nextButtonProps?.children ||\n (isLast ? 'Finish' : 'Next')}\n </Button>\n </div>\n </div>\n </FloatingLayerProvider>\n </div>\n </>\n );\n}\n\nexport default Tour;\n"],"mappings":";;;;;;AAyCA,SAAS,KAAK,OAAkB;CAC9B,MAAM,EACJ,OAAO,OACP,SACA,QAAQ,EAAE,EACV,SAAS,mBACT,UACA,OAAO,MACP,WACA,aACE;CAEJ,MAAM,CAAC,cAAc,mBAAmB,SAAS,EAAE;CACnD,MAAM,UAAU,qBAAqB;AAErC,iBAAgB;AACd,MAAI,CAAC,KAAM,iBAAgB,EAAE;IAC5B,CAAC,KAAK,CAAC;CAEV,MAAM,EAAE,YAAY,eAAe,cAAc,kBAAkB;AAEnE,KAAI,CAAC,QAAQ,MAAM,WAAW,EAAG,QAAO;CAExC,MAAM,OAAO,MAAM;CACnB,MAAM,SAAS,YAAY,MAAM,SAAS;CAE1C,MAAM,eAAe;AACnB,MAAI,QAAQ;AACV,eAAY;AACZ,cAAW;SACN;GACL,MAAM,OAAO,UAAU;AACvB,OAAI,sBAAsB,OAAW,iBAAgB,KAAK;AAC1D,cAAW,KAAK;;;CAIpB,MAAM,eAAe;EACnB,MAAM,OAAO,KAAK,IAAI,GAAG,UAAU,EAAE;AACrC,MAAI,sBAAsB,OAAW,iBAAgB,KAAK;AAC1D,aAAW,KAAK;;AAGlB,QACE,qBAAA,UAAA,EAAA,UAAA,CACG,QACC,oBAAC,OAAD;EACE,WAAU;EACV,OAAO,EAAE,QAAQ,YAAY;EAC7B,SAAS;EACT,CAAA,EAEJ,oBAAC,OAAD;EACE,WAAW,GACT,oHACA,kEACA,UACD;EACD,OAAO;GAAE,QAAQ;GAAe,GAAG,MAAM;GAAO;YAEhD,qBAAC,uBAAD;GAAuB,OAAO;aAA9B;IACG,MAAM,SACL,oBAAC,OAAD;KAAK,WAAU;eAA0B,KAAK;KAAY,CAAA;IAE3D,MAAM,SACL,oBAAC,OAAD;KAAK,WAAU;eACZ,KAAK;KACF,CAAA;IAEP,MAAM,eACL,oBAAC,OAAD;KAAK,WAAU;eACZ,KAAK;KACF,CAAA;IAER,qBAAC,OAAD;KAAK,WAAU;eAAf,CACE,qBAAC,QAAD;MAAM,WAAU;gBAAhB;OACG,UAAU;OAAE;OAAE,MAAM;OAChB;SACP,qBAAC,OAAD;MAAK,WAAU;gBAAf,CACG,UAAU,KACT,oBAAC,gBAAD;OAAQ,MAAK;OAAY,MAAK;OAAQ,SAAS;iBAC5C,MAAM,iBAAiB,YAAY;OAC7B,CAAA,EAEX,oBAAC,gBAAD;OAAQ,MAAK;OAAU,MAAK;OAAQ,SAAS;iBAC1C,MAAM,iBAAiB,aACrB,SAAS,WAAW;OAChB,CAAA,CACL;QACF;;IACgB;;EACpB,CAAA,CACL,EAAA,CAAA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/Tour/index.tsx"],"sourcesContent":["import React, { useEffect, useState } from 'react';\nimport Button from '../Button';\nimport {\n FloatingLayerProvider,\n useFloatingLayer,\n} from '../_utils/floatingLayer';\nimport { cn } from '../lib/utils';\n\nexport interface TourStepProps {\n title?: React.ReactNode;\n description?: React.ReactNode;\n cover?: React.ReactNode;\n target?: (() => HTMLElement | null) | null;\n placement?:\n | 'top'\n | 'bottom'\n | 'left'\n | 'right'\n | 'topLeft'\n | 'topRight'\n | 'bottomLeft'\n | 'bottomRight';\n mask?: boolean;\n className?: string;\n style?: React.CSSProperties;\n nextButtonProps?: { children?: React.ReactNode };\n prevButtonProps?: { children?: React.ReactNode };\n}\n\nexport interface TourProps {\n open?: boolean;\n onClose?: () => void;\n steps?: TourStepProps[];\n current?: number;\n onChange?: (current: number) => void;\n mask?: boolean;\n type?: 'default' | 'primary';\n className?: string;\n onFinish?: () => void;\n}\n\nfunction Tour(props: TourProps) {\n const {\n open = false,\n onClose,\n steps = [],\n current: controlledCurrent,\n onChange,\n mask = true,\n className,\n onFinish,\n } = props;\n\n const [innerCurrent, setInnerCurrent] = useState(0);\n const current = controlledCurrent ?? innerCurrent;\n\n useEffect(() => {\n if (!open) setInnerCurrent(0);\n }, [open]);\n\n const { maskZIndex, contentZIndex, nextLevel } = useFloatingLayer();\n\n if (!open || steps.length === 0) return null;\n\n const step = steps[current];\n const isLast = current === steps.length - 1;\n const titleId = `ald-tour-title-${current}`;\n const descriptionId = `ald-tour-description-${current}`;\n\n const goNext = () => {\n if (isLast) {\n onFinish?.();\n onClose?.();\n } else {\n const next = current + 1;\n if (controlledCurrent === undefined) setInnerCurrent(next);\n onChange?.(next);\n }\n };\n\n const goPrev = () => {\n const prev = Math.max(0, current - 1);\n if (controlledCurrent === undefined) setInnerCurrent(prev);\n onChange?.(prev);\n };\n\n return (\n <>\n {mask && (\n <div\n className=\"ald-tour-mask tw-fixed tw-inset-0 tw-z-[1000] tw-bg-[var(--background-inverted)] tw-opacity-45\"\n style={{ zIndex: maskZIndex }}\n onClick={onClose}\n />\n )}\n <div\n className={cn(\n 'ald-tour tw-fixed tw-z-[1001] tw-max-w-sm tw-rounded-r-100 tw-bg-[var(--background-default)] tw-p-6 tw-shadow-[var(--elevation-bottom-bottom-xl)]',\n 'tw-left-1/2 tw-top-1/2 tw--translate-x-1/2 tw--translate-y-1/2',\n className,\n )}\n style={{ zIndex: contentZIndex, ...step?.style }}\n role=\"dialog\"\n aria-modal=\"false\"\n aria-labelledby={step?.title ? titleId : undefined}\n aria-describedby={step?.description ? descriptionId : undefined}\n tabIndex={-1}\n onKeyDown={(event) => {\n if (event.key === 'Escape') onClose?.();\n }}\n >\n <FloatingLayerProvider value={nextLevel}>\n {step?.cover && (\n <div className=\"ald-tour-cover tw-mb-4\">{step.cover}</div>\n )}\n {step?.title && (\n <div\n id={titleId}\n className=\"ald-tour-title tw-mb-2 tw-text-base tw-font-semibold tw-text-[var(--content-primary)]\"\n >\n {step.title}\n </div>\n )}\n {step?.description && (\n <div\n id={descriptionId}\n className=\"ald-tour-description tw-mb-4 tw-text-sm tw-text-[var(--content-secondary)]\"\n >\n {step.description}\n </div>\n )}\n <div className=\"ald-tour-footer tw-flex tw-items-center tw-justify-between\">\n <span className=\"tw-text-xs tw-text-[var(--content-tertiary)]\">\n {current + 1}/{steps.length}\n </span>\n <div className=\"tw-flex tw-gap-2\">\n {current > 0 && (\n <Button type=\"secondary\" size=\"small\" onClick={goPrev}>\n {step?.prevButtonProps?.children || 'Prev'}\n </Button>\n )}\n <Button type=\"primary\" size=\"small\" onClick={goNext}>\n {step?.nextButtonProps?.children ||\n (isLast ? 'Finish' : 'Next')}\n </Button>\n </div>\n </div>\n </FloatingLayerProvider>\n </div>\n </>\n );\n}\n\nexport default Tour;\n"],"mappings":";;;;;;AAyCA,SAAS,KAAK,OAAkB;CAC9B,MAAM,EACJ,OAAO,OACP,SACA,QAAQ,EAAE,EACV,SAAS,mBACT,UACA,OAAO,MACP,WACA,aACE;CAEJ,MAAM,CAAC,cAAc,mBAAmB,SAAS,EAAE;CACnD,MAAM,UAAU,qBAAqB;AAErC,iBAAgB;AACd,MAAI,CAAC,KAAM,iBAAgB,EAAE;IAC5B,CAAC,KAAK,CAAC;CAEV,MAAM,EAAE,YAAY,eAAe,cAAc,kBAAkB;AAEnE,KAAI,CAAC,QAAQ,MAAM,WAAW,EAAG,QAAO;CAExC,MAAM,OAAO,MAAM;CACnB,MAAM,SAAS,YAAY,MAAM,SAAS;CAC1C,MAAM,UAAU,kBAAkB;CAClC,MAAM,gBAAgB,wBAAwB;CAE9C,MAAM,eAAe;AACnB,MAAI,QAAQ;AACV,eAAY;AACZ,cAAW;SACN;GACL,MAAM,OAAO,UAAU;AACvB,OAAI,sBAAsB,OAAW,iBAAgB,KAAK;AAC1D,cAAW,KAAK;;;CAIpB,MAAM,eAAe;EACnB,MAAM,OAAO,KAAK,IAAI,GAA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.role ?? "tree",
56
+ "aria-label": rest["aria-label"] ?? "Tree",
55
57
  checkable,
56
58
  selectable,
57
59
  showIcon,
@@ -1 +1 @@
1
- {"version":3,"file":"Tree2.js","names":[],"sources":["../../src/Tree/Tree.tsx"],"sourcesContent":["import './tree.css';\nimport { cn } from '../lib/utils';\nimport { produce } from 'immer';\nimport { noop } from 'lodash';\nimport type { BasicDataNode, TreeProps as RcTreeProps } from 'rc-tree';\nimport RcTree from 'rc-tree';\nimport type { DataNode, Key } from 'rc-tree/es/interface';\nimport * as React from 'react';\nimport { ConfigContext } from '../ConfigProvider';\nimport HighlightText from '../HighlightText';\nimport { ArrowRightLightLine, DragLine } from '../Icon';\nimport collapseMotion from '../_utils/motion';\nimport { LocaleContext, getTranslator } from '../locale/default';\nimport { composeAllowDrop } from './utils/composeAllowDrop';\nimport dropIndicatorRender from './utils/dropIndicator';\nimport renderSwitcherIcon from './utils/iconUtil';\nconst TREE_SWITCH_CION_SIZE = 16;\nconst NODE_DISABLE_CLASS_NAME = 'ald-tree-node-disabled';\nexport type SwitcherIcon =\n | React.ReactNode\n | ((props: AldTreeNodeProps) => React.ReactNode);\nexport type TreeLeafIcon =\n | React.ReactNode\n | ((props: AldTreeNodeProps) => React.ReactNode);\n\nexport interface AldTreeNodeAttribute {\n eventKey: string;\n prefixCls: string;\n className: string;\n expanded: boolean;\n selected: boolean;\n checked: boolean;\n halfChecked: boolean;\n children: React.ReactNode;\n title: React.ReactNode;\n pos: string;\n dragOver: boolean;\n dragOverGapTop: boolean;\n dragOverGapBottom: boolean;\n isLeaf: boolean;\n selectable: boolean;\n disabled: boolean;\n disableCheckbox: boolean;\n}\n\nexport interface AldTreeNodeProps {\n className?: string;\n checkable?: boolean;\n disabled?: boolean;\n disableCheckbox?: boolean;\n title?: string | React.ReactNode;\n key?: Key;\n eventKey?: string;\n isLeaf?: boolean;\n checked?: boolean;\n expanded?: boolean;\n loading?: boolean;\n selected?: boolean;\n selectable?: boolean;\n icon?:\n | ((treeNode: AldTreeNodeAttribute) => React.ReactNode)\n | React.ReactNode;\n children?: React.ReactNode;\n [customProp: string]: any;\n}\n\nexport type AldTreeNode = React.Component<AldTreeNodeProps, object>;\n\nexport interface AldTreeNodeBaseEvent {\n node: AldTreeNode;\n nativeEvent: MouseEvent;\n}\n\nexport interface AldTreeNodeCheckedEvent extends AldTreeNodeBaseEvent {\n event: 'check';\n checked?: boolean;\n checkedNodes?: AldTreeNode[];\n}\n\nexport interface AldTreeNodeSelectedEvent extends AldTreeNodeBaseEvent {\n event: 'select';\n selected?: boolean;\n selectedNodes?: DataNode[];\n}\n\nexport interface AldTreeNodeExpandedEvent extends AldTreeNodeBaseEvent {\n expanded?: boolean;\n}\n\nexport interface AldTreeNodeMouseEvent {\n node: AldTreeNode;\n event: React.DragEvent<HTMLElement>;\n}\n\nexport interface AldTreeNodeDragEnterEvent extends AldTreeNodeMouseEvent {\n expandedKeys: Key[];\n}\n\nexport interface AldTreeNodeAttribute {\n node: AldTreeNode;\n dragNode: AldTreeNode;\n dragNodesKeys: Key[];\n dropPosition: number;\n dropToGap?: boolean;\n event: React.MouseEvent<HTMLElement>;\n}\n\n// [Legacy] Compatible for v3\nexport type TreeNodeNormal = DataNode;\n\ntype DraggableFn = (node: DataNode) => boolean;\n\ninterface DropOnlyResolvers {\n nodeDraggable: DraggableFn | undefined;\n nodeDroppable: DraggableFn;\n}\n\ninterface DraggableConfig {\n icon?: React.ReactNode | false;\n /** 节点是否可作为 drag source(拖起来)。返回 false:不显示 drag handle、不能起拖。 */\n nodeDraggable?: DraggableFn;\n /**\n * 节点是否可作为 drop target(接收落入)。返回 true:即使 nodeDraggable=false 仍注册\n * onDragOver/onDrop 等 listener,浏览器才会真正派发 drop 事件。\n *\n * 解决 rc-tree 5.x 把\"可拖\"与\"可放\"绑到同一个 nodeDraggable 的限制——之前要让\"类目可接收\n * 资源拖入但本身不可拖\"只能让 nodeDraggable 全返回 true,再用业务侧 CSS hack 隐藏 drag icon。\n *\n * 默认不传 = 沿用 nodeDraggable 行为(向后兼容)。\n */\n nodeDroppable?: DraggableFn;\n}\n\nexport interface TreeProps<T extends BasicDataNode = DataNode>\n extends Omit<\n RcTreeProps<T>,\n | 'prefixCls'\n | 'showLine'\n | 'direction'\n | 'draggable'\n | 'icon'\n | 'switcherIcon'\n | 'filterTreeNode'\n > {\n showLine?: boolean | { showLeafIcon: boolean | TreeLeafIcon };\n className?: string;\n /** 是否支持多选 */\n multiple?: boolean;\n /** 是否自动展开父节点 */\n autoExpandParent?: boolean;\n /** Checkable状态下节点选择完全受控(父子节点选中状态不再关联) */\n checkStrictly?: boolean;\n /** 是否支持选中 */\n checkable?: boolean;\n /** 是否禁用树 */\n disabled?: boolean;\n /** 默认展开所有树节点 */\n defaultExpandAll?: boolean;\n /** 默认展开对应树节点 */\n defaultExpandParent?: boolean;\n /** 默认展开指定的树节点 */\n defaultExpandedKeys?: Key[];\n /** (受控)展开指定的树节点 */\n expandedKeys?: Key[];\n /** (受控)选中复选框的树节点 */\n checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[] };\n /** 默认选中复选框的树节点 */\n defaultCheckedKeys?: Key[];\n /** (受控)设置选中的树节点 */\n selectedKeys?: Key[];\n /** 默认选中的树节点 */\n defaultSelectedKeys?: Key[];\n selectable?: boolean;\n /** 点击树节点触发 */\n filterTreeNode?: (node: DataNode) => boolean;\n loadedKeys?: Key[];\n /** 设置节点可拖拽(IE>8) */\n draggable?: DraggableFn | boolean | DraggableConfig;\n style?: React.CSSProperties;\n showIcon?: boolean;\n icon?:\n | ((nodeProps: AldTreeNodeAttribute) => React.ReactNode)\n | React.ReactNode\n | RcTreeProps<T>['icon'];\n switcherIcon?: SwitcherIcon | RcTreeProps<T>['switcherIcon'];\n prefixCls?: string;\n children?: React.ReactNode;\n blockNode?: boolean;\n size?: 'large' | 'small';\n titleRender?: (node: T) => React.ReactNode;\n showTabLeader?: boolean;\n handlerRender?: (node: T) => React.ReactNode;\n highlightKeywords?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Tree = React.forwardRef<any, TreeProps>((props, ref) => {\n const { locale } = React.useContext(LocaleContext);\n const t = getTranslator(locale);\n\n const { getPrefixCls, direction, virtual } = React.useContext(ConfigContext);\n const size = props.size || 'large';\n const {\n className,\n showIcon = false,\n showLine,\n blockNode = false,\n children,\n checkable = false,\n selectable = true,\n draggable,\n titleRender,\n showTabLeader,\n handlerRender = noop,\n filterTreeNode,\n treeData,\n highlightKeywords,\n motion = { ...collapseMotion, motionAppear: false },\n ...rest\n } = props;\n const prefixCls = getPrefixCls('tree', 'ald-tree');\n\n const customTitleRender = React.useCallback(\n (node: DataNode) => {\n const renderedTitle = titleRender\n ? titleRender(node)\n : typeof node.title === 'function'\n ? node.title(node)\n : node.title;\n const renderedHandler = handlerRender(node) as React.ReactNode;\n const hasHandler =\n renderedHandler !== null &&\n renderedHandler !== undefined &&\n renderedHandler !== false;\n return (\n <span\n className={cn(\n 'ald-tree-title-layout',\n hasHandler && 'ald-tree-title-layout-with-handler',\n )}\n >\n <span className=\"ald-tree-title-content\">{renderedTitle}</span>\n {showTabLeader && hasHandler && (\n <div className=\"ald-tree-tab-leader\"></div>\n )}\n {hasHandler && (\n <span className=\"ald-tree-title-handler\">{renderedHandler}</span>\n )}\n </span>\n );\n },\n [titleRender, showTabLeader, handlerRender],\n );\n const newProps = {\n ...rest,\n checkable,\n selectable,\n showIcon,\n motion,\n blockNode,\n showLine: Boolean(showLine),\n dropIndicatorRender,\n titleRender: customTitleRender,\n };\n\n // 一次性吃掉 draggable 的归一化:rc-tree 看到的 mergedDraggable + 我们内部用的\n // dropOnlyResolvers(原样保留用户 nodeDraggable/nodeDroppable)。集中一处避免两处 useMemo\n // 的判断散开导致字段扩展时遗漏。\n const { draggableConfig, dropOnlyResolvers } = React.useMemo(() => {\n if (!draggable) {\n return {\n draggableConfig: false as const,\n dropOnlyResolvers: null as DropOnlyResolvers | null,\n };\n }\n const newIcon = (\n <DragLine\n size={TREE_SWITCH_CION_SIZE}\n color={'var(--content-secondary)'}\n ></DragLine>\n );\n let mergedDraggable: DraggableConfig = { icon: newIcon };\n switch (typeof draggable) {\n case 'function':\n mergedDraggable.nodeDraggable = draggable;\n break;\n case 'object':\n mergedDraggable = {\n ...draggable,\n icon: draggable.icon === undefined ? newIcon : draggable.icon,\n };\n break;\n default:\n break;\n }\n\n // rc-tree 5.x 把\"可拖(drag source)\"与\"可放(drop target)\"绑到同一个 nodeDraggable:\n // 该返回 false 时 onDragOver/onDrop 也连带不注册,浏览器认为该节点 not droppable\n // → drop 事件根本不派发。为了让\"类目可接收资源拖入但本身不可拖\",把 rc-tree 看到的\n // nodeDraggable 改成 nodeDraggable || nodeDroppable,从而保证 drop listener 仍注册。\n // 真正的 drag-source 阻断由 document 级 dragstart capture handler 负责(见下方 effect)。\n let resolvers: DropOnlyResolvers | null = null;\n if (mergedDraggable.nodeDroppable) {\n const userNodeDraggable = mergedDraggable.nodeDraggable;\n const userNodeDroppable = mergedDraggable.nodeDroppable;\n resolvers = {\n nodeDraggable: userNodeDraggable,\n nodeDroppable: userNodeDroppable,\n };\n mergedDraggable = {\n ...mergedDraggable,\n nodeDraggable: (node: DataNode) =>\n (userNodeDraggable ? userNodeDraggable(node) : true) ||\n userNodeDroppable(node),\n };\n }\n\n return { draggableConfig: mergedDraggable, dropOnlyResolvers: resolvers };\n }, [draggable]);\n\n /**\n * drop-only 节点不能真的起拖。\n *\n * 历史教训:以前在 props.onDragStart 里调 preventDefault。问题是 rc-tree 内部\n * onNodeDragStart(Tree.js:88-99)会在调用 user onDragStart **之前**把\n * draggingNodeKey/dragNodeProps 写进 state;TreeNode(TreeNode.js:112)也已经先\n * setDragNodeHighlight(true)。然后 preventDefault 让浏览器取消拖拽,dragend 不再派发\n * → onWindowDragEnd 永远不触发 → state 卡在\"正在拖类目\",外层 .ald-tree-treenode\n * 卡着 `dragging`、内层 .ald-tree-node-content-wrapper 卡着 `ald-tree-node-selected`\n * 高亮,直到下一次合法 dragstart 才被覆盖。\n *\n * 修复手段:document 级 dragstart capture handler,在 rc-tree 的 React 监听器之前\n * stopPropagation+preventDefault,让 TreeNode 的 onDragStart 整段都不执行,rc-tree\n * 内部 state 彻底不写入。document 是 React root 容器的祖先,capture 阶段先于 React\n * delegation 监听器,因此 stopPropagation 能彻底拦截。\n */\n React.useLayoutEffect(() => {\n if (!dropOnlyResolvers) return;\n const handler = (e: DragEvent) => {\n const target = e.target as HTMLElement | null;\n if (!target?.closest) return;\n if (target.closest('.ald-tree-treenode-drop-only')) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n document.addEventListener('dragstart', handler, true);\n return () => document.removeEventListener('dragstart', handler, true);\n }, [dropOnlyResolvers]);\n\n /**\n * nodeDroppable 同时收口到 rc-tree 的 allowDrop:避免出现\"nodeDroppable=false 但 rc-tree\n * 默认 allowDrop=()=>true 仍然接收 drop\"的语义裂缝。用户自传的 allowDrop 与 nodeDroppable\n * 取 AND(任一拒绝即拒绝)。\n */\n const composedAllowDrop = React.useMemo(\n () => composeAllowDrop(rest.allowDrop, dropOnlyResolvers?.nodeDroppable),\n [rest.allowDrop, dropOnlyResolvers],\n );\n const renderIndent = (nodeProps: AldTreeNodeProps) => {\n const { pos, isLeaf } = nodeProps as AldTreeNodeProps & { pos?: string };\n // rc-tree `pos` 格式:\"0\" 是虚拟根,\"0-0\" 是首层节点,\"0-0-1\" 是 leaf。\n // 顶层节点 level=0 不缩进;每层 +1 unit(switcher 宽度),与 antd Tree 行为一致。\n // leaf 在未开启 showLine 时 renderSwitcherIcon 返回 null,没有真实 switcher 占位;\n // 需要补一个 switcher 宽度,保证业务图标和同级可展开节点对齐。\n // `?? 2` 兜底:当 pos 缺失时按\"首层节点 `0-0` 长度 = 2\"处理,结果 level=0 不缩进;\n // 切勿改成 1 或 0,否则缺 pos 的节点会被错误右移。\n const level = Math.max(0, (pos?.split('-').length ?? 2) - 2);\n const leafSwitcherWidth = isLeaf && !showLine ? TREE_SWITCH_CION_SIZE : 0;\n return (\n <span\n style={{\n width: level * TREE_SWITCH_CION_SIZE + leafSwitcherWidth,\n flexShrink: 0,\n }}\n ></span>\n );\n };\n const newTreeData = React.useMemo(() => {\n if (!filterTreeNode || !treeData) return treeData;\n\n const shouldNodeDisabled = (node: DataNode): boolean => {\n // 初始化一个标志来表示是否需要为当前节点添加className\n let shouldAddDisabled = true;\n if (filterTreeNode(node)) {\n shouldAddDisabled = false;\n }\n\n if (node.children) {\n // 遍历当前节点的子节点,只要有一个子节点不disable,则该不需要添加className\n const allChildrenShouldAddDisabled = node.children.reduce(\n (pre, child) => {\n return shouldNodeDisabled(child) && pre;\n },\n shouldAddDisabled,\n );\n shouldAddDisabled = allChildrenShouldAddDisabled;\n }\n\n // 如果shouldAddDisabled为true,就为当前节点添加className\n if (shouldAddDisabled) {\n node.className = node.className?.includes(NODE_DISABLE_CLASS_NAME)\n ? node.className\n : cn(node.className, NODE_DISABLE_CLASS_NAME);\n } else {\n const reg = /ald-tree-node-disabled/g;\n node.className?.replace(reg, ' ');\n }\n if (highlightKeywords && typeof node.title !== 'function') {\n node.title = (\n <HighlightText keyword={highlightKeywords}>\n {node.title}\n </HighlightText>\n );\n }\n return shouldAddDisabled;\n };\n const newTreeData = produce(treeData, (draft) => {\n for (const rootNode of draft) {\n shouldNodeDisabled(rootNode);\n }\n });\n return newTreeData;\n }, [filterTreeNode, treeData, highlightKeywords]);\n\n /** 给 drop-only 节点的 wrapper 加 'ald-tree-treenode-drop-only' className(rc-tree 5.x\n * 会把 DataNode.className 透传到 .ald-tree-treenode 上)。css 据此隐藏 drag handle icon\n * 并提供 not-allowed cursor,区分纯 drop target 与真正可拖节点。 */\n const finalTreeData = React.useMemo(() => {\n if (!dropOnlyResolvers || !newTreeData) return newTreeData;\n const { nodeDraggable, nodeDroppable } = dropOnlyResolvers;\n return produce(newTreeData, (draft) => {\n const visit = (nodes: DataNode[] | undefined) => {\n if (!nodes) return;\n for (const node of nodes) {\n const isDraggable = nodeDraggable ? nodeDraggable(node) : true;\n const isDroppable = nodeDroppable(node);\n if (!isDraggable && isDroppable) {\n const existing = node.className ?? '';\n if (!existing.includes('ald-tree-treenode-drop-only')) {\n node.className = cn(existing, 'ald-tree-treenode-drop-only');\n }\n }\n visit(node.children as DataNode[] | undefined);\n }\n };\n visit(draft as DataNode[]);\n });\n }, [newTreeData, dropOnlyResolvers]);\n\n const noChildren = React.useMemo(() => {\n if (finalTreeData?.length) {\n return finalTreeData.every((node) => {\n return !node.children?.length && node.isLeaf !== false;\n });\n }\n return true;\n }, [finalTreeData]);\n\n return (\n <RcTree\n itemHeight={20}\n ref={ref}\n virtual={virtual}\n {...newProps}\n allowDrop={composedAllowDrop}\n prefixCls={prefixCls}\n treeData={finalTreeData}\n className={cn(\n {\n [`${prefixCls}-icon-hide`]: !showIcon,\n [`${prefixCls}-block-node`]: blockNode,\n [`${prefixCls}-unselectable`]: !selectable,\n [`${prefixCls}-large`]: size === 'large',\n [`${prefixCls}-rtl`]: direction === 'rtl',\n ['ald-draggable-tree']: draggable,\n [`${prefixCls}-no-children`]: noChildren,\n },\n // antd 兼容:保留 ant-* class,消费方 CSS 可能依赖该选择器\n 'ant-tree',\n className,\n )}\n direction={direction as any}\n checkable={\n checkable ? (\n <span className={`${prefixCls}-checkbox-inner`} />\n ) : (\n checkable\n )\n }\n selectable={selectable}\n // @ts-ignore\n switcherIcon={(nodeProps: AldTreeNodeProps) => {\n return (\n <>\n {renderIndent(nodeProps)}\n {renderSwitcherIcon(\n prefixCls,\n <ArrowRightLightLine\n size={TREE_SWITCH_CION_SIZE}\n color={'var(--content-secondary)'}\n >\n {t.Tree.expand}\n </ArrowRightLightLine>,\n showLine,\n nodeProps,\n TREE_SWITCH_CION_SIZE,\n )}\n </>\n );\n }}\n draggable={draggableConfig}\n >\n {children}\n </RcTree>\n );\n});\n\nexport default Tree;\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAM,wBAAwB;AAC9B,IAAM,0BAA0B;AAmLhC,IAAM,OAAO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AO,SAAS;AACnC,UAAO,CAAC,KAAK,UAAU,UAAU,KAAK,WAAW;IACjD;AAEJ,SAAO;IACN,CAAC,cAAc,CAAC;AAEnB,QACE,oBAAC,QAAD;EACE,YAAY;EACP;EACI;EACT,GAAI;EACJ,WAAW;EACA;EACX,UAAU;EACV,WAAW,GACT;IACG,GAAG,UAAU,cAAc,CAAC;IAC5B,GAAG,UAAU,eAAe;IAC5B,GAAG,UAAU,iBAAiB,CAAC;IAC/B,GAAG,UAAU,UAAU,SAAS;IAChC,GAAG,UAAU,QAAQ,cAAc;IACnC,uBAAuB;IACvB,GAAG,UAAU,gBAAgB;GAC/B,EAED,YACA,UACD;EACU;EACX,WACE,YACE,oBAAC,QAAD,EAAM,WAAW,GAAG,UAAU,kBAAoB,CAAA,GAElD;EAGQ;EAEZ,eAAe,cAAgC;AAC7C,UACE,qBAAA,UAAA,EAAA,UAAA,CACG,aAAa,UAAU,EACvB,mBACC,WACA,oBAAC,MAAD;IACE,MAAM;IACN,OAAO;cAEN,EAAE,KAAK;IACY,CAAA,EACtB,UACA,WACA,sBACD,CACA,EAAA,CAAA;;EAGP,WAAW;EAEV;EACM,CAAA;EAEX"}
1
+ {"version":3,"file":"Tree2.js","names":[],"sources":["../../src/Tree/Tree.tsx"],"sourcesContent":["import './tree.css';\nimport { cn } from '../lib/utils';\nimport { produce } from 'immer';\nimport { noop } from 'lodash';\nimport type { BasicDataNode, TreeProps as RcTreeProps } from 'rc-tree';\nimport RcTree from 'rc-tree';\nimport type { DataNode, Key } from 'rc-tree/es/interface';\nimport * as React from 'react';\nimport { ConfigContext } from '../ConfigProvider';\nimport HighlightText from '../HighlightText';\nimport { ArrowRightLightLine, DragLine } from '../Icon';\nimport collapseMotion from '../_utils/motion';\nimport { LocaleContext, getTranslator } from '../locale/default';\nimport { composeAllowDrop } from './utils/composeAllowDrop';\nimport dropIndicatorRender from './utils/dropIndicator';\nimport renderSwitcherIcon from './utils/iconUtil';\nconst TREE_SWITCH_CION_SIZE = 16;\nconst NODE_DISABLE_CLASS_NAME = 'ald-tree-node-disabled';\nexport type SwitcherIcon =\n | React.ReactNode\n | ((props: AldTreeNodeProps) => React.ReactNode);\nexport type TreeLeafIcon =\n | React.ReactNode\n | ((props: AldTreeNodeProps) => React.ReactNode);\n\nexport interface AldTreeNodeAttribute {\n eventKey: string;\n prefixCls: string;\n className: string;\n expanded: boolean;\n selected: boolean;\n checked: boolean;\n halfChecked: boolean;\n children: React.ReactNode;\n title: React.ReactNode;\n pos: string;\n dragOver: boolean;\n dragOverGapTop: boolean;\n dragOverGapBottom: boolean;\n isLeaf: boolean;\n selectable: boolean;\n disabled: boolean;\n disableCheckbox: boolean;\n}\n\nexport interface AldTreeNodeProps {\n className?: string;\n checkable?: boolean;\n disabled?: boolean;\n disableCheckbox?: boolean;\n title?: string | React.ReactNode;\n key?: Key;\n eventKey?: string;\n isLeaf?: boolean;\n checked?: boolean;\n expanded?: boolean;\n loading?: boolean;\n selected?: boolean;\n selectable?: boolean;\n icon?:\n | ((treeNode: AldTreeNodeAttribute) => React.ReactNode)\n | React.ReactNode;\n children?: React.ReactNode;\n [customProp: string]: any;\n}\n\nexport type AldTreeNode = React.Component<AldTreeNodeProps, object>;\n\nexport interface AldTreeNodeBaseEvent {\n node: AldTreeNode;\n nativeEvent: MouseEvent;\n}\n\nexport interface AldTreeNodeCheckedEvent extends AldTreeNodeBaseEvent {\n event: 'check';\n checked?: boolean;\n checkedNodes?: AldTreeNode[];\n}\n\nexport interface AldTreeNodeSelectedEvent extends AldTreeNodeBaseEvent {\n event: 'select';\n selected?: boolean;\n selectedNodes?: DataNode[];\n}\n\nexport interface AldTreeNodeExpandedEvent extends AldTreeNodeBaseEvent {\n expanded?: boolean;\n}\n\nexport interface AldTreeNodeMouseEvent {\n node: AldTreeNode;\n event: React.DragEvent<HTMLElement>;\n}\n\nexport interface AldTreeNodeDragEnterEvent extends AldTreeNodeMouseEvent {\n expandedKeys: Key[];\n}\n\nexport interface AldTreeNodeAttribute {\n node: AldTreeNode;\n dragNode: AldTreeNode;\n dragNodesKeys: Key[];\n dropPosition: number;\n dropToGap?: boolean;\n event: React.MouseEvent<HTMLElement>;\n}\n\n// [Legacy] Compatible for v3\nexport type TreeNodeNormal = DataNode;\n\ntype DraggableFn = (node: DataNode) => boolean;\n\ninterface DropOnlyResolvers {\n nodeDraggable: DraggableFn | undefined;\n nodeDroppable: DraggableFn;\n}\n\ninterface DraggableConfig {\n icon?: React.ReactNode | false;\n /** 节点是否可作为 drag source(拖起来)。返回 false:不显示 drag handle、不能起拖。 */\n nodeDraggable?: DraggableFn;\n /**\n * 节点是否可作为 drop target(接收落入)。返回 true:即使 nodeDraggable=false 仍注册\n * onDragOver/onDrop 等 listener,浏览器才会真正派发 drop 事件。\n *\n * 解决 rc-tree 5.x 把\"可拖\"与\"可放\"绑到同一个 nodeDraggable 的限制——之前要让\"类目可接收\n * 资源拖入但本身不可拖\"只能让 nodeDraggable 全返回 true,再用业务侧 CSS hack 隐藏 drag icon。\n *\n * 默认不传 = 沿用 nodeDraggable 行为(向后兼容)。\n */\n nodeDroppable?: DraggableFn;\n}\n\nexport interface TreeProps<T extends BasicDataNode = DataNode>\n extends Omit<\n RcTreeProps<T>,\n | 'prefixCls'\n | 'showLine'\n | 'direction'\n | 'draggable'\n | 'icon'\n | 'switcherIcon'\n | 'filterTreeNode'\n > {\n showLine?: boolean | { showLeafIcon: boolean | TreeLeafIcon };\n className?: string;\n /** 是否支持多选 */\n multiple?: boolean;\n /** 是否自动展开父节点 */\n autoExpandParent?: boolean;\n /** Checkable状态下节点选择完全受控(父子节点选中状态不再关联) */\n checkStrictly?: boolean;\n /** 是否支持选中 */\n checkable?: boolean;\n /** 是否禁用树 */\n disabled?: boolean;\n /** 默认展开所有树节点 */\n defaultExpandAll?: boolean;\n /** 默认展开对应树节点 */\n defaultExpandParent?: boolean;\n /** 默认展开指定的树节点 */\n defaultExpandedKeys?: Key[];\n /** (受控)展开指定的树节点 */\n expandedKeys?: Key[];\n /** (受控)选中复选框的树节点 */\n checkedKeys?: Key[] | { checked: Key[]; halfChecked: Key[] };\n /** 默认选中复选框的树节点 */\n defaultCheckedKeys?: Key[];\n /** (受控)设置选中的树节点 */\n selectedKeys?: Key[];\n /** 默认选中的树节点 */\n defaultSelectedKeys?: Key[];\n selectable?: boolean;\n /** 点击树节点触发 */\n filterTreeNode?: (node: DataNode) => boolean;\n loadedKeys?: Key[];\n /** 设置节点可拖拽(IE>8) */\n draggable?: DraggableFn | boolean | DraggableConfig;\n style?: React.CSSProperties;\n showIcon?: boolean;\n icon?:\n | ((nodeProps: AldTreeNodeAttribute) => React.ReactNode)\n | React.ReactNode\n | RcTreeProps<T>['icon'];\n switcherIcon?: SwitcherIcon | RcTreeProps<T>['switcherIcon'];\n prefixCls?: string;\n children?: React.ReactNode;\n blockNode?: boolean;\n size?: 'large' | 'small';\n titleRender?: (node: T) => React.ReactNode;\n showTabLeader?: boolean;\n handlerRender?: (node: T) => React.ReactNode;\n highlightKeywords?: string;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Tree = React.forwardRef<any, TreeProps>((props, ref) => {\n const { locale } = React.useContext(LocaleContext);\n const t = getTranslator(locale);\n\n const { getPrefixCls, direction, virtual } = React.useContext(ConfigContext);\n const size = props.size || 'large';\n const {\n className,\n showIcon = false,\n showLine,\n blockNode = false,\n children,\n checkable = false,\n selectable = true,\n draggable,\n titleRender,\n showTabLeader,\n handlerRender = noop,\n filterTreeNode,\n treeData,\n highlightKeywords,\n motion = { ...collapseMotion, motionAppear: false },\n ...rest\n } = props;\n const prefixCls = getPrefixCls('tree', 'ald-tree');\n\n const customTitleRender = React.useCallback(\n (node: DataNode) => {\n const renderedTitle = titleRender\n ? titleRender(node)\n : typeof node.title === 'function'\n ? node.title(node)\n : node.title;\n const renderedHandler = handlerRender(node) as React.ReactNode;\n const hasHandler =\n renderedHandler !== null &&\n renderedHandler !== undefined &&\n renderedHandler !== false;\n return (\n <span\n className={cn(\n 'ald-tree-title-layout',\n hasHandler && 'ald-tree-title-layout-with-handler',\n )}\n >\n <span className=\"ald-tree-title-content\">{renderedTitle}</span>\n {showTabLeader && hasHandler && (\n <div className=\"ald-tree-tab-leader\"></div>\n )}\n {hasHandler && (\n <span className=\"ald-tree-title-handler\">{renderedHandler}</span>\n )}\n </span>\n );\n },\n [titleRender, showTabLeader, handlerRender],\n );\n const newProps = {\n ...rest,\n role: (rest as any).role ?? 'tree',\n 'aria-label': (rest as any)['aria-label'] ?? 'Tree',\n checkable,\n selectable,\n showIcon,\n motion,\n blockNode,\n showLine: Boolean(showLine),\n dropIndicatorRender,\n titleRender: customTitleRender,\n };\n\n // 一次性吃掉 draggable 的归一化:rc-tree 看到的 mergedDraggable + 我们内部用的\n // dropOnlyResolvers(原样保留用户 nodeDraggable/nodeDroppable)。集中一处避免两处 useMemo\n // 的判断散开导致字段扩展时遗漏。\n const { draggableConfig, dropOnlyResolvers } = React.useMemo(() => {\n if (!draggable) {\n return {\n draggableConfig: false as const,\n dropOnlyResolvers: null as DropOnlyResolvers | null,\n };\n }\n const newIcon = (\n <DragLine\n size={TREE_SWITCH_CION_SIZE}\n color={'var(--content-secondary)'}\n ></DragLine>\n );\n let mergedDraggable: DraggableConfig = { icon: newIcon };\n switch (typeof draggable) {\n case 'function':\n mergedDraggable.nodeDraggable = draggable;\n break;\n case 'object':\n mergedDraggable = {\n ...draggable,\n icon: draggable.icon === undefined ? newIcon : draggable.icon,\n };\n break;\n default:\n break;\n }\n\n // rc-tree 5.x 把\"可拖(drag source)\"与\"可放(drop target)\"绑到同一个 nodeDraggable:\n // 该返回 false 时 onDragOver/onDrop 也连带不注册,浏览器认为该节点 not droppable\n // → drop 事件根本不派发。为了让\"类目可接收资源拖入但本身不可拖\",把 rc-tree 看到的\n // nodeDraggable 改成 nodeDraggable || nodeDroppable,从而保证 drop listener 仍注册。\n // 真正的 drag-source 阻断由 document 级 dragstart capture handler 负责(见下方 effect)。\n let resolvers: DropOnlyResolvers | null = null;\n if (mergedDraggable.nodeDroppable) {\n const userNodeDraggable = mergedDraggable.nodeDraggable;\n const userNodeDroppable = mergedDraggable.nodeDroppable;\n resolvers = {\n nodeDraggable: userNodeDraggable,\n nodeDroppable: userNodeDroppable,\n };\n mergedDraggable = {\n ...mergedDraggable,\n nodeDraggable: (node: DataNode) =>\n (userNodeDraggable ? userNodeDraggable(node) : true) ||\n userNodeDroppable(node),\n };\n }\n\n return { draggableConfig: mergedDraggable, dropOnlyResolvers: resolvers };\n }, [draggable]);\n\n /**\n * drop-only 节点不能真的起拖。\n *\n * 历史教训:以前在 props.onDragStart 里调 preventDefault。问题是 rc-tree 内部\n * onNodeDragStart(Tree.js:88-99)会在调用 user onDragStart **之前**把\n * draggingNodeKey/dragNodeProps 写进 state;TreeNode(TreeNode.js:112)也已经先\n * setDragNodeHighlight(true)。然后 preventDefault 让浏览器取消拖拽,dragend 不再派发\n * → onWindowDragEnd 永远不触发 → state 卡在\"正在拖类目\",外层 .ald-tree-treenode\n * 卡着 `dragging`、内层 .ald-tree-node-content-wrapper 卡着 `ald-tree-node-selected`\n * 高亮,直到下一次合法 dragstart 才被覆盖。\n *\n * 修复手段:document 级 dragstart capture handler,在 rc-tree 的 React 监听器之前\n * stopPropagation+preventDefault,让 TreeNode 的 onDragStart 整段都不执行,rc-tree\n * 内部 state 彻底不写入。document 是 React root 容器的祖先,capture 阶段先于 React\n * delegation 监听器,因此 stopPropagation 能彻底拦截。\n */\n React.useLayoutEffect(() => {\n if (!dropOnlyResolvers) return;\n const handler = (e: DragEvent) => {\n const target = e.target as HTMLElement | null;\n if (!target?.closest) return;\n if (target.closest('.ald-tree-treenode-drop-only')) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n document.addEventListener('dragstart', handler, true);\n return () => document.removeEventListener('dragstart', handler, true);\n }, [dropOnlyResolvers]);\n\n /**\n * nodeDroppable 同时收口到 rc-tree 的 allowDrop:避免出现\"nodeDroppable=false 但 rc-tree\n * 默认 allowDrop=()=>true 仍然接收 drop\"的语义裂缝。用户自传的 allowDrop 与 nodeDroppable\n * 取 AND(任一拒绝即拒绝)。\n */\n const composedAllowDrop = React.useMemo(\n () => composeAllowDrop(rest.allowDrop, dropOnlyResolvers?.nodeDroppable),\n [rest.allowDrop, dropOnlyResolvers],\n );\n const renderIndent = (nodeProps: AldTreeNodeProps) => {\n const { pos, isLeaf } = nodeProps as AldTreeNodeProps & { pos?: string };\n // rc-tree `pos` 格式:\"0\" 是虚拟根,\"0-0\" 是首层节点,\"0-0-1\" 是 leaf。\n // 顶层节点 level=0 不缩进;每层 +1 unit(switcher 宽度),与 antd Tree 行为一致。\n // leaf 在未开启 showLine 时 renderSwitcherIcon 返回 null,没有真实 switcher 占位;\n // 需要补一个 switcher 宽度,保证业务图标和同级可展开节点对齐。\n // `?? 2` 兜底:当 pos 缺失时按\"首层节点 `0-0` 长度 = 2\"处理,结果 level=0 不缩进;\n // 切勿改成 1 或 0,否则缺 pos 的节点会被错误右移。\n const level = Math.max(0, (pos?.split('-').length ?? 2) - 2);\n const leafSwitcherWidth = isLeaf && !showLine ? TREE_SWITCH_CION_SIZE : 0;\n return (\n <span\n style={{\n width: level * TREE_SWITCH_CION_SIZE + leafSwitcherWidth,\n flexShrink: 0,\n }}\n ></span>\n );\n };\n const newTreeData = React.useMemo(() => {\n if (!filterTreeNode || !treeData) return treeData;\n\n const shouldNodeDisabled = (node: DataNode): boolean => {\n // 初始化一个标志来表示是否需要为当前节点添加className\n let shouldAddDisabled = true;\n if (filterTreeNode(node)) {\n shouldAddDisabled = false;\n }\n\n if (node.children) {\n // 遍历当前节点的子节点,只要有一个子节点不disable,则该不需要添加className\n const allChildrenShouldAddDisabled = node.children.reduce(\n (pre, child) => {\n return shouldNodeDisabled(child) && pre;\n },\n shouldAddDisabled,\n );\n shouldAddDisabled = allChildrenShouldAddDisabled;\n }\n\n // 如果shouldAddDisabled为true,就为当前节点添加className\n if (shouldAddDisabled) {\n node.className = node.className?.includes(NODE_DISABLE_CLASS_NAME)\n ? node.className\n : cn(node.className, NODE_DISABLE_CLASS_NAME);\n } else {\n const reg = /ald-tree-node-disabled/g;\n node.className?.replace(reg, ' ');\n }\n if (highlightKeywords && typeof node.title !== 'function') {\n node.title = (\n <HighlightText keyword={highlightKeywords}>\n {node.title}\n </HighlightText>\n );\n }\n return shouldAddDisabled;\n };\n const newTreeData = produce(treeData, (draft) => {\n for (const rootNode of draft) {\n shouldNodeDisabled(rootNode);\n }\n });\n return newTreeData;\n }, [filterTreeNode, treeData, highlightKeywords]);\n\n /** 给 drop-only 节点的 wrapper 加 'ald-tree-treenode-drop-only' className(rc-tree 5.x\n * 会把 DataNode.className 透传到 .ald-tree-treenode 上)。css 据此隐藏 drag handle icon\n * 并提供 not-allowed cursor,区分纯 drop target 与真正可拖节点。 */\n const finalTreeData = React.useMemo(() => {\n if (!dropOnlyResolvers || !newTreeData) return newTreeData;\n const { nodeDraggable, nodeDroppable } = dropOnlyResolvers;\n return produce(newTreeData, (draft) => {\n const visit = (nodes: DataNode[] | undefined) => {\n if (!nodes) return;\n for (const node of nodes) {\n const isDraggable = nodeDraggable ? nodeDraggable(node) : true;\n const isDroppable = nodeDroppable(node);\n if (!isDraggable && isDroppable) {\n const existing = node.className ?? '';\n if (!existing.includes('ald-tree-treenode-drop-only')) {\n node.className = cn(existing, 'ald-tree-treenode-drop-only');\n }\n }\n visit(node.children as DataNode[] | undefined);\n }\n };\n visit(draft as DataNode[]);\n });\n }, [newTreeData, dropOnlyResolvers]);\n\n const noChildren = React.useMemo(() => {\n if (finalTreeData?.length) {\n return finalTreeData.every((node) => {\n return !node.children?.length && node.isLeaf !== false;\n });\n }\n return true;\n }, [finalTreeData]);\n\n return (\n <RcTree\n itemHeight={20}\n ref={ref}\n virtual={virtual}\n {...newProps}\n allowDrop={composedAllowDrop}\n prefixCls={prefixCls}\n treeData={finalTreeData}\n className={cn(\n {\n [`${prefixCls}-icon-hide`]: !showIcon,\n [`${prefixCls}-block-node`]: blockNode,\n [`${prefixCls}-unselectable`]: !selectable,\n [`${prefixCls}-large`]: size === 'large',\n [`${prefixCls}-rtl`]: direction === 'rtl',\n ['ald-draggable-tree']: draggable,\n [`${prefixCls}-no-children`]: noChildren,\n },\n // antd 兼容:保留 ant-* class,消费方 CSS 可能依赖该选择器\n 'ant-tree',\n className,\n )}\n direction={direction as any}\n checkable={\n checkable ? (\n <span className={`${prefixCls}-checkbox-inner`} />\n ) : (\n checkable\n )\n }\n selectable={selectable}\n // @ts-ignore\n switcherIcon={(nodeProps: AldTreeNodeProps) => {\n return (\n <>\n {renderIndent(nodeProps)}\n {renderSwitcherIcon(\n prefixCls,\n <ArrowRightLightLine\n size={TREE_SWITCH_CION_SIZE}\n color={'var(--content-secondary)'}\n >\n {t.Tree.expand}\n </ArrowRightLightLine>,\n showLine,\n nodeProps,\n TREE_SWITCH_CION_SIZE,\n )}\n </>\n );\n }}\n draggable={draggableConfig}\n >\n {children}\n </RcTree>\n );\n});\n\nexport default Tree;\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,IAAM,wBAAwB;AAC9B,IAAM,0BAA0B;AAmLhC,IAAM,OAAO,QAAM,YAA4B,OAAO,QAAQ;CAC5D,MAAM,EAAE,WAAW,QAAM,WAAW,cAAc;CAClD,MAAM,IAAI,cAAc,OAAO;CAE/B,MAAM,EAAE,cAAc,WAAW,YAAY,QAAM,WAAW,cAAc;CAC5E,MAAM,OAAO,MAAM,QAAQ;CAC3B,MAAM,EACJ,WACA,WAAW,OACX,UACA,YAAY,OACZ,UACA,YAAY,OACZ,aAAa,MACb,WACA,aACA,eACA,gBAAgB,MAChB,gBACA,UACA,mBACA,SAAS;EAAE,GAAG;EAAgB,cAAc;EAAO,EACnD,GAAG,SACD;CACJ,MAAM,YAAY,aAAa,QAAQ,WAAW;CAElD,MAAM,oBAAoB,QAAM,aAC7B,SAAmB;EAClB,MAAM,gBAAgB,cAClB,YAAY,KAAK,GACjB,OAAO,KAAK,UAAU,aACtB,KAAK,MAAM,KAAK,GAChB,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AElD;EAGQ;EAEZ,eAAe,cAAgC;AAC7C,UACE,qBAAA,UAAA,EAAA,UAAA,CACG,aAAa,UAAU,EACvB,mBACC,WACA,oBAAC,MAAD;IACE,MAAM;IACN,OAAO;cAEN,EAAE,KAAK;IACY,CAAA,EACtB,UACA,WACA,sBACD,CACA,EAAA,CAAA;;EAGP,WAAW;EAEV;EACM,CAAA;EAEX"}
@@ -0,0 +1,17 @@
1
+ export declare function markDialogEscapeEvent(event: KeyboardEvent): void;
2
+ export declare function shouldDismissDialogEscape(event: KeyboardEvent): boolean;
3
+ export declare function getDialogFocusableElements(container: HTMLElement): HTMLElement[];
4
+ export declare function isDialogChildOverlayActive(container: HTMLElement): boolean;
5
+ export declare function focusInitialDialogTarget(container: HTMLElement): void;
6
+ export declare function restoreDialogFocus(target: HTMLElement | null): void;
7
+ interface DialogAccessibilityOptions {
8
+ open: boolean;
9
+ isTop: boolean;
10
+ keyboard: boolean;
11
+ containerRef: {
12
+ current: HTMLElement | null;
13
+ };
14
+ onEscape: (event: KeyboardEvent) => void;
15
+ }
16
+ export declare function useDialogAccessibility({ open, isTop, keyboard, containerRef, onEscape, }: DialogAccessibilityOptions): void;
17
+ export {};
@@ -0,0 +1,110 @@
1
+ import { useEffect, useLayoutEffect, useRef } from "react";
2
+ //#region src/_utils/dialogAccessibility.ts
3
+ var FOCUSABLE_SELECTOR = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]):not([disabled])";
4
+ var dialogEscapeEvents = /* @__PURE__ */ new WeakSet();
5
+ function markDialogEscapeEvent(event) {
6
+ dialogEscapeEvents.add(event);
7
+ }
8
+ function shouldDismissDialogEscape(event) {
9
+ return !event.cancelBubble && (!event.defaultPrevented || dialogEscapeEvents.has(event));
10
+ }
11
+ function getDialogFocusableElements(container) {
12
+ return Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((element) => {
13
+ if (element.closest("[inert]")) return false;
14
+ if (element.getAttribute("aria-hidden") === "true") return false;
15
+ if (element.getAttribute("aria-disabled") === "true") return false;
16
+ return element.tabIndex >= 0;
17
+ });
18
+ }
19
+ function isDialogChildOverlayActive(container) {
20
+ const activeElement = document.activeElement;
21
+ if (!(activeElement instanceof HTMLElement)) return false;
22
+ const activeOverlay = activeElement.closest("[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]");
23
+ return !!activeOverlay && activeOverlay !== container;
24
+ }
25
+ function focusInitialDialogTarget(container) {
26
+ const activeElement = document.activeElement;
27
+ const activeOverlay = activeElement instanceof HTMLElement ? activeElement.closest("[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]") : null;
28
+ if (activeOverlay && activeOverlay !== container && activeOverlay.getAttribute("role") !== "dialog" && activeOverlay.getAttribute("role") !== "alertdialog") return;
29
+ (getDialogFocusableElements(container).find((element) => element.dataset.overlayClose !== "true") ?? null ?? container).focus({ preventScroll: true });
30
+ }
31
+ function restoreDialogFocus(target) {
32
+ queueMicrotask(() => {
33
+ if (target?.isConnected && target.tabIndex !== -1) {
34
+ target.focus({ preventScroll: true });
35
+ return;
36
+ }
37
+ Array.from(document.querySelectorAll(FOCUSABLE_SELECTOR)).find((element) => {
38
+ if (element.closest("[role=\"dialog\"], [role=\"alertdialog\"]")) return false;
39
+ if (element.closest("[inert]")) return false;
40
+ if (element.getAttribute("aria-disabled") === "true") return false;
41
+ return element.tabIndex >= 0;
42
+ })?.focus({ preventScroll: true });
43
+ });
44
+ }
45
+ function useDialogAccessibility({ open, isTop, keyboard, containerRef, onEscape }) {
46
+ const focusRestoreTargetRef = useRef(null);
47
+ const prevOpenRef = useRef(false);
48
+ useLayoutEffect(() => {
49
+ const wasOpen = prevOpenRef.current;
50
+ if (open && !wasOpen) focusRestoreTargetRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
51
+ if (!open && wasOpen) {
52
+ restoreDialogFocus(focusRestoreTargetRef.current);
53
+ focusRestoreTargetRef.current = null;
54
+ }
55
+ prevOpenRef.current = open;
56
+ }, [open]);
57
+ useEffect(() => {
58
+ if (!open || !isTop || !containerRef.current) return;
59
+ const container = containerRef.current;
60
+ const handleKeyDown = (event) => {
61
+ if (event.key !== "Tab") return;
62
+ if (isDialogChildOverlayActive(container)) return;
63
+ const focusable = getDialogFocusableElements(container);
64
+ if (focusable.length === 0) {
65
+ if (document.activeElement !== container) {
66
+ event.preventDefault();
67
+ container.focus({ preventScroll: true });
68
+ }
69
+ return;
70
+ }
71
+ const first = focusable[0];
72
+ const last = focusable[focusable.length - 1];
73
+ if (event.shiftKey) {
74
+ if (document.activeElement === first || !container.contains(document.activeElement)) {
75
+ event.preventDefault();
76
+ last.focus({ preventScroll: true });
77
+ }
78
+ } else if (document.activeElement === last || !container.contains(document.activeElement)) {
79
+ event.preventDefault();
80
+ first.focus({ preventScroll: true });
81
+ }
82
+ };
83
+ document.addEventListener("keydown", handleKeyDown);
84
+ return () => document.removeEventListener("keydown", handleKeyDown);
85
+ }, [
86
+ containerRef,
87
+ isTop,
88
+ open
89
+ ]);
90
+ useEffect(() => {
91
+ if (!open || !isTop || !keyboard) return;
92
+ const handleEscape = (event) => {
93
+ if (event.key !== "Escape") return;
94
+ queueMicrotask(() => {
95
+ if (shouldDismissDialogEscape(event)) onEscape(event);
96
+ });
97
+ };
98
+ window.addEventListener("keydown", handleEscape, true);
99
+ return () => window.removeEventListener("keydown", handleEscape, true);
100
+ }, [
101
+ isTop,
102
+ keyboard,
103
+ onEscape,
104
+ open
105
+ ]);
106
+ }
107
+ //#endregion
108
+ export { focusInitialDialogTarget, markDialogEscapeEvent, restoreDialogFocus, useDialogAccessibility };
109
+
110
+ //# sourceMappingURL=dialogAccessibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialogAccessibility.js","names":[],"sources":["../../src/_utils/dialogAccessibility.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useRef } from 'react';\n\nconst FOCUSABLE_SELECTOR =\n 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"]):not([disabled])';\n\nconst dialogEscapeEvents = new WeakSet<KeyboardEvent>();\n\nexport function markDialogEscapeEvent(event: KeyboardEvent) {\n dialogEscapeEvents.add(event);\n}\n\nexport function shouldDismissDialogEscape(event: KeyboardEvent) {\n return (\n !event.cancelBubble &&\n (!event.defaultPrevented || dialogEscapeEvents.has(event))\n );\n}\n\nexport function getDialogFocusableElements(container: HTMLElement) {\n return Array.from(\n container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).filter((element) => {\n if (element.closest('[inert]')) return false;\n if (element.getAttribute('aria-hidden') === 'true') return false;\n if (element.getAttribute('aria-disabled') === 'true') return false;\n return element.tabIndex >= 0;\n });\n}\n\nexport function isDialogChildOverlayActive(container: HTMLElement) {\n const activeElement = document.activeElement;\n if (!(activeElement instanceof HTMLElement)) return false;\n const activeOverlay = activeElement.closest<HTMLElement>(\n '[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]',\n );\n\n return !!activeOverlay && activeOverlay !== container;\n}\n\nexport function focusInitialDialogTarget(container: HTMLElement) {\n const activeElement = document.activeElement;\n const activeOverlay =\n activeElement instanceof HTMLElement\n ? activeElement.closest<HTMLElement>(\n '[role=\"dialog\"], [role=\"alertdialog\"], [role=\"menu\"], [role=\"listbox\"]',\n )\n : null;\n\n if (\n activeOverlay &&\n activeOverlay !== container &&\n activeOverlay.getAttribute('role') !== 'dialog' &&\n activeOverlay.getAttribute('role') !== 'alertdialog'\n ) {\n return;\n }\n\n const focusable = getDialogFocusableElements(container);\n const preferred =\n focusable.find((element) => element.dataset.overlayClose !== 'true') ??\n null;\n\n (preferred ?? container).focus({ preventScroll: true });\n}\n\nexport function restoreDialogFocus(target: HTMLElement | null) {\n queueMicrotask(() => {\n if (target?.isConnected && target.tabIndex !== -1) {\n target.focus({ preventScroll: true });\n return;\n }\n\n const fallback = Array.from(\n document.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),\n ).find((element) => {\n if (element.closest('[role=\"dialog\"], [role=\"alertdialog\"]')) {\n return false;\n }\n if (element.closest('[inert]')) return false;\n if (element.getAttribute('aria-disabled') === 'true') return false;\n return element.tabIndex >= 0;\n });\n\n fallback?.focus({ preventScroll: true });\n });\n}\n\ninterface DialogAccessibilityOptions {\n open: boolean;\n isTop: boolean;\n keyboard: boolean;\n containerRef: { current: HTMLElement | null };\n onEscape: (event: KeyboardEvent) => void;\n}\n\nexport function useDialogAccessibility({\n open,\n isTop,\n keyboard,\n containerRef,\n onEscape,\n}: DialogAccessibilityOptions) {\n const focusRestoreTargetRef = useRef<HTMLElement | null>(null);\n const prevOpenRef = useRef(false);\n\n useLayoutEffect(() => {\n const wasOpen = prevOpenRef.current;\n if (open && !wasOpen) {\n focusRestoreTargetRef.current =\n document.activeElement instanceof HTMLElement\n ? document.activeElement\n : null;\n }\n if (!open && wasOpen) {\n restoreDialogFocus(focusRestoreTargetRef.current);\n focusRestoreTargetRef.current = null;\n }\n prevOpenRef.current = open;\n }, [open]);\n\n useEffect(() => {\n if (!open || !isTop || !containerRef.current) return;\n const container = containerRef.current;\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key !== 'Tab') return;\n if (isDialogChildOverlayActive(container)) return;\n\n const focusable = getDialogFocusableElements(container);\n if (focusable.length === 0) {\n if (document.activeElement !== container) {\n event.preventDefault();\n container.focus({ preventScroll: true });\n }\n return;\n }\n\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n\n if (event.shiftKey) {\n if (\n document.activeElement === first ||\n !container.contains(document.activeElement)\n ) {\n event.preventDefault();\n last.focus({ preventScroll: true });\n }\n } else if (\n document.activeElement === last ||\n !container.contains(document.activeElement)\n ) {\n event.preventDefault();\n first.focus({ preventScroll: true });\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n return () => document.removeEventListener('keydown', handleKeyDown);\n }, [containerRef, isTop, open]);\n\n useEffect(() => {\n if (!open || !isTop || !keyboard) return;\n\n const handleEscape = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return;\n queueMicrotask(() => {\n if (shouldDismissDialogEscape(event)) {\n onEscape(event);\n }\n });\n };\n\n window.addEventListener('keydown', handleEscape, true);\n return () => window.removeEventListener('keydown', handleEscape, true);\n }, [isTop, keyboard, onEscape, open]);\n}\n"],"mappings":";;AAEA,IAAM,qBACJ;AAEF,IAAM,qCAAqB,IAAI,SAAwB;AAEvD,SAAgB,sBAAsB,OAAsB;AAC1D,oBAAmB,IAAI,MAAM;;AAG/B,SAAgB,0BAA0B,OAAsB;AAC9D,QACE,CAAC,MAAM,iBACN,CAAC,MAAM,oBAAoB,mBAAmB,IAAI,MAAM;;AAI7D,SAAgB,2BAA2B,WAAwB;AACjE,QAAO,MAAM,KACX,UAAU,iBAA8B,mBAAmB,CAC5D,CAAC,QAAQ,YAAY;AACpB,MAAI,QAAQ,QAAQ,UAAU,CAAE,QAAO;AACvC,MAAI,QAAQ,aAAa,cAAc,KAAK,OAAQ,QAAO;AAC3D,MAAI,QAAQ,aAAa,gBAAgB,KAAK,OAAQ,QAAO;AAC7D,SAAO,QAAQ,YAAY;GAC3B;;AAGJ,SAAgB,2BAA2B,WAAwB;CACjE,MAAM,gBAAgB,SAAS;AAC/B,KAAI,EAAE,yBAAyB,aAAc,QAAO;CACpD,MAAM,gBAAgB,cAAc,QAClC,iFACD;AAED,QAAO,CAAC,CAAC,iBAAiB,kBAAkB;;AAG9C,SAAgB,yBAAyB,WAAwB;CAC/D,MAAM,gBAAgB,SAAS;CAC/B,MAAM,gBACJ,yBAAyB,cACrB,cAAc,QACZ,iFACD,GACD;AAEN,KACE,iBACA,kBAAkB,aAClB,cAAc,aAAa,OAAO,KAAK,YACvC,cAAc,aAAa,OAAO,KAAK,cAEvC;AAQF,EALkB,2BAA2B,UAAU,CAE3C,MAAM,YAAY,QAAQ,QAAQ,iBAAiB,OAAO,IACpE,QAEY,WAA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,UAAU,UAAU,SAAS;AAE1C,OAAI,MAAM,UACR;QACE,SAAS,kBAAkB,SAC3B,CAAC,UAAU,SAAS,SAAS,cAAc,EAC3C;AACA,WAAM,gBAAgB;AACtB,UAAK,MAAM,EAAE,eAAe,MAAM,CAAC;;cAGrC,SAAS,kBAAkB,QAC3B,CAAC,UAAU,SAAS,SAAS,cAAc,EAC3C;AACA,UAAM,gBAAgB;AACtB,UAAM,MAAM,EAAE,eAAe,MAAM,CAAC;;;AAIxC,WAAS,iBAAiB,WAAW,cAAc;AACnD,eAAa,SAAS,oBAAoB,WAAW,cAAc;IAClE;EAAC;EAAc;EAAO;EAAK,CAAC;AAE/B,iBAAgB;AACd,MAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAU;EAElC,MAAM,gBAAgB,UAAyB;AAC7C,OAAI,MAAM,QAAQ,SAAU;AAC5B,wBAAqB;AACnB,QAAI,0BAA0B,MAAM,CAClC,UAAS,MAAM;KAEjB;;AAGJ,SAAO,iBAAiB,WAAW,cAAc,KAAK;AACtD,eAAa,OAAO,oBAAoB,WAAW,cAAc,KAAK;IACrE;EAAC;EAAO;EAAU;EAAU;EAAK,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { default as React } from 'react';
2
+ export type SemanticOwnerAriaProps = Pick<React.AriaAttributes, 'aria-label' | 'aria-labelledby' | 'aria-describedby' | 'aria-invalid' | 'aria-required' | 'aria-busy' | 'aria-disabled' | 'aria-readonly'>;
3
+ export declare function getSemanticOwnerAriaProps(props: SemanticOwnerAriaProps): SemanticOwnerAriaProps;
@@ -0,0 +1,17 @@
1
+ //#region src/_utils/formControlSemanticOwner.ts
2
+ function getSemanticOwnerAriaProps(props) {
3
+ return {
4
+ "aria-label": props["aria-label"] || void 0,
5
+ "aria-labelledby": props["aria-labelledby"] || void 0,
6
+ "aria-describedby": props["aria-describedby"] || void 0,
7
+ "aria-invalid": props["aria-invalid"],
8
+ "aria-required": props["aria-required"],
9
+ "aria-busy": props["aria-busy"],
10
+ "aria-disabled": props["aria-disabled"],
11
+ "aria-readonly": props["aria-readonly"]
12
+ };
13
+ }
14
+ //#endregion
15
+ export { getSemanticOwnerAriaProps };
16
+
17
+ //# sourceMappingURL=formControlSemanticOwner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formControlSemanticOwner.js","names":[],"sources":["../../src/_utils/formControlSemanticOwner.ts"],"sourcesContent":["import React from 'react';\n\nexport type SemanticOwnerAriaProps = Pick<\n React.AriaAttributes,\n | 'aria-label'\n | 'aria-labelledby'\n | 'aria-describedby'\n | 'aria-invalid'\n | 'aria-required'\n | 'aria-busy'\n | 'aria-disabled'\n | 'aria-readonly'\n>;\n\nexport function getSemanticOwnerAriaProps(\n props: SemanticOwnerAriaProps,\n): SemanticOwnerAriaProps {\n return {\n 'aria-label': props['aria-label'] || undefined,\n 'aria-labelledby': props['aria-labelledby'] || undefined,\n 'aria-describedby': props['aria-describedby'] || undefined,\n 'aria-invalid': props['aria-invalid'],\n 'aria-required': props['aria-required'],\n 'aria-busy': props['aria-busy'],\n 'aria-disabled': props['aria-disabled'],\n 'aria-readonly': props['aria-readonly'],\n };\n}\n"],"mappings":";AAcA,SAAgB,0BACd,OACwB;AACxB,QAAO;EACL,cAAc,MAAM,iBAAiB;EACrC,mBAAmB,MAAM,sBAAsB;EAC/C,oBAAoB,MAAM,uBAAuB;EACjD,gBAAgB,MAAM;EACtB,iBAAiB,MAAM;EACvB,aAAa,MAAM;EACnB,iBAAiB,MAAM;EACvB,iBAAiB,MAAM;EACxB"}
@@ -129,16 +129,6 @@ function useTopModalContentZIndex() {
129
129
  const ordered = getOrderedEntries();
130
130
  return ordered[ordered.length - 1]?.contentZIndex;
131
131
  }
132
- function useBodyScrollLock(locked) {
133
- const ownerRef = useRef();
134
- if (!ownerRef.current) ownerRef.current = Symbol("body-scroll-lock");
135
- useLayoutEffect(() => {
136
- if (!locked) return;
137
- const owner = ownerRef.current;
138
- acquireBodyScrollLock(owner);
139
- return () => releaseBodyScrollLock(owner);
140
- }, [locked]);
141
- }
142
132
  function ModalLayerProvider({ id, children }) {
143
133
  return /* @__PURE__ */ jsx(ModalLayerContext.Provider, {
144
134
  value: id,
@@ -146,6 +136,6 @@ function ModalLayerProvider({ id, children }) {
146
136
  });
147
137
  }
148
138
  //#endregion
149
- export { ModalLayerProvider, useBodyScrollLock, useModalLayer, useTopModalContentZIndex };
139
+ export { ModalLayerProvider, useModalLayer, useTopModalContentZIndex };
150
140
 
151
141
  //# sourceMappingURL=overlayCoordinator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"overlayCoordinator.js","names":[],"sources":["../../src/_utils/overlayCoordinator.tsx"],"sourcesContent":["import React, {\n createContext,\n useContext,\n useLayoutEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport {\n FLOATING_LAYER_BASE_Z_INDEX,\n FLOATING_LAYER_STEP,\n} from './floatingLayer';\n\ninterface ModalLayerEntry {\n id: number;\n parentId?: number;\n requestedZIndex: number;\n openedAt: number;\n maskZIndex: number;\n contentZIndex: number;\n}\n\nexport interface ModalLayer {\n id: number;\n maskZIndex: number;\n contentZIndex: number;\n isTop: boolean;\n}\n\nconst ModalLayerContext = createContext<number | undefined>(undefined);\nconst entries = new Map<number, ModalLayerEntry>();\nconst listeners = new Set<() => void>();\nconst bodyScrollLockOwners = new Set<unknown>();\nlet nextId = 0;\nlet nextOpenedAt = 0;\nlet version = 0;\nlet bodyScrollLocked = false;\nlet previousBodyOverflow = '';\n\nfunction getOrderedEntries() {\n const orderedByOpen = Array.from(entries.values()).sort(\n (left, right) => left.openedAt - right.openedAt,\n );\n const ordered: ModalLayerEntry[] = [];\n const visited = new Set<number>();\n\n const visit = (entry: ModalLayerEntry) => {\n if (visited.has(entry.id)) return;\n const parent = entry.parentId ? entries.get(entry.parentId) : undefined;\n if (parent) visit(parent);\n visited.add(entry.id);\n ordered.push(entry);\n };\n\n orderedByOpen.forEach(visit);\n return ordered;\n}\n\nfunction notify() {\n version += 1;\n listeners.forEach((listener) => listener());\n}\n\nfunction updateLayers() {\n let nextZIndex = FLOATING_LAYER_BASE_Z_INDEX;\n getOrderedEntries().forEach((entry) => {\n entry.maskZIndex = Math.max(entry.requestedZIndex, nextZIndex);\n entry.contentZIndex = entry.maskZIndex + 1;\n nextZIndex = entry.maskZIndex + FLOATING_LAYER_STEP;\n });\n notify();\n}\n\nfunction acquireBodyScrollLock(owner: unknown) {\n if (typeof document === 'undefined') return;\n if (bodyScrollLockOwners.has(owner)) return;\n if (!bodyScrollLocked) {\n previousBodyOverflow = document.body.style.overflow;\n bodyScrollLocked = true;\n }\n bodyScrollLockOwners.add(owner);\n document.body.style.overflow = 'hidden';\n}\n\nfunction releaseBodyScrollLock(owner: unknown) {\n if (typeof document === 'undefined') return;\n bodyScrollLockOwners.delete(owner);\n if (bodyScrollLocked && bodyScrollLockOwners.size === 0) {\n document.body.style.overflow = previousBodyOverflow;\n bodyScrollLocked = false;\n }\n}\n\nfunction registerModal(id: number, requestedZIndex: number, parentId?: number) {\n entries.set(id, {\n id,\n parentId,\n requestedZIndex,\n openedAt: ++nextOpenedAt,\n maskZIndex: requestedZIndex,\n contentZIndex: requestedZIndex + 1,\n });\n acquireBodyScrollLock(id);\n updateLayers();\n}\n\nfunction unregisterModal(id: number) {\n if (!entries.delete(id)) return;\n releaseBodyScrollLock(id);\n updateLayers();\n}\n\nfunction updateModal(id: number, requestedZIndex: number, parentId?: number) {\n const entry = entries.get(id);\n if (\n !entry ||\n (entry.requestedZIndex === requestedZIndex && entry.parentId === parentId)\n )\n return;\n entry.requestedZIndex = requestedZIndex;\n entry.parentId = parentId;\n updateLayers();\n}\n\nfunction subscribe(listener: () => void) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n}\n\nfunction getVersion() {\n return version;\n}\n\nexport function useModalLayer(\n open: boolean,\n requestedZIndex = FLOATING_LAYER_BASE_Z_INDEX,\n): ModalLayer {\n const parentId = useContext(ModalLayerContext);\n const idRef = useRef<number>();\n const layerOptionsRef = useRef({ parentId, requestedZIndex });\n layerOptionsRef.current = { parentId, requestedZIndex };\n if (!idRef.current) idRef.current = ++nextId;\n const id = idRef.current;\n\n useSyncExternalStore(subscribe, getVersion, getVersion);\n\n useLayoutEffect(() => {\n if (!open) return;\n registerModal(\n id,\n layerOptionsRef.current.requestedZIndex,\n layerOptionsRef.current.parentId,\n );\n return () => unregisterModal(id);\n }, [id, open]);\n\n useLayoutEffect(() => {\n if (open) updateModal(id, requestedZIndex, parentId);\n }, [id, open, parentId, requestedZIndex]);\n\n const entry = entries.get(id);\n const ordered = getOrderedEntries();\n const topEntry = ordered[ordered.length - 1];\n\n return {\n id,\n maskZIndex: entry?.maskZIndex ?? requestedZIndex,\n contentZIndex: entry?.contentZIndex ?? requestedZIndex + 1,\n isTop: entry ? topEntry?.id === id : true,\n };\n}\n\nexport function useTopModalContentZIndex() {\n useSyncExternalStore(subscribe, getVersion, getVersion);\n const ordered = getOrderedEntries();\n return ordered[ordered.length - 1]?.contentZIndex;\n}\n\nexport function useBodyScrollLock(locked: boolean) {\n const ownerRef = useRef<symbol>();\n if (!ownerRef.current) ownerRef.current = Symbol('body-scroll-lock');\n\n useLayoutEffect(() => {\n if (!locked) return;\n const owner = ownerRef.current!;\n acquireBodyScrollLock(owner);\n return () => releaseBodyScrollLock(owner);\n }, [locked]);\n}\n\nexport function ModalLayerProvider({\n id,\n children,\n}: {\n id: number;\n children: React.ReactNode;\n}) {\n return (\n <ModalLayerContext.Provider value={id}>\n {children}\n </ModalLayerContext.Provider>\n );\n}\n"],"mappings":";;;;AA4BA,IAAM,oBAAoB,cAAkC,OAAU;AACtE,IAAM,0BAAU,IAAI,KAA8B;AAClD,IAAM,4BAAY,IAAI,KAAiB;AACvC,IAAM,uCAAuB,IAAI,KAAc;AAC/C,IAAI,SAAS;AACb,IAAI,eAAe;AACnB,IAAI,UAAU;AACd,IAAI,mBAAmB;AACvB,IAAI,uBAAuB;AAE3B,SAAS,oBAAoB;CAC3B,MAAM,gBAAgB,MAAM,KA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BAAqB,WAAW,YAAY,WAAW;CACvD,MAAM,UAAU,mBAAmB;AACnC,QAAO,QAAQ,QAAQ,SAAS,IAAI;;AAGtC,SAAgB,kBAAkB,QAAiB;CACjD,MAAM,WAAW,QAAgB;AACjC,KAAI,CAAC,SAAS,QAAS,UAAS,UAAU,OAAO,mBAAmB;AAEpE,uBAAsB;AACpB,MAAI,CAAC,OAAQ;EACb,MAAM,QAAQ,SAAS;AACvB,wBAAsB,MAAM;AAC5B,eAAa,sBAAsB,MAAM;IACxC,CAAC,OAAO,CAAC;;AAGd,SAAgB,mBAAmB,EACjC,IACA,YAIC;AACD,QACE,oBAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAChC;EAC0B,CAAA"}
1
+ {"version":3,"file":"overlayCoordinator.js","names":[],"sources":["../../src/_utils/overlayCoordinator.tsx"],"sourcesContent":["import React, {\n createContext,\n useContext,\n useLayoutEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport {\n FLOATING_LAYER_BASE_Z_INDEX,\n FLOATING_LAYER_STEP,\n} from './floatingLayer';\n\ninterface ModalLayerEntry {\n id: number;\n parentId?: number;\n requestedZIndex: number;\n openedAt: number;\n maskZIndex: number;\n contentZIndex: number;\n}\n\nexport interface ModalLayer {\n id: number;\n maskZIndex: number;\n contentZIndex: number;\n isTop: boolean;\n}\n\nconst ModalLayerContext = createContext<number | undefined>(undefined);\nconst entries = new Map<number, ModalLayerEntry>();\nconst listeners = new Set<() => void>();\nconst bodyScrollLockOwners = new Set<unknown>();\nlet nextId = 0;\nlet nextOpenedAt = 0;\nlet version = 0;\nlet bodyScrollLocked = false;\nlet previousBodyOverflow = '';\n\nfunction getOrderedEntries() {\n const orderedByOpen = Array.from(entries.values()).sort(\n (left, right) => left.openedAt - right.openedAt,\n );\n const ordered: ModalLayerEntry[] = [];\n const visited = new Set<number>();\n\n const visit = (entry: ModalLayerEntry) => {\n if (visited.has(entry.id)) return;\n const parent = entry.parentId ? entries.get(entry.parentId) : undefined;\n if (parent) visit(parent);\n visited.add(entry.id);\n ordered.push(entry);\n };\n\n orderedByOpen.forEach(visit);\n return ordered;\n}\n\nfunction notify() {\n version += 1;\n listeners.forEach((listener) => listener());\n}\n\nfunction updateLayers() {\n let nextZIndex = FLOATING_LAYER_BASE_Z_INDEX;\n getOrderedEntries().forEach((entry) => {\n entry.maskZIndex = Math.max(entry.requestedZIndex, nextZIndex);\n entry.contentZIndex = entry.maskZIndex + 1;\n nextZIndex = entry.maskZIndex + FLOATING_LAYER_STEP;\n });\n notify();\n}\n\nfunction acquireBodyScrollLock(owner: unknown) {\n if (typeof document === 'undefined') return;\n if (bodyScrollLockOwners.has(owner)) return;\n if (!bodyScrollLocked) {\n previousBodyOverflow = document.body.style.overflow;\n bodyScrollLocked = true;\n }\n bodyScrollLockOwners.add(owner);\n document.body.style.overflow = 'hidden';\n}\n\nfunction releaseBodyScrollLock(owner: unknown) {\n if (typeof document === 'undefined') return;\n bodyScrollLockOwners.delete(owner);\n if (bodyScrollLocked && bodyScrollLockOwners.size === 0) {\n document.body.style.overflow = previousBodyOverflow;\n bodyScrollLocked = false;\n }\n}\n\nfunction registerModal(id: number, requestedZIndex: number, parentId?: number) {\n entries.set(id, {\n id,\n parentId,\n requestedZIndex,\n openedAt: ++nextOpenedAt,\n maskZIndex: requestedZIndex,\n contentZIndex: requestedZIndex + 1,\n });\n acquireBodyScrollLock(id);\n updateLayers();\n}\n\nfunction unregisterModal(id: number) {\n if (!entries.delete(id)) return;\n releaseBodyScrollLock(id);\n updateLayers();\n}\n\nfunction updateModal(id: number, requestedZIndex: number, parentId?: number) {\n const entry = entries.get(id);\n if (\n !entry ||\n (entry.requestedZIndex === requestedZIndex && entry.parentId === parentId)\n )\n return;\n entry.requestedZIndex = requestedZIndex;\n entry.parentId = parentId;\n updateLayers();\n}\n\nfunction subscribe(listener: () => void) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n}\n\nfunction getVersion() {\n return version;\n}\n\nexport function useModalLayer(\n open: boolean,\n requestedZIndex = FLOATING_LAYER_BASE_Z_INDEX,\n): ModalLayer {\n const parentId = useContext(ModalLayerContext);\n const idRef = useRef<number>();\n const layerOptionsRef = useRef({ parentId, requestedZIndex });\n layerOptionsRef.current = { parentId, requestedZIndex };\n if (!idRef.current) idRef.current = ++nextId;\n const id = idRef.current;\n\n useSyncExternalStore(subscribe, getVersion, getVersion);\n\n useLayoutEffect(() => {\n if (!open) return;\n registerModal(\n id,\n layerOptionsRef.current.requestedZIndex,\n layerOptionsRef.current.parentId,\n );\n return () => unregisterModal(id);\n }, [id, open]);\n\n useLayoutEffect(() => {\n if (open) updateModal(id, requestedZIndex, parentId);\n }, [id, open, parentId, requestedZIndex]);\n\n const entry = entries.get(id);\n const ordered = getOrderedEntries();\n const topEntry = ordered[ordered.length - 1];\n\n return {\n id,\n maskZIndex: entry?.maskZIndex ?? requestedZIndex,\n contentZIndex: entry?.contentZIndex ?? requestedZIndex + 1,\n isTop: entry ? topEntry?.id === id : true,\n };\n}\n\nexport function useTopModalContentZIndex() {\n useSyncExternalStore(subscribe, getVersion, getVersion);\n const ordered = getOrderedEntries();\n return ordered[ordered.length - 1]?.contentZIndex;\n}\n\nexport function useBodyScrollLock(locked: boolean) {\n const ownerRef = useRef<symbol>();\n if (!ownerRef.current) ownerRef.current = Symbol('body-scroll-lock');\n\n useLayoutEffect(() => {\n if (!locked) return;\n const owner = ownerRef.current!;\n acquireBodyScrollLock(owner);\n return () => releaseBodyScrollLock(owner);\n }, [locked]);\n}\n\nexport function ModalLayerProvider({\n id,\n children,\n}: {\n id: number;\n children: React.ReactNode;\n}) {\n return (\n <ModalLayerContext.Provider value={id}>\n {children}\n </ModalLayerContext.Provider>\n );\n}\n"],"mappings":";;;;AA4BA,IAAM,oBAAoB,cAAkC,OAAU;AACtE,IAAM,0BAAU,IAAI,KAA8B;AAClD,IAAM,4BAAY,IAAI,KAAiB;AACvC,IAAM,uCAAuB,IAAI,KAAc;AAC/C,IAAI,SAAS;AACb,IAAI,eAAe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