jodit 4.19.12 → 4.20.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 (219) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/es2015/jodit.css +76 -1
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +9 -9
  5. package/es2015/jodit.js +1583 -681
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +9 -9
  8. package/es2015/plugins/debug/debug.css +1 -1
  9. package/es2015/plugins/debug/debug.js +1 -1
  10. package/es2015/plugins/debug/debug.min.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  12. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  13. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  14. package/es2018/jodit.fat.min.css +1 -1
  15. package/es2018/jodit.fat.min.js +9 -9
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +9 -9
  18. package/es2018/plugins/debug/debug.min.js +1 -1
  19. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  20. package/es2021/jodit.css +76 -1
  21. package/es2021/jodit.fat.min.css +1 -1
  22. package/es2021/jodit.fat.min.js +14 -14
  23. package/es2021/jodit.js +1564 -678
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +14 -14
  26. package/es2021/plugins/debug/debug.css +1 -1
  27. package/es2021/plugins/debug/debug.js +1 -1
  28. package/es2021/plugins/debug/debug.min.js +1 -1
  29. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  30. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  31. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  32. package/es2021.en/jodit.css +76 -1
  33. package/es2021.en/jodit.fat.min.css +1 -1
  34. package/es2021.en/jodit.fat.min.js +14 -14
  35. package/es2021.en/jodit.js +1514 -628
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +14 -14
  38. package/es2021.en/plugins/debug/debug.css +1 -1
  39. package/es2021.en/plugins/debug/debug.js +1 -1
  40. package/es2021.en/plugins/debug/debug.min.js +1 -1
  41. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  42. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  43. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  44. package/es5/jodit.css +96 -2
  45. package/es5/jodit.fat.min.css +1 -1
  46. package/es5/jodit.fat.min.js +2 -2
  47. package/es5/jodit.js +1844 -791
  48. package/es5/jodit.min.css +3 -3
  49. package/es5/jodit.min.js +2 -2
  50. package/es5/plugins/debug/debug.css +1 -1
  51. package/es5/plugins/debug/debug.js +1 -1
  52. package/es5/plugins/debug/debug.min.js +1 -1
  53. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  54. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  55. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  56. package/es5/polyfills.fat.min.js +1 -1
  57. package/es5/polyfills.js +1 -1
  58. package/es5/polyfills.min.js +1 -1
  59. package/esm/config.d.ts +10 -3
  60. package/esm/core/constants.js +1 -1
  61. package/esm/core/global.d.ts +6 -0
  62. package/esm/core/global.js +21 -4
  63. package/esm/core/helpers/html/safe-html.js +26 -0
  64. package/esm/core/helpers/utils/anchor.d.ts +22 -0
  65. package/esm/core/helpers/utils/anchor.js +29 -0
  66. package/esm/core/helpers/utils/index.d.ts +1 -0
  67. package/esm/core/helpers/utils/index.js +1 -0
  68. package/esm/core/ui/popup/popup.d.ts +5 -0
  69. package/esm/core/ui/popup/popup.js +5 -0
  70. package/esm/jodit.d.ts +4 -0
  71. package/esm/jodit.js +16 -15
  72. package/esm/langs/ar.d.ts +5 -0
  73. package/esm/langs/ar.js +5 -0
  74. package/esm/langs/az.d.ts +5 -0
  75. package/esm/langs/az.js +5 -0
  76. package/esm/langs/cs_cz.d.ts +5 -0
  77. package/esm/langs/cs_cz.js +6 -1
  78. package/esm/langs/de.d.ts +5 -0
  79. package/esm/langs/de.js +6 -0
  80. package/esm/langs/es.d.ts +5 -0
  81. package/esm/langs/es.js +6 -1
  82. package/esm/langs/fa.d.ts +5 -0
  83. package/esm/langs/fa.js +6 -1
  84. package/esm/langs/fi.d.ts +5 -0
  85. package/esm/langs/fi.js +5 -0
  86. package/esm/langs/fr.d.ts +5 -0
  87. package/esm/langs/fr.js +5 -0
  88. package/esm/langs/he.d.ts +5 -0
  89. package/esm/langs/he.js +6 -1
  90. package/esm/langs/hu.d.ts +5 -0
  91. package/esm/langs/hu.js +5 -0
  92. package/esm/langs/id.d.ts +5 -0
  93. package/esm/langs/id.js +6 -1
  94. package/esm/langs/it.d.ts +5 -0
  95. package/esm/langs/it.js +6 -1
  96. package/esm/langs/ja.d.ts +5 -0
  97. package/esm/langs/ja.js +6 -1
  98. package/esm/langs/ko.d.ts +5 -0
  99. package/esm/langs/ko.js +6 -1
  100. package/esm/langs/mn.d.ts +5 -0
  101. package/esm/langs/mn.js +6 -1
  102. package/esm/langs/nl.d.ts +5 -0
  103. package/esm/langs/nl.js +5 -0
  104. package/esm/langs/no.d.ts +5 -0
  105. package/esm/langs/no.js +5 -0
  106. package/esm/langs/pl.d.ts +5 -0
  107. package/esm/langs/pl.js +5 -0
  108. package/esm/langs/pt_br.d.ts +5 -0
  109. package/esm/langs/pt_br.js +6 -1
  110. package/esm/langs/ru.d.ts +5 -0
  111. package/esm/langs/ru.js +6 -1
  112. package/esm/langs/sk.d.ts +5 -0
  113. package/esm/langs/sk.js +5 -0
  114. package/esm/langs/sv.d.ts +5 -0
  115. package/esm/langs/sv.js +5 -0
  116. package/esm/langs/tr.d.ts +5 -0
  117. package/esm/langs/tr.js +6 -1
  118. package/esm/langs/ua.d.ts +5 -0
  119. package/esm/langs/ua.js +6 -1
  120. package/esm/langs/zh_cn.d.ts +5 -0
  121. package/esm/langs/zh_cn.js +6 -1
  122. package/esm/langs/zh_tw.d.ts +5 -0
  123. package/esm/langs/zh_tw.js +5 -0
  124. package/esm/languages.js +7 -1
  125. package/esm/modules/file-browser/file-browser.d.ts +3 -4
  126. package/esm/modules/file-browser/file-browser.js +12 -12
  127. package/esm/modules/toolbar/button/button.d.ts +7 -0
  128. package/esm/modules/toolbar/button/button.js +30 -4
  129. package/esm/modules/uploader/config.js +18 -18
  130. package/esm/modules/uploader/helpers/index.d.ts +1 -0
  131. package/esm/modules/uploader/helpers/index.js +1 -0
  132. package/esm/modules/uploader/helpers/normalize-uploader-data.d.ts +32 -0
  133. package/esm/modules/uploader/helpers/normalize-uploader-data.js +54 -0
  134. package/esm/modules/uploader/helpers/send-files.js +11 -6
  135. package/esm/modules/uploader/uploader.d.ts +4 -5
  136. package/esm/modules/uploader/uploader.js +12 -8
  137. package/esm/plugins/all.d.ts +1 -0
  138. package/esm/plugins/all.js +1 -0
  139. package/esm/plugins/anchor/anchor.d.ts +67 -0
  140. package/esm/plugins/anchor/anchor.js +302 -0
  141. package/esm/plugins/anchor/config.d.ts +6 -0
  142. package/esm/plugins/anchor/config.js +13 -0
  143. package/esm/plugins/file/file.d.ts +1 -1
  144. package/esm/plugins/file/file.js +6 -6
  145. package/esm/plugins/image/image.js +2 -2
  146. package/esm/plugins/image-caption/image-caption.js +1 -2
  147. package/esm/plugins/image-properties/utils/open-image-popup.js +7 -6
  148. package/esm/plugins/index.d.ts +1 -0
  149. package/esm/plugins/inline-popup/config/config.d.ts +8 -2
  150. package/esm/plugins/inline-popup/config/config.js +1 -0
  151. package/esm/plugins/inline-popup/config/items/cells.js +0 -10
  152. package/esm/plugins/inline-popup/config/items/img.js +1 -1
  153. package/esm/plugins/inline-popup/inline-popup.d.ts +9 -12
  154. package/esm/plugins/inline-popup/inline-popup.js +53 -77
  155. package/esm/plugins/link/link.js +150 -3
  156. package/esm/plugins/select/select.d.ts +31 -0
  157. package/esm/plugins/select/select.js +235 -2
  158. package/esm/plugins/select-cells/select-cells.d.ts +11 -0
  159. package/esm/plugins/select-cells/select-cells.js +48 -17
  160. package/esm/plugins/video/config.d.ts +1 -1
  161. package/esm/plugins/video/config.js +4 -3
  162. package/esm/plugins/video-properties/video-properties.js +7 -6
  163. package/esm/styles/icons/anchor.svg.js +1 -0
  164. package/esm/styles/icons/index.d.ts +1 -1
  165. package/esm/styles/icons/index.js +2 -1
  166. package/esm/types/file-browser.d.ts +8 -1
  167. package/esm/types/popup.d.ts +1 -0
  168. package/esm/types/uploader.d.ts +39 -1
  169. package/package.json +1 -1
  170. package/types/config.d.ts +10 -3
  171. package/types/core/global.d.ts +6 -0
  172. package/types/core/helpers/utils/anchor.d.ts +22 -0
  173. package/types/core/helpers/utils/index.d.ts +1 -0
  174. package/types/core/ui/popup/popup.d.ts +5 -0
  175. package/types/jodit.d.ts +4 -0
  176. package/types/langs/ar.d.ts +5 -0
  177. package/types/langs/az.d.ts +5 -0
  178. package/types/langs/cs_cz.d.ts +5 -0
  179. package/types/langs/de.d.ts +5 -0
  180. package/types/langs/es.d.ts +5 -0
  181. package/types/langs/fa.d.ts +5 -0
  182. package/types/langs/fi.d.ts +5 -0
  183. package/types/langs/fr.d.ts +5 -0
  184. package/types/langs/he.d.ts +5 -0
  185. package/types/langs/hu.d.ts +5 -0
  186. package/types/langs/id.d.ts +5 -0
  187. package/types/langs/it.d.ts +5 -0
  188. package/types/langs/ja.d.ts +5 -0
  189. package/types/langs/ko.d.ts +5 -0
  190. package/types/langs/mn.d.ts +5 -0
  191. package/types/langs/nl.d.ts +5 -0
  192. package/types/langs/no.d.ts +5 -0
  193. package/types/langs/pl.d.ts +5 -0
  194. package/types/langs/pt_br.d.ts +5 -0
  195. package/types/langs/ru.d.ts +5 -0
  196. package/types/langs/sk.d.ts +5 -0
  197. package/types/langs/sv.d.ts +5 -0
  198. package/types/langs/tr.d.ts +5 -0
  199. package/types/langs/ua.d.ts +5 -0
  200. package/types/langs/zh_cn.d.ts +5 -0
  201. package/types/langs/zh_tw.d.ts +5 -0
  202. package/types/modules/file-browser/file-browser.d.ts +3 -4
  203. package/types/modules/toolbar/button/button.d.ts +7 -0
  204. package/types/modules/uploader/helpers/index.d.ts +1 -0
  205. package/types/modules/uploader/helpers/normalize-uploader-data.d.ts +32 -0
  206. package/types/modules/uploader/uploader.d.ts +4 -5
  207. package/types/plugins/anchor/anchor.d.ts +67 -0
  208. package/types/plugins/anchor/config.d.ts +6 -0
  209. package/types/plugins/file/file.d.ts +1 -1
  210. package/types/plugins/index.d.ts +1 -0
  211. package/types/plugins/inline-popup/config/config.d.ts +8 -2
  212. package/types/plugins/inline-popup/inline-popup.d.ts +9 -12
  213. package/types/plugins/select/select.d.ts +31 -0
  214. package/types/plugins/select-cells/select-cells.d.ts +11 -0
  215. package/types/plugins/video/config.d.ts +1 -1
  216. package/types/styles/icons/index.d.ts +1 -1
  217. package/types/types/file-browser.d.ts +8 -1
  218. package/types/types/popup.d.ts +1 -0
  219. package/types/types/uploader.d.ts +39 -1
@@ -30,24 +30,14 @@ export class inlinePopup extends Plugin {
30
30
  constructor() {
31
31
  super(...arguments);
32
32
  this.type = null;
33
- /**
34
- * The user pressed a button inside the selection toolbar — after the
35
- * command fires `closeAllPopups`, the toolbar should be shown again
36
- * while the selection is still there. See #1238
37
- */
38
- this.__reopenSelectionPopup = false;
39
- /**
40
- * The alignment controls fire `recalcPositionPopup` once they have moved
41
- * the element, and their button then fires `closeAllPopups`. The popup
42
- * opens again beside the element, as the selection toolbar does
43
- */
44
- this.__reopenFor = null;
45
33
  this.snapRange = null;
46
34
  this.__keyDownElement = null;
47
35
  this.elmsList = keys(this.j.o.popup, false).filter(s => !this.isExcludedTarget(s));
48
36
  }
49
37
  get popup() {
50
- return new Popup(this.jodit, false);
38
+ const popup = new Popup(this.jodit, false);
39
+ popup.keepOpen = this.j.o.toolbarInlineKeepOpen;
40
+ return popup;
51
41
  }
52
42
  get toolbar() {
53
43
  return makeCollection(this.jodit, this.popup);
@@ -64,10 +54,10 @@ export class inlinePopup extends Plugin {
64
54
  const isMedia = type === 'jodit-media';
65
55
  // Beside the media in a wrapper kept in the content, which can fill
66
56
  // the line, and below a captioned image's caption, so it stays in view
67
- const bound = (mediaWrapper && getWrappedMedia(this.j, mediaWrapper)) ||
57
+ const bound = () => (mediaWrapper && getWrappedMedia(this.j, mediaWrapper)) ||
68
58
  getCaptionWrapper(this.j, target) ||
69
59
  target;
70
- this.showPopup(() => this.__bound(bound, isMedia), type, target);
60
+ this.showPopup(() => this.__bound(bound(), isMedia), type, target);
71
61
  return false;
72
62
  }
73
63
  }
@@ -94,14 +84,19 @@ export class inlinePopup extends Plugin {
94
84
  * Show inline popup with some toolbar
95
85
  *
96
86
  * @param type - selection, img, a etc.
87
+ * @param force - make the popup again for the same target
97
88
  */
98
- showPopup(rect, type, target) {
89
+ showPopup(rect, type, target, force = false) {
99
90
  type = type.toLowerCase();
100
91
  if (!this.canShowPopupForType(type)) {
101
92
  return false;
102
93
  }
103
- if (this.type !== type || target !== this.previousTarget) {
94
+ if (force || this.type !== type || target !== this.previousTarget) {
104
95
  this.previousTarget = target;
96
+ // What it showed is taken out, not destructed: an element a
97
+ // function returns is its own, and may be shown again
98
+ this.popup.elements.slice().forEach(elm => this.popup.remove(elm));
99
+ Dom.detach(this.popup.getElm('content'));
105
100
  const data = this.j.o.popup[type];
106
101
  let content;
107
102
  if (isFunction(data)) {
@@ -207,65 +202,31 @@ export class inlinePopup extends Plugin {
207
202
  })
208
203
  .on('hidePopup', this.hidePopup)
209
204
  .on('showInlineToolbar', this.showInlineToolbar)
210
- .on('showPopup', (elm, rect, type) => {
211
- this.showPopup(rect, type || (isString(elm) ? elm : elm.nodeName), isString(elm) ? undefined : elm);
205
+ .on('showPopup', (elm, rect, type, force) => {
206
+ this.showPopup(rect, type || (isString(elm) ? elm : elm.nodeName), isString(elm) ? undefined : elm, force);
212
207
  })
213
208
  .on('mousedown keydown', this.onSelectionStart)
214
209
  .on('change', () => {
215
- if (this.popup.isOpened &&
216
- this.previousTarget &&
217
- !this.previousTarget.parentNode) {
210
+ if (!this.popup.isOpened) {
211
+ return;
212
+ }
213
+ if (this.previousTarget && !this.previousTarget.parentNode) {
218
214
  this.hidePopup();
219
215
  this.previousTarget = undefined;
220
216
  }
217
+ else if (this.type === 'selection' &&
218
+ !this.__hasSelectedContent()) {
219
+ this.hidePopup();
220
+ }
221
221
  })
222
- .on([this.j.ew, this.j.ow], 'mouseup keyup', this.onSelectionEnd)
223
- .on([this.j.ew, this.j.ow], 'mousedown touchstart', this.__onDocumentMouseDown)
224
- .on('closeAllPopups', this.__onCloseAllPopups);
222
+ .on([this.j.ew, this.j.ow], 'mouseup keyup', this.onSelectionEnd);
225
223
  this.addListenersForElements();
226
224
  }
225
+ /**
226
+ * Follow the element once a control has moved it, as the alignments do
227
+ */
227
228
  onRecalcPositionPopup() {
228
- if (this.popup.isOpened &&
229
- this.type !== 'selection' &&
230
- this.previousTarget) {
231
- this.__reopenFor = this.previousTarget;
232
- }
233
- }
234
- __onDocumentMouseDown(e) {
235
- this.__reopenFor = null;
236
- if (this.popup.isOpened &&
237
- this.type === 'selection' &&
238
- e.target &&
239
- UIElement.closestElement(e.target, Popup)) {
240
- this.__reopenSelectionPopup = true;
241
- }
242
- }
243
- __onCloseAllPopups() {
244
- const target = this.__reopenFor;
245
- if (target) {
246
- this.__reopenFor = null;
247
- // After the popup's own `closeAllPopups` handler, as below
248
- this.j.async.setTimeout(() => {
249
- if (this.j.editor.contains(target)) {
250
- this.onClick(target);
251
- }
252
- }, 1);
253
- }
254
- if (!this.__reopenSelectionPopup) {
255
- return;
256
- }
257
- this.__reopenSelectionPopup = false;
258
- if (!this.j.o.toolbarInlineForSelection) {
259
- return;
260
- }
261
- // a zero timeout would run synchronously — before the popup's own
262
- // `closeAllPopups` handler closes it; defer to the next macrotask
263
- this.j.async.setTimeout(() => {
264
- const sel = this.j.s.sel;
265
- if (sel && !sel.isCollapsed) {
266
- this.showPopup(() => this.__selectionBound(), 'selection');
267
- }
268
- }, 1);
229
+ this.popup.updatePosition();
269
230
  }
270
231
  /**
271
232
  * The selection rect comes from the editor document — in iframe mode its
@@ -315,9 +276,8 @@ export class inlinePopup extends Plugin {
315
276
  return;
316
277
  }
317
278
  const type = 'selection';
318
- const sel = this.j.s.sel;
319
279
  const range = this.j.s.range;
320
- if ((sel === null || sel === void 0 ? void 0 : sel.isCollapsed) || this.isSelectedTarget(range)) {
280
+ if (!this.__hasSelectedContent() || this.isSelectedTarget(range)) {
321
281
  if (this.type === type && this.popup.isOpened) {
322
282
  this.hidePopup();
323
283
  }
@@ -329,6 +289,30 @@ export class inlinePopup extends Plugin {
329
289
  }
330
290
  this.showPopup(() => this.__selectionBound(), type);
331
291
  }
292
+ /**
293
+ * The selection holds more than a line break. A double click past the end
294
+ * of a line, or a drag from there into the next, selects only the break,
295
+ * with any rule, video or empty line it crosses: it starts at the end of a
296
+ * line, after everything in it, and holds no text that shows
297
+ */
298
+ __hasSelectedContent() {
299
+ const { sel, range } = this.j.s;
300
+ if (!sel || sel.isCollapsed) {
301
+ return false;
302
+ }
303
+ // HTML collapses ASCII white space, but not  
304
+ const showsText = (r) => /[^\t\n\f\r \uFEFF\u200B]/.test(r.toString());
305
+ const line = Dom.closest(range.startContainer, Dom.isBlock, this.j.editor);
306
+ if (!line || line === this.j.editor || showsText(range)) {
307
+ return true;
308
+ }
309
+ // The rest of the line after the selection's start
310
+ const rest = this.j.s.createRange();
311
+ rest.setStart(range.startContainer, range.startOffset);
312
+ rest.setEnd(line, line.childNodes.length);
313
+ return (showsText(rest) ||
314
+ toArray(line.querySelectorAll(':not(br):empty')).some(elm => rest.intersectsNode(elm)));
315
+ }
332
316
  /**
333
317
  * In not collapsed selection - only one image
334
318
  */
@@ -349,9 +333,7 @@ export class inlinePopup extends Plugin {
349
333
  beforeDestruct(jodit) {
350
334
  jodit.e
351
335
  .off('showPopup')
352
- .off([this.j.ew, this.j.ow], 'mouseup keyup', this.onSelectionEnd)
353
- .off([this.j.ew, this.j.ow], 'mousedown touchstart', this.__onDocumentMouseDown)
354
- .off('closeAllPopups', this.__onCloseAllPopups);
336
+ .off([this.j.ew, this.j.ow], 'mouseup keyup', this.onSelectionEnd);
355
337
  this.removeListenersForElements();
356
338
  }
357
339
  _eventsList() {
@@ -409,12 +391,6 @@ __decorate([
409
391
  __decorate([
410
392
  watch(':recalcPositionPopup')
411
393
  ], inlinePopup.prototype, "onRecalcPositionPopup", null);
412
- __decorate([
413
- autobind
414
- ], inlinePopup.prototype, "__onDocumentMouseDown", null);
415
- __decorate([
416
- autobind
417
- ], inlinePopup.prototype, "__onCloseAllPopups", null);
418
394
  __decorate([
419
395
  autobind
420
396
  ], inlinePopup.prototype, "onSelectionStart", null);
@@ -13,12 +13,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
14
  return c > 3 && r && Object.defineProperty(target, key, r), r;
15
15
  };
16
- import { KEY_BACKSPACE, KEY_TAB } from "../../core/constants.js";
16
+ import { KEY_BACKSPACE, KEY_DOWN, KEY_ESC, KEY_TAB, KEY_UP } from "../../core/constants.js";
17
17
  import { autobind } from "../../core/decorators/index.js";
18
18
  import { Dom } from "../../core/dom/index.js";
19
- import { pluginSystem } from "../../core/global.js";
20
- import { attr, call, convertMediaUrlToVideoEmbed, isString, isURL, prepareEmbedCode, refs, stripTags } from "../../core/helpers/index.js";
19
+ import { pluginSystem, uniqueUid } from "../../core/global.js";
20
+ import { attr, call, convertMediaUrlToVideoEmbed, getAnchorName, getAnchors, isString, isURL, position, prepareEmbedCode, refs, stripTags } from "../../core/helpers/index.js";
21
21
  import { Plugin } from "../../core/plugin/index.js";
22
+ import { UIElement } from "../../core/ui/element.js";
23
+ import { Icon } from "../../core/ui/icon.js";
24
+ import { Popup } from "../../core/ui/popup/popup.js";
22
25
  import "./config.js";
23
26
  import { EMAIL, findTypedLink } from "./typed-link.js";
24
27
  /**
@@ -205,6 +208,7 @@ export class link extends Plugin {
205
208
  target_checkbox.checked = openInNewTabCheckboxDefaultChecked;
206
209
  }
207
210
  }
211
+ addAnchorList(jodit, url_input, content_input, isImageContent);
208
212
  jodit.editor.normalize();
209
213
  const snapshot = jodit.history.snapshot.make();
210
214
  if (unlink) {
@@ -453,6 +457,149 @@ __decorate([
453
457
  const NO_TYPED_LINKS = new Set(['a', 'pre', 'code']);
454
458
  const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'CapsLock']);
455
459
  pluginSystem.add('link', link);
460
+ /**
461
+ * A dropdown arrow in the URL field that lists the document's anchors by the
462
+ * words after them, and fills in the one picked. The list opens in a popup of
463
+ * its own, from the arrow or the down arrow key, and closes once an address is
464
+ * typed
465
+ */
466
+ function addAnchorList(jodit, url, content, isImage) {
467
+ const anchors = getAnchors(jodit.editor);
468
+ const field = url === null || url === void 0 ? void 0 : url.closest('.jodit-ui-input__wrapper');
469
+ const input = field && UIElement.closestElement(field, UIElement);
470
+ if (!field || !input || !anchors.length) {
471
+ return;
472
+ }
473
+ const { c } = jodit;
474
+ const label = jodit.i18n('Link to an anchor');
475
+ const toggle = c.element('button', {
476
+ type: 'button',
477
+ class: 'jodit-link-anchors__toggle',
478
+ title: label,
479
+ 'aria-label': label
480
+ });
481
+ const heading = c.div('jodit-link-anchors__heading', {
482
+ id: 'jodit-link-anchors-' + uniqueUid()
483
+ });
484
+ const list = c.div('jodit-link-anchors', {
485
+ role: 'group',
486
+ 'aria-labelledby': heading.id
487
+ });
488
+ const icon = (name) => {
489
+ var _a;
490
+ return (_a = Icon.makeIcon(jodit, {
491
+ name,
492
+ iconURL: '',
493
+ fill: '',
494
+ scale: undefined
495
+ })) !== null && _a !== void 0 ? _a : c.span();
496
+ };
497
+ const dropdown = new Popup(jodit).setMod('padding', false);
498
+ const items = [];
499
+ let filled = '';
500
+ const open = () => {
501
+ var _a;
502
+ if (dropdown.isOpened) {
503
+ return;
504
+ }
505
+ // Clicks in the list then count as the form's, which stays open
506
+ dropdown.parentElement || (dropdown.parentElement = input);
507
+ list.style.minWidth = field.offsetWidth + 'px';
508
+ dropdown.open(() => position(field));
509
+ attr(toggle, 'aria-expanded', true);
510
+ items.forEach((item, index) => attr(item, 'aria-current', url.value === '#' + getAnchorName(anchors[index])));
511
+ (_a = list.querySelector('[aria-current=true]')) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
512
+ block: 'nearest'
513
+ });
514
+ };
515
+ toggle.append(icon('chevron'));
516
+ attr(toggle, 'aria-expanded', false);
517
+ heading.textContent = jodit.i18n('On this page');
518
+ list.appendChild(heading);
519
+ dropdown.setContent(list);
520
+ anchors.forEach(anchor => {
521
+ const name = getAnchorName(anchor);
522
+ const text = textAfter(jodit, anchor) || name;
523
+ const item = c.element('button', {
524
+ type: 'button',
525
+ tabindex: -1,
526
+ class: 'jodit-link-anchors__item'
527
+ });
528
+ items.push(item);
529
+ const textBox = c.span('jodit-link-anchors__text');
530
+ textBox.textContent = text;
531
+ const nameBox = c.span('jodit-link-anchors__name');
532
+ nameBox.textContent = '#' + name;
533
+ item.append(icon('anchor'), textBox, nameBox);
534
+ list.appendChild(item);
535
+ jodit.e.on(item, 'click', () => {
536
+ dropdown.close();
537
+ url.value = '#' + name;
538
+ if (!isImage &&
539
+ (!content.value.trim() || content.value === filled)) {
540
+ content.value = filled = text;
541
+ }
542
+ url.focus();
543
+ });
544
+ });
545
+ // A press on the arrow closes the open list before the click
546
+ let wasOpen = false;
547
+ jodit.e
548
+ .on(dropdown, 'beforeClose', () => attr(toggle, 'aria-expanded', false))
549
+ .on(toggle, 'mousedown', () => (wasOpen = dropdown.isOpened))
550
+ .on(toggle, 'click', () => {
551
+ wasOpen || dropdown.isOpened ? dropdown.close() : open();
552
+ wasOpen = false;
553
+ })
554
+ .on(url, 'input.anchors', () => {
555
+ if (url.value && !url.value.startsWith('#')) {
556
+ dropdown.close();
557
+ }
558
+ })
559
+ .on(url, 'keydown.anchors', (e) => {
560
+ if (e.key === KEY_DOWN) {
561
+ e.preventDefault();
562
+ open();
563
+ items[0].focus();
564
+ }
565
+ if (e.key === KEY_ESC && dropdown.isOpened) {
566
+ e.stopPropagation();
567
+ dropdown.close();
568
+ }
569
+ })
570
+ .on(list, 'keydown', (e) => {
571
+ var _a;
572
+ const index = items.indexOf(e.target);
573
+ if (e.key === KEY_DOWN || e.key === KEY_UP) {
574
+ e.preventDefault();
575
+ (_a = items[index + (e.key === KEY_DOWN ? 1 : -1)]) === null || _a === void 0 ? void 0 : _a.focus();
576
+ }
577
+ if (e.key === KEY_ESC) {
578
+ e.stopPropagation();
579
+ dropdown.close();
580
+ url.focus();
581
+ }
582
+ });
583
+ // The URL input is destructed when the form closes
584
+ input.hookStatus('destructed', () => {
585
+ dropdown.destruct();
586
+ jodit.e.off([toggle, list, ...items]).off(url, '.anchors');
587
+ });
588
+ Dom.after(url, toggle);
589
+ }
590
+ /**
591
+ * The words after an anchor in its block, which say where it is
592
+ */
593
+ function textAfter(jodit, anchor) {
594
+ var _a;
595
+ const range = jodit.ed.createRange();
596
+ range.selectNodeContents((_a = Dom.up(anchor, Dom.isBlock, jodit.editor)) !== null && _a !== void 0 ? _a : jodit.editor);
597
+ range.setStartAfter(anchor);
598
+ const text = range.toString().replace(/\s+/g, ' ').trim();
599
+ return text.length > 50
600
+ ? text.slice(0, 50).replace(/\s+\S*$/, '') + '…'
601
+ : text;
602
+ }
456
603
  /**
457
604
  * Guess a usable `href` from the selected text for the link dialog.
458
605
  * Returns an empty string when the text is not a plausible URL/email,
@@ -26,6 +26,21 @@ export declare class select extends Plugin {
26
26
  private proxyEventsList;
27
27
  protected afterInit(jodit: IJodit): void;
28
28
  protected beforeDestruct(jodit: IJodit): void;
29
+ private __selectedMediaStyle;
30
+ /**
31
+ * The browsers shade an image in the selection, but Chrome doesn't shade
32
+ * a video with controls, or one in a `jodit-media` wrapper, so a selection
33
+ * that took one in didn't show it, and typing deleted it unseen (#1768).
34
+ * The media gets the same shade from a filter, in place of the tint Safari
35
+ * gives a block wrapper's whole line. It's a style in the editing
36
+ * document, as selected cells get their border, so the content, and with
37
+ * it the value, the history and a copy, doesn't change. Media a click
38
+ * selected whole is left alone, as its resize frame shows it (#1528). A
39
+ * change, read-only and the source mode redo or drop the style, as the
40
+ * selection may not change with them, and the style's paths could then
41
+ * fit other elements
42
+ */
43
+ private __markSelectedMedia;
29
44
  private onStartSelection;
30
45
  /**
31
46
  * Where the last press started. Chrome reports a drag that begins in one
@@ -93,5 +108,21 @@ export declare class select extends Plugin {
93
108
  * Normalize selection after triple click
94
109
  */
95
110
  protected onTripleClickNormalizeSelection(e: MouseEvent): void;
111
+ /**
112
+ * A double click past the end of a line selects only its line break, up
113
+ * to the start of the next line a caret can go on. The browsers show no
114
+ * caret for it, and typing replaces the break, joining the lines and
115
+ * taking any video in between with it (#1768). Put the caret at the end
116
+ * of the line instead
117
+ */
118
+ protected onDblClickPastLineEnd(): void;
119
+ /**
120
+ * The browsers have no caret position beside an uneditable block alone
121
+ * on its line, such as a video, so a drag that ends on its line runs on
122
+ * past it, and typing deletes it (#1768). Until the pointer has passed
123
+ * the block, the selection stops at the last caret place in the block
124
+ * before its line, or for a drag upwards at the first in the block after
125
+ */
126
+ protected onMouseUpOnUneditableLine(e: MouseEvent): void;
96
127
  protected onCopyNormalizeSelectionBound(e?: ClipboardEvent): void;
97
128
  }