refactoring

This commit is contained in:
Philipp Kühn
2021-06-04 15:55:05 +02:00
parent e680544b7d
commit af91b811bf

View File

@@ -4,9 +4,6 @@ import {
nodeInputRule, nodeInputRule,
mergeAttributes, mergeAttributes,
findChildrenInRange, findChildrenInRange,
isNodeSelection,
Predicate,
NodeWithPos,
} from '@tiptap/core' } from '@tiptap/core'
export interface FigureOptions { export interface FigureOptions {
@@ -127,25 +124,9 @@ export const Figure = Node.create<FigureOptions>({
imageToFigure: () => ({ tr }) => { imageToFigure: () => ({ tr }) => {
const { doc, selection } = tr const { doc, selection } = tr
const nodes: NodeWithPos[] = [] const { from, to } = selection
const predicate: Predicate = node => node.type.name === 'image' const range = { from, to }
const nodes = findChildrenInRange(doc, range, node => node.type.name === 'image')
if (isNodeSelection(selection)) {
const node = doc.nodeAt(selection.from)
if (!node || !predicate(node)) {
return false
}
nodes.push({ node, pos: selection.from })
} else {
const range = {
from: selection.from,
to: selection.to,
}
nodes.push(...findChildrenInRange(doc, range, predicate))
}
if (!nodes.length) { if (!nodes.length) {
return false return false