add hardbreak extension
This commit is contained in:
38
packages/extension-hardbreak/index.ts
Normal file
38
packages/extension-hardbreak/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Node } from '@tiptap/core'
|
||||
import { chainCommands, exitCode } from 'prosemirror-commands'
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Editor {
|
||||
hardbreak(): Editor,
|
||||
}
|
||||
}
|
||||
|
||||
export default new Node()
|
||||
.name('hardbreak')
|
||||
.schema(() => ({
|
||||
inline: true,
|
||||
group: 'inline',
|
||||
selectable: false,
|
||||
parseDOM: [
|
||||
{ tag: 'br' },
|
||||
],
|
||||
toDOM: () => ['br'],
|
||||
}))
|
||||
.commands(({ editor, type }) => ({
|
||||
hardbreak: next => () => {
|
||||
const { state, view } = editor
|
||||
const { dispatch } = view
|
||||
|
||||
chainCommands(exitCode, () => {
|
||||
dispatch(state.tr.replaceSelectionWith(type.create()).scrollIntoView())
|
||||
return true
|
||||
})(state, dispatch, view)
|
||||
|
||||
next()
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Mod-Enter': () => editor.hardbreak(),
|
||||
'Shift-Enter': () => editor.hardbreak(),
|
||||
}))
|
||||
.create()
|
||||
18
packages/extension-hardbreak/package.json
Normal file
18
packages/extension-hardbreak/package.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@tiptap/extension-hardbreak",
|
||||
"version": "1.0.0",
|
||||
"source": "index.ts",
|
||||
"main": "dist/tiptap-extension-hardbreak.js",
|
||||
"umd:main": "dist/tiptap-extension-hardbreak.umd.js",
|
||||
"module": "dist/tiptap-extension-hardbreak.mjs",
|
||||
"unpkg": "dist/tiptap-extension-hardbreak.js",
|
||||
"jsdelivr": "dist/tiptap-extension-hardbreak.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "2.x",
|
||||
"prosemirror-commands": "^1.1.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user