Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "Portal", {
enumerable: true,
get: function() {
return Portal;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _usePortal = require("./usePortal");
const _renderPortal = require("./renderPortal");
const Portal = (props)=>{
const state = (0, _usePortal.usePortal_unstable)(props);
return (0, _renderPortal.renderPortal_unstable)(state);
};
Portal.displayName = 'Portal';
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Portal/Portal.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { usePortal_unstable } from './usePortal';\nimport { renderPortal_unstable } from './renderPortal';\nimport type { PortalProps } from './Portal.types';\n\n/**\n * A portal provides a way to render children into a DOM node\n * that exists outside the DOM hierarchy of the parent component.\n */\nexport const Portal: React.FC<PortalProps> = props => {\n const state = usePortal_unstable(props);\n\n return renderPortal_unstable(state);\n};\n\nPortal.displayName = 'Portal';\n"],"names":["Portal","props","state","usePortal_unstable","renderPortal_unstable","displayName"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":";;;;+BAUaA;;;eAAAA;;;;iEAVU;2BAEY;8BACG;AAO/B,MAAMA,SAAgCC,CAAAA;IAC3C,MAAMC,QAAQC,IAAAA,6BAAAA,EAAmBF;IAEjC,OAAOG,IAAAA,mCAAAA,EAAsBF;AAC/B;AAEAF,OAAOK,WAAW,GAAG"}
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Portal/Portal.types.ts"],"sourcesContent":["import * as React from 'react';\n\nexport type PortalProps = {\n /**\n * React children\n */\n children?: React.ReactNode;\n\n /**\n * Where the portal children are mounted on DOM\n *\n * @default a new element on document.body without any styling\n */\n mountNode?: HTMLElement | null | { element?: HTMLElement | null; className?: string };\n};\n\nexport type PortalState = Pick<PortalProps, 'children'> & {\n mountNode: HTMLElement | null | undefined;\n\n /**\n * Ref to the root span element as virtual parent\n */\n virtualParentRootRef: React.MutableRefObject<HTMLSpanElement | null>;\n};\n"],"names":[],"rangeMappings":";;;;;","mappings":";;;;;iEAAuB"}
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
Portal: function() {
return _Portal.Portal;
},
renderPortal_unstable: function() {
return _renderPortal.renderPortal_unstable;
},
usePortal_unstable: function() {
return _usePortal.usePortal_unstable;
}
});
const _Portal = require("./Portal");
const _renderPortal = require("./renderPortal");
const _usePortal = require("./usePortal");
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Portal/index.ts"],"sourcesContent":["export { Portal } from './Portal';\nexport type { PortalProps, PortalState } from './Portal.types';\nexport { renderPortal_unstable } from './renderPortal';\nexport { usePortal_unstable } from './usePortal';\n"],"names":["Portal","renderPortal_unstable","usePortal_unstable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;;;;IAASA,MAAM;eAANA,cAAM;;IAENC,qBAAqB;eAArBA,mCAAqB;;IACrBC,kBAAkB;eAAlBA,6BAAkB;;;wBAHJ;8BAEe;2BACH"}
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "renderPortal_unstable", {
enumerable: true,
get: function() {
return renderPortal_unstable;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _reactdom = /*#__PURE__*/ _interop_require_wildcard._(require("react-dom"));
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const renderPortal_unstable = (state)=>{
return /*#__PURE__*/ _react.createElement("span", {
hidden: true,
ref: state.virtualParentRootRef
}, state.mountNode && /*#__PURE__*/ _reactdom.createPortal(state.children, state.mountNode));
};
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Portal/renderPortal.tsx"],"sourcesContent":["import * as ReactDOM from 'react-dom';\nimport * as React from 'react';\nimport type { PortalState } from './Portal.types';\n\n/**\n * Render the final JSX of Portal\n */\nexport const renderPortal_unstable = (state: PortalState): React.ReactElement => {\n return (\n <span hidden ref={state.virtualParentRootRef}>\n {state.mountNode && ReactDOM.createPortal(state.children, state.mountNode)}\n </span>\n );\n};\n"],"names":["renderPortal_unstable","state","React","createElement","span","hidden","ref","virtualParentRootRef","mountNode","ReactDOM","createPortal","children"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":";;;;+BAOaA;;;eAAAA;;;;oEAPa;iEACH;AAMhB,MAAMA,wBAAwB,CAACC;IACpC,OAAA,WAAA,GACEC,OAAAC,aAAA,CAACC,QAAAA;QAAKC,QAAAA;QAAOC,KAAKL,MAAMM,oBAAoB;OACzCN,MAAMO,SAAS,IAAA,WAAA,GAAIC,UAASC,YAAY,CAACT,MAAMU,QAAQ,EAAEV,MAAMO,SAAS;AAG/E"}
@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "usePortal_unstable", {
enumerable: true,
get: function() {
return usePortal_unstable;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _reactutilities = require("@fluentui/react-utilities");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _toMountNodeProps = require("../../utils/toMountNodeProps");
const _usePortalMountNode = require("./usePortalMountNode");
const usePortal_unstable = (props)=>{
const { element, className } = (0, _toMountNodeProps.toMountNodeProps)(props.mountNode);
const virtualParentRootRef = _react.useRef(null);
const fallbackElement = (0, _usePortalMountNode.usePortalMountNode)({
disabled: !!element,
className
});
const mountNode = element !== null && element !== void 0 ? element : fallbackElement;
const state = {
children: props.children,
mountNode,
virtualParentRootRef
};
_react.useEffect(()=>{
if (!mountNode) {
return;
}
const virtualParent = virtualParentRootRef.current;
// By default, we create a mount node for portal on `document.body` (see usePortalMountNode()) and have following structure:
//
// <body>
// <!-- ⚛️ application root -->
// <div id="root">
// <!-- ⬇️ portal node rendered in a tree to anchor (virtual parent node) -->
// <span aria-hidden="true"></span>
// </div>
// <div id="portal-mount-node">
// <!-- 🧩portal content -->
// </div>
// </body>
//
// To make sure that `.elementContains()` works correctly, we link a virtual parent to a portal node (a virtual parent node becomes a parent of mount node):
// virtual.contains(mountNode) === false
// (while we need ⬇️⬇️⬇️)
// elementsContains(virtualParent, mountNode) === true
// elementsContains(mountNode, virtualParent) === false
//
// For more details, check docs for virtual parent utils.
//
// However, if a user provides a custom mount node (via `props`) the structure could be different:
//
// <body>
// <!-- application root -->
// <div id="root">
// <div id="portal-mount-node">
// <!-- 🧩portal content -->
//
// <span aria-hidden="true"></span>
// </div>
// </div>
// </body>
//
// A mount node in this case contains portal's content and a virtual parent node. In this case nodes linking is redundant and the check below avoids it.
//
// Otherwise, there is a circular reference - both elements are parents of each other:
// elementsContains(mountNode, virtualParent) === true
// elementsContains(virtualParent, mountNode) === true
const isVirtualParentInsideChild = mountNode.contains(virtualParent);
if (virtualParent && !isVirtualParentInsideChild) {
(0, _reactutilities.setVirtualParent)(mountNode, virtualParent);
return ()=>{
(0, _reactutilities.setVirtualParent)(mountNode, undefined);
};
}
}, [
virtualParentRootRef,
mountNode
]);
return state;
};
@@ -0,0 +1 @@
{"version":3,"sources":["../src/components/Portal/usePortal.ts"],"sourcesContent":["import { setVirtualParent } from '@fluentui/react-utilities';\nimport * as React from 'react';\n\nimport { toMountNodeProps } from '../../utils/toMountNodeProps';\nimport { usePortalMountNode } from './usePortalMountNode';\nimport type { PortalProps, PortalState } from './Portal.types';\n\n/**\n * Create the state required to render Portal.\n *\n * The returned state can be modified with hooks such as usePortalStyles, before being passed to renderPortal_unstable.\n *\n * @param props - props from this instance of Portal\n */\nexport const usePortal_unstable = (props: PortalProps): PortalState => {\n const { element, className } = toMountNodeProps(props.mountNode);\n\n const virtualParentRootRef = React.useRef<HTMLSpanElement>(null);\n const fallbackElement = usePortalMountNode({ disabled: !!element, className });\n\n const mountNode = element ?? fallbackElement;\n const state: PortalState = {\n children: props.children,\n mountNode,\n virtualParentRootRef,\n };\n\n React.useEffect(() => {\n if (!mountNode) {\n return;\n }\n\n const virtualParent = virtualParentRootRef.current;\n\n // By default, we create a mount node for portal on `document.body` (see usePortalMountNode()) and have following structure:\n //\n // <body>\n // <!-- ⚛️ application root -->\n // <div id=\"root\">\n // <!-- ⬇️ portal node rendered in a tree to anchor (virtual parent node) -->\n // <span aria-hidden=\"true\"></span>\n // </div>\n // <div id=\"portal-mount-node\">\n // <!-- 🧩portal content -->\n // </div>\n // </body>\n //\n // To make sure that `.elementContains()` works correctly, we link a virtual parent to a portal node (a virtual parent node becomes a parent of mount node):\n // virtual.contains(mountNode) === false\n // (while we need ⬇️⬇️⬇️)\n // elementsContains(virtualParent, mountNode) === true\n // elementsContains(mountNode, virtualParent) === false\n //\n // For more details, check docs for virtual parent utils.\n //\n // However, if a user provides a custom mount node (via `props`) the structure could be different:\n //\n // <body>\n // <!-- application root -->\n // <div id=\"root\">\n // <div id=\"portal-mount-node\">\n // <!-- 🧩portal content -->\n //\n // <span aria-hidden=\"true\"></span>\n // </div>\n // </div>\n // </body>\n //\n // A mount node in this case contains portal's content and a virtual parent node. In this case nodes linking is redundant and the check below avoids it.\n //\n // Otherwise, there is a circular reference - both elements are parents of each other:\n // elementsContains(mountNode, virtualParent) === true\n // elementsContains(virtualParent, mountNode) === true\n const isVirtualParentInsideChild = mountNode.contains(virtualParent);\n\n if (virtualParent && !isVirtualParentInsideChild) {\n setVirtualParent(mountNode, virtualParent);\n\n return () => {\n setVirtualParent(mountNode, undefined);\n };\n }\n }, [virtualParentRootRef, mountNode]);\n\n return state;\n};\n"],"names":["usePortal_unstable","props","element","className","toMountNodeProps","mountNode","virtualParentRootRef","React","useRef","fallbackElement","usePortalMountNode","disabled","state","children","useEffect","virtualParent","current","isVirtualParentInsideChild","contains","setVirtualParent","undefined"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAcaA;;;eAAAA;;;;gCAdoB;iEACV;kCAEU;oCACE;AAU5B,MAAMA,qBAAqB,CAACC;IACjC,MAAM,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGC,IAAAA,kCAAAA,EAAiBH,MAAMI,SAAS;IAE/D,MAAMC,uBAAuBC,OAAMC,MAAM,CAAkB;IAC3D,MAAMC,kBAAkBC,IAAAA,sCAAAA,EAAmB;QAAEC,UAAU,CAAC,CAACT;QAASC;IAAU;IAE5E,MAAME,YAAYH,YAAAA,QAAAA,YAAAA,KAAAA,IAAAA,UAAWO;IAC7B,MAAMG,QAAqB;QACzBC,UAAUZ,MAAMY,QAAQ;QACxBR;QACAC;IACF;IAEAC,OAAMO,SAAS,CAAC;QACd,IAAI,CAACT,WAAW;YACd;QACF;QAEA,MAAMU,gBAAgBT,qBAAqBU,OAAO;QAElD,4HAA4H;QAC5H,EAAE;QACF,SAAS;QACT,iCAAiC;QACjC,oBAAoB;QACpB,iFAAiF;QACjF,uCAAuC;QACvC,WAAW;QACX,iCAAiC;QACjC,gCAAgC;QAChC,WAAW;QACX,UAAU;QACV,EAAE;QACF,4JAA4J;QAC5J,0CAA0C;QAC1C,2BAA2B;QAC3B,wDAAwD;QACxD,yDAAyD;QACzD,EAAE;QACF,yDAAyD;QACzD,EAAE;QACF,kGAAkG;QAClG,EAAE;QACF,SAAS;QACT,8BAA8B;QAC9B,oBAAoB;QACpB,mCAAmC;QACnC,kCAAkC;QAClC,EAAE;QACF,yCAAyC;QACzC,aAAa;QACb,WAAW;QACX,UAAU;QACV,EAAE;QACF,wJAAwJ;QACxJ,EAAE;QACF,sFAAsF;QACtF,wDAAwD;QACxD,wDAAwD;QACxD,MAAMC,6BAA6BZ,UAAUa,QAAQ,CAACH;QAEtD,IAAIA,iBAAiB,CAACE,4BAA4B;YAChDE,IAAAA,gCAAAA,EAAiBd,WAAWU;YAE5B,OAAO;gBACLI,IAAAA,gCAAAA,EAAiBd,WAAWe;YAC9B;QACF;IACF,GAAG;QAACd;QAAsBD;KAAU;IAEpC,OAAOO;AACT"}
@@ -0,0 +1,88 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "usePortalMountNode", {
enumerable: true,
get: function() {
return usePortalMountNode;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _reactsharedcontexts = require("@fluentui/react-shared-contexts");
const _react1 = require("@griffel/react");
const _reacttabster = require("@fluentui/react-tabster");
const _usedisposable = require("use-disposable");
const _usePortalMountNodeStylesstyles = require("./usePortalMountNodeStyles.styles");
const useInsertionEffect = _react['useInsertion' + 'Effect'];
const usePortalMountNode = (options)=>{
'use no memo';
const { targetDocument, dir } = (0, _reactsharedcontexts.useFluent_unstable)();
const mountNode = (0, _reactsharedcontexts.usePortalMountNode)();
const focusVisibleRef = (0, _reacttabster.useFocusVisible)();
const classes = (0, _usePortalMountNodeStylesstyles.usePortalMountNodeStylesStyles)();
const themeClassName = (0, _reactsharedcontexts.useThemeClassName_unstable)();
const className = (0, _react1.mergeClasses)(themeClassName, classes.root, options.className);
const targetNode = mountNode !== null && mountNode !== void 0 ? mountNode : targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.body;
const element = (0, _usedisposable.useDisposable)(()=>{
if (targetNode === undefined || options.disabled) {
return [
null,
()=>null
];
}
const newElement = targetNode.ownerDocument.createElement('div');
targetNode.appendChild(newElement);
return [
newElement,
()=>newElement.remove()
];
}, [
targetNode
]);
if (useInsertionEffect) {
// eslint-disable-next-line react-hooks/rules-of-hooks
useInsertionEffect(()=>{
if (!element) {
return;
}
const classesToApply = className.split(' ').filter(Boolean);
element.classList.add(...classesToApply);
element.setAttribute('dir', dir);
element.setAttribute('data-portal-node', 'true');
focusVisibleRef.current = element;
return ()=>{
element.classList.remove(...classesToApply);
element.removeAttribute('dir');
};
}, [
className,
dir,
element,
focusVisibleRef
]);
} else {
// This useMemo call is intentional for React 17
// We don't want to re-create the portal element when its attributes change.
// This also should not be done in an effect because, changing the value of css variables
// after initial mount can trigger interesting CSS side effects like transitions.
// eslint-disable-next-line react-hooks/rules-of-hooks
_react.useMemo(()=>{
if (!element) {
return;
}
// Force replace all classes
element.className = className;
element.setAttribute('dir', dir);
element.setAttribute('data-portal-node', 'true');
focusVisibleRef.current = element;
}, [
className,
dir,
element,
focusVisibleRef
]);
}
return element;
};
File diff suppressed because one or more lines are too long
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "usePortalMountNodeStylesStyles", {
enumerable: true,
get: function() {
return usePortalMountNodeStylesStyles;
}
});
const _react = require("@griffel/react");
const usePortalMountNodeStylesStyles = /*#__PURE__*/ (0, _react.__styles)({
root: {
qhf8xq: "f1euv43f",
Bhzewxz: "f15twtuk",
oyh7mz: [
"f1vgc2s3",
"f1e31b4d"
],
j35jbq: [
"f1e31b4d",
"f1vgc2s3"
],
Bj3rh1h: "f494woh"
}
}, {
d: [
".f1euv43f{position:absolute;}",
".f15twtuk{top:0;}",
".f1vgc2s3{left:0;}",
".f1e31b4d{right:0;}",
".f494woh{z-index:1000000;}"
]
});
@@ -0,0 +1 @@
{"version":3,"sources":["usePortalMountNodeStyles.styles.js"],"sourcesContent":["import { makeStyles } from '@griffel/react';\nexport const usePortalMountNodeStylesStyles = makeStyles({\n root: {\n // Creates new stacking context to prevent z-index issues\n // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_positioned_layout/Understanding_z-index/Stacking_context\n //\n // Also keeps a portal on top of a page to prevent scrollbars from appearing\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n zIndex: 1000000\n }\n});\n"],"names":["usePortalMountNodeStylesStyles","__styles","root","qhf8xq","Bhzewxz","oyh7mz","j35jbq","Bj3rh1h","d"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BACaA;;;eAAAA;;;uBADc;AACpB,MAAMA,iCAA8B,WAAA,GAAGC,IAAAA,eAAA,EAAA;IAAAC,MAAA;QAAAC,QAAA;QAAAC,SAAA;QAAAC,QAAA;YAAA;YAAA;SAAA;QAAAC,QAAA;YAAA;YAAA;SAAA;QAAAC,SAAA;IAAA;AAAA,GAAA;IAAAC,GAAA;QAAA;QAAA;QAAA;QAAA;QAAA;KAAA;AAAA"}