@plotdb/quill 1.0.1 → 1.0.2

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 (291) hide show
  1. package/blots/block.d.ts +34 -0
  2. package/blots/block.js +182 -0
  3. package/blots/block.js.map +1 -0
  4. package/blots/break.d.ts +8 -0
  5. package/blots/break.js +21 -0
  6. package/blots/break.js.map +1 -0
  7. package/blots/container.d.ts +4 -0
  8. package/blots/container.js +4 -0
  9. package/blots/container.js.map +1 -0
  10. package/blots/cursor.d.ts +26 -0
  11. package/blots/cursor.js +170 -0
  12. package/blots/cursor.js.map +1 -0
  13. package/blots/embed.d.ts +18 -0
  14. package/blots/embed.js +72 -0
  15. package/blots/embed.js.map +1 -0
  16. package/blots/inline.d.ts +12 -0
  17. package/blots/inline.js +48 -0
  18. package/blots/inline.js.map +1 -0
  19. package/blots/scroll.d.ts +49 -0
  20. package/blots/scroll.js +349 -0
  21. package/blots/scroll.js.map +1 -0
  22. package/blots/text.d.ts +5 -0
  23. package/blots/text.js +16 -0
  24. package/blots/text.js.map +1 -0
  25. package/core/composition.d.ts +12 -0
  26. package/core/composition.js +44 -0
  27. package/core/composition.js.map +1 -0
  28. package/core/editor.d.ts +28 -0
  29. package/core/editor.js +404 -0
  30. package/core/editor.js.map +1 -0
  31. package/core/emitter.d.ts +33 -0
  32. package/core/emitter.js +78 -0
  33. package/core/emitter.js.map +1 -0
  34. package/core/instances.d.ts +3 -0
  35. package/core/instances.js +2 -0
  36. package/core/instances.js.map +1 -0
  37. package/core/logger.d.ts +7 -0
  38. package/core/logger.js +24 -0
  39. package/core/logger.js.map +1 -0
  40. package/core/module.d.ts +8 -0
  41. package/core/module.js +10 -0
  42. package/core/module.js.map +1 -0
  43. package/core/quill.d.ts +218 -0
  44. package/core/quill.js +630 -0
  45. package/core/quill.js.map +1 -0
  46. package/core/selection.d.ts +74 -0
  47. package/core/selection.js +374 -0
  48. package/core/selection.js.map +1 -0
  49. package/core/theme.d.ts +32 -0
  50. package/core/theme.js +28 -0
  51. package/core/theme.js.map +1 -0
  52. package/core/utils/createRegistryWithFormats.d.ts +5 -0
  53. package/core/utils/createRegistryWithFormats.js +29 -0
  54. package/core/utils/createRegistryWithFormats.js.map +1 -0
  55. package/core/utils/scrollRectIntoView.d.ts +11 -0
  56. package/core/utils/scrollRectIntoView.js +110 -0
  57. package/core/utils/scrollRectIntoView.js.map +1 -0
  58. package/core.d.ts +7 -0
  59. package/core.js +37 -0
  60. package/core.js.map +1 -0
  61. package/dist/quill.bubble.css +10 -0
  62. package/dist/quill.bubble.css.map +1 -0
  63. package/dist/quill.core.css +10 -0
  64. package/dist/quill.core.css.map +1 -0
  65. package/dist/quill.core.js +3 -0
  66. package/dist/quill.core.js.LICENSE.txt +7 -0
  67. package/dist/quill.core.js.map +1 -0
  68. package/dist/quill.js +3 -0
  69. package/dist/quill.js.LICENSE.txt +7 -0
  70. package/dist/quill.js.map +1 -0
  71. package/dist/quill.snow.css +10 -0
  72. package/dist/quill.snow.css.map +1 -0
  73. package/formats/align.d.ts +5 -0
  74. package/formats/align.js +10 -0
  75. package/formats/align.js.map +1 -0
  76. package/formats/background.d.ts +5 -0
  77. package/formats/background.js +10 -0
  78. package/formats/background.js.map +1 -0
  79. package/formats/blockquote.d.ts +6 -0
  80. package/formats/blockquote.js +7 -0
  81. package/formats/blockquote.js.map +1 -0
  82. package/formats/bold.d.ts +11 -0
  83. package/formats/bold.js +19 -0
  84. package/formats/bold.js.map +1 -0
  85. package/formats/code.d.ts +15 -0
  86. package/formats/code.js +44 -0
  87. package/formats/code.js.map +1 -0
  88. package/formats/color.d.ts +7 -0
  89. package/formats/color.js +18 -0
  90. package/formats/color.js.map +1 -0
  91. package/formats/direction.d.ts +5 -0
  92. package/formats/direction.js +10 -0
  93. package/formats/direction.js.map +1 -0
  94. package/formats/font.d.ts +7 -0
  95. package/formats/font.js +14 -0
  96. package/formats/font.js.map +1 -0
  97. package/formats/formula.d.ts +10 -0
  98. package/formats/formula.js +34 -0
  99. package/formats/formula.js.map +1 -0
  100. package/formats/header.d.ts +7 -0
  101. package/formats/header.js +10 -0
  102. package/formats/header.js.map +1 -0
  103. package/formats/image.d.ts +13 -0
  104. package/formats/image.js +44 -0
  105. package/formats/image.js.map +1 -0
  106. package/formats/indent.d.ts +8 -0
  107. package/formats/indent.js +30 -0
  108. package/formats/indent.js.map +1 -0
  109. package/formats/italic.d.ts +6 -0
  110. package/formats/italic.js +7 -0
  111. package/formats/italic.js.map +1 -0
  112. package/formats/link.d.ts +13 -0
  113. package/formats/link.js +36 -0
  114. package/formats/link.js.map +1 -0
  115. package/formats/list.d.ts +13 -0
  116. package/formats/list.js +50 -0
  117. package/formats/list.js.map +1 -0
  118. package/formats/script.d.ts +8 -0
  119. package/formats/script.js +21 -0
  120. package/formats/script.js.map +1 -0
  121. package/formats/size.d.ts +4 -0
  122. package/formats/size.js +11 -0
  123. package/formats/size.js.map +1 -0
  124. package/formats/strike.d.ts +6 -0
  125. package/formats/strike.js +7 -0
  126. package/formats/strike.js.map +1 -0
  127. package/formats/table.d.ts +45 -0
  128. package/formats/table.js +176 -0
  129. package/formats/table.js.map +1 -0
  130. package/formats/underline.d.ts +6 -0
  131. package/formats/underline.js +7 -0
  132. package/formats/underline.js.map +1 -0
  133. package/formats/video.d.ts +14 -0
  134. package/formats/video.js +49 -0
  135. package/formats/video.js.map +1 -0
  136. package/modules/clipboard.d.ts +43 -0
  137. package/modules/clipboard.js +477 -0
  138. package/modules/clipboard.js.map +1 -0
  139. package/modules/history.d.ts +36 -0
  140. package/modules/history.js +178 -0
  141. package/modules/history.js.map +1 -0
  142. package/modules/input.d.ts +10 -0
  143. package/modules/input.js +83 -0
  144. package/modules/input.js.map +1 -0
  145. package/modules/keyboard.d.ts +58 -0
  146. package/modules/keyboard.js +713 -0
  147. package/modules/keyboard.js.map +1 -0
  148. package/modules/normalizeExternalHTML/index.d.ts +2 -0
  149. package/modules/normalizeExternalHTML/index.js +12 -0
  150. package/modules/normalizeExternalHTML/index.js.map +1 -0
  151. package/modules/normalizeExternalHTML/normalizers/googleDocs.d.ts +1 -0
  152. package/modules/normalizeExternalHTML/normalizers/googleDocs.js +24 -0
  153. package/modules/normalizeExternalHTML/normalizers/googleDocs.js.map +1 -0
  154. package/modules/normalizeExternalHTML/normalizers/msWord.d.ts +1 -0
  155. package/modules/normalizeExternalHTML/normalizers/msWord.js +87 -0
  156. package/modules/normalizeExternalHTML/normalizers/msWord.js.map +1 -0
  157. package/modules/syntax.d.ts +50 -0
  158. package/modules/syntax.js +332 -0
  159. package/modules/syntax.js.map +1 -0
  160. package/modules/table.d.ts +20 -0
  161. package/modules/table.js +125 -0
  162. package/modules/table.js.map +1 -0
  163. package/modules/tableEmbed.d.ts +27 -0
  164. package/modules/tableEmbed.js +209 -0
  165. package/modules/tableEmbed.js.map +1 -0
  166. package/modules/toolbar.d.ts +24 -0
  167. package/modules/toolbar.js +265 -0
  168. package/modules/toolbar.js.map +1 -0
  169. package/modules/uiNode.d.ts +19 -0
  170. package/modules/uiNode.js +95 -0
  171. package/modules/uiNode.js.map +1 -0
  172. package/modules/uploader.d.ts +15 -0
  173. package/modules/uploader.js +69 -0
  174. package/modules/uploader.js.map +1 -0
  175. package/package.json +3 -2
  176. package/quill.d.ts +5 -0
  177. package/quill.js +82 -0
  178. package/quill.js.map +1 -0
  179. package/themes/base.d.ts +35 -0
  180. package/themes/base.js +257 -0
  181. package/themes/base.js.map +1 -0
  182. package/themes/bubble.d.ts +18 -0
  183. package/themes/bubble.js +114 -0
  184. package/themes/bubble.js.map +1 -0
  185. package/themes/snow.d.ts +9 -0
  186. package/themes/snow.js +122 -0
  187. package/themes/snow.js.map +1 -0
  188. package/types.d.js +2 -0
  189. package/types.d.js.map +1 -0
  190. package/ui/color-picker.d.ts +7 -0
  191. package/ui/color-picker.js +30 -0
  192. package/ui/color-picker.js.map +1 -0
  193. package/ui/icon-picker.d.ts +7 -0
  194. package/ui/icon-picker.js +22 -0
  195. package/ui/icon-picker.js.map +1 -0
  196. package/ui/icons.d.ts +49 -0
  197. package/ui/icons.js +82 -0
  198. package/ui/icons.js.map +1 -0
  199. package/ui/picker.d.ts +16 -0
  200. package/ui/picker.js +171 -0
  201. package/ui/picker.js.map +1 -0
  202. package/ui/tooltip.d.ts +12 -0
  203. package/ui/tooltip.js +56 -0
  204. package/ui/tooltip.js.map +1 -0
  205. package/babel.config.cjs +0 -12
  206. package/scripts/babel-svg-inline-import.cjs +0 -44
  207. package/scripts/build +0 -20
  208. package/src/types.d.ts +0 -6
  209. package/webpack.common.cjs +0 -69
  210. package/webpack.config.cjs +0 -42
  211. /package/{src/assets → assets}/base.styl +0 -0
  212. /package/{src/assets → assets}/bubble/toolbar.styl +0 -0
  213. /package/{src/assets → assets}/bubble/tooltip.styl +0 -0
  214. /package/{src/assets → assets}/bubble.styl +0 -0
  215. /package/{src/assets → assets}/core.styl +0 -0
  216. /package/{src/assets → assets}/favicon.png +0 -0
  217. /package/{src/assets → assets}/icons/align-center.svg +0 -0
  218. /package/{src/assets → assets}/icons/align-justify.svg +0 -0
  219. /package/{src/assets → assets}/icons/align-left.svg +0 -0
  220. /package/{src/assets → assets}/icons/align-right.svg +0 -0
  221. /package/{src/assets → assets}/icons/attachment.svg +0 -0
  222. /package/{src/assets → assets}/icons/audio.svg +0 -0
  223. /package/{src/assets → assets}/icons/authorship.svg +0 -0
  224. /package/{src/assets → assets}/icons/background.svg +0 -0
  225. /package/{src/assets → assets}/icons/blockquote.svg +0 -0
  226. /package/{src/assets → assets}/icons/bold.svg +0 -0
  227. /package/{src/assets → assets}/icons/clean.svg +0 -0
  228. /package/{src/assets → assets}/icons/code.svg +0 -0
  229. /package/{src/assets → assets}/icons/color.svg +0 -0
  230. /package/{src/assets → assets}/icons/comment.svg +0 -0
  231. /package/{src/assets → assets}/icons/direction-ltr.svg +0 -0
  232. /package/{src/assets → assets}/icons/direction-rtl.svg +0 -0
  233. /package/{src/assets → assets}/icons/dropdown.svg +0 -0
  234. /package/{src/assets → assets}/icons/embed.svg +0 -0
  235. /package/{src/assets → assets}/icons/emoji.svg +0 -0
  236. /package/{src/assets → assets}/icons/float-center.svg +0 -0
  237. /package/{src/assets → assets}/icons/float-full.svg +0 -0
  238. /package/{src/assets → assets}/icons/float-left.svg +0 -0
  239. /package/{src/assets → assets}/icons/float-right.svg +0 -0
  240. /package/{src/assets → assets}/icons/font.svg +0 -0
  241. /package/{src/assets → assets}/icons/formula.svg +0 -0
  242. /package/{src/assets → assets}/icons/hashtag.svg +0 -0
  243. /package/{src/assets → assets}/icons/header-2.svg +0 -0
  244. /package/{src/assets → assets}/icons/header-3.svg +0 -0
  245. /package/{src/assets → assets}/icons/header-4.svg +0 -0
  246. /package/{src/assets → assets}/icons/header-5.svg +0 -0
  247. /package/{src/assets → assets}/icons/header-6.svg +0 -0
  248. /package/{src/assets → assets}/icons/header.svg +0 -0
  249. /package/{src/assets → assets}/icons/horizontal-rule.svg +0 -0
  250. /package/{src/assets → assets}/icons/image.svg +0 -0
  251. /package/{src/assets → assets}/icons/indent.svg +0 -0
  252. /package/{src/assets → assets}/icons/italic.svg +0 -0
  253. /package/{src/assets → assets}/icons/link.svg +0 -0
  254. /package/{src/assets → assets}/icons/list-bullet.svg +0 -0
  255. /package/{src/assets → assets}/icons/list-check.svg +0 -0
  256. /package/{src/assets → assets}/icons/list-ordered.svg +0 -0
  257. /package/{src/assets → assets}/icons/map.svg +0 -0
  258. /package/{src/assets → assets}/icons/mention.svg +0 -0
  259. /package/{src/assets → assets}/icons/more.svg +0 -0
  260. /package/{src/assets → assets}/icons/outdent.svg +0 -0
  261. /package/{src/assets → assets}/icons/redo.svg +0 -0
  262. /package/{src/assets → assets}/icons/size-decrease.svg +0 -0
  263. /package/{src/assets → assets}/icons/size-increase.svg +0 -0
  264. /package/{src/assets → assets}/icons/size.svg +0 -0
  265. /package/{src/assets → assets}/icons/spacing.svg +0 -0
  266. /package/{src/assets → assets}/icons/speech.svg +0 -0
  267. /package/{src/assets → assets}/icons/strike.svg +0 -0
  268. /package/{src/assets → assets}/icons/subscript.svg +0 -0
  269. /package/{src/assets → assets}/icons/superscript.svg +0 -0
  270. /package/{src/assets → assets}/icons/table-border-all.svg +0 -0
  271. /package/{src/assets → assets}/icons/table-border-bottom.svg +0 -0
  272. /package/{src/assets → assets}/icons/table-border-left.svg +0 -0
  273. /package/{src/assets → assets}/icons/table-border-none.svg +0 -0
  274. /package/{src/assets → assets}/icons/table-border-outside.svg +0 -0
  275. /package/{src/assets → assets}/icons/table-border-right.svg +0 -0
  276. /package/{src/assets → assets}/icons/table-border-top.svg +0 -0
  277. /package/{src/assets → assets}/icons/table-delete-cells.svg +0 -0
  278. /package/{src/assets → assets}/icons/table-delete-columns.svg +0 -0
  279. /package/{src/assets → assets}/icons/table-delete-rows.svg +0 -0
  280. /package/{src/assets → assets}/icons/table-insert-cells.svg +0 -0
  281. /package/{src/assets → assets}/icons/table-insert-columns.svg +0 -0
  282. /package/{src/assets → assets}/icons/table-insert-rows.svg +0 -0
  283. /package/{src/assets → assets}/icons/table-merge-cells.svg +0 -0
  284. /package/{src/assets → assets}/icons/table-unmerge-cells.svg +0 -0
  285. /package/{src/assets → assets}/icons/table.svg +0 -0
  286. /package/{src/assets → assets}/icons/underline.svg +0 -0
  287. /package/{src/assets → assets}/icons/undo.svg +0 -0
  288. /package/{src/assets → assets}/icons/video.svg +0 -0
  289. /package/{src/assets → assets}/snow/toolbar.styl +0 -0
  290. /package/{src/assets → assets}/snow/tooltip.styl +0 -0
  291. /package/{src/assets → assets}/snow.styl +0 -0
package/core/quill.js ADDED
@@ -0,0 +1,630 @@
1
+ import { merge } from 'lodash-es';
2
+ import * as Parchment from 'parchment';
3
+ import Delta from 'quill-delta';
4
+ import Editor from './editor.js';
5
+ import Emitter from './emitter.js';
6
+ import instances from './instances.js';
7
+ import logger from './logger.js';
8
+ import Module from './module.js';
9
+ import Selection, { Range } from './selection.js';
10
+ import Composition from './composition.js';
11
+ import Theme from './theme.js';
12
+ import scrollRectIntoView from './utils/scrollRectIntoView.js';
13
+ import createRegistryWithFormats from './utils/createRegistryWithFormats.js';
14
+ const debug = logger('quill');
15
+ const globalRegistry = new Parchment.Registry();
16
+ Parchment.ParentBlot.uiClass = 'ql-ui';
17
+
18
+ /**
19
+ * Options for initializing a Quill instance
20
+ */
21
+
22
+ /**
23
+ * Similar to QuillOptions, but with all properties expanded to their default values,
24
+ * and all selectors resolved to HTMLElements.
25
+ */
26
+
27
+ class Quill {
28
+ static DEFAULTS = {
29
+ bounds: null,
30
+ modules: {
31
+ clipboard: true,
32
+ keyboard: true,
33
+ history: true,
34
+ uploader: true
35
+ },
36
+ placeholder: '',
37
+ readOnly: false,
38
+ registry: globalRegistry,
39
+ theme: 'default'
40
+ };
41
+ static events = Emitter.events;
42
+ static sources = Emitter.sources;
43
+ static version = typeof "1.0.2" === 'undefined' ? 'dev' : "1.0.2";
44
+ static imports = {
45
+ delta: Delta,
46
+ parchment: Parchment,
47
+ 'core/module': Module,
48
+ 'core/theme': Theme
49
+ };
50
+ static debug(limit) {
51
+ if (limit === true) {
52
+ limit = 'log';
53
+ }
54
+ logger.level(limit);
55
+ }
56
+ static find(node) {
57
+ let bubble = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
58
+ return instances.get(node) || globalRegistry.find(node, bubble);
59
+ }
60
+ static import(name) {
61
+ if (this.imports[name] == null) {
62
+ debug.error(`Cannot import ${name}. Are you sure it was registered?`);
63
+ }
64
+ return this.imports[name];
65
+ }
66
+ static register() {
67
+ if (typeof (arguments.length <= 0 ? undefined : arguments[0]) !== 'string') {
68
+ const target = arguments.length <= 0 ? undefined : arguments[0];
69
+ const overwrite = !!(arguments.length <= 1 ? undefined : arguments[1]);
70
+ const name = 'attrName' in target ? target.attrName : target.blotName;
71
+ if (typeof name === 'string') {
72
+ // Shortcut for formats:
73
+ // register(Blot | Attributor, overwrite)
74
+ this.register(`formats/${name}`, target, overwrite);
75
+ } else {
76
+ Object.keys(target).forEach(key => {
77
+ this.register(key, target[key], overwrite);
78
+ });
79
+ }
80
+ } else {
81
+ const path = arguments.length <= 0 ? undefined : arguments[0];
82
+ const target = arguments.length <= 1 ? undefined : arguments[1];
83
+ const overwrite = !!(arguments.length <= 2 ? undefined : arguments[2]);
84
+ if (this.imports[path] != null && !overwrite) {
85
+ debug.warn(`Overwriting ${path} with`, target);
86
+ }
87
+ this.imports[path] = target;
88
+ if ((path.startsWith('blots/') || path.startsWith('formats/')) && target && typeof target !== 'boolean' && target.blotName !== 'abstract') {
89
+ globalRegistry.register(target);
90
+ }
91
+ if (typeof target.register === 'function') {
92
+ target.register(globalRegistry);
93
+ }
94
+ }
95
+ }
96
+ constructor(container) {
97
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
98
+ this.options = expandConfig(container, options);
99
+ this.container = this.options.container;
100
+ if (this.container == null) {
101
+ debug.error('Invalid Quill container', container);
102
+ return;
103
+ }
104
+ if (this.options.debug) {
105
+ Quill.debug(this.options.debug);
106
+ }
107
+ const html = this.container.innerHTML.trim();
108
+ this.container.classList.add('ql-container');
109
+ this.container.innerHTML = '';
110
+ instances.set(this.container, this);
111
+ this.root = this.addContainer('ql-editor');
112
+ this.root.classList.add('ql-blank');
113
+ this.emitter = new Emitter();
114
+ const scrollBlotName = Parchment.ScrollBlot.blotName;
115
+ const ScrollBlot = this.options.registry.query(scrollBlotName);
116
+ if (!ScrollBlot || !('blotName' in ScrollBlot)) {
117
+ throw new Error(`Cannot initialize Quill without "${scrollBlotName}" blot`);
118
+ }
119
+ this.scroll = new ScrollBlot(this.options.registry, this.root, {
120
+ emitter: this.emitter
121
+ });
122
+ this.editor = new Editor(this.scroll);
123
+ this.selection = new Selection(this.scroll, this.emitter);
124
+ this.composition = new Composition(this.scroll, this.emitter);
125
+ this.theme = new this.options.theme(this, this.options); // eslint-disable-line new-cap
126
+ this.keyboard = this.theme.addModule('keyboard');
127
+ this.clipboard = this.theme.addModule('clipboard');
128
+ this.history = this.theme.addModule('history');
129
+ this.uploader = this.theme.addModule('uploader');
130
+ this.theme.addModule('input');
131
+ this.theme.addModule('uiNode');
132
+ this.theme.init();
133
+ this.emitter.on(Emitter.events.EDITOR_CHANGE, type => {
134
+ if (type === Emitter.events.TEXT_CHANGE) {
135
+ this.root.classList.toggle('ql-blank', this.editor.isBlank());
136
+ }
137
+ });
138
+ this.emitter.on(Emitter.events.SCROLL_UPDATE, (source, mutations) => {
139
+ const oldRange = this.selection.lastRange;
140
+ const [newRange] = this.selection.getRange();
141
+ const selectionInfo = oldRange && newRange ? {
142
+ oldRange,
143
+ newRange
144
+ } : undefined;
145
+ modify.call(this, () => this.editor.update(null, mutations, selectionInfo), source);
146
+ });
147
+ this.emitter.on(Emitter.events.SCROLL_EMBED_UPDATE, (blot, delta) => {
148
+ const oldRange = this.selection.lastRange;
149
+ const [newRange] = this.selection.getRange();
150
+ const selectionInfo = oldRange && newRange ? {
151
+ oldRange,
152
+ newRange
153
+ } : undefined;
154
+ modify.call(this, () => {
155
+ const change = new Delta().retain(blot.offset(this)).retain({
156
+ [blot.statics.blotName]: delta
157
+ });
158
+ return this.editor.update(change, [], selectionInfo);
159
+ }, Quill.sources.USER);
160
+ });
161
+ if (html) {
162
+ const contents = this.clipboard.convert({
163
+ html: `${html}<p><br></p>`,
164
+ text: '\n'
165
+ });
166
+ this.setContents(contents);
167
+ }
168
+ this.history.clear();
169
+ if (this.options.placeholder) {
170
+ this.root.setAttribute('data-placeholder', this.options.placeholder);
171
+ }
172
+ if (this.options.readOnly) {
173
+ this.disable();
174
+ }
175
+ this.allowReadOnlyEdits = false;
176
+ }
177
+ addContainer(container) {
178
+ let refNode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
179
+ if (typeof container === 'string') {
180
+ const className = container;
181
+ container = document.createElement('div');
182
+ container.classList.add(className);
183
+ }
184
+ this.container.insertBefore(container, refNode);
185
+ return container;
186
+ }
187
+ blur() {
188
+ this.selection.setRange(null);
189
+ }
190
+ deleteText(index, length, source) {
191
+ // @ts-expect-error
192
+ [index, length,, source] = overload(index, length, source);
193
+ return modify.call(this, () => {
194
+ return this.editor.deleteText(index, length);
195
+ }, source, index, -1 * length);
196
+ }
197
+ disable() {
198
+ this.enable(false);
199
+ }
200
+ editReadOnly(modifier) {
201
+ this.allowReadOnlyEdits = true;
202
+ const value = modifier();
203
+ this.allowReadOnlyEdits = false;
204
+ return value;
205
+ }
206
+ enable() {
207
+ let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
208
+ this.scroll.enable(enabled);
209
+ this.container.classList.toggle('ql-disabled', !enabled);
210
+ }
211
+ focus() {
212
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
213
+ this.selection.focus();
214
+ if (!options.preventScroll) {
215
+ this.scrollSelectionIntoView();
216
+ }
217
+ }
218
+ format(name, value) {
219
+ let source = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Emitter.sources.API;
220
+ return modify.call(this, () => {
221
+ const range = this.getSelection(true);
222
+ let change = new Delta();
223
+ if (range == null) return change;
224
+ if (this.scroll.query(name, Parchment.Scope.BLOCK)) {
225
+ change = this.editor.formatLine(range.index, range.length, {
226
+ [name]: value
227
+ });
228
+ } else if (range.length === 0) {
229
+ this.selection.format(name, value);
230
+ return change;
231
+ } else {
232
+ change = this.editor.formatText(range.index, range.length, {
233
+ [name]: value
234
+ });
235
+ }
236
+ this.setSelection(range, Emitter.sources.SILENT);
237
+ return change;
238
+ }, source);
239
+ }
240
+ formatLine(index, length, name, value, source) {
241
+ let formats;
242
+ // eslint-disable-next-line prefer-const
243
+ [index, length, formats, source] = overload(index, length,
244
+ // @ts-expect-error
245
+ name, value, source);
246
+ return modify.call(this, () => {
247
+ return this.editor.formatLine(index, length, formats);
248
+ }, source, index, 0);
249
+ }
250
+ formatText(index, length, name, value, source) {
251
+ let formats;
252
+ // eslint-disable-next-line prefer-const
253
+ [index, length, formats, source] = overload(
254
+ // @ts-expect-error
255
+ index, length, name, value, source);
256
+ return modify.call(this, () => {
257
+ return this.editor.formatText(index, length, formats);
258
+ }, source, index, 0);
259
+ }
260
+ getBounds(index) {
261
+ let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
262
+ let bounds = null;
263
+ if (typeof index === 'number') {
264
+ bounds = this.selection.getBounds(index, length);
265
+ } else {
266
+ bounds = this.selection.getBounds(index.index, index.length);
267
+ }
268
+ if (!bounds) return null;
269
+ const containerBounds = this.container.getBoundingClientRect();
270
+ return {
271
+ bottom: bounds.bottom - containerBounds.top,
272
+ height: bounds.height,
273
+ left: bounds.left - containerBounds.left,
274
+ right: bounds.right - containerBounds.left,
275
+ top: bounds.top - containerBounds.top,
276
+ width: bounds.width
277
+ };
278
+ }
279
+ getContents() {
280
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
281
+ let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getLength() - index;
282
+ [index, length] = overload(index, length);
283
+ return this.editor.getContents(index, length);
284
+ }
285
+ getFormat() {
286
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getSelection(true);
287
+ let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
288
+ if (typeof index === 'number') {
289
+ return this.editor.getFormat(index, length);
290
+ }
291
+ return this.editor.getFormat(index.index, index.length);
292
+ }
293
+ getIndex(blot) {
294
+ return blot.offset(this.scroll);
295
+ }
296
+ getLength() {
297
+ return this.scroll.length();
298
+ }
299
+ getLeaf(index) {
300
+ return this.scroll.leaf(index);
301
+ }
302
+ getLine(index) {
303
+ return this.scroll.line(index);
304
+ }
305
+ getLines() {
306
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
307
+ let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Number.MAX_VALUE;
308
+ if (typeof index !== 'number') {
309
+ return this.scroll.lines(index.index, index.length);
310
+ }
311
+ return this.scroll.lines(index, length);
312
+ }
313
+ getModule(name) {
314
+ return this.theme.modules[name];
315
+ }
316
+ getSelection() {
317
+ let focus = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
318
+ if (focus) this.focus();
319
+ this.update(); // Make sure we access getRange with editor in consistent state
320
+ return this.selection.getRange()[0];
321
+ }
322
+ getSemanticHTML() {
323
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
324
+ let length = arguments.length > 1 ? arguments[1] : undefined;
325
+ if (typeof index === 'number') {
326
+ length = length ?? this.getLength() - index;
327
+ }
328
+ // @ts-expect-error
329
+ [index, length] = overload(index, length);
330
+ return this.editor.getHTML(index, length);
331
+ }
332
+ getText() {
333
+ let index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
334
+ let length = arguments.length > 1 ? arguments[1] : undefined;
335
+ if (typeof index === 'number') {
336
+ length = length ?? this.getLength() - index;
337
+ }
338
+ // @ts-expect-error
339
+ [index, length] = overload(index, length);
340
+ return this.editor.getText(index, length);
341
+ }
342
+ hasFocus() {
343
+ return this.selection.hasFocus();
344
+ }
345
+ insertEmbed(index, embed, value) {
346
+ let source = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Quill.sources.API;
347
+ return modify.call(this, () => {
348
+ return this.editor.insertEmbed(index, embed, value);
349
+ }, source, index);
350
+ }
351
+ insertText(index, text, name, value, source) {
352
+ let formats;
353
+ // eslint-disable-next-line prefer-const
354
+ // @ts-expect-error
355
+ [index,, formats, source] = overload(index, 0, name, value, source);
356
+ return modify.call(this, () => {
357
+ return this.editor.insertText(index, text, formats);
358
+ }, source, index, text.length);
359
+ }
360
+ isEnabled() {
361
+ return this.scroll.isEnabled();
362
+ }
363
+ off() {
364
+ return this.emitter.off(...arguments);
365
+ }
366
+ on() {
367
+ return this.emitter.on(...arguments);
368
+ }
369
+ once() {
370
+ return this.emitter.once(...arguments);
371
+ }
372
+ removeFormat(index, length, source) {
373
+ [index, length,, source] = overload(index, length, source);
374
+ return modify.call(this, () => {
375
+ return this.editor.removeFormat(index, length);
376
+ }, source, index);
377
+ }
378
+ scrollRectIntoView(rect) {
379
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
380
+ scrollRectIntoView(this.root, rect, options);
381
+ }
382
+
383
+ /**
384
+ * @deprecated Use Quill#scrollSelectionIntoView() instead.
385
+ */
386
+ scrollIntoView() {
387
+ console.warn('Quill#scrollIntoView() has been deprecated and will be removed in the near future. Please use Quill#scrollSelectionIntoView() instead.');
388
+ this.scrollSelectionIntoView();
389
+ }
390
+
391
+ /**
392
+ * Scroll the current selection into the visible area.
393
+ * If the selection is already visible, no scrolling will occur.
394
+ */
395
+ scrollSelectionIntoView() {
396
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
397
+ const range = this.selection.lastRange;
398
+ const bounds = range && this.selection.getBounds(range.index, range.length);
399
+ if (bounds) {
400
+ this.scrollRectIntoView(bounds, options);
401
+ }
402
+ }
403
+ setContents(delta) {
404
+ let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Emitter.sources.API;
405
+ return modify.call(this, () => {
406
+ delta = new Delta(delta);
407
+ const length = this.getLength();
408
+ // Quill will set empty editor to \n
409
+ const delete1 = this.editor.deleteText(0, length);
410
+ const applied = this.editor.insertContents(0, delta);
411
+ // Remove extra \n from empty editor initialization
412
+ const delete2 = this.editor.deleteText(this.getLength() - 1, 1);
413
+ return delete1.compose(applied).compose(delete2);
414
+ }, source);
415
+ }
416
+ setSelection(index, length, source) {
417
+ if (index == null) {
418
+ // @ts-expect-error https://github.com/microsoft/TypeScript/issues/22609
419
+ this.selection.setRange(null, length || Quill.sources.API);
420
+ } else {
421
+ // @ts-expect-error
422
+ [index, length,, source] = overload(index, length, source);
423
+ this.selection.setRange(new Range(Math.max(0, index), length), source);
424
+ if (source !== Emitter.sources.SILENT) {
425
+ this.scrollSelectionIntoView();
426
+ }
427
+ }
428
+ }
429
+ setText(text) {
430
+ let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Emitter.sources.API;
431
+ const delta = new Delta().insert(text);
432
+ return this.setContents(delta, source);
433
+ }
434
+ update() {
435
+ let source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Emitter.sources.USER;
436
+ const change = this.scroll.update(source); // Will update selection before selection.update() does if text changes
437
+ this.selection.update(source);
438
+ // TODO this is usually undefined
439
+ return change;
440
+ }
441
+ updateContents(delta) {
442
+ let source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Emitter.sources.API;
443
+ return modify.call(this, () => {
444
+ delta = new Delta(delta);
445
+ return this.editor.applyDelta(delta);
446
+ }, source, true);
447
+ }
448
+ }
449
+ function resolveSelector(selector) {
450
+ return typeof selector === 'string' ? document.querySelector(selector) : selector;
451
+ }
452
+ function expandModuleConfig(config) {
453
+ return Object.entries(config ?? {}).reduce((expanded, _ref) => {
454
+ let [key, value] = _ref;
455
+ return {
456
+ ...expanded,
457
+ [key]: value === true ? {} : value
458
+ };
459
+ }, {});
460
+ }
461
+ function omitUndefinedValuesFromOptions(obj) {
462
+ return Object.fromEntries(Object.entries(obj).filter(entry => entry[1] !== undefined));
463
+ }
464
+ function expandConfig(containerOrSelector, options) {
465
+ const container = resolveSelector(containerOrSelector);
466
+ if (!container) {
467
+ throw new Error('Invalid Quill container');
468
+ }
469
+ const shouldUseDefaultTheme = !options.theme || options.theme === Quill.DEFAULTS.theme;
470
+ const theme = shouldUseDefaultTheme ? Theme : Quill.import(`themes/${options.theme}`);
471
+ if (!theme) {
472
+ throw new Error(`Invalid theme ${options.theme}. Did you register it?`);
473
+ }
474
+ const {
475
+ modules: quillModuleDefaults,
476
+ ...quillDefaults
477
+ } = Quill.DEFAULTS;
478
+ const {
479
+ modules: themeModuleDefaults,
480
+ ...themeDefaults
481
+ } = theme.DEFAULTS;
482
+ let userModuleOptions = expandModuleConfig(options.modules);
483
+ // Special case toolbar shorthand
484
+ if (userModuleOptions != null && userModuleOptions.toolbar && userModuleOptions.toolbar.constructor !== Object) {
485
+ userModuleOptions = {
486
+ ...userModuleOptions,
487
+ toolbar: {
488
+ container: userModuleOptions.toolbar
489
+ }
490
+ };
491
+ }
492
+ const modules = merge({}, expandModuleConfig(quillModuleDefaults), expandModuleConfig(themeModuleDefaults), userModuleOptions);
493
+ const config = {
494
+ ...quillDefaults,
495
+ ...omitUndefinedValuesFromOptions(themeDefaults),
496
+ ...omitUndefinedValuesFromOptions(options)
497
+ };
498
+ let registry = options.registry;
499
+ if (registry) {
500
+ if (options.formats) {
501
+ debug.warn('Ignoring "formats" option because "registry" is specified');
502
+ }
503
+ } else {
504
+ registry = options.formats ? createRegistryWithFormats(options.formats, config.registry, debug) : config.registry;
505
+ }
506
+ return {
507
+ ...config,
508
+ registry,
509
+ container,
510
+ theme,
511
+ modules: Object.entries(modules).reduce((modulesWithDefaults, _ref2) => {
512
+ let [name, value] = _ref2;
513
+ if (!value) return modulesWithDefaults;
514
+ const moduleClass = Quill.import(`modules/${name}`);
515
+ if (moduleClass == null) {
516
+ debug.error(`Cannot load ${name} module. Are you sure you registered it?`);
517
+ return modulesWithDefaults;
518
+ }
519
+ return {
520
+ ...modulesWithDefaults,
521
+ // @ts-expect-error
522
+ [name]: merge({}, moduleClass.DEFAULTS || {}, value)
523
+ };
524
+ }, {}),
525
+ bounds: resolveSelector(config.bounds)
526
+ };
527
+ }
528
+
529
+ // Handle selection preservation and TEXT_CHANGE emission
530
+ // common to modification APIs
531
+ function modify(modifier, source, index, shift) {
532
+ if (!this.isEnabled() && source === Emitter.sources.USER && !this.allowReadOnlyEdits) {
533
+ return new Delta();
534
+ }
535
+ let range = index == null ? null : this.getSelection();
536
+ const oldDelta = this.editor.delta;
537
+ const change = modifier();
538
+ if (range != null) {
539
+ if (index === true) {
540
+ index = range.index; // eslint-disable-line prefer-destructuring
541
+ }
542
+ if (shift == null) {
543
+ range = shiftRange(range, change, source);
544
+ } else if (shift !== 0) {
545
+ // @ts-expect-error index should always be number
546
+ range = shiftRange(range, index, shift, source);
547
+ }
548
+ this.setSelection(range, Emitter.sources.SILENT);
549
+ }
550
+ if (change.length() > 0) {
551
+ const args = [Emitter.events.TEXT_CHANGE, change, oldDelta, source];
552
+ this.emitter.emit(Emitter.events.EDITOR_CHANGE, ...args);
553
+ if (source !== Emitter.sources.SILENT) {
554
+ this.emitter.emit(...args);
555
+ }
556
+ }
557
+ return change;
558
+ }
559
+ function overload(index, length, name, value, source) {
560
+ let formats = {};
561
+ // @ts-expect-error
562
+ if (typeof index.index === 'number' && typeof index.length === 'number') {
563
+ // Allow for throwaway end (used by insertText/insertEmbed)
564
+ if (typeof length !== 'number') {
565
+ // @ts-expect-error
566
+ source = value;
567
+ value = name;
568
+ name = length;
569
+ // @ts-expect-error
570
+ length = index.length; // eslint-disable-line prefer-destructuring
571
+ // @ts-expect-error
572
+ index = index.index; // eslint-disable-line prefer-destructuring
573
+ } else {
574
+ // @ts-expect-error
575
+ length = index.length; // eslint-disable-line prefer-destructuring
576
+ // @ts-expect-error
577
+ index = index.index; // eslint-disable-line prefer-destructuring
578
+ }
579
+ } else if (typeof length !== 'number') {
580
+ // @ts-expect-error
581
+ source = value;
582
+ value = name;
583
+ name = length;
584
+ length = 0;
585
+ }
586
+ // Handle format being object, two format name/value strings or excluded
587
+ if (typeof name === 'object') {
588
+ // @ts-expect-error Fix me later
589
+ formats = name;
590
+ // @ts-expect-error
591
+ source = value;
592
+ } else if (typeof name === 'string') {
593
+ if (value != null) {
594
+ formats[name] = value;
595
+ } else {
596
+ // @ts-expect-error
597
+ source = name;
598
+ }
599
+ }
600
+ // Handle optional source
601
+ source = source || Emitter.sources.API;
602
+ // @ts-expect-error
603
+ return [index, length, formats, source];
604
+ }
605
+ function shiftRange(range, index, lengthOrSource, source) {
606
+ const length = typeof lengthOrSource === 'number' ? lengthOrSource : 0;
607
+ if (range == null) return null;
608
+ let start;
609
+ let end;
610
+ // @ts-expect-error -- TODO: add a better type guard around `index`
611
+ if (index && typeof index.transformPosition === 'function') {
612
+ [start, end] = [range.index, range.index + range.length].map(pos =>
613
+ // @ts-expect-error -- TODO: add a better type guard around `index`
614
+ index.transformPosition(pos, source !== Emitter.sources.USER));
615
+ } else {
616
+ [start, end] = [range.index, range.index + range.length].map(pos => {
617
+ // @ts-expect-error -- TODO: add a better type guard around `index`
618
+ if (pos < index || pos === index && source === Emitter.sources.USER) return pos;
619
+ if (length >= 0) {
620
+ return pos + length;
621
+ }
622
+ // @ts-expect-error -- TODO: add a better type guard around `index`
623
+ return Math.max(index, pos + length);
624
+ });
625
+ }
626
+ return new Range(start, end - start);
627
+ }
628
+ export { Parchment, Range };
629
+ export { globalRegistry, expandConfig, overload, Quill as default };
630
+ //# sourceMappingURL=quill.js.map