@gingkoo/pandora-metabase 1.0.62 → 1.0.63
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.
- package/lib/cjs/components/metabase/index.js +8 -4
- package/lib/cjs/components/popup.d.ts +40 -102
- package/lib/cjs/components/popup.js +219 -190
- package/lib/es/components/metabase/index.js +8 -4
- package/lib/es/components/popup.d.ts +40 -102
- package/lib/es/components/popup.js +220 -191
- package/package.json +1 -1
|
@@ -157,8 +157,10 @@ var Metabase = function Metabase(props) {
|
|
|
157
157
|
disabled: saveLoading,
|
|
158
158
|
onClick: onCheck,
|
|
159
159
|
children: btnText || (0, _locale.__)('SqlQueryBuilder.visualize')
|
|
160
|
-
}) : null, store.popupContainer.current && (0, _jsxRuntime.jsx)(_popup["default"]
|
|
161
|
-
|
|
160
|
+
}) : null, store.popupContainer.current && (0, _jsxRuntime.jsx)(_popup["default"]
|
|
161
|
+
// container={store.popupData.container || store.popupContainer.current}
|
|
162
|
+
, {
|
|
163
|
+
// container={store.popupData.container || store.popupContainer.current}
|
|
162
164
|
visible: store.popupData.visible,
|
|
163
165
|
node: store.popupData.node,
|
|
164
166
|
closable: store.popupClosable,
|
|
@@ -168,8 +170,10 @@ var Metabase = function Metabase(props) {
|
|
|
168
170
|
});
|
|
169
171
|
},
|
|
170
172
|
children: popupContent
|
|
171
|
-
}), store.popupContainer.current && (0, _jsxRuntime.jsx)(_popup["default"]
|
|
172
|
-
|
|
173
|
+
}), store.popupContainer.current && (0, _jsxRuntime.jsx)(_popup["default"]
|
|
174
|
+
// container={store.popupData2.container || store.popupContainer.current}
|
|
175
|
+
, {
|
|
176
|
+
// container={store.popupData2.container || store.popupContainer.current}
|
|
173
177
|
visible: store.popupData2.visible,
|
|
174
178
|
node: store.popupData2.node,
|
|
175
179
|
closable: store.popupClosable2,
|
|
@@ -1,109 +1,47 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
interface PropsType {
|
|
3
|
+
visible: boolean;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
hideVisible: () => void;
|
|
6
|
+
node: HTMLElement;
|
|
7
|
+
innerSpacing?: number;
|
|
8
|
+
zIndex?: string | number;
|
|
9
|
+
closable?: boolean;
|
|
10
|
+
}
|
|
2
11
|
interface StateType {
|
|
3
12
|
popupRefreshKey: number;
|
|
4
13
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
initResizeObserver: () => void;
|
|
15
|
-
bindEvent: () => void;
|
|
16
|
-
closePopup: () => void;
|
|
17
|
-
attachParent: (popupContainer: HTMLSpanElement) => void;
|
|
18
|
-
getCurrentNodePos: () => {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
t: number;
|
|
22
|
-
h: any;
|
|
23
|
-
};
|
|
24
|
-
getContainer: () => HTMLSpanElement;
|
|
25
|
-
getComponent: () => import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
didUpdate: () => void | false;
|
|
27
|
-
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
28
|
-
context: unknown;
|
|
29
|
-
setState<K extends "popupRefreshKey">(state: StateType | ((prevState: Readonly<StateType>, props: Readonly<PropsType>) => StateType | Pick<StateType, K> | null) | Pick<StateType, K> | null, callback?: (() => void) | undefined): void;
|
|
30
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
31
|
-
readonly props: Readonly<PropsType>;
|
|
32
|
-
state: Readonly<StateType>;
|
|
33
|
-
refs: {
|
|
34
|
-
[key: string]: React.ReactInstance;
|
|
35
|
-
};
|
|
36
|
-
shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): boolean;
|
|
37
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
38
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<StateType>): any;
|
|
39
|
-
componentWillMount?(): void;
|
|
40
|
-
UNSAFE_componentWillMount?(): void;
|
|
41
|
-
componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
42
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
43
|
-
componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
44
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
45
|
-
};
|
|
46
|
-
defaultProps: {
|
|
14
|
+
declare class TriggerInternal extends React.Component<PropsType, StateType> {
|
|
15
|
+
private resizeObserver;
|
|
16
|
+
private resetId;
|
|
17
|
+
private popupContainer;
|
|
18
|
+
private contentResizeObserver;
|
|
19
|
+
private scrollHeightCheckTimer;
|
|
20
|
+
private lastScrollHeight;
|
|
21
|
+
private handleClickOutside;
|
|
22
|
+
static defaultProps: {
|
|
47
23
|
visible: boolean;
|
|
48
|
-
|
|
24
|
+
closable: boolean;
|
|
25
|
+
innerSpacing: number;
|
|
49
26
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
y: number;
|
|
68
|
-
t: number;
|
|
69
|
-
h: any;
|
|
70
|
-
};
|
|
71
|
-
getContainer: () => HTMLSpanElement;
|
|
72
|
-
getComponent: () => import("react/jsx-runtime").JSX.Element;
|
|
73
|
-
didUpdate: () => void | false;
|
|
74
|
-
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
75
|
-
context: unknown;
|
|
76
|
-
setState<K extends "popupRefreshKey">(state: StateType | ((prevState: Readonly<StateType>, props: Readonly<PropsType>) => StateType | Pick<StateType, K> | null) | Pick<StateType, K> | null, callback?: (() => void) | undefined): void;
|
|
77
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
78
|
-
readonly props: Readonly<PropsType>;
|
|
79
|
-
state: Readonly<StateType>;
|
|
80
|
-
refs: {
|
|
81
|
-
[key: string]: React.ReactInstance;
|
|
82
|
-
};
|
|
83
|
-
shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): boolean;
|
|
84
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
85
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<StateType>): any;
|
|
86
|
-
componentWillMount?(): void;
|
|
87
|
-
UNSAFE_componentWillMount?(): void;
|
|
88
|
-
componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
89
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
90
|
-
componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
91
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
92
|
-
};
|
|
93
|
-
defaultProps: {
|
|
94
|
-
visible: boolean;
|
|
95
|
-
children: null;
|
|
96
|
-
};
|
|
97
|
-
contextType?: React.Context<any> | undefined;
|
|
98
|
-
};
|
|
99
|
-
export default _default;
|
|
100
|
-
interface PropsType {
|
|
101
|
-
visible: boolean;
|
|
102
|
-
children: any;
|
|
103
|
-
hideVisible: Function;
|
|
104
|
-
node: any;
|
|
105
|
-
innerSpacing?: number;
|
|
106
|
-
container?: HTMLDivElement;
|
|
107
|
-
zIndex?: string | null;
|
|
108
|
-
closable?: boolean;
|
|
27
|
+
ref: React.RefObject<HTMLDivElement>;
|
|
28
|
+
constructor(props: PropsType);
|
|
29
|
+
componentDidMount(): void;
|
|
30
|
+
componentDidUpdate(prevProps: PropsType): void;
|
|
31
|
+
componentWillUnmount(): void;
|
|
32
|
+
private mountPopup;
|
|
33
|
+
private unmountPopup;
|
|
34
|
+
private cleanup;
|
|
35
|
+
private refreshPopup;
|
|
36
|
+
private initContentResizeObserver;
|
|
37
|
+
private startScrollHeightCheck;
|
|
38
|
+
private closePopup;
|
|
39
|
+
private createPopupContainer;
|
|
40
|
+
private getContainer;
|
|
41
|
+
private getComponent;
|
|
42
|
+
private didUpdate;
|
|
43
|
+
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
109
44
|
}
|
|
45
|
+
export declare function generateTrigger(PortalComponent: any): typeof TriggerInternal;
|
|
46
|
+
declare const _default: typeof TriggerInternal;
|
|
47
|
+
export default _default;
|
|
@@ -21,207 +21,236 @@ var _event = require("../utils/event");
|
|
|
21
21
|
var _Portal = _interopRequireDefault(require("../common/Portal"));
|
|
22
22
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
23
23
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, (0, _isNativeReflectConstruct2["default"])() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
24
|
-
function returnDocument(element) {
|
|
25
|
-
if (element) {
|
|
26
|
-
return element.ownerDocument;
|
|
27
|
-
}
|
|
28
|
-
return window.document;
|
|
29
|
-
}
|
|
30
24
|
var outSpacing = 10;
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
25
|
+
var TriggerInternal = /*#__PURE__*/function (_React$Component) {
|
|
26
|
+
function TriggerInternal(props) {
|
|
27
|
+
var _this;
|
|
28
|
+
(0, _classCallCheck2["default"])(this, TriggerInternal);
|
|
29
|
+
_this = _callSuper(this, TriggerInternal, [props]);
|
|
30
|
+
(0, _defineProperty2["default"])(_this, "resizeObserver", null);
|
|
31
|
+
(0, _defineProperty2["default"])(_this, "resetId", -1);
|
|
32
|
+
(0, _defineProperty2["default"])(_this, "popupContainer", null);
|
|
33
|
+
(0, _defineProperty2["default"])(_this, "contentResizeObserver", null);
|
|
34
|
+
(0, _defineProperty2["default"])(_this, "scrollHeightCheckTimer", null);
|
|
35
|
+
(0, _defineProperty2["default"])(_this, "lastScrollHeight", 0);
|
|
36
|
+
(0, _defineProperty2["default"])(_this, "handleClickOutside", function (e) {
|
|
37
|
+
var ele = e.target;
|
|
38
|
+
while (ele) {
|
|
39
|
+
if (ele === _this.props.node) return;
|
|
40
|
+
if (_this.popupContainer && ele === _this.popupContainer) return;
|
|
41
|
+
ele = ele.parentNode;
|
|
42
|
+
}
|
|
43
|
+
_this.closePopup();
|
|
44
|
+
});
|
|
45
|
+
(0, _defineProperty2["default"])(_this, "ref", React.createRef());
|
|
46
|
+
(0, _defineProperty2["default"])(_this, "mountPopup", function () {
|
|
47
|
+
_this.createPopupContainer();
|
|
48
|
+
_this.resetId = _event.winResetEvent.addEvent(_this.didUpdate, _this, 300);
|
|
49
|
+
window.addEventListener('scroll', _this.didUpdate, true);
|
|
50
|
+
document.body.addEventListener('click', _this.handleClickOutside, false);
|
|
51
|
+
_this.initContentResizeObserver();
|
|
52
|
+
_this.startScrollHeightCheck();
|
|
53
|
+
setTimeout(function () {
|
|
54
|
+
_this.didUpdate();
|
|
55
|
+
if (_this.popupContainer) {
|
|
56
|
+
_this.popupContainer.style.opacity = '1';
|
|
57
|
+
_this.popupContainer.style.willChange = 'transform';
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
}, 0);
|
|
60
|
+
setTimeout(function () {
|
|
61
|
+
_this.didUpdate();
|
|
62
|
+
}, 100);
|
|
63
|
+
});
|
|
64
|
+
(0, _defineProperty2["default"])(_this, "unmountPopup", function () {
|
|
65
|
+
if (_this.popupContainer) {
|
|
66
|
+
_this.popupContainer.style.opacity = '0';
|
|
67
|
+
}
|
|
68
|
+
_this.cleanup();
|
|
69
|
+
});
|
|
70
|
+
(0, _defineProperty2["default"])(_this, "cleanup", function () {
|
|
71
|
+
_event.winResetEvent.removeEvent(_this.resetId);
|
|
72
|
+
window.removeEventListener('scroll', _this.didUpdate, true);
|
|
73
|
+
document.body.removeEventListener('click', _this.handleClickOutside, false);
|
|
74
|
+
if (_this.resizeObserver) {
|
|
75
|
+
_this.resizeObserver.disconnect();
|
|
76
|
+
_this.resizeObserver = null;
|
|
77
|
+
}
|
|
78
|
+
if (_this.contentResizeObserver) {
|
|
79
|
+
_this.contentResizeObserver.disconnect();
|
|
80
|
+
_this.contentResizeObserver = null;
|
|
81
|
+
}
|
|
82
|
+
if (_this.scrollHeightCheckTimer) {
|
|
83
|
+
clearInterval(_this.scrollHeightCheckTimer);
|
|
84
|
+
_this.scrollHeightCheckTimer = null;
|
|
85
|
+
}
|
|
86
|
+
if (_this.popupContainer && document.body.contains(_this.popupContainer)) {
|
|
87
|
+
document.body.removeChild(_this.popupContainer);
|
|
88
|
+
_this.popupContainer = null;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
(0, _defineProperty2["default"])(_this, "refreshPopup", function () {
|
|
92
|
+
_this.setState(function (prev) {
|
|
89
93
|
return {
|
|
90
|
-
|
|
91
|
-
y: (0, _helperDom.getElementTop)(node) - (0, _helperDom.getElementTop)(container),
|
|
92
|
-
t: (0, _helperDom.getElementTop)(container),
|
|
93
|
-
h: node.offsetHeight
|
|
94
|
+
popupRefreshKey: prev.popupRefreshKey + 1
|
|
94
95
|
};
|
|
95
96
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
popupContainer.style.left = '0px';
|
|
106
|
-
popupContainer.style.transform = "translateX(".concat(pos.x, "px) translateY(").concat(pos.y + pos.h + innerSpacing, "px) translateZ(0px)");
|
|
107
|
-
popupContainer.style.pointerEvents = 'none';
|
|
108
|
-
popupContainer.style.zIndex = zIndex || '999';
|
|
109
|
-
_this.attachParent(popupContainer);
|
|
110
|
-
return popupContainer;
|
|
97
|
+
});
|
|
98
|
+
(0, _defineProperty2["default"])(_this, "initContentResizeObserver", function () {
|
|
99
|
+
var targetNode = _this.ref.current;
|
|
100
|
+
if (!targetNode) return;
|
|
101
|
+
if (_this.contentResizeObserver) {
|
|
102
|
+
_this.contentResizeObserver.disconnect();
|
|
103
|
+
}
|
|
104
|
+
_this.contentResizeObserver = new ResizeObserver(function () {
|
|
105
|
+
_this.didUpdate();
|
|
111
106
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
transition: 'all 0.3s',
|
|
121
|
-
boxShadow: '0 4px 10px rgba(0,0,0,0.13)',
|
|
122
|
-
borderRadius: 6
|
|
123
|
-
},
|
|
124
|
-
onClick: function onClick(e) {
|
|
125
|
-
return _this.props.closable && e.stopPropagation();
|
|
126
|
-
},
|
|
127
|
-
onMouseDown: function onMouseDown(e) {
|
|
128
|
-
return e.stopPropagation();
|
|
129
|
-
},
|
|
130
|
-
children: React.cloneElement(_this.props.children, {
|
|
131
|
-
key: _this.state.popupRefreshKey,
|
|
132
|
-
didUpdate: _this.didUpdate
|
|
133
|
-
})
|
|
134
|
-
});
|
|
107
|
+
_this.contentResizeObserver.observe(targetNode);
|
|
108
|
+
// 额外监听图片加载
|
|
109
|
+
var images = targetNode.querySelectorAll('img');
|
|
110
|
+
images.forEach(function (img) {
|
|
111
|
+
if (!img.complete) {
|
|
112
|
+
img.addEventListener('load', _this.didUpdate);
|
|
113
|
+
img.addEventListener('error', _this.didUpdate);
|
|
114
|
+
}
|
|
135
115
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var _getWindowSize = (0, _helperDom.getWindowSize)(),
|
|
149
|
-
winH = _getWindowSize.height;
|
|
150
|
-
var containerH = (0, _helperDom.getContainerVisibleHeight)(container);
|
|
151
|
-
var downH = (containerH || winH) - posY - pos.h; // 元素下面可用高度
|
|
152
|
-
var maxHeight = 0;
|
|
153
|
-
var topHeight = (0, _helperDom.getScrollTop)(container);
|
|
154
|
-
if (downH >= posY || realHeight <= downH - innerSpacing - outSpacing) {
|
|
155
|
-
// 下面比上面宽敞 或 下面足够放下所有 放下面
|
|
156
|
-
maxHeight = Math.min(realHeight, downH - innerSpacing - outSpacing);
|
|
157
|
-
topHeight += posY + pos.h + innerSpacing;
|
|
158
|
-
} else {
|
|
159
|
-
// 放上面
|
|
160
|
-
maxHeight = Math.min(realHeight, posY - innerSpacing - outSpacing);
|
|
161
|
-
topHeight += posY - innerSpacing - maxHeight;
|
|
116
|
+
});
|
|
117
|
+
(0, _defineProperty2["default"])(_this, "startScrollHeightCheck", function () {
|
|
118
|
+
if (_this.scrollHeightCheckTimer) {
|
|
119
|
+
clearInterval(_this.scrollHeightCheckTimer);
|
|
120
|
+
}
|
|
121
|
+
_this.scrollHeightCheckTimer = window.setInterval(function () {
|
|
122
|
+
if (_this.ref.current) {
|
|
123
|
+
var currentScrollHeight = _this.ref.current.scrollHeight;
|
|
124
|
+
if (currentScrollHeight !== _this.lastScrollHeight) {
|
|
125
|
+
_this.lastScrollHeight = currentScrollHeight;
|
|
126
|
+
_this.didUpdate();
|
|
127
|
+
}
|
|
162
128
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
129
|
+
}, 100);
|
|
130
|
+
});
|
|
131
|
+
(0, _defineProperty2["default"])(_this, "closePopup", function () {
|
|
132
|
+
if (_this.props.visible && _this.props.closable) {
|
|
133
|
+
_this.props.hideVisible();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
(0, _defineProperty2["default"])(_this, "createPopupContainer", function () {
|
|
137
|
+
var _this$props$zIndex;
|
|
138
|
+
if (_this.popupContainer) return;
|
|
139
|
+
var container = document.createElement('span');
|
|
140
|
+
container.style.cssText = "\n position: absolute;\n top: 0;\n left: 0;\n pointer-events: none;\n z-index: ".concat((_this$props$zIndex = _this.props.zIndex) !== null && _this$props$zIndex !== void 0 ? _this$props$zIndex : 999, ";\n opacity: 0;\n transition: opacity 0.2s ease;\n will-change: transform;\n ");
|
|
141
|
+
document.body.appendChild(container);
|
|
142
|
+
_this.popupContainer = container;
|
|
143
|
+
});
|
|
144
|
+
(0, _defineProperty2["default"])(_this, "getContainer", function () {
|
|
145
|
+
if (!_this.popupContainer) {
|
|
146
|
+
_this.createPopupContainer();
|
|
147
|
+
}
|
|
148
|
+
return _this.popupContainer;
|
|
149
|
+
});
|
|
150
|
+
(0, _defineProperty2["default"])(_this, "getComponent", function () {
|
|
151
|
+
return (0, _jsxRuntime.jsx)("div", {
|
|
152
|
+
ref: _this.ref,
|
|
153
|
+
style: {
|
|
154
|
+
overflowX: 'hidden',
|
|
155
|
+
overflowY: 'auto',
|
|
156
|
+
backgroundColor: '#fff',
|
|
157
|
+
pointerEvents: 'auto',
|
|
158
|
+
transition: 'max-height 0.3s ease',
|
|
159
|
+
boxShadow: '0 4px 10px rgba(0,0,0,0.13)',
|
|
160
|
+
borderRadius: 6,
|
|
161
|
+
position: 'relative'
|
|
162
|
+
},
|
|
163
|
+
onClick: function onClick(e) {
|
|
164
|
+
return _this.props.closable && e.stopPropagation();
|
|
165
|
+
},
|
|
166
|
+
onMouseDown: function onMouseDown(e) {
|
|
167
|
+
return e.stopPropagation();
|
|
168
|
+
},
|
|
169
|
+
children: React.cloneElement(_this.props.children, {
|
|
170
|
+
key: _this.state.popupRefreshKey
|
|
171
|
+
})
|
|
167
172
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
});
|
|
174
|
+
(0, _defineProperty2["default"])(_this, "didUpdate", function () {
|
|
175
|
+
if (!_this.props.visible || !_this.props.node || !_this.ref.current || !_this.popupContainer) return;
|
|
176
|
+
var _this$props = _this.props,
|
|
177
|
+
node = _this$props.node,
|
|
178
|
+
_this$props$innerSpac = _this$props.innerSpacing,
|
|
179
|
+
innerSpacing = _this$props$innerSpac === void 0 ? 10 : _this$props$innerSpac;
|
|
180
|
+
var rect = node.getBoundingClientRect();
|
|
181
|
+
var triggerTop = rect.top + window.scrollY;
|
|
182
|
+
var triggerLeft = rect.left + window.scrollX;
|
|
183
|
+
var triggerHeight = rect.height;
|
|
184
|
+
var popupContent = _this.ref.current;
|
|
185
|
+
var realHeight = popupContent.scrollHeight;
|
|
186
|
+
var _getWindowSize = (0, _helperDom.getWindowSize)(),
|
|
187
|
+
viewportHeight = _getWindowSize.height;
|
|
188
|
+
var spaceBelow = viewportHeight - rect.bottom;
|
|
189
|
+
var spaceAbove = rect.top;
|
|
190
|
+
var topPosition;
|
|
191
|
+
var maxHeight;
|
|
192
|
+
if (spaceBelow >= realHeight + innerSpacing + outSpacing || spaceBelow >= spaceAbove) {
|
|
193
|
+
topPosition = triggerTop + triggerHeight + innerSpacing;
|
|
194
|
+
maxHeight = Math.min(realHeight, spaceBelow - innerSpacing - outSpacing);
|
|
195
|
+
} else {
|
|
196
|
+
maxHeight = Math.min(realHeight, spaceAbove - innerSpacing - outSpacing);
|
|
197
|
+
topPosition = triggerTop - innerSpacing - maxHeight;
|
|
198
|
+
}
|
|
199
|
+
_this.popupContainer.style.transform = "translate(".concat(triggerLeft, "px, ").concat(topPosition, "px)");
|
|
200
|
+
popupContent.style.maxHeight = "".concat(maxHeight, "px");
|
|
201
|
+
});
|
|
202
|
+
_this.state = {
|
|
203
|
+
popupRefreshKey: 1
|
|
204
|
+
};
|
|
205
|
+
return _this;
|
|
206
|
+
}
|
|
207
|
+
(0, _inherits2["default"])(TriggerInternal, _React$Component);
|
|
208
|
+
return (0, _createClass2["default"])(TriggerInternal, [{
|
|
209
|
+
key: "componentDidMount",
|
|
210
|
+
value: function componentDidMount() {
|
|
211
|
+
if (this.props.visible) {
|
|
212
|
+
this.mountPopup();
|
|
213
|
+
}
|
|
172
214
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.
|
|
178
|
-
this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
|
|
179
|
-
this.bindEvent();
|
|
180
|
-
// 延迟绑定 ResizeObserver 到 ensure the element is ready
|
|
181
|
-
this.initResizeObserver();
|
|
182
|
-
}
|
|
183
|
-
}, {
|
|
184
|
-
key: "componentDidUpdate",
|
|
185
|
-
value: function componentDidUpdate(prevProps) {
|
|
186
|
-
// 如果 children 发生变化,重新初始化观察器
|
|
187
|
-
if (prevProps.children !== this.props.children) {
|
|
188
|
-
this.initResizeObserver();
|
|
189
|
-
}
|
|
190
|
-
if (prevProps.node !== this.props.node) {
|
|
191
|
-
this.refreshPopup(); //点击元素不同,刷新一下
|
|
192
|
-
}
|
|
215
|
+
}, {
|
|
216
|
+
key: "componentDidUpdate",
|
|
217
|
+
value: function componentDidUpdate(prevProps) {
|
|
218
|
+
if (!prevProps.visible && this.props.visible) {
|
|
219
|
+
this.mountPopup();
|
|
193
220
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
value: function componentWillUnmount() {
|
|
197
|
-
_event.winResetEvent.removeEvent(this.resetId);
|
|
198
|
-
this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
|
|
199
|
-
if (this.resizeObserver) {
|
|
200
|
-
this.resizeObserver.disconnect();
|
|
201
|
-
this.resizeObserver = null;
|
|
202
|
-
}
|
|
221
|
+
if (prevProps.visible && !this.props.visible) {
|
|
222
|
+
this.unmountPopup();
|
|
203
223
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
if (prevProps.children !== this.props.children) {
|
|
225
|
+
this.initContentResizeObserver();
|
|
226
|
+
}
|
|
227
|
+
if (prevProps.node !== this.props.node) {
|
|
228
|
+
this.refreshPopup();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}, {
|
|
232
|
+
key: "componentWillUnmount",
|
|
233
|
+
value: function componentWillUnmount() {
|
|
234
|
+
this.cleanup();
|
|
235
|
+
}
|
|
236
|
+
}, {
|
|
237
|
+
key: "render",
|
|
238
|
+
value: function render() {
|
|
239
|
+
if (!this.props.visible || !this.popupContainer) return null;
|
|
240
|
+
return (0, _jsxRuntime.jsx)(_Portal["default"], {
|
|
241
|
+
getContainer: this.getContainer,
|
|
242
|
+
didUpdate: this.didUpdate,
|
|
243
|
+
children: this.getComponent()
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}]);
|
|
247
|
+
}(React.Component);
|
|
248
|
+
(0, _defineProperty2["default"])(TriggerInternal, "defaultProps", {
|
|
249
|
+
visible: false,
|
|
250
|
+
closable: true,
|
|
251
|
+
innerSpacing: 10
|
|
252
|
+
});
|
|
253
|
+
function generateTrigger(PortalComponent) {
|
|
254
|
+
return TriggerInternal;
|
|
226
255
|
}
|
|
227
256
|
var _default = exports["default"] = generateTrigger(_Portal["default"]);
|
|
@@ -151,8 +151,10 @@ var Metabase = function Metabase(props) {
|
|
|
151
151
|
disabled: saveLoading,
|
|
152
152
|
onClick: onCheck,
|
|
153
153
|
children: btnText || __('SqlQueryBuilder.visualize')
|
|
154
|
-
}) : null, store.popupContainer.current && _jsx(Popup
|
|
155
|
-
|
|
154
|
+
}) : null, store.popupContainer.current && _jsx(Popup
|
|
155
|
+
// container={store.popupData.container || store.popupContainer.current}
|
|
156
|
+
, {
|
|
157
|
+
// container={store.popupData.container || store.popupContainer.current}
|
|
156
158
|
visible: store.popupData.visible,
|
|
157
159
|
node: store.popupData.node,
|
|
158
160
|
closable: store.popupClosable,
|
|
@@ -162,8 +164,10 @@ var Metabase = function Metabase(props) {
|
|
|
162
164
|
});
|
|
163
165
|
},
|
|
164
166
|
children: popupContent
|
|
165
|
-
}), store.popupContainer.current && _jsx(Popup
|
|
166
|
-
|
|
167
|
+
}), store.popupContainer.current && _jsx(Popup
|
|
168
|
+
// container={store.popupData2.container || store.popupContainer.current}
|
|
169
|
+
, {
|
|
170
|
+
// container={store.popupData2.container || store.popupContainer.current}
|
|
167
171
|
visible: store.popupData2.visible,
|
|
168
172
|
node: store.popupData2.node,
|
|
169
173
|
closable: store.popupClosable2,
|
|
@@ -1,109 +1,47 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
interface PropsType {
|
|
3
|
+
visible: boolean;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
hideVisible: () => void;
|
|
6
|
+
node: HTMLElement;
|
|
7
|
+
innerSpacing?: number;
|
|
8
|
+
zIndex?: string | number;
|
|
9
|
+
closable?: boolean;
|
|
10
|
+
}
|
|
2
11
|
interface StateType {
|
|
3
12
|
popupRefreshKey: number;
|
|
4
13
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
initResizeObserver: () => void;
|
|
15
|
-
bindEvent: () => void;
|
|
16
|
-
closePopup: () => void;
|
|
17
|
-
attachParent: (popupContainer: HTMLSpanElement) => void;
|
|
18
|
-
getCurrentNodePos: () => {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
t: number;
|
|
22
|
-
h: any;
|
|
23
|
-
};
|
|
24
|
-
getContainer: () => HTMLSpanElement;
|
|
25
|
-
getComponent: () => import("react/jsx-runtime").JSX.Element;
|
|
26
|
-
didUpdate: () => void | false;
|
|
27
|
-
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
28
|
-
context: unknown;
|
|
29
|
-
setState<K extends "popupRefreshKey">(state: StateType | ((prevState: Readonly<StateType>, props: Readonly<PropsType>) => StateType | Pick<StateType, K> | null) | Pick<StateType, K> | null, callback?: (() => void) | undefined): void;
|
|
30
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
31
|
-
readonly props: Readonly<PropsType>;
|
|
32
|
-
state: Readonly<StateType>;
|
|
33
|
-
refs: {
|
|
34
|
-
[key: string]: React.ReactInstance;
|
|
35
|
-
};
|
|
36
|
-
shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): boolean;
|
|
37
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
38
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<StateType>): any;
|
|
39
|
-
componentWillMount?(): void;
|
|
40
|
-
UNSAFE_componentWillMount?(): void;
|
|
41
|
-
componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
42
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
43
|
-
componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
44
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
45
|
-
};
|
|
46
|
-
defaultProps: {
|
|
14
|
+
declare class TriggerInternal extends React.Component<PropsType, StateType> {
|
|
15
|
+
private resizeObserver;
|
|
16
|
+
private resetId;
|
|
17
|
+
private popupContainer;
|
|
18
|
+
private contentResizeObserver;
|
|
19
|
+
private scrollHeightCheckTimer;
|
|
20
|
+
private lastScrollHeight;
|
|
21
|
+
private handleClickOutside;
|
|
22
|
+
static defaultProps: {
|
|
47
23
|
visible: boolean;
|
|
48
|
-
|
|
24
|
+
closable: boolean;
|
|
25
|
+
innerSpacing: number;
|
|
49
26
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
y: number;
|
|
68
|
-
t: number;
|
|
69
|
-
h: any;
|
|
70
|
-
};
|
|
71
|
-
getContainer: () => HTMLSpanElement;
|
|
72
|
-
getComponent: () => import("react/jsx-runtime").JSX.Element;
|
|
73
|
-
didUpdate: () => void | false;
|
|
74
|
-
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
75
|
-
context: unknown;
|
|
76
|
-
setState<K extends "popupRefreshKey">(state: StateType | ((prevState: Readonly<StateType>, props: Readonly<PropsType>) => StateType | Pick<StateType, K> | null) | Pick<StateType, K> | null, callback?: (() => void) | undefined): void;
|
|
77
|
-
forceUpdate(callback?: (() => void) | undefined): void;
|
|
78
|
-
readonly props: Readonly<PropsType>;
|
|
79
|
-
state: Readonly<StateType>;
|
|
80
|
-
refs: {
|
|
81
|
-
[key: string]: React.ReactInstance;
|
|
82
|
-
};
|
|
83
|
-
shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): boolean;
|
|
84
|
-
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
85
|
-
getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<StateType>): any;
|
|
86
|
-
componentWillMount?(): void;
|
|
87
|
-
UNSAFE_componentWillMount?(): void;
|
|
88
|
-
componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
89
|
-
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
|
|
90
|
-
componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
91
|
-
UNSAFE_componentWillUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<StateType>, nextContext: any): void;
|
|
92
|
-
};
|
|
93
|
-
defaultProps: {
|
|
94
|
-
visible: boolean;
|
|
95
|
-
children: null;
|
|
96
|
-
};
|
|
97
|
-
contextType?: React.Context<any> | undefined;
|
|
98
|
-
};
|
|
99
|
-
export default _default;
|
|
100
|
-
interface PropsType {
|
|
101
|
-
visible: boolean;
|
|
102
|
-
children: any;
|
|
103
|
-
hideVisible: Function;
|
|
104
|
-
node: any;
|
|
105
|
-
innerSpacing?: number;
|
|
106
|
-
container?: HTMLDivElement;
|
|
107
|
-
zIndex?: string | null;
|
|
108
|
-
closable?: boolean;
|
|
27
|
+
ref: React.RefObject<HTMLDivElement>;
|
|
28
|
+
constructor(props: PropsType);
|
|
29
|
+
componentDidMount(): void;
|
|
30
|
+
componentDidUpdate(prevProps: PropsType): void;
|
|
31
|
+
componentWillUnmount(): void;
|
|
32
|
+
private mountPopup;
|
|
33
|
+
private unmountPopup;
|
|
34
|
+
private cleanup;
|
|
35
|
+
private refreshPopup;
|
|
36
|
+
private initContentResizeObserver;
|
|
37
|
+
private startScrollHeightCheck;
|
|
38
|
+
private closePopup;
|
|
39
|
+
private createPopupContainer;
|
|
40
|
+
private getContainer;
|
|
41
|
+
private getComponent;
|
|
42
|
+
private didUpdate;
|
|
43
|
+
render(): import("react/jsx-runtime").JSX.Element | null;
|
|
109
44
|
}
|
|
45
|
+
export declare function generateTrigger(PortalComponent: any): typeof TriggerInternal;
|
|
46
|
+
declare const _default: typeof TriggerInternal;
|
|
47
|
+
export default _default;
|
|
@@ -8,210 +8,239 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
8
8
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
import * as React from 'react';
|
|
11
|
-
import { getWindowSize
|
|
11
|
+
import { getWindowSize } from '../utils/helper-dom';
|
|
12
12
|
import { winResetEvent } from '../utils/event';
|
|
13
13
|
import Portal from '../common/Portal';
|
|
14
|
-
function returnDocument(element) {
|
|
15
|
-
if (element) {
|
|
16
|
-
return element.ownerDocument;
|
|
17
|
-
}
|
|
18
|
-
return window.document;
|
|
19
|
-
}
|
|
20
14
|
var outSpacing = 10;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
var TriggerInternal = /*#__PURE__*/function (_React$Component) {
|
|
16
|
+
function TriggerInternal(props) {
|
|
17
|
+
var _this;
|
|
18
|
+
_classCallCheck(this, TriggerInternal);
|
|
19
|
+
_this = _callSuper(this, TriggerInternal, [props]);
|
|
20
|
+
_defineProperty(_this, "resizeObserver", null);
|
|
21
|
+
_defineProperty(_this, "resetId", -1);
|
|
22
|
+
_defineProperty(_this, "popupContainer", null);
|
|
23
|
+
_defineProperty(_this, "contentResizeObserver", null);
|
|
24
|
+
_defineProperty(_this, "scrollHeightCheckTimer", null);
|
|
25
|
+
_defineProperty(_this, "lastScrollHeight", 0);
|
|
26
|
+
_defineProperty(_this, "handleClickOutside", function (e) {
|
|
27
|
+
var ele = e.target;
|
|
28
|
+
while (ele) {
|
|
29
|
+
if (ele === _this.props.node) return;
|
|
30
|
+
if (_this.popupContainer && ele === _this.popupContainer) return;
|
|
31
|
+
ele = ele.parentNode;
|
|
32
|
+
}
|
|
33
|
+
_this.closePopup();
|
|
34
|
+
});
|
|
35
|
+
_defineProperty(_this, "ref", React.createRef());
|
|
36
|
+
_defineProperty(_this, "mountPopup", function () {
|
|
37
|
+
_this.createPopupContainer();
|
|
38
|
+
_this.resetId = winResetEvent.addEvent(_this.didUpdate, _this, 300);
|
|
39
|
+
window.addEventListener('scroll', _this.didUpdate, true);
|
|
40
|
+
document.body.addEventListener('click', _this.handleClickOutside, false);
|
|
41
|
+
_this.initContentResizeObserver();
|
|
42
|
+
_this.startScrollHeightCheck();
|
|
43
|
+
setTimeout(function () {
|
|
44
|
+
_this.didUpdate();
|
|
45
|
+
if (_this.popupContainer) {
|
|
46
|
+
_this.popupContainer.style.opacity = '1';
|
|
47
|
+
_this.popupContainer.style.willChange = 'transform';
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
49
|
+
}, 0);
|
|
50
|
+
setTimeout(function () {
|
|
51
|
+
_this.didUpdate();
|
|
52
|
+
}, 100);
|
|
53
|
+
});
|
|
54
|
+
_defineProperty(_this, "unmountPopup", function () {
|
|
55
|
+
if (_this.popupContainer) {
|
|
56
|
+
_this.popupContainer.style.opacity = '0';
|
|
57
|
+
}
|
|
58
|
+
_this.cleanup();
|
|
59
|
+
});
|
|
60
|
+
_defineProperty(_this, "cleanup", function () {
|
|
61
|
+
winResetEvent.removeEvent(_this.resetId);
|
|
62
|
+
window.removeEventListener('scroll', _this.didUpdate, true);
|
|
63
|
+
document.body.removeEventListener('click', _this.handleClickOutside, false);
|
|
64
|
+
if (_this.resizeObserver) {
|
|
65
|
+
_this.resizeObserver.disconnect();
|
|
66
|
+
_this.resizeObserver = null;
|
|
67
|
+
}
|
|
68
|
+
if (_this.contentResizeObserver) {
|
|
69
|
+
_this.contentResizeObserver.disconnect();
|
|
70
|
+
_this.contentResizeObserver = null;
|
|
71
|
+
}
|
|
72
|
+
if (_this.scrollHeightCheckTimer) {
|
|
73
|
+
clearInterval(_this.scrollHeightCheckTimer);
|
|
74
|
+
_this.scrollHeightCheckTimer = null;
|
|
75
|
+
}
|
|
76
|
+
if (_this.popupContainer && document.body.contains(_this.popupContainer)) {
|
|
77
|
+
document.body.removeChild(_this.popupContainer);
|
|
78
|
+
_this.popupContainer = null;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
_defineProperty(_this, "refreshPopup", function () {
|
|
82
|
+
_this.setState(function (prev) {
|
|
79
83
|
return {
|
|
80
|
-
|
|
81
|
-
y: getElementTop(node) - getElementTop(container),
|
|
82
|
-
t: getElementTop(container),
|
|
83
|
-
h: node.offsetHeight
|
|
84
|
+
popupRefreshKey: prev.popupRefreshKey + 1
|
|
84
85
|
};
|
|
85
86
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
popupContainer.style.left = '0px';
|
|
96
|
-
popupContainer.style.transform = "translateX(".concat(pos.x, "px) translateY(").concat(pos.y + pos.h + innerSpacing, "px) translateZ(0px)");
|
|
97
|
-
popupContainer.style.pointerEvents = 'none';
|
|
98
|
-
popupContainer.style.zIndex = zIndex || '999';
|
|
99
|
-
_this.attachParent(popupContainer);
|
|
100
|
-
return popupContainer;
|
|
87
|
+
});
|
|
88
|
+
_defineProperty(_this, "initContentResizeObserver", function () {
|
|
89
|
+
var targetNode = _this.ref.current;
|
|
90
|
+
if (!targetNode) return;
|
|
91
|
+
if (_this.contentResizeObserver) {
|
|
92
|
+
_this.contentResizeObserver.disconnect();
|
|
93
|
+
}
|
|
94
|
+
_this.contentResizeObserver = new ResizeObserver(function () {
|
|
95
|
+
_this.didUpdate();
|
|
101
96
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
transition: 'all 0.3s',
|
|
111
|
-
boxShadow: '0 4px 10px rgba(0,0,0,0.13)',
|
|
112
|
-
borderRadius: 6
|
|
113
|
-
},
|
|
114
|
-
onClick: function onClick(e) {
|
|
115
|
-
return _this.props.closable && e.stopPropagation();
|
|
116
|
-
},
|
|
117
|
-
onMouseDown: function onMouseDown(e) {
|
|
118
|
-
return e.stopPropagation();
|
|
119
|
-
},
|
|
120
|
-
children: React.cloneElement(_this.props.children, {
|
|
121
|
-
key: _this.state.popupRefreshKey,
|
|
122
|
-
didUpdate: _this.didUpdate
|
|
123
|
-
})
|
|
124
|
-
});
|
|
97
|
+
_this.contentResizeObserver.observe(targetNode);
|
|
98
|
+
// 额外监听图片加载
|
|
99
|
+
var images = targetNode.querySelectorAll('img');
|
|
100
|
+
images.forEach(function (img) {
|
|
101
|
+
if (!img.complete) {
|
|
102
|
+
img.addEventListener('load', _this.didUpdate);
|
|
103
|
+
img.addEventListener('error', _this.didUpdate);
|
|
104
|
+
}
|
|
125
105
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var _getWindowSize = getWindowSize(),
|
|
139
|
-
winH = _getWindowSize.height;
|
|
140
|
-
var containerH = getContainerVisibleHeight(container);
|
|
141
|
-
var downH = (containerH || winH) - posY - pos.h; // 元素下面可用高度
|
|
142
|
-
var maxHeight = 0;
|
|
143
|
-
var topHeight = getScrollTop(container);
|
|
144
|
-
if (downH >= posY || realHeight <= downH - innerSpacing - outSpacing) {
|
|
145
|
-
// 下面比上面宽敞 或 下面足够放下所有 放下面
|
|
146
|
-
maxHeight = Math.min(realHeight, downH - innerSpacing - outSpacing);
|
|
147
|
-
topHeight += posY + pos.h + innerSpacing;
|
|
148
|
-
} else {
|
|
149
|
-
// 放上面
|
|
150
|
-
maxHeight = Math.min(realHeight, posY - innerSpacing - outSpacing);
|
|
151
|
-
topHeight += posY - innerSpacing - maxHeight;
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(_this, "startScrollHeightCheck", function () {
|
|
108
|
+
if (_this.scrollHeightCheckTimer) {
|
|
109
|
+
clearInterval(_this.scrollHeightCheckTimer);
|
|
110
|
+
}
|
|
111
|
+
_this.scrollHeightCheckTimer = window.setInterval(function () {
|
|
112
|
+
if (_this.ref.current) {
|
|
113
|
+
var currentScrollHeight = _this.ref.current.scrollHeight;
|
|
114
|
+
if (currentScrollHeight !== _this.lastScrollHeight) {
|
|
115
|
+
_this.lastScrollHeight = currentScrollHeight;
|
|
116
|
+
_this.didUpdate();
|
|
117
|
+
}
|
|
152
118
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
119
|
+
}, 100);
|
|
120
|
+
});
|
|
121
|
+
_defineProperty(_this, "closePopup", function () {
|
|
122
|
+
if (_this.props.visible && _this.props.closable) {
|
|
123
|
+
_this.props.hideVisible();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
_defineProperty(_this, "createPopupContainer", function () {
|
|
127
|
+
var _this$props$zIndex;
|
|
128
|
+
if (_this.popupContainer) return;
|
|
129
|
+
var container = document.createElement('span');
|
|
130
|
+
container.style.cssText = "\n position: absolute;\n top: 0;\n left: 0;\n pointer-events: none;\n z-index: ".concat((_this$props$zIndex = _this.props.zIndex) !== null && _this$props$zIndex !== void 0 ? _this$props$zIndex : 999, ";\n opacity: 0;\n transition: opacity 0.2s ease;\n will-change: transform;\n ");
|
|
131
|
+
document.body.appendChild(container);
|
|
132
|
+
_this.popupContainer = container;
|
|
133
|
+
});
|
|
134
|
+
_defineProperty(_this, "getContainer", function () {
|
|
135
|
+
if (!_this.popupContainer) {
|
|
136
|
+
_this.createPopupContainer();
|
|
137
|
+
}
|
|
138
|
+
return _this.popupContainer;
|
|
139
|
+
});
|
|
140
|
+
_defineProperty(_this, "getComponent", function () {
|
|
141
|
+
return _jsx("div", {
|
|
142
|
+
ref: _this.ref,
|
|
143
|
+
style: {
|
|
144
|
+
overflowX: 'hidden',
|
|
145
|
+
overflowY: 'auto',
|
|
146
|
+
backgroundColor: '#fff',
|
|
147
|
+
pointerEvents: 'auto',
|
|
148
|
+
transition: 'max-height 0.3s ease',
|
|
149
|
+
boxShadow: '0 4px 10px rgba(0,0,0,0.13)',
|
|
150
|
+
borderRadius: 6,
|
|
151
|
+
position: 'relative'
|
|
152
|
+
},
|
|
153
|
+
onClick: function onClick(e) {
|
|
154
|
+
return _this.props.closable && e.stopPropagation();
|
|
155
|
+
},
|
|
156
|
+
onMouseDown: function onMouseDown(e) {
|
|
157
|
+
return e.stopPropagation();
|
|
158
|
+
},
|
|
159
|
+
children: React.cloneElement(_this.props.children, {
|
|
160
|
+
key: _this.state.popupRefreshKey
|
|
161
|
+
})
|
|
157
162
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(_this, "didUpdate", function () {
|
|
165
|
+
if (!_this.props.visible || !_this.props.node || !_this.ref.current || !_this.popupContainer) return;
|
|
166
|
+
var _this$props = _this.props,
|
|
167
|
+
node = _this$props.node,
|
|
168
|
+
_this$props$innerSpac = _this$props.innerSpacing,
|
|
169
|
+
innerSpacing = _this$props$innerSpac === void 0 ? 10 : _this$props$innerSpac;
|
|
170
|
+
var rect = node.getBoundingClientRect();
|
|
171
|
+
var triggerTop = rect.top + window.scrollY;
|
|
172
|
+
var triggerLeft = rect.left + window.scrollX;
|
|
173
|
+
var triggerHeight = rect.height;
|
|
174
|
+
var popupContent = _this.ref.current;
|
|
175
|
+
var realHeight = popupContent.scrollHeight;
|
|
176
|
+
var _getWindowSize = getWindowSize(),
|
|
177
|
+
viewportHeight = _getWindowSize.height;
|
|
178
|
+
var spaceBelow = viewportHeight - rect.bottom;
|
|
179
|
+
var spaceAbove = rect.top;
|
|
180
|
+
var topPosition;
|
|
181
|
+
var maxHeight;
|
|
182
|
+
if (spaceBelow >= realHeight + innerSpacing + outSpacing || spaceBelow >= spaceAbove) {
|
|
183
|
+
topPosition = triggerTop + triggerHeight + innerSpacing;
|
|
184
|
+
maxHeight = Math.min(realHeight, spaceBelow - innerSpacing - outSpacing);
|
|
185
|
+
} else {
|
|
186
|
+
maxHeight = Math.min(realHeight, spaceAbove - innerSpacing - outSpacing);
|
|
187
|
+
topPosition = triggerTop - innerSpacing - maxHeight;
|
|
188
|
+
}
|
|
189
|
+
_this.popupContainer.style.transform = "translate(".concat(triggerLeft, "px, ").concat(topPosition, "px)");
|
|
190
|
+
popupContent.style.maxHeight = "".concat(maxHeight, "px");
|
|
191
|
+
});
|
|
192
|
+
_this.state = {
|
|
193
|
+
popupRefreshKey: 1
|
|
194
|
+
};
|
|
195
|
+
return _this;
|
|
196
|
+
}
|
|
197
|
+
_inherits(TriggerInternal, _React$Component);
|
|
198
|
+
return _createClass(TriggerInternal, [{
|
|
199
|
+
key: "componentDidMount",
|
|
200
|
+
value: function componentDidMount() {
|
|
201
|
+
if (this.props.visible) {
|
|
202
|
+
this.mountPopup();
|
|
203
|
+
}
|
|
162
204
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
this.
|
|
168
|
-
this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
|
|
169
|
-
this.bindEvent();
|
|
170
|
-
// 延迟绑定 ResizeObserver 到 ensure the element is ready
|
|
171
|
-
this.initResizeObserver();
|
|
172
|
-
}
|
|
173
|
-
}, {
|
|
174
|
-
key: "componentDidUpdate",
|
|
175
|
-
value: function componentDidUpdate(prevProps) {
|
|
176
|
-
// 如果 children 发生变化,重新初始化观察器
|
|
177
|
-
if (prevProps.children !== this.props.children) {
|
|
178
|
-
this.initResizeObserver();
|
|
179
|
-
}
|
|
180
|
-
if (prevProps.node !== this.props.node) {
|
|
181
|
-
this.refreshPopup(); //点击元素不同,刷新一下
|
|
182
|
-
}
|
|
205
|
+
}, {
|
|
206
|
+
key: "componentDidUpdate",
|
|
207
|
+
value: function componentDidUpdate(prevProps) {
|
|
208
|
+
if (!prevProps.visible && this.props.visible) {
|
|
209
|
+
this.mountPopup();
|
|
183
210
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
value: function componentWillUnmount() {
|
|
187
|
-
winResetEvent.removeEvent(this.resetId);
|
|
188
|
-
this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
|
|
189
|
-
if (this.resizeObserver) {
|
|
190
|
-
this.resizeObserver.disconnect();
|
|
191
|
-
this.resizeObserver = null;
|
|
192
|
-
}
|
|
211
|
+
if (prevProps.visible && !this.props.visible) {
|
|
212
|
+
this.unmountPopup();
|
|
193
213
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
if (prevProps.children !== this.props.children) {
|
|
215
|
+
this.initContentResizeObserver();
|
|
216
|
+
}
|
|
217
|
+
if (prevProps.node !== this.props.node) {
|
|
218
|
+
this.refreshPopup();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "componentWillUnmount",
|
|
223
|
+
value: function componentWillUnmount() {
|
|
224
|
+
this.cleanup();
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "render",
|
|
228
|
+
value: function render() {
|
|
229
|
+
if (!this.props.visible || !this.popupContainer) return null;
|
|
230
|
+
return _jsx(Portal, {
|
|
231
|
+
getContainer: this.getContainer,
|
|
232
|
+
didUpdate: this.didUpdate,
|
|
233
|
+
children: this.getComponent()
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}]);
|
|
237
|
+
}(React.Component);
|
|
238
|
+
_defineProperty(TriggerInternal, "defaultProps", {
|
|
239
|
+
visible: false,
|
|
240
|
+
closable: true,
|
|
241
|
+
innerSpacing: 10
|
|
242
|
+
});
|
|
243
|
+
export function generateTrigger(PortalComponent) {
|
|
244
|
+
return TriggerInternal;
|
|
216
245
|
}
|
|
217
246
|
export default generateTrigger(Portal);
|