@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.
@@ -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, getScrollTop, getElementLeft, getElementTop, getContainerVisibleHeight } from '../utils/helper-dom';
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
- export function generateTrigger(PortalComponent) {
22
- var Trigger = /*#__PURE__*/function (_React$Component) {
23
- function Trigger(props) {
24
- var _this;
25
- _classCallCheck(this, Trigger);
26
- _this = _callSuper(this, Trigger, [props]);
27
- _defineProperty(_this, "resizeObserver", null);
28
- // 显式声明 resizeObserver 属性
29
- _defineProperty(_this, "resetId", -1);
30
- _defineProperty(_this, "ref", React.createRef());
31
- // 刷新弹窗内容
32
- _defineProperty(_this, "refreshPopup", function () {
33
- _this.setState(function (prev) {
34
- return {
35
- popupRefreshKey: prev.popupRefreshKey + 1
36
- };
37
- });
38
- });
39
- // children高度变化后,从新计算高度
40
- _defineProperty(_this, "initResizeObserver", function () {
41
- var targetNode = _this.ref.current;
42
- if (!targetNode) return;
43
- // 如果已经存在 ResizeObserver,先断开连接
44
- if (_this.resizeObserver) {
45
- _this.resizeObserver.disconnect();
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
- // 初始化 ResizeObserver 并开始观察目标节点
48
- _this.resizeObserver = new ResizeObserver(function (entries) {
49
- entries.forEach(function (entry) {
50
- _this.didUpdate();
51
- });
52
- });
53
- _this.resizeObserver.observe(targetNode);
54
- });
55
- _defineProperty(_this, "bindEvent", function () {
56
- var that = _this;
57
- returnDocument().body.addEventListener('click', function (e) {
58
- var ele = e.target;
59
- while (ele != null) {
60
- if (ele === that.props.node) {
61
- return false;
62
- }
63
- ele = ele.parentNode;
64
- }
65
- that.closePopup();
66
- }, false);
67
- });
68
- _defineProperty(_this, "closePopup", function () {
69
- _this.props.visible && _this.props.closable && _this.props.hideVisible();
70
- });
71
- _defineProperty(_this, "attachParent", function (popupContainer) {
72
- var mountNode = _this.props.container || returnDocument().body;
73
- mountNode.appendChild(popupContainer);
74
- });
75
- _defineProperty(_this, "getCurrentNodePos", function () {
76
- var _this$props = _this.props,
77
- node = _this$props.node,
78
- container = _this$props.container;
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
- x: getElementLeft(node) - getElementLeft(container),
81
- y: getElementTop(node) - getElementTop(container),
82
- t: getElementTop(container),
83
- h: node.offsetHeight
84
+ popupRefreshKey: prev.popupRefreshKey + 1
84
85
  };
85
86
  });
86
- _defineProperty(_this, "getContainer", function () {
87
- var pos = _this.getCurrentNodePos();
88
- var _this$props2 = _this.props,
89
- _this$props2$innerSpa = _this$props2.innerSpacing,
90
- innerSpacing = _this$props2$innerSpa === void 0 ? 10 : _this$props2$innerSpa,
91
- zIndex = _this$props2.zIndex;
92
- var popupContainer = returnDocument().createElement('span');
93
- popupContainer.style.position = 'absolute';
94
- popupContainer.style.top = '0px';
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
- _defineProperty(_this, "getComponent", function () {
103
- return _jsx("div", {
104
- ref: _this.ref,
105
- style: {
106
- overflowX: 'hidden',
107
- overflowY: 'auto',
108
- backgroundColor: '#fff',
109
- pointerEvents: 'auto',
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
- _defineProperty(_this, "didUpdate", function () {
127
- var _this$ref;
128
- if (!_this.props.node) return false;
129
- var _this$props3 = _this.props,
130
- _this$props3$innerSpa = _this$props3.innerSpacing,
131
- innerSpacing = _this$props3$innerSpa === void 0 ? 10 : _this$props3$innerSpa,
132
- container = _this$props3.container;
133
- var pos = _this.getCurrentNodePos();
134
- var posY = pos.y - getScrollTop(container);
135
- if (!_this.ref) return false;
136
- 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;
137
- if (!realHeight) return false;
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
- _this.ref.current.offsetParent.style.transform = "translateX(".concat(pos.x, "px) translateY(").concat(topHeight, "px) translateZ(0px)");
154
- _this.ref.current.offsetParent.style.transition = 'all 0.3s';
155
- _this.ref.current.style.cssText += "max-height: ".concat(maxHeight, "px");
156
- _this.ref.current.style.cssText += "position: relative";
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
- _this.state = {
159
- popupRefreshKey: 1
160
- };
161
- return _this;
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
- _inherits(Trigger, _React$Component);
164
- return _createClass(Trigger, [{
165
- key: "componentDidMount",
166
- value: function componentDidMount() {
167
- this.resetId = winResetEvent.addEvent(this.didUpdate, this, 300);
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
- key: "componentWillUnmount",
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
- key: "render",
196
- value: function render() {
197
- var portal = null;
198
- if (this.props.visible) {
199
- portal = _jsx(PortalComponent, {
200
- getContainer: this.getContainer,
201
- didUpdate: this.didUpdate,
202
- children: this.getComponent()
203
- });
204
- }
205
- return portal;
206
- }
207
- }]);
208
- }(React.Component);
209
- // 监听窗口改变事件id 用于组件销毁的时候清除事件
210
- _defineProperty(Trigger, "defaultProps", {
211
- visible: false,
212
- // 是否显示
213
- children: null
214
- });
215
- return Trigger;
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);
@@ -138,16 +138,20 @@ var useStore = function useStore() {
138
138
  setFieldEnableAlias = _useState42[1]; // 字段名是否开启别名
139
139
  var _useState43 = useState(true),
140
140
  _useState44 = _slicedToArray(_useState43, 2),
141
- isSelectFields = _useState44[0],
142
- setIsSelectFields = _useState44[1]; // 是否默认勾选字段
143
- var _useState45 = useState(false),
141
+ groupByEnableAlias = _useState44[0],
142
+ setGroupByEnableAlias = _useState44[1]; // 聚合是否开启别名
143
+ var _useState45 = useState(true),
144
144
  _useState46 = _slicedToArray(_useState45, 2),
145
- tableFlat = _useState46[0],
146
- setTableFlat = _useState46[1]; // 是否平铺数据表
147
- var _useState47 = useState([]),
145
+ isSelectFields = _useState46[0],
146
+ setIsSelectFields = _useState46[1]; // 是否默认勾选字段
147
+ var _useState47 = useState(false),
148
148
  _useState48 = _slicedToArray(_useState47, 2),
149
- sourceTable = _useState48[0],
150
- setSourceTable = _useState48[1];
149
+ tableFlat = _useState48[0],
150
+ setTableFlat = _useState48[1]; // 是否平铺数据表
151
+ var _useState49 = useState([]),
152
+ _useState50 = _slicedToArray(_useState49, 2),
153
+ sourceTable = _useState50[0],
154
+ setSourceTable = _useState50[1];
151
155
  // 外层ref
152
156
  var popupContainer = useRef();
153
157
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
@@ -726,6 +730,8 @@ var useStore = function useStore() {
726
730
  setTableEnableAlias: setTableEnableAlias,
727
731
  fieldEnableAlias: fieldEnableAlias,
728
732
  setFieldEnableAlias: setFieldEnableAlias,
733
+ groupByEnableAlias: groupByEnableAlias,
734
+ setGroupByEnableAlias: setGroupByEnableAlias,
729
735
  isSelectFields: isSelectFields,
730
736
  setIsSelectFields: setIsSelectFields,
731
737
  tableFlat: tableFlat,
package/lib/es/index.js CHANGED
@@ -52,6 +52,8 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
52
52
  tableEnableAlias = _props$tableEnableAli === void 0 ? true : _props$tableEnableAli,
53
53
  _props$fieldEnableAli = props.fieldEnableAlias,
54
54
  fieldEnableAlias = _props$fieldEnableAli === void 0 ? true : _props$fieldEnableAli,
55
+ _props$groupByEnableA = props.groupByEnableAlias,
56
+ groupByEnableAlias = _props$groupByEnableA === void 0 ? true : _props$groupByEnableA,
55
57
  _props$isSelectFields = props.isSelectFields,
56
58
  isSelectFields = _props$isSelectFields === void 0 ? true : _props$isSelectFields,
57
59
  _props$tableFlat = props.tableFlat,
@@ -86,9 +88,10 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
86
88
  store.setIsExit(isExit);
87
89
  store.setTableEnableAlias(tableEnableAlias);
88
90
  store.setFieldEnableAlias(fieldEnableAlias);
91
+ store.setGroupByEnableAlias(groupByEnableAlias);
89
92
  store.setIsSelectFields(isSelectFields);
90
93
  store.setTableFlat(tableFlat);
91
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, isSelectFields, tableFlat]);
94
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, groupByEnableAlias, isSelectFields, tableFlat]);
92
95
  React.useImperativeHandle(ref, function () {
93
96
  return {
94
97
  // setDatasource: (list) => {
package/lib/es/types.d.ts CHANGED
@@ -40,6 +40,7 @@ export interface MetabaseProps {
40
40
  isExit?: boolean;
41
41
  tableEnableAlias?: boolean;
42
42
  fieldEnableAlias?: boolean;
43
+ groupByEnableAlias?: boolean;
43
44
  isSelectFields?: boolean;
44
45
  tableFlat?: boolean;
45
46
  onChange?: (newData: MetaListType[], curData: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",