@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
@@ -0,0 +1,713 @@
1
+ import { cloneDeep, isEqual } from 'lodash-es';
2
+ import Delta, { AttributeMap } from 'quill-delta';
3
+ import { EmbedBlot, Scope, TextBlot } from 'parchment';
4
+ import Quill from '../core/quill.js';
5
+ import logger from '../core/logger.js';
6
+ import Module from '../core/module.js';
7
+ const debug = logger('quill:keyboard');
8
+ const SHORTKEY = /Mac/i.test(navigator.platform) ? 'metaKey' : 'ctrlKey';
9
+ class Keyboard extends Module {
10
+ static match(evt, binding) {
11
+ if (['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].some(key => {
12
+ return !!binding[key] !== evt[key] && binding[key] !== null;
13
+ })) {
14
+ return false;
15
+ }
16
+ return binding.key === evt.key || binding.key === evt.which;
17
+ }
18
+ constructor(quill, options) {
19
+ super(quill, options);
20
+ this.bindings = {};
21
+ // @ts-expect-error Fix me later
22
+ Object.keys(this.options.bindings).forEach(name => {
23
+ // @ts-expect-error Fix me later
24
+ if (this.options.bindings[name]) {
25
+ // @ts-expect-error Fix me later
26
+ this.addBinding(this.options.bindings[name]);
27
+ }
28
+ });
29
+ this.addBinding({
30
+ key: 'Enter',
31
+ shiftKey: null
32
+ }, this.handleEnter);
33
+ this.addBinding({
34
+ key: 'Enter',
35
+ metaKey: null,
36
+ ctrlKey: null,
37
+ altKey: null
38
+ }, () => {});
39
+ if (/Firefox/i.test(navigator.userAgent)) {
40
+ // Need to handle delete and backspace for Firefox in the general case #1171
41
+ this.addBinding({
42
+ key: 'Backspace'
43
+ }, {
44
+ collapsed: true
45
+ }, this.handleBackspace);
46
+ this.addBinding({
47
+ key: 'Delete'
48
+ }, {
49
+ collapsed: true
50
+ }, this.handleDelete);
51
+ } else {
52
+ this.addBinding({
53
+ key: 'Backspace'
54
+ }, {
55
+ collapsed: true,
56
+ prefix: /^.?$/
57
+ }, this.handleBackspace);
58
+ this.addBinding({
59
+ key: 'Delete'
60
+ }, {
61
+ collapsed: true,
62
+ suffix: /^.?$/
63
+ }, this.handleDelete);
64
+ }
65
+ this.addBinding({
66
+ key: 'Backspace'
67
+ }, {
68
+ collapsed: false
69
+ }, this.handleDeleteRange);
70
+ this.addBinding({
71
+ key: 'Delete'
72
+ }, {
73
+ collapsed: false
74
+ }, this.handleDeleteRange);
75
+ this.addBinding({
76
+ key: 'Backspace',
77
+ altKey: null,
78
+ ctrlKey: null,
79
+ metaKey: null,
80
+ shiftKey: null
81
+ }, {
82
+ collapsed: true,
83
+ offset: 0
84
+ }, this.handleBackspace);
85
+ this.listen();
86
+ }
87
+ addBinding(keyBinding) {
88
+ let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
89
+ let handler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
90
+ const binding = normalize(keyBinding);
91
+ if (binding == null) {
92
+ debug.warn('Attempted to add invalid keyboard binding', binding);
93
+ return;
94
+ }
95
+ if (typeof context === 'function') {
96
+ context = {
97
+ handler: context
98
+ };
99
+ }
100
+ if (typeof handler === 'function') {
101
+ handler = {
102
+ handler
103
+ };
104
+ }
105
+ const keys = Array.isArray(binding.key) ? binding.key : [binding.key];
106
+ keys.forEach(key => {
107
+ const singleBinding = {
108
+ ...binding,
109
+ key,
110
+ ...context,
111
+ ...handler
112
+ };
113
+ this.bindings[singleBinding.key] = this.bindings[singleBinding.key] || [];
114
+ this.bindings[singleBinding.key].push(singleBinding);
115
+ });
116
+ }
117
+ listen() {
118
+ this.quill.root.addEventListener('keydown', evt => {
119
+ if (evt.defaultPrevented || evt.isComposing) return;
120
+
121
+ // evt.isComposing is false when pressing Enter/Backspace when composing in Safari
122
+ // https://bugs.webkit.org/show_bug.cgi?id=165004
123
+ const isComposing = evt.keyCode === 229 && (evt.key === 'Enter' || evt.key === 'Backspace');
124
+ if (isComposing) return;
125
+ const bindings = (this.bindings[evt.key] || []).concat(this.bindings[evt.which] || []);
126
+ const matches = bindings.filter(binding => Keyboard.match(evt, binding));
127
+ if (matches.length === 0) return;
128
+ // @ts-expect-error
129
+ const blot = Quill.find(evt.target, true);
130
+ if (blot && blot.scroll !== this.quill.scroll) return;
131
+ const range = this.quill.getSelection();
132
+ if (range == null || !this.quill.hasFocus()) return;
133
+ const [line, offset] = this.quill.getLine(range.index);
134
+ const [leafStart, offsetStart] = this.quill.getLeaf(range.index);
135
+ const [leafEnd, offsetEnd] = range.length === 0 ? [leafStart, offsetStart] : this.quill.getLeaf(range.index + range.length);
136
+ const prefixText = leafStart instanceof TextBlot ? leafStart.value().slice(0, offsetStart) : '';
137
+ const suffixText = leafEnd instanceof TextBlot ? leafEnd.value().slice(offsetEnd) : '';
138
+ const curContext = {
139
+ collapsed: range.length === 0,
140
+ // @ts-expect-error Fix me later
141
+ empty: range.length === 0 && line.length() <= 1,
142
+ format: this.quill.getFormat(range),
143
+ line,
144
+ offset,
145
+ prefix: prefixText,
146
+ suffix: suffixText,
147
+ event: evt
148
+ };
149
+ const prevented = matches.some(binding => {
150
+ if (binding.collapsed != null && binding.collapsed !== curContext.collapsed) {
151
+ return false;
152
+ }
153
+ if (binding.empty != null && binding.empty !== curContext.empty) {
154
+ return false;
155
+ }
156
+ if (binding.offset != null && binding.offset !== curContext.offset) {
157
+ return false;
158
+ }
159
+ if (Array.isArray(binding.format)) {
160
+ // any format is present
161
+ if (binding.format.every(name => curContext.format[name] == null)) {
162
+ return false;
163
+ }
164
+ } else if (typeof binding.format === 'object') {
165
+ // all formats must match
166
+ if (!Object.keys(binding.format).every(name => {
167
+ // @ts-expect-error Fix me later
168
+ if (binding.format[name] === true) return curContext.format[name] != null;
169
+ // @ts-expect-error Fix me later
170
+ if (binding.format[name] === false) return curContext.format[name] == null;
171
+ // @ts-expect-error Fix me later
172
+ return isEqual(binding.format[name], curContext.format[name]);
173
+ })) {
174
+ return false;
175
+ }
176
+ }
177
+ if (binding.prefix != null && !binding.prefix.test(curContext.prefix)) {
178
+ return false;
179
+ }
180
+ if (binding.suffix != null && !binding.suffix.test(curContext.suffix)) {
181
+ return false;
182
+ }
183
+ // @ts-expect-error Fix me later
184
+ return binding.handler.call(this, range, curContext, binding) !== true;
185
+ });
186
+ if (prevented) {
187
+ evt.preventDefault();
188
+ }
189
+ });
190
+ }
191
+ handleBackspace(range, context) {
192
+ // Check for astral symbols
193
+ const length = /[\uD800-\uDBFF][\uDC00-\uDFFF]$/.test(context.prefix) ? 2 : 1;
194
+ if (range.index === 0 || this.quill.getLength() <= 1) return;
195
+ let formats = {};
196
+ const [line] = this.quill.getLine(range.index);
197
+ let delta = new Delta().retain(range.index - length).delete(length);
198
+ if (context.offset === 0) {
199
+ // Always deleting newline here, length always 1
200
+ const [prev] = this.quill.getLine(range.index - 1);
201
+ if (prev) {
202
+ const isPrevLineEmpty = prev.statics.blotName === 'block' && prev.length() <= 1;
203
+ if (!isPrevLineEmpty) {
204
+ // @ts-expect-error Fix me later
205
+ const curFormats = line.formats();
206
+ const prevFormats = this.quill.getFormat(range.index - 1, 1);
207
+ formats = AttributeMap.diff(curFormats, prevFormats) || {};
208
+ if (Object.keys(formats).length > 0) {
209
+ // line.length() - 1 targets \n in line, another -1 for newline being deleted
210
+ const formatDelta = new Delta()
211
+ // @ts-expect-error Fix me later
212
+ .retain(range.index + line.length() - 2).retain(1, formats);
213
+ delta = delta.compose(formatDelta);
214
+ }
215
+ }
216
+ }
217
+ }
218
+ this.quill.updateContents(delta, Quill.sources.USER);
219
+ this.quill.focus();
220
+ }
221
+ handleDelete(range, context) {
222
+ // Check for astral symbols
223
+ const length = /^[\uD800-\uDBFF][\uDC00-\uDFFF]/.test(context.suffix) ? 2 : 1;
224
+ if (range.index >= this.quill.getLength() - length) return;
225
+ let formats = {};
226
+ const [line] = this.quill.getLine(range.index);
227
+ let delta = new Delta().retain(range.index).delete(length);
228
+ // @ts-expect-error Fix me later
229
+ if (context.offset >= line.length() - 1) {
230
+ const [next] = this.quill.getLine(range.index + 1);
231
+ if (next) {
232
+ // @ts-expect-error Fix me later
233
+ const curFormats = line.formats();
234
+ const nextFormats = this.quill.getFormat(range.index, 1);
235
+ formats = AttributeMap.diff(curFormats, nextFormats) || {};
236
+ if (Object.keys(formats).length > 0) {
237
+ delta = delta.retain(next.length() - 1).retain(1, formats);
238
+ }
239
+ }
240
+ }
241
+ this.quill.updateContents(delta, Quill.sources.USER);
242
+ this.quill.focus();
243
+ }
244
+ handleDeleteRange(range) {
245
+ deleteRange({
246
+ range,
247
+ quill: this.quill
248
+ });
249
+ this.quill.focus();
250
+ }
251
+ handleEnter(range, context) {
252
+ const lineFormats = Object.keys(context.format).reduce((formats, format) => {
253
+ if (this.quill.scroll.query(format, Scope.BLOCK) && !Array.isArray(context.format[format])) {
254
+ formats[format] = context.format[format];
255
+ }
256
+ return formats;
257
+ }, {});
258
+ const delta = new Delta().retain(range.index).delete(range.length).insert('\n', lineFormats);
259
+ this.quill.updateContents(delta, Quill.sources.USER);
260
+ this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
261
+ this.quill.focus();
262
+ }
263
+ }
264
+ const defaultOptions = {
265
+ bindings: {
266
+ bold: makeFormatHandler('bold'),
267
+ italic: makeFormatHandler('italic'),
268
+ underline: makeFormatHandler('underline'),
269
+ indent: {
270
+ // highlight tab or tab at beginning of list, indent or blockquote
271
+ key: 'Tab',
272
+ format: ['blockquote', 'indent', 'list'],
273
+ handler(range, context) {
274
+ if (context.collapsed && context.offset !== 0) return true;
275
+ this.quill.format('indent', '+1', Quill.sources.USER);
276
+ return false;
277
+ }
278
+ },
279
+ outdent: {
280
+ key: 'Tab',
281
+ shiftKey: true,
282
+ format: ['blockquote', 'indent', 'list'],
283
+ // highlight tab or tab at beginning of list, indent or blockquote
284
+ handler(range, context) {
285
+ if (context.collapsed && context.offset !== 0) return true;
286
+ this.quill.format('indent', '-1', Quill.sources.USER);
287
+ return false;
288
+ }
289
+ },
290
+ 'outdent backspace': {
291
+ key: 'Backspace',
292
+ collapsed: true,
293
+ shiftKey: null,
294
+ metaKey: null,
295
+ ctrlKey: null,
296
+ altKey: null,
297
+ format: ['indent', 'list'],
298
+ offset: 0,
299
+ handler(range, context) {
300
+ if (context.format.indent != null) {
301
+ this.quill.format('indent', '-1', Quill.sources.USER);
302
+ } else if (context.format.list != null) {
303
+ this.quill.format('list', false, Quill.sources.USER);
304
+ }
305
+ }
306
+ },
307
+ 'indent code-block': makeCodeBlockHandler(true),
308
+ 'outdent code-block': makeCodeBlockHandler(false),
309
+ 'remove tab': {
310
+ key: 'Tab',
311
+ shiftKey: true,
312
+ collapsed: true,
313
+ prefix: /\t$/,
314
+ handler(range) {
315
+ this.quill.deleteText(range.index - 1, 1, Quill.sources.USER);
316
+ }
317
+ },
318
+ tab: {
319
+ key: 'Tab',
320
+ handler(range, context) {
321
+ if (context.format.table) return true;
322
+ this.quill.history.cutoff();
323
+ const delta = new Delta().retain(range.index).delete(range.length).insert('\t');
324
+ this.quill.updateContents(delta, Quill.sources.USER);
325
+ this.quill.history.cutoff();
326
+ this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
327
+ return false;
328
+ }
329
+ },
330
+ 'blockquote empty enter': {
331
+ key: 'Enter',
332
+ collapsed: true,
333
+ format: ['blockquote'],
334
+ empty: true,
335
+ handler() {
336
+ this.quill.format('blockquote', false, Quill.sources.USER);
337
+ }
338
+ },
339
+ 'list empty enter': {
340
+ key: 'Enter',
341
+ collapsed: true,
342
+ format: ['list'],
343
+ empty: true,
344
+ handler(range, context) {
345
+ const formats = {
346
+ list: false
347
+ };
348
+ if (context.format.indent) {
349
+ formats.indent = false;
350
+ }
351
+ this.quill.formatLine(range.index, range.length, formats, Quill.sources.USER);
352
+ }
353
+ },
354
+ 'checklist enter': {
355
+ key: 'Enter',
356
+ collapsed: true,
357
+ format: {
358
+ list: 'checked'
359
+ },
360
+ handler(range) {
361
+ const [line, offset] = this.quill.getLine(range.index);
362
+ const formats = {
363
+ // @ts-expect-error Fix me later
364
+ ...line.formats(),
365
+ list: 'checked'
366
+ };
367
+ const delta = new Delta().retain(range.index).insert('\n', formats)
368
+ // @ts-expect-error Fix me later
369
+ .retain(line.length() - offset - 1).retain(1, {
370
+ list: 'unchecked'
371
+ });
372
+ this.quill.updateContents(delta, Quill.sources.USER);
373
+ this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
374
+ this.quill.scrollSelectionIntoView();
375
+ }
376
+ },
377
+ 'header enter': {
378
+ key: 'Enter',
379
+ collapsed: true,
380
+ format: ['header'],
381
+ suffix: /^$/,
382
+ handler(range, context) {
383
+ const [line, offset] = this.quill.getLine(range.index);
384
+ const delta = new Delta().retain(range.index).insert('\n', context.format)
385
+ // @ts-expect-error Fix me later
386
+ .retain(line.length() - offset - 1).retain(1, {
387
+ header: null
388
+ });
389
+ this.quill.updateContents(delta, Quill.sources.USER);
390
+ this.quill.setSelection(range.index + 1, Quill.sources.SILENT);
391
+ this.quill.scrollSelectionIntoView();
392
+ }
393
+ },
394
+ 'table backspace': {
395
+ key: 'Backspace',
396
+ format: ['table'],
397
+ collapsed: true,
398
+ offset: 0,
399
+ handler() {}
400
+ },
401
+ 'table delete': {
402
+ key: 'Delete',
403
+ format: ['table'],
404
+ collapsed: true,
405
+ suffix: /^$/,
406
+ handler() {}
407
+ },
408
+ 'table enter': {
409
+ key: 'Enter',
410
+ shiftKey: null,
411
+ format: ['table'],
412
+ handler(range) {
413
+ const module = this.quill.getModule('table');
414
+ if (module) {
415
+ // @ts-expect-error
416
+ const [table, row, cell, offset] = module.getTable(range);
417
+ const shift = tableSide(table, row, cell, offset);
418
+ if (shift == null) return;
419
+ let index = table.offset();
420
+ if (shift < 0) {
421
+ const delta = new Delta().retain(index).insert('\n');
422
+ this.quill.updateContents(delta, Quill.sources.USER);
423
+ this.quill.setSelection(range.index + 1, range.length, Quill.sources.SILENT);
424
+ } else if (shift > 0) {
425
+ index += table.length();
426
+ const delta = new Delta().retain(index).insert('\n');
427
+ this.quill.updateContents(delta, Quill.sources.USER);
428
+ this.quill.setSelection(index, Quill.sources.USER);
429
+ }
430
+ }
431
+ }
432
+ },
433
+ 'table tab': {
434
+ key: 'Tab',
435
+ shiftKey: null,
436
+ format: ['table'],
437
+ handler(range, context) {
438
+ const {
439
+ event,
440
+ line: cell
441
+ } = context;
442
+ const offset = cell.offset(this.quill.scroll);
443
+ if (event.shiftKey) {
444
+ this.quill.setSelection(offset - 1, Quill.sources.USER);
445
+ } else {
446
+ this.quill.setSelection(offset + cell.length(), Quill.sources.USER);
447
+ }
448
+ }
449
+ },
450
+ 'list autofill': {
451
+ key: ' ',
452
+ shiftKey: null,
453
+ collapsed: true,
454
+ format: {
455
+ 'code-block': false,
456
+ blockquote: false,
457
+ table: false
458
+ },
459
+ prefix: /^\s*?(\d+\.|-|\*|\[ ?\]|\[x\])$/,
460
+ handler(range, context) {
461
+ if (this.quill.scroll.query('list') == null) return true;
462
+ const {
463
+ length
464
+ } = context.prefix;
465
+ const [line, offset] = this.quill.getLine(range.index);
466
+ if (offset > length) return true;
467
+ let value;
468
+ switch (context.prefix.trim()) {
469
+ case '[]':
470
+ case '[ ]':
471
+ value = 'unchecked';
472
+ break;
473
+ case '[x]':
474
+ value = 'checked';
475
+ break;
476
+ case '-':
477
+ case '*':
478
+ value = 'bullet';
479
+ break;
480
+ default:
481
+ value = 'ordered';
482
+ }
483
+ this.quill.insertText(range.index, ' ', Quill.sources.USER);
484
+ this.quill.history.cutoff();
485
+ const delta = new Delta().retain(range.index - offset).delete(length + 1)
486
+ // @ts-expect-error Fix me later
487
+ .retain(line.length() - 2 - offset).retain(1, {
488
+ list: value
489
+ });
490
+ this.quill.updateContents(delta, Quill.sources.USER);
491
+ this.quill.history.cutoff();
492
+ this.quill.setSelection(range.index - length, Quill.sources.SILENT);
493
+ return false;
494
+ }
495
+ },
496
+ 'code exit': {
497
+ key: 'Enter',
498
+ collapsed: true,
499
+ format: ['code-block'],
500
+ prefix: /^$/,
501
+ suffix: /^\s*$/,
502
+ handler(range) {
503
+ const [line, offset] = this.quill.getLine(range.index);
504
+ let numLines = 2;
505
+ let cur = line;
506
+ while (cur != null && cur.length() <= 1 && cur.formats()['code-block']) {
507
+ // @ts-expect-error
508
+ cur = cur.prev;
509
+ numLines -= 1;
510
+ // Requisite prev lines are empty
511
+ if (numLines <= 0) {
512
+ const delta = new Delta()
513
+ // @ts-expect-error Fix me later
514
+ .retain(range.index + line.length() - offset - 2).retain(1, {
515
+ 'code-block': null
516
+ }).delete(1);
517
+ this.quill.updateContents(delta, Quill.sources.USER);
518
+ this.quill.setSelection(range.index - 1, Quill.sources.SILENT);
519
+ return false;
520
+ }
521
+ }
522
+ return true;
523
+ }
524
+ },
525
+ 'embed left': makeEmbedArrowHandler('ArrowLeft', false),
526
+ 'embed left shift': makeEmbedArrowHandler('ArrowLeft', true),
527
+ 'embed right': makeEmbedArrowHandler('ArrowRight', false),
528
+ 'embed right shift': makeEmbedArrowHandler('ArrowRight', true),
529
+ 'table down': makeTableArrowHandler(false),
530
+ 'table up': makeTableArrowHandler(true)
531
+ }
532
+ };
533
+ Keyboard.DEFAULTS = defaultOptions;
534
+ function makeCodeBlockHandler(indent) {
535
+ return {
536
+ key: 'Tab',
537
+ shiftKey: !indent,
538
+ format: {
539
+ 'code-block': true
540
+ },
541
+ handler(range, _ref) {
542
+ let {
543
+ event
544
+ } = _ref;
545
+ const CodeBlock = this.quill.scroll.query('code-block');
546
+ // @ts-expect-error
547
+ const {
548
+ TAB
549
+ } = CodeBlock;
550
+ if (range.length === 0 && !event.shiftKey) {
551
+ this.quill.insertText(range.index, TAB, Quill.sources.USER);
552
+ this.quill.setSelection(range.index + TAB.length, Quill.sources.SILENT);
553
+ return;
554
+ }
555
+ const lines = range.length === 0 ? this.quill.getLines(range.index, 1) : this.quill.getLines(range);
556
+ let {
557
+ index,
558
+ length
559
+ } = range;
560
+ lines.forEach((line, i) => {
561
+ if (indent) {
562
+ line.insertAt(0, TAB);
563
+ if (i === 0) {
564
+ index += TAB.length;
565
+ } else {
566
+ length += TAB.length;
567
+ }
568
+ // @ts-expect-error Fix me later
569
+ } else if (line.domNode.textContent.startsWith(TAB)) {
570
+ line.deleteAt(0, TAB.length);
571
+ if (i === 0) {
572
+ index -= TAB.length;
573
+ } else {
574
+ length -= TAB.length;
575
+ }
576
+ }
577
+ });
578
+ this.quill.update(Quill.sources.USER);
579
+ this.quill.setSelection(index, length, Quill.sources.SILENT);
580
+ }
581
+ };
582
+ }
583
+ function makeEmbedArrowHandler(key, shiftKey) {
584
+ const where = key === 'ArrowLeft' ? 'prefix' : 'suffix';
585
+ return {
586
+ key,
587
+ shiftKey,
588
+ altKey: null,
589
+ [where]: /^$/,
590
+ handler(range) {
591
+ let {
592
+ index
593
+ } = range;
594
+ if (key === 'ArrowRight') {
595
+ index += range.length + 1;
596
+ }
597
+ const [leaf] = this.quill.getLeaf(index);
598
+ if (!(leaf instanceof EmbedBlot)) return true;
599
+ if (key === 'ArrowLeft') {
600
+ if (shiftKey) {
601
+ this.quill.setSelection(range.index - 1, range.length + 1, Quill.sources.USER);
602
+ } else {
603
+ this.quill.setSelection(range.index - 1, Quill.sources.USER);
604
+ }
605
+ } else if (shiftKey) {
606
+ this.quill.setSelection(range.index, range.length + 1, Quill.sources.USER);
607
+ } else {
608
+ this.quill.setSelection(range.index + range.length + 1, Quill.sources.USER);
609
+ }
610
+ return false;
611
+ }
612
+ };
613
+ }
614
+ function makeFormatHandler(format) {
615
+ return {
616
+ key: format[0],
617
+ shortKey: true,
618
+ handler(range, context) {
619
+ this.quill.format(format, !context.format[format], Quill.sources.USER);
620
+ }
621
+ };
622
+ }
623
+ function makeTableArrowHandler(up) {
624
+ return {
625
+ key: up ? 'ArrowUp' : 'ArrowDown',
626
+ collapsed: true,
627
+ format: ['table'],
628
+ handler(range, context) {
629
+ // TODO move to table module
630
+ const key = up ? 'prev' : 'next';
631
+ const cell = context.line;
632
+ const targetRow = cell.parent[key];
633
+ if (targetRow != null) {
634
+ if (targetRow.statics.blotName === 'table-row') {
635
+ // @ts-expect-error
636
+ let targetCell = targetRow.children.head;
637
+ let cur = cell;
638
+ while (cur.prev != null) {
639
+ // @ts-expect-error
640
+ cur = cur.prev;
641
+ targetCell = targetCell.next;
642
+ }
643
+ const index = targetCell.offset(this.quill.scroll) + Math.min(context.offset, targetCell.length() - 1);
644
+ this.quill.setSelection(index, 0, Quill.sources.USER);
645
+ }
646
+ } else {
647
+ // @ts-expect-error
648
+ const targetLine = cell.table()[key];
649
+ if (targetLine != null) {
650
+ if (up) {
651
+ this.quill.setSelection(targetLine.offset(this.quill.scroll) + targetLine.length() - 1, 0, Quill.sources.USER);
652
+ } else {
653
+ this.quill.setSelection(targetLine.offset(this.quill.scroll), 0, Quill.sources.USER);
654
+ }
655
+ }
656
+ }
657
+ return false;
658
+ }
659
+ };
660
+ }
661
+ function normalize(binding) {
662
+ if (typeof binding === 'string' || typeof binding === 'number') {
663
+ binding = {
664
+ key: binding
665
+ };
666
+ } else if (typeof binding === 'object') {
667
+ binding = cloneDeep(binding);
668
+ } else {
669
+ return null;
670
+ }
671
+ if (binding.shortKey) {
672
+ binding[SHORTKEY] = binding.shortKey;
673
+ delete binding.shortKey;
674
+ }
675
+ return binding;
676
+ }
677
+
678
+ // TODO: Move into quill.ts or editor.ts
679
+ function deleteRange(_ref2) {
680
+ let {
681
+ quill,
682
+ range
683
+ } = _ref2;
684
+ const lines = quill.getLines(range);
685
+ let formats = {};
686
+ if (lines.length > 1) {
687
+ const firstFormats = lines[0].formats();
688
+ const lastFormats = lines[lines.length - 1].formats();
689
+ formats = AttributeMap.diff(lastFormats, firstFormats) || {};
690
+ }
691
+ quill.deleteText(range, Quill.sources.USER);
692
+ if (Object.keys(formats).length > 0) {
693
+ quill.formatLine(range.index, 1, formats, Quill.sources.USER);
694
+ }
695
+ quill.setSelection(range.index, Quill.sources.SILENT);
696
+ }
697
+ function tableSide(_table, row, cell, offset) {
698
+ if (row.prev == null && row.next == null) {
699
+ if (cell.prev == null && cell.next == null) {
700
+ return offset === 0 ? -1 : 1;
701
+ }
702
+ return cell.prev == null ? -1 : 1;
703
+ }
704
+ if (row.prev == null) {
705
+ return -1;
706
+ }
707
+ if (row.next == null) {
708
+ return 1;
709
+ }
710
+ return null;
711
+ }
712
+ export { Keyboard as default, SHORTKEY, normalize, deleteRange };
713
+ //# sourceMappingURL=keyboard.js.map