@salutejs/plasma-new-hope 0.146.0-canary.1436.10882554984.0 → 0.146.1-canary.1412.10900761739.0
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/components/Drawer/Drawer.css +4 -3
- package/cjs/components/Drawer/Drawer.js +1 -1
- package/cjs/components/Drawer/Drawer.styles.js +2 -0
- package/cjs/components/Drawer/Drawer.styles.js.map +1 -1
- package/cjs/components/Drawer/hooks/useDrawer.js +1 -1
- package/cjs/components/Modal/Modal.css +4 -3
- package/cjs/components/Modal/hooks/useModal.js +1 -1
- package/cjs/components/Notification/NotificationsProvider.css +4 -3
- package/cjs/components/Popup/Popup.js +155 -38
- package/cjs/components/Popup/Popup.js.map +1 -1
- package/cjs/components/Popup/Popup.styles.js +21 -9
- package/cjs/components/Popup/Popup.styles.js.map +1 -1
- package/cjs/components/Popup/Popup.styles_8h77g1.css +4 -0
- package/cjs/components/Popup/PopupContext.css +4 -0
- package/cjs/components/Popup/PopupContext.js +9 -9
- package/cjs/components/Popup/PopupContext.js.map +1 -1
- package/cjs/components/Popup/hooks/usePopup.js +1 -1
- package/cjs/components/Popup/hooks/usePopup.js.map +1 -1
- package/cjs/index.css +4 -3
- package/emotion/cjs/components/Popup/Popup.js +156 -38
- package/emotion/cjs/components/Popup/Popup.styles.js +25 -5
- package/emotion/cjs/components/Popup/PopupContext.js +10 -9
- package/emotion/cjs/components/Popup/hooks/usePopup.js +1 -1
- package/emotion/cjs/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
- package/emotion/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
- package/emotion/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
- package/emotion/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
- package/emotion/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
- package/emotion/es/components/Popup/Popup.js +156 -39
- package/emotion/es/components/Popup/Popup.styles.js +24 -4
- package/emotion/es/components/Popup/PopupContext.js +10 -10
- package/emotion/es/components/Popup/hooks/usePopup.js +1 -1
- package/emotion/es/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
- package/emotion/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
- package/emotion/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
- package/emotion/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
- package/emotion/es/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
- package/es/components/Drawer/Drawer.css +4 -3
- package/es/components/Drawer/Drawer.js +1 -1
- package/es/components/Drawer/Drawer.styles.js +2 -0
- package/es/components/Drawer/Drawer.styles.js.map +1 -1
- package/es/components/Drawer/hooks/useDrawer.js +1 -1
- package/es/components/Modal/Modal.css +4 -3
- package/es/components/Modal/hooks/useModal.js +1 -1
- package/es/components/Notification/NotificationsProvider.css +4 -3
- package/es/components/Popup/Popup.js +157 -40
- package/es/components/Popup/Popup.js.map +1 -1
- package/es/components/Popup/Popup.styles.js +20 -10
- package/es/components/Popup/Popup.styles.js.map +1 -1
- package/es/components/Popup/Popup.styles_8h77g1.css +4 -0
- package/es/components/Popup/PopupContext.css +4 -0
- package/es/components/Popup/PopupContext.js +10 -10
- package/es/components/Popup/PopupContext.js.map +1 -1
- package/es/components/Popup/hooks/usePopup.js +1 -1
- package/es/components/Popup/hooks/usePopup.js.map +1 -1
- package/es/index.css +4 -3
- package/package.json +3 -3
- package/styled-components/cjs/components/Popup/Popup.js +156 -38
- package/styled-components/cjs/components/Popup/Popup.styles.js +7 -4
- package/styled-components/cjs/components/Popup/PopupContext.js +10 -9
- package/styled-components/cjs/components/Popup/hooks/usePopup.js +1 -1
- package/styled-components/cjs/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
- package/styled-components/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
- package/styled-components/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
- package/styled-components/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
- package/styled-components/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
- package/styled-components/es/components/Popup/Popup.js +156 -39
- package/styled-components/es/components/Popup/Popup.styles.js +6 -3
- package/styled-components/es/components/Popup/PopupContext.js +10 -10
- package/styled-components/es/components/Popup/hooks/usePopup.js +1 -1
- package/styled-components/es/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
- package/styled-components/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
- package/styled-components/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
- package/styled-components/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
- package/styled-components/es/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
- package/types/components/Popup/Popup.d.ts +1 -1
- package/types/components/Popup/Popup.d.ts.map +1 -1
- package/types/components/Popup/Popup.styles.d.ts +1 -0
- package/types/components/Popup/Popup.styles.d.ts.map +1 -1
- package/types/components/Popup/PopupContext.d.ts.map +1 -1
- package/cjs/components/Popup/Popup.css +0 -3
- package/cjs/components/Popup/Popup.styles_141jyqa.css +0 -3
- package/es/components/Popup/Popup.css +0 -3
- package/es/components/Popup/Popup.styles_141jyqa.css +0 -3
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.popupRoot = exports.popupConfig = exports.handlePosition = void 0;
|
8
8
|
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
9
|
+
var _reactDom = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react-dom"));
|
9
10
|
var _plasmaCore = /*#__PURE__*/require("@salutejs/plasma-core");
|
10
11
|
var _utils = /*#__PURE__*/require("../../utils");
|
11
12
|
var _Portal = /*#__PURE__*/require("../Portal");
|
@@ -13,7 +14,9 @@ var _PopupContext = /*#__PURE__*/require("./PopupContext");
|
|
13
14
|
var _PopupRoot = /*#__PURE__*/require("./PopupRoot");
|
14
15
|
var _hooks = /*#__PURE__*/require("./hooks");
|
15
16
|
var _Popup = /*#__PURE__*/require("./Popup.tokens");
|
17
|
+
var _Popup2 = /*#__PURE__*/require("./Popup.styles");
|
16
18
|
var _excluded = ["id", "isOpen", "opened", "placement", "offset", "frame", "children", "overlay", "role", "zIndex", "popupInfo", "withAnimation", "className"];
|
19
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
17
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
18
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
19
22
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
@@ -48,8 +51,8 @@ var handlePosition = exports.handlePosition = function handlePosition(placement,
|
|
48
51
|
var bottom;
|
49
52
|
var transform;
|
50
53
|
var placements = placement.split('-');
|
51
|
-
placements.forEach(function (
|
52
|
-
switch (
|
54
|
+
placements.forEach(function (placementValue) {
|
55
|
+
switch (placementValue) {
|
53
56
|
case 'left':
|
54
57
|
left = x;
|
55
58
|
break;
|
@@ -82,9 +85,139 @@ var handlePosition = exports.handlePosition = function handlePosition(placement,
|
|
82
85
|
transform: transform
|
83
86
|
};
|
84
87
|
};
|
88
|
+
/*
|
89
|
+
const getPortalParent = (frame: 'document' | string | React.RefObject<HTMLElement>, portalRef) => {
|
90
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
91
|
+
portalRef.current = frame.current;
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
|
95
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
96
|
+
const element = document.getElementById(frame);
|
97
|
+
if (element) {
|
98
|
+
const portal = document.createElement('div');
|
99
|
+
portal.className = 'frame-portal';
|
100
|
+
portal.style.position = 'relative';
|
101
|
+
portal.style.width = '0';
|
102
|
+
|
103
|
+
element.appendChild(portal);
|
104
|
+
portalRef.current = portal;
|
105
|
+
|
106
|
+
return;
|
107
|
+
//
|
108
|
+
// const portal = document?.querySelector('.frame-portal');
|
109
|
+
// if (!portal) {
|
110
|
+
// portal = document.createElement('div');
|
111
|
+
// document.getElementById(frame)?.appendChild(portal);
|
112
|
+
// }
|
113
|
+
// return portal;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
const portal = document.getElementById(POPUP_PORTAL_ID);
|
118
|
+
|
119
|
+
if (!portal) {
|
120
|
+
ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
121
|
+
}
|
122
|
+
|
123
|
+
portalRef.current = portal;
|
124
|
+
|
125
|
+
let portal;
|
126
|
+
|
127
|
+
const hasFrame = typeof frame !== 'string' && frame && frame.current;
|
128
|
+
if (hasFrame) {
|
129
|
+
portal = frame.current;
|
130
|
+
} else {
|
131
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
132
|
+
|
133
|
+
portal = document.getElementById(POPUP_PORTAL_ID);
|
134
|
+
|
135
|
+
if (!portal) {
|
136
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
137
|
+
portal = document.createElement('div');
|
138
|
+
document.getElementById(frame)?.appendChild(portal);
|
139
|
+
} else {
|
140
|
+
portal.className('frame-portal');
|
141
|
+
document.body.appendChild(portal);
|
142
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
};
|
148
|
+
|
149
|
+
const usePortalContainer = (frame: 'document' | string | React.RefObject<HTMLElement>) => {
|
150
|
+
const portalRef = useRef<HTMLDivElement | null>(null);
|
151
|
+
|
152
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
153
|
+
return frame.current;
|
154
|
+
}
|
155
|
+
|
156
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
157
|
+
const element = document.getElementById(frame);
|
158
|
+
|
159
|
+
const portal = document?.querySelector('.frame-portal');
|
160
|
+
|
161
|
+
if (portal) {
|
162
|
+
return portal;
|
163
|
+
}
|
164
|
+
|
165
|
+
if (element) {
|
166
|
+
const portal = document.createElement('div');
|
167
|
+
portal.className = 'frame-portal';
|
168
|
+
portal.style.position = 'relative';
|
169
|
+
// portal.style.width = '0';
|
170
|
+
|
171
|
+
element.appendChild(portal);
|
172
|
+
return portal;
|
173
|
+
//
|
174
|
+
// const portal = document?.querySelector('.frame-portal');
|
175
|
+
// if (!portal) {
|
176
|
+
// portal = document.createElement('div');
|
177
|
+
// document.getElementById(frame)?.appendChild(portal);
|
178
|
+
// }
|
179
|
+
// return portal;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
const portal = document.getElementById(POPUP_PORTAL_ID);
|
184
|
+
|
185
|
+
if (!portal) {
|
186
|
+
const res = ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
187
|
+
|
188
|
+
console.log('!!! res', res);
|
189
|
+
}
|
190
|
+
|
191
|
+
console.log('!!!! portalRef.current', portalRef.current, document.getElementById(POPUP_PORTAL_ID));
|
192
|
+
return portalRef.current;
|
193
|
+
|
194
|
+
let portal;
|
195
|
+
|
196
|
+
const hasFrame = typeof frame !== 'string' && frame && frame.current;
|
197
|
+
if (hasFrame) {
|
198
|
+
portal = frame.current;
|
199
|
+
} else {
|
200
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
201
|
+
|
202
|
+
portal = document.getElementById(POPUP_PORTAL_ID);
|
203
|
+
|
204
|
+
if (!portal) {
|
205
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
206
|
+
portal = document.createElement('div');
|
207
|
+
document.getElementById(frame)?.appendChild(portal);
|
208
|
+
} else {
|
209
|
+
portal.className('frame-portal');
|
210
|
+
document.body.appendChild(portal);
|
211
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
212
|
+
}
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
};
|
217
|
+
*/
|
85
218
|
|
86
219
|
/**
|
87
|
-
* Базовый
|
220
|
+
* Базовый компонент Popup.
|
88
221
|
*/
|
89
222
|
var popupRoot = exports.popupRoot = function popupRoot(Root) {
|
90
223
|
return /*#__PURE__*/(0, _react.forwardRef)(function (_ref, outerRootRef) {
|
@@ -123,44 +256,11 @@ var popupRoot = exports.popupRoot = function popupRoot(Root) {
|
|
123
256
|
var portalRef = (0, _react.useRef)(null);
|
124
257
|
var contentRef = (0, _react.useRef)(null);
|
125
258
|
var innerRef = (0, _plasmaCore.useForkRef)(contentRef, outerRootRef);
|
126
|
-
var _useState = (0, _react.useState)(false),
|
127
|
-
_useState2 = _slicedToArray(_useState, 2),
|
128
|
-
forceRender = _useState2[1];
|
129
|
-
(0, _react.useEffect)(function () {
|
130
|
-
var portal = document.getElementById(_PopupContext.POPUP_PORTAL_ID);
|
131
|
-
if (typeof frame !== 'string' && frame && frame.current) {
|
132
|
-
portal = frame.current;
|
133
|
-
}
|
134
|
-
if (!portal) {
|
135
|
-
portal = document.createElement('div');
|
136
|
-
portal.setAttribute('id', _PopupContext.POPUP_PORTAL_ID);
|
137
|
-
/**
|
138
|
-
* Нужно для того, чтобы во фрейме не происходило скачков контента
|
139
|
-
* при анимации через transform, если есть элемент с шириной/высотой в 100% (Overlay)
|
140
|
-
*/
|
141
|
-
portal.style.width = '0';
|
142
|
-
if (typeof frame === 'string' && frame !== 'document') {
|
143
|
-
var _document$getElementB;
|
144
|
-
(_document$getElementB = document.getElementById(frame)) === null || _document$getElementB === void 0 || _document$getElementB.appendChild(portal);
|
145
|
-
} else {
|
146
|
-
document.body.appendChild(portal);
|
147
|
-
}
|
148
|
-
}
|
149
|
-
portalRef.current = portal;
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Изменение стейта нужно для того, чтобы Popup
|
153
|
-
* отобразился после записи DOM элемента в portalRef.current
|
154
|
-
*/
|
155
|
-
forceRender(true);
|
156
|
-
}, []);
|
157
259
|
if (!isVisible && !innerIsOpen) {
|
158
260
|
return null;
|
159
261
|
}
|
160
262
|
var cls = (0, _utils.cx)(className, animationInfo !== null && animationInfo !== void 0 && animationInfo.endAnimation ? _Popup.classes.endAnimation : '', animationInfo !== null && animationInfo !== void 0 && animationInfo.endTransition ? _Popup.classes.endTransition : '');
|
161
|
-
|
162
|
-
container: portalRef.current
|
163
|
-
}, /*#__PURE__*/_react["default"].createElement(Root, _extends({
|
263
|
+
var rootNode = /*#__PURE__*/_react["default"].createElement(Root, _extends({
|
164
264
|
className: cls
|
165
265
|
}, rest), overlay, /*#__PURE__*/_react["default"].createElement(_PopupRoot.PopupRoot, {
|
166
266
|
id: innerId,
|
@@ -170,7 +270,25 @@ var popupRoot = exports.popupRoot = function popupRoot(Root) {
|
|
170
270
|
zIndex: zIndex,
|
171
271
|
animationInfo: animationInfo,
|
172
272
|
setVisible: setVisible
|
173
|
-
}, children))
|
273
|
+
}, children));
|
274
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
275
|
+
return /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
276
|
+
container: frame.current
|
277
|
+
}, rootNode);
|
278
|
+
}
|
279
|
+
var withFrameId = typeof frame === 'string' && frame !== 'document';
|
280
|
+
var containerElement = withFrameId && document.getElementById(frame);
|
281
|
+
if (containerElement) {
|
282
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_reactDom["default"].createPortal( /*#__PURE__*/_react["default"].createElement(_Popup2.StyledPortalContainer, {
|
283
|
+
ref: portalRef
|
284
|
+
}, portalRef.current && /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
285
|
+
container: portalRef.current
|
286
|
+
}, rootNode)), containerElement));
|
287
|
+
}
|
288
|
+
var globalPortal = typeof document !== 'undefined' && document.getElementById(_PopupContext.POPUP_PORTAL_ID);
|
289
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, globalPortal && /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
|
290
|
+
container: globalPortal
|
291
|
+
}, rootNode));
|
174
292
|
});
|
175
293
|
};
|
176
294
|
var popupConfig = exports.popupConfig = {
|
@@ -3,18 +3,21 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.StyledPortal = exports.PopupView = exports.PopupRootContainer = void 0;
|
6
|
+
exports.StyledPortalContainer = exports.StyledPortal = exports.PopupView = exports.PopupRootContainer = void 0;
|
7
7
|
var _styledComponents = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("styled-components"));
|
8
8
|
var _utils = /*#__PURE__*/require("./utils");
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
10
10
|
var StyledPortal = exports.StyledPortal = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
11
11
|
componentId: "plasma-new-hope__sc-rkhnjn-0"
|
12
|
-
})([""]);
|
13
|
-
var
|
12
|
+
})(["position:fixed;top:0;left:0;right:0;bottom:0;:empty{width:0;pointer-events:none;}:not(:empty){width:auto;pointer-events:auto;}"]);
|
13
|
+
var StyledPortalContainer = exports.StyledPortalContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
14
14
|
componentId: "plasma-new-hope__sc-rkhnjn-1"
|
15
|
+
})(["width:0;"]);
|
16
|
+
var PopupView = exports.PopupView = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
17
|
+
componentId: "plasma-new-hope__sc-rkhnjn-2"
|
15
18
|
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
16
19
|
var PopupRootContainer = exports.PopupRootContainer = /*#__PURE__*/_styledComponents["default"].div.withConfig({
|
17
|
-
componentId: "plasma-new-hope__sc-rkhnjn-
|
20
|
+
componentId: "plasma-new-hope__sc-rkhnjn-3"
|
18
21
|
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (_ref) {
|
19
22
|
var zIndex = _ref.zIndex;
|
20
23
|
return zIndex || _utils.DEFAULT_Z_INDEX;
|
@@ -6,7 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
});
|
7
7
|
exports.usePopupContext = exports.PopupProvider = exports.POPUP_PORTAL_ID = void 0;
|
8
8
|
var _react = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react"));
|
9
|
+
var _reactDom = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("react-dom"));
|
9
10
|
var _ModalContext = /*#__PURE__*/require("../Modal/ModalContext");
|
11
|
+
var _Popup = /*#__PURE__*/require("./Popup.styles");
|
12
|
+
var _StyledPortal;
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
10
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
11
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
12
16
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -23,9 +27,11 @@ var POPUP_PORTAL_ID = exports.POPUP_PORTAL_ID = 'plasma-popup-root';
|
|
23
27
|
var items = [];
|
24
28
|
var PopupContext = /*#__PURE__*/(0, _react.createContext)({
|
25
29
|
items: items,
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
26
31
|
register: function register(_info) {
|
27
32
|
throw new Error('Function not implemented. Add PopupProvider');
|
28
33
|
},
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
29
35
|
unregister: function unregister(_id) {
|
30
36
|
throw new Error('Function not implemented. Add PopupProvider');
|
31
37
|
}
|
@@ -36,6 +42,7 @@ var usePopupContext = exports.usePopupContext = function usePopupContext() {
|
|
36
42
|
var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
37
43
|
var children = _ref.children;
|
38
44
|
var prevBodyOverflowY = (0, _react.useRef)(typeof document !== 'undefined' ? document.body.style.overflowY : '');
|
45
|
+
// eslint-disable-next-line no-shadow
|
39
46
|
var _useState = (0, _react.useState)([]),
|
40
47
|
_useState2 = _slicedToArray(_useState, 2),
|
41
48
|
items = _useState2[0],
|
@@ -73,15 +80,9 @@ var PopupProvider = exports.PopupProvider = function PopupProvider(_ref) {
|
|
73
80
|
register: register,
|
74
81
|
unregister: unregister
|
75
82
|
};
|
76
|
-
(0, _react.useEffect)(function () {
|
77
|
-
return function () {
|
78
|
-
var portal = document.createElement('div');
|
79
|
-
if (portal && document.body.contains(portal)) {
|
80
|
-
document.body.removeChild(portal);
|
81
|
-
}
|
82
|
-
};
|
83
|
-
}, []);
|
84
83
|
return /*#__PURE__*/_react["default"].createElement(PopupContext.Provider, {
|
85
84
|
value: context
|
86
|
-
}, children
|
85
|
+
}, children, /*#__PURE__*/_reactDom["default"].createPortal(_StyledPortal || (_StyledPortal = /*#__PURE__*/_react["default"].createElement(_Popup.StyledPortal, {
|
86
|
+
id: POPUP_PORTAL_ID
|
87
|
+
})), document.body));
|
87
88
|
};
|
@@ -18,7 +18,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
18
18
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
19
19
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
20
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
21
|
-
// Хук для
|
21
|
+
// Хук для подключения анимации
|
22
22
|
var usePopupAnimation = function usePopupAnimation() {
|
23
23
|
var _useState = (0, _react.useState)(false),
|
24
24
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -8,7 +8,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
8
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
9
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
|
-
import React, { forwardRef,
|
11
|
+
import React, { forwardRef, useRef } from 'react';
|
12
|
+
import ReactDOM from 'react-dom';
|
12
13
|
import { useForkRef, safeUseId } from '@salutejs/plasma-core';
|
13
14
|
import { cx } from '../../utils';
|
14
15
|
import { Portal } from '../Portal';
|
@@ -16,6 +17,7 @@ import { POPUP_PORTAL_ID } from './PopupContext';
|
|
16
17
|
import { PopupRoot } from './PopupRoot';
|
17
18
|
import { usePopup } from './hooks';
|
18
19
|
import { classes } from './Popup.tokens';
|
20
|
+
import { StyledPortalContainer } from './Popup.styles';
|
19
21
|
export var handlePosition = function handlePosition(placement, offset) {
|
20
22
|
var x = '0rem';
|
21
23
|
var y = '0rem';
|
@@ -39,8 +41,8 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
39
41
|
var bottom;
|
40
42
|
var transform;
|
41
43
|
var placements = placement.split('-');
|
42
|
-
placements.forEach(function (
|
43
|
-
switch (
|
44
|
+
placements.forEach(function (placementValue) {
|
45
|
+
switch (placementValue) {
|
44
46
|
case 'left':
|
45
47
|
left = x;
|
46
48
|
break;
|
@@ -73,9 +75,139 @@ export var handlePosition = function handlePosition(placement, offset) {
|
|
73
75
|
transform: transform
|
74
76
|
};
|
75
77
|
};
|
78
|
+
/*
|
79
|
+
const getPortalParent = (frame: 'document' | string | React.RefObject<HTMLElement>, portalRef) => {
|
80
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
81
|
+
portalRef.current = frame.current;
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
|
85
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
86
|
+
const element = document.getElementById(frame);
|
87
|
+
if (element) {
|
88
|
+
const portal = document.createElement('div');
|
89
|
+
portal.className = 'frame-portal';
|
90
|
+
portal.style.position = 'relative';
|
91
|
+
portal.style.width = '0';
|
92
|
+
|
93
|
+
element.appendChild(portal);
|
94
|
+
portalRef.current = portal;
|
95
|
+
|
96
|
+
return;
|
97
|
+
//
|
98
|
+
// const portal = document?.querySelector('.frame-portal');
|
99
|
+
// if (!portal) {
|
100
|
+
// portal = document.createElement('div');
|
101
|
+
// document.getElementById(frame)?.appendChild(portal);
|
102
|
+
// }
|
103
|
+
// return portal;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
const portal = document.getElementById(POPUP_PORTAL_ID);
|
108
|
+
|
109
|
+
if (!portal) {
|
110
|
+
ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
111
|
+
}
|
112
|
+
|
113
|
+
portalRef.current = portal;
|
114
|
+
|
115
|
+
let portal;
|
116
|
+
|
117
|
+
const hasFrame = typeof frame !== 'string' && frame && frame.current;
|
118
|
+
if (hasFrame) {
|
119
|
+
portal = frame.current;
|
120
|
+
} else {
|
121
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
122
|
+
|
123
|
+
portal = document.getElementById(POPUP_PORTAL_ID);
|
124
|
+
|
125
|
+
if (!portal) {
|
126
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
127
|
+
portal = document.createElement('div');
|
128
|
+
document.getElementById(frame)?.appendChild(portal);
|
129
|
+
} else {
|
130
|
+
portal.className('frame-portal');
|
131
|
+
document.body.appendChild(portal);
|
132
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
const usePortalContainer = (frame: 'document' | string | React.RefObject<HTMLElement>) => {
|
140
|
+
const portalRef = useRef<HTMLDivElement | null>(null);
|
141
|
+
|
142
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
143
|
+
return frame.current;
|
144
|
+
}
|
145
|
+
|
146
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
147
|
+
const element = document.getElementById(frame);
|
148
|
+
|
149
|
+
const portal = document?.querySelector('.frame-portal');
|
150
|
+
|
151
|
+
if (portal) {
|
152
|
+
return portal;
|
153
|
+
}
|
154
|
+
|
155
|
+
if (element) {
|
156
|
+
const portal = document.createElement('div');
|
157
|
+
portal.className = 'frame-portal';
|
158
|
+
portal.style.position = 'relative';
|
159
|
+
// portal.style.width = '0';
|
160
|
+
|
161
|
+
element.appendChild(portal);
|
162
|
+
return portal;
|
163
|
+
//
|
164
|
+
// const portal = document?.querySelector('.frame-portal');
|
165
|
+
// if (!portal) {
|
166
|
+
// portal = document.createElement('div');
|
167
|
+
// document.getElementById(frame)?.appendChild(portal);
|
168
|
+
// }
|
169
|
+
// return portal;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
const portal = document.getElementById(POPUP_PORTAL_ID);
|
174
|
+
|
175
|
+
if (!portal) {
|
176
|
+
const res = ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
177
|
+
|
178
|
+
console.log('!!! res', res);
|
179
|
+
}
|
180
|
+
|
181
|
+
console.log('!!!! portalRef.current', portalRef.current, document.getElementById(POPUP_PORTAL_ID));
|
182
|
+
return portalRef.current;
|
183
|
+
|
184
|
+
let portal;
|
185
|
+
|
186
|
+
const hasFrame = typeof frame !== 'string' && frame && frame.current;
|
187
|
+
if (hasFrame) {
|
188
|
+
portal = frame.current;
|
189
|
+
} else {
|
190
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
191
|
+
|
192
|
+
portal = document.getElementById(POPUP_PORTAL_ID);
|
193
|
+
|
194
|
+
if (!portal) {
|
195
|
+
if (typeof frame === 'string' && frame !== 'document') {
|
196
|
+
portal = document.createElement('div');
|
197
|
+
document.getElementById(frame)?.appendChild(portal);
|
198
|
+
} else {
|
199
|
+
portal.className('frame-portal');
|
200
|
+
document.body.appendChild(portal);
|
201
|
+
// ReactDOM.createPortal(<StyledPortal id={POPUP_PORTAL_ID} ref={portalRef} />, document.body);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
};
|
207
|
+
*/
|
76
208
|
|
77
209
|
/**
|
78
|
-
* Базовый
|
210
|
+
* Базовый компонент Popup.
|
79
211
|
*/
|
80
212
|
export var popupRoot = function popupRoot(Root) {
|
81
213
|
return /*#__PURE__*/forwardRef(function (_ref, outerRootRef) {
|
@@ -114,44 +246,11 @@ export var popupRoot = function popupRoot(Root) {
|
|
114
246
|
var portalRef = useRef(null);
|
115
247
|
var contentRef = useRef(null);
|
116
248
|
var innerRef = useForkRef(contentRef, outerRootRef);
|
117
|
-
var _useState = useState(false),
|
118
|
-
_useState2 = _slicedToArray(_useState, 2),
|
119
|
-
forceRender = _useState2[1];
|
120
|
-
useEffect(function () {
|
121
|
-
var portal = document.getElementById(POPUP_PORTAL_ID);
|
122
|
-
if (typeof frame !== 'string' && frame && frame.current) {
|
123
|
-
portal = frame.current;
|
124
|
-
}
|
125
|
-
if (!portal) {
|
126
|
-
portal = document.createElement('div');
|
127
|
-
portal.setAttribute('id', POPUP_PORTAL_ID);
|
128
|
-
/**
|
129
|
-
* Нужно для того, чтобы во фрейме не происходило скачков контента
|
130
|
-
* при анимации через transform, если есть элемент с шириной/высотой в 100% (Overlay)
|
131
|
-
*/
|
132
|
-
portal.style.width = '0';
|
133
|
-
if (typeof frame === 'string' && frame !== 'document') {
|
134
|
-
var _document$getElementB;
|
135
|
-
(_document$getElementB = document.getElementById(frame)) === null || _document$getElementB === void 0 || _document$getElementB.appendChild(portal);
|
136
|
-
} else {
|
137
|
-
document.body.appendChild(portal);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
portalRef.current = portal;
|
141
|
-
|
142
|
-
/**
|
143
|
-
* Изменение стейта нужно для того, чтобы Popup
|
144
|
-
* отобразился после записи DOM элемента в portalRef.current
|
145
|
-
*/
|
146
|
-
forceRender(true);
|
147
|
-
}, []);
|
148
249
|
if (!isVisible && !innerIsOpen) {
|
149
250
|
return null;
|
150
251
|
}
|
151
252
|
var cls = cx(className, animationInfo !== null && animationInfo !== void 0 && animationInfo.endAnimation ? classes.endAnimation : '', animationInfo !== null && animationInfo !== void 0 && animationInfo.endTransition ? classes.endTransition : '');
|
152
|
-
|
153
|
-
container: portalRef.current
|
154
|
-
}, /*#__PURE__*/React.createElement(Root, _extends({
|
253
|
+
var rootNode = /*#__PURE__*/React.createElement(Root, _extends({
|
155
254
|
className: cls
|
156
255
|
}, rest), overlay, /*#__PURE__*/React.createElement(PopupRoot, {
|
157
256
|
id: innerId,
|
@@ -161,7 +260,25 @@ export var popupRoot = function popupRoot(Root) {
|
|
161
260
|
zIndex: zIndex,
|
162
261
|
animationInfo: animationInfo,
|
163
262
|
setVisible: setVisible
|
164
|
-
}, children))
|
263
|
+
}, children));
|
264
|
+
if (typeof frame !== 'string' && frame && frame.current) {
|
265
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
266
|
+
container: frame.current
|
267
|
+
}, rootNode);
|
268
|
+
}
|
269
|
+
var withFrameId = typeof frame === 'string' && frame !== 'document';
|
270
|
+
var containerElement = withFrameId && document.getElementById(frame);
|
271
|
+
if (containerElement) {
|
272
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(StyledPortalContainer, {
|
273
|
+
ref: portalRef
|
274
|
+
}, portalRef.current && /*#__PURE__*/React.createElement(Portal, {
|
275
|
+
container: portalRef.current
|
276
|
+
}, rootNode)), containerElement));
|
277
|
+
}
|
278
|
+
var globalPortal = typeof document !== 'undefined' && document.getElementById(POPUP_PORTAL_ID);
|
279
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, globalPortal && /*#__PURE__*/React.createElement(Portal, {
|
280
|
+
container: globalPortal
|
281
|
+
}, rootNode));
|
165
282
|
});
|
166
283
|
};
|
167
284
|
export var popupConfig = {
|
@@ -2,12 +2,15 @@ import styled from 'styled-components';
|
|
2
2
|
import { DEFAULT_Z_INDEX } from './utils';
|
3
3
|
export var StyledPortal = /*#__PURE__*/styled.div.withConfig({
|
4
4
|
componentId: "plasma-new-hope__sc-rkhnjn-0"
|
5
|
-
})([""]);
|
6
|
-
export var
|
5
|
+
})(["position:fixed;top:0;left:0;right:0;bottom:0;:empty{width:0;pointer-events:none;}:not(:empty){width:auto;pointer-events:auto;}"]);
|
6
|
+
export var StyledPortalContainer = /*#__PURE__*/styled.div.withConfig({
|
7
7
|
componentId: "plasma-new-hope__sc-rkhnjn-1"
|
8
|
+
})(["width:0;"]);
|
9
|
+
export var PopupView = /*#__PURE__*/styled.div.withConfig({
|
10
|
+
componentId: "plasma-new-hope__sc-rkhnjn-2"
|
8
11
|
})(["position:relative;max-width:100%;pointer-events:all;"]);
|
9
12
|
export var PopupRootContainer = /*#__PURE__*/styled.div.withConfig({
|
10
|
-
componentId: "plasma-new-hope__sc-rkhnjn-
|
13
|
+
componentId: "plasma-new-hope__sc-rkhnjn-3"
|
11
14
|
})(["position:absolute;z-index:", ";left:", ";right:", ";top:", ";bottom:", ";transform:", ";"], function (_ref) {
|
12
15
|
var zIndex = _ref.zIndex;
|
13
16
|
return zIndex || DEFAULT_Z_INDEX;
|