@nocobase/client-v2 2.2.51 → 2.2.53
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/FlowModelRepository.d.ts +4 -1
- package/es/flow/FlowPage.d.ts +1 -1
- package/es/flow/useRouteContentRequest.d.ts +20 -0
- package/es/index.mjs +114 -90
- package/lib/index.js +99 -75
- package/package.json +7 -7
- package/src/flow/FlowModelRepository.ts +47 -1
- package/src/flow/FlowPage.tsx +25 -10
- package/src/flow/__tests__/FlowModelRepository.test.ts +38 -1
- package/src/flow/__tests__/FlowPage.test.tsx +78 -46
- package/src/flow/models/base/PageModel/PageTabModel.tsx +27 -12
- package/src/flow/models/blocks/details/DetailsItemModel.tsx +53 -9
- package/src/flow/models/blocks/details/__tests__/DetailsItemModel.spacing.test.tsx +58 -33
- package/src/flow/useRouteContentRequest.tsx +46 -0
|
@@ -7,46 +7,71 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { FlowEngine } from '@nocobase/flow-engine';
|
|
10
|
+
import { FlowEngine, FlowModel, Tracker } from '@nocobase/flow-engine';
|
|
11
11
|
import { render } from '@testing-library/react';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { expect, it, vi } from 'vitest';
|
|
14
14
|
import { DetailsItemModel } from '../DetailsItemModel';
|
|
15
15
|
|
|
16
16
|
it.each([
|
|
17
|
-
[true, 'horizontal', ''],
|
|
18
|
-
[true, '
|
|
19
|
-
[
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
['DetailsBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '3px', '29px', true],
|
|
18
|
+
['GridCardBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '8px', '24px', true],
|
|
19
|
+
['GridCardBlockModel', true, 'horizontal', 'DisplayTextFieldModel', 'tag', '8px', '24px', false],
|
|
20
|
+
['DetailsBlockModel', true, 'horizontal', 'DisplayHtmlFieldModel', 'text', '3px', '29px', false],
|
|
21
|
+
['CCTaskCardDetailsModel', true, 'horizontal', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
22
|
+
['DetailsBlockModel', false, 'horizontal', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
23
|
+
['GridCardBlockModel', true, 'vertical', 'DisplayTextFieldModel', 'text', '', '', false],
|
|
24
|
+
] as const)(
|
|
25
|
+
'selects phone styles for %s, mobile=%s, %s, %s (%s)',
|
|
26
|
+
(block, mobile, layout, field, displayStyle, margin, minHeight, plainText) => {
|
|
27
|
+
const engine = new FlowEngine();
|
|
28
|
+
engine.registerModels({ [field]: FlowModel });
|
|
29
|
+
const model = new DetailsItemModel({ uid: 'detail-field', flowEngine: engine });
|
|
30
|
+
model.context.defineProperty('blockModel', { value: { use: block, props: { layout } } });
|
|
31
|
+
model.context.defineProperty('isMobileLayout', { value: mobile });
|
|
32
|
+
model.setProps('label', 'Name');
|
|
33
|
+
model.setStepParams('fieldSettings', 'init', { fieldPath: 'name' });
|
|
34
|
+
model.setSubModel('field', { use: field, props: { displayStyle } });
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
const { container } = render(React.cloneElement(model.renderItem(), {}, <span>Value</span>));
|
|
37
|
+
const item = container.querySelector<HTMLElement>('.ant-form-item');
|
|
38
|
+
const value = item.querySelector('.ant-form-item-control-input-content');
|
|
39
|
+
const rules = Array.from(document.styleSheets).flatMap((sheet) => Array.from(sheet.cssRules));
|
|
40
|
+
const narrowRules = rules.flatMap((rule) =>
|
|
41
|
+
rule instanceof CSSMediaRule && rule.conditionText === '(max-width: 575px)' ? Array.from(rule.cssRules) : [],
|
|
42
|
+
);
|
|
43
|
+
const declarations = (element: Element, property: string) =>
|
|
44
|
+
narrowRules
|
|
45
|
+
.flatMap((rule) =>
|
|
46
|
+
rule instanceof CSSStyleRule && element.matches(rule.selectorText)
|
|
47
|
+
? [rule.style.getPropertyValue(property)]
|
|
48
|
+
: [],
|
|
49
|
+
)
|
|
50
|
+
.filter(Boolean);
|
|
29
51
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
item.matches(rule.selectorText);
|
|
52
|
+
expect(item.style.marginBottom).toBe(margin ? '' : '12px');
|
|
53
|
+
expect(declarations(item, 'margin-bottom')).toEqual(margin ? [margin] : []);
|
|
54
|
+
expect(declarations(item, 'min-height')).toEqual(minHeight ? [minHeight] : []);
|
|
55
|
+
expect(declarations(value, 'line-height')).toEqual(plainText ? ['max(20px, 1.4em)'] : []);
|
|
56
|
+
},
|
|
57
|
+
);
|
|
37
58
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
it('does not subscribe the grid card item to field renderer prop writes', () => {
|
|
60
|
+
const engine = new FlowEngine();
|
|
61
|
+
engine.registerModels({ DisplayTextFieldModel: FlowModel });
|
|
62
|
+
const item = new DetailsItemModel({ uid: 'card-field', flowEngine: engine });
|
|
63
|
+
item.context.defineProperty('blockModel', { value: { use: 'GridCardBlockModel', props: { layout: 'horizontal' } } });
|
|
64
|
+
item.context.defineProperty('isMobileLayout', { value: true });
|
|
65
|
+
item.context.defineProperty('fieldIndex', { value: 0 });
|
|
66
|
+
item.setStepParams('fieldSettings', 'init', { fieldPath: 'name' });
|
|
67
|
+
const field = item.setSubModel('field', { use: 'DisplayTextFieldModel' });
|
|
68
|
+
const invalidate = vi.fn();
|
|
69
|
+
const tracker = new Tracker(invalidate);
|
|
70
|
+
try {
|
|
71
|
+
tracker.track(() => item.renderItem());
|
|
72
|
+
field.getFork('0').setProps({ value: 'First row' });
|
|
73
|
+
expect(invalidate).not.toHaveBeenCalled();
|
|
74
|
+
} finally {
|
|
75
|
+
tracker.dispose();
|
|
76
|
+
}
|
|
52
77
|
});
|
|
@@ -0,0 +1,46 @@
|
|
|
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 { useRequest } from 'ahooks';
|
|
11
|
+
import type { FlowModel } from '@nocobase/flow-engine';
|
|
12
|
+
import React, { useEffect } from 'react';
|
|
13
|
+
import { isRouteContentConfirmed } from './FlowModelRepository';
|
|
14
|
+
|
|
15
|
+
// Keep the current renderer mounted while the first editor confirms the stored page or grid.
|
|
16
|
+
export function useRouteContentRequest(
|
|
17
|
+
load: (forEditing: boolean) => Promise<FlowModel>,
|
|
18
|
+
editing: boolean,
|
|
19
|
+
refreshDeps: unknown[],
|
|
20
|
+
) {
|
|
21
|
+
const { data, error, loading, refresh } = useRequest(
|
|
22
|
+
async () => ({ model: await load(editing), confirmed: editing, refreshDeps }),
|
|
23
|
+
{ refreshDeps },
|
|
24
|
+
);
|
|
25
|
+
const current = data && refreshDeps.every((dep, i) => Object.is(dep, data.refreshDeps[i])) ? data : undefined;
|
|
26
|
+
const needsConfirmation =
|
|
27
|
+
editing && !!current?.model && !current.confirmed && !isRouteContentConfirmed(current.model);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (needsConfirmation && !loading && !error) refresh();
|
|
30
|
+
}, [needsConfirmation, loading, error, refresh]);
|
|
31
|
+
|
|
32
|
+
return { model: current?.model, error, loading, needsConfirmation };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function RouteContent({
|
|
36
|
+
pending,
|
|
37
|
+
className,
|
|
38
|
+
children,
|
|
39
|
+
}: React.PropsWithChildren<{ pending: boolean; className?: string }>) {
|
|
40
|
+
// React 18 forwards inert as a string attribute. Keep the same DOM and component state during initialization.
|
|
41
|
+
return (
|
|
42
|
+
<div className={className} style={{ display: 'contents' }} {...(pending ? { inert: '' } : {})}>
|
|
43
|
+
{children}
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|