Skip to content

Commit 486dacc

Browse files
committed
[Ui] wysiwyg : add bubble menu and link configuration
new parameters : - :bubble-toolbar - :link-configuration
1 parent 044dce7 commit 486dacc

File tree

8 files changed

+2759
-2685
lines changed

8 files changed

+2759
-2685
lines changed

vertigo-ui-wysiwyg/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vertigo-ui-wysiwyg/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"@tiptap/extension-blockquote": "^2.6.6",
1212
"@tiptap/extension-bold": "^2.6.6",
13+
"@tiptap/extension-bubble-menu": "^2.6.6",
1314
"@tiptap/extension-bullet-list": "^2.6.6",
1415
"@tiptap/extension-document": "^2.6.6",
1516
"@tiptap/extension-gapcursor": "^2.6.6",

vertigo-ui-wysiwyg/src/components/Wysiwyg.vue

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@
3030
@click="commands[btn].action(editor)"></button>
3131
</div>
3232
</div>
33+
<bubble-menu :editor="editor"
34+
:tippy-options="{ duration: 100 }"
35+
v-if="editor && bubbleToolbar">
36+
<div class="toolbar bubble">
37+
<div v-for="btnGroup in bubbleToolbar" class="button-group" :class="{'gap' : btnGroup.length === 0}">
38+
<button v-for="btn in btnGroup"
39+
type="button" :key="btn"
40+
:class="[commands[btn].class, {'is-active': commands[btn].active?.(editor)}]"
41+
:aria-pressed="commands[btn].active?.(editor)"
42+
:disabled="commands[btn].disabled?.(editor)"
43+
:aria-disabled="commands[btn].disabled?.(editor)"
44+
:title="$vui.i18n().wysiwyg[btn]"
45+
:aria-label="$vui.i18n().wysiwyg[btn]"
46+
@click="commands[btn].action(editor)"></button>
47+
</div>
48+
</div>
49+
</bubble-menu>
3350
<editor-content :editor="editor" class="editor"></editor-content>
3451
</template>
3552
</div>
@@ -39,7 +56,7 @@
3956
import { watch, ref } from 'vue'
4057
4158
// import mandatory tiptap components
42-
import { useEditor, EditorContent } from '@tiptap/vue-3'
59+
import { useEditor, EditorContent, BubbleMenu } from '@tiptap/vue-3'
4360
import Document from '@tiptap/extension-document'
4461
import Paragraph from '@tiptap/extension-paragraph'
4562
import Text from '@tiptap/extension-text'
@@ -64,15 +81,7 @@
6481
import Subscript from '@tiptap/extension-subscript'
6582
import Superscript from '@tiptap/extension-superscript'
6683
67-
const TextAlign = RawTextAlign.configure({
68-
types: ['heading', 'paragraph'],
69-
})
70-
71-
// Consider exposing additional configuration, for example for domain whitelist https://tiptap.dev/docs/editor/extensions/marks/link#validate
72-
const Link = RawLink.configure({
73-
openOnClick: false,
74-
})
75-
84+
// props and model
7685
let displayHtml = ref(false);
7786
7887
const model = defineModel();
@@ -81,10 +90,29 @@
8190
toolbar: {
8291
type: Array,
8392
default: [['bold', 'italic', 'underline'], ['unordered', 'ordered', 'outdent', 'indent'], [], ['undo', 'redo'], ['viewsource']]
93+
},
94+
bubbleToolbar: {
95+
type: Array,
96+
default: null
97+
},
98+
linkConfiguration: {
99+
type: Object,
100+
default: {}
84101
}
85102
})
86103
104+
// Configure extensions
105+
const TextAlign = RawTextAlign.configure({
106+
types: ['heading', 'paragraph'],
107+
})
108+
109+
// Example for domain whitelist https://tiptap.dev/docs/editor/extensions/marks/link#validate
110+
const Link = RawLink.configure({
111+
openOnClick: false,
112+
...props.linkConfiguration
113+
})
87114
115+
// commands definitions
88116
const commands = {
89117
'bold' : {
90118
class: 'mdi mdi-format-bold',
@@ -331,6 +359,13 @@
331359
padding: 0.3rem;
332360
font-size: 18px;
333361
362+
&.bubble {
363+
background-color: white;
364+
border-radius: 0.7rem;
365+
box-shadow: 5px 5px 10px #ccc;
366+
padding: 0.2rem;
367+
}
368+
334369
.button-group {
335370
position: relative;
336371
margin: 0 4px;

vertigo-ui/src/main/resources/io/vertigo/ui/static/js/wysiwyg/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)