fix a bug for task item
This commit is contained in:
@@ -72,7 +72,12 @@ const TaskItem = Node.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
return ({ HTMLAttributes, getPos, editor }) => {
|
return ({
|
||||||
|
node,
|
||||||
|
HTMLAttributes,
|
||||||
|
getPos,
|
||||||
|
editor,
|
||||||
|
}) => {
|
||||||
const { view } = editor
|
const { view } = editor
|
||||||
const listItem = document.createElement('li')
|
const listItem = document.createElement('li')
|
||||||
const checkbox = document.createElement('input')
|
const checkbox = document.createElement('input')
|
||||||
@@ -91,7 +96,7 @@ const TaskItem = Node.create({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (HTMLAttributes['data-checked'] === true) {
|
if (node.attrs.checked) {
|
||||||
checkbox.setAttribute('checked', 'checked')
|
checkbox.setAttribute('checked', 'checked')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,11 +109,17 @@ const TaskItem = Node.create({
|
|||||||
return {
|
return {
|
||||||
dom: listItem,
|
dom: listItem,
|
||||||
contentDOM: content,
|
contentDOM: content,
|
||||||
update: node => {
|
update: updatedNode => {
|
||||||
if (node.type !== this.type) {
|
if (updatedNode.type !== this.type) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updatedNode.attrs.checked) {
|
||||||
|
checkbox.setAttribute('checked', 'checked')
|
||||||
|
} else {
|
||||||
|
checkbox.removeAttribute('checked')
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user