@gingkoo/pandora-metabase 1.0.154 → 1.0.155-alpha.1

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.
@@ -5,6 +5,7 @@ export type RightClickMenuState = {
5
5
  item: any;
6
6
  itemText: string;
7
7
  target: HTMLElement;
8
+ ownerDocument?: Document;
8
9
  };
9
10
  export declare const openSqbRightClickMenu: (store: any, event: React.MouseEvent<HTMLElement>, setMenuState?: (state: RightClickMenuState | null) => void) => void;
10
11
  interface SqbRightClickMenuProps {
@@ -16,8 +16,17 @@ var _classnames = _interopRequireDefault(require("classnames"));
16
16
  var _utils = require("../utils");
17
17
  var _useProvider = require("../hooks/use-provider");
18
18
  var MENU_VIEWPORT_GAP = 8;
19
+ var isHTMLElement = function isHTMLElement(target) {
20
+ var _target$ownerDocument;
21
+ if (!target) return false;
22
+ var ownerWindow = (_target$ownerDocument = target.ownerDocument) === null || _target$ownerDocument === void 0 ? void 0 : _target$ownerDocument.defaultView;
23
+ if (ownerWindow !== null && ownerWindow !== void 0 && ownerWindow.HTMLElement) {
24
+ return target instanceof ownerWindow.HTMLElement;
25
+ }
26
+ return typeof HTMLElement !== 'undefined' && target instanceof HTMLElement;
27
+ };
19
28
  var findRightClickTarget = function findRightClickTarget(target) {
20
- var element = target instanceof HTMLElement ? target : null;
29
+ var element = isHTMLElement(target) ? target : null;
21
30
  while (element) {
22
31
  var _element$classList, _element$classList2, _element$classList3;
23
32
  if ((_element$classList = element.classList) !== null && _element$classList !== void 0 && _element$classList.contains('Sqb-TableName') || (_element$classList2 = element.classList) !== null && _element$classList2 !== void 0 && _element$classList2.contains(':Sqb-TableName') && !((_element$classList3 = element.classList) !== null && _element$classList3 !== void 0 && _element$classList3.contains('operator-trigger'))) {
@@ -80,7 +89,8 @@ var openSqbRightClickMenu = exports.openSqbRightClickMenu = function openSqbRigh
80
89
  y: event.clientY,
81
90
  item: item,
82
91
  itemText: itemText,
83
- target: target
92
+ target: target,
93
+ ownerDocument: target.ownerDocument
84
94
  });
85
95
  };
86
96
  var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
@@ -104,6 +114,8 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
104
114
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
105
115
  menuPosition = _useState4[0],
106
116
  setMenuPosition = _useState4[1];
117
+ var menuDocument = (rightClickMenuState === null || rightClickMenuState === void 0 ? void 0 : rightClickMenuState.ownerDocument) || (typeof document === 'undefined' ? undefined : document);
118
+ var menuWindow = (menuDocument === null || menuDocument === void 0 ? void 0 : menuDocument.defaultView) || (typeof window === 'undefined' ? undefined : window);
107
119
  var handleRightClickMenuItem = function () {
108
120
  var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(menuItem) {
109
121
  var _store$getRightClickM2;
@@ -149,51 +161,52 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
149
161
  };
150
162
  }();
151
163
  (0, _react.useEffect)(function () {
152
- if (!rightClickMenuState) return;
164
+ if (!rightClickMenuState || !menuDocument || !menuWindow) return;
153
165
  var closeRightClickMenu = function closeRightClickMenu() {
154
166
  return setRightClickMenuState(null);
155
167
  };
156
- window.addEventListener('click', closeRightClickMenu);
157
- window.addEventListener('scroll', closeRightClickMenu, true);
158
- window.addEventListener('resize', closeRightClickMenu);
168
+ menuDocument.addEventListener('click', closeRightClickMenu);
169
+ menuWindow.addEventListener('scroll', closeRightClickMenu, true);
170
+ menuWindow.addEventListener('resize', closeRightClickMenu);
159
171
  return function () {
160
- window.removeEventListener('click', closeRightClickMenu);
161
- window.removeEventListener('scroll', closeRightClickMenu, true);
162
- window.removeEventListener('resize', closeRightClickMenu);
172
+ menuDocument.removeEventListener('click', closeRightClickMenu);
173
+ menuWindow.removeEventListener('scroll', closeRightClickMenu, true);
174
+ menuWindow.removeEventListener('resize', closeRightClickMenu);
163
175
  };
164
- }, [rightClickMenuState]);
176
+ }, [rightClickMenuState, menuDocument, menuWindow]);
165
177
  (0, _react.useEffect)(function () {
166
- if (!rightClickMenuState || typeof document === 'undefined') {
178
+ if (!rightClickMenuState || !(menuDocument !== null && menuDocument !== void 0 && menuDocument.body)) {
167
179
  setMenuContainer(null);
168
180
  return;
169
181
  }
170
- var container = document.createElement('div');
182
+ var container = menuDocument.createElement('div');
171
183
  container.setAttribute('data-sqb-right-click-menu-container', 'true');
172
- document.body.appendChild(container);
184
+ menuDocument.body.appendChild(container);
173
185
  setMenuContainer(container);
174
186
  return function () {
175
- if (document.body.contains(container)) {
176
- document.body.removeChild(container);
187
+ if (menuDocument.body.contains(container)) {
188
+ menuDocument.body.removeChild(container);
177
189
  }
178
190
  };
179
- }, [rightClickMenuState]);
191
+ }, [rightClickMenuState, menuDocument]);
180
192
  (0, _react.useLayoutEffect)(function () {
181
- if (!rightClickMenuState) return;
193
+ if (!rightClickMenuState || !menuWindow) return;
182
194
  var menuElement = menuRef.current;
183
195
  var menuWidth = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetWidth) || 0;
184
196
  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);
197
+ var maxLeft = Math.max(MENU_VIEWPORT_GAP, menuWindow.innerWidth - menuWidth - MENU_VIEWPORT_GAP);
198
+ var maxTop = Math.max(MENU_VIEWPORT_GAP, menuWindow.innerHeight - menuHeight - MENU_VIEWPORT_GAP);
187
199
  setMenuPosition({
188
200
  left: Math.min(Math.max(rightClickMenuState.x, MENU_VIEWPORT_GAP), maxLeft),
189
201
  top: Math.min(Math.max(rightClickMenuState.y, MENU_VIEWPORT_GAP), maxTop)
190
202
  });
191
- }, [rightClickMenuState, rightClickMenu.length, menuContainer]);
203
+ }, [rightClickMenuState, rightClickMenu.length, menuContainer, menuWindow]);
192
204
  if (!rightClickMenuState) return null;
193
205
  var menuNode = (0, _jsxRuntime.jsx)("div", {
194
206
  ref: menuRef,
195
207
  className: 'Sqb-right-click-menu',
196
208
  style: {
209
+ position: 'fixed',
197
210
  left: menuPosition.left,
198
211
  top: menuPosition.top,
199
212
  zIndex: popupZIndex ? popupZIndex + 10 : 9999
@@ -5,6 +5,7 @@ export type RightClickMenuState = {
5
5
  item: any;
6
6
  itemText: string;
7
7
  target: HTMLElement;
8
+ ownerDocument?: Document;
8
9
  };
9
10
  export declare const openSqbRightClickMenu: (store: any, event: React.MouseEvent<HTMLElement>, setMenuState?: (state: RightClickMenuState | null) => void) => void;
10
11
  interface SqbRightClickMenuProps {
@@ -9,8 +9,17 @@ import cx from 'classnames';
9
9
  import { normalizeLegacySummarizeForSave, splitByUnion } from '../utils';
10
10
  import { useStore } from '../hooks/use-provider';
11
11
  var MENU_VIEWPORT_GAP = 8;
12
+ var isHTMLElement = function isHTMLElement(target) {
13
+ var _target$ownerDocument;
14
+ if (!target) return false;
15
+ var ownerWindow = (_target$ownerDocument = target.ownerDocument) === null || _target$ownerDocument === void 0 ? void 0 : _target$ownerDocument.defaultView;
16
+ if (ownerWindow !== null && ownerWindow !== void 0 && ownerWindow.HTMLElement) {
17
+ return target instanceof ownerWindow.HTMLElement;
18
+ }
19
+ return typeof HTMLElement !== 'undefined' && target instanceof HTMLElement;
20
+ };
12
21
  var findRightClickTarget = function findRightClickTarget(target) {
13
- var element = target instanceof HTMLElement ? target : null;
22
+ var element = isHTMLElement(target) ? target : null;
14
23
  while (element) {
15
24
  var _element$classList, _element$classList2, _element$classList3;
16
25
  if ((_element$classList = element.classList) !== null && _element$classList !== void 0 && _element$classList.contains('Sqb-TableName') || (_element$classList2 = element.classList) !== null && _element$classList2 !== void 0 && _element$classList2.contains(':Sqb-TableName') && !((_element$classList3 = element.classList) !== null && _element$classList3 !== void 0 && _element$classList3.contains('operator-trigger'))) {
@@ -73,7 +82,8 @@ export var openSqbRightClickMenu = function openSqbRightClickMenu(store, event,
73
82
  y: event.clientY,
74
83
  item: item,
75
84
  itemText: itemText,
76
- target: target
85
+ target: target,
86
+ ownerDocument: target.ownerDocument
77
87
  });
78
88
  };
79
89
  var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
@@ -97,6 +107,8 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
97
107
  _useState4 = _slicedToArray(_useState3, 2),
98
108
  menuPosition = _useState4[0],
99
109
  setMenuPosition = _useState4[1];
110
+ var menuDocument = (rightClickMenuState === null || rightClickMenuState === void 0 ? void 0 : rightClickMenuState.ownerDocument) || (typeof document === 'undefined' ? undefined : document);
111
+ var menuWindow = (menuDocument === null || menuDocument === void 0 ? void 0 : menuDocument.defaultView) || (typeof window === 'undefined' ? undefined : window);
100
112
  var handleRightClickMenuItem = function () {
101
113
  var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(menuItem) {
102
114
  var _store$getRightClickM2;
@@ -142,51 +154,52 @@ var SqbRightClickMenu = function SqbRightClickMenu(_ref) {
142
154
  };
143
155
  }();
144
156
  useEffect(function () {
145
- if (!rightClickMenuState) return;
157
+ if (!rightClickMenuState || !menuDocument || !menuWindow) return;
146
158
  var closeRightClickMenu = function closeRightClickMenu() {
147
159
  return setRightClickMenuState(null);
148
160
  };
149
- window.addEventListener('click', closeRightClickMenu);
150
- window.addEventListener('scroll', closeRightClickMenu, true);
151
- window.addEventListener('resize', closeRightClickMenu);
161
+ menuDocument.addEventListener('click', closeRightClickMenu);
162
+ menuWindow.addEventListener('scroll', closeRightClickMenu, true);
163
+ menuWindow.addEventListener('resize', closeRightClickMenu);
152
164
  return function () {
153
- window.removeEventListener('click', closeRightClickMenu);
154
- window.removeEventListener('scroll', closeRightClickMenu, true);
155
- window.removeEventListener('resize', closeRightClickMenu);
165
+ menuDocument.removeEventListener('click', closeRightClickMenu);
166
+ menuWindow.removeEventListener('scroll', closeRightClickMenu, true);
167
+ menuWindow.removeEventListener('resize', closeRightClickMenu);
156
168
  };
157
- }, [rightClickMenuState]);
169
+ }, [rightClickMenuState, menuDocument, menuWindow]);
158
170
  useEffect(function () {
159
- if (!rightClickMenuState || typeof document === 'undefined') {
171
+ if (!rightClickMenuState || !(menuDocument !== null && menuDocument !== void 0 && menuDocument.body)) {
160
172
  setMenuContainer(null);
161
173
  return;
162
174
  }
163
- var container = document.createElement('div');
175
+ var container = menuDocument.createElement('div');
164
176
  container.setAttribute('data-sqb-right-click-menu-container', 'true');
165
- document.body.appendChild(container);
177
+ menuDocument.body.appendChild(container);
166
178
  setMenuContainer(container);
167
179
  return function () {
168
- if (document.body.contains(container)) {
169
- document.body.removeChild(container);
180
+ if (menuDocument.body.contains(container)) {
181
+ menuDocument.body.removeChild(container);
170
182
  }
171
183
  };
172
- }, [rightClickMenuState]);
184
+ }, [rightClickMenuState, menuDocument]);
173
185
  useLayoutEffect(function () {
174
- if (!rightClickMenuState) return;
186
+ if (!rightClickMenuState || !menuWindow) return;
175
187
  var menuElement = menuRef.current;
176
188
  var menuWidth = (menuElement === null || menuElement === void 0 ? void 0 : menuElement.offsetWidth) || 0;
177
189
  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);
190
+ var maxLeft = Math.max(MENU_VIEWPORT_GAP, menuWindow.innerWidth - menuWidth - MENU_VIEWPORT_GAP);
191
+ var maxTop = Math.max(MENU_VIEWPORT_GAP, menuWindow.innerHeight - menuHeight - MENU_VIEWPORT_GAP);
180
192
  setMenuPosition({
181
193
  left: Math.min(Math.max(rightClickMenuState.x, MENU_VIEWPORT_GAP), maxLeft),
182
194
  top: Math.min(Math.max(rightClickMenuState.y, MENU_VIEWPORT_GAP), maxTop)
183
195
  });
184
- }, [rightClickMenuState, rightClickMenu.length, menuContainer]);
196
+ }, [rightClickMenuState, rightClickMenu.length, menuContainer, menuWindow]);
185
197
  if (!rightClickMenuState) return null;
186
198
  var menuNode = _jsx("div", {
187
199
  ref: menuRef,
188
200
  className: 'Sqb-right-click-menu',
189
201
  style: {
202
+ position: 'fixed',
190
203
  left: menuPosition.left,
191
204
  top: menuPosition.top,
192
205
  zIndex: popupZIndex ? popupZIndex + 10 : 9999
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.154",
3
+ "version": "1.0.155-alpha.1",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",