-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(Text Editor): Quill Editor * fix: Add imageDrop module - prevent default events * refactor(Comment): Comment is now frappe control - Use quill's bubble theme for comment control * feat: Support @mentions in comment area - Uses quill-mention package * fix: Use setContents to fix autofocus bug * fix: Spaces to Tabs * fix: Missing semicolon * fix: Fix style * fix: Remove all of summernote - Remove comment.js (use fieldtype: 'Comment') - Add quill styles to webform.css * fix: Replace color/background with indent/outdent
- Loading branch information
1 parent
8acdc06
commit 1053427
Showing
12 changed files
with
375 additions
and
760 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,124 @@ | ||
import 'quill-mention'; | ||
|
||
frappe.ui.form.ControlComment = frappe.ui.form.ControlTextEditor.extend({ | ||
make_wrapper() { | ||
this.comment_wrapper = !this.no_wrapper ? $(` | ||
<div class="comment-input-wrapper"> | ||
<div class="comment-input-header"> | ||
<span class="small text-muted">${__("Add a comment")}</span> | ||
<button class="btn btn-default btn-comment btn-xs pull-right"> | ||
${__("Comment")} | ||
</button> | ||
</div> | ||
<div class="comment-input-container"> | ||
<div class="frappe-control"></div> | ||
<div class="text-muted small"> | ||
${__("Ctrl+Enter to add comment")} | ||
</div> | ||
</div> | ||
</div> | ||
`) : $('<div class="frappe-control"></div>'); | ||
|
||
this.comment_wrapper.appendTo(this.parent); | ||
|
||
// wrapper should point to frappe-control | ||
this.$wrapper = !this.no_wrapper | ||
? this.comment_wrapper.find('.frappe-control') | ||
: this.comment_wrapper; | ||
|
||
this.wrapper = this.$wrapper; | ||
|
||
this.button = this.comment_wrapper.find('.btn-comment'); | ||
}, | ||
|
||
bind_events() { | ||
this._super(); | ||
|
||
this.button.click(() => { | ||
this.submit(); | ||
}); | ||
|
||
this.$wrapper.on('keydown', e => { | ||
const key = frappe.ui.keys.get_key(e); | ||
if (key === 'ctrl+enter') { | ||
e.preventDefault(); | ||
this.submit(); | ||
} | ||
}); | ||
|
||
this.quill.on('text-change', frappe.utils.debounce(() => { | ||
this.update_state(); | ||
}, 300)); | ||
}, | ||
|
||
submit() { | ||
this.on_submit && this.on_submit(this.get_value()); | ||
}, | ||
|
||
update_state() { | ||
const value = this.get_value(); | ||
if (strip_html(value)) { | ||
this.button.removeClass('btn-default').addClass('btn-primary'); | ||
} else { | ||
this.button.addClass('btn-default').removeClass('btn-primary'); | ||
} | ||
}, | ||
|
||
get_quill_options() { | ||
const options = this._super(); | ||
return Object.assign(options, { | ||
theme: 'bubble', | ||
modules: Object.assign(options.modules, { | ||
mention: this.get_mention_options() | ||
}) | ||
}); | ||
}, | ||
|
||
get_mention_options() { | ||
if (!(this.mentions && this.mentions.length)) { | ||
return null; | ||
} | ||
|
||
const at_values = this.mentions.map((value, i) => { | ||
return { | ||
id: i, | ||
value | ||
}; | ||
}); | ||
|
||
return { | ||
allowedChars: /^[A-Za-z0-9_]*$/, | ||
mentionDenotationChars: ["@"], | ||
isolateCharacter: true, | ||
source: function(searchTerm, renderList, mentionChar) { | ||
let values; | ||
|
||
if (mentionChar === "@") { | ||
values = at_values; | ||
} | ||
|
||
if (searchTerm.length === 0) { | ||
renderList(values, searchTerm); | ||
} else { | ||
const matches = []; | ||
for (let i = 0; i < values.length; i++) { | ||
if (~values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())) { | ||
matches.push(values[i]); | ||
} | ||
} | ||
renderList(matches, searchTerm); | ||
} | ||
}, | ||
}; | ||
}, | ||
|
||
get_toolbar_options() { | ||
return [ | ||
['bold', 'italic', 'underline'], | ||
['blockquote', 'code-block'], | ||
['link', 'image'], | ||
[{ 'list': 'ordered' }, { 'list': 'bullet' }], | ||
['clean'] | ||
]; | ||
}, | ||
}); |
Oops, something went wrong.