@writergate/quill-image-uploader-nextjs 0.0.15 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/quill.imageUploader.js +56 -0
package/package.json
CHANGED
@@ -11,17 +11,73 @@ class ImageUploader {
|
|
11
11
|
"[Missing config] upload function that returns a promise is required"
|
12
12
|
);
|
13
13
|
|
14
|
+
if (typeof this.options.newComment !== "function")
|
15
|
+
console.warn(
|
16
|
+
"[Missing config] newComment function that returns a promise is required"
|
17
|
+
);
|
18
|
+
|
19
|
+
if (typeof this.options.showComments !== "function")
|
20
|
+
console.warn(
|
21
|
+
"[Missing config] showComments function that returns a promise is required"
|
22
|
+
);
|
23
|
+
|
14
24
|
var toolbar = this.quill.getModule("toolbar");
|
15
25
|
toolbar.addHandler("image", this.selectLocalImage.bind(this));
|
16
26
|
toolbar.addHandler("code-block", this.fixHighlighter.bind(this));
|
17
27
|
toolbar.addHandler("clean", this.clean.bind(this));
|
28
|
+
toolbar.addHandler("underline", this.addComment.bind(this));
|
18
29
|
|
19
30
|
this.handleDrop = this.handleDrop.bind(this);
|
20
31
|
this.handlePaste = this.handlePaste.bind(this);
|
21
32
|
|
22
33
|
this.quill.root.addEventListener("drop", this.handleDrop, false);
|
23
34
|
this.quill.root.addEventListener("paste", this.handlePaste, false);
|
35
|
+
this.quill.on('text-change', this.renderComments.bind(this));
|
36
|
+
}
|
37
|
+
|
38
|
+
addComment() {
|
39
|
+
var range = this.quill.getSelection();
|
40
|
+
|
41
|
+
if (range && range.length > 0 && this.options.newComment) {
|
42
|
+
range.top = this.quill.getBounds(range.index, range.length).top
|
43
|
+
this.options.newComment(range, this.quill);
|
44
|
+
}
|
45
|
+
this.quill.theme.tooltip.hide();
|
46
|
+
}
|
47
|
+
|
48
|
+
calculateIndexChange(delta) {
|
49
|
+
var index = delta.ops[0].retain || 0;
|
50
|
+
const change = delta.changeLength();
|
51
|
+
return { index: index, change: change };
|
52
|
+
}
|
53
|
+
|
54
|
+
adjustIndex(currentIndex, indexDelta) {
|
55
|
+
if (indexDelta.change > 0 && currentIndex < indexDelta.index) {
|
56
|
+
// comment index is before the modified text and modification didn't shift content before its starting point
|
57
|
+
return currentIndex;
|
58
|
+
} else if (indexDelta.change < 0 && currentIndex < (indexDelta.index + indexDelta.change)) {
|
59
|
+
// code shifted before its starting point but the comment index is before the modified text
|
60
|
+
return currentIndex;
|
61
|
+
} else {
|
62
|
+
return currentIndex + indexDelta.change;
|
63
|
+
}
|
64
|
+
}
|
24
65
|
|
66
|
+
renderComments(delta, oldDelta, source) {
|
67
|
+
if (Object.keys(this.options.comments(this.quill)).length !== 0) {
|
68
|
+
var indexDelta = this.calculateIndexChange(delta);
|
69
|
+
var commentObjs = {};
|
70
|
+
for (const [key, value] of Object.entries((this.options.comments(this.quill)))) {
|
71
|
+
var newIndex = this.adjustIndex(value.range.index, indexDelta);
|
72
|
+
var length = value.range.length;
|
73
|
+
if (newIndex > 0) {
|
74
|
+
commentObjs[key] = { range: { index: newIndex, length: length, top: this.quill.getBounds(newIndex, length).top }, message: value.message };
|
75
|
+
}
|
76
|
+
}
|
77
|
+
if (this.options.showComments) {
|
78
|
+
this.options.showComments(commentObjs, this.quill);
|
79
|
+
}
|
80
|
+
}
|
25
81
|
}
|
26
82
|
|
27
83
|
fixHighlighter() {
|