@gingkoo/pandora-metabase 1.0.150 → 1.0.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,5 +12,5 @@ interface SqbRightClickMenuProps {
12
12
  state?: RightClickMenuState | null;
13
13
  setState?: (state: RightClickMenuState | null) => void;
14
14
  }
15
- declare const SqbRightClickMenu: ({ popupZIndex, state, setState }: SqbRightClickMenuProps) => React.JSX.Element | null;
15
+ declare const SqbRightClickMenu: ({ popupZIndex, state, setState }: SqbRightClickMenuProps) => React.ReactPortal | null;
16
16
  export default SqbRightClickMenu;
@@ -7,12 +7,15 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.openSqbRightClickMenu = exports["default"] = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/asyncToGenerator"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
10
11
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/typeof"));
11
12
  var _jsxRuntime = require("react/jsx-runtime");
12
13
  var _react = require("react");
14
+ var _reactDom = _interopRequireDefault(require("react-dom"));
13
15
  var _classnames = _interopRequireDefault(require("classnames"));
14
16
  var _utils = require("../utils");
15
17
  var _useProvider = require("../hooks/use-provider");
18
+ var MENU_VIEWPORT_GAP = 8;
16
19
  var findRightClickTarget = function findRightClickTarget(target) {
17
20
  var element = target instanceof HTMLElement ? target : null;
18
21
  while (element) {
@@ -89,6 +92,18 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
89
92
  rightClickMenu = _store$rightClickMenu === void 0 ? [] : _store$rightClickMenu;
90
93
  var rightClickMenuState = state === undefined ? store.rightClickMenuState : state;
91
94
  var setRightClickMenuState = setState || store.setRightClickMenuState;
95
+ var menuRef = (0, _react.useRef)(null);
96
+ var _useState = (0, _react.useState)(null),
97
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
98
+ menuContainer = _useState2[0],
99
+ setMenuContainer = _useState2[1];
100
+ var _useState3 = (0, _react.useState)({
101
+ left: 0,
102
+ top: 0
103
+ }),
104
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
105
+ menuPosition = _useState4[0],
106
+ setMenuPosition = _useState4[1];
92
107
  var handleRightClickMenuItem = function () {
93
108
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(menuItem) {
94
109
  var _store$getRightClickM2;
@@ -147,12 +162,40 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
147
162
  window.removeEventListener('resize', closeRightClickMenu);
148
163
  };
149
164
  }, [rightClickMenuState]);
165
+ (0, _react.useEffect)(function () {
166
+ if (!rightClickMenuState || typeof document === 'undefined') {
167
+ setMenuContainer(null);
168
+ return;
169
+ }
170
+ var container = document.createElement('div');
171
+ container.setAttribute('data-sqb-right-click-menu-container', 'true');
172
+ document.body.appendChild(container);
173
+ setMenuContainer(container);
174
+ return function () {
175
+ if (document.body.contains(container)) {
176
+ document.body.removeChild(container);
177
+ }
178
+ };
179
+ }, [rightClickMenuState]);
180
+ (0, _react.useLayoutEffect)(function () {
181
+ if (!rightClickMenuState) return;
182
+ var menuElement = menuRef.current;
183
+ var menuWidth = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetWidth) || 0;
184
+ var menuHeight = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetHeight) || 0;
185
+ var maxLeft = Math.max(MENU_VIEWPORT_GAP, window.innerWidth - menuWidth - MENU_VIEWPORT_GAP);
186
+ var maxTop = Math.max(MENU_VIEWPORT_GAP, window.innerHeight - menuHeight - MENU_VIEWPORT_GAP);
187
+ setMenuPosition({
188
+ left: Math.min(Math.max(rightClickMenuState.x, MENU_VIEWPORT_GAP), maxLeft),
189
+ top: Math.min(Math.max(rightClickMenuState.y, MENU_VIEWPORT_GAP), maxTop)
190
+ });
191
+ }, [rightClickMenuState, rightClickMenu.length, menuContainer]);
150
192
  if (!rightClickMenuState) return null;
151
- return (0, _jsxRuntime.jsx)("div", {
193
+ var menuNode = (0, _jsxRuntime.jsx)("div", {
194
+ ref: menuRef,
152
195
  className: 'Sqb-right-click-menu',
153
196
  style: {
154
- left: rightClickMenuState.x,
155
- top: rightClickMenuState.y,
197
+ left: menuPosition.left,
198
+ top: menuPosition.top,
156
199
  zIndex: popupZIndex ? popupZIndex + 10 : 9999
157
200
  },
158
201
  onClick: function onClick(event) {
@@ -175,5 +218,7 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
175
218
  }, menuItem.value);
176
219
  })
177
220
  });
221
+ if (!menuContainer) return null;
222
+ return _reactDom["default"].createPortal(menuNode, menuContainer);
178
223
  };
179
224
  var _default = exports["default"] = SqbRightClickMenu;
@@ -12,5 +12,5 @@ interface SqbRightClickMenuProps {
12
12
  state?: RightClickMenuState | null;
13
13
  setState?: (state: RightClickMenuState | null) => void;
14
14
  }
15
- declare const SqbRightClickMenu: ({ popupZIndex, state, setState }: SqbRightClickMenuProps) => React.JSX.Element | null;
15
+ declare const SqbRightClickMenu: ({ popupZIndex, state, setState }: SqbRightClickMenuProps) => React.ReactPortal | null;
16
16
  export default SqbRightClickMenu;
@@ -1,11 +1,14 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _typeof from "@babel/runtime/helpers/esm/typeof";
3
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
- import { useEffect } from 'react';
6
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
7
+ import ReactDOM from 'react-dom';
6
8
  import cx from 'classnames';
7
9
  import { normalizeLegacySummarizeForSave, splitByUnion } from '../utils';
8
10
  import { useStore } from '../hooks/use-provider';
11
+ var MENU_VIEWPORT_GAP = 8;
9
12
  var findRightClickTarget = function findRightClickTarget(target) {
10
13
  var element = target instanceof HTMLElement ? target : null;
11
14
  while (element) {
@@ -82,6 +85,18 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
82
85
  rightClickMenu = _store$rightClickMenu === void 0 ? [] : _store$rightClickMenu;
83
86
  var rightClickMenuState = state === undefined ? store.rightClickMenuState : state;
84
87
  var setRightClickMenuState = setState || store.setRightClickMenuState;
88
+ var menuRef = useRef(null);
89
+ var _useState = useState(null),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ menuContainer = _useState2[0],
92
+ setMenuContainer = _useState2[1];
93
+ var _useState3 = useState({
94
+ left: 0,
95
+ top: 0
96
+ }),
97
+ _useState4 = _slicedToArray(_useState3, 2),
98
+ menuPosition = _useState4[0],
99
+ setMenuPosition = _useState4[1];
85
100
  var handleRightClickMenuItem = function () {
86
101
  var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(menuItem) {
87
102
  var _store$getRightClickM2;
@@ -140,12 +155,40 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
140
155
  window.removeEventListener('resize', closeRightClickMenu);
141
156
  };
142
157
  }, [rightClickMenuState]);
158
+ useEffect(function () {
159
+ if (!rightClickMenuState || typeof document === 'undefined') {
160
+ setMenuContainer(null);
161
+ return;
162
+ }
163
+ var container = document.createElement('div');
164
+ container.setAttribute('data-sqb-right-click-menu-container', 'true');
165
+ document.body.appendChild(container);
166
+ setMenuContainer(container);
167
+ return function () {
168
+ if (document.body.contains(container)) {
169
+ document.body.removeChild(container);
170
+ }
171
+ };
172
+ }, [rightClickMenuState]);
173
+ useLayoutEffect(function () {
174
+ if (!rightClickMenuState) return;
175
+ var menuElement = menuRef.current;
176
+ var menuWidth = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetWidth) || 0;
177
+ var menuHeight = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetHeight) || 0;
178
+ var maxLeft = Math.max(MENU_VIEWPORT_GAP, window.innerWidth - menuWidth - MENU_VIEWPORT_GAP);
179
+ var maxTop = Math.max(MENU_VIEWPORT_GAP, window.innerHeight - menuHeight - MENU_VIEWPORT_GAP);
180
+ setMenuPosition({
181
+ left: Math.min(Math.max(rightClickMenuState.x, MENU_VIEWPORT_GAP), maxLeft),
182
+ top: Math.min(Math.max(rightClickMenuState.y, MENU_VIEWPORT_GAP), maxTop)
183
+ });
184
+ }, [rightClickMenuState, rightClickMenu.length, menuContainer]);
143
185
  if (!rightClickMenuState) return null;
144
- return _jsx("div", {
186
+ var menuNode = _jsx("div", {
187
+ ref: menuRef,
145
188
  className: 'Sqb-right-click-menu',
146
189
  style: {
147
- left: rightClickMenuState.x,
148
- top: rightClickMenuState.y,
190
+ left: menuPosition.left,
191
+ top: menuPosition.top,
149
192
  zIndex: popupZIndex ? popupZIndex + 10 : 9999
150
193
  },
151
194
  onClick: function onClick(event) {
@@ -168,5 +211,7 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
168
211
  }, menuItem.value);
169
212
  })
170
213
  });
214
+ if (!menuContainer) return null;
215
+ return ReactDOM.createPortal(menuNode, menuContainer);
171
216
  };
172
217
  export default SqbRightClickMenu;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.150",
3
+ "version": "1.0.151",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",