Merge pull request #278 from Chrissi2812/issue-232

fixes #232: Clicking toolbar TodoItem lifts TodoItem
This commit is contained in:
Philipp Kühn 2019-05-09 10:32:08 +02:00 committed by GitHub
commit 7cd0fd40ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 11 deletions

View File

@ -69,7 +69,9 @@ export default {
new CodeBlock(), new CodeBlock(),
new HardBreak(), new HardBreak(),
new Heading({ levels: [1, 2, 3] }), new Heading({ levels: [1, 2, 3] }),
new TodoItem(), new TodoItem({
nested: true,
}),
new TodoList(), new TodoList(),
new Bold(), new Bold(),
new Code(), new Code(),
@ -135,14 +137,23 @@ li[data-type="todo_item"] {
.todo-content { .todo-content {
flex: 1; flex: 1;
> p:last-of-type {
margin-bottom: 0;
}
> ul[data-type="todo_list"] {
margin: .5rem 0;
}
} }
li[data-done="true"] { li[data-done="true"] {
> .todo-content {
> p {
text-decoration: line-through; text-decoration: line-through;
} }
}
li[data-done="true"] .todo-checkbox { > .todo-checkbox {
background-color: $color-black; background-color: $color-black;
}
} }
li[data-done="false"] { li[data-done="false"] {

View File

@ -24,6 +24,7 @@
"prosemirror-inputrules": "^1.0.1", "prosemirror-inputrules": "^1.0.1",
"prosemirror-schema-list": "^1.0.3", "prosemirror-schema-list": "^1.0.3",
"prosemirror-state": "^1.2.2", "prosemirror-state": "^1.2.2",
"prosemirror-model": "^1.7.0",
"tiptap-utils": "^1.4.1" "tiptap-utils": "^1.4.1"
} }
} }

View File

@ -1,3 +1,5 @@
import { Fragment, Slice } from 'prosemirror-model'
// this is a copy of canSplit // this is a copy of canSplit
// see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js // see https://github.com/ProseMirror/prosemirror-transform/blob/master/src/structure.js

View File

@ -1,5 +1,5 @@
import { Node } from 'tiptap' import { Node } from 'tiptap'
import { splitToDefaultListItem, liftListItem } from 'tiptap-commands' import { sinkListItem, splitToDefaultListItem, liftListItem } from 'tiptap-commands'
export default class TodoItem extends Node { export default class TodoItem extends Node {
@ -7,6 +7,12 @@ export default class TodoItem extends Node {
return 'todo_item' return 'todo_item'
} }
get defaultOptions() {
return {
nested: false,
}
}
get view() { get view() {
return { return {
props: ['node', 'updateAttrs', 'editable'], props: ['node', 'updateAttrs', 'editable'],
@ -34,7 +40,7 @@ export default class TodoItem extends Node {
}, },
}, },
draggable: true, draggable: true,
content: 'paragraph', content: this.options.nested ? '(paragraph|todo_list)+' : 'paragraph+',
toDOM: node => { toDOM: node => {
const { done } = node.attrs const { done } = node.attrs
@ -61,6 +67,7 @@ export default class TodoItem extends Node {
keys({ type }) { keys({ type }) {
return { return {
Enter: splitToDefaultListItem(type), Enter: splitToDefaultListItem(type),
Tab: this.options.nested ? sinkListItem(type) : () => {},
'Shift-Tab': liftListItem(type), 'Shift-Tab': liftListItem(type),
} }
} }

View File

@ -1,5 +1,5 @@
import { Node } from 'tiptap' import { Node } from 'tiptap'
import { wrapInList, wrappingInputRule } from 'tiptap-commands' import { toggleList, wrappingInputRule } from 'tiptap-commands'
export default class TodoList extends Node { export default class TodoList extends Node {
@ -19,8 +19,8 @@ export default class TodoList extends Node {
} }
} }
commands({ type }) { commands({ type, schema }) {
return () => wrapInList(type) return () => toggleList(type, schema.nodes.todo_item)
} }
inputRules({ type }) { inputRules({ type }) {