@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
@@ -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,15 +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
- var isSettingCaseList = (0, _react.useRef)(false);
104
195
  var operatorList = (0, _react.useMemo)(function () {
105
196
  if (store.operatorList.length > 0) {
106
197
  return store.operatorList;
107
- } else {
108
- return _utils3.operatorList;
109
198
  }
199
+ return _utils3.operatorList;
110
200
  }, [store.operatorList]);
111
201
  var _useState3 = (0, _react.useState)(''),
112
202
  _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
@@ -117,6 +207,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
117
207
  previewMode = _useState6[0],
118
208
  setPreviewMode = _useState6[1];
119
209
  var _useState7 = (0, _react.useState)(function () {
210
+ if (!enableCopy) {
211
+ return false;
212
+ }
120
213
  if (store.copyType.includes(_types.FormulaTypeEnum.ALL)) {
121
214
  return true;
122
215
  }
@@ -125,34 +218,221 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
125
218
  _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
126
219
  isCopy = _useState8[0],
127
220
  setIsCopy = _useState8[1];
128
- // const [formulaList, setFunctionList] = useState<{ [params: string]: FormulaTemplatesItem }>(
129
- // );
130
221
  var formulaList = (0, _react.useMemo)(function () {
131
222
  return (0, _utils.getObjTem)(store.formulaTemplates);
132
223
  }, [store.formulaTemplates]);
133
- (0, _react.useEffect)(function () {
134
- setOldCode(getPreviewStr(caseList));
135
- }, []);
136
224
  var _useState9 = (0, _react.useState)(''),
137
225
  _useState0 = (0, _slicedToArray2["default"])(_useState9, 2),
138
226
  filterVal = _useState0[0],
139
227
  setFilterVal = _useState0[1];
140
228
  var setCaseList = function setCaseList(data) {
141
- var quotes = data.map(function (v, i) {
142
- if (v !== null && v !== void 0 && v.quotes) {
143
- return v === null || v === void 0 ? void 0 : v.quotes;
144
- } else if (v !== null && v !== void 0 && v.fieldName) {
145
- return v === null || v === void 0 ? void 0 : v.fieldName;
146
- } else {
147
- return v.val;
148
- }
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;
149
233
  }).join(' ');
150
- isSettingCaseList.current = true;
151
- // setCaseListState(data);
152
234
  caseList = data;
153
235
  caseListRef.current = data;
154
236
  onChange === null || onChange === void 0 || onChange(data, quotes);
155
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
+ };
156
436
  var _useState1 = (0, _react.useState)(-1),
157
437
  _useState10 = (0, _slicedToArray2["default"])(_useState1, 2),
158
438
  ind = _useState10[0],
@@ -170,56 +450,194 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
170
450
  isCheck = _useState14[0],
171
451
  setIsCheck = _useState14[1];
172
452
  var myInstanceIdRef = (0, _react.useRef)(Math.random().toString(36).slice(2));
173
- var _useState15 = (0, _react.useState)(!!window.__sqb_selection_active__),
453
+ var _useState15 = (0, _react.useState)(null),
174
454
  _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
175
- globalSelectionActive = _useState16[0],
176
- setGlobalSelectionActive = _useState16[1];
177
- 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__),
178
458
  _useState18 = (0, _slicedToArray2["default"])(_useState17, 2),
179
- globalSelectionOwner = _useState18[0],
180
- setGlobalSelectionOwner = _useState18[1];
181
- var _useState19 = (0, _react.useState)([]),
459
+ globalSelectionActive = _useState18[0],
460
+ setGlobalSelectionActive = _useState18[1];
461
+ var _useState19 = (0, _react.useState)(window.__sqb_selection_owner__ || null),
182
462
  _useState20 = (0, _slicedToArray2["default"])(_useState19, 2),
183
- selectedIndices = _useState20[0],
184
- setSelectedIndices = _useState20[1];
185
- var _useState21 = (0, _react.useState)(null),
463
+ globalSelectionOwner = _useState20[0],
464
+ setGlobalSelectionOwner = _useState20[1];
465
+ var _useState21 = (0, _react.useState)([]),
186
466
  _useState22 = (0, _slicedToArray2["default"])(_useState21, 2),
187
- hoveredCopyIndex = _useState22[0],
188
- setHoveredCopyIndex = _useState22[1];
189
- (0, _react.useEffect)(function () {
190
- // Skip if this update came from setCaseList (to avoid infinite loop)
191
- if (isSettingCaseList.current) {
192
- isSettingCaseList.current = false;
193
- return;
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
+ }
194
485
  }
195
- var _errorInfo = (0, _utils3.validateExpressionIntegrity)(caseList);
196
- setErrorInfo(_errorInfo);
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;
197
561
  }, [caseList]);
198
- // 获取预览字符串
199
- var getPreviewStr = function getPreviewStr() {
200
- var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
201
- return data.map(function (v, i) {
202
- if (v !== null && v !== void 0 && v.quotes) {
203
- return v === null || v === void 0 ? void 0 : v.quotes;
204
- } else if (v !== null && v !== void 0 && v.fieldName) {
205
- return v === null || v === void 0 ? void 0 : v.fieldName;
206
- } else {
207
- if (v.type === _types.AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
208
- 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;
577
+ }
578
+ if (depth === 1 && (item.val === 'when' || item.val === 'else')) {
579
+ if (currentRow.length > 0) rows.push(currentRow);
580
+ currentRow = [itemIndex];
581
+ return;
209
582
  }
210
- if (v.type === _types.AtomsTypeEnum.OPERATOR && (v.val === '(' || v.val === ')')) {
211
- return "".concat(v.val);
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
+ }
212
591
  }
213
- return v.val;
214
592
  }
215
- }).join(' ');
593
+ currentRow.push(itemIndex);
594
+ });
595
+ if (currentRow.length > 0) {
596
+ rows.push(currentRow);
597
+ }
598
+ return rows;
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);
216
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]);
217
628
  function closePopup() {
218
629
  store.setPopup({
219
630
  visible: false
220
631
  });
221
632
  }
222
- // 连接符
633
+ var getSelectTriggerProps = function getSelectTriggerProps() {
634
+ return {
635
+ clickToClose: true,
636
+ style: {
637
+ zIndex: (0, _helperDom.getTopLayerZIndex)() + 1
638
+ }
639
+ };
640
+ };
223
641
  var selectOperator = function selectOperator(props) {
224
642
  var triggerElement = props.triggerElement,
225
643
  ind = props.ind,
@@ -235,9 +653,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
235
653
  },
236
654
  showSearch: true,
237
655
  trigger: trigger,
238
- triggerProps: {
239
- clickToClose: true
240
- },
656
+ triggerProps: getSelectTriggerProps(),
241
657
  virtualListProps: {
242
658
  threshold: null
243
659
  },
@@ -254,6 +670,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
254
670
  onVisibleChange: function onVisibleChange(visible) {
255
671
  if (visible) {
256
672
  setFilterVal('');
673
+ lockParentPopup();
674
+ } else {
675
+ unlockParentPopup(300);
257
676
  }
258
677
  },
259
678
  value: '',
@@ -267,7 +686,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
267
686
  },
268
687
  value: filterVal,
269
688
  placeholder: (0, _locale.__)('SqlQueryBuilder.pleaseEnter'),
270
- // size='large'
271
689
  onChange: function onChange(val) {
272
690
  setFilterVal(val);
273
691
  }
@@ -285,7 +703,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
285
703
  })]
286
704
  });
287
705
  };
288
- // 字段
289
706
  function handleField(e, i, val) {
290
707
  store.setPopup({
291
708
  visible: true,
@@ -296,7 +713,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
296
713
  multiple: false,
297
714
  value: [val],
298
715
  theme: _enum.ColumnsPopupThemeEnum.skyBlue,
299
- onSelect: function onSelect(fields, quotes) {
716
+ onSelect: function onSelect(fields) {
300
717
  var _caseList = caseList.slice();
301
718
  _caseList[i] = fields[0];
302
719
  setCaseList(_caseList);
@@ -305,7 +722,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
305
722
  })
306
723
  });
307
724
  }
308
- // 常量
309
725
  var handleConstant = function handleConstant(val, i) {
310
726
  var _caseList = caseList.slice();
311
727
  var currentItem = _caseList[i];
@@ -325,7 +741,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
325
741
  _caseList = (0, _utils3.insertTemplateAt)(oldVal, val, _caseList, i);
326
742
  setCaseList(_caseList);
327
743
  };
328
- // 表达式
329
744
  function handleExpression(e, i, val) {
330
745
  store.setPopup({
331
746
  visible: true,
@@ -346,7 +761,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
346
761
  })
347
762
  });
348
763
  }
349
- // 删除
350
764
  function handleDel(e, index) {
351
765
  e.stopPropagation();
352
766
  var _caseList = caseList.slice();
@@ -354,13 +768,21 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
354
768
  setCaseList(_caseList);
355
769
  closePopup();
356
770
  }
357
- // 重置粘贴状态
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
+ }
358
781
  function initPaste() {
359
782
  var isDispatch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
360
783
  setSelectedIndices([]);
361
784
  setLocalItem([]);
362
785
  setIsCheck(false);
363
- //有些事不需要通知别的过滤器重置勾选状态
364
786
  if (isDispatch) {
365
787
  window.dispatchEvent(new CustomEvent('sqb-check-active', {
366
788
  detail: {
@@ -369,11 +791,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
369
791
  }));
370
792
  }
371
793
  }
372
- // 粘贴到末尾并清除勾选
373
794
  function handlePaste() {
374
795
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
375
796
  var _caseList = caseList.slice();
376
- // determine items to paste (selected items have priority)
377
797
  var itemsToPaste = _storage["default"]._metabaseCopyItems || [];
378
798
  itemsToPaste = (0, _utils2.changeCopyField)(itemsToPaste, data);
379
799
  if (itemsToPaste.length) {
@@ -386,13 +806,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
386
806
  }
387
807
  initPaste();
388
808
  }
389
- // 将值存在 localStorage
390
809
  function setLocalItem(next) {
391
810
  var _caseList = caseList.slice();
392
- // determine items to paste (selected items have priority)
393
811
  var itemsToPaste = [];
394
812
  if (next.length > 0) {
395
- // paste all selected items
396
813
  itemsToPaste = next.map(function (i) {
397
814
  return _caseList[i] ? (0, _cloneDeep["default"])(_caseList[i]) : null;
398
815
  }).filter(Boolean);
@@ -414,11 +831,33 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
414
831
  });
415
832
  setSelectedIndices(next);
416
833
  setLocalItem(next);
417
- // const active = next.length > 0;
418
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
+ };
419
858
  var copyAll = function copyAll() {
420
859
  _setIsCheck(true);
421
- var allIndices = caseList.map(function (v, i) {
860
+ var allIndices = caseList.map(function (_, i) {
422
861
  return i;
423
862
  });
424
863
  setSelectedIndices(allIndices);
@@ -427,11 +866,9 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
427
866
  var delSelect = function delSelect() {
428
867
  _pandora.Modal.confirm({
429
868
  title: (0, _locale.__)('metabase.prompt'),
430
- // 提示
431
869
  content: (0, _locale.__)('customColumn.confirmDelete'),
432
- // 确认删除吗
433
870
  onOk: function () {
434
- var _onOk = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee() {
871
+ var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
435
872
  var selectedIndexSet, _caseList;
436
873
  return _regenerator["default"].wrap(function (_context) {
437
874
  while (1) switch (_context.prev = _context.next) {
@@ -456,7 +893,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
456
893
  onCancel: function onCancel() {}
457
894
  });
458
895
  };
459
- // 开启关闭勾选,清除别的过滤器勾选
460
896
  var _setIsCheck = function _setIsCheck(val) {
461
897
  initPaste();
462
898
  setIsCheck(val);
@@ -474,7 +910,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
474
910
  window.removeEventListener('sqb-check-active', onCheckActive);
475
911
  };
476
912
  }, []);
477
- // 添加
478
913
  var addOperator = function addOperator(type, index, position) {
479
914
  var _caseList = caseList.slice() || [];
480
915
  var _ind = index;
@@ -494,14 +929,59 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
494
929
  _caseList.splice(index + 1, 0, temItem);
495
930
  _ind = index + 1;
496
931
  } else {
497
- //替换
498
932
  _caseList.splice(index, 1, temItem);
499
933
  _ind = index;
500
934
  }
501
935
  setCaseList(_caseList);
502
936
  return _ind < 0 ? 0 : _ind;
503
937
  };
504
- // 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
+ };
505
985
  var showNotExists = function showNotExists(i) {
506
986
  var _caseList$i, _caseList$i2;
507
987
  var _store$preProps = store.preProps,
@@ -510,23 +990,22 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
510
990
  other = (0, _objectWithoutProperties2["default"])(_store$preProps, _excluded);
511
991
  var _value = ((_caseList$i = caseList[i]) === null || _caseList$i === void 0 ? void 0 : _caseList$i.notExists) || [];
512
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;
513
994
  var _toolbar = notExistsToolbar || toolbar;
514
- // _toolbar = _toolbar.filter((v: string) => v !== 'group'); // 子查询不需要分组
515
- var o = _pandora.Modal2.openModal({
995
+ var o = openChildModal({
996
+ zIndex: childModalZIndex,
516
997
  title: caseList[i].type,
517
- transparentMask: true,
998
+ transparentMask: false,
518
999
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
519
1000
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1001
+ popupZIndex: childModalZIndex + 1,
520
1002
  notExistsColumns: exitData,
521
- // showFields={false}
522
1003
  isExit: true,
523
- // showSubquery={subShowSubquery}
524
1004
  toolbar: _toolbar,
525
1005
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
526
1006
  value: (0, _cloneDeep["default"])(_value),
527
1007
  onOk: function onOk(newList) {
528
1008
  try {
529
- // 子查询未改变不做操作
530
1009
  if ((0, _isEqual["default"])(newList, oldList)) {
531
1010
  o.close();
532
1011
  return;
@@ -540,18 +1019,14 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
540
1019
  onChange === null || onChange === void 0 || onChange(caseList, '');
541
1020
  setCaseList((0, _toConsumableArray2["default"])(caseList));
542
1021
  o.close();
543
- } catch (e) {
544
- console.warn(e);
545
- } finally {
1022
+ } catch (e) {} finally {
546
1023
  o.close();
547
1024
  }
548
1025
  }
549
1026
  }))
550
- }),
551
- onClose: function onClose() {}
1027
+ })
552
1028
  });
553
1029
  };
554
- // 子查询 窗口
555
1030
  var showSubQuery = function showSubQuery(i) {
556
1031
  var _caseList$i3, _caseList$i4;
557
1032
  var _store$preProps2 = store.preProps,
@@ -563,12 +1038,15 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
563
1038
  other = (0, _objectWithoutProperties2["default"])(_store$preProps2, _excluded2);
564
1039
  var _value = ((_caseList$i3 = caseList[i]) === null || _caseList$i3 === void 0 ? void 0 : _caseList$i3.subQuery) || [];
565
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;
566
1042
  var _toolbar = subToolbar || toolbar;
567
- var o = _pandora.Modal2.openModal({
1043
+ var o = openChildModal({
1044
+ zIndex: childModalZIndex,
568
1045
  title: (0, _locale.__)('SqlQueryBuilder.subquery'),
569
- transparentMask: true,
1046
+ transparentMask: false,
570
1047
  content: (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
571
1048
  children: (0, _jsxRuntime.jsx)(_index2["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), {}, {
1049
+ popupZIndex: childModalZIndex + 1,
572
1050
  isExit: true,
573
1051
  isSubquery: true,
574
1052
  notExistsColumns: exitData,
@@ -578,7 +1056,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
578
1056
  value: (0, _cloneDeep["default"])(_value),
579
1057
  onOk: function onOk(newList) {
580
1058
  try {
581
- // 子查询未改变不做操作
582
1059
  if ((0, _isEqual["default"])(newList, oldList)) {
583
1060
  o.close();
584
1061
  return;
@@ -592,15 +1069,12 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
592
1069
  onChange === null || onChange === void 0 || onChange(caseList, '');
593
1070
  setCaseList((0, _toConsumableArray2["default"])(caseList));
594
1071
  o.close();
595
- } catch (e) {
596
- console.warn(e);
597
- } finally {
1072
+ } catch (e) {} finally {
598
1073
  o.close();
599
1074
  }
600
1075
  }
601
1076
  }))
602
- }),
603
- onClose: function onClose() {}
1077
+ })
604
1078
  });
605
1079
  };
606
1080
  function selectConstant(e) {
@@ -625,7 +1099,6 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
625
1099
  })
626
1100
  });
627
1101
  }
628
- // 函数弹窗
629
1102
  var showFunction = function showFunction(e, i) {
630
1103
  var _value = caseList[i];
631
1104
  var o = _pandora.Modal2.openModal({
@@ -662,317 +1135,275 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
662
1135
  onClose: function onClose() {}
663
1136
  });
664
1137
  };
665
- // 分段
666
- var itemDom = function itemDom(v, index) {
1138
+ var itemDom = function itemDom(v, index, groupType) {
667
1139
  var type = v.type;
668
1140
  if (v.type === _types.AtomsTypeEnum.NOT_EXISTS || v.type === _types.AtomsTypeEnum.EXISTS) {
669
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
670
- isError: (0, _utils2.isExistsError)(v.notExists, store.existsError),
671
- children: (0, _jsxRuntime.jsxs)("div", {
672
- className: "Sqb-TableName purple-name",
673
- onClick: function onClick(e) {
674
- return showNotExists(index);
675
- },
676
- children: [v.type, " ( * )", (0, _jsxRuntime.jsx)("span", {
677
- className: 'item-del',
678
- style: {
679
- fontSize: 0
680
- },
681
- onClick: function onClick(e) {
682
- return handleDel(e, index);
683
- },
684
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
685
- })]
686
- }, index)
687
- }, index);
688
- } else if (v.type === _types.AtomsTypeEnum.SUB_QUERY) {
689
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
690
- isError: (0, _utils2.isExistsError)(v.subQuery, store.existsError),
691
- children: (0, _jsxRuntime.jsxs)("div", {
692
- className: "Sqb-TableName purple-name",
693
- onClick: function onClick(e) {
694
- return showSubQuery(index);
695
- },
696
- children: [v.label || (0, _locale.__)('SqlQueryBuilder.subquery'), (0, _jsxRuntime.jsx)("span", {
697
- className: 'item-del',
698
- style: {
699
- fontSize: 0
700
- },
701
- onClick: function onClick(e) {
702
- return handleDel(e, index);
703
- },
704
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
705
- })]
706
- }, index)
707
- }, index);
708
- } else if (type === _types.AtomsTypeEnum.FIELD) {
709
- // 字段
710
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
711
- isError: (0, _utils2.isError)(v, data),
712
- children: (0, _jsxRuntime.jsxs)("div", {
713
- className: (0, _classnames["default"])("Sqb-TableName ", {
714
- notSelected: !(v !== null && v !== void 0 && v.fieldName)
1141
+ return {
1142
+ className: 'purple-name',
1143
+ onClick: function onClick() {
1144
+ return showNotExists(index);
1145
+ },
1146
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1147
+ children: [v.type, " ( * )", renderDeleteIcon(v, index, groupType)]
1148
+ })
1149
+ };
1150
+ }
1151
+ if (v.type === _types.AtomsTypeEnum.SUB_QUERY) {
1152
+ return {
1153
+ className: 'purple-name',
1154
+ onClick: function onClick() {
1155
+ return showSubQuery(index);
1156
+ },
1157
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1158
+ children: [v.label || (0, _locale.__)('SqlQueryBuilder.subquery'), renderDeleteIcon(v, index, groupType)]
1159
+ })
1160
+ };
1161
+ }
1162
+ if (type === _types.AtomsTypeEnum.FIELD) {
1163
+ return {
1164
+ className: (0, _classnames["default"])({
1165
+ notSelected: !(v !== null && v !== void 0 && v.fieldName)
1166
+ }),
1167
+ onClick: function onClick(e) {
1168
+ return handleField(e, index, v);
1169
+ },
1170
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1171
+ children: [!(v !== null && v !== void 0 && v.fieldName) && (0, _locale.__)('customColumn.selectField'), v.fieldName, renderDeleteIcon(v, index, groupType)]
1172
+ })
1173
+ };
1174
+ }
1175
+ if (type === _types.AtomsTypeEnum.INPUT_STRING) {
1176
+ return {
1177
+ className: 'notSelected',
1178
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1179
+ children: [(0, _jsxRuntime.jsx)(_pandoraIcons.FieldString, {}), (0, _jsxRuntime.jsx)(_pandora.Input, {
1180
+ className: ':sqb-Custom-input',
1181
+ value: v.val,
1182
+ placeholder: (0, _locale.__)('SqlQueryBuilder.pleaseEnter'),
1183
+ size: 'large',
1184
+ onChange: function onChange(val) {
1185
+ handleConstant(val, index);
1186
+ }
1187
+ }), renderDeleteIcon(v, index, groupType)]
1188
+ })
1189
+ };
1190
+ }
1191
+ if (type === _types.AtomsTypeEnum.INPUT_NUMBER) {
1192
+ return {
1193
+ className: 'notSelected',
1194
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1195
+ children: [(0, _jsxRuntime.jsx)(_pandoraIcons.FieldNumber, {}), (0, _jsxRuntime.jsx)(_pandora.InputNumber, {
1196
+ className: ':sqb-Custom-input',
1197
+ value: v.val,
1198
+ placeholder: (0, _locale.__)('SqlQueryBuilder.pleaseEnter'),
1199
+ size: 'large',
1200
+ onChange: function onChange(val) {
1201
+ handleConstant(val, index);
1202
+ }
1203
+ }), renderDeleteIcon(v, index, groupType)]
1204
+ })
1205
+ };
1206
+ }
1207
+ if (type === _types.AtomsTypeEnum.OPERATOR) {
1208
+ if (isFixedCaseOperator(v)) {
1209
+ return {
1210
+ raw: true,
1211
+ node: (0, _jsxRuntime.jsx)("span", {
1212
+ className: 'Sqb-CaseKeyword',
1213
+ children: v.val
1214
+ })
1215
+ };
1216
+ }
1217
+ if (groupType === 'logic' && isFixedLogicOperator(v)) {
1218
+ return {
1219
+ raw: true,
1220
+ node: (0, _jsxRuntime.jsx)("span", {
1221
+ className: 'Sqb-CaseKeyword',
1222
+ children: v.val
1223
+ })
1224
+ };
1225
+ }
1226
+ if (groupType === 'logic' && ['and', 'or'].includes(v.val)) {
1227
+ var nextLogicOperator = v.val === 'and' ? 'or' : 'and';
1228
+ return {
1229
+ className: (0, _classnames["default"])({
1230
+ 'logic-operator': true,
1231
+ 'logic-and': v.val === 'and',
1232
+ 'logic-or': v.val === 'or'
715
1233
  }),
716
- onClick: function onClick(e) {
717
- return handleField(e, index, v);
1234
+ onClick: function onClick() {
1235
+ handleConstant(nextLogicOperator, index);
718
1236
  },
719
- children: [!(v !== null && v !== void 0 && v.fieldName) && (0, _locale.__)('customColumn.selectField'), v.fieldName, (0, _jsxRuntime.jsx)("span", {
720
- className: 'item-del',
721
- style: {
722
- fontSize: 0
723
- },
724
- onClick: function onClick(e) {
725
- return handleDel(e, index);
726
- },
727
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
728
- })]
729
- })
730
- }, index);
731
- } else if (type === _types.AtomsTypeEnum.INPUT_STRING) {
732
- // 输入框
733
- return (0, _jsxRuntime.jsxs)("div", {
734
- className: (0, _classnames["default"])("Sqb-TableName notSelected "),
735
- children: [(0, _jsxRuntime.jsx)(_pandoraIcons.FieldString, {}), (0, _jsxRuntime.jsx)(_pandora.Input, {
736
- className: ':Sqb-Custom-input',
1237
+ node: renderTokenContent(v.val)
1238
+ };
1239
+ }
1240
+ return {
1241
+ className: (0, _classnames["default"])('operator-trigger', {
1242
+ notSelected: !v.val,
1243
+ 'flow-operator': ['case', 'when', 'then', 'else', 'end'].includes(v.val),
1244
+ 'logic-operator': ['and', 'or'].includes(v.val),
1245
+ 'logic-and': v.val === 'and',
1246
+ 'logic-or': v.val === 'or'
1247
+ }),
1248
+ node: (0, _jsxRuntime.jsx)(_pandora.Select, {
1249
+ triggerProps: getSelectTriggerProps(),
737
1250
  value: v.val,
738
- placeholder: (0, _locale.__)('SqlQueryBuilder.pleaseEnter'),
739
- size: 'large',
740
- onChange: function onChange(val) {
741
- handleConstant(val, index);
742
- }
743
- }), (0, _jsxRuntime.jsx)("span", {
744
- className: 'item-del',
745
- style: {
746
- fontSize: 0
747
- },
748
- onClick: function onClick(e) {
749
- return handleDel(e, index);
1251
+ triggerElement: function triggerElement() {
1252
+ return renderTokenContent((0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1253
+ children: [!v.val && (0, _locale.__)('customColumn.selectOperator'), v.val, renderDeleteIcon(v, index)]
1254
+ }));
750
1255
  },
751
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
752
- })]
753
- });
754
- } else if (type === _types.AtomsTypeEnum.INPUT_NUMBER) {
755
- // 输入框
756
- return (0, _jsxRuntime.jsxs)("div", {
757
- className: (0, _classnames["default"])("Sqb-TableName notSelected "),
758
- children: [(0, _jsxRuntime.jsx)(_pandoraIcons.FieldNumber, {}), (0, _jsxRuntime.jsx)(_pandora.InputNumber, {
759
- className: ':sqb-Custom-input',
760
- value: v.val,
761
- placeholder: (0, _locale.__)('SqlQueryBuilder.pleaseEnter'),
762
- size: 'large',
763
1256
  onChange: function onChange(val) {
764
1257
  handleConstant(val, index);
765
- }
766
- }), (0, _jsxRuntime.jsx)("span", {
767
- className: 'item-del',
768
- style: {
769
- fontSize: 0
770
- },
771
- onClick: function onClick(e) {
772
- return handleDel(e, index);
773
1258
  },
774
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
775
- })]
776
- });
777
- } else if (type === _types.AtomsTypeEnum.OPERATOR) {
778
- //连接符
779
- return (0, _jsxRuntime.jsx)(_pandora.Select, {
780
- triggerProps: {
781
- clickToClose: true
782
- },
783
- value: v.val,
784
- triggerElement: function triggerElement(value) {
785
- return (0, _jsxRuntime.jsxs)("div", {
786
- className: (0, _classnames["default"])("Sqb-TableName Sqb-TableName-OPERATOR", {
787
- notSelected: !v.val
788
- }),
789
- children: [!v.val && (0, _locale.__)('customColumn.selectOperator'), v.val, (0, _jsxRuntime.jsx)("span", {
790
- className: 'item-del',
791
- style: {
792
- fontSize: 0
793
- },
794
- onClick: function onClick(e) {
795
- return handleDel(e, index);
796
- },
797
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
798
- })]
799
- });
800
- },
801
- onChange: function onChange(val) {
802
- handleConstant(val, index);
803
- },
804
- children: operatorList.map(function (option, index) {
805
- return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
806
- value: option,
807
- children: option
808
- }, index + '' + ind);
1259
+ children: operatorList.map(function (option, optionIndex) {
1260
+ return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
1261
+ value: option,
1262
+ children: option
1263
+ }, optionIndex + '' + ind);
1264
+ })
809
1265
  })
810
- });
811
- } else if (type === _types.AtomsTypeEnum.CONSTANT) {
812
- //常量
813
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
814
- isError: !!(v.id || v.val) && !(0, _utils3.getConstantLabel)(store.constantList, v.id || v.val),
815
- message: "\u5E38\u91CF\u4E22\u5931",
816
- children: (0, _jsxRuntime.jsxs)("div", {
817
- className: (0, _classnames["default"])("Sqb-TableName", {
818
- notSelected: !v.val
819
- }),
820
- "v-index": index,
821
- "v-val": v.id || v.val,
822
- onClick: selectConstant,
823
- children: [(0, _utils3.getConstantLabel)(store.constantList, v.id || v.val, v.val) || (0, _locale.__)('SqlQueryBuilder.pickConstant'), (0, _jsxRuntime.jsx)("span", {
824
- className: 'item-del',
825
- style: {
826
- fontSize: 0
827
- },
828
- onClick: function onClick(e) {
829
- return handleDel(e, index);
830
- },
831
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
832
- })]
1266
+ };
1267
+ }
1268
+ if (type === _types.AtomsTypeEnum.CONSTANT) {
1269
+ return {
1270
+ className: (0, _classnames["default"])({
1271
+ notSelected: !v.val
1272
+ }),
1273
+ attrs: {
1274
+ 'v-index': index,
1275
+ 'v-val': v.id || v.val
1276
+ },
1277
+ onClick: selectConstant,
1278
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1279
+ children: [(0, _utils3.getConstantLabel)(store.constantList, v.id || v.val, v.val) || (0, _locale.__)('SqlQueryBuilder.pickConstant'), renderDeleteIcon(v, index, groupType)]
833
1280
  })
834
- }, index);
835
- } else if (otherTypeMap.has(String(type))) {
836
- // 业务自定义常量类型(otherTypes)
1281
+ };
1282
+ }
1283
+ if (otherTypeMap.has(String(type))) {
837
1284
  var currentOtherType = otherTypeMap.get(String(type));
838
1285
  var listSource = (currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.list) || [];
839
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
840
- isError: !!(v.id || v.val) && !(0, _utils3.getConstantLabel)(listSource, v.id || v.val),
841
- message: "".concat(currentOtherType === null || currentOtherType === void 0 ? void 0 : currentOtherType.label, "\u4E22\u5931"),
842
- children: (0, _jsxRuntime.jsxs)("div", {
843
- className: (0, _classnames["default"])("Sqb-TableName", {
844
- notSelected: !v.val
845
- }),
846
- "v-index": index,
847
- "v-val": v.id || v.val,
848
- "v-type": type,
849
- onClick: selectConstant,
850
- children: [(0, _utils3.getConstantLabel)(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), (0, _jsxRuntime.jsx)("span", {
851
- className: 'item-del',
852
- style: {
853
- fontSize: 0
854
- },
855
- onClick: function onClick(e) {
856
- return handleDel(e, index);
857
- },
858
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
859
- })]
1286
+ return {
1287
+ className: (0, _classnames["default"])({
1288
+ notSelected: !v.val
1289
+ }),
1290
+ attrs: {
1291
+ 'v-index': index,
1292
+ 'v-val': v.id || v.val,
1293
+ 'v-type': type
1294
+ },
1295
+ onClick: selectConstant,
1296
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1297
+ children: [(0, _utils3.getConstantLabel)(listSource, v.id || v.val, v.val) || "\u8BF7\u9009\u62E9".concat(currentOtherType.label), renderDeleteIcon(v, index, groupType)]
860
1298
  })
861
- }, index);
862
- } else if (type === _types.AtomsTypeEnum.EXPRESSION) {
1299
+ };
1300
+ }
1301
+ if (type === _types.AtomsTypeEnum.EXPRESSION) {
863
1302
  if (~['早于', '晚于', '在'].indexOf(v.condition) && v.rhs.length > 1) {
864
- var _caseList$index$quote;
865
- var _caseList = caseList.slice();
866
- _caseList[index].rhs = [_caseList[index].rhs[0]];
867
- _caseList[index].quotes = (_caseList$index$quote = _caseList[index].quotes.split(' || ')) === null || _caseList$index$quote === void 0 ? void 0 : _caseList$index$quote[0];
868
- setCaseList(_caseList);
1303
+ var _nextList$index$quote;
1304
+ var nextList = caseList.slice();
1305
+ nextList[index].rhs = [nextList[index].rhs[0]];
1306
+ nextList[index].quotes = (_nextList$index$quote = nextList[index].quotes.split(' || ')) === null || _nextList$index$quote === void 0 ? void 0 : _nextList$index$quote[0];
1307
+ setCaseList(nextList);
869
1308
  }
870
- // 表达式
871
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
872
- isError: (0, _utils2.isError)(v, data),
873
- children: (0, _jsxRuntime.jsxs)("div", {
874
- className: (0, _classnames["default"])("Sqb-TableName purple-name", {
875
- notSelected: !v.quotes
876
- }),
877
- onClick: function onClick(e) {
878
- return handleExpression(e, index, v);
879
- },
880
- children: [v.quotes ? v.quotes : (0, _locale.__)('customColumn.selectExpression'), (0, _jsxRuntime.jsx)("span", {
881
- className: 'item-del',
882
- style: {
883
- fontSize: 0
884
- },
885
- onClick: function onClick(e) {
886
- return handleDel(e, index);
887
- },
888
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
889
- })]
1309
+ return {
1310
+ className: (0, _classnames["default"])('purple-name', {
1311
+ notSelected: !v.quotes
1312
+ }),
1313
+ onClick: function onClick(e) {
1314
+ return handleExpression(e, index, v);
1315
+ },
1316
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1317
+ children: [v.quotes ? v.quotes : (0, _locale.__)('customColumn.selectExpression'), renderDeleteIcon(v, index, groupType)]
890
1318
  })
891
- }, index);
892
- } else if (type === _types.AtomsTypeEnum.FORMULA) {
893
- // 公式
894
- return (0, _jsxRuntime.jsx)(_itemName["default"], {
895
- isError: (0, _utils2.isError)(v, data) || (0, _utils.formulaIsError)(v, formulaList),
896
- message: (0, _utils.formulaIsError)(v, formulaList) ? '公式丢失' : '',
897
- children: (0, _jsxRuntime.jsxs)("div", {
898
- className: (0, _classnames["default"])("Sqb-TableName gray-name"),
899
- onClick: function onClick(e) {
900
- return showFunction(e, index);
1319
+ };
1320
+ }
1321
+ if (type === _types.AtomsTypeEnum.CASE_WHEN) {
1322
+ return {
1323
+ raw: true,
1324
+ node: renderCaseWhenEditor(v, index)
1325
+ };
1326
+ }
1327
+ if (type === _types.AtomsTypeEnum.AND_OR) {
1328
+ return {
1329
+ raw: true,
1330
+ node: renderAndOrEditor(v, index)
1331
+ };
1332
+ }
1333
+ if (type === _types.AtomsTypeEnum.FORMULA) {
1334
+ return {
1335
+ className: 'gray-name',
1336
+ onClick: function onClick(e) {
1337
+ return showFunction(e, index);
1338
+ },
1339
+ node: (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1340
+ children: [v.name ? (0, _utils.getQuotes)(v, v.args, formulaList) : (0, _locale.__)('customColumn.selectFormula'), renderDeleteIcon(v, index, groupType)]
1341
+ })
1342
+ };
1343
+ }
1344
+ if (type === _types.AtomsTypeEnum.SELECT) {
1345
+ return {
1346
+ className: (0, _classnames["default"])('operator-trigger', {
1347
+ notSelected: !v.val,
1348
+ 'flow-operator': v.val === 'caseWhen',
1349
+ 'logic-operator': v.val === 'andOr'
1350
+ }),
1351
+ node: (0, _jsxRuntime.jsx)(_pandora.Select, {
1352
+ triggerProps: getSelectTriggerProps(),
1353
+ multiple: v.multiple,
1354
+ value: v.val,
1355
+ triggerElement: function triggerElement() {
1356
+ return renderTokenContent((0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1357
+ children: [!v.val && (0, _locale.__)('customColumn.selectOperator'), v.val, !v.fixed && renderDeleteIcon(v, index, groupType)]
1358
+ }));
901
1359
  },
902
- children: [v.name ? (0, _utils.getQuotes)(v, v.args, formulaList) : (0, _locale.__)('customColumn.selectFormula'), (0, _jsxRuntime.jsx)("span", {
903
- className: 'item-del',
904
- style: {
905
- fontSize: 0
906
- },
907
- onClick: function onClick(e) {
908
- return handleDel(e, index);
909
- },
910
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
911
- })]
1360
+ onChange: function onChange(val) {
1361
+ handleConstant(val, index);
1362
+ },
1363
+ children: v.options.map(function (option, optionIndex) {
1364
+ return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
1365
+ value: option.value,
1366
+ children: option.label
1367
+ }, optionIndex + '' + ind);
1368
+ })
912
1369
  })
913
- }, index);
914
- } else if (type === _types.AtomsTypeEnum.SELECT) {
915
- // 选择框
916
- return (0, _jsxRuntime.jsx)(_pandora.Select, {
917
- triggerProps: {
918
- clickToClose: true
919
- },
920
- multiple: v.multiple,
921
- value: v.val,
922
- triggerElement: function triggerElement(value) {
923
- return (0, _jsxRuntime.jsxs)("div", {
924
- className: (0, _classnames["default"])("Sqb-TableName Sqb-TableName-OPERATOR", {
925
- notSelected: !v.val
926
- }),
927
- children: [!v.val && (0, _locale.__)('customColumn.selectOperator'), v.val, !v.fixed && (0, _jsxRuntime.jsx)("span", {
928
- className: 'item-del',
929
- style: {
930
- fontSize: 0
931
- },
932
- onClick: function onClick(e) {
933
- return handleDel(e, index);
934
- },
935
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
936
- })]
937
- });
938
- },
939
- onChange: function onChange(val) {
940
- handleConstant(val, index);
1370
+ };
1371
+ }
1372
+ if (groupType === 'logic') {
1373
+ return {
1374
+ className: (0, _classnames["default"])('gray-name', 'notSelected'),
1375
+ style: {
1376
+ minWidth: 44,
1377
+ justifyContent: 'center'
941
1378
  },
942
- children: v.options.map(function (option, index) {
943
- return (0, _jsxRuntime.jsx)(_pandora.Select.Option, {
944
- value: option.value,
945
- children: option.label
946
- }, index + '' + ind);
1379
+ node: selectOperator({
1380
+ triggerElement: function triggerElement() {
1381
+ return renderTokenContent((0, _jsxRuntime.jsx)(_icons.AddIcon, {}));
1382
+ },
1383
+ ind: index,
1384
+ position: ''
947
1385
  })
948
- });
949
- } else {
950
- return selectOperator({
1386
+ };
1387
+ }
1388
+ return {
1389
+ className: (0, _classnames["default"])({
1390
+ notSelected: true
1391
+ }),
1392
+ node: selectOperator({
951
1393
  triggerElement: function triggerElement() {
952
- return (0, _jsxRuntime.jsxs)("div", {
953
- className: (0, _classnames["default"])("Sqb-TableName ", {
954
- notSelected: true
955
- }),
956
- children: [(0, _locale.__)('customColumn.selectCustomInput'), (0, _jsxRuntime.jsx)("span", {
957
- className: 'item-del',
958
- style: {
959
- fontSize: 0
960
- },
961
- onClick: function onClick(e) {
962
- return handleDel(e, index);
963
- },
964
- children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
965
- })]
966
- });
1394
+ return renderTokenContent((0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
1395
+ children: [(0, _locale.__)('customColumn.selectCustomInput'), renderDeleteIcon(v, index, groupType)]
1396
+ }));
967
1397
  },
968
1398
  ind: index,
969
1399
  position: ''
970
- });
971
- }
1400
+ })
1401
+ };
972
1402
  };
973
1403
  var copyDom = function copyDom() {
974
1404
  var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;
975
1405
  var positioned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1406
+ if (embedded) return null;
976
1407
  if (!isCopy || selectedIndices.length === 0 && checkedItemsCount === 0) return null;
977
1408
  return (0, _jsxRuntime.jsx)("div", {
978
1409
  className: (0, _classnames["default"])('Sqb-Filter-item-copy', {
@@ -1000,10 +1431,147 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1000
1431
  })
1001
1432
  });
1002
1433
  };
1434
+ var renderItemShell = function renderItemShell(v, i, groupType, extraClassName) {
1435
+ var showCheckbox = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
1436
+ var itemContent = itemDom(v, i, groupType);
1437
+ var isCompositeAtom = v.type === _types.AtomsTypeEnum.CASE_WHEN || v.type === _types.AtomsTypeEnum.AND_OR;
1438
+ var isPassiveCaseKeyword = groupType === 'caseWhen' && isFixedCaseOperator(v) || groupType === 'logic' && isFixedLogicOperator(v);
1439
+ return (0, _jsxRuntime.jsx)(_react["default"].Fragment, {
1440
+ children: (0, _jsxRuntime.jsxs)("div", {
1441
+ className: (0, _classnames["default"])('Sqb-Filter-item', (0, _defineProperty2["default"])({
1442
+ hover: ind === i && hoveredCopyIndex !== i,
1443
+ 'item-fixed': v.fixed || false,
1444
+ 'item-selected': isCheck,
1445
+ 'item-composite': isCompositeAtom,
1446
+ 'group-child': groupType !== 'single',
1447
+ 'group-flow-child': groupType === 'caseWhen',
1448
+ 'group-logic-child': groupType === 'logic'
1449
+ }, extraClassName || '', !!extraClassName)),
1450
+ onMouseEnter: function onMouseEnter(e) {
1451
+ if (isCheck || isPassiveCaseKeyword) return;
1452
+ setInd(i);
1453
+ },
1454
+ onMouseLeave: function onMouseLeave() {
1455
+ if (isCheck || isPassiveCaseKeyword) return;
1456
+ setInd(-1);
1457
+ },
1458
+ children: [copyDom(i), canShowInsertArrows(v, groupType) && selectOperator({
1459
+ triggerElement: function triggerElement() {
1460
+ return (0, _jsxRuntime.jsx)("div", {
1461
+ className: 'left-arrow',
1462
+ "v-index": i,
1463
+ "v-type": 'before',
1464
+ onClick: function onClick() {
1465
+ if (!selectedIndices.length) addOperator(_types.AtomsTypeEnum.UNKNOWN, i, 'before');
1466
+ },
1467
+ children: (0, _jsxRuntime.jsx)("img", {
1468
+ src: _arrow["default"]
1469
+ })
1470
+ });
1471
+ },
1472
+ ind: i,
1473
+ position: 'before',
1474
+ trigger: 'hover'
1475
+ }), !embedded && showCheckbox && v.type !== _types.AtomsTypeEnum.UNKNOWN && (0, _jsxRuntime.jsx)(_pandora.Checkbox, {
1476
+ className: 'item-check',
1477
+ checked: selectedIndices.includes(i),
1478
+ disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1479
+ onChange: function onChange(e) {
1480
+ var _e$target$checked, _e$target;
1481
+ 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));
1482
+ }
1483
+ }), (0, _jsxRuntime.jsx)("div", {
1484
+ style: {
1485
+ pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1486
+ },
1487
+ className: (0, _classnames["default"])({
1488
+ openCheck: isCheck
1489
+ }),
1490
+ children: (0, _jsxRuntime.jsx)(_itemName["default"], (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, getItemNameProps(v)), {}, {
1491
+ children: itemContent.raw ? itemContent.node : (0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
1492
+ className: (0, _classnames["default"])('Sqb-TableName', itemContent.className),
1493
+ onClick: itemContent.onClick,
1494
+ style: itemContent.style
1495
+ }, itemContent.attrs || {}), {}, {
1496
+ children: itemContent.node
1497
+ }))
1498
+ }))
1499
+ }), canShowInsertArrows(v, groupType) && selectOperator({
1500
+ triggerElement: function triggerElement(value) {
1501
+ return (0, _jsxRuntime.jsx)("div", {
1502
+ className: 'right-arrow',
1503
+ "v-index": i,
1504
+ "v-type": 'after',
1505
+ onClick: function onClick() {
1506
+ addOperator(_types.AtomsTypeEnum.UNKNOWN, i, 'after');
1507
+ },
1508
+ children: (0, _jsxRuntime.jsx)("img", {
1509
+ src: _arrow["default"]
1510
+ })
1511
+ });
1512
+ },
1513
+ ind: i,
1514
+ position: 'after',
1515
+ trigger: 'hover'
1516
+ })]
1517
+ })
1518
+ }, i);
1519
+ };
1520
+ var renderCaseSection = function renderCaseSection(itemIndices, groupType, sectionClassName) {
1521
+ return itemIndices.map(function (itemIndex) {
1522
+ return renderItemShell(caseList[itemIndex], itemIndex, groupType, "case-row-item ".concat(sectionClassName), false);
1523
+ });
1524
+ };
1525
+ var renderDeleteIcon = function renderDeleteIcon(item, index, groupType) {
1526
+ if (!canDeleteItem(item, groupType)) return null;
1527
+ return (0, _jsxRuntime.jsx)("span", {
1528
+ className: 'item-del',
1529
+ style: {
1530
+ fontSize: 0
1531
+ },
1532
+ onClick: function onClick(e) {
1533
+ return handleDel(e, index);
1534
+ },
1535
+ children: (0, _jsxRuntime.jsx)(_icons.CloseIcon, {})
1536
+ });
1537
+ };
1538
+ var renderCaseRecoverButton = function renderCaseRecoverButton(onClick, className, label) {
1539
+ return (0, _jsxRuntime.jsxs)("button", {
1540
+ type: 'button',
1541
+ className: (0, _classnames["default"])('Sqb-CaseRecover', className),
1542
+ onClick: onClick,
1543
+ children: [(0, _jsxRuntime.jsx)(_pandoraIcons.FfPlus, {}), (0, _jsxRuntime.jsx)("span", {
1544
+ children: label
1545
+ })]
1546
+ });
1547
+ };
1548
+ var renderGroupInsertArrow = function renderGroupInsertArrow(index, position) {
1549
+ return selectOperator({
1550
+ triggerElement: function triggerElement() {
1551
+ return (0, _jsxRuntime.jsx)("div", {
1552
+ className: position === 'before' ? 'left-arrow' : 'right-arrow',
1553
+ "v-index": index,
1554
+ "v-type": position,
1555
+ onClick: function onClick() {
1556
+ if (position === 'before' && selectedIndices.length) return;
1557
+ addOperator(_types.AtomsTypeEnum.UNKNOWN, index, position);
1558
+ },
1559
+ children: (0, _jsxRuntime.jsx)("img", {
1560
+ src: _arrow["default"]
1561
+ })
1562
+ });
1563
+ },
1564
+ ind: index,
1565
+ position: position,
1566
+ trigger: 'hover'
1567
+ });
1568
+ };
1003
1569
  return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1004
1570
  children: (0, _jsxRuntime.jsxs)("div", {
1005
- className: "Sqb-NotebookCell",
1006
- children: [isCopy && caseList.length > 0 && (0, _jsxRuntime.jsxs)(_pandora.Space, {
1571
+ className: (0, _classnames["default"])('Sqb-NotebookCell', {
1572
+ 'Sqb-NotebookCell--embedded': embedded
1573
+ }),
1574
+ children: [!embedded && isCopy && caseList.length > 0 && (0, _jsxRuntime.jsxs)(_pandora.Space, {
1007
1575
  size: 'small',
1008
1576
  direction: 'vertical',
1009
1577
  className: (0, _classnames["default"])('item-isCheck', {
@@ -1042,75 +1610,8 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1042
1610
  },
1043
1611
  children: "\u6E05\u9664\u590D\u5236"
1044
1612
  })]
1045
- }), (_caseList2 = caseList) === null || _caseList2 === void 0 ? void 0 : _caseList2.map(function (v, i) {
1046
- return (0, _jsxRuntime.jsx)(_react["default"].Fragment, {
1047
- children: (0, _jsxRuntime.jsxs)("div", {
1048
- className: (0, _classnames["default"])('Sqb-Filter-item', {
1049
- hover: ind === i && hoveredCopyIndex !== i,
1050
- 'item-fixed': v.fixed || false,
1051
- 'item-selected': isCheck
1052
- }),
1053
- onMouseEnter: function onMouseEnter(e) {
1054
- if (isCheck) return;
1055
- setInd(i);
1056
- },
1057
- onMouseLeave: function onMouseLeave() {
1058
- if (isCheck) return;
1059
- setInd(-1);
1060
- },
1061
- children: [copyDom(i), selectOperator({
1062
- triggerElement: function triggerElement() {
1063
- return (0, _jsxRuntime.jsx)("div", {
1064
- className: 'left-arrow',
1065
- "v-index": i,
1066
- "v-type": 'before',
1067
- onClick: function onClick() {
1068
- if (!selectedIndices.length) addOperator(_types.AtomsTypeEnum.UNKNOWN, i, 'before');
1069
- },
1070
- children: (0, _jsxRuntime.jsx)("img", {
1071
- src: _arrow["default"]
1072
- })
1073
- });
1074
- },
1075
- ind: i,
1076
- position: 'before',
1077
- trigger: 'hover'
1078
- }), v.type !== _types.AtomsTypeEnum.UNKNOWN && (0, _jsxRuntime.jsx)(_pandora.Checkbox, {
1079
- className: 'item-check',
1080
- checked: selectedIndices.includes(i),
1081
- disabled: globalSelectionActive && globalSelectionOwner !== myInstanceIdRef.current,
1082
- onChange: function onChange(e) {
1083
- var _e$target$checked, _e$target;
1084
- 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));
1085
- }
1086
- }), (0, _jsxRuntime.jsx)("div", {
1087
- style: {
1088
- pointerEvents: isCheck || store.isMetabaseCopy ? 'none' : 'auto'
1089
- },
1090
- className: (0, _classnames["default"])('Sqb-Filter-item-content', {
1091
- openCheck: isCheck
1092
- }),
1093
- children: itemDom(v, i)
1094
- }), selectOperator({
1095
- triggerElement: function triggerElement(value) {
1096
- return (0, _jsxRuntime.jsx)("div", {
1097
- className: 'right-arrow',
1098
- "v-index": i,
1099
- "v-type": 'after',
1100
- onClick: function onClick() {
1101
- addOperator(_types.AtomsTypeEnum.UNKNOWN, i, 'after');
1102
- },
1103
- children: (0, _jsxRuntime.jsx)("img", {
1104
- src: _arrow["default"]
1105
- })
1106
- });
1107
- },
1108
- ind: i,
1109
- position: 'after',
1110
- trigger: 'hover'
1111
- })]
1112
- }, i)
1113
- }, i);
1613
+ }), caseList.map(function (item, itemIndex) {
1614
+ return renderItemShell(item, itemIndex, 'single');
1114
1615
  }), Array.from(caseList).length < 1 && selectOperator({
1115
1616
  triggerElement: function triggerElement() {
1116
1617
  return (0, _jsxRuntime.jsx)("div", {
@@ -1121,7 +1622,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1121
1622
  ind: -1,
1122
1623
  position: 'add',
1123
1624
  trigger: 'click'
1124
- }), copyDom(-1, false), showPreview && (0, _jsxRuntime.jsx)("div", {
1625
+ }), !embedded && copyDom(-1, false), !embedded && showPreview && (0, _jsxRuntime.jsx)("div", {
1125
1626
  className: (0, _classnames["default"])("mb-2 font-bold uppercase tracking-wider preview-box"),
1126
1627
  style: {
1127
1628
  fontSize: 12,
@@ -1164,54 +1665,10 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
1164
1665
  isSqlError: errorInfo.isError
1165
1666
  }),
1166
1667
  children: caseList.map(function (v, i) {
1167
- if (v !== null && v !== void 0 && v.quotes) {
1168
- return (0, _jsxRuntime.jsx)("span", {
1169
- className: 'mr-1',
1170
- children: v === null || v === void 0 ? void 0 : v.quotes
1171
- }, i);
1172
- } else if (v !== null && v !== void 0 && v.fieldName) {
1173
- return (0, _jsxRuntime.jsx)("span", {
1174
- className: 'mr-1',
1175
- children: v === null || v === void 0 ? void 0 : v.fieldName
1176
- }, i);
1177
- } else {
1178
- if (v.type === _types.AtomsTypeEnum.OPERATOR && (v.val === 'and' || v.val === 'or')) {
1179
- return (0, _jsxRuntime.jsxs)("span", {
1180
- className: 'mr-1',
1181
- children: [(0, _jsxRuntime.jsx)("br", {}), v.val, (0, _jsxRuntime.jsx)("br", {})]
1182
- }, i);
1183
- }
1184
- if (v.type === _types.AtomsTypeEnum.OPERATOR) {
1185
- if (v.val === '(' || v.val === ')') {
1186
- return (0, _jsxRuntime.jsx)("span", {
1187
- className: (0, _classnames["default"])('mr-1', {
1188
- error: errorInfo.isBracket
1189
- }),
1190
- children: v.val
1191
- }, i);
1192
- }
1193
- if (v.val === 'case' || v.val === 'end' || v.val === 'when' || v.val === 'then') {
1194
- return (0, _jsxRuntime.jsx)("span", {
1195
- className: (0, _classnames["default"])('mr-1', {
1196
- error: errorInfo.isCase
1197
- }),
1198
- children: v.val
1199
- }, i);
1200
- }
1201
- if (v.val === 'over') {
1202
- return (0, _jsxRuntime.jsx)("span", {
1203
- className: (0, _classnames["default"])('mr-1', {
1204
- error: errorInfo.isOver
1205
- }),
1206
- children: v.val
1207
- }, i);
1208
- }
1209
- }
1210
- return (0, _jsxRuntime.jsx)("span", {
1211
- className: 'mr-1',
1212
- children: v.val
1213
- }, i);
1214
- }
1668
+ return (0, _jsxRuntime.jsx)("span", {
1669
+ className: 'mr-1',
1670
+ children: getItemDisplayText(v)
1671
+ }, i);
1215
1672
  })
1216
1673
  }), (0, _jsxRuntime.jsx)("div", {
1217
1674
  className: 'errorMsg mt-2',