docs: update extension examples

This commit is contained in:
Hans Pagel
2021-10-19 21:28:48 +02:00
parent 71077f6d62
commit 3fe97621e7
11 changed files with 69 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ 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 Collaboration from '@tiptap/extension-collaboration'
import Placeholder from '@tiptap/extension-placeholder'
import * as Y from 'yjs' import * as Y from 'yjs'
import { WebrtcProvider } from 'y-webrtc' import { WebrtcProvider } from 'y-webrtc'
@@ -35,6 +36,9 @@ export default {
Collaboration.configure({ Collaboration.configure({
document: ydoc, document: ydoc,
}), }),
Placeholder.configure({
placeholder: 'Write something … Itll be shared with everyone else looking at this example.',
}),
], ],
}) })
}, },
@@ -45,3 +49,21 @@ export default {
}, },
} }
</script> </script>
<style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
/* Placeholder (at the top) */
.ProseMirror p.is-editor-empty:first-child::before {
content: attr(data-placeholder);
float: left;
color: #adb5bd;
pointer-events: none;
height: 0;
}
</style>

View File

@@ -11,6 +11,7 @@ import Collaboration from '@tiptap/extension-collaboration'
import CollaborationCursor from '@tiptap/extension-collaboration-cursor' import CollaborationCursor from '@tiptap/extension-collaboration-cursor'
import * as Y from 'yjs' import * as Y from 'yjs'
import { WebrtcProvider } from 'y-webrtc' import { WebrtcProvider } from 'y-webrtc'
import Placeholder from '@tiptap/extension-placeholder'
export default { export default {
components: { components: {
@@ -43,6 +44,9 @@ export default {
color: '#f783ac', color: '#f783ac',
}, },
}), }),
Placeholder.configure({
placeholder: 'Write something … Itll be shared with everyone else looking at this example.',
}),
], ],
}) })
}, },
@@ -55,6 +59,22 @@ export default {
</script> </script>
<style lang="scss"> <style lang="scss">
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
/* Placeholder (at the top) */
.ProseMirror p.is-editor-empty:first-child::before {
content: attr(data-placeholder);
float: left;
color: #adb5bd;
pointer-events: none;
height: 0;
}
/* Give a remote user a caret */ /* Give a remote user a caret */
.collaboration-cursor__caret { .collaboration-cursor__caret {
position: relative; position: relative;

View File

@@ -27,7 +27,7 @@
green green
</button> </button>
<button @click="editor.chain().focus().unsetColor().run()"> <button @click="editor.chain().focus().unsetColor().run()">
remove color unsetColor
</button> </button>
<editor-content :editor="editor" /> <editor-content :editor="editor" />

View File

@@ -1,7 +1,5 @@
<template> <template>
<div> <editor-content :editor="editor" />
<editor-content :editor="editor" />
</div>
</template> </template>
<script> <script>

View File

@@ -2,13 +2,13 @@
<div> <div>
<floating-menu :editor="editor" v-if="editor"> <floating-menu :editor="editor" v-if="editor">
<button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }"> <button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
h1 H1
</button> </button>
<button @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }"> <button @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
h2 H2
</button> </button>
<button @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }"> <button @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }">
bullet list Bullet List
</button> </button>
</floating-menu> </floating-menu>
<editor-content :editor="editor" /> <editor-content :editor="editor" />

View File

@@ -81,8 +81,12 @@ export default {
} }
code { code {
font-size: 0.9rem;
padding: 0.25em;
border-radius: 0.25em;
background-color: rgba(#616161, 0.1); background-color: rgba(#616161, 0.1);
color: #616161; color: #616161;
box-decoration-break: clone;
} }
} }
</style> </style>

View File

@@ -16,7 +16,7 @@
cursive cursive
</button> </button>
<button @click="editor.chain().focus().unsetFontFamily().run()"> <button @click="editor.chain().focus().unsetFontFamily().run()">
Remove font-family unsetFontFamily
</button> </button>
<editor-content :editor="editor" /> <editor-content :editor="editor" />

View File

@@ -1,7 +1,5 @@
<template> <template>
<div> <editor-content :editor="editor" />
<editor-content :editor="editor" />
</div>
</template> </template>
<script> <script>

View File

@@ -22,7 +22,18 @@ export default {
this.editor = new Editor({ this.editor = new Editor({
extensions: [ extensions: [
StarterKit, StarterKit,
Placeholder, Placeholder.configure({
// Use a placeholder:
placeholder: 'Write something …',
// Use different placeholders depending on the node type:
// placeholder: ({ node }) => {
// if (node.type.name === 'heading') {
// return 'Whats the title?'
// }
// return 'Can you add some further context?'
// },
}),
], ],
}) })
}, },
@@ -45,7 +56,7 @@ export default {
.ProseMirror p.is-editor-empty:first-child::before { .ProseMirror p.is-editor-empty:first-child::before {
content: attr(data-placeholder); content: attr(data-placeholder);
float: left; float: left;
color: #ced4da; color: #adb5bd;
pointer-events: none; pointer-events: none;
height: 0; height: 0;
} }
@@ -54,7 +65,7 @@ export default {
/*.ProseMirror p.is-empty::before { /*.ProseMirror p.is-empty::before {
content: attr(data-placeholder); content: attr(data-placeholder);
float: left; float: left;
color: #ced4da; color: #adb5bd;
pointer-events: none; pointer-events: none;
height: 0; height: 0;
}*/ }*/

View File

@@ -13,7 +13,7 @@
justify justify
</button> </button>
<button @click="editor.chain().focus().unsetTextAlign().run()"> <button @click="editor.chain().focus().unsetTextAlign().run()">
set default unsetTextAlign
</button> </button>
<editor-content :editor="editor" /> <editor-content :editor="editor" />
</div> </div>

View File

@@ -1,7 +1,5 @@
<template> <template>
<div> <editor-content :editor="editor" />
<editor-content :editor="editor" />
</div>
</template> </template>
<script> <script>