feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View 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>
);

View 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;
},
};

View File

@@ -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 };

View 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';

View 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' />