replace extensions
This commit is contained in:
@@ -7,52 +7,40 @@ interface FocusOptions {
|
||||
nested: boolean,
|
||||
}
|
||||
|
||||
export default class Focus extends Extension {
|
||||
export default new Extension<FocusOptions>()
|
||||
.name('focus')
|
||||
.defaults({
|
||||
className: 'has-focus',
|
||||
nested: false,
|
||||
})
|
||||
.plugins(({ editor, options }) => [
|
||||
new Plugin({
|
||||
props: {
|
||||
decorations: ({ doc, selection }) => {
|
||||
const { isEditable, isFocused } = editor
|
||||
const { anchor } = selection
|
||||
const decorations: Decoration[] = []
|
||||
|
||||
name = 'focus'
|
||||
if (!isEditable || !isFocused) {
|
||||
return
|
||||
}
|
||||
|
||||
constructor(options: Partial<FocusOptions> = {}) {
|
||||
super(options)
|
||||
}
|
||||
doc.descendants((node, pos) => {
|
||||
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
||||
|
||||
defaultOptions(): FocusOptions {
|
||||
return {
|
||||
className: 'has-focus',
|
||||
nested: false,
|
||||
}
|
||||
}
|
||||
|
||||
plugins() {
|
||||
return [
|
||||
new Plugin({
|
||||
props: {
|
||||
decorations: ({ doc, selection }) => {
|
||||
const { isEditable, isFocused } = this.editor
|
||||
const { anchor } = selection
|
||||
const decorations: Decoration[] = []
|
||||
|
||||
if (!isEditable || !isFocused) {
|
||||
return
|
||||
if (hasAnchor && !node.isText) {
|
||||
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
||||
class: options.className,
|
||||
})
|
||||
decorations.push(decoration)
|
||||
}
|
||||
|
||||
doc.descendants((node, pos) => {
|
||||
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
||||
return options.nested
|
||||
})
|
||||
|
||||
if (hasAnchor && !node.isText) {
|
||||
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
||||
class: this.options.className,
|
||||
})
|
||||
decorations.push(decoration)
|
||||
}
|
||||
|
||||
return this.options.nested
|
||||
})
|
||||
|
||||
return DecorationSet.create(doc, decorations)
|
||||
},
|
||||
return DecorationSet.create(doc, decorations)
|
||||
},
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
}),
|
||||
])
|
||||
.create()
|
||||
|
||||
Reference in New Issue
Block a user