@nocobase/client-v2 2.1.0-beta.23 → 2.1.0-beta.24
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.
- package/es/flow/components/Grid/index.d.ts +5 -3
- package/es/flow/models/base/GridModel.d.ts +19 -2
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
- package/es/index.mjs +88 -88
- package/lib/index.js +82 -82
- package/package.json +5 -5
- package/src/flow/components/Grid/index.tsx +66 -20
- package/src/flow/models/base/BlockGridModel.tsx +2 -2
- package/src/flow/models/base/GridModel.tsx +428 -195
- package/src/flow/models/base/__tests__/BlockGridModel.dragOverlayConfig.test.ts +44 -0
- package/src/flow/models/base/__tests__/GridModel.computeOverlayRect.test.ts +29 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +181 -2
- package/src/flow/models/base/__tests__/GridModel.resizeLayout.test.ts +124 -0
- package/src/flow/models/base/__tests__/GridModel.visibleLayout.test.ts +55 -15
- package/src/flow/models/blocks/details/DetailsGridModel.tsx +6 -6
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +54 -14
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +45 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +6 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/client-v2",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.24",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@formily/antd-v5": "1.2.3",
|
|
25
25
|
"@formily/react": "^2.2.27",
|
|
26
26
|
"@formily/shared": "^2.2.27",
|
|
27
|
-
"@nocobase/flow-engine": "2.1.0-beta.
|
|
28
|
-
"@nocobase/sdk": "2.1.0-beta.
|
|
29
|
-
"@nocobase/shared": "2.1.0-beta.
|
|
27
|
+
"@nocobase/flow-engine": "2.1.0-beta.24",
|
|
28
|
+
"@nocobase/sdk": "2.1.0-beta.24",
|
|
29
|
+
"@nocobase/shared": "2.1.0-beta.24",
|
|
30
30
|
"antd": "5.24.2",
|
|
31
31
|
"classnames": "^2.3.1",
|
|
32
32
|
"dayjs": "^1.11.10",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"react-i18next": "^11.15.1",
|
|
36
36
|
"react-router-dom": "^6.30.1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f77b85530a2d127d9bfe4dca3a26fbb02c1139ba"
|
|
39
39
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { EMPTY_COLUMN_UID } from '@nocobase/flow-engine';
|
|
10
|
+
import { EMPTY_COLUMN_UID, GridLayoutPath, GridLayoutV2, normalizeGridLayout } from '@nocobase/flow-engine';
|
|
11
11
|
import { Col, Row } from 'antd';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
|
|
@@ -16,37 +16,63 @@ interface DragOverlayRect {
|
|
|
16
16
|
readonly left: number;
|
|
17
17
|
readonly width: number;
|
|
18
18
|
readonly height: number;
|
|
19
|
-
readonly type: 'column' | 'column-edge' | 'row-gap' | 'empty-row' | 'empty-column';
|
|
19
|
+
readonly type: 'column' | 'column-edge' | 'row-gap' | 'empty-row' | 'empty-column' | 'item-edge';
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
interface GridProps {
|
|
23
|
-
readonly rows
|
|
23
|
+
readonly rows?: Record<string, string[][]>;
|
|
24
24
|
readonly sizes?: Record<string, number[]>;
|
|
25
|
+
readonly layout?: GridLayoutV2;
|
|
25
26
|
readonly renderItem: (uid: string) => React.ReactNode;
|
|
26
27
|
readonly rowGap?: number;
|
|
27
28
|
readonly colGap?: number;
|
|
28
29
|
readonly dragOverlayRect?: DragOverlayRect | null;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
export function Grid({
|
|
32
|
-
|
|
32
|
+
export function Grid({
|
|
33
|
+
rows = {},
|
|
34
|
+
sizes = {},
|
|
35
|
+
layout,
|
|
36
|
+
renderItem,
|
|
37
|
+
rowGap = 16,
|
|
38
|
+
colGap = 16,
|
|
39
|
+
dragOverlayRect,
|
|
40
|
+
}: GridProps) {
|
|
41
|
+
const normalizedLayout = layout || normalizeGridLayout({ rows, sizes });
|
|
42
|
+
if (!normalizedLayout.rows.length) {
|
|
33
43
|
return (
|
|
34
|
-
<div style={{ position: 'relative' }} data-grid-empty-container>
|
|
44
|
+
<div style={{ position: 'relative' }} data-grid-root data-grid-empty-container>
|
|
35
45
|
{dragOverlayRect && <GridDragOverlay rect={dragOverlayRect} />}
|
|
36
46
|
</div>
|
|
37
47
|
);
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
return (
|
|
41
|
-
<div style={{ position: 'relative', display: 'flex', flexDirection: 'column', gap: rowGap }}>
|
|
51
|
+
<div style={{ position: 'relative', display: 'flex', flexDirection: 'column', gap: rowGap }} data-grid-root>
|
|
42
52
|
{dragOverlayRect && <GridDragOverlay rect={dragOverlayRect} />}
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
<GridRows rows={normalizedLayout.rows} renderItem={renderItem} rowGap={rowGap} colGap={colGap} parentPath={[]} />
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface GridRowsProps {
|
|
59
|
+
readonly rows: GridLayoutV2['rows'];
|
|
60
|
+
readonly renderItem: (uid: string) => React.ReactNode;
|
|
61
|
+
readonly rowGap: number;
|
|
62
|
+
readonly colGap: number;
|
|
63
|
+
readonly parentPath: GridLayoutPath;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function GridRows({ rows, renderItem, rowGap, colGap, parentPath }: GridRowsProps) {
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
{rows.map((row) => {
|
|
70
|
+
const colCount = row.cells.length;
|
|
71
|
+
const rowSizes = row.sizes || [];
|
|
46
72
|
const hasAnySize = rowSizes.some((v) => v != null && v !== undefined);
|
|
73
|
+
const rowPath = [...parentPath, { rowId: row.id }];
|
|
47
74
|
|
|
48
|
-
|
|
49
|
-
const spans = cells.map((_, cellIdx) => {
|
|
75
|
+
const spans = row.cells.map((_, cellIdx) => {
|
|
50
76
|
if (hasAnySize) {
|
|
51
77
|
const assigned = rowSizes.reduce((sum, v) => sum + (v || 0), 0);
|
|
52
78
|
const unassignedCount = colCount - rowSizes.filter(Boolean).length;
|
|
@@ -58,22 +84,24 @@ export function Grid({ rows, sizes = {}, renderItem, rowGap = 16, colGap = 16, d
|
|
|
58
84
|
});
|
|
59
85
|
|
|
60
86
|
return (
|
|
61
|
-
<Row key={
|
|
62
|
-
{cells.map((cell, cellIdx) => (
|
|
87
|
+
<Row key={row.id} gutter={colGap} data-grid-row-id={row.id} data-grid-path={JSON.stringify(rowPath)}>
|
|
88
|
+
{row.cells.map((cell, cellIdx) => (
|
|
63
89
|
<GridColumn
|
|
64
|
-
key={
|
|
65
|
-
rowKey={
|
|
90
|
+
key={cell.id}
|
|
91
|
+
rowKey={row.id}
|
|
66
92
|
columnIndex={cellIdx}
|
|
67
93
|
span={spans[cellIdx]}
|
|
68
94
|
rowGap={rowGap}
|
|
95
|
+
colGap={colGap}
|
|
69
96
|
cell={cell}
|
|
97
|
+
path={[...rowPath.slice(0, -1), { rowId: row.id, cellId: cell.id }]}
|
|
70
98
|
renderItem={renderItem}
|
|
71
99
|
/>
|
|
72
100
|
))}
|
|
73
101
|
</Row>
|
|
74
102
|
);
|
|
75
103
|
})}
|
|
76
|
-
|
|
104
|
+
</>
|
|
77
105
|
);
|
|
78
106
|
}
|
|
79
107
|
|
|
@@ -82,7 +110,9 @@ interface GridColumnProps {
|
|
|
82
110
|
readonly columnIndex: number;
|
|
83
111
|
readonly span: number;
|
|
84
112
|
readonly rowGap: number;
|
|
85
|
-
readonly
|
|
113
|
+
readonly colGap: number;
|
|
114
|
+
readonly cell: GridLayoutV2['rows'][number]['cells'][number];
|
|
115
|
+
readonly path: GridLayoutPath;
|
|
86
116
|
readonly renderItem: (uid: string) => React.ReactNode;
|
|
87
117
|
}
|
|
88
118
|
|
|
@@ -91,13 +121,21 @@ const GridColumn = React.memo(function GridColumn({
|
|
|
91
121
|
columnIndex,
|
|
92
122
|
span,
|
|
93
123
|
rowGap,
|
|
124
|
+
colGap,
|
|
94
125
|
cell,
|
|
126
|
+
path,
|
|
95
127
|
renderItem,
|
|
96
128
|
}: GridColumnProps) {
|
|
129
|
+
const items = cell.items || [];
|
|
97
130
|
return (
|
|
98
|
-
<Col
|
|
131
|
+
<Col
|
|
132
|
+
span={span}
|
|
133
|
+
data-grid-column-row-id={rowKey}
|
|
134
|
+
data-grid-column-index={columnIndex}
|
|
135
|
+
data-grid-path={JSON.stringify(path)}
|
|
136
|
+
>
|
|
99
137
|
<div style={{ display: 'flex', flexDirection: 'column', gap: rowGap }}>
|
|
100
|
-
{
|
|
138
|
+
{items.map((uid, itemIdx) => {
|
|
101
139
|
if (uid === EMPTY_COLUMN_UID) {
|
|
102
140
|
return null;
|
|
103
141
|
}
|
|
@@ -108,11 +146,15 @@ const GridColumn = React.memo(function GridColumn({
|
|
|
108
146
|
data-grid-column-index={columnIndex}
|
|
109
147
|
data-grid-item-index={itemIdx}
|
|
110
148
|
data-grid-item-uid={uid}
|
|
149
|
+
data-grid-path={JSON.stringify(path)}
|
|
111
150
|
>
|
|
112
151
|
{renderItem(uid)}
|
|
113
152
|
</div>
|
|
114
153
|
);
|
|
115
154
|
})}
|
|
155
|
+
{cell.rows?.length ? (
|
|
156
|
+
<GridRows rows={cell.rows} renderItem={renderItem} rowGap={rowGap} colGap={colGap} parentPath={path} />
|
|
157
|
+
) : null}
|
|
116
158
|
</div>
|
|
117
159
|
</Col>
|
|
118
160
|
);
|
|
@@ -152,6 +194,10 @@ function GridDragOverlay({ rect }: Readonly<{ rect: DragOverlayRect }>) {
|
|
|
152
194
|
border: '2px dashed var(--colorPrimary)',
|
|
153
195
|
backgroundColor: 'rgba(22, 119, 255, 0.04)',
|
|
154
196
|
},
|
|
197
|
+
'item-edge': {
|
|
198
|
+
border: '2px solid var(--colorPrimary)',
|
|
199
|
+
backgroundColor: 'rgba(22, 119, 255, 0.12)',
|
|
200
|
+
},
|
|
155
201
|
};
|
|
156
202
|
|
|
157
203
|
return <div style={{ ...baseStyle, ...typeStyles[rect.type] }} />;
|
|
@@ -27,8 +27,8 @@ export class BlockGridModel extends GridModel {
|
|
|
27
27
|
dragOverlayConfig: DragOverlayConfig = {
|
|
28
28
|
// 列内插入
|
|
29
29
|
columnInsert: {
|
|
30
|
-
before: { offsetTop: -
|
|
31
|
-
after: { offsetTop:
|
|
30
|
+
before: { offsetTop: -12 },
|
|
31
|
+
after: { offsetTop: 12 },
|
|
32
32
|
},
|
|
33
33
|
// 列边缘
|
|
34
34
|
columnEdge: {
|