Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Sep 3, 2024
2 parents 7f398cd + 30c6fd7 commit a58fbfd
Show file tree
Hide file tree
Showing 39 changed files with 956 additions and 315 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/pr-reviewer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,26 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = ${{ github.event.pull_request.number }};
const baseUrl = `https://cherrymd.com/pr${prNumber}/examples`;
const response = await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
### 【预览链接】
- https://cherrymd.com/pr${{ github.event.pull_request.number }}/examples/index.html
- [full model](${baseUrl}/index.html)
- [basic](${baseUrl}/basic.html)
- [mobile](${baseUrl}/h5.html)
- [multiple instances](${baseUrl}/multiple.html)
- [editor without toolbar](${baseUrl}/notoolbar.html)
- [pure preview](${baseUrl}/preview_only.html)
- [XSS](${baseUrl}/xss.html)(Not allowed by default)
- [img wysiwyg](${baseUrl}/img.html)
- [table wysiwyg](${baseUrl}/table.html)
- [headers with auto num](${baseUrl}/head_num.html)
- [流式输入模式(AI chart场景)](${baseUrl}/ai_chat.html)
- [VIM 编辑模式](${baseUrl}/vim.html)
`
});
});
1 change: 1 addition & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
if: ${{ env.GIT_DIFF_FILES }}
run: |
for file in ${{ env.GIT_DIFF_FILES }}; do
mkdir -p "base-repo/$(dirname "$file")"
cp "$file" "base-repo/$file"
done
Expand Down
18 changes: 8 additions & 10 deletions client/electron/preload/menu/category/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ ipcMain.on('save-file-as-info', async (event, arg: { data: string }) => {
if (filePath) {
fs.writeFile(filePath, arg.data, (err) => {
if (err) {
event.reply('save-file-as-reply', { status: -1, message: err.message, filePath: '' })
event.reply('save-file-as-reply', { status: -1, message: err.message, filePath: '', isSaved: false })
} else {
event.reply('save-file-as-reply', { status: 0, message: 'save file as success', filePath: filePath })
const menu = Menu.getApplicationMenu();
const saveFileBtn = menu.getMenuItemById('save-file');
saveFileBtn.enabled = false
saveFileBtn.enabled = false;
event.reply('save-file-as-reply', { status: 0, message: 'save file as success', filePath: filePath, isSaved: true })
}
});
} else {
event.reply('save-file-as-reply', { status: -2, message: 'save file as canceled', filePath: '' })
event.reply('save-file-as-reply', { status: -2, message: 'save file as canceled', filePath: '', isSaved: false })
}

})
Expand All @@ -114,17 +114,15 @@ ipcMain.on('sava-file-type', (event, arg: { filePath: string, data: string }) =>
if (arg.filePath) {
fs.writeFile(arg.filePath, arg.data, (err) => {
if (err) {
console.error('err', err);
event.reply('save-file-reply', { status: -1, message: err.message, });
event.reply('save-file-reply', { status: -1, message: err.message, isSaved: false });
} else {
console.error('success');
event.reply('save-file-reply', { status: 0, message: 'save file as success' });
const menu = Menu.getApplicationMenu();
const saveFileBtn = menu.getMenuItemById('save-file');
saveFileBtn.enabled = false
saveFileBtn.enabled = false;
event.reply('save-file-reply', { status: 0, message: 'save file as success', isSaved: true });
}
});
} else {
saveFileAs()
saveFileAs();
}
})
6 changes: 5 additions & 1 deletion client/electron/preload/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,25 @@ const menuConfig: Array<MenuItemConstructorOptions | MenuItem> = [
{
id: "new-file",
label: '新建文件',
accelerator: isMac ? 'Cmd+N' : 'Ctrl+N',
click: () => newFile(),
},
{
id: "open-file",
label: '打开文件...',
accelerator: isMac ? 'Cmd+O' : 'Ctrl+O',
click: () => openFile(),
},
{
id: "save-file-as",
label: '另存为...',
accelerator: isMac ? 'Cmd+Shift+S' : 'Ctrl+Shift+S',
click: () => saveFileAs(),
},
{
id: "save-file",
label: '保存',
accelerator: isMac ? 'Cmd+S' : 'Ctrl+S',
click: () => saveFile(),
enabled: false
},
Expand Down Expand Up @@ -96,7 +100,7 @@ const menuConfig: Array<MenuItemConstructorOptions | MenuItem> = [
},
]
// isPackaged ? [] :
menuConfig.push({
menuConfig.push({
label: "打开DevTools",
role: 'toggleDevTools'
})
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/CherryMarkdown/cherry.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useStoreCherry } from "@/store/storeCherry";
import Cherry from "cherry-markdown";
import { CherryOptions } from "cherry-markdown/types/cherry";
import { ipcRenderer } from "electron";
import { onMounted } from "vue";
import { onMounted, shallowReactive } from "vue";

/**
*@description 初始化 CherryMarkdown
Expand Down Expand Up @@ -279,7 +279,7 @@ const initCherryMarkdown = () => {

onMounted(() => {
const cherryInstance = new Cherry(defaultConfig as Partial<CherryOptions>);
storeCherry.cherry = cherryInstance
storeCherry.cherry = shallowReactive(cherryInstance)
})
}

Expand Down
42 changes: 33 additions & 9 deletions client/src/components/CherryMarkdown/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,44 @@
</template>
<script setup lang="ts">
import { ipcRenderer } from "electron";
import { MessagePlugin as TMessagePlugin } from 'tdesign-vue-next';
import { MessagePlugin as TMessagePlugin, DialogPlugin as TDialogPlugin } from 'tdesign-vue-next';
import { useStoreElectronMenu } from "@/store/storeElectronMenu";
import { useStoreCherry } from "@/store/storeCherry";
import initCherryMarkdown from "./cherry.config";
import { h } from "vue";
const storeElectronMenu = useStoreElectronMenu()
const storeCherry = useStoreCherry()
const storeCherry = useStoreCherry();
initCherryMarkdown();
/**
* @description 新建文件
*/
ipcRenderer.on('new_file', () => {
storeCherry.cherry?.setMarkdown('')
storeElectronMenu.saveFilePath = ''
if (storeCherry.cherryMarkdown && !storeElectronMenu.isSaved) {
const confirmDia = TDialogPlugin.confirm({
header: '提示',
body: () => h('div', [
'确定要新建文件吗?',
h('span', { style: { color: 'red' } }, '还未保存的将丢失数据!')
]),
onConfirm: () => {
storeCherry.cherry?.setMarkdown('');
storeElectronMenu.saveFilePath = '';
confirmDia.hide();
},
onClose: () => {
confirmDia.hide();
},
onCancel: () => {
confirmDia.hide();
}
})
} else {
storeCherry.cherry?.setMarkdown('');
storeElectronMenu.saveFilePath = ''
}
})
/**
Expand All @@ -45,18 +67,19 @@ ipcRenderer.on('open_file', (_event, arg: { status: -2 | -1 | 0, message: string
ipcRenderer.on('save-file-as',
() => ipcRenderer.send('save-file-as-info', { data: storeCherry.cherry?.getMarkdown() }))
ipcRenderer.on('save-file-as-reply', (event, arg: { status: -2 | -1 | 0, message: string, filePath: string }) => {
ipcRenderer.on('save-file-as-reply', (event, arg: { status: -2 | -1 | 0, message: string, filePath: string, isSaved: boolean }) => {
switch (arg.status) {
case 0:
storeElectronMenu.saveFilePath = arg.filePath
storeElectronMenu.saveFilePath = arg.filePath;
break;
case -1:
TMessagePlugin.error(arg.message);
break;
case -2:
TMessagePlugin.warning(arg.message);
break;
}
};
storeElectronMenu.isSaved = arg.isSaved;
})
/**
Expand All @@ -66,10 +89,11 @@ ipcRenderer.on('save-file', () => {
ipcRenderer.send('sava-file-type', { filePath: storeElectronMenu.saveFilePath, data: storeCherry.cherry?.getMarkdown() })
})
ipcRenderer.on('save-file-reply', (event, arg: { status: -1 | 0, message: string }) => {
ipcRenderer.on('save-file-reply', (event, arg: { status: -1 | 0, message: string, isSaved: boolean }) => {
if (arg.status === -1) {
TMessagePlugin.error(arg.message);
}
};
storeElectronMenu.isSaved = arg.isSaved;
})
</script>
Expand Down
6 changes: 5 additions & 1 deletion client/src/store/storeElectronMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { defineStore } from 'pinia'
/**
*
* @param isTextChange - 文本是否被改变
* @param saveFilePath - 保存文件的路径
* @param isSaved - 文件是否被保存
*/
type ElectronMenuState = {
isTextChange: boolean;
saveFilePath: string
saveFilePath: string;
isSaved: boolean;
}

export const useStoreElectronMenu = defineStore('electron-menu', {
state: (): ElectronMenuState => ({
isTextChange: false,
saveFilePath: '',
isSaved: false
}),
})
30 changes: 30 additions & 0 deletions examples/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,36 @@ <h2 class="one-api__name">Previewer.scrollToId(id:string)</h2>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">setLocale(locale:string)</h2>
<p class="one-api__desc">修改语言<br>系统默认支持:zh_CN | en_US | ru_RU</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.setLocale('en_US');</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">setTheme(theme:string)</h2>
<p class="one-api__desc">修改主题</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.setTheme('dark');</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">setCodeBlockTheme(theme:string)</h2>
<p class="one-api__desc">修改代码块主题</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.setCodeBlockTheme('one-dark');</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<br>
<hr>

Expand Down
23 changes: 21 additions & 2 deletions examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ var customMenuA = Cherry.createMenuHook('加粗斜体', {
* 定义一个空壳,用于自行规划cherry已有工具栏的层级结构
*/
var customMenuB = Cherry.createMenuHook('实验室', {
iconName: '',
icon: {
type: 'svg',
content: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10" /><path d="M8 14s1.5 2 4 2 4-2 4-2" /><line x1="9" y1="9" x2="9.01" y2="9" /><line x1="15" y1="9" x2="15.01" y2="9" /></svg>',
iconStyle: 'width: 15px; height: 15px; vertical-align: middle;',
},
});
/**
* 定义一个自带二级菜单的工具栏
Expand Down Expand Up @@ -202,7 +206,7 @@ var basicConfig = {
'customMenuCName',
'theme',
],
toolbarRight: ['fullScreen', '|', 'wordCount'],
toolbarRight: ['fullScreen', '|', 'changeLocale', 'wordCount'],
bubble: ['bold', 'italic', 'underline', 'strikethrough', 'sub', 'sup', 'quote', 'ruby', '|', 'size', 'color'], // array or false
sidebar: ['mobilePreview', 'copy', 'theme', 'publish'],
sidebar: ['mobilePreview', 'copy', 'theme'],
Expand All @@ -216,6 +220,20 @@ var basicConfig = {
customMenuCName: customMenuC,
customMenuTable,
},
shortcutKeySettings: {
/** 是否替换已有的快捷键, true: 替换默认快捷键; false: 会追加到默认快捷键里,相同的shortcutKey会覆盖默认的 */
isReplace: false,
shortcutKeyMap: {
'Alt-Digit1': {
hookName: 'header',
aliasName: '标题',
},
'Control-Shift-KeyX': {
hookName: 'bold',
aliasName: '加粗',
},
},
},
// config: {
// publish: [
// {
Expand All @@ -235,6 +253,7 @@ var basicConfig = {
previewer: {
// 自定义markdown预览区域class
// className: 'markdown'
floatWhenClosePreviewer: true,
},
keydown: [],
//extensions: [],
Expand Down
Loading

0 comments on commit a58fbfd

Please sign in to comment.