@elliemae/ds-floating-context 3.55.1 → 3.57.0-next.1
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/dist/cjs/DSFloatingContext.js +47 -57
- package/dist/cjs/DSFloatingContext.js.map +2 -2
- package/dist/cjs/typescript-testing/typescript-floating-context-valid.js +94 -0
- package/dist/cjs/typescript-testing/typescript-floating-context-valid.js.map +7 -0
- package/dist/cjs/useComputedPositionStyles.js +69 -48
- package/dist/cjs/useComputedPositionStyles.js.map +3 -3
- package/dist/cjs/utils/computePosition.js +4 -7
- package/dist/cjs/utils/computePosition.js.map +2 -2
- package/dist/cjs/utils/detectOverflow.js +5 -3
- package/dist/cjs/utils/detectOverflow.js.map +2 -2
- package/dist/esm/DSFloatingContext.js +48 -58
- package/dist/esm/DSFloatingContext.js.map +2 -2
- package/dist/esm/typescript-testing/typescript-floating-context-valid.js +71 -0
- package/dist/esm/typescript-testing/typescript-floating-context-valid.js.map +7 -0
- package/dist/esm/useComputedPositionStyles.js +69 -48
- package/dist/esm/useComputedPositionStyles.js.map +3 -3
- package/dist/esm/utils/computePosition.js +4 -7
- package/dist/esm/utils/computePosition.js.map +2 -2
- package/dist/esm/utils/detectOverflow.js +5 -3
- package/dist/esm/utils/detectOverflow.js.map +2 -2
- package/dist/types/DSFloatingContext.d.ts +3 -2
- package/dist/types/tests/FloatingContext.event.test.d.ts +1 -0
- package/dist/types/tests/FloatingContext.exports.test.d.ts +1 -0
- package/dist/types/tests/FloatingContext.get-owner-props.test.d.ts +1 -0
- package/dist/types/tests/playwright/FloatingContext.test.playwright.d.ts +1 -0
- package/dist/types/typescript-testing/typescript-floating-context-valid.d.ts +1 -0
- package/dist/types/useComputedPositionStyles.d.ts +6 -23
- package/dist/types/utils/computePosition.d.ts +2 -2
- package/package.json +7 -7
- /package/dist/types/tests/{FloatingContext.test.d.ts → FloatingContext.a11y.test.d.ts} +0 -0
- /package/dist/types/tests/{FloatingContext.test.playwright.d.ts → FloatingContext.data-testid.test.d.ts} +0 -0
|
@@ -36,7 +36,6 @@ var React = __toESM(require("react"));
|
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
38
38
|
var import_ds_hooks_headless_tooltip = require("@elliemae/ds-hooks-headless-tooltip");
|
|
39
|
-
var import_ds_system = require("@elliemae/ds-system");
|
|
40
39
|
var import_react_desc_prop_types = require("./react-desc-prop-types.js");
|
|
41
40
|
var import_useComputedPositionStyles = require("./useComputedPositionStyles.js");
|
|
42
41
|
var import_positionObserver = require("./utils/positionObserver.js");
|
|
@@ -56,76 +55,65 @@ const useFloatingContext = (props = {}) => {
|
|
|
56
55
|
externallyControlledIsOpen
|
|
57
56
|
} = propsWithDefault;
|
|
58
57
|
const [internalIsOpen, setInternalIsOpen] = import_react.default.useState(false);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
58
|
+
const isOpen = (0, import_react.useMemo)(
|
|
59
|
+
() => externallyControlledIsOpen !== void 0 ? externallyControlledIsOpen : internalIsOpen,
|
|
60
|
+
[externallyControlledIsOpen, internalIsOpen]
|
|
61
|
+
);
|
|
62
|
+
const handleOpen = import_react.default.useCallback(() => {
|
|
64
63
|
setInternalIsOpen(true);
|
|
65
64
|
onOpen?.();
|
|
66
65
|
}, [onOpen]);
|
|
67
|
-
const
|
|
66
|
+
const handleClose = import_react.default.useCallback(() => {
|
|
68
67
|
setInternalIsOpen(false);
|
|
69
68
|
onClose?.();
|
|
70
69
|
}, [onClose]);
|
|
71
|
-
const tooltipHelpers = (0, import_ds_hooks_headless_tooltip.useHeadlessTooltip)({ onOpen:
|
|
72
|
-
const { setReferenceElement, hideTooltip, showTooltip } = tooltipHelpers;
|
|
73
|
-
const [reference, _setReference] = import_react.default.useState(null);
|
|
70
|
+
const tooltipHelpers = (0, import_ds_hooks_headless_tooltip.useHeadlessTooltip)({ onOpen: handleOpen, onClose: handleClose });
|
|
71
|
+
const { setReferenceElement, referenceElement, hideTooltip, showTooltip } = tooltipHelpers;
|
|
74
72
|
const [floating, setFloating] = import_react.default.useState(null);
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
reference,
|
|
73
|
+
const { arrowStyles, floatingStyles, hasComputedOnce, updateStyles, debouncedUpdateStyles, mutableUpdateStyles } = (0, import_useComputedPositionStyles.useComputedPositionStyles)({
|
|
74
|
+
reference: referenceElement,
|
|
78
75
|
floating,
|
|
79
76
|
placement,
|
|
80
77
|
placementOrderPreference,
|
|
81
78
|
customOffset,
|
|
82
|
-
withoutPortal
|
|
79
|
+
withoutPortal,
|
|
80
|
+
preventComputing: !isOpen,
|
|
81
|
+
debounceMs: 150
|
|
83
82
|
});
|
|
84
83
|
(0, import_react.useEffect)(() => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (reference) {
|
|
91
|
-
requestAnimationFrame(() => {
|
|
92
|
-
debouncedUpdateStyles();
|
|
84
|
+
if (!isOpen) return;
|
|
85
|
+
const observers = [];
|
|
86
|
+
if (floating) {
|
|
87
|
+
const roFloating = new ResizeObserver(() => {
|
|
88
|
+
mutableUpdateStyles.current();
|
|
93
89
|
});
|
|
90
|
+
roFloating.observe(floating);
|
|
91
|
+
observers.push(roFloating);
|
|
94
92
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}, [
|
|
112
|
-
needsToCalculateBecauseStillInvisibleWhenShouldBeOpen,
|
|
113
|
-
mutableUpdateStyles,
|
|
114
|
-
// this dependency is the point of this useEffect
|
|
115
|
-
// it will keep triggering until the position is calculated if it needs to be calculated
|
|
116
|
-
workaroundToEnsureAPositionWasCalculatedIfOpen
|
|
117
|
-
]);
|
|
118
|
-
const setReference = (0, import_ds_system.mergeRefs)(_setReference, setReferenceElement);
|
|
119
|
-
const refs = import_react.default.useMemo(
|
|
93
|
+
return () => observers.forEach((o) => o.disconnect());
|
|
94
|
+
}, [isOpen, floating, updateStyles, mutableUpdateStyles]);
|
|
95
|
+
const onObservedMovement = import_react.default.useCallback(() => {
|
|
96
|
+
if (!isOpen) return;
|
|
97
|
+
debouncedUpdateStyles();
|
|
98
|
+
}, [isOpen, debouncedUpdateStyles]);
|
|
99
|
+
(0, import_positionObserver.usePositionObserver)(referenceElement, onObservedMovement);
|
|
100
|
+
const computedFloatingStyles = (0, import_react.useMemo)(
|
|
101
|
+
() => ({
|
|
102
|
+
...floatingStyles,
|
|
103
|
+
visibility: isOpen && hasComputedOnce ? "visible" : "hidden"
|
|
104
|
+
}),
|
|
105
|
+
[floatingStyles, hasComputedOnce, isOpen]
|
|
106
|
+
);
|
|
107
|
+
const refs = (0, import_react.useMemo)(
|
|
120
108
|
() => ({
|
|
121
|
-
setReference,
|
|
109
|
+
setReference: setReferenceElement,
|
|
122
110
|
setFloating,
|
|
123
111
|
floating,
|
|
124
|
-
reference
|
|
112
|
+
reference: referenceElement
|
|
125
113
|
}),
|
|
126
|
-
[
|
|
114
|
+
[setReferenceElement, floating, referenceElement]
|
|
127
115
|
);
|
|
128
|
-
const handlers = import_react.
|
|
116
|
+
const handlers = (0, import_react.useMemo)(
|
|
129
117
|
() => ({
|
|
130
118
|
onMouseEnter: tooltipHelpers.onMouseEnter,
|
|
131
119
|
onMouseLeave: tooltipHelpers.onMouseLeave,
|
|
@@ -137,9 +125,9 @@ const useFloatingContext = (props = {}) => {
|
|
|
137
125
|
return (0, import_react.useMemo)(
|
|
138
126
|
() => ({
|
|
139
127
|
refs,
|
|
140
|
-
floatingStyles,
|
|
128
|
+
floatingStyles: computedFloatingStyles,
|
|
141
129
|
handlers,
|
|
142
|
-
isOpen
|
|
130
|
+
isOpen,
|
|
143
131
|
arrowStyles,
|
|
144
132
|
hideTooltip,
|
|
145
133
|
showTooltip,
|
|
@@ -149,13 +137,14 @@ const useFloatingContext = (props = {}) => {
|
|
|
149
137
|
portalDOMContainer,
|
|
150
138
|
animationDuration
|
|
151
139
|
},
|
|
152
|
-
mutableUpdateStyles
|
|
140
|
+
mutableUpdateStyles,
|
|
141
|
+
forceUpdatePosition: updateStyles
|
|
153
142
|
}),
|
|
154
143
|
[
|
|
155
144
|
refs,
|
|
156
|
-
|
|
145
|
+
computedFloatingStyles,
|
|
157
146
|
handlers,
|
|
158
|
-
|
|
147
|
+
isOpen,
|
|
159
148
|
arrowStyles,
|
|
160
149
|
hideTooltip,
|
|
161
150
|
showTooltip,
|
|
@@ -163,7 +152,8 @@ const useFloatingContext = (props = {}) => {
|
|
|
163
152
|
withoutAnimation,
|
|
164
153
|
portalDOMContainer,
|
|
165
154
|
animationDuration,
|
|
166
|
-
mutableUpdateStyles
|
|
155
|
+
mutableUpdateStyles,
|
|
156
|
+
updateStyles
|
|
167
157
|
]
|
|
168
158
|
);
|
|
169
159
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/DSFloatingContext.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\nimport React, {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\n/* eslint-disable consistent-return */\n/* eslint-disable max-statements */\nimport React, { useMemo, useEffect } from 'react';\nimport {\n useMemoMergePropsWithDefault,\n useValidateTypescriptPropTypes,\n describe,\n type ValidationMap,\n} from '@elliemae/ds-props-helpers';\nimport { useHeadlessTooltip } from '@elliemae/ds-hooks-headless-tooltip';\nimport type { DSHookFloatingContextT } from './react-desc-prop-types.js';\nimport { defaultProps, DSFloatingContextPropTypes } from './react-desc-prop-types.js';\nimport { useComputedPositionStyles } from './useComputedPositionStyles.js';\nimport { usePositionObserver } from './utils/positionObserver.js';\n\nconst useFloatingContext = (props: DSHookFloatingContextT.Props = {}) => {\n const propsWithDefault = useMemoMergePropsWithDefault<DSHookFloatingContextT.InternalProps>(props, defaultProps);\n useValidateTypescriptPropTypes(propsWithDefault, DSFloatingContextPropTypes, 'FloatingContext');\n\n const {\n withoutPortal,\n withoutAnimation,\n portalDOMContainer,\n animationDuration,\n placement,\n customOffset,\n placementOrderPreference,\n onOpen,\n onClose,\n externallyControlledIsOpen,\n } = propsWithDefault;\n\n const [internalIsOpen, setInternalIsOpen] = React.useState<boolean>(false);\n const isOpen = useMemo(\n () => (externallyControlledIsOpen !== undefined ? externallyControlledIsOpen : internalIsOpen),\n [externallyControlledIsOpen, internalIsOpen],\n );\n\n const handleOpen = React.useCallback(() => {\n setInternalIsOpen(true);\n onOpen?.();\n }, [onOpen]);\n\n const handleClose = React.useCallback(() => {\n setInternalIsOpen(false);\n onClose?.();\n }, [onClose]);\n\n const tooltipHelpers = useHeadlessTooltip({ onOpen: handleOpen, onClose: handleClose });\n const { setReferenceElement, referenceElement, hideTooltip, showTooltip } = tooltipHelpers;\n\n // Anchor and floating refs\n const [floating, setFloating] = React.useState<HTMLElement | null>(null);\n\n // Compute position (skip when closed)\n const { arrowStyles, floatingStyles, hasComputedOnce, updateStyles, debouncedUpdateStyles, mutableUpdateStyles } =\n useComputedPositionStyles({\n reference: referenceElement,\n floating,\n placement,\n placementOrderPreference,\n customOffset,\n withoutPortal,\n preventComputing: !isOpen,\n debounceMs: 150,\n });\n\n useEffect(() => {\n if (!isOpen) return;\n\n const observers: ResizeObserver[] = [];\n\n if (floating) {\n const roFloating = new ResizeObserver(() => {\n mutableUpdateStyles.current();\n });\n roFloating.observe(floating);\n observers.push(roFloating);\n }\n\n return () => observers.forEach((o) => o.disconnect());\n }, [isOpen, floating, updateStyles, mutableUpdateStyles]);\n\n const onObservedMovement = React.useCallback(() => {\n if (!isOpen) return;\n debouncedUpdateStyles();\n }, [isOpen, debouncedUpdateStyles]);\n usePositionObserver(referenceElement, onObservedMovement);\n\n // Expose visibility: only visible if open and already computed at least once\n const computedFloatingStyles = useMemo<React.CSSProperties>(\n () => ({\n ...floatingStyles,\n visibility: isOpen && hasComputedOnce ? 'visible' : 'hidden',\n }),\n [floatingStyles, hasComputedOnce, isOpen],\n );\n\n const refs = useMemo(\n () => ({\n setReference: setReferenceElement,\n setFloating,\n floating,\n reference: referenceElement,\n }),\n [setReferenceElement, floating, referenceElement],\n );\n\n const handlers = useMemo(\n () => ({\n onMouseEnter: tooltipHelpers.onMouseEnter,\n onMouseLeave: tooltipHelpers.onMouseLeave,\n onFocus: tooltipHelpers.onFocus,\n onBlur: tooltipHelpers.onBlur,\n }),\n [tooltipHelpers.onBlur, tooltipHelpers.onFocus, tooltipHelpers.onMouseEnter, tooltipHelpers.onMouseLeave],\n );\n\n return useMemo(\n () => ({\n refs,\n floatingStyles: computedFloatingStyles,\n handlers,\n isOpen,\n arrowStyles,\n hideTooltip,\n showTooltip,\n context: {\n withoutPortal,\n withoutAnimation,\n portalDOMContainer,\n animationDuration,\n },\n mutableUpdateStyles,\n forceUpdatePosition: updateStyles,\n }),\n [\n refs,\n computedFloatingStyles,\n handlers,\n isOpen,\n arrowStyles,\n hideTooltip,\n showTooltip,\n withoutPortal,\n withoutAnimation,\n portalDOMContainer,\n animationDuration,\n mutableUpdateStyles,\n updateStyles,\n ],\n );\n};\n\nuseFloatingContext.displayName = 'FloatingContext';\nconst UseFloatingContextWithSchema = describe(useFloatingContext);\nUseFloatingContextWithSchema.propTypes =\n DSFloatingContextPropTypes as unknown as ValidationMap<DSHookFloatingContextT.Props>;\n\nexport { useFloatingContext, UseFloatingContextWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;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MACA;AAAA,MACA,qBAAqB;AAAA,IACvB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEA,mBAAmB,cAAc;AACjC,MAAM,mCAA+B,kCAAS,kBAAkB;AAChE,6BAA6B,YAC3B;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var React = __toESM(require("react"));
|
|
25
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
26
|
+
var import_react = __toESM(require("react"));
|
|
27
|
+
var import__ = require("../index.js");
|
|
28
|
+
const testOptionalProps = {};
|
|
29
|
+
const testPartialDefaults = {
|
|
30
|
+
withoutAnimation: false,
|
|
31
|
+
withoutPortal: false,
|
|
32
|
+
animationDuration: 300
|
|
33
|
+
};
|
|
34
|
+
const testCompleteDefaults = {
|
|
35
|
+
withoutAnimation: false,
|
|
36
|
+
withoutPortal: false,
|
|
37
|
+
animationDuration: 300,
|
|
38
|
+
placement: "top",
|
|
39
|
+
customOffset: [10, 10],
|
|
40
|
+
portalDOMContainer: document.body
|
|
41
|
+
};
|
|
42
|
+
const testInternalProps = {
|
|
43
|
+
...testOptionalProps,
|
|
44
|
+
...testCompleteDefaults
|
|
45
|
+
};
|
|
46
|
+
const testInternalPropsAsSyntax = {
|
|
47
|
+
...testOptionalProps,
|
|
48
|
+
...testCompleteDefaults
|
|
49
|
+
};
|
|
50
|
+
const testExplicitDefinition = {
|
|
51
|
+
animationDuration: 300,
|
|
52
|
+
withoutAnimation: false,
|
|
53
|
+
withoutPortal: false,
|
|
54
|
+
placement: "top",
|
|
55
|
+
customOffset: [10, 10],
|
|
56
|
+
portalDOMContainer: document.body,
|
|
57
|
+
...testOptionalProps
|
|
58
|
+
};
|
|
59
|
+
const testInferedTypeCompatibility = {
|
|
60
|
+
...testOptionalProps,
|
|
61
|
+
...testPartialDefaults,
|
|
62
|
+
animationDuration: 300
|
|
63
|
+
};
|
|
64
|
+
const testDefinitionAsConst = {
|
|
65
|
+
animationDuration: 300,
|
|
66
|
+
withoutAnimation: false,
|
|
67
|
+
withoutPortal: false,
|
|
68
|
+
placement: "top",
|
|
69
|
+
portalDOMContainer: document.body
|
|
70
|
+
};
|
|
71
|
+
const ExampleUsageComponent = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
72
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
73
|
+
import__.FloatingWrapper,
|
|
74
|
+
{
|
|
75
|
+
...testExplicitDefinition,
|
|
76
|
+
innerRef: import_react.default.createRef(),
|
|
77
|
+
isOpen: true,
|
|
78
|
+
floatingStyles: {},
|
|
79
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: "Content" })
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
83
|
+
import__.FloatingWrapper,
|
|
84
|
+
{
|
|
85
|
+
...testInferedTypeCompatibility,
|
|
86
|
+
innerRef: import_react.default.createRef(),
|
|
87
|
+
isOpen: true,
|
|
88
|
+
floatingStyles: {},
|
|
89
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: "Content" })
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import__.FloatingWrapper, { ...testDefinitionAsConst, innerRef: import_react.default.createRef(), isOpen: true, floatingStyles: {}, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: "Content" }) })
|
|
93
|
+
] });
|
|
94
|
+
//# sourceMappingURL=typescript-floating-context-valid.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/typescript-testing/typescript-floating-context-valid.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */\nimport React from 'react';\nimport { FloatingWrapper } from '../index.js';\nimport type { DSHookFloatingContextT } from '../index.js';\n\n// test we expose the namespace and the namespace follows our deliverable conventions\ntype ComponentPropsForApp = DSHookFloatingContextT.Props;\ntype ComponentPropsInternals = DSHookFloatingContextT.InternalProps;\ntype ComponentPropsDefaultProps = DSHookFloatingContextT.DefaultProps;\ntype ComponentPropsOptionalProps = DSHookFloatingContextT.OptionalProps;\n\nconst testOptionalProps: ComponentPropsOptionalProps = {};\n\n// difference Props and InternalProps is that InternalProps has all the default props filled in\n// Props allows for partial defaults\nconst testPartialDefaults: Partial<ComponentPropsDefaultProps> = {\n withoutAnimation: false,\n withoutPortal: false,\n animationDuration: 300,\n};\n\n// InternalProps requires all defaults to be filled in\nconst testCompleteDefaults: Required<ComponentPropsDefaultProps> = {\n withoutAnimation: false,\n withoutPortal: false,\n animationDuration: 300,\n placement: 'top',\n customOffset: [10, 10],\n portalDOMContainer: document.body,\n};\n\nconst testInternalProps: ComponentPropsInternals = {\n ...testOptionalProps,\n ...testCompleteDefaults,\n};\n\nconst testInternalPropsAsSyntax = {\n ...testOptionalProps,\n ...testCompleteDefaults,\n} as ComponentPropsInternals;\n\n// using the explicit type definition, if there is an error, it will be marked on the key that is wrong\nconst testExplicitDefinition: ComponentPropsForApp = {\n animationDuration: 300,\n withoutAnimation: false,\n withoutPortal: false,\n placement: 'top',\n customOffset: [10, 10],\n portalDOMContainer: document.body,\n ...testOptionalProps,\n};\n\n// using the \"as\" syntax, if there is an error, it will be marking the whole object as wrong because it is not compatible with the type\nconst testInferedTypeCompatibility = {\n ...testOptionalProps,\n ...testPartialDefaults,\n animationDuration: 300,\n} as ComponentPropsForApp;\n\nconst testDefinitionAsConst = {\n animationDuration: 300,\n withoutAnimation: false,\n withoutPortal: false,\n placement: 'top',\n portalDOMContainer: document.body,\n} as const;\n\nconst ExampleUsageComponent = () => (\n <>\n {/* works with explicitly casted props, all syntaxes */}\n <FloatingWrapper\n {...testExplicitDefinition}\n innerRef={React.createRef<HTMLDivElement>()}\n isOpen\n floatingStyles={{}}\n >\n <div>Content</div>\n </FloatingWrapper>\n <FloatingWrapper\n {...testInferedTypeCompatibility}\n innerRef={React.createRef<HTMLDivElement>()}\n isOpen\n floatingStyles={{}}\n >\n <div>Content</div>\n </FloatingWrapper>\n <FloatingWrapper {...testDefinitionAsConst} innerRef={React.createRef<HTMLDivElement>()} isOpen floatingStyles={{}}>\n <div>Content</div>\n </FloatingWrapper>\n {/* works with inline values */}\n </>\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAuB;ACoErB;AAnEF,mBAAkB;AAClB,eAAgC;AAShC,MAAM,oBAAiD,CAAC;AAIxD,MAAM,sBAA2D;AAAA,EAC/D,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,mBAAmB;AACrB;AAGA,MAAM,uBAA6D;AAAA,EACjE,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,mBAAmB;AAAA,EACnB,WAAW;AAAA,EACX,cAAc,CAAC,IAAI,EAAE;AAAA,EACrB,oBAAoB,SAAS;AAC/B;AAEA,MAAM,oBAA6C;AAAA,EACjD,GAAG;AAAA,EACH,GAAG;AACL;AAEA,MAAM,4BAA4B;AAAA,EAChC,GAAG;AAAA,EACH,GAAG;AACL;AAGA,MAAM,yBAA+C;AAAA,EACnD,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,WAAW;AAAA,EACX,cAAc,CAAC,IAAI,EAAE;AAAA,EACrB,oBAAoB,SAAS;AAAA,EAC7B,GAAG;AACL;AAGA,MAAM,+BAA+B;AAAA,EACnC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,mBAAmB;AACrB;AAEA,MAAM,wBAAwB;AAAA,EAC5B,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,eAAe;AAAA,EACf,WAAW;AAAA,EACX,oBAAoB,SAAS;AAC/B;AAEA,MAAM,wBAAwB,MAC5B,4EAEE;AAAA;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,aAAAA,QAAM,UAA0B;AAAA,MAC1C,QAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MAEjB,sDAAC,SAAI,qBAAO;AAAA;AAAA,EACd;AAAA,EACA;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAU,aAAAA,QAAM,UAA0B;AAAA,MAC1C,QAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MAEjB,sDAAC,SAAI,qBAAO;AAAA;AAAA,EACd;AAAA,EACA,4CAAC,4BAAiB,GAAG,uBAAuB,UAAU,aAAAA,QAAM,UAA0B,GAAG,QAAM,MAAC,gBAAgB,CAAC,GAC/G,sDAAC,SAAI,qBAAO,GACd;AAAA,GAEF;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -32,66 +32,87 @@ __export(useComputedPositionStyles_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(useComputedPositionStyles_exports);
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
|
-
var import_react =
|
|
35
|
+
var import_react = require("react");
|
|
36
36
|
var import_lodash_es = require("lodash-es");
|
|
37
37
|
var import_computePosition = require("./utils/computePosition.js");
|
|
38
38
|
const useComputedPositionStyles = (config) => {
|
|
39
|
-
const {
|
|
40
|
-
const [arrowStyles, setArrowStyles] = (0, import_react.useState)({
|
|
41
|
-
style: { left: 0 },
|
|
42
|
-
placement: "top"
|
|
43
|
-
});
|
|
44
|
-
const [floatingStyles, setFloatingStyles] = (0, import_react.useState)({
|
|
45
|
-
position: "absolute",
|
|
46
|
-
zIndex: 3e3,
|
|
47
|
-
top: 0,
|
|
48
|
-
left: 0,
|
|
49
|
-
visibility: "hidden"
|
|
50
|
-
});
|
|
51
|
-
const canComputePosition = reference !== null && floating !== null;
|
|
52
|
-
const canAndShouldComputePosition = canComputePosition && preventComputing !== true;
|
|
53
|
-
const updateStyles = import_react.default.useCallback(() => {
|
|
54
|
-
if (canAndShouldComputePosition) {
|
|
55
|
-
const { coordsStyle, finalPlacement, coordsArrow } = (0, import_computePosition.computePosition)({
|
|
56
|
-
reference,
|
|
57
|
-
floating,
|
|
58
|
-
placement,
|
|
59
|
-
placementOrderPreference,
|
|
60
|
-
customOffset,
|
|
61
|
-
withoutPortal
|
|
62
|
-
});
|
|
63
|
-
setFloatingStyles({
|
|
64
|
-
position: "absolute",
|
|
65
|
-
zIndex: 3e3,
|
|
66
|
-
...coordsStyle
|
|
67
|
-
});
|
|
68
|
-
setArrowStyles({ style: coordsArrow, placement: finalPlacement });
|
|
69
|
-
}
|
|
70
|
-
}, [
|
|
71
|
-
canAndShouldComputePosition,
|
|
39
|
+
const {
|
|
72
40
|
reference,
|
|
73
41
|
floating,
|
|
74
42
|
placement,
|
|
75
43
|
placementOrderPreference,
|
|
76
44
|
customOffset,
|
|
77
|
-
withoutPortal
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
const
|
|
83
|
-
|
|
45
|
+
withoutPortal,
|
|
46
|
+
preventComputing = false,
|
|
47
|
+
debounceMs = 150
|
|
48
|
+
} = config;
|
|
49
|
+
const [arrowStyles, setArrowStyles] = (0, import_react.useState)({ style: { left: 0 }, placement: "top" });
|
|
50
|
+
const [floatingStyles, setFloatingStyles] = (0, import_react.useState)({
|
|
51
|
+
position: "absolute",
|
|
52
|
+
zIndex: 3e3,
|
|
53
|
+
visibility: "hidden",
|
|
54
|
+
willChange: "transform"
|
|
55
|
+
});
|
|
56
|
+
const [hasComputedOnce, setHasComputedOnce] = (0, import_react.useState)(false);
|
|
57
|
+
const canCompute = reference !== null && floating !== null && !preventComputing;
|
|
58
|
+
const updateStyles = (0, import_react.useCallback)(() => {
|
|
59
|
+
if (!canCompute) return;
|
|
60
|
+
const { coordsStyle, finalPlacement, coordsArrow } = (0, import_computePosition.computePosition)({
|
|
61
|
+
reference,
|
|
62
|
+
floating,
|
|
63
|
+
placement,
|
|
64
|
+
placementOrderPreference,
|
|
65
|
+
customOffset,
|
|
66
|
+
withoutPortal
|
|
67
|
+
});
|
|
68
|
+
setFloatingStyles((prev) => ({
|
|
84
69
|
position: "absolute",
|
|
85
70
|
zIndex: 3e3,
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
...prev,
|
|
72
|
+
...coordsStyle
|
|
73
|
+
}));
|
|
74
|
+
setArrowStyles({ style: coordsArrow, placement: finalPlacement });
|
|
75
|
+
setHasComputedOnce(true);
|
|
76
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
77
|
+
const mutableUpdateStyles = (0, import_react.useRef)(updateStyles);
|
|
78
|
+
mutableUpdateStyles.current = updateStyles;
|
|
79
|
+
const debouncedUpdateStyles = (0, import_react.useMemo)(() => {
|
|
80
|
+
const d = (0, import_lodash_es.debounce)(() => {
|
|
81
|
+
mutableUpdateStyles.current();
|
|
82
|
+
}, debounceMs);
|
|
83
|
+
return d;
|
|
84
|
+
}, [debounceMs]);
|
|
85
|
+
(0, import_react.useLayoutEffect)(
|
|
86
|
+
() => () => {
|
|
87
|
+
debouncedUpdateStyles.cancel();
|
|
88
|
+
},
|
|
89
|
+
[debouncedUpdateStyles]
|
|
90
|
+
);
|
|
91
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
92
|
+
if (canCompute) {
|
|
93
|
+
mutableUpdateStyles.current();
|
|
94
|
+
}
|
|
95
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
96
|
+
const forceUpdatePosition = (0, import_react.useCallback)(() => {
|
|
97
|
+
mutableUpdateStyles.current();
|
|
98
|
+
}, []);
|
|
99
|
+
const resetVisibilityOnly = (0, import_react.useCallback)(() => {
|
|
100
|
+
setFloatingStyles((prev) => ({
|
|
101
|
+
...prev,
|
|
88
102
|
visibility: "hidden"
|
|
89
|
-
});
|
|
90
|
-
setArrowStyles({ style: { left: 0 }, placement: "top" });
|
|
103
|
+
}));
|
|
91
104
|
}, []);
|
|
92
|
-
return import_react.
|
|
93
|
-
() => ({
|
|
94
|
-
|
|
105
|
+
return (0, import_react.useMemo)(
|
|
106
|
+
() => ({
|
|
107
|
+
arrowStyles,
|
|
108
|
+
floatingStyles,
|
|
109
|
+
hasComputedOnce,
|
|
110
|
+
updateStyles: forceUpdatePosition,
|
|
111
|
+
debouncedUpdateStyles,
|
|
112
|
+
mutableUpdateStyles,
|
|
113
|
+
resetVisibilityOnly
|
|
114
|
+
}),
|
|
115
|
+
[arrowStyles, floatingStyles, hasComputedOnce, forceUpdatePosition, debouncedUpdateStyles, resetVisibilityOnly]
|
|
95
116
|
);
|
|
96
117
|
};
|
|
97
118
|
//# sourceMappingURL=useComputedPositionStyles.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useComputedPositionStyles.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\nimport { useLayoutEffect, useMemo, useRef, useState, useCallback } from 'react';\nimport { debounce } from 'lodash-es';\nimport { type CSSProperties } from 'styled-components';\nimport { computePosition } from './utils/computePosition.js';\nimport type { DSHookFloatingContextT } from './react-desc-prop-types.js';\nimport type { PopoverArrowT } from './parts/PopoverArrow.js';\n\ntype UseComputedPositionStylesT = {\n /** Prevent computing when closed (optimization + avoids unnecessary frames) */\n preventComputing?: boolean;\n reference: Element | null;\n floating: HTMLElement | null;\n placement: DSHookFloatingContextT.PopperPlacementsT;\n placementOrderPreference?: DSHookFloatingContextT.PopperPlacementsT[];\n customOffset: [number, number];\n withoutPortal: boolean;\n /** Debounce ms for scroll/resize/observer events */\n debounceMs?: number;\n};\n\nexport const useComputedPositionStyles = (config: UseComputedPositionStylesT) => {\n const {\n reference,\n floating,\n placement,\n placementOrderPreference,\n customOffset,\n withoutPortal,\n preventComputing = false,\n debounceMs = 150,\n } = config;\n\n const [arrowStyles, setArrowStyles] = useState<PopoverArrowT>({ style: { left: 0 }, placement: 'top' });\n\n // Important: do not initialize top/left to (0,0); keep hidden until the first computation\n const [floatingStyles, setFloatingStyles] = useState<CSSProperties>({\n position: 'absolute',\n zIndex: 3000,\n visibility: 'hidden',\n willChange: 'transform',\n });\n\n const [hasComputedOnce, setHasComputedOnce] = useState(false);\n\n const canCompute = reference !== null && floating !== null && !preventComputing;\n\n const updateStyles = useCallback(() => {\n if (!canCompute) return;\n\n const { coordsStyle, finalPlacement, coordsArrow } = computePosition({\n reference,\n floating,\n placement,\n placementOrderPreference,\n customOffset,\n withoutPortal,\n });\n\n // Do not touch visibility here; it is managed outside depending on open/hasComputedOnce\n setFloatingStyles((prev) => ({\n position: 'absolute',\n zIndex: 3000,\n ...prev,\n ...coordsStyle,\n }));\n setArrowStyles({ style: coordsArrow, placement: finalPlacement });\n setHasComputedOnce(true);\n }, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);\n\n // Store latest update function in a ref to keep debounced stable\n const mutableUpdateStyles = useRef(updateStyles);\n mutableUpdateStyles.current = updateStyles;\n\n const debouncedUpdateStyles = useMemo(() => {\n const d = debounce(() => {\n mutableUpdateStyles.current();\n }, debounceMs);\n return d;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [debounceMs]);\n\n // Clean up debounce on unmount\n useLayoutEffect(\n () => () => {\n debouncedUpdateStyles.cancel();\n },\n [debouncedUpdateStyles],\n );\n\n // Recalculate BEFORE paint when dependencies change\n useLayoutEffect(() => {\n if (canCompute) {\n mutableUpdateStyles.current();\n }\n }, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);\n\n const forceUpdatePosition = useCallback(() => {\n mutableUpdateStyles.current();\n }, []);\n\n // Do not reset coordinates when closing; just hide\n const resetVisibilityOnly = useCallback(() => {\n setFloatingStyles((prev) => ({\n ...prev,\n visibility: 'hidden',\n }));\n }, []);\n\n return useMemo(\n () => ({\n arrowStyles,\n floatingStyles,\n hasComputedOnce,\n updateStyles: forceUpdatePosition,\n debouncedUpdateStyles,\n mutableUpdateStyles,\n resetVisibilityOnly,\n }),\n [arrowStyles, floatingStyles, hasComputedOnce, forceUpdatePosition, debouncedUpdateStyles, resetVisibilityOnly],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAwE;AACxE,uBAAyB;AAEzB,6BAAgC;AAiBzB,MAAM,4BAA4B,CAAC,WAAuC;AAC/E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,IACnB,aAAa;AAAA,EACf,IAAI;AAEJ,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAwB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,WAAW,MAAM,CAAC;AAGtG,QAAM,CAAC,gBAAgB,iBAAiB,QAAI,uBAAwB;AAAA,IAClE,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,YAAY;AAAA,EACd,CAAC;AAED,QAAM,CAAC,iBAAiB,kBAAkB,QAAI,uBAAS,KAAK;AAE5D,QAAM,aAAa,cAAc,QAAQ,aAAa,QAAQ,CAAC;AAE/D,QAAM,mBAAe,0BAAY,MAAM;AACrC,QAAI,CAAC,WAAY;AAEjB,UAAM,EAAE,aAAa,gBAAgB,YAAY,QAAI,wCAAgB;AAAA,MACnE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAGD,sBAAkB,CAAC,UAAU;AAAA,MAC3B,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,GAAG;AAAA,MACH,GAAG;AAAA,IACL,EAAE;AACF,mBAAe,EAAE,OAAO,aAAa,WAAW,eAAe,CAAC;AAChE,uBAAmB,IAAI;AAAA,EACzB,GAAG,CAAC,YAAY,WAAW,UAAU,WAAW,0BAA0B,cAAc,aAAa,CAAC;AAGtG,QAAM,0BAAsB,qBAAO,YAAY;AAC/C,sBAAoB,UAAU;AAE9B,QAAM,4BAAwB,sBAAQ,MAAM;AAC1C,UAAM,QAAI,2BAAS,MAAM;AACvB,0BAAoB,QAAQ;AAAA,IAC9B,GAAG,UAAU;AACb,WAAO;AAAA,EAET,GAAG,CAAC,UAAU,CAAC;AAGf;AAAA,IACE,MAAM,MAAM;AACV,4BAAsB,OAAO;AAAA,IAC/B;AAAA,IACA,CAAC,qBAAqB;AAAA,EACxB;AAGA,oCAAgB,MAAM;AACpB,QAAI,YAAY;AACd,0BAAoB,QAAQ;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,YAAY,WAAW,UAAU,WAAW,0BAA0B,cAAc,aAAa,CAAC;AAEtG,QAAM,0BAAsB,0BAAY,MAAM;AAC5C,wBAAoB,QAAQ;AAAA,EAC9B,GAAG,CAAC,CAAC;AAGL,QAAM,0BAAsB,0BAAY,MAAM;AAC5C,sBAAkB,CAAC,UAAU;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IACd,EAAE;AAAA,EACJ,GAAG,CAAC,CAAC;AAEL,aAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA,CAAC,aAAa,gBAAgB,iBAAiB,qBAAqB,uBAAuB,mBAAmB;AAAA,EAChH;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -60,6 +60,7 @@ const adjustForFixedParent = (child) => {
|
|
|
60
60
|
};
|
|
61
61
|
const computePosition = (props) => {
|
|
62
62
|
const { reference, floating, placement, placementOrderPreference, customOffset, withoutPortal } = props;
|
|
63
|
+
const scrollBarY = window.innerHeight - document.documentElement.clientHeight;
|
|
63
64
|
const parentOffsets = withoutPortal ? adjustForFixedParent(reference) : {
|
|
64
65
|
top: 0,
|
|
65
66
|
left: 0
|
|
@@ -90,7 +91,7 @@ const computePosition = (props) => {
|
|
|
90
91
|
if (checks.every((check) => {
|
|
91
92
|
return check;
|
|
92
93
|
})) {
|
|
93
|
-
coords.top = -overflows.top + window.scrollY - parentOffsets.top;
|
|
94
|
+
coords.top = -overflows.top + window.scrollY - parentOffsets.top + scrollBarY;
|
|
94
95
|
coords.left = -overflows.left + window.scrollX - parentOffsets.left;
|
|
95
96
|
finalPlacement = currentPlacement;
|
|
96
97
|
break;
|
|
@@ -104,13 +105,9 @@ const computePosition = (props) => {
|
|
|
104
105
|
}
|
|
105
106
|
return {
|
|
106
107
|
coordsStyle: {
|
|
107
|
-
|
|
108
|
+
transform: `translate3d(${Math.round(coords.left ?? 0)}px, ${Math.round(coords.top ?? 0)}px, 0)`,
|
|
108
109
|
top: 0,
|
|
109
|
-
|
|
110
|
-
// when we use transform we force the browser to use hardware acceleration
|
|
111
|
-
// hardware acceleration is faster and more reliable than the browser's own rounding
|
|
112
|
-
// it also helps with css animations and so on
|
|
113
|
-
transform: `translate(${coords.left}px, ${coords.top}px)`
|
|
110
|
+
left: 0
|
|
114
111
|
},
|
|
115
112
|
finalPlacement,
|
|
116
113
|
coordsArrow: (0, import_getArrowOffset.getArrowOffset)(finalPlacement, isVertical)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/computePosition.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-nested-ternary */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable max-params */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable arrow-body-style */\nimport type { DSHookFloatingContextT } from '../react-desc-prop-types.js';\nimport { getExpandedFallbackPlacements } from './getExpandedFallbackPlacements.js';\nimport { getArrowOffset } from './getArrowOffset.js';\nimport getOppositePlacement from './getOppositePlacement.js';\nimport { detectOverflow } from './detectOverflow.js';\n\ninterface ComputePositionProps {\n reference: Element;\n floating: HTMLElement;\n placement: DSHookFloatingContextT.PopperPlacementsT;\n placementOrderPreference?: DSHookFloatingContextT.PopperPlacementsT[];\n customOffset: [number, number];\n withoutPortal: boolean;\n}\n\nconst findFixedParent = (el: Element | null) => {\n let element = el;\n while (element && element !== document.body) {\n const style = getComputedStyle(element);\n if (style.position === 'fixed' || style.position === 'absolute') {\n return element;\n }\n element = element.parentElement;\n }\n return null;\n};\n\nconst adjustForFixedParent = (child: Element) => {\n const fixedParent = findFixedParent(child);\n if (fixedParent) {\n const rect = fixedParent.getBoundingClientRect();\n return { top: rect.top, left: rect.left };\n }\n return {\n top: 0,\n left: 0,\n };\n};\n\nexport const computePosition = (props: ComputePositionProps) => {\n const { reference, floating, placement, placementOrderPreference, customOffset, withoutPortal } = props;\n\n const parentOffsets = withoutPortal\n ? adjustForFixedParent(reference)\n : {\n top: 0,\n left: 0,\n };\n const referenceRect = reference.getBoundingClientRect();\n const floatingRect = floating.getBoundingClientRect();\n\n const variationPlacement = placement.split('-')[1];\n const fallbackPlacements = placementOrderPreference || getExpandedFallbackPlacements(placement);\n\n const coords: { top?: number; left?: number; bottom?: number; right?: number } = {};\n\n let isVertical = false;\n const placements = [placement].concat(fallbackPlacements as DSHookFloatingContextT.PopperPlacementsT[]);\n let finalPlacement = '';\n\n for (let i = 0; i < placements.length; i += 1) {\n const currentPlacement = placements[i];\n\n const currentBasePlacement = currentPlacement.split('-')[0] as keyof typeof coords;\n isVertical = ['top', 'bottom'].indexOf(currentBasePlacement) >= 0;\n\n const overflows = detectOverflow(referenceRect, floatingRect, currentPlacement, customOffset);\n\n const checks: boolean[] = [];\n\n const isStartVariation = variationPlacement === 'start';\n\n let mainVariationSide: keyof typeof coords = isVertical\n ? isStartVariation\n ? 'right'\n : 'left'\n : isStartVariation\n ? 'bottom'\n : 'top';\n\n const len = isVertical ? 'width' : 'height';\n\n if (referenceRect[len] > floatingRect[len]) {\n mainVariationSide = getOppositePlacement(mainVariationSide) as keyof typeof coords;\n }\n\n const altVariationSide = getOppositePlacement(mainVariationSide) as keyof typeof coords;\n\n checks.push(overflows[currentBasePlacement] <= 0);\n checks.push(overflows[mainVariationSide] <= 0, overflows[altVariationSide] <= 0);\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADQvB,2CAA8C;AAC9C,4BAA+B;AAC/B,kCAAiC;AACjC,4BAA+B;AAW/B,MAAM,kBAAkB,CAAC,OAAuB;AAC9C,MAAI,UAAU;AACd,SAAO,WAAW,YAAY,SAAS,MAAM;AAC3C,UAAM,QAAQ,iBAAiB,OAAO;AACtC,QAAI,MAAM,aAAa,WAAW,MAAM,aAAa,YAAY;AAC/D,aAAO;AAAA,IACT;AACA,cAAU,QAAQ;AAAA,EACpB;AACA,SAAO;AACT;AAEA,MAAM,uBAAuB,CAAC,UAAmB;AAC/C,QAAM,cAAc,gBAAgB,KAAK;AACzC,MAAI,aAAa;AACf,UAAM,OAAO,YAAY,sBAAsB;AAC/C,WAAO,EAAE,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK;AAAA,EAC1C;AACA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AACF;AAEO,MAAM,kBAAkB,CAAC,UAAgC;AAC9D,QAAM,EAAE,WAAW,UAAU,WAAW,0BAA0B,cAAc,cAAc,IAAI;AAElG,QAAM,gBAAgB,gBAClB,qBAAqB,SAAS,IAC9B;AAAA,IACE,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AACJ,QAAM,gBAAgB,UAAU,sBAAsB;AACtD,QAAM,eAAe,SAAS,sBAAsB;AAEpD,QAAM,qBAAqB,UAAU,MAAM,GAAG,EAAE,CAAC;AACjD,QAAM,qBAAqB,gCAA4B,oEAA8B,SAAS;AAE9F,QAAM,SAA2E,CAAC;AAElF,MAAI,aAAa;AACjB,QAAM,aAAa,CAAC,SAAS,EAAE,OAAO,kBAAgE;AACtG,MAAI,iBAAiB;AAErB,WAAS,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK,GAAG;AAC7C,UAAM,mBAAmB,WAAW,CAAC;AAErC,UAAM,uBAAuB,iBAAiB,MAAM,GAAG,EAAE,CAAC;AAC1D,iBAAa,CAAC,OAAO,QAAQ,EAAE,QAAQ,oBAAoB,KAAK;AAEhE,UAAM,gBAAY,sCAAe,eAAe,cAAc,kBAAkB,YAAY;AAE5F,UAAM,SAAoB,CAAC;AAE3B,UAAM,mBAAmB,uBAAuB;AAEhD,QAAI,oBAAyC,aACzC,mBACE,UACA,SACF,mBACE,WACA;AAEN,UAAM,MAAM,aAAa,UAAU;AAEnC,QAAI,cAAc,GAAG,IAAI,aAAa,GAAG,GAAG;AAC1C,8BAAoB,4BAAAA,SAAqB,iBAAiB;AAAA,IAC5D;AAEA,UAAM,uBAAmB,4BAAAA,SAAqB,iBAAiB;AAE/D,WAAO,KAAK,UAAU,oBAAoB,KAAK,CAAC;AAChD,WAAO,KAAK,UAAU,iBAAiB,KAAK,GAAG,UAAU,gBAAgB,KAAK,CAAC;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-nested-ternary */\n/* eslint-disable complexity */\n/* eslint-disable max-statements */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable max-params */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable arrow-body-style */\nimport type { DSHookFloatingContextT } from '../react-desc-prop-types.js';\nimport { getExpandedFallbackPlacements } from './getExpandedFallbackPlacements.js';\nimport { getArrowOffset } from './getArrowOffset.js';\nimport getOppositePlacement from './getOppositePlacement.js';\nimport { detectOverflow } from './detectOverflow.js';\n\ninterface ComputePositionProps {\n reference: Element;\n floating: HTMLElement;\n placement: DSHookFloatingContextT.PopperPlacementsT;\n placementOrderPreference?: DSHookFloatingContextT.PopperPlacementsT[];\n customOffset: [number, number];\n withoutPortal: boolean;\n}\n\nconst findFixedParent = (el: Element | null) => {\n let element = el;\n while (element && element !== document.body) {\n const style = getComputedStyle(element);\n if (style.position === 'fixed' || style.position === 'absolute') {\n return element;\n }\n element = element.parentElement;\n }\n return null;\n};\n\nconst adjustForFixedParent = (child: Element) => {\n const fixedParent = findFixedParent(child);\n if (fixedParent) {\n const rect = fixedParent.getBoundingClientRect();\n return { top: rect.top, left: rect.left };\n }\n return {\n top: 0,\n left: 0,\n };\n};\n\nexport const computePosition = (props: ComputePositionProps) => {\n const { reference, floating, placement, placementOrderPreference, customOffset, withoutPortal } = props;\n\n const scrollBarY = window.innerHeight - document.documentElement.clientHeight;\n\n const parentOffsets = withoutPortal\n ? adjustForFixedParent(reference)\n : {\n top: 0,\n left: 0,\n };\n const referenceRect = reference.getBoundingClientRect();\n const floatingRect = floating.getBoundingClientRect();\n\n const variationPlacement = placement.split('-')[1];\n const fallbackPlacements = placementOrderPreference || getExpandedFallbackPlacements(placement);\n\n const coords: { top?: number; left?: number; bottom?: number; right?: number } = {};\n\n let isVertical = false;\n const placements = [placement].concat(fallbackPlacements as DSHookFloatingContextT.PopperPlacementsT[]);\n let finalPlacement = '';\n\n for (let i = 0; i < placements.length; i += 1) {\n const currentPlacement = placements[i];\n\n const currentBasePlacement = currentPlacement.split('-')[0] as keyof typeof coords;\n isVertical = ['top', 'bottom'].indexOf(currentBasePlacement) >= 0;\n\n const overflows = detectOverflow(referenceRect, floatingRect, currentPlacement, customOffset);\n\n const checks: boolean[] = [];\n\n const isStartVariation = variationPlacement === 'start';\n\n let mainVariationSide: keyof typeof coords = isVertical\n ? isStartVariation\n ? 'right'\n : 'left'\n : isStartVariation\n ? 'bottom'\n : 'top';\n\n const len = isVertical ? 'width' : 'height';\n\n if (referenceRect[len] > floatingRect[len]) {\n mainVariationSide = getOppositePlacement(mainVariationSide) as keyof typeof coords;\n }\n\n const altVariationSide = getOppositePlacement(mainVariationSide) as keyof typeof coords;\n\n checks.push(overflows[currentBasePlacement] <= 0);\n checks.push(overflows[mainVariationSide] <= 0, overflows[altVariationSide] <= 0);\n if (\n checks.every((check) => {\n return check;\n })\n ) {\n coords.top = -overflows.top + window.scrollY - parentOffsets.top + scrollBarY;\n coords.left = -overflows.left + window.scrollX - parentOffsets.left;\n finalPlacement = currentPlacement;\n\n break;\n }\n }\n\n if (!finalPlacement) {\n // if we don't find a placement that fits, we use the original one\n finalPlacement = placement;\n const overflows = detectOverflow(referenceRect, floatingRect, placement, customOffset);\n coords.top = -overflows.top + window.scrollY - parentOffsets.top;\n coords.left = -overflows.left + window.scrollX - parentOffsets.left;\n }\n\n return {\n coordsStyle: {\n transform: `translate3d(${Math.round(coords.left ?? 0)}px, ${Math.round(coords.top ?? 0)}px, 0)`,\n top: 0,\n left: 0,\n },\n finalPlacement,\n coordsArrow: getArrowOffset(finalPlacement, isVertical),\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADQvB,2CAA8C;AAC9C,4BAA+B;AAC/B,kCAAiC;AACjC,4BAA+B;AAW/B,MAAM,kBAAkB,CAAC,OAAuB;AAC9C,MAAI,UAAU;AACd,SAAO,WAAW,YAAY,SAAS,MAAM;AAC3C,UAAM,QAAQ,iBAAiB,OAAO;AACtC,QAAI,MAAM,aAAa,WAAW,MAAM,aAAa,YAAY;AAC/D,aAAO;AAAA,IACT;AACA,cAAU,QAAQ;AAAA,EACpB;AACA,SAAO;AACT;AAEA,MAAM,uBAAuB,CAAC,UAAmB;AAC/C,QAAM,cAAc,gBAAgB,KAAK;AACzC,MAAI,aAAa;AACf,UAAM,OAAO,YAAY,sBAAsB;AAC/C,WAAO,EAAE,KAAK,KAAK,KAAK,MAAM,KAAK,KAAK;AAAA,EAC1C;AACA,SAAO;AAAA,IACL,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AACF;AAEO,MAAM,kBA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ACA,aAAO,MAAM,CAAC,UAAU,MAAM,OAAO,UAAU,cAAc,MAAM;AACnE,aAAO,OAAO,CAAC,UAAU,OAAO,OAAO,UAAU,cAAc;AAC/D,uBAAiB;AAEjB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,gBAAgB;AAEnB,qBAAiB;AACjB,UAAM,gBAAY,sCAAe,eAAe,cAAc,WAAW,YAAY;AACrF,WAAO,MAAM,CAAC,UAAU,MAAM,OAAO,UAAU,cAAc;AAC7D,WAAO,OAAO,CAAC,UAAU,OAAO,OAAO,UAAU,cAAc;AAAA,EACjE;AAEA,SAAO;AAAA,IACL,aAAa;AAAA,MACX,WAAW,eAAe,KAAK,MAAM,OAAO,QAAQ,CAAC,CAAC,OAAO,KAAK,MAAM,OAAO,OAAO,CAAC,CAAC;AAAA,MACxF,KAAK;AAAA,MACL,MAAM;AAAA,IACR;AAAA,IACA;AAAA,IACA,iBAAa,sCAAe,gBAAgB,UAAU;AAAA,EACxD;AACF;",
|
|
6
6
|
"names": ["getOppositePlacement"]
|
|
7
7
|
}
|
|
@@ -54,11 +54,13 @@ function domRectToObject(rect) {
|
|
|
54
54
|
const detectOverflow = (referenceRect, floatingRect, placement, customOffset) => {
|
|
55
55
|
const basePlacement = placement.split("-")[0];
|
|
56
56
|
const isVertical = ["top", "bottom"].indexOf(basePlacement) >= 0;
|
|
57
|
+
const scrollBarX = window.innerWidth - document.documentElement.clientWidth;
|
|
58
|
+
const scrollBarY = window.innerHeight - document.documentElement.clientHeight;
|
|
57
59
|
const clippingClientRect = {
|
|
58
60
|
top: 0,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
left: 0,
|
|
62
|
+
right: document.documentElement.clientWidth + scrollBarX,
|
|
63
|
+
bottom: document.documentElement.clientHeight + scrollBarY
|
|
62
64
|
};
|
|
63
65
|
const popperOffsets = (0, import_computeOffsets.default)(placement, referenceRect, floatingRect);
|
|
64
66
|
const popperClientRect = rectToClientRect({ ...domRectToObject(floatingRect), ...popperOffsets });
|