@live-change/wysiwyg-frontend 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Michał Łaszczewski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <!--head-->
5
+ </head>
6
+ <body>
7
+ <div id="app"><!--app-html--></div>
8
+ <!--app-data-->
9
+ <script type="module" src="/src/entry-client.js"></script>
10
+ </body>
11
+ </html>
Binary file
@@ -0,0 +1,38 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+
4
+ <svg
5
+ version="1.1"
6
+ id="Layer_1"
7
+ x="0px"
8
+ y="0px"
9
+ width="512px"
10
+ height="512px"
11
+ viewBox="0 0 512 512"
12
+ enable-background="new 0 0 512 512"
13
+ xml:space="preserve"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ xmlns:svg="http://www.w3.org/2000/svg"
16
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
17
+ xmlns:cc="http://creativecommons.org/ns#"
18
+ xmlns:dc="http://purl.org/dc/elements/1.1/"><metadata
19
+ id="metadata9"><rdf:RDF><cc:Work
20
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
21
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
22
+ id="defs7" />
23
+ <rect
24
+ style="fill:#dbdbdb;fill-opacity:1;stroke:none;stroke-width:1.88976383;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
25
+ id="rect821"
26
+ width="512.54236"
27
+ height="512.54236"
28
+ x="0.54237288"
29
+ y="0.54237235" />
30
+ <path
31
+ style="fill:#f6f6f6;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
32
+ d="M 0.54237288,470.23729 125.83051,306.44068 l 60.20339,70.50847 130.71186,-174.10169 195.79661,261.42373 0.54235,48.81353 H 0.54237288 Z"
33
+ id="path816" /><circle
34
+ style="fill:#f6f6f6;fill-opacity:1;stroke:none;stroke-width:4.80000019;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
35
+ id="path818"
36
+ cx="118.50848"
37
+ cy="106.57627"
38
+ r="57.762711" /></svg>
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+
4
+ <svg
5
+ version="1.1"
6
+ id="Layer_1"
7
+ x="0px"
8
+ y="0px"
9
+ width="512px"
10
+ height="512px"
11
+ viewBox="0 0 512 512"
12
+ enable-background="new 0 0 512 512"
13
+ xml:space="preserve"
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ xmlns:svg="http://www.w3.org/2000/svg"
16
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
17
+ xmlns:cc="http://creativecommons.org/ns#"
18
+ xmlns:dc="http://purl.org/dc/elements/1.1/"><metadata
19
+ id="metadata9"><rdf:RDF><cc:Work
20
+ rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
21
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
22
+ id="defs7" />
23
+ <rect
24
+ style="fill:#dbdbdb;fill-opacity:1;stroke:none;stroke-width:1.88976383;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
25
+ id="rect821"
26
+ width="512.54236"
27
+ height="512.54236"
28
+ x="0.54237288"
29
+ y="0.54237235" /><path
30
+ d="m 313.14122,310.64877 c 9.02181,-8.85097 12.15686,-31.23733 20.41627,-39.3056 11.69771,-11.43183 24.39381,-25.50218 27.98588,-43.06851 4.82003,-23.34203 -4.96846,-26.30516 -4.96846,-34.3713 0,-16.90002 -0.15376,-44.65739 -5.43081,-62.68607 -0.30326,-23.7809 -4.20499,-34.123578 -12.38858,-43.031138 -7.72017,-8.33522 -26.68637,-6.366203 -36.59125,-11.85361 C 286.83605,67.825407 274.23818,64.594254 258.15823,64.17461 v -0.09503 c -0.47624,0 -0.93539,0.05659 -1.41162,0.05659 -0.78484,0 -1.53123,-0.05659 -2.35343,-0.05659 l 0.0395,0.151627 c -39.17105,1.472492 -80.84608,26.170627 -95.16524,65.895863 -5.31335,14.71958 -3.28881,46.87521 -3.28881,63.77522 0,8.06721 -9.78742,11.02927 -4.96846,34.37131 3.61129,17.56632 16.28817,31.63668 27.98588,43.06851 8.26048,8.06827 11.39446,30.45462 20.39705,39.30559 1.96902,13.0378 2.1986,9.31012 2.12278,21.23954 -0.0203,4.03307 0.11426,10.28502 -6.32669,16.4398 -12.17822,11.6614 -40.14595,36.95324 -63.08756,46.79832 -30.24,12.98014 -79.41203,33.74237 -90.746691,39.59069 -11.334661,5.84833 -41.2532541,21.69763 -41.2532541,31.79045 0,10.11417 0,47.33542 0,47.33542 h 253.3742451 5.79494 253.37318 c 0,0 0,-37.22125 0,-47.33542 0,-10.09282 -29.89723,-25.94212 -41.25645,-31.79045 -11.35389,-5.84938 -60.48321,-26.61055 -90.72641,-39.59069 -22.32976,-9.57707 -49.43685,-33.81712 -62.09344,-45.84158 -4.2808,-4.05228 -7.3016,-8.29784 -7.3411,-18.62023 -0.0737,-12.00417 0.23278,-7.41692 2.14306,-20.01478"
31
+ id="path2"
32
+ style="clip-rule:evenodd;fill-rule:evenodd;stroke-width:1.06779659;fill:#f6f6f6;fill-opacity:1" />
33
+ </svg>
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <svg
3
+ width="512"
4
+ height="512"
5
+ viewBox="0 0 135.46667 135.46667"
6
+ version="1.1"
7
+ id="svg977"
8
+ xmlns="http://www.w3.org/2000/svg"
9
+ xmlns:svg="http://www.w3.org/2000/svg"
10
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
11
+ xmlns:cc="http://creativecommons.org/ns#"
12
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
13
+ <defs
14
+ id="defs971" />
15
+ <metadata
16
+ id="metadata974">
17
+ <rdf:RDF>
18
+ <cc:Work
19
+ rdf:about="">
20
+ <dc:format>image/svg+xml</dc:format>
21
+ <dc:type
22
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
23
+ </cc:Work>
24
+ </rdf:RDF>
25
+ </metadata>
26
+ <g
27
+ id="layer1"
28
+ style="fill:#666666">
29
+ <path
30
+ style="fill:#666666;fill-opacity:1;stroke:none;stroke-width:2.70907px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
31
+ d="M 54.181439,13.558436 67.726801,0.01304296 135.45359,67.739804 67.726801,135.46667 29.799793,97.539626 V 65.030766 L 13.545362,81.285197 0,67.739804 40.636077,27.103727 81.272154,67.739804 67.726801,81.285197 51.472371,65.030766 V 92.12155 l 16.25443,16.25433 40.636069,-40.636076 z"
32
+ id="path892" />
33
+ </g>
34
+ </svg>
Binary file
@@ -0,0 +1,32 @@
1
+ <template>
2
+ <view-root>
3
+ <template #navbar>
4
+ <NavBar />
5
+ </template>
6
+ </view-root>
7
+ </template>
8
+
9
+ <script setup>
10
+ import 'primevue/resources/themes/saga-green/theme.css'
11
+ import "@fortawesome/fontawesome-free/css/all.min.css"
12
+
13
+ import NavBar from "./NavBar.vue"
14
+ import ViewRoot from "@live-change/frontend-base/ViewRoot.vue"
15
+
16
+ import { useMeta } from 'vue-meta'
17
+ const { meta } = useMeta({
18
+ title: 'Title',
19
+ htmlAttrs: {
20
+ lang: 'en',
21
+ amp: true
22
+ }
23
+ })
24
+
25
+ import { watch } from 'vue'
26
+ import { client as useClient } from '@live-change/vue3-ssr'
27
+ const client = useClient()
28
+ watch(client, (newClient, oldClient) => {
29
+ console.log("WATCH CLIENT", oldClient, '=>', newClient)
30
+ })
31
+
32
+ </script>
@@ -0,0 +1,23 @@
1
+ import { h, ref } from 'vue'
2
+ import Button from "primevue/button"
3
+ import { toRefs } from '@vueuse/core'
4
+
5
+ function renderNode(node, r, marks, nodes) {
6
+ const renderer = nodes[node.type]
7
+ if(!renderer) return h('div', { style: 'color: red' }, `[unknown node type ${node.type}]`)
8
+ return renderer(node, r, marks, nodes)
9
+ }
10
+
11
+ function ContentView(props, context) {
12
+ const { content, config } = props
13
+ if(content) {
14
+ const doc = JSON.parse(content)
15
+ const r = nodes => nodes?.map(n => renderNode(n, r, config.marks, config.nodes))
16
+ return renderNode(doc, r, config.marks, config.nodes)
17
+ }
18
+ return h('div', {}, [
19
+ h('h1', {}, 'Content View'),
20
+ ])
21
+ }
22
+
23
+ export default ContentView
@@ -0,0 +1,130 @@
1
+ <template>
2
+ <div class="relative">
3
+ <slot v-if="editor" name="menu" :editor="editor">
4
+ <EditorMenu :editor="editor" :config="config" />
5
+ </slot>
6
+ <editor-content :editor="editor" class="content" />
7
+ </div>
8
+ </template>
9
+
10
+ <script setup>
11
+
12
+ import { useEditor, EditorContent } from '@tiptap/vue-3'
13
+ import { ref, computed, watch, provide, defineEmits, defineProps, getCurrentInstance, onUnmounted } from 'vue'
14
+ import { toRefs, useDebounceFn } from '@vueuse/core'
15
+ import EditorMenu from "./EditorMenu.vue"
16
+ import { getExtensions } from "./contentConfigExtensions.js"
17
+ import { getSchemaSpecFromConfig } from "./schemaJson.js"
18
+
19
+ import { live, path, useApi, inboxReader } from '@live-change/vue3-ssr'
20
+ import ProseMirrorCollab from "./ProseMirrorCollab.js"
21
+ import { sendableSteps, receiveTransaction, getVersion } from 'prosemirror-collab'
22
+ import { Step } from 'prosemirror-transform'
23
+
24
+ const props = defineProps({
25
+ document: {
26
+ type: String,
27
+ required: true
28
+ },
29
+ type: {
30
+ type: String,
31
+ required: true
32
+ },
33
+ purpose: {
34
+ type: String,
35
+ required: true
36
+ },
37
+ config: {
38
+ type: Object,
39
+ required: true
40
+ },
41
+ initialContent: {
42
+ type: Object,
43
+ default: () => ({ type: 'doc', content: [ ] })
44
+ }
45
+ })
46
+
47
+ const appContext = getCurrentInstance().appContext
48
+ const api = useApi(appContext)
49
+
50
+ const { document } = props
51
+
52
+ let documentData = await api.get(['prosemirror', 'document', { document }])
53
+ if(!documentData) {
54
+ documentData = {
55
+ id: document,
56
+ document: props.document,
57
+ type: props.type,
58
+ purpose: props.purpose,
59
+ content: props.initialContent,
60
+ version: 0
61
+ }
62
+ console.log(['prosemirror', 'createDocument'], documentData)
63
+ await api.command(['prosemirror', 'createDocument'], documentData)
64
+ }
65
+
66
+ const extensions = getExtensions(props.config)
67
+ console.log("CONFIG", props.config, 'EXTENSIONS', extensions)
68
+ const editor = useEditor({
69
+ content: documentData.content,
70
+ extensions: [
71
+ ...extensions,
72
+ ProseMirrorCollab.configure({
73
+ version: documentData.version,
74
+ clientID: api.windowId
75
+ })
76
+ ],
77
+ onTransaction: ({ editor, transaction }) => {
78
+ console.log("EDITOR UPDATE", editor, transaction)
79
+ saveDebounced()
80
+ }
81
+ })
82
+
83
+ function save() {
84
+ const state = editor.value.reactiveState.value
85
+ const sendable = sendableSteps(state)
86
+ if(sendable) {
87
+ console.log("SENDABLE STEPS", sendable)
88
+ const serializedSteps = sendable.steps.map(step => step.toJSON())
89
+ console.log("SERIALIZED STEPS", serializedSteps)
90
+ api.command(['prosemirror', 'doSteps'], {
91
+ document, type: props.type,
92
+ version: sendable.version, steps: serializedSteps, window: api.windowId
93
+ })
94
+ }
95
+ }
96
+
97
+ const saveDebounced = useDebounceFn(save, 100)
98
+
99
+ if(typeof window != 'undefined') {
100
+ const stepsReader = inboxReader(
101
+ (rawPosition, bucketSize) => {
102
+ const positionCounter = +rawPosition.split(':').pop().replace(/"/g, '')
103
+ const position = `${JSON.stringify(document)}:${JSON.stringify(positionCounter.toFixed().padStart(10, '0'))}`
104
+ return ['prosemirror', 'steps', { document, gt: position, limit: bucketSize }]
105
+ },
106
+ (message) => {
107
+ console.log("MESSAGE!", message)
108
+ const modifiedVersion = +message.id.split(':').pop().replace(/"/g, '')
109
+ const originalVersion = modifiedVersion - message.steps.length
110
+ const state = editor.value.reactiveState.value
111
+ const currentVersion = getVersion(state)
112
+ if(currentVersion < originalVersion) throw new Error("COLLAB REQUESTED BACK STEPS!")
113
+ console.log("COLLAB VERSION", currentVersion, "ORIGINAL VERSION", originalVersion, "MODIFIED VERSION", modifiedVersion)
114
+ const versionDiff = currentVersion - originalVersion
115
+ const newSteps = message.steps.slice(versionDiff)
116
+ console.log("RUNNING STEPS", newSteps.length, "/", message.steps.length)
117
+ const steps = newSteps.map(stepJson => Step.fromJSON(editor.value.schema, stepJson))
118
+ const clientIDs = steps.map(step => message.window)
119
+ const transaction = receiveTransaction(state, steps, clientIDs)
120
+ editor.value.view.dispatch(transaction)
121
+ },
122
+ `${JSON.stringify(document)}:${JSON.stringify(documentData.version.toFixed().padStart(10, '0'))}`
123
+ )
124
+ onUnmounted(() => stepsReader.dispose())
125
+ }
126
+ </script>
127
+
128
+ <style scoped>
129
+
130
+ </style>
@@ -0,0 +1,55 @@
1
+ <template>
2
+ <div>
3
+ <DocumentEditor :document="document" :type="'rich'" :purpose="'test'"
4
+ :initialContent="emptyContent"
5
+ :config="contentConfig" />
6
+ </div>
7
+ </template>
8
+
9
+ <script setup>
10
+
11
+ import DocumentEditor from "./DocumentEditor.vue"
12
+ import { ref } from 'vue'
13
+ import { basicMarks, messageNodes, richEditorNodes } from "./contentConfig.js"
14
+
15
+ const contentConfig = {
16
+ marks: {
17
+ ...basicMarks
18
+ },
19
+ nodes: {
20
+ //...messageNodes,
21
+ ...richEditorNodes
22
+ }
23
+ }
24
+
25
+ const document = 'testDocument'
26
+
27
+ const emptyContent = {
28
+ "type": "doc",
29
+ "content": [].concat(new Array(2).fill(
30
+ {
31
+ "type": "paragraph",
32
+ "content": [
33
+ {
34
+ "type": "text",
35
+ "text": "test"
36
+ },
37
+ {
38
+ "type": "text",
39
+ "marks": [
40
+ {
41
+ "type": "bold"
42
+ }
43
+ ],
44
+ "text": "est"
45
+ }
46
+ ]
47
+ }
48
+ ))
49
+ }
50
+
51
+ </script>
52
+
53
+ <style scoped>
54
+
55
+ </style>
@@ -0,0 +1,104 @@
1
+ <template>
2
+ <div class="relative">
3
+ <slot v-if="editor" name="menu" :editor="editor">
4
+ <EditorMenu :editor="editor" :config="config" />
5
+ </slot>
6
+ <editor-content :editor="editor" class="content" />
7
+ </div>
8
+ </template>
9
+
10
+ <script setup>
11
+
12
+ import { useEditor, EditorContent } from '@tiptap/vue-3'
13
+
14
+ import { ref, computed, watch, provide, defineEmits, defineProps } from 'vue'
15
+ import { toRefs } from '@vueuse/core'
16
+ import EditorMenu from "./EditorMenu.vue"
17
+ import { getExtensions } from "./contentConfigExtensions.js"
18
+ import { getSchemaSpecFromConfig } from "./schemaJson.js"
19
+
20
+ const props = defineProps({
21
+ modelValue: {
22
+ type: String,
23
+ default: JSON.stringify({ type: 'doc', content: [ ] })
24
+ },
25
+ config: {
26
+ type: Object,
27
+ required: true
28
+ }
29
+ })
30
+
31
+ const emit = defineEmits(['update:modelValue'])
32
+
33
+ const extensions = getExtensions(props.config)
34
+
35
+ const editor = useEditor({
36
+ content: JSON.parse(props.modelValue),
37
+ extensions,
38
+ onUpdate: ({ editor, transaction }) => {
39
+ console.log("EDITOR UPDATE", editor, transaction)
40
+ const editorJson = JSON.stringify(editor.getJSON())
41
+ emit('update:modelValue', editorJson)
42
+ emit('update', { editor, transaction })
43
+ }
44
+ })
45
+
46
+ const { modelValue, config } = toRefs(props)
47
+
48
+ watch(() => modelValue.value, value => {
49
+ const editorJson = JSON.stringify(editor.value.getJSON())
50
+ const isSame = editorJson === value
51
+ if (isSame) return
52
+ editor.commands.setContent(JSON.parse(value), false)
53
+ })
54
+
55
+ const schemaSpec = ref(getSchemaSpecFromConfig(props.config))
56
+
57
+ provide('wysiwyg', {})
58
+
59
+ </script>
60
+
61
+ <style lang="scss">
62
+ .ProseMirror {
63
+ > * + * {
64
+ margin-top: 0.75em;
65
+ }
66
+
67
+ code {
68
+ display: block;
69
+ white-space: pre-wrap;
70
+ font-size: 0.8rem;
71
+ padding: 0.75rem 1rem;
72
+ background-color:#e9ecef;
73
+ color: #495057;
74
+ }
75
+ }
76
+
77
+ .content {
78
+ padding: 1rem 0 0;
79
+
80
+ h3 {
81
+ margin: 1rem 0 0.5rem;
82
+ }
83
+
84
+ pre {
85
+ border-radius: 5px;
86
+ color: #333;
87
+ }
88
+
89
+ code {
90
+ display: block;
91
+ white-space: pre-wrap;
92
+ font-size: 0.8rem;
93
+ padding: 0.75rem 1rem;
94
+ background-color:#e9ecef;
95
+ color: #495057;
96
+ }
97
+
98
+ img {
99
+ width: 100%;
100
+ }
101
+
102
+ }
103
+
104
+ </style>
@@ -0,0 +1,123 @@
1
+ <template>
2
+ <div class="surface-card p-1 shadow-2 border-round sticky flex flex-row flex-wrap"
3
+ style="top: 90px; z-index: 1">
4
+ <div class="p-buttonset mr-1 mb-1">
5
+ <Button v-if="config.marks.bold" label="B" class="p-button-sm font-bold"
6
+ :class="{ 'p-button-outlined': !editor.isActive('bold') }"
7
+ @click="editor.chain().focus().toggleBold().run()" />
8
+ <Button v-if="config.marks.italic" label="I" class="p-button-sm font-italic"
9
+ :class="{ 'p-button-outlined': !editor.isActive('italic') }"
10
+ @click="editor.chain().focus().toggleItalic().run()" />
11
+ <Button v-if="config.marks.underline" label="U" class="p-button-sm underline"
12
+ :class="{ 'p-button-outlined': !editor.isActive('underline') }"
13
+ @click="editor.chain().focus().toggleUnderline().run()" />
14
+ <Button v-if="config.marks.strike" label="S" class="p-button-sm line-through"
15
+ :class="{ 'p-button-outlined': !editor.isActive('strike') }"
16
+ @click="editor.chain().focus().toggleStrike().run()" />
17
+ </div>
18
+
19
+ <div class="p-buttonset mr-1 mb-1">
20
+ <Button v-if="config.nodes.bulletList" icon="fa-solid fa-list-ul" class="p-button-sm"
21
+ :class="{ 'p-button-outlined': !editor.isActive('bulletlist') }"
22
+ @click="editor.chain().focus().toggleBulletList().run()" />
23
+ <Button v-if="config.nodes.orderedList" icon="fa-solid fa-list-ol" class="p-button-sm"
24
+ :class="{ 'p-button-outlined': !editor.isActive('orderedlist') }"
25
+ @click="editor.chain().focus().toggleOrderedList().run()" />
26
+ </div>
27
+
28
+ <div v-if="config.nodes.heading" class="p-buttonset mr-1 mb-1">
29
+ <Button label="H1" class="p-button-sm"
30
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 1 }) }"
31
+ @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" />
32
+ <Button label="H2" class="p-button-sm"
33
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 2 }) }"
34
+ @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" />
35
+ <Button label="H3" class="p-button-sm"
36
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 3 }) }"
37
+ @click="editor.chain().focus().toggleHeading({ level: 3 }).run()" />
38
+ <Button label="H4" class="p-button-sm"
39
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 4 }) }"
40
+ @click="editor.chain().focus().toggleHeading({ level: 4 }).run()" />
41
+ <Button label="H5" class="p-button-sm"
42
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 5 }) }"
43
+ @click="editor.chain().focus().toggleHeading({ level: 5 }).run()" />
44
+ <Button label="H6" class="p-button-sm"
45
+ :class="{ 'p-button-outlined': !editor.isActive('heading', { level: 6 }) }"
46
+ @click="editor.chain().focus().toggleHeading({ level: 6 }).run()" />
47
+ </div>
48
+
49
+ <div class="p-buttonset mr-1 mb-1">
50
+ <Button v-if="config.nodes.blockquote" icon="fa-solid fa-quote-left" class="p-button-sm"
51
+ :class="{ 'p-button-outlined': !editor.isActive('blockquote') }"
52
+ @click="editor.chain().focus().toggleBlockquote().run()" />
53
+ <Button v-if="config.nodes.codeBlock" icon="fa-solid fa-code" class="p-button-sm"
54
+ :class="{ 'p-button-outlined': !editor.isActive('codeblock') }"
55
+ @click="editor.chain().focus().toggleCodeBlock().run()" />
56
+ </div>
57
+
58
+ <div class="p-buttonset mr-1 mb-1">
59
+ <Button v-if="config.nodes.hardBreak" label="BR" class="p-button-sm"
60
+ :class="{ 'p-button-outlined': true }"
61
+ @click="editor.chain().focus().setHardBreak().run()" />
62
+ <Button v-if="config.nodes.horizontalRule" label="HR" class="p-button-sm"
63
+ :class="{ 'p-button-outlined': true }"
64
+ @click="editor.chain().focus().setHorizontalRule().run()" />
65
+ </div>
66
+
67
+ <div class="p-buttonset mr-1 mb-1">
68
+ <!-- <Button v-if="config.nodes.hardBreak" icon="pi pi-image" class="p-button-sm"
69
+ :class="{ 'p-button-outlined': true }"
70
+ @click="editor.chain().focus().setImage().run()" />-->
71
+ <FileInput @input="handleImageUpload" class="inline-block"
72
+ accept="image/png,image/jpeg,image/webp,.jpg,.jpeg,.png,.webp">
73
+ <Button v-if="config.nodes.hardBreak" icon="pi pi-image" class="p-button-sm"
74
+ :class="{ 'p-button-outlined': true }" />
75
+ </FileInput>
76
+ </div>
77
+
78
+ </div>
79
+ </template>
80
+
81
+ <script setup>
82
+ import Button from "primevue/button"
83
+
84
+ import { inject, getCurrentInstance } from "vue"
85
+ import { toRefs } from "@vueuse/core"
86
+ import { uploadImage } from "@live-change/image-frontend"
87
+ import { FileInput } from "@live-change/upload-frontend"
88
+
89
+ const appContext = getCurrentInstance().appContext
90
+ const workingZone = inject('workingZone')
91
+
92
+ const props = defineProps({
93
+ editor: {
94
+ type: Object,
95
+ required: true
96
+ },
97
+ config: {
98
+ type: Object,
99
+ required: true
100
+ }
101
+ })
102
+
103
+ const { editor, config } = toRefs(props)
104
+
105
+ async function handleImageUpload(file) {
106
+ const upload = uploadImage('test', { file },
107
+ { preparedPreview: true, appContext, generateId: true })
108
+ await workingZone.addPromise('disconnectContact', (async () => {
109
+ editor.value.chain().focus().setImage({ image: upload.id }).run()
110
+ await upload.prepare()
111
+ })())
112
+ console.log("START UPLOAD!")
113
+ await upload.upload()
114
+ }
115
+
116
+ window.editor = editor.value
117
+ </script>
118
+
119
+ <style scoped>
120
+ .p-buttonset .p-button:not(:last-child) { /* buttonset bug fix */
121
+ border-right: 0 none !important;
122
+ }
123
+ </style>