mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
remove replaceWithNode
This commit is contained in:
parent
571db1042b
commit
f71e4df72e
@ -21,10 +21,10 @@ editor.chain().focus().bold().run()
|
||||
| ------------------- | ------------------------------------------ |
|
||||
| .removeMark() | Remove a mark in the current selection. |
|
||||
| .removeMarks() | Remove all marks in the current selection. |
|
||||
| .replaceWithNode() | Replace a given range with a node. |
|
||||
| .selectParentNode() | Select the parent node. |
|
||||
| .toggleMark() | Toggle a mark on and off. |
|
||||
| .toggleBlockType() | Toggle a node with another node. |
|
||||
| .setBlockType() | Replace a given range with a node. |
|
||||
| .updateMark() | Update a mark with new attributes. |
|
||||
|
||||
### Selection
|
||||
|
@ -7,7 +7,6 @@ export { insertText } from './insertText'
|
||||
export { liftListItem } from './liftListItem'
|
||||
export { removeMark } from './removeMark'
|
||||
export { removeMarks } from './removeMarks'
|
||||
export { replaceWithNode } from './replaceWithNode'
|
||||
export { scrollIntoView } from './scrollIntoView'
|
||||
export { selectAll } from './selectAll'
|
||||
export { selectParentNode } from './selectParentNode'
|
||||
|
@ -1,36 +0,0 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command } from '../Editor'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
interface Range {
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
|
||||
type ReplaceWithNodeCommand = (
|
||||
typeOrName: NodeType,
|
||||
attrs: {},
|
||||
range?: Range,
|
||||
) => Command
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Commands {
|
||||
replaceWithNode: ReplaceWithNodeCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export const replaceWithNode: ReplaceWithNodeCommand = (typeOrName, attrs = {}, range) => ({ view, tr, state }) => {
|
||||
const { $from, $to } = tr.selection
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const index = $from.index()
|
||||
const from = range ? range.from : $from.pos
|
||||
const to = range ? range.to : $to.pos
|
||||
|
||||
if (!$from.parent.canReplaceWith(index, index, type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
view.dispatch(tr.replaceWith(from, to, type.create(attrs)))
|
||||
|
||||
return true
|
||||
}
|
Loading…
Reference in New Issue
Block a user