@nocobase/flow-engine 2.1.0-alpha.30 → 2.1.0-alpha.32

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.
@@ -42,6 +42,7 @@ __export(data_source_exports, {
42
42
  CollectionManager: () => CollectionManager,
43
43
  DataSource: () => DataSource,
44
44
  DataSourceManager: () => DataSourceManager,
45
+ getCollectionFieldInterface: () => getCollectionFieldInterface,
45
46
  isFieldInterfaceMatch: () => isFieldInterfaceMatch,
46
47
  jioToJoiSchema: () => import_jioToJoiSchema.jioToJoiSchema
47
48
  });
@@ -279,6 +280,20 @@ const _DataSourceManager = class _DataSourceManager {
279
280
  };
280
281
  __name(_DataSourceManager, "DataSourceManager");
281
282
  let DataSourceManager = _DataSourceManager;
283
+ function getCollectionFieldInterface(interfaceName, ...dataSourceManagers) {
284
+ if (!interfaceName) {
285
+ return void 0;
286
+ }
287
+ for (const dataSourceManager of dataSourceManagers) {
288
+ const collectionFieldInterfaceManager = dataSourceManager == null ? void 0 : dataSourceManager.collectionFieldInterfaceManager;
289
+ const getFieldInterface = collectionFieldInterfaceManager == null ? void 0 : collectionFieldInterfaceManager.getFieldInterface;
290
+ if (typeof getFieldInterface === "function") {
291
+ return getFieldInterface.call(collectionFieldInterfaceManager, interfaceName);
292
+ }
293
+ }
294
+ return void 0;
295
+ }
296
+ __name(getCollectionFieldInterface, "getCollectionFieldInterface");
282
297
  const _DataSource = class _DataSource {
283
298
  dataSourceManager;
284
299
  collectionManager;
@@ -982,7 +997,17 @@ const _CollectionField = class _CollectionField {
982
997
  abortEarly: false
983
998
  });
984
999
  if (error) {
985
- const message = error.details.map((d) => d.message.replace(/"value"/g, `"${label}"`)).join(", ");
1000
+ const message = error.details.map((d) => {
1001
+ const translated = this.flowEngine.translate(d.type, {
1002
+ ...d.context,
1003
+ ns: "data-source-main",
1004
+ label
1005
+ });
1006
+ if (translated && translated !== d.type) {
1007
+ return translated;
1008
+ }
1009
+ return d.message.replace(/"value"/g, `"${label}"`);
1010
+ }).join(", ");
986
1011
  return Promise.reject(message);
987
1012
  }
988
1013
  return Promise.resolve();
@@ -1002,8 +1027,14 @@ const _CollectionField = class _CollectionField {
1002
1027
  return this.targetCollection.getFields();
1003
1028
  }
1004
1029
  getInterfaceOptions() {
1005
- const app = this.flowEngine.context.app;
1006
- return app.dataSourceManager.collectionFieldInterfaceManager.getFieldInterface(this.interface);
1030
+ var _a, _b, _c;
1031
+ const ctx = this.flowEngine.context;
1032
+ return getCollectionFieldInterface(
1033
+ this.interface,
1034
+ (_b = (_a = this.collection) == null ? void 0 : _a.dataSource) == null ? void 0 : _b.dataSourceManager,
1035
+ ctx.dataSourceManager,
1036
+ (_c = ctx.app) == null ? void 0 : _c.dataSourceManager
1037
+ );
1007
1038
  }
1008
1039
  getFilterOperators() {
1009
1040
  var _a;
@@ -1068,6 +1099,7 @@ __name(isFieldInterfaceMatch, "isFieldInterfaceMatch");
1068
1099
  CollectionManager,
1069
1100
  DataSource,
1070
1101
  DataSourceManager,
1102
+ getCollectionFieldInterface,
1071
1103
  isFieldInterfaceMatch,
1072
1104
  jioToJoiSchema
1073
1105
  });
@@ -43,6 +43,10 @@ function encodeFilterByTk(val) {
43
43
  return encodeURIComponent(String(val));
44
44
  }
45
45
  __name(encodeFilterByTk, "encodeFilterByTk");
46
+ function hasUsableSourceId(sourceId) {
47
+ return sourceId !== void 0 && sourceId !== null && String(sourceId) !== "";
48
+ }
49
+ __name(hasUsableSourceId, "hasUsableSourceId");
46
50
  function generatePathnameFromViewParams(viewParams) {
47
51
  if (!viewParams || viewParams.length === 0) {
48
52
  return "/admin";
@@ -62,8 +66,8 @@ function generatePathnameFromViewParams(viewParams) {
62
66
  segments.push("filterbytk", encoded);
63
67
  }
64
68
  }
65
- if (viewParam.sourceId) {
66
- segments.push("sourceid", viewParam.sourceId);
69
+ if (hasUsableSourceId(viewParam.sourceId)) {
70
+ segments.push("sourceid", String(viewParam.sourceId));
67
71
  }
68
72
  });
69
73
  return "/" + segments.join("/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.1.0-alpha.30",
3
+ "version": "2.1.0-alpha.32",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.1.0-alpha.30",
12
- "@nocobase/shared": "2.1.0-alpha.30",
11
+ "@nocobase/sdk": "2.1.0-alpha.32",
12
+ "@nocobase/shared": "2.1.0-alpha.32",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "292ae0ad87f195ed201b274902d21ecd96f5ddd0"
40
+ "gitHead": "1ba7d717e156651db17c615f9b9c48edd669d19b"
41
41
  }
@@ -19,6 +19,9 @@ interface ExtendedFormItemProps extends FormItemProps {
19
19
  showLabel?: boolean;
20
20
  }
21
21
 
22
+ export const verticalFormItemLabelStyle = { paddingBottom: 0 };
23
+ export const formItemStyle = { marginBottom: 12 };
24
+
22
25
  const formItemPropKeys: (keyof ExtendedFormItemProps)[] = [
23
26
  'colon',
24
27
  'dependencies',
@@ -73,6 +76,8 @@ export const FormItem = ({
73
76
  });
74
77
  const { label, labelWrap, colon = true, layout } = rest;
75
78
  const effectiveLabelWrap = !layout || layout === 'vertical' ? true : labelWrap;
79
+ const labelColStyle =
80
+ layout === 'vertical' ? { width: labelWidth, ...verticalFormItemLabelStyle } : { width: labelWidth };
76
81
  const renderLabel = () => {
77
82
  if (!showLabel) return null;
78
83
  if (effectiveLabelWrap) {
@@ -118,7 +123,8 @@ export const FormItem = ({
118
123
  return (
119
124
  <Form.Item
120
125
  {...rest}
121
- labelCol={{ style: { width: labelWidth } }}
126
+ style={{ ...formItemStyle, ...rest.style }}
127
+ labelCol={{ style: labelColStyle }}
122
128
  layout={layout}
123
129
  label={renderLabel()}
124
130
  colon={false}
@@ -0,0 +1,25 @@
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 { describe, expect, it } from 'vitest';
11
+ import { formItemStyle, verticalFormItemLabelStyle } from '../FormItem';
12
+
13
+ describe('FormItem', () => {
14
+ it('keeps vertical label-to-value spacing consistent with v1', () => {
15
+ expect(verticalFormItemLabelStyle).toEqual({
16
+ paddingBottom: 0,
17
+ });
18
+ });
19
+
20
+ it('keeps spacing between form items consistent with v1', () => {
21
+ expect(formItemStyle).toEqual({
22
+ marginBottom: 12,
23
+ });
24
+ });
25
+ });
@@ -829,6 +829,52 @@ describe('simulateLayoutForSlot', () => {
829
829
  expect(nestedRows[1].sizes).toEqual([12, 12]);
830
830
  });
831
831
 
832
+ it('keeps nested column insertion target when removing a sibling collapses the original path', () => {
833
+ const layout = createLayout(
834
+ {
835
+ vyvfw2jw071: [['6ad3ccaabd5', 'ff8b4b57f65']],
836
+ ablhoqw51gb: [['21b422021b8']],
837
+ },
838
+ {
839
+ vyvfw2jw071: [24],
840
+ ablhoqw51gb: [24],
841
+ },
842
+ ['vyvfw2jw071', 'ablhoqw51gb'],
843
+ );
844
+ layout.layout = normalizeGridLayout({
845
+ rows: layout.rows,
846
+ sizes: layout.sizes,
847
+ rowOrder: layout.rowOrder,
848
+ itemUids: ['6ad3ccaabd5', 'ff8b4b57f65', '21b422021b8'],
849
+ });
850
+
851
+ const slot: LayoutSlot = {
852
+ type: 'column',
853
+ rowId: 'll5vo5pzj3u',
854
+ columnIndex: 0,
855
+ insertIndex: 1,
856
+ position: 'after',
857
+ path: [
858
+ { rowId: 'vyvfw2jw071', cellId: 'vyvfw2jw071:cell:0' },
859
+ { rowId: 'll5vo5pzj3u', cellId: 'ghy612j5zzg' },
860
+ ],
861
+ rect,
862
+ };
863
+
864
+ const result = simulateLayoutForSlot({ slot, sourceUid: 'ff8b4b57f65', layout });
865
+
866
+ expect(result.layout!.rows).toMatchObject([
867
+ {
868
+ id: 'vyvfw2jw071',
869
+ cells: [{ items: ['6ad3ccaabd5', 'ff8b4b57f65'] }],
870
+ },
871
+ {
872
+ id: 'ablhoqw51gb',
873
+ cells: [{ items: ['21b422021b8'] }],
874
+ },
875
+ ]);
876
+ });
877
+
832
878
  it('treats dragging an item to its own item-edge as no-op', () => {
833
879
  const layout = createLayout(
834
880
  {
@@ -1146,6 +1146,21 @@ const findCellByPath = (layout: GridLayoutV2, path?: GridLayoutPath) => {
1146
1146
  return null;
1147
1147
  };
1148
1148
 
1149
+ const findCellByPathOrClosestAncestor = (layout: GridLayoutV2, path?: GridLayoutPath) => {
1150
+ if (!path?.length) {
1151
+ return null;
1152
+ }
1153
+
1154
+ for (let length = path.length; length > 0; length -= 1) {
1155
+ const target = findCellByPath(layout, path.slice(0, length));
1156
+ if (target) {
1157
+ return target;
1158
+ }
1159
+ }
1160
+
1161
+ return null;
1162
+ };
1163
+
1149
1164
  const removeItemFromGridLayout = (layout: GridLayoutV2, sourceUid: string) => {
1150
1165
  const removeFromRows = (rows: GridRowV2[]): GridRowV2[] =>
1151
1166
  rows
@@ -1231,7 +1246,7 @@ const simulateGridLayoutForSlot = ({
1231
1246
 
1232
1247
  switch (slot.type) {
1233
1248
  case 'column': {
1234
- const target = findCellByPath(cloned, targetPath);
1249
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1235
1250
  if (!target) {
1236
1251
  break;
1237
1252
  }
@@ -1247,7 +1262,7 @@ const simulateGridLayoutForSlot = ({
1247
1262
  break;
1248
1263
  }
1249
1264
  case 'empty-column': {
1250
- const target = findCellByPath(cloned, targetPath);
1265
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1251
1266
  if (target) {
1252
1267
  delete target.cell.rows;
1253
1268
  target.cell.items = [sourceUid];
@@ -1255,7 +1270,7 @@ const simulateGridLayoutForSlot = ({
1255
1270
  break;
1256
1271
  }
1257
1272
  case 'column-edge': {
1258
- const target = findCellByPath(cloned, targetPath);
1273
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1259
1274
  if (!target) {
1260
1275
  break;
1261
1276
  }
@@ -1282,7 +1297,7 @@ const simulateGridLayoutForSlot = ({
1282
1297
  if (!targetItemUid) {
1283
1298
  break;
1284
1299
  }
1285
- const target = findCellByPath(cloned, targetPath);
1300
+ const target = findCellByPathOrClosestAncestor(cloned, targetPath);
1286
1301
  if (!target?.cell.items) {
1287
1302
  break;
1288
1303
  }