Merge branch 'main' into feature/extension-code-block-lowlight

# Conflicts:
#	docs/src/docPages/api/nodes/code-block-lowlight.md
#	docs/src/links.yaml
This commit is contained in:
Philipp Kühn
2021-04-04 23:13:52 +02:00
64 changed files with 981 additions and 277 deletions

View File

@@ -15,7 +15,10 @@ export default () => {
],
content: `
<p>
Hey, try to select some text here. There will popup a menu for selecting some inline styles. Remember: you have full control about content and styling of this menu.
Try to select <em>this text</em> to see what we call the bubble menu.
</p>
<p>
Neat, isnt it? Add an empty paragraph to see the floating menu.
</p>
`,
})
@@ -27,19 +30,19 @@ export default () => {
onClick={() => editor.chain().focus().toggleBold().run()}
className={editor.isActive('bold') ? 'is-active' : ''}
>
bold
Bold
</button>
<button
onClick={() => editor.chain().focus().toggleItalic().run()}
className={editor.isActive('italic') ? 'is-active' : ''}
>
italic
Italic
</button>
<button
onClick={() => editor.chain().focus().toggleStrike().run()}
className={editor.isActive('strike') ? 'is-active' : ''}
>
strike
Strike
</button>
</BubbleMenu>}
@@ -48,19 +51,19 @@ export default () => {
onClick={() => editor.chain().focus().toggleHeading({ level: 1 }).run()}
className={editor.isActive('heading', { level: 1 }) ? 'is-active' : ''}
>
h1
H1
</button>
<button
onClick={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
className={editor.isActive('heading', { level: 2 }) ? 'is-active' : ''}
>
h2
H2
</button>
<button
onClick={() => editor.chain().focus().toggleBulletList().run()}
className={editor.isActive('bulletList') ? 'is-active' : ''}
>
bullet list
Bullet List
</button>
</FloatingMenu>}

View File

@@ -2,25 +2,25 @@
<div style="position: relative">
<bubble-menu class="bubble-menu" :editor="editor" v-if="editor">
<button @click="editor.chain().focus().toggleBold().run()" :class="{ 'is-active': editor.isActive('bold') }">
bold
Bold
</button>
<button @click="editor.chain().focus().toggleItalic().run()" :class="{ 'is-active': editor.isActive('italic') }">
italic
Italic
</button>
<button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
strike
Strike
</button>
</bubble-menu>
<floating-menu class="floating-menu" :editor="editor" v-if="editor">
<button @click="editor.chain().focus().toggleHeading({ level: 1 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 1 }) }">
h1
H1
</button>
<button @click="editor.chain().focus().toggleHeading({ level: 2 }).run()" :class="{ 'is-active': editor.isActive('heading', { level: 2 }) }">
h2
H2
</button>
<button @click="editor.chain().focus().toggleBulletList().run()" :class="{ 'is-active': editor.isActive('bulletList') }">
bullet list
Bullet List
</button>
</floating-menu>
@@ -57,7 +57,10 @@ export default {
],
content: `
<p>
Hey, try to select some text here. Youll see a formatting menu pop up. And as always, you are in full control about content and styling of this menu.
Try to select <em>this text</em> to see what we call the bubble menu.
</p>
<p>
Neat, isnt it? Add an empty paragraph to see the floating menu.
</p>
`,
})

View File

@@ -10,8 +10,9 @@ export default () => {
],
content: `
<p>
This is an example of a medium-like editor. Enter a new line and some buttons will appear.
This is an example of a Medium-like editor. Enter a new line and some buttons will appear.
</p>
<p></p>
`,
})

View File

@@ -38,8 +38,9 @@ export default {
],
content: `
<p>
This is an example of a medium-like editor. Enter a new line and some buttons will appear.
This is an example of a Medium-like editor. Enter a new line and some buttons will appear.
</p>
<p></p>
`,
})
},

View File

@@ -3,49 +3,50 @@
</template>
<script>
// Option 1: Browser + server-side
import { generateHTML } from '@tiptap/html'
// Option 2: Browser-only (lightweight)
// import { generateHTML } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Bold from '@tiptap/extension-bold'
export default {
data() {
return {
output: '',
json: {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Example ',
},
{
type: 'text',
marks: [
{
type: 'bold',
},
],
text: 'Text',
},
],
},
],
},
}
},
const json = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Example ',
},
{
type: 'text',
marks: [
{
type: 'bold',
},
],
text: 'Text',
},
],
},
],
}
mounted() {
this.output = generateHTML(this.json, [
Document,
Paragraph,
Text,
Bold,
])
export default {
computed: {
output() {
return generateHTML(json, [
Document,
Paragraph,
Text,
Bold,
// other extensions …
])
},
},
}
</script>

View File

@@ -0,0 +1,77 @@
import { Node, mergeAttributes } from '@tiptap/core'
export default Node.create({
name: 'nodeView',
group: 'block',
atom: true,
addAttributes() {
return {
count: {
default: 0,
},
}
},
parseHTML() {
return [
{
tag: 'node-view',
},
]
},
renderHTML({ HTMLAttributes }) {
return ['node-view', mergeAttributes(HTMLAttributes)]
},
addNodeView() {
return ({ editor, node, getPos }) => {
const { view } = editor
// Markup
/*
<div class="node-view">
<span class="label">Node view</span>
<div class="content">
<button>
This button has been clicked ${node.attrs.count} times.
</button>
</div>
</div>
*/
const dom = document.createElement('div')
dom.classList.add('node-view')
const label = document.createElement('span')
label.classList.add('label')
label.innerHTML = 'Node view'
const content = document.createElement('div')
content.classList.add('content')
const button = document.createElement('button')
button.innerHTML = `This button has been clicked ${node.attrs.count} times.`
button.addEventListener('click', () => {
if (typeof getPos === 'function') {
view.dispatch(view.state.tr.setNodeMarkup(getPos(), undefined, {
count: node.attrs.count + 1,
}))
editor.commands.focus()
}
})
content.append(button)
dom.append(label, content)
return {
dom,
}
}
},
})

View File

@@ -5,7 +5,7 @@
<script>
import { Editor, EditorContent } from '@tiptap/vue-2'
import { defaultExtensions } from '@tiptap/starter-kit'
import VueComponent from './index.js'
import NodeView from './Extension.js'
export default {
components: {
@@ -22,13 +22,13 @@ export default {
this.editor = new Editor({
extensions: [
...defaultExtensions(),
VueComponent,
NodeView,
],
content: `
<p>
This is still the text editor youre used to, but enriched with node views.
</p>
<node-view count="0"></node-view>
<node-view></node-view>
<p>
Did you see that? Thats a JavaScript node view. We are really living in the future.
</p>
@@ -52,7 +52,8 @@ export default {
::v-deep {
.node-view {
border: 1px solid #adb5bd;
background: #FAF594;
border: 3px solid #0D0D0D;
border-radius: 0.5rem;
margin: 1rem 0;
position: relative;
@@ -60,7 +61,7 @@ export default {
.label {
margin-left: 1rem;
background-color: #adb5bd;
background-color: #0D0D0D;
font-size: 0.6rem;
letter-spacing: 1px;
font-weight: bold;
@@ -73,7 +74,8 @@ export default {
}
.content {
margin: 2.5rem 1rem 1rem;
margin-top: 1.5rem;
padding: 1rem;
}
}
</style>

View File

@@ -5,15 +5,7 @@ export default Node.create({
group: 'block',
atom: true,
addAttributes() {
return {
count: {
default: 0,
},
}
},
content: 'inline*',
parseHTML() {
return [
@@ -29,32 +21,32 @@ export default Node.create({
addNodeView() {
return () => {
// Markup
/*
<div class="node-view">
<span class="label">Node view</span>
<div class="content"></div>
</div>
*/
const dom = document.createElement('div')
dom.classList.add('node-view')
const label = document.createElement('span')
label.classList.add('label')
label.innerHTML = 'Node View'
label.innerHTML = 'Node view'
label.contentEditable = false
const content = document.createElement('div')
content.classList.add('content')
content.innerHTML = 'Im rendered with JavaScript.'
dom.append(label, content)
return {
dom,
contentDOM: content,
}
}
},
})
// <node-view-wrapper class="vue-component">
// <span class="label">Vue Component</span>
// <div class="content">
// <button @click="increase">
// This button has been clicked {{ node.attrs.count }} times.
// </button>
// </div>
// </node-view-wrapper>

View File

@@ -0,0 +1,85 @@
<template>
<editor-content :editor="editor" />
</template>
<script>
import { Editor, EditorContent } from '@tiptap/vue-2'
import { defaultExtensions } from '@tiptap/starter-kit'
import NodeView from './Extension.js'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
...defaultExtensions(),
NodeView,
],
content: `
<p>
This is still the text editor youre used to, but enriched with node views.
</p>
<node-view>
<p>This is editable.</p>
</node-view>
<p>
Did you see that? Thats a JavaScript node view. We are really living in the future.
</p>
`,
})
},
beforeDestroy() {
this.editor.destroy()
},
}
</script>
<style lang="scss" scoped>
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
::v-deep {
.node-view {
background: #FAF594;
border: 3px solid #0D0D0D;
border-radius: 0.5rem;
margin: 1rem 0;
position: relative;
}
.label {
margin-left: 1rem;
background-color: #0D0D0D;
font-size: 0.6rem;
letter-spacing: 1px;
font-weight: bold;
text-transform: uppercase;
color: #fff;
position: absolute;
top: 0;
padding: 0.25rem 0.75rem;
border-radius: 0 0 0.5rem 0.5rem;
}
.content {
margin: 2.5rem 1rem 1rem;
padding: 0.5rem;
border: 2px dashed #0D0D0D20;
border-radius: 0.5rem;
}
}
</style>