mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
fix details
This commit is contained in:
parent
a6c1e2e20f
commit
fd6b346799
@ -11,7 +11,9 @@ export default Node.create({
|
||||
|
||||
content: 'inline*',
|
||||
|
||||
// group: 'block',
|
||||
group: 'block',
|
||||
|
||||
isolating: true,
|
||||
|
||||
defaultOptions: <DetailsSummaryOptions>{
|
||||
HTMLAttributes: {},
|
||||
|
@ -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
|
||||
// },
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user