@khanacademy/wonder-blocks-floating 0.0.0-PR2828-20251023210924 → 0.0.0-PR2828-20251024012051
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/CHANGELOG.md +1 -7
- package/dist/es/index.js +2 -38
- package/dist/index.js +17 -52
- package/package.json +3 -3
- package/tsconfig-build.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-floating
|
|
2
2
|
|
|
3
|
-
## 0.0.0-PR2828-
|
|
3
|
+
## 0.0.0-PR2828-20251024012051
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- 440bcca: Add Floating package (experiment)
|
|
8
8
|
- 7557bf9: Switch to @floating-ui/react-dom
|
|
9
|
-
|
|
10
|
-
### Patch Changes
|
|
11
|
-
|
|
12
|
-
- Updated dependencies [7557bf9]
|
|
13
|
-
- Updated dependencies [8059bb7]
|
|
14
|
-
- @khanacademy/wonder-blocks-modal@0.0.0-PR2828-20251023210924
|
package/dist/es/index.js
CHANGED
|
@@ -1,50 +1,14 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import * as ReactDOM from 'react-dom';
|
|
3
4
|
import { useFloating, autoUpdate, hide, offset, flip, shift, arrow } from '@floating-ui/react-dom';
|
|
4
5
|
import { StyleSheet, css } from 'aphrodite';
|
|
5
6
|
import { semanticColor, border, boxShadow } from '@khanacademy/wonder-blocks-tokens';
|
|
6
7
|
|
|
7
|
-
function checkDCE() {
|
|
8
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
9
|
-
if (
|
|
10
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' ||
|
|
11
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function'
|
|
12
|
-
) {
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
16
|
-
// This branch is unreachable because this function is only called
|
|
17
|
-
// in production, but the condition is true only in development.
|
|
18
|
-
// Therefore if the branch is still here, dead code elimination wasn't
|
|
19
|
-
// properly applied.
|
|
20
|
-
// Don't change the message. React DevTools relies on it. Also make sure
|
|
21
|
-
// this message doesn't occur elsewhere in this function, or it will cause
|
|
22
|
-
// a false positive.
|
|
23
|
-
throw new Error('^_^');
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
// Verify that the code above has been dead code eliminated (DCE'd).
|
|
27
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE);
|
|
28
|
-
} catch (err) {
|
|
29
|
-
// DevTools shouldn't crash React, no matter what.
|
|
30
|
-
// We should still report in case we break this code.
|
|
31
|
-
console.error(err);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (process.env.NODE_ENV === 'production') {
|
|
36
|
-
// DCE check should happen before ReactDOM bundle executes so that
|
|
37
|
-
// DevTools can report bad minification during injection.
|
|
38
|
-
checkDCE();
|
|
39
|
-
module.exports = require('./cjs/react-dom.production.min.js');
|
|
40
|
-
} else {
|
|
41
|
-
module.exports = require('./cjs/react-dom.development.js');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
8
|
const ModalLauncherPortalAttributeName="data-modal-launcher-portal";
|
|
45
9
|
|
|
46
10
|
function maybeGetNextAncestorModalLauncherPortal(element){let candidateElement=element&&element.parentElement;while(candidateElement&&!candidateElement.hasAttribute(ModalLauncherPortalAttributeName)){candidateElement=candidateElement.parentElement;}return candidateElement}function maybeGetPortalMountedModalHostElement(element){return maybeGetNextAncestorModalLauncherPortal(element)}
|
|
47
11
|
|
|
48
|
-
function Floating({arrow:arrowElement,content,children,portal=true,placement="top",defaultOpen=false,showArrow=true,useFocusManager=true}){const[isOpen,setIsOpen]=React.useState(defaultOpen);const arrowRef=React.useRef(null);React.useEffect(()=>{setIsOpen(defaultOpen);},[defaultOpen]);const{refs,elements,floatingStyles,middlewareData}=useFloating({placement,whileElementsMounted:autoUpdate,middleware:[hide(),offset(20),flip(),shift({padding:12}),...showArrow?[arrow({element:arrowRef})]:[]]});const trigger=React.useMemo(()=>React.cloneElement(children,{ref:refs.setReference,...children.props}),[children,refs.setReference]);const floatingContainer=jsxs("div",{ref:refs.setFloating,style:{...floatingStyles,visibility:middlewareData.hide?.referenceHidden?"hidden":"visible"},className:css(styles.floating),children:[content,showArrow&&jsx("div",{ref:arrowRef,style:{position:"absolute",left:middlewareData.arrow?.x,top:middlewareData.arrow?.y},children:arrowElement})]});let renderedContent=null;if(portal){const root=maybeGetPortalMountedModalHostElement(elements.reference)||document.body;renderedContent=
|
|
12
|
+
function Floating({arrow:arrowElement,content,children,portal=true,placement="top",defaultOpen=false,showArrow=true,useFocusManager=true}){const[isOpen,setIsOpen]=React.useState(defaultOpen);const arrowRef=React.useRef(null);React.useEffect(()=>{setIsOpen(defaultOpen);},[defaultOpen]);const{refs,elements,floatingStyles,middlewareData}=useFloating({placement,whileElementsMounted:autoUpdate,middleware:[hide(),offset(20),flip(),shift({padding:12}),...showArrow?[arrow({element:arrowRef})]:[]]});const trigger=React.useMemo(()=>React.cloneElement(children,{ref:refs.setReference,...children.props}),[children,refs.setReference]);const floatingContainer=jsxs("div",{ref:refs.setFloating,style:{...floatingStyles,visibility:middlewareData.hide?.referenceHidden?"hidden":"visible"},className:css(styles.floating),children:[content,showArrow&&jsx("div",{ref:arrowRef,style:{position:"absolute",left:middlewareData.arrow?.x,top:middlewareData.arrow?.y},children:arrowElement})]});let renderedContent=null;if(portal){const root=maybeGetPortalMountedModalHostElement(elements.reference)||document.body;renderedContent=ReactDOM.createPortal(floatingContainer,root);}else {renderedContent=floatingContainer;}return jsxs(Fragment,{children:[trigger,isOpen&&renderedContent]})}const styles=StyleSheet.create({floating:{background:semanticColor.core.background.base.default,border:`solid ${border.width.thin} ${semanticColor.core.border.neutral.subtle}`,borderRadius:border.radius.radius_040,maxWidth:288,boxShadow:boxShadow.mid,justifyContent:"center"}});
|
|
49
13
|
|
|
50
14
|
export { Floating, maybeGetPortalMountedModalHostElement };
|
package/dist/index.js
CHANGED
|
@@ -4,72 +4,37 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
|
+
var ReactDOM = require('react-dom');
|
|
7
8
|
var reactDom = require('@floating-ui/react-dom');
|
|
8
9
|
var aphrodite = require('aphrodite');
|
|
9
10
|
var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
|
|
10
11
|
|
|
11
12
|
function _interopNamespace(e) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
if (e && e.__esModule) return e;
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
21
24
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
n["default"] = e;
|
|
26
|
-
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
n["default"] = e;
|
|
27
|
+
return Object.freeze(n);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
|
-
|
|
31
|
-
function checkDCE() {
|
|
32
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
33
|
-
if (
|
|
34
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' ||
|
|
35
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function'
|
|
36
|
-
) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
40
|
-
// This branch is unreachable because this function is only called
|
|
41
|
-
// in production, but the condition is true only in development.
|
|
42
|
-
// Therefore if the branch is still here, dead code elimination wasn't
|
|
43
|
-
// properly applied.
|
|
44
|
-
// Don't change the message. React DevTools relies on it. Also make sure
|
|
45
|
-
// this message doesn't occur elsewhere in this function, or it will cause
|
|
46
|
-
// a false positive.
|
|
47
|
-
throw new Error('^_^');
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
// Verify that the code above has been dead code eliminated (DCE'd).
|
|
51
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
// DevTools shouldn't crash React, no matter what.
|
|
54
|
-
// We should still report in case we break this code.
|
|
55
|
-
console.error(err);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (process.env.NODE_ENV === 'production') {
|
|
60
|
-
// DCE check should happen before ReactDOM bundle executes so that
|
|
61
|
-
// DevTools can report bad minification during injection.
|
|
62
|
-
checkDCE();
|
|
63
|
-
module.exports = require('./cjs/react-dom.production.min.js');
|
|
64
|
-
} else {
|
|
65
|
-
module.exports = require('./cjs/react-dom.development.js');
|
|
66
|
-
}
|
|
31
|
+
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
|
67
32
|
|
|
68
33
|
const ModalLauncherPortalAttributeName="data-modal-launcher-portal";
|
|
69
34
|
|
|
70
35
|
function maybeGetNextAncestorModalLauncherPortal(element){let candidateElement=element&&element.parentElement;while(candidateElement&&!candidateElement.hasAttribute(ModalLauncherPortalAttributeName)){candidateElement=candidateElement.parentElement;}return candidateElement}function maybeGetPortalMountedModalHostElement(element){return maybeGetNextAncestorModalLauncherPortal(element)}
|
|
71
36
|
|
|
72
|
-
function Floating({arrow:arrowElement,content,children,portal=true,placement="top",defaultOpen=false,showArrow=true,useFocusManager=true}){const[isOpen,setIsOpen]=React__namespace.useState(defaultOpen);const arrowRef=React__namespace.useRef(null);React__namespace.useEffect(()=>{setIsOpen(defaultOpen);},[defaultOpen]);const{refs,elements,floatingStyles,middlewareData}=reactDom.useFloating({placement,whileElementsMounted:reactDom.autoUpdate,middleware:[reactDom.hide(),reactDom.offset(20),reactDom.flip(),reactDom.shift({padding:12}),...showArrow?[reactDom.arrow({element:arrowRef})]:[]]});const trigger=React__namespace.useMemo(()=>React__namespace.cloneElement(children,{ref:refs.setReference,...children.props}),[children,refs.setReference]);const floatingContainer=jsxRuntime.jsxs("div",{ref:refs.setFloating,style:{...floatingStyles,visibility:middlewareData.hide?.referenceHidden?"hidden":"visible"},className:aphrodite.css(styles.floating),children:[content,showArrow&&jsxRuntime.jsx("div",{ref:arrowRef,style:{position:"absolute",left:middlewareData.arrow?.x,top:middlewareData.arrow?.y},children:arrowElement})]});let renderedContent=null;if(portal){const root=maybeGetPortalMountedModalHostElement(elements.reference)||document.body;renderedContent=
|
|
37
|
+
function Floating({arrow:arrowElement,content,children,portal=true,placement="top",defaultOpen=false,showArrow=true,useFocusManager=true}){const[isOpen,setIsOpen]=React__namespace.useState(defaultOpen);const arrowRef=React__namespace.useRef(null);React__namespace.useEffect(()=>{setIsOpen(defaultOpen);},[defaultOpen]);const{refs,elements,floatingStyles,middlewareData}=reactDom.useFloating({placement,whileElementsMounted:reactDom.autoUpdate,middleware:[reactDom.hide(),reactDom.offset(20),reactDom.flip(),reactDom.shift({padding:12}),...showArrow?[reactDom.arrow({element:arrowRef})]:[]]});const trigger=React__namespace.useMemo(()=>React__namespace.cloneElement(children,{ref:refs.setReference,...children.props}),[children,refs.setReference]);const floatingContainer=jsxRuntime.jsxs("div",{ref:refs.setFloating,style:{...floatingStyles,visibility:middlewareData.hide?.referenceHidden?"hidden":"visible"},className:aphrodite.css(styles.floating),children:[content,showArrow&&jsxRuntime.jsx("div",{ref:arrowRef,style:{position:"absolute",left:middlewareData.arrow?.x,top:middlewareData.arrow?.y},children:arrowElement})]});let renderedContent=null;if(portal){const root=maybeGetPortalMountedModalHostElement(elements.reference)||document.body;renderedContent=ReactDOM__namespace.createPortal(floatingContainer,root);}else {renderedContent=floatingContainer;}return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[trigger,isOpen&&renderedContent]})}const styles=aphrodite.StyleSheet.create({floating:{background:wonderBlocksTokens.semanticColor.core.background.base.default,border:`solid ${wonderBlocksTokens.border.width.thin} ${wonderBlocksTokens.semanticColor.core.border.neutral.subtle}`,borderRadius:wonderBlocksTokens.border.radius.radius_040,maxWidth:288,boxShadow:wonderBlocksTokens.boxShadow.mid,justifyContent:"center"}});
|
|
73
38
|
|
|
74
39
|
exports.Floating = Floating;
|
|
75
40
|
exports.maybeGetPortalMountedModalHostElement = maybeGetPortalMountedModalHostElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-floating",
|
|
3
|
-
"version": "0.0.0-PR2828-
|
|
3
|
+
"version": "0.0.0-PR2828-20251024012051",
|
|
4
4
|
"description": "Floating component for Wonder Blocks using Floating UI.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/es/index.js",
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@floating-ui/react-dom": "2.1.6",
|
|
16
|
-
"@khanacademy/wonder-blocks-modal": "0.0.0-PR2828-20251023210924",
|
|
17
16
|
"@khanacademy/wonder-blocks-tokens": "14.0.0"
|
|
18
17
|
},
|
|
19
18
|
"peerDependencies": {
|
|
20
19
|
"aphrodite": "^1.2.5",
|
|
21
|
-
"react": "18.2.0"
|
|
20
|
+
"react": "18.2.0",
|
|
21
|
+
"react-dom": "18.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@khanacademy/wb-dev-build-settings": "3.2.0"
|