@agentscope-ai/flow 0.0.1

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 (176) hide show
  1. package/README.zh-CN.md +67 -0
  2. package/dist/components/base-node/index.d.ts +27 -0
  3. package/dist/components/base-node/index.js +320 -0
  4. package/dist/components/base-node/index.less +258 -0
  5. package/dist/components/branch-title-header/index.d.ts +12 -0
  6. package/dist/components/branch-title-header/index.js +176 -0
  7. package/dist/components/branch-title-header/index.less +28 -0
  8. package/dist/components/check-list-btn/index.d.ts +4 -0
  9. package/dist/components/check-list-btn/index.js +144 -0
  10. package/dist/components/check-list-btn/index.less +113 -0
  11. package/dist/components/code-input/index.d.ts +24 -0
  12. package/dist/components/code-input/index.js +356 -0
  13. package/dist/components/code-input/index.less +87 -0
  14. package/dist/components/condition-item/index.d.ts +13 -0
  15. package/dist/components/condition-item/index.js +185 -0
  16. package/dist/components/condition-item/index.less +23 -0
  17. package/dist/components/custom-connection-line/index.d.ts +4 -0
  18. package/dist/components/custom-connection-line/index.js +28 -0
  19. package/dist/components/custom-handle/source-handle.d.ts +10 -0
  20. package/dist/components/custom-handle/source-handle.js +45 -0
  21. package/dist/components/custom-handle/target-handle.d.ts +6 -0
  22. package/dist/components/custom-handle/target-handle.js +21 -0
  23. package/dist/components/custom-inputs-control/index.d.ts +56 -0
  24. package/dist/components/custom-inputs-control/index.js +366 -0
  25. package/dist/components/custom-inputs-control/index.less +28 -0
  26. package/dist/components/custom-outputs-form/index.d.ts +24 -0
  27. package/dist/components/custom-outputs-form/index.js +346 -0
  28. package/dist/components/custom-outputs-form/index.less +51 -0
  29. package/dist/components/drag-panel/index.d.ts +10 -0
  30. package/dist/components/drag-panel/index.js +79 -0
  31. package/dist/components/drag-panel/index.less +23 -0
  32. package/dist/components/draggable-with-handle/index.d.ts +13 -0
  33. package/dist/components/draggable-with-handle/index.js +81 -0
  34. package/dist/components/draggable-with-handle/index.less +23 -0
  35. package/dist/components/flow-aside/index.d.ts +4 -0
  36. package/dist/components/flow-aside/index.js +62 -0
  37. package/dist/components/flow-aside/index.less +84 -0
  38. package/dist/components/flow-base-edge/index.d.ts +5 -0
  39. package/dist/components/flow-base-edge/index.js +226 -0
  40. package/dist/components/flow-base-edge/index.less +28 -0
  41. package/dist/components/flow-base-edge/linear-gradient-svg.d.ts +21 -0
  42. package/dist/components/flow-base-edge/linear-gradient-svg.js +32 -0
  43. package/dist/components/flow-icon/index.d.ts +9 -0
  44. package/dist/components/flow-icon/index.js +30 -0
  45. package/dist/components/flow-icon/index.less +20 -0
  46. package/dist/components/flow-mini-map/index.d.ts +4 -0
  47. package/dist/components/flow-mini-map/index.js +26 -0
  48. package/dist/components/flow-mini-map/index.less +22 -0
  49. package/dist/components/flow-panel/config-panel.d.ts +15 -0
  50. package/dist/components/flow-panel/config-panel.js +303 -0
  51. package/dist/components/flow-panel/index.d.ts +7 -0
  52. package/dist/components/flow-panel/index.js +7 -0
  53. package/dist/components/flow-panel/index.less +85 -0
  54. package/dist/components/flow-panel/panel-container.d.ts +12 -0
  55. package/dist/components/flow-panel/panel-container.js +25 -0
  56. package/dist/components/flow-tools/add-node-btn.d.ts +3 -0
  57. package/dist/components/flow-tools/add-node-btn.js +26 -0
  58. package/dist/components/flow-tools/history-btn.d.ts +3 -0
  59. package/dist/components/flow-tools/history-btn.js +59 -0
  60. package/dist/components/flow-tools/index.d.ts +4 -0
  61. package/dist/components/flow-tools/index.js +29 -0
  62. package/dist/components/flow-tools/index.less +82 -0
  63. package/dist/components/flow-tools/layout-btn.d.ts +3 -0
  64. package/dist/components/flow-tools/layout-btn.js +27 -0
  65. package/dist/components/flow-tools/mini-map-btn.d.ts +3 -0
  66. package/dist/components/flow-tools/mini-map-btn.js +32 -0
  67. package/dist/components/flow-tools/scale-btn.d.ts +3 -0
  68. package/dist/components/flow-tools/scale-btn.js +101 -0
  69. package/dist/components/flow-tools/short-key-btn.d.ts +3 -0
  70. package/dist/components/flow-tools/short-key-btn.js +38 -0
  71. package/dist/components/flow-tools/short-key-content.d.ts +4 -0
  72. package/dist/components/flow-tools/short-key-content.js +153 -0
  73. package/dist/components/flow-tools/short-key-content.less +38 -0
  74. package/dist/components/flow-tools/touch-mode-btn.d.ts +3 -0
  75. package/dist/components/flow-tools/touch-mode-btn.js +89 -0
  76. package/dist/components/input-text-area/index.d.ts +16 -0
  77. package/dist/components/input-text-area/index.js +74 -0
  78. package/dist/components/input-text-area/index.less +30 -0
  79. package/dist/components/judge-form/index.d.ts +13 -0
  80. package/dist/components/judge-form/index.js +182 -0
  81. package/dist/components/judge-form/index.less +11 -0
  82. package/dist/components/node-menu/index.d.ts +35 -0
  83. package/dist/components/node-menu/index.js +266 -0
  84. package/dist/components/node-menu/index.less +79 -0
  85. package/dist/components/node-resizer/index.d.ts +11 -0
  86. package/dist/components/node-resizer/index.js +46 -0
  87. package/dist/components/node-resizer/index.less +12 -0
  88. package/dist/components/node-result-panel/index.d.ts +9 -0
  89. package/dist/components/node-result-panel/index.js +155 -0
  90. package/dist/components/node-result-panel/index.less +132 -0
  91. package/dist/components/node-tree/index.d.ts +4 -0
  92. package/dist/components/node-tree/index.js +213 -0
  93. package/dist/components/node-tree/index.less +51 -0
  94. package/dist/components/output-params-tree/index.d.ts +10 -0
  95. package/dist/components/output-params-tree/index.js +34 -0
  96. package/dist/components/output-params-tree/index.less +27 -0
  97. package/dist/components/script-code-mirror/index.d.ts +14 -0
  98. package/dist/components/script-code-mirror/index.js +162 -0
  99. package/dist/components/script-code-mirror/index.less +11 -0
  100. package/dist/components/script-edit-modal/index.d.ts +30 -0
  101. package/dist/components/script-edit-modal/index.js +84 -0
  102. package/dist/components/script-edit-modal/index.less +24 -0
  103. package/dist/components/select-with-desc/index.d.ts +5 -0
  104. package/dist/components/select-with-desc/index.js +20 -0
  105. package/dist/components/select-with-desc/index.less +11 -0
  106. package/dist/components/task-status/index.d.ts +4 -0
  107. package/dist/components/task-status/index.js +209 -0
  108. package/dist/components/task-status/index.less +65 -0
  109. package/dist/components/var-input-text-area/index.d.ts +17 -0
  110. package/dist/components/var-input-text-area/index.js +211 -0
  111. package/dist/components/var-input-text-area/index.less +64 -0
  112. package/dist/components/var-type-prefix/index.d.ts +17 -0
  113. package/dist/components/var-type-prefix/index.js +21 -0
  114. package/dist/components/variable-input/index.d.ts +24 -0
  115. package/dist/components/variable-input/index.js +163 -0
  116. package/dist/components/variable-input/index.less +13 -0
  117. package/dist/components/variable-tree-select/index.d.ts +33 -0
  118. package/dist/components/variable-tree-select/index.js +160 -0
  119. package/dist/components/variable-tree-select/index.less +61 -0
  120. package/dist/constant/index.d.ts +61 -0
  121. package/dist/constant/index.js +515 -0
  122. package/dist/flow/animate.css +5 -0
  123. package/dist/flow/context.d.ts +12 -0
  124. package/dist/flow/context.js +44 -0
  125. package/dist/flow/index.d.ts +13 -0
  126. package/dist/flow/index.js +162 -0
  127. package/dist/flow/index.less +72 -0
  128. package/dist/hooks/index.d.ts +10 -0
  129. package/dist/hooks/index.js +10 -0
  130. package/dist/hooks/use-edges-interaction.d.ts +11 -0
  131. package/dist/hooks/use-edges-interaction.js +125 -0
  132. package/dist/hooks/use-flow-debug-interaction.d.ts +5 -0
  133. package/dist/hooks/use-flow-debug-interaction.js +23 -0
  134. package/dist/hooks/use-flow-interaction.d.ts +12 -0
  135. package/dist/hooks/use-flow-interaction.js +173 -0
  136. package/dist/hooks/use-flow-key-press.d.ts +1 -0
  137. package/dist/hooks/use-flow-key-press.js +32 -0
  138. package/dist/hooks/use-flow-save.d.ts +5 -0
  139. package/dist/hooks/use-flow-save.js +47 -0
  140. package/dist/hooks/use-flow-view-port.d.ts +7 -0
  141. package/dist/hooks/use-flow-view-port.js +46 -0
  142. package/dist/hooks/use-history.d.ts +21 -0
  143. package/dist/hooks/use-history.js +80 -0
  144. package/dist/hooks/use-nodes-interaction.d.ts +34 -0
  145. package/dist/hooks/use-nodes-interaction.js +777 -0
  146. package/dist/hooks/use-nodes-output-params.d.ts +31 -0
  147. package/dist/hooks/use-nodes-output-params.js +300 -0
  148. package/dist/hooks/use-nodes-update.d.ts +9 -0
  149. package/dist/hooks/use-nodes-update.js +38 -0
  150. package/dist/hooks/use-work-flow.d.ts +4 -0
  151. package/dist/hooks/use-work-flow.js +21 -0
  152. package/dist/i18n/i18n.d.ts +62 -0
  153. package/dist/i18n/i18n.js +111 -0
  154. package/dist/i18n/index.d.ts +3 -0
  155. package/dist/i18n/index.js +12 -0
  156. package/dist/i18n/locales/en-us.json +327 -0
  157. package/dist/i18n/locales/ja-jp.json +300 -0
  158. package/dist/i18n/locales/zh-cn.json +327 -0
  159. package/dist/index.css +1 -0
  160. package/dist/index.d.ts +47 -0
  161. package/dist/index.js +47 -0
  162. package/dist/index.less +1 -0
  163. package/dist/store/index.d.ts +70 -0
  164. package/dist/store/index.js +146 -0
  165. package/dist/tailwind.css +28 -0
  166. package/dist/types/work-flow.d.ts +188 -0
  167. package/dist/types/work-flow.js +1 -0
  168. package/dist/utils/default-values.d.ts +2 -0
  169. package/dist/utils/default-values.js +16 -0
  170. package/dist/utils/index.d.ts +39 -0
  171. package/dist/utils/index.js +273 -0
  172. package/dist/utils/unique-id.d.ts +2 -0
  173. package/dist/utils/unique-id.js +39 -0
  174. package/dist/utils/work-flow.d.ts +17 -0
  175. package/dist/utils/work-flow.js +44 -0
  176. package/package.json +78 -0
@@ -0,0 +1,356 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ import $i18n from "../../i18n";
9
+ import { Modal, useCommonConfig } from '@agentscope-ai/design';
10
+ import { SparkEnlargeLine } from '@agentscope-ai/icons';
11
+ import { javascript } from '@codemirror/lang-javascript';
12
+ import { linter } from '@codemirror/lint';
13
+ import { vscodeDark, vscodeLight } from '@uiw/codemirror-theme-vscode';
14
+ import ReactCodeMirror from '@uiw/react-codemirror';
15
+ import classNames from 'classnames';
16
+ import React, { useMemo, useRef, useState } from 'react';
17
+ import "./index.less";
18
+ /**
19
+ * Get more precise JavaScript value type
20
+ * @param value The value to check type for
21
+ * @returns Type string
22
+ */
23
+ var getDetailedType = function getDetailedType(value) {
24
+ if (value === null) return 'null';
25
+ if (value === undefined) return 'undefined';
26
+ if (Array.isArray(value)) {
27
+ if (value.length === 0) return $i18n.get({
28
+ id: 'spark-flow.components.CodeInput.index.arrayEmpty',
29
+ dm: 'Array(空数组)'
30
+ });
31
+ var elementTypes = new Set(value.map(function (item) {
32
+ return getDetailedType(item);
33
+ }));
34
+ if (elementTypes.size === 1) {
35
+ return "Array<".concat(Array.from(elementTypes)[0], ">");
36
+ } else {
37
+ return $i18n.get({
38
+ id: 'spark-flow.components.CodeInput.index.arrayMixed',
39
+ dm: 'Array<混合类型>'
40
+ }, {});
41
+ }
42
+ }
43
+ if (_typeof(value) === 'object') {
44
+ if (value instanceof Date) return 'Date';
45
+ if (value instanceof RegExp) return 'RegExp';
46
+ if (value instanceof Map) return 'Map';
47
+ if (value instanceof Set) return 'Set';
48
+ if (value.name && value.type && typeof value.name === 'string' && typeof value.type === 'string') {
49
+ return $i18n.get({
50
+ id: 'spark-flow.components.CodeInput.index.fileObject',
51
+ dm: 'File样式对象'
52
+ });
53
+ }
54
+ return 'Object';
55
+ }
56
+ if (typeof value === 'number') {
57
+ if (isNaN(value)) return 'NaN';
58
+ if (!isFinite(value)) return value > 0 ? 'Infinity' : '-Infinity';
59
+ }
60
+ return _typeof(value);
61
+ };
62
+
63
+ /**
64
+ * Validate if JSON value matches the specified type
65
+ * @param value JSON string
66
+ * @param type Expected type
67
+ * @returns Array of error messages, empty array if validation passes
68
+ */
69
+ var validateValueByType = function validateValueByType(value, type) {
70
+ var errors = [];
71
+ try {
72
+ var parsedValue = JSON.parse(value);
73
+ if (type.startsWith('Array<')) {
74
+ if (!Array.isArray(parsedValue)) {
75
+ errors.push($i18n.get({
76
+ id: 'spark-flow.components.CodeInput.index.expectArrayGotVar1',
77
+ dm: '期望类型为数组,但得到了{var1}'
78
+ }, {
79
+ var1: getDetailedType(parsedValue)
80
+ }));
81
+ return errors;
82
+ }
83
+ var elementType = type.substring(6, type.length - 1);
84
+ parsedValue.forEach(function (item, index) {
85
+ if (elementType === 'Object') {
86
+ if (_typeof(item) !== 'object' || item === null || Array.isArray(item)) {
87
+ errors.push($i18n.get({
88
+ id: 'spark-flow.components.CodeInput.index.arrayItemNotObjectVar1Var2',
89
+ dm: '数组中第{var1}项不是对象类型,而是{var2}'
90
+ }, {
91
+ var1: index + 1,
92
+ var2: getDetailedType(item)
93
+ }));
94
+ }
95
+ } else if (elementType === 'String') {
96
+ if (typeof item !== 'string') {
97
+ errors.push($i18n.get({
98
+ id: 'spark-flow.components.CodeInput.index.arrayItemNotStringVar1Var2',
99
+ dm: '数组中第{var1}项不是字符串类型,而是{var2}'
100
+ }, {
101
+ var1: index + 1,
102
+ var2: getDetailedType(item)
103
+ }));
104
+ }
105
+ } else if (elementType === 'Number') {
106
+ if (typeof item !== 'number' || isNaN(item)) {
107
+ errors.push($i18n.get({
108
+ id: 'spark-flow.components.CodeInput.index.arrayItemNotNumberVar1Var2',
109
+ dm: '数组中第{var1}项不是数字类型,而是{var2}'
110
+ }, {
111
+ var1: index + 1,
112
+ var2: getDetailedType(item)
113
+ }));
114
+ }
115
+ } else if (elementType === 'Boolean') {
116
+ if (typeof item !== 'boolean') {
117
+ errors.push($i18n.get({
118
+ id: 'spark-flow.components.CodeInput.index.arrayItemNotBooleanVar1Var2',
119
+ dm: '数组中第{var1}项不是布尔类型,而是{var2}'
120
+ }, {
121
+ var1: index + 1,
122
+ var2: getDetailedType(item)
123
+ }));
124
+ }
125
+ } else if (elementType === 'File') {
126
+ if (_typeof(item) !== 'object' || !item.name || !item.type) {
127
+ errors.push($i18n.get({
128
+ id: 'spark-flow.components.CodeInput.index.arrayItemNotFileVar1Var2',
129
+ dm: '数组中第{var1}项不是文件类型,而是{var2}'
130
+ }, {
131
+ var1: index + 1,
132
+ var2: getDetailedType(item)
133
+ }));
134
+ }
135
+ }
136
+ });
137
+ } else if (type === 'Object') {
138
+ if (_typeof(parsedValue) !== 'object' || parsedValue === null || Array.isArray(parsedValue)) {
139
+ errors.push($i18n.get({
140
+ id: 'spark-flow.components.CodeInput.index.expectObjectGotVar1',
141
+ dm: '期望类型为对象,但得到了{var1}'
142
+ }, {
143
+ var1: getDetailedType(parsedValue)
144
+ }));
145
+ }
146
+ } else if (type === 'String') {
147
+ if (typeof parsedValue !== 'string') {
148
+ errors.push($i18n.get({
149
+ id: 'spark-flow.components.CodeInput.index.expectStringGotVar1',
150
+ dm: '期望类型为字符串,但得到了{var1}'
151
+ }, {
152
+ var1: getDetailedType(parsedValue)
153
+ }));
154
+ }
155
+ } else if (type === 'Number') {
156
+ if (typeof parsedValue !== 'number' || isNaN(parsedValue)) {
157
+ errors.push($i18n.get({
158
+ id: 'spark-flow.components.CodeInput.index.expectNumberGotVar1',
159
+ dm: '期望类型为数字,但得到了{var1}'
160
+ }, {
161
+ var1: getDetailedType(parsedValue)
162
+ }));
163
+ }
164
+ } else if (type === 'Boolean') {
165
+ if (typeof parsedValue !== 'boolean') {
166
+ errors.push($i18n.get({
167
+ id: 'spark-flow.components.CodeInput.index.expectBooleanGotVar1',
168
+ dm: '期望类型为布尔值,但得到了{var1}'
169
+ }, {
170
+ var1: getDetailedType(parsedValue)
171
+ }));
172
+ }
173
+ } else if (type === 'File') {
174
+ if (_typeof(parsedValue) !== 'object' || !parsedValue.name || !parsedValue.type) {
175
+ errors.push($i18n.get({
176
+ id: 'spark-flow.components.CodeInput.index.expectFileGotVar1',
177
+ dm: '期望类型为文件,但得到了{var1}'
178
+ }, {
179
+ var1: getDetailedType(parsedValue)
180
+ }));
181
+ }
182
+ }
183
+ } catch (error) {
184
+ errors.push($i18n.get({
185
+ id: 'spark-flow.components.CodeInput.index.jsonParseErrorVar1',
186
+ dm: 'JSON解析错误:{var1}'
187
+ }, {
188
+ var1: error.message
189
+ }));
190
+ }
191
+ return errors;
192
+ };
193
+ var CodeEdit = function CodeEdit(_ref) {
194
+ var value = _ref.value,
195
+ height = _ref.height,
196
+ onChange = _ref.onChange,
197
+ type = _ref.type,
198
+ _ref$showGutter = _ref.showGutter,
199
+ showGutter = _ref$showGutter === void 0 ? false : _ref$showGutter,
200
+ disabled = _ref.disabled,
201
+ onErrorChange = _ref.onErrorChange;
202
+ // 使用 ref 来缓存上一次的错误状态,避免重复触发
203
+ var lastHasErrorsRef = useRef(false);
204
+ var typeLinter = useMemo(function () {
205
+ return linter(function (view) {
206
+ var text = view.state.doc.toString();
207
+ var diagnostics = [];
208
+ var hasErrors = false;
209
+ try {
210
+ JSON.parse(text);
211
+ var typeErrors = validateValueByType(text, type);
212
+ if (typeErrors.length > 0) {
213
+ hasErrors = true;
214
+ typeErrors.forEach(function (error) {
215
+ diagnostics.push({
216
+ from: 0,
217
+ to: text.length,
218
+ severity: 'error',
219
+ message: error,
220
+ actions: []
221
+ });
222
+ });
223
+ }
224
+ } catch (error) {
225
+ hasErrors = true;
226
+ var errorMessage = $i18n.get({
227
+ id: 'spark-flow.components.CodeInput.index.jsonParseErrorVar1',
228
+ dm: 'JSON解析错误:{var1}'
229
+ }, {
230
+ var1: error.message
231
+ });
232
+ diagnostics.push({
233
+ from: 0,
234
+ to: text.length,
235
+ severity: 'error',
236
+ message: errorMessage,
237
+ actions: []
238
+ });
239
+ }
240
+
241
+ // 只有错误状态发生变化时才触发回调
242
+ if (hasErrors !== lastHasErrorsRef.current && onErrorChange) {
243
+ lastHasErrorsRef.current = hasErrors;
244
+ onErrorChange(hasErrors);
245
+ }
246
+ return diagnostics;
247
+ });
248
+ }, [type, onErrorChange]);
249
+ var _useCommonConfig = useCommonConfig(),
250
+ isDarkMode = _useCommonConfig.isDarkMode;
251
+ return /*#__PURE__*/React.createElement(ReactCodeMirror, {
252
+ value: value,
253
+ height: height,
254
+ onChange: onChange,
255
+ readOnly: disabled,
256
+ theme: isDarkMode ? vscodeDark : vscodeLight,
257
+ basicSetup: {
258
+ lineNumbers: showGutter,
259
+ foldGutter: showGutter
260
+ },
261
+ extensions: [javascript({
262
+ typescript: false,
263
+ jsx: false
264
+ }), typeLinter]
265
+ });
266
+ };
267
+ export var CodeInputModal = function CodeInputModal(_ref2) {
268
+ var value = _ref2.value,
269
+ onOk = _ref2.onOk,
270
+ type = _ref2.type,
271
+ onClose = _ref2.onClose,
272
+ disabled = _ref2.disabled,
273
+ onErrorChange = _ref2.onErrorChange;
274
+ var _useState = useState(value),
275
+ _useState2 = _slicedToArray(_useState, 2),
276
+ codeVal = _useState2[0],
277
+ setCodeVal = _useState2[1];
278
+ var handleOk = function handleOk() {
279
+ onOk(codeVal);
280
+ };
281
+ return /*#__PURE__*/React.createElement(Modal, {
282
+ onCancel: onClose,
283
+ title: $i18n.get({
284
+ id: 'spark-flow.components.CodeInput.index.jsonEdit',
285
+ dm: 'JSON编辑'
286
+ }),
287
+ open: true,
288
+ width: 960,
289
+ onOk: handleOk
290
+ }, /*#__PURE__*/React.createElement("div", {
291
+ className: "spark-flow-code-input-modal-content spark-flow-code-input"
292
+ }, /*#__PURE__*/React.createElement(CodeEdit, {
293
+ showGutter: true,
294
+ height: '85vh',
295
+ onChange: setCodeVal,
296
+ value: codeVal,
297
+ type: type,
298
+ disabled: disabled,
299
+ onErrorChange: onErrorChange
300
+ })));
301
+ };
302
+ var CodeInput = function CodeInput(_ref3) {
303
+ var value = _ref3.value,
304
+ onChange = _ref3.onChange,
305
+ type = _ref3.type,
306
+ _ref3$height = _ref3.height,
307
+ height = _ref3$height === void 0 ? '200px' : _ref3$height,
308
+ className = _ref3.className,
309
+ style = _ref3.style,
310
+ isCompact = _ref3.isCompact,
311
+ disabled = _ref3.disabled,
312
+ onErrorChange = _ref3.onErrorChange;
313
+ var _useState3 = useState(false),
314
+ _useState4 = _slicedToArray(_useState3, 2),
315
+ open = _useState4[0],
316
+ setOpen = _useState4[1];
317
+ var handleChange = function handleChange(value) {
318
+ onChange === null || onChange === void 0 || onChange(value);
319
+ };
320
+ var handleOk = function handleOk(value) {
321
+ onChange === null || onChange === void 0 || onChange(value);
322
+ setOpen(false);
323
+ };
324
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
325
+ className: classNames('spark-flow-code-input', className, {
326
+ 'spark-flow-code-input-compact': isCompact,
327
+ 'spark-flow-code-input-disabled': disabled
328
+ }),
329
+ style: style
330
+ }, /*#__PURE__*/React.createElement(CodeEdit, {
331
+ value: value,
332
+ height: height,
333
+ onChange: handleChange,
334
+ type: type,
335
+ disabled: disabled,
336
+ onErrorChange: onErrorChange
337
+ }), /*#__PURE__*/React.createElement(SparkEnlargeLine, {
338
+ className: "spark-flow-code-input-expand-icon",
339
+ style: {
340
+ cursor: 'pointer'
341
+ },
342
+ onClick: function onClick() {
343
+ return setOpen(true);
344
+ }
345
+ })), open && /*#__PURE__*/React.createElement(CodeInputModal, {
346
+ value: value,
347
+ onOk: handleOk,
348
+ type: type,
349
+ onClose: function onClose() {
350
+ return setOpen(false);
351
+ },
352
+ disabled: disabled,
353
+ onErrorChange: onErrorChange
354
+ }));
355
+ };
356
+ export default CodeInput;
@@ -0,0 +1,87 @@
1
+ @import '../../index.less';
2
+
3
+ .spark-flow-code-input {
4
+ position: relative;
5
+ border: 1px solid e('var(--@{ant-prefix}-color-border)');
6
+ border-radius: 6px;
7
+ padding: 4px 0;
8
+ background: e('var(--@{ant-prefix}-color-bg-container)');
9
+
10
+ .cm-content {
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ .cm-gutters {
16
+ border-radius: 6px 0 0 6px;
17
+ background: transparent;
18
+ }
19
+
20
+ .cm-editor {
21
+ border-radius: 6px;
22
+ height: auto;
23
+ min-height: 22px;
24
+ background: transparent;
25
+
26
+ &.cm-focused {
27
+ outline: none !important;
28
+ }
29
+ }
30
+
31
+ &:not(.spark-flow-code-input-modal-content) .cm-activeLine {
32
+ background-color: transparent !important;
33
+ }
34
+
35
+ .cm-diagnosticText {
36
+ color: e('var(--@{ant-prefix}-color-error)');
37
+ font-size: 12px;
38
+ }
39
+
40
+ .cm-diagnosticAction {
41
+ color: e('var(--@{ant-prefix}-color-primary)');
42
+ cursor: pointer;
43
+ margin-left: 8px;
44
+ }
45
+
46
+ &.spark-flow-code-input-compact {
47
+ border-radius: 0 6px 6px 0;
48
+
49
+ .cm-editor {
50
+ border-radius: 0 6px 6px 0;
51
+ }
52
+ }
53
+
54
+ &.spark-flow-code-input-disabled {
55
+ cursor: not-allowed;
56
+ background: e('var(--@{ant-prefix}-color-bg-container-disabled)');
57
+ }
58
+
59
+ .spark-flow-code-input-expand-icon {
60
+ position: absolute;
61
+ bottom: 4px;
62
+ right: 4px;
63
+ pointer-events: none;
64
+ opacity: 0;
65
+ background-color: e('var(--@{ant-prefix}-color-mauve-bg)');
66
+ transition: all 0.3s ease-in-out;
67
+ border-radius: 4px;
68
+ }
69
+
70
+ &:hover {
71
+ .spark-flow-code-input-expand-icon {
72
+ pointer-events: auto;
73
+ opacity: 1;
74
+ }
75
+ }
76
+
77
+ .cm-lintPoint::after {
78
+ left: -3px;
79
+ bottom: -2px;
80
+ }
81
+ }
82
+
83
+ .spark-flow-code-input-modal-content {
84
+ .cm-editor {
85
+ height: 60vh;
86
+ }
87
+ }
@@ -0,0 +1,13 @@
1
+ import { IConditionItem } from "../../types/work-flow";
2
+ import React from 'react';
3
+ import { IVarTreeItem } from '../variable-tree-select';
4
+ import './index.less';
5
+ export declare const operatorLabelRender: (val: string) => "<" | ">" | "=" | "≠" | "≥" | "≤" | "∋" | "∌" | undefined;
6
+ export interface IConditionItemProps {
7
+ value: IConditionItem;
8
+ onChange: (value: Partial<IConditionItem>) => void;
9
+ leftVariableList: IVarTreeItem[];
10
+ rightVariableList: IVarTreeItem[];
11
+ disabled?: boolean;
12
+ }
13
+ export default function ConditionItem(props: IConditionItemProps): React.JSX.Element;
@@ -0,0 +1,185 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { filterVarItemsByType } from "../../hooks";
8
+ import { Divider, Flex, Select } from 'antd';
9
+ import React, { useMemo } from 'react';
10
+ import { OPERATOR_OPTS_MAP } from "../../constant";
11
+ import { VALUE_FROM_OPTIONS, variableFromLabelRender, VariableSelector } from "../custom-inputs-control";
12
+ import { VariableBaseInput } from "../variable-input";
13
+ import "./index.less";
14
+ var getRightType = function getRightType(type) {
15
+ return type !== null && type !== void 0 && type.includes('Array') || ['Object', 'File'].includes(type) ? 'String' : type;
16
+ };
17
+ export var operatorLabelRender = function operatorLabelRender(val) {
18
+ switch (val) {
19
+ case 'equals':
20
+ case 'isNull':
21
+ case 'lengthEquals':
22
+ case 'isTrue':
23
+ case 'isFalse':
24
+ return '=';
25
+ case 'notEquals':
26
+ case 'isNotNull':
27
+ return '≠';
28
+ case 'greater':
29
+ case 'lengthGreater':
30
+ return '>';
31
+ case 'greaterAndEqual':
32
+ case 'lengthGreaterAndEqual':
33
+ return '≥';
34
+ case 'less':
35
+ case 'lengthLess':
36
+ return '<';
37
+ case 'lessAndEqual':
38
+ case 'lengthLessAndEqual':
39
+ return '≤';
40
+ case 'contains':
41
+ return '∋';
42
+ case 'notContains':
43
+ return '∌';
44
+ }
45
+ };
46
+ export default function ConditionItem(props) {
47
+ var memoRightVariableListByType = useMemo(function () {
48
+ var list = [];
49
+ props.rightVariableList.forEach(function (item) {
50
+ var subList = filterVarItemsByType(item.children, props.value.right.type ? [props.value.right.type] : []);
51
+ if (subList.length > 0) {
52
+ list.push(_objectSpread(_objectSpread({}, item), {}, {
53
+ children: subList
54
+ }));
55
+ }
56
+ });
57
+ return list;
58
+ }, [props.value.right.type, props.rightVariableList]);
59
+ var memoRightForm = useMemo(function () {
60
+ switch (props.value.operator) {
61
+ case 'isNull':
62
+ case 'isNotNull':
63
+ return /*#__PURE__*/React.createElement("div", {
64
+ className: "spark-flow-condition-item-disabled-label"
65
+ }, "Null");
66
+ case 'isTrue':
67
+ return /*#__PURE__*/React.createElement("div", {
68
+ className: "spark-flow-condition-item-disabled-label"
69
+ }, "True");
70
+ case 'isFalse':
71
+ return /*#__PURE__*/React.createElement("div", {
72
+ className: "spark-flow-condition-item-disabled-label"
73
+ }, "False");
74
+ default:
75
+ return /*#__PURE__*/React.createElement(Flex, {
76
+ align: "center"
77
+ }, /*#__PURE__*/React.createElement(Select, {
78
+ disabled: props.disabled,
79
+ variant: "borderless",
80
+ style: {
81
+ width: 60
82
+ },
83
+ options: VALUE_FROM_OPTIONS,
84
+ value: props.value.right.value_from,
85
+ onChange: function onChange(val) {
86
+ return props.onChange({
87
+ right: _objectSpread(_objectSpread({}, props.value.right), {}, {
88
+ value_from: val,
89
+ value: void 0
90
+ })
91
+ });
92
+ },
93
+ popupMatchSelectWidth: false,
94
+ className: "spark-flow-variable-from-select",
95
+ labelRender: function labelRender(val) {
96
+ return variableFromLabelRender(val.value);
97
+ }
98
+ }), /*#__PURE__*/React.createElement(Divider, {
99
+ className: "spark-flow-condition-item-divider",
100
+ type: "vertical"
101
+ }), props.value.right.value_from === 'refer' && /*#__PURE__*/React.createElement("div", {
102
+ className: "flex-1"
103
+ }, /*#__PURE__*/React.createElement(VariableSelector, {
104
+ disabled: props.disabled,
105
+ variant: "borderless",
106
+ variableList: memoRightVariableListByType,
107
+ prefix: props.value.right.type,
108
+ value: props.value.right,
109
+ onChange: function onChange(val) {
110
+ return props.onChange({
111
+ right: _objectSpread(_objectSpread({}, props.value.right), val)
112
+ });
113
+ }
114
+ })), props.value.right.value_from === 'input' && /*#__PURE__*/React.createElement("div", {
115
+ className: "flex-1"
116
+ }, /*#__PURE__*/React.createElement(VariableBaseInput, {
117
+ disabled: props.disabled,
118
+ variant: "borderless",
119
+ value: props.value.right.value,
120
+ prefix: props.value.right.type,
121
+ onChange: function onChange(val) {
122
+ return props.onChange({
123
+ right: _objectSpread(_objectSpread({}, props.value.right), val)
124
+ });
125
+ },
126
+ type: props.value.right.type
127
+ })));
128
+ }
129
+ }, [props.value, props.disabled, props.onChange]);
130
+ return /*#__PURE__*/React.createElement("div", {
131
+ className: "spark-flow-condition-item"
132
+ }, /*#__PURE__*/React.createElement(Flex, {
133
+ align: "center",
134
+ className: "spark-flow-condition-item-header"
135
+ }, /*#__PURE__*/React.createElement("div", {
136
+ className: "flex-1"
137
+ }, /*#__PURE__*/React.createElement(VariableSelector, {
138
+ variant: "borderless",
139
+ variableList: props.leftVariableList,
140
+ value: props.value.left,
141
+ disabled: props.disabled,
142
+ onChange: function onChange(val) {
143
+ props.onChange({
144
+ left: _objectSpread(_objectSpread({}, props.value.left), val),
145
+ right: props.value.left.type === val.type ? props.value.right : {
146
+ value_from: props.value.right.value_from,
147
+ value: void 0,
148
+ type: getRightType(val.type)
149
+ },
150
+ operator: void 0
151
+ });
152
+ }
153
+ })), /*#__PURE__*/React.createElement(Divider, {
154
+ className: 'spark-flow-condition-item-divider',
155
+ type: "vertical"
156
+ }), /*#__PURE__*/React.createElement(Select, {
157
+ disabled: props.disabled,
158
+ labelRender: function labelRender(val) {
159
+ return operatorLabelRender(val.value);
160
+ },
161
+ variant: "borderless",
162
+ style: {
163
+ width: 80
164
+ },
165
+ value: props.value.operator,
166
+ onChange: function onChange(val) {
167
+ // set to default type (based on left condition)
168
+ var right = _objectSpread(_objectSpread({}, props.value.right), {}, {
169
+ type: getRightType(props.value.left.type),
170
+ value: void 0
171
+ });
172
+
173
+ // if the condition is related to length, set to Number type
174
+ if (['greater', 'greaterAndEqual', 'less', 'lessAndEqual', 'lengthGreater', 'lengthGreaterAndEqual', 'lengthLess', 'lengthLessAndEqual', 'lengthEquals'].includes(val)) {
175
+ right.type = 'Number';
176
+ }
177
+ props.onChange({
178
+ operator: val,
179
+ right: right
180
+ });
181
+ },
182
+ popupMatchSelectWidth: false,
183
+ options: OPERATOR_OPTS_MAP[props.value.left.type || 'String']
184
+ })), memoRightForm);
185
+ }
@@ -0,0 +1,23 @@
1
+ @import '../../index.less';
2
+
3
+ .spark-flow-condition-item {
4
+ border: 1px solid e('var(--@{ant-prefix}-color-border-secondary)');
5
+ border-radius: 6px;
6
+
7
+ &-header {
8
+ border-bottom: 1px solid e('var(--@{ant-prefix}-color-border-secondary)');
9
+ }
10
+
11
+ .spark-flow-condition-item-divider {
12
+ height: 20px;
13
+ margin: 0;
14
+ }
15
+
16
+ &-disabled-label {
17
+ background: e('var(--@{ant-prefix}-color-fill-secondary)');
18
+ padding: 6px 8px;
19
+ font-size: 12px;
20
+ line-height: 20px;
21
+ color: e('var(--@{ant-prefix}-color-text-tertiary)');
22
+ }
23
+ }
@@ -0,0 +1,4 @@
1
+ import { ConnectionLineComponentProps } from '@xyflow/react';
2
+ import React from 'react';
3
+ declare const _default: React.NamedExoticComponent<ConnectionLineComponentProps>;
4
+ export default _default;