-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tasks are correctly represented by Deltas using attributes #1
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ const Parchment = Quill.import('parchment'); | |
const Module = Quill.import('core/module'); | ||
const Delta = Quill.import('delta'); | ||
|
||
//create and register a new class Attributor for checked tasks | ||
var checkedAttributor = new Parchment.Attributor.Class('checked', 'checked'); | ||
Quill.register(checkedAttributor); | ||
|
||
class TaskListItem extends ListItem { | ||
format(name, value) { | ||
if (name === TaskList.blotName && !value) { | ||
|
@@ -17,7 +21,7 @@ class TaskListItem extends ListItem { | |
// when inserting a new list item, remove the 'checked' css class | ||
clone() { | ||
const clone = super.clone(); | ||
clone.domNode.classList.remove('checked'); | ||
checkedAttributor.remove(clone.domNode) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a |
||
return clone; | ||
} | ||
} | ||
|
@@ -47,9 +51,10 @@ class TaskListModule extends Module { | |
|
||
this.quill.container.addEventListener('click', (e) => { | ||
if (e.target.matches('ul.task-list > li')) { | ||
e.target.classList.toggle('checked'); | ||
// dummy update so that quill detects a change | ||
this.quill.updateContents(new Delta().retain(1)); | ||
if (checkedAttributor.value(e.target)) | ||
checkedAttributor.remove(e.target); | ||
else | ||
checkedAttributor.add(e.target, true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add parenthesis. |
||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
cursor: default | ||
pointer-events: all | ||
|
||
.ql-editor ul.task-list > li.checked | ||
.ql-editor ul.task-list > li.checked-true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this what parchment produces? Is it possible to retain the class just as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the way the Attributor is set now, that's what parchment creates. I think it would be possible to have it set the class to only "checked" but then the task's Delta would be represented weirdly (it wouldn't say whether or not the task's checked). At least, that's how I interpreted parchment's kinda confusing docs. |
||
text-decoration: line-through | ||
|
||
.ql-editor ul.task-list > li.checked::before | ||
content: "✔" | ||
.ql-editor ul.task-list > li.checked-true::before | ||
content: "✓" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
->let