@nocobase/client-v2 2.2.0-beta.7 → 2.2.0-beta.8
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/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +1 -0
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
- package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
- package/es/flow/models/blocks/table/TableActionsColumnModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +1 -1
- package/es/flow/models/blocks/table/dragSort/dragSortSettings.d.ts +2 -1
- package/es/flow/models/blocks/table/dragSort/dragSortUtils.d.ts +6 -4
- package/es/flow/resolveViewParamsToViewList.d.ts +1 -1
- package/es/index.mjs +103 -87
- package/lib/index.js +105 -89
- package/package.json +7 -7
- package/src/collection-manager/field-configure.ts +1 -1
- package/src/collection-manager/interfaces/id.ts +1 -1
- package/src/collection-manager/interfaces/m2m.tsx +2 -2
- package/src/collection-manager/interfaces/m2o.tsx +2 -2
- package/src/collection-manager/interfaces/nanoid.ts +1 -1
- package/src/collection-manager/interfaces/o2m.tsx +2 -2
- package/src/collection-manager/interfaces/obo.tsx +2 -2
- package/src/collection-manager/interfaces/oho.tsx +2 -2
- package/src/collection-manager/interfaces/properties/index.ts +2 -2
- package/src/collection-manager/interfaces/uuid.ts +1 -1
- package/src/flow/__tests__/getKey.test.ts +7 -0
- package/src/flow/__tests__/resolveViewParamsToViewList.test.ts +34 -0
- package/src/flow/actions/__tests__/afterSuccess.test.ts +73 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +104 -0
- package/src/flow/actions/afterSuccess.tsx +142 -3
- package/src/flow/actions/index.ts +1 -1
- package/src/flow/actions/openView.tsx +38 -4
- package/src/flow/admin-shell/BaseLayoutModel.tsx +25 -3
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +5 -2
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +1 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +5 -4
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +82 -0
- package/src/flow/getViewDiffAndUpdateHidden.tsx +1 -0
- package/src/flow/models/base/ActionModelCore.tsx +6 -4
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
- package/src/flow/models/blocks/filter-form/fields/FilterFormCustomFieldModel.tsx +1 -1
- package/src/flow/models/blocks/form/FormActionModel.tsx +1 -1
- package/src/flow/models/blocks/form/__tests__/submitHandler.test.ts +54 -1
- package/src/flow/models/blocks/form/submitHandler.ts +17 -3
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
- package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +35 -12
- package/src/flow/models/blocks/table/TableBlockModel.tsx +25 -14
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +57 -1
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.dragSort.test.ts +127 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.rowSelection.test.tsx +1 -0
- package/src/flow/models/blocks/table/dragSort/dragSortHooks.tsx +28 -17
- package/src/flow/models/blocks/table/dragSort/dragSortSettings.ts +13 -6
- package/src/flow/models/blocks/table/dragSort/dragSortUtils.ts +15 -2
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/settings-center/SystemSettingsPage.tsx +1 -1
|
@@ -38,6 +38,11 @@ type FormBlockModel = FlowModel & {
|
|
|
38
38
|
getAclActionName?: () => string;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
export type FormValuePatch = {
|
|
42
|
+
path: NamePath;
|
|
43
|
+
value: unknown;
|
|
44
|
+
};
|
|
45
|
+
|
|
41
46
|
export class FormValueRuntime {
|
|
42
47
|
private readonly model: FormBlockModel;
|
|
43
48
|
private readonly getForm: () => FormInstance;
|
|
@@ -142,6 +147,49 @@ export class FormValueRuntime {
|
|
|
142
147
|
return this.getForm().getFieldsValue(true);
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
getUserEditedValuePatches(): FormValuePatch[] {
|
|
151
|
+
const snapshot = this.getFormValuesSnapshot();
|
|
152
|
+
if (!snapshot || typeof snapshot !== 'object') {
|
|
153
|
+
return [];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const patches: FormValuePatch[] = [];
|
|
157
|
+
const pathKeys = Array.from(this.userEditedSet).sort(
|
|
158
|
+
(a, b) => pathKeyToNamePath(a).length - pathKeyToNamePath(b).length,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
for (const pathKey of pathKeys) {
|
|
162
|
+
if (!this.isCurrentUserEditedPath(pathKey)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
167
|
+
if (!namePath.length || !_.has(snapshot, namePath as any)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const value = _.get(snapshot, namePath as any);
|
|
172
|
+
if (typeof value === 'undefined') {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
patches.push({
|
|
177
|
+
path: namePath,
|
|
178
|
+
value: this.omitNonUserDescendantValues(pathKey, this.toMirrorSnapshot(value)),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return patches;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getUserEditedValuesSnapshot(): Record<string, unknown> {
|
|
186
|
+
const values: Record<string, unknown> = {};
|
|
187
|
+
for (const patch of this.getUserEditedValuePatches()) {
|
|
188
|
+
_.set(values, patch.path as any, patch.value);
|
|
189
|
+
}
|
|
190
|
+
return values;
|
|
191
|
+
}
|
|
192
|
+
|
|
145
193
|
private toMirrorSnapshot(value: any) {
|
|
146
194
|
const raw = isObservable(value) ? toJS(value) : value;
|
|
147
195
|
return _.cloneDeepWith(raw, (item) => {
|
|
@@ -1453,6 +1501,49 @@ export class FormValueRuntime {
|
|
|
1453
1501
|
return null;
|
|
1454
1502
|
}
|
|
1455
1503
|
|
|
1504
|
+
private findLatestWriteMeta(pathKey: string): FormValueWriteMeta | undefined {
|
|
1505
|
+
let latest: FormValueWriteMeta | undefined;
|
|
1506
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
1507
|
+
const prefix: NamePath = [];
|
|
1508
|
+
|
|
1509
|
+
for (let i = 0; i < namePath.length; i++) {
|
|
1510
|
+
prefix.push(namePath[i]);
|
|
1511
|
+
const meta = this.lastWriteMetaByPathKey.get(namePathToPathKey(prefix as any));
|
|
1512
|
+
if (!meta) {
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
if (!latest || meta.writeSeq >= latest.writeSeq) {
|
|
1516
|
+
latest = meta;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
return latest;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
private isCurrentUserEditedPath(pathKey: string) {
|
|
1524
|
+
const lastWrite = this.findLatestWriteMeta(pathKey);
|
|
1525
|
+
return !lastWrite || lastWrite.source === 'user';
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
private omitNonUserDescendantValues(pathKey: string, value: unknown) {
|
|
1529
|
+
if (!value || typeof value !== 'object') {
|
|
1530
|
+
return value;
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
const namePath = pathKeyToNamePath(pathKey);
|
|
1534
|
+
for (const childKey of this.lastWriteMetaByPathKey.keys()) {
|
|
1535
|
+
if (!this.isDescendantPathKey(childKey, pathKey)) {
|
|
1536
|
+
continue;
|
|
1537
|
+
}
|
|
1538
|
+
if (this.isCurrentUserEditedPath(childKey)) {
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
_.unset(value as Record<string, unknown>, pathKeyToNamePath(childKey).slice(namePath.length) as any);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
return value;
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1456
1547
|
private isDescendantPathKey(candidateKey: string, parentKey: string) {
|
|
1457
1548
|
if (!candidateKey || !parentKey || candidateKey === parentKey) return false;
|
|
1458
1549
|
const candidatePath = pathKeyToNamePath(candidateKey);
|
|
@@ -16,24 +16,238 @@ import { CodeEditor } from '../../../components/code-editor';
|
|
|
16
16
|
|
|
17
17
|
const NAMESPACE = 'client';
|
|
18
18
|
|
|
19
|
+
const getRootElement = (element: HTMLElement | null) => {
|
|
20
|
+
if (!element) return document.documentElement;
|
|
21
|
+
return (
|
|
22
|
+
(element.closest('.nb-block-grid') as HTMLElement | null) ||
|
|
23
|
+
(element.closest('.nb-page-wrapper') as HTMLElement | null) ||
|
|
24
|
+
(element.closest('.nb-page') as HTMLElement | null) ||
|
|
25
|
+
document.documentElement
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const getOuterHeight = (element?: HTMLElement | null) => {
|
|
30
|
+
if (!element) return 0;
|
|
31
|
+
const rect = element.getBoundingClientRect();
|
|
32
|
+
const style = window.getComputedStyle(element);
|
|
33
|
+
const marginTop = parseFloat(style.marginTop) || 0;
|
|
34
|
+
const marginBottom = parseFloat(style.marginBottom) || 0;
|
|
35
|
+
return rect.height + marginTop + marginBottom;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const getPadding = (element: HTMLElement | null) => {
|
|
39
|
+
if (!element || element === document.documentElement) {
|
|
40
|
+
return { top: 0, bottom: 0 };
|
|
41
|
+
}
|
|
42
|
+
const style = window.getComputedStyle(element);
|
|
43
|
+
return {
|
|
44
|
+
top: parseFloat(style.paddingTop) || 0,
|
|
45
|
+
bottom: parseFloat(style.paddingBottom) || 0,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getPageHeader = (root: HTMLElement) => {
|
|
50
|
+
const page = root.closest('.nb-page') as HTMLElement | null;
|
|
51
|
+
if (!page) return null;
|
|
52
|
+
return (
|
|
53
|
+
(page.querySelector('.ant-page-header') as HTMLElement | null) ||
|
|
54
|
+
(page.querySelector('.pageHeaderCss') as HTMLElement | null)
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getAddBlockContainer = (root: HTMLElement) => {
|
|
59
|
+
const button = root.querySelector('[data-flow-add-block]') as HTMLElement | null;
|
|
60
|
+
if (!button) return null;
|
|
61
|
+
return (button.parentElement as HTMLElement | null) || button;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function getValidPageTop(a: number, b: number) {
|
|
65
|
+
const aValid = a > 0;
|
|
66
|
+
const bValid = b > 0;
|
|
67
|
+
|
|
68
|
+
if (aValid) return a;
|
|
69
|
+
if (bValid) return b;
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const usePlainHostHeight = ({
|
|
74
|
+
height,
|
|
75
|
+
heightMode,
|
|
76
|
+
hostRef,
|
|
77
|
+
marginBlock,
|
|
78
|
+
}: {
|
|
79
|
+
height?: number;
|
|
80
|
+
heightMode?: string;
|
|
81
|
+
hostRef: React.RefObject<HTMLDivElement>;
|
|
82
|
+
marginBlock: number;
|
|
83
|
+
}) => {
|
|
84
|
+
const [fullHeight, setFullHeight] = React.useState<number>();
|
|
85
|
+
const updateFullHeight = React.useCallback(() => {
|
|
86
|
+
if (heightMode !== 'fullHeight' || typeof window === 'undefined') {
|
|
87
|
+
setFullHeight((prev) => (prev === undefined ? prev : undefined));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const hostEl = hostRef.current;
|
|
91
|
+
if (!hostEl) return;
|
|
92
|
+
const root = getRootElement(hostEl);
|
|
93
|
+
const hostRect = hostEl.getBoundingClientRect();
|
|
94
|
+
const rootRect = root === document.documentElement ? { top: 0 } : root.getBoundingClientRect();
|
|
95
|
+
const padding = getPadding(root);
|
|
96
|
+
const addBlockContainer = getAddBlockContainer(root);
|
|
97
|
+
const pageTop = rootRect.top + padding.top;
|
|
98
|
+
const topOffset = Math.max(0, hostRect.top - pageTop);
|
|
99
|
+
let bottomOffset = padding.bottom + marginBlock;
|
|
100
|
+
if (addBlockContainer) {
|
|
101
|
+
const gapBetween = marginBlock;
|
|
102
|
+
bottomOffset = gapBetween + getOuterHeight(addBlockContainer) + padding.bottom;
|
|
103
|
+
}
|
|
104
|
+
const nextHeight = Math.max(
|
|
105
|
+
0,
|
|
106
|
+
Math.floor(window.innerHeight - getValidPageTop(pageTop, 110) - topOffset - bottomOffset - 1),
|
|
107
|
+
);
|
|
108
|
+
setFullHeight((prev) => (prev === nextHeight ? prev : nextHeight));
|
|
109
|
+
}, [heightMode, hostRef, marginBlock]);
|
|
110
|
+
|
|
111
|
+
React.useLayoutEffect(() => {
|
|
112
|
+
updateFullHeight();
|
|
113
|
+
}, [updateFullHeight]);
|
|
114
|
+
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (heightMode !== 'fullHeight' || typeof window === 'undefined') return;
|
|
117
|
+
const hostEl = hostRef.current;
|
|
118
|
+
if (!hostEl || typeof ResizeObserver === 'undefined') return;
|
|
119
|
+
const root = getRootElement(hostEl);
|
|
120
|
+
const pageHeader = getPageHeader(root);
|
|
121
|
+
const addBlockContainer = getAddBlockContainer(root);
|
|
122
|
+
const observer = new ResizeObserver(() => updateFullHeight());
|
|
123
|
+
observer.observe(hostEl);
|
|
124
|
+
if (root instanceof HTMLElement) {
|
|
125
|
+
observer.observe(root);
|
|
126
|
+
}
|
|
127
|
+
if (pageHeader) observer.observe(pageHeader);
|
|
128
|
+
if (addBlockContainer) observer.observe(addBlockContainer);
|
|
129
|
+
window.addEventListener('resize', updateFullHeight);
|
|
130
|
+
return () => {
|
|
131
|
+
observer.disconnect();
|
|
132
|
+
window.removeEventListener('resize', updateFullHeight);
|
|
133
|
+
};
|
|
134
|
+
}, [heightMode, hostRef, updateFullHeight]);
|
|
135
|
+
|
|
136
|
+
if (heightMode === 'specifyValue') {
|
|
137
|
+
return height;
|
|
138
|
+
}
|
|
139
|
+
if (heightMode === 'fullHeight') {
|
|
140
|
+
return fullHeight;
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const JSBlockPlainHost = ({
|
|
146
|
+
uid,
|
|
147
|
+
className,
|
|
148
|
+
heightMode,
|
|
149
|
+
height,
|
|
150
|
+
style,
|
|
151
|
+
beforeContent,
|
|
152
|
+
afterContent,
|
|
153
|
+
contentRef,
|
|
154
|
+
marginBlock,
|
|
155
|
+
...rest
|
|
156
|
+
}: React.HTMLAttributes<HTMLDivElement> & {
|
|
157
|
+
uid: string;
|
|
158
|
+
heightMode?: string;
|
|
159
|
+
height?: number;
|
|
160
|
+
beforeContent?: React.ReactNode;
|
|
161
|
+
afterContent?: React.ReactNode;
|
|
162
|
+
contentRef: React.RefObject<HTMLDivElement>;
|
|
163
|
+
marginBlock: number;
|
|
164
|
+
}) => {
|
|
165
|
+
const hostRef = React.useRef<HTMLDivElement | null>(null);
|
|
166
|
+
const resolvedHeight = usePlainHostHeight({ height, heightMode, hostRef, marginBlock });
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div
|
|
170
|
+
{...rest}
|
|
171
|
+
ref={hostRef}
|
|
172
|
+
id={`model-${uid}`}
|
|
173
|
+
className={className}
|
|
174
|
+
style={{
|
|
175
|
+
display: 'flex',
|
|
176
|
+
flexDirection: 'column',
|
|
177
|
+
height: resolvedHeight ?? undefined,
|
|
178
|
+
minHeight: 0,
|
|
179
|
+
overflow: 'auto',
|
|
180
|
+
...(style || {}),
|
|
181
|
+
}}
|
|
182
|
+
>
|
|
183
|
+
{beforeContent}
|
|
184
|
+
<div ref={contentRef} />
|
|
185
|
+
{afterContent}
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
19
190
|
export class JSBlockModel extends BlockModel {
|
|
20
191
|
// Avoid double-run on first mount; only rerun after remounts
|
|
21
192
|
private _mountedOnce = false;
|
|
193
|
+
|
|
194
|
+
get showBlockCard() {
|
|
195
|
+
return this.getStepParams('jsSettings', 'showBlockCard')?.showBlockCard !== false;
|
|
196
|
+
}
|
|
197
|
+
|
|
22
198
|
renderComponent(): React.ReactNode {
|
|
23
199
|
return <div ref={this.context.ref} />;
|
|
24
200
|
}
|
|
25
201
|
render() {
|
|
26
202
|
const decoratorProps = this.decoratorProps || {};
|
|
27
|
-
const {
|
|
203
|
+
const {
|
|
204
|
+
className,
|
|
205
|
+
id: _ignoredId,
|
|
206
|
+
title,
|
|
207
|
+
description,
|
|
208
|
+
showCard: _ignoredShowCard,
|
|
209
|
+
heightMode,
|
|
210
|
+
height,
|
|
211
|
+
style,
|
|
212
|
+
beforeContent,
|
|
213
|
+
afterContent,
|
|
214
|
+
...rest
|
|
215
|
+
} = decoratorProps;
|
|
28
216
|
const mergedClassName = ['code-block', className].filter(Boolean).join(' ');
|
|
29
217
|
|
|
218
|
+
if (!this.showBlockCard) {
|
|
219
|
+
return (
|
|
220
|
+
<JSBlockPlainHost
|
|
221
|
+
{...rest}
|
|
222
|
+
uid={this.uid}
|
|
223
|
+
className={mergedClassName}
|
|
224
|
+
heightMode={heightMode}
|
|
225
|
+
height={height}
|
|
226
|
+
style={style}
|
|
227
|
+
beforeContent={beforeContent}
|
|
228
|
+
afterContent={afterContent}
|
|
229
|
+
contentRef={this.context.ref}
|
|
230
|
+
marginBlock={this.context.themeToken?.marginBlock ?? 0}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const cardProps = {
|
|
236
|
+
...rest,
|
|
237
|
+
height,
|
|
238
|
+
style,
|
|
239
|
+
...(beforeContent === undefined ? {} : { beforeContent }),
|
|
240
|
+
...(afterContent === undefined ? {} : { afterContent }),
|
|
241
|
+
};
|
|
242
|
+
|
|
30
243
|
return (
|
|
31
244
|
<BlockItemCard
|
|
32
245
|
id={`model-${this.uid}`}
|
|
33
246
|
className={mergedClassName}
|
|
34
247
|
title={title}
|
|
35
248
|
description={description}
|
|
36
|
-
{
|
|
249
|
+
heightMode={heightMode}
|
|
250
|
+
{...cardProps}
|
|
37
251
|
>
|
|
38
252
|
<div ref={this.context.ref} />
|
|
39
253
|
</BlockItemCard>
|
|
@@ -61,6 +275,13 @@ JSBlockModel.registerFlow({
|
|
|
61
275
|
key: 'jsSettings',
|
|
62
276
|
title: 'JavaScript settings',
|
|
63
277
|
steps: {
|
|
278
|
+
showBlockCard: {
|
|
279
|
+
title: tExpr('Show block card'),
|
|
280
|
+
uiMode: { type: 'switch', key: 'showBlockCard' },
|
|
281
|
+
defaultParams: {
|
|
282
|
+
showBlockCard: true,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
64
285
|
runJs: {
|
|
65
286
|
title: tExpr('Write JavaScript'),
|
|
66
287
|
useRawParams: true,
|
|
@@ -0,0 +1,150 @@
|
|
|
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 { App, ConfigProvider } from 'antd';
|
|
12
|
+
import { render } from '@nocobase/test/client';
|
|
13
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
14
|
+
import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
15
|
+
import { JSBlockModel } from '../JSBlock';
|
|
16
|
+
|
|
17
|
+
function createJSBlock(uid: string, showBlockCard?: boolean, decoratorProps?: Record<string, unknown>) {
|
|
18
|
+
const engine = new FlowEngine();
|
|
19
|
+
engine.registerModels({ JSBlockModel });
|
|
20
|
+
const model = engine.createModel<JSBlockModel>({
|
|
21
|
+
use: 'JSBlockModel',
|
|
22
|
+
uid,
|
|
23
|
+
stepParams:
|
|
24
|
+
typeof showBlockCard === 'boolean'
|
|
25
|
+
? {
|
|
26
|
+
jsSettings: {
|
|
27
|
+
showBlockCard: {
|
|
28
|
+
showBlockCard,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: undefined,
|
|
33
|
+
});
|
|
34
|
+
model.setDecoratorProps({
|
|
35
|
+
className: 'custom-js-block-shell',
|
|
36
|
+
style: {
|
|
37
|
+
minHeight: 120,
|
|
38
|
+
},
|
|
39
|
+
...(decoratorProps || {}),
|
|
40
|
+
});
|
|
41
|
+
return { engine, model };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function renderBlock(engine: FlowEngine, model: JSBlockModel) {
|
|
45
|
+
return render(
|
|
46
|
+
<FlowEngineProvider engine={engine}>
|
|
47
|
+
<ConfigProvider>
|
|
48
|
+
<App>{model.render()}</App>
|
|
49
|
+
</ConfigProvider>
|
|
50
|
+
</FlowEngineProvider>,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
describe('JSBlockModel', () => {
|
|
55
|
+
it('renders with the outer block card by default', () => {
|
|
56
|
+
const { engine, model } = createJSBlock('js-block-with-card');
|
|
57
|
+
const { container } = renderBlock(engine, model);
|
|
58
|
+
const host = container.querySelector('#model-js-block-with-card');
|
|
59
|
+
|
|
60
|
+
expect(host).toBeTruthy();
|
|
61
|
+
expect(host?.classList.contains('ant-card')).toBe(true);
|
|
62
|
+
expect(host?.classList.contains('code-block')).toBe(true);
|
|
63
|
+
expect(host?.classList.contains('custom-js-block-shell')).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('renders a plain host without the outer card when showBlockCard is false', () => {
|
|
67
|
+
const { engine, model } = createJSBlock('js-block-without-card', false, {
|
|
68
|
+
showCard: true,
|
|
69
|
+
});
|
|
70
|
+
const { container } = renderBlock(engine, model);
|
|
71
|
+
const host = container.querySelector('#model-js-block-without-card') as HTMLElement | null;
|
|
72
|
+
|
|
73
|
+
expect(container.querySelector('.ant-card')).toBeNull();
|
|
74
|
+
expect(host).toBeInstanceOf(HTMLDivElement);
|
|
75
|
+
expect(host?.classList.contains('code-block')).toBe(true);
|
|
76
|
+
expect(host?.classList.contains('custom-js-block-shell')).toBe(true);
|
|
77
|
+
expect(host?.style.minHeight).toBe('120px');
|
|
78
|
+
expect(model.context.ref.current).toBe(host?.firstElementChild);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps cardless specified-height content scrollable inside the plain host', () => {
|
|
82
|
+
const { engine, model } = createJSBlock('js-block-without-card-height', false, {
|
|
83
|
+
heightMode: 'specifyValue',
|
|
84
|
+
height: 80,
|
|
85
|
+
style: undefined,
|
|
86
|
+
});
|
|
87
|
+
const { container } = renderBlock(engine, model);
|
|
88
|
+
const host = container.querySelector('#model-js-block-without-card-height') as HTMLElement | null;
|
|
89
|
+
const overflowContent = document.createElement('div');
|
|
90
|
+
overflowContent.style.height = '200px';
|
|
91
|
+
model.context.ref.current?.appendChild(overflowContent);
|
|
92
|
+
|
|
93
|
+
expect(host?.style.height).toBe('80px');
|
|
94
|
+
expect(host?.style.minHeight).toBe('0');
|
|
95
|
+
expect(host?.style.overflow).toBe('auto');
|
|
96
|
+
expect(model.context.ref.current?.firstElementChild).toBe(overflowContent);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('calculates cardless full-height on the plain host', () => {
|
|
100
|
+
const originalInnerHeight = window.innerHeight;
|
|
101
|
+
Object.defineProperty(window, 'innerHeight', {
|
|
102
|
+
configurable: true,
|
|
103
|
+
value: 500,
|
|
104
|
+
});
|
|
105
|
+
const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
|
|
106
|
+
if ((this as HTMLElement).id === 'model-js-block-without-card-full-height') {
|
|
107
|
+
return {
|
|
108
|
+
x: 0,
|
|
109
|
+
y: 150,
|
|
110
|
+
top: 150,
|
|
111
|
+
left: 0,
|
|
112
|
+
bottom: 150,
|
|
113
|
+
right: 0,
|
|
114
|
+
width: 0,
|
|
115
|
+
height: 0,
|
|
116
|
+
toJSON: () => ({}),
|
|
117
|
+
} as DOMRect;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
x: 0,
|
|
121
|
+
y: 0,
|
|
122
|
+
top: 0,
|
|
123
|
+
left: 0,
|
|
124
|
+
bottom: 0,
|
|
125
|
+
right: 0,
|
|
126
|
+
width: 0,
|
|
127
|
+
height: 0,
|
|
128
|
+
toJSON: () => ({}),
|
|
129
|
+
} as DOMRect;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const { engine, model } = createJSBlock('js-block-without-card-full-height', false, {
|
|
134
|
+
heightMode: 'fullHeight',
|
|
135
|
+
style: undefined,
|
|
136
|
+
});
|
|
137
|
+
const { container } = renderBlock(engine, model);
|
|
138
|
+
const host = container.querySelector('#model-js-block-without-card-full-height') as HTMLElement | null;
|
|
139
|
+
|
|
140
|
+
expect(parseInt(host?.style.height || '0', 10)).toBeGreaterThan(0);
|
|
141
|
+
expect(host?.style.overflow).toBe('auto');
|
|
142
|
+
} finally {
|
|
143
|
+
rectSpy.mockRestore();
|
|
144
|
+
Object.defineProperty(window, 'innerHeight', {
|
|
145
|
+
configurable: true,
|
|
146
|
+
value: originalInnerHeight,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
observer,
|
|
23
23
|
} from '@nocobase/flow-engine';
|
|
24
24
|
import { Skeleton, Tooltip } from 'antd';
|
|
25
|
+
import classNames from 'classnames';
|
|
25
26
|
import React from 'react';
|
|
26
27
|
import { ActionModel } from '../../base/ActionModel';
|
|
27
28
|
import { TableCustomColumnModel } from './TableCustomColumnModel';
|
|
@@ -33,6 +34,33 @@ const rowActionButtonTypeOptions = [
|
|
|
33
34
|
{ value: 'link', label: '{{t("Link")}}' },
|
|
34
35
|
{ value: 'text', label: '{{t("Text")}}' },
|
|
35
36
|
];
|
|
37
|
+
export const tableRowActionsClassName = css`
|
|
38
|
+
display: flex;
|
|
39
|
+
flex-wrap: wrap;
|
|
40
|
+
align-items: center;
|
|
41
|
+
line-height: inherit;
|
|
42
|
+
> div:empty {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.nb-table-row-action-button.ant-btn-link,
|
|
47
|
+
.nb-table-row-action-button.ant-btn-text {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
font: inherit;
|
|
51
|
+
height: auto;
|
|
52
|
+
line-height: inherit;
|
|
53
|
+
padding: 0;
|
|
54
|
+
border: 0;
|
|
55
|
+
box-shadow: none;
|
|
56
|
+
vertical-align: baseline;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.nb-table-row-action-button.ant-btn-link > span,
|
|
60
|
+
.nb-table-row-action-button.ant-btn-text > span {
|
|
61
|
+
line-height: inherit;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
36
64
|
|
|
37
65
|
const Columns = observer<any>(({ record, model, index }) => {
|
|
38
66
|
const isConfigMode = !!model.context.flowSettingsEnabled;
|
|
@@ -42,17 +70,7 @@ const Columns = observer<any>(({ record, model, index }) => {
|
|
|
42
70
|
<DndProvider>
|
|
43
71
|
<div
|
|
44
72
|
style={{ gap: model.context?.themeToken?.marginSM ?? 16 }}
|
|
45
|
-
className={
|
|
46
|
-
display: flex;
|
|
47
|
-
flex-wrap: wrap;
|
|
48
|
-
align-items: center;
|
|
49
|
-
> div:empty {
|
|
50
|
-
display: none;
|
|
51
|
-
}
|
|
52
|
-
button {
|
|
53
|
-
padding: 0;
|
|
54
|
-
}
|
|
55
|
-
`}
|
|
73
|
+
className={`nb-table-row-actions ${tableRowActionsClassName}`}
|
|
56
74
|
>
|
|
57
75
|
{model.mapSubModels('actions', (action: ActionModel) => {
|
|
58
76
|
// Static hidden can be skipped safely; dynamic hidden is handled by fork.beforeRender + model.render wrapper.
|
|
@@ -68,7 +86,12 @@ const Columns = observer<any>(({ record, model, index }) => {
|
|
|
68
86
|
cachedFork.dispose();
|
|
69
87
|
}
|
|
70
88
|
|
|
71
|
-
const fork = action.createFork(
|
|
89
|
+
const fork = action.createFork(
|
|
90
|
+
{
|
|
91
|
+
className: classNames(action.props?.className, 'nb-table-row-action-button'),
|
|
92
|
+
},
|
|
93
|
+
slotKey,
|
|
94
|
+
);
|
|
72
95
|
(fork as any).buttonTypeOptions = rowActionButtonTypeOptions;
|
|
73
96
|
recordIdentityByFork.set(fork, recordIdentity);
|
|
74
97
|
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
useDragSortRowComponent,
|
|
56
56
|
dragSortSettings,
|
|
57
57
|
dragSortBySettings,
|
|
58
|
+
hasSortField,
|
|
58
59
|
} from './dragSort';
|
|
59
60
|
|
|
60
61
|
const MemoizedTable = React.memo(Table);
|
|
@@ -429,9 +430,18 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
429
430
|
return nextIndex;
|
|
430
431
|
}
|
|
431
432
|
|
|
433
|
+
getDragSortFieldName(): string | undefined {
|
|
434
|
+
const dragSortBy = this.props.dragSortBy;
|
|
435
|
+
if (!this.props.dragSort || typeof dragSortBy !== 'string' || !hasSortField(this.collection, dragSortBy)) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return dragSortBy;
|
|
440
|
+
}
|
|
441
|
+
|
|
432
442
|
getLeftAuxiliaryColumn() {
|
|
433
443
|
const showIndex = this.isShowIndexEnabled();
|
|
434
|
-
const showDragHandle = this.
|
|
444
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
435
445
|
if (!showIndex && !showDragHandle) {
|
|
436
446
|
return null;
|
|
437
447
|
}
|
|
@@ -477,7 +487,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
477
487
|
index = this.getRecordIndex(record, index);
|
|
478
488
|
const rowKey = getRowKey(record, this.collection.filterTargetKey);
|
|
479
489
|
const rowKeyString = rowKey == null ? rowKey : String(rowKey);
|
|
480
|
-
const showDragHandle = this.
|
|
490
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
481
491
|
return (
|
|
482
492
|
<div
|
|
483
493
|
role="button"
|
|
@@ -1082,11 +1092,13 @@ const HighPerformanceTable = React.memo(
|
|
|
1082
1092
|
};
|
|
1083
1093
|
}, [rowKeys]);
|
|
1084
1094
|
|
|
1095
|
+
const dragSortFieldName = model.getDragSortFieldName();
|
|
1096
|
+
|
|
1085
1097
|
// 拖拽相关的 Body Wrapper 组件
|
|
1086
|
-
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc);
|
|
1098
|
+
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc, dragSortFieldName);
|
|
1087
1099
|
|
|
1088
1100
|
// 行组件
|
|
1089
|
-
const RowComponent = useDragSortRowComponent(
|
|
1101
|
+
const RowComponent = useDragSortRowComponent(!!dragSortFieldName);
|
|
1090
1102
|
|
|
1091
1103
|
const components = useMemo(() => {
|
|
1092
1104
|
return {
|
|
@@ -1109,15 +1121,14 @@ const HighPerformanceTable = React.memo(
|
|
|
1109
1121
|
}
|
|
1110
1122
|
`;
|
|
1111
1123
|
|
|
1112
|
-
const selectionPaddingClass =
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
: undefined;
|
|
1124
|
+
const selectionPaddingClass = dragSortFieldName
|
|
1125
|
+
? css`
|
|
1126
|
+
.ant-table-thead > tr > th.ant-table-selection-column,
|
|
1127
|
+
.ant-table-tbody > tr > td.ant-table-selection-column {
|
|
1128
|
+
padding-left: 32px !important;
|
|
1129
|
+
}
|
|
1130
|
+
`
|
|
1131
|
+
: undefined;
|
|
1121
1132
|
|
|
1122
1133
|
const tableBodyMinHeightClass = tableScroll?.y
|
|
1123
1134
|
? css`
|
|
@@ -1128,7 +1139,7 @@ const HighPerformanceTable = React.memo(
|
|
|
1128
1139
|
: undefined;
|
|
1129
1140
|
|
|
1130
1141
|
return classNames(baseClass, selectionPaddingClass, tableBodyMinHeightClass);
|
|
1131
|
-
}, [
|
|
1142
|
+
}, [dragSortFieldName, tableScroll?.y]);
|
|
1132
1143
|
|
|
1133
1144
|
return (
|
|
1134
1145
|
<MemoizedTable
|