@plotdb/quill 1.0.0

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.
Files changed (287) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +3 -0
  3. package/assets/base.styl +309 -0
  4. package/assets/bubble/toolbar.styl +14 -0
  5. package/assets/bubble/tooltip.styl +49 -0
  6. package/assets/bubble.styl +45 -0
  7. package/assets/core.styl +215 -0
  8. package/assets/favicon.png +0 -0
  9. package/assets/icons/align-center.svg +5 -0
  10. package/assets/icons/align-justify.svg +5 -0
  11. package/assets/icons/align-left.svg +5 -0
  12. package/assets/icons/align-right.svg +5 -0
  13. package/assets/icons/attachment.svg +3 -0
  14. package/assets/icons/audio.svg +5 -0
  15. package/assets/icons/authorship.svg +5 -0
  16. package/assets/icons/background.svg +52 -0
  17. package/assets/icons/blockquote.svg +6 -0
  18. package/assets/icons/bold.svg +4 -0
  19. package/assets/icons/clean.svg +7 -0
  20. package/assets/icons/code.svg +5 -0
  21. package/assets/icons/color.svg +5 -0
  22. package/assets/icons/comment.svg +3 -0
  23. package/assets/icons/direction-ltr.svg +7 -0
  24. package/assets/icons/direction-rtl.svg +7 -0
  25. package/assets/icons/dropdown.svg +4 -0
  26. package/assets/icons/embed.svg +3 -0
  27. package/assets/icons/emoji.svg +6 -0
  28. package/assets/icons/float-center.svg +5 -0
  29. package/assets/icons/float-full.svg +5 -0
  30. package/assets/icons/float-left.svg +7 -0
  31. package/assets/icons/float-right.svg +7 -0
  32. package/assets/icons/font.svg +5 -0
  33. package/assets/icons/formula.svg +5 -0
  34. package/assets/icons/hashtag.svg +6 -0
  35. package/assets/icons/header-2.svg +3 -0
  36. package/assets/icons/header-3.svg +3 -0
  37. package/assets/icons/header-4.svg +3 -0
  38. package/assets/icons/header-5.svg +3 -0
  39. package/assets/icons/header-6.svg +3 -0
  40. package/assets/icons/header.svg +3 -0
  41. package/assets/icons/horizontal-rule.svg +4 -0
  42. package/assets/icons/image.svg +5 -0
  43. package/assets/icons/indent.svg +6 -0
  44. package/assets/icons/italic.svg +5 -0
  45. package/assets/icons/link.svg +5 -0
  46. package/assets/icons/list-bullet.svg +8 -0
  47. package/assets/icons/list-check.svg +8 -0
  48. package/assets/icons/list-ordered.svg +9 -0
  49. package/assets/icons/map.svg +5 -0
  50. package/assets/icons/mention.svg +4 -0
  51. package/assets/icons/more.svg +3 -0
  52. package/assets/icons/outdent.svg +6 -0
  53. package/assets/icons/redo.svg +4 -0
  54. package/assets/icons/size-decrease.svg +5 -0
  55. package/assets/icons/size-increase.svg +6 -0
  56. package/assets/icons/size.svg +6 -0
  57. package/assets/icons/spacing.svg +9 -0
  58. package/assets/icons/speech.svg +6 -0
  59. package/assets/icons/strike.svg +5 -0
  60. package/assets/icons/subscript.svg +4 -0
  61. package/assets/icons/superscript.svg +4 -0
  62. package/assets/icons/table-border-all.svg +5 -0
  63. package/assets/icons/table-border-bottom.svg +28 -0
  64. package/assets/icons/table-border-left.svg +28 -0
  65. package/assets/icons/table-border-none.svg +25 -0
  66. package/assets/icons/table-border-outside.svg +35 -0
  67. package/assets/icons/table-border-right.svg +28 -0
  68. package/assets/icons/table-border-top.svg +28 -0
  69. package/assets/icons/table-delete-cells.svg +13 -0
  70. package/assets/icons/table-delete-columns.svg +8 -0
  71. package/assets/icons/table-delete-rows.svg +9 -0
  72. package/assets/icons/table-insert-cells.svg +13 -0
  73. package/assets/icons/table-insert-columns.svg +8 -0
  74. package/assets/icons/table-insert-rows.svg +9 -0
  75. package/assets/icons/table-merge-cells.svg +4 -0
  76. package/assets/icons/table-unmerge-cells.svg +7 -0
  77. package/assets/icons/table.svg +11 -0
  78. package/assets/icons/underline.svg +4 -0
  79. package/assets/icons/undo.svg +4 -0
  80. package/assets/icons/video.svg +14 -0
  81. package/assets/snow/toolbar.styl +26 -0
  82. package/assets/snow/tooltip.styl +53 -0
  83. package/assets/snow.styl +18 -0
  84. package/blots/block.d.ts +34 -0
  85. package/blots/block.js +182 -0
  86. package/blots/block.js.map +1 -0
  87. package/blots/break.d.ts +8 -0
  88. package/blots/break.js +21 -0
  89. package/blots/break.js.map +1 -0
  90. package/blots/container.d.ts +4 -0
  91. package/blots/container.js +4 -0
  92. package/blots/container.js.map +1 -0
  93. package/blots/cursor.d.ts +26 -0
  94. package/blots/cursor.js +170 -0
  95. package/blots/cursor.js.map +1 -0
  96. package/blots/embed.d.ts +18 -0
  97. package/blots/embed.js +72 -0
  98. package/blots/embed.js.map +1 -0
  99. package/blots/inline.d.ts +12 -0
  100. package/blots/inline.js +48 -0
  101. package/blots/inline.js.map +1 -0
  102. package/blots/scroll.d.ts +49 -0
  103. package/blots/scroll.js +349 -0
  104. package/blots/scroll.js.map +1 -0
  105. package/blots/text.d.ts +5 -0
  106. package/blots/text.js +16 -0
  107. package/blots/text.js.map +1 -0
  108. package/core/composition.d.ts +12 -0
  109. package/core/composition.js +44 -0
  110. package/core/composition.js.map +1 -0
  111. package/core/editor.d.ts +28 -0
  112. package/core/editor.js +404 -0
  113. package/core/editor.js.map +1 -0
  114. package/core/emitter.d.ts +33 -0
  115. package/core/emitter.js +78 -0
  116. package/core/emitter.js.map +1 -0
  117. package/core/instances.d.ts +3 -0
  118. package/core/instances.js +2 -0
  119. package/core/instances.js.map +1 -0
  120. package/core/logger.d.ts +7 -0
  121. package/core/logger.js +24 -0
  122. package/core/logger.js.map +1 -0
  123. package/core/module.d.ts +8 -0
  124. package/core/module.js +10 -0
  125. package/core/module.js.map +1 -0
  126. package/core/quill.d.ts +218 -0
  127. package/core/quill.js +630 -0
  128. package/core/quill.js.map +1 -0
  129. package/core/selection.d.ts +74 -0
  130. package/core/selection.js +374 -0
  131. package/core/selection.js.map +1 -0
  132. package/core/theme.d.ts +32 -0
  133. package/core/theme.js +28 -0
  134. package/core/theme.js.map +1 -0
  135. package/core/utils/createRegistryWithFormats.d.ts +5 -0
  136. package/core/utils/createRegistryWithFormats.js +29 -0
  137. package/core/utils/createRegistryWithFormats.js.map +1 -0
  138. package/core/utils/scrollRectIntoView.d.ts +11 -0
  139. package/core/utils/scrollRectIntoView.js +110 -0
  140. package/core/utils/scrollRectIntoView.js.map +1 -0
  141. package/core.d.ts +7 -0
  142. package/core.js +37 -0
  143. package/core.js.map +1 -0
  144. package/dist/quill.bubble.css +10 -0
  145. package/dist/quill.bubble.css.map +1 -0
  146. package/dist/quill.core.css +10 -0
  147. package/dist/quill.core.css.map +1 -0
  148. package/dist/quill.core.js +3 -0
  149. package/dist/quill.core.js.LICENSE.txt +7 -0
  150. package/dist/quill.core.js.map +1 -0
  151. package/dist/quill.js +3 -0
  152. package/dist/quill.js.LICENSE.txt +7 -0
  153. package/dist/quill.js.map +1 -0
  154. package/dist/quill.snow.css +10 -0
  155. package/dist/quill.snow.css.map +1 -0
  156. package/formats/align.d.ts +5 -0
  157. package/formats/align.js +10 -0
  158. package/formats/align.js.map +1 -0
  159. package/formats/background.d.ts +5 -0
  160. package/formats/background.js +10 -0
  161. package/formats/background.js.map +1 -0
  162. package/formats/blockquote.d.ts +6 -0
  163. package/formats/blockquote.js +7 -0
  164. package/formats/blockquote.js.map +1 -0
  165. package/formats/bold.d.ts +11 -0
  166. package/formats/bold.js +19 -0
  167. package/formats/bold.js.map +1 -0
  168. package/formats/code.d.ts +15 -0
  169. package/formats/code.js +44 -0
  170. package/formats/code.js.map +1 -0
  171. package/formats/color.d.ts +7 -0
  172. package/formats/color.js +18 -0
  173. package/formats/color.js.map +1 -0
  174. package/formats/direction.d.ts +5 -0
  175. package/formats/direction.js +10 -0
  176. package/formats/direction.js.map +1 -0
  177. package/formats/font.d.ts +7 -0
  178. package/formats/font.js +14 -0
  179. package/formats/font.js.map +1 -0
  180. package/formats/formula.d.ts +10 -0
  181. package/formats/formula.js +34 -0
  182. package/formats/formula.js.map +1 -0
  183. package/formats/header.d.ts +7 -0
  184. package/formats/header.js +10 -0
  185. package/formats/header.js.map +1 -0
  186. package/formats/image.d.ts +13 -0
  187. package/formats/image.js +44 -0
  188. package/formats/image.js.map +1 -0
  189. package/formats/indent.d.ts +8 -0
  190. package/formats/indent.js +30 -0
  191. package/formats/indent.js.map +1 -0
  192. package/formats/italic.d.ts +6 -0
  193. package/formats/italic.js +7 -0
  194. package/formats/italic.js.map +1 -0
  195. package/formats/link.d.ts +13 -0
  196. package/formats/link.js +36 -0
  197. package/formats/link.js.map +1 -0
  198. package/formats/list.d.ts +13 -0
  199. package/formats/list.js +50 -0
  200. package/formats/list.js.map +1 -0
  201. package/formats/script.d.ts +8 -0
  202. package/formats/script.js +21 -0
  203. package/formats/script.js.map +1 -0
  204. package/formats/size.d.ts +4 -0
  205. package/formats/size.js +11 -0
  206. package/formats/size.js.map +1 -0
  207. package/formats/strike.d.ts +6 -0
  208. package/formats/strike.js +7 -0
  209. package/formats/strike.js.map +1 -0
  210. package/formats/table.d.ts +45 -0
  211. package/formats/table.js +176 -0
  212. package/formats/table.js.map +1 -0
  213. package/formats/underline.d.ts +6 -0
  214. package/formats/underline.js +7 -0
  215. package/formats/underline.js.map +1 -0
  216. package/formats/video.d.ts +14 -0
  217. package/formats/video.js +49 -0
  218. package/formats/video.js.map +1 -0
  219. package/modules/clipboard.d.ts +43 -0
  220. package/modules/clipboard.js +477 -0
  221. package/modules/clipboard.js.map +1 -0
  222. package/modules/history.d.ts +36 -0
  223. package/modules/history.js +178 -0
  224. package/modules/history.js.map +1 -0
  225. package/modules/input.d.ts +10 -0
  226. package/modules/input.js +83 -0
  227. package/modules/input.js.map +1 -0
  228. package/modules/keyboard.d.ts +58 -0
  229. package/modules/keyboard.js +713 -0
  230. package/modules/keyboard.js.map +1 -0
  231. package/modules/normalizeExternalHTML/index.d.ts +2 -0
  232. package/modules/normalizeExternalHTML/index.js +12 -0
  233. package/modules/normalizeExternalHTML/index.js.map +1 -0
  234. package/modules/normalizeExternalHTML/normalizers/googleDocs.d.ts +1 -0
  235. package/modules/normalizeExternalHTML/normalizers/googleDocs.js +24 -0
  236. package/modules/normalizeExternalHTML/normalizers/googleDocs.js.map +1 -0
  237. package/modules/normalizeExternalHTML/normalizers/msWord.d.ts +1 -0
  238. package/modules/normalizeExternalHTML/normalizers/msWord.js +87 -0
  239. package/modules/normalizeExternalHTML/normalizers/msWord.js.map +1 -0
  240. package/modules/syntax.d.ts +50 -0
  241. package/modules/syntax.js +332 -0
  242. package/modules/syntax.js.map +1 -0
  243. package/modules/table.d.ts +20 -0
  244. package/modules/table.js +125 -0
  245. package/modules/table.js.map +1 -0
  246. package/modules/tableEmbed.d.ts +27 -0
  247. package/modules/tableEmbed.js +209 -0
  248. package/modules/tableEmbed.js.map +1 -0
  249. package/modules/toolbar.d.ts +24 -0
  250. package/modules/toolbar.js +265 -0
  251. package/modules/toolbar.js.map +1 -0
  252. package/modules/uiNode.d.ts +19 -0
  253. package/modules/uiNode.js +95 -0
  254. package/modules/uiNode.js.map +1 -0
  255. package/modules/uploader.d.ts +15 -0
  256. package/modules/uploader.js +69 -0
  257. package/modules/uploader.js.map +1 -0
  258. package/package.json +102 -0
  259. package/quill.d.ts +5 -0
  260. package/quill.js +82 -0
  261. package/quill.js.map +1 -0
  262. package/themes/base.d.ts +35 -0
  263. package/themes/base.js +257 -0
  264. package/themes/base.js.map +1 -0
  265. package/themes/bubble.d.ts +18 -0
  266. package/themes/bubble.js +114 -0
  267. package/themes/bubble.js.map +1 -0
  268. package/themes/snow.d.ts +9 -0
  269. package/themes/snow.js +122 -0
  270. package/themes/snow.js.map +1 -0
  271. package/types.d.js +2 -0
  272. package/types.d.js.map +1 -0
  273. package/ui/color-picker.d.ts +7 -0
  274. package/ui/color-picker.js +30 -0
  275. package/ui/color-picker.js.map +1 -0
  276. package/ui/icon-picker.d.ts +7 -0
  277. package/ui/icon-picker.js +22 -0
  278. package/ui/icon-picker.js.map +1 -0
  279. package/ui/icons.d.ts +49 -0
  280. package/ui/icons.js +82 -0
  281. package/ui/icons.js.map +1 -0
  282. package/ui/picker.d.ts +16 -0
  283. package/ui/picker.js +171 -0
  284. package/ui/picker.js.map +1 -0
  285. package/ui/tooltip.d.ts +12 -0
  286. package/ui/tooltip.js +56 -0
  287. package/ui/tooltip.js.map +1 -0
@@ -0,0 +1,170 @@
1
+ import { EmbedBlot, Scope } from 'parchment';
2
+ import TextBlot from './text.js';
3
+ class Cursor extends EmbedBlot {
4
+ static blotName = 'cursor';
5
+ static className = 'ql-cursor';
6
+ static tagName = 'span';
7
+ static CONTENTS = '\uFEFF'; // Zero width no break space
8
+
9
+ static value() {
10
+ return undefined;
11
+ }
12
+ constructor(scroll, domNode, selection) {
13
+ super(scroll, domNode);
14
+ this.selection = selection;
15
+ this.textNode = document.createTextNode(Cursor.CONTENTS);
16
+ this.domNode.appendChild(this.textNode);
17
+ this.savedLength = 0;
18
+ }
19
+ detach() {
20
+ // super.detach() will also clear domNode.__blot
21
+ if (this.parent != null) this.parent.removeChild(this);
22
+ }
23
+ format(name, value) {
24
+ if (this.savedLength !== 0) {
25
+ super.format(name, value);
26
+ return;
27
+ }
28
+ // TODO: Fix this next time the file is edited.
29
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
30
+ let target = this;
31
+ let index = 0;
32
+ while (target != null && target.statics.scope !== Scope.BLOCK_BLOT) {
33
+ index += target.offset(target.parent);
34
+ target = target.parent;
35
+ }
36
+ if (target != null) {
37
+ this.savedLength = Cursor.CONTENTS.length;
38
+ // @ts-expect-error TODO: allow empty context in Parchment
39
+ target.optimize();
40
+ target.formatAt(index, Cursor.CONTENTS.length, name, value);
41
+ this.savedLength = 0;
42
+ }
43
+ }
44
+ index(node, offset) {
45
+ if (node === this.textNode) return 0;
46
+ return super.index(node, offset);
47
+ }
48
+ length() {
49
+ return this.savedLength;
50
+ }
51
+ position() {
52
+ return [this.textNode, this.textNode.data.length];
53
+ }
54
+ remove() {
55
+ super.remove();
56
+ // @ts-expect-error Fix me later
57
+ this.parent = null;
58
+ }
59
+ restore() {
60
+ if (this.selection.composing || this.parent == null) return null;
61
+ const range = this.selection.getNativeRange();
62
+ // Browser may push down styles/nodes inside the cursor blot.
63
+ // https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#push-down-values
64
+ while (this.domNode.lastChild != null && this.domNode.lastChild !== this.textNode) {
65
+ // @ts-expect-error Fix me later
66
+ this.domNode.parentNode.insertBefore(this.domNode.lastChild, this.domNode);
67
+ }
68
+ const prevTextBlot = this.prev instanceof TextBlot ? this.prev : null;
69
+ const prevTextLength = prevTextBlot ? prevTextBlot.length() : 0;
70
+ const nextTextBlot = this.next instanceof TextBlot ? this.next : null;
71
+ // @ts-expect-error TODO: make TextBlot.text public
72
+ const nextText = nextTextBlot ? nextTextBlot.text : '';
73
+ const {
74
+ textNode
75
+ } = this;
76
+ // take text from inside this blot and reset it
77
+ const newText = textNode.data.split(Cursor.CONTENTS).join('');
78
+ textNode.data = Cursor.CONTENTS;
79
+
80
+ // proactively merge TextBlots around cursor so that optimization
81
+ // doesn't lose the cursor. the reason we are here in cursor.restore
82
+ // could be that the user clicked in prevTextBlot or nextTextBlot, or
83
+ // the user typed something.
84
+ let mergedTextBlot;
85
+ if (prevTextBlot) {
86
+ mergedTextBlot = prevTextBlot;
87
+ if (newText || nextTextBlot) {
88
+ prevTextBlot.insertAt(prevTextBlot.length(), newText + nextText);
89
+ if (nextTextBlot) {
90
+ nextTextBlot.remove();
91
+ }
92
+ }
93
+ } else if (nextTextBlot) {
94
+ mergedTextBlot = nextTextBlot;
95
+ nextTextBlot.insertAt(0, newText);
96
+ } else {
97
+ const newTextNode = document.createTextNode(newText);
98
+ mergedTextBlot = this.scroll.create(newTextNode);
99
+ this.parent.insertBefore(mergedTextBlot, this);
100
+ }
101
+ this.remove();
102
+ if (range) {
103
+ // calculate selection to restore
104
+ const remapOffset = (node, offset) => {
105
+ if (prevTextBlot && node === prevTextBlot.domNode) {
106
+ return offset;
107
+ }
108
+ if (node === textNode) {
109
+ return prevTextLength + offset - 1;
110
+ }
111
+ if (nextTextBlot && node === nextTextBlot.domNode) {
112
+ return prevTextLength + newText.length + offset;
113
+ }
114
+ return null;
115
+ };
116
+ const start = remapOffset(range.start.node, range.start.offset);
117
+ const end = remapOffset(range.end.node, range.end.offset);
118
+ if (start !== null && end !== null) {
119
+ return {
120
+ startNode: mergedTextBlot.domNode,
121
+ startOffset: start,
122
+ endNode: mergedTextBlot.domNode,
123
+ endOffset: end
124
+ };
125
+ }
126
+ }
127
+ return null;
128
+ }
129
+ update(mutations, context) {
130
+ if (mutations.some(mutation => {
131
+ return mutation.type === 'characterData' && mutation.target === this.textNode;
132
+ })) {
133
+ const range = this.restore();
134
+ if (range) context.range = range;
135
+ }
136
+ }
137
+
138
+ // Avoid .ql-cursor being a descendant of `<a/>`.
139
+ // The reason is Safari pushes down `<a/>` on text insertion.
140
+ // That will cause DOM nodes not sync with the model.
141
+ //
142
+ // For example ({I} is the caret), given the markup:
143
+ // <a><span class="ql-cursor">\uFEFF{I}</span></a>
144
+ // When typing a char "x", `<a/>` will be pushed down inside the `<span>` first:
145
+ // <span class="ql-cursor"><a>\uFEFF{I}</a></span>
146
+ // And then "x" will be inserted after `<a/>`:
147
+ // <span class="ql-cursor"><a>\uFEFF</a>d{I}</span>
148
+ optimize(context) {
149
+ // @ts-expect-error Fix me later
150
+ super.optimize(context);
151
+ let {
152
+ parent
153
+ } = this;
154
+ while (parent) {
155
+ if (parent.domNode.tagName === 'A') {
156
+ this.savedLength = Cursor.CONTENTS.length;
157
+ // @ts-expect-error TODO: make isolate generic
158
+ parent.isolate(this.offset(parent), this.length()).unwrap();
159
+ this.savedLength = 0;
160
+ break;
161
+ }
162
+ parent = parent.parent;
163
+ }
164
+ }
165
+ value() {
166
+ return '';
167
+ }
168
+ }
169
+ export default Cursor;
170
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","names":["EmbedBlot","Scope","TextBlot","Cursor","blotName","className","tagName","CONTENTS","value","undefined","constructor","scroll","domNode","selection","textNode","document","createTextNode","appendChild","savedLength","detach","parent","removeChild","format","name","target","index","statics","scope","BLOCK_BLOT","offset","length","optimize","formatAt","node","position","data","remove","restore","composing","range","getNativeRange","lastChild","parentNode","insertBefore","prevTextBlot","prev","prevTextLength","nextTextBlot","next","nextText","text","newText","split","join","mergedTextBlot","insertAt","newTextNode","create","remapOffset","start","end","startNode","startOffset","endNode","endOffset","update","mutations","context","some","mutation","type","isolate","unwrap"],"sources":["../../src/blots/cursor.ts"],"sourcesContent":["import { EmbedBlot, Scope } from 'parchment';\nimport type { Parent, ScrollBlot } from 'parchment';\nimport type Selection from '../core/selection.js';\nimport TextBlot from './text.js';\nimport type { EmbedContextRange } from './embed.js';\n\nclass Cursor extends EmbedBlot {\n static blotName = 'cursor';\n static className = 'ql-cursor';\n static tagName = 'span';\n static CONTENTS = '\\uFEFF'; // Zero width no break space\n\n static value() {\n return undefined;\n }\n\n selection: Selection;\n textNode: Text;\n savedLength: number;\n\n constructor(scroll: ScrollBlot, domNode: HTMLElement, selection: Selection) {\n super(scroll, domNode);\n this.selection = selection;\n this.textNode = document.createTextNode(Cursor.CONTENTS);\n this.domNode.appendChild(this.textNode);\n this.savedLength = 0;\n }\n\n detach() {\n // super.detach() will also clear domNode.__blot\n if (this.parent != null) this.parent.removeChild(this);\n }\n\n format(name: string, value: unknown) {\n if (this.savedLength !== 0) {\n super.format(name, value);\n return;\n }\n // TODO: Fix this next time the file is edited.\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let target: Parent | this = this;\n let index = 0;\n while (target != null && target.statics.scope !== Scope.BLOCK_BLOT) {\n index += target.offset(target.parent);\n target = target.parent;\n }\n if (target != null) {\n this.savedLength = Cursor.CONTENTS.length;\n // @ts-expect-error TODO: allow empty context in Parchment\n target.optimize();\n target.formatAt(index, Cursor.CONTENTS.length, name, value);\n this.savedLength = 0;\n }\n }\n\n index(node: Node, offset: number) {\n if (node === this.textNode) return 0;\n return super.index(node, offset);\n }\n\n length() {\n return this.savedLength;\n }\n\n position(): [Text, number] {\n return [this.textNode, this.textNode.data.length];\n }\n\n remove() {\n super.remove();\n // @ts-expect-error Fix me later\n this.parent = null;\n }\n\n restore(): EmbedContextRange | null {\n if (this.selection.composing || this.parent == null) return null;\n const range = this.selection.getNativeRange();\n // Browser may push down styles/nodes inside the cursor blot.\n // https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#push-down-values\n while (\n this.domNode.lastChild != null &&\n this.domNode.lastChild !== this.textNode\n ) {\n // @ts-expect-error Fix me later\n this.domNode.parentNode.insertBefore(\n this.domNode.lastChild,\n this.domNode,\n );\n }\n\n const prevTextBlot = this.prev instanceof TextBlot ? this.prev : null;\n const prevTextLength = prevTextBlot ? prevTextBlot.length() : 0;\n const nextTextBlot = this.next instanceof TextBlot ? this.next : null;\n // @ts-expect-error TODO: make TextBlot.text public\n const nextText = nextTextBlot ? nextTextBlot.text : '';\n const { textNode } = this;\n // take text from inside this blot and reset it\n const newText = textNode.data.split(Cursor.CONTENTS).join('');\n textNode.data = Cursor.CONTENTS;\n\n // proactively merge TextBlots around cursor so that optimization\n // doesn't lose the cursor. the reason we are here in cursor.restore\n // could be that the user clicked in prevTextBlot or nextTextBlot, or\n // the user typed something.\n let mergedTextBlot;\n if (prevTextBlot) {\n mergedTextBlot = prevTextBlot;\n if (newText || nextTextBlot) {\n prevTextBlot.insertAt(prevTextBlot.length(), newText + nextText);\n if (nextTextBlot) {\n nextTextBlot.remove();\n }\n }\n } else if (nextTextBlot) {\n mergedTextBlot = nextTextBlot;\n nextTextBlot.insertAt(0, newText);\n } else {\n const newTextNode = document.createTextNode(newText);\n mergedTextBlot = this.scroll.create(newTextNode);\n this.parent.insertBefore(mergedTextBlot, this);\n }\n\n this.remove();\n if (range) {\n // calculate selection to restore\n const remapOffset = (node: Node, offset: number) => {\n if (prevTextBlot && node === prevTextBlot.domNode) {\n return offset;\n }\n if (node === textNode) {\n return prevTextLength + offset - 1;\n }\n if (nextTextBlot && node === nextTextBlot.domNode) {\n return prevTextLength + newText.length + offset;\n }\n return null;\n };\n\n const start = remapOffset(range.start.node, range.start.offset);\n const end = remapOffset(range.end.node, range.end.offset);\n if (start !== null && end !== null) {\n return {\n startNode: mergedTextBlot.domNode,\n startOffset: start,\n endNode: mergedTextBlot.domNode,\n endOffset: end,\n };\n }\n }\n return null;\n }\n\n update(mutations: MutationRecord[], context: Record<string, unknown>) {\n if (\n mutations.some((mutation) => {\n return (\n mutation.type === 'characterData' && mutation.target === this.textNode\n );\n })\n ) {\n const range = this.restore();\n if (range) context.range = range;\n }\n }\n\n // Avoid .ql-cursor being a descendant of `<a/>`.\n // The reason is Safari pushes down `<a/>` on text insertion.\n // That will cause DOM nodes not sync with the model.\n //\n // For example ({I} is the caret), given the markup:\n // <a><span class=\"ql-cursor\">\\uFEFF{I}</span></a>\n // When typing a char \"x\", `<a/>` will be pushed down inside the `<span>` first:\n // <span class=\"ql-cursor\"><a>\\uFEFF{I}</a></span>\n // And then \"x\" will be inserted after `<a/>`:\n // <span class=\"ql-cursor\"><a>\\uFEFF</a>d{I}</span>\n optimize(context?: unknown) {\n // @ts-expect-error Fix me later\n super.optimize(context);\n\n let { parent } = this;\n while (parent) {\n if (parent.domNode.tagName === 'A') {\n this.savedLength = Cursor.CONTENTS.length;\n // @ts-expect-error TODO: make isolate generic\n parent.isolate(this.offset(parent), this.length()).unwrap();\n this.savedLength = 0;\n break;\n }\n parent = parent.parent;\n }\n }\n\n value() {\n return '';\n }\n}\n\nexport default Cursor;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,KAAK,QAAQ,WAAW;AAG5C,OAAOC,QAAQ,MAAM,WAAW;AAGhC,MAAMC,MAAM,SAASH,SAAS,CAAC;EAC7B,OAAOI,QAAQ,GAAG,QAAQ;EAC1B,OAAOC,SAAS,GAAG,WAAW;EAC9B,OAAOC,OAAO,GAAG,MAAM;EACvB,OAAOC,QAAQ,GAAG,QAAQ,CAAC,CAAC;;EAE5B,OAAOC,KAAKA,CAAA,EAAG;IACb,OAAOC,SAAS;EAClB;EAMAC,WAAWA,CAACC,MAAkB,EAAEC,OAAoB,EAAEC,SAAoB,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AAO,KAAK,GAAG,EAAE;QAClC,IAAI,CAACY,WAAW,GAAGf,MAAM,CAACI,QAAQ,CAACuB,MAAM;QACzC;QACAV,MAAM,CAACmD,OAAO,CAAC,IAAI,CAAC1C,MAAM,CAACT,MAAM,CAAC,EAAE,IAAI,CAACU,MAAM,CAAC,CAAC,CAAC,CAAC0C,MAAM,CAAC,CAAC;QAC3D,IAAI,CAACtD,WAAW,GAAG,CAAC;QACpB;MACF;MACAE,MAAM,GAAGA,MAAM,CAACA,MAAM;IACxB;EACF;EAEAZ,KAAKA,CAAA,EAAG;IACN,OAAO,EAAE;EACX;AACF;AAEA,eAAeL,MAAM","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ import type { ScrollBlot } from 'parchment';
2
+ import { EmbedBlot } from 'parchment';
3
+ export interface EmbedContextRange {
4
+ startNode: Node | Text;
5
+ startOffset: number;
6
+ endNode?: Node | Text;
7
+ endOffset?: number;
8
+ }
9
+ declare class Embed extends EmbedBlot {
10
+ contentNode: HTMLSpanElement;
11
+ leftGuard: Text;
12
+ rightGuard: Text;
13
+ constructor(scroll: ScrollBlot, node: Node);
14
+ index(node: Node, offset: number): number;
15
+ restore(node: Text): EmbedContextRange | null;
16
+ update(mutations: MutationRecord[], context: Record<string, unknown>): void;
17
+ }
18
+ export default Embed;
package/blots/embed.js ADDED
@@ -0,0 +1,72 @@
1
+ import { EmbedBlot } from 'parchment';
2
+ import TextBlot from './text.js';
3
+ const GUARD_TEXT = '\uFEFF';
4
+ class Embed extends EmbedBlot {
5
+ constructor(scroll, node) {
6
+ super(scroll, node);
7
+ this.contentNode = document.createElement('span');
8
+ this.contentNode.setAttribute('contenteditable', 'false');
9
+ Array.from(this.domNode.childNodes).forEach(childNode => {
10
+ this.contentNode.appendChild(childNode);
11
+ });
12
+ this.leftGuard = document.createTextNode(GUARD_TEXT);
13
+ this.rightGuard = document.createTextNode(GUARD_TEXT);
14
+ this.domNode.appendChild(this.leftGuard);
15
+ this.domNode.appendChild(this.contentNode);
16
+ this.domNode.appendChild(this.rightGuard);
17
+ }
18
+ index(node, offset) {
19
+ if (node === this.leftGuard) return 0;
20
+ if (node === this.rightGuard) return 1;
21
+ return super.index(node, offset);
22
+ }
23
+ restore(node) {
24
+ let range = null;
25
+ let textNode;
26
+ const text = node.data.split(GUARD_TEXT).join('');
27
+ if (node === this.leftGuard) {
28
+ if (this.prev instanceof TextBlot) {
29
+ const prevLength = this.prev.length();
30
+ this.prev.insertAt(prevLength, text);
31
+ range = {
32
+ startNode: this.prev.domNode,
33
+ startOffset: prevLength + text.length
34
+ };
35
+ } else {
36
+ textNode = document.createTextNode(text);
37
+ this.parent.insertBefore(this.scroll.create(textNode), this);
38
+ range = {
39
+ startNode: textNode,
40
+ startOffset: text.length
41
+ };
42
+ }
43
+ } else if (node === this.rightGuard) {
44
+ if (this.next instanceof TextBlot) {
45
+ this.next.insertAt(0, text);
46
+ range = {
47
+ startNode: this.next.domNode,
48
+ startOffset: text.length
49
+ };
50
+ } else {
51
+ textNode = document.createTextNode(text);
52
+ this.parent.insertBefore(this.scroll.create(textNode), this.next);
53
+ range = {
54
+ startNode: textNode,
55
+ startOffset: text.length
56
+ };
57
+ }
58
+ }
59
+ node.data = GUARD_TEXT;
60
+ return range;
61
+ }
62
+ update(mutations, context) {
63
+ mutations.forEach(mutation => {
64
+ if (mutation.type === 'characterData' && (mutation.target === this.leftGuard || mutation.target === this.rightGuard)) {
65
+ const range = this.restore(mutation.target);
66
+ if (range) context.range = range;
67
+ }
68
+ });
69
+ }
70
+ }
71
+ export default Embed;
72
+ //# sourceMappingURL=embed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed.js","names":["EmbedBlot","TextBlot","GUARD_TEXT","Embed","constructor","scroll","node","contentNode","document","createElement","setAttribute","Array","from","domNode","childNodes","forEach","childNode","appendChild","leftGuard","createTextNode","rightGuard","index","offset","restore","range","textNode","text","data","split","join","prev","prevLength","length","insertAt","startNode","startOffset","parent","insertBefore","create","next","update","mutations","context","mutation","type","target"],"sources":["../../src/blots/embed.ts"],"sourcesContent":["import type { ScrollBlot } from 'parchment';\nimport { EmbedBlot } from 'parchment';\nimport TextBlot from './text.js';\n\nconst GUARD_TEXT = '\\uFEFF';\n\nexport interface EmbedContextRange {\n startNode: Node | Text;\n startOffset: number;\n endNode?: Node | Text;\n endOffset?: number;\n}\n\nclass Embed extends EmbedBlot {\n contentNode: HTMLSpanElement;\n leftGuard: Text;\n rightGuard: Text;\n\n constructor(scroll: ScrollBlot, node: Node) {\n super(scroll, node);\n this.contentNode = document.createElement('span');\n this.contentNode.setAttribute('contenteditable', 'false');\n Array.from(this.domNode.childNodes).forEach((childNode) => {\n this.contentNode.appendChild(childNode);\n });\n this.leftGuard = document.createTextNode(GUARD_TEXT);\n this.rightGuard = document.createTextNode(GUARD_TEXT);\n this.domNode.appendChild(this.leftGuard);\n this.domNode.appendChild(this.contentNode);\n this.domNode.appendChild(this.rightGuard);\n }\n\n index(node: Node, offset: number) {\n if (node === this.leftGuard) return 0;\n if (node === this.rightGuard) return 1;\n return super.index(node, offset);\n }\n\n restore(node: Text): EmbedContextRange | null {\n let range: EmbedContextRange | null = null;\n let textNode: Text;\n const text = node.data.split(GUARD_TEXT).join('');\n if (node === this.leftGuard) {\n if (this.prev instanceof TextBlot) {\n const prevLength = this.prev.length();\n this.prev.insertAt(prevLength, text);\n range = {\n startNode: this.prev.domNode,\n startOffset: prevLength + text.length,\n };\n } else {\n textNode = document.createTextNode(text);\n this.parent.insertBefore(this.scroll.create(textNode), this);\n range = {\n startNode: textNode,\n startOffset: text.length,\n };\n }\n } else if (node === this.rightGuard) {\n if (this.next instanceof TextBlot) {\n this.next.insertAt(0, text);\n range = {\n startNode: this.next.domNode,\n startOffset: text.length,\n };\n } else {\n textNode = document.createTextNode(text);\n this.parent.insertBefore(this.scroll.create(textNode), this.next);\n range = {\n startNode: textNode,\n startOffset: text.length,\n };\n }\n }\n node.data = GUARD_TEXT;\n return range;\n }\n\n update(mutations: MutationRecord[], context: Record<string, unknown>) {\n mutations.forEach((mutation) => {\n if (\n mutation.type === 'characterData' &&\n (mutation.target === this.leftGuard ||\n mutation.target === this.rightGuard)\n ) {\n const range = this.restore(mutation.target as Text);\n if (range) context.range = range;\n }\n });\n }\n}\n\nexport default Embed;\n"],"mappings":"AACA,SAASA,SAAS,QAAQ,WAAW;AACrC,OAAOC,QAAQ,MAAM,WAAW;AAEhC,MAAMC,UAAU,GAAG,QAAQ;AAS3B,MAAMC,KAAK,SAASH,SAAS,CAAC;EAK5BI,WAAWA,CAACC,MAAkB,EAAEC,IAAU,EAAE;IAC1C,KAAK,CAACD,MAAM,EAAEC,IAAI,CAAC;IACnB,IAAI,CAACC,WAAW,GAAGC,QAAQ,CAACC,aAAa,CAAC,MAAM,CAAC;IACjD,IAAI,CAACF,WAAW,CAACG,YAAY,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACzDC,KAAK,CAACC,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,UAAU,CAAC,CAACC,OAAO,CAAEC,SAAS,IAAK;MACzD,IAAI,CAACT,WAAW,CAACU,WAAW,CAACD,SAAS,CAAC;IACzC,CAAC,CAAC;IACF,IAAI,CAACE,SAAS,GAAGV,QAAQ,CAACW,cAAc,CAACjB,UAAU,CAAC;IACpD,IAAI,CAACkB,UAAU,GAAGZ,QAAQ,CAACW,cAAc,CAACjB,UAAU,CAAC;IACrD,IAAI,CAACW,OAAO,CAACI,WAAW,CAAC,IAAI,CAACC,SAAS,CAAC;IACxC,IAAI,CAACL,OAAO,CAACI,WAAW,CAAC,IAAI,CAACV,WAAW,CAAC;IAC1C,IAAI,CAACM,OAAO,CAACI,WAAW,CAAC,IAAI,CAACG,UAAU,CAAC;EAC3C;EAEAC,KAAKA,CAACf,IAAU,EAAEgB,MAAc,EAAE;IAChC,IAAIhB,IAAI,KAAK,IAAI,CAACY,SAAS,EAAE,OAAO,CAAC;IACrC,IAAIZ,IAAI,KAAK,IAAI,CAACc,UAAU,EAAE,OAAO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MACH,CAAC,MAAM;QACLP,QAAQ,GAAGjB,QAAQ,CAACW,cAAc,CAACO,IAAI,CAAC;QACxC,IAAI,CAACU,MAAM,CAACC,YAAY,CAAC,IAAI,CAAChC,MAAM,CAACiC,MAAM,CAACb,QAAQ,CAAC,EAAE,IAAI,CAACc,IAAI,CAAC;QACjEf,KAAK,GAAG;UACNU,SAAS,EAAET,QAAQ;UACnBU,WAAW,EAAET,IAAI,CAACM;QACpB,CAAC;MACH;IACF;IACA1B,IAAI,CAACqB,IAAI,GAAGzB,UAAU;IACtB,OAAOsB,KAAK;EACd;EAEAgB,MAAMA,CAACC,SAA2B,EAAEC,OAAgC,EAAE;IACpED,SAAS,CAAC1B,OAAO,CAAE4B,QAAQ,IAAK;MAC9B,IACEA,QAAQ,CAACC,IAAI,KAAK,eAAe,KAChCD,QAAQ,CAACE,MAAM,KAAK,IAAI,CAAC3B,SAAS,IACjCyB,QAAQ,CAACE,MAAM,KAAK,IAAI,CAACzB,UAAU,CAAC,EACtC;QACA,MAAMI,KAAK,GAAG,IAAI,CAACD,OAAO,CAACoB,QAAQ,CAACE,MAAc,CAAC;QACnD,IAAIrB,KAAK,EAAEkB,OAAO,CAAClB,KAAK,GAAGA,KAAK;MAClC;IACF,CAAC,CAAC;EACJ;AACF;AAEA,eAAerB,KAAK","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ import { InlineBlot } from 'parchment';
2
+ import type { BlotConstructor } from 'parchment';
3
+ declare class Inline extends InlineBlot {
4
+ static allowedChildren: BlotConstructor[];
5
+ static order: string[];
6
+ static compare(self: string, other: string): number;
7
+ formatAt(index: number, length: number, name: string, value: unknown): void;
8
+ optimize(context: {
9
+ [key: string]: any;
10
+ }): void;
11
+ }
12
+ export default Inline;
@@ -0,0 +1,48 @@
1
+ import { EmbedBlot, InlineBlot, Scope } from 'parchment';
2
+ import Break from './break.js';
3
+ import Text from './text.js';
4
+ class Inline extends InlineBlot {
5
+ static allowedChildren = [Inline, Break, EmbedBlot, Text];
6
+ // Lower index means deeper in the DOM tree, since not found (-1) is for embeds
7
+ static order = ['cursor', 'inline',
8
+ // Must be lower
9
+ 'link',
10
+ // Chrome wants <a> to be lower
11
+ 'underline', 'strike', 'italic', 'bold', 'script', 'code' // Must be higher
12
+ ];
13
+ static compare(self, other) {
14
+ const selfIndex = Inline.order.indexOf(self);
15
+ const otherIndex = Inline.order.indexOf(other);
16
+ if (selfIndex >= 0 || otherIndex >= 0) {
17
+ return selfIndex - otherIndex;
18
+ }
19
+ if (self === other) {
20
+ return 0;
21
+ }
22
+ if (self < other) {
23
+ return -1;
24
+ }
25
+ return 1;
26
+ }
27
+ formatAt(index, length, name, value) {
28
+ if (Inline.compare(this.statics.blotName, name) < 0 && this.scroll.query(name, Scope.BLOT)) {
29
+ const blot = this.isolate(index, length);
30
+ if (value) {
31
+ blot.wrap(name, value);
32
+ }
33
+ } else {
34
+ super.formatAt(index, length, name, value);
35
+ }
36
+ }
37
+ optimize(context) {
38
+ super.optimize(context);
39
+ if (this.parent instanceof Inline && Inline.compare(this.statics.blotName, this.parent.statics.blotName) > 0) {
40
+ const parent = this.parent.isolate(this.offset(), this.length());
41
+ // @ts-expect-error TODO: make isolate generic
42
+ this.moveChildren(parent);
43
+ parent.wrap(this);
44
+ }
45
+ }
46
+ }
47
+ export default Inline;
48
+ //# sourceMappingURL=inline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inline.js","names":["EmbedBlot","InlineBlot","Scope","Break","Text","Inline","allowedChildren","order","compare","self","other","selfIndex","indexOf","otherIndex","formatAt","index","length","name","value","statics","blotName","scroll","query","BLOT","blot","isolate","wrap","optimize","context","parent","offset","moveChildren"],"sources":["../../src/blots/inline.ts"],"sourcesContent":["import { EmbedBlot, InlineBlot, Scope } from 'parchment';\nimport type { BlotConstructor } from 'parchment';\nimport Break from './break.js';\nimport Text from './text.js';\n\nclass Inline extends InlineBlot {\n static allowedChildren: BlotConstructor[] = [Inline, Break, EmbedBlot, Text];\n // Lower index means deeper in the DOM tree, since not found (-1) is for embeds\n static order = [\n 'cursor',\n 'inline', // Must be lower\n 'link', // Chrome wants <a> to be lower\n 'underline',\n 'strike',\n 'italic',\n 'bold',\n 'script',\n 'code', // Must be higher\n ];\n\n static compare(self: string, other: string) {\n const selfIndex = Inline.order.indexOf(self);\n const otherIndex = Inline.order.indexOf(other);\n if (selfIndex >= 0 || otherIndex >= 0) {\n return selfIndex - otherIndex;\n }\n if (self === other) {\n return 0;\n }\n if (self < other) {\n return -1;\n }\n return 1;\n }\n\n formatAt(index: number, length: number, name: string, value: unknown) {\n if (\n Inline.compare(this.statics.blotName, name) < 0 &&\n this.scroll.query(name, Scope.BLOT)\n ) {\n const blot = this.isolate(index, length);\n if (value) {\n blot.wrap(name, value);\n }\n } else {\n super.formatAt(index, length, name, value);\n }\n }\n\n optimize(context: { [key: string]: any }) {\n super.optimize(context);\n if (\n this.parent instanceof Inline &&\n Inline.compare(this.statics.blotName, this.parent.statics.blotName) > 0\n ) {\n const parent = this.parent.isolate(this.offset(), this.length());\n // @ts-expect-error TODO: make isolate generic\n this.moveChildren(parent);\n parent.wrap(this);\n }\n }\n}\n\nexport default Inline;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,UAAU,EAAEC,KAAK,QAAQ,WAAW;AAExD,OAAOC,KAAK,MAAM,YAAY;AAC9B,OAAOC,IAAI,MAAM,WAAW;AAE5B,MAAMC,MAAM,SAASJ,UAAU,CAAC;EAC9B,OAAOK,eAAe,GAAsB,CAACD,MAAM,EAAEF,KAAK,EAAEH,SAAS,EAAEI,IAAI,CAAC;EAC5E;EACA,OAAOG,KAAK,GAAG,CACb,QAAQ,EACR,QAAQ;EAAE;EACV,MAAM;EAAE;EACR,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,CAAE;EAAA,CACT;EAED,OAAOC,OAAOA,CAACC,IAAY,EAAEC,KAAa,EAAE;IAC1C,MAAMC,SAAS,GAAGN,MAAM,CAACE,KA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C,CAAC,EAAE,IAAI,CAACd,MAAM,CAAC,CAAC,CAAC;MAChE;MACA,IAAI,CAACe,YAAY,CAACF,MAAM,CAAC;MACzBA,MAAM,CAACH,IAAI,CAAC,IAAI,CAAC;IACnB;EACF;AACF;AAEA,eAAerB,MAAM","ignoreList":[]}
@@ -0,0 +1,49 @@
1
+ import { LeafBlot, ScrollBlot } from 'parchment';
2
+ import type { Blot, Registry } from 'parchment';
3
+ import Delta from 'quill-delta';
4
+ import Emitter from '../core/emitter.js';
5
+ import type { EmitterSource } from '../core/emitter.js';
6
+ import Block, { BlockEmbed } from './block.js';
7
+ import Container from './container.js';
8
+ declare class Scroll extends ScrollBlot {
9
+ static blotName: string;
10
+ static className: string;
11
+ static tagName: string;
12
+ static defaultChild: typeof Block;
13
+ static allowedChildren: (typeof Block | typeof BlockEmbed | typeof Container)[];
14
+ emitter: Emitter;
15
+ batch: false | MutationRecord[];
16
+ constructor(registry: Registry, domNode: HTMLDivElement, { emitter }: {
17
+ emitter: Emitter;
18
+ });
19
+ batchStart(): void;
20
+ batchEnd(): void;
21
+ emitMount(blot: Blot): void;
22
+ emitUnmount(blot: Blot): void;
23
+ emitEmbedUpdate(blot: Blot, change: unknown): void;
24
+ deleteAt(index: number, length: number): void;
25
+ enable(enabled?: boolean): void;
26
+ formatAt(index: number, length: number, format: string, value: unknown): void;
27
+ insertAt(index: number, value: string, def?: unknown): void;
28
+ insertBefore(blot: Blot, ref?: Blot | null): void;
29
+ insertContents(index: number, delta: Delta): void;
30
+ isEnabled(): boolean;
31
+ leaf(index: number): [LeafBlot | null, number];
32
+ line(index: number): [Block | BlockEmbed | null, number];
33
+ lines(index?: number, length?: number): (Block | BlockEmbed)[];
34
+ optimize(context?: {
35
+ [key: string]: any;
36
+ }): void;
37
+ optimize(mutations?: MutationRecord[], context?: {
38
+ [key: string]: any;
39
+ }): void;
40
+ path(index: number): [Blot, number][];
41
+ remove(): void;
42
+ update(source?: EmitterSource): void;
43
+ update(mutations?: MutationRecord[]): void;
44
+ updateEmbedAt(index: number, key: string, change: unknown): void;
45
+ protected handleDragStart(event: DragEvent): void;
46
+ private deltaToRenderBlocks;
47
+ private createBlock;
48
+ }
49
+ export default Scroll;