mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
Merge branch 'main' of https://github.com/ueberdosis/tiptap-next into main
# Conflicts: # docs/src/demos/Experiments/Comments/index.vue
This commit is contained in:
commit
c1531b5ab2
@ -1,6 +1,6 @@
|
||||
context('/demos/Extensions/Annotations', () => {
|
||||
context('/demos/Experiments/Annotation', () => {
|
||||
before(() => {
|
||||
cy.visit('/demos/Extensions/Annotations')
|
||||
cy.visit('/demos/Experiments/Annotation')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
|
@ -1,17 +1,33 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="editor">
|
||||
<button @click="addAnnotation" :disabled="!editor.can().addAnnotation()">
|
||||
add annotation
|
||||
<h2>
|
||||
Original Editor
|
||||
</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="deleteAnnotation(comment.type.spec.data.id)">
|
||||
<button @click="deleteComment(comment.type.spec.data.id)">
|
||||
remove
|
||||
</button>
|
||||
</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>
|
||||
</template>
|
||||
@ -21,6 +37,10 @@ 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 Annotation from './extension'
|
||||
|
||||
export default {
|
||||
@ -31,19 +51,29 @@ export default {
|
||||
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>
|
||||
@ -54,21 +84,49 @@ export default {
|
||||
</p>
|
||||
`,
|
||||
})
|
||||
|
||||
this.anotherEditor = new Editor({
|
||||
extensions: [
|
||||
Document,
|
||||
Paragraph,
|
||||
Text,
|
||||
Bold,
|
||||
Heading,
|
||||
Annotation.configure({
|
||||
document: this.ydoc,
|
||||
}),
|
||||
Collaboration.configure({
|
||||
document: this.ydoc,
|
||||
}),
|
||||
],
|
||||
})
|
||||
},
|
||||
|
||||
methods: {
|
||||
addAnnotation() {
|
||||
const content = prompt('Annotation', '')
|
||||
addComment() {
|
||||
const content = prompt('Comment', '')
|
||||
|
||||
this.editor.commands.addAnnotation(content)
|
||||
},
|
||||
deleteAnnotation(id) {
|
||||
addAnotherComment() {
|
||||
const content = prompt('Comment', '')
|
||||
|
||||
this.anotherEditor.commands.addAnnotation(content)
|
||||
},
|
||||
deleteComment(id) {
|
||||
this.editor.commands.deleteAnnotation(id)
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
json() {
|
||||
return this.ydoc.toJSON()
|
||||
},
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
this.anotherEditor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -1,7 +0,0 @@
|
||||
context('/demos/Examples/Annotations', () => {
|
||||
before(() => {
|
||||
cy.visit('/demos/Examples/Annotations')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
})
|
@ -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 you’re 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>
|
@ -3,7 +3,6 @@ Congratulations! You’ve found our playground with a list of experiments. Be aw
|
||||
|
||||
## New
|
||||
* [Linter](/experiments/linter)
|
||||
* [Annotation](/experiments/annotation)
|
||||
* [Comments](/experiments/comments)
|
||||
* [Color](/experiments/color)
|
||||
* [Commands](/experiments/commands)
|
||||
|
@ -1,5 +0,0 @@
|
||||
# Annotation
|
||||
|
||||
⚠️ Experiment
|
||||
|
||||
<demo name="Experiments/Annotation" />
|
@ -2,4 +2,4 @@
|
||||
|
||||
⚠️ Experiment
|
||||
|
||||
<demo name="Experiments/Comments" />
|
||||
<demo name="Experiments/Annotation" />
|
||||
|
Loading…
Reference in New Issue
Block a user