@octanejs/floating-ui 0.1.46 → 0.1.47
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.
- package/LICENSE +1 -0
- package/LICENSE.react.upstream +20 -0
- package/LICENSE.upstream +21 -0
- package/README.md +3 -2
- package/UPSTREAM.md +41 -0
- package/dist/cjs/FloatingFocusManager.cjs +10 -5
- package/dist/cjs/FloatingPortal.cjs +39 -7
- package/dist/cjs/delayGroup.cjs +115 -2
- package/dist/cjs/index.cjs +9 -0
- package/dist/cjs/inner.cjs +193 -0
- package/dist/cjs/useDismiss.cjs +2 -0
- package/dist/cjs/useFloating.cjs +31 -5
- package/package.json +39 -8
- package/src/FloatingFocusManager.ts +53 -46
- package/src/FloatingPortal.ts +70 -35
- package/src/delayGroup.ts +154 -1
- package/src/index.ts +9 -0
- package/src/inner.ts +218 -0
- package/src/useDismiss.ts +1 -1
- package/src/useFloating.ts +39 -5
package/LICENSE
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Floating UI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/LICENSE.upstream
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Floating UI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -8,8 +8,9 @@ tree), the full interaction-hook set (`useInteractions`, `useHover` +
|
|
|
8
8
|
`safePolygon`, `useClick`, `useFocus`, `useDismiss`, `useRole`,
|
|
9
9
|
`useClientPoint`, `useListNavigation`, `useTypeahead`), the component layer
|
|
10
10
|
(`FloatingPortal`, `FloatingOverlay`, `FloatingFocusManager`, `FloatingArrow`,
|
|
11
|
-
`FloatingList`, `Composite`),
|
|
12
|
-
everywhere in octane, `forwardRef`
|
|
11
|
+
`FloatingList`, `Composite`), transitions, both delay-group APIs, and the
|
|
12
|
+
deprecated `inner`/`useInnerOffset` pair. As everywhere in octane, `forwardRef`
|
|
13
|
+
becomes a plain `ref` prop.
|
|
13
14
|
|
|
14
15
|
```tsx
|
|
15
16
|
import { useFloating, useInteractions, useHover, offset, flip } from '@octanejs/floating-ui';
|
package/UPSTREAM.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Upstream provenance
|
|
2
|
+
|
|
3
|
+
- Repository: https://github.com/floating-ui/floating-ui
|
|
4
|
+
- Release: `@floating-ui/react@0.27.19`
|
|
5
|
+
- Commit: `d8020ee98c702caa31fa9b4d929ca782c6b58c59`
|
|
6
|
+
- Source roots: `packages/core`, `packages/dom`, `packages/react`,
|
|
7
|
+
`packages/react-dom`, and `packages/utils`
|
|
8
|
+
- Test roots: `packages/react/test` and `packages/react-dom/test`
|
|
9
|
+
- License: MIT
|
|
10
|
+
- npm integrity:
|
|
11
|
+
`sha512-31B8h5mm8YxotlE7/AU/PhNAl8eWxAmjL/v2QOxroDNkTFLk3Uu82u63N3b6TXa4EGJeeZLVcd/9AlNlVqzeog==`
|
|
12
|
+
|
|
13
|
+
`upstream/` is a byte-exact, hash-verified tree from that commit. The pristine
|
|
14
|
+
lane runs the original React and React DOM runtime suites with the commit's
|
|
15
|
+
React 18.2.0, React DOM 18.2.0, Testing Library, tabbable 6.2.0, and Vitest
|
|
16
|
+
3.0.9 versions. The adapted lane regenerates the same tests under
|
|
17
|
+
`tests/upstream/` from `audit/upstream.lock.json`, then applies only the
|
|
18
|
+
reviewed patches in `audit/upstream-patches/`.
|
|
19
|
+
|
|
20
|
+
Both runtime lanes register the same 307 upstream cases. The pristine lane has
|
|
21
|
+
301 passes and six upstream-declared skips. The adapted lane crosswalks the
|
|
22
|
+
same 301 executed identities: 272 are compatible passes and 29 use Vitest's
|
|
23
|
+
`fails` modifier as executable negative controls for documented Octane
|
|
24
|
+
divergences. The same six upstream skips remain explicit non-evidence. See
|
|
25
|
+
`audit/runtime-crosswalk.json`, `audit/expected-failures.json`, and
|
|
26
|
+
`audit/upstream-skips.json`; no skipped or expected-failure case is counted as
|
|
27
|
+
an adapted compatibility pass.
|
|
28
|
+
|
|
29
|
+
The two original `index.test-d.tsx` programs also compile in pristine and
|
|
30
|
+
adapted type lanes. Their `@ts-expect-error` assertions are negative controls:
|
|
31
|
+
removing the expected diagnostic makes the typecheck fail.
|
|
32
|
+
|
|
33
|
+
The pristine type lane uses the commit's TypeScript 5.4.2,
|
|
34
|
+
`@types/react@18.3.19`, and `@types/react-dom@18.3.1`. The adapted lane uses
|
|
35
|
+
`tsrx-tsc` and records the permitted React-to-Octane transforms and the
|
|
36
|
+
combined-entry-point diagnostics in `audit/type-parity.json`.
|
|
37
|
+
|
|
38
|
+
The package's older differential lane remains supplemental evidence: it
|
|
39
|
+
compiles one repository fixture for React and Octane and compares independent
|
|
40
|
+
hook placement output. Real Chromium layout and `autoUpdate` coverage remains
|
|
41
|
+
in the ordinary `floating-ui-browser` project.
|
|
@@ -20,6 +20,7 @@ var FloatingFocusManager_exports = {};
|
|
|
20
20
|
__export(FloatingFocusManager_exports, {
|
|
21
21
|
FloatingFocusManager: () => FloatingFocusManager,
|
|
22
22
|
VisuallyHiddenDismiss: () => VisuallyHiddenDismiss,
|
|
23
|
+
markOthers: () => markOthers,
|
|
23
24
|
supportsInert: () => supportsInert
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(FloatingFocusManager_exports);
|
|
@@ -646,6 +647,7 @@ function FloatingFocusManager(props) {
|
|
|
646
647
|
return null;
|
|
647
648
|
}
|
|
648
649
|
return (0, import_octane.createElement)(VisuallyHiddenDismiss, {
|
|
650
|
+
key: `dismiss-${location}`,
|
|
649
651
|
ref: location === "start" ? startDismissButtonRef : endDismissButtonRef,
|
|
650
652
|
onClick: (event) => onOpenChange(false, event),
|
|
651
653
|
children: typeof visuallyHiddenDismiss === "string" ? visuallyHiddenDismiss : "Dismiss"
|
|
@@ -653,7 +655,8 @@ function FloatingFocusManager(props) {
|
|
|
653
655
|
}
|
|
654
656
|
const shouldRenderGuards = !disabled && guards && (modal ? !isUntrappedTypeableCombobox : true) && (isInsidePortal || modal);
|
|
655
657
|
return [
|
|
656
|
-
shouldRenderGuards
|
|
658
|
+
shouldRenderGuards ? (0, import_octane.createElement)(import_FloatingPortal.FocusGuard, {
|
|
659
|
+
key: "guard-inside-before",
|
|
657
660
|
"data-type": "inside",
|
|
658
661
|
ref: mergedBeforeGuardRef,
|
|
659
662
|
onFocus: (event) => {
|
|
@@ -669,11 +672,12 @@ function FloatingFocusManager(props) {
|
|
|
669
672
|
}
|
|
670
673
|
}
|
|
671
674
|
}
|
|
672
|
-
}),
|
|
675
|
+
}) : null,
|
|
673
676
|
!isUntrappedTypeableCombobox && renderDismissButton("start"),
|
|
674
|
-
children,
|
|
677
|
+
(0, import_octane.createElement)(import_octane.Fragment, { key: "children", children }),
|
|
675
678
|
renderDismissButton("end"),
|
|
676
|
-
shouldRenderGuards
|
|
679
|
+
shouldRenderGuards ? (0, import_octane.createElement)(import_FloatingPortal.FocusGuard, {
|
|
680
|
+
key: "guard-inside-after",
|
|
677
681
|
"data-type": "inside",
|
|
678
682
|
ref: mergedAfterGuardRef,
|
|
679
683
|
onFocus: (event) => {
|
|
@@ -690,12 +694,13 @@ function FloatingFocusManager(props) {
|
|
|
690
694
|
}
|
|
691
695
|
}
|
|
692
696
|
}
|
|
693
|
-
})
|
|
697
|
+
}) : null
|
|
694
698
|
];
|
|
695
699
|
}
|
|
696
700
|
// Annotate the CommonJS export names for ESM import in node:
|
|
697
701
|
0 && (module.exports = {
|
|
698
702
|
FloatingFocusManager,
|
|
699
703
|
VisuallyHiddenDismiss,
|
|
704
|
+
markOthers,
|
|
700
705
|
supportsInert
|
|
701
706
|
});
|
|
@@ -45,6 +45,9 @@ const HIDDEN_STYLES = {
|
|
|
45
45
|
};
|
|
46
46
|
function FocusGuard(props) {
|
|
47
47
|
const [role, setRole] = (0, import_octane.useState)(void 0, (0, import_internal.S)("FocusGuard:role"));
|
|
48
|
+
const elementRef = (0, import_octane.useRef)(null, (0, import_internal.S)("FocusGuard:element"));
|
|
49
|
+
const forwardedRef = props.ref;
|
|
50
|
+
const onFocus = props.onFocus;
|
|
48
51
|
(0, import_utils.useModernLayoutEffect)(
|
|
49
52
|
() => {
|
|
50
53
|
if ((0, import_utils.isSafari)()) {
|
|
@@ -54,8 +57,28 @@ function FocusGuard(props) {
|
|
|
54
57
|
[],
|
|
55
58
|
(0, import_internal.S)("FocusGuard:eff")
|
|
56
59
|
);
|
|
60
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
61
|
+
() => {
|
|
62
|
+
const element = elementRef.current;
|
|
63
|
+
if (!element || !onFocus) return;
|
|
64
|
+
const handleFocus = (event) => onFocus(event);
|
|
65
|
+
element.addEventListener("focusin", handleFocus);
|
|
66
|
+
return () => element.removeEventListener("focusin", handleFocus);
|
|
67
|
+
},
|
|
68
|
+
[onFocus],
|
|
69
|
+
(0, import_internal.S)("FocusGuard:focus")
|
|
70
|
+
);
|
|
71
|
+
const { ref: _ref, onFocus: _onFocus, ...elementProps } = props;
|
|
57
72
|
return (0, import_octane.createElement)("span", {
|
|
58
|
-
...
|
|
73
|
+
...elementProps,
|
|
74
|
+
ref: (element) => {
|
|
75
|
+
elementRef.current = element;
|
|
76
|
+
if (typeof forwardedRef === "function") {
|
|
77
|
+
forwardedRef(element);
|
|
78
|
+
} else if (forwardedRef) {
|
|
79
|
+
forwardedRef.current = element;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
59
82
|
tabIndex: 0,
|
|
60
83
|
role,
|
|
61
84
|
"aria-hidden": role ? void 0 : true,
|
|
@@ -200,7 +223,8 @@ function FloatingPortal(props) {
|
|
|
200
223
|
return (0, import_octane.createElement)(PortalContext.Provider, {
|
|
201
224
|
value,
|
|
202
225
|
children: [
|
|
203
|
-
shouldRenderGuards && portalNode
|
|
226
|
+
shouldRenderGuards && portalNode ? (0, import_octane.createElement)(FocusGuard, {
|
|
227
|
+
key: "guard-outside-before",
|
|
204
228
|
"data-type": "outside",
|
|
205
229
|
ref: beforeOutsideRef,
|
|
206
230
|
onFocus: (event) => {
|
|
@@ -211,10 +235,18 @@ function FloatingPortal(props) {
|
|
|
211
235
|
(0, import_utils.getPreviousTabbable)(domReference)?.focus();
|
|
212
236
|
}
|
|
213
237
|
}
|
|
214
|
-
}),
|
|
215
|
-
shouldRenderGuards && portalNode
|
|
216
|
-
|
|
217
|
-
|
|
238
|
+
}) : null,
|
|
239
|
+
shouldRenderGuards && portalNode ? (0, import_octane.createElement)("span", {
|
|
240
|
+
key: "aria-owns",
|
|
241
|
+
"aria-owns": portalNode.id,
|
|
242
|
+
style: HIDDEN_OWNER_STYLES
|
|
243
|
+
}) : null,
|
|
244
|
+
portalNode ? (0, import_octane.createElement)(import_octane.Fragment, {
|
|
245
|
+
key: "portal-children",
|
|
246
|
+
children: (0, import_octane.createPortal)(children, portalNode)
|
|
247
|
+
}) : null,
|
|
248
|
+
shouldRenderGuards && portalNode ? (0, import_octane.createElement)(FocusGuard, {
|
|
249
|
+
key: "guard-outside-after",
|
|
218
250
|
"data-type": "outside",
|
|
219
251
|
ref: afterOutsideRef,
|
|
220
252
|
onFocus: (event) => {
|
|
@@ -226,7 +258,7 @@ function FloatingPortal(props) {
|
|
|
226
258
|
focusManagerState?.closeOnFocusOut && focusManagerState?.onOpenChange(false, event, "focus-out");
|
|
227
259
|
}
|
|
228
260
|
}
|
|
229
|
-
})
|
|
261
|
+
}) : null
|
|
230
262
|
]
|
|
231
263
|
});
|
|
232
264
|
}
|
package/dist/cjs/delayGroup.cjs
CHANGED
|
@@ -20,8 +20,10 @@ var delayGroup_exports = {};
|
|
|
20
20
|
__export(delayGroup_exports, {
|
|
21
21
|
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
22
22
|
FloatingDelayGroupContext: () => FloatingDelayGroupContext,
|
|
23
|
+
NextFloatingDelayGroup: () => NextFloatingDelayGroup,
|
|
23
24
|
useDelayGroup: () => useDelayGroup,
|
|
24
|
-
useDelayGroupContext: () => useDelayGroupContext
|
|
25
|
+
useDelayGroupContext: () => useDelayGroupContext,
|
|
26
|
+
useNextDelayGroup: () => useNextDelayGroup
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(delayGroup_exports);
|
|
27
29
|
var import_octane = require("octane");
|
|
@@ -145,10 +147,121 @@ function useDelayGroup(...args) {
|
|
|
145
147
|
);
|
|
146
148
|
return groupContext;
|
|
147
149
|
}
|
|
150
|
+
const NextFloatingDelayGroupContext = (0, import_octane.createContext)({
|
|
151
|
+
hasProvider: false,
|
|
152
|
+
timeoutMs: 0,
|
|
153
|
+
delayRef: { current: 0 },
|
|
154
|
+
initialDelayRef: { current: 0 },
|
|
155
|
+
timeoutIdRef: { current: -1 },
|
|
156
|
+
currentIdRef: { current: null },
|
|
157
|
+
currentContextRef: { current: null }
|
|
158
|
+
});
|
|
159
|
+
function NextFloatingDelayGroup(props) {
|
|
160
|
+
const children = props.children;
|
|
161
|
+
const delay = props.delay;
|
|
162
|
+
const timeoutMs = props.timeoutMs ?? 0;
|
|
163
|
+
const delayRef = (0, import_octane.useRef)(delay, (0, import_internal.S)("NextFloatingDelayGroup:delay"));
|
|
164
|
+
const initialDelayRef = (0, import_octane.useRef)(delay, (0, import_internal.S)("NextFloatingDelayGroup:initialDelay"));
|
|
165
|
+
const currentIdRef = (0, import_octane.useRef)(null, (0, import_internal.S)("NextFloatingDelayGroup:currentId"));
|
|
166
|
+
const currentContextRef = (0, import_octane.useRef)(
|
|
167
|
+
null,
|
|
168
|
+
(0, import_internal.S)("NextFloatingDelayGroup:currentContext")
|
|
169
|
+
);
|
|
170
|
+
const timeoutIdRef = (0, import_octane.useRef)(-1, (0, import_internal.S)("NextFloatingDelayGroup:timeoutId"));
|
|
171
|
+
const value = (0, import_octane.useMemo)(
|
|
172
|
+
() => ({
|
|
173
|
+
hasProvider: true,
|
|
174
|
+
delayRef,
|
|
175
|
+
initialDelayRef,
|
|
176
|
+
currentIdRef,
|
|
177
|
+
timeoutMs,
|
|
178
|
+
currentContextRef,
|
|
179
|
+
timeoutIdRef
|
|
180
|
+
}),
|
|
181
|
+
[timeoutMs],
|
|
182
|
+
(0, import_internal.S)("NextFloatingDelayGroup:value")
|
|
183
|
+
);
|
|
184
|
+
return (0, import_octane.createElement)(NextFloatingDelayGroupContext.Provider, { value, children });
|
|
185
|
+
}
|
|
186
|
+
function useNextDelayGroup(...args) {
|
|
187
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
188
|
+
const context = user[0];
|
|
189
|
+
const options = user[1] ?? {};
|
|
190
|
+
const enabled = options.enabled ?? true;
|
|
191
|
+
const { open, onOpenChange, floatingId } = context;
|
|
192
|
+
const groupContext = (0, import_octane.useContext)(NextFloatingDelayGroupContext);
|
|
193
|
+
const {
|
|
194
|
+
currentIdRef,
|
|
195
|
+
delayRef,
|
|
196
|
+
timeoutMs,
|
|
197
|
+
initialDelayRef,
|
|
198
|
+
currentContextRef,
|
|
199
|
+
hasProvider,
|
|
200
|
+
timeoutIdRef
|
|
201
|
+
} = groupContext;
|
|
202
|
+
const [isInstantPhase, setIsInstantPhase] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "state"));
|
|
203
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
204
|
+
() => {
|
|
205
|
+
function unset() {
|
|
206
|
+
setIsInstantPhase(false);
|
|
207
|
+
currentContextRef.current?.setIsInstantPhase(false);
|
|
208
|
+
currentIdRef.current = null;
|
|
209
|
+
currentContextRef.current = null;
|
|
210
|
+
delayRef.current = initialDelayRef.current;
|
|
211
|
+
}
|
|
212
|
+
if (!enabled || !currentIdRef.current) return;
|
|
213
|
+
if (!open && currentIdRef.current === floatingId) {
|
|
214
|
+
setIsInstantPhase(false);
|
|
215
|
+
if (timeoutMs) {
|
|
216
|
+
timeoutIdRef.current = window.setTimeout(unset, timeoutMs);
|
|
217
|
+
return () => clearTimeout(timeoutIdRef.current);
|
|
218
|
+
}
|
|
219
|
+
unset();
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[enabled, open, floatingId, timeoutMs],
|
|
223
|
+
(0, import_internal.subSlot)(slot, "e:close")
|
|
224
|
+
);
|
|
225
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
226
|
+
() => {
|
|
227
|
+
if (!enabled || !open) return;
|
|
228
|
+
const prevContext = currentContextRef.current;
|
|
229
|
+
const prevId = currentIdRef.current;
|
|
230
|
+
currentContextRef.current = { onOpenChange, setIsInstantPhase };
|
|
231
|
+
currentIdRef.current = floatingId;
|
|
232
|
+
delayRef.current = { open: 0, close: (0, import_utils.getDelay)(initialDelayRef.current, "close") };
|
|
233
|
+
if (prevId !== null && prevId !== floatingId) {
|
|
234
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
235
|
+
setIsInstantPhase(true);
|
|
236
|
+
prevContext?.setIsInstantPhase(true);
|
|
237
|
+
prevContext?.onOpenChange(false);
|
|
238
|
+
} else {
|
|
239
|
+
setIsInstantPhase(false);
|
|
240
|
+
prevContext?.setIsInstantPhase(false);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
[enabled, open, floatingId, onOpenChange],
|
|
244
|
+
(0, import_internal.subSlot)(slot, "e:open")
|
|
245
|
+
);
|
|
246
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
247
|
+
() => () => {
|
|
248
|
+
currentContextRef.current = null;
|
|
249
|
+
},
|
|
250
|
+
[currentContextRef],
|
|
251
|
+
(0, import_internal.subSlot)(slot, "e:cleanup")
|
|
252
|
+
);
|
|
253
|
+
return (0, import_octane.useMemo)(
|
|
254
|
+
() => ({ hasProvider, delayRef, isInstantPhase }),
|
|
255
|
+
[hasProvider, delayRef, isInstantPhase],
|
|
256
|
+
(0, import_internal.subSlot)(slot, "result")
|
|
257
|
+
);
|
|
258
|
+
}
|
|
148
259
|
// Annotate the CommonJS export names for ESM import in node:
|
|
149
260
|
0 && (module.exports = {
|
|
150
261
|
FloatingDelayGroup,
|
|
151
262
|
FloatingDelayGroupContext,
|
|
263
|
+
NextFloatingDelayGroup,
|
|
152
264
|
useDelayGroup,
|
|
153
|
-
useDelayGroupContext
|
|
265
|
+
useDelayGroupContext,
|
|
266
|
+
useNextDelayGroup
|
|
154
267
|
});
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
FloatingTree: () => import_tree.FloatingTree,
|
|
35
35
|
FloatingTreeContext: () => import_tree.FloatingTreeContext,
|
|
36
36
|
FocusGuard: () => import_FloatingPortal.FocusGuard,
|
|
37
|
+
NextFloatingDelayGroup: () => import_delayGroup.NextFloatingDelayGroup,
|
|
37
38
|
PortalContext: () => import_FloatingPortal.PortalContext,
|
|
38
39
|
VisuallyHiddenDismiss: () => import_FloatingFocusManager.VisuallyHiddenDismiss,
|
|
39
40
|
arrow: () => import_useFloating.arrow,
|
|
@@ -46,6 +47,7 @@ __export(index_exports, {
|
|
|
46
47
|
getOverflowAncestors: () => import_dom.getOverflowAncestors,
|
|
47
48
|
hide: () => import_dom.hide,
|
|
48
49
|
inline: () => import_dom.inline,
|
|
50
|
+
inner: () => import_inner.inner,
|
|
49
51
|
limitShift: () => import_dom.limitShift,
|
|
50
52
|
offset: () => import_dom.offset,
|
|
51
53
|
platform: () => import_dom.platform,
|
|
@@ -66,10 +68,12 @@ __export(index_exports, {
|
|
|
66
68
|
useFocus: () => import_useFocus.useFocus,
|
|
67
69
|
useHover: () => import_useHover.useHover,
|
|
68
70
|
useId: () => import_useId.useId,
|
|
71
|
+
useInnerOffset: () => import_inner.useInnerOffset,
|
|
69
72
|
useInteractions: () => import_useInteractions.useInteractions,
|
|
70
73
|
useListItem: () => import_FloatingList.useListItem,
|
|
71
74
|
useListNavigation: () => import_useListNavigation.useListNavigation,
|
|
72
75
|
useMergeRefs: () => import_useMergeRefs.useMergeRefs,
|
|
76
|
+
useNextDelayGroup: () => import_delayGroup.useNextDelayGroup,
|
|
73
77
|
usePortalContext: () => import_FloatingPortal.usePortalContext,
|
|
74
78
|
usePositionFloating: () => import_useFloating2.usePositionFloating,
|
|
75
79
|
useRole: () => import_useRole.useRole,
|
|
@@ -103,6 +107,7 @@ var import_Composite = require("./Composite.cjs");
|
|
|
103
107
|
var import_FloatingFocusManager = require("./FloatingFocusManager.cjs");
|
|
104
108
|
var import_transitions = require("./transitions.cjs");
|
|
105
109
|
var import_delayGroup = require("./delayGroup.cjs");
|
|
110
|
+
var import_inner = require("./inner.cjs");
|
|
106
111
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
112
|
0 && (module.exports = {
|
|
108
113
|
Composite,
|
|
@@ -121,6 +126,7 @@ var import_delayGroup = require("./delayGroup.cjs");
|
|
|
121
126
|
FloatingTree,
|
|
122
127
|
FloatingTreeContext,
|
|
123
128
|
FocusGuard,
|
|
129
|
+
NextFloatingDelayGroup,
|
|
124
130
|
PortalContext,
|
|
125
131
|
VisuallyHiddenDismiss,
|
|
126
132
|
arrow,
|
|
@@ -133,6 +139,7 @@ var import_delayGroup = require("./delayGroup.cjs");
|
|
|
133
139
|
getOverflowAncestors,
|
|
134
140
|
hide,
|
|
135
141
|
inline,
|
|
142
|
+
inner,
|
|
136
143
|
limitShift,
|
|
137
144
|
offset,
|
|
138
145
|
platform,
|
|
@@ -153,10 +160,12 @@ var import_delayGroup = require("./delayGroup.cjs");
|
|
|
153
160
|
useFocus,
|
|
154
161
|
useHover,
|
|
155
162
|
useId,
|
|
163
|
+
useInnerOffset,
|
|
156
164
|
useInteractions,
|
|
157
165
|
useListItem,
|
|
158
166
|
useListNavigation,
|
|
159
167
|
useMergeRefs,
|
|
168
|
+
useNextDelayGroup,
|
|
160
169
|
usePortalContext,
|
|
161
170
|
usePositionFloating,
|
|
162
171
|
useRole,
|
|
@@ -0,0 +1,193 @@
|
|
|
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 inner_exports = {};
|
|
20
|
+
__export(inner_exports, {
|
|
21
|
+
inner: () => inner,
|
|
22
|
+
useInnerOffset: () => useInnerOffset
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(inner_exports);
|
|
25
|
+
var import_dom = require("@floating-ui/dom");
|
|
26
|
+
var import_utils = require("@floating-ui/utils");
|
|
27
|
+
var import_octane = require("octane");
|
|
28
|
+
var import_internal = require("./internal.cjs");
|
|
29
|
+
var import_utils2 = require("./utils/index.cjs");
|
|
30
|
+
function getArgsWithCustomFloatingHeight(state, height) {
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
rects: {
|
|
34
|
+
...state.rects,
|
|
35
|
+
floating: { ...state.rects.floating, height }
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const inner = (props) => ({
|
|
40
|
+
name: "inner",
|
|
41
|
+
options: props,
|
|
42
|
+
async fn(state) {
|
|
43
|
+
const {
|
|
44
|
+
listRef,
|
|
45
|
+
overflowRef,
|
|
46
|
+
onFallbackChange,
|
|
47
|
+
offset: innerOffset = 0,
|
|
48
|
+
index = 0,
|
|
49
|
+
minItemsVisible = 4,
|
|
50
|
+
referenceOverflowThreshold = 0,
|
|
51
|
+
scrollRef,
|
|
52
|
+
...detectOverflowOptions
|
|
53
|
+
} = (0, import_utils.evaluate)(props, state);
|
|
54
|
+
const {
|
|
55
|
+
rects,
|
|
56
|
+
platform,
|
|
57
|
+
elements: { floating }
|
|
58
|
+
} = state;
|
|
59
|
+
const item = listRef.current[index];
|
|
60
|
+
const scrollEl = scrollRef?.current || floating;
|
|
61
|
+
const clientTop = floating.clientTop || scrollEl.clientTop;
|
|
62
|
+
const floatingIsBordered = floating.clientTop !== 0;
|
|
63
|
+
const scrollElIsBordered = scrollEl.clientTop !== 0;
|
|
64
|
+
const floatingIsScrollEl = floating === scrollEl;
|
|
65
|
+
if (!item) return {};
|
|
66
|
+
const nextArgs = {
|
|
67
|
+
...state,
|
|
68
|
+
...await (0, import_dom.offset)(
|
|
69
|
+
-item.offsetTop - floating.clientTop - rects.reference.height / 2 - item.offsetHeight / 2 - innerOffset
|
|
70
|
+
).fn(state)
|
|
71
|
+
};
|
|
72
|
+
const overflow = await platform.detectOverflow(
|
|
73
|
+
getArgsWithCustomFloatingHeight(
|
|
74
|
+
nextArgs,
|
|
75
|
+
scrollEl.scrollHeight + clientTop + floating.clientTop
|
|
76
|
+
),
|
|
77
|
+
detectOverflowOptions
|
|
78
|
+
);
|
|
79
|
+
const refOverflow = await platform.detectOverflow(nextArgs, {
|
|
80
|
+
...detectOverflowOptions,
|
|
81
|
+
elementContext: "reference"
|
|
82
|
+
});
|
|
83
|
+
const diffY = (0, import_utils.max)(0, overflow.top);
|
|
84
|
+
const nextY = nextArgs.y + diffY;
|
|
85
|
+
const isScrollable = scrollEl.scrollHeight > scrollEl.clientHeight;
|
|
86
|
+
const rounder = isScrollable ? (value) => value : import_utils.round;
|
|
87
|
+
const maxHeight = rounder(
|
|
88
|
+
(0, import_utils.max)(
|
|
89
|
+
0,
|
|
90
|
+
scrollEl.scrollHeight + (floatingIsBordered && floatingIsScrollEl || scrollElIsBordered ? clientTop * 2 : 0) - diffY - (0, import_utils.max)(0, overflow.bottom)
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
scrollEl.style.maxHeight = `${maxHeight}px`;
|
|
94
|
+
scrollEl.scrollTop = diffY;
|
|
95
|
+
if (onFallbackChange) {
|
|
96
|
+
const shouldFallback = scrollEl.offsetHeight < item.offsetHeight * (0, import_utils.min)(minItemsVisible, listRef.current.length) - 1 || refOverflow.top >= -referenceOverflowThreshold || refOverflow.bottom >= -referenceOverflowThreshold;
|
|
97
|
+
(0, import_octane.flushSync)(() => onFallbackChange(shouldFallback));
|
|
98
|
+
}
|
|
99
|
+
if (overflowRef) {
|
|
100
|
+
overflowRef.current = await platform.detectOverflow(
|
|
101
|
+
getArgsWithCustomFloatingHeight(
|
|
102
|
+
{ ...nextArgs, y: nextY },
|
|
103
|
+
scrollEl.offsetHeight + clientTop + floating.clientTop
|
|
104
|
+
),
|
|
105
|
+
detectOverflowOptions
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return { y: nextY };
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
function useInnerOffset(...args) {
|
|
112
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
113
|
+
const context = user[0];
|
|
114
|
+
const props = user[1];
|
|
115
|
+
const { open, elements } = context;
|
|
116
|
+
const { enabled = true, overflowRef, scrollRef, onChange: unstableOnChange } = props;
|
|
117
|
+
const onChange = (0, import_utils2.useEffectEvent)(unstableOnChange, (0, import_internal.subSlot)(slot, "change"));
|
|
118
|
+
const controlledScrollingRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "controlled"));
|
|
119
|
+
const prevScrollTopRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "prevScrollTop"));
|
|
120
|
+
const initialOverflowRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "initialOverflow"));
|
|
121
|
+
(0, import_utils2.useModernLayoutEffect)(
|
|
122
|
+
() => {
|
|
123
|
+
if (!enabled) return;
|
|
124
|
+
const el = scrollRef?.current || elements.floating;
|
|
125
|
+
if (!open || !el) return;
|
|
126
|
+
const scrollElement = el;
|
|
127
|
+
function onWheel(event) {
|
|
128
|
+
if (event.ctrlKey || overflowRef.current == null) return;
|
|
129
|
+
const deltaY = event.deltaY;
|
|
130
|
+
const isAtTop = overflowRef.current.top >= -0.5;
|
|
131
|
+
const isAtBottom = overflowRef.current.bottom >= -0.5;
|
|
132
|
+
const remainingScroll = scrollElement.scrollHeight - scrollElement.clientHeight;
|
|
133
|
+
const sign = deltaY < 0 ? -1 : 1;
|
|
134
|
+
const method = deltaY < 0 ? "max" : "min";
|
|
135
|
+
if (scrollElement.scrollHeight <= scrollElement.clientHeight) return;
|
|
136
|
+
if (!isAtTop && deltaY > 0 || !isAtBottom && deltaY < 0) {
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
(0, import_octane.flushSync)(
|
|
139
|
+
() => onChange((value) => value + Math[method](deltaY, remainingScroll * sign))
|
|
140
|
+
);
|
|
141
|
+
} else if (/firefox/i.test((0, import_utils2.getUserAgent)())) {
|
|
142
|
+
scrollElement.scrollTop += deltaY;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
scrollElement.addEventListener("wheel", onWheel);
|
|
146
|
+
requestAnimationFrame(() => {
|
|
147
|
+
prevScrollTopRef.current = scrollElement.scrollTop;
|
|
148
|
+
if (overflowRef.current != null) initialOverflowRef.current = { ...overflowRef.current };
|
|
149
|
+
});
|
|
150
|
+
return () => {
|
|
151
|
+
prevScrollTopRef.current = null;
|
|
152
|
+
initialOverflowRef.current = null;
|
|
153
|
+
scrollElement.removeEventListener("wheel", onWheel);
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
[enabled, open, elements.floating, overflowRef, scrollRef, onChange],
|
|
157
|
+
(0, import_internal.subSlot)(slot, "e:wheel")
|
|
158
|
+
);
|
|
159
|
+
const floating = (0, import_octane.useMemo)(
|
|
160
|
+
() => ({
|
|
161
|
+
onKeyDown() {
|
|
162
|
+
controlledScrollingRef.current = true;
|
|
163
|
+
},
|
|
164
|
+
onWheel() {
|
|
165
|
+
controlledScrollingRef.current = false;
|
|
166
|
+
},
|
|
167
|
+
onPointerMove() {
|
|
168
|
+
controlledScrollingRef.current = false;
|
|
169
|
+
},
|
|
170
|
+
onScroll() {
|
|
171
|
+
const el = scrollRef?.current || elements.floating;
|
|
172
|
+
if (!overflowRef.current || !el || !controlledScrollingRef.current) return;
|
|
173
|
+
if (prevScrollTopRef.current !== null) {
|
|
174
|
+
const scrollDiff = el.scrollTop - prevScrollTopRef.current;
|
|
175
|
+
if (overflowRef.current.bottom < -0.5 && scrollDiff < -1 || overflowRef.current.top < -0.5 && scrollDiff > 1) {
|
|
176
|
+
(0, import_octane.flushSync)(() => onChange((value) => value + scrollDiff));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
requestAnimationFrame(() => {
|
|
180
|
+
prevScrollTopRef.current = el.scrollTop;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}),
|
|
184
|
+
[elements.floating, onChange, overflowRef, scrollRef],
|
|
185
|
+
(0, import_internal.subSlot)(slot, "floating")
|
|
186
|
+
);
|
|
187
|
+
return (0, import_octane.useMemo)(() => enabled ? { floating } : {}, [enabled, floating], (0, import_internal.subSlot)(slot, "result"));
|
|
188
|
+
}
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
inner,
|
|
192
|
+
useInnerOffset
|
|
193
|
+
});
|
package/dist/cjs/useDismiss.cjs
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var useDismiss_exports = {};
|
|
20
20
|
__export(useDismiss_exports, {
|
|
21
|
+
normalizeProp: () => normalizeProp,
|
|
21
22
|
useDismiss: () => useDismiss
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(useDismiss_exports);
|
|
@@ -333,5 +334,6 @@ function useDismiss(...args) {
|
|
|
333
334
|
}
|
|
334
335
|
// Annotate the CommonJS export names for ESM import in node:
|
|
335
336
|
0 && (module.exports = {
|
|
337
|
+
normalizeProp,
|
|
336
338
|
useDismiss
|
|
337
339
|
});
|