Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions task_list.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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
let checkedAttributor = new Parchment.Attributor.Class('checked', 'checked');
Quill.register(checkedAttributor);

class TaskListItem extends ListItem {
format(name, value) {
if (name === TaskList.blotName && !value) {
Expand All @@ -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);
return clone;
}
}
Expand Down Expand Up @@ -47,9 +51,12 @@ 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);
}
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions task_list.sass
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
cursor: default
pointer-events: all

.ql-editor ul.task-list > li.checked
.ql-editor ul.task-list > li.checked-true
Copy link
Owner

Choose a reason for hiding this comment

The 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 checked?
Otherwise this is a breaking change.

Copy link
Author

Choose a reason for hiding this comment

The 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: ""