@gingkoo/pandora-metabase 1.0.62 → 1.0.64
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/modules/summarize/group-by.js +1 -1
- package/lib/cjs/components/modules/summarize/select-index.js +1 -1
- package/lib/cjs/components/popup.d.ts +40 -102
- package/lib/cjs/components/popup.js +219 -190
- package/lib/cjs/hooks/use-state.js +14 -8
- package/lib/cjs/index.js +4 -1
- package/lib/cjs/types.d.ts +1 -0
- package/lib/es/components/metabase/index.js +8 -4
- package/lib/es/components/modules/summarize/group-by.js +1 -1
- package/lib/es/components/modules/summarize/select-index.js +1 -1
- package/lib/es/components/popup.d.ts +40 -102
- package/lib/es/components/popup.js +220 -191
- package/lib/es/hooks/use-state.js +14 -8
- package/lib/es/index.js +4 -1
- package/lib/es/types.d.ts +1 -0
- 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,
|
|
@@ -342,7 +342,7 @@ var GroupBy = function GroupBy(props) {
|
|
|
342
342
|
return handleUpdate(e, i);
|
|
343
343
|
},
|
|
344
344
|
children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
345
|
-
children: store.
|
|
345
|
+
children: store.groupByEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
|
|
346
346
|
title: !(0, _utils.isValidSQLAlias)(v === null || v === void 0 ? void 0 : v.fieldAlias) ? (0, _locale.__)('SqlQueryBuilder.aliasForRules') : (0, _locale.__)('SqlQueryBuilder.alias'),
|
|
347
347
|
children: (0, _jsxRuntime.jsx)(_pandora.Button, {
|
|
348
348
|
className: (0, _classnames["default"])(':Sqb-TableName-as :Sqb-TableName green-name', (0, _defineProperty2["default"])({}, 'isError', !(0, _utils.isValidSQLAlias)(v === null || v === void 0 ? void 0 : v.fieldAlias))),
|
|
@@ -340,7 +340,7 @@ var SelectIndex = function SelectIndex(props) {
|
|
|
340
340
|
return handleUpdate(e, i);
|
|
341
341
|
},
|
|
342
342
|
children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
343
|
-
children: store.
|
|
343
|
+
children: store.groupByEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
|
|
344
344
|
title: !(0, _utils.isValidSQLAlias)(v === null || v === void 0 ? void 0 : v.fieldAlias) ? (0, _locale.__)('SqlQueryBuilder.aliasForRules') : (0, _locale.__)('SqlQueryBuilder.alias'),
|
|
345
345
|
children: (0, _jsxRuntime.jsx)(_pandora.Button, {
|
|
346
346
|
className: (0, _classnames["default"])(':Sqb-TableName-as :Sqb-TableName green-name', (0, _defineProperty2["default"])({}, 'isError', !(0, _utils.isValidSQLAlias)(v === null || v === void 0 ? void 0 : v.fieldAlias))),
|
|
@@ -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"]);
|