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

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
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import React from 'react';
10
+ export declare const FieldSkeleton: React.FC;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var FieldSkeleton_exports = {};
39
+ __export(FieldSkeleton_exports, {
40
+ FieldSkeleton: () => FieldSkeleton
41
+ });
42
+ module.exports = __toCommonJS(FieldSkeleton_exports);
43
+ var import_react = __toESM(require("react"));
44
+ var import_provider = require("../provider");
45
+ const FieldSkeleton = /* @__PURE__ */ __name(() => {
46
+ const flowEngine = (0, import_provider.useFlowEngine)();
47
+ const token = flowEngine.context.themeToken;
48
+ return /* @__PURE__ */ import_react.default.createElement(
49
+ "span",
50
+ {
51
+ style: {
52
+ display: "inline-block",
53
+ width: "100%",
54
+ height: 16,
55
+ backgroundColor: token.colorFillSecondary,
56
+ borderRadius: token.borderRadiusSM
57
+ }
58
+ }
59
+ );
60
+ }, "FieldSkeleton");
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ FieldSkeleton
64
+ });
@@ -42,7 +42,6 @@ __export(FlowModelRenderer_exports, {
42
42
  });
43
43
  module.exports = __toCommonJS(FlowModelRenderer_exports);
44
44
  var import_reactive_react = require("@formily/reactive-react");
45
- var import_antd = require("antd");
46
45
  var import_lodash = __toESM(require("lodash"));
47
46
  var import_react = __toESM(require("react"));
48
47
  var import_react_error_boundary = require("react-error-boundary");
@@ -180,7 +179,7 @@ const FlowModelRendererCore = (0, import_reactive_react.observer)(
180
179
  const FlowModelRenderer = (0, import_reactive_react.observer)(
181
180
  ({
182
181
  model,
183
- fallback = /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton.Button, { size: "small" }),
182
+ fallback = null,
184
183
  showFlowSettings = false,
185
184
  flowSettingsVariant = "dropdown",
186
185
  hideRemoveInSettings = false,
@@ -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) {
@@ -42,6 +42,7 @@ export declare class FlowModel<Structure extends DefaultStructure = DefaultStruc
42
42
  private _options;
43
43
  protected _title: string;
44
44
  isNew: boolean;
45
+ skeleton: any;
45
46
  /**
46
47
  * 所有 fork 实例的引用集合。
47
48
  * 使用 Set 便于在销毁时主动遍历并调用 dispose,避免悬挂引用。
@@ -93,6 +93,7 @@ const _FlowModel = class _FlowModel {
93
93
  __publicField(this, "_title");
94
94
  __publicField(this, "isNew", false);
95
95
  // 标记是否为新建状态
96
+ __publicField(this, "skeleton", null);
96
97
  /**
97
98
  * 所有 fork 实例的引用集合。
98
99
  * 使用 Set 便于在销毁时主动遍历并调用 dispose,避免悬挂引用。
@@ -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.15",
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": "62569ef83962291d3cf09f0758bf7ffec3625dfa"
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} />;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import React from 'react';
11
+ import { useFlowEngine } from '../provider';
12
+
13
+ export const FieldSkeleton: React.FC = () => {
14
+ const flowEngine = useFlowEngine();
15
+ const token = flowEngine.context.themeToken;
16
+ return (
17
+ <span
18
+ style={{
19
+ display: 'inline-block',
20
+ width: '100%',
21
+ height: 16,
22
+ backgroundColor: token.colorFillSecondary,
23
+ borderRadius: token.borderRadiusSM,
24
+ }}
25
+ />
26
+ );
27
+ };
@@ -43,7 +43,6 @@
43
43
  */
44
44
 
45
45
  import { observer } from '@formily/reactive-react';
46
- import { Skeleton, Spin } from 'antd';
47
46
  import _ from 'lodash';
48
47
  import React from 'react';
49
48
  import { ErrorBoundary } from 'react-error-boundary';
@@ -329,7 +328,7 @@ const FlowModelRendererCore: React.FC<{
329
328
  export const FlowModelRenderer: React.FC<FlowModelRendererProps> = observer(
330
329
  ({
331
330
  model,
332
- fallback = <Skeleton.Button size="small" />,
331
+ fallback = null,
333
332
  showFlowSettings = false,
334
333
  flowSettingsVariant = 'dropdown',
335
334
  hideRemoveInSettings = false,
@@ -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
 
@@ -89,6 +89,7 @@ export class FlowModel<Structure extends DefaultStructure = DefaultStructure> {
89
89
  private _options: FlowModelOptions<Structure>;
90
90
  protected _title: string;
91
91
  public isNew = false; // 标记是否为新建状态
92
+ public skeleton = null;
92
93
 
93
94
  /**
94
95
  * 所有 fork 实例的引用集合。
@@ -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
  }