add node view to task item
This commit is contained in:
@@ -8,6 +8,8 @@ import { Extensions, NodeViewRenderer } from './types'
|
||||
import getSchema from './utils/getSchema'
|
||||
import getSchemaTypeByName from './utils/getSchemaTypeByName'
|
||||
import splitExtensions from './utils/splitExtensions'
|
||||
import getAttributesFromExtensions from './utils/getAttributesFromExtensions'
|
||||
import getRenderedAttributes from './utils/getRenderedAttributes'
|
||||
|
||||
export default class ExtensionManager {
|
||||
|
||||
@@ -97,14 +99,17 @@ export default class ExtensionManager {
|
||||
}
|
||||
|
||||
get nodeViews() {
|
||||
const { editor } = this
|
||||
const { nodeExtensions } = splitExtensions(this.extensions)
|
||||
const allAttributes = getAttributesFromExtensions(this.extensions)
|
||||
|
||||
return Object.fromEntries(nodeExtensions
|
||||
.filter(extension => !!extension.addNodeView)
|
||||
.map(extension => {
|
||||
const extensionAttributes = allAttributes.filter(attribute => attribute.type === extension.name)
|
||||
const context = {
|
||||
options: extension.options,
|
||||
editor: this.editor,
|
||||
editor,
|
||||
type: getSchemaTypeByName(extension.name, this.schema),
|
||||
}
|
||||
|
||||
@@ -115,12 +120,17 @@ export default class ExtensionManager {
|
||||
view: EditorView,
|
||||
getPos: (() => number) | boolean,
|
||||
decorations: Decoration[],
|
||||
) => renderer({
|
||||
editor: this.editor,
|
||||
node,
|
||||
getPos,
|
||||
decorations,
|
||||
})
|
||||
) => {
|
||||
const attributes = getRenderedAttributes(node, extensionAttributes)
|
||||
|
||||
return renderer({
|
||||
editor,
|
||||
node,
|
||||
getPos,
|
||||
decorations,
|
||||
attributes,
|
||||
})
|
||||
}
|
||||
|
||||
return [extension.name, nodeview]
|
||||
}))
|
||||
|
||||
@@ -8,7 +8,7 @@ import getNodeType from '../utils/getNodeType'
|
||||
function isList(node: Node, schema: Schema) {
|
||||
return (node.type === schema.nodes.bullet_list
|
||||
|| node.type === schema.nodes.ordered_list
|
||||
|| node.type === schema.nodes.todo_list)
|
||||
|| node.type === schema.nodes.task_list)
|
||||
}
|
||||
|
||||
export const ToggleList = createExtension({
|
||||
|
||||
@@ -48,7 +48,8 @@ export type NodeViewRendererProps = {
|
||||
editor: Editor,
|
||||
node: Node,
|
||||
getPos: (() => number) | boolean,
|
||||
decorations: Decoration[]
|
||||
decorations: Decoration[],
|
||||
attributes: AnyObject,
|
||||
}
|
||||
|
||||
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Node, Mark } from 'prosemirror-model'
|
||||
import { ExtensionAttribute } from '../types'
|
||||
import { ExtensionAttribute, AnyObject } from '../types'
|
||||
import mergeAttributes from './mergeAttributes'
|
||||
|
||||
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): { [key: string]: any } {
|
||||
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): AnyObject {
|
||||
return extensionAttributes
|
||||
.filter(item => item.attribute.rendered)
|
||||
.map(item => {
|
||||
|
||||
Reference in New Issue
Block a user