@nocobase/client-v2 2.1.11 → 2.1.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.
- package/es/flow/actions/afterSuccess.d.ts +8 -1
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/models/blocks/form/submitHandler.d.ts +1 -1
- 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 +137 -89
- package/lib/index.js +163 -115
- 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/dateTimeFormat.tsx +2 -2
- 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/__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/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/TableColumnModel.tsx +6 -2
- 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/__tests__/TableColumnModel.test.tsx +51 -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/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/resolveViewParamsToViewList.tsx +11 -3
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/settings-center/SystemSettingsPage.tsx +1 -1
|
@@ -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);
|
|
@@ -419,9 +420,18 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
419
420
|
return nextIndex;
|
|
420
421
|
}
|
|
421
422
|
|
|
423
|
+
getDragSortFieldName(): string | undefined {
|
|
424
|
+
const dragSortBy = this.props.dragSortBy;
|
|
425
|
+
if (!this.props.dragSort || typeof dragSortBy !== 'string' || !hasSortField(this.collection, dragSortBy)) {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return dragSortBy;
|
|
430
|
+
}
|
|
431
|
+
|
|
422
432
|
getLeftAuxiliaryColumn() {
|
|
423
433
|
const showIndex = this.isShowIndexEnabled();
|
|
424
|
-
const showDragHandle = this.
|
|
434
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
425
435
|
if (!showIndex && !showDragHandle) {
|
|
426
436
|
return null;
|
|
427
437
|
}
|
|
@@ -467,7 +477,7 @@ export class TableBlockModel extends CollectionBlockModel<TableBlockModelStructu
|
|
|
467
477
|
index = this.getRecordIndex(record, index);
|
|
468
478
|
const rowKey = getRowKey(record, this.collection.filterTargetKey);
|
|
469
479
|
const rowKeyString = rowKey == null ? rowKey : String(rowKey);
|
|
470
|
-
const showDragHandle = this.
|
|
480
|
+
const showDragHandle = !!this.getDragSortFieldName();
|
|
471
481
|
return (
|
|
472
482
|
<div
|
|
473
483
|
role="button"
|
|
@@ -1072,11 +1082,13 @@ const HighPerformanceTable = React.memo(
|
|
|
1072
1082
|
};
|
|
1073
1083
|
}, [rowKeys]);
|
|
1074
1084
|
|
|
1085
|
+
const dragSortFieldName = model.getDragSortFieldName();
|
|
1086
|
+
|
|
1075
1087
|
// 拖拽相关的 Body Wrapper 组件
|
|
1076
|
-
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc);
|
|
1088
|
+
const BodyWrapperComponent = useDragSortBodyWrapper(model, dataSourceRef, getRowKeyFunc, dragSortFieldName);
|
|
1077
1089
|
|
|
1078
1090
|
// 行组件
|
|
1079
|
-
const RowComponent = useDragSortRowComponent(
|
|
1091
|
+
const RowComponent = useDragSortRowComponent(!!dragSortFieldName);
|
|
1080
1092
|
|
|
1081
1093
|
const components = useMemo(() => {
|
|
1082
1094
|
return {
|
|
@@ -1099,15 +1111,14 @@ const HighPerformanceTable = React.memo(
|
|
|
1099
1111
|
}
|
|
1100
1112
|
`;
|
|
1101
1113
|
|
|
1102
|
-
const selectionPaddingClass =
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
: undefined;
|
|
1114
|
+
const selectionPaddingClass = dragSortFieldName
|
|
1115
|
+
? css`
|
|
1116
|
+
.ant-table-thead > tr > th.ant-table-selection-column,
|
|
1117
|
+
.ant-table-tbody > tr > td.ant-table-selection-column {
|
|
1118
|
+
padding-left: 32px !important;
|
|
1119
|
+
}
|
|
1120
|
+
`
|
|
1121
|
+
: undefined;
|
|
1111
1122
|
|
|
1112
1123
|
const tableBodyMinHeightClass = tableScroll?.y
|
|
1113
1124
|
? css`
|
|
@@ -1118,7 +1129,7 @@ const HighPerformanceTable = React.memo(
|
|
|
1118
1129
|
: undefined;
|
|
1119
1130
|
|
|
1120
1131
|
return classNames(baseClass, selectionPaddingClass, tableBodyMinHeightClass);
|
|
1121
|
-
}, [
|
|
1132
|
+
}, [dragSortFieldName, tableScroll?.y]);
|
|
1122
1133
|
|
|
1123
1134
|
return (
|
|
1124
1135
|
<MemoizedTable
|
|
@@ -373,14 +373,18 @@ TableColumnModel.registerFlow({
|
|
|
373
373
|
currentProps: ctx.model.props,
|
|
374
374
|
})
|
|
375
375
|
: undefined;
|
|
376
|
+
const collectionFieldComponentProps = collectionField.getComponentProps();
|
|
376
377
|
const componentProps =
|
|
377
378
|
collectionField.isAssociationField() && titleField
|
|
378
379
|
? {
|
|
379
|
-
...
|
|
380
|
+
...collectionFieldComponentProps,
|
|
380
381
|
...targetCollectionField?.getComponentProps?.(),
|
|
381
382
|
...savedDateTimeDisplayProps,
|
|
382
383
|
}
|
|
383
|
-
:
|
|
384
|
+
: {
|
|
385
|
+
...collectionFieldComponentProps,
|
|
386
|
+
...savedDateTimeDisplayProps,
|
|
387
|
+
};
|
|
384
388
|
ctx.model.setProps('title', collectionField.title);
|
|
385
389
|
ctx.model.setProps('dataIndex', collectionField.name);
|
|
386
390
|
// for quick edit
|
|
@@ -13,7 +13,7 @@ import { App, ConfigProvider } from 'antd';
|
|
|
13
13
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
14
14
|
import { FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
15
15
|
import { ActionModel } from '../../../base/ActionModel';
|
|
16
|
-
import { TableActionsColumnModel } from '../TableActionsColumnModel';
|
|
16
|
+
import { TableActionsColumnModel, tableRowActionsClassName } from '../TableActionsColumnModel';
|
|
17
17
|
|
|
18
18
|
const capturedDroppableUids: string[] = [];
|
|
19
19
|
const capturedRendererProps: any[] = [];
|
|
@@ -61,6 +61,10 @@ class TestAlwaysActionModel extends ActionModel {
|
|
|
61
61
|
defaultProps: any = { type: 'link', title: 'Always' };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
class TestTextActionModel extends ActionModel {
|
|
65
|
+
defaultProps: any = { type: 'text', title: 'Text action' };
|
|
66
|
+
}
|
|
67
|
+
|
|
64
68
|
// 在 beforeRender 中,根据 inputArgs(即当前行 record)决定是否隐藏按钮
|
|
65
69
|
TestViewActionModel.registerFlow({
|
|
66
70
|
key: 'autoHideByPhone',
|
|
@@ -158,6 +162,58 @@ describe('TableActionsColumnModel: hidden action layout', () => {
|
|
|
158
162
|
expect(wrappers).toHaveLength(0);
|
|
159
163
|
expect(secondUid).toBeTruthy();
|
|
160
164
|
});
|
|
165
|
+
|
|
166
|
+
it('renders row link and text actions with compact button styles', async () => {
|
|
167
|
+
const engine = new FlowEngine();
|
|
168
|
+
engine.registerModels({ TableActionsColumnModel, TestViewActionModel, TestTextActionModel });
|
|
169
|
+
|
|
170
|
+
const actionsCol = engine.createModel<TableActionsColumnModel>({
|
|
171
|
+
use: 'TableActionsColumnModel',
|
|
172
|
+
props: { width: 200, title: 'Actions' },
|
|
173
|
+
subModels: { actions: [{ use: 'TestViewActionModel' }, { use: 'TestTextActionModel' }] },
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const colProps = actionsCol.getColumnProps();
|
|
177
|
+
const record = { id: 1, phone: '000000' } as any;
|
|
178
|
+
|
|
179
|
+
const { container } = render(
|
|
180
|
+
<FlowEngineProvider engine={engine}>
|
|
181
|
+
<ConfigProvider>
|
|
182
|
+
<App>{colProps.render?.(undefined, record, 0) as any}</App>
|
|
183
|
+
</ConfigProvider>
|
|
184
|
+
</FlowEngineProvider>,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
await waitFor(() => {
|
|
188
|
+
expect(screen.getByText('View')).toBeInTheDocument();
|
|
189
|
+
expect(screen.getByText('Text action')).toBeInTheDocument();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const actions = container.querySelector('.nb-table-row-actions');
|
|
193
|
+
expect(actions).toBeInTheDocument();
|
|
194
|
+
expect(actions).toHaveClass(tableRowActionsClassName);
|
|
195
|
+
|
|
196
|
+
const linkButton = actions?.querySelector('.ant-btn-link') as HTMLButtonElement;
|
|
197
|
+
const textButton = actions?.querySelector('.ant-btn-text') as HTMLButtonElement;
|
|
198
|
+
|
|
199
|
+
expect(linkButton).toBeInTheDocument();
|
|
200
|
+
expect(textButton).toBeInTheDocument();
|
|
201
|
+
expect(linkButton).toHaveClass('nb-table-row-action-button');
|
|
202
|
+
expect(textButton).toHaveClass('nb-table-row-action-button');
|
|
203
|
+
|
|
204
|
+
const actionButtonStyleText = Array.from(document.querySelectorAll('style'))
|
|
205
|
+
.map((style) => style.textContent || '')
|
|
206
|
+
.find((styleText) => styleText.includes('.nb-table-row-action-button.ant-btn-link'));
|
|
207
|
+
expect(actionButtonStyleText).toContain(tableRowActionsClassName);
|
|
208
|
+
expect(actionButtonStyleText).toContain('font:inherit');
|
|
209
|
+
expect(actionButtonStyleText).toContain('height:auto');
|
|
210
|
+
expect(actionButtonStyleText).toContain('line-height:inherit');
|
|
211
|
+
expect(actionButtonStyleText).toContain('padding:0');
|
|
212
|
+
expect(actionButtonStyleText).toContain('border:0');
|
|
213
|
+
expect(actionButtonStyleText).toContain('box-shadow:none');
|
|
214
|
+
expect(actionButtonStyleText).not.toContain('1.5714285714285714');
|
|
215
|
+
expect(actionButtonStyleText).not.toContain('!important');
|
|
216
|
+
});
|
|
161
217
|
});
|
|
162
218
|
|
|
163
219
|
describe('TableActionsColumnModel: drag integration', () => {
|