move extensions to own package

This commit is contained in:
Philipp Kühn
2018-08-23 22:08:19 +02:00
parent 2ef23d3003
commit e2176f00fd
32 changed files with 420 additions and 65 deletions

View File

@@ -0,0 +1,39 @@
import { Mark } from 'tiptap'
import { toggleMark } from 'tiptap-commands'
export default class BoldMark extends Mark {
get name() {
return 'bold'
}
get schema() {
return {
parseDOM: [
{
tag: 'strong',
},
{
tag: 'b',
getAttrs: node => node.style.fontWeight != 'normal' && null,
},
{
style: 'font-weight',
getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null,
},
],
toDOM: () => ['strong', 0],
}
}
keys({ type }) {
return {
'Mod-b': toggleMark(type),
}
}
command({ type }) {
return toggleMark(type)
}
}

View File

@@ -0,0 +1,29 @@
import { Mark } from 'tiptap'
import { toggleMark } from 'tiptap-commands'
export default class CodeMark extends Mark {
get name() {
return 'code'
}
get schema() {
return {
parseDOM: [
{ tag: 'code' },
],
toDOM: () => ['code', 0],
}
}
keys({ type }) {
return {
'Mod-`': toggleMark(type),
}
}
command({ type }) {
return toggleMark(type)
}
}

View File

@@ -0,0 +1,31 @@
import { Mark } from 'tiptap'
import { toggleMark } from 'tiptap-commands'
export default class ItalicMark extends Mark {
get name() {
return 'italic'
}
get schema() {
return {
parseDOM: [
{ tag: 'i' },
{ tag: 'em' },
{ style: 'font-style=italic' },
],
toDOM: () => ['em', 0],
}
}
keys({ type }) {
return {
'Mod-i': toggleMark(type),
}
}
command({ type }) {
return toggleMark(type)
}
}

View File

@@ -0,0 +1,55 @@
import { Mark } from 'tiptap'
import { updateMark, removeMark } from 'tiptap-commands'
export default class LinkMark extends Mark {
get name() {
return 'link'
}
get view() {
return {
props: ['node'],
methods: {
onClick() {
console.log('click on link')
},
},
template: `
<a :href="node.attrs.href" rel="noopener noreferrer nofollow" ref="content" @click="onClick"></a>
`,
}
}
get schema() {
return {
attrs: {
href: {
default: null,
},
},
inclusive: false,
parseDOM: [
{
tag: 'a[href]',
getAttrs: dom => ({
href: dom.getAttribute('href'),
}),
},
],
toDOM: node => ['a', {
...node.attrs,
rel: 'noopener noreferrer nofollow',
}, 0],
}
}
command({ type, attrs }) {
if (attrs.href) {
return updateMark(type, attrs)
}
return removeMark(type)
}
}