@nocobase/client-v2 2.1.27 → 2.1.28
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/FlowRoute.d.ts +2 -2
- package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
- package/es/index.mjs +67 -67
- package/lib/index.js +71 -71
- package/package.json +8 -7
- package/src/flow/__tests__/FlowRoute.test.tsx +1 -0
- package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
- package/src/flow/components/FlowRoute.tsx +6 -28
- package/src/flow/index.ts +2 -0
- package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/client-v2",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.28",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.mjs",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@formily/antd-v5": "1.2.3",
|
|
28
28
|
"@formily/react": "^2.2.27",
|
|
29
29
|
"@formily/shared": "^2.2.27",
|
|
30
|
-
"@nocobase/evaluators": "2.1.
|
|
31
|
-
"@nocobase/flow-engine": "2.1.
|
|
32
|
-
"@nocobase/sdk": "2.1.
|
|
33
|
-
"@nocobase/shared": "2.1.
|
|
34
|
-
"@nocobase/utils": "2.1.
|
|
30
|
+
"@nocobase/evaluators": "2.1.28",
|
|
31
|
+
"@nocobase/flow-engine": "2.1.28",
|
|
32
|
+
"@nocobase/sdk": "2.1.28",
|
|
33
|
+
"@nocobase/shared": "2.1.28",
|
|
34
|
+
"@nocobase/utils": "2.1.28",
|
|
35
35
|
"ahooks": "^3.7.2",
|
|
36
36
|
"antd": "5.24.2",
|
|
37
37
|
"antd-style": "3.7.1",
|
|
@@ -44,8 +44,9 @@
|
|
|
44
44
|
"json5": "^2.2.3",
|
|
45
45
|
"jsqr": "^1.4.0",
|
|
46
46
|
"lodash": "4.17.21",
|
|
47
|
+
"react-device-detect": "2.2.3",
|
|
47
48
|
"react-i18next": "^11.15.1",
|
|
48
49
|
"react-router-dom": "^6.30.1"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "584c0c0e69d32fe502014a6836b3fcb669e89525"
|
|
51
52
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { createMockClient, PluginFlowEngine } from '@nocobase/client-v2';
|
|
11
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
12
|
+
|
|
13
|
+
const { detectedDeviceType } = vi.hoisted(() => ({
|
|
14
|
+
detectedDeviceType: { value: 'mobile' },
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
vi.mock('react-device-detect', () => ({
|
|
18
|
+
get deviceType() {
|
|
19
|
+
return detectedDeviceType.value;
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
describe('PluginFlowEngine', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
detectedDeviceType.value = 'mobile';
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should register the current device type before shared flow components', async () => {
|
|
29
|
+
const app = createMockClient({
|
|
30
|
+
router: {
|
|
31
|
+
type: 'memory',
|
|
32
|
+
initialEntries: ['/'],
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
const plugin = new PluginFlowEngine({}, app);
|
|
36
|
+
const addComponents = app.addComponents.bind(app);
|
|
37
|
+
const deviceTypesBeforeComponentRegistration: string[] = [];
|
|
38
|
+
vi.spyOn(app, 'addComponents').mockImplementation((components) => {
|
|
39
|
+
deviceTypesBeforeComponentRegistration.push(app.flowEngine.context.deviceType);
|
|
40
|
+
return addComponents(components);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
await plugin.load();
|
|
44
|
+
|
|
45
|
+
expect(app.flowEngine.context.deviceType).toBe('mobile');
|
|
46
|
+
expect(deviceTypesBeforeComponentRegistration).toEqual(['mobile']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should normalize the browser device type to computer', async () => {
|
|
50
|
+
detectedDeviceType.value = 'browser';
|
|
51
|
+
const app = createMockClient();
|
|
52
|
+
const plugin = new PluginFlowEngine({}, app);
|
|
53
|
+
|
|
54
|
+
await plugin.load();
|
|
55
|
+
|
|
56
|
+
expect(app.flowEngine.context.deviceType).toBe('computer');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
import { type FlowEngine, useFlowContext, useFlowEngine } from '@nocobase/flow-engine';
|
|
11
11
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
12
|
-
import { deviceType } from 'react-device-detect';
|
|
13
12
|
import { useParams } from 'react-router-dom';
|
|
14
13
|
import { useApp } from '../../hooks/useApp';
|
|
15
14
|
import { NocoBaseDesktopRouteType } from '../../flow-compat';
|
|
@@ -19,6 +18,7 @@ import { getLayoutModel, type BaseLayoutModel } from '../admin-shell/BaseLayoutM
|
|
|
19
18
|
import { useLayoutRoutePage } from '../admin-shell/useLayoutRoutePage';
|
|
20
19
|
import { AppNotFound } from '../../components';
|
|
21
20
|
import { useKeepAlive } from '../../components/KeepAlive';
|
|
21
|
+
import { registerDeviceTypeContext } from '../internal/registerDeviceTypeContext';
|
|
22
22
|
|
|
23
23
|
type FlowRouteGuardState = {
|
|
24
24
|
pending: boolean;
|
|
@@ -94,31 +94,9 @@ const BridgeFlowRoute = ({
|
|
|
94
94
|
const layoutContentRef = useRef<HTMLDivElement>(null);
|
|
95
95
|
|
|
96
96
|
useEffect(() => {
|
|
97
|
-
flowEngine.context.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
meta: {
|
|
101
|
-
type: 'string',
|
|
102
|
-
title: flowEngine.translate('Current device type'),
|
|
103
|
-
interface: 'select',
|
|
104
|
-
uiSchema: {
|
|
105
|
-
enum: [
|
|
106
|
-
{ label: flowEngine.translate('Computer'), value: 'computer' },
|
|
107
|
-
{ label: flowEngine.translate('Mobile'), value: 'mobile' },
|
|
108
|
-
{ label: flowEngine.translate('Tablet'), value: 'tablet' },
|
|
109
|
-
{ label: flowEngine.translate('SmartTv'), value: 'smarttv' },
|
|
110
|
-
{ label: flowEngine.translate('Console'), value: 'console' },
|
|
111
|
-
{ label: flowEngine.translate('Wearable'), value: 'wearable' },
|
|
112
|
-
{ label: flowEngine.translate('Embedded'), value: 'embedded' },
|
|
113
|
-
],
|
|
114
|
-
'x-component': 'Select',
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
info: {
|
|
118
|
-
description: 'Current device type (computer/mobile/tablet/...).',
|
|
119
|
-
detail: 'string',
|
|
120
|
-
},
|
|
121
|
-
});
|
|
97
|
+
if (!flowEngine.context.getPropertyOptions('deviceType')) {
|
|
98
|
+
registerDeviceTypeContext(flowEngine);
|
|
99
|
+
}
|
|
122
100
|
}, [flowEngine]);
|
|
123
101
|
|
|
124
102
|
useLayoutRoutePage({
|
|
@@ -136,8 +114,8 @@ const BridgeFlowRoute = ({
|
|
|
136
114
|
/**
|
|
137
115
|
* 管理后台动态页面路由组件。
|
|
138
116
|
*
|
|
139
|
-
* 负责读取当前路由页面 UID
|
|
140
|
-
*
|
|
117
|
+
* 负责读取当前路由页面 UID,并把页面生命周期桥接到 AdminLayout host model。
|
|
118
|
+
* 设备变量通常由 PluginFlowEngine 共享初始化提供;独立渲染时会在挂载后补充注册。
|
|
141
119
|
*
|
|
142
120
|
* @example
|
|
143
121
|
* ```tsx
|
package/src/flow/index.ts
CHANGED
|
@@ -22,12 +22,14 @@ import { Markdown } from './common/Markdown/Markdown';
|
|
|
22
22
|
import { LiquidEngine } from './common/Liquid';
|
|
23
23
|
import type { PreviewRunJSResult } from './components/code-editor/runjsDiagnostics';
|
|
24
24
|
import { TextAreaWithContextSelector } from './components/TextAreaWithContextSelector';
|
|
25
|
+
import { registerDeviceTypeContext } from './internal/registerDeviceTypeContext';
|
|
25
26
|
|
|
26
27
|
export class PluginFlowEngine<TApp extends BaseApplication<any> = BaseApplication<any>> extends Plugin<
|
|
27
28
|
PluginOptions<any>,
|
|
28
29
|
TApp
|
|
29
30
|
> {
|
|
30
31
|
async load() {
|
|
32
|
+
registerDeviceTypeContext(this.flowEngine);
|
|
31
33
|
this.app.addComponents({ FlowRoute });
|
|
32
34
|
this.app.flowEngine.setModelRepository(new FlowModelRepository(this.app));
|
|
33
35
|
const filteredModels = Object.fromEntries(
|
|
@@ -0,0 +1,39 @@
|
|
|
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 type { FlowEngine } from '@nocobase/flow-engine';
|
|
11
|
+
import { deviceType } from 'react-device-detect';
|
|
12
|
+
|
|
13
|
+
export const registerDeviceTypeContext = (flowEngine: FlowEngine) => {
|
|
14
|
+
flowEngine.context.defineProperty('deviceType', {
|
|
15
|
+
get: () => (deviceType === 'browser' ? 'computer' : deviceType),
|
|
16
|
+
cache: false,
|
|
17
|
+
meta: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
title: flowEngine.translate('Current device type'),
|
|
20
|
+
interface: 'select',
|
|
21
|
+
uiSchema: {
|
|
22
|
+
enum: [
|
|
23
|
+
{ label: flowEngine.translate('Computer'), value: 'computer' },
|
|
24
|
+
{ label: flowEngine.translate('Mobile'), value: 'mobile' },
|
|
25
|
+
{ label: flowEngine.translate('Tablet'), value: 'tablet' },
|
|
26
|
+
{ label: flowEngine.translate('SmartTv'), value: 'smarttv' },
|
|
27
|
+
{ label: flowEngine.translate('Console'), value: 'console' },
|
|
28
|
+
{ label: flowEngine.translate('Wearable'), value: 'wearable' },
|
|
29
|
+
{ label: flowEngine.translate('Embedded'), value: 'embedded' },
|
|
30
|
+
],
|
|
31
|
+
'x-component': 'Select',
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
info: {
|
|
35
|
+
description: 'Current device type (computer/mobile/tablet/...).',
|
|
36
|
+
detail: 'string',
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
};
|