Skip to content

Commit

Permalink
feat: import worker with url
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Apr 12, 2024
1 parent caa79d1 commit eb026ef
Show file tree
Hide file tree
Showing 10 changed files with 391 additions and 50 deletions.
13 changes: 0 additions & 13 deletions web/components/chat/OBEditor/ob-plugin.ts

This file was deleted.

2 changes: 1 addition & 1 deletion web/components/chat/completion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useRef, useEffect, useMemo, useContext } from 'react';
import { useSearchParams } from 'next/navigation';
import MonacoEditor from './OBEditor/monaco-editor';
import MonacoEditor from './monaco-editor';
import ChatContent from './chat-content';
import ChatFeedback from './chat-feedback';
import { ChatContext } from '@/app/chat-context';
Expand Down
2 changes: 1 addition & 1 deletion web/components/chat/db-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Select, Table, Tooltip } from 'antd';
import { Input, Tree } from 'antd';
import Icon from '@ant-design/icons';
import type { DataNode } from 'antd/es/tree';
import MonacoEditor, { ISession } from './OBEditor/monaco-editor';
import MonacoEditor, { ISession } from './monaco-editor';
import { sendGetRequest, sendSpacePostRequest } from '@/utils/request';
import { useSearchParams } from 'next/navigation';
import { OnChange } from '@monaco-editor/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import Editor, { OnChange, loader } from '@monaco-editor/react';
import classNames from 'classnames';
import { useContext, useMemo } from 'react';
import { formatSql } from '@/utils';
import { getModelService } from './service';
import { getModelService } from './ob-editor/service';
import { useLatest } from 'ahooks';
import { ChatContext } from '@/app/chat-context';
import { github, githubDark } from './theme';
import { github, githubDark } from './ob-editor/theme';
import { register } from './ob-editor/ob-plugin';

loader.config({ monaco });

Expand Down Expand Up @@ -47,9 +48,7 @@ export default function MonacoEditor({ className, value, language = 'mysql', onC
const context = useContext(ChatContext);

async function pluginRegister(editor: monaco.editor.IStandaloneCodeEditor) {
console.log('register plugin');
const module = await import('./ob-plugin');
const plugin = module.register();
const plugin = await register()
plugin.setModelOptions(
editor.getModel()?.id || '',
getModelService({
Expand Down
31 changes: 31 additions & 0 deletions web/components/chat/ob-editor/ob-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import type Plugin from '@oceanbase-odc/monaco-plugin-ob';

let plugin: Plugin;

export async function register(): Promise<Plugin> {
window.obMonaco = {
getWorkerUrl: (type: string) => {
switch (type) {
case 'mysql': {
return location.origin + '/_next/static/ob-workers/mysql.js'
}
case 'obmysql': {
return location.origin + '/_next/static/ob-workers/obmysql.js'
}
case 'oboracle': {
return location.origin + '/_next/static/ob-workers/oracle.js'
}
}
return "";
}
}
const module = await import('@oceanbase-odc/monaco-plugin-ob')
const Plugin = module.default;
if (plugin) {
return plugin;
}
plugin = new Plugin();
plugin.setup(["mysql"]);
return plugin;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IModelOptions } from '@oceanbase-odc/monaco-plugin-ob/dist/type';
import { ISession } from './monaco-editor';
import { ISession } from '../monaco-editor';


export function getModelService(
Expand All @@ -9,7 +9,6 @@ export function getModelService(
return {
delimiter,
async getTableList(schemaName?: string) {
console.log('getTableList')
return session?.()?.getTableList(schemaName) || []
},
async getTableColumns(tableName: string, dbName?: string) {
Expand Down
File renamed without changes.
14 changes: 12 additions & 2 deletions web/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @type {import('next').NextConfig} */
const CopyPlugin = require('copy-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require('path');
const nextConfig = {
output: 'export',
experimental: {
Expand All @@ -13,11 +15,19 @@ const nextConfig = {
},
trailingSlash: true,
images: { unoptimized: true },
webpack5: true,
webpack: (config, { isServer }) => {
config.resolve.fallback = { fs: false };
if (!isServer) {

config.plugins.push(
new CopyPlugin({
patterns: [
{
from: path.join(__dirname, 'node_modules/@oceanbase-odc/monaco-plugin-ob/worker-dist/'),
to: 'static/ob-workers'
},
],
})
)
// 添加 monaco-editor-webpack-plugin 插件
config.plugins.push(
new MonacoWebpackPlugin({
Expand Down
Loading

0 comments on commit eb026ef

Please sign in to comment.