@writergate/quill-image-uploader-nextjs 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@writergate/quill-image-uploader-nextjs",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/enlear/quill-image-uploader-nextjs.git"
@@ -58,8 +58,5 @@
58
58
  "bugs": {
59
59
  "url": "https://github.com/enlear/quill-image-uploader-nextjs/issues"
60
60
  },
61
- "homepage": "https://github.com/enlear/quill-image-uploader-nextjs#readme",
62
- "dependencies": {
63
- "nanoid": "^4.0.2"
64
- }
61
+ "homepage": "https://github.com/enlear/quill-image-uploader-nextjs#readme"
65
62
  }
@@ -31,7 +31,3 @@
31
31
  transform: rotate(360deg);
32
32
  }
33
33
  }
34
-
35
- .ql-wg-comment-wrapper{
36
- display: inline !important
37
- }
@@ -1,6 +1,5 @@
1
1
  import LoadingImage from "./blots/image.js";
2
2
  import CommentBlot from "./blots/comment.js";
3
- import GenerateRandomId from "./utils/nano-id.js";
4
3
 
5
4
  class ImageUploader {
6
5
  constructor(quill, options) {
@@ -13,6 +12,11 @@ class ImageUploader {
13
12
  "[Missing config] upload function that returns a promise is required"
14
13
  );
15
14
 
15
+ if (typeof this.options.renderComment !== "function")
16
+ console.warn(
17
+ "[Missing config] renderComment function that returns a promise is required"
18
+ );
19
+
16
20
  if (typeof this.options.newComment !== "function")
17
21
  console.warn(
18
22
  "[Missing config] newComment function that returns a promise is required"
@@ -32,6 +36,7 @@ class ImageUploader {
32
36
 
33
37
  this.handleDrop = this.handleDrop.bind(this);
34
38
  this.handlePaste = this.handlePaste.bind(this);
39
+ this.renderComment = this.renderComment.bind(this);
35
40
 
36
41
  this.quill.root.addEventListener("drop", this.handleDrop, false);
37
42
  this.quill.root.addEventListener("paste", this.handlePaste, false);
@@ -45,15 +50,29 @@ class ImageUploader {
45
50
  }
46
51
  }
47
52
 
53
+ renderComment(comment) {
54
+ const { id, range } = comment;
55
+ const { index, length } = range;
56
+ const formattedRange = {
57
+ length,
58
+ index,
59
+ };
60
+
61
+ this.quill.formatText(
62
+ formattedRange,
63
+ CommentBlot.blotName,
64
+ { commentId: id },
65
+ "user"
66
+ );
67
+ }
68
+
48
69
  addComment() {
49
- const commentId = GenerateRandomId();
50
70
  let range = this.quill.getSelection();
51
71
  if (range && range.length > 0 && this.options.newComment) {
52
72
  this.quill.history.userOnly = true;
53
73
  range.top = this.quill.getBounds(range.index, range.length).top;
54
74
  const selectedText = this.quill.getText(range.index, range.length);
55
- this.quill.formatText(range, CommentBlot.blotName, { commentId }, "user");
56
- this.options.newComment(range, selectedText, commentId);
75
+ this.options.newComment(range, selectedText);
57
76
  }
58
77
  this.quill.theme.tooltip.hide();
59
78
  this.quill.history.userOnly = true;
@@ -80,7 +99,6 @@ class ImageUploader {
80
99
 
81
100
  clean() {
82
101
  const range = this.quill.getSelection(true);
83
- const formats = this.quill.getFormat(range);
84
102
  // running it twise to remove colors
85
103
  this.quill.removeFormat(range.index, range.length, "user");
86
104
  this.quill.removeFormat(range.index, range.length, "user");
@@ -236,5 +254,5 @@ class ImageUploader {
236
254
  }
237
255
 
238
256
  window.ImageUploader = ImageUploader;
257
+ export const commentBlotName = CommentBlot.blotName;
239
258
  export default ImageUploader;
240
- export { CommentBlot, LoadingImage };
@@ -1,9 +0,0 @@
1
- const nanoid = require("nanoid");
2
- const alphabet = nanoid.customAlphabet(
3
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
4
- 9
5
- );
6
-
7
- const generateRandomId = () => alphabet();
8
-
9
- export default generateRandomId;