@gingkoo/pandora-metabase 1.0.117 → 1.0.119

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.
Files changed (195) hide show
  1. package/lib/cjs/common/Portal/index.js +0 -2
  2. package/lib/cjs/common/SplitView/index.d.ts +0 -4
  3. package/lib/cjs/common/SplitView/index.js +0 -10
  4. package/lib/cjs/components/dialog/custom-column/config.js +4 -48
  5. package/lib/cjs/components/dialog/custom-column/expression-editor.js +3 -14
  6. package/lib/cjs/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
  7. package/lib/cjs/components/dialog/custom-column/expressions/suggest.js +2 -43
  8. package/lib/cjs/components/dialog/custom-column/expressions/tokenizer.js +8 -65
  9. package/lib/cjs/components/dialog/custom-column/index.js +2 -4
  10. package/lib/cjs/components/dialog/custom-column/tokenized-expression.js +2 -3
  11. package/lib/cjs/components/dialog/custom-column/tokenizedI-input.js +1 -1
  12. package/lib/cjs/components/dialog/custom-editor/index.js +2 -7
  13. package/lib/cjs/components/dialog/diff-viewer/index copy.js +1 -16
  14. package/lib/cjs/components/dialog/expression/date-format-picker.js +2 -20
  15. package/lib/cjs/components/dialog/expression/date-format.js +2 -8
  16. package/lib/cjs/components/dialog/expression/index.d.ts +0 -3
  17. package/lib/cjs/components/dialog/expression/index.js +2 -83
  18. package/lib/cjs/components/dialog/formula/index.js +1 -30
  19. package/lib/cjs/components/dialog/formula/utils.js +2 -10
  20. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
  21. package/lib/cjs/components/dialog/formula-list/CaseWhenGroup.js +109 -0
  22. package/lib/cjs/components/dialog/formula-list/LogicGroup.d.ts +9 -0
  23. package/lib/cjs/components/dialog/formula-list/LogicGroup.js +43 -0
  24. package/lib/cjs/components/dialog/formula-list/index.d.ts +3 -0
  25. package/lib/cjs/components/dialog/formula-list/index.js +966 -509
  26. package/lib/cjs/components/dialog/formula-list/index.less +724 -0
  27. package/lib/cjs/components/dialog/formula-list/utils.d.ts +0 -7
  28. package/lib/cjs/components/dialog/formula-list/utils.js +117 -112
  29. package/lib/cjs/components/dialog/select-column/index.d.ts +0 -6
  30. package/lib/cjs/components/dialog/select-column/index.js +4 -15
  31. package/lib/cjs/components/dialog/select-column-multiple/index.d.ts +0 -8
  32. package/lib/cjs/components/dialog/select-column-multiple/index.js +6 -45
  33. package/lib/cjs/components/dialog/select-join/index.d.ts +0 -5
  34. package/lib/cjs/components/dialog/select-join/index.js +0 -6
  35. package/lib/cjs/components/dialog/select-join-column/index.d.ts +0 -8
  36. package/lib/cjs/components/dialog/select-join-column/index.js +7 -21
  37. package/lib/cjs/components/dialog/select-join-column-multiple/index.d.ts +0 -8
  38. package/lib/cjs/components/dialog/select-join-column-multiple/index.js +5 -35
  39. package/lib/cjs/components/dialog/select-permission-table/index.d.ts +0 -5
  40. package/lib/cjs/components/dialog/select-permission-table/index.js +0 -6
  41. package/lib/cjs/components/dialog/select-summarize/index.d.ts +3 -3
  42. package/lib/cjs/components/dialog/select-summarize/index.js +105 -18
  43. package/lib/cjs/components/dialog/select-summarize/index.less +23 -0
  44. package/lib/cjs/components/dialog/select-table/index.d.ts +0 -6
  45. package/lib/cjs/components/dialog/select-table/index.js +1 -9
  46. package/lib/cjs/components/metabase/index.js +72 -86
  47. package/lib/cjs/components/metabase/index.less +14 -7
  48. package/lib/cjs/components/modules/components/Wrapper.js +1 -1
  49. package/lib/cjs/components/modules/components/header.js +2 -2
  50. package/lib/cjs/components/modules/components/meta-icon.d.ts +0 -3
  51. package/lib/cjs/components/modules/components/meta-icon.js +2 -47
  52. package/lib/cjs/components/modules/custom-column.js +3 -29
  53. package/lib/cjs/components/modules/enum/filter-enum.js +9 -88
  54. package/lib/cjs/components/modules/filter.js +2 -20
  55. package/lib/cjs/components/modules/index.d.ts +4 -2
  56. package/lib/cjs/components/modules/index.js +24 -1
  57. package/lib/cjs/components/modules/join-data.js +13 -291
  58. package/lib/cjs/components/modules/row-limit.js +0 -1
  59. package/lib/cjs/components/modules/sort.js +1 -61
  60. package/lib/cjs/components/modules/summarize/group-by.d.ts +0 -5
  61. package/lib/cjs/components/modules/summarize/group-by.js +231 -76
  62. package/lib/cjs/components/modules/summarize/select-index.js +96 -46
  63. package/lib/cjs/components/modules/table-data.js +11 -64
  64. package/lib/cjs/components/popup.js +26 -32
  65. package/lib/cjs/hooks/patch.d.ts +1 -0
  66. package/lib/cjs/hooks/patch.js +104 -6
  67. package/lib/cjs/hooks/patch2.js +3 -165
  68. package/lib/cjs/hooks/use-provider.js +0 -3
  69. package/lib/cjs/hooks/use-state.js +55 -135
  70. package/lib/cjs/index.js +0 -15
  71. package/lib/cjs/locale/en.js +5 -0
  72. package/lib/cjs/locale/index.js +1 -4
  73. package/lib/cjs/locale/zh.js +5 -0
  74. package/lib/cjs/sql-formula.js +0 -1
  75. package/lib/cjs/store/enum.d.ts +6 -6
  76. package/lib/cjs/store/enum.js +0 -13
  77. package/lib/cjs/store/helper.d.ts +2 -1
  78. package/lib/cjs/store/helper.js +15 -225
  79. package/lib/cjs/store/types.d.ts +45 -67
  80. package/lib/cjs/store/types.js +3 -49
  81. package/lib/cjs/types.d.ts +1 -0
  82. package/lib/cjs/utils/cookies.js +0 -3
  83. package/lib/cjs/utils/event.js +1 -1
  84. package/lib/cjs/utils/helper-dom.d.ts +1 -0
  85. package/lib/cjs/utils/helper-dom.js +17 -10
  86. package/lib/cjs/utils/helper.js +1 -24
  87. package/lib/cjs/utils/keydown.js +4 -7
  88. package/lib/cjs/utils/platform.d.ts +0 -9
  89. package/lib/cjs/utils/platform.js +0 -10
  90. package/lib/cjs/utils/selection.js +0 -6
  91. package/lib/cjs/utils/storage.d.ts +0 -9
  92. package/lib/cjs/utils/storage.js +1 -11
  93. package/lib/cjs/utils/transformSql.d.ts +5 -0
  94. package/lib/cjs/utils/transformSql.js +42 -113
  95. package/lib/cjs/utils.d.ts +1 -6
  96. package/lib/cjs/utils.js +115 -255
  97. package/lib/es/common/Portal/index.js +0 -2
  98. package/lib/es/common/SplitView/index.d.ts +0 -4
  99. package/lib/es/common/SplitView/index.js +0 -10
  100. package/lib/es/components/dialog/custom-column/config.js +4 -48
  101. package/lib/es/components/dialog/custom-column/expression-editor.js +3 -14
  102. package/lib/es/components/dialog/custom-column/expressions/suggest.d.ts +2 -34
  103. package/lib/es/components/dialog/custom-column/expressions/suggest.js +2 -43
  104. package/lib/es/components/dialog/custom-column/expressions/tokenizer.js +8 -65
  105. package/lib/es/components/dialog/custom-column/index.js +2 -4
  106. package/lib/es/components/dialog/custom-column/tokenized-expression.js +1 -3
  107. package/lib/es/components/dialog/custom-column/tokenizedI-input.js +1 -1
  108. package/lib/es/components/dialog/custom-editor/index.js +1 -7
  109. package/lib/es/components/dialog/diff-viewer/index copy.js +1 -15
  110. package/lib/es/components/dialog/expression/date-format-picker.js +2 -20
  111. package/lib/es/components/dialog/expression/date-format.js +2 -8
  112. package/lib/es/components/dialog/expression/index.d.ts +0 -3
  113. package/lib/es/components/dialog/expression/index.js +2 -82
  114. package/lib/es/components/dialog/formula/index.js +0 -30
  115. package/lib/es/components/dialog/formula/utils.js +2 -10
  116. package/lib/es/components/dialog/formula-list/CaseWhenGroup.d.ts +19 -0
  117. package/lib/es/components/dialog/formula-list/CaseWhenGroup.js +102 -0
  118. package/lib/es/components/dialog/formula-list/LogicGroup.d.ts +9 -0
  119. package/lib/es/components/dialog/formula-list/LogicGroup.js +36 -0
  120. package/lib/es/components/dialog/formula-list/index.d.ts +3 -0
  121. package/lib/es/components/dialog/formula-list/index.js +965 -509
  122. package/lib/es/components/dialog/formula-list/index.less +724 -0
  123. package/lib/es/components/dialog/formula-list/utils.d.ts +0 -7
  124. package/lib/es/components/dialog/formula-list/utils.js +117 -112
  125. package/lib/es/components/dialog/index.js +3 -3
  126. package/lib/es/components/dialog/select-column/index.d.ts +0 -6
  127. package/lib/es/components/dialog/select-column/index.js +4 -14
  128. package/lib/es/components/dialog/select-column-multiple/index.d.ts +0 -8
  129. package/lib/es/components/dialog/select-column-multiple/index.js +7 -47
  130. package/lib/es/components/dialog/select-join/index.d.ts +0 -5
  131. package/lib/es/components/dialog/select-join/index.js +0 -5
  132. package/lib/es/components/dialog/select-join-column/index.d.ts +0 -8
  133. package/lib/es/components/dialog/select-join-column/index.js +7 -20
  134. package/lib/es/components/dialog/select-join-column-multiple/index.d.ts +0 -8
  135. package/lib/es/components/dialog/select-join-column-multiple/index.js +5 -34
  136. package/lib/es/components/dialog/select-permission-table/index.d.ts +0 -5
  137. package/lib/es/components/dialog/select-permission-table/index.js +0 -5
  138. package/lib/es/components/dialog/select-summarize/index.d.ts +3 -3
  139. package/lib/es/components/dialog/select-summarize/index.js +106 -18
  140. package/lib/es/components/dialog/select-summarize/index.less +23 -0
  141. package/lib/es/components/dialog/select-table/index.d.ts +0 -6
  142. package/lib/es/components/dialog/select-table/index.js +1 -8
  143. package/lib/es/components/metabase/index.js +72 -87
  144. package/lib/es/components/metabase/index.less +14 -7
  145. package/lib/es/components/modules/components/Wrapper.js +1 -1
  146. package/lib/es/components/modules/components/header.js +2 -2
  147. package/lib/es/components/modules/components/meta-icon.d.ts +0 -3
  148. package/lib/es/components/modules/components/meta-icon.js +2 -46
  149. package/lib/es/components/modules/custom-column.js +3 -29
  150. package/lib/es/components/modules/enum/filter-enum.js +9 -88
  151. package/lib/es/components/modules/filter.js +2 -19
  152. package/lib/es/components/modules/index.d.ts +4 -2
  153. package/lib/es/components/modules/index.js +24 -1
  154. package/lib/es/components/modules/join-data.js +13 -291
  155. package/lib/es/components/modules/row-limit.js +0 -1
  156. package/lib/es/components/modules/sort.js +1 -61
  157. package/lib/es/components/modules/summarize/group-by.d.ts +0 -5
  158. package/lib/es/components/modules/summarize/group-by.js +233 -78
  159. package/lib/es/components/modules/summarize/select-index.js +96 -46
  160. package/lib/es/components/modules/table-data.js +11 -64
  161. package/lib/es/components/popup.js +27 -33
  162. package/lib/es/hooks/patch.d.ts +1 -0
  163. package/lib/es/hooks/patch.js +103 -5
  164. package/lib/es/hooks/patch2.js +2 -164
  165. package/lib/es/hooks/use-provider.js +0 -3
  166. package/lib/es/hooks/use-state.js +55 -135
  167. package/lib/es/index.js +0 -14
  168. package/lib/es/locale/en.js +5 -0
  169. package/lib/es/locale/index.js +1 -4
  170. package/lib/es/locale/zh.js +5 -0
  171. package/lib/es/sql-formula.js +0 -1
  172. package/lib/es/store/enum.d.ts +6 -6
  173. package/lib/es/store/enum.js +0 -13
  174. package/lib/es/store/helper.d.ts +2 -1
  175. package/lib/es/store/helper.js +13 -224
  176. package/lib/es/store/types.d.ts +45 -67
  177. package/lib/es/store/types.js +3 -49
  178. package/lib/es/types.d.ts +1 -0
  179. package/lib/es/types.js +1 -18
  180. package/lib/es/utils/cookies.js +0 -3
  181. package/lib/es/utils/event.js +1 -1
  182. package/lib/es/utils/helper-dom.d.ts +1 -0
  183. package/lib/es/utils/helper-dom.js +16 -9
  184. package/lib/es/utils/helper.js +1 -24
  185. package/lib/es/utils/keydown.js +4 -7
  186. package/lib/es/utils/platform.d.ts +0 -9
  187. package/lib/es/utils/platform.js +0 -10
  188. package/lib/es/utils/selection.js +0 -6
  189. package/lib/es/utils/storage.d.ts +0 -9
  190. package/lib/es/utils/storage.js +1 -10
  191. package/lib/es/utils/transformSql.d.ts +5 -0
  192. package/lib/es/utils/transformSql.js +42 -112
  193. package/lib/es/utils.d.ts +1 -6
  194. package/lib/es/utils.js +116 -255
  195. package/package.json +1 -1
@@ -1,7 +1,8 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
7
  var _excluded = ["notExistsToolbar", "toolbar"],
7
8
  _excluded2 = ["subToolbar", "notExistsColumns", "showFields", "isExit", "toolbar"];
@@ -11,7 +12,6 @@ import React, { useEffect, useState, useMemo, useRef, forwardRef } from 'react';
11
12
  import './index.less';
12
13
  import { FieldString, FieldNumber, FfPlus } from '@gingkoo/pandora-icons';
13
14
  import cx from 'classnames';
14
- // import './index.less';
15
15
  import Metabase from '../../../index';
16
16
  import { __ } from '../../../locale';
17
17
  import isEqual from 'lodash/isEqual';
@@ -31,22 +31,25 @@ import { useStore, Provider } from '../../../hooks/use-provider';
31
31
  import ItemName from '../../modules/components/item-name';
32
32
  import DiffViewer from '../diff-viewer';
33
33
  import storage from '../../../utils/storage';
34
+ import { getTopLayerZIndex } from '../../../utils/helper-dom';
35
+ import CaseWhenGroup from './CaseWhenGroup';
36
+ import LogicGroup from './LogicGroup';
37
+ var CASE_FIXED_OPERATORS = ['case', 'when', 'then', 'else', 'end'];
38
+ var LOGIC_FIXED_OPERATORS = ['(', ')'];
39
+ var LOGIC_REQUIRED_OPERATORS = ['(', ')'];
34
40
  var FormulaList = forwardRef(function (props, ref) {
35
- var _storage$_metabaseCop, _caseList2;
36
- // 响应 storage._metabaseCopyItems 变化,保证粘贴按钮能实时显示
41
+ var _storage$_metabaseCop;
37
42
  var _useState = useState((storage === null || storage === void 0 || (_storage$_metabaseCop = storage._metabaseCopyItems) === null || _storage$_metabaseCop === void 0 ? void 0 : _storage$_metabaseCop.length) || 0),
38
43
  _useState2 = _slicedToArray(_useState, 2),
39
44
  checkedItemsCount = _useState2[0],
40
45
  setCheckedItemsCount = _useState2[1];
41
46
  useEffect(function () {
42
47
  var _storage$_metabaseCop3;
43
- // 监听 _metabaseCopyItems 变化(自定义事件)
44
48
  var handler = function handler() {
45
49
  var _storage$_metabaseCop2;
46
50
  setCheckedItemsCount((storage === null || storage === void 0 || (_storage$_metabaseCop2 = storage._metabaseCopyItems) === null || _storage$_metabaseCop2 === void 0 ? void 0 : _storage$_metabaseCop2.length) || 0);
47
51
  };
48
52
  window.addEventListener('sqb-checked-items-changed', handler);
49
- // 初始化
50
53
  setCheckedItemsCount((storage === null || storage === void 0 || (_storage$_metabaseCop3 = storage._metabaseCopyItems) === null || _storage$_metabaseCop3 === void 0 ? void 0 : _storage$_metabaseCop3.length) || 0);
51
54
  return function () {
52
55
  window.removeEventListener('sqb-checked-items-changed', handler);
@@ -68,7 +71,96 @@ var FormulaList = forwardRef(function (props, ref) {
68
71
  showPreview = _props$showPreview === void 0 ? true : _props$showPreview,
69
72
  check = props.check,
70
73
  _props$_type = props._type,
71
- _type = _props$_type === void 0 ? 'filter' : _props$_type;
74
+ _type = _props$_type === void 0 ? 'filter' : _props$_type,
75
+ _props$embedded = props.embedded,
76
+ embedded = _props$embedded === void 0 ? false : _props$embedded,
77
+ _props$enableCopy = props.enableCopy,
78
+ enableCopy = _props$enableCopy === void 0 ? true : _props$enableCopy,
79
+ parentPopupChannel = props.parentPopupChannel;
80
+ var parentPopupLockCountRef = useRef(0);
81
+ var parentPopupUnlockTimerRef = useRef(null);
82
+ var setParentClosable = function setParentClosable(closable) {
83
+ if (!parentPopupChannel) return;
84
+ if (parentPopupChannel === 'secondary') {
85
+ store.setClosable2(closable);
86
+ return;
87
+ }
88
+ store.setClosable(closable);
89
+ };
90
+ var lockParentPopup = function lockParentPopup() {
91
+ if (!parentPopupChannel) return;
92
+ if (parentPopupUnlockTimerRef.current) {
93
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
94
+ parentPopupUnlockTimerRef.current = null;
95
+ }
96
+ parentPopupLockCountRef.current += 1;
97
+ if (parentPopupLockCountRef.current === 1) {
98
+ setParentClosable(false);
99
+ }
100
+ };
101
+ var unlockParentPopup = function unlockParentPopup() {
102
+ var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
103
+ if (!parentPopupChannel) return;
104
+ var runUnlock = function runUnlock() {
105
+ parentPopupUnlockTimerRef.current = null;
106
+ parentPopupLockCountRef.current = Math.max(0, parentPopupLockCountRef.current - 1);
107
+ if (parentPopupLockCountRef.current === 0) {
108
+ setParentClosable(true);
109
+ }
110
+ };
111
+ if (delay > 0) {
112
+ if (parentPopupUnlockTimerRef.current) {
113
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
114
+ }
115
+ parentPopupUnlockTimerRef.current = window.setTimeout(runUnlock, delay);
116
+ return;
117
+ }
118
+ runUnlock();
119
+ };
120
+ var openChildModal = function openChildModal(options) {
121
+ var _options$zIndex, _modalInstance;
122
+ var lockDelay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 120;
123
+ if (parentPopupChannel) {
124
+ lockParentPopup();
125
+ }
126
+ var modalZIndex = (_options$zIndex = options.zIndex) !== null && _options$zIndex !== void 0 ? _options$zIndex : getTopLayerZIndex() + 1;
127
+ var closed = false;
128
+ var modalInstance;
129
+ var releaseParentPopup = function releaseParentPopup() {
130
+ if (!parentPopupChannel || closed) return;
131
+ closed = true;
132
+ unlockParentPopup(lockDelay);
133
+ };
134
+ modalInstance = Modal2.openModal(_objectSpread(_objectSpread({
135
+ zIndex: modalZIndex
136
+ }, options), {}, {
137
+ onClose: function onClose() {
138
+ var _options$onClose;
139
+ releaseParentPopup();
140
+ (_options$onClose = options.onClose) === null || _options$onClose === void 0 || _options$onClose.call(options);
141
+ }
142
+ }));
143
+ var originalClose = (_modalInstance = modalInstance) === null || _modalInstance === void 0 || (_modalInstance = _modalInstance.close) === null || _modalInstance === void 0 ? void 0 : _modalInstance.bind(modalInstance);
144
+ if (originalClose) {
145
+ modalInstance.close = function () {
146
+ releaseParentPopup();
147
+ return originalClose.apply(void 0, arguments);
148
+ };
149
+ }
150
+ return modalInstance;
151
+ };
152
+ useEffect(function () {
153
+ return function () {
154
+ if (parentPopupUnlockTimerRef.current) {
155
+ window.clearTimeout(parentPopupUnlockTimerRef.current);
156
+ parentPopupUnlockTimerRef.current = null;
157
+ }
158
+ if (parentPopupLockCountRef.current > 0) {
159
+ parentPopupLockCountRef.current = 0;
160
+ setParentClosable(true);
161
+ }
162
+ };
163
+ }, [parentPopupChannel]);
72
164
  var mergedTypes = useMemo(function () {
73
165
  var map = new Map();
74
166
  [].concat(_toConsumableArray(_customTypes), _toConsumableArray(otherTypes)).forEach(function (item) {
@@ -90,15 +182,12 @@ var FormulaList = forwardRef(function (props, ref) {
90
182
  return map;
91
183
  }, [otherTypes]);
92
184
  var caseList = value || [];
93
- // const [caseList, setCaseListState] = useState<AtomsItem[]>(cloneDeep(value));
94
185
  var caseListRef = useRef(caseList);
95
- var isSettingCaseList = useRef(false);
96
186
  var operatorList = useMemo(function () {
97
187
  if (store.operatorList.length > 0) {
98
188
  return store.operatorList;
99
- } else {
100
- return __operatorList;
101
189
  }
190
+ return __operatorList;
102
191
  }, [store.operatorList]);
103
192
  var _useState3 = useState(''),
104
193
  _useState4 = _slicedToArray(_useState3, 2),
@@ -109,6 +198,9 @@ var FormulaList = forwardRef(function (props, ref) {
109
198
  previewMode = _useState6[0],
110
199
  setPreviewMode = _useState6[1];
111
200
  var _useState7 = useState(function () {
201
+ if (!enableCopy) {
202
+ return false;
203
+ }
112
204
  if (store.copyType.includes(FormulaTypeEnum.ALL)) {
113
205
  return true;
114
206
  }
@@ -117,34 +209,221 @@ var FormulaList = forwardRef(function (props, ref) {
117
209
  _useState8 = _slicedToArray(_useState7, 2),
118
210
  isCopy = _useState8[0],
119
211
  setIsCopy = _useState8[1];
120
- // const [formulaList, setFunctionList] = useState<{ [params: string]: FormulaTemplatesItem }>(
121
- // );
122
212
  var formulaList = useMemo(function () {
123
213
  return getObjTem(store.formulaTemplates);
124
214
  }, [store.formulaTemplates]);
125
- useEffect(function () {
126
- setOldCode(getPreviewStr(caseList));
127
- }, []);
128
215
  var _useState9 = useState(''),
129
216
  _useState0 = _slicedToArray(_useState9, 2),
130
217
  filterVal = _useState0[0],
131
218
  setFilterVal = _useState0[1];
132
219
  var setCaseList = function setCaseList(data) {
133
- var quotes = data.map(function (v, i) {
134
- if (v !== null && v !== void 0 && v.quotes) {
135
- return v === null || v === void 0 ? void 0 : v.quotes;
136
- } else if (v !== null && v !== void 0 && v.fieldName) {
137
- return v === null || v === void 0 ? void 0 : v.fieldName;
138
- } else {
139
- return v.val;
140
- }
220
+ var quotes = data.map(function (v) {
221
+ if (v !== null && v !== void 0 && v.quotes) return v.quotes;
222
+ if (v !== null && v !== void 0 && v.fieldName) return v.fieldName;
223
+ return v === null || v === void 0 ? void 0 : v.val;
141
224
  }).join(' ');
142
- isSettingCaseList.current = true;
143
- // setCaseListState(data);
144
225
  caseList = data;
145
226
  caseListRef.current = data;
146
227
  onChange === null || onChange === void 0 || onChange(data, quotes);
147
228
  };
229
+ var updateAtomAt = function updateAtomAt(index, nextItem) {
230
+ var nextList = caseList.slice();
231
+ nextList[index] = nextItem;
232
+ setCaseList(nextList);
233
+ };
234
+ function getItemDisplayText(v) {
235
+ if (!v) return '';
236
+ if (v.quotes) return v.quotes;
237
+ if (v.fieldName) return v.fieldName;
238
+ if (v.type === AtomsTypeEnum.FORMULA) {
239
+ return v.name ? getQuotes(v, v.args, formulaList) : '';
240
+ }
241
+ if (v.type === AtomsTypeEnum.CASE_WHEN) {
242
+ var caseValueText = (v.caseValue || []).map(function (item) {
243
+ return getItemDisplayText(item);
244
+ }).join(' ');
245
+ var branchText = (v.branches || []).map(function (branch) {
246
+ var whenText = (branch.when || []).map(function (item) {
247
+ return getItemDisplayText(item);
248
+ }).join(' ');
249
+ var thenText = (branch.then || []).map(function (item) {
250
+ return getItemDisplayText(item);
251
+ }).join(' ');
252
+ return "when ".concat(whenText, " then ").concat(thenText).trim();
253
+ }).join(' ');
254
+ var elseText = (v.elseValue || []).length ? " else ".concat((v.elseValue || []).map(function (item) {
255
+ return getItemDisplayText(item);
256
+ }).join(' ')) : '';
257
+ return "case ".concat(caseValueText, " ").concat(branchText).concat(elseText, " end").replace(/\s+/g, ' ').trim();
258
+ }
259
+ if (v.type === AtomsTypeEnum.AND_OR) {
260
+ var listText = (v.list || []).map(function (item) {
261
+ return getItemDisplayText(item);
262
+ }).join(' ');
263
+ return "".concat(v.operator || 'and', " ( ").concat(listText, " )").replace(/\s+/g, ' ').trim();
264
+ }
265
+ if (Array.isArray(v.val)) {
266
+ return v.val.join(', ');
267
+ }
268
+ return v.val || '';
269
+ }
270
+ var getPreviewStr = function getPreviewStr() {
271
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
272
+ return data.map(function (v) {
273
+ if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
274
+ return "\r".concat(v.val, "\r");
275
+ }
276
+ if (v.type === AtomsTypeEnum.OPERATOR && (v.val === '(' || v.val === ')')) {
277
+ return "".concat(v.val);
278
+ }
279
+ return getItemDisplayText(v);
280
+ }).join(' ');
281
+ };
282
+ useEffect(function () {
283
+ setOldCode(getPreviewStr(caseList));
284
+ }, []);
285
+ var renderTokenContent = function renderTokenContent(children) {
286
+ return _jsx("span", {
287
+ className: 'Sqb-TokenContent',
288
+ children: children
289
+ });
290
+ };
291
+ var renderNestedFormulaList = function renderNestedFormulaList(list, onNestedChange) {
292
+ return _jsx("div", {
293
+ className: 'Sqb-NestedFormulaList',
294
+ children: _jsx(FormulaList, {
295
+ ref: ref,
296
+ embedded: true,
297
+ value: list,
298
+ data: data,
299
+ exitData: exitData,
300
+ onChange: function onChange(atoms) {
301
+ return onNestedChange(atoms);
302
+ },
303
+ customTypes: _customTypes,
304
+ otherTypes: otherTypes,
305
+ isCustom: isCustom,
306
+ showPreview: false,
307
+ check: check,
308
+ _type: _type,
309
+ parentPopupChannel: parentPopupChannel
310
+ })
311
+ });
312
+ };
313
+ var renderCaseWhenEditor = function renderCaseWhenEditor(value, index) {
314
+ return _jsx(CaseWhenGroup, {
315
+ caseValueContent: renderNestedFormulaList(value.caseValue || [], function (nextList) {
316
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
317
+ caseValue: nextList
318
+ }));
319
+ }),
320
+ branches: (value.branches || []).map(function (branch, branchIndex) {
321
+ return {
322
+ key: "case-".concat(index, "-branch-").concat(branchIndex),
323
+ whenContent: renderNestedFormulaList(branch.when || [], function (nextList) {
324
+ var nextBranches = (value.branches || []).slice();
325
+ nextBranches[branchIndex] = _objectSpread(_objectSpread({}, branch), {}, {
326
+ when: nextList
327
+ });
328
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
329
+ branches: nextBranches
330
+ }));
331
+ }),
332
+ thenContent: renderNestedFormulaList(branch.then || [], function (nextList) {
333
+ var nextBranches = (value.branches || []).slice();
334
+ nextBranches[branchIndex] = _objectSpread(_objectSpread({}, branch), {}, {
335
+ then: nextList
336
+ });
337
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
338
+ branches: nextBranches
339
+ }));
340
+ }),
341
+ onAddAfter: function onAddAfter(e) {
342
+ e.stopPropagation();
343
+ var nextBranches = (value.branches || []).slice();
344
+ nextBranches.splice(branchIndex + 1, 0, {
345
+ when: [{
346
+ val: '',
347
+ type: AtomsTypeEnum.UNKNOWN
348
+ }],
349
+ then: [{
350
+ val: '',
351
+ type: AtomsTypeEnum.UNKNOWN
352
+ }]
353
+ });
354
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
355
+ branches: nextBranches
356
+ }));
357
+ },
358
+ onDelete: function onDelete(e) {
359
+ e.stopPropagation();
360
+ var nextBranches = (value.branches || []).filter(function (_, currentIndex) {
361
+ return currentIndex !== branchIndex;
362
+ });
363
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
364
+ branches: nextBranches
365
+ }));
366
+ }
367
+ };
368
+ }),
369
+ elseContent: value.elseValue ? renderNestedFormulaList(value.elseValue || [], function (nextList) {
370
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
371
+ elseValue: nextList
372
+ }));
373
+ }) : undefined,
374
+ onAddBranch: function onAddBranch(e) {
375
+ e.stopPropagation();
376
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
377
+ branches: [].concat(_toConsumableArray(value.branches || []), [{
378
+ when: [{
379
+ val: '',
380
+ type: AtomsTypeEnum.UNKNOWN
381
+ }],
382
+ then: [{
383
+ val: '',
384
+ type: AtomsTypeEnum.UNKNOWN
385
+ }]
386
+ }])
387
+ }));
388
+ },
389
+ onAddElse: function onAddElse(e) {
390
+ e.stopPropagation();
391
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
392
+ elseValue: [{
393
+ val: '',
394
+ type: AtomsTypeEnum.UNKNOWN
395
+ }]
396
+ }));
397
+ },
398
+ onRemoveElse: function onRemoveElse(e) {
399
+ e.stopPropagation();
400
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
401
+ elseValue: undefined
402
+ }));
403
+ },
404
+ onDeleteCase: function onDeleteCase(e) {
405
+ return handleDel(e, index);
406
+ }
407
+ });
408
+ };
409
+ var renderAndOrEditor = function renderAndOrEditor(value, index) {
410
+ return _jsx(LogicGroup, {
411
+ operator: value.operator || 'and',
412
+ onToggleOperator: function onToggleOperator() {
413
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
414
+ operator: value.operator === 'or' ? 'and' : 'or'
415
+ }));
416
+ },
417
+ content: renderNestedFormulaList(value.list || [], function (nextList) {
418
+ updateAtomAt(index, _objectSpread(_objectSpread({}, value), {}, {
419
+ list: nextList
420
+ }));
421
+ }),
422
+ onDelete: function onDelete(e) {
423
+ return handleDel(e, index);
424
+ }
425
+ });
426
+ };
148
427
  var _useState1 = useState(-1),
149
428
  _useState10 = _slicedToArray(_useState1, 2),
150
429
  ind = _useState10[0],
@@ -162,56 +441,194 @@ var FormulaList = forwardRef(function (props, ref) {
162
441
  isCheck = _useState14[0],
163
442
  setIsCheck = _useState14[1];
164
443
  var myInstanceIdRef = useRef(Math.random().toString(36).slice(2));
165
- var _useState15 = useState(!!window.__sqb_selection_active__),
444
+ var _useState15 = useState(null),
166
445
  _useState16 = _slicedToArray(_useState15, 2),
167
- globalSelectionActive = _useState16[0],
168
- setGlobalSelectionActive = _useState16[1];
169
- var _useState17 = useState(window.__sqb_selection_owner__ || null),
446
+ hoveredCaseGroupKey = _useState16[0],
447
+ setHoveredCaseGroupKey = _useState16[1];
448
+ var _useState17 = useState(!!window.__sqb_selection_active__),
170
449
  _useState18 = _slicedToArray(_useState17, 2),
171
- globalSelectionOwner = _useState18[0],
172
- setGlobalSelectionOwner = _useState18[1];
173
- var _useState19 = useState([]),
450
+ globalSelectionActive = _useState18[0],
451
+ setGlobalSelectionActive = _useState18[1];
452
+ var _useState19 = useState(window.__sqb_selection_owner__ || null),
174
453
  _useState20 = _slicedToArray(_useState19, 2),
175
- selectedIndices = _useState20[0],
176
- setSelectedIndices = _useState20[1];
177
- var _useState21 = useState(null),
454
+ globalSelectionOwner = _useState20[0],
455
+ setGlobalSelectionOwner = _useState20[1];
456
+ var _useState21 = useState([]),
178
457
  _useState22 = _slicedToArray(_useState21, 2),
179
- hoveredCopyIndex = _useState22[0],
180
- setHoveredCopyIndex = _useState22[1];
181
- useEffect(function () {
182
- // Skip if this update came from setCaseList (to avoid infinite loop)
183
- if (isSettingCaseList.current) {
184
- isSettingCaseList.current = false;
185
- return;
458
+ selectedIndices = _useState22[0],
459
+ setSelectedIndices = _useState22[1];
460
+ var _useState23 = useState(null),
461
+ _useState24 = _slicedToArray(_useState23, 2),
462
+ hoveredCopyIndex = _useState24[0],
463
+ setHoveredCopyIndex = _useState24[1];
464
+ var getCaseGroupEnd = function getCaseGroupEnd(list, startIndex) {
465
+ var depth = 0;
466
+ for (var index = startIndex; index < list.length; index++) {
467
+ var item = list[index];
468
+ if (item.type !== AtomsTypeEnum.OPERATOR) continue;
469
+ if (item.val === 'case') depth += 1;
470
+ if (item.val === 'end') {
471
+ depth -= 1;
472
+ if (depth === 0) {
473
+ return index;
474
+ }
475
+ }
186
476
  }
187
- var _errorInfo = validateExpressionIntegrity(caseList);
188
- setErrorInfo(_errorInfo);
477
+ return startIndex;
478
+ };
479
+ var getLogicGroupIndices = function getLogicGroupIndices(list, startIndex) {
480
+ var _list, _list2;
481
+ var prevItem = list[startIndex - 1];
482
+ var currentItem = list[startIndex];
483
+ if (!currentItem) return [];
484
+ if (currentItem.type === AtomsTypeEnum.OPERATOR && ['and', 'or'].includes(currentItem.val) && ((_list = list[startIndex + 1]) === null || _list === void 0 ? void 0 : _list.type) === AtomsTypeEnum.OPERATOR && ((_list2 = list[startIndex + 1]) === null || _list2 === void 0 ? void 0 : _list2.val) === '(') {
485
+ var depth = 0;
486
+ var _indices = [];
487
+ for (var index = startIndex; index < list.length; index++) {
488
+ var item = list[index];
489
+ _indices.push(index);
490
+ if ((item === null || item === void 0 ? void 0 : item.type) !== AtomsTypeEnum.OPERATOR) continue;
491
+ if (item.val === '(') depth += 1;
492
+ if (item.val === ')') {
493
+ depth -= 1;
494
+ if (depth === 0) {
495
+ return _indices;
496
+ }
497
+ }
498
+ }
499
+ return _indices;
500
+ }
501
+ if (currentItem.type === AtomsTypeEnum.OPERATOR) return [];
502
+ if ((prevItem === null || prevItem === void 0 ? void 0 : prevItem.type) === AtomsTypeEnum.OPERATOR && ['and', 'or'].includes((prevItem === null || prevItem === void 0 ? void 0 : prevItem.val) || '')) {
503
+ return [];
504
+ }
505
+ var indices = [startIndex];
506
+ var cursor = startIndex;
507
+ while (cursor + 2 < list.length) {
508
+ var operatorItem = list[cursor + 1];
509
+ var nextItem = list[cursor + 2];
510
+ if ((operatorItem === null || operatorItem === void 0 ? void 0 : operatorItem.type) !== AtomsTypeEnum.OPERATOR || !['and', 'or'].includes((operatorItem === null || operatorItem === void 0 ? void 0 : operatorItem.val) || '') || !nextItem || nextItem.type === AtomsTypeEnum.OPERATOR) {
511
+ break;
512
+ }
513
+ indices.push(cursor + 1, cursor + 2);
514
+ cursor += 2;
515
+ }
516
+ return indices.length >= 3 ? indices : [];
517
+ };
518
+ var renderGroups = useMemo(function () {
519
+ var groups = [];
520
+ var index = 0;
521
+ while (index < caseList.length) {
522
+ var item = caseList[index];
523
+ if ((item === null || item === void 0 ? void 0 : item.type) === AtomsTypeEnum.OPERATOR && (item === null || item === void 0 ? void 0 : item.val) === 'case') {
524
+ var endIndex = getCaseGroupEnd(caseList, index);
525
+ groups.push({
526
+ type: 'caseWhen',
527
+ indices: Array.from({
528
+ length: endIndex - index + 1
529
+ }, function (_, offset) {
530
+ return index + offset;
531
+ })
532
+ });
533
+ index = endIndex + 1;
534
+ continue;
535
+ }
536
+ var logicIndices = getLogicGroupIndices(caseList, index);
537
+ if (logicIndices.length > 0) {
538
+ groups.push({
539
+ type: 'logic',
540
+ indices: logicIndices
541
+ });
542
+ index = logicIndices[logicIndices.length - 1] + 1;
543
+ continue;
544
+ }
545
+ groups.push({
546
+ type: 'single',
547
+ indices: [index]
548
+ });
549
+ index += 1;
550
+ }
551
+ return groups;
189
552
  }, [caseList]);
190
- // 获取预览字符串
191
- var getPreviewStr = function getPreviewStr() {
192
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
193
- return data.map(function (v, i) {
194
- if (v !== null && v !== void 0 && v.quotes) {
195
- return v === null || v === void 0 ? void 0 : v.quotes;
196
- } else if (v !== null && v !== void 0 && v.fieldName) {
197
- return v === null || v === void 0 ? void 0 : v.fieldName;
198
- } else {
199
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
200
- return "\r".concat(v.val, "\r");
553
+ var getCaseGroupRows = function getCaseGroupRows(indices) {
554
+ var rows = [];
555
+ var currentRow = [];
556
+ var depth = 0;
557
+ indices.forEach(function (itemIndex) {
558
+ var item = caseList[itemIndex];
559
+ if ((item === null || item === void 0 ? void 0 : item.type) === AtomsTypeEnum.OPERATOR) {
560
+ if (item.val === 'case') {
561
+ if (depth === 0) {
562
+ if (currentRow.length > 0) rows.push(currentRow);
563
+ currentRow = [itemIndex];
564
+ depth = 1;
565
+ return;
566
+ }
567
+ depth += 1;
568
+ }
569
+ if (depth === 1 && (item.val === 'when' || item.val === 'else')) {
570
+ if (currentRow.length > 0) rows.push(currentRow);
571
+ currentRow = [itemIndex];
572
+ return;
201
573
  }
202
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === '(' || v.val === ')')) {
203
- return "".concat(v.val);
574
+ if (item.val === 'end') {
575
+ depth -= 1;
576
+ if (depth === 0) {
577
+ if (currentRow.length > 0) rows.push(currentRow);
578
+ rows.push([itemIndex]);
579
+ currentRow = [];
580
+ return;
581
+ }
204
582
  }
205
- return v.val;
206
583
  }
207
- }).join(' ');
584
+ currentRow.push(itemIndex);
585
+ });
586
+ if (currentRow.length > 0) {
587
+ rows.push(currentRow);
588
+ }
589
+ return rows;
590
+ };
591
+ var isFixedCaseOperator = function isFixedCaseOperator(item) {
592
+ return item.type === AtomsTypeEnum.OPERATOR && CASE_FIXED_OPERATORS.includes(item.val || '');
593
+ };
594
+ var isFixedLogicOperator = function isFixedLogicOperator(item) {
595
+ return item.type === AtomsTypeEnum.OPERATOR && LOGIC_FIXED_OPERATORS.includes(item.val || '');
596
+ };
597
+ var isRequiredLogicOperator = function isRequiredLogicOperator(item) {
598
+ return item.type === AtomsTypeEnum.OPERATOR && LOGIC_REQUIRED_OPERATORS.includes(item.val || '');
599
+ };
600
+ var canDeleteItem = function canDeleteItem(item, groupType) {
601
+ if (groupType === 'logic') {
602
+ return !isRequiredLogicOperator(item);
603
+ }
604
+ return !isFixedCaseOperator(item);
208
605
  };
606
+ var canShowInsertArrows = function canShowInsertArrows(item, groupType) {
607
+ if (groupType === 'caseWhen') {
608
+ return !isFixedCaseOperator(item);
609
+ }
610
+ if (groupType === 'logic') {
611
+ return !isRequiredLogicOperator(item);
612
+ }
613
+ return !(item.type === AtomsTypeEnum.OPERATOR && ['case', 'end'].includes(item.val));
614
+ };
615
+ useEffect(function () {
616
+ var _errorInfo = validateExpressionIntegrity(caseList);
617
+ setErrorInfo(_errorInfo);
618
+ }, [caseList]);
209
619
  function closePopup() {
210
620
  store.setPopup({
211
621
  visible: false
212
622
  });
213
623
  }
214
- // 连接符
624
+ var getSelectTriggerProps = function getSelectTriggerProps() {
625
+ return {
626
+ clickToClose: true,
627
+ style: {
628
+ zIndex: getTopLayerZIndex() + 1
629
+ }
630
+ };
631
+ };
215
632
  var selectOperator = function selectOperator(props) {
216
633
  var triggerElement = props.triggerElement,
217
634
  ind = props.ind,
@@ -227,9 +644,7 @@ var FormulaList = forwardRef(function (props, ref) {
227
644
  },
228
645
  showSearch: true,
229
646
  trigger: trigger,
230
- triggerProps: {
231
- clickToClose: true
232
- },
647
+ triggerProps: getSelectTriggerProps(),
233
648
  virtualListProps: {
234
649
  threshold: null
235
650
  },
@@ -246,6 +661,9 @@ var FormulaList = forwardRef(function (props, ref) {
246
661
  onVisibleChange: function onVisibleChange(visible) {
247
662
  if (visible) {
248
663
  setFilterVal('');
664
+ lockParentPopup();
665
+ } else {
666
+ unlockParentPopup(300);
249
667
  }
250
668
  },
251
669
  value: '',
@@ -259,7 +677,6 @@ var FormulaList = forwardRef(function (props, ref) {
259
677
  },
260
678
  value: filterVal,
261
679
  placeholder: __('SqlQueryBuilder.pleaseEnter'),
262
- // size='large'
263
680
  onChange: function onChange(val) {
264
681
  setFilterVal(val);
265
682
  }
@@ -277,7 +694,6 @@ var FormulaList = forwardRef(function (props, ref) {
277
694
  })]
278
695
  });
279
696
  };
280
- // 字段
281
697
  function handleField(e, i, val) {
282
698
  store.setPopup({
283
699
  visible: true,
@@ -288,7 +704,7 @@ var FormulaList = forwardRef(function (props, ref) {
288
704
  multiple: false,
289
705
  value: [val],
290
706
  theme: ColumnsPopupThemeEnum.skyBlue,
291
- onSelect: function onSelect(fields, quotes) {
707
+ onSelect: function onSelect(fields) {
292
708
  var _caseList = caseList.slice();
293
709
  _caseList[i] = fields[0];
294
710
  setCaseList(_caseList);
@@ -297,7 +713,6 @@ var FormulaList = forwardRef(function (props, ref) {
297
713
  })
298
714
  });
299
715
  }
300
- // 常量
301
716
  var handleConstant = function handleConstant(val, i) {
302
717
  var _caseList = caseList.slice();
303
718
  var currentItem = _caseList[i];
@@ -317,7 +732,6 @@ var FormulaList = forwardRef(function (props, ref) {
317
732
  _caseList = insertTemplateAt(oldVal, val, _caseList, i);
318
733
  setCaseList(_caseList);
319
734
  };
320
- // 表达式
321
735
  function handleExpression(e, i, val) {
322
736
  store.setPopup({
323
737
  visible: true,
@@ -338,7 +752,6 @@ var FormulaList = forwardRef(function (props, ref) {
338
752
  })
339
753
  });
340
754
  }
341
- // 删除
342
755
  function handleDel(e, index) {
343
756
  e.stopPropagation();
344
757
  var _caseList = caseList.slice();
@@ -346,13 +759,21 @@ var FormulaList = forwardRef(function (props, ref) {
346
759
  setCaseList(_caseList);
347
760
  closePopup();
348
761
  }
349
- // 重置粘贴状态
762
+ function handleDelItems(e, indices) {
763
+ e.stopPropagation();
764
+ if (!indices.length) return;
765
+ var indexSet = new Set(indices);
766
+ var _caseList = caseList.filter(function (_, itemIndex) {
767
+ return !indexSet.has(itemIndex);
768
+ });
769
+ setCaseList(_caseList);
770
+ closePopup();
771
+ }
350
772
  function initPaste() {
351
773
  var isDispatch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
352
774
  setSelectedIndices([]);
353
775
  setLocalItem([]);
354
776
  setIsCheck(false);
355
- //有些事不需要通知别的过滤器重置勾选状态
356
777
  if (isDispatch) {
357
778
  window.dispatchEvent(new CustomEvent('sqb-check-active', {
358
779
  detail: {
@@ -361,11 +782,9 @@ var FormulaList = forwardRef(function (props, ref) {
361
782
  }));
362
783
  }
363
784
  }
364
- // 粘贴到末尾并清除勾选
365
785
  function handlePaste() {
366
786
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
367
787
  var _caseList = caseList.slice();
368
- // determine items to paste (selected items have priority)
369
788
  var itemsToPaste = storage._metabaseCopyItems || [];
370
789
  itemsToPaste = changeCopyField(itemsToPaste, data);
371
790
  if (itemsToPaste.length) {
@@ -378,13 +797,10 @@ var FormulaList = forwardRef(function (props, ref) {
378
797
  }
379
798
  initPaste();
380
799
  }
381
- // 将值存在 localStorage
382
800
  function setLocalItem(next) {
383
801
  var _caseList = caseList.slice();
384
- // determine items to paste (selected items have priority)
385
802
  var itemsToPaste = [];
386
803
  if (next.length > 0) {
387
- // paste all selected items
388
804
  itemsToPaste = next.map(function (i) {
389
805
  return _caseList[i] ? cloneDeep(_caseList[i]) : null;
390
806
  }).filter(Boolean);
@@ -406,11 +822,33 @@ var FormulaList = forwardRef(function (props, ref) {
406
822
  });
407
823
  setSelectedIndices(next);
408
824
  setLocalItem(next);
409
- // const active = next.length > 0;
410
825
  }
826
+ function toggleSelectGroup(indices, checked) {
827
+ var next = selectedIndices.slice();
828
+ if (checked) {
829
+ indices.forEach(function (index) {
830
+ if (!next.includes(index)) next.push(index);
831
+ });
832
+ } else {
833
+ var indexSet = new Set(indices);
834
+ next = next.filter(function (index) {
835
+ return !indexSet.has(index);
836
+ });
837
+ }
838
+ next = next.sort(function (a, b) {
839
+ return a - b;
840
+ });
841
+ setSelectedIndices(next);
842
+ setLocalItem(next);
843
+ }
844
+ var isGroupSelected = function isGroupSelected(indices) {
845
+ return indices.length > 0 && indices.every(function (index) {
846
+ return selectedIndices.includes(index);
847
+ });
848
+ };
411
849
  var copyAll = function copyAll() {
412
850
  _setIsCheck(true);
413
- var allIndices = caseList.map(function (v, i) {
851
+ var allIndices = caseList.map(function (_, i) {
414
852
  return i;
415
853
  });
416
854
  setSelectedIndices(allIndices);
@@ -419,11 +857,9 @@ var FormulaList = forwardRef(function (props, ref) {
419
857
  var delSelect = function delSelect() {
420
858
  Modal.confirm({
421
859
  title: __('metabase.prompt'),
422
- // 提示
423
860
  content: __('customColumn.confirmDelete'),
424
- // 确认删除吗
425
861
  onOk: function () {
426
- var _onOk = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
862
+ var _onOk = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
427
863
  var selectedIndexSet, _caseList;
428
864
  return _regeneratorRuntime.wrap(function (_context) {
429
865
  while (1) switch (_context.prev = _context.next) {
@@ -448,7 +884,6 @@ var FormulaList = forwardRef(function (props, ref) {
448
884
  onCancel: function onCancel() {}
449
885
  });
450
886
  };
451
- // 开启关闭勾选,清除别的过滤器勾选
452
887
  var _setIsCheck = function _setIsCheck(val) {
453
888
  initPaste();
454
889
  setIsCheck(val);
@@ -466,7 +901,6 @@ var FormulaList = forwardRef(function (props, ref) {
466
901
  window.removeEventListener('sqb-check-active', onCheckActive);
467
902
  };
468
903
  }, []);
469
- // 添加
470
904
  var addOperator = function addOperator(type, index, position) {
471
905
  var _caseList = caseList.slice() || [];
472
906
  var _ind = index;
@@ -486,14 +920,59 @@ var FormulaList = forwardRef(function (props, ref) {
486
920
  _caseList.splice(index + 1, 0, temItem);
487
921
  _ind = index + 1;
488
922
  } else {
489
- //替换
490
923
  _caseList.splice(index, 1, temItem);
491
924
  _ind = index;
492
925
  }
493
926
  setCaseList(_caseList);
494
927
  return _ind < 0 ? 0 : _ind;
495
928
  };
496
- // NotExists 窗口
929
+ var getItemNameProps = function getItemNameProps(v) {
930
+ if (v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.EXISTS) {
931
+ return {
932
+ isError: isExistsError(v.notExists, store.existsError)
933
+ };
934
+ }
935
+ if (v.type === AtomsTypeEnum.SUB_QUERY) {
936
+ return {
937
+ isError: isExistsError(v.subQuery, store.existsError)
938
+ };
939
+ }
940
+ if (v.type === AtomsTypeEnum.FIELD) {
941
+ return {
942
+ isError: isError(v, data)
943
+ };
944
+ }
945
+ if (v.type === AtomsTypeEnum.CONSTANT) {
946
+ return {
947
+ isError: !!(v.id || v.val) && !getConstantLabel(store.constantList, v.id || v.val),
948
+ message: '常量丢失'
949
+ };
950
+ }
951
+ if (otherTypeMap.has(String(v.type))) {
952
+ var currentOtherType = otherTypeMap.get(String(v.type));
953
+ var listSource = (currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.list) || [];
954
+ return {
955
+ isError: !!(v.id || v.val) && !getConstantLabel(listSource, v.id || v.val),
956
+ message: "".concat(currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.label, "\u4E22\u5931")
957
+ };
958
+ }
959
+ if (v.type === AtomsTypeEnum.EXPRESSION) {
960
+ return {
961
+ isError: isError(v, data)
962
+ };
963
+ }
964
+ if (v.type === AtomsTypeEnum.FORMULA) {
965
+ var formulaMissing = formulaIsError(v, formulaList);
966
+ return {
967
+ isError: isError(v, data) || formulaMissing,
968
+ message: formulaMissing ? '公式丢失' : ''
969
+ };
970
+ }
971
+ return {
972
+ isError: false,
973
+ message: ''
974
+ };
975
+ };
497
976
  var showNotExists = function showNotExists(i) {
498
977
  var _caseList$i, _caseList$i2;
499
978
  var _store$preProps = store.preProps,
@@ -502,23 +981,22 @@ var FormulaList = forwardRef(function (props, ref) {
502
981
  other = _objectWithoutProperties(_store$preProps, _excluded);
503
982
  var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
504
983
  var oldList = cloneDeep(((_caseList$i2 = caseList[i]) === null || _caseList$i2 === void 0 ? void 0 : _caseList$i2.notExists) || []);
984
+ var childModalZIndex = getTopLayerZIndex() + 1;
505
985
  var _toolbar = notExistsToolbar || toolbar;
506
- // _toolbar = _toolbar.filter((v: string) => v !== 'group'); // 子查询不需要分组
507
- var o = Modal2.openModal({
986
+ var o = openChildModal({
987
+ zIndex: childModalZIndex,
508
988
  title: caseList[i].type,
509
- transparentMask: true,
989
+ transparentMask: false,
510
990
  content: _jsx(_Fragment, {
511
991
  children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
992
+ popupZIndex: childModalZIndex + 1,
512
993
  notExistsColumns: exitData,
513
- // showFields={false}
514
994
  isExit: true,
515
- // showSubquery={subShowSubquery}
516
995
  toolbar: _toolbar,
517
996
  btnText: __('SqlQueryBuilder.confirm'),
518
997
  value: cloneDeep(_value),
519
998
  onOk: function onOk(newList) {
520
999
  try {
521
- // 子查询未改变不做操作
522
1000
  if (isEqual(newList, oldList)) {
523
1001
  o.close();
524
1002
  return;
@@ -532,18 +1010,14 @@ var FormulaList = forwardRef(function (props, ref) {
532
1010
  onChange === null || onChange === void 0 || onChange(caseList, '');
533
1011
  setCaseList(_toConsumableArray(caseList));
534
1012
  o.close();
535
- } catch (e) {
536
- console.warn(e);
537
- } finally {
1013
+ } catch (e) {} finally {
538
1014
  o.close();
539
1015
  }
540
1016
  }
541
1017
  }))
542
- }),
543
- onClose: function onClose() {}
1018
+ })
544
1019
  });
545
1020
  };
546
- // 子查询 窗口
547
1021
  var showSubQuery = function showSubQuery(i) {
548
1022
  var _caseList$i3, _caseList$i4;
549
1023
  var _store$preProps2 = store.preProps,
@@ -555,12 +1029,15 @@ var FormulaList = forwardRef(function (props, ref) {
555
1029
  other = _objectWithoutProperties(_store$preProps2, _excluded2);
556
1030
  var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
557
1031
  var oldList = cloneDeep(((_caseList$i4 = caseList[i]) === null || _caseList$i4 === void 0 ? void 0 : _caseList$i4.subQuery) || []);
1032
+ var childModalZIndex = getTopLayerZIndex() + 1;
558
1033
  var _toolbar = subToolbar || toolbar;
559
- var o = Modal2.openModal({
1034
+ var o = openChildModal({
1035
+ zIndex: childModalZIndex,
560
1036
  title: __('SqlQueryBuilder.subquery'),
561
- transparentMask: true,
1037
+ transparentMask: false,
562
1038
  content: _jsx(_Fragment, {
563
1039
  children: _jsx(Metabase, _objectSpread(_objectSpread({}, other), {}, {
1040
+ popupZIndex: childModalZIndex + 1,
564
1041
  isExit: true,
565
1042
  isSubquery: true,
566
1043
  notExistsColumns: exitData,
@@ -570,7 +1047,6 @@ var FormulaList = forwardRef(function (props, ref) {
570
1047
  value: cloneDeep(_value),
571
1048
  onOk: function onOk(newList) {
572
1049
  try {
573
- // 子查询未改变不做操作
574
1050
  if (isEqual(newList, oldList)) {
575
1051
  o.close();
576
1052
  return;
@@ -584,15 +1060,12 @@ var FormulaList = forwardRef(function (props, ref) {
584
1060
  onChange === null || onChange === void 0 || onChange(caseList, '');
585
1061
  setCaseList(_toConsumableArray(caseList));
586
1062
  o.close();
587
- } catch (e) {
588
- console.warn(e);
589
- } finally {
1063
+ } catch (e) {} finally {
590
1064
  o.close();
591
1065
  }
592
1066
  }
593
1067
  }))
594
- }),
595
- onClose: function onClose() {}
1068
+ })
596
1069
  });
597
1070
  };
598
1071
  function selectConstant(e) {
@@ -617,7 +1090,6 @@ var FormulaList = forwardRef(function (props, ref) {
617
1090
  })
618
1091
  });
619
1092
  }
620
- // 函数弹窗
621
1093
  var showFunction = function showFunction(e, i) {
622
1094
  var _value = caseList[i];
623
1095
  var o = Modal2.openModal({
@@ -654,317 +1126,275 @@ var FormulaList = forwardRef(function (props, ref) {
654
1126
  onClose: function onClose() {}
655
1127
  });
656
1128
  };
657
- // 分段
658
- var itemDom = function itemDom(v, index) {
1129
+ var itemDom = function itemDom(v, index, groupType) {
659
1130
  var type = v.type;
660
1131
  if (v.type === AtomsTypeEnum.NOT_EXISTS || v.type === AtomsTypeEnum.EXISTS) {
661
- return _jsx(ItemName, {
662
- isError: isExistsError(v.notExists, store.existsError),
663
- children: _jsxs("div", {
664
- className: "Sqb-TableName purple-name",
665
- onClick: function onClick(e) {
666
- return showNotExists(index);
667
- },
668
- children: [v.type, " ( * )", _jsx("span", {
669
- className: 'item-del',
670
- style: {
671
- fontSize: 0
672
- },
673
- onClick: function onClick(e) {
674
- return handleDel(e, index);
675
- },
676
- children: _jsx(CloseIcon, {})
677
- })]
678
- }, index)
679
- }, index);
680
- } else if (v.type === AtomsTypeEnum.SUB_QUERY) {
681
- return _jsx(ItemName, {
682
- isError: isExistsError(v.subQuery, store.existsError),
683
- children: _jsxs("div", {
684
- className: "Sqb-TableName purple-name",
685
- onClick: function onClick(e) {
686
- return showSubQuery(index);
687
- },
688
- children: [v.label || __('SqlQueryBuilder.subquery'), _jsx("span", {
689
- className: 'item-del',
690
- style: {
691
- fontSize: 0
692
- },
693
- onClick: function onClick(e) {
694
- return handleDel(e, index);
695
- },
696
- children: _jsx(CloseIcon, {})
697
- })]
698
- }, index)
699
- }, index);
700
- } else if (type === AtomsTypeEnum.FIELD) {
701
- // 字段
702
- return _jsx(ItemName, {
703
- isError: isError(v, data),
704
- children: _jsxs("div", {
705
- className: cx("Sqb-TableName ", {
706
- notSelected: !(v !== null && v !== void 0 && v.fieldName)
1132
+ return {
1133
+ className: 'purple-name',
1134
+ onClick: function onClick() {
1135
+ return showNotExists(index);
1136
+ },
1137
+ node: _jsxs(_Fragment, {
1138
+ children: [v.type, " ( * )", renderDeleteIcon(v, index, groupType)]
1139
+ })
1140
+ };
1141
+ }
1142
+ if (v.type === AtomsTypeEnum.SUB_QUERY) {
1143
+ return {
1144
+ className: 'purple-name',
1145
+ onClick: function onClick() {
1146
+ return showSubQuery(index);
1147
+ },
1148
+ node: _jsxs(_Fragment, {
1149
+ children: [v.label || __('SqlQueryBuilder.subquery'), renderDeleteIcon(v, index, groupType)]
1150
+ })
1151
+ };
1152
+ }
1153
+ if (type === AtomsTypeEnum.FIELD) {
1154
+ return {
1155
+ className: cx({
1156
+ notSelected: !(v !== null && v !== void 0 && v.fieldName)
1157
+ }),
1158
+ onClick: function onClick(e) {
1159
+ return handleField(e, index, v);
1160
+ },
1161
+ node: _jsxs(_Fragment, {
1162
+ children: [!(v !== null && v !== void 0 && v.fieldName) && __('customColumn.selectField'), v.fieldName, renderDeleteIcon(v, index, groupType)]
1163
+ })
1164
+ };
1165
+ }
1166
+ if (type === AtomsTypeEnum.INPUT_STRING) {
1167
+ return {
1168
+ className: 'notSelected',
1169
+ node: _jsxs(_Fragment, {
1170
+ children: [_jsx(FieldString, {}), _jsx(Input, {
1171
+ className: ':sqb-Custom-input',
1172
+ value: v.val,
1173
+ placeholder: __('SqlQueryBuilder.pleaseEnter'),
1174
+ size: 'large',
1175
+ onChange: function onChange(val) {
1176
+ handleConstant(val, index);
1177
+ }
1178
+ }), renderDeleteIcon(v, index, groupType)]
1179
+ })
1180
+ };
1181
+ }
1182
+ if (type === AtomsTypeEnum.INPUT_NUMBER) {
1183
+ return {
1184
+ className: 'notSelected',
1185
+ node: _jsxs(_Fragment, {
1186
+ children: [_jsx(FieldNumber, {}), _jsx(InputNumber, {
1187
+ className: ':sqb-Custom-input',
1188
+ value: v.val,
1189
+ placeholder: __('SqlQueryBuilder.pleaseEnter'),
1190
+ size: 'large',
1191
+ onChange: function onChange(val) {
1192
+ handleConstant(val, index);
1193
+ }
1194
+ }), renderDeleteIcon(v, index, groupType)]
1195
+ })
1196
+ };
1197
+ }
1198
+ if (type === AtomsTypeEnum.OPERATOR) {
1199
+ if (isFixedCaseOperator(v)) {
1200
+ return {
1201
+ raw: true,
1202
+ node: _jsx("span", {
1203
+ className: 'Sqb-CaseKeyword',
1204
+ children: v.val
1205
+ })
1206
+ };
1207
+ }
1208
+ if (groupType === 'logic' && isFixedLogicOperator(v)) {
1209
+ return {
1210
+ raw: true,
1211
+ node: _jsx("span", {
1212
+ className: 'Sqb-CaseKeyword',
1213
+ children: v.val
1214
+ })
1215
+ };
1216
+ }
1217
+ if (groupType === 'logic' && ['and', 'or'].includes(v.val)) {
1218
+ var nextLogicOperator = v.val === 'and' ? 'or' : 'and';
1219
+ return {
1220
+ className: cx({
1221
+ 'logic-operator': true,
1222
+ 'logic-and': v.val === 'and',
1223
+ 'logic-or': v.val === 'or'
707
1224
  }),
708
- onClick: function onClick(e) {
709
- return handleField(e, index, v);
1225
+ onClick: function onClick() {
1226
+ handleConstant(nextLogicOperator, index);
710
1227
  },
711
- children: [!(v !== null && v !== void 0 && v.fieldName) && __('customColumn.selectField'), v.fieldName, _jsx("span", {
712
- className: 'item-del',
713
- style: {
714
- fontSize: 0
715
- },
716
- onClick: function onClick(e) {
717
- return handleDel(e, index);
718
- },
719
- children: _jsx(CloseIcon, {})
720
- })]
721
- })
722
- }, index);
723
- } else if (type === AtomsTypeEnum.INPUT_STRING) {
724
- // 输入框
725
- return _jsxs("div", {
726
- className: cx("Sqb-TableName notSelected "),
727
- children: [_jsx(FieldString, {}), _jsx(Input, {
728
- className: ':Sqb-Custom-input',
1228
+ node: renderTokenContent(v.val)
1229
+ };
1230
+ }
1231
+ return {
1232
+ className: cx('operator-trigger', {
1233
+ notSelected: !v.val,
1234
+ 'flow-operator': ['case', 'when', 'then', 'else', 'end'].includes(v.val),
1235
+ 'logic-operator': ['and', 'or'].includes(v.val),
1236
+ 'logic-and': v.val === 'and',
1237
+ 'logic-or': v.val === 'or'
1238
+ }),
1239
+ node: _jsx(Select, {
1240
+ triggerProps: getSelectTriggerProps(),
729
1241
  value: v.val,
730
- placeholder: __('SqlQueryBuilder.pleaseEnter'),
731
- size: 'large',
732
- onChange: function onChange(val) {
733
- handleConstant(val, index);
734
- }
735
- }), _jsx("span", {
736
- className: 'item-del',
737
- style: {
738
- fontSize: 0
739
- },
740
- onClick: function onClick(e) {
741
- return handleDel(e, index);
1242
+ triggerElement: function triggerElement() {
1243
+ return renderTokenContent(_jsxs(_Fragment, {
1244
+ children: [!v.val && __('customColumn.selectOperator'), v.val, renderDeleteIcon(v, index)]
1245
+ }));
742
1246
  },
743
- children: _jsx(CloseIcon, {})
744
- })]
745
- });
746
- } else if (type === AtomsTypeEnum.INPUT_NUMBER) {
747
- // 输入框
748
- return _jsxs("div", {
749
- className: cx("Sqb-TableName notSelected "),
750
- children: [_jsx(FieldNumber, {}), _jsx(InputNumber, {
751
- className: ':sqb-Custom-input',
752
- value: v.val,
753
- placeholder: __('SqlQueryBuilder.pleaseEnter'),
754
- size: 'large',
755
1247
  onChange: function onChange(val) {
756
1248
  handleConstant(val, index);
757
- }
758
- }), _jsx("span", {
759
- className: 'item-del',
760
- style: {
761
- fontSize: 0
762
- },
763
- onClick: function onClick(e) {
764
- return handleDel(e, index);
765
1249
  },
766
- children: _jsx(CloseIcon, {})
767
- })]
768
- });
769
- } else if (type === AtomsTypeEnum.OPERATOR) {
770
- //连接符
771
- return _jsx(Select, {
772
- triggerProps: {
773
- clickToClose: true
774
- },
775
- value: v.val,
776
- triggerElement: function triggerElement(value) {
777
- return _jsxs("div", {
778
- className: cx("Sqb-TableName Sqb-TableName-OPERATOR", {
779
- notSelected: !v.val
780
- }),
781
- children: [!v.val && __('customColumn.selectOperator'), v.val, _jsx("span", {
782
- className: 'item-del',
783
- style: {
784
- fontSize: 0
785
- },
786
- onClick: function onClick(e) {
787
- return handleDel(e, index);
788
- },
789
- children: _jsx(CloseIcon, {})
790
- })]
791
- });
792
- },
793
- onChange: function onChange(val) {
794
- handleConstant(val, index);
795
- },
796
- children: operatorList.map(function (option, index) {
797
- return _jsx(Select.Option, {
798
- value: option,
799
- children: option
800
- }, index + '' + ind);
1250
+ children: operatorList.map(function (option, optionIndex) {
1251
+ return _jsx(Select.Option, {
1252
+ value: option,
1253
+ children: option
1254
+ }, optionIndex + '' + ind);
1255
+ })
801
1256
  })
802
- });
803
- } else if (type === AtomsTypeEnum.CONSTANT) {
804
- //常量
805
- return _jsx(ItemName, {
806
- isError: !!(v.id || v.val) && !getConstantLabel(store.constantList, v.id || v.val),
807
- message: "\u5E38\u91CF\u4E22\u5931",
808
- children: _jsxs("div", {
809
- className: cx("Sqb-TableName", {
810
- notSelected: !v.val
811
- }),
812
- "v-index": index,
813
- "v-val": v.id || v.val,
814
- onClick: selectConstant,
815
- children: [getConstantLabel(store.constantList, v.id || v.val, v.val) || __('SqlQueryBuilder.pickConstant'), _jsx("span", {
816
- className: 'item-del',
817
- style: {
818
- fontSize: 0
819
- },
820
- onClick: function onClick(e) {
821
- return handleDel(e, index);
822
- },
823
- children: _jsx(CloseIcon, {})
824
- })]
1257
+ };
1258
+ }
1259
+ if (type === AtomsTypeEnum.CONSTANT) {
1260
+ return {
1261
+ className: cx({
1262
+ notSelected: !v.val
1263
+ }),
1264
+ attrs: {
1265
+ 'v-index': index,
1266
+ 'v-val': v.id || v.val
1267
+ },
1268
+ onClick: selectConstant,
1269
+ node: _jsxs(_Fragment, {
1270
+ children: [getConstantLabel(store.constantList, v.id || v.val, v.val) || __('SqlQueryBuilder.pickConstant'), renderDeleteIcon(v, index, groupType)]
825
1271
  })
826
- }, index);
827
- } else if (otherTypeMap.has(String(type))) {
828
- // 业务自定义常量类型(otherTypes)
1272
+ };
1273
+ }
1274
+ if (otherTypeMap.has(String(type))) {
829
1275
  var currentOtherType = otherTypeMap.get(String(type));
830
1276
  var listSource = (currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.list) || [];
831
- return _jsx(ItemName, {
832
- isError: !!(v.id || v.val) && !getConstantLabel(listSource, v.id || v.val),
833
- message: "".concat(currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.label, "\u4E22\u5931"),
834
- children: _jsxs("div", {
835
- className: cx("Sqb-TableName", {
836
- notSelected: !v.val
837
- }),
838
- "v-index": index,
839
- "v-val": v.id || v.val,
840
- "v-type": type,
841
- onClick: selectConstant,
842
- children: [getConstantLabel(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), _jsx("span", {
843
- className: 'item-del',
844
- style: {
845
- fontSize: 0
846
- },
847
- onClick: function onClick(e) {
848
- return handleDel(e, index);
849
- },
850
- children: _jsx(CloseIcon, {})
851
- })]
1277
+ return {
1278
+ className: cx({
1279
+ notSelected: !v.val
1280
+ }),
1281
+ attrs: {
1282
+ 'v-index': index,
1283
+ 'v-val': v.id || v.val,
1284
+ 'v-type': type
1285
+ },
1286
+ onClick: selectConstant,
1287
+ node: _jsxs(_Fragment, {
1288
+ children: [getConstantLabel(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), renderDeleteIcon(v, index, groupType)]
852
1289
  })
853
- }, index);
854
- } else if (type === AtomsTypeEnum.EXPRESSION) {
1290
+ };
1291
+ }
1292
+ if (type === AtomsTypeEnum.EXPRESSION) {
855
1293
  if (~['早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
856
- var _caseList$index$quote;
857
- var _caseList = caseList.slice();
858
- _caseList[index].rhs = [_caseList[index].rhs[0]];
859
- _caseList[index].quotes = (_caseList$index$quote = _caseList[index].quotes.split(' || ')) === null || _caseList$index$quote === void 0 ? void 0 : _caseList$index$quote[0];
860
- setCaseList(_caseList);
1294
+ var _nextList$index$quote;
1295
+ var nextList = caseList.slice();
1296
+ nextList[index].rhs = [nextList[index].rhs[0]];
1297
+ nextList[index].quotes = (_nextList$index$quote = nextList[index].quotes.split(' || ')) === null || _nextList$index$quote === void 0 ? void 0 : _nextList$index$quote[0];
1298
+ setCaseList(nextList);
861
1299
  }
862
- // 表达式
863
- return _jsx(ItemName, {
864
- isError: isError(v, data),
865
- children: _jsxs("div", {
866
- className: cx("Sqb-TableName purple-name", {
867
- notSelected: !v.quotes
868
- }),
869
- onClick: function onClick(e) {
870
- return handleExpression(e, index, v);
871
- },
872
- children: [v.quotes ? v.quotes : __('customColumn.selectExpression'), _jsx("span", {
873
- className: 'item-del',
874
- style: {
875
- fontSize: 0
876
- },
877
- onClick: function onClick(e) {
878
- return handleDel(e, index);
879
- },
880
- children: _jsx(CloseIcon, {})
881
- })]
1300
+ return {
1301
+ className: cx('purple-name', {
1302
+ notSelected: !v.quotes
1303
+ }),
1304
+ onClick: function onClick(e) {
1305
+ return handleExpression(e, index, v);
1306
+ },
1307
+ node: _jsxs(_Fragment, {
1308
+ children: [v.quotes ? v.quotes : __('customColumn.selectExpression'), renderDeleteIcon(v, index, groupType)]
882
1309
  })
883
- }, index);
884
- } else if (type === AtomsTypeEnum.FORMULA) {
885
- // 公式
886
- return _jsx(ItemName, {
887
- isError: isError(v, data) || formulaIsError(v, formulaList),
888
- message: formulaIsError(v, formulaList) ? '公式丢失' : '',
889
- children: _jsxs("div", {
890
- className: cx("Sqb-TableName gray-name"),
891
- onClick: function onClick(e) {
892
- return showFunction(e, index);
1310
+ };
1311
+ }
1312
+ if (type === AtomsTypeEnum.CASE_WHEN) {
1313
+ return {
1314
+ raw: true,
1315
+ node: renderCaseWhenEditor(v, index)
1316
+ };
1317
+ }
1318
+ if (type === AtomsTypeEnum.AND_OR) {
1319
+ return {
1320
+ raw: true,
1321
+ node: renderAndOrEditor(v, index)
1322
+ };
1323
+ }
1324
+ if (type === AtomsTypeEnum.FORMULA) {
1325
+ return {
1326
+ className: 'gray-name',
1327
+ onClick: function onClick(e) {
1328
+ return showFunction(e, index);
1329
+ },
1330
+ node: _jsxs(_Fragment, {
1331
+ children: [v.name ? getQuotes(v, v.args, formulaList) : __('customColumn.selectFormula'), renderDeleteIcon(v, index, groupType)]
1332
+ })
1333
+ };
1334
+ }
1335
+ if (type === AtomsTypeEnum.SELECT) {
1336
+ return {
1337
+ className: cx('operator-trigger', {
1338
+ notSelected: !v.val,
1339
+ 'flow-operator': v.val === 'caseWhen',
1340
+ 'logic-operator': v.val === 'andOr'
1341
+ }),
1342
+ node: _jsx(Select, {
1343
+ triggerProps: getSelectTriggerProps(),
1344
+ multiple: v.multiple,
1345
+ value: v.val,
1346
+ triggerElement: function triggerElement() {
1347
+ return renderTokenContent(_jsxs(_Fragment, {
1348
+ children: [!v.val && __('customColumn.selectOperator'), v.val, !v.fixed && renderDeleteIcon(v, index, groupType)]
1349
+ }));
893
1350
  },
894
- children: [v.name ? getQuotes(v, v.args, formulaList) : __('customColumn.selectFormula'), _jsx("span", {
895
- className: 'item-del',
896
- style: {
897
- fontSize: 0
898
- },
899
- onClick: function onClick(e) {
900
- return handleDel(e, index);
901
- },
902
- children: _jsx(CloseIcon, {})
903
- })]
1351
+ onChange: function onChange(val) {
1352
+ handleConstant(val, index);
1353
+ },
1354
+ children: v.options.map(function (option, optionIndex) {
1355
+ return _jsx(Select.Option, {
1356
+ value: option.value,
1357
+ children: option.label
1358
+ }, optionIndex + '' + ind);
1359
+ })
904
1360
  })
905
- }, index);
906
- } else if (type === AtomsTypeEnum.SELECT) {
907
- // 选择框
908
- return _jsx(Select, {
909
- triggerProps: {
910
- clickToClose: true
911
- },
912
- multiple: v.multiple,
913
- value: v.val,
914
- triggerElement: function triggerElement(value) {
915
- return _jsxs("div", {
916
- className: cx("Sqb-TableName Sqb-TableName-OPERATOR", {
917
- notSelected: !v.val
918
- }),
919
- children: [!v.val && __('customColumn.selectOperator'), v.val, !v.fixed && _jsx("span", {
920
- className: 'item-del',
921
- style: {
922
- fontSize: 0
923
- },
924
- onClick: function onClick(e) {
925
- return handleDel(e, index);
926
- },
927
- children: _jsx(CloseIcon, {})
928
- })]
929
- });
930
- },
931
- onChange: function onChange(val) {
932
- handleConstant(val, index);
1361
+ };
1362
+ }
1363
+ if (groupType === 'logic') {
1364
+ return {
1365
+ className: cx('gray-name', 'notSelected'),
1366
+ style: {
1367
+ minWidth: 44,
1368
+ justifyContent: 'center'
933
1369
  },
934
- children: v.options.map(function (option, index) {
935
- return _jsx(Select.Option, {
936
- value: option.value,
937
- children: option.label
938
- }, index + '' + ind);
1370
+ node: selectOperator({
1371
+ triggerElement: function triggerElement() {
1372
+ return renderTokenContent(_jsx(AddIcon, {}));
1373
+ },
1374
+ ind: index,
1375
+ position: ''
939
1376
  })
940
- });
941
- } else {
942
- return selectOperator({
1377
+ };
1378
+ }
1379
+ return {
1380
+ className: cx({
1381
+ notSelected: true
1382
+ }),
1383
+ node: selectOperator({
943
1384
  triggerElement: function triggerElement() {
944
- return _jsxs("div", {
945
- className: cx("Sqb-TableName ", {
946
- notSelected: true
947
- }),
948
- children: [__('customColumn.selectCustomInput'), _jsx("span", {
949
- className: 'item-del',
950
- style: {
951
- fontSize: 0
952
- },
953
- onClick: function onClick(e) {
954
- return handleDel(e, index);
955
- },
956
- children: _jsx(CloseIcon, {})
957
- })]
958
- });
1385
+ return renderTokenContent(_jsxs(_Fragment, {
1386
+ children: [__('customColumn.selectCustomInput'), renderDeleteIcon(v, index, groupType)]
1387
+ }));
959
1388
  },
960
1389
  ind: index,
961
1390
  position: ''
962
- });
963
- }
1391
+ })
1392
+ };
964
1393
  };
965
1394
  var copyDom = function copyDom() {
966
1395
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
967
1396
  var positioned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1397
+ if (embedded) return null;
968
1398
  if (!isCopy || selectedIndices.length === 0 && checkedItemsCount === 0) return null;
969
1399
  return _jsx("div", {
970
1400
  className: cx('Sqb-Filter-item-copy', {
@@ -992,10 +1422,147 @@ var FormulaList = forwardRef(function (props, ref) {
992
1422
  })
993
1423
  });
994
1424
  };
1425
+ var renderItemShell = function renderItemShell(v, i, groupType, extraClassName) {
1426
+ var showCheckbox = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1427
+ var itemContent = itemDom(v, i, groupType);
1428
+ var isCompositeAtom = v.type === AtomsTypeEnum.CASE_WHEN || v.type === AtomsTypeEnum.AND_OR;
1429
+ var isPassiveCaseKeyword = groupType === 'caseWhen' && isFixedCaseOperator(v) || groupType === 'logic' && isFixedLogicOperator(v);
1430
+ return _jsx(React.Fragment, {
1431
+ children: _jsxs("div", {
1432
+ className: cx('Sqb-Filter-item', _defineProperty({
1433
+ hover: ind === i && hoveredCopyIndex !== i,
1434
+ 'item-fixed': v.fixed || false,
1435
+ 'item-selected': isCheck,
1436
+ 'item-composite': isCompositeAtom,
1437
+ 'group-child': groupType !== 'single',
1438
+ 'group-flow-child': groupType === 'caseWhen',
1439
+ 'group-logic-child': groupType === 'logic'
1440
+ }, extraClassName || '', !!extraClassName)),
1441
+ onMouseEnter: function onMouseEnter(e) {
1442
+ if (isCheck || isPassiveCaseKeyword) return;
1443
+ setInd(i);
1444
+ },
1445
+ onMouseLeave: function onMouseLeave() {
1446
+ if (isCheck || isPassiveCaseKeyword) return;
1447
+ setInd(-1);
1448
+ },
1449
+ children: [copyDom(i), canShowInsertArrows(v, groupType) && selectOperator({
1450
+ triggerElement: function triggerElement() {
1451
+ return _jsx("div", {
1452
+ className: 'left-arrow',
1453
+ "v-index": i,
1454
+ "v-type": 'before',
1455
+ onClick: function onClick() {
1456
+ if (!selectedIndices.length) addOperator(AtomsTypeEnum.UNKNOWN, i, 'before');
1457
+ },
1458
+ children: _jsx("img", {
1459
+ src: arrow
1460
+ })
1461
+ });
1462
+ },
1463
+ ind: i,
1464
+ position: 'before',
1465
+ trigger: 'hover'
1466
+ }), !embedded && showCheckbox && v.type !== AtomsTypeEnum.UNKNOWN && _jsx(Checkbox, {
1467
+ className: 'item-check',
1468
+ checked: selectedIndices.includes(i),
1469
+ disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1470
+ onChange: function onChange(e) {
1471
+ var _e$target$checked, _e$target;
1472
+ return toggleSelect(i, (_e$target$checked = e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked) !== null && _e$target$checked !== void 0 ? _e$target$checked : !selectedIndices.includes(i));
1473
+ }
1474
+ }), _jsx("div", {
1475
+ style: {
1476
+ pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1477
+ },
1478
+ className: cx({
1479
+ openCheck: isCheck
1480
+ }),
1481
+ children: _jsx(ItemName, _objectSpread(_objectSpread({}, getItemNameProps(v)), {}, {
1482
+ children: itemContent.raw ? itemContent.node : _jsx("div", _objectSpread(_objectSpread({
1483
+ className: cx('Sqb-TableName', itemContent.className),
1484
+ onClick: itemContent.onClick,
1485
+ style: itemContent.style
1486
+ }, itemContent.attrs || {}), {}, {
1487
+ children: itemContent.node
1488
+ }))
1489
+ }))
1490
+ }), canShowInsertArrows(v, groupType) && selectOperator({
1491
+ triggerElement: function triggerElement(value) {
1492
+ return _jsx("div", {
1493
+ className: 'right-arrow',
1494
+ "v-index": i,
1495
+ "v-type": 'after',
1496
+ onClick: function onClick() {
1497
+ addOperator(AtomsTypeEnum.UNKNOWN, i, 'after');
1498
+ },
1499
+ children: _jsx("img", {
1500
+ src: arrow
1501
+ })
1502
+ });
1503
+ },
1504
+ ind: i,
1505
+ position: 'after',
1506
+ trigger: 'hover'
1507
+ })]
1508
+ })
1509
+ }, i);
1510
+ };
1511
+ var renderCaseSection = function renderCaseSection(itemIndices, groupType, sectionClassName) {
1512
+ return itemIndices.map(function (itemIndex) {
1513
+ return renderItemShell(caseList[itemIndex], itemIndex, groupType, "case-row-item ".concat(sectionClassName), false);
1514
+ });
1515
+ };
1516
+ var renderDeleteIcon = function renderDeleteIcon(item, index, groupType) {
1517
+ if (!canDeleteItem(item, groupType)) return null;
1518
+ return _jsx("span", {
1519
+ className: 'item-del',
1520
+ style: {
1521
+ fontSize: 0
1522
+ },
1523
+ onClick: function onClick(e) {
1524
+ return handleDel(e, index);
1525
+ },
1526
+ children: _jsx(CloseIcon, {})
1527
+ });
1528
+ };
1529
+ var renderCaseRecoverButton = function renderCaseRecoverButton(onClick, className, label) {
1530
+ return _jsxs("button", {
1531
+ type: 'button',
1532
+ className: cx('Sqb-CaseRecover', className),
1533
+ onClick: onClick,
1534
+ children: [_jsx(FfPlus, {}), _jsx("span", {
1535
+ children: label
1536
+ })]
1537
+ });
1538
+ };
1539
+ var renderGroupInsertArrow = function renderGroupInsertArrow(index, position) {
1540
+ return selectOperator({
1541
+ triggerElement: function triggerElement() {
1542
+ return _jsx("div", {
1543
+ className: position === 'before' ? 'left-arrow' : 'right-arrow',
1544
+ "v-index": index,
1545
+ "v-type": position,
1546
+ onClick: function onClick() {
1547
+ if (position === 'before' && selectedIndices.length) return;
1548
+ addOperator(AtomsTypeEnum.UNKNOWN, index, position);
1549
+ },
1550
+ children: _jsx("img", {
1551
+ src: arrow
1552
+ })
1553
+ });
1554
+ },
1555
+ ind: index,
1556
+ position: position,
1557
+ trigger: 'hover'
1558
+ });
1559
+ };
995
1560
  return _jsx(_Fragment, {
996
1561
  children: _jsxs("div", {
997
- className: "Sqb-NotebookCell",
998
- children: [isCopy && caseList.length > 0 && _jsxs(Space, {
1562
+ className: cx('Sqb-NotebookCell', {
1563
+ 'Sqb-NotebookCell--embedded': embedded
1564
+ }),
1565
+ children: [!embedded && isCopy && caseList.length > 0 && _jsxs(Space, {
999
1566
  size: 'small',
1000
1567
  direction: 'vertical',
1001
1568
  className: cx('item-isCheck', {
@@ -1034,75 +1601,8 @@ var FormulaList = forwardRef(function (props, ref) {
1034
1601
  },
1035
1602
  children: "\u6E05\u9664\u590D\u5236"
1036
1603
  })]
1037
- }), (_caseList2 = caseList) === null || _caseList2 === void 0 ? void 0 : _caseList2.map(function (v, i) {
1038
- return _jsx(React.Fragment, {
1039
- children: _jsxs("div", {
1040
- className: cx('Sqb-Filter-item', {
1041
- hover: ind === i && hoveredCopyIndex !== i,
1042
- 'item-fixed': v.fixed || false,
1043
- 'item-selected': isCheck
1044
- }),
1045
- onMouseEnter: function onMouseEnter(e) {
1046
- if (isCheck) return;
1047
- setInd(i);
1048
- },
1049
- onMouseLeave: function onMouseLeave() {
1050
- if (isCheck) return;
1051
- setInd(-1);
1052
- },
1053
- children: [copyDom(i), selectOperator({
1054
- triggerElement: function triggerElement() {
1055
- return _jsx("div", {
1056
- className: 'left-arrow',
1057
- "v-index": i,
1058
- "v-type": 'before',
1059
- onClick: function onClick() {
1060
- if (!selectedIndices.length) addOperator(AtomsTypeEnum.UNKNOWN, i, 'before');
1061
- },
1062
- children: _jsx("img", {
1063
- src: arrow
1064
- })
1065
- });
1066
- },
1067
- ind: i,
1068
- position: 'before',
1069
- trigger: 'hover'
1070
- }), v.type !== AtomsTypeEnum.UNKNOWN && _jsx(Checkbox, {
1071
- className: 'item-check',
1072
- checked: selectedIndices.includes(i),
1073
- disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1074
- onChange: function onChange(e) {
1075
- var _e$target$checked, _e$target;
1076
- return toggleSelect(i, (_e$target$checked = e === null || e === void 0 || (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.checked) !== null && _e$target$checked !== void 0 ? _e$target$checked : !selectedIndices.includes(i));
1077
- }
1078
- }), _jsx("div", {
1079
- style: {
1080
- pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1081
- },
1082
- className: cx('Sqb-Filter-item-content', {
1083
- openCheck: isCheck
1084
- }),
1085
- children: itemDom(v, i)
1086
- }), selectOperator({
1087
- triggerElement: function triggerElement(value) {
1088
- return _jsx("div", {
1089
- className: 'right-arrow',
1090
- "v-index": i,
1091
- "v-type": 'after',
1092
- onClick: function onClick() {
1093
- addOperator(AtomsTypeEnum.UNKNOWN, i, 'after');
1094
- },
1095
- children: _jsx("img", {
1096
- src: arrow
1097
- })
1098
- });
1099
- },
1100
- ind: i,
1101
- position: 'after',
1102
- trigger: 'hover'
1103
- })]
1104
- }, i)
1105
- }, i);
1604
+ }), caseList.map(function (item, itemIndex) {
1605
+ return renderItemShell(item, itemIndex, 'single');
1106
1606
  }), Array.from(caseList).length < 1 && selectOperator({
1107
1607
  triggerElement: function triggerElement() {
1108
1608
  return _jsx("div", {
@@ -1113,7 +1613,7 @@ var FormulaList = forwardRef(function (props, ref) {
1113
1613
  ind: -1,
1114
1614
  position: 'add',
1115
1615
  trigger: 'click'
1116
- }), copyDom(-1, false), showPreview && _jsx("div", {
1616
+ }), !embedded && copyDom(-1, false), !embedded && showPreview && _jsx("div", {
1117
1617
  className: cx("mb-2 font-bold uppercase tracking-wider preview-box"),
1118
1618
  style: {
1119
1619
  fontSize: 12,
@@ -1156,54 +1656,10 @@ var FormulaList = forwardRef(function (props, ref) {
1156
1656
  isSqlError: errorInfo.isError
1157
1657
  }),
1158
1658
  children: caseList.map(function (v, i) {
1159
- if (v !== null && v !== void 0 && v.quotes) {
1160
- return _jsx("span", {
1161
- className: 'mr-1',
1162
- children: v === null || v === void 0 ? void 0 : v.quotes
1163
- }, i);
1164
- } else if (v !== null && v !== void 0 && v.fieldName) {
1165
- return _jsx("span", {
1166
- className: 'mr-1',
1167
- children: v === null || v === void 0 ? void 0 : v.fieldName
1168
- }, i);
1169
- } else {
1170
- if (v.type === AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
1171
- return _jsxs("span", {
1172
- className: 'mr-1',
1173
- children: [_jsx("br", {}), v.val, _jsx("br", {})]
1174
- }, i);
1175
- }
1176
- if (v.type === AtomsTypeEnum.OPERATOR) {
1177
- if (v.val === '(' || v.val === ')') {
1178
- return _jsx("span", {
1179
- className: cx('mr-1', {
1180
- error: errorInfo.isBracket
1181
- }),
1182
- children: v.val
1183
- }, i);
1184
- }
1185
- if (v.val === 'case' || v.val === 'end' || v.val === 'when' || v.val === 'then') {
1186
- return _jsx("span", {
1187
- className: cx('mr-1', {
1188
- error: errorInfo.isCase
1189
- }),
1190
- children: v.val
1191
- }, i);
1192
- }
1193
- if (v.val === 'over') {
1194
- return _jsx("span", {
1195
- className: cx('mr-1', {
1196
- error: errorInfo.isOver
1197
- }),
1198
- children: v.val
1199
- }, i);
1200
- }
1201
- }
1202
- return _jsx("span", {
1203
- className: 'mr-1',
1204
- children: v.val
1205
- }, i);
1206
- }
1659
+ return _jsx("span", {
1660
+ className: 'mr-1',
1661
+ children: getItemDisplayText(v)
1662
+ }, i);
1207
1663
  })
1208
1664
  }), _jsx("div", {
1209
1665
  className: 'errorMsg mt-2',