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

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.0",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/enlear/quill-image-uploader-nextjs.git"
@@ -47,14 +47,8 @@ class ImageUploader {
47
47
 
48
48
  calculateIndexChange(delta) {
49
49
  var index = delta.ops[0].retain || 0;
50
- var insert = delta.ops.filter(function (i) {
51
- return i.insert;
52
- }).map(function (i) { return i.attributes && i.attributes['code-block'] ? i.insert.replaceAll('\n', '') : i.insert; }).join()
53
- var insLength = insert ? insert.length : 0;
54
- var delLength = delta.ops.filter(function (i) {
55
- return i.delete;
56
- }).map(function (i) { return i.delete }).reduce((a, b) => a + b, 0);
57
- return { index: index, change: insLength - delLength };
50
+ const change = delta.changeLength();
51
+ return { index: index, change: change };
58
52
  }
59
53
 
60
54
  adjustIndex(currentIndex, indexDelta) {
@@ -62,7 +56,7 @@ class ImageUploader {
62
56
  // comment index is before the modified text and modification didn't shift content before its starting point
63
57
  return currentIndex;
64
58
  } else if (indexDelta.change < 0 && currentIndex < (indexDelta.index + indexDelta.change)) {
65
- // code shifted before its starting point but still the comment index is before the modified text
59
+ // code shifted before its starting point but the comment index is before the modified text
66
60
  return currentIndex;
67
61
  } else {
68
62
  return currentIndex + indexDelta.change;
@@ -70,14 +64,20 @@ class ImageUploader {
70
64
  }
71
65
 
72
66
  renderComments(delta, oldDelta, source) {
73
- if (source === "user" && this.options.comments && Object.keys(this.options.comments()).length !== 0) {
67
+ if (Object.keys(this.options.comments(this.quill)).length !== 0) {
74
68
  var indexDelta = this.calculateIndexChange(delta);
75
69
  var commentObjs = {};
76
- for (const [key, value] of Object.entries((this.options.comments()))) {
70
+ var topIncrement = 0;
71
+ for (const [key, value] of Object.entries((this.options.comments(this.quill)))) {
77
72
  var newIndex = this.adjustIndex(value.range.index, indexDelta);
78
73
  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
+ topIncrement = topIncrement + 25;
78
+ }
79
79
  if (newIndex > 0) {
80
- commentObjs[key] = { range: { index: newIndex, length: length, top: this.quill.getBounds(newIndex, length).top }, message: value.message };
80
+ commentObjs[key] = { range: { index: newIndex, length: length, top: top }, message: value.message };
81
81
  }
82
82
  }
83
83
  if (this.options.showComments) {