refactoring
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user