jodit 4.19.14 → 4.20.1

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 (217) 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 +12 -12
  5. package/es2015/jodit.js +1464 -599
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +12 -12
  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 +12 -12
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +12 -12
  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 +17 -17
  23. package/es2021/jodit.js +1445 -596
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +17 -17
  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 +17 -17
  35. package/es2021.en/jodit.js +1419 -570
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +17 -17
  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 +1707 -706
  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/helpers/utils/anchor.d.ts +22 -0
  62. package/esm/core/helpers/utils/anchor.js +29 -0
  63. package/esm/core/helpers/utils/index.d.ts +1 -0
  64. package/esm/core/helpers/utils/index.js +1 -0
  65. package/esm/core/ui/form/inputs/input/input.js +2 -0
  66. package/esm/core/ui/popup/popup.d.ts +5 -0
  67. package/esm/core/ui/popup/popup.js +5 -0
  68. package/esm/jodit.js +11 -14
  69. package/esm/langs/ar.d.ts +5 -0
  70. package/esm/langs/ar.js +5 -0
  71. package/esm/langs/az.d.ts +5 -0
  72. package/esm/langs/az.js +5 -0
  73. package/esm/langs/cs_cz.d.ts +5 -0
  74. package/esm/langs/cs_cz.js +6 -1
  75. package/esm/langs/de.d.ts +5 -0
  76. package/esm/langs/de.js +6 -0
  77. package/esm/langs/es.d.ts +5 -0
  78. package/esm/langs/es.js +6 -1
  79. package/esm/langs/fa.d.ts +5 -0
  80. package/esm/langs/fa.js +6 -1
  81. package/esm/langs/fi.d.ts +5 -0
  82. package/esm/langs/fi.js +5 -0
  83. package/esm/langs/fr.d.ts +5 -0
  84. package/esm/langs/fr.js +5 -0
  85. package/esm/langs/he.d.ts +5 -0
  86. package/esm/langs/he.js +6 -1
  87. package/esm/langs/hu.d.ts +5 -0
  88. package/esm/langs/hu.js +5 -0
  89. package/esm/langs/id.d.ts +5 -0
  90. package/esm/langs/id.js +6 -1
  91. package/esm/langs/it.d.ts +5 -0
  92. package/esm/langs/it.js +6 -1
  93. package/esm/langs/ja.d.ts +5 -0
  94. package/esm/langs/ja.js +6 -1
  95. package/esm/langs/ko.d.ts +5 -0
  96. package/esm/langs/ko.js +6 -1
  97. package/esm/langs/mn.d.ts +5 -0
  98. package/esm/langs/mn.js +6 -1
  99. package/esm/langs/nl.d.ts +5 -0
  100. package/esm/langs/nl.js +5 -0
  101. package/esm/langs/no.d.ts +5 -0
  102. package/esm/langs/no.js +5 -0
  103. package/esm/langs/pl.d.ts +5 -0
  104. package/esm/langs/pl.js +5 -0
  105. package/esm/langs/pt_br.d.ts +5 -0
  106. package/esm/langs/pt_br.js +6 -1
  107. package/esm/langs/ru.d.ts +5 -0
  108. package/esm/langs/ru.js +6 -1
  109. package/esm/langs/sk.d.ts +5 -0
  110. package/esm/langs/sk.js +5 -0
  111. package/esm/langs/sv.d.ts +5 -0
  112. package/esm/langs/sv.js +5 -0
  113. package/esm/langs/tr.d.ts +5 -0
  114. package/esm/langs/tr.js +6 -1
  115. package/esm/langs/ua.d.ts +5 -0
  116. package/esm/langs/ua.js +6 -1
  117. package/esm/langs/zh_cn.d.ts +5 -0
  118. package/esm/langs/zh_cn.js +6 -1
  119. package/esm/langs/zh_tw.d.ts +5 -0
  120. package/esm/langs/zh_tw.js +5 -0
  121. package/esm/modules/file-browser/file-browser.d.ts +3 -4
  122. package/esm/modules/file-browser/file-browser.js +12 -12
  123. package/esm/modules/toolbar/button/button.d.ts +7 -0
  124. package/esm/modules/toolbar/button/button.js +32 -4
  125. package/esm/modules/uploader/config.js +18 -18
  126. package/esm/modules/uploader/helpers/index.d.ts +1 -0
  127. package/esm/modules/uploader/helpers/index.js +1 -0
  128. package/esm/modules/uploader/helpers/normalize-uploader-data.d.ts +32 -0
  129. package/esm/modules/uploader/helpers/normalize-uploader-data.js +54 -0
  130. package/esm/modules/uploader/helpers/send-files.js +11 -6
  131. package/esm/modules/uploader/uploader.d.ts +4 -5
  132. package/esm/modules/uploader/uploader.js +12 -8
  133. package/esm/plugins/all.d.ts +1 -0
  134. package/esm/plugins/all.js +1 -0
  135. package/esm/plugins/anchor/anchor.d.ts +67 -0
  136. package/esm/plugins/anchor/anchor.js +302 -0
  137. package/esm/plugins/anchor/config.d.ts +6 -0
  138. package/esm/plugins/anchor/config.js +13 -0
  139. package/esm/plugins/file/file.d.ts +1 -1
  140. package/esm/plugins/file/file.js +6 -6
  141. package/esm/plugins/image/image.js +2 -2
  142. package/esm/plugins/image-caption/image-caption.js +1 -2
  143. package/esm/plugins/image-properties/utils/open-image-popup.js +7 -6
  144. package/esm/plugins/index.d.ts +1 -0
  145. package/esm/plugins/inline-popup/config/config.d.ts +8 -2
  146. package/esm/plugins/inline-popup/config/config.js +1 -0
  147. package/esm/plugins/inline-popup/config/items/cells.js +0 -10
  148. package/esm/plugins/inline-popup/config/items/img.js +1 -1
  149. package/esm/plugins/inline-popup/inline-popup.d.ts +9 -12
  150. package/esm/plugins/inline-popup/inline-popup.js +53 -77
  151. package/esm/plugins/link/link.js +150 -3
  152. package/esm/plugins/link/template.js +3 -1
  153. package/esm/plugins/resizer/resizer.d.ts +6 -0
  154. package/esm/plugins/resizer/resizer.js +11 -0
  155. package/esm/plugins/select/select.d.ts +31 -0
  156. package/esm/plugins/select/select.js +235 -2
  157. package/esm/plugins/select-cells/select-cells.d.ts +11 -0
  158. package/esm/plugins/select-cells/select-cells.js +48 -17
  159. package/esm/plugins/video/config.d.ts +1 -1
  160. package/esm/plugins/video/config.js +4 -3
  161. package/esm/plugins/video-properties/video-properties.js +7 -6
  162. package/esm/styles/icons/anchor.svg.js +1 -0
  163. package/esm/styles/icons/index.d.ts +1 -1
  164. package/esm/styles/icons/index.js +2 -1
  165. package/esm/types/file-browser.d.ts +8 -1
  166. package/esm/types/popup.d.ts +1 -0
  167. package/esm/types/uploader.d.ts +39 -1
  168. package/package.json +1 -1
  169. package/types/config.d.ts +10 -3
  170. package/types/core/helpers/utils/anchor.d.ts +22 -0
  171. package/types/core/helpers/utils/index.d.ts +1 -0
  172. package/types/core/ui/popup/popup.d.ts +5 -0
  173. package/types/langs/ar.d.ts +5 -0
  174. package/types/langs/az.d.ts +5 -0
  175. package/types/langs/cs_cz.d.ts +5 -0
  176. package/types/langs/de.d.ts +5 -0
  177. package/types/langs/es.d.ts +5 -0
  178. package/types/langs/fa.d.ts +5 -0
  179. package/types/langs/fi.d.ts +5 -0
  180. package/types/langs/fr.d.ts +5 -0
  181. package/types/langs/he.d.ts +5 -0
  182. package/types/langs/hu.d.ts +5 -0
  183. package/types/langs/id.d.ts +5 -0
  184. package/types/langs/it.d.ts +5 -0
  185. package/types/langs/ja.d.ts +5 -0
  186. package/types/langs/ko.d.ts +5 -0
  187. package/types/langs/mn.d.ts +5 -0
  188. package/types/langs/nl.d.ts +5 -0
  189. package/types/langs/no.d.ts +5 -0
  190. package/types/langs/pl.d.ts +5 -0
  191. package/types/langs/pt_br.d.ts +5 -0
  192. package/types/langs/ru.d.ts +5 -0
  193. package/types/langs/sk.d.ts +5 -0
  194. package/types/langs/sv.d.ts +5 -0
  195. package/types/langs/tr.d.ts +5 -0
  196. package/types/langs/ua.d.ts +5 -0
  197. package/types/langs/zh_cn.d.ts +5 -0
  198. package/types/langs/zh_tw.d.ts +5 -0
  199. package/types/modules/file-browser/file-browser.d.ts +3 -4
  200. package/types/modules/toolbar/button/button.d.ts +7 -0
  201. package/types/modules/uploader/helpers/index.d.ts +1 -0
  202. package/types/modules/uploader/helpers/normalize-uploader-data.d.ts +32 -0
  203. package/types/modules/uploader/uploader.d.ts +4 -5
  204. package/types/plugins/anchor/anchor.d.ts +67 -0
  205. package/types/plugins/anchor/config.d.ts +6 -0
  206. package/types/plugins/file/file.d.ts +1 -1
  207. package/types/plugins/index.d.ts +1 -0
  208. package/types/plugins/inline-popup/config/config.d.ts +8 -2
  209. package/types/plugins/inline-popup/inline-popup.d.ts +9 -12
  210. package/types/plugins/resizer/resizer.d.ts +6 -0
  211. package/types/plugins/select/select.d.ts +31 -0
  212. package/types/plugins/select-cells/select-cells.d.ts +11 -0
  213. package/types/plugins/video/config.d.ts +1 -1
  214. package/types/styles/icons/index.d.ts +1 -1
  215. package/types/types/file-browser.d.ts +8 -1
  216. package/types/types/popup.d.ts +1 -0
  217. package/types/types/uploader.d.ts +39 -1
@@ -20,7 +20,7 @@ declare module 'jodit/config' {
20
20
  * Jodit.make('#editor', {
21
21
  * file: {
22
22
  * defaultHandlerSuccess(data) {
23
- * data.files.forEach(file => {
23
+ * data.items.forEach(({ file }) => {
24
24
  * this.s.insertHTML(`<a class="file" href="${data.baseurl + file}">${file}</a>`);
25
25
  * });
26
26
  * }
@@ -7,6 +7,7 @@ import { Dom } from "../../core/dom/dom.js";
7
7
  import { pluginSystem } from "../../core/global.js";
8
8
  import { attr } from "../../core/helpers/utils/attr.js";
9
9
  import { Config } from "../../config.js";
10
+ import { getItems } from "../../modules/uploader/helpers/normalize-uploader-data.js";
10
11
  import { FileSelectorWidget } from "../../modules/widget/index.js";
11
12
  /**
12
13
  * Selected text becomes the link's text, as the Link button does, instead
@@ -30,14 +31,14 @@ function wrapSelectionInLink(editor, href, title = '') {
30
31
  return true;
31
32
  }
32
33
  function insertLinks(data) {
33
- var _a;
34
- (_a = data.files) === null || _a === void 0 ? void 0 : _a.forEach(file => {
35
- const href = data.baseurl + file;
34
+ const { baseurl } = data;
35
+ getItems(data).forEach(({ file }) => {
36
+ const href = baseurl + file;
36
37
  if (wrapSelectionInLink(this, href)) {
37
38
  return;
38
39
  }
39
40
  const link = this.createInside.element('a', { href });
40
- link.textContent = this.o.uploader.getDisplayName.call(this.uploader, data.baseurl, file);
41
+ link.textContent = this.o.uploader.getDisplayName.call(this.uploader, baseurl, file);
41
42
  this.s.insertNode(link);
42
43
  });
43
44
  }
@@ -71,8 +72,7 @@ Config.prototype.controls.file = {
71
72
  }
72
73
  return FileSelectorWidget(editor, {
73
74
  filebrowser: (data) => {
74
- data.files &&
75
- data.files.forEach(file => insert(data.baseurl + file));
75
+ getItems(data).forEach(({ file }) => insert(data.baseurl + file));
76
76
  close();
77
77
  },
78
78
  upload: (data) => {
@@ -9,6 +9,7 @@ import { $$ } from "../../core/helpers/index.js";
9
9
  import { attr } from "../../core/helpers/utils/attr.js";
10
10
  import { Icon } from "../../core/ui/icon.js";
11
11
  import { Config } from "../../config.js";
12
+ import { getItems } from "../../modules/uploader/helpers/normalize-uploader-data.js";
12
13
  import { FileSelectorWidget } from "../../modules/widget/index.js";
13
14
  import imageIcon from "./image.svg.js";
14
15
  Icon.set('image', imageIcon);
@@ -27,8 +28,7 @@ Config.prototype.controls.image = {
27
28
  return FileSelectorWidget(editor, {
28
29
  filebrowser: (data) => {
29
30
  editor.s.restore();
30
- data.files &&
31
- data.files.forEach(file => editor.s.insertImage(data.baseurl + file, null, editor.o.imageDefaultWidth));
31
+ getItems(data).forEach(({ file }) => editor.s.insertImage(data.baseurl + file, null, editor.o.imageDefaultWidth));
32
32
  close();
33
33
  },
34
34
  upload: true,
@@ -425,10 +425,9 @@ export class imageCaption extends Plugin {
425
425
  const fresh = this.__freshCaption(wrapper);
426
426
  this.__unrecorded(() => fresh ? this.__restore(fresh) : this.__uncaption(wrapper, image));
427
427
  // The click opened the image's popup below the caption, so it
428
- // opens again below the image, as after the popup's Caption button
428
+ // moves below the image, as after the popup's Caption button
429
429
  if (clicked) {
430
430
  j.e.fire('recalcPositionPopup');
431
- j.e.fire('closeAllPopups');
432
431
  }
433
432
  }, 1);
434
433
  }
@@ -3,9 +3,9 @@
3
3
  * Released under MIT see LICENSE.txt in the project root for license information.
4
4
  * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net
5
5
  */
6
- import { isArray } from "../../../core/helpers/checker/is-array.js";
7
6
  import { position } from "../../../core/helpers/size/position.js";
8
7
  import { Popup } from "../../../core/ui/popup/popup.js";
8
+ import { getItems } from "../../../modules/uploader/helpers/normalize-uploader-data.js";
9
9
  import { FileSelectorWidget } from "../../../modules/widget/file-selector/file-selector.js";
10
10
  /** @private */
11
11
  export function openImagePopup(j, dialog, state, button) {
@@ -17,15 +17,16 @@ export function openImagePopup(j, dialog, state, button) {
17
17
  popup
18
18
  .setContent(FileSelectorWidget(j, {
19
19
  upload: (data) => {
20
- if (data.files && data.files.length) {
21
- state.values.imageSrc =
22
- data.baseurl + data.files[0];
20
+ const [item] = getItems(data);
21
+ if (item) {
22
+ state.values.imageSrc = data.baseurl + item.file;
23
23
  }
24
24
  closePopup();
25
25
  },
26
26
  filebrowser: async (data) => {
27
- if (data && isArray(data.files) && data.files.length) {
28
- state.values.imageSrc = data.files[0];
27
+ const [item] = data ? getItems(data) : [];
28
+ if (item) {
29
+ state.values.imageSrc = item.file;
29
30
  closePopup();
30
31
  }
31
32
  }
@@ -40,6 +40,7 @@ import "./key-arrow-outside/key-arrow-outside";
40
40
  import "./limit/limit";
41
41
  import "./line-height/line-height";
42
42
  import "./link/link";
43
+ import "./anchor/anchor";
43
44
  import "./media/media";
44
45
  import "./mobile/mobile";
45
46
  import "./ordered-list/ordered-list";
@@ -6,14 +6,14 @@
6
6
  /**
7
7
  * @module plugins/inline-popup
8
8
  */
9
- import type { IControlType, IDictionary, IJodit } from "../../../types/index";
9
+ import type { IControlType, IDictionary, IJodit, IUIElement } from "../../../types/index";
10
10
  declare module 'jodit/config' {
11
11
  interface Config {
12
12
  /**
13
13
  * Element-specific popup toolbars. Keys are tag names (e.g. `img`, `a`, `cells`)
14
14
  * and values are button lists or factory functions that return them.
15
15
  */
16
- popup: IDictionary<Array<IControlType | string> | ((editor: IJodit, target: HTMLElement | undefined, close: () => void) => Array<IControlType | string> | HTMLElement | string)>;
16
+ popup: IDictionary<Array<IControlType | string> | ((editor: IJodit, target: HTMLElement | undefined, close: () => void) => Array<IControlType | string> | HTMLElement | IUIElement | string)>;
17
17
  /**
18
18
  * List of button names to exclude from the inline toolbar
19
19
  */
@@ -26,6 +26,12 @@ declare module 'jodit/config' {
26
26
  * Show an inline toolbar when the user selects text
27
27
  */
28
28
  toolbarInlineForSelection: boolean;
29
+ /**
30
+ * Keep an inline toolbar open after one of its buttons runs, beside its
31
+ * element or the selection. A list the button opened still closes.
32
+ * `false` closes the toolbar after every button
33
+ */
34
+ toolbarInlineKeepOpen: boolean;
29
35
  /**
30
36
  * CSS selector or array of selectors for elements that should not trigger the inline toolbar
31
37
  */
@@ -22,6 +22,7 @@ import * as th from "../icons/th.svg.js";
22
22
  import * as thList from "../icons/th-list.svg.js";
23
23
  Config.prototype.toolbarInline = true;
24
24
  Config.prototype.toolbarInlineForSelection = false;
25
+ Config.prototype.toolbarInlineKeepOpen = true;
25
26
  Config.prototype.toolbarInlineDisableFor = [];
26
27
  Config.prototype.toolbarInlineDisabledButtons = ['source'];
27
28
  Icon.set('addcolumn', addcolumn.default)
@@ -5,7 +5,6 @@
5
5
  */
6
6
  import { Dom } from "../../../../core/dom/dom.js";
7
7
  import { isJoditObject, isString } from "../../../../core/helpers/checker/index.js";
8
- import { position } from "../../../../core/helpers/size/position.js";
9
8
  import { css } from "../../../../core/helpers/utils/css.js";
10
9
  const cmd = (control) => control.args && isString(control.args[0])
11
10
  ? control.args[0].toLowerCase()
@@ -88,15 +87,6 @@ export default [
88
87
  return;
89
88
  }
90
89
  editor.execCommand('tableheaderrow', false, table);
91
- const [cell] = editor
92
- .getInstance('Table', editor.o)
93
- .getAllSelectedCells();
94
- // Beside the cell that replaced the one it opened for
95
- if (cell) {
96
- editor.e.fire('showPopup', table, () => position(cell, editor), 'cells');
97
- }
98
- // The popup stays open, so the button shows the new state
99
- return true;
100
90
  },
101
91
  isActive: (editor, button) => Dom.isTag(button.target, 'table') &&
102
92
  editor
@@ -106,7 +106,7 @@ export default [
106
106
  const caption = editor.e.fire('toggleImageCaption', image);
107
107
  editor.synchronizeValues();
108
108
  if (Dom.isHTMLElement(caption)) {
109
- editor.e.fire('hideResizer');
109
+ editor.e.fire('hidePopup hideResizer');
110
110
  editor.s.setCursorIn(caption);
111
111
  }
112
112
  else {
@@ -29,6 +29,7 @@ export declare class inlinePopup extends Plugin {
29
29
  * Show inline popup with some toolbar
30
30
  *
31
31
  * @param type - selection, img, a etc.
32
+ * @param force - make the popup again for the same target
32
33
  */
33
34
  private showPopup;
34
35
  private previousTarget?;
@@ -59,20 +60,9 @@ export declare class inlinePopup extends Plugin {
59
60
  /** @override **/
60
61
  protected afterInit(jodit: IJodit): void;
61
62
  /**
62
- * The user pressed a button inside the selection toolbar — after the
63
- * command fires `closeAllPopups`, the toolbar should be shown again
64
- * while the selection is still there. See #1238
63
+ * Follow the element once a control has moved it, as the alignments do
65
64
  */
66
- private __reopenSelectionPopup;
67
- /**
68
- * The alignment controls fire `recalcPositionPopup` once they have moved
69
- * the element, and their button then fires `closeAllPopups`. The popup
70
- * opens again beside the element, as the selection toolbar does
71
- */
72
- private __reopenFor;
73
65
  protected onRecalcPositionPopup(): void;
74
- private __onDocumentMouseDown;
75
- private __onCloseAllPopups;
76
66
  /**
77
67
  * The selection rect comes from the editor document — in iframe mode its
78
68
  * coordinates are iframe-local, while the popup lives in the host
@@ -88,6 +78,13 @@ export declare class inlinePopup extends Plugin {
88
78
  * Selection change handler
89
79
  */
90
80
  private onSelectionChange;
81
+ /**
82
+ * The selection holds more than a line break. A double click past the end
83
+ * of a line, or a drag from there into the next, selects only the break,
84
+ * with any rule, video or empty line it crosses: it starts at the end of a
85
+ * line, after everything in it, and holds no text that shows
86
+ */
87
+ private __hasSelectedContent;
91
88
  /**
92
89
  * In not collapsed selection - only one image
93
90
  */
@@ -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 &nbsp;
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,
@@ -11,7 +11,9 @@ export const formTemplate = (editor) => {
11
11
  new UIBlock(editor, [
12
12
  new UIInput(editor, {
13
13
  name: 'url',
14
- type: 'text',
14
+ // Touch keyboards leave a URL field as typed, with no capital or
15
+ // correction. The form is `novalidate`, so any address still goes in
16
+ type: 'url',
15
17
  ref: 'url_input',
16
18
  label: 'URL',
17
19
  placeholder: 'http://',
@@ -30,6 +30,12 @@ export declare class resizer extends Plugin {
30
30
  private sizeViewer;
31
31
  /** @override */
32
32
  protected afterInit(editor: IJodit): void;
33
+ /**
34
+ * A tap that selects an image sends no `click` (iPadOS), so `touchend`
35
+ * stands in for it. A tick later, after `onClickOutside` has had the same
36
+ * `touchend`, as `click` comes after `mouseup`
37
+ */
38
+ protected onEditorTouchEnd(e: TouchEvent): void;
33
39
  /**
34
40
  * Click in the editor area
35
41
  */