@writergate/quill-image-uploader-nextjs 0.1.6 → 0.1.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@writergate/quill-image-uploader-nextjs",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/enlear/quill-image-uploader-nextjs.git"
@@ -32,71 +32,19 @@ class ImageUploader {
32
32
 
33
33
  this.quill.root.addEventListener("drop", this.handleDrop, false);
34
34
  this.quill.root.addEventListener("paste", this.handlePaste, false);
35
-
36
- this.renderComments.bind(this);
37
- const debouncedRenderComments = this.debounce((delta, oldDelta, source) => this.renderComments(delta, oldDelta, source), 2000);
38
- this.quill.on('text-change', debouncedRenderComments.bind(this));
39
35
  }
40
36
 
41
37
  addComment() {
42
38
  var range = this.quill.getSelection();
39
+ var selectedText = this.quill.getText(range.index, range.length);
43
40
 
44
41
  if (range && range.length > 0 && this.options.newComment) {
45
42
  range.top = this.quill.getBounds(range.index, range.length).top
46
- this.options.newComment(range, this.quill);
43
+ this.options.newComment(range, selectedText);
47
44
  }
48
45
  this.quill.theme.tooltip.hide();
49
46
  }
50
47
 
51
- calculateIndexChange(delta) {
52
- var index = delta.ops[0].retain || 0;
53
- const change = delta.changeLength();
54
- return { index: index, change: change };
55
- }
56
-
57
- adjustIndex(currentIndex, indexDelta) {
58
- if (indexDelta.change > 0 && currentIndex < indexDelta.index) {
59
- // comment index is before the modified text and modification didn't shift content before its starting point
60
- return currentIndex;
61
- } else if (indexDelta.change < 0 && currentIndex < (indexDelta.index + indexDelta.change)) {
62
- // code shifted before its starting point but the comment index is before the modified text
63
- return currentIndex;
64
- } else {
65
- return currentIndex + indexDelta.change;
66
- }
67
- }
68
-
69
- renderComments(delta, oldDelta, source) {
70
- if (source === "user" && this.options.comments && Object.keys(this.options.comments()).length !== 0) {
71
- var indexDelta = this.calculateIndexChange(delta);
72
- var commentObjs = {};
73
- var topIncrement = 0;
74
- for (const [key, value] of Object.entries((this.options.comments(this.quill)))) {
75
- var newIndex = this.adjustIndex(value.range.index, indexDelta);
76
- var length = value.range.length;
77
- var top = this.quill.getBounds(newIndex, 0).top;
78
- if (newIndex >= this.quill.getLength()) {
79
- top = this.quill.getBounds(this.quill.getLength(), 0).top + topIncrement;
80
- topIncrement = topIncrement + 25;
81
- }
82
- if (newIndex > 0) {
83
- commentObjs[key] = { range: { index: newIndex, length: length, top: top }, message: value.message };
84
- }
85
- }
86
- if (this.options.showComments) {
87
- this.options.showComments(commentObjs, this.quill);
88
- }
89
- }
90
- }
91
-
92
- debounce(func, timeout = 300) {
93
- let timer;
94
- return (...args) => {
95
- clearTimeout(timer);
96
- timer = setTimeout(() => { func.apply(this, args); }, timeout);
97
- };
98
- }
99
-
100
48
  fixHighlighter() {
101
49
  const range = this.quill.getSelection(true);
102
50
  const formats = this.quill.getFormat(range);