@salutejs/plasma-new-hope 0.146.0-dev.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.
Files changed (84) hide show
  1. package/cjs/components/Drawer/Drawer.css +4 -3
  2. package/cjs/components/Drawer/Drawer.js +1 -1
  3. package/cjs/components/Drawer/Drawer.styles.js +2 -0
  4. package/cjs/components/Drawer/Drawer.styles.js.map +1 -1
  5. package/cjs/components/Drawer/hooks/useDrawer.js +1 -1
  6. package/cjs/components/Modal/Modal.css +4 -3
  7. package/cjs/components/Modal/hooks/useModal.js +1 -1
  8. package/cjs/components/Notification/NotificationsProvider.css +4 -3
  9. package/cjs/components/Popup/Popup.js +155 -38
  10. package/cjs/components/Popup/Popup.js.map +1 -1
  11. package/cjs/components/Popup/Popup.styles.js +21 -9
  12. package/cjs/components/Popup/Popup.styles.js.map +1 -1
  13. package/cjs/components/Popup/Popup.styles_8h77g1.css +4 -0
  14. package/cjs/components/Popup/PopupContext.css +4 -0
  15. package/cjs/components/Popup/PopupContext.js +9 -9
  16. package/cjs/components/Popup/PopupContext.js.map +1 -1
  17. package/cjs/components/Popup/hooks/usePopup.js +1 -1
  18. package/cjs/components/Popup/hooks/usePopup.js.map +1 -1
  19. package/cjs/index.css +4 -3
  20. package/emotion/cjs/components/Popup/Popup.js +156 -38
  21. package/emotion/cjs/components/Popup/Popup.styles.js +25 -5
  22. package/emotion/cjs/components/Popup/PopupContext.js +10 -9
  23. package/emotion/cjs/components/Popup/hooks/usePopup.js +1 -1
  24. package/emotion/cjs/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
  25. package/emotion/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
  26. package/emotion/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
  27. package/emotion/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
  28. package/emotion/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
  29. package/emotion/es/components/Popup/Popup.js +156 -39
  30. package/emotion/es/components/Popup/Popup.styles.js +24 -4
  31. package/emotion/es/components/Popup/PopupContext.js +10 -10
  32. package/emotion/es/components/Popup/hooks/usePopup.js +1 -1
  33. package/emotion/es/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
  34. package/emotion/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
  35. package/emotion/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
  36. package/emotion/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
  37. package/emotion/es/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
  38. package/es/components/Drawer/Drawer.css +4 -3
  39. package/es/components/Drawer/Drawer.js +1 -1
  40. package/es/components/Drawer/Drawer.styles.js +2 -0
  41. package/es/components/Drawer/Drawer.styles.js.map +1 -1
  42. package/es/components/Drawer/hooks/useDrawer.js +1 -1
  43. package/es/components/Modal/Modal.css +4 -3
  44. package/es/components/Modal/hooks/useModal.js +1 -1
  45. package/es/components/Notification/NotificationsProvider.css +4 -3
  46. package/es/components/Popup/Popup.js +157 -40
  47. package/es/components/Popup/Popup.js.map +1 -1
  48. package/es/components/Popup/Popup.styles.js +20 -10
  49. package/es/components/Popup/Popup.styles.js.map +1 -1
  50. package/es/components/Popup/Popup.styles_8h77g1.css +4 -0
  51. package/es/components/Popup/PopupContext.css +4 -0
  52. package/es/components/Popup/PopupContext.js +10 -10
  53. package/es/components/Popup/PopupContext.js.map +1 -1
  54. package/es/components/Popup/hooks/usePopup.js +1 -1
  55. package/es/components/Popup/hooks/usePopup.js.map +1 -1
  56. package/es/index.css +4 -3
  57. package/package.json +3 -3
  58. package/styled-components/cjs/components/Popup/Popup.js +156 -38
  59. package/styled-components/cjs/components/Popup/Popup.styles.js +7 -4
  60. package/styled-components/cjs/components/Popup/PopupContext.js +10 -9
  61. package/styled-components/cjs/components/Popup/hooks/usePopup.js +1 -1
  62. package/styled-components/cjs/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
  63. package/styled-components/cjs/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
  64. package/styled-components/cjs/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
  65. package/styled-components/cjs/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
  66. package/styled-components/cjs/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
  67. package/styled-components/es/components/Popup/Popup.js +156 -39
  68. package/styled-components/es/components/Popup/Popup.styles.js +6 -3
  69. package/styled-components/es/components/Popup/PopupContext.js +10 -10
  70. package/styled-components/es/components/Popup/hooks/usePopup.js +1 -1
  71. package/styled-components/es/examples/plasma_b2c/components/Drawer/Drawer.stories.tsx +1 -1
  72. package/styled-components/es/examples/plasma_b2c/components/Modal/Modal.stories.tsx +1 -1
  73. package/styled-components/es/examples/plasma_b2c/components/Popup/Popup.stories.tsx +1 -1
  74. package/styled-components/es/examples/plasma_web/components/Modal/Modal.stories.tsx +1 -1
  75. package/styled-components/es/examples/plasma_web/components/Popup/Popup.stories.tsx +1 -1
  76. package/types/components/Popup/Popup.d.ts +1 -1
  77. package/types/components/Popup/Popup.d.ts.map +1 -1
  78. package/types/components/Popup/Popup.styles.d.ts +1 -0
  79. package/types/components/Popup/Popup.styles.d.ts.map +1 -1
  80. package/types/components/Popup/PopupContext.d.ts.map +1 -1
  81. package/cjs/components/Popup/Popup.css +0 -3
  82. package/cjs/components/Popup/Popup.styles_141jyqa.css +0 -3
  83. package/es/components/Popup/Popup.css +0 -3
  84. 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 (placement) {
52
- switch (placement) {
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
- * Базовый копмонент Popup.
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
- return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, portalRef.current && /*#__PURE__*/_react["default"].createElement(_Portal.Portal, {
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 PopupView = exports.PopupView = /*#__PURE__*/_styledComponents["default"].div.withConfig({
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-2"
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),
@@ -211,7 +211,7 @@ export const DrawerDemo: StoryObj<StoryDrawerProps> = {
211
211
  asModal: true,
212
212
  closePlacement: 'right',
213
213
  width: '25vw',
214
- height: '100dvh',
214
+ height: '100vh',
215
215
  borderRadius: 'none',
216
216
  },
217
217
  render: (args) => <StoryDrawerDemo {...args} />,
@@ -80,7 +80,7 @@ const StyledButton = styled(Button)`
80
80
  `;
81
81
 
82
82
  const StyledWrapper = styled.div`
83
- height: 1200px;
83
+ height: 300px;
84
84
  `;
85
85
 
86
86
  const Content = styled.div`
@@ -55,7 +55,7 @@ const StyledButton = styled(Button)`
55
55
  `;
56
56
 
57
57
  const StyledWrapper = styled.div`
58
- height: 1200px;
58
+ height: 600px;
59
59
  `;
60
60
 
61
61
  const OtherContent = styled.div`
@@ -80,7 +80,7 @@ const StyledButton = styled(Button)`
80
80
  `;
81
81
 
82
82
  const StyledWrapper = styled.div`
83
- height: 1200px;
83
+ height: 300px;
84
84
  `;
85
85
 
86
86
  const Content = styled.div`
@@ -55,7 +55,7 @@ const StyledButton = styled(Button)`
55
55
  `;
56
56
 
57
57
  const StyledWrapper = styled.div`
58
- height: 1200px;
58
+ height: 600px;
59
59
  `;
60
60
 
61
61
  const OtherContent = styled.div`
@@ -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, useEffect, useRef, useState } from 'react';
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 (placement) {
43
- switch (placement) {
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
- * Базовый копмонент Popup.
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
- return /*#__PURE__*/React.createElement(React.Fragment, null, portalRef.current && /*#__PURE__*/React.createElement(Portal, {
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 PopupView = /*#__PURE__*/styled.div.withConfig({
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-2"
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;