jodit 4.18.12 → 4.19.4

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 (255) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/es2015/jodit.css +10 -1
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +18 -12
  5. package/es2015/jodit.js +2464 -300
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +18 -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 +18 -12
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +18 -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 +10 -1
  21. package/es2021/jodit.fat.min.css +1 -1
  22. package/es2021/jodit.fat.min.js +26 -19
  23. package/es2021/jodit.js +2426 -297
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +26 -19
  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 +10 -1
  33. package/es2021.en/jodit.fat.min.css +1 -1
  34. package/es2021.en/jodit.fat.min.js +29 -22
  35. package/es2021.en/jodit.js +2400 -271
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +29 -22
  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 +11 -2
  45. package/es5/jodit.fat.min.css +1 -1
  46. package/es5/jodit.fat.min.js +2 -2
  47. package/es5/jodit.js +2823 -360
  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 +44 -1
  60. package/esm/config.js +2 -1
  61. package/esm/core/constants.js +1 -1
  62. package/esm/core/dom/dom.js +4 -2
  63. package/esm/core/event-emitter/event-emitter.js +1 -0
  64. package/esm/core/helpers/utils/align.d.ts +6 -1
  65. package/esm/core/helpers/utils/align.js +22 -12
  66. package/esm/core/helpers/utils/image-caption.d.ts +24 -0
  67. package/esm/core/helpers/utils/image-caption.js +43 -0
  68. package/esm/core/helpers/utils/index.d.ts +1 -0
  69. package/esm/core/helpers/utils/index.js +1 -0
  70. package/esm/core/selection/selection.d.ts +3 -0
  71. package/esm/core/selection/selection.js +20 -5
  72. package/esm/core/ui/helpers/focus-form-field.d.ts +12 -0
  73. package/esm/core/ui/helpers/focus-form-field.js +21 -0
  74. package/esm/jodit.js +18 -2
  75. package/esm/langs/ar.d.ts +2 -0
  76. package/esm/langs/ar.js +2 -0
  77. package/esm/langs/az.d.ts +2 -0
  78. package/esm/langs/az.js +2 -0
  79. package/esm/langs/cs_cz.d.ts +2 -0
  80. package/esm/langs/cs_cz.js +2 -0
  81. package/esm/langs/de.d.ts +2 -0
  82. package/esm/langs/de.js +2 -0
  83. package/esm/langs/es.d.ts +2 -0
  84. package/esm/langs/es.js +2 -0
  85. package/esm/langs/fa.d.ts +2 -0
  86. package/esm/langs/fa.js +2 -0
  87. package/esm/langs/fi.d.ts +2 -0
  88. package/esm/langs/fi.js +2 -0
  89. package/esm/langs/fr.d.ts +2 -0
  90. package/esm/langs/fr.js +2 -0
  91. package/esm/langs/he.d.ts +2 -0
  92. package/esm/langs/he.js +2 -0
  93. package/esm/langs/hu.d.ts +2 -0
  94. package/esm/langs/hu.js +2 -0
  95. package/esm/langs/id.d.ts +2 -0
  96. package/esm/langs/id.js +2 -0
  97. package/esm/langs/it.d.ts +2 -0
  98. package/esm/langs/it.js +2 -0
  99. package/esm/langs/ja.d.ts +2 -0
  100. package/esm/langs/ja.js +2 -0
  101. package/esm/langs/ko.d.ts +2 -0
  102. package/esm/langs/ko.js +2 -0
  103. package/esm/langs/mn.d.ts +2 -0
  104. package/esm/langs/mn.js +2 -0
  105. package/esm/langs/nl.d.ts +2 -0
  106. package/esm/langs/nl.js +2 -0
  107. package/esm/langs/no.d.ts +2 -0
  108. package/esm/langs/no.js +2 -0
  109. package/esm/langs/pl.d.ts +2 -0
  110. package/esm/langs/pl.js +2 -0
  111. package/esm/langs/pt_br.d.ts +2 -0
  112. package/esm/langs/pt_br.js +2 -0
  113. package/esm/langs/ru.d.ts +2 -0
  114. package/esm/langs/ru.js +2 -0
  115. package/esm/langs/sk.d.ts +2 -0
  116. package/esm/langs/sk.js +2 -0
  117. package/esm/langs/sv.d.ts +2 -0
  118. package/esm/langs/sv.js +2 -0
  119. package/esm/langs/tr.d.ts +2 -0
  120. package/esm/langs/tr.js +2 -0
  121. package/esm/langs/ua.d.ts +2 -0
  122. package/esm/langs/ua.js +2 -0
  123. package/esm/langs/zh_cn.d.ts +2 -0
  124. package/esm/langs/zh_cn.js +2 -0
  125. package/esm/langs/zh_tw.d.ts +2 -0
  126. package/esm/langs/zh_tw.js +2 -0
  127. package/esm/modules/table/table.d.ts +27 -0
  128. package/esm/modules/table/table.js +110 -2
  129. package/esm/modules/toolbar/button/button.js +11 -3
  130. package/esm/modules/uploader/helpers/send-files.js +3 -1
  131. package/esm/modules/widget/tabs/tabs.js +2 -0
  132. package/esm/plugins/all.d.ts +1 -0
  133. package/esm/plugins/all.js +1 -0
  134. package/esm/plugins/backspace/backspace.js +17 -1
  135. package/esm/plugins/backspace/cases/check-remove-char.js +1 -11
  136. package/esm/plugins/backspace/helpers.d.ts +5 -0
  137. package/esm/plugins/backspace/helpers.js +11 -0
  138. package/esm/plugins/clean-html/clean-html.js +2 -2
  139. package/esm/plugins/clean-html/helpers/index.d.ts +1 -0
  140. package/esm/plugins/clean-html/helpers/index.js +1 -0
  141. package/esm/plugins/clean-html/helpers/remove-format/remove-format-for-word.d.ts +16 -0
  142. package/esm/plugins/clean-html/helpers/remove-format/remove-format-for-word.js +109 -0
  143. package/esm/plugins/drag-and-drop-element/drag-and-drop-element.js +4 -2
  144. package/esm/plugins/format-block/config.d.ts +13 -0
  145. package/esm/plugins/format-block/config.js +38 -1
  146. package/esm/plugins/format-block/content-fonts.d.ts +17 -0
  147. package/esm/plugins/format-block/content-fonts.js +156 -0
  148. package/esm/plugins/image-caption/config.d.ts +31 -0
  149. package/esm/plugins/image-caption/config.js +11 -0
  150. package/esm/plugins/image-caption/image-caption.d.ts +140 -0
  151. package/esm/plugins/image-caption/image-caption.js +799 -0
  152. package/esm/plugins/image-processor/image-processor.d.ts +2 -1
  153. package/esm/plugins/image-processor/image-processor.js +9 -4
  154. package/esm/plugins/image-properties/config.js +1 -0
  155. package/esm/plugins/image-properties/image-properties.js +19 -5
  156. package/esm/plugins/image-properties/interface.d.ts +6 -0
  157. package/esm/plugins/image-properties/readers/align.d.ts +1 -1
  158. package/esm/plugins/image-properties/readers/index.js +9 -3
  159. package/esm/plugins/image-properties/readers/margin.d.ts +1 -1
  160. package/esm/plugins/image-properties/readers/size.d.ts +5 -1
  161. package/esm/plugins/image-properties/readers/size.js +4 -5
  162. package/esm/plugins/image-properties/ui/ui-image-main-tab.d.ts +2 -0
  163. package/esm/plugins/image-properties/ui/ui-image-main-tab.js +20 -0
  164. package/esm/plugins/image-properties/writers/caption.d.ts +15 -0
  165. package/esm/plugins/image-properties/writers/caption.js +18 -0
  166. package/esm/plugins/image-properties/writers/index.js +15 -10
  167. package/esm/plugins/image-properties/writers/link.js +7 -2
  168. package/esm/plugins/image-properties/writers/margin.d.ts +1 -1
  169. package/esm/plugins/image-properties/writers/size.d.ts +5 -2
  170. package/esm/plugins/image-properties/writers/size.js +16 -2
  171. package/esm/plugins/indent/helpers.d.ts +9 -0
  172. package/esm/plugins/indent/helpers.js +23 -3
  173. package/esm/plugins/indent/indent.js +2 -20
  174. package/esm/plugins/index.d.ts +1 -0
  175. package/esm/plugins/inline-popup/config/config.js +4 -0
  176. package/esm/plugins/inline-popup/config/items/cells.js +29 -0
  177. package/esm/plugins/inline-popup/config/items/img.js +35 -5
  178. package/esm/plugins/inline-popup/icons/caption.svg.js +1 -0
  179. package/esm/plugins/inline-popup/icons/headerrow.svg.js +1 -0
  180. package/esm/plugins/inline-popup/inline-popup.js +3 -2
  181. package/esm/plugins/placeholder/placeholder.js +7 -1
  182. package/esm/plugins/resize-cells/resize-cells.d.ts +49 -0
  183. package/esm/plugins/resize-cells/resize-cells.js +247 -13
  184. package/esm/plugins/resizer/resizer.js +13 -2
  185. package/esm/plugins/select-cells/select-cells.d.ts +5 -0
  186. package/esm/plugins/select-cells/select-cells.js +29 -11
  187. package/esm/plugins/tab/cases/index.d.ts +1 -0
  188. package/esm/plugins/tab/cases/index.js +1 -0
  189. package/esm/plugins/tab/cases/on-tab-inside-li.js +3 -1
  190. package/esm/plugins/tab/cases/tab-spaces.d.ts +32 -0
  191. package/esm/plugins/tab/cases/tab-spaces.js +263 -0
  192. package/esm/plugins/tab/config.d.ts +10 -0
  193. package/esm/plugins/tab/config.js +2 -1
  194. package/esm/plugins/tab/tab.js +61 -6
  195. package/esm/types/types.d.ts +16 -0
  196. package/esm/types/uploader.d.ts +6 -0
  197. package/package.json +1 -1
  198. package/types/config.d.ts +44 -1
  199. package/types/core/helpers/utils/align.d.ts +6 -1
  200. package/types/core/helpers/utils/image-caption.d.ts +24 -0
  201. package/types/core/helpers/utils/index.d.ts +1 -0
  202. package/types/core/selection/selection.d.ts +3 -0
  203. package/types/core/ui/helpers/focus-form-field.d.ts +12 -0
  204. package/types/langs/ar.d.ts +2 -0
  205. package/types/langs/az.d.ts +2 -0
  206. package/types/langs/cs_cz.d.ts +2 -0
  207. package/types/langs/de.d.ts +2 -0
  208. package/types/langs/es.d.ts +2 -0
  209. package/types/langs/fa.d.ts +2 -0
  210. package/types/langs/fi.d.ts +2 -0
  211. package/types/langs/fr.d.ts +2 -0
  212. package/types/langs/he.d.ts +2 -0
  213. package/types/langs/hu.d.ts +2 -0
  214. package/types/langs/id.d.ts +2 -0
  215. package/types/langs/it.d.ts +2 -0
  216. package/types/langs/ja.d.ts +2 -0
  217. package/types/langs/ko.d.ts +2 -0
  218. package/types/langs/mn.d.ts +2 -0
  219. package/types/langs/nl.d.ts +2 -0
  220. package/types/langs/no.d.ts +2 -0
  221. package/types/langs/pl.d.ts +2 -0
  222. package/types/langs/pt_br.d.ts +2 -0
  223. package/types/langs/ru.d.ts +2 -0
  224. package/types/langs/sk.d.ts +2 -0
  225. package/types/langs/sv.d.ts +2 -0
  226. package/types/langs/tr.d.ts +2 -0
  227. package/types/langs/ua.d.ts +2 -0
  228. package/types/langs/zh_cn.d.ts +2 -0
  229. package/types/langs/zh_tw.d.ts +2 -0
  230. package/types/modules/table/table.d.ts +27 -0
  231. package/types/plugins/backspace/helpers.d.ts +5 -0
  232. package/types/plugins/clean-html/helpers/index.d.ts +1 -0
  233. package/types/plugins/clean-html/helpers/remove-format/remove-format-for-word.d.ts +16 -0
  234. package/types/plugins/format-block/config.d.ts +13 -0
  235. package/types/plugins/format-block/content-fonts.d.ts +17 -0
  236. package/types/plugins/image-caption/config.d.ts +31 -0
  237. package/types/plugins/image-caption/image-caption.d.ts +140 -0
  238. package/types/plugins/image-processor/image-processor.d.ts +2 -1
  239. package/types/plugins/image-properties/interface.d.ts +6 -0
  240. package/types/plugins/image-properties/readers/align.d.ts +1 -1
  241. package/types/plugins/image-properties/readers/margin.d.ts +1 -1
  242. package/types/plugins/image-properties/readers/size.d.ts +5 -1
  243. package/types/plugins/image-properties/ui/ui-image-main-tab.d.ts +2 -0
  244. package/types/plugins/image-properties/writers/caption.d.ts +15 -0
  245. package/types/plugins/image-properties/writers/margin.d.ts +1 -1
  246. package/types/plugins/image-properties/writers/size.d.ts +5 -2
  247. package/types/plugins/indent/helpers.d.ts +9 -0
  248. package/types/plugins/index.d.ts +1 -0
  249. package/types/plugins/resize-cells/resize-cells.d.ts +49 -0
  250. package/types/plugins/select-cells/select-cells.d.ts +5 -0
  251. package/types/plugins/tab/cases/index.d.ts +1 -0
  252. package/types/plugins/tab/cases/tab-spaces.d.ts +32 -0
  253. package/types/plugins/tab/config.d.ts +10 -0
  254. package/types/types/types.d.ts +16 -0
  255. package/types/types/uploader.d.ts +6 -0
@@ -7,6 +7,7 @@ import { Dom } from "../../../../core/dom/index.js";
7
7
  import { isString } from "../../../../core/helpers/checker/is-string.js";
8
8
  import { getAlignClasses, getHAlign, hAlignElement } from "../../../../core/helpers/utils/align.js";
9
9
  import { css } from "../../../../core/helpers/utils/css.js";
10
+ import { getCaptionWrapper } from "../../../../core/helpers/utils/image-caption.js";
10
11
  import { getMediaWrapper } from "../../../../core/helpers/utils/media-wrapper.js";
11
12
  // A Normal image sits where the text of its line is aligned (#1531)
12
13
  const lineAlign = (editor, elm) => {
@@ -28,7 +29,12 @@ const lineAlign = (editor, elm) => {
28
29
  return 'left';
29
30
  }
30
31
  };
31
- const currentAlign = (editor, elm) => elm ? getHAlign(elm, getAlignClasses(editor, elm)) : 'normal';
32
+ // A captioned image is aligned by the element holding it and its caption
33
+ const alignedBox = (editor, elm) => { var _a; return (_a = getCaptionWrapper(editor, elm)) !== null && _a !== void 0 ? _a : elm; };
34
+ const currentAlign = (editor, elm) => {
35
+ const box = alignedBox(editor, elm);
36
+ return box ? getHAlign(box, getAlignClasses(editor, box)) : 'normal';
37
+ };
32
38
  export const align = {
33
39
  name: 'left',
34
40
  childTemplate: (_, __, value) => value,
@@ -58,7 +64,8 @@ export const align = {
58
64
  if (!command) {
59
65
  return false;
60
66
  }
61
- hAlignElement(elm, command, getAlignClasses(editor, elm));
67
+ const box = alignedBox(editor, elm);
68
+ hAlignElement(box, command, getAlignClasses(editor, box));
62
69
  if (Dom.isTag(elm, new Set(['jodit', 'jodit-media'])) &&
63
70
  elm.firstElementChild) {
64
71
  const media = elm.firstElementChild;
@@ -75,7 +82,9 @@ export default [
75
82
  icon: 'bin',
76
83
  tooltip: 'Delete',
77
84
  exec: (editor, image) => {
78
- image && editor.s.removeNode(image);
85
+ var _a;
86
+ image &&
87
+ editor.s.removeNode((_a = getCaptionWrapper(editor, image)) !== null && _a !== void 0 ? _a : image);
79
88
  }
80
89
  },
81
90
  {
@@ -88,16 +97,37 @@ export default [
88
97
  },
89
98
  tooltip: 'Edit'
90
99
  },
100
+ {
101
+ name: 'caption',
102
+ exec: (editor, image) => {
103
+ if (!Dom.isTag(image, 'img')) {
104
+ return;
105
+ }
106
+ const caption = editor.e.fire('toggleImageCaption', image);
107
+ editor.synchronizeValues();
108
+ if (Dom.isHTMLElement(caption)) {
109
+ editor.e.fire('hideResizer');
110
+ editor.s.setCursorIn(caption);
111
+ }
112
+ else {
113
+ editor.e.fire('recalcPositionPopup');
114
+ }
115
+ },
116
+ isActive: (editor, button) => Boolean(getCaptionWrapper(editor, button.target)),
117
+ tooltip: 'Caption'
118
+ },
91
119
  {
92
120
  name: 'valign',
93
121
  list: ['Top', 'Middle', 'Bottom', 'Normal'],
94
122
  tooltip: 'Vertical align',
95
- // `vertical-align` only moves an image in the line, not a floated or block one
123
+ // `vertical-align` only moves an image in the line, not a floated or block
124
+ // one, nor a captioned one, which is placed by its caption's element
96
125
  isDisabled: (editor, button) => {
97
126
  const image = button.target;
98
127
  return Boolean(image &&
99
128
  (['left', 'right'].includes(css(image, 'float')) ||
100
- css(image, 'display') === 'block'));
129
+ css(image, 'display') === 'block' ||
130
+ getCaptionWrapper(editor, image)));
101
131
  },
102
132
  exec: (editor, image, { control }) => {
103
133
  if (!Dom.isTag(image, 'img')) {
@@ -0,0 +1 @@
1
+ export default "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"> <g fill=\"none\"> <rect x=\"3\" y=\"3\" width=\"18\" height=\"13\" rx=\"2\"/><path d=\"m3 13 5-4 4 3 3-3 6 5\"/><path d=\"M7 21h10\"/> </g> </svg> ";
@@ -0,0 +1 @@
1
+ export default "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"> <g fill=\"none\"> <rect x=\"3\" y=\"3\" width=\"18\" height=\"18\" rx=\"2.5\"/><path d=\"M3 9V5.5A2.5 2.5 0 0 1 5.5 3h13A2.5 2.5 0 0 1 21 5.5V9z\" fill=\"currentColor\"/><path d=\"M3 15h18M9 9v12M15 9v12\"/> </g> </svg> ";
@@ -16,7 +16,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
16
16
  import { autobind, cache, debounce, wait, watch } from "../../core/decorators/index.js";
17
17
  import { Dom } from "../../core/dom/index.js";
18
18
  import { pluginSystem } from "../../core/global.js";
19
- import { camelCase, getMediaWrapper, getWrappedMedia, isArray, isFunction, isString, keys, position, splitArray, toArray } from "../../core/helpers/index.js";
19
+ import { camelCase, getCaptionWrapper, getMediaWrapper, getWrappedMedia, isArray, isFunction, isString, keys, position, splitArray, toArray } from "../../core/helpers/index.js";
20
20
  import { Plugin } from "../../core/plugin/index.js";
21
21
  import { isMoved } from "../../core/selection/helpers/index.js";
22
22
  import { UIElement } from "../../core/ui/index.js";
@@ -63,8 +63,9 @@ export class inlinePopup extends Plugin {
63
63
  if (target && type && this.canShowPopupForType(type)) {
64
64
  const isMedia = type === 'jodit-media';
65
65
  // Beside the media in a wrapper kept in the content, which can fill
66
- // the line
66
+ // the line, and below a captioned image's caption, so it stays in view
67
67
  const bound = (mediaWrapper && getWrappedMedia(this.j, mediaWrapper)) ||
68
+ getCaptionWrapper(this.j, target) ||
68
69
  target;
69
70
  this.showPopup(() => this.__bound(bound, isMedia), type, target);
70
71
  return false;
@@ -14,7 +14,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
14
14
  return c > 3 && r && Object.defineProperty(target, key, r), r;
15
15
  };
16
16
  import * as consts from "../../core/constants.js";
17
- import { INSEPARABLE_TAGS } from "../../core/constants.js";
17
+ import { INSEPARABLE_TAGS, NBSP_SPACE } from "../../core/constants.js";
18
18
  import { debounce } from "../../core/decorators/index.js";
19
19
  import { Dom } from "../../core/dom/dom.js";
20
20
  import { pluginSystem } from "../../core/global.js";
@@ -28,6 +28,12 @@ import "./config.js";
28
28
  * @private
29
29
  */
30
30
  export function isEditorEmpty(root) {
31
+ var _a;
32
+ // A non-breaking space is typed, where other white space can just lay out
33
+ // the HTML
34
+ return isBlank(root) && !((_a = root.textContent) === null || _a === void 0 ? void 0 : _a.includes(NBSP_SPACE));
35
+ }
36
+ function isBlank(root) {
31
37
  var _a;
32
38
  if (!root.firstChild) {
33
39
  return true;
@@ -37,6 +37,28 @@ export declare class resizeCells extends Plugin {
37
37
  private minX;
38
38
  private maxX;
39
39
  private startX;
40
+ /**
41
+ * The table's and its cells' styles as a column drag started, put back
42
+ * before each new width
43
+ */
44
+ private startStyles;
45
+ private startLeft;
46
+ private startEdge;
47
+ /**
48
+ * The row whose height the handle sets, or null while it sets a width
49
+ */
50
+ private workRow;
51
+ private startY;
52
+ private startHeight;
53
+ private rowStyle;
54
+ /**
55
+ * The boxes that scroll the row, with their styles, as a row drag turns
56
+ * off their scroll anchoring, which would move the border off the pointer
57
+ */
58
+ private anchored;
59
+ private scrolled;
60
+ private scrollFrame;
61
+ private pointerY;
40
62
  /**
41
63
  * Click on resize handle
42
64
  */
@@ -49,6 +71,23 @@ export declare class resizeCells extends Plugin {
49
71
  * Mouse up every where after move and click
50
72
  */
51
73
  private onMouseUp;
74
+ private resizeColumnsOrTable;
75
+ private restoreStyles;
76
+ /**
77
+ * Where the border the handle is on lies: the work cell's left side
78
+ * for the table's left edge, otherwise its right side
79
+ */
80
+ private columnEdge;
81
+ /**
82
+ * Sets the row's height from where the pointer is, and how far the drag
83
+ * has scrolled. The browser keeps the row as tall as its content
84
+ */
85
+ private resizeRow;
86
+ /**
87
+ * While the pointer is near or past the top or bottom of the part of the
88
+ * row's scroller in view, scrolls it on, and the row's border with it
89
+ */
90
+ private scrollAlong;
52
91
  /**
53
92
  * Resize only one column
54
93
  */
@@ -68,6 +107,16 @@ export declare class resizeCells extends Plugin {
68
107
  * Calc helper resize handle position
69
108
  */
70
109
  private calcHandlePosition;
110
+ /**
111
+ * Shows the handle across the table on the border below a row, near the
112
+ * cell's bottom or near its top, which is the bottom of the row above.
113
+ * The table's top edge has no row above it
114
+ */
115
+ private calcRowHandlePosition;
116
+ /**
117
+ * Lays the handle across the table on the border below the row
118
+ */
119
+ private placeRowHandle;
71
120
  /** @override */
72
121
  afterInit(editor: IJodit): void;
73
122
  /**
@@ -17,11 +17,16 @@ import * as consts from "../../core/constants.js";
17
17
  import { autobind } from "../../core/decorators/index.js";
18
18
  import { Dom } from "../../core/dom/dom.js";
19
19
  import { pluginSystem } from "../../core/global.js";
20
- import { $$, call, dataBind, getContentWidth, offset } from "../../core/helpers/index.js";
20
+ import { $$, attr, call, dataBind, getContentWidth, offset } from "../../core/helpers/index.js";
21
21
  import { css } from "../../core/helpers/utils/css.js";
22
22
  import { Plugin, Table } from "../../modules/index.js";
23
23
  import "./config.js";
24
24
  const key = 'table_processor_observer-resize';
25
+ /**
26
+ * How near the top or bottom of what a row scrolls in the pointer starts
27
+ * scrolling it, as the editor's iframe passes on no moves outside it
28
+ */
29
+ const SCROLL_EDGE = 20;
25
30
  /**
26
31
  * Process tables in editor
27
32
  */
@@ -37,6 +42,11 @@ export class resizeCells extends Plugin {
37
42
  .on(this.resizeHandler, 'mousedown.table touchstart.table', this.onHandleMouseDown)
38
43
  .on(this.resizeHandler, 'mouseenter.table', () => {
39
44
  this.j.async.clearTimeout(this.hideTimeout);
45
+ })
46
+ .on(this.resizeHandler, 'mouseleave.table', () => {
47
+ if (!this.drag) {
48
+ this.hideResizeHandle();
49
+ }
40
50
  });
41
51
  }
42
52
  };
@@ -45,6 +55,28 @@ export class resizeCells extends Plugin {
45
55
  this.minX = 0;
46
56
  this.maxX = 0;
47
57
  this.startX = 0;
58
+ /**
59
+ * The table's and its cells' styles as a column drag started, put back
60
+ * before each new width
61
+ */
62
+ this.startStyles = [];
63
+ this.startLeft = 0;
64
+ this.startEdge = 0;
65
+ /**
66
+ * The row whose height the handle sets, or null while it sets a width
67
+ */
68
+ this.workRow = null;
69
+ this.startY = 0;
70
+ this.startHeight = 0;
71
+ this.rowStyle = null;
72
+ /**
73
+ * The boxes that scroll the row, with their styles, as a row drag turns
74
+ * off their scroll anchoring, which would move the border off the pointer
75
+ */
76
+ this.anchored = [];
77
+ this.scrolled = 0;
78
+ this.scrollFrame = 0;
79
+ this.pointerY = 0;
48
80
  }
49
81
  /**
50
82
  * Shortcut for Table module
@@ -64,7 +96,11 @@ export class resizeCells extends Plugin {
64
96
  }
65
97
  hideResizeHandle() {
66
98
  this.hideTimeout = this.j.async.setTimeout(() => {
67
- Dom.safeRemove(this.resizeHandler);
99
+ // A late move from inside the cell can come once the pointer
100
+ // is on the handle, which covers the border
101
+ if (!this.resizeHandler.matches(':hover')) {
102
+ Dom.safeRemove(this.resizeHandler);
103
+ }
68
104
  }, {
69
105
  timeout: this.j.defaultTimeout,
70
106
  label: 'hideResizer'
@@ -84,6 +120,21 @@ export class resizeCells extends Plugin {
84
120
  this.startX = event.clientX;
85
121
  this.j.lock(key);
86
122
  this.resizeHandler.classList.add('jodit-table-resizer_moved');
123
+ if (this.workRow) {
124
+ this.startY = event.clientY;
125
+ this.startHeight = this.workRow.offsetHeight;
126
+ this.rowStyle = attr(this.workRow, 'style');
127
+ this.scrolled = 0;
128
+ this.anchored = scrollersOf(this.workRow).map(elm => {
129
+ const style = attr(elm, 'style');
130
+ css(elm, 'overflowAnchor', 'none');
131
+ return [elm, style];
132
+ });
133
+ return false;
134
+ }
135
+ this.startStyles = [this.workTable, ...$$('td,th', this.workTable)].map(elm => [elm, attr(elm, 'style')]);
136
+ this.startLeft = parseFloat(this.resizeHandler.style.left);
137
+ this.startEdge = this.columnEdge();
87
138
  let box;
88
139
  this.minX = 0;
89
140
  this.maxX = 1000000;
@@ -112,6 +163,7 @@ export class resizeCells extends Plugin {
112
163
  * Mouse move after click on resize handle
113
164
  */
114
165
  onMouseMove(event) {
166
+ var _a;
115
167
  if (!this.drag) {
116
168
  return;
117
169
  }
@@ -119,6 +171,16 @@ export class resizeCells extends Plugin {
119
171
  let x = event.clientX;
120
172
  const workplacePosition = offset((this.resizeHandler.parentNode ||
121
173
  this.j.od.documentElement), this.j, this.j.od, true);
174
+ if (this.workRow) {
175
+ const view = scrollViewOf(this.workRow);
176
+ this.pointerY =
177
+ Math.min(Math.max(event.clientY, view.top), view.bottom) +
178
+ (!this.j.o.iframe ? 0 : workplacePosition.top);
179
+ this.resizeRow(this.workRow);
180
+ this.scrollAlong(view, event.clientY);
181
+ (_a = this.j.s.sel) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
182
+ return;
183
+ }
122
184
  if (x < this.minX) {
123
185
  x = this.minX;
124
186
  }
@@ -127,7 +189,14 @@ export class resizeCells extends Plugin {
127
189
  }
128
190
  this.resizeDelta =
129
191
  x - this.startX + (!this.j.o.iframe ? 0 : workplacePosition.left);
130
- css(this.resizeHandler, 'left', x - (this.j.o.iframe ? 0 : workplacePosition.left) + 'px');
192
+ this.restoreStyles();
193
+ this.resizeColumnsOrTable();
194
+ const tableBox = offset(this.workTable, this.j, this.j.ed);
195
+ Object.assign(this.resizeHandler.style, {
196
+ left: this.startLeft + this.columnEdge() - this.startEdge + 'px',
197
+ top: tableBox.top - workplacePosition.top + 'px',
198
+ height: tableBox.height + 'px'
199
+ });
131
200
  const sel = this.j.s.sel;
132
201
  sel && sel.removeAllRanges();
133
202
  }
@@ -145,18 +214,107 @@ export class resizeCells extends Plugin {
145
214
  this.drag = false;
146
215
  this.j.e.off(this.j.ew, 'mousemove.table touchmove.table', this.onMouseMove);
147
216
  this.resizeHandler.classList.remove('jodit-table-resizer_moved');
148
- if (this.startX !== e.clientX) {
149
- // resize column
150
- if (this.wholeTable == null) {
151
- this.resizeColumns();
217
+ if (this.workRow) {
218
+ this.j.async.cancelAnimationFrame(this.scrollFrame);
219
+ this.anchored.forEach(([elm, style]) => attr(elm, 'style', style));
220
+ this.anchored = [];
221
+ const height = this.workRow.offsetHeight;
222
+ if (height !== this.startHeight) {
223
+ css(this.workRow, 'height', height + 'px');
152
224
  }
153
225
  else {
154
- this.resizeTable();
226
+ attr(this.workRow, 'style', this.rowStyle);
227
+ }
228
+ }
229
+ else {
230
+ this.restoreStyles();
231
+ if (this.startX !== e.clientX) {
232
+ this.resizeColumnsOrTable();
155
233
  }
156
234
  }
157
235
  this.j.synchronizeValues();
158
236
  this.j.s.focus();
159
237
  }
238
+ resizeColumnsOrTable() {
239
+ if (this.wholeTable == null) {
240
+ this.resizeColumns();
241
+ }
242
+ else {
243
+ this.resizeTable();
244
+ }
245
+ }
246
+ restoreStyles() {
247
+ this.startStyles.forEach(([elm, style]) => attr(elm, 'style', style));
248
+ }
249
+ /**
250
+ * Where the border the handle is on lies: the work cell's left side
251
+ * for the table's left edge, otherwise its right side
252
+ */
253
+ columnEdge() {
254
+ const { left, right } = this.workCell.getBoundingClientRect();
255
+ return this.wholeTable === true ? left : right;
256
+ }
257
+ /**
258
+ * Sets the row's height from where the pointer is, and how far the drag
259
+ * has scrolled. The browser keeps the row as tall as its content
260
+ */
261
+ resizeRow(row) {
262
+ const height = Math.max(0, Math.round(this.startHeight + this.pointerY - this.startY + this.scrolled));
263
+ css(row, 'height', height + 'px');
264
+ this.placeRowHandle(row);
265
+ return row.offsetHeight === height;
266
+ }
267
+ /**
268
+ * While the pointer is near or past the top or bottom of the part of the
269
+ * row's scroller in view, scrolls it on, and the row's border with it
270
+ */
271
+ scrollAlong(view, clientY) {
272
+ this.j.async.cancelAnimationFrame(this.scrollFrame);
273
+ const past = clientY < view.top + SCROLL_EDGE
274
+ ? clientY - view.top - SCROLL_EDGE
275
+ : clientY > view.bottom - SCROLL_EDGE
276
+ ? clientY - view.bottom + SCROLL_EDGE
277
+ : 0;
278
+ if (!past) {
279
+ return;
280
+ }
281
+ const { scroller } = view;
282
+ const step = Math.sign(past) * Math.min(Math.ceil(Math.abs(past) / 2), 20);
283
+ const scroll = () => {
284
+ const { workRow } = this;
285
+ if (!workRow) {
286
+ return;
287
+ }
288
+ const scrollTop = scroller.scrollTop;
289
+ if (step > 0) {
290
+ // Growing the row first makes the room to scroll down into
291
+ this.scrolled += step;
292
+ this.resizeRow(workRow);
293
+ scroller.scrollTop = scrollTop + step;
294
+ const missed = step - (scroller.scrollTop - scrollTop);
295
+ if (missed > 0.5) {
296
+ this.scrolled -= missed;
297
+ this.resizeRow(workRow);
298
+ return;
299
+ }
300
+ this.placeRowHandle(workRow);
301
+ }
302
+ else {
303
+ scroller.scrollTop = scrollTop + step;
304
+ const moved = scroller.scrollTop - scrollTop;
305
+ this.scrolled += moved;
306
+ // A row at its content's height can't follow the pointer up
307
+ if (!moved || !this.resizeRow(workRow)) {
308
+ scroller.scrollTop = scrollTop;
309
+ this.scrolled -= moved;
310
+ this.resizeRow(workRow);
311
+ return;
312
+ }
313
+ }
314
+ this.scrollFrame = this.j.async.requestAnimationFrame(scroll);
315
+ };
316
+ this.scrollFrame = this.j.async.requestAnimationFrame(scroll);
317
+ }
160
318
  /**
161
319
  * Resize only one column
162
320
  */
@@ -204,18 +362,23 @@ export class resizeCells extends Plugin {
204
362
  /**
205
363
  * Calc helper resize handle position
206
364
  */
207
- calcHandlePosition(table, cell, offsetX = 0, delta = 0) {
365
+ calcHandlePosition(table, cell, offsetX = 0, delta = 0, clientY = NaN) {
208
366
  const box = offset(cell, this.j, this.j.ed);
209
367
  if (offsetX > consts.NEARBY && offsetX < box.width - consts.NEARBY) {
210
- this.hideResizeHandle();
368
+ if (!this.calcRowHandlePosition(cell, clientY)) {
369
+ this.hideResizeHandle();
370
+ }
211
371
  return;
212
372
  }
373
+ this.workRow = null;
374
+ this.resizeHandler.classList.remove('jodit-table-resizer_row');
213
375
  const workplacePosition = offset(this.j.workplace, this.j, this.j.od, true), parentBox = offset(table, this.j, this.j.ed);
214
376
  css(this.resizeHandler, 'left', (offsetX <= consts.NEARBY ? box.left : box.left + box.width) -
215
377
  workplacePosition.left +
216
378
  delta +
217
379
  'px');
218
380
  Object.assign(this.resizeHandler.style, {
381
+ width: '',
219
382
  height: parentBox.height + 'px',
220
383
  top: parentBox.top - workplacePosition.top + 'px'
221
384
  });
@@ -229,6 +392,42 @@ export class resizeCells extends Plugin {
229
392
  this.setWorkCell(cell, !nextTD ? false : null);
230
393
  }
231
394
  }
395
+ /**
396
+ * Shows the handle across the table on the border below a row, near the
397
+ * cell's bottom or near its top, which is the bottom of the row above.
398
+ * The table's top edge has no row above it
399
+ */
400
+ calcRowHandlePosition(cell, clientY) {
401
+ const { top, bottom } = cell.getBoundingClientRect();
402
+ const table = Dom.up(cell, (elm) => Dom.isTag(elm, 'table'), this.j.editor);
403
+ const index = cell.parentNode.rowIndex;
404
+ const row = Math.abs(bottom - clientY) <= consts.NEARBY
405
+ ? table.rows[index + cell.rowSpan - 1]
406
+ : Math.abs(clientY - top) <= consts.NEARBY
407
+ ? table.rows[index - 1]
408
+ : null;
409
+ if (!row) {
410
+ return false;
411
+ }
412
+ this.workRow = row;
413
+ this.workTable = table;
414
+ this.resizeHandler.classList.add('jodit-table-resizer_row');
415
+ this.placeRowHandle(row);
416
+ this.showResizeHandle();
417
+ return true;
418
+ }
419
+ /**
420
+ * Lays the handle across the table on the border below the row
421
+ */
422
+ placeRowHandle(row) {
423
+ const workplacePosition = offset(this.j.workplace, this.j, this.j.od, true), tableBox = offset(this.workTable, this.j, this.j.ed), rowBox = offset(row, this.j, this.j.ed);
424
+ Object.assign(this.resizeHandler.style, {
425
+ left: tableBox.left - workplacePosition.left + 'px',
426
+ width: tableBox.width + 'px',
427
+ height: '',
428
+ top: rowBox.top + rowBox.height - workplacePosition.top + 'px'
429
+ });
430
+ }
232
431
  /** @override */
233
432
  afterInit(editor) {
234
433
  if (!editor.o.tableAllowCellResize) {
@@ -241,7 +440,7 @@ export class resizeCells extends Plugin {
241
440
  $$('table', editor.editor).forEach(this.observe);
242
441
  })
243
442
  .on(this.j.ow, 'scroll.resize-cells', () => {
244
- if (!this.drag) {
443
+ if (!this.drag || this.workRow) {
245
444
  return;
246
445
  }
247
446
  const parent = Dom.up(this.workCell, (elm) => Dom.isTag(elm, 'table'), editor.editor);
@@ -268,7 +467,8 @@ export class resizeCells extends Plugin {
268
467
  dataBind(table, key, true);
269
468
  this.j.e
270
469
  .on(table, 'mouseleave.resize-cells', (e) => {
271
- if (this.resizeHandler &&
470
+ if (!this.drag &&
471
+ this.resizeHandler &&
272
472
  this.resizeHandler !== e.relatedTarget) {
273
473
  this.hideResizeHandle();
274
474
  }
@@ -281,7 +481,7 @@ export class resizeCells extends Plugin {
281
481
  if (!cell) {
282
482
  return;
283
483
  }
284
- this.calcHandlePosition(table, cell, event.offsetX);
484
+ this.calcHandlePosition(table, cell, event.offsetX, 0, event.clientY);
285
485
  }, {
286
486
  timeout: this.j.defaultTimeout
287
487
  }));
@@ -306,4 +506,38 @@ __decorate([
306
506
  __decorate([
307
507
  autobind
308
508
  ], resizeCells.prototype, "observe", null);
509
+ /**
510
+ * The boxes around the row that can scroll it, nearest first, and its
511
+ * document's
512
+ */
513
+ function scrollersOf(row) {
514
+ const doc = row.ownerDocument;
515
+ const root = (doc.scrollingElement || doc.documentElement);
516
+ const scrollers = [];
517
+ for (let elm = row.parentElement; elm && elm !== root; elm = elm.parentElement) {
518
+ if (/auto|scroll|overlay/.test(String(css(elm, 'overflowY')))) {
519
+ scrollers.push(elm);
520
+ }
521
+ }
522
+ return [...scrollers, root];
523
+ }
524
+ /**
525
+ * What scrolls the row up and down, the nearest box around it with more
526
+ * than it shows or else its document, and the part of it in the window's view
527
+ */
528
+ function scrollViewOf(row) {
529
+ var _a, _b, _c;
530
+ const height = (_b = (_a = row.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.innerHeight) !== null && _b !== void 0 ? _b : 0;
531
+ const scrollers = scrollersOf(row);
532
+ const scroller = (_c = scrollers.find(elm => elm.scrollHeight > elm.clientHeight)) !== null && _c !== void 0 ? _c : scrollers[scrollers.length - 1];
533
+ if (scroller === scrollers[scrollers.length - 1]) {
534
+ return { scroller, top: 0, bottom: height };
535
+ }
536
+ const top = scroller.getBoundingClientRect().top + scroller.clientTop;
537
+ return {
538
+ scroller,
539
+ top: Math.max(top, 0),
540
+ bottom: Math.min(top + scroller.clientHeight, height)
541
+ };
542
+ }
309
543
  pluginSystem.add('resizeCells', resizeCells);
@@ -18,7 +18,7 @@ import { IS_ES_NEXT, IS_IE, KEY_ALT } from "../../core/constants.js";
18
18
  import { autobind, watch } from "../../core/decorators/index.js";
19
19
  import { Dom } from "../../core/dom/dom.js";
20
20
  import { eventEmitter, getContainer, pluginSystem } from "../../core/global.js";
21
- import { $$, attr, css, dataBind, getWrappedMedia, innerWidth, markOwner, offset } from "../../core/helpers/index.js";
21
+ import { $$, attr, css, dataBind, getCaptionWrapper, getWrappedMedia, innerWidth, markOwner, offset } from "../../core/helpers/index.js";
22
22
  import { cssInline } from "../../core/helpers/utils/css.js";
23
23
  import { Plugin } from "../../core/plugin/plugin.js";
24
24
  import { isMoved } from "../../core/selection/helpers/index.js";
@@ -403,6 +403,16 @@ export class resizer extends Plugin {
403
403
  return offset((this.rect.parentNode || this.j.od.documentElement), this.j, this.j.od, true);
404
404
  }
405
405
  applySize(element, key, value) {
406
+ // A captioned image fills the element holding it and its caption,
407
+ // which takes the width
408
+ const wrapper = key === 'width' && Dom.isTag(element, 'img')
409
+ ? getCaptionWrapper(this.j, element)
410
+ : null;
411
+ if (wrapper) {
412
+ css(wrapper, 'width', value);
413
+ css(element, 'width', '100%');
414
+ return;
415
+ }
406
416
  const changeAttrs = Dom.isImage(element) && this.j.o.resizer.forImageChangeAttributes;
407
417
  if (changeAttrs) {
408
418
  attr(element, key, value);
@@ -418,6 +428,7 @@ export class resizer extends Plugin {
418
428
  return Boolean(this.element && this.j.editor.contains(this.element));
419
429
  }
420
430
  onDelete(e) {
431
+ var _a;
421
432
  if (!this.element) {
422
433
  return;
423
434
  }
@@ -426,7 +437,7 @@ export class resizer extends Plugin {
426
437
  return;
427
438
  }
428
439
  if (this.element.tagName !== 'JODIT') {
429
- this.j.s.select(this.element);
440
+ this.j.s.select((_a = getCaptionWrapper(this.j, this.element)) !== null && _a !== void 0 ? _a : this.element);
430
441
  }
431
442
  else {
432
443
  Dom.safeRemove(this.element);
@@ -75,6 +75,11 @@ export declare class selectCells extends Plugin {
75
75
  * Execute custom commands for table
76
76
  */
77
77
  private onExecCommand;
78
+ /**
79
+ * Turns the table's header row on or off. The caret and the marked cells
80
+ * move to the cells that replace them
81
+ */
82
+ private __toggleHeaderRow;
78
83
  /**
79
84
  * The cell that takes the caret when rows or columns are deleted: the next
80
85
  * one in the same column (or row) that is not deleted, else the previous one