feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
49
frontend/packages/arch/bot-monaco-editor/src/index.tsx
Normal file
49
frontend/packages/arch/bot-monaco-editor/src/index.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Suspense, lazy } from 'react';
|
||||
|
||||
import { type EditorProps, type DiffEditorProps } from '@monaco-editor/react';
|
||||
|
||||
import { loader } from './loader';
|
||||
|
||||
const LazyEditor = lazy(async () => {
|
||||
await loader.config();
|
||||
const { Editor } = await import('./monaco-editor');
|
||||
return {
|
||||
default: Editor,
|
||||
};
|
||||
});
|
||||
const LazyDiffEditor = lazy(async () => {
|
||||
await loader.config();
|
||||
const { DiffEditor } = await import('./monaco-editor');
|
||||
return {
|
||||
default: DiffEditor,
|
||||
};
|
||||
});
|
||||
|
||||
const FallbackComponent = <div>Loading Editor...</div>;
|
||||
export const Editor = (props: EditorProps) => (
|
||||
<Suspense fallback={FallbackComponent}>
|
||||
<LazyEditor {...props} />
|
||||
</Suspense>
|
||||
);
|
||||
|
||||
export const DiffEditor = (props: DiffEditorProps) => (
|
||||
<Suspense fallback={FallbackComponent}>
|
||||
<LazyDiffEditor {...props} />
|
||||
</Suspense>
|
||||
);
|
||||
33
frontend/packages/arch/bot-monaco-editor/src/loader.ts
Normal file
33
frontend/packages/arch/bot-monaco-editor/src/loader.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const loader = {
|
||||
async init(): Promise<any> {
|
||||
const load = await this.config();
|
||||
return load.init();
|
||||
},
|
||||
|
||||
async config(config = {}): Promise<any> {
|
||||
const monaco = await import('monaco-editor');
|
||||
const { loader: load } = await import('@monaco-editor/react');
|
||||
load.config({
|
||||
monaco,
|
||||
...config,
|
||||
});
|
||||
return load;
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Editor, { DiffEditor } from '@monaco-editor/react';
|
||||
|
||||
export { Editor, DiffEditor };
|
||||
25
frontend/packages/arch/bot-monaco-editor/src/types.ts
Normal file
25
frontend/packages/arch/bot-monaco-editor/src/types.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export type { IRange, editor } from 'monaco-editor';
|
||||
|
||||
export type { Monaco, OnMount } from '@monaco-editor/react';
|
||||
|
||||
export type MonacoEditor =
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
typeof import('monaco-editor/esm/vs/editor/editor.api');
|
||||
|
||||
export { type EditorProps, type DiffEditorProps } from '@monaco-editor/react';
|
||||
17
frontend/packages/arch/bot-monaco-editor/src/typings.d.ts
vendored
Normal file
17
frontend/packages/arch/bot-monaco-editor/src/typings.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/// <reference types='@coze-arch/bot-typings' />
|
||||
Reference in New Issue
Block a user