From e0eb661c8ff12399a9398894157eaf3cd8a5df78 Mon Sep 17 00:00:00 2001 From: liji <896126514@qq.com> Date: Thu, 26 Sep 2024 14:40:01 +0800 Subject: [PATCH] feat: printer --- examples/App.vue | 2 + package.json | 1 + pnpm-lock.yaml | 9 ++- src/components/EchoEditor.vue | 2 + src/components/Menubars.vue | 21 +----- src/components/Printer.vue | 73 +++++++++++++++++++ .../FindAndReplace/FindAndReplace.ts | 4 +- src/extensions/Printer/Printer.ts | 25 +++++++ src/extensions/Printer/index.ts | 1 + src/extensions/index.ts | 3 + src/hooks/index.ts | 1 + src/hooks/useHotkeys.ts | 28 +++++++ src/hooks/useStore.ts | 7 ++ src/locales/locales/en.ts | 1 + src/locales/locales/zh.ts | 1 + 15 files changed, 157 insertions(+), 22 deletions(-) create mode 100644 src/components/Printer.vue create mode 100644 src/extensions/Printer/Printer.ts create mode 100644 src/extensions/Printer/index.ts create mode 100644 src/hooks/useHotkeys.ts diff --git a/examples/App.vue b/examples/App.vue index 0a92f55..f906845 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -118,6 +118,7 @@ import { Code, AI, Preview, + Printer, } from 'echo-editor' import { ExportWord } from './extensions/ExportWord' import OpenAI from 'openai' @@ -324,6 +325,7 @@ const extensions = [ upload: handleFileUpload, }), FindAndReplace.configure({ spacer: true }), + Printer, Preview, ] async function handleFileUpload(files: File[]) { diff --git a/package.json b/package.json index 89d0858..e481faa 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "echo-drag-handle-plugin": "^0.0.2", + "hotkeys-js": "^3.13.7", "tippy.js": "^6.3.7" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bb9edd9..7b05c7e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -152,6 +152,9 @@ importers: echo-drag-handle-plugin: specifier: ^0.0.2 version: 0.0.2(@tiptap/core@2.6.6)(@tiptap/pm@2.6.6)(y-prosemirror@1.2.5) + hotkeys-js: + specifier: ^3.13.7 + version: 3.13.7 tippy.js: specifier: ^6.3.7 version: 6.3.7 @@ -1908,7 +1911,7 @@ packages: /@types/node-fetch@2.6.11: resolution: {integrity: sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==} dependencies: - '@types/node': 18.19.33 + '@types/node': 20.12.12 form-data: 4.0.0 dev: false @@ -4212,6 +4215,10 @@ packages: parse-passwd: 1.0.0 dev: true + /hotkeys-js@3.13.7: + resolution: {integrity: sha512-ygFIdTqqwG4fFP7kkiYlvayZppeIQX2aPpirsngkv1xM1lP0piDY5QEh68nQnIKvz64hfocxhBaD/uK3sSK1yQ==} + dev: false + /http-errors@2.0.0: resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} engines: {node: '>= 0.8'} diff --git a/src/components/EchoEditor.vue b/src/components/EchoEditor.vue index 32d4920..5c9409f 100644 --- a/src/components/EchoEditor.vue +++ b/src/components/EchoEditor.vue @@ -16,6 +16,7 @@ import AIMenu from './menus/AIMenu.vue' import Menubars from './Menubars.vue' import Toolbar from './Toolbar.vue' import Preview from './Preview.vue' +import Printer from './Printer.vue' import FindAndReplace from './FindAndReplace.vue' import { EchoEditorOnChange } from '@/type' import { useDark, useToggle } from '@vueuse/core' @@ -176,6 +177,7 @@ defineExpose({ editor }) +
([ shortcut: ['mod', 'P'], action: () => { // 实现打印 - const content = props.editor.getHTML() - if (content) { - const printWindow = window.open('', '', 'width=600,height=600') // 打开新窗口 - if (printWindow) { - printWindow.document.write(` - - - - - - ${content} - - - `) - printWindow.document.close() // 关闭文档流 - printWindow.focus() // 聚焦到打印窗口 - printWindow.print() // 调用打印 - printWindow.close() // 打印后关闭窗口 - } - } + store.state.printer = true }, }, ], diff --git a/src/components/Printer.vue b/src/components/Printer.vue new file mode 100644 index 0000000..e555114 --- /dev/null +++ b/src/components/Printer.vue @@ -0,0 +1,73 @@ + +