Skip to content

Commit

Permalink
fix(MonacoEditor): SSR failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Jul 29, 2024
1 parent 6af870a commit f3d36b9
Show file tree
Hide file tree
Showing 13 changed files with 1,102 additions and 247 deletions.
5 changes: 2 additions & 3 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ const themeConfig = {
sidebarGroupModePath: ['/components'],
nav: [
{ link: '/components/chat-input-area', title: 'Components' },
{ link: '/changelog', title: 'Changelog' },
{ link: 'https://ui.lobehub.com/', title: 'LobeHub UI' },
{ link: 'https://ant.design/components/overview', title: 'Antd Components' },
// { link: '/colors', title: 'Colors' },
{ link: 'https://lucide.dev/icons', title: 'Lucide Icons' },
{ link: 'https://ant-design.github.io/antd-style', title: 'CSSinJS' },
{ link: '/changelog', title: 'Changelog' },
],
socialLinks: {
// discord: 'https://discord.gg/AYFPHvv2jT',
Expand Down Expand Up @@ -113,7 +113,6 @@ export default defineConfig({
}`,
],
themeConfig,
title: 'Yunti UI',
exportStatic: {
// 忽略预渲染失败的错误
ignorePreRenderError: true,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ test-output
.umi-production
.umi-test
.dumi/tmp*
server

# husky
.husky/prepare-commit-msg
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dev:father": "father dev",
"docs:build": "dumi build",
"docs:build-analyze": "ANALYZE=1 dumi build",
"docs:build-nc": "COMPRESS=none dumi build",
"docs:dev": "dumi dev",
"docs:preview": "dumi preview --port 9000",
"doctor": "father doctor",
Expand Down Expand Up @@ -85,8 +86,9 @@
"@lexical/selection": "^0.16.1",
"@lexical/text": "^0.16.1",
"@lexical/utils": "^0.16.1",
"@lobehub/ui": "^1.146.4",
"@lobehub/ui": "^1.147.0",
"@melloware/react-logviewer": "^5.1.1",
"@monaco-editor/loader": "^1.4.0",
"@shikijs/transformers": "^1.10.3",
"leva": "^0",
"lexical": "^0.16.1",
Expand All @@ -108,8 +110,8 @@
"@types/react-dom": "^18",
"@vitest/coverage-v8": "latest",
"@yuntijs/lint": "^1.7.0",
"antd": "^5.19.0",
"antd-style": "^3.6.1",
"antd": "^5.19.3",
"antd-style": "^3.6.2",
"babel-plugin-antd-style": "latest",
"commitlint": "^18",
"dayjs": "^1.11.10",
Expand Down
353 changes: 171 additions & 182 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions src/MonacoEditor/base/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { isBrowser } from '@/utils/tools';

export interface EditorMeta {
singleton: boolean;
[key: string]: any;
}

export class Controller {
private methodMap: Record<string, (...args: any[]) => void>;
private meta: EditorMeta;

constructor() {
this.methodMap = {};
this.meta = { singleton: false };
}

registerMethod(name: string, fn: (...args: any[]) => void) {
this.methodMap[name] = fn;
}

call(name: string, ...args: any[]) {
return this.methodMap[name]?.(...args);
}

updateMeta(obj: Partial<EditorMeta>) {
Object.assign(this.meta, obj);
}

getMeta() {
return Object.freeze({ ...this.meta });
}
}

const CONFIGURE_KEY = '__base_monaco_editor_controller__';
const fakeWindow: any = isBrowser && window;

if (fakeWindow && !fakeWindow[CONFIGURE_KEY]) {
fakeWindow[CONFIGURE_KEY] = new Controller();
}

export const controller: Controller = fakeWindow[CONFIGURE_KEY];
Loading

0 comments on commit f3d36b9

Please sign in to comment.