Skip to content

Commit

Permalink
feat(vscodePlugin): support theme selected state (#965)
Browse files Browse the repository at this point in the history
chore(upgrade): `cherry-markdown` up ` v0.8.50`
  • Loading branch information
RSS1102 authored Nov 7, 2024
1 parent c2533e8 commit 468592a
Show file tree
Hide file tree
Showing 25 changed files with 686 additions and 403 deletions.
1 change: 0 additions & 1 deletion vscodePlugin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
out
/dist
node_modules
.vscode-test/

web-resources/scripts/global-vars.js

1 change: 0 additions & 1 deletion vscodePlugin/.vscodeignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
Expand Down
1 change: 0 additions & 1 deletion vscodePlugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
"mocha": "^8.4.0",
"ts-loader": "^9.2.2",
"typescript": "^4.3.2",
"vscode-test": "^1.5.2",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.0"
},
Expand Down
7 changes: 3 additions & 4 deletions vscodePlugin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"sourceMap": true,
"rootDir": "src",
"strict": true /* enable all strict type-checking options */
"strict": true /* enable all strict type-checking options */
/* Additional Checks */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
Expand All @@ -19,7 +19,6 @@
"src/**/*.ts"
],
"exclude": [
"node_modules",
".vscode-test"
"node_modules"
]
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vscodePlugin/web-resources/dist/cherry-markdown.core.js

Large diffs are not rendered by default.

153 changes: 93 additions & 60 deletions vscodePlugin/web-resources/dist/cherry-markdown.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vscodePlugin/web-resources/dist/cherry-markdown.esm.js

Large diffs are not rendered by default.

667 changes: 483 additions & 184 deletions vscodePlugin/web-resources/dist/cherry-markdown.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vscodePlugin/web-resources/dist/cherry-markdown.js.map

Large diffs are not rendered by default.

143 changes: 84 additions & 59 deletions vscodePlugin/web-resources/dist/cherry-markdown.markdown.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vscodePlugin/web-resources/dist/cherry-markdown.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vscodePlugin/web-resources/dist/cherry-markdown.min.js

Large diffs are not rendered by default.

Binary file modified vscodePlugin/web-resources/dist/fonts/ch-icon.eot
Binary file not shown.
Binary file modified vscodePlugin/web-resources/dist/fonts/ch-icon.ttf
Binary file not shown.
Binary file modified vscodePlugin/web-resources/dist/fonts/ch-icon.woff
Binary file not shown.
Binary file modified vscodePlugin/web-resources/dist/fonts/ch-icon.woff2
Binary file not shown.
90 changes: 10 additions & 80 deletions vscodePlugin/web-resources/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,81 +56,6 @@ const customMenuFont = Cherry.createMenuHook('字体样式', {
// ],
// });

// eslint-disable-next-line no-undef
const customMenuChangeTheme = Cherry.createMenuHook('主题', {
iconName: 'insertChart',
onClick: (selection, type) => {
changeTheme(type);
vscode.postMessage({
type: 'change-theme',
data: type,
});
},
subMenuConfig: [
{
noIcon: true,
name: '默认·default',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'default');
},
},
{
noIcon: true,
name: '暗黑·dark',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'dark');
},
},
{
noIcon: true,
name: '明亮·light',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'light');
},
},
{
noIcon: true,
name: '清新·green',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'green');
},
},
{
noIcon: true,
name: '热情·red',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'red');
},
},
{
noIcon: true,
name: '淡雅·violet',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'violet');
},
},
{
noIcon: true,
name: '清幽·blue',
onclick: () => {
cherry.toolbar.menus.hooks.customMenuChangeTheme.fire(null, 'blue');
},
},
],
});

function changeTheme(theme) {
const cherryDom = cherry.wrapperDom;
const cherryPreviewDom = cherry.previewer.getDom();
cherryDom.className = `${cherryDom.className.replace(
/ theme__[\S]+$/,
'',
)} theme__${theme}`;
cherryPreviewDom.className = `${cherryPreviewDom.className.replace(
/ theme__[\S]+$/,
'',
)} theme__${theme}`;
}

/** 处理 a 链接跳转问题 */
const onClickLink = (target) => {
Expand Down Expand Up @@ -258,12 +183,11 @@ const basicConfig = {
'customMenuChangeModule',
'mobilePreview',
'copy',
'customMenuChangeTheme',
'theme',
],
customMenu: {
customMenuChangeModule,
customMenuFont,
customMenuChangeTheme,
},
toc: true,
},
Expand Down Expand Up @@ -299,6 +223,15 @@ const basicConfig = {
window.uploadFileCallback = callback;
},
},
event: {
// 当编辑区内容有实际变化时触发
changeMainTheme: (theme) => {
vscode.postMessage({
type: 'change-theme',
data: theme,
});
},
},
previewer: {
// 自定义markdown预览区域class
// className: 'markdown'
Expand Down Expand Up @@ -349,14 +282,12 @@ function isHttpUrl(url) {

const mdInfo = JSON.parse(document.getElementById('markdown-info').value);
const config = Object.assign({}, basicConfig, { value: mdInfo.text });
const { theme } = mdInfo;
// eslint-disable-next-line new-cap, no-undef
const cherry = new Cherry(config);
// eslint-disable-next-line no-undef
const vscode = acquireVsCodeApi();
// 图片缓存
// const imgCache = {};
changeTheme(theme);

// function afterInit() {
// setTimeout(() => {
Expand Down Expand Up @@ -475,7 +406,6 @@ window.addEventListener('message', (e) => {
case 'editor-change':
window.disableEditListener = true;
cherry.setValue(data.text);
changeTheme(data.theme);
editTimeOut && clearTimeout(editTimeOut);
editTimeOut = setTimeout(() => {
window.disableEditListener = false;
Expand Down

0 comments on commit 468592a

Please sign in to comment.