@nocobase/plugin-workflow 0.9.0-alpha.2 → 0.9.1-alpha.2

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 (138) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +9 -0
  3. package/lib/client/AddButton.d.ts +1 -1
  4. package/lib/client/AddButton.js +43 -27
  5. package/lib/client/Branch.d.ts +1 -1
  6. package/lib/client/ExecutionCanvas.js +5 -10
  7. package/lib/client/WorkflowCanvas.js +12 -42
  8. package/lib/client/WorkflowProvider.js +10 -1
  9. package/lib/client/components/CollectionBlockInitializer.d.ts +7 -0
  10. package/lib/client/components/CollectionBlockInitializer.js +81 -0
  11. package/lib/client/components/CollectionFieldInitializers.d.ts +2 -0
  12. package/lib/client/components/CollectionFieldInitializers.js +89 -0
  13. package/lib/client/components/CollectionFieldset.js +25 -33
  14. package/lib/client/components/FilterDynamicComponent.d.ts +6 -0
  15. package/lib/client/components/FilterDynamicComponent.js +43 -0
  16. package/lib/client/components/NullRender.d.ts +1 -0
  17. package/lib/client/components/NullRender.js +10 -0
  18. package/lib/client/components/RadioWithTooltip.d.ts +7 -0
  19. package/lib/client/components/RadioWithTooltip.js +94 -0
  20. package/lib/client/constants.d.ts +10 -8
  21. package/lib/client/constants.js +52 -14
  22. package/lib/client/index.d.ts +0 -1
  23. package/lib/client/index.js +1 -10
  24. package/lib/client/locale/en-US.d.ts +18 -18
  25. package/lib/client/locale/en-US.js +19 -19
  26. package/lib/client/locale/zh-CN.d.ts +47 -20
  27. package/lib/client/locale/zh-CN.js +48 -21
  28. package/lib/client/nodes/calculation.d.ts +39 -7
  29. package/lib/client/nodes/calculation.js +165 -19
  30. package/lib/client/nodes/condition.d.ts +67 -4
  31. package/lib/client/nodes/condition.js +283 -31
  32. package/lib/client/nodes/create.d.ts +10 -10
  33. package/lib/client/nodes/create.js +28 -42
  34. package/lib/client/nodes/delay.d.ts +4 -4
  35. package/lib/client/nodes/delay.js +10 -8
  36. package/lib/client/nodes/destroy.d.ts +4 -7
  37. package/lib/client/nodes/destroy.js +4 -5
  38. package/lib/client/nodes/index.d.ts +10 -2
  39. package/lib/client/nodes/index.js +217 -110
  40. package/lib/client/nodes/manual/AssigneesSelect.d.ts +6 -0
  41. package/lib/client/nodes/manual/AssigneesSelect.js +65 -0
  42. package/lib/client/nodes/manual/ModeConfig.d.ts +5 -0
  43. package/lib/client/nodes/manual/ModeConfig.js +160 -0
  44. package/lib/client/nodes/manual/SchemaConfig.d.ts +6 -0
  45. package/lib/client/nodes/manual/SchemaConfig.js +715 -0
  46. package/lib/client/nodes/manual/WorkflowTodo.d.ts +8 -0
  47. package/lib/client/nodes/manual/WorkflowTodo.js +691 -0
  48. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +5 -0
  49. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +75 -0
  50. package/lib/client/nodes/manual/index.d.ts +62 -0
  51. package/lib/client/nodes/manual/index.js +137 -0
  52. package/lib/client/nodes/parallel.d.ts +12 -7
  53. package/lib/client/nodes/parallel.js +32 -39
  54. package/lib/client/nodes/query.d.ts +11 -19
  55. package/lib/client/nodes/query.js +40 -47
  56. package/lib/client/nodes/request.d.ts +77 -42
  57. package/lib/client/nodes/request.js +123 -69
  58. package/lib/client/nodes/update.d.ts +33 -29
  59. package/lib/client/nodes/update.js +14 -7
  60. package/lib/client/schemas/collection.d.ts +0 -3
  61. package/lib/client/schemas/collection.js +2 -7
  62. package/lib/client/schemas/executions.js +1 -1
  63. package/lib/client/schemas/workflows.js +1 -1
  64. package/lib/client/style.js +51 -9
  65. package/lib/client/triggers/collection.d.ts +44 -15
  66. package/lib/client/triggers/collection.js +104 -82
  67. package/lib/client/triggers/index.d.ts +6 -3
  68. package/lib/client/triggers/index.js +167 -74
  69. package/lib/client/triggers/schedule/DateFieldsSelect.js +1 -3
  70. package/lib/client/triggers/schedule/ScheduleConfig.js +15 -17
  71. package/lib/client/triggers/schedule/index.d.ts +7 -6
  72. package/lib/client/triggers/schedule/index.js +39 -81
  73. package/lib/client/utils.d.ts +1 -0
  74. package/lib/client/utils.js +38 -0
  75. package/lib/client/variable.d.ts +21 -0
  76. package/lib/client/variable.js +147 -0
  77. package/lib/server/Plugin.d.ts +3 -3
  78. package/lib/server/Plugin.js +12 -21
  79. package/lib/server/Processor.d.ts +9 -2
  80. package/lib/server/Processor.js +33 -33
  81. package/lib/server/actions/index.js +2 -4
  82. package/lib/server/actions/workflows.d.ts +1 -0
  83. package/lib/server/actions/workflows.js +80 -23
  84. package/lib/server/collections/executions.js +5 -7
  85. package/lib/server/collections/flow_nodes.js +6 -18
  86. package/lib/server/collections/jobs.js +3 -1
  87. package/lib/server/collections/workflows.js +8 -4
  88. package/lib/server/constants.d.ts +9 -3
  89. package/lib/server/constants.js +11 -5
  90. package/lib/server/functions/index.d.ts +4 -0
  91. package/lib/server/functions/index.js +38 -0
  92. package/lib/server/index.d.ts +0 -1
  93. package/lib/server/index.js +0 -14
  94. package/lib/server/instructions/calculation.d.ts +2 -7
  95. package/lib/server/instructions/calculation.js +32 -37
  96. package/lib/server/instructions/condition.d.ts +4 -4
  97. package/lib/server/instructions/condition.js +126 -54
  98. package/lib/server/instructions/index.js +1 -1
  99. package/lib/server/instructions/manual/actions.js +101 -0
  100. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.d.ts +2 -0
  101. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/jobs.js +2 -1
  102. package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.js +10 -10
  103. package/lib/server/instructions/manual/index.d.ts +25 -0
  104. package/lib/server/instructions/manual/index.js +200 -0
  105. package/lib/server/instructions/parallel.js +11 -7
  106. package/lib/server/instructions/request.d.ts +5 -4
  107. package/lib/server/instructions/request.js +60 -79
  108. package/lib/server/migrations/20230221032941-change-request-body-type.d.ts +5 -0
  109. package/lib/server/migrations/20230221032941-change-request-body-type.js +113 -0
  110. package/lib/server/migrations/20230221071831-calculation-expression.d.ts +4 -0
  111. package/lib/server/migrations/20230221071831-calculation-expression.js +143 -0
  112. package/lib/server/migrations/20230221121203-condition-calculation.d.ts +4 -0
  113. package/lib/server/migrations/20230221121203-condition-calculation.js +126 -0
  114. package/lib/server/migrations/20230221162902-jsonb-to-json.d.ts +4 -0
  115. package/lib/server/migrations/20230221162902-jsonb-to-json.js +81 -0
  116. package/lib/server/triggers/schedule.js +11 -3
  117. package/package.json +10 -10
  118. package/lib/client/calculators.d.ts +0 -89
  119. package/lib/client/calculators.js +0 -668
  120. package/lib/client/components/CollectionFieldSelect.d.ts +0 -2
  121. package/lib/client/components/CollectionFieldSelect.js +0 -106
  122. package/lib/client/components/EjsTextArea.d.ts +0 -2
  123. package/lib/client/components/EjsTextArea.js +0 -232
  124. package/lib/server/actions/jobs.d.ts +0 -2
  125. package/lib/server/actions/jobs.js +0 -39
  126. package/lib/server/calculators/index.d.ts +0 -40
  127. package/lib/server/calculators/index.js +0 -187
  128. package/lib/server/extensions/assignees/actions.js +0 -75
  129. package/lib/server/extensions/assignees/index.d.ts +0 -2
  130. package/lib/server/extensions/assignees/index.js +0 -273
  131. package/lib/server/extensions/index.d.ts +0 -3
  132. package/lib/server/extensions/index.js +0 -13
  133. package/lib/server/instructions/prompt.d.ts +0 -19
  134. package/lib/server/instructions/prompt.js +0 -131
  135. /package/lib/server/{extensions/assignees → instructions/manual}/actions.d.ts +0 -0
  136. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.d.ts +0 -0
  137. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users.js +0 -0
  138. /package/lib/server/{extensions/assignees/collections → instructions/manual/collecions}/users_jobs.d.ts +0 -0
@@ -1,668 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BaseTypeSet = void 0;
7
- exports.Calculation = Calculation;
8
- exports.Operand = Operand;
9
- exports.VariableComponent = VariableComponent;
10
- exports.calculators = exports.VariableTypesContext = exports.VariableTypes = void 0;
11
- exports.parseValue = parseValue;
12
- exports.useOperandContext = useOperandContext;
13
- exports.useVariableTypes = useVariableTypes;
14
-
15
- function _react() {
16
- const data = _interopRequireDefault(require("react"));
17
-
18
- _react = function _react() {
19
- return data;
20
- };
21
-
22
- return data;
23
- }
24
-
25
- function _antd() {
26
- const data = require("antd");
27
-
28
- _antd = function _antd() {
29
- return data;
30
- };
31
-
32
- return data;
33
- }
34
-
35
- function _css() {
36
- const data = require("@emotion/css");
37
-
38
- _css = function _css() {
39
- return data;
40
- };
41
-
42
- return data;
43
- }
44
-
45
- function _client() {
46
- const data = require("@nocobase/client");
47
-
48
- _client = function _client() {
49
- return data;
50
- };
51
-
52
- return data;
53
- }
54
-
55
- var _nodes = require("./nodes");
56
-
57
- var _FlowContext = require("./FlowContext");
58
-
59
- var _triggers = require("./triggers");
60
-
61
- function _reactI18next() {
62
- const data = require("react-i18next");
63
-
64
- _reactI18next = function _reactI18next() {
65
- return data;
66
- };
67
-
68
- return data;
69
- }
70
-
71
- function _client2() {
72
- const data = require("@nocobase/utils/client");
73
-
74
- _client2 = function _client2() {
75
- return data;
76
- };
77
-
78
- return data;
79
- }
80
-
81
- var _locale = require("./locale");
82
-
83
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
84
-
85
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
86
-
87
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
88
-
89
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
90
-
91
- function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
92
-
93
- 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."); }
94
-
95
- 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); }
96
-
97
- 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; }
98
-
99
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
100
-
101
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
102
-
103
- function NullRender() {
104
- return null;
105
- }
106
-
107
- const calculators = new (_client2().Registry)();
108
- exports.calculators = calculators;
109
- calculators.register('equal', {
110
- name: '=',
111
- type: 'boolean',
112
- group: 'boolean'
113
- });
114
- calculators.register('notEqual', {
115
- name: '≠',
116
- type: 'boolean',
117
- group: 'boolean'
118
- });
119
- calculators.register('gt', {
120
- name: '>',
121
- type: 'boolean',
122
- group: 'boolean'
123
- });
124
- calculators.register('gte', {
125
- name: '≥',
126
- type: 'boolean',
127
- group: 'boolean'
128
- });
129
- calculators.register('lt', {
130
- name: '<',
131
- type: 'boolean',
132
- group: 'boolean'
133
- });
134
- calculators.register('lte', {
135
- name: '≤',
136
- type: 'boolean',
137
- group: 'boolean'
138
- });
139
- calculators.register('add', {
140
- name: '+',
141
- type: 'number',
142
- group: 'number'
143
- });
144
- calculators.register('minus', {
145
- name: '-',
146
- type: 'number',
147
- group: 'number'
148
- });
149
- calculators.register('multiple', {
150
- name: '*',
151
- type: 'number',
152
- group: 'number'
153
- });
154
- calculators.register('divide', {
155
- name: '/',
156
- type: 'number',
157
- group: 'number'
158
- });
159
- calculators.register('mod', {
160
- name: '%',
161
- type: 'number',
162
- group: 'number'
163
- });
164
- calculators.register('includes', {
165
- name: '{{t("contains")}}',
166
- type: 'boolean',
167
- group: 'string'
168
- });
169
- calculators.register('notIncludes', {
170
- name: '{{t("does not contain")}}',
171
- type: 'boolean',
172
- group: 'string'
173
- });
174
- calculators.register('startsWith', {
175
- name: '{{t("starts with")}}',
176
- type: 'boolean',
177
- group: 'string'
178
- });
179
- calculators.register('notStartsWith', {
180
- name: '{{t("not starts with")}}',
181
- type: 'boolean',
182
- group: 'string'
183
- });
184
- calculators.register('endsWith', {
185
- name: '{{t("ends with")}}',
186
- type: 'boolean',
187
- group: 'string'
188
- });
189
- calculators.register('notEndsWith', {
190
- name: '{{t("not ends with")}}',
191
- type: 'boolean',
192
- group: 'string'
193
- });
194
- calculators.register('concat', {
195
- name: `{{t("concat", { ns: "${_locale.NAMESPACE}" })}}`,
196
- type: 'string',
197
- group: 'string'
198
- });
199
- const calculatorGroups = [{
200
- value: 'boolean',
201
- title: '{{t("Comparision")}}'
202
- }, {
203
- value: 'number',
204
- title: `{{t("Arithmetic calculation", { ns: "${_locale.NAMESPACE}" })}}`
205
- }, {
206
- value: 'string',
207
- title: `{{t("String operation", { ns: "${_locale.NAMESPACE}" })}}`
208
- }, {
209
- value: 'date',
210
- title: `{{t("Date", { ns: "${_locale.NAMESPACE}" })}}`
211
- }];
212
-
213
- function getGroupCalculators(group) {
214
- return Array.from(calculators.getEntities()).filter(([key, value]) => value.group === group);
215
- }
216
-
217
- const JT_VALUE_RE = /^\s*\{\{([\s\S]*)\}\}\s*$/;
218
-
219
- function getType(value) {
220
- if (value == null) {
221
- return 'null';
222
- }
223
-
224
- const type = typeof value;
225
-
226
- switch (type) {
227
- case 'object':
228
- break;
229
-
230
- default:
231
- // 'boolean'
232
- // 'number'
233
- // 'bigint'
234
- // 'string'
235
- // 'symbol'
236
- return type;
237
- }
238
-
239
- if (value instanceof Date) {
240
- return 'date';
241
- }
242
-
243
- return 'object';
244
- }
245
-
246
- function parseValue(value, Types) {
247
- var _type;
248
-
249
- const valueType = getType(value);
250
-
251
- if (valueType !== 'string') {
252
- return {
253
- type: 'constant',
254
- value,
255
- options: {
256
- type: valueType
257
- }
258
- };
259
- }
260
-
261
- const matcher = value.match(JT_VALUE_RE);
262
-
263
- if (!matcher) {
264
- return {
265
- type: 'constant',
266
- value,
267
- options: {
268
- type: 'string'
269
- }
270
- };
271
- }
272
-
273
- const _matcher$1$split = matcher[1].split('.'),
274
- _matcher$1$split2 = _toArray(_matcher$1$split),
275
- type = _matcher$1$split2[0],
276
- paths = _matcher$1$split2.slice(1);
277
-
278
- return {
279
- type,
280
- options: paths.length ? (_type = (Types || VariableTypes)[type]) === null || _type === void 0 ? void 0 : _type.parse(paths) : {}
281
- };
282
- }
283
-
284
- const BaseTypeSet = new Set(['boolean', 'number', 'string', 'date']);
285
- exports.BaseTypeSet = BaseTypeSet;
286
- const ConstantTypes = {
287
- null: {
288
- title: `{{t("Null", { ns: "${_locale.NAMESPACE}" })}}`,
289
- value: 'null',
290
- default: null,
291
- component: NullRender
292
- },
293
- string: {
294
- title: `{{t("String", { ns: "${_locale.NAMESPACE}" })}}`,
295
- value: 'string',
296
-
297
- component({
298
- onChange: _onChange,
299
- value
300
- }) {
301
- return _react().default.createElement(_antd().Input, {
302
- value: value,
303
- onChange: ev => _onChange(ev.target.value)
304
- });
305
- },
306
-
307
- default: ''
308
- },
309
- number: {
310
- title: '{{t("Number")}}',
311
- value: 'number',
312
-
313
- component({
314
- onChange,
315
- value
316
- }) {
317
- return _react().default.createElement(_antd().InputNumber, {
318
- value: value,
319
- onChange: onChange
320
- });
321
- },
322
-
323
- default: 0
324
- },
325
- boolean: {
326
- title: `{{t("Boolean", { ns: "${_locale.NAMESPACE}" })}}`,
327
- value: 'boolean',
328
-
329
- component({
330
- onChange,
331
- value
332
- }) {
333
- const _useTranslation = (0, _reactI18next().useTranslation)(),
334
- t = _useTranslation.t;
335
-
336
- return _react().default.createElement(_antd().Select, {
337
- value: value,
338
- onChange: onChange,
339
- placeholder: t('Select')
340
- }, _react().default.createElement(_antd().Select.Option, {
341
- value: true
342
- }, (0, _locale.lang)('True')), _react().default.createElement(_antd().Select.Option, {
343
- value: false
344
- }, (0, _locale.lang)('False')));
345
- },
346
-
347
- default: false
348
- } // date: {
349
- // title: '日期',
350
- // value: 'date',
351
- // component({ onChange, type, options, value }) {
352
- // return <DatePicker value={value} onChange={v => onChange({ value: v, type, options })}/>;
353
- // },
354
- // default: new Date()
355
- // }
356
-
357
- };
358
- const VariableTypes = {
359
- constant: {
360
- title: `{{t("Constant", { ns: "${_locale.NAMESPACE}" })}}`,
361
- value: 'constant',
362
- options: Object.values(ConstantTypes).map(item => ({
363
- value: item.value,
364
- label: item.title
365
- })),
366
-
367
- component(props) {
368
- var _ConstantTypes$option;
369
-
370
- const _useOperandContext = useOperandContext(),
371
- _useOperandContext$op = _useOperandContext.options,
372
- options = _useOperandContext$op === void 0 ? {
373
- type: 'string'
374
- } : _useOperandContext$op;
375
-
376
- return (_ConstantTypes$option = ConstantTypes[options.type]) === null || _ConstantTypes$option === void 0 ? void 0 : _ConstantTypes$option.component(props);
377
- },
378
-
379
- appendTypeValue({
380
- options = {
381
- type: 'string'
382
- }
383
- }) {
384
- return (options === null || options === void 0 ? void 0 : options.type) ? [options.type] : [];
385
- },
386
-
387
- onTypeChange([type, optionsType], onChange) {
388
- const value = ConstantTypes[optionsType].default;
389
- onChange(value);
390
- },
391
-
392
- parse(path) {
393
- return {
394
- path
395
- };
396
- }
397
-
398
- },
399
- $jobsMapByNodeId: {
400
- title: `{{t("Node result", { ns: "${_locale.NAMESPACE}" })}}`,
401
- value: '$jobsMapByNodeId',
402
-
403
- options() {
404
- const node = (0, _nodes.useNodeContext)();
405
- const stack = [];
406
-
407
- for (let current = node.upstream; current; current = current.upstream) {
408
- const _instructions$get = _nodes.instructions.get(current.type),
409
- getter = _instructions$get.getter; // Note: consider `getter` as the key of a value available node
410
-
411
-
412
- if (getter) {
413
- var _current$title;
414
-
415
- stack.push({
416
- value: current.id,
417
- label: (_current$title = current.title) !== null && _current$title !== void 0 ? _current$title : `#${current.id}`
418
- });
419
- }
420
- }
421
-
422
- return stack;
423
- },
424
-
425
- component(props) {
426
- const _useFlowContext = (0, _FlowContext.useFlowContext)(),
427
- nodes = _useFlowContext.nodes;
428
-
429
- const _useOperandContext2 = useOperandContext(),
430
- options = _useOperandContext2.options;
431
-
432
- if (!(options === null || options === void 0 ? void 0 : options.nodeId)) {
433
- return null;
434
- }
435
-
436
- const node = nodes.find(n => n.id == options.nodeId);
437
-
438
- if (!node) {
439
- return null;
440
- }
441
-
442
- const instruction = _nodes.instructions.get(node.type);
443
-
444
- return instruction === null || instruction === void 0 ? void 0 : instruction.getter(props);
445
- },
446
-
447
- appendTypeValue({
448
- options = {}
449
- }) {
450
- return options.nodeId ? [Number.parseInt(options.nodeId, 10)] : [];
451
- },
452
-
453
- onTypeChange([type, nodeId], onChange) {
454
- onChange(`{{${type}.${nodeId}}}`);
455
- },
456
-
457
- parse([nodeId, ...path]) {
458
- return {
459
- nodeId,
460
- path: path.join('.')
461
- };
462
- },
463
-
464
- stringify(next) {
465
- return `{{${next.join('.')}}}`;
466
- }
467
-
468
- },
469
- $context: {
470
- title: `{{t("Trigger variables", { ns: "${_locale.NAMESPACE}" })}}`,
471
- value: '$context',
472
-
473
- options() {
474
- var _trigger$getOptions, _trigger$getOptions2;
475
-
476
- const _useFlowContext2 = (0, _FlowContext.useFlowContext)(),
477
- workflow = _useFlowContext2.workflow;
478
-
479
- const trigger = _triggers.triggers.get(workflow.type);
480
-
481
- return (_trigger$getOptions = trigger === null || trigger === void 0 ? void 0 : (_trigger$getOptions2 = trigger.getOptions) === null || _trigger$getOptions2 === void 0 ? void 0 : _trigger$getOptions2.call(trigger, workflow.config)) !== null && _trigger$getOptions !== void 0 ? _trigger$getOptions : null;
482
- },
483
-
484
- component(props) {
485
- const _useFlowContext3 = (0, _FlowContext.useFlowContext)(),
486
- workflow = _useFlowContext3.workflow;
487
-
488
- const trigger = _triggers.triggers.get(workflow.type);
489
-
490
- return trigger === null || trigger === void 0 ? void 0 : trigger.getter(props);
491
- },
492
-
493
- appendTypeValue({
494
- options
495
- }) {
496
- return options.type ? [options.type] : [];
497
- },
498
-
499
- onTypeChange([type, optionType], onChange) {
500
- onChange(`{{${type}.${optionType}}}`);
501
- },
502
-
503
- parse([type, ...path]) {
504
- return _objectSpread({
505
- type
506
- }, (path === null || path === void 0 ? void 0 : path.length) ? {
507
- path: path.join('.')
508
- } : {});
509
- },
510
-
511
- stringify(next) {
512
- return `{{${next.join('.')}}}`;
513
- }
514
-
515
- } // calculation: Calculation
516
-
517
- };
518
- exports.VariableTypes = VariableTypes;
519
-
520
- const VariableTypesContext = _react().default.createContext({});
521
-
522
- exports.VariableTypesContext = VariableTypesContext;
523
-
524
- function useVariableTypes() {
525
- return _react().default.useContext(VariableTypesContext);
526
- }
527
-
528
- const OperandContext = _react().default.createContext(null);
529
-
530
- function useOperandContext() {
531
- return _react().default.useContext(OperandContext);
532
- }
533
-
534
- function Operand({
535
- value = null,
536
- onChange: _onChange2,
537
- children
538
- }) {
539
- const compile = (0, _client().useCompile)();
540
- const Types = useVariableTypes();
541
- const operand = parseValue(value, Types);
542
- const type = operand.type;
543
-
544
- const _ref = Types[type] || {},
545
- _ref$component = _ref.component,
546
- Variable = _ref$component === void 0 ? NullRender : _ref$component,
547
- appendTypeValue = _ref.appendTypeValue;
548
-
549
- return _react().default.createElement("div", {
550
- className: (0, _css().css)`
551
- display: flex;
552
- gap: .5em;
553
- align-items: center;
554
- `
555
- }, _react().default.createElement(_antd().Cascader, {
556
- allowClear: false,
557
- value: [Types[type] ? type : '', ...(appendTypeValue ? appendTypeValue(operand) : [])],
558
- options: Object.values(Types).map(item => {
559
- const options = typeof item.options === 'function' ? item.options() : item.options;
560
- return {
561
- label: compile(item.title),
562
- value: item.value,
563
- children: compile(options),
564
- disabled: options && !options.length,
565
- isLeaf: !options
566
- };
567
- }),
568
- onChange: next => {
569
- // 类型变化,包括主类型和子类型
570
- const _Types$next$ = Types[next[0]],
571
- onTypeChange = _Types$next$.onTypeChange,
572
- stringify = _Types$next$.stringify; // 自定义处理
573
-
574
- if (typeof onTypeChange === 'function') {
575
- return onTypeChange(next, _onChange2);
576
- } // 主类型变化
577
-
578
-
579
- if (next[0] !== type) {
580
- if (next[0] === 'constant') {
581
- return _onChange2(null);
582
- } else if (stringify) {
583
- return _onChange2(stringify(next));
584
- }
585
-
586
- return _onChange2({
587
- type: next[0],
588
- value: null
589
- });
590
- }
591
- }
592
- }), _react().default.createElement(OperandContext.Provider, {
593
- value: operand
594
- }, children !== null && children !== void 0 ? children : _react().default.createElement(Variable, {
595
- value: operand.value,
596
- onChange: _onChange2
597
- })));
598
- }
599
-
600
- function Calculation({
601
- calculator,
602
- operands = [null],
603
- onChange: _onChange3
604
- }) {
605
- const _useWorkflowTranslati = (0, _locale.useWorkflowTranslation)(),
606
- t = _useWorkflowTranslati.t;
607
-
608
- const compile = (0, _client().useCompile)();
609
- return _react().default.createElement(VariableTypesContext.Provider, {
610
- value: VariableTypes
611
- }, _react().default.createElement("div", {
612
- className: (0, _css().css)`
613
- display: flex;
614
- gap: .5em;
615
- align-items: center;
616
- `
617
- }, _react().default.createElement(Operand, {
618
- value: operands[0],
619
- onChange: v => _onChange3({
620
- calculator,
621
- operands: [v, operands[1]]
622
- })
623
- }), typeof operands[0] !== 'undefined' ? _react().default.createElement(_react().default.Fragment, null, _react().default.createElement(_antd().Select, {
624
- value: calculator,
625
- onChange: v => _onChange3({
626
- operands,
627
- calculator: v
628
- }),
629
- placeholder: t('Calculator')
630
- }, calculatorGroups.filter(group => Boolean(getGroupCalculators(group.value).length)).map(group => _react().default.createElement(_antd().Select.OptGroup, {
631
- key: group.value,
632
- label: compile(group.title)
633
- }, getGroupCalculators(group.value).map(([value, {
634
- name
635
- }]) => _react().default.createElement(_antd().Select.Option, {
636
- key: value,
637
- value: value
638
- }, compile(name)))))), _react().default.createElement(Operand, {
639
- value: operands[1],
640
- onChange: v => _onChange3({
641
- calculator,
642
- operands: [operands[0], v]
643
- })
644
- })) : null));
645
- }
646
-
647
- function VariableComponent({
648
- value,
649
- onChange,
650
- renderSchemaComponent
651
- }) {
652
- const VTypes = _objectSpread(_objectSpread({}, VariableTypes), {}, {
653
- constant: {
654
- title: `{{t("Constant", { ns: "${_locale.NAMESPACE}" })}}`,
655
- value: 'constant'
656
- }
657
- });
658
-
659
- const _parseValue = parseValue(value, VTypes),
660
- type = _parseValue.type;
661
-
662
- return _react().default.createElement(VariableTypesContext.Provider, {
663
- value: VTypes
664
- }, _react().default.createElement(Operand, {
665
- value: value,
666
- onChange: onChange
667
- }, type === 'constant' ? renderSchemaComponent() : null));
668
- }
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export default function (props: any): JSX.Element;