| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.AllZIndexPortals = AllZIndexPortals;
|
|---|
| 7 | var _react = _interopRequireWildcard(require("react"));
|
|---|
| 8 | var React = _react;
|
|---|
| 9 | var _hooks = require("../state/hooks");
|
|---|
| 10 | var _zIndexSlice = require("../state/zIndexSlice");
|
|---|
| 11 | var _zIndexSelectors = require("./zIndexSelectors");
|
|---|
| 12 | function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|---|
| 13 | function ZIndexSvgPortal(_ref) {
|
|---|
| 14 | var {
|
|---|
| 15 | zIndex,
|
|---|
| 16 | isPanorama
|
|---|
| 17 | } = _ref;
|
|---|
| 18 | var ref = (0, _react.useRef)(null);
|
|---|
| 19 | var dispatch = (0, _hooks.useAppDispatch)();
|
|---|
| 20 | (0, _react.useLayoutEffect)(() => {
|
|---|
| 21 | if (ref.current) {
|
|---|
| 22 | dispatch((0, _zIndexSlice.registerZIndexPortalElement)({
|
|---|
| 23 | zIndex,
|
|---|
| 24 | element: ref.current,
|
|---|
| 25 | isPanorama
|
|---|
| 26 | }));
|
|---|
| 27 | }
|
|---|
| 28 | return () => {
|
|---|
| 29 | dispatch((0, _zIndexSlice.unregisterZIndexPortalElement)({
|
|---|
| 30 | zIndex,
|
|---|
| 31 | isPanorama
|
|---|
| 32 | }));
|
|---|
| 33 | };
|
|---|
| 34 | }, [dispatch, zIndex, isPanorama]);
|
|---|
| 35 | // these g elements should not be tabbable
|
|---|
| 36 | return /*#__PURE__*/React.createElement("g", {
|
|---|
| 37 | tabIndex: -1,
|
|---|
| 38 | ref: ref
|
|---|
| 39 | });
|
|---|
| 40 | }
|
|---|
| 41 | function AllZIndexPortals(_ref2) {
|
|---|
| 42 | var {
|
|---|
| 43 | children,
|
|---|
| 44 | isPanorama
|
|---|
| 45 | } = _ref2;
|
|---|
| 46 | var allRegisteredZIndexes = (0, _hooks.useAppSelector)(_zIndexSelectors.selectAllRegisteredZIndexes);
|
|---|
| 47 | if (!allRegisteredZIndexes || allRegisteredZIndexes.length === 0) {
|
|---|
| 48 | return children;
|
|---|
| 49 | }
|
|---|
| 50 | var allNegativeZIndexes = allRegisteredZIndexes.filter(zIndex => zIndex < 0);
|
|---|
| 51 | // We exclude zero on purpose - that is the default layer, and it doesn't need a portal.
|
|---|
| 52 | var allPositiveZIndexes = allRegisteredZIndexes.filter(zIndex => zIndex > 0);
|
|---|
| 53 | return /*#__PURE__*/React.createElement(React.Fragment, null, allNegativeZIndexes.map(zIndex => /*#__PURE__*/React.createElement(ZIndexSvgPortal, {
|
|---|
| 54 | key: zIndex,
|
|---|
| 55 | zIndex: zIndex,
|
|---|
| 56 | isPanorama: isPanorama
|
|---|
| 57 | })), children, allPositiveZIndexes.map(zIndex => /*#__PURE__*/React.createElement(ZIndexSvgPortal, {
|
|---|
| 58 | key: zIndex,
|
|---|
| 59 | zIndex: zIndex,
|
|---|
| 60 | isPanorama: isPanorama
|
|---|
| 61 | })));
|
|---|
| 62 | } |
|---|