@nocobase/client-v2 2.2.0-alpha.3 → 2.2.0-alpha.5
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/BaseApplication.d.ts +2 -0
- package/es/RouteRepository.d.ts +8 -0
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/form/TypedVariableInput.d.ts +9 -1
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/admin-shell/BaseLayoutModel.d.ts +6 -0
- package/es/flow/admin-shell/BaseLayoutRouteCoordinator.d.ts +7 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/models/base/ActionModelCore.d.ts +2 -0
- package/es/flow/routeTransientInputArgs.d.ts +14 -0
- package/es/index.d.ts +6 -0
- package/es/index.mjs +229 -143
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/markdownSanitize.d.ts +11 -0
- package/lib/index.js +219 -133
- package/package.json +7 -7
- package/src/BaseApplication.tsx +2 -0
- package/src/RouteRepository.ts +25 -0
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/authRedirect.ts +38 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +58 -34
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +52 -0
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/FlowPage.tsx +29 -2
- package/src/flow/__tests__/FlowPage.test.tsx +152 -25
- package/src/flow/__tests__/FlowRoute.test.tsx +547 -2
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +62 -0
- package/src/flow/actions/__tests__/openView.defineProps.route.test.tsx +80 -20
- package/src/flow/actions/dataScopeFilter.ts +10 -1
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/actions/openView.tsx +21 -1
- package/src/flow/admin-shell/BaseLayoutModel.tsx +124 -0
- package/src/flow/admin-shell/BaseLayoutRouteCoordinator.ts +184 -42
- package/src/flow/admin-shell/__tests__/AdminLayoutRouteCoordinator.test.ts +1016 -119
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +41 -4
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +436 -2
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +48 -0
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/common/Markdown/Display.tsx +14 -3
- package/src/flow/common/Markdown/Edit.tsx +19 -7
- package/src/flow/components/FlowRoute.tsx +128 -16
- package/src/flow/internal/components/Markdown/util.ts +2 -1
- package/src/flow/models/base/ActionModel.tsx +10 -8
- package/src/flow/models/base/ActionModelCore.tsx +5 -0
- package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/models/fields/TextareaFieldModel.tsx +42 -19
- package/src/flow/models/fields/__tests__/TextareaFieldModel.test.tsx +32 -1
- package/src/flow/models/topbar/TopbarActionModel.tsx +78 -3
- package/src/flow/routeTransientInputArgs.ts +27 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/index.ts +6 -0
- package/src/nocobase-buildin-plugin/index.tsx +7 -1
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
- package/src/utils/markdownSanitize.ts +88 -0
|
@@ -9,56 +9,79 @@
|
|
|
9
9
|
|
|
10
10
|
import { Input } from 'antd';
|
|
11
11
|
import type { TextAreaProps } from 'antd/es/input';
|
|
12
|
-
import
|
|
13
|
-
import React, { useEffect, useRef } from 'react';
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
14
13
|
import { largeField, EditableItemModel } from '@nocobase/flow-engine';
|
|
15
14
|
import { FieldModel } from '../base/FieldModel';
|
|
16
15
|
|
|
17
16
|
function IMESafeTextArea(props: TextAreaProps) {
|
|
18
17
|
const { value, onChange, onCompositionStart, onCompositionEnd, ...rest } = props;
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
18
|
+
const [textAreaValue, setTextAreaValue] = useState<TextAreaProps['value']>(() => normalizeTextAreaValue(value));
|
|
19
|
+
const textAreaValueRef = useRef<TextAreaProps['value']>(textAreaValue);
|
|
20
|
+
const pendingLocalValuesRef = useRef<TextAreaProps['value'][]>([]);
|
|
22
21
|
|
|
23
22
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
previousValueRef.current = value;
|
|
23
|
+
const nextValue = normalizeTextAreaValue(value);
|
|
24
|
+
const pendingValues = pendingLocalValuesRef.current;
|
|
25
|
+
const pendingIndex = pendingValues.findIndex((item) => Object.is(item, nextValue));
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
textArea.value = nextValue;
|
|
27
|
+
if (pendingIndex >= 0) {
|
|
28
|
+
pendingValues.splice(0, pendingIndex + 1);
|
|
29
|
+
if (!Object.is(textAreaValueRef.current, nextValue)) {
|
|
30
|
+
return;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
33
|
+
|
|
34
|
+
pendingValues.length = 0;
|
|
35
|
+
if (Object.is(textAreaValueRef.current, nextValue)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
textAreaValueRef.current = nextValue;
|
|
40
|
+
setTextAreaValue(nextValue);
|
|
36
41
|
}, [value]);
|
|
37
42
|
|
|
38
43
|
const getEventValue = (event: React.ChangeEvent<HTMLTextAreaElement> | React.CompositionEvent<HTMLTextAreaElement>) =>
|
|
39
44
|
event.currentTarget.value;
|
|
40
45
|
|
|
46
|
+
const recordLocalValue = (
|
|
47
|
+
event: React.ChangeEvent<HTMLTextAreaElement> | React.CompositionEvent<HTMLTextAreaElement>,
|
|
48
|
+
) => {
|
|
49
|
+
const nextValue = getEventValue(event);
|
|
50
|
+
const pendingValues = pendingLocalValuesRef.current;
|
|
51
|
+
pendingValues.push(nextValue);
|
|
52
|
+
if (pendingValues.length > 20) {
|
|
53
|
+
pendingValues.shift();
|
|
54
|
+
}
|
|
55
|
+
textAreaValueRef.current = nextValue;
|
|
56
|
+
setTextAreaValue(nextValue);
|
|
57
|
+
};
|
|
58
|
+
|
|
41
59
|
return (
|
|
42
60
|
<Input.TextArea
|
|
43
61
|
{...rest}
|
|
44
|
-
|
|
45
|
-
defaultValue={defaultValue}
|
|
62
|
+
value={textAreaValue}
|
|
46
63
|
onChange={(event) => {
|
|
47
|
-
|
|
64
|
+
recordLocalValue(event);
|
|
48
65
|
onChange?.(event);
|
|
49
66
|
}}
|
|
50
67
|
onCompositionStart={(event) => {
|
|
51
|
-
|
|
68
|
+
recordLocalValue(event);
|
|
52
69
|
onCompositionStart?.(event);
|
|
53
70
|
}}
|
|
54
71
|
onCompositionEnd={(event) => {
|
|
55
|
-
|
|
72
|
+
recordLocalValue(event);
|
|
56
73
|
onCompositionEnd?.(event);
|
|
57
74
|
}}
|
|
58
75
|
/>
|
|
59
76
|
);
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
function normalizeTextAreaValue(nextValue: unknown): TextAreaProps['value'] {
|
|
80
|
+
if (typeof nextValue === 'bigint') return String(nextValue);
|
|
81
|
+
if (nextValue == null) return '';
|
|
82
|
+
return nextValue as TextAreaProps['value'];
|
|
83
|
+
}
|
|
84
|
+
|
|
62
85
|
@largeField()
|
|
63
86
|
export class TextareaFieldModel extends FieldModel {
|
|
64
87
|
render() {
|
|
@@ -7,8 +7,9 @@
|
|
|
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 { FieldModelRenderer, FlowEngine, FlowEngineProvider } from '@nocobase/flow-engine';
|
|
11
11
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
12
|
+
import { Form } from 'antd';
|
|
12
13
|
import React from 'react';
|
|
13
14
|
import { describe, expect, it, vi } from 'vitest';
|
|
14
15
|
import { TextareaFieldModel } from '../TextareaFieldModel';
|
|
@@ -23,6 +24,36 @@ function createTextareaFieldModel(props?: Record<string, unknown>) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
describe('TextareaFieldModel', () => {
|
|
27
|
+
it('syncs multiline values assigned through the form renderer', async () => {
|
|
28
|
+
const flowEngine = new FlowEngine();
|
|
29
|
+
const model = createTextareaFieldModel();
|
|
30
|
+
model.dispatchEvent = vi.fn().mockResolvedValue([]);
|
|
31
|
+
|
|
32
|
+
function FormHost() {
|
|
33
|
+
const [form] = Form.useForm();
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
form.setFieldsValue({ address: 'aaaaaa\nbbbbbb' });
|
|
37
|
+
}, [form]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<FlowEngineProvider engine={flowEngine}>
|
|
41
|
+
<Form form={form}>
|
|
42
|
+
<Form.Item name="address">
|
|
43
|
+
<FieldModelRenderer model={model} />
|
|
44
|
+
</Form.Item>
|
|
45
|
+
</Form>
|
|
46
|
+
</FlowEngineProvider>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
render(<FormHost />);
|
|
51
|
+
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect((screen.getByRole('textbox') as HTMLTextAreaElement).value).toBe('aaaaaa\nbbbbbb');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
26
57
|
it('keeps IME composition text visible before the parent value is committed', () => {
|
|
27
58
|
const onChange = vi.fn();
|
|
28
59
|
const onCompositionStart = vi.fn();
|
|
@@ -18,6 +18,7 @@ import { Link, useLocation } from 'react-router-dom';
|
|
|
18
18
|
import { useACLRoleContext } from '../../../acl';
|
|
19
19
|
import type { BaseApplication } from '../../../BaseApplication';
|
|
20
20
|
import type { PluginSettingsPageType } from '../../../PluginSettingsManager';
|
|
21
|
+
import { shouldOpenAdminRouteInNewWindow } from '../../../RouterManager';
|
|
21
22
|
import { useApp } from '../../../hooks/useApp';
|
|
22
23
|
import {
|
|
23
24
|
filterRenderableSettings,
|
|
@@ -65,7 +66,10 @@ const topbarActionTriggerClassName = css`
|
|
|
65
66
|
height: 100%;
|
|
66
67
|
`;
|
|
67
68
|
|
|
68
|
-
type TopbarSettingsAppLike = Pick<
|
|
69
|
+
type TopbarSettingsAppLike = Pick<
|
|
70
|
+
BaseApplication<any>,
|
|
71
|
+
'name' | 'router' | 'getPublicPath' | 'getHref' | 'layoutManager'
|
|
72
|
+
>;
|
|
69
73
|
|
|
70
74
|
const normalizeTopbarPath = (pathname?: string) => {
|
|
71
75
|
const trimmed = pathname?.trim();
|
|
@@ -103,10 +107,57 @@ const stripTopbarRouterBasePath = (pathname: string, basename?: string) => {
|
|
|
103
107
|
return normalizedPath;
|
|
104
108
|
};
|
|
105
109
|
|
|
110
|
+
const getTopbarAppPath = (pathname: string) => {
|
|
111
|
+
const normalizedPath = normalizeTopbarPath(pathname);
|
|
112
|
+
const match = /^(.*?\/(?:apps|_app)\/[^/]+)(?=\/|$)/.exec(normalizedPath);
|
|
113
|
+
const appPath = match?.[1] || '';
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
appPath,
|
|
117
|
+
routePath: appPath ? normalizeTopbarPath(normalizedPath.slice(appPath.length)) : normalizedPath,
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getTopbarContextAppPath = (app: TopbarSettingsAppLike | undefined, basename?: string) => {
|
|
122
|
+
const basenameAppPath = getTopbarAppPath(basename || '').appPath;
|
|
123
|
+
if (basenameAppPath) {
|
|
124
|
+
return basenameAppPath;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const publicPathAppPath = getTopbarAppPath(app?.getPublicPath?.() || '').appPath;
|
|
128
|
+
if (publicPathAppPath) {
|
|
129
|
+
return publicPathAppPath;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (app?.name && app.name !== 'main' && app.getHref) {
|
|
133
|
+
return normalizeTopbarBasePath(app.getHref('/'));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return '';
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const prependTopbarAppPath = (pathname: string, appPath: string) => {
|
|
140
|
+
const normalizedPath = normalizeTopbarPath(pathname);
|
|
141
|
+
|
|
142
|
+
if (!appPath || normalizedPath === appPath || normalizedPath.startsWith(`${appPath}/`)) {
|
|
143
|
+
return normalizedPath;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return `${appPath}${normalizedPath}`;
|
|
147
|
+
};
|
|
148
|
+
|
|
106
149
|
const isAdminRuntimePath = (pathname: string) => {
|
|
107
150
|
return pathname === '/admin' || pathname.startsWith('/admin/');
|
|
108
151
|
};
|
|
109
152
|
|
|
153
|
+
const getTopbarAdminRoutePath = (app: TopbarSettingsAppLike | undefined) => {
|
|
154
|
+
try {
|
|
155
|
+
return app?.layoutManager?.getLayout?.('admin')?.routePath;
|
|
156
|
+
} catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
110
161
|
const buildTopbarDocumentHref = (targetPath: string, basename?: string) => {
|
|
111
162
|
const normalizedTarget = normalizeTopbarPath(targetPath);
|
|
112
163
|
const normalizedBase = normalizeTopbarBasePath(basename);
|
|
@@ -136,9 +187,33 @@ function TopbarInternalSettingsLabel(props: { title: React.ReactNode; path?: str
|
|
|
136
187
|
const targetPath = props.path || '/admin/settings';
|
|
137
188
|
const basename = getTopbarRouterBasePath(app);
|
|
138
189
|
const currentPath = stripTopbarRouterBasePath(location.pathname, basename);
|
|
190
|
+
const currentLocationAppPath = getTopbarAppPath(currentPath);
|
|
191
|
+
const currentAppPath = currentLocationAppPath.appPath || getTopbarContextAppPath(app, basename);
|
|
192
|
+
const currentRoutePath = currentLocationAppPath.appPath ? currentLocationAppPath.routePath : currentPath;
|
|
193
|
+
const targetPathInCurrentApp = prependTopbarAppPath(stripTopbarRouterBasePath(targetPath, basename), currentAppPath);
|
|
194
|
+
|
|
195
|
+
if (currentAppPath) {
|
|
196
|
+
const href = buildTopbarDocumentHref(targetPathInCurrentApp, basename);
|
|
197
|
+
const shouldOpenInNewWindow = shouldOpenAdminRouteInNewWindow({
|
|
198
|
+
currentPathname: currentPath,
|
|
199
|
+
targetPathname: targetPathInCurrentApp,
|
|
200
|
+
basePath: basename,
|
|
201
|
+
adminRoutePath: getTopbarAdminRoutePath(app),
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<a
|
|
206
|
+
href={href}
|
|
207
|
+
target={shouldOpenInNewWindow ? '_blank' : undefined}
|
|
208
|
+
rel={shouldOpenInNewWindow ? 'noopener noreferrer' : undefined}
|
|
209
|
+
>
|
|
210
|
+
{props.title}
|
|
211
|
+
</a>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
139
214
|
|
|
140
|
-
if (isAdminRuntimePath(
|
|
141
|
-
return <Link to={
|
|
215
|
+
if (isAdminRuntimePath(currentRoutePath)) {
|
|
216
|
+
return <Link to={targetPathInCurrentApp}>{props.title}</Link>;
|
|
142
217
|
}
|
|
143
218
|
|
|
144
219
|
return (
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export const ROUTE_TRANSIENT_INPUT_ARGS_KEY = '__nocobaseOpenViewInputArgs';
|
|
11
|
+
|
|
12
|
+
export type RouteTransientInputArgsState = {
|
|
13
|
+
[ROUTE_TRANSIENT_INPUT_ARGS_KEY]?: Record<string, Record<string, unknown>>;
|
|
14
|
+
usr?: RouteTransientInputArgsState;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getRouteTransientInputArgs = (state: unknown, viewUid?: string) => {
|
|
18
|
+
if (!viewUid || !state || typeof state !== 'object') {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const stateValue = state as RouteTransientInputArgsState;
|
|
23
|
+
const values = (stateValue[ROUTE_TRANSIENT_INPUT_ARGS_KEY] || stateValue.usr?.[ROUTE_TRANSIENT_INPUT_ARGS_KEY])?.[
|
|
24
|
+
viewUid
|
|
25
|
+
];
|
|
26
|
+
return values && typeof values === 'object' ? values : {};
|
|
27
|
+
};
|
|
@@ -207,6 +207,48 @@ describe('dateTimeFormat', () => {
|
|
|
207
207
|
expect(save).toHaveBeenCalled();
|
|
208
208
|
});
|
|
209
209
|
|
|
210
|
+
it('syncs ordinary table column props when date time format settings are saved', async () => {
|
|
211
|
+
const setProps = vi.fn();
|
|
212
|
+
const save = vi.fn();
|
|
213
|
+
const setParentProps = vi.fn();
|
|
214
|
+
const model = {
|
|
215
|
+
context: {
|
|
216
|
+
collectionField: {
|
|
217
|
+
type: 'datetime',
|
|
218
|
+
interface: 'datetime',
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
setProps,
|
|
222
|
+
save,
|
|
223
|
+
parent: {
|
|
224
|
+
use: 'TableColumnModel',
|
|
225
|
+
setProps: setParentProps,
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
model.parent['subModels'] = {
|
|
229
|
+
field: model,
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
await dateTimeFormat.beforeParamsSave(
|
|
233
|
+
{ model },
|
|
234
|
+
{
|
|
235
|
+
picker: 'date',
|
|
236
|
+
dateFormat: 'YYYY-MM-DD',
|
|
237
|
+
showTime: true,
|
|
238
|
+
timeFormat: 'HH:mm:ss',
|
|
239
|
+
},
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(setParentProps).toHaveBeenCalledWith({
|
|
243
|
+
picker: 'date',
|
|
244
|
+
dateFormat: 'YYYY-MM-DD',
|
|
245
|
+
showTime: true,
|
|
246
|
+
timeFormat: 'HH:mm:ss',
|
|
247
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
248
|
+
});
|
|
249
|
+
expect(save).toHaveBeenCalled();
|
|
250
|
+
});
|
|
251
|
+
|
|
210
252
|
it('hides time format for association title date-only fields', () => {
|
|
211
253
|
const ctx = {
|
|
212
254
|
model: {
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,8 @@ export * from './layout-manager';
|
|
|
30
30
|
export * from './hooks';
|
|
31
31
|
export { default as languageCodes } from './locale/languageCodes';
|
|
32
32
|
export * from './nocobase-buildin-plugin';
|
|
33
|
+
export { getRouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
|
|
34
|
+
export type { RouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
|
|
33
35
|
export * from './collection-field-interface/CollectionFieldInterface';
|
|
34
36
|
export * from './collection-field-interface/CollectionFieldInterfaceManager';
|
|
35
37
|
export * from './collection-manager/field-configure';
|
|
@@ -38,7 +40,10 @@ export * from './collection-manager/filter-operators';
|
|
|
38
40
|
export * from './collection-manager/interfaces';
|
|
39
41
|
export * from './collection-manager/template-fields';
|
|
40
42
|
export * from './data-source';
|
|
43
|
+
export * from './entry-actions';
|
|
41
44
|
export * from './flow';
|
|
45
|
+
export { CodeEditorExtension } from './flow/components/code-editor/extension';
|
|
46
|
+
export type { CodeEditorExtra, CodeEditorExtraRegistry, EditorRef } from './flow/components/code-editor/types';
|
|
42
47
|
export {
|
|
43
48
|
DEFAULT_DATA_SOURCE_KEY,
|
|
44
49
|
IconPicker,
|
|
@@ -47,4 +52,5 @@ export {
|
|
|
47
52
|
NocoBaseDesktopRouteType,
|
|
48
53
|
} from './flow-compat';
|
|
49
54
|
export type { NocoBaseDesktopRoute } from './flow-compat';
|
|
55
|
+
export * from './utils/markdownSanitize';
|
|
50
56
|
export { default as AntdAppProvider } from './theme/AntdAppProvider';
|
|
@@ -15,7 +15,12 @@ import type { Application } from '../Application';
|
|
|
15
15
|
import { getCurrentV2RedirectPath, getDefaultV2AdminRedirectPath } from '../authRedirect';
|
|
16
16
|
import { AppNotFound } from '../components';
|
|
17
17
|
import { PluginFlowEngine } from '../flow';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
ADMIN_LAYOUT_MODEL_UID,
|
|
20
|
+
AdminLayoutMenuItemModel,
|
|
21
|
+
AdminLayoutModel,
|
|
22
|
+
AppSwitcherActionPanelModel,
|
|
23
|
+
} from '../flow/admin-shell/admin-layout';
|
|
19
24
|
import { useApp } from '../hooks/useApp';
|
|
20
25
|
import { Plugin } from '../Plugin';
|
|
21
26
|
import { AdminSettingsLayoutModel } from '../settings-center';
|
|
@@ -326,6 +331,7 @@ export class NocoBaseBuildInPlugin extends Plugin<any, Application> {
|
|
|
326
331
|
this.app.flowEngine.registerModels({
|
|
327
332
|
AdminLayoutModel,
|
|
328
333
|
AdminLayoutMenuItemModel,
|
|
334
|
+
AppSwitcherActionPanelModel,
|
|
329
335
|
AdminSettingsLayoutModel,
|
|
330
336
|
});
|
|
331
337
|
this.app.layoutManager.registerLayout({
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
export type RouteRuntimeVersion = 'legacy' | 'modern';
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
__nocobase_modern_client_prefix__?: string;
|
|
15
|
+
__nocobase_public_path__?: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hasModernClientPrefix() {
|
|
20
|
+
return (
|
|
21
|
+
typeof window !== 'undefined' &&
|
|
22
|
+
typeof window.__nocobase_modern_client_prefix__ === 'string' &&
|
|
23
|
+
window.__nocobase_modern_client_prefix__.trim().length > 0
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function hasConfiguredPublicPath() {
|
|
28
|
+
return typeof window !== 'undefined' && typeof window.__nocobase_public_path__ === 'string';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Normalize any app/public-path-like input into a root-relative pathname:
|
|
32
|
+
*
|
|
33
|
+
* - `nocobase//v/` -> `/nocobase/v`
|
|
34
|
+
* - `/` -> `/`
|
|
35
|
+
*/
|
|
36
|
+
function normalizeRootRelativePath(value = '/') {
|
|
37
|
+
const normalized = `/${String(value || '/').trim() || '/'}`.replace(/\/{2,}/g, '/');
|
|
38
|
+
if (normalized !== '/' && normalized.endsWith('/')) {
|
|
39
|
+
return normalized.replace(/\/+$/g, '');
|
|
40
|
+
}
|
|
41
|
+
return normalized;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Public-path form always ends with `/`, so it can be compared as a base path:
|
|
45
|
+
*
|
|
46
|
+
* - `/nocobase/v` -> `/nocobase/v/`
|
|
47
|
+
* - `/` -> `/`
|
|
48
|
+
*/
|
|
49
|
+
function normalizePublicPath(value = '/') {
|
|
50
|
+
const normalized = normalizeRootRelativePath(value);
|
|
51
|
+
return normalized.endsWith('/') ? normalized : `${normalized}/`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Check whether a concrete pathname is rendered under a runtime base path:
|
|
55
|
+
*
|
|
56
|
+
* - pathname `/nocobase/v/admin/workflow/workflows/1`
|
|
57
|
+
* basePath `/nocobase/v/`
|
|
58
|
+
* => true
|
|
59
|
+
*
|
|
60
|
+
* - pathname `/nocobase/admin/settings/workflow/workflows/1`
|
|
61
|
+
* basePath `/nocobase/v/`
|
|
62
|
+
* => false
|
|
63
|
+
*/
|
|
64
|
+
function isPathnameInsideBasePath(pathname: string, basePath: string) {
|
|
65
|
+
const normalizedPathname = normalizeRootRelativePath(pathname);
|
|
66
|
+
const normalizedBasePath = normalizePublicPath(basePath);
|
|
67
|
+
const trimmedBasePath = normalizedBasePath.replace(/\/+$/g, '') || '/';
|
|
68
|
+
|
|
69
|
+
if (trimmedBasePath === '/') {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return normalizedPathname === trimmedBasePath || normalizedPathname.startsWith(`${trimmedBasePath}/`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getNormalizedModernClientPrefix() {
|
|
77
|
+
if (typeof window === 'undefined') {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const prefix = window.__nocobase_modern_client_prefix__?.trim();
|
|
82
|
+
return prefix ? prefix.replace(/^\/+|\/+$/g, '') : '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Derive the actual modern-client base path from injected globals.
|
|
86
|
+
*
|
|
87
|
+
* Only returns a value when `__nocobase_public_path__` itself already points to
|
|
88
|
+
* the modern client shell:
|
|
89
|
+
*
|
|
90
|
+
* - legacy shell:
|
|
91
|
+
* `__nocobase_public_path__ = "/nocobase/"`
|
|
92
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
93
|
+
* => `""`
|
|
94
|
+
*
|
|
95
|
+
* - modern shell:
|
|
96
|
+
* `__nocobase_public_path__ = "/nocobase/v/"`
|
|
97
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
98
|
+
* => `"/nocobase/v/"`
|
|
99
|
+
*/
|
|
100
|
+
function getModernClientBasePath() {
|
|
101
|
+
const normalizedPrefix = getNormalizedModernClientPrefix();
|
|
102
|
+
if (!normalizedPrefix) {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (typeof window === 'undefined') {
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const publicPath = window.__nocobase_public_path__?.trim();
|
|
111
|
+
if (publicPath && normalizePublicPath(publicPath).endsWith(`/${normalizedPrefix}/`)) {
|
|
112
|
+
return normalizePublicPath(publicPath);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** True only when the current page is actually running under the resolved
|
|
119
|
+
* modern-client base path.
|
|
120
|
+
*
|
|
121
|
+
* Example:
|
|
122
|
+
* - pathname `/v/admin/workflow/workflows/1`, modern base `/v/` => true
|
|
123
|
+
* - pathname `/admin/settings/workflow/workflows/1`, modern base `/v/` => false
|
|
124
|
+
*/
|
|
125
|
+
function isPathnameInModernClientRuntime() {
|
|
126
|
+
if (typeof window === 'undefined') {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const pathname = window.location?.pathname ?? '';
|
|
131
|
+
const modernClientBasePath = getModernClientBasePath();
|
|
132
|
+
if (!pathname || !modernClientBasePath) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return isPathnameInsideBasePath(pathname, modernClientBasePath);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Fallback for incomplete/mocked environments where public path was not
|
|
140
|
+
* injected but the modern prefix still exists.
|
|
141
|
+
*
|
|
142
|
+
* Example:
|
|
143
|
+
* - pathname `/v/admin/workflow/workflows/1`
|
|
144
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
145
|
+
* `__nocobase_public_path__` missing
|
|
146
|
+
* => true
|
|
147
|
+
*/
|
|
148
|
+
function isPathnameInModernClientRuntimeByPrefix() {
|
|
149
|
+
if (typeof window === 'undefined') {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const normalizedPrefix = getNormalizedModernClientPrefix();
|
|
154
|
+
const pathname = window.location?.pathname ?? '';
|
|
155
|
+
if (!normalizedPrefix || !pathname) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return isPathnameInsideBasePath(pathname, normalizePublicPath(normalizedPrefix));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Resolve which client shell currently owns the route.
|
|
163
|
+
*
|
|
164
|
+
* - returns `modern` when the current page is actually mounted under the modern
|
|
165
|
+
* client base path (`/v/`, `/nocobase/v/`, ...)
|
|
166
|
+
* - returns `legacy` when the route is still under the legacy shell, even if the
|
|
167
|
+
* modern prefix global has been injected into the page
|
|
168
|
+
*/
|
|
169
|
+
export function getRouteRuntimeVersion(): RouteRuntimeVersion {
|
|
170
|
+
if (typeof window === 'undefined') {
|
|
171
|
+
return hasModernClientPrefix() ? 'modern' : 'legacy';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (hasConfiguredPublicPath()) {
|
|
175
|
+
return isPathnameInModernClientRuntime() ? 'modern' : 'legacy';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Defensive fallback for incomplete test/mocked environments where public
|
|
179
|
+
// path was not injected but the modern prefix still exists.
|
|
180
|
+
if (isPathnameInModernClientRuntimeByPrefix()) {
|
|
181
|
+
return 'modern';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return 'legacy';
|
|
185
|
+
}
|
package/src/utils/index.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import React, { ComponentType, FC } from 'react';
|
|
|
11
11
|
import { BlankComponent } from '../components';
|
|
12
12
|
|
|
13
13
|
export * from './appVersionHTML';
|
|
14
|
+
export * from './getRouteRuntimeVersion';
|
|
14
15
|
|
|
15
16
|
export function normalizeContainer(container: Element | ShadowRoot | string): Element | null {
|
|
16
17
|
if (!container) {
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
export function stripMarkdownIframeTags(markdown: string) {
|
|
11
|
+
if (!markdown) {
|
|
12
|
+
return markdown;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let result = '';
|
|
16
|
+
let cursor = 0;
|
|
17
|
+
|
|
18
|
+
while (cursor < markdown.length) {
|
|
19
|
+
const iframeStart = markdown.slice(cursor).search(/<iframe\b/i);
|
|
20
|
+
if (iframeStart === -1) {
|
|
21
|
+
result += markdown.slice(cursor);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const start = cursor + iframeStart;
|
|
26
|
+
result += markdown.slice(cursor, start);
|
|
27
|
+
|
|
28
|
+
const openingEnd = findTagEnd(markdown, start);
|
|
29
|
+
if (openingEnd === -1) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const openingTag = markdown.slice(start, openingEnd + 1);
|
|
34
|
+
if (/\/\s*>$/.test(openingTag)) {
|
|
35
|
+
cursor = openingEnd + 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const closingStart = markdown.slice(openingEnd + 1).search(/<\/iframe\s*>/i);
|
|
40
|
+
if (closingStart === -1) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
cursor =
|
|
45
|
+
openingEnd + 1 + closingStart + markdown.slice(openingEnd + 1 + closingStart).match(/^<\/iframe\s*>/i)[0].length;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function stripMarkdownIframes(html: string) {
|
|
52
|
+
if (!html || typeof DOMParser === 'undefined') {
|
|
53
|
+
return html;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const doc = new DOMParser().parseFromString(html, 'text/html');
|
|
57
|
+
doc.querySelectorAll('iframe').forEach((iframe) => iframe.remove());
|
|
58
|
+
return doc.body.innerHTML;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function removeMarkdownIframes(container?: ParentNode | null) {
|
|
62
|
+
container?.querySelectorAll('iframe').forEach((iframe) => iframe.remove());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function findTagEnd(html: string, start: number) {
|
|
66
|
+
let quote: string | undefined;
|
|
67
|
+
|
|
68
|
+
for (let index = start; index < html.length; index += 1) {
|
|
69
|
+
const char = html[index];
|
|
70
|
+
if (quote) {
|
|
71
|
+
if (char === quote) {
|
|
72
|
+
quote = undefined;
|
|
73
|
+
}
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (char === '"' || char === "'") {
|
|
78
|
+
quote = char;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (char === '>') {
|
|
83
|
+
return index;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return -1;
|
|
88
|
+
}
|