@gingkoo/pandora-metabase 1.0.118 → 1.0.120

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