@writergate/quill-image-uploader-nextjs 0.1.4 → 0.1.5

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.4",
3
+ "version": "0.1.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/enlear/quill-image-uploader-nextjs.git"
@@ -32,7 +32,10 @@ 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
- this.quill.on('text-change', this.renderComments.bind(this));
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));
36
39
  }
37
40
 
38
41
  addComment() {
@@ -64,16 +67,16 @@ class ImageUploader {
64
67
  }
65
68
 
66
69
  renderComments(delta, oldDelta, source) {
67
- if (Object.keys(this.options.comments(this.quill)).length !== 0) {
70
+ if (source === "user" && this.options.comments && Object.keys(this.options.comments()).length !== 0) {
68
71
  var indexDelta = this.calculateIndexChange(delta);
69
72
  var commentObjs = {};
70
73
  var topIncrement = 0;
71
74
  for (const [key, value] of Object.entries((this.options.comments(this.quill)))) {
72
75
  var newIndex = this.adjustIndex(value.range.index, indexDelta);
73
76
  var length = value.range.length;
74
- var top = this.quill.getBounds(newIndex, length).top;
75
- if(top >= this.quill.getLength()){
76
- top = this.quill.getLength() + topIncrement;
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;
77
80
  topIncrement = topIncrement + 25;
78
81
  }
79
82
  if (newIndex > 0) {
@@ -86,6 +89,14 @@ class ImageUploader {
86
89
  }
87
90
  }
88
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
+
89
100
  fixHighlighter() {
90
101
  const range = this.quill.getSelection(true);
91
102
  const formats = this.quill.getFormat(range);