| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.zIndexReducer = exports.unregisterZIndexPortalElement = exports.unregisterZIndexPortal = exports.registerZIndexPortalElement = exports.registerZIndexPortal = void 0;
|
|---|
| 7 | var _toolkit = require("@reduxjs/toolkit");
|
|---|
| 8 | var _immer = require("immer");
|
|---|
| 9 | var _DefaultZIndexes = require("../zIndex/DefaultZIndexes");
|
|---|
| 10 | function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|---|
| 11 | function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|---|
| 12 | function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|---|
| 13 | function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|---|
| 14 | function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
|
|---|
| 15 | * This slice contains a registry of z-index values for various components.
|
|---|
| 16 | * The state is a map from z-index numbers to element references.
|
|---|
| 17 | */
|
|---|
| 18 | var seed = {};
|
|---|
| 19 | var initialState = {
|
|---|
| 20 | zIndexMap: Object.values(_DefaultZIndexes.DefaultZIndexes).reduce((acc, current) => _objectSpread(_objectSpread({}, acc), {}, {
|
|---|
| 21 | [current]: {
|
|---|
| 22 | element: undefined,
|
|---|
| 23 | panoramaElement: undefined,
|
|---|
| 24 | consumers: 0
|
|---|
| 25 | }
|
|---|
| 26 | }), seed)
|
|---|
| 27 | };
|
|---|
| 28 | var defaultZIndexSet = new Set(Object.values(_DefaultZIndexes.DefaultZIndexes));
|
|---|
| 29 | function isDefaultZIndex(zIndex) {
|
|---|
| 30 | return defaultZIndexSet.has(zIndex);
|
|---|
| 31 | }
|
|---|
| 32 | var zIndexSlice = (0, _toolkit.createSlice)({
|
|---|
| 33 | name: 'zIndex',
|
|---|
| 34 | initialState,
|
|---|
| 35 | reducers: {
|
|---|
| 36 | registerZIndexPortal: {
|
|---|
| 37 | reducer: (state, action) => {
|
|---|
| 38 | var {
|
|---|
| 39 | zIndex
|
|---|
| 40 | } = action.payload;
|
|---|
| 41 | if (state.zIndexMap[zIndex]) {
|
|---|
| 42 | state.zIndexMap[zIndex].consumers += 1;
|
|---|
| 43 | } else {
|
|---|
| 44 | state.zIndexMap[zIndex] = {
|
|---|
| 45 | consumers: 1,
|
|---|
| 46 | element: undefined,
|
|---|
| 47 | panoramaElement: undefined
|
|---|
| 48 | };
|
|---|
| 49 | }
|
|---|
| 50 | },
|
|---|
| 51 | prepare: (0, _toolkit.prepareAutoBatched)()
|
|---|
| 52 | },
|
|---|
| 53 | unregisterZIndexPortal: {
|
|---|
| 54 | reducer: (state, action) => {
|
|---|
| 55 | var {
|
|---|
| 56 | zIndex
|
|---|
| 57 | } = action.payload;
|
|---|
| 58 | if (state.zIndexMap[zIndex]) {
|
|---|
| 59 | state.zIndexMap[zIndex].consumers -= 1;
|
|---|
| 60 | /*
|
|---|
| 61 | * Garbage collect unused z-index entries, except for default z-indexes.
|
|---|
| 62 | * Default z-indexes are always rendered, regardless of whether there are consumers or not.
|
|---|
| 63 | * And because of that, even if we delete this entry, the ZIndexPortal provider will still be rendered
|
|---|
| 64 | * and React is not going to re-create it, and it won't re-register the element ID.
|
|---|
| 65 | * So let's not delete default z-index entries.
|
|---|
| 66 | */
|
|---|
| 67 | if (state.zIndexMap[zIndex].consumers <= 0 && !isDefaultZIndex(zIndex)) {
|
|---|
| 68 | delete state.zIndexMap[zIndex];
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | },
|
|---|
| 72 | prepare: (0, _toolkit.prepareAutoBatched)()
|
|---|
| 73 | },
|
|---|
| 74 | registerZIndexPortalElement: {
|
|---|
| 75 | reducer: (state, action) => {
|
|---|
| 76 | var {
|
|---|
| 77 | zIndex,
|
|---|
| 78 | element,
|
|---|
| 79 | isPanorama
|
|---|
| 80 | } = action.payload;
|
|---|
| 81 | if (state.zIndexMap[zIndex]) {
|
|---|
| 82 | if (isPanorama) {
|
|---|
| 83 | state.zIndexMap[zIndex].panoramaElement = (0, _immer.castDraft)(element);
|
|---|
| 84 | } else {
|
|---|
| 85 | state.zIndexMap[zIndex].element = (0, _immer.castDraft)(element);
|
|---|
| 86 | }
|
|---|
| 87 | } else {
|
|---|
| 88 | state.zIndexMap[zIndex] = {
|
|---|
| 89 | consumers: 0,
|
|---|
| 90 | element: isPanorama ? undefined : (0, _immer.castDraft)(element),
|
|---|
| 91 | panoramaElement: isPanorama ? (0, _immer.castDraft)(element) : undefined
|
|---|
| 92 | };
|
|---|
| 93 | }
|
|---|
| 94 | },
|
|---|
| 95 | prepare: (0, _toolkit.prepareAutoBatched)()
|
|---|
| 96 | },
|
|---|
| 97 | unregisterZIndexPortalElement: {
|
|---|
| 98 | reducer: (state, action) => {
|
|---|
| 99 | var {
|
|---|
| 100 | zIndex
|
|---|
| 101 | } = action.payload;
|
|---|
| 102 | if (state.zIndexMap[zIndex]) {
|
|---|
| 103 | if (action.payload.isPanorama) {
|
|---|
| 104 | state.zIndexMap[zIndex].panoramaElement = undefined;
|
|---|
| 105 | } else {
|
|---|
| 106 | state.zIndexMap[zIndex].element = undefined;
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | },
|
|---|
| 110 | prepare: (0, _toolkit.prepareAutoBatched)()
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | });
|
|---|
| 114 | var {
|
|---|
| 115 | registerZIndexPortal,
|
|---|
| 116 | unregisterZIndexPortal,
|
|---|
| 117 | registerZIndexPortalElement,
|
|---|
| 118 | unregisterZIndexPortalElement
|
|---|
| 119 | } = zIndexSlice.actions;
|
|---|
| 120 | exports.unregisterZIndexPortalElement = unregisterZIndexPortalElement;
|
|---|
| 121 | exports.registerZIndexPortalElement = registerZIndexPortalElement;
|
|---|
| 122 | exports.unregisterZIndexPortal = unregisterZIndexPortal;
|
|---|
| 123 | exports.registerZIndexPortal = registerZIndexPortal;
|
|---|
| 124 | var zIndexReducer = exports.zIndexReducer = zIndexSlice.reducer; |
|---|