@elliemae/ds-floating-context 3.54.1 → 3.55.0-next.10
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 +50 -49
- 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 +68 -48
- package/dist/cjs/useComputedPositionStyles.js.map +3 -3
- package/dist/esm/DSFloatingContext.js +51 -50
- 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 +68 -48
- package/dist/esm/useComputedPositionStyles.js.map +3 -3
- package/dist/types/DSFloatingContext.d.ts +2 -1
- package/dist/types/parts/FloatingWrapper/config/useFloatingWrapper.d.ts +1 -1
- 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/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
|
@@ -56,67 +56,66 @@ const useFloatingContext = (props = {}) => {
|
|
|
56
56
|
externallyControlledIsOpen
|
|
57
57
|
} = propsWithDefault;
|
|
58
58
|
const [internalIsOpen, setInternalIsOpen] = import_react.default.useState(false);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
59
|
+
const isOpen = (0, import_react.useMemo)(
|
|
60
|
+
() => externallyControlledIsOpen !== void 0 ? externallyControlledIsOpen : internalIsOpen,
|
|
61
|
+
[externallyControlledIsOpen, internalIsOpen]
|
|
62
|
+
);
|
|
63
|
+
const handleOpen = import_react.default.useCallback(() => {
|
|
64
64
|
setInternalIsOpen(true);
|
|
65
65
|
onOpen?.();
|
|
66
66
|
}, [onOpen]);
|
|
67
|
-
const
|
|
67
|
+
const handleClose = import_react.default.useCallback(() => {
|
|
68
68
|
setInternalIsOpen(false);
|
|
69
69
|
onClose?.();
|
|
70
70
|
}, [onClose]);
|
|
71
|
-
const tooltipHelpers = (0, import_ds_hooks_headless_tooltip.useHeadlessTooltip)({ onOpen:
|
|
71
|
+
const tooltipHelpers = (0, import_ds_hooks_headless_tooltip.useHeadlessTooltip)({ onOpen: handleOpen, onClose: handleClose });
|
|
72
72
|
const { setReferenceElement, hideTooltip, showTooltip } = tooltipHelpers;
|
|
73
|
-
const [reference,
|
|
73
|
+
const [reference, setReferenceInternal] = import_react.default.useState(null);
|
|
74
74
|
const [floating, setFloating] = import_react.default.useState(null);
|
|
75
|
-
const
|
|
76
|
-
const { arrowStyles, floatingStyles, mutableUpdateStyles, debouncedUpdateStyles } = (0, import_useComputedPositionStyles.useComputedPositionStyles)({
|
|
75
|
+
const { arrowStyles, floatingStyles, hasComputedOnce, updateStyles, debouncedUpdateStyles, mutableUpdateStyles } = (0, import_useComputedPositionStyles.useComputedPositionStyles)({
|
|
77
76
|
reference,
|
|
78
77
|
floating,
|
|
79
78
|
placement,
|
|
80
79
|
placementOrderPreference,
|
|
81
80
|
customOffset,
|
|
82
|
-
withoutPortal
|
|
81
|
+
withoutPortal,
|
|
82
|
+
preventComputing: !isOpen,
|
|
83
|
+
debounceMs: 150
|
|
83
84
|
});
|
|
84
85
|
(0, import_react.useEffect)(() => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
requestAnimationFrame(() => {
|
|
92
|
-
debouncedUpdateStyles();
|
|
86
|
+
if (!isOpen) return;
|
|
87
|
+
const observers = [];
|
|
88
|
+
if (floating) {
|
|
89
|
+
const roFloating = new ResizeObserver(() => {
|
|
90
|
+
mutableUpdateStyles.current();
|
|
91
|
+
requestAnimationFrame(() => mutableUpdateStyles.current());
|
|
93
92
|
});
|
|
93
|
+
roFloating.observe(floating);
|
|
94
|
+
observers.push(roFloating);
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
requestAnimationFrame(() => {
|
|
99
|
-
mutableUpdateStyles?.current();
|
|
100
|
-
});
|
|
101
|
-
}, [isOpenSourceOfTruth, mutableUpdateStyles]);
|
|
102
|
-
const { visibility } = floatingStyles;
|
|
103
|
-
const needsToCalculateBecauseStillInvisibleWhenShouldBeOpen = isOpenSourceOfTruth && visibility === "hidden";
|
|
104
|
-
(0, import_react.useEffect)(() => {
|
|
105
|
-
if (needsToCalculateBecauseStillInvisibleWhenShouldBeOpen) {
|
|
106
|
-
mutableUpdateStyles?.current();
|
|
107
|
-
requestAnimationFrame(() => {
|
|
108
|
-
setWorkaroundToEnsureAPositionWasCalculatedIfOpen((o) => o + 1);
|
|
96
|
+
if (reference) {
|
|
97
|
+
const roRef = new ResizeObserver(() => {
|
|
98
|
+
mutableUpdateStyles.current();
|
|
109
99
|
});
|
|
100
|
+
roRef.observe(reference);
|
|
101
|
+
observers.push(roRef);
|
|
110
102
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
103
|
+
return () => observers.forEach((o) => o.disconnect());
|
|
104
|
+
}, [isOpen, floating, reference, mutableUpdateStyles]);
|
|
105
|
+
const onObservedMovement = import_react.default.useCallback(() => {
|
|
106
|
+
if (!isOpen) return;
|
|
107
|
+
debouncedUpdateStyles();
|
|
108
|
+
}, [isOpen, debouncedUpdateStyles]);
|
|
109
|
+
(0, import_positionObserver.usePositionObserver)(reference, onObservedMovement);
|
|
110
|
+
const computedFloatingStyles = (0, import_react.useMemo)(
|
|
111
|
+
() => ({
|
|
112
|
+
...floatingStyles,
|
|
113
|
+
visibility: isOpen && hasComputedOnce ? "visible" : "hidden"
|
|
114
|
+
}),
|
|
115
|
+
[floatingStyles, isOpen, hasComputedOnce]
|
|
116
|
+
);
|
|
117
|
+
const setReference = (0, import_ds_system.mergeRefs)(setReferenceInternal, setReferenceElement);
|
|
118
|
+
const refs = (0, import_react.useMemo)(
|
|
120
119
|
() => ({
|
|
121
120
|
setReference,
|
|
122
121
|
setFloating,
|
|
@@ -125,7 +124,7 @@ const useFloatingContext = (props = {}) => {
|
|
|
125
124
|
}),
|
|
126
125
|
[setReference, floating, reference]
|
|
127
126
|
);
|
|
128
|
-
const handlers = import_react.
|
|
127
|
+
const handlers = (0, import_react.useMemo)(
|
|
129
128
|
() => ({
|
|
130
129
|
onMouseEnter: tooltipHelpers.onMouseEnter,
|
|
131
130
|
onMouseLeave: tooltipHelpers.onMouseLeave,
|
|
@@ -137,9 +136,9 @@ const useFloatingContext = (props = {}) => {
|
|
|
137
136
|
return (0, import_react.useMemo)(
|
|
138
137
|
() => ({
|
|
139
138
|
refs,
|
|
140
|
-
floatingStyles,
|
|
139
|
+
floatingStyles: computedFloatingStyles,
|
|
141
140
|
handlers,
|
|
142
|
-
isOpen
|
|
141
|
+
isOpen,
|
|
143
142
|
arrowStyles,
|
|
144
143
|
hideTooltip,
|
|
145
144
|
showTooltip,
|
|
@@ -149,13 +148,14 @@ const useFloatingContext = (props = {}) => {
|
|
|
149
148
|
portalDOMContainer,
|
|
150
149
|
animationDuration
|
|
151
150
|
},
|
|
152
|
-
mutableUpdateStyles
|
|
151
|
+
mutableUpdateStyles,
|
|
152
|
+
forceUpdatePosition: updateStyles
|
|
153
153
|
}),
|
|
154
154
|
[
|
|
155
155
|
refs,
|
|
156
|
-
|
|
156
|
+
computedFloatingStyles,
|
|
157
157
|
handlers,
|
|
158
|
-
|
|
158
|
+
isOpen,
|
|
159
159
|
arrowStyles,
|
|
160
160
|
hideTooltip,
|
|
161
161
|
showTooltip,
|
|
@@ -163,7 +163,8 @@ const useFloatingContext = (props = {}) => {
|
|
|
163
163
|
withoutAnimation,
|
|
164
164
|
portalDOMContainer,
|
|
165
165
|
animationDuration,
|
|
166
|
-
mutableUpdateStyles
|
|
166
|
+
mutableUpdateStyles,
|
|
167
|
+
updateStyles
|
|
167
168
|
]
|
|
168
169
|
);
|
|
169
170
|
};
|
|
@@ -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 { mergeRefs } from '@elliemae/ds-system';\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, hideTooltip, showTooltip } = tooltipHelpers;\n\n // Anchor and floating refs\n const [reference, setReferenceInternal] = React.useState<Element | null>(null);\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,\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 // inmediato + siguiente frame para asentar\n mutableUpdateStyles.current();\n requestAnimationFrame(() => mutableUpdateStyles.current());\n });\n roFloating.observe(floating);\n observers.push(roFloating);\n }\n\n if (reference) {\n const roRef = new ResizeObserver(() => {\n mutableUpdateStyles.current();\n });\n roRef.observe(reference);\n observers.push(roRef);\n }\n\n return () => observers.forEach((o) => o.disconnect());\n }, [isOpen, floating, reference, mutableUpdateStyles]);\n\n const onObservedMovement = React.useCallback(() => {\n if (!isOpen) return;\n debouncedUpdateStyles();\n }, [isOpen, debouncedUpdateStyles]);\n usePositionObserver(reference, 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, isOpen, hasComputedOnce],\n );\n\n const setReference = mergeRefs(setReferenceInternal, setReferenceElement);\n\n const refs = useMemo(\n () => ({\n setReference,\n setFloating,\n floating,\n reference,\n }),\n [setReference, floating, reference],\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,mBAA0C;AAC1C,8BAKO;AACP,uCAAmC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A,IACL,OAAO;AAAA,MACL;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,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,86 @@ __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: "top,left"
|
|
55
|
+
// hint to browser for smoother positioning updates
|
|
56
|
+
});
|
|
57
|
+
const [hasComputedOnce, setHasComputedOnce] = (0, import_react.useState)(false);
|
|
58
|
+
const canCompute = reference !== null && floating !== null && !preventComputing;
|
|
59
|
+
const updateStyles = (0, import_react.useCallback)(() => {
|
|
60
|
+
if (!canCompute) return;
|
|
61
|
+
const { coordsStyle, finalPlacement, coordsArrow } = (0, import_computePosition.computePosition)({
|
|
62
|
+
reference,
|
|
63
|
+
floating,
|
|
64
|
+
placement,
|
|
65
|
+
placementOrderPreference,
|
|
66
|
+
customOffset,
|
|
67
|
+
withoutPortal
|
|
68
|
+
});
|
|
69
|
+
setFloatingStyles((prev) => ({
|
|
84
70
|
position: "absolute",
|
|
85
71
|
zIndex: 3e3,
|
|
86
|
-
|
|
87
|
-
|
|
72
|
+
...prev,
|
|
73
|
+
...coordsStyle
|
|
74
|
+
}));
|
|
75
|
+
setArrowStyles({ style: coordsArrow, placement: finalPlacement });
|
|
76
|
+
setHasComputedOnce(true);
|
|
77
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
78
|
+
const mutableUpdateStyles = (0, import_react.useRef)(updateStyles);
|
|
79
|
+
mutableUpdateStyles.current = updateStyles;
|
|
80
|
+
const debouncedUpdateStyles = (0, import_react.useMemo)(() => {
|
|
81
|
+
const d = (0, import_lodash_es.debounce)(() => mutableUpdateStyles.current(), debounceMs);
|
|
82
|
+
return d;
|
|
83
|
+
}, [debounceMs]);
|
|
84
|
+
(0, import_react.useLayoutEffect)(
|
|
85
|
+
() => () => {
|
|
86
|
+
debouncedUpdateStyles.cancel();
|
|
87
|
+
},
|
|
88
|
+
[debouncedUpdateStyles]
|
|
89
|
+
);
|
|
90
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
91
|
+
if (canCompute) {
|
|
92
|
+
mutableUpdateStyles.current();
|
|
93
|
+
}
|
|
94
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
95
|
+
const forceUpdatePosition = (0, import_react.useCallback)(() => {
|
|
96
|
+
mutableUpdateStyles.current();
|
|
97
|
+
}, []);
|
|
98
|
+
const resetVisibilityOnly = (0, import_react.useCallback)(() => {
|
|
99
|
+
setFloatingStyles((prev) => ({
|
|
100
|
+
...prev,
|
|
88
101
|
visibility: "hidden"
|
|
89
|
-
});
|
|
90
|
-
setArrowStyles({ style: { left: 0 }, placement: "top" });
|
|
102
|
+
}));
|
|
91
103
|
}, []);
|
|
92
|
-
return import_react.
|
|
93
|
-
() => ({
|
|
94
|
-
|
|
104
|
+
return (0, import_react.useMemo)(
|
|
105
|
+
() => ({
|
|
106
|
+
arrowStyles,
|
|
107
|
+
floatingStyles,
|
|
108
|
+
hasComputedOnce,
|
|
109
|
+
updateStyles: forceUpdatePosition,
|
|
110
|
+
debouncedUpdateStyles,
|
|
111
|
+
mutableUpdateStyles,
|
|
112
|
+
resetVisibilityOnly
|
|
113
|
+
}),
|
|
114
|
+
[arrowStyles, floatingStyles, hasComputedOnce, forceUpdatePosition, debouncedUpdateStyles, resetVisibilityOnly]
|
|
95
115
|
);
|
|
96
116
|
};
|
|
97
117
|
//# 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: 'top,left', // hint to browser for smoother positioning updates\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(() => mutableUpdateStyles.current(), 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;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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} from "react";
|
|
3
3
|
import {
|
|
4
4
|
useMemoMergePropsWithDefault,
|
|
5
5
|
useValidateTypescriptPropTypes,
|
|
@@ -26,67 +26,66 @@ const useFloatingContext = (props = {}) => {
|
|
|
26
26
|
externallyControlledIsOpen
|
|
27
27
|
} = propsWithDefault;
|
|
28
28
|
const [internalIsOpen, setInternalIsOpen] = React2.useState(false);
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
29
|
+
const isOpen = useMemo(
|
|
30
|
+
() => externallyControlledIsOpen !== void 0 ? externallyControlledIsOpen : internalIsOpen,
|
|
31
|
+
[externallyControlledIsOpen, internalIsOpen]
|
|
32
|
+
);
|
|
33
|
+
const handleOpen = React2.useCallback(() => {
|
|
34
34
|
setInternalIsOpen(true);
|
|
35
35
|
onOpen?.();
|
|
36
36
|
}, [onOpen]);
|
|
37
|
-
const
|
|
37
|
+
const handleClose = React2.useCallback(() => {
|
|
38
38
|
setInternalIsOpen(false);
|
|
39
39
|
onClose?.();
|
|
40
40
|
}, [onClose]);
|
|
41
|
-
const tooltipHelpers = useHeadlessTooltip({ onOpen:
|
|
41
|
+
const tooltipHelpers = useHeadlessTooltip({ onOpen: handleOpen, onClose: handleClose });
|
|
42
42
|
const { setReferenceElement, hideTooltip, showTooltip } = tooltipHelpers;
|
|
43
|
-
const [reference,
|
|
43
|
+
const [reference, setReferenceInternal] = React2.useState(null);
|
|
44
44
|
const [floating, setFloating] = React2.useState(null);
|
|
45
|
-
const
|
|
46
|
-
const { arrowStyles, floatingStyles, mutableUpdateStyles, debouncedUpdateStyles } = useComputedPositionStyles({
|
|
45
|
+
const { arrowStyles, floatingStyles, hasComputedOnce, updateStyles, debouncedUpdateStyles, mutableUpdateStyles } = useComputedPositionStyles({
|
|
47
46
|
reference,
|
|
48
47
|
floating,
|
|
49
48
|
placement,
|
|
50
49
|
placementOrderPreference,
|
|
51
50
|
customOffset,
|
|
52
|
-
withoutPortal
|
|
51
|
+
withoutPortal,
|
|
52
|
+
preventComputing: !isOpen,
|
|
53
|
+
debounceMs: 150
|
|
53
54
|
});
|
|
54
55
|
useEffect(() => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
requestAnimationFrame(() => {
|
|
62
|
-
debouncedUpdateStyles();
|
|
56
|
+
if (!isOpen) return;
|
|
57
|
+
const observers = [];
|
|
58
|
+
if (floating) {
|
|
59
|
+
const roFloating = new ResizeObserver(() => {
|
|
60
|
+
mutableUpdateStyles.current();
|
|
61
|
+
requestAnimationFrame(() => mutableUpdateStyles.current());
|
|
63
62
|
});
|
|
63
|
+
roFloating.observe(floating);
|
|
64
|
+
observers.push(roFloating);
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
requestAnimationFrame(() => {
|
|
69
|
-
mutableUpdateStyles?.current();
|
|
70
|
-
});
|
|
71
|
-
}, [isOpenSourceOfTruth, mutableUpdateStyles]);
|
|
72
|
-
const { visibility } = floatingStyles;
|
|
73
|
-
const needsToCalculateBecauseStillInvisibleWhenShouldBeOpen = isOpenSourceOfTruth && visibility === "hidden";
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
if (needsToCalculateBecauseStillInvisibleWhenShouldBeOpen) {
|
|
76
|
-
mutableUpdateStyles?.current();
|
|
77
|
-
requestAnimationFrame(() => {
|
|
78
|
-
setWorkaroundToEnsureAPositionWasCalculatedIfOpen((o) => o + 1);
|
|
66
|
+
if (reference) {
|
|
67
|
+
const roRef = new ResizeObserver(() => {
|
|
68
|
+
mutableUpdateStyles.current();
|
|
79
69
|
});
|
|
70
|
+
roRef.observe(reference);
|
|
71
|
+
observers.push(roRef);
|
|
80
72
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
73
|
+
return () => observers.forEach((o) => o.disconnect());
|
|
74
|
+
}, [isOpen, floating, reference, mutableUpdateStyles]);
|
|
75
|
+
const onObservedMovement = React2.useCallback(() => {
|
|
76
|
+
if (!isOpen) return;
|
|
77
|
+
debouncedUpdateStyles();
|
|
78
|
+
}, [isOpen, debouncedUpdateStyles]);
|
|
79
|
+
usePositionObserver(reference, onObservedMovement);
|
|
80
|
+
const computedFloatingStyles = useMemo(
|
|
81
|
+
() => ({
|
|
82
|
+
...floatingStyles,
|
|
83
|
+
visibility: isOpen && hasComputedOnce ? "visible" : "hidden"
|
|
84
|
+
}),
|
|
85
|
+
[floatingStyles, isOpen, hasComputedOnce]
|
|
86
|
+
);
|
|
87
|
+
const setReference = mergeRefs(setReferenceInternal, setReferenceElement);
|
|
88
|
+
const refs = useMemo(
|
|
90
89
|
() => ({
|
|
91
90
|
setReference,
|
|
92
91
|
setFloating,
|
|
@@ -95,7 +94,7 @@ const useFloatingContext = (props = {}) => {
|
|
|
95
94
|
}),
|
|
96
95
|
[setReference, floating, reference]
|
|
97
96
|
);
|
|
98
|
-
const handlers =
|
|
97
|
+
const handlers = useMemo(
|
|
99
98
|
() => ({
|
|
100
99
|
onMouseEnter: tooltipHelpers.onMouseEnter,
|
|
101
100
|
onMouseLeave: tooltipHelpers.onMouseLeave,
|
|
@@ -107,9 +106,9 @@ const useFloatingContext = (props = {}) => {
|
|
|
107
106
|
return useMemo(
|
|
108
107
|
() => ({
|
|
109
108
|
refs,
|
|
110
|
-
floatingStyles,
|
|
109
|
+
floatingStyles: computedFloatingStyles,
|
|
111
110
|
handlers,
|
|
112
|
-
isOpen
|
|
111
|
+
isOpen,
|
|
113
112
|
arrowStyles,
|
|
114
113
|
hideTooltip,
|
|
115
114
|
showTooltip,
|
|
@@ -119,13 +118,14 @@ const useFloatingContext = (props = {}) => {
|
|
|
119
118
|
portalDOMContainer,
|
|
120
119
|
animationDuration
|
|
121
120
|
},
|
|
122
|
-
mutableUpdateStyles
|
|
121
|
+
mutableUpdateStyles,
|
|
122
|
+
forceUpdatePosition: updateStyles
|
|
123
123
|
}),
|
|
124
124
|
[
|
|
125
125
|
refs,
|
|
126
|
-
|
|
126
|
+
computedFloatingStyles,
|
|
127
127
|
handlers,
|
|
128
|
-
|
|
128
|
+
isOpen,
|
|
129
129
|
arrowStyles,
|
|
130
130
|
hideTooltip,
|
|
131
131
|
showTooltip,
|
|
@@ -133,7 +133,8 @@ const useFloatingContext = (props = {}) => {
|
|
|
133
133
|
withoutAnimation,
|
|
134
134
|
portalDOMContainer,
|
|
135
135
|
animationDuration,
|
|
136
|
-
mutableUpdateStyles
|
|
136
|
+
mutableUpdateStyles,
|
|
137
|
+
updateStyles
|
|
137
138
|
]
|
|
138
139
|
);
|
|
139
140
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSFloatingContext.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\nimport React, {
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* 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 { mergeRefs } from '@elliemae/ds-system';\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, hideTooltip, showTooltip } = tooltipHelpers;\n\n // Anchor and floating refs\n const [reference, setReferenceInternal] = React.useState<Element | null>(null);\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,\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 // inmediato + siguiente frame para asentar\n mutableUpdateStyles.current();\n requestAnimationFrame(() => mutableUpdateStyles.current());\n });\n roFloating.observe(floating);\n observers.push(roFloating);\n }\n\n if (reference) {\n const roRef = new ResizeObserver(() => {\n mutableUpdateStyles.current();\n });\n roRef.observe(reference);\n observers.push(roRef);\n }\n\n return () => observers.forEach((o) => o.disconnect());\n }, [isOpen, floating, reference, mutableUpdateStyles]);\n\n const onObservedMovement = React.useCallback(() => {\n if (!isOpen) return;\n debouncedUpdateStyles();\n }, [isOpen, debouncedUpdateStyles]);\n usePositionObserver(reference, 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, isOpen, hasComputedOnce],\n );\n\n const setReference = mergeRefs(setReferenceInternal, setReferenceElement);\n\n const refs = useMemo(\n () => ({\n setReference,\n setFloating,\n floating,\n reference,\n }),\n [setReference, floating, reference],\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"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACGvB,OAAOA,UAAS,SAAS,iBAAiB;AAC1C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AA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;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,QACP;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,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,+BAA+B,SAAS,kBAAkB;AAChE,6BAA6B,YAC3B;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import React2 from "react";
|
|
4
|
+
import { FloatingWrapper } from "../index.js";
|
|
5
|
+
const testOptionalProps = {};
|
|
6
|
+
const testPartialDefaults = {
|
|
7
|
+
withoutAnimation: false,
|
|
8
|
+
withoutPortal: false,
|
|
9
|
+
animationDuration: 300
|
|
10
|
+
};
|
|
11
|
+
const testCompleteDefaults = {
|
|
12
|
+
withoutAnimation: false,
|
|
13
|
+
withoutPortal: false,
|
|
14
|
+
animationDuration: 300,
|
|
15
|
+
placement: "top",
|
|
16
|
+
customOffset: [10, 10],
|
|
17
|
+
portalDOMContainer: document.body
|
|
18
|
+
};
|
|
19
|
+
const testInternalProps = {
|
|
20
|
+
...testOptionalProps,
|
|
21
|
+
...testCompleteDefaults
|
|
22
|
+
};
|
|
23
|
+
const testInternalPropsAsSyntax = {
|
|
24
|
+
...testOptionalProps,
|
|
25
|
+
...testCompleteDefaults
|
|
26
|
+
};
|
|
27
|
+
const testExplicitDefinition = {
|
|
28
|
+
animationDuration: 300,
|
|
29
|
+
withoutAnimation: false,
|
|
30
|
+
withoutPortal: false,
|
|
31
|
+
placement: "top",
|
|
32
|
+
customOffset: [10, 10],
|
|
33
|
+
portalDOMContainer: document.body,
|
|
34
|
+
...testOptionalProps
|
|
35
|
+
};
|
|
36
|
+
const testInferedTypeCompatibility = {
|
|
37
|
+
...testOptionalProps,
|
|
38
|
+
...testPartialDefaults,
|
|
39
|
+
animationDuration: 300
|
|
40
|
+
};
|
|
41
|
+
const testDefinitionAsConst = {
|
|
42
|
+
animationDuration: 300,
|
|
43
|
+
withoutAnimation: false,
|
|
44
|
+
withoutPortal: false,
|
|
45
|
+
placement: "top",
|
|
46
|
+
portalDOMContainer: document.body
|
|
47
|
+
};
|
|
48
|
+
const ExampleUsageComponent = () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
|
+
/* @__PURE__ */ jsx(
|
|
50
|
+
FloatingWrapper,
|
|
51
|
+
{
|
|
52
|
+
...testExplicitDefinition,
|
|
53
|
+
innerRef: React2.createRef(),
|
|
54
|
+
isOpen: true,
|
|
55
|
+
floatingStyles: {},
|
|
56
|
+
children: /* @__PURE__ */ jsx("div", { children: "Content" })
|
|
57
|
+
}
|
|
58
|
+
),
|
|
59
|
+
/* @__PURE__ */ jsx(
|
|
60
|
+
FloatingWrapper,
|
|
61
|
+
{
|
|
62
|
+
...testInferedTypeCompatibility,
|
|
63
|
+
innerRef: React2.createRef(),
|
|
64
|
+
isOpen: true,
|
|
65
|
+
floatingStyles: {},
|
|
66
|
+
children: /* @__PURE__ */ jsx("div", { children: "Content" })
|
|
67
|
+
}
|
|
68
|
+
),
|
|
69
|
+
/* @__PURE__ */ jsx(FloatingWrapper, { ...testDefinitionAsConst, innerRef: React2.createRef(), isOpen: true, floatingStyles: {}, children: /* @__PURE__ */ jsx("div", { children: "Content" }) })
|
|
70
|
+
] });
|
|
71
|
+
//# 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,YAAY,WAAW;ACoErB,mBAQI,KARJ;AAnEF,OAAOA,YAAW;AAClB,SAAS,uBAAuB;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,iCAEE;AAAA;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAUA,OAAM,UAA0B;AAAA,MAC1C,QAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MAEjB,8BAAC,SAAI,qBAAO;AAAA;AAAA,EACd;AAAA,EACA;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,UAAUA,OAAM,UAA0B;AAAA,MAC1C,QAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MAEjB,8BAAC,SAAI,qBAAO;AAAA;AAAA,EACd;AAAA,EACA,oBAAC,mBAAiB,GAAG,uBAAuB,UAAUA,OAAM,UAA0B,GAAG,QAAM,MAAC,gBAAgB,CAAC,GAC/G,8BAAC,SAAI,qBAAO,GACd;AAAA,GAEF;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -1,64 +1,84 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { useLayoutEffect, useMemo, useRef, useState, useCallback } from "react";
|
|
3
3
|
import { debounce } from "lodash-es";
|
|
4
4
|
import { computePosition } from "./utils/computePosition.js";
|
|
5
5
|
const useComputedPositionStyles = (config) => {
|
|
6
|
-
const {
|
|
7
|
-
const [arrowStyles, setArrowStyles] = useState({
|
|
8
|
-
style: { left: 0 },
|
|
9
|
-
placement: "top"
|
|
10
|
-
});
|
|
11
|
-
const [floatingStyles, setFloatingStyles] = useState({
|
|
12
|
-
position: "absolute",
|
|
13
|
-
zIndex: 3e3,
|
|
14
|
-
top: 0,
|
|
15
|
-
left: 0,
|
|
16
|
-
visibility: "hidden"
|
|
17
|
-
});
|
|
18
|
-
const canComputePosition = reference !== null && floating !== null;
|
|
19
|
-
const canAndShouldComputePosition = canComputePosition && preventComputing !== true;
|
|
20
|
-
const updateStyles = React2.useCallback(() => {
|
|
21
|
-
if (canAndShouldComputePosition) {
|
|
22
|
-
const { coordsStyle, finalPlacement, coordsArrow } = computePosition({
|
|
23
|
-
reference,
|
|
24
|
-
floating,
|
|
25
|
-
placement,
|
|
26
|
-
placementOrderPreference,
|
|
27
|
-
customOffset,
|
|
28
|
-
withoutPortal
|
|
29
|
-
});
|
|
30
|
-
setFloatingStyles({
|
|
31
|
-
position: "absolute",
|
|
32
|
-
zIndex: 3e3,
|
|
33
|
-
...coordsStyle
|
|
34
|
-
});
|
|
35
|
-
setArrowStyles({ style: coordsArrow, placement: finalPlacement });
|
|
36
|
-
}
|
|
37
|
-
}, [
|
|
38
|
-
canAndShouldComputePosition,
|
|
6
|
+
const {
|
|
39
7
|
reference,
|
|
40
8
|
floating,
|
|
41
9
|
placement,
|
|
42
10
|
placementOrderPreference,
|
|
43
11
|
customOffset,
|
|
44
|
-
withoutPortal
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
|
|
12
|
+
withoutPortal,
|
|
13
|
+
preventComputing = false,
|
|
14
|
+
debounceMs = 150
|
|
15
|
+
} = config;
|
|
16
|
+
const [arrowStyles, setArrowStyles] = useState({ style: { left: 0 }, placement: "top" });
|
|
17
|
+
const [floatingStyles, setFloatingStyles] = useState({
|
|
18
|
+
position: "absolute",
|
|
19
|
+
zIndex: 3e3,
|
|
20
|
+
visibility: "hidden",
|
|
21
|
+
willChange: "top,left"
|
|
22
|
+
// hint to browser for smoother positioning updates
|
|
23
|
+
});
|
|
24
|
+
const [hasComputedOnce, setHasComputedOnce] = useState(false);
|
|
25
|
+
const canCompute = reference !== null && floating !== null && !preventComputing;
|
|
26
|
+
const updateStyles = useCallback(() => {
|
|
27
|
+
if (!canCompute) return;
|
|
28
|
+
const { coordsStyle, finalPlacement, coordsArrow } = computePosition({
|
|
29
|
+
reference,
|
|
30
|
+
floating,
|
|
31
|
+
placement,
|
|
32
|
+
placementOrderPreference,
|
|
33
|
+
customOffset,
|
|
34
|
+
withoutPortal
|
|
35
|
+
});
|
|
36
|
+
setFloatingStyles((prev) => ({
|
|
51
37
|
position: "absolute",
|
|
52
38
|
zIndex: 3e3,
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
...prev,
|
|
40
|
+
...coordsStyle
|
|
41
|
+
}));
|
|
42
|
+
setArrowStyles({ style: coordsArrow, placement: finalPlacement });
|
|
43
|
+
setHasComputedOnce(true);
|
|
44
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
45
|
+
const mutableUpdateStyles = useRef(updateStyles);
|
|
46
|
+
mutableUpdateStyles.current = updateStyles;
|
|
47
|
+
const debouncedUpdateStyles = useMemo(() => {
|
|
48
|
+
const d = debounce(() => mutableUpdateStyles.current(), debounceMs);
|
|
49
|
+
return d;
|
|
50
|
+
}, [debounceMs]);
|
|
51
|
+
useLayoutEffect(
|
|
52
|
+
() => () => {
|
|
53
|
+
debouncedUpdateStyles.cancel();
|
|
54
|
+
},
|
|
55
|
+
[debouncedUpdateStyles]
|
|
56
|
+
);
|
|
57
|
+
useLayoutEffect(() => {
|
|
58
|
+
if (canCompute) {
|
|
59
|
+
mutableUpdateStyles.current();
|
|
60
|
+
}
|
|
61
|
+
}, [canCompute, reference, floating, placement, placementOrderPreference, customOffset, withoutPortal]);
|
|
62
|
+
const forceUpdatePosition = useCallback(() => {
|
|
63
|
+
mutableUpdateStyles.current();
|
|
64
|
+
}, []);
|
|
65
|
+
const resetVisibilityOnly = useCallback(() => {
|
|
66
|
+
setFloatingStyles((prev) => ({
|
|
67
|
+
...prev,
|
|
55
68
|
visibility: "hidden"
|
|
56
|
-
});
|
|
57
|
-
setArrowStyles({ style: { left: 0 }, placement: "top" });
|
|
69
|
+
}));
|
|
58
70
|
}, []);
|
|
59
|
-
return
|
|
60
|
-
() => ({
|
|
61
|
-
|
|
71
|
+
return useMemo(
|
|
72
|
+
() => ({
|
|
73
|
+
arrowStyles,
|
|
74
|
+
floatingStyles,
|
|
75
|
+
hasComputedOnce,
|
|
76
|
+
updateStyles: forceUpdatePosition,
|
|
77
|
+
debouncedUpdateStyles,
|
|
78
|
+
mutableUpdateStyles,
|
|
79
|
+
resetVisibilityOnly
|
|
80
|
+
}),
|
|
81
|
+
[arrowStyles, floatingStyles, hasComputedOnce, forceUpdatePosition, debouncedUpdateStyles, resetVisibilityOnly]
|
|
62
82
|
);
|
|
63
83
|
};
|
|
64
84
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/useComputedPositionStyles.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* 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: 'top,left', // hint to browser for smoother positioning updates\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(() => mutableUpdateStyles.current(), 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"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,iBAAiB,SAAS,QAAQ,UAAU,mBAAmB;AACxE,SAAS,gBAAgB;AAEzB,SAAS,uBAAuB;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,IAAI,SAAwB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,WAAW,MAAM,CAAC;AAGtG,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAwB;AAAA,IAClE,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,YAAY;AAAA;AAAA,EACd,CAAC;AAED,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAS,KAAK;AAE5D,QAAM,aAAa,cAAc,QAAQ,aAAa,QAAQ,CAAC;AAE/D,QAAM,eAAe,YAAY,MAAM;AACrC,QAAI,CAAC,WAAY;AAEjB,UAAM,EAAE,aAAa,gBAAgB,YAAY,IAAI,gBAAgB;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,sBAAsB,OAAO,YAAY;AAC/C,sBAAoB,UAAU;AAE9B,QAAM,wBAAwB,QAAQ,MAAM;AAC1C,UAAM,IAAI,SAAS,MAAM,oBAAoB,QAAQ,GAAG,UAAU;AAClE,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,kBAAgB,MAAM;AACpB,QAAI,YAAY;AACd,0BAAoB,QAAQ;AAAA,IAC9B;AAAA,EACF,GAAG,CAAC,YAAY,WAAW,UAAU,WAAW,0BAA0B,cAAc,aAAa,CAAC;AAEtG,QAAM,sBAAsB,YAAY,MAAM;AAC5C,wBAAoB,QAAQ;AAAA,EAC9B,GAAG,CAAC,CAAC;AAGL,QAAM,sBAAsB,YAAY,MAAM;AAC5C,sBAAkB,CAAC,UAAU;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IACd,EAAE;AAAA,EACJ,GAAG,CAAC,CAAC;AAEL,SAAO;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
|
}
|
|
@@ -8,7 +8,7 @@ declare const useFloatingContext: {
|
|
|
8
8
|
floating: HTMLElement | null;
|
|
9
9
|
reference: Element | null;
|
|
10
10
|
};
|
|
11
|
-
floatingStyles:
|
|
11
|
+
floatingStyles: React.CSSProperties;
|
|
12
12
|
handlers: {
|
|
13
13
|
onMouseEnter: () => void;
|
|
14
14
|
onMouseLeave: () => void;
|
|
@@ -26,6 +26,7 @@ declare const useFloatingContext: {
|
|
|
26
26
|
animationDuration: number;
|
|
27
27
|
};
|
|
28
28
|
mutableUpdateStyles: React.MutableRefObject<() => void>;
|
|
29
|
+
forceUpdatePosition: () => void;
|
|
29
30
|
};
|
|
30
31
|
displayName: string;
|
|
31
32
|
};
|
|
@@ -115,7 +115,7 @@ export declare const useFloatingWrapper: (propsFromUser: DSFloatingWrapperT.Prop
|
|
|
115
115
|
onBlurCapture?: React.FocusEventHandler<Element> | undefined;
|
|
116
116
|
onChange?: React.FormEventHandler<Element> | undefined;
|
|
117
117
|
onChangeCapture?: React.FormEventHandler<Element> | undefined;
|
|
118
|
-
onBeforeInput?: React.
|
|
118
|
+
onBeforeInput?: React.InputEventHandler<Element> | undefined;
|
|
119
119
|
onBeforeInputCapture?: React.FormEventHandler<Element> | undefined;
|
|
120
120
|
onInput?: React.FormEventHandler<Element> | undefined;
|
|
121
121
|
onInputCapture?: React.FormEventHandler<Element> | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import { type CSSProperties } from 'styled-components';
|
|
3
2
|
import type { DSHookFloatingContextT } from './react-desc-prop-types.js';
|
|
4
3
|
import type { PopoverArrowT } from './parts/PopoverArrow.js';
|
|
5
4
|
type UseComputedPositionStylesT = {
|
|
5
|
+
/** Prevent computing when closed (optimization + avoids unnecessary frames) */
|
|
6
6
|
preventComputing?: boolean;
|
|
7
7
|
reference: Element | null;
|
|
8
8
|
floating: HTMLElement | null;
|
|
@@ -10,33 +10,16 @@ type UseComputedPositionStylesT = {
|
|
|
10
10
|
placementOrderPreference?: DSHookFloatingContextT.PopperPlacementsT[];
|
|
11
11
|
customOffset: [number, number];
|
|
12
12
|
withoutPortal: boolean;
|
|
13
|
+
/** Debounce ms for scroll/resize/observer events */
|
|
14
|
+
debounceMs?: number;
|
|
13
15
|
};
|
|
14
|
-
/**
|
|
15
|
-
* this custom hook has a single purpose, to compute the position of the floating element relative to the reference element
|
|
16
|
-
*
|
|
17
|
-
* we ideally don't want to calculate positions if the open flag is false as the styles should not be visible so not relevant.
|
|
18
|
-
* @param {UseComputedPositionStylesT} config - The configuration object.
|
|
19
|
-
* @param {Boolean} config.preventComputing - If true, the position will not be computed, usually used when the open flag is false.
|
|
20
|
-
* @param {Element} config.reference - The reference element as a DOM element.
|
|
21
|
-
* @param {HTMLElement} config.floating - The floating element as a DOM element (required to calculate the best fitting position).
|
|
22
|
-
* @param {DSHookFloatingContextT.PopperPlacementsT} config.placement - The placement of the floating element relative to the reference element to be applied if possible.
|
|
23
|
-
* @param {DSHookFloatingContextT.PopperPlacementsT[]} config.placementOrderPreference - The order of preference for the placement of the floating element relative to the reference element, the first one that fits will be used.
|
|
24
|
-
* @param {[number, number]} config.customOffset - The offset of the floating element relative to the reference element if any is desired.
|
|
25
|
-
* @param {Boolean} config.withoutPortal - If true, the floating element will be positioned relative to the reference element, otherwise it will be positioned relative to the viewport.
|
|
26
|
-
*
|
|
27
|
-
* @returns results
|
|
28
|
-
* @returns results.arrowStyles - the styles to be applied to the arrow element if any is desired
|
|
29
|
-
* @returns results.floatingStyles - the styles to be applied to the floating element
|
|
30
|
-
* @returns results.updateStyles - a function to be called to update the styles of the floating element on demand if needed
|
|
31
|
-
* @returns results.debouncedUpdateStyles - a debounced version of the updateStyles function to be used when lot of invocations are expected (e.g. on scroll)
|
|
32
|
-
* @returns results.mutableUpdateStyles - a ref to the updateStyles function to be used when the function needs to be called in a useEffect or similar
|
|
33
|
-
*/
|
|
34
16
|
export declare const useComputedPositionStyles: (config: UseComputedPositionStylesT) => {
|
|
35
17
|
arrowStyles: PopoverArrowT;
|
|
36
18
|
floatingStyles: CSSProperties;
|
|
19
|
+
hasComputedOnce: boolean;
|
|
37
20
|
updateStyles: () => void;
|
|
38
21
|
debouncedUpdateStyles: import("lodash").DebouncedFunc<() => void>;
|
|
39
|
-
mutableUpdateStyles:
|
|
40
|
-
|
|
22
|
+
mutableUpdateStyles: import("react").MutableRefObject<() => void>;
|
|
23
|
+
resetVisibilityOnly: () => void;
|
|
41
24
|
};
|
|
42
25
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-floating-context",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.55.0-next.10",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Popper Hook",
|
|
6
6
|
"files": [
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"indent": 4
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@elliemae/ds-
|
|
40
|
-
"@elliemae/ds-
|
|
41
|
-
"@elliemae/ds-
|
|
42
|
-
"@elliemae/ds-
|
|
39
|
+
"@elliemae/ds-hooks-headless-tooltip": "3.55.0-next.10",
|
|
40
|
+
"@elliemae/ds-system": "3.55.0-next.10",
|
|
41
|
+
"@elliemae/ds-typescript-helpers": "3.55.0-next.10",
|
|
42
|
+
"@elliemae/ds-props-helpers": "3.55.0-next.10"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@elliemae/pui-cli": "9.0.0-next.65",
|
|
46
46
|
"jest": "~29.7.0",
|
|
47
|
-
"@elliemae/ds-monorepo-devops": "3.
|
|
47
|
+
"@elliemae/ds-monorepo-devops": "3.55.0-next.10"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"lodash-es": "^4.17.21",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"dev": "cross-env NODE_ENV=development node ../../../scripts/build/build.mjs --watch",
|
|
62
|
-
"test": "pui-cli test --passWithNoTests --coverage=\"false\"",
|
|
62
|
+
"test": "[ -n \"$CI\" ] || playwright test -c ./playwright.config.mjs && pui-cli test --passWithNoTests --coverage=\"false\"",
|
|
63
63
|
"lint": "node ../../../scripts/lint.mjs --fix",
|
|
64
64
|
"lint:strict": "node ../../../scripts/lint-strict.mjs",
|
|
65
65
|
"dts": "node ../../../scripts/dts.mjs",
|
|
File without changes
|
|
File without changes
|