fix details

This commit is contained in:
Philipp Kühn 2021-02-11 08:59:58 +01:00
parent a6c1e2e20f
commit fd6b346799
2 changed files with 6 additions and 38 deletions

View File

@ -11,7 +11,9 @@ export default Node.create({
content: 'inline*',
// group: 'block',
group: 'block',
isolating: true,
defaultOptions: <DetailsSummaryOptions>{
HTMLAttributes: {},

View File

@ -29,26 +29,8 @@ export default Node.create({
},
addNodeView() {
return ({
HTMLAttributes,
}) => {
return ({ HTMLAttributes }) => {
const item = document.createElement('details')
let open = false
item.addEventListener('click', event => {
// @ts-ignore
const { localName } = event.target
if (localName === 'summary') {
open = !open
if (open) {
item.setAttribute('open', 'open')
} else {
item.removeAttribute('open')
}
}
})
Object.entries(HTMLAttributes).forEach(([key, value]) => {
item.setAttribute(key, value)
@ -57,25 +39,9 @@ export default Node.create({
return {
dom: item,
contentDOM: item,
ignoreMutation: (updatedNode: MutationRecord) => {
// @ts-ignore
console.log({ updatedNode }, 'ignoreMutation', updatedNode.attributeName === 'open')
return updatedNode.attributeName === 'open'
ignoreMutation: (mutation: MutationRecord) => {
return !item.contains(mutation.target) || item === mutation.target
},
// update: updatedNode => {
// if (updatedNode.type !== this.type) {
// return false
// }
// if (updatedNode.attrs.open) {
// item.setAttribute('open', 'open')
// } else {
// item.removeAttribute('open')
// }
// return true
// },
}
}
},