details: refactoring to use divs instead of semantic markup
This commit is contained in:
@@ -20,9 +20,14 @@ export default Node.create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
parseHTML() {
|
parseHTML() {
|
||||||
return [{
|
return [
|
||||||
|
{
|
||||||
tag: 'details',
|
tag: 'details',
|
||||||
}]
|
},
|
||||||
|
{
|
||||||
|
tag: 'div[data-type="details"]',
|
||||||
|
},
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
renderHTML({ HTMLAttributes }) {
|
renderHTML({ HTMLAttributes }) {
|
||||||
@@ -31,7 +36,24 @@ export default Node.create({
|
|||||||
|
|
||||||
addNodeView() {
|
addNodeView() {
|
||||||
return ({ HTMLAttributes }) => {
|
return ({ HTMLAttributes }) => {
|
||||||
const item = document.createElement('details')
|
const item = document.createElement('div')
|
||||||
|
item.setAttribute('data-type', 'details')
|
||||||
|
|
||||||
|
const toggle = document.createElement('div')
|
||||||
|
toggle.setAttribute('data-type', 'detailsToggle')
|
||||||
|
item.append(toggle)
|
||||||
|
|
||||||
|
const content = document.createElement('div')
|
||||||
|
content.setAttribute('data-type', 'detailsContent')
|
||||||
|
item.append(content)
|
||||||
|
|
||||||
|
toggle.addEventListener('click', () => {
|
||||||
|
if (item.hasAttribute('open')) {
|
||||||
|
item.removeAttribute('open')
|
||||||
|
} else {
|
||||||
|
item.setAttribute('open', 'open')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
Object.entries(HTMLAttributes).forEach(([key, value]) => {
|
Object.entries(HTMLAttributes).forEach(([key, value]) => {
|
||||||
item.setAttribute(key, value)
|
item.setAttribute(key, value)
|
||||||
@@ -39,7 +61,7 @@ export default Node.create({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
dom: item,
|
dom: item,
|
||||||
contentDOM: item,
|
contentDOM: content,
|
||||||
ignoreMutation: (mutation: MutationRecord) => {
|
ignoreMutation: (mutation: MutationRecord) => {
|
||||||
return !item.contains(mutation.target) || item === mutation.target
|
return !item.contains(mutation.target) || item === mutation.target
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,16 @@
|
|||||||
</button>
|
</button>
|
||||||
|
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
|
|
||||||
|
<h2>HTML</h2>
|
||||||
|
{{ editor.getHTML() }}
|
||||||
|
|
||||||
|
<h2>Issues</h2>
|
||||||
|
<ul>
|
||||||
|
<li>Commands don’t work</li>
|
||||||
|
<li>Fails to open nested details</li>
|
||||||
|
<li>Node can’t be deleted (if it’s the last node)</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -60,17 +70,30 @@ export default {
|
|||||||
margin-top: 0.75em;
|
margin-top: 0.75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
details {
|
details,
|
||||||
summary::before {
|
[data-type="details"] {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
[data-type="detailsContent"] > *:not(summary) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="detailsToggle"]::before {
|
||||||
|
cursor: pointer;
|
||||||
content: '▸';
|
content: '▸';
|
||||||
color: red;
|
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
width: 1em;
|
width: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
&[open] summary::before {
|
&[open] {
|
||||||
|
[data-type="detailsContent"] > *:not(summary) {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="detailsToggle"]::before {
|
||||||
content: '▾';
|
content: '▾';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user