details: add (not working) commands & basic styling
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Node, mergeAttributes } from '@tiptap/core'
|
import { Node, mergeAttributes, Command } from '@tiptap/core'
|
||||||
|
|
||||||
export interface DetailsOptions {
|
export interface DetailsOptions {
|
||||||
HTMLAttributes: {
|
HTMLAttributes: {
|
||||||
@@ -13,6 +13,8 @@ export default Node.create({
|
|||||||
|
|
||||||
group: 'block',
|
group: 'block',
|
||||||
|
|
||||||
|
// defining: true,
|
||||||
|
|
||||||
defaultOptions: <DetailsOptions>{
|
defaultOptions: <DetailsOptions>{
|
||||||
HTMLAttributes: {},
|
HTMLAttributes: {},
|
||||||
},
|
},
|
||||||
@@ -44,4 +46,30 @@ export default Node.create({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
addCommands() {
|
||||||
|
return {
|
||||||
|
/**
|
||||||
|
* Set a details node
|
||||||
|
*/
|
||||||
|
setDetails: (): Command => ({ commands }) => {
|
||||||
|
// TODO: Doesn’t work
|
||||||
|
return commands.wrapIn('details')
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Toggle a details node
|
||||||
|
*/
|
||||||
|
toggleDetails: (): Command => ({ commands }) => {
|
||||||
|
// TODO: Doesn’t work
|
||||||
|
return commands.toggleWrap('details')
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Unset a details node
|
||||||
|
*/
|
||||||
|
unsetDetails: (): Command => ({ commands }) => {
|
||||||
|
// TODO: Doesn’t work
|
||||||
|
return commands.lift('details')
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="editor">
|
<div v-if="editor">
|
||||||
|
<button @click="editor.chain().focus().toggleBlockquote().run()" :class="{ 'is-active': editor.isActive('details') }">
|
||||||
|
details
|
||||||
|
</button>
|
||||||
|
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -39,6 +43,7 @@ export default {
|
|||||||
<summary>A closed details tag</summary>
|
<summary>A closed details tag</summary>
|
||||||
<p>More info about the details.</p>
|
<p>More info about the details.</p>
|
||||||
</details>
|
</details>
|
||||||
|
<p>That’s it.</p>
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -54,5 +59,18 @@ export default {
|
|||||||
> * + * {
|
> * + * {
|
||||||
margin-top: 0.75em;
|
margin-top: 0.75em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
details {
|
||||||
|
summary::before {
|
||||||
|
content: '▸';
|
||||||
|
color: red;
|
||||||
|
display: inline-block;
|
||||||
|
width: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[open] summary::before {
|
||||||
|
content: '▾';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user