mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-16 03:39:00 +08:00
Merge branch 'master' into markdown-paste
This commit is contained in:
commit
d9b2e2054d
@ -29,7 +29,11 @@ body, .usertext {
|
|||||||
|
|
||||||
|
|
||||||
export const ExplicitImportExample = `import javascript from 'highlight.js/lib/languages/javascript'
|
export const ExplicitImportExample = `import javascript from 'highlight.js/lib/languages/javascript'
|
||||||
|
import css from 'highlight.js/lib/languages/css'
|
||||||
import { Editor } from 'tiptap'
|
import { Editor } from 'tiptap'
|
||||||
|
import {
|
||||||
|
CodeBlockHighlight,
|
||||||
|
} from 'tiptap-extensions'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -38,7 +42,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
extensions: [
|
extensions: [
|
||||||
new CodeBlockHighlightNode({
|
new CodeBlockHighlight({
|
||||||
languages: {
|
languages: {
|
||||||
javascript,
|
javascript,
|
||||||
css,
|
css,
|
||||||
|
14
packages/tiptap-commands/src/commands/nodeInputRule.js
Normal file
14
packages/tiptap-commands/src/commands/nodeInputRule.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { InputRule } from 'prosemirror-inputrules'
|
||||||
|
|
||||||
|
export default function (regexp, type, getAttrs) {
|
||||||
|
return new InputRule(regexp, (state, match, start, end) => {
|
||||||
|
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
|
||||||
|
const { tr } = state
|
||||||
|
|
||||||
|
if (match[0]) {
|
||||||
|
tr.replaceWith(start - 1, end, type.create(attrs))
|
||||||
|
}
|
||||||
|
|
||||||
|
return tr
|
||||||
|
})
|
||||||
|
}
|
@ -40,6 +40,7 @@ import {
|
|||||||
|
|
||||||
import insertText from './commands/insertText'
|
import insertText from './commands/insertText'
|
||||||
import markInputRule from './commands/markInputRule'
|
import markInputRule from './commands/markInputRule'
|
||||||
|
import nodeInputRule from './commands/nodeInputRule'
|
||||||
import pasteRule from './commands/pasteRule'
|
import pasteRule from './commands/pasteRule'
|
||||||
import markPasteRule from './commands/markPasteRule'
|
import markPasteRule from './commands/markPasteRule'
|
||||||
import removeMark from './commands/removeMark'
|
import removeMark from './commands/removeMark'
|
||||||
@ -93,6 +94,7 @@ export {
|
|||||||
insertText,
|
insertText,
|
||||||
markInputRule,
|
markInputRule,
|
||||||
markPasteRule,
|
markPasteRule,
|
||||||
|
nodeInputRule,
|
||||||
pasteRule,
|
pasteRule,
|
||||||
removeMark,
|
removeMark,
|
||||||
replaceText,
|
replaceText,
|
||||||
|
@ -122,13 +122,16 @@ export default class CodeBlockHighlight extends Node {
|
|||||||
init(_, { doc }) {
|
init(_, { doc }) {
|
||||||
return getDecorations(doc)
|
return getDecorations(doc)
|
||||||
},
|
},
|
||||||
apply(tr, set) {
|
apply(transaction, decorationSet, oldState) {
|
||||||
// TODO: find way to cache decorations
|
// TODO: find way to cache decorations
|
||||||
// see: https://discuss.prosemirror.net/t/how-to-update-multiple-inline-decorations-on-node-change/1493
|
// see: https://discuss.prosemirror.net/t/how-to-update-multiple-inline-decorations-on-node-change/1493
|
||||||
if (tr.docChanged) {
|
|
||||||
return getDecorations(tr.doc)
|
const previousNodeName = oldState.selection.$head.parent.type.name
|
||||||
|
if (transaction.docChanged && previousNodeName === 'code_block') {
|
||||||
|
return getDecorations(transaction.doc)
|
||||||
}
|
}
|
||||||
return set.map(tr.mapping, tr.doc)
|
|
||||||
|
return decorationSet.map(transaction.mapping, transaction.doc)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Node } from 'tiptap'
|
import { Node } from 'tiptap'
|
||||||
|
import { nodeInputRule } from 'tiptap-commands'
|
||||||
|
|
||||||
export default class HorizontalRule extends Node {
|
export default class HorizontalRule extends Node {
|
||||||
get name() {
|
get name() {
|
||||||
@ -16,4 +17,10 @@ export default class HorizontalRule extends Node {
|
|||||||
commands({ type }) {
|
commands({ type }) {
|
||||||
return () => (state, dispatch) => dispatch(state.tr.replaceSelectionWith(type.create()))
|
return () => (state, dispatch) => dispatch(state.tr.replaceSelectionWith(type.create()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inputRules({ type }) {
|
||||||
|
return [
|
||||||
|
nodeInputRule(/^(?:---|___\s|\*\*\*\s)$/, type),
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user