-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<template> | ||
<q-btn-dropdown icon="mdi-format-line-spacing" menu-anchor="bottom left" menu-self="top left" class="o-line-height-dropdown" content-class="o-menu o-line-height-dropdown-menu" dense flat> | ||
<q-list> | ||
<template v-for="(item, index) of types"> | ||
<q-separator :key="index" v-if="item.separator" /> | ||
<q-item :key="index" clickable v-close-popup | ||
@click.native="commands.lineHeight({lineHeight: item.value})" v-else> | ||
<q-item-section>{{item.label}}</q-item-section> | ||
</q-item> | ||
</template> | ||
</q-list> | ||
</q-btn-dropdown> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'o-line-height-dropdown', | ||
data () { | ||
return { | ||
types: [ | ||
{ label: 'Default', value: '0' }, | ||
{ label: '1', value: '1', separator: true }, | ||
{ label: '1.15', value: '1.15' }, | ||
{ label: '1.5', value: '1.5' }, | ||
{ label: '2', value: '2' }, | ||
{ label: '2.5', value: '2.5' }, | ||
{ label: '3', value: '3' }, | ||
] | ||
} | ||
}, | ||
props: { | ||
commands: { | ||
type: Object | ||
} | ||
}, | ||
methods: { | ||
}, | ||
computed: { | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="stylus"> | ||
.o-line-height-dropdown { | ||
padding 4px | ||
.q-btn-dropdown__arrow { | ||
margin-left 0 | ||
} | ||
} | ||
.o-line-height-dropdown-menu { | ||
.q-list { | ||
.q-icon { | ||
font-size 1rem | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Extension } from 'tiptap' | ||
import { setLineHeight } from '../utils/line_height' | ||
|
||
export default class LineHeight extends Extension { | ||
get name () { | ||
return 'lineHeight' | ||
} | ||
|
||
commands () { | ||
return attrs => (state, dispatch) => { | ||
let { selection } = state | ||
const tr = setLineHeight( | ||
state.tr.setSelection(selection), | ||
attrs.lineHeight, | ||
) | ||
|
||
if (tr.docChanged) { | ||
dispatch && dispatch(tr) | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Utils: alignment | ||
* @see https://github.com/Leecason/element-tiptap/blob/master/src/extensions/text_align.ts | ||
* @todo Table | ||
*/ | ||
|
||
const ALLOWED_NODE_TYPES = [ | ||
'paragraph', | ||
'heading', | ||
'list_item', | ||
'todo_item', | ||
] | ||
|
||
export function setLineHeight (tr, lineHeight) { | ||
console.log('line-height', lineHeight) | ||
const { selection, doc } = tr | ||
|
||
if (!selection || !doc) { | ||
return tr | ||
} | ||
|
||
const { from, to } = selection | ||
|
||
const tasks = [] | ||
lineHeight = lineHeight || null | ||
|
||
doc.nodesBetween(from, to, (node, pos) => { | ||
const nodeType = node.type | ||
if (ALLOWED_NODE_TYPES.includes(nodeType.name)) { | ||
const height = node.attrs.lineHeight || null | ||
if (height !== lineHeight) { | ||
tasks.push({ | ||
node, | ||
pos, | ||
nodeType, | ||
}) | ||
|
||
return nodeType.name !== 'list_item' && nodeType.name !== 'todo_item' | ||
} | ||
} | ||
return true | ||
}) | ||
|
||
if (!tasks.length) return tr | ||
|
||
tasks.forEach(job => { | ||
const { node, pos, nodeType } = job | ||
let { attrs } = node | ||
attrs = { | ||
...attrs, | ||
lineHeight: lineHeight, | ||
} | ||
|
||
tr = tr.setNodeMarkup(pos, nodeType, attrs, node.marks) | ||
}) | ||
|
||
return tr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters