@octanejs/base-ui 0.1.30 → 0.1.32

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 (201) hide show
  1. package/dist/cjs/accordion.cjs +497 -0
  2. package/dist/cjs/alert-dialog.cjs +65 -0
  3. package/dist/cjs/avatar.cjs +234 -0
  4. package/dist/cjs/button.cjs +54 -0
  5. package/dist/cjs/checkbox-group.cjs +165 -0
  6. package/dist/cjs/checkbox.cjs +475 -0
  7. package/dist/cjs/collapsible.cjs +700 -0
  8. package/dist/cjs/context-menu.cjs +257 -0
  9. package/dist/cjs/csp-provider.cjs +40 -0
  10. package/dist/cjs/dialog.cjs +741 -0
  11. package/dist/cjs/direction-provider.cjs +35 -0
  12. package/dist/cjs/field.cjs +559 -0
  13. package/dist/cjs/fieldset.cjs +101 -0
  14. package/dist/cjs/form.cjs +177 -0
  15. package/dist/cjs/index.cjs +133 -0
  16. package/dist/cjs/input.cjs +32 -0
  17. package/dist/cjs/internal.cjs +51 -0
  18. package/dist/cjs/menu.cjs +2420 -0
  19. package/dist/cjs/menubar.cjs +132 -0
  20. package/dist/cjs/merge-props.cjs +34 -0
  21. package/dist/cjs/meter.cjs +169 -0
  22. package/dist/cjs/number-field.cjs +812 -0
  23. package/dist/cjs/popover.cjs +966 -0
  24. package/dist/cjs/preview-card.cjs +632 -0
  25. package/dist/cjs/progress.cjs +206 -0
  26. package/dist/cjs/radio-group.cjs +264 -0
  27. package/dist/cjs/radio.cjs +327 -0
  28. package/dist/cjs/separator.cjs +44 -0
  29. package/dist/cjs/slider.cjs +1384 -0
  30. package/dist/cjs/switch.cjs +306 -0
  31. package/dist/cjs/tabs.cjs +727 -0
  32. package/dist/cjs/toast.cjs +1766 -0
  33. package/dist/cjs/toggle-group.cjs +118 -0
  34. package/dist/cjs/toggle.cjs +121 -0
  35. package/dist/cjs/tooltip.cjs +835 -0
  36. package/dist/cjs/unstable-use-media-query.cjs +79 -0
  37. package/dist/cjs/use-render.cjs +40 -0
  38. package/dist/cjs/utils/CSPContext.cjs +38 -0
  39. package/dist/cjs/utils/CheckboxGroupContext.cjs +40 -0
  40. package/dist/cjs/utils/CompositeRootContext.cjs +40 -0
  41. package/dist/cjs/utils/ContextMenuRootContext.cjs +42 -0
  42. package/dist/cjs/utils/DirectionContext.cjs +34 -0
  43. package/dist/cjs/utils/FloatingPortalLite.cjs +47 -0
  44. package/dist/cjs/utils/InternalBackdrop.cjs +49 -0
  45. package/dist/cjs/utils/MenubarContext.cjs +40 -0
  46. package/dist/cjs/utils/RadioGroupContext.cjs +34 -0
  47. package/dist/cjs/utils/RequestQueue.cjs +111 -0
  48. package/dist/cjs/utils/TimeoutManager.cjs +50 -0
  49. package/dist/cjs/utils/ToggleGroupContext.cjs +40 -0
  50. package/dist/cjs/utils/adaptiveOriginMiddleware.cjs +94 -0
  51. package/dist/cjs/utils/addEventListener.cjs +33 -0
  52. package/dist/cjs/utils/areArraysEqual.cjs +30 -0
  53. package/dist/cjs/utils/clamp.cjs +30 -0
  54. package/dist/cjs/utils/closePart.cjs +70 -0
  55. package/dist/cjs/utils/collapsibleOpenStateMapping.cjs +42 -0
  56. package/dist/cjs/utils/composeRefs.cjs +68 -0
  57. package/dist/cjs/utils/composite/CompositeItem.cjs +59 -0
  58. package/dist/cjs/utils/composite/CompositeList.cjs +177 -0
  59. package/dist/cjs/utils/composite/CompositeListContext.cjs +43 -0
  60. package/dist/cjs/utils/composite/CompositeRoot.cjs +118 -0
  61. package/dist/cjs/utils/composite/grid-utils.cjs +343 -0
  62. package/dist/cjs/utils/composite/gridNavigation.cjs +92 -0
  63. package/dist/cjs/utils/composite/keys.cjs +174 -0
  64. package/dist/cjs/utils/composite/list-utils.cjs +90 -0
  65. package/dist/cjs/utils/composite/useCompositeItem.cjs +63 -0
  66. package/dist/cjs/utils/composite/useCompositeListItem.cjs +104 -0
  67. package/dist/cjs/utils/composite/useCompositeRoot.cjs +263 -0
  68. package/dist/cjs/utils/constants.cjs +56 -0
  69. package/dist/cjs/utils/contains.cjs +46 -0
  70. package/dist/cjs/utils/createChangeEventDetails.cjs +92 -0
  71. package/dist/cjs/utils/dom.cjs +35 -0
  72. package/dist/cjs/utils/empty.cjs +34 -0
  73. package/dist/cjs/utils/field/FieldItemContext.cjs +34 -0
  74. package/dist/cjs/utils/field/FieldRootContext.cjs +80 -0
  75. package/dist/cjs/utils/field/FormContext.cjs +41 -0
  76. package/dist/cjs/utils/field/LabelableContext.cjs +43 -0
  77. package/dist/cjs/utils/field/LabelableProvider.cjs +115 -0
  78. package/dist/cjs/utils/field/constants.cjs +68 -0
  79. package/dist/cjs/utils/field/getCombinedFieldValidityData.cjs +36 -0
  80. package/dist/cjs/utils/field/useAriaLabelledBy.cjs +87 -0
  81. package/dist/cjs/utils/field/useFieldControlRegistration.cjs +165 -0
  82. package/dist/cjs/utils/field/useFieldValidation.cjs +285 -0
  83. package/dist/cjs/utils/field/useLabel.cjs +99 -0
  84. package/dist/cjs/utils/field/useLabelableId.cjs +105 -0
  85. package/dist/cjs/utils/field/useRegisterFieldControl.cjs +60 -0
  86. package/dist/cjs/utils/findRootOwnerId.cjs +37 -0
  87. package/dist/cjs/utils/floating/FloatingDelayGroup.cjs +219 -0
  88. package/dist/cjs/utils/floating/FloatingFocusManager.cjs +685 -0
  89. package/dist/cjs/utils/floating/FloatingPortal.cjs +230 -0
  90. package/dist/cjs/utils/floating/FloatingRootStore.cjs +87 -0
  91. package/dist/cjs/utils/floating/FloatingTree.cjs +86 -0
  92. package/dist/cjs/utils/floating/FloatingTreeStore.cjs +41 -0
  93. package/dist/cjs/utils/floating/FocusGuard.cjs +54 -0
  94. package/dist/cjs/utils/floating/composite.cjs +42 -0
  95. package/dist/cjs/utils/floating/constants.cjs +34 -0
  96. package/dist/cjs/utils/floating/createAttribute.cjs +30 -0
  97. package/dist/cjs/utils/floating/createEventEmitter.cjs +44 -0
  98. package/dist/cjs/utils/floating/element.cjs +103 -0
  99. package/dist/cjs/utils/floating/enqueueFocus.cjs +51 -0
  100. package/dist/cjs/utils/floating/event.cjs +65 -0
  101. package/dist/cjs/utils/floating/getEmptyRootContext.cjs +42 -0
  102. package/dist/cjs/utils/floating/gridNavigation.cjs +45 -0
  103. package/dist/cjs/utils/floating/markOthers.cjs +181 -0
  104. package/dist/cjs/utils/floating/nodes.cjs +48 -0
  105. package/dist/cjs/utils/floating/safePolygon.cjs +301 -0
  106. package/dist/cjs/utils/floating/tabbable.cjs +242 -0
  107. package/dist/cjs/utils/floating/types.cjs +16 -0
  108. package/dist/cjs/utils/floating/useClick.cjs +153 -0
  109. package/dist/cjs/utils/floating/useClientPoint.cjs +225 -0
  110. package/dist/cjs/utils/floating/useDismiss.cjs +506 -0
  111. package/dist/cjs/utils/floating/useFloating.cjs +186 -0
  112. package/dist/cjs/utils/floating/useFloatingRootContext.cjs +75 -0
  113. package/dist/cjs/utils/floating/useFocus.cjs +184 -0
  114. package/dist/cjs/utils/floating/useHoverFloatingInteraction.cjs +231 -0
  115. package/dist/cjs/utils/floating/useHoverInteractionSharedState.cjs +113 -0
  116. package/dist/cjs/utils/floating/useHoverReferenceInteraction.cjs +380 -0
  117. package/dist/cjs/utils/floating/useHoverShared.cjs +65 -0
  118. package/dist/cjs/utils/floating/useListNavigation.cjs +665 -0
  119. package/dist/cjs/utils/floating/useSyncedFloatingRootContext.cjs +91 -0
  120. package/dist/cjs/utils/floating/useTypeahead.cjs +187 -0
  121. package/dist/cjs/utils/formatNumber.cjs +60 -0
  122. package/dist/cjs/utils/generateId.cjs +32 -0
  123. package/dist/cjs/utils/getCssDimensions.cjs +42 -0
  124. package/dist/cjs/utils/getDefaultFormSubmitter.cjs +42 -0
  125. package/dist/cjs/utils/getDisabledMountTransitionStyles.cjs +32 -0
  126. package/dist/cjs/utils/getElementRef.cjs +35 -0
  127. package/dist/cjs/utils/getPseudoElementBounds.cjs +56 -0
  128. package/dist/cjs/utils/getStateAttributesProps.cjs +46 -0
  129. package/dist/cjs/utils/hideMiddleware.cjs +42 -0
  130. package/dist/cjs/utils/inertValue.cjs +30 -0
  131. package/dist/cjs/utils/matchesFocusVisible.cjs +38 -0
  132. package/dist/cjs/utils/mergeCleanups.cjs +37 -0
  133. package/dist/cjs/utils/mergeObjects.cjs +39 -0
  134. package/dist/cjs/utils/mergeProps.cjs +182 -0
  135. package/dist/cjs/utils/noop.cjs +29 -0
  136. package/dist/cjs/utils/number/constants.cjs +34 -0
  137. package/dist/cjs/utils/number/parse.cjs +258 -0
  138. package/dist/cjs/utils/number/types.cjs +16 -0
  139. package/dist/cjs/utils/number/validate.cjs +104 -0
  140. package/dist/cjs/utils/owner.cjs +35 -0
  141. package/dist/cjs/utils/platform.cjs +83 -0
  142. package/dist/cjs/utils/popupStateMapping.cjs +74 -0
  143. package/dist/cjs/utils/popups/index.cjs +39 -0
  144. package/dist/cjs/utils/popups/inlineRect.cjs +218 -0
  145. package/dist/cjs/utils/popups/popupStoreUtils.cjs +379 -0
  146. package/dist/cjs/utils/popups/popupTriggerMap.cjs +76 -0
  147. package/dist/cjs/utils/popups/store.cjs +118 -0
  148. package/dist/cjs/utils/popups/useTriggerFocusGuards.cjs +72 -0
  149. package/dist/cjs/utils/resolveAriaLabelledBy.cjs +35 -0
  150. package/dist/cjs/utils/resolveClassName.cjs +30 -0
  151. package/dist/cjs/utils/resolveRef.cjs +33 -0
  152. package/dist/cjs/utils/resolveStyle.cjs +30 -0
  153. package/dist/cjs/utils/serializeValue.cjs +40 -0
  154. package/dist/cjs/utils/slider/asc.cjs +30 -0
  155. package/dist/cjs/utils/slider/getMidpoint.cjs +34 -0
  156. package/dist/cjs/utils/slider/getPushedThumbValues.cjs +73 -0
  157. package/dist/cjs/utils/slider/getSliderValue.cjs +42 -0
  158. package/dist/cjs/utils/slider/replaceArrayItemAtIndex.cjs +33 -0
  159. package/dist/cjs/utils/slider/resolveThumbCollision.cjs +155 -0
  160. package/dist/cjs/utils/slider/roundValueToStep.cjs +45 -0
  161. package/dist/cjs/utils/slider/validateMinimumDistance.cjs +40 -0
  162. package/dist/cjs/utils/slider/valueArrayToPercentages.cjs +36 -0
  163. package/dist/cjs/utils/store/ReactStore.cjs +135 -0
  164. package/dist/cjs/utils/store/Store.cjs +83 -0
  165. package/dist/cjs/utils/store/createSelector.cjs +74 -0
  166. package/dist/cjs/utils/store/useStore.cjs +51 -0
  167. package/dist/cjs/utils/stringifyLocale.cjs +36 -0
  168. package/dist/cjs/utils/useAnchorPositioning.cjs +421 -0
  169. package/dist/cjs/utils/useAnchoredPopupScrollLock.cjs +59 -0
  170. package/dist/cjs/utils/useAnimationFrame.cjs +93 -0
  171. package/dist/cjs/utils/useAnimationsFinished.cjs +98 -0
  172. package/dist/cjs/utils/useBaseUiId.cjs +36 -0
  173. package/dist/cjs/utils/useButton.cjs +177 -0
  174. package/dist/cjs/utils/useCheckboxGroupParent.cjs +114 -0
  175. package/dist/cjs/utils/useControlled.cjs +47 -0
  176. package/dist/cjs/utils/useEnhancedClickHandler.cjs +60 -0
  177. package/dist/cjs/utils/useFocusableWhenDisabled.cjs +77 -0
  178. package/dist/cjs/utils/useForcedRerendering.cjs +35 -0
  179. package/dist/cjs/utils/useIsHydrating.cjs +44 -0
  180. package/dist/cjs/utils/useMixedToggleClickHandler.cjs +66 -0
  181. package/dist/cjs/utils/useOnFirstRender.cjs +35 -0
  182. package/dist/cjs/utils/useOnMount.cjs +36 -0
  183. package/dist/cjs/utils/useOpenChangeComplete.cjs +57 -0
  184. package/dist/cjs/utils/useOpenInteractionType.cjs +69 -0
  185. package/dist/cjs/utils/usePopupAutoResize.cjs +191 -0
  186. package/dist/cjs/utils/usePopupViewport.cjs +283 -0
  187. package/dist/cjs/utils/usePositioner.cjs +53 -0
  188. package/dist/cjs/utils/usePressAndHold.cjs +51 -0
  189. package/dist/cjs/utils/usePreviousValue.cjs +47 -0
  190. package/dist/cjs/utils/useRefWithInit.cjs +41 -0
  191. package/dist/cjs/utils/useRegisteredLabelId.cjs +48 -0
  192. package/dist/cjs/utils/useRenderElement.cjs +106 -0
  193. package/dist/cjs/utils/useScrollLock.cjs +232 -0
  194. package/dist/cjs/utils/useStableCallback.cjs +41 -0
  195. package/dist/cjs/utils/useTimeout.cjs +66 -0
  196. package/dist/cjs/utils/useTransitionStatus.cjs +116 -0
  197. package/dist/cjs/utils/useValueAsRef.cjs +43 -0
  198. package/dist/cjs/utils/useValueChanged.cjs +55 -0
  199. package/dist/cjs/utils/valueToPercent.cjs +30 -0
  200. package/dist/cjs/utils/visuallyHidden.cjs +49 -0
  201. package/package.json +20 -8
@@ -0,0 +1,727 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var tabs_exports = {};
20
+ __export(tabs_exports, {
21
+ Tabs: () => Tabs,
22
+ TabsList: () => TabsList,
23
+ TabsPanel: () => TabsPanel,
24
+ TabsRoot: () => TabsRoot,
25
+ TabsTab: () => TabsTab,
26
+ useTabsListContext: () => useTabsListContext,
27
+ useTabsRootContext: () => useTabsRootContext
28
+ });
29
+ module.exports = __toCommonJS(tabs_exports);
30
+ var import_octane = require("octane");
31
+ var import_internal = require("./internal.cjs");
32
+ var import_useRenderElement = require("./utils/useRenderElement.cjs");
33
+ var import_useBaseUiId = require("./utils/useBaseUiId.cjs");
34
+ var import_useButton = require("./utils/useButton.cjs");
35
+ var import_useControlled = require("./utils/useControlled.cjs");
36
+ var import_useStableCallback = require("./utils/useStableCallback.cjs");
37
+ var import_inertValue = require("./utils/inertValue.cjs");
38
+ var import_owner = require("./utils/owner.cjs");
39
+ var import_element = require("./utils/floating/element.cjs");
40
+ var import_useTransitionStatus = require("./utils/useTransitionStatus.cjs");
41
+ var import_useOpenChangeComplete = require("./utils/useOpenChangeComplete.cjs");
42
+ var import_CompositeList = require("./utils/composite/CompositeList.cjs");
43
+ var import_CompositeRoot = require("./utils/composite/CompositeRoot.cjs");
44
+ var import_useCompositeItem = require("./utils/composite/useCompositeItem.cjs");
45
+ var import_useCompositeListItem = require("./utils/composite/useCompositeListItem.cjs");
46
+ var import_keys = require("./utils/composite/keys.cjs");
47
+ var import_createChangeEventDetails = require("./utils/createChangeEventDetails.cjs");
48
+ const EMPTY_DISABLED_INDICES = [];
49
+ const tabsStateAttributesMapping = {
50
+ tabActivationDirection: (dir) => ({
51
+ "data-activation-direction": dir
52
+ })
53
+ };
54
+ const TabsRootContext = (0, import_octane.createContext)(void 0);
55
+ function useTabsRootContext() {
56
+ const context = (0, import_octane.useContext)(TabsRootContext);
57
+ if (context === void 0) {
58
+ throw new Error(
59
+ "Base UI: TabsRootContext is missing. Tabs parts must be placed within <Tabs.Root>."
60
+ );
61
+ }
62
+ return context;
63
+ }
64
+ const TabsListContext = (0, import_octane.createContext)(void 0);
65
+ function useTabsListContext() {
66
+ const context = (0, import_octane.useContext)(TabsListContext);
67
+ if (context === void 0) {
68
+ throw new Error(
69
+ "Base UI: TabsListContext is missing. TabsList parts must be placed within <Tabs.List>."
70
+ );
71
+ }
72
+ return context;
73
+ }
74
+ function computeActivationDirection(oldValue, newValue, orientation, tabMap) {
75
+ if (oldValue == null || newValue == null) {
76
+ return "none";
77
+ }
78
+ let oldTab = null;
79
+ let newTab = null;
80
+ for (const [tabElement, tabMetadata] of tabMap.entries()) {
81
+ if (tabMetadata == null) {
82
+ continue;
83
+ }
84
+ const tabValue = tabMetadata.value ?? tabMetadata.index;
85
+ if (oldValue === tabValue) {
86
+ oldTab = tabElement;
87
+ }
88
+ if (newValue === tabValue) {
89
+ newTab = tabElement;
90
+ }
91
+ if (oldTab != null && newTab != null) {
92
+ break;
93
+ }
94
+ }
95
+ if (oldTab == null || newTab == null) {
96
+ if (oldTab !== newTab && (typeof oldValue === "number" || typeof oldValue === "string") && typeof oldValue === typeof newValue) {
97
+ if (orientation === "horizontal") {
98
+ return newValue > oldValue ? "right" : "left";
99
+ }
100
+ return newValue > oldValue ? "down" : "up";
101
+ }
102
+ return "none";
103
+ }
104
+ const oldRect = oldTab.getBoundingClientRect();
105
+ const newRect = newTab.getBoundingClientRect();
106
+ if (orientation === "horizontal") {
107
+ if (newRect.left < oldRect.left) {
108
+ return "left";
109
+ }
110
+ if (newRect.left > oldRect.left) {
111
+ return "right";
112
+ }
113
+ } else {
114
+ if (newRect.top < oldRect.top) {
115
+ return "up";
116
+ }
117
+ if (newRect.top > oldRect.top) {
118
+ return "down";
119
+ }
120
+ }
121
+ return "none";
122
+ }
123
+ function TabsRoot(props) {
124
+ const slot = (0, import_internal.S)("TabsRoot");
125
+ const {
126
+ className,
127
+ defaultValue: defaultValueProp = 0,
128
+ onValueChange: onValueChangeProp,
129
+ orientation = "horizontal",
130
+ render,
131
+ value: valueProp,
132
+ style,
133
+ ref,
134
+ ...elementProps
135
+ } = props;
136
+ const hasExplicitDefaultValueProp = props.defaultValue !== void 0;
137
+ const tabPanelRefs = (0, import_octane.useRef)([], (0, import_internal.subSlot)(slot, "panelRefs"));
138
+ const [mountedTabPanels, setMountedTabPanels] = (0, import_octane.useState)(
139
+ () => /* @__PURE__ */ new Map(),
140
+ (0, import_internal.subSlot)(slot, "mountedPanels")
141
+ );
142
+ const [value, setValue] = (0, import_useControlled.useControlled)(
143
+ { controlled: valueProp, default: defaultValueProp, name: "Tabs", state: "value" },
144
+ (0, import_internal.subSlot)(slot, "value")
145
+ );
146
+ const isControlled = valueProp !== void 0;
147
+ const [tabMap, setTabMap] = (0, import_octane.useState)(() => /* @__PURE__ */ new Map(), (0, import_internal.subSlot)(slot, "tabMap"));
148
+ const lastKnownTabElementRef = (0, import_octane.useRef)(void 0, (0, import_internal.subSlot)(slot, "lastTabEl"));
149
+ const getTabElementBySelectedValue = (0, import_useStableCallback.useStableCallback)(
150
+ (selectedValue) => {
151
+ if (selectedValue === void 0) {
152
+ return null;
153
+ }
154
+ for (const [tabElement, tabMetadata] of tabMap.entries()) {
155
+ if (tabMetadata != null && selectedValue === (tabMetadata.value ?? tabMetadata.index)) {
156
+ return tabElement;
157
+ }
158
+ }
159
+ return null;
160
+ },
161
+ (0, import_internal.subSlot)(slot, "getTabEl")
162
+ );
163
+ const [activationDirectionState, setActivationDirectionState] = (0, import_octane.useState)(
164
+ () => ({ previousValue: value, tabActivationDirection: "none" }),
165
+ (0, import_internal.subSlot)(slot, "activationDir")
166
+ );
167
+ const { previousValue, tabActivationDirection: committedTabActivationDirection } = activationDirectionState;
168
+ let tabActivationDirection = committedTabActivationDirection;
169
+ let directionComputationIncomplete = false;
170
+ if (previousValue !== value) {
171
+ tabActivationDirection = computeActivationDirection(previousValue, value, orientation, tabMap);
172
+ directionComputationIncomplete = previousValue != null && value != null && getTabElementBySelectedValue(value) == null;
173
+ }
174
+ const nextPreviousValue = directionComputationIncomplete ? previousValue : value;
175
+ const shouldSyncActivationDirectionState = previousValue !== nextPreviousValue || committedTabActivationDirection !== tabActivationDirection;
176
+ (0, import_octane.useLayoutEffect)(
177
+ () => {
178
+ if (!shouldSyncActivationDirectionState) {
179
+ return;
180
+ }
181
+ setActivationDirectionState({
182
+ previousValue: nextPreviousValue,
183
+ tabActivationDirection
184
+ });
185
+ },
186
+ [nextPreviousValue, shouldSyncActivationDirectionState, tabActivationDirection],
187
+ (0, import_internal.subSlot)(slot, "e:syncDir")
188
+ );
189
+ const onValueChange = (0, import_useStableCallback.useStableCallback)(
190
+ (newValue, eventDetails) => {
191
+ const activationDirection = computeActivationDirection(value, newValue, orientation, tabMap);
192
+ eventDetails.activationDirection = activationDirection;
193
+ onValueChangeProp?.(newValue, eventDetails);
194
+ if (eventDetails.isCanceled) {
195
+ return;
196
+ }
197
+ setValue(newValue);
198
+ },
199
+ (0, import_internal.subSlot)(slot, "onValueChange")
200
+ );
201
+ const notifyAutomaticValueChange = (0, import_useStableCallback.useStableCallback)(
202
+ (nextValue, reason) => {
203
+ onValueChangeProp?.(
204
+ nextValue,
205
+ (0, import_createChangeEventDetails.createChangeEventDetails)(reason, void 0, void 0, {
206
+ activationDirection: "none"
207
+ })
208
+ );
209
+ },
210
+ (0, import_internal.subSlot)(slot, "notifyAuto")
211
+ );
212
+ const registerMountedTabPanel = (0, import_useStableCallback.useStableCallback)(
213
+ (panelValue, panelId) => {
214
+ setMountedTabPanels((prev) => {
215
+ if (prev.get(panelValue) === panelId) {
216
+ return prev;
217
+ }
218
+ const next = new Map(prev);
219
+ next.set(panelValue, panelId);
220
+ return next;
221
+ });
222
+ },
223
+ (0, import_internal.subSlot)(slot, "registerPanel")
224
+ );
225
+ const unregisterMountedTabPanel = (0, import_useStableCallback.useStableCallback)(
226
+ (panelValue, panelId) => {
227
+ setMountedTabPanels((prev) => {
228
+ if (!prev.has(panelValue) || prev.get(panelValue) !== panelId) {
229
+ return prev;
230
+ }
231
+ const next = new Map(prev);
232
+ next.delete(panelValue);
233
+ return next;
234
+ });
235
+ },
236
+ (0, import_internal.subSlot)(slot, "unregisterPanel")
237
+ );
238
+ const getTabPanelIdByValue = (0, import_useStableCallback.useStableCallback)(
239
+ (tabValue) => mountedTabPanels.get(tabValue),
240
+ (0, import_internal.subSlot)(slot, "getPanelId")
241
+ );
242
+ const getTabIdByPanelValue = (0, import_useStableCallback.useStableCallback)(
243
+ (tabPanelValue) => {
244
+ for (const tabMetadata of tabMap.values()) {
245
+ if (tabPanelValue === tabMetadata?.value) {
246
+ return tabMetadata?.id;
247
+ }
248
+ }
249
+ return void 0;
250
+ },
251
+ (0, import_internal.subSlot)(slot, "getTabId")
252
+ );
253
+ const tabsContextValue = (0, import_octane.useMemo)(
254
+ () => ({
255
+ getTabElementBySelectedValue,
256
+ getTabIdByPanelValue,
257
+ getTabPanelIdByValue,
258
+ onValueChange,
259
+ orientation,
260
+ registerMountedTabPanel,
261
+ setTabMap,
262
+ unregisterMountedTabPanel,
263
+ tabActivationDirection,
264
+ value
265
+ }),
266
+ [
267
+ getTabElementBySelectedValue,
268
+ getTabIdByPanelValue,
269
+ getTabPanelIdByValue,
270
+ onValueChange,
271
+ orientation,
272
+ registerMountedTabPanel,
273
+ setTabMap,
274
+ unregisterMountedTabPanel,
275
+ tabActivationDirection,
276
+ value
277
+ ],
278
+ (0, import_internal.subSlot)(slot, "ctx")
279
+ );
280
+ const selectedTabMetadata = (0, import_octane.useMemo)(
281
+ () => {
282
+ for (const tabMetadata of tabMap.values()) {
283
+ if (tabMetadata != null && tabMetadata.value === value) {
284
+ return tabMetadata;
285
+ }
286
+ }
287
+ return void 0;
288
+ },
289
+ [tabMap, value],
290
+ (0, import_internal.subSlot)(slot, "selectedMeta")
291
+ );
292
+ const firstEnabledTabValue = (0, import_octane.useMemo)(
293
+ () => {
294
+ for (const tabMetadata of tabMap.values()) {
295
+ if (tabMetadata != null && !tabMetadata.disabled) {
296
+ return tabMetadata.value;
297
+ }
298
+ }
299
+ return void 0;
300
+ },
301
+ [tabMap],
302
+ (0, import_internal.subSlot)(slot, "firstEnabled")
303
+ );
304
+ const shouldNotifyInitialValueChangeRef = (0, import_octane.useRef)(
305
+ !hasExplicitDefaultValueProp,
306
+ (0, import_internal.subSlot)(slot, "notifyInitial")
307
+ );
308
+ const initialDefaultValueRef = (0, import_octane.useRef)(defaultValueProp, (0, import_internal.subSlot)(slot, "initialDefault"));
309
+ const shouldHonorDisabledDefaultValueRef = (0, import_octane.useRef)(
310
+ hasExplicitDefaultValueProp,
311
+ (0, import_internal.subSlot)(slot, "honorDisabled")
312
+ );
313
+ const didRegisterTabsRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "didRegister"));
314
+ (0, import_octane.useLayoutEffect)(
315
+ () => {
316
+ if (isControlled) {
317
+ return;
318
+ }
319
+ function commitAutomaticValueChange(fallbackValue, fallbackReason) {
320
+ setValue(fallbackValue);
321
+ setActivationDirectionState((prev) => {
322
+ if (prev.previousValue === fallbackValue && prev.tabActivationDirection === "none") {
323
+ return prev;
324
+ }
325
+ return { previousValue: fallbackValue, tabActivationDirection: "none" };
326
+ });
327
+ notifyAutomaticValueChange(fallbackValue, fallbackReason);
328
+ shouldNotifyInitialValueChangeRef.current = false;
329
+ }
330
+ if (tabMap.size === 0) {
331
+ if (didRegisterTabsRef.current && value !== null && !lastKnownTabElementRef.current?.isConnected) {
332
+ commitAutomaticValueChange(null, import_createChangeEventDetails.REASONS.missing);
333
+ }
334
+ return;
335
+ }
336
+ didRegisterTabsRef.current = true;
337
+ lastKnownTabElementRef.current = tabMap.keys().next().value;
338
+ const selectionIsDisabled = selectedTabMetadata?.disabled;
339
+ const selectionIsMissing = selectedTabMetadata == null && value !== null;
340
+ if (!selectionIsDisabled && value === initialDefaultValueRef.current) {
341
+ shouldHonorDisabledDefaultValueRef.current = false;
342
+ }
343
+ if (shouldHonorDisabledDefaultValueRef.current && selectionIsDisabled && value === initialDefaultValueRef.current) {
344
+ return;
345
+ }
346
+ const shouldNotifyInitialValueChange = shouldNotifyInitialValueChangeRef.current;
347
+ if (selectionIsDisabled || selectionIsMissing) {
348
+ const fallbackValue = firstEnabledTabValue ?? null;
349
+ if (value === fallbackValue) {
350
+ shouldNotifyInitialValueChangeRef.current = false;
351
+ return;
352
+ }
353
+ let fallbackReason = import_createChangeEventDetails.REASONS.missing;
354
+ if (shouldNotifyInitialValueChange) {
355
+ fallbackReason = import_createChangeEventDetails.REASONS.initial;
356
+ } else if (selectionIsDisabled) {
357
+ fallbackReason = import_createChangeEventDetails.REASONS.disabled;
358
+ }
359
+ commitAutomaticValueChange(fallbackValue, fallbackReason);
360
+ return;
361
+ }
362
+ if (shouldNotifyInitialValueChange && selectedTabMetadata != null) {
363
+ notifyAutomaticValueChange(value, import_createChangeEventDetails.REASONS.initial);
364
+ shouldNotifyInitialValueChangeRef.current = false;
365
+ }
366
+ },
367
+ [
368
+ firstEnabledTabValue,
369
+ isControlled,
370
+ notifyAutomaticValueChange,
371
+ selectedTabMetadata,
372
+ setValue,
373
+ tabMap,
374
+ value
375
+ ],
376
+ (0, import_internal.subSlot)(slot, "e:fallback")
377
+ );
378
+ const state = { orientation, tabActivationDirection };
379
+ const element = (0, import_useRenderElement.useRenderElement)(
380
+ "div",
381
+ { render, className, style },
382
+ {
383
+ state,
384
+ ref,
385
+ props: elementProps,
386
+ stateAttributesMapping: tabsStateAttributesMapping
387
+ },
388
+ (0, import_internal.subSlot)(slot, "re")
389
+ );
390
+ return (0, import_octane.createElement)(TabsRootContext.Provider, {
391
+ value: tabsContextValue,
392
+ children: (0, import_octane.createElement)(import_CompositeList.CompositeList, {
393
+ elementsRef: tabPanelRefs,
394
+ children: element
395
+ })
396
+ });
397
+ }
398
+ function TabsList(props) {
399
+ const slot = (0, import_internal.S)("TabsList");
400
+ const {
401
+ activateOnFocus = false,
402
+ className,
403
+ loopFocus = true,
404
+ render,
405
+ style,
406
+ ref,
407
+ ...elementProps
408
+ } = props;
409
+ const { onValueChange, orientation, value, setTabMap, tabActivationDirection } = useTabsRootContext();
410
+ const [highlightedTabIndex, setHighlightedTabIndex] = (0, import_octane.useState)(0, (0, import_internal.subSlot)(slot, "highlighted"));
411
+ const [tabsListElement, setTabsListElement] = (0, import_octane.useState)(
412
+ null,
413
+ (0, import_internal.subSlot)(slot, "listEl")
414
+ );
415
+ const tabResizeObserverElementsRef = (0, import_octane.useRef)(/* @__PURE__ */ new Set(), (0, import_internal.subSlot)(slot, "resizeEls"));
416
+ const registerTabResizeObserverElement = (0, import_useStableCallback.useStableCallback)(
417
+ (element) => {
418
+ tabResizeObserverElementsRef.current.add(element);
419
+ return () => {
420
+ tabResizeObserverElementsRef.current.delete(element);
421
+ };
422
+ },
423
+ (0, import_internal.subSlot)(slot, "registerResize")
424
+ );
425
+ const onTabActivation = (0, import_useStableCallback.useStableCallback)(
426
+ (newValue, eventDetails) => {
427
+ if (newValue !== value) {
428
+ onValueChange(newValue, eventDetails);
429
+ }
430
+ },
431
+ (0, import_internal.subSlot)(slot, "onTabActivation")
432
+ );
433
+ const state = { orientation, tabActivationDirection };
434
+ const defaultProps = {
435
+ "aria-orientation": orientation === "vertical" ? "vertical" : void 0,
436
+ role: "tablist"
437
+ };
438
+ const tabsListContextValue = (0, import_octane.useMemo)(
439
+ () => ({
440
+ activateOnFocus,
441
+ highlightedTabIndex,
442
+ registerTabResizeObserverElement,
443
+ onTabActivation,
444
+ setHighlightedTabIndex,
445
+ tabsListElement
446
+ }),
447
+ [
448
+ activateOnFocus,
449
+ highlightedTabIndex,
450
+ registerTabResizeObserverElement,
451
+ onTabActivation,
452
+ setHighlightedTabIndex,
453
+ tabsListElement
454
+ ],
455
+ (0, import_internal.subSlot)(slot, "ctx")
456
+ );
457
+ return (0, import_octane.createElement)(TabsListContext.Provider, {
458
+ value: tabsListContextValue,
459
+ children: (0, import_octane.createElement)(import_CompositeRoot.CompositeRoot, {
460
+ render,
461
+ className,
462
+ style,
463
+ state,
464
+ refs: [ref, setTabsListElement],
465
+ props: [defaultProps, elementProps],
466
+ stateAttributesMapping: tabsStateAttributesMapping,
467
+ highlightedIndex: highlightedTabIndex,
468
+ enableHomeAndEndKeys: true,
469
+ loopFocus,
470
+ orientation,
471
+ onHighlightedIndexChange: setHighlightedTabIndex,
472
+ onMapChange: setTabMap,
473
+ disabledIndices: EMPTY_DISABLED_INDICES
474
+ })
475
+ });
476
+ }
477
+ function TabsTab(props) {
478
+ const slot = (0, import_internal.S)("TabsTab");
479
+ const {
480
+ className,
481
+ disabled = false,
482
+ render,
483
+ value,
484
+ id: idProp,
485
+ nativeButton = true,
486
+ style,
487
+ ref,
488
+ ...elementProps
489
+ } = props;
490
+ const {
491
+ value: activeTabValue,
492
+ getTabPanelIdByValue,
493
+ orientation,
494
+ tabActivationDirection
495
+ } = useTabsRootContext();
496
+ const {
497
+ activateOnFocus,
498
+ highlightedTabIndex,
499
+ onTabActivation,
500
+ registerTabResizeObserverElement,
501
+ setHighlightedTabIndex,
502
+ tabsListElement
503
+ } = useTabsListContext();
504
+ const id = (0, import_useBaseUiId.useBaseUiId)(idProp, (0, import_internal.subSlot)(slot, "id"));
505
+ const tabMetadata = (0, import_octane.useMemo)(
506
+ () => ({ disabled, id, value }),
507
+ [disabled, id, value],
508
+ (0, import_internal.subSlot)(slot, "meta")
509
+ );
510
+ const { compositeProps, compositeRef, index } = (0, import_useCompositeItem.useCompositeItem)(
511
+ { metadata: tabMetadata },
512
+ (0, import_internal.subSlot)(slot, "composite")
513
+ );
514
+ const active = value === activeTabValue;
515
+ const isNavigatingRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "navigating"));
516
+ const tabElementRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "tabEl"));
517
+ (0, import_octane.useLayoutEffect)(
518
+ () => {
519
+ const tabElement = tabElementRef.current;
520
+ if (!tabElement) {
521
+ return void 0;
522
+ }
523
+ return registerTabResizeObserverElement(tabElement);
524
+ },
525
+ [registerTabResizeObserverElement],
526
+ (0, import_internal.subSlot)(slot, "e:resize")
527
+ );
528
+ (0, import_octane.useLayoutEffect)(
529
+ () => {
530
+ if (isNavigatingRef.current) {
531
+ isNavigatingRef.current = false;
532
+ return;
533
+ }
534
+ if (!(active && index > -1 && highlightedTabIndex !== index)) {
535
+ return;
536
+ }
537
+ const listElement = tabsListElement;
538
+ if (listElement != null) {
539
+ const activeEl = (0, import_element.activeElement)((0, import_owner.ownerDocument)(listElement));
540
+ if (activeEl && (0, import_element.contains)(listElement, activeEl)) {
541
+ return;
542
+ }
543
+ }
544
+ if (!disabled) {
545
+ setHighlightedTabIndex(index);
546
+ }
547
+ },
548
+ [active, index, highlightedTabIndex, setHighlightedTabIndex, disabled, tabsListElement],
549
+ (0, import_internal.subSlot)(slot, "e:sync")
550
+ );
551
+ const { getButtonProps, buttonRef } = (0, import_useButton.useButton)(
552
+ { disabled, native: nativeButton, focusableWhenDisabled: true },
553
+ (0, import_internal.subSlot)(slot, "button")
554
+ );
555
+ const tabPanelId = getTabPanelIdByValue(value);
556
+ const isPressingRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "pressing"));
557
+ const isMainButtonRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "mainButton"));
558
+ function onClick(event) {
559
+ if (active || disabled) {
560
+ return;
561
+ }
562
+ onTabActivation(
563
+ value,
564
+ (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.none, event, void 0, { activationDirection: "none" })
565
+ );
566
+ }
567
+ function onFocus(event) {
568
+ if (active) {
569
+ return;
570
+ }
571
+ if (index > -1 && !disabled) {
572
+ setHighlightedTabIndex(index);
573
+ }
574
+ if (disabled) {
575
+ return;
576
+ }
577
+ if (activateOnFocus && (!isPressingRef.current || isPressingRef.current && isMainButtonRef.current)) {
578
+ onTabActivation(
579
+ value,
580
+ (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.none, event, void 0, { activationDirection: "none" })
581
+ );
582
+ }
583
+ }
584
+ function onPointerDown(event) {
585
+ if (active || disabled) {
586
+ return;
587
+ }
588
+ isPressingRef.current = true;
589
+ function handlePointerUp() {
590
+ isPressingRef.current = false;
591
+ isMainButtonRef.current = false;
592
+ }
593
+ if (!event.button || event.button === 0) {
594
+ isMainButtonRef.current = true;
595
+ const doc = (0, import_owner.ownerDocument)(event.currentTarget);
596
+ doc.addEventListener("pointerup", handlePointerUp, { once: true });
597
+ }
598
+ }
599
+ const state = { disabled, active, orientation, tabActivationDirection };
600
+ return (0, import_useRenderElement.useRenderElement)(
601
+ "button",
602
+ { render, className, style },
603
+ {
604
+ state,
605
+ ref: [ref, buttonRef, compositeRef, tabElementRef],
606
+ props: [
607
+ compositeProps,
608
+ {
609
+ role: "tab",
610
+ "aria-controls": tabPanelId,
611
+ "aria-selected": active,
612
+ id,
613
+ onClick,
614
+ onFocus,
615
+ onPointerDown,
616
+ [import_keys.ACTIVE_COMPOSITE_ITEM]: active ? "" : void 0,
617
+ onKeyDownCapture() {
618
+ isNavigatingRef.current = true;
619
+ }
620
+ },
621
+ elementProps,
622
+ getButtonProps
623
+ ],
624
+ stateAttributesMapping: tabsStateAttributesMapping
625
+ },
626
+ (0, import_internal.subSlot)(slot, "re")
627
+ );
628
+ }
629
+ const panelStateAttributesMapping = {
630
+ ...tabsStateAttributesMapping,
631
+ ...import_useTransitionStatus.transitionStatusMapping
632
+ };
633
+ function TabsPanel(props) {
634
+ const slot = (0, import_internal.S)("TabsPanel");
635
+ const { className, value, render, keepMounted = false, style, ref, ...elementProps } = props;
636
+ const {
637
+ value: selectedValue,
638
+ getTabIdByPanelValue,
639
+ orientation,
640
+ tabActivationDirection,
641
+ registerMountedTabPanel,
642
+ unregisterMountedTabPanel
643
+ } = useTabsRootContext();
644
+ const id = (0, import_useBaseUiId.useBaseUiId)(void 0, (0, import_internal.subSlot)(slot, "id"));
645
+ const metadata = (0, import_octane.useMemo)(() => ({ id, value }), [id, value], (0, import_internal.subSlot)(slot, "meta"));
646
+ const { ref: listItemRef, index } = (0, import_useCompositeListItem.useCompositeListItem)({ metadata }, (0, import_internal.subSlot)(slot, "listItem"));
647
+ const open = value === selectedValue;
648
+ const { mounted, transitionStatus, setMounted } = (0, import_useTransitionStatus.useTransitionStatus)(
649
+ open,
650
+ (0, import_internal.subSlot)(slot, "transition")
651
+ );
652
+ const hidden = !mounted;
653
+ const correspondingTabId = getTabIdByPanelValue(value);
654
+ const state = { hidden, orientation, tabActivationDirection, transitionStatus };
655
+ const panelRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "panelRef"));
656
+ const element = (0, import_useRenderElement.useRenderElement)(
657
+ "div",
658
+ { render, className, style },
659
+ {
660
+ state,
661
+ ref: [ref, listItemRef, panelRef],
662
+ props: [
663
+ {
664
+ "aria-labelledby": correspondingTabId,
665
+ hidden,
666
+ id,
667
+ role: "tabpanel",
668
+ tabIndex: open ? 0 : -1,
669
+ inert: (0, import_inertValue.inertValue)(!open),
670
+ "data-index": index
671
+ },
672
+ elementProps
673
+ ],
674
+ stateAttributesMapping: panelStateAttributesMapping
675
+ },
676
+ (0, import_internal.subSlot)(slot, "re")
677
+ );
678
+ (0, import_useOpenChangeComplete.useOpenChangeComplete)(
679
+ {
680
+ open,
681
+ ref: panelRef,
682
+ onComplete() {
683
+ if (!open) {
684
+ setMounted(false);
685
+ }
686
+ }
687
+ },
688
+ (0, import_internal.subSlot)(slot, "openComplete")
689
+ );
690
+ (0, import_octane.useLayoutEffect)(
691
+ () => {
692
+ if (hidden && !keepMounted) {
693
+ return void 0;
694
+ }
695
+ if (id == null) {
696
+ return void 0;
697
+ }
698
+ registerMountedTabPanel(value, id);
699
+ return () => {
700
+ unregisterMountedTabPanel(value, id);
701
+ };
702
+ },
703
+ [hidden, keepMounted, value, id, registerMountedTabPanel, unregisterMountedTabPanel],
704
+ (0, import_internal.subSlot)(slot, "e:register")
705
+ );
706
+ const shouldRender = keepMounted || mounted;
707
+ if (!shouldRender) {
708
+ return null;
709
+ }
710
+ return element;
711
+ }
712
+ const Tabs = {
713
+ Root: TabsRoot,
714
+ List: TabsList,
715
+ Tab: TabsTab,
716
+ Panel: TabsPanel
717
+ };
718
+ // Annotate the CommonJS export names for ESM import in node:
719
+ 0 && (module.exports = {
720
+ Tabs,
721
+ TabsList,
722
+ TabsPanel,
723
+ TabsRoot,
724
+ TabsTab,
725
+ useTabsListContext,
726
+ useTabsRootContext
727
+ });