@nocobase/client-v2 2.2.0-beta.8 → 2.2.0-beta.9
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/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 +2 -0
- package/es/index.mjs +212 -126
- package/es/utils/markdownSanitize.d.ts +11 -0
- package/lib/index.js +198 -112
- 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/authRedirect.ts +38 -0
- 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 +2 -0
- package/src/nocobase-buildin-plugin/index.tsx +7 -1
- 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
|
@@ -38,6 +38,7 @@ export * from './collection-manager/filter-operators';
|
|
|
38
38
|
export * from './collection-manager/interfaces';
|
|
39
39
|
export * from './collection-manager/template-fields';
|
|
40
40
|
export * from './data-source';
|
|
41
|
+
export * from './entry-actions';
|
|
41
42
|
export * from './flow';
|
|
42
43
|
export {
|
|
43
44
|
DEFAULT_DATA_SOURCE_KEY,
|
|
@@ -47,4 +48,5 @@ export {
|
|
|
47
48
|
NocoBaseDesktopRouteType,
|
|
48
49
|
} from './flow-compat';
|
|
49
50
|
export type { NocoBaseDesktopRoute } from './flow-compat';
|
|
51
|
+
export * from './utils/markdownSanitize';
|
|
50
52
|
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,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
|
+
}
|