@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
@@ -0,0 +1,715 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SchemaConfig = SchemaConfig;
7
+ exports.SchemaConfigButton = SchemaConfigButton;
8
+
9
+ function _react() {
10
+ const data = _interopRequireWildcard(require("react"));
11
+
12
+ _react = function _react() {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _react2() {
20
+ const data = require("@formily/react");
21
+
22
+ _react2 = function _react2() {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
28
+
29
+ function _antd() {
30
+ const data = require("@formily/antd");
31
+
32
+ _antd = function _antd() {
33
+ return data;
34
+ };
35
+
36
+ return data;
37
+ }
38
+
39
+ function _lodash() {
40
+ const data = require("lodash");
41
+
42
+ _lodash = function _lodash() {
43
+ return data;
44
+ };
45
+
46
+ return data;
47
+ }
48
+
49
+ function _reactI18next() {
50
+ const data = require("react-i18next");
51
+
52
+ _reactI18next = function _reactI18next() {
53
+ return data;
54
+ };
55
+
56
+ return data;
57
+ }
58
+
59
+ function _client() {
60
+ const data = require("@nocobase/client");
61
+
62
+ _client = function _client() {
63
+ return data;
64
+ };
65
+
66
+ return data;
67
+ }
68
+
69
+ function _client2() {
70
+ const data = require("@nocobase/utils/client");
71
+
72
+ _client2 = function _client2() {
73
+ return data;
74
+ };
75
+
76
+ return data;
77
+ }
78
+
79
+ var _triggers = require("../../triggers");
80
+
81
+ var _ = require("..");
82
+
83
+ var _FlowContext = require("../../FlowContext");
84
+
85
+ var _locale = require("../../locale");
86
+
87
+ var _constants = require("../../constants");
88
+
89
+ const _excluded = ["insert"],
90
+ _excluded2 = ["unique", "type"],
91
+ _excluded3 = ["properties"],
92
+ _excluded4 = ["action", "actionProps"];
93
+
94
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
95
+
96
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
97
+
98
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
99
+
100
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
101
+
102
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
103
+
104
+ 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."); }
105
+
106
+ 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); }
107
+
108
+ 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; }
109
+
110
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
111
+
112
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
113
+
114
+ 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; }
115
+
116
+ 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; }
117
+
118
+ 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; }
119
+
120
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
121
+
122
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
123
+
124
+ function useTriggerInitializers() {
125
+ const _useFlowContext = (0, _FlowContext.useFlowContext)(),
126
+ workflow = _useFlowContext.workflow;
127
+
128
+ const trigger = (0, _triggers.useTrigger)();
129
+ return trigger.useInitializers ? trigger.useInitializers(workflow.config) : null;
130
+ }
131
+
132
+ ;
133
+
134
+ function SimpleDesigner() {
135
+ const _useTranslation = (0, _reactI18next().useTranslation)(),
136
+ t = _useTranslation.t;
137
+
138
+ return _react().default.createElement(_client().GeneralSchemaDesigner, {
139
+ title: t('Form')
140
+ }, _react().default.createElement(_client().SchemaSettings.BlockTitleItem, null), _react().default.createElement(_client().SchemaSettings.Divider, null), _react().default.createElement(_client().SchemaSettings.Remove, {
141
+ removeParentsIfNoChildren: true,
142
+ breakRemoveOn: {
143
+ 'x-component': 'Grid'
144
+ }
145
+ }));
146
+ }
147
+
148
+ function FormBlockInitializer(_ref) {
149
+ let insert = _ref.insert,
150
+ props = _objectWithoutProperties(_ref, _excluded);
151
+
152
+ return _react().default.createElement(_client().SchemaInitializer.Item, _objectSpread(_objectSpread({}, props), {}, {
153
+ onClick: () => {
154
+ insert({
155
+ type: 'void',
156
+ 'x-component': 'CardItem',
157
+ 'x-designer': 'SimpleDesigner',
158
+ properties: {
159
+ grid: {
160
+ type: 'void',
161
+ 'x-component': 'Grid',
162
+ 'x-initializer': 'AddFormField'
163
+ }
164
+ }
165
+ });
166
+ }
167
+ }));
168
+ }
169
+
170
+ function AddBlockButton(props) {
171
+ const current = (0, _.useNodeContext)();
172
+ const nodes = (0, _.useAvailableUpstreams)(current);
173
+ const triggerInitializers = [useTriggerInitializers()].filter(Boolean);
174
+ const nodeBlockInitializers = nodes.map(node => {
175
+ var _instruction$useIniti;
176
+
177
+ const instruction = _.instructions.get(node.type);
178
+
179
+ return instruction === null || instruction === void 0 ? void 0 : (_instruction$useIniti = instruction.useInitializers) === null || _instruction$useIniti === void 0 ? void 0 : _instruction$useIniti.call(instruction, node);
180
+ }).filter(Boolean);
181
+ const dataBlockInitializers = [...triggerInitializers, ...(nodeBlockInitializers.length ? [{
182
+ key: 'nodes',
183
+ type: 'subMenu',
184
+ title: `{{t("Node result", { ns: "${_locale.NAMESPACE}" })}}`,
185
+ children: nodeBlockInitializers
186
+ }] : [])].filter(Boolean);
187
+ const items = [...(dataBlockInitializers.length ? [{
188
+ type: 'itemGroup',
189
+ title: '{{t("Data blocks")}}',
190
+ children: dataBlockInitializers
191
+ }] : []), {
192
+ type: 'itemGroup',
193
+ title: '{{t("Form")}}',
194
+ children: [{
195
+ key: 'form',
196
+ type: 'item',
197
+ title: '{{t("Form")}}',
198
+ component: FormBlockInitializer
199
+ }]
200
+ }, {
201
+ type: 'itemGroup',
202
+ title: '{{t("Other blocks")}}',
203
+ children: [{
204
+ type: 'item',
205
+ title: '{{t("Markdown")}}',
206
+ component: 'MarkdownBlockInitializer'
207
+ }]
208
+ }];
209
+ return _react().default.createElement(_client().SchemaInitializer.Button, _objectSpread(_objectSpread({}, props), {}, {
210
+ wrap: _client().gridRowColWrap,
211
+ items: items,
212
+ title: "{{t('Add block')}}"
213
+ }));
214
+ }
215
+
216
+ ;
217
+ const GroupLabels = {
218
+ basic: '{{t("Basic")}}',
219
+ choices: '{{t("Choices")}}',
220
+ media: '{{t("Media")}}',
221
+ datetime: '{{t("Date & Time")}}',
222
+ relation: '{{t("Relation")}}',
223
+ advanced: '{{t("Advanced type")}}',
224
+ systemInfo: '{{t("System info")}}',
225
+ others: '{{t("Others")}}'
226
+ };
227
+
228
+ function getOptions(interfaces) {
229
+ const fields = {};
230
+ Object.keys(interfaces).forEach(type => {
231
+ const schema = interfaces[type];
232
+ const _schema$group = schema.group,
233
+ group = _schema$group === void 0 ? 'others' : _schema$group;
234
+ fields[group] = fields[group] || {};
235
+ (0, _lodash().set)(fields, [group, type], schema);
236
+ });
237
+ return Object.keys(GroupLabels).filter(groupName => ['basic', 'choices', 'datetime', 'media'].includes(groupName)).map(groupName => ({
238
+ title: GroupLabels[groupName],
239
+ children: Object.keys(fields[groupName] || {}).map(type => {
240
+ const field = fields[groupName][type];
241
+ return _objectSpread({
242
+ value: type,
243
+ title: field.title,
244
+ name: type
245
+ }, fields[groupName][type]);
246
+ }).sort((a, b) => a.order - b.order)
247
+ }));
248
+ }
249
+
250
+ function useCommonInterfaceInitializers() {
251
+ const _useCollectionManager = (0, _client().useCollectionManager)(),
252
+ interfaces = _useCollectionManager.interfaces;
253
+
254
+ const options = getOptions(interfaces);
255
+ return options.map(group => ({
256
+ key: group.title,
257
+ type: 'itemGroup',
258
+ title: group.title,
259
+ children: group.children.map(item => ({
260
+ key: item.name,
261
+ type: 'item',
262
+ title: item.title,
263
+ component: FormFieldInitializer,
264
+ fieldInterface: item.name
265
+ }))
266
+ }));
267
+ }
268
+
269
+ const AddFormFieldButtonContext = _react().default.createContext({});
270
+
271
+ function AddFormField(props) {
272
+ const _props$insertPosition = props.insertPosition,
273
+ insertPosition = _props$insertPosition === void 0 ? 'beforeEnd' : _props$insertPosition,
274
+ component = props.component;
275
+ const items = useCommonInterfaceInitializers();
276
+ const collection = (0, _react().useContext)(_client().CollectionContext);
277
+
278
+ const _useState = (0, _react().useState)(null),
279
+ _useState2 = _slicedToArray(_useState, 2),
280
+ interfaceOptions = _useState2[0],
281
+ setInterface = _useState2[1];
282
+
283
+ const _useState3 = (0, _react().useState)(),
284
+ _useState4 = _slicedToArray(_useState3, 2),
285
+ insert = _useState4[0],
286
+ setCallback = _useState4[1];
287
+
288
+ return _react().default.createElement(AddFormFieldButtonContext.Provider, {
289
+ value: {
290
+ onAddField(item) {
291
+ const _cloneDeep = (0, _lodash().cloneDeep)(item),
292
+ _cloneDeep$properties = _cloneDeep.properties,
293
+ unique = _cloneDeep$properties.unique,
294
+ type = _cloneDeep$properties.type,
295
+ properties = _objectWithoutProperties(_cloneDeep$properties, _excluded2),
296
+ options = _objectWithoutProperties(_cloneDeep, _excluded3);
297
+
298
+ delete properties.name['x-disabled'];
299
+ setInterface(_objectSpread(_objectSpread({}, options), {}, {
300
+ properties
301
+ }));
302
+ },
303
+
304
+ setCallback
305
+ }
306
+ }, _react().default.createElement(_client().SchemaInitializer.Button, {
307
+ wrap: _client().gridRowColWrap,
308
+ insertPosition: insertPosition,
309
+ items: items,
310
+ component: component,
311
+ title: "{{t('Configure fields')}}"
312
+ }), _react().default.createElement(_client().ActionContext.Provider, {
313
+ value: {
314
+ visible: Boolean(interfaceOptions)
315
+ }
316
+ }, interfaceOptions ? _react().default.createElement(_client().SchemaComponent, {
317
+ schema: {
318
+ type: 'void',
319
+ name: 'drawer',
320
+ title: '{{t("Configure field")}}',
321
+ 'x-decorator': 'Form',
322
+ 'x-component': 'Action.Drawer',
323
+ properties: _objectSpread(_objectSpread({}, interfaceOptions.properties), {}, {
324
+ footer: {
325
+ type: 'void',
326
+ 'x-component': 'Action.Drawer.Footer',
327
+ properties: {
328
+ cancel: {
329
+ type: 'void',
330
+ title: '{{t("Cancel")}}',
331
+ 'x-component': 'Action',
332
+ 'x-component-props': {
333
+ useAction() {
334
+ const form = (0, _react2().useForm)();
335
+ return {
336
+ run() {
337
+ return _asyncToGenerator(function* () {
338
+ setCallback(null);
339
+ setInterface(null);
340
+ form.reset();
341
+ })();
342
+ }
343
+
344
+ };
345
+ }
346
+
347
+ }
348
+ },
349
+ submit: {
350
+ type: 'void',
351
+ title: '{{t("Submit")}}',
352
+ 'x-component': 'Action',
353
+ 'x-component-props': {
354
+ type: 'primary',
355
+
356
+ useAction() {
357
+ const _useForm = (0, _react2().useForm)(),
358
+ values = _useForm.values,
359
+ query = _useForm.query;
360
+
361
+ return {
362
+ run() {
363
+ return _asyncToGenerator(function* () {
364
+ var _values$name, _values$uiSchema$titl, _values$uiSchema, _collection$fields, _collection$fields2;
365
+
366
+ const options = interfaceOptions.default;
367
+ const defaultName = (0, _client2().uid)();
368
+ options.name = (_values$name = values.name) !== null && _values$name !== void 0 ? _values$name : defaultName;
369
+ options.uiSchema.title = (_values$uiSchema$titl = (_values$uiSchema = values.uiSchema) === null || _values$uiSchema === void 0 ? void 0 : _values$uiSchema.title) !== null && _values$uiSchema$titl !== void 0 ? _values$uiSchema$titl : defaultName;
370
+ options.interface = interfaceOptions.name;
371
+ const existed = (_collection$fields = collection.fields) === null || _collection$fields === void 0 ? void 0 : _collection$fields.find(item => item.name === options.name);
372
+
373
+ if (existed) {
374
+ const field = query('name').take();
375
+ field.setFeedback({
376
+ type: 'error',
377
+ // code: 'FormulaError',
378
+ messages: [(0, _locale.lang)('Field name existed in form')]
379
+ });
380
+ return;
381
+ }
382
+
383
+ (_collection$fields2 = collection.fields) === null || _collection$fields2 === void 0 ? void 0 : _collection$fields2.push((0, _client2().merge)(options, values));
384
+ insert({
385
+ name: options.name,
386
+ type: options.uiSchema.type,
387
+ 'x-decorator': 'FormItem',
388
+ 'x-component': 'CollectionField',
389
+ 'x-component-props': {},
390
+ 'x-collection-field': `${collection.name}.${options.name}`,
391
+ 'x-designer': 'FormItem.Designer'
392
+ });
393
+ setCallback(null);
394
+ setInterface(null);
395
+ })();
396
+ }
397
+
398
+ };
399
+ }
400
+
401
+ }
402
+ }
403
+ }
404
+ }
405
+ })
406
+ },
407
+ components: {
408
+ ArrayTable: _antd().ArrayTable
409
+ }
410
+ }) : null));
411
+ }
412
+
413
+ function FormFieldInitializer(props) {
414
+ const item = props.item,
415
+ insert = props.insert;
416
+
417
+ const _useContext = (0, _react().useContext)(AddFormFieldButtonContext),
418
+ onAddField = _useContext.onAddField,
419
+ setCallback = _useContext.setCallback;
420
+
421
+ const _useCollectionManager2 = (0, _client().useCollectionManager)(),
422
+ getInterface = _useCollectionManager2.getInterface;
423
+
424
+ const interfaceOptions = getInterface(item.fieldInterface);
425
+ return _react().default.createElement(_client().SchemaInitializer.Item, {
426
+ key: item.fieldInterface,
427
+ onClick: () => {
428
+ setCallback(() => insert);
429
+ onAddField(interfaceOptions);
430
+ }
431
+ });
432
+ }
433
+
434
+ ;
435
+
436
+ function findFormFields(formSchema, fields) {
437
+ if (!formSchema) {
438
+ return;
439
+ }
440
+
441
+ if (!formSchema.properties) {
442
+ if (formSchema['x-component'] === 'CollectionField') {
443
+ fields.push(formSchema);
444
+ }
445
+
446
+ return;
447
+ }
448
+
449
+ Object.keys(formSchema.properties).forEach(key => {
450
+ findFormFields(formSchema.properties[key], fields);
451
+ });
452
+ }
453
+
454
+ function SchemaComponentRefreshProvider(props) {
455
+ const ctx = (0, _client().useSchemaComponentContext)();
456
+ return _react().default.createElement(_client().SchemaComponentContext.Provider, {
457
+ value: _objectSpread(_objectSpread({}, ctx), {}, {
458
+ refresh() {
459
+ var _ctx$refresh, _props$onRefresh;
460
+
461
+ ctx === null || ctx === void 0 ? void 0 : (_ctx$refresh = ctx.refresh) === null || _ctx$refresh === void 0 ? void 0 : _ctx$refresh.call(ctx);
462
+ props === null || props === void 0 ? void 0 : (_props$onRefresh = props.onRefresh) === null || _props$onRefresh === void 0 ? void 0 : _props$onRefresh.call(props);
463
+ }
464
+
465
+ })
466
+ }, props.children);
467
+ }
468
+
469
+ ;
470
+
471
+ function ActionInitializer(_ref2) {
472
+ let action = _ref2.action,
473
+ actionProps = _ref2.actionProps,
474
+ props = _objectWithoutProperties(_ref2, _excluded4);
475
+
476
+ return _react().default.createElement(_client().InitializerWithSwitch, _objectSpread(_objectSpread({}, props), {}, {
477
+ schema: {
478
+ type: 'void',
479
+ title: props.title,
480
+ 'x-decorator': 'ManualActionStatusProvider',
481
+ 'x-decorator-props': {
482
+ value: action
483
+ },
484
+ 'x-component': 'Action',
485
+ 'x-component-props': _objectSpread(_objectSpread({}, actionProps), {}, {
486
+ useAction: '{{ useSubmit }}'
487
+ }),
488
+ 'x-designer': 'Action.Designer',
489
+ 'x-action': `${action}`
490
+ },
491
+ type: "x-action"
492
+ }));
493
+ }
494
+
495
+ function AddActionButton(props) {
496
+ return _react().default.createElement(_client().SchemaInitializer.Button, _objectSpread(_objectSpread({}, props), {}, {
497
+ items: [{
498
+ key: _constants.JOB_STATUS.RESOLVED,
499
+ type: 'item',
500
+ title: `{{t("Continue the process", { ns: "${_locale.NAMESPACE}" })}}`,
501
+ component: ActionInitializer,
502
+ action: _constants.JOB_STATUS.RESOLVED,
503
+ actionProps: {
504
+ type: 'primary'
505
+ }
506
+ }, {
507
+ key: _constants.JOB_STATUS.REJECTED,
508
+ type: 'item',
509
+ title: `{{t("Terminate the process", { ns: "${_locale.NAMESPACE}" })}}`,
510
+ component: ActionInitializer,
511
+ action: _constants.JOB_STATUS.REJECTED,
512
+ actionProps: {
513
+ type: 'danger'
514
+ }
515
+ }, {
516
+ key: _constants.JOB_STATUS.PENDING,
517
+ type: 'item',
518
+ title: `{{t("Save temporarily", { ns: "${_locale.NAMESPACE}" })}}`,
519
+ component: ActionInitializer,
520
+ action: _constants.JOB_STATUS.PENDING
521
+ }],
522
+ title: "{{t('Configure actions')}}"
523
+ }));
524
+ } // NOTE: fake useAction for ui configuration
525
+
526
+
527
+ function useSubmit() {
528
+ return {
529
+ run() {}
530
+
531
+ };
532
+ }
533
+
534
+ function useFlowRecordFromBlock() {
535
+ return {};
536
+ }
537
+
538
+ function SchemaConfig({
539
+ value,
540
+ onChange
541
+ }) {
542
+ const ctx = (0, _react().useContext)(_client().SchemaComponentContext);
543
+ const trigger = (0, _triggers.useTrigger)();
544
+ const node = (0, _.useNodeContext)();
545
+ const nodes = (0, _.useAvailableUpstreams)(node);
546
+ const form = (0, _react2().useForm)();
547
+
548
+ const _useFlowContext2 = (0, _FlowContext.useFlowContext)(),
549
+ workflow = _useFlowContext2.workflow;
550
+
551
+ const _ref3 = value !== null && value !== void 0 ? value : {},
552
+ _ref3$collection = _ref3.collection,
553
+ collection = _ref3$collection === void 0 ? {
554
+ name: (0, _client2().uid)(),
555
+ fields: []
556
+ } : _ref3$collection,
557
+ blocks = _ref3.blocks,
558
+ actions = _ref3.actions;
559
+
560
+ const nodeInitializers = {};
561
+ const nodeComponents = {};
562
+ nodes.forEach(item => {
563
+ const instruction = _.instructions.get(item.type);
564
+
565
+ Object.assign(nodeInitializers, instruction.initializers);
566
+ Object.assign(nodeComponents, instruction.components);
567
+ });
568
+ const schema = new (_react2().Schema)({
569
+ properties: {
570
+ drawer: {
571
+ type: 'void',
572
+ title: '{{t("Configure form")}}',
573
+ 'x-decorator': 'Form',
574
+ 'x-component': 'Action.Drawer',
575
+ 'x-component-props': {
576
+ className: 'nb-action-popup'
577
+ },
578
+ properties: {
579
+ tabs: {
580
+ type: 'void',
581
+ 'x-component': 'Tabs',
582
+ 'x-component-props': {},
583
+ 'x-initializer': 'TabPaneInitializers',
584
+ 'x-initializer-props': {
585
+ gridInitializer: 'AddBlockButton'
586
+ },
587
+ properties: blocks !== null && blocks !== void 0 ? blocks : {
588
+ tab1: {
589
+ type: 'void',
590
+ title: `{{t("Manual", { ns: "${_locale.NAMESPACE}" })}}`,
591
+ 'x-component': 'Tabs.TabPane',
592
+ 'x-designer': 'Tabs.Designer',
593
+ properties: {
594
+ grid: {
595
+ type: 'void',
596
+ 'x-component': 'Grid',
597
+ 'x-initializer': 'AddBlockButton',
598
+ properties: {}
599
+ }
600
+ }
601
+ }
602
+ }
603
+ },
604
+ footer: {
605
+ type: 'void',
606
+ 'x-component': 'Action.Drawer.Footer',
607
+ 'x-component-props': {
608
+ style: {
609
+ background: '#fff'
610
+ }
611
+ },
612
+ properties: {
613
+ actions: {
614
+ type: 'void',
615
+ 'x-component': 'ActionBar',
616
+ 'x-initializer': 'AddActionButton',
617
+ properties: actions !== null && actions !== void 0 ? actions : {
618
+ resolve: {
619
+ type: 'void',
620
+ title: `{{t("Continue the process", { ns: "${_locale.NAMESPACE}" })}}`,
621
+ 'x-decorator': 'ManualActionStatusProvider',
622
+ 'x-decorator-props': {
623
+ value: _constants.JOB_STATUS.RESOLVED
624
+ },
625
+ 'x-component': 'Action',
626
+ 'x-component-props': {
627
+ type: 'primary',
628
+ useAction: '{{ useSubmit }}'
629
+ },
630
+ 'x-designer': 'Action.Designer',
631
+ 'x-action': `${_constants.JOB_STATUS.RESOLVED}`
632
+ }
633
+ }
634
+ }
635
+ }
636
+ }
637
+ }
638
+ }
639
+ }
640
+ });
641
+ return _react().default.createElement(_client().SchemaComponentContext.Provider, {
642
+ value: _objectSpread(_objectSpread({}, ctx), {}, {
643
+ designable: !workflow.executed
644
+ })
645
+ }, _react().default.createElement(_client().SchemaInitializerProvider, {
646
+ initializers: _objectSpread(_objectSpread({
647
+ AddBlockButton,
648
+ AddFormField,
649
+ AddActionButton
650
+ }, trigger.initializers), nodeInitializers)
651
+ }, _react().default.createElement(SchemaComponentRefreshProvider, {
652
+ onRefresh: () => {
653
+ var _footer$properties$ac;
654
+
655
+ const _get = (0, _lodash().get)(schema.toJSON(), 'properties.drawer.properties'),
656
+ tabs = _get.tabs,
657
+ footer = _get.footer;
658
+
659
+ const fields = [];
660
+ findFormFields(tabs, fields);
661
+
662
+ for (let i = collection.fields.length - 1; i >= 0; i--) {
663
+ if (!fields.find(field => field.name === collection.fields[i].name)) {
664
+ collection.fields.splice(i, 1);
665
+ }
666
+ }
667
+
668
+ const actionKeys = Object.values((_footer$properties$ac = footer.properties.actions.properties) !== null && _footer$properties$ac !== void 0 ? _footer$properties$ac : {}).reduce((actions, {
669
+ ['x-action']: status
670
+ }) => actions.concat(Number.parseInt(status, 10)), []);
671
+ form.setValuesIn('config.actions', actionKeys);
672
+ onChange({
673
+ collection,
674
+ blocks: tabs.properties,
675
+ actions: footer.properties.actions.properties
676
+ });
677
+ }
678
+ }, _react().default.createElement(_client().CollectionProvider, {
679
+ collection: collection
680
+ }, _react().default.createElement(_client().SchemaComponent, {
681
+ schema: schema,
682
+ components: _objectSpread(_objectSpread({}, nodeComponents), {}, {
683
+ // NOTE: fake provider component
684
+ ManualActionStatusProvider(props) {
685
+ return props.children;
686
+ },
687
+
688
+ SimpleDesigner
689
+ }),
690
+ scope: {
691
+ useSubmit,
692
+ useFlowRecordFromBlock
693
+ }
694
+ })))));
695
+ }
696
+
697
+ function SchemaConfigButton(props) {
698
+ const _useFlowContext3 = (0, _FlowContext.useFlowContext)(),
699
+ workflow = _useFlowContext3.workflow;
700
+
701
+ const _useState5 = (0, _react().useState)(false),
702
+ _useState6 = _slicedToArray(_useState5, 2),
703
+ visible = _useState6[0],
704
+ setVisible = _useState6[1];
705
+
706
+ return _react().default.createElement(_react().default.Fragment, null, _react().default.createElement("div", {
707
+ className: "ant-btn ant-btn-primary",
708
+ onClick: () => setVisible(true)
709
+ }, workflow.executed ? (0, _locale.lang)('View user interface') : (0, _locale.lang)('Configure user interface')), _react().default.createElement(_client().ActionContext.Provider, {
710
+ value: {
711
+ visible,
712
+ setVisible
713
+ }
714
+ }, props.children));
715
+ }