# Conflicts:
#	docs/src/demos/Experiments/Comments/index.vue
This commit is contained in:
Philipp Kühn 2021-02-11 22:52:07 +01:00
commit c1531b5ab2
7 changed files with 67 additions and 168 deletions

View File

@ -1,6 +1,6 @@
context('/demos/Extensions/Annotations', () => { context('/demos/Experiments/Annotation', () => {
before(() => { before(() => {
cy.visit('/demos/Extensions/Annotations') cy.visit('/demos/Experiments/Annotation')
}) })
// TODO: Write tests // TODO: Write tests

View File

@ -1,17 +1,33 @@
<template> <template>
<div> <div>
<div v-if="editor"> <div v-if="editor">
<button @click="addAnnotation" :disabled="!editor.can().addAnnotation()"> <h2>
add annotation Original Editor
</h2>
<button @click="addComment" :disabled="!editor.can().addAnnotation()">
comment
</button> </button>
<editor-content :editor="editor" /> <editor-content :editor="editor" />
<div v-for="comment in comments" :key="comment.type.spec.data.id"> <div v-for="comment in comments" :key="comment.type.spec.data.id">
{{ comment.type.spec.data }} {{ comment.type.spec.data }}
<button @click="deleteAnnotation(comment.type.spec.data.id)"> <button @click="deleteComment(comment.type.spec.data.id)">
remove remove
</button> </button>
</div> </div>
<h2>
Another Editor
</h2>
<button @click="addAnotherComment" :disabled="!anotherEditor.can().addAnnotation()">
comment
</button>
<editor-content :editor="anotherEditor" />
<h2>
Y.js document
</h2>
{{ json }}
</div> </div>
</div> </div>
</template> </template>
@ -21,6 +37,10 @@ import { Editor, EditorContent } from '@tiptap/vue-starter-kit'
import Document from '@tiptap/extension-document' import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph' import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text' import Text from '@tiptap/extension-text'
import Collaboration from '@tiptap/extension-collaboration'
import Bold from '@tiptap/extension-bold'
import Heading from '@tiptap/extension-heading'
import * as Y from 'yjs'
import Annotation from './extension' import Annotation from './extension'
export default { export default {
@ -31,19 +51,29 @@ export default {
data() { data() {
return { return {
editor: null, editor: null,
anotherEditor: null,
comments: [], comments: [],
ydoc: null,
} }
}, },
mounted() { mounted() {
this.ydoc = new Y.Doc()
this.editor = new Editor({ this.editor = new Editor({
extensions: [ extensions: [
Document, Document,
Paragraph, Paragraph,
Text, Text,
Bold,
Heading,
Annotation.configure({ Annotation.configure({
document: this.ydoc,
onUpdate: items => { this.comments = items }, onUpdate: items => { this.comments = items },
}), }),
Collaboration.configure({
document: this.ydoc,
}),
], ],
content: ` content: `
<p> <p>
@ -54,21 +84,49 @@ export default {
</p> </p>
`, `,
}) })
this.anotherEditor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Bold,
Heading,
Annotation.configure({
document: this.ydoc,
}),
Collaboration.configure({
document: this.ydoc,
}),
],
})
}, },
methods: { methods: {
addAnnotation() { addComment() {
const content = prompt('Annotation', '') const content = prompt('Comment', '')
this.editor.commands.addAnnotation(content) this.editor.commands.addAnnotation(content)
}, },
deleteAnnotation(id) { addAnotherComment() {
const content = prompt('Comment', '')
this.anotherEditor.commands.addAnnotation(content)
},
deleteComment(id) {
this.editor.commands.deleteAnnotation(id) this.editor.commands.deleteAnnotation(id)
}, },
}, },
computed: {
json() {
return this.ydoc.toJSON()
},
},
beforeDestroy() { beforeDestroy() {
this.editor.destroy() this.editor.destroy()
this.anotherEditor.destroy()
}, },
} }
</script> </script>

View File

@ -1,7 +0,0 @@
context('/demos/Examples/Annotations', () => {
before(() => {
cy.visit('/demos/Examples/Annotations')
})
// TODO: Write tests
})

View File

@ -1,146 +0,0 @@
<template>
<div>
<div v-if="editor">
<h2>
Original
</h2>
<button @click="addComment" :disabled="!editor.can().addAnnotation()">
comment
</button>
<editor-content :editor="editor" />
<div v-for="comment in comments" :key="comment.type.spec.data.id">
{{ comment.type.spec.data }}
<button @click="deleteComment(comment.type.spec.data.id)">
remove
</button>
</div>
<!-- <br>
<h2>
ProseMirror JSON from Y.js document
</h2>
{{ rawDocument }} -->
<br>
<h2>
Y.js document
</h2>
{{ json }}
<br>
<h2>
Mirror
</h2>
<editor-content :editor="anotherEditor" />
</div>
</div>
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-starter-kit'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Collaboration from '@tiptap/extension-collaboration'
import Bold from '@tiptap/extension-bold'
import Heading from '@tiptap/extension-heading'
import * as Y from 'yjs'
import { yDocToProsemirrorJSON } from 'y-prosemirror'
import Annotation from '../Annotation/extension'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
anotherEditor: null,
comments: [],
ydoc: null,
}
},
mounted() {
this.ydoc = new Y.Doc()
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Bold,
Heading,
Annotation.configure({
document: this.ydoc,
onUpdate: items => { this.comments = items },
}),
Collaboration.configure({
document: this.ydoc,
}),
],
content: `
<p>
Annotations can be used to add additional information to the content, for example comments. They live on a different level than the actual editor content.
</p>
<p>
This example allows you to add plain text, but youre free to add more complex data, for example JSON from another tiptap instance. :-)
</p>
`,
})
this.anotherEditor = new Editor({
extensions: [
Document,
Paragraph,
Text,
// Annotation.configure({
// onUpdate: items => { this.comments = items },
// }),
Collaboration.configure({
document: this.ydoc,
}),
],
})
},
methods: {
addComment() {
const content = prompt('Comment', '')
this.editor.commands.addAnnotation(content)
},
deleteComment(id) {
this.editor.commands.deleteAnnotation(id)
},
},
computed: {
rawDocument() {
return yDocToProsemirrorJSON(this.ydoc, 'default')
},
json() {
return this.ydoc.toJSON()
},
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
.annotation {
background: #9DEF8F;
}
</style>

View File

@ -3,7 +3,6 @@ Congratulations! Youve found our playground with a list of experiments. Be aw
## New ## New
* [Linter](/experiments/linter) * [Linter](/experiments/linter)
* [Annotation](/experiments/annotation)
* [Comments](/experiments/comments) * [Comments](/experiments/comments)
* [Color](/experiments/color) * [Color](/experiments/color)
* [Commands](/experiments/commands) * [Commands](/experiments/commands)

View File

@ -1,5 +0,0 @@
# Annotation
⚠️ Experiment
<demo name="Experiments/Annotation" />

View File

@ -2,4 +2,4 @@
⚠️ Experiment ⚠️ Experiment
<demo name="Experiments/Comments" /> <demo name="Experiments/Annotation" />