@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.
@@ -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
- container: store.popupData.container || store.popupContainer.current,
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
- container: store.popupData2.container || store.popupContainer.current,
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.fieldEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
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.fieldEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
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
- export declare function generateTrigger(PortalComponent: any): {
6
- new (props: PropsType): {
7
- resizeObserver: ResizeObserver | null;
8
- resetId: number;
9
- ref: any;
10
- componentDidMount(): void;
11
- componentDidUpdate(prevProps: PropsType): void;
12
- componentWillUnmount(): void;
13
- refreshPopup: () => void;
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
- children: null;
24
+ closable: boolean;
25
+ innerSpacing: number;
49
26
  };
50
- contextType?: React.Context<any> | undefined;
51
- };
52
- declare const _default: {
53
- new (props: PropsType): {
54
- resizeObserver: ResizeObserver | null;
55
- resetId: number;
56
- ref: any;
57
- componentDidMount(): void;
58
- componentDidUpdate(prevProps: PropsType): void;
59
- componentWillUnmount(): void;
60
- refreshPopup: () => void;
61
- initResizeObserver: () => void;
62
- bindEvent: () => void;
63
- closePopup: () => void;
64
- attachParent: (popupContainer: HTMLSpanElement) => void;
65
- getCurrentNodePos: () => {
66
- x: number;
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 generateTrigger(PortalComponent) {
32
- var Trigger = /*#__PURE__*/function (_React$Component) {
33
- function Trigger(props) {
34
- var _this;
35
- (0, _classCallCheck2["default"])(this, Trigger);
36
- _this = _callSuper(this, Trigger, [props]);
37
- (0, _defineProperty2["default"])(_this, "resizeObserver", null);
38
- // 显式声明 resizeObserver 属性
39
- (0, _defineProperty2["default"])(_this, "resetId", -1);
40
- (0, _defineProperty2["default"])(_this, "ref", React.createRef());
41
- // 刷新弹窗内容
42
- (0, _defineProperty2["default"])(_this, "refreshPopup", function () {
43
- _this.setState(function (prev) {
44
- return {
45
- popupRefreshKey: prev.popupRefreshKey + 1
46
- };
47
- });
48
- });
49
- // children高度变化后,从新计算高度
50
- (0, _defineProperty2["default"])(_this, "initResizeObserver", function () {
51
- var targetNode = _this.ref.current;
52
- if (!targetNode) return;
53
- // 如果已经存在 ResizeObserver,先断开连接
54
- if (_this.resizeObserver) {
55
- _this.resizeObserver.disconnect();
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
- // 初始化 ResizeObserver 并开始观察目标节点
58
- _this.resizeObserver = new ResizeObserver(function (entries) {
59
- entries.forEach(function (entry) {
60
- _this.didUpdate();
61
- });
62
- });
63
- _this.resizeObserver.observe(targetNode);
64
- });
65
- (0, _defineProperty2["default"])(_this, "bindEvent", function () {
66
- var that = _this;
67
- returnDocument().body.addEventListener('click', function (e) {
68
- var ele = e.target;
69
- while (ele != null) {
70
- if (ele === that.props.node) {
71
- return false;
72
- }
73
- ele = ele.parentNode;
74
- }
75
- that.closePopup();
76
- }, false);
77
- });
78
- (0, _defineProperty2["default"])(_this, "closePopup", function () {
79
- _this.props.visible && _this.props.closable && _this.props.hideVisible();
80
- });
81
- (0, _defineProperty2["default"])(_this, "attachParent", function (popupContainer) {
82
- var mountNode = _this.props.container || returnDocument().body;
83
- mountNode.appendChild(popupContainer);
84
- });
85
- (0, _defineProperty2["default"])(_this, "getCurrentNodePos", function () {
86
- var _this$props = _this.props,
87
- node = _this$props.node,
88
- container = _this$props.container;
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
- x: (0, _helperDom.getElementLeft)(node) - (0, _helperDom.getElementLeft)(container),
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
- (0, _defineProperty2["default"])(_this, "getContainer", function () {
97
- var pos = _this.getCurrentNodePos();
98
- var _this$props2 = _this.props,
99
- _this$props2$innerSpa = _this$props2.innerSpacing,
100
- innerSpacing = _this$props2$innerSpa === void 0 ? 10 : _this$props2$innerSpa,
101
- zIndex = _this$props2.zIndex;
102
- var popupContainer = returnDocument().createElement('span');
103
- popupContainer.style.position = 'absolute';
104
- popupContainer.style.top = '0px';
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
- (0, _defineProperty2["default"])(_this, "getComponent", function () {
113
- return (0, _jsxRuntime.jsx)("div", {
114
- ref: _this.ref,
115
- style: {
116
- overflowX: 'hidden',
117
- overflowY: 'auto',
118
- backgroundColor: '#fff',
119
- pointerEvents: 'auto',
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
- (0, _defineProperty2["default"])(_this, "didUpdate", function () {
137
- var _this$ref;
138
- if (!_this.props.node) return false;
139
- var _this$props3 = _this.props,
140
- _this$props3$innerSpa = _this$props3.innerSpacing,
141
- innerSpacing = _this$props3$innerSpa === void 0 ? 10 : _this$props3$innerSpa,
142
- container = _this$props3.container;
143
- var pos = _this.getCurrentNodePos();
144
- var posY = pos.y - (0, _helperDom.getScrollTop)(container);
145
- if (!_this.ref) return false;
146
- var realHeight = ((_this$ref = _this.ref) === null || _this$ref === void 0 || (_this$ref = _this$ref.current) === null || _this$ref === void 0 || (_this$ref = _this$ref.childNodes) === null || _this$ref === void 0 || (_this$ref = _this$ref[0]) === null || _this$ref === void 0 ? void 0 : _this$ref.offsetHeight) || 0;
147
- if (!realHeight) return false;
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
- _this.ref.current.offsetParent.style.transform = "translateX(".concat(pos.x, "px) translateY(").concat(topHeight, "px) translateZ(0px)");
164
- _this.ref.current.offsetParent.style.transition = 'all 0.3s';
165
- _this.ref.current.style.cssText += "max-height: ".concat(maxHeight, "px");
166
- _this.ref.current.style.cssText += "position: relative";
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
- _this.state = {
169
- popupRefreshKey: 1
170
- };
171
- return _this;
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
- (0, _inherits2["default"])(Trigger, _React$Component);
174
- return (0, _createClass2["default"])(Trigger, [{
175
- key: "componentDidMount",
176
- value: function componentDidMount() {
177
- this.resetId = _event.winResetEvent.addEvent(this.didUpdate, this, 300);
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
- key: "componentWillUnmount",
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
- key: "render",
206
- value: function render() {
207
- var portal = null;
208
- if (this.props.visible) {
209
- portal = (0, _jsxRuntime.jsx)(PortalComponent, {
210
- getContainer: this.getContainer,
211
- didUpdate: this.didUpdate,
212
- children: this.getComponent()
213
- });
214
- }
215
- return portal;
216
- }
217
- }]);
218
- }(React.Component);
219
- // 监听窗口改变事件id 用于组件销毁的时候清除事件
220
- (0, _defineProperty2["default"])(Trigger, "defaultProps", {
221
- visible: false,
222
- // 是否显示
223
- children: null
224
- });
225
- return Trigger;
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"]);