@nocobase/flow-engine 2.0.0-alpha.13 → 2.0.0-alpha.14

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.
@@ -65,7 +65,7 @@ function FieldModelRenderer(props) {
65
65
  let val;
66
66
  if (e && e.target && typeof e.target.value !== "undefined") {
67
67
  val = e.target.value;
68
- } else if (typeof e === "string" || typeof e === "object" && !(e instanceof Event)) {
68
+ } else if (typeof e === "string" || typeof e === "number" || typeof e === "object" && !(e instanceof Event)) {
69
69
  val = e;
70
70
  } else {
71
71
  val = "";
@@ -89,7 +89,7 @@ function FieldModelRenderer(props) {
89
89
  onCompositionEnd: handleCompositionEnd
90
90
  };
91
91
  (0, import_react.useEffect)(() => {
92
- model.setProps(modelProps);
92
+ model && model.setProps(modelProps);
93
93
  }, [modelProps]);
94
94
  return /* @__PURE__ */ import_react.default.createElement(import_flow_engine.FlowModelRenderer, { model, ...rest });
95
95
  }
@@ -49,7 +49,9 @@ export declare class DataSource {
49
49
  addCollection(collection: Collection | CollectionOptions): void;
50
50
  updateCollection(newOptions: CollectionOptions): void;
51
51
  upsertCollection(options: CollectionOptions): Collection;
52
- upsertCollections(collections: CollectionOptions[]): void;
52
+ upsertCollections(collections: CollectionOptions[], options?: {
53
+ clearFields?: boolean;
54
+ }): void;
53
55
  removeCollection(name: string): void;
54
56
  clearCollections(): void;
55
57
  setOptions(newOptions?: any): void;
@@ -68,9 +70,13 @@ export declare class CollectionManager {
68
70
  get flowEngine(): FlowEngine;
69
71
  addCollection(collection: Collection | CollectionOptions): void;
70
72
  removeCollection(name: string): void;
71
- updateCollection(newOptions: CollectionOptions): void;
73
+ updateCollection(newOptions: CollectionOptions, options?: {
74
+ clearFields?: boolean;
75
+ }): void;
72
76
  upsertCollection(options: CollectionOptions): Collection;
73
- upsertCollections(collections: CollectionOptions[]): void;
77
+ upsertCollections(collections: CollectionOptions[], options?: {
78
+ clearFields?: boolean;
79
+ }): void;
74
80
  sortCollectionsByInherits(collections: CollectionOptions[]): CollectionOptions[];
75
81
  getCollection(name: string): Collection | undefined;
76
82
  getCollections(): Collection[];
@@ -97,7 +103,9 @@ export declare class Collection {
97
103
  get titleCollectionField(): CollectionField;
98
104
  initInherits(): void;
99
105
  setDataSource(dataSource: DataSource): void;
100
- setOptions(newOptions?: any): void;
106
+ setOptions(newOptions?: any, options?: {
107
+ clearFields?: boolean;
108
+ }): void;
101
109
  getFields(): CollectionField[];
102
110
  getToOneAssociationFields(): CollectionField[];
103
111
  getAssociationFields(types?: any[]): CollectionField[];
@@ -153,8 +153,8 @@ const _DataSource = class _DataSource {
153
153
  upsertCollection(options) {
154
154
  return this.collectionManager.upsertCollection(options);
155
155
  }
156
- upsertCollections(collections) {
157
- return this.collectionManager.upsertCollections(collections);
156
+ upsertCollections(collections, options = {}) {
157
+ return this.collectionManager.upsertCollections(collections, options);
158
158
  }
159
159
  removeCollection(name) {
160
160
  return this.collectionManager.removeCollection(name);
@@ -205,12 +205,12 @@ const _CollectionManager = class _CollectionManager {
205
205
  removeCollection(name) {
206
206
  this.collections.delete(name);
207
207
  }
208
- updateCollection(newOptions) {
208
+ updateCollection(newOptions, options = {}) {
209
209
  const collection = this.getCollection(newOptions.name);
210
210
  if (!collection) {
211
211
  throw new Error(`Collection ${newOptions.name} not found`);
212
212
  }
213
- collection.setOptions(newOptions);
213
+ collection.setOptions(newOptions, options);
214
214
  }
215
215
  upsertCollection(options) {
216
216
  if (this.collections.has(options.name)) {
@@ -220,10 +220,10 @@ const _CollectionManager = class _CollectionManager {
220
220
  }
221
221
  return this.getCollection(options.name);
222
222
  }
223
- upsertCollections(collections) {
223
+ upsertCollections(collections, options = {}) {
224
224
  for (const collection of (0, import_sortCollectionsByInherits.sortCollectionsByInherits)(collections)) {
225
225
  if (this.collections.has(collection.name)) {
226
- this.updateCollection(collection);
226
+ this.updateCollection(collection, options);
227
227
  } else {
228
228
  this.addCollection(collection);
229
229
  }
@@ -378,10 +378,13 @@ const _Collection = class _Collection {
378
378
  setDataSource(dataSource) {
379
379
  this.dataSource = dataSource;
380
380
  }
381
- setOptions(newOptions = {}) {
381
+ setOptions(newOptions = {}, options = {}) {
382
382
  Object.keys(this.options).forEach((key) => delete this.options[key]);
383
383
  Object.assign(this.options, newOptions);
384
384
  this.initInherits();
385
+ if (options.clearFields) {
386
+ this.clearFields();
387
+ }
385
388
  this.upsertFields(this.options.fields || []);
386
389
  }
387
390
  getFields() {
@@ -446,7 +449,6 @@ const _Collection = class _Collection {
446
449
  return field.targetCollection.getFieldByPath(otherKeys.join("."));
447
450
  }
448
451
  getField(fieldName) {
449
- this.setFields(this.options.fields);
450
452
  return this.fields.get(fieldName);
451
453
  }
452
454
  getFullFieldPath(name) {
@@ -130,6 +130,7 @@ const _MultiRecordResource = class _MultiRecordResource extends import_baseRecor
130
130
  async create(data, options) {
131
131
  const config = this.mergeRequestConfig({ data }, this.createActionOptions, options);
132
132
  await this.runAction("create", config);
133
+ this.emit("saved", data);
133
134
  await this.refresh();
134
135
  }
135
136
  async get(filterByTk) {
@@ -155,6 +156,7 @@ const _MultiRecordResource = class _MultiRecordResource extends import_baseRecor
155
156
  options
156
157
  );
157
158
  await this.runAction("update", config);
159
+ this.emit("saved", data);
158
160
  await this.refresh();
159
161
  }
160
162
  async destroySelectedRows() {
@@ -69,6 +69,7 @@ const _SingleRecordResource = class _SingleRecordResource extends import_baseRec
69
69
  ...config,
70
70
  data
71
71
  });
72
+ this.emit("saved", data);
72
73
  if ((options == null ? void 0 : options.refresh) !== false) {
73
74
  await this.refresh();
74
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.14",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -33,5 +33,5 @@
33
33
  ],
34
34
  "author": "NocoBase Team",
35
35
  "license": "AGPL-3.0",
36
- "gitHead": "b5b60c6ddb996b96bdc1e6d21604ef6585ae01e8"
36
+ "gitHead": "6b4785d03d0a551f1fe6815e9bcbc7a9f38901df"
37
37
  }
@@ -34,7 +34,7 @@ export function FieldModelRenderer(props: any) {
34
34
  let val;
35
35
  if (e && e.target && typeof e.target.value !== 'undefined') {
36
36
  val = e.target.value;
37
- } else if (typeof e === 'string' || (typeof e === 'object' && !(e instanceof Event))) {
37
+ } else if (typeof e === 'string' || typeof e === 'number' || (typeof e === 'object' && !(e instanceof Event))) {
38
38
  val = e;
39
39
  } else {
40
40
  val = '';
@@ -61,7 +61,7 @@ export function FieldModelRenderer(props: any) {
61
61
  onCompositionEnd: handleCompositionEnd,
62
62
  };
63
63
  useEffect(() => {
64
- model.setProps(modelProps);
64
+ model && model.setProps(modelProps);
65
65
  }, [modelProps]);
66
66
 
67
67
  return <FlowModelRenderer model={model} {...rest} />;
@@ -144,8 +144,8 @@ export class DataSource {
144
144
  return this.collectionManager.upsertCollection(options);
145
145
  }
146
146
 
147
- upsertCollections(collections: CollectionOptions[]) {
148
- return this.collectionManager.upsertCollections(collections);
147
+ upsertCollections(collections: CollectionOptions[], options: { clearFields?: boolean } = {}) {
148
+ return this.collectionManager.upsertCollections(collections, options);
149
149
  }
150
150
 
151
151
  removeCollection(name: string) {
@@ -210,12 +210,12 @@ export class CollectionManager {
210
210
  this.collections.delete(name);
211
211
  }
212
212
 
213
- updateCollection(newOptions: CollectionOptions) {
213
+ updateCollection(newOptions: CollectionOptions, options: { clearFields?: boolean } = {}) {
214
214
  const collection = this.getCollection(newOptions.name);
215
215
  if (!collection) {
216
216
  throw new Error(`Collection ${newOptions.name} not found`);
217
217
  }
218
- collection.setOptions(newOptions);
218
+ collection.setOptions(newOptions, options);
219
219
  }
220
220
 
221
221
  upsertCollection(options: CollectionOptions) {
@@ -227,10 +227,10 @@ export class CollectionManager {
227
227
  return this.getCollection(options.name);
228
228
  }
229
229
 
230
- upsertCollections(collections: CollectionOptions[]) {
230
+ upsertCollections(collections: CollectionOptions[], options: { clearFields?: boolean } = {}) {
231
231
  for (const collection of sortCollectionsByInherits(collections)) {
232
232
  if (this.collections.has(collection.name)) {
233
- this.updateCollection(collection);
233
+ this.updateCollection(collection, options);
234
234
  } else {
235
235
  this.addCollection(collection);
236
236
  }
@@ -412,10 +412,13 @@ export class Collection {
412
412
  this.dataSource = dataSource;
413
413
  }
414
414
 
415
- setOptions(newOptions: any = {}) {
415
+ setOptions(newOptions: any = {}, options: { clearFields?: boolean } = {}) {
416
416
  Object.keys(this.options).forEach((key) => delete this.options[key]);
417
417
  Object.assign(this.options, newOptions);
418
418
  this.initInherits();
419
+ if (options.clearFields) {
420
+ this.clearFields();
421
+ }
419
422
  this.upsertFields(this.options.fields || []);
420
423
  }
421
424
 
@@ -490,7 +493,6 @@ export class Collection {
490
493
  }
491
494
 
492
495
  getField(fieldName: string): CollectionField | undefined {
493
- this.setFields(this.options.fields); //数据表字段被删除
494
496
  return this.fields.get(fieldName);
495
497
  }
496
498
 
@@ -113,6 +113,7 @@ export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDa
113
113
  async create(data: TDataItem, options?: AxiosRequestConfig): Promise<void> {
114
114
  const config = this.mergeRequestConfig({ data }, this.createActionOptions, options);
115
115
  await this.runAction('create', config);
116
+ this.emit('saved', data);
116
117
  await this.refresh();
117
118
  }
118
119
 
@@ -140,6 +141,7 @@ export class MultiRecordResource<TDataItem = any> extends BaseRecordResource<TDa
140
141
  options,
141
142
  );
142
143
  await this.runAction('update', config);
144
+ this.emit('saved', data);
143
145
  await this.refresh();
144
146
  }
145
147
 
@@ -43,6 +43,7 @@ export class SingleRecordResource<TData = any> extends BaseRecordResource<TData>
43
43
  ...config,
44
44
  data,
45
45
  });
46
+ this.emit('saved', data);
46
47
  if (options?.refresh !== false) {
47
48
  await this.refresh();
48
49
  }