Skip to content

Commit 1ad65cd

Browse files
committed
perf(core): 优化 Monaco 组件性能并添加卸载前清理逻辑
- 更新版本号至 0.0.7.1 - 引入 onBeforeUnmount 钩子,在组件卸载前销毁 Monaco 编辑器实例 - 优化部分代码格式,提高可读性
1 parent b4dc01c commit 1ad65cd

File tree

17 files changed

+106
-106
lines changed

17 files changed

+106
-106
lines changed

apps/docs/docusaurus.config.ts

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,155 @@
1-
import type * as Preset from '@docusaurus/preset-classic';
2-
import type { Config } from '@docusaurus/types';
3-
import { themes as prismThemes } from 'prism-react-renderer';
1+
import type * as Preset from "@docusaurus/preset-classic";
2+
import type { Config } from "@docusaurus/types";
3+
import { themes as prismThemes } from "prism-react-renderer";
44

55
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
66

77
const config: Config = {
8-
title: 'Vue Shiki Monaco Editor',
9-
tagline: '基于 Monaco Editor + Shiki 的现代化 Vue 3 代码编辑器组件',
10-
favicon: 'img/favicon.ico',
8+
title: "Vue Shiki Monaco Editor",
9+
tagline: "基于 Monaco Editor + Shiki 的现代化 Vue 3 代码编辑器组件",
10+
favicon: "img/favicon.ico",
1111

1212
// Future flags, see https://docusaurus.io/docs/api/docusaurus-config#future
1313
future: {
1414
v4: true, // Improve compatibility with the upcoming Docusaurus v4
1515
},
1616

1717
// Set the production url of your site here
18-
url: 'https://lisentowind.github.io',
18+
url: "https://lisentowind.github.io",
1919
// Set the /<baseUrl>/ pathname under which your site is served
2020
// For GitHub pages deployment, it is often '/<projectName>/'
21-
baseUrl: '/vue-shiki-monaco/',
21+
baseUrl: "/vue-shiki-monaco/",
2222

2323
// GitHub pages deployment config.
2424
// If you aren't using GitHub pages, you don't need these.
25-
organizationName: 'lisentowind', // Usually your GitHub org/user name.
26-
projectName: 'vue-shiki-monaco', // Usually your repo name.
25+
organizationName: "lisentowind", // Usually your GitHub org/user name.
26+
projectName: "vue-shiki-monaco", // Usually your repo name.
2727

28-
onBrokenLinks: 'throw',
29-
onBrokenMarkdownLinks: 'warn',
28+
onBrokenLinks: "throw",
29+
onBrokenMarkdownLinks: "warn",
3030

3131
// Even if you don't use internationalization, you can use this field to set
3232
// useful metadata like html lang. For example, if your site is Chinese, you
3333
// may want to replace "en" with "zh-Hans".
3434
i18n: {
35-
defaultLocale: 'zh-Hans',
36-
locales: ['zh-Hans', 'en'],
35+
defaultLocale: "zh-Hans",
36+
locales: ["zh-Hans", "en"],
3737
localeConfigs: {
38-
'zh-Hans': {
39-
label: '简体中文',
40-
direction: 'ltr',
41-
htmlLang: 'zh-CN',
38+
"zh-Hans": {
39+
label: "简体中文",
40+
direction: "ltr",
41+
htmlLang: "zh-CN",
4242
},
43-
'en': {
44-
label: 'English',
45-
direction: 'ltr',
46-
htmlLang: 'en-US',
43+
en: {
44+
label: "English",
45+
direction: "ltr",
46+
htmlLang: "en-US",
4747
},
4848
},
4949
},
5050

5151
presets: [
5252
[
53-
'classic',
53+
"classic",
5454
{
5555
docs: {
56-
sidebarPath: './sidebars.ts',
57-
editUrl: 'https://github.com/lisentowind/vue-shiki-monaco/edit/main/apps/docs/',
58-
routeBasePath: 'docs',
56+
sidebarPath: "./sidebars.ts",
57+
editUrl:
58+
"https://github.com/lisentowind/vue-shiki-monaco/edit/main/apps/docs/",
59+
routeBasePath: "docs",
5960
},
6061
blog: {
6162
showReadingTime: true,
6263
feedOptions: {
63-
type: ['rss', 'atom'],
64+
type: ["rss", "atom"],
6465
xslt: true,
6566
},
6667
// Please change this to your repo.
6768
// Remove this to remove the "edit this page" links.
6869
editUrl:
69-
'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
70+
"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/",
7071
// Useful options to enforce blogging best practices
71-
onInlineTags: 'warn',
72-
onInlineAuthors: 'warn',
73-
onUntruncatedBlogPosts: 'warn',
72+
onInlineTags: "warn",
73+
onInlineAuthors: "warn",
74+
onUntruncatedBlogPosts: "warn",
7475
},
7576
theme: {
76-
customCss: './src/css/custom.css',
77+
customCss: "./src/css/custom.css",
7778
},
7879
} satisfies Preset.Options,
7980
],
8081
],
8182

8283
themeConfig: {
8384
// Replace with your project's social card
84-
image: 'img/docusaurus-social-card.jpg',
85+
image: "img/docusaurus-social-card.jpg",
8586
navbar: {
86-
title: 'Vue Shiki Monaco Editor ',
87+
title: "Vue Shiki Monaco Editor ",
8788
logo: {
88-
alt: 'Vue Shiki Monaco Editor Logo',
89-
src: 'img/logo.svg',
89+
alt: "Vue Shiki Monaco Editor Logo",
90+
src: "img/logo.png",
9091
},
9192
items: [
9293
{
93-
type: 'docSidebar',
94-
sidebarId: 'tutorialSidebar',
95-
position: 'left',
96-
label: '文档',
94+
type: "docSidebar",
95+
sidebarId: "tutorialSidebar",
96+
position: "left",
97+
label: "文档",
9798
},
9899
{
99-
type: 'localeDropdown',
100-
position: 'right',
100+
type: "localeDropdown",
101+
position: "right",
101102
},
102103
{
103-
href: 'https://github.com/lisentowind/vue-shiki-monaco',
104-
label: 'GitHub',
105-
position: 'right',
104+
href: "https://github.com/lisentowind/vue-shiki-monaco",
105+
label: "GitHub",
106+
position: "right",
106107
},
107108
],
108109
},
109110
footer: {
110-
style: 'dark',
111+
style: "dark",
111112
links: [
112113
{
113-
title: '文档',
114+
title: "文档",
114115
items: [
115116
{
116-
label: '快速开始',
117-
to: '/docs/getting-started',
117+
label: "快速开始",
118+
to: "/docs/getting-started",
118119
},
119120
{
120-
label: 'API 参考',
121-
to: '/docs/api',
121+
label: "API 参考",
122+
to: "/docs/api",
122123
},
123124
{
124-
label: '使用示例',
125-
to: '/docs/examples',
125+
label: "使用示例",
126+
to: "/docs/examples",
126127
},
127128
],
128129
},
129130
{
130-
title: '社区',
131+
title: "社区",
131132
items: [
132133
{
133-
label: 'GitHub Issues',
134-
href: 'https://github.com/lisentowind/vue-shiki-monaco/issues',
134+
label: "GitHub Issues",
135+
href: "https://github.com/lisentowind/vue-shiki-monaco/issues",
135136
},
136137
{
137-
label: 'GitHub Discussions',
138-
href: 'https://github.com/lisentowind/vue-shiki-monaco/discussions',
138+
label: "GitHub Discussions",
139+
href: "https://github.com/lisentowind/vue-shiki-monaco/discussions",
139140
},
140141
],
141142
},
142143
{
143-
title: '更多',
144+
title: "更多",
144145
items: [
145146
{
146-
label: 'GitHub',
147-
href: 'https://github.com/lisentowind/vue-shiki-monaco',
147+
label: "GitHub",
148+
href: "https://github.com/lisentowind/vue-shiki-monaco",
148149
},
149150
{
150-
label: 'NPM',
151-
href: 'https://www.npmjs.com/package/vue-shiki-monaco',
151+
label: "NPM",
152+
href: "https://www.npmjs.com/package/vue-shiki-monaco",
152153
},
153154
],
154155
},

apps/docs/static/img/favicon.ico

4.57 KB
Binary file not shown.

apps/docs/static/img/logo.png

807 KB
Loading

packages/core/.storybook/manager.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import type { State } from '@storybook/manager-api';
2-
import { addons } from '@storybook/manager-api';
3-
import { create } from '@storybook/theming';
1+
import type { State } from "@storybook/manager-api";
2+
import { addons } from "@storybook/manager-api";
3+
import { create } from "@storybook/theming";
44

55
const theme = create({
6-
base: 'light',
7-
brandTitle: 'vue-shiki-monaco',
8-
brandImage: '/logo.svg',
6+
base: "light",
7+
brandTitle: "vue-shiki-monaco",
8+
brandImage: "/logo.png",
99
});
1010

1111
const darkTheme = create({
12-
base: 'dark',
13-
brandTitle: 'vue-shiki-monaco',
14-
brandImage: '/logo.svg',
12+
base: "dark",
13+
brandTitle: "vue-shiki-monaco",
1514
});
1615

1716
addons.setConfig({
@@ -25,15 +24,15 @@ addons.setConfig({
2524
// 右侧面板宽度(像素)
2625
rightPanelWidth: 520,
2726
// 控制面板位置:'bottom' 或 'right'
28-
panelPosition: 'right',
27+
panelPosition: "right",
2928
// 是否启用快捷键
3029
enableShortcuts: false,
3130
// 是否显示顶部工具栏
3231
showToolbar: true,
3332
// 初始选中的面板(undefined 表示不强制选中)
3433
selectedPanel: undefined,
3534
// 初始激活的界面元素:'sidebar' 或 'panel'
36-
initialActive: 'sidebar',
35+
initialActive: "sidebar",
3736

3837
// 自定义布局逻辑
3938
layoutCustomisations: {
@@ -42,13 +41,13 @@ addons.setConfig({
4241
// defaultValue: 默认显示状态
4342
showSidebar(state: State, defaultValue: boolean) {
4443
// 当故事ID为'landing'时隐藏侧边栏,其他情况使用默认设置
45-
return state.storyId === 'landing' ? false : defaultValue;
44+
return state.storyId === "landing" ? false : defaultValue;
4645
},
4746

4847
// 根据视图模式动态显示/隐藏工具栏
4948
showToolbar(state: State, defaultValue: boolean) {
5049
// 当视图模式为'docs'时隐藏工具栏,其他情况使用默认设置
51-
return state.viewMode === 'docs' ? false : defaultValue;
50+
return state.viewMode === "docs" ? false : defaultValue;
5251
},
5352
},
5453

@@ -57,7 +56,7 @@ addons.setConfig({
5756
// 是否显示根目录节点
5857
showRoots: false,
5958
// 默认折叠的根目录(数组中的名称对应故事分类)
60-
collapsedRoots: ['other'],
59+
collapsedRoots: ["other"],
6160
},
6261

6362
// 顶部工具栏配置

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-shiki-monaco",
3-
"version": "0.0.7",
3+
"version": "0.0.7.1",
44
"description": "一个封shiki和monaco-editor的Vue组件",
55
"homepage": "https://lisentowind.github.io/vue-shiki-monaco/",
66
"repository": {

packages/core/src/components/Monaco/index.vue

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { ref, onMounted, onUnmounted, watch } from "vue";
2+
import { ref, onMounted, onUnmounted, watch, onBeforeUnmount } from "vue";
33
import type { EditInstance } from "../../hooks/useMonacoEdit";
44
import { useMonacoEdit } from "../../hooks/useMonacoEdit";
55
import type { BundledLanguage, BundledTheme } from "shiki";
@@ -30,13 +30,13 @@ interface Props {
3030
enabled?: boolean;
3131
items?: string[] | "minimal" | "basic" | "full";
3232
customItems?: ContextMenuItem[];
33-
variant?: 'classic' | 'glass';
33+
variant?: "classic" | "glass";
3434
};
3535
minimapContextMenu?: {
3636
enabled?: boolean;
3737
items?: string[] | "minimal" | "basic" | "full";
3838
customItems?: ContextMenuItem[];
39-
variant?: 'classic' | 'glass';
39+
variant?: "classic" | "glass";
4040
};
4141
}
4242
@@ -297,7 +297,9 @@ const setupContextMenu = () => {
297297
// 尝试预先请求剪贴板权限(可选)
298298
try {
299299
if ("permissions" in navigator) {
300-
await (navigator as any).permissions.query({ name: "clipboard-read" });
300+
await (navigator as any).permissions.query({
301+
name: "clipboard-read",
302+
});
301303
}
302304
} catch (error) {
303305
// 忽略权限检查错误
@@ -312,7 +314,9 @@ const setupContextMenu = () => {
312314
// 获取minimap菜单项配置
313315
let minimapEnabledItems: string[] = [];
314316
if (typeof props.minimapContextMenu?.items === "string") {
315-
minimapEnabledItems = MINIMAP_MENU_PRESETS[props.minimapContextMenu.items] as any;
317+
minimapEnabledItems = MINIMAP_MENU_PRESETS[
318+
props.minimapContextMenu.items
319+
] as any;
316320
} else if (Array.isArray(props.minimapContextMenu?.items)) {
317321
minimapEnabledItems = props.minimapContextMenu.items;
318322
}
@@ -354,6 +358,10 @@ const handleMinimapContextMenuItemClick = (item: ContextMenuItem) => {
354358
}
355359
};
356360
361+
onBeforeUnmount(() => {
362+
monacoEditHook?.destroy();
363+
});
364+
357365
// 暴露方法给父组件
358366
defineExpose({
359367
getEditor: () => editorInstance,
3.92 KB
Binary file not shown.
807 KB
Loading

packages/core/storybook-public/logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/core/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)