From beefc1d5ef8061e33a04e6209f35b67767ead8dc Mon Sep 17 00:00:00 2001 From: kolaente Date: Sat, 21 Oct 2023 14:02:53 +0200 Subject: [PATCH] feat(editor): add bubble menu --- package.json | 1 + pnpm-lock.yaml | 11 +++ src/components/input/editor/TipTap.vue | 122 ++++++++++++++++++++++++- src/components/misc/Icon.ts | 3 +- 4 files changed, 133 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index dae5d2562..768bd87c6 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "@tiptap/extension-task-item": "2.0.3", "@tiptap/extension-task-list": "2.0.3", "@tiptap/extension-typography": "2.0.3", + "@tiptap/extension-underline": "^2.1.12", "@tiptap/starter-kit": "2.0.3", "@tiptap/suggestion": "^2.1.12", "@tiptap/vue-3": "2.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4304b5f39..e9e54ae4d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,6 +82,9 @@ dependencies: '@tiptap/extension-typography': specifier: 2.0.3 version: 2.0.3(@tiptap/core@2.1.12) + '@tiptap/extension-underline': + specifier: ^2.1.12 + version: 2.1.12(@tiptap/core@2.1.12) '@tiptap/starter-kit': specifier: 2.0.3 version: 2.0.3(@tiptap/pm@2.1.12) @@ -4498,6 +4501,14 @@ packages: '@tiptap/core': 2.1.12(@tiptap/pm@2.1.12) dev: false + /@tiptap/extension-underline@2.1.12(@tiptap/core@2.1.12): + resolution: {integrity: sha512-NwwdhFT8gDD0VUNLQx85yFBhP9a8qg8GPuxlGzAP/lPTV8Ubh3vSeQ5N9k2ZF/vHlEvnugzeVCbmYn7wf8vn1g==} + peerDependencies: + '@tiptap/core': ^2.0.0 + dependencies: + '@tiptap/core': 2.1.12(@tiptap/pm@2.1.12) + dev: false + /@tiptap/pm@2.1.12: resolution: {integrity: sha512-Q3MXXQABG4CZBesSp82yV84uhJh/W0Gag6KPm2HRWPimSFELM09Z9/5WK9RItAYE0aLhe4Krnyiczn9AAa1tQQ==} dependencies: diff --git a/src/components/input/editor/TipTap.vue b/src/components/input/editor/TipTap.vue index 00136cd80..0288ad310 100644 --- a/src/components/input/editor/TipTap.vue +++ b/src/components/input/editor/TipTap.vue @@ -5,6 +5,60 @@ :editor="editor" :upload-callback="uploadCallback" /> + + + + + + + + + + + + + + + + + + + + /^https?:\/\//.test(href), @@ -215,6 +272,7 @@ const editor = useEditor({ Commands.configure({ suggestion: suggestionSetup(t), }), + BubbleMenu, ], onUpdate: () => { // HTML @@ -256,7 +314,7 @@ function addImage() { uploadCallback(files).then(urls => { urls.forEach(url => { editor.value - .chain() + ?.chain() .focus() .setImage({src: url}) .run() @@ -270,10 +328,40 @@ function addImage() { const url = window.prompt('URL') if (url) { - editor.value.chain().focus().setImage({src: url}).run() + editor.value?.chain().focus().setImage({src: url}).run() onImageAdded() } } + +function setLink() { + const previousUrl = editor.value?.getAttributes('link').href + const url = window.prompt('URL', previousUrl) + + // cancelled + if (url === null) { + return + } + + // empty + if (url === '') { + editor.value + ?.chain() + .focus() + .extendMarkRange('link') + .unsetLink() + .run() + + return + } + + // update link + editor.value + ?.chain() + .focus() + .extendMarkRange('link') + .setLink({href: url, target: '_blank'}) + .run() +} diff --git a/src/components/misc/Icon.ts b/src/components/misc/Icon.ts index cc8aed567..d50e3953d 100644 --- a/src/components/misc/Icon.ts +++ b/src/components/misc/Icon.ts @@ -73,7 +73,7 @@ import { faUnlink, faParagraph, faTable, - faX, faArrowTurnDown, faListCheck, faXmark, faXmarksLines, faFont, faRulerHorizontal, + faX, faArrowTurnDown, faListCheck, faXmark, faXmarksLines, faFont, faRulerHorizontal, faUnderline, } from '@fortawesome/free-solid-svg-icons' import { faBellSlash, @@ -185,6 +185,7 @@ library.add(faXmark) library.add(faXmarksLines) library.add(faFont) library.add(faRulerHorizontal) +library.add(faUnderline) // overwriting the wrong types export default FontAwesomeIcon as unknown as FontAwesomeIconFixedTypes \ No newline at end of file