From 9942713de7ac9115347c8008f82e387225f066d6 Mon Sep 17 00:00:00 2001 From: purocean Date: Thu, 25 Feb 2021 11:13:43 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Preview.vue | 84 ++------------- frontend/src/plugins/TransformImgOutLink.ts | 108 ++++++++++++++++++++ frontend/src/useful/plugin.ts | 58 +++++++++++ frontend/src/useful/shortcut.ts | 42 +++++--- 4 files changed, 199 insertions(+), 93 deletions(-) create mode 100644 frontend/src/plugins/TransformImgOutLink.ts create mode 100644 frontend/src/useful/plugin.ts diff --git a/frontend/src/components/Preview.vue b/frontend/src/components/Preview.vue index fc019311..a0c4516e 100644 --- a/frontend/src/components/Preview.vue +++ b/frontend/src/components/Preview.vue @@ -41,7 +41,6 @@ import loadsh from 'lodash' import { useStore } from 'vuex' import { computed, defineComponent, nextTick, onBeforeUnmount, onMounted, ref, toRefs, watch } from 'vue' -import mime from 'mime-types' import Markdown from 'markdown-it' import TaskLists from 'markdown-it-task-lists' import katex from 'markdown-it-katex' @@ -65,13 +64,13 @@ import MindMapPlugin from '../plugins/MindMapPlugin' import file from '../useful/file' import env from '../useful/env' import { encodeMarkdownLink } from '../useful/utils' +import { triggerHook } from '../useful/plugin' import 'github-markdown-css/github-markdown.css' import 'highlight.js/styles/atom-one-dark.css' import 'katex/dist/katex.min.css' import { useBus } from '../useful/bus' -import { useToast } from '../useful/toast' -import { hasCtrlCmd, isAction } from '../useful/shortcut' +import { hasCtrlCmd } from '../useful/shortcut' HighlightLineNumber.addStyles() @@ -111,7 +110,6 @@ export default defineComponent({ setup (_, { emit }) { const bus = useBus() const store = useStore() - const toast = useToast() const { currentContent, currentFile, autoPreview } = toRefs(store.state) const fileRepo = computed(() => currentFile.value?.repo) @@ -273,63 +271,9 @@ export default defineComponent({ nextTick(() => bus.emit('preview-rendered')) }, 500, { leading: true }) - async function transformImgOutLink (img: HTMLImageElement) { - const transform = (ximg: HTMLImageElement): Promise => { - const canvas = document.createElement('canvas') - canvas.width = ximg.naturalWidth - canvas.height = ximg.naturalHeight - canvas.getContext('2d')!!.drawImage(ximg, 0, 0) - return new Promise((resolve, reject) => { - canvas.toBlob(async blob => { - try { - const imgFile = new File([blob!!], 'file.png') - const { relativePath } = await file.upload(fileRepo.value, filePath.value, imgFile) - resolve(relativePath) - } catch (error) { - reject(error) - } - }) - }) - } - - let replacedLink = '' - const imgAttrSrc = img.getAttribute('src') || '' - if (img.src.startsWith('data:')) { - replacedLink = await transform(img) - } else if (imgAttrSrc.startsWith('http://') || imgAttrSrc.startsWith('https://')) { - const res = await window.fetch(`api/proxy?url=${encodeURIComponent(img.src)}&headers=${img.getAttribute('headers') || ''}`) - const blob = await res.blob() - const imgFile = new File([blob!!], 'file.' + mime.extension(res.headers.get('content-type')!!)) - const { relativePath } = await file.upload(fileRepo.value, filePath.value, imgFile) - replacedLink = relativePath - } - - if (replacedLink) { - return { oldLink: img.src, replacedLink: encodeMarkdownLink(replacedLink) } - } - - return null - } - async function keydownHandler (e: KeyboardEvent) { - // 转换所有外链图片到本地 - if (isAction(e, 'transform-img-link')) { - e.preventDefault() - e.stopPropagation() - const result = [] - const imgList = refView.value!!.querySelectorAll('img') - for (let i = 0; i < imgList.length; i++) { - toast.show('info', `正在转换外链图片 ${i + 1}/${imgList.length}`) - - const img = imgList[i] - const data = await transformImgOutLink(img) - if (data) { - result.push(data) - } - } - result.forEach(data => bus.emit('editor-replace-value', { search: data.oldLink, replace: data.replacedLink })) - bus.emit('tree-refresh') - } + const getRefview = () => refView.value + triggerHook('ON_VIEW_KEY_DOWN', e, getRefview()) } function handleScroll (e: any) { @@ -350,6 +294,8 @@ export default defineComponent({ } async function handleClick (e: MouseEvent) { + triggerHook('ON_VIEW_ELEMENT_CLICK', e) + const target = e.target as HTMLElement const preventEvent = () => { @@ -432,24 +378,6 @@ export default defineComponent({ bus.emit('copy-text', target.innerText) } - if (target.tagName === 'IMG') { - const img = target as HTMLImageElement - if (isAction(e, 'transform-img-link-by-click')) { // 转换外链图片到本地 - const data = await transformImgOutLink(img) - if (data) { - bus.emit('tree-refresh') - bus.emit('editor-replace-value', { search: data.oldLink, replace: data.replacedLink }) - } - } else if (img.parentElement!!.tagName === 'A') { - handleLink(img.parentElement as HTMLAnchorElement) - } else { - env.openAlwaysOnTopWindow(img.src) - } - - e.stopPropagation() - return - } - if (target.tagName === 'INPUT' && target.parentElement!!.classList.contains('source-line')) { switchTodo(parseInt(target.parentElement!!.dataset.sourceLine || '0'), (target as HTMLInputElement).checked) e.preventDefault() diff --git a/frontend/src/plugins/TransformImgOutLink.ts b/frontend/src/plugins/TransformImgOutLink.ts new file mode 100644 index 00000000..364d20a7 --- /dev/null +++ b/frontend/src/plugins/TransformImgOutLink.ts @@ -0,0 +1,108 @@ +import mime from 'mime-types' +import file from '@/useful/file' +import { Plugin, Ctx } from '@/useful/plugin' +import { CtrlCmd, isAction, LeftClick, Shift } from '@/useful/shortcut' +import { encodeMarkdownLink } from '@/useful/utils' +import { useBus } from '@/useful/bus' +import env from '@/useful/env' +import { useToast } from '@/useful/toast' +import store from '@/store' + +async function transformImgOutLink (img: HTMLImageElement) { + const { currentFile } = store.state + const { repo, path } = currentFile + + const transform = (ximg: HTMLImageElement): Promise => { + const canvas = document.createElement('canvas') + canvas.width = ximg.naturalWidth + canvas.height = ximg.naturalHeight + canvas.getContext('2d')!!.drawImage(ximg, 0, 0) + return new Promise((resolve, reject) => { + canvas.toBlob(async blob => { + try { + const imgFile = new File([blob!!], 'file.png') + const { relativePath } = await file.upload(repo, path, imgFile) + resolve(relativePath) + } catch (error) { + reject(error) + } + }) + }) + } + + let replacedLink = '' + const imgAttrSrc = img.getAttribute('src') || '' + if (img.src.startsWith('data:')) { + replacedLink = await transform(img) + } else if (imgAttrSrc.startsWith('http://') || imgAttrSrc.startsWith('https://')) { + const res = await window.fetch(`api/proxy?url=${encodeURIComponent(img.src)}&headers=${img.getAttribute('headers') || ''}`) + const blob = await res.blob() + const imgFile = new File([blob!!], 'file.' + mime.extension(res.headers.get('content-type')!!)) + const { relativePath } = await file.upload(repo, path, imgFile) + replacedLink = relativePath + } + + if (replacedLink) { + return { oldLink: img.src, replacedLink: encodeMarkdownLink(replacedLink) } + } + + return null +} + +const actionKeydown = 'transform-img-link' +const actionClick = 'transform-img-link-by-click' + +export const plugin = { + name: 'transform-img-out-link', + register: (ctx: Ctx) => { + ctx.registerShortcutAction(actionKeydown, [CtrlCmd, Shift, 'l']) + ctx.registerShortcutAction(actionClick, [CtrlCmd, Shift, LeftClick]) + + ctx.registerHook('ON_VIEW_KEY_DOWN', async (e: KeyboardEvent, refView: HTMLElement) => { + const toast = useToast() + const bus = useBus() + + if (isAction(e, actionKeydown)) { + e.preventDefault() + e.stopPropagation() + const result = [] + const imgList = refView.querySelectorAll('img') + for (let i = 0; i < imgList.length; i++) { + toast.show('info', `正在转换外链图片 ${i + 1}/${imgList.length}`) + + const img = imgList[i] + const data = await transformImgOutLink(img) + if (data) { + result.push(data) + } + } + result.forEach(data => bus.emit('editor-replace-value', { search: data.oldLink, replace: data.replacedLink })) + bus.emit('tree-refresh') + } + }) + + ctx.registerHook('ON_VIEW_ELEMENT_CLICK', async (e: MouseEvent) => { + const bus = useBus() + const target = e.target as HTMLElement + if (target.tagName !== 'IMG') { + return false + } + + const img = target as HTMLImageElement + if (isAction(e, actionClick)) { // 转换外链图片到本地 + const data = await transformImgOutLink(img) + if (data) { + bus.emit('tree-refresh') + bus.emit('editor-replace-value', { search: data.oldLink, replace: data.replacedLink }) + } + } else { + env.openAlwaysOnTopWindow(img.src) + } + + e.stopPropagation() + e.preventDefault() + + return true + }) + } +} as Plugin diff --git a/frontend/src/useful/plugin.ts b/frontend/src/useful/plugin.ts new file mode 100644 index 00000000..4c792d01 --- /dev/null +++ b/frontend/src/useful/plugin.ts @@ -0,0 +1,58 @@ +import { addAction } from './shortcut' +import { getLogger } from './utils' + +export type HookType = 'ON_VIEW_ELEMENT_CLICK' + | 'ON_VIEW_KEY_DOWN' + +export interface Plugin { + name: string; + register?: (ctx: Ctx) => void; +} + +const logger = getLogger('plugin') + +const plugins: {[name: string]: Plugin} = {} + +const hooks: { [key in HookType]?: ((...args: any[]) => boolean | void | Promise)[] } = {} + +const ctx = { + registerShortcutAction (name: string, keys: (string | number)[]) { + addAction(name, keys) + }, + registerHook: (type: HookType, fun: (...args: any[]) => void) => { + if (Array.isArray(hooks[type])) { + hooks[type] = [...hooks[type]!!, fun] + } else { + hooks[type] = [fun] + } + } +} + +export type Ctx = typeof ctx; + +export const register = (plugin: Plugin) => { + logger.debug('register', plugin) + plugins[plugin.name] = plugin + plugin.register && plugin.register(ctx) +} + +export const init = () => { + logger.debug('init') + + const localPlugins = [ + require('@/plugins/TransformImgOutLink').plugin + ] + + localPlugins.forEach(register) +} + +export const triggerHook = async (type: HookType, ...args: any[]) => { + logger.debug('triggerHook', type, hooks, args) + for (const fun of (hooks[type] || [])) { + if (await fun(...args)) { + break + } + } +} + +init() diff --git a/frontend/src/useful/shortcut.ts b/frontend/src/useful/shortcut.ts index 47cbce3a..53c84197 100644 --- a/frontend/src/useful/shortcut.ts +++ b/frontend/src/useful/shortcut.ts @@ -4,15 +4,15 @@ import env from './env' const logger = getLogger('shortcut') const isMacOS = env.isMacOS -const Ctrl = 'Ctrl' -const CtrlCmd = 'CtrlCmd' -const Alt = 'Alt' -const Shift = 'Shift' -const LeftClick = 0 +export const Ctrl = 'Ctrl' +export const CtrlCmd = 'CtrlCmd' +export const Alt = 'Alt' +export const Shift = 'Shift' +export const LeftClick = 0 type XKey = typeof Ctrl | typeof CtrlCmd | typeof Alt | typeof Shift -const actions = { +const defaultActions = { 'toggle-side': [Alt, 'e'], 'toggle-wrap': [Alt, 'w'], 'toggle-view': [Alt, 'v'], @@ -20,13 +20,15 @@ const actions = { 'toggle-readme': [Alt, 'h'], 'insert-document': [CtrlCmd, Alt, 'i'], 'show-quick-open': [CtrlCmd, 'p'], - 'transform-img-link-by-click': [CtrlCmd, Shift, LeftClick], - 'transform-img-link': [CtrlCmd, Shift, 'l'], 'file-tabs-switch-left': [Ctrl, Alt, 'ArrowLeft'], 'file-tabs-switch-right': [Ctrl, Alt, 'ArrowRight'], } -type ActionName = keyof typeof actions +const actions: {[key: string]: (string | number)[]} = { + ...defaultActions +} + +type ActionName = keyof typeof defaultActions export const hasCtrlCmd = (e: KeyboardEvent | MouseEvent) => isMacOS ? e.metaKey : e.ctrlKey @@ -43,11 +45,6 @@ export const getKeyLabel = (key: XKey | string | number) => { } } -export const getActionLabel = (name: ActionName) => { - const keys: any[] = actions[name] - return keys.map(getKeyLabel).join(' + ') -} - export const matchKeys = (e: KeyboardEvent | MouseEvent, keys: (string | number)[]) => { for (const key of keys) { switch (key) { @@ -80,7 +77,22 @@ export const getCurrentAction = (e: KeyboardEvent | MouseEvent) => { return (Object.keys(actions) as ActionName[]).find(action => matchKeys(e, actions[action])) } -export const isAction = (e: KeyboardEvent | MouseEvent, name: ActionName) => { +export function isAction (e: KeyboardEvent | MouseEvent, name: ActionName): boolean +export function isAction (e: KeyboardEvent | MouseEvent, name: string): boolean +export function isAction (e: KeyboardEvent | MouseEvent, name: string) { logger.debug('isAction', name, e) return matchKeys(e, actions[name]) } + +export function getActionLabel (name: ActionName): string +export function getActionLabel (name: string): string +export function getActionLabel (name: string): string { + const keys: any[] = actions[name] + return keys.map(getKeyLabel).join(' + ') +} + +export function addAction (name: ActionName, keys: (string | number)[]): void +export function addAction (name: string, keys: (string | number)[]): void +export function addAction (name: string, keys: (string | number)[]): void { + actions[name] = keys +} From 43060874f9453a43445c97fbd0792a8a935137ed Mon Sep 17 00:00:00 2001 From: purocean Date: Thu, 25 Feb 2021 11:22:46 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/plugins/TransformImgOutLink.ts | 2 +- frontend/src/useful/plugin.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontend/src/plugins/TransformImgOutLink.ts b/frontend/src/plugins/TransformImgOutLink.ts index 364d20a7..64781023 100644 --- a/frontend/src/plugins/TransformImgOutLink.ts +++ b/frontend/src/plugins/TransformImgOutLink.ts @@ -52,7 +52,7 @@ async function transformImgOutLink (img: HTMLImageElement) { const actionKeydown = 'transform-img-link' const actionClick = 'transform-img-link-by-click' -export const plugin = { +export default { name: 'transform-img-out-link', register: (ctx: Ctx) => { ctx.registerShortcutAction(actionKeydown, [CtrlCmd, Shift, 'l']) diff --git a/frontend/src/useful/plugin.ts b/frontend/src/useful/plugin.ts index 4c792d01..3adf8ca6 100644 --- a/frontend/src/useful/plugin.ts +++ b/frontend/src/useful/plugin.ts @@ -40,10 +40,16 @@ export const init = () => { logger.debug('init') const localPlugins = [ - require('@/plugins/TransformImgOutLink').plugin + require('@/plugins/TransformImgOutLink') ] - localPlugins.forEach(register) + localPlugins.forEach((plugin) => { + if (plugin.__esModule && plugin.default) { + register(plugin.default) + } else { + register(plugin) + } + }) } export const triggerHook = async (type: HookType, ...args: any[]) => { From bfab83881e80212a0626bade3b4e5bab3792ac8d Mon Sep 17 00:00:00 2001 From: purocean Date: Fri, 26 Feb 2021 14:06:44 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package.json | 2 +- frontend/src/components/Editor.vue | 100 ++------ frontend/src/components/MonacoEditor.vue | 11 - frontend/src/components/Preview.vue | 223 ++---------------- frontend/src/components/TreeNode.vue | 10 +- frontend/src/plugins/CodePlugin.ts | 15 -- frontend/src/plugins/LinkTargetPlugin.ts | 13 - .../plugins/{AppletPlugin.ts => applet.ts} | 21 +- ...ghtNumberPlugin.ts => code-line-number.ts} | 14 +- frontend/src/plugins/copy-text.ts | 42 ++++ .../plugins/{DrawioPlugin.ts => drawio.ts} | 39 ++- .../plugins/{EChartsPlugin.ts => echarts.ts} | 23 +- frontend/src/plugins/markdown-code.ts | 20 ++ frontend/src/plugins/markdown-link.ts | 104 ++++++++ ...eLinePlugin.ts => markdown-source-line.ts} | 23 +- .../plugins/{TocPlugin.ts => markdown-toc.ts} | 12 +- .../plugins/{MermaidPlugin.ts => mermaid.ts} | 13 +- .../plugins/{MindMapPlugin.ts => mind-map.ts} | 26 +- .../{PlantumlPlugin.ts => plantuml.ts} | 31 ++- .../src/plugins/{RunPlugin.ts => run-code.ts} | 11 +- frontend/src/plugins/switch-todo.ts | 36 +++ frontend/src/plugins/table-cell-edit.ts | 116 +++++++++ ...mgOutLink.ts => transform-img-out-link.ts} | 0 frontend/src/useful/plugin.ts | 58 ++++- frontend/src/useful/startup.ts | 7 +- frontend/src/views/Main.vue | 3 +- frontend/yarn.lock | 10 +- yarn.lock | 5 + 28 files changed, 589 insertions(+), 399 deletions(-) delete mode 100644 frontend/src/plugins/CodePlugin.ts delete mode 100644 frontend/src/plugins/LinkTargetPlugin.ts rename frontend/src/plugins/{AppletPlugin.ts => applet.ts} (85%) rename frontend/src/plugins/{HightLightNumberPlugin.ts => code-line-number.ts} (90%) create mode 100644 frontend/src/plugins/copy-text.ts rename frontend/src/plugins/{DrawioPlugin.ts => drawio.ts} (83%) rename frontend/src/plugins/{EChartsPlugin.ts => echarts.ts} (77%) create mode 100644 frontend/src/plugins/markdown-code.ts create mode 100644 frontend/src/plugins/markdown-link.ts rename frontend/src/plugins/{SourceLinePlugin.ts => markdown-source-line.ts} (55%) rename frontend/src/plugins/{TocPlugin.ts => markdown-toc.ts} (94%) rename frontend/src/plugins/{MermaidPlugin.ts => mermaid.ts} (78%) rename frontend/src/plugins/{MindMapPlugin.ts => mind-map.ts} (91%) rename frontend/src/plugins/{PlantumlPlugin.ts => plantuml.ts} (91%) rename frontend/src/plugins/{RunPlugin.ts => run-code.ts} (92%) create mode 100644 frontend/src/plugins/switch-todo.ts create mode 100644 frontend/src/plugins/table-cell-edit.ts rename frontend/src/plugins/{TransformImgOutLink.ts => transform-img-out-link.ts} (100%) diff --git a/frontend/package.json b/frontend/package.json index 9bac09b6..605169c6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,7 +16,7 @@ "github-markdown-css": "^4.0.0", "highlight.js": "^10.4.1", "katex": "^0.6.0", - "loadsh": "^0.0.4", + "lodash": "^4.17.21", "markdown-it": "^12.0.1", "markdown-it-attrs": "^3.0.3", "markdown-it-footnote": "^3.0.2", diff --git a/frontend/src/components/Editor.vue b/frontend/src/components/Editor.vue index a532f4ba..c69c6180 100644 --- a/frontend/src/components/Editor.vue +++ b/frontend/src/components/Editor.vue @@ -45,7 +45,6 @@ export default defineComponent({ const getEditor = () => refEditor.value const revealLine = (line: number) => getEditor().revealLine(line) const revealLineInCenter = (line: number) => getEditor().revealLineInCenter(line) - const switchTodo = (line: number, checked: boolean) => getEditor().switchTodo(line, checked) const toUri = (file: any) => File.toUri(file) async function inputPassword (title: string, filename: string) { @@ -253,100 +252,35 @@ export default defineComponent({ const resize = () => nextTick(() => getEditor().resize()) const insert = (text?: string) => getEditor().insert(text) + const replaceValue = (value?: { search: string; replace: string }) => { if (value) { getEditor().replaceValue(value.search, value.replace) } } - const toggleWrap = () => getEditor().toggleWrap() - - const editTableCell = async (params?: { start: number; end: number; cellIndex: number }) => { - if (!params) { - return + const replaceLine = (params?: { line: number; value: string }) => { + if (params) { + getEditor().replaceLine(params.line, params.value) } - - const { start, end, cellIndex } = params - if (end - start !== 1) { - toast.show('warning', '暂只支持编辑单行文本') - return - } - - const escapedSplit = (str: string) => { - const result = [] - const max = str.length - let pos = 0 - let ch = str.charCodeAt(pos) - let isEscaped = false - let lastPos = 0 - let current = '' - - while (pos < max) { - if (ch === 0x7c/* | */) { - if (!isEscaped) { - // pipe separating cells, '|' - result.push(current + str.substring(lastPos, pos)) - current = '' - lastPos = pos + 1 - } else { - // escaped pipe, '\|' - current += str.substring(lastPos, pos - 1) - lastPos = pos - } - } - - isEscaped = (ch === 0x5c/* \ */) - pos++ - - ch = str.charCodeAt(pos) - } - - result.push(current + str.substring(lastPos)) - - if (result.length && result[0] === '') result.shift() - if (result.length && result[result.length - 1] === '') result.pop() - - return result - } - - const text = getEditor().getLineContent(start).trim() - const columns = escapedSplit(text) - const cellText = columns[cellIndex] - - if (typeof cellText !== 'string') { - toast.show('warning', '编辑错误') - return - } - - let value = await modal.input({ - title: '编辑单元格', - type: 'textarea', - value: cellText, - modalWidth: '600px', - hint: '单元格内容', - }) - if (typeof value !== 'string') { - toast.show('warning', '取消编辑') - return - } - - if (!value.startsWith(' ') && cellIndex > 0) value = ' ' + value - if (!value.endsWith(' ') && cellIndex < columns.length - 1) value += ' ' - columns[cellIndex] = value.replace(/\|/g, '\\|').replace(/\n/g, ' ') - - let content = columns.join('|').trim() - if (text.startsWith('|')) content = '| ' + content - if (text.endsWith('|')) content += ' |' - - getEditor().replaceLine(start, content) } + const getLine = (params?: {line: number; callback?: (value: string) => void}) => { + if (params) { + const { line, callback } = params + callback && callback(getEditor().getLineContent(line)) + } + } + + const toggleWrap = () => getEditor().toggleWrap() + onMounted(() => { bus.on('resize', resize) bus.on('editor-insert-value', insert) bus.on('editor-replace-value', replaceValue) + bus.on('editor-get-line', getLine) + bus.on('editor-replace-line', replaceLine) bus.on('editor-toggle-wrap', toggleWrap) - bus.on('editor-edit-table-cell', editTableCell) bus.on('file-new', createFile as any) restartTimer() }) @@ -355,16 +289,16 @@ export default defineComponent({ bus.off('resize', resize) bus.off('editor-insert-value', insert) bus.off('editor-replace-value', replaceValue) + bus.off('editor-get-line', getLine) + bus.off('editor-replace-line', replaceLine) bus.off('editor-toggle-wrap', toggleWrap) bus.off('file-new', createFile as any) - bus.off('editor-edit-table-cell', editTableCell) }) return { refEditor, revealLine, revealLineInCenter, - switchTodo, setCurrentValue, syncScrollView, pasteImg, diff --git a/frontend/src/components/MonacoEditor.vue b/frontend/src/components/MonacoEditor.vue index ae3d492d..67d2b867 100644 --- a/frontend/src/components/MonacoEditor.vue +++ b/frontend/src/components/MonacoEditor.vue @@ -204,16 +204,6 @@ export default defineComponent({ return getEditor().getModel()!!.getLineContent(line) } - function switchTodo (line: number, checked: boolean) { - if (checked) { - const value = getLineContent(line).replace('[ ]', `[x] ~~${dayjs().format('YYYY-MM-DD HH:mm')}~~`) - replaceLine(line, value) - } else { - const value = getLineContent(line).replace(/(\[x\] ~~[\d-: ]+~~|\[x\])/, '[ ]') - replaceLine(line, value) - } - } - function getValue () { return getEditor().getModel()!!.getValue(getMonaco().editor.DefaultEndOfLine.LF) } @@ -323,7 +313,6 @@ export default defineComponent({ revealLine, revealLineInCenter, setScrollToTop, - switchTodo, replaceValue, replaceLine, toggleWrap, diff --git a/frontend/src/components/Preview.vue b/frontend/src/components/Preview.vue index a0c4516e..b0c13016 100644 --- a/frontend/src/components/Preview.vue +++ b/frontend/src/components/Preview.vue @@ -38,7 +38,7 @@ - - diff --git a/frontend/src/components/StatusBar.vue b/frontend/src/components/StatusBar.vue index 49325b31..65230b05 100644 --- a/frontend/src/components/StatusBar.vue +++ b/frontend/src/components/StatusBar.vue @@ -1,6 +1,6 @@