@nocobase/plugin-workflow 0.9.1-alpha.2 → 0.9.2-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 (131) hide show
  1. package/lib/client/AddButton.js +17 -64
  2. package/lib/client/Branch.js +0 -13
  3. package/lib/client/ExecutionCanvas.js +16 -63
  4. package/lib/client/ExecutionLink.js +3 -21
  5. package/lib/client/ExecutionPage.js +1 -19
  6. package/lib/client/ExecutionResourceProvider.js +6 -23
  7. package/lib/client/FlowContext.js +0 -8
  8. package/lib/client/WorkflowCanvas.js +56 -127
  9. package/lib/client/WorkflowLink.js +3 -21
  10. package/lib/client/WorkflowPage.js +1 -19
  11. package/lib/client/WorkflowProvider.js +24 -47
  12. package/lib/client/WorkflowShortcut.js +0 -16
  13. package/lib/client/components/CollectionBlockInitializer.js +12 -22
  14. package/lib/client/components/CollectionFieldInitializers.js +5 -24
  15. package/lib/client/components/CollectionFieldset.js +31 -79
  16. package/lib/client/components/Duration.js +0 -14
  17. package/lib/client/components/DynamicExpression.d.ts +4 -0
  18. package/lib/client/components/DynamicExpression.js +102 -0
  19. package/lib/client/components/FieldsSelect.d.ts +2 -0
  20. package/lib/client/components/FieldsSelect.js +66 -0
  21. package/lib/client/components/FilterDynamicComponent.js +1 -10
  22. package/lib/client/components/NullRender.js +0 -1
  23. package/lib/client/components/OpenDrawer.js +10 -35
  24. package/lib/client/components/RadioWithTooltip.js +5 -27
  25. package/lib/client/components/renderEngineReference.d.ts +1 -0
  26. package/lib/client/components/renderEngineReference.js +55 -0
  27. package/lib/client/constants.js +0 -9
  28. package/lib/client/index.js +0 -6
  29. package/lib/client/interfaces/expression.d.ts +3 -0
  30. package/lib/client/interfaces/expression.js +37 -0
  31. package/lib/client/locale/index.js +5 -15
  32. package/lib/client/locale/pt-BR.d.ts +130 -0
  33. package/lib/client/locale/pt-BR.js +136 -0
  34. package/lib/client/locale/zh-CN.d.ts +16 -1
  35. package/lib/client/locale/zh-CN.js +17 -2
  36. package/lib/client/nodes/calculation.d.ts +54 -3
  37. package/lib/client/nodes/calculation.js +136 -63
  38. package/lib/client/nodes/condition.d.ts +1 -1
  39. package/lib/client/nodes/condition.js +21 -76
  40. package/lib/client/nodes/create.d.ts +35 -9
  41. package/lib/client/nodes/create.js +13 -19
  42. package/lib/client/nodes/delay.d.ts +1 -3
  43. package/lib/client/nodes/delay.js +3 -10
  44. package/lib/client/nodes/destroy.d.ts +1 -6
  45. package/lib/client/nodes/destroy.js +12 -9
  46. package/lib/client/nodes/index.d.ts +2 -2
  47. package/lib/client/nodes/index.js +45 -147
  48. package/lib/client/nodes/manual/AssigneesSelect.js +6 -17
  49. package/lib/client/nodes/manual/ModeConfig.js +0 -27
  50. package/lib/client/nodes/manual/SchemaConfig.js +87 -449
  51. package/lib/client/nodes/manual/WorkflowTodo.js +99 -163
  52. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +4 -20
  53. package/lib/client/nodes/manual/forms/customForm.d.ts +40 -0
  54. package/lib/client/nodes/manual/forms/customForm.js +411 -0
  55. package/lib/client/nodes/manual/index.d.ts +12 -1
  56. package/lib/client/nodes/manual/index.js +54 -41
  57. package/lib/client/nodes/parallel.js +7 -41
  58. package/lib/client/nodes/query.d.ts +28 -7
  59. package/lib/client/nodes/query.js +15 -22
  60. package/lib/client/nodes/request.d.ts +2 -3
  61. package/lib/client/nodes/request.js +5 -22
  62. package/lib/client/nodes/update.d.ts +1 -6
  63. package/lib/client/nodes/update.js +8 -16
  64. package/lib/client/schemas/collection.d.ts +20 -4
  65. package/lib/client/schemas/collection.js +26 -22
  66. package/lib/client/schemas/executions.js +3 -18
  67. package/lib/client/schemas/workflows.js +10 -33
  68. package/lib/client/style.js +24 -21
  69. package/lib/client/triggers/collection.d.ts +24 -20
  70. package/lib/client/triggers/collection.js +34 -123
  71. package/lib/client/triggers/index.d.ts +2 -5
  72. package/lib/client/triggers/index.js +34 -105
  73. package/lib/client/triggers/schedule/DateFieldsSelect.js +6 -29
  74. package/lib/client/triggers/schedule/EndsByField.js +1 -18
  75. package/lib/client/triggers/schedule/OnField.js +10 -38
  76. package/lib/client/triggers/schedule/RepeatField.js +4 -32
  77. package/lib/client/triggers/schedule/ScheduleConfig.js +10 -51
  78. package/lib/client/triggers/schedule/index.d.ts +21 -0
  79. package/lib/client/triggers/schedule/index.js +21 -22
  80. package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +8 -4
  81. package/lib/client/utils.d.ts +1 -0
  82. package/lib/client/utils.js +31 -10
  83. package/lib/client/variable.d.ts +7 -6
  84. package/lib/client/variable.js +132 -71
  85. package/lib/index.js +0 -2
  86. package/lib/server/Plugin.d.ts +7 -7
  87. package/lib/server/Plugin.js +76 -111
  88. package/lib/server/Processor.d.ts +2 -0
  89. package/lib/server/Processor.js +62 -125
  90. package/lib/server/actions/index.js +3 -10
  91. package/lib/server/actions/nodes.js +34 -87
  92. package/lib/server/actions/workflows.js +46 -96
  93. package/lib/server/collections/executions.js +1 -1
  94. package/lib/server/collections/flow_nodes.js +7 -4
  95. package/lib/server/collections/jobs.js +1 -1
  96. package/lib/server/collections/workflows.js +3 -4
  97. package/lib/server/fields/expression-field.d.ts +8 -0
  98. package/lib/server/fields/expression-field.js +26 -0
  99. package/lib/server/fields/index.d.ts +1 -0
  100. package/lib/server/fields/index.js +12 -0
  101. package/lib/server/functions/index.js +3 -14
  102. package/lib/server/index.js +0 -6
  103. package/lib/server/instructions/calculation.js +22 -17
  104. package/lib/server/instructions/condition.js +8 -52
  105. package/lib/server/instructions/create.js +31 -15
  106. package/lib/server/instructions/delay.js +4 -32
  107. package/lib/server/instructions/destroy.js +6 -12
  108. package/lib/server/instructions/index.js +6 -23
  109. package/lib/server/instructions/manual/actions.js +22 -31
  110. package/lib/server/instructions/manual/collecions/users_jobs.js +1 -1
  111. package/lib/server/instructions/manual/index.d.ts +13 -12
  112. package/lib/server/instructions/manual/index.js +9 -47
  113. package/lib/server/instructions/parallel.js +9 -36
  114. package/lib/server/instructions/query.js +17 -15
  115. package/lib/server/instructions/request.js +7 -30
  116. package/lib/server/instructions/update.js +8 -14
  117. package/lib/server/migrations/20221129153547-calculation-variables.js +3 -27
  118. package/lib/server/migrations/20230221032941-change-request-body-type.js +3 -26
  119. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -33
  120. package/lib/server/migrations/20230221121203-condition-calculation.js +5 -28
  121. package/lib/server/migrations/20230221162902-jsonb-to-json.js +3 -18
  122. package/lib/server/migrations/20230411034722-manual-multi-form.d.ts +4 -0
  123. package/lib/server/migrations/20230411034722-manual-multi-form.js +303 -0
  124. package/lib/server/models/Execution.js +0 -5
  125. package/lib/server/models/FlowNode.js +0 -5
  126. package/lib/server/models/Job.js +0 -5
  127. package/lib/server/models/Workflow.js +0 -5
  128. package/lib/server/triggers/collection.js +39 -61
  129. package/lib/server/triggers/index.js +3 -22
  130. package/lib/server/triggers/schedule.js +72 -194
  131. package/package.json +14 -11
@@ -0,0 +1,411 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _react() {
8
+ const data = _interopRequireWildcard(require("react"));
9
+ _react = function _react() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _lodash() {
15
+ const data = require("lodash");
16
+ _lodash = function _lodash() {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _core() {
22
+ const data = require("@formily/core");
23
+ _core = function _core() {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _react2() {
29
+ const data = require("@formily/react");
30
+ _react2 = function _react2() {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _antd() {
36
+ const data = require("@formily/antd");
37
+ _antd = function _antd() {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _client() {
43
+ const data = require("@nocobase/client");
44
+ _client = function _client() {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _client2() {
50
+ const data = require("@nocobase/utils/client");
51
+ _client2 = function _client2() {
52
+ return data;
53
+ };
54
+ return data;
55
+ }
56
+ var _constants = require("../../../constants");
57
+ var _locale = require("../../../locale");
58
+ const _excluded = ["insert"],
59
+ _excluded2 = ["unique", "type"],
60
+ _excluded3 = ["properties"];
61
+ 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); }
62
+ 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; }
63
+ 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); } }
64
+ 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); }); }; }
65
+ 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; }
66
+ 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; }
67
+ 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; }
68
+ 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; }
69
+ 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; }
70
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
71
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
72
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
73
+ 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."); }
74
+ 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); }
75
+ 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; }
76
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
77
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
78
+ const FormCollectionContext = _react().default.createContext(null);
79
+ function FormCollectionProvider(props) {
80
+ var _props$collection$fie, _props$collection;
81
+ const _useState = (0, _react().useState)((_props$collection$fie = (_props$collection = props.collection) === null || _props$collection === void 0 ? void 0 : _props$collection.fields) !== null && _props$collection$fie !== void 0 ? _props$collection$fie : []),
82
+ _useState2 = _slicedToArray(_useState, 2),
83
+ fields = _useState2[0],
84
+ setCollectionFields = _useState2[1];
85
+ return _react().default.createElement(FormCollectionContext.Provider, {
86
+ value: {
87
+ setCollectionFields
88
+ }
89
+ }, _react().default.createElement(_client().CollectionProvider, {
90
+ collection: _objectSpread(_objectSpread({}, props.collection), {}, {
91
+ fields
92
+ })
93
+ }, props.children));
94
+ }
95
+ function CustomFormBlockInitializer(_ref) {
96
+ let insert = _ref.insert,
97
+ props = _objectWithoutProperties(_ref, _excluded);
98
+ return _react().default.createElement(_client().SchemaInitializer.Item, _objectSpread(_objectSpread({}, props), {}, {
99
+ onClick: () => {
100
+ insert({
101
+ type: 'void',
102
+ 'x-decorator': 'FormCollectionProvider',
103
+ 'x-decorator-props': {
104
+ collection: {
105
+ name: (0, _client2().uid)(),
106
+ fields: []
107
+ }
108
+ },
109
+ 'x-component': 'CardItem',
110
+ 'x-component-props': {
111
+ title: '{{t("Form")}}'
112
+ },
113
+ 'x-designer': 'SimpleDesigner',
114
+ 'x-designer-props': {
115
+ type: 'customForm'
116
+ },
117
+ properties: {
118
+ [(0, _client2().uid)()]: {
119
+ type: 'void',
120
+ 'x-component': 'FormV2',
121
+ 'x-component-props': {
122
+ // disabled / read-pretty / initialValues
123
+ useProps: '{{ useFormBlockProps }}'
124
+ },
125
+ properties: {
126
+ grid: {
127
+ type: 'void',
128
+ 'x-component': 'Grid',
129
+ 'x-initializer': 'AddCustomFormField'
130
+ },
131
+ actions: {
132
+ type: 'void',
133
+ 'x-decorator': 'ActionBarProvider',
134
+ 'x-component': 'ActionBar',
135
+ 'x-component-props': {
136
+ layout: 'one-column',
137
+ style: {
138
+ marginTop: '1.5em'
139
+ }
140
+ },
141
+ 'x-initializer': 'AddActionButton',
142
+ properties: {
143
+ resolve: {
144
+ type: 'void',
145
+ title: `{{t("Continue the process", { ns: "${_locale.NAMESPACE}" })}}`,
146
+ 'x-decorator': 'ManualActionStatusProvider',
147
+ 'x-decorator-props': {
148
+ value: _constants.JOB_STATUS.RESOLVED
149
+ },
150
+ 'x-component': 'Action',
151
+ 'x-component-props': {
152
+ type: 'primary',
153
+ useAction: '{{ useSubmit }}'
154
+ },
155
+ 'x-designer': 'Action.Designer',
156
+ 'x-action': `${_constants.JOB_STATUS.RESOLVED}`
157
+ }
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ });
164
+ }
165
+ }));
166
+ }
167
+ const GroupLabels = {
168
+ basic: '{{t("Basic")}}',
169
+ choices: '{{t("Choices")}}',
170
+ media: '{{t("Media")}}',
171
+ datetime: '{{t("Date & Time")}}',
172
+ relation: '{{t("Relation")}}',
173
+ advanced: '{{t("Advanced type")}}',
174
+ systemInfo: '{{t("System info")}}',
175
+ others: '{{t("Others")}}'
176
+ };
177
+ function getOptions(interfaces) {
178
+ const fields = {};
179
+ Object.keys(interfaces).forEach(type => {
180
+ const schema = interfaces[type];
181
+ const _schema$group = schema.group,
182
+ group = _schema$group === void 0 ? 'others' : _schema$group;
183
+ fields[group] = fields[group] || {};
184
+ (0, _lodash().set)(fields, [group, type], schema);
185
+ });
186
+ return Object.keys(GroupLabels).filter(groupName => ['basic', 'choices', 'datetime', 'media'].includes(groupName)).map(groupName => ({
187
+ title: GroupLabels[groupName],
188
+ children: Object.keys(fields[groupName] || {}).map(type => {
189
+ const field = fields[groupName][type];
190
+ return _objectSpread({
191
+ value: type,
192
+ title: field.title,
193
+ name: type
194
+ }, fields[groupName][type]);
195
+ }).sort((a, b) => a.order - b.order)
196
+ }));
197
+ }
198
+ function useCommonInterfaceInitializers() {
199
+ const _useCollectionManager = (0, _client().useCollectionManager)(),
200
+ interfaces = _useCollectionManager.interfaces;
201
+ const options = getOptions(interfaces);
202
+ return options.map(group => ({
203
+ key: group.title,
204
+ type: 'itemGroup',
205
+ title: group.title,
206
+ children: group.children.map(item => ({
207
+ key: item.name,
208
+ type: 'item',
209
+ title: item.title,
210
+ component: CustomFormFieldInitializer,
211
+ fieldInterface: item.name
212
+ }))
213
+ }));
214
+ }
215
+ const AddCustomFormFieldButtonContext = _react().default.createContext({});
216
+ function AddCustomFormField(props) {
217
+ const _props$insertPosition = props.insertPosition,
218
+ insertPosition = _props$insertPosition === void 0 ? 'beforeEnd' : _props$insertPosition,
219
+ component = props.component;
220
+ const items = useCommonInterfaceInitializers();
221
+ const collection = (0, _react().useContext)(_client().CollectionContext);
222
+ const _useState3 = (0, _react().useState)(null),
223
+ _useState4 = _slicedToArray(_useState3, 2),
224
+ interfaceOptions = _useState4[0],
225
+ setInterface = _useState4[1];
226
+ const _useState5 = (0, _react().useState)(),
227
+ _useState6 = _slicedToArray(_useState5, 2),
228
+ insert = _useState6[0],
229
+ setCallback = _useState6[1];
230
+ const _useContext = (0, _react().useContext)(FormCollectionContext),
231
+ setCollectionFields = _useContext.setCollectionFields;
232
+ return _react().default.createElement(AddCustomFormFieldButtonContext.Provider, {
233
+ value: {
234
+ onAddField(item) {
235
+ const _cloneDeep = (0, _lodash().cloneDeep)(item),
236
+ _cloneDeep$properties = _cloneDeep.properties,
237
+ unique = _cloneDeep$properties.unique,
238
+ type = _cloneDeep$properties.type,
239
+ properties = _objectWithoutProperties(_cloneDeep$properties, _excluded2),
240
+ options = _objectWithoutProperties(_cloneDeep, _excluded3);
241
+ delete properties.name['x-disabled'];
242
+ setInterface(_objectSpread(_objectSpread({}, options), {}, {
243
+ properties
244
+ }));
245
+ },
246
+ setCallback
247
+ }
248
+ }, _react().default.createElement(_client().SchemaInitializer.Button, {
249
+ wrap: _client().gridRowColWrap,
250
+ insertPosition: insertPosition,
251
+ items: items,
252
+ component: component,
253
+ title: "{{t('Configure fields')}}"
254
+ }), _react().default.createElement(_client().ActionContext.Provider, {
255
+ value: {
256
+ visible: Boolean(interfaceOptions)
257
+ }
258
+ }, interfaceOptions ? _react().default.createElement(_client().SchemaComponent, {
259
+ schema: {
260
+ type: 'void',
261
+ name: 'drawer',
262
+ title: '{{t("Configure field")}}',
263
+ 'x-decorator': 'Form',
264
+ 'x-component': 'Action.Drawer',
265
+ properties: _objectSpread(_objectSpread({}, interfaceOptions.properties), {}, {
266
+ footer: {
267
+ type: 'void',
268
+ 'x-component': 'Action.Drawer.Footer',
269
+ properties: {
270
+ cancel: {
271
+ type: 'void',
272
+ title: '{{t("Cancel")}}',
273
+ 'x-component': 'Action',
274
+ 'x-component-props': {
275
+ useAction() {
276
+ const form = (0, _react2().useForm)();
277
+ return {
278
+ run() {
279
+ return _asyncToGenerator(function* () {
280
+ setCallback(null);
281
+ setInterface(null);
282
+ form.reset();
283
+ })();
284
+ }
285
+ };
286
+ }
287
+ }
288
+ },
289
+ submit: {
290
+ type: 'void',
291
+ title: '{{t("Submit")}}',
292
+ 'x-component': 'Action',
293
+ 'x-component-props': {
294
+ type: 'primary',
295
+ useAction() {
296
+ const _useForm = (0, _react2().useForm)(),
297
+ values = _useForm.values,
298
+ query = _useForm.query;
299
+ return {
300
+ run() {
301
+ return _asyncToGenerator(function* () {
302
+ var _values$name, _values$uiSchema$titl, _values$uiSchema, _collection$fields;
303
+ const options = interfaceOptions.default;
304
+ const defaultName = (0, _client2().uid)();
305
+ options.name = (_values$name = values.name) !== null && _values$name !== void 0 ? _values$name : defaultName;
306
+ 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;
307
+ options.interface = interfaceOptions.name;
308
+ const existed = (_collection$fields = collection.fields) === null || _collection$fields === void 0 ? void 0 : _collection$fields.find(item => item.name === options.name);
309
+ if (existed) {
310
+ const field = query('name').take();
311
+ field.setFeedback({
312
+ type: 'error',
313
+ // code: 'FormulaError',
314
+ messages: [(0, _locale.lang)('Field name existed in form')]
315
+ });
316
+ return;
317
+ }
318
+ const newField = (0, _client2().merge)(options, values);
319
+ setCollectionFields([...collection.fields, newField]);
320
+ insert({
321
+ name: options.name,
322
+ type: options.uiSchema.type,
323
+ 'x-decorator': 'FormItem',
324
+ 'x-component': 'CollectionField',
325
+ 'x-interface-options': newField,
326
+ 'x-collection-field': `${collection.name}.${options.name}`,
327
+ 'x-designer': 'FormItem.Designer'
328
+ });
329
+ setCallback(null);
330
+ setInterface(null);
331
+ })();
332
+ }
333
+ };
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ })
340
+ },
341
+ components: {
342
+ ArrayTable: _antd().ArrayTable
343
+ }
344
+ }) : null));
345
+ }
346
+ function CustomFormFieldInitializer(props) {
347
+ const item = props.item,
348
+ insert = props.insert;
349
+ const _useContext2 = (0, _react().useContext)(AddCustomFormFieldButtonContext),
350
+ onAddField = _useContext2.onAddField,
351
+ setCallback = _useContext2.setCallback;
352
+ const _useCollectionManager2 = (0, _client().useCollectionManager)(),
353
+ getInterface = _useCollectionManager2.getInterface;
354
+ const interfaceOptions = getInterface(item.fieldInterface);
355
+ return _react().default.createElement(_client().SchemaInitializer.Item, {
356
+ key: item.fieldInterface,
357
+ onClick: () => {
358
+ setCallback(() => insert);
359
+ onAddField(interfaceOptions);
360
+ }
361
+ });
362
+ }
363
+ ;
364
+ function useFormBlockProps() {
365
+ var _user$data;
366
+ const _useRecord = (0, _client().useRecord)(),
367
+ status = _useRecord.status,
368
+ result = _useRecord.result,
369
+ userId = _useRecord.userId;
370
+ const _useCurrentUserContex = (0, _client().useCurrentUserContext)(),
371
+ user = _useCurrentUserContex.data;
372
+ const _useFieldSchema = (0, _react2().useFieldSchema)(),
373
+ name = _useFieldSchema.name;
374
+ const pattern = Boolean(status) ? (result === null || result === void 0 ? void 0 : result[name]) ? 'readPretty' : 'disabled' : (user === null || user === void 0 ? void 0 : (_user$data = user.data) === null || _user$data === void 0 ? void 0 : _user$data.id) !== userId ? 'disabled' : 'editable';
375
+ const form = (0, _react().useMemo)(() => {
376
+ var _result$name;
377
+ return (0, _core().createForm)({
378
+ pattern,
379
+ initialValues: (_result$name = result === null || result === void 0 ? void 0 : result[name]) !== null && _result$name !== void 0 ? _result$name : {}
380
+ });
381
+ }, [result, name]);
382
+ return {
383
+ form
384
+ };
385
+ }
386
+ var _default = {
387
+ title: `{{t("Custom form", { ns: "${_locale.NAMESPACE}" })}}`,
388
+ config: {
389
+ initializer: {
390
+ key: 'customForm',
391
+ type: 'item',
392
+ title: `{{t("Custom form", { ns: "${_locale.NAMESPACE}" })}}`,
393
+ component: CustomFormBlockInitializer
394
+ },
395
+ initializers: {
396
+ AddCustomFormField
397
+ },
398
+ components: {
399
+ FormCollectionProvider
400
+ }
401
+ },
402
+ block: {
403
+ scope: {
404
+ useFormBlockProps
405
+ },
406
+ components: {
407
+ FormCollectionProvider: _client().CollectionProvider
408
+ }
409
+ }
410
+ };
411
+ exports.default = _default;
@@ -41,9 +41,14 @@ declare const _default: {
41
41
  schema: {
42
42
  type: string;
43
43
  'x-component': string;
44
+ default: any;
44
45
  };
45
46
  };
46
47
  };
48
+ forms: {
49
+ type: string;
50
+ default: {};
51
+ };
47
52
  };
48
53
  view: {};
49
54
  scope: {};
@@ -53,7 +58,13 @@ declare const _default: {
53
58
  ModeConfig: typeof ModeConfig;
54
59
  AssigneesSelect: typeof AssigneesSelect;
55
60
  };
56
- getOptions(config: any, types: any): any;
61
+ getOptions(config: any, types: any): {
62
+ key: string;
63
+ value: string;
64
+ label: any;
65
+ title: any;
66
+ children: any;
67
+ }[];
57
68
  useInitializers(node: any): SchemaInitializerItemOptions | null;
58
69
  initializers: {
59
70
  CollectionFieldInitializers: typeof CollectionFieldInitializers;
@@ -4,41 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  function _client() {
9
8
  const data = require("@nocobase/client");
10
-
11
9
  _client = function _client() {
12
10
  return data;
13
11
  };
14
-
15
12
  return data;
16
13
  }
17
-
18
14
  var _CollectionBlockInitializer = require("../../components/CollectionBlockInitializer");
19
-
20
15
  var _CollectionFieldInitializers = require("../../components/CollectionFieldInitializers");
21
-
22
16
  var _variable = require("../../variable");
23
-
24
17
  var _locale = require("../../locale");
25
-
26
18
  var _SchemaConfig = require("./SchemaConfig");
27
-
28
19
  var _ModeConfig = require("./ModeConfig");
29
-
30
20
  var _AssigneesSelect = require("./AssigneesSelect");
31
-
32
21
  const MULTIPLE_ASSIGNED_MODE = {
33
22
  SINGLE: Symbol('single'),
34
23
  ALL: Symbol('all'),
35
24
  ANY: Symbol('any'),
36
25
  ALL_PERCENTAGE: Symbol('all percentage'),
37
26
  ANY_PERCENTAGE: Symbol('any percentage')
38
- }; // TODO(optimize): change to register way
39
-
27
+ };
28
+ // TODO(optimize): change to register way
40
29
  const initializerGroup = _client().BlockInitializers.items.find(group => group.key === 'media');
41
-
42
30
  if (!initializerGroup.children.find(item => item.key === 'workflowTodos')) {
43
31
  initializerGroup.children.push({
44
32
  key: 'workflowTodos',
@@ -48,7 +36,6 @@ if (!initializerGroup.children.find(item => item.key === 'workflowTodos')) {
48
36
  icon: 'CheckSquareOutlined'
49
37
  });
50
38
  }
51
-
52
39
  var _default = {
53
40
  title: `{{t("Manual", { ns: "${_locale.NAMESPACE}" })}}`,
54
41
  type: 'manual',
@@ -59,7 +46,8 @@ var _default = {
59
46
  title: `{{t("Assignees", { ns: "${_locale.NAMESPACE}" })}}`,
60
47
  'x-decorator': 'FormItem',
61
48
  'x-component': 'AssigneesSelect',
62
- 'x-component-props': {// multiple: true,
49
+ 'x-component-props': {
50
+ // multiple: true,
63
51
  },
64
52
  required: true,
65
53
  default: []
@@ -87,9 +75,14 @@ var _default = {
87
75
  properties: {
88
76
  schema: {
89
77
  type: 'object',
90
- 'x-component': 'SchemaConfig'
78
+ 'x-component': 'SchemaConfig',
79
+ default: null
91
80
  }
92
81
  }
82
+ },
83
+ forms: {
84
+ type: 'object',
85
+ default: {}
93
86
  }
94
87
  },
95
88
  view: {},
@@ -100,36 +93,56 @@ var _default = {
100
93
  ModeConfig: _ModeConfig.ModeConfig,
101
94
  AssigneesSelect: _AssigneesSelect.AssigneesSelect
102
95
  },
103
-
104
96
  getOptions(config, types) {
105
- var _config$schema$collec, _config$schema, _config$schema$collec2;
106
-
107
- const fields = ((_config$schema$collec = (_config$schema = config.schema) === null || _config$schema === void 0 ? void 0 : (_config$schema$collec2 = _config$schema.collection) === null || _config$schema$collec2 === void 0 ? void 0 : _config$schema$collec2.fields) !== null && _config$schema$collec !== void 0 ? _config$schema$collec : []).map(field => ({
108
- key: field.name,
109
- value: field.name,
110
- label: field.uiSchema.title,
111
- title: field.uiSchema.title
112
- }));
113
- const filteredFields = (0, _variable.filterTypedFields)(fields, types);
114
- return filteredFields.length ? filteredFields : null;
97
+ var _config$forms;
98
+ const formKeys = Object.keys((_config$forms = config.forms) !== null && _config$forms !== void 0 ? _config$forms : {});
99
+ if (!formKeys.length) {
100
+ return null;
101
+ }
102
+ const options = formKeys.map(formKey => {
103
+ var _form$collection$fiel, _form$collection;
104
+ const form = config.forms[formKey];
105
+ const fields = ((_form$collection$fiel = (_form$collection = form.collection) === null || _form$collection === void 0 ? void 0 : _form$collection.fields) !== null && _form$collection$fiel !== void 0 ? _form$collection$fiel : []).map(field => ({
106
+ key: field.name,
107
+ value: field.name,
108
+ label: field.uiSchema.title,
109
+ title: field.uiSchema.title
110
+ }));
111
+ const filteredFields = (0, _variable.filterTypedFields)(fields, types);
112
+ return filteredFields.length ? {
113
+ key: formKey,
114
+ value: formKey,
115
+ label: form.title || formKey,
116
+ title: form.title || formKey,
117
+ children: filteredFields
118
+ } : null;
119
+ }).filter(Boolean);
120
+ return options.length ? options : null;
115
121
  },
116
-
117
122
  useInitializers(node) {
118
- var _node$config$schema, _node$config$schema$c, _node$config$schema$c2, _node$title;
119
-
120
- if (!((_node$config$schema = node.config.schema) === null || _node$config$schema === void 0 ? void 0 : (_node$config$schema$c = _node$config$schema.collection) === null || _node$config$schema$c === void 0 ? void 0 : (_node$config$schema$c2 = _node$config$schema$c.fields) === null || _node$config$schema$c2 === void 0 ? void 0 : _node$config$schema$c2.length) || node.config.mode) {
123
+ var _node$config$forms;
124
+ const formKeys = Object.keys((_node$config$forms = node.config.forms) !== null && _node$config$forms !== void 0 ? _node$config$forms : {});
125
+ if (!formKeys.length || node.config.mode) {
121
126
  return null;
122
127
  }
123
-
124
- return {
125
- type: 'item',
126
- title: (_node$title = node.title) !== null && _node$title !== void 0 ? _node$title : `#${node.id}`,
127
- component: _CollectionBlockInitializer.CollectionBlockInitializer,
128
- collection: node.config.schema.collection,
129
- dataSource: `{{$jobsMapByNodeId.${node.id}}}`
130
- };
128
+ const forms = formKeys.map(formKey => {
129
+ var _form$collection2, _form$collection2$fie, _form$title;
130
+ const form = node.config.forms[formKey];
131
+ return ((_form$collection2 = form.collection) === null || _form$collection2 === void 0 ? void 0 : (_form$collection2$fie = _form$collection2.fields) === null || _form$collection2$fie === void 0 ? void 0 : _form$collection2$fie.length) ? {
132
+ type: 'item',
133
+ title: (_form$title = form.title) !== null && _form$title !== void 0 ? _form$title : formKey,
134
+ component: _CollectionBlockInitializer.CollectionBlockInitializer,
135
+ collection: form.collection,
136
+ dataSource: `{{$jobsMapByNodeId.${node.id}.${formKey}}}`
137
+ } : null;
138
+ }).filter(Boolean);
139
+ return forms.length ? {
140
+ key: 'forms',
141
+ type: 'subMenu',
142
+ title: node.title,
143
+ children: forms
144
+ } : null;
131
145
  },
132
-
133
146
  initializers: {
134
147
  CollectionFieldInitializers: _CollectionFieldInitializers.CollectionFieldInitializers
135
148
  }