Merge branch 'master' of git://github.com/scrumpy/tiptap
This commit is contained in:
32
examples/Components/Routes/DragHandle/DragItem.js
Normal file
32
examples/Components/Routes/DragHandle/DragItem.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Node } from 'tiptap'
|
||||||
|
|
||||||
|
export default class DragItem extends Node {
|
||||||
|
|
||||||
|
get name() {
|
||||||
|
return 'drag_item'
|
||||||
|
}
|
||||||
|
|
||||||
|
get schema() {
|
||||||
|
return {
|
||||||
|
group: 'block',
|
||||||
|
draggable: true,
|
||||||
|
content: 'paragraph+',
|
||||||
|
toDOM: () => ['div', { 'data-type': this.name }, 0],
|
||||||
|
parseDOM: [{
|
||||||
|
tag: `[data-type="${this.name}"]`,
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get view() {
|
||||||
|
return {
|
||||||
|
template: `
|
||||||
|
<div data-type="drag_item">
|
||||||
|
<div ref="content" contenteditable="true"></div>
|
||||||
|
<div data-drag-handle contenteditable="false"></div>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
70
examples/Components/Routes/DragHandle/index.vue
Normal file
70
examples/Components/Routes/DragHandle/index.vue
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<template>
|
||||||
|
<div class="editor">
|
||||||
|
<editor-content class="editor__content" :editor="editor" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import Icon from 'Components/Icon'
|
||||||
|
import { Editor, EditorContent } from 'tiptap'
|
||||||
|
import { Heading, Code } from 'tiptap-extensions'
|
||||||
|
import DragItem from './DragItem'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
Icon,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
editor: new Editor({
|
||||||
|
extensions: [
|
||||||
|
new Heading(),
|
||||||
|
new Code(),
|
||||||
|
new DragItem(),
|
||||||
|
],
|
||||||
|
content: `
|
||||||
|
<h2>
|
||||||
|
Drag Handle
|
||||||
|
</h2>
|
||||||
|
<p>
|
||||||
|
Add <code>data-drag-handle</code> to a DOM element within your node view to define your custom drag handle.
|
||||||
|
</p>
|
||||||
|
<div data-type="drag_item">
|
||||||
|
Drag me!
|
||||||
|
</div>
|
||||||
|
<div data-type="drag_item">
|
||||||
|
Try it!
|
||||||
|
</div>
|
||||||
|
<div data-type="drag_item">
|
||||||
|
It works!
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.destroy()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
[data-type="drag_item"] {
|
||||||
|
display: flex;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background-color: rgba(black, 0.05);
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
|
||||||
|
> :first-child {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
> :last-child {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-left: auto;
|
||||||
|
cursor: move;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -60,6 +60,9 @@
|
|||||||
<router-link class="subnavigation__link" to="/trailing-paragraph">
|
<router-link class="subnavigation__link" to="/trailing-paragraph">
|
||||||
Trailing Paragraph
|
Trailing Paragraph
|
||||||
</router-link>
|
</router-link>
|
||||||
|
<router-link class="subnavigation__link" to="/drag-handle">
|
||||||
|
Drag Handle
|
||||||
|
</router-link>
|
||||||
<router-link class="subnavigation__link" to="/export">
|
<router-link class="subnavigation__link" to="/export">
|
||||||
Export HTML or JSON
|
Export HTML or JSON
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|||||||
@@ -151,6 +151,13 @@ const routes = [
|
|||||||
githubUrl: 'https://github.com/scrumpy/tiptap/tree/master/examples/Components/Routes/TrailingParagraph',
|
githubUrl: 'https://github.com/scrumpy/tiptap/tree/master/examples/Components/Routes/TrailingParagraph',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/drag-handle',
|
||||||
|
component: () => import('Components/Routes/DragHandle'),
|
||||||
|
meta: {
|
||||||
|
githubUrl: 'https://github.com/scrumpy/tiptap/tree/master/examples/Components/Routes/DragHandle',
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/export',
|
path: '/export',
|
||||||
component: () => import('Components/Routes/Export'),
|
component: () => import('Components/Routes/Export'),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tiptap-extensions",
|
"name": "tiptap-extensions",
|
||||||
"version": "1.28.0",
|
"version": "1.28.1",
|
||||||
"description": "Extensions for tiptap",
|
"description": "Extensions for tiptap",
|
||||||
"homepage": "https://tiptap.scrumpy.io",
|
"homepage": "https://tiptap.scrumpy.io",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
"prosemirror-transform": "^1.1.4",
|
"prosemirror-transform": "^1.1.4",
|
||||||
"prosemirror-utils": "^0.9.6",
|
"prosemirror-utils": "^0.9.6",
|
||||||
"prosemirror-view": "^1.11.4",
|
"prosemirror-view": "^1.11.4",
|
||||||
"tiptap": "^1.26.0",
|
"tiptap": "^1.26.1",
|
||||||
"tiptap-commands": "^1.12.0"
|
"tiptap-commands": "^1.12.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
fixTables,
|
fixTables,
|
||||||
} from 'prosemirror-tables'
|
} from 'prosemirror-tables'
|
||||||
import { createTable } from 'prosemirror-utils'
|
import { createTable } from 'prosemirror-utils'
|
||||||
|
import { TextSelection } from 'prosemirror-state'
|
||||||
import TableNodes from './TableNodes'
|
import TableNodes from './TableNodes'
|
||||||
|
|
||||||
export default class Table extends Node {
|
export default class Table extends Node {
|
||||||
@@ -43,6 +44,11 @@ export default class Table extends Node {
|
|||||||
(state, dispatch) => {
|
(state, dispatch) => {
|
||||||
const nodes = createTable(schema, rowsCount, colsCount, withHeaderRow)
|
const nodes = createTable(schema, rowsCount, colsCount, withHeaderRow)
|
||||||
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
|
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView()
|
||||||
|
|
||||||
|
// get selection for first cell
|
||||||
|
const resolvedPos = tr.doc.resolve(tr.selection.anchor - nodes.content.size)
|
||||||
|
tr.setSelection(TextSelection.near(resolvedPos))
|
||||||
|
|
||||||
dispatch(tr)
|
dispatch(tr)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tiptap",
|
"name": "tiptap",
|
||||||
"version": "1.26.0",
|
"version": "1.26.1",
|
||||||
"description": "A rich-text editor for Vue.js",
|
"description": "A rich-text editor for Vue.js",
|
||||||
"homepage": "https://tiptap.scrumpy.io",
|
"homepage": "https://tiptap.scrumpy.io",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -91,7 +91,10 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hide(event) {
|
hide(event) {
|
||||||
if (event && event.relatedTarget) {
|
if (event
|
||||||
|
&& event.relatedTarget
|
||||||
|
&& this.options.element.parentNode.contains(event.relatedTarget)
|
||||||
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ class Menu {
|
|||||||
this.isActive = false
|
this.isActive = false
|
||||||
this.left = 0
|
this.left = 0
|
||||||
this.bottom = 0
|
this.bottom = 0
|
||||||
|
this.top = 0
|
||||||
|
|
||||||
// the mousedown event is fired before blur so we can prevent it
|
// the mousedown event is fired before blur so we can prevent it
|
||||||
this.options.element.addEventListener('mousedown', this.handleClick)
|
this.options.element.addEventListener('mousedown', this.handleClick)
|
||||||
@@ -129,6 +130,7 @@ class Menu {
|
|||||||
this.left = Math.round(this.options.keepInBounds
|
this.left = Math.round(this.options.keepInBounds
|
||||||
? Math.min(box.width - (el.width / 2), Math.max(left, el.width / 2)) : left)
|
? Math.min(box.width - (el.width / 2), Math.max(left, el.width / 2)) : left)
|
||||||
this.bottom = Math.round(box.bottom - start.top)
|
this.bottom = Math.round(box.bottom - start.top)
|
||||||
|
this.top = Math.round(end.bottom - box.top)
|
||||||
this.isActive = true
|
this.isActive = true
|
||||||
|
|
||||||
this.sendUpdate()
|
this.sendUpdate()
|
||||||
@@ -139,11 +141,15 @@ class Menu {
|
|||||||
isActive: this.isActive,
|
isActive: this.isActive,
|
||||||
left: this.left,
|
left: this.left,
|
||||||
bottom: this.bottom,
|
bottom: this.bottom,
|
||||||
|
top: this.top,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
hide(event) {
|
hide(event) {
|
||||||
if (event && event.relatedTarget) {
|
if (event
|
||||||
|
&& event.relatedTarget
|
||||||
|
&& this.options.element.parentNode.contains(event.relatedTarget)
|
||||||
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user