jodit 3.8.7 → 3.9.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 (180) hide show
  1. package/.github/workflows/tests.yml +23 -0
  2. package/.idea/dictionaries/v_chupurnov.xml +1 -0
  3. package/.idea/workspace.xml +340 -298
  4. package/CHANGELOG.MD +132 -24
  5. package/README.md +3 -4
  6. package/build/jodit.css +92 -34
  7. package/build/jodit.es2018.css +65 -30
  8. package/build/jodit.es2018.en.css +65 -30
  9. package/build/jodit.es2018.en.js +1214 -693
  10. package/build/jodit.es2018.en.min.css +1 -1
  11. package/build/jodit.es2018.en.min.js +1 -1
  12. package/build/jodit.es2018.js +1214 -693
  13. package/build/jodit.es2018.min.css +1 -1
  14. package/build/jodit.es2018.min.js +1 -1
  15. package/build/jodit.js +2271 -1628
  16. package/build/jodit.min.css +2 -2
  17. package/build/jodit.min.js +1 -1
  18. package/index.d.ts +10 -0
  19. package/package.json +14 -13
  20. package/src/config.ts +1 -1
  21. package/src/core/async.ts +7 -5
  22. package/src/core/constants.ts +2 -0
  23. package/src/core/dom.ts +123 -102
  24. package/src/core/events/{events-native.ts → event-emitter.ts} +14 -9
  25. package/src/core/events/index.ts +1 -1
  26. package/src/core/global.ts +2 -2
  27. package/src/core/helpers/array/to-array.ts +1 -0
  28. package/src/core/helpers/data-bind.ts +2 -2
  29. package/src/core/helpers/size/index.ts +1 -0
  30. package/src/core/helpers/size/object-size.ts +22 -0
  31. package/src/core/helpers/utils/utils.ts +20 -4
  32. package/src/core/request/ajax.ts +212 -0
  33. package/src/core/request/config.ts +37 -0
  34. package/{build-system/minimizer/index.js → src/core/request/index.ts} +2 -1
  35. package/src/core/request/response.ts +39 -0
  36. package/src/core/selection/select.ts +60 -27
  37. package/src/core/selection/style/api/element-has-same-style.ts +13 -0
  38. package/src/core/selection/style/api/{get-closest-wrapper.ts → extract.ts} +26 -43
  39. package/src/core/selection/style/api/finite-state-machine.ts +66 -0
  40. package/src/core/selection/style/api/get-suit-parent.ts +1 -1
  41. package/src/core/selection/style/api/index.ts +12 -5
  42. package/src/core/selection/style/api/{check-special-elements.ts → is-inside-invisible-element.ts} +1 -1
  43. package/src/core/selection/style/api/is-suit-element.ts +36 -5
  44. package/src/core/selection/style/api/toggle/toggle-css.ts +134 -0
  45. package/src/core/selection/style/api/toggle/toggle-ordered-list.ts +49 -0
  46. package/src/core/selection/style/api/toggle-commit-styles.ts +27 -0
  47. package/src/core/selection/style/api/unwrap-children.ts +45 -16
  48. package/src/core/selection/style/api/wrap-and-commit-style.ts +68 -0
  49. package/src/core/selection/style/api/wrap-ordered-list.ts +37 -0
  50. package/src/core/selection/style/api/wrap-unwrapped-text.ts +29 -27
  51. package/src/core/selection/style/apply-style.ts +161 -91
  52. package/src/core/selection/style/commit-style.ts +13 -0
  53. package/src/core/traits/elms.ts +1 -0
  54. package/src/core/ui/button/button/button.less +2 -0
  55. package/src/core/ui/helpers/buttons.ts +14 -6
  56. package/src/core/ui/helpers/get-control-type.ts +3 -1
  57. package/src/core/ui/list/list.less +1 -0
  58. package/src/core/ui/popup/popup.less +5 -3
  59. package/src/core/view/view-with-toolbar.ts +4 -0
  60. package/src/core/view/view.ts +3 -3
  61. package/src/modules/context-menu/context-menu.ts +1 -1
  62. package/src/modules/file-browser/README.MD +1 -1
  63. package/src/modules/file-browser/data-provider.ts +22 -42
  64. package/src/modules/file-browser/file-browser.ts +3 -0
  65. package/src/modules/index.ts +1 -1
  66. package/src/modules/status-bar/status-bar.less +27 -1
  67. package/src/modules/status-bar/status-bar.ts +15 -1
  68. package/src/modules/table.ts +197 -168
  69. package/src/modules/uploader/uploader.ts +4 -3
  70. package/src/modules/widget/tabs/tabs.less +1 -0
  71. package/src/plugins/bold.ts +2 -2
  72. package/src/plugins/fix/clean-html.ts +37 -16
  73. package/src/plugins/font.ts +11 -1
  74. package/src/plugins/indent.ts +25 -18
  75. package/src/plugins/index.ts +1 -0
  76. package/src/plugins/mobile.ts +10 -14
  77. package/src/plugins/ordered-list.ts +40 -1
  78. package/src/plugins/powered-by-jodit.ts +39 -0
  79. package/src/plugins/print/preview.ts +9 -2
  80. package/src/plugins/resizer/resizer.less +10 -7
  81. package/src/plugins/resizer/resizer.ts +12 -14
  82. package/src/plugins/size/assests/resize-handler.svg +4 -0
  83. package/src/plugins/size/resize-handler.ts +5 -5
  84. package/src/plugins/size/size.less +6 -8
  85. package/src/plugins/size/size.ts +1 -3
  86. package/src/plugins/source/source.ts +16 -2
  87. package/src/plugins/table/config.ts +3 -1
  88. package/src/plugins/table/select-cells.ts +23 -5
  89. package/src/plugins/table/table.less +0 -1
  90. package/src/styles/themes/dark.less +11 -1
  91. package/src/types/ajax.d.ts +15 -6
  92. package/src/types/async.d.ts +5 -4
  93. package/src/types/events.d.ts +12 -12
  94. package/src/types/style.d.ts +2 -0
  95. package/src/types/toolbar.d.ts +2 -1
  96. package/src/types/view.d.ts +3 -2
  97. package/types/core/async.d.ts +3 -3
  98. package/types/core/constants.d.ts +1 -0
  99. package/types/core/dom.d.ts +27 -20
  100. package/types/core/events/{events-native.d.ts → event-emitter.d.ts} +8 -3
  101. package/types/core/events/index.d.ts +1 -1
  102. package/types/core/global.d.ts +2 -2
  103. package/types/core/helpers/size/index.d.ts +1 -0
  104. package/{src/types/core.js → types/core/helpers/size/object-size.d.ts} +2 -3
  105. package/types/core/helpers/utils/utils.d.ts +12 -4
  106. package/types/core/{ajax.d.ts → request/ajax.d.ts} +5 -15
  107. package/types/core/request/config.d.ts +14 -0
  108. package/{build-system/rules/css.js → types/core/request/index.d.ts} +2 -7
  109. package/types/core/request/response.d.ts +16 -0
  110. package/types/core/selection/style/api/element-has-same-style.d.ts +4 -0
  111. package/types/core/selection/style/api/{get-closest-wrapper.d.ts → extract.d.ts} +6 -5
  112. package/types/core/selection/style/api/finite-state-machine.d.ts +21 -0
  113. package/types/core/selection/style/api/index.d.ts +12 -5
  114. package/types/core/selection/style/api/{check-special-elements.d.ts → is-inside-invisible-element.d.ts} +1 -1
  115. package/types/core/selection/style/api/is-suit-element.d.ts +10 -0
  116. package/types/core/selection/style/api/toggle/toggle-css.d.ts +11 -0
  117. package/types/core/selection/style/api/toggle/toggle-ordered-list.d.ts +11 -0
  118. package/types/core/selection/style/api/{toggle-styles.d.ts → toggle-commit-styles.d.ts} +1 -3
  119. package/types/core/selection/style/api/{post-process-list-element.d.ts → wrap-and-commit-style.d.ts} +3 -3
  120. package/types/core/selection/style/api/wrap-ordered-list.d.ts +12 -0
  121. package/types/core/selection/style/api/wrap-unwrapped-text.d.ts +2 -2
  122. package/types/core/selection/style/apply-style.d.ts +1 -4
  123. package/types/core/selection/style/commit-style.d.ts +7 -0
  124. package/types/core/ui/helpers/buttons.d.ts +2 -2
  125. package/types/core/view/view-with-toolbar.d.ts +2 -1
  126. package/types/core/view/view.d.ts +2 -2
  127. package/types/modules/file-browser/data-provider.d.ts +1 -1
  128. package/types/modules/index.d.ts +1 -1
  129. package/types/modules/status-bar/status-bar.d.ts +6 -1
  130. package/types/modules/table.d.ts +2 -2
  131. package/types/plugins/fix/clean-html.d.ts +4 -0
  132. package/types/plugins/index.d.ts +1 -0
  133. package/types/plugins/ordered-list.d.ts +8 -1
  134. package/{build-system/plugins/banner.js → types/plugins/powered-by-jodit.d.ts} +7 -10
  135. package/types/plugins/size/resize-handler.d.ts +1 -1
  136. package/types/plugins/source/source.d.ts +1 -1
  137. package/types/types/ajax.d.ts +15 -6
  138. package/types/types/async.d.ts +5 -4
  139. package/types/types/events.d.ts +12 -12
  140. package/types/types/style.d.ts +2 -0
  141. package/types/types/toolbar.d.ts +2 -1
  142. package/types/types/view.d.ts +3 -2
  143. package/.editorconfig +0 -15
  144. package/.eslintignore +0 -3
  145. package/.eslintrc.js +0 -109
  146. package/.prettierrc.json +0 -9
  147. package/.stylelintrc.json +0 -16
  148. package/app.css +0 -112
  149. package/build-system/index.js +0 -78
  150. package/build-system/loaders/css-variables-prefixes.js +0 -12
  151. package/build-system/loaders/lang-loader.js +0 -57
  152. package/build-system/loaders/style.js +0 -31
  153. package/build-system/loaders/svg-loader.js +0 -21
  154. package/build-system/minimizer/css.js +0 -20
  155. package/build-system/minimizer/js.js +0 -41
  156. package/build-system/plugins/define.js +0 -22
  157. package/build-system/plugins/extract-css.js +0 -21
  158. package/build-system/plugins/index.js +0 -31
  159. package/build-system/plugins/post-build.js +0 -52
  160. package/build-system/rules/extra-typescript.js +0 -22
  161. package/build-system/rules/index.js +0 -17
  162. package/build-system/rules/internal-typescript.js +0 -23
  163. package/build-system/rules/langs.js +0 -20
  164. package/build-system/rules/svg.js +0 -16
  165. package/build-system/utils/filename.js +0 -14
  166. package/build-system/utils/post-build.js +0 -28
  167. package/build-system/variables.js +0 -51
  168. package/composer.json +0 -12
  169. package/src/core/ajax.ts +0 -269
  170. package/src/core/selection/style/api/post-process-list-element.ts +0 -33
  171. package/src/core/selection/style/api/toggle-styles.ts +0 -74
  172. package/src/types/core.d.ts +0 -7
  173. package/src/types/core.js.map +0 -1
  174. package/src/types/storage.d.ts +0 -13
  175. package/src/types/storage.js +0 -8
  176. package/src/types/storage.js.map +0 -1
  177. package/types/types/core.js +0 -8
  178. package/types/types/core.js.map +0 -1
  179. package/types/types/storage.js +0 -8
  180. package/types/types/storage.js.map +0 -1
@@ -0,0 +1,134 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+
7
+ import type { CommitMode, IJodit } from '../../../../../types';
8
+ import type { CommitStyle } from '../../commit-style';
9
+ import {
10
+ attr,
11
+ css,
12
+ dataBind,
13
+ kebabCase,
14
+ normalizeCssValue,
15
+ size
16
+ } from '../../../../helpers';
17
+ import { Dom } from '../../../../dom';
18
+ import { CHANGE, UNSET, UNWRAP } from '../../commit-style';
19
+ import { getContainer } from '../../../../global';
20
+
21
+ /**
22
+ * Toggles css and classname
23
+ */
24
+ export function toggleCSS(
25
+ commitStyle: CommitStyle,
26
+ elm: HTMLElement,
27
+ jodit: IJodit,
28
+ mode: CommitMode,
29
+ dry: boolean = false
30
+ ): CommitMode {
31
+ const { style, className } = commitStyle.options;
32
+
33
+ if (style && size(style) > 0) {
34
+ Object.keys(style).forEach((rule: string) => {
35
+ const inlineValue = elm.style.getPropertyValue(kebabCase(rule));
36
+
37
+ if (inlineValue === '' && style[rule] == null) {
38
+ return;
39
+ }
40
+
41
+ if (
42
+ getNativeCSSValue(jodit, elm, rule) ===
43
+ normalizeCssValue(rule, style[rule] as string)
44
+ ) {
45
+ !dry && css(elm, rule, null);
46
+ mode = UNSET;
47
+ mode = removeExtraCSS(commitStyle, elm, mode);
48
+ return;
49
+ }
50
+
51
+ mode = CHANGE;
52
+ !dry && css(elm, rule, style[rule]);
53
+ });
54
+ }
55
+
56
+ if (className) {
57
+ if (elm.classList.contains(className)) {
58
+ elm.classList.remove(className);
59
+ mode = UNSET;
60
+ } else {
61
+ elm.classList.add(className);
62
+ mode = CHANGE;
63
+ }
64
+ }
65
+
66
+ return mode;
67
+ }
68
+
69
+ /**
70
+ * If the element has an empty style attribute, it removes the attribute,
71
+ * and if it is default, it removes the element itself
72
+ */
73
+ function removeExtraCSS(
74
+ commitStyle: CommitStyle,
75
+ elm: HTMLElement,
76
+ mode: CommitMode
77
+ ): CommitMode {
78
+ if (!attr(elm, 'style')) {
79
+ attr(elm, 'style', null);
80
+
81
+ if (elm.tagName.toLowerCase() === commitStyle.defaultTag) {
82
+ Dom.unwrap(elm);
83
+ mode = UNWRAP;
84
+ }
85
+ }
86
+
87
+ return mode;
88
+ }
89
+
90
+ /**
91
+ * Creates an iframe into which elements will be inserted to test their default styles in the browser
92
+ */
93
+ function getShadowRoot(jodit: IJodit): HTMLElement {
94
+ if (dataBind(jodit, 'shadowRoot') !== undefined) {
95
+ return dataBind(jodit, 'shadowRoot');
96
+ }
97
+
98
+ const container = getContainer(jodit, function Utils() {});
99
+
100
+ const iframe = document.createElement('iframe');
101
+ css(iframe, {
102
+ width: 0,
103
+ height: 0,
104
+ position: 'absolute',
105
+ border: 0
106
+ });
107
+
108
+ iframe.src = 'about:blank';
109
+ container.appendChild(iframe);
110
+
111
+ const doc = iframe.contentWindow?.document;
112
+
113
+ const shadowRoot = !doc ? jodit.od.body : doc.body;
114
+ dataBind(jodit, 'shadowRoot', shadowRoot);
115
+
116
+ return shadowRoot;
117
+ }
118
+
119
+ /**
120
+ * `strong -> fontWeight 700`
121
+ */
122
+ function getNativeCSSValue(
123
+ jodit: IJodit,
124
+ elm: HTMLElement,
125
+ key: string
126
+ ): ReturnType<typeof css> {
127
+ const newElm = jodit.create.element(elm.tagName.toLowerCase());
128
+ newElm.style.cssText = elm.style.cssText;
129
+ const root = getShadowRoot(jodit);
130
+ root.appendChild(newElm);
131
+ const result = css(newElm, key);
132
+ Dom.safeRemove(newElm);
133
+ return result;
134
+ }
@@ -0,0 +1,49 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+
7
+ import type { IJodit, CommitMode } from '../../../../../types';
8
+ import type { CommitStyle } from '../../commit-style';
9
+ import { Dom } from '../../../../dom';
10
+ import { extractSelectedPart } from '../extract';
11
+ import { CHANGE, INITIAL, REPLACE } from '../../commit-style';
12
+ import { toggleCSS } from './toggle-css';
13
+
14
+ /**
15
+ * Replaces `ul->ol` or `ol->ul`, apply styles to the list, or remove a list item from it
16
+ */
17
+ export function toggleOrderedList(
18
+ style: CommitStyle,
19
+ li: HTMLElement,
20
+ jodit: IJodit,
21
+ mode: CommitMode
22
+ ): CommitMode {
23
+ if (!li) {
24
+ return mode;
25
+ }
26
+
27
+ const list = li.parentElement;
28
+
29
+ if (!list) {
30
+ return mode;
31
+ }
32
+
33
+ // ul => ol, ol => ul
34
+ if (list.tagName.toLowerCase() !== style.element) {
35
+ const newList = Dom.replace(list, style.element, jodit.createInside);
36
+ toggleCSS(style, newList, jodit, mode);
37
+ return REPLACE;
38
+ }
39
+
40
+ if (toggleCSS(style, li.parentElement, jodit, INITIAL, true) === CHANGE) {
41
+ return toggleCSS(style, li.parentElement, jodit, mode);
42
+ }
43
+
44
+ extractSelectedPart(list, li, jodit);
45
+ Dom.unwrap(li.parentElement);
46
+ Dom.replace(li, jodit.o.enter, jodit.createInside);
47
+
48
+ return mode;
49
+ }
@@ -0,0 +1,27 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+
7
+ import type { CommitStyle } from '../commit-style';
8
+ import { Dom } from '../../../dom';
9
+
10
+ /**
11
+ * Add or remove styles to element
12
+ * @param elm - The element to switch styles
13
+ */
14
+ export function toggleCommitStyles(
15
+ commitStyle: CommitStyle,
16
+ elm: HTMLElement
17
+ ): boolean {
18
+ if (
19
+ commitStyle.elementIsBlock ||
20
+ (Dom.isTag(elm, commitStyle.element) && !commitStyle.elementIsDefault)
21
+ ) {
22
+ Dom.unwrap(elm);
23
+ return true;
24
+ }
25
+
26
+ return false;
27
+ }
@@ -6,39 +6,68 @@
6
6
 
7
7
  import type { CommitStyle } from '../commit-style';
8
8
  import { Dom } from '../../../dom';
9
- import { isSuitElement } from './is-suit-element';
9
+ import { isSameStyleChild, isSuitElement } from './is-suit-element';
10
+ import { attr, css } from '../../../helpers';
11
+ import type { IDictionary } from '../../../../types';
10
12
 
11
13
  /**
12
14
  * Unwrap all suit elements inside
13
15
  */
14
16
  export function unwrapChildren(style: CommitStyle, font: HTMLElement): boolean {
15
17
  const needUnwrap: Node[] = [];
18
+ const needChangeStyle: any[] = [];
16
19
 
17
20
  let firstElementSuit: boolean | undefined;
18
21
 
22
+ const cssStyle = style.options.style;
23
+
19
24
  if (font.firstChild) {
20
- Dom.find(
21
- font.firstChild,
22
- (elm: Node | null) => {
23
- if (elm && isSuitElement(style, elm as HTMLElement, true)) {
24
- if (firstElementSuit === undefined) {
25
- firstElementSuit = true;
25
+ const gen = Dom.eachGen(font);
26
+
27
+ let item = gen.next();
28
+
29
+ while (!item.done) {
30
+ const elm = item.value;
31
+
32
+ if (isSuitElement(style, elm as HTMLElement, true)) {
33
+ if (firstElementSuit === undefined) {
34
+ firstElementSuit = true;
35
+ }
36
+
37
+ needUnwrap.push(elm);
38
+ } else if (cssStyle && isSameStyleChild(style, elm)) {
39
+ if (firstElementSuit === undefined) {
40
+ firstElementSuit = false;
41
+ }
42
+
43
+ needChangeStyle.push(() => {
44
+ css(
45
+ elm,
46
+ Object.keys(cssStyle).reduce((acc, key) => {
47
+ acc[key] = null;
48
+ return acc;
49
+ }, <IDictionary>{})
50
+ );
51
+
52
+ if (!attr(elm, 'style')) {
53
+ attr(elm, 'style', null);
26
54
  }
27
55
 
28
- needUnwrap.push(elm);
29
- } else {
30
- if (firstElementSuit === undefined) {
31
- firstElementSuit = false;
56
+ if (elm.nodeName.toLowerCase() === style.element) {
57
+ needUnwrap.push(elm);
32
58
  }
59
+ });
60
+ } else if (!Dom.isEmptyTextNode(elm)) {
61
+ if (firstElementSuit === undefined) {
62
+ firstElementSuit = false;
33
63
  }
64
+ }
34
65
 
35
- return false;
36
- },
37
- font,
38
- true
39
- );
66
+ item = gen.next();
67
+ }
40
68
  }
41
69
 
70
+ needChangeStyle.forEach(clb => clb());
42
71
  needUnwrap.forEach(Dom.unwrap);
43
72
 
44
73
  return Boolean(firstElementSuit);
@@ -0,0 +1,68 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+
7
+ import type { IJodit } from '../../../../types';
8
+ import type { CommitStyle } from '../commit-style';
9
+ import { Dom } from '../../../dom';
10
+ import { wrapUnwrappedText } from './wrap-unwrapped-text';
11
+ import { attr } from '../../../helpers';
12
+ import { wrapOrderedList } from './wrap-ordered-list';
13
+
14
+ /**
15
+ * Replaces the parent tag with the applicable one, or wraps the text and also replaces the tag
16
+ */
17
+ export function wrapAndCommitStyle(
18
+ commitStyle: CommitStyle,
19
+ font: HTMLElement,
20
+ jodit: IJodit
21
+ ): HTMLElement {
22
+ const wrapper = findOrCreateWrapper(commitStyle, font, jodit);
23
+
24
+ return commitStyle.elementIsList
25
+ ? wrapOrderedList(commitStyle, wrapper, jodit)
26
+ : Dom.replace(wrapper, commitStyle.element, jodit.createInside, true);
27
+ }
28
+
29
+ /**
30
+ * If we apply a block element, then it finds the closest block parent (exclude table cell etc.),
31
+ * otherwise it wraps free text in an element.
32
+ */
33
+ function findOrCreateWrapper(
34
+ commitStyle: CommitStyle,
35
+ font: HTMLElement,
36
+ jodit: IJodit
37
+ ): HTMLElement {
38
+ if (commitStyle.elementIsBlock) {
39
+ const box = Dom.up(
40
+ font,
41
+ node =>
42
+ Dom.isBlock(node) &&
43
+ !Dom.isTag(node, [
44
+ 'td',
45
+ 'th',
46
+ 'tr',
47
+ 'tbody',
48
+ 'table',
49
+ 'li',
50
+ 'ul',
51
+ 'ol'
52
+ ]),
53
+ jodit.editor
54
+ );
55
+
56
+ if (box) {
57
+ return box;
58
+ }
59
+ }
60
+
61
+ if (commitStyle.elementIsBlock) {
62
+ return wrapUnwrappedText(commitStyle, font, jodit, jodit.s.createRange);
63
+ }
64
+
65
+ attr(font, 'size', null);
66
+
67
+ return font;
68
+ }
@@ -0,0 +1,37 @@
1
+ /*!
2
+ * Jodit Editor (https://xdsoft.net/jodit/)
3
+ * Released under MIT see LICENSE.txt in the project root for license information.
4
+ * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
+ */
6
+
7
+ import type { IJodit } from '../../../../types';
8
+ import { Dom } from '../../../dom';
9
+ import type { CommitStyle } from '../commit-style';
10
+
11
+ /**
12
+ * Replaces non-leaf items with leaf items and either creates a new list or
13
+ * adds a new item to the nearest old list
14
+ */
15
+ export function wrapOrderedList(
16
+ commitStyle: CommitStyle,
17
+ wrapper: HTMLElement,
18
+ jodit: IJodit
19
+ ): HTMLElement {
20
+ const newWrapper = Dom.replace(wrapper, 'li', jodit.createInside);
21
+
22
+ let list =
23
+ newWrapper.previousElementSibling || newWrapper.nextElementSibling;
24
+
25
+ if (!Dom.isTag(list, ['ul', 'ol'])) {
26
+ list = jodit.createInside.element(commitStyle.element);
27
+ Dom.before(newWrapper, list);
28
+ }
29
+
30
+ if (newWrapper.previousElementSibling === list) {
31
+ Dom.append(list, newWrapper);
32
+ } else {
33
+ Dom.prepend(list, newWrapper);
34
+ }
35
+
36
+ return <HTMLElement>list;
37
+ }
@@ -4,10 +4,9 @@
4
4
  * Copyright (c) 2013-2021 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
5
5
  */
6
6
 
7
- import type { ICreate, Nullable } from '../../../../types';
7
+ import type { IJodit, Nullable } from '../../../../types';
8
8
  import type { CommitStyle } from '../commit-style';
9
9
  import { Dom } from '../../../dom';
10
- import { postProcessListElement } from './post-process-list-element';
11
10
 
12
11
  /**
13
12
  * Wrap text or inline elements inside Block element
@@ -15,35 +14,40 @@ import { postProcessListElement } from './post-process-list-element';
15
14
  export function wrapUnwrappedText(
16
15
  style: CommitStyle,
17
16
  elm: Node,
18
- root: HTMLElement,
19
- ci: ICreate,
17
+ jodit: IJodit,
20
18
  getRange: () => Range
21
19
  ): HTMLElement {
22
- const edge = (n: Node, key: keyof Node = 'previousSibling') => {
23
- let edgeNode: Node = n,
24
- node: Nullable<Node> = n;
20
+ const root = jodit.editor,
21
+ ci = jodit.createInside,
22
+ edge = (n: Node, key: keyof Node = 'previousSibling') => {
23
+ let edgeNode: Node = n,
24
+ node: Nullable<Node> = n;
25
25
 
26
- while (node) {
27
- edgeNode = node;
26
+ while (node) {
27
+ if (Dom.isTag(node, jodit.o.enter)) {
28
+ break;
29
+ }
28
30
 
29
- if (node[key]) {
30
- node = node[key] as Nullable<Node>;
31
- } else {
32
- node =
33
- node.parentNode &&
34
- !Dom.isBlock(node.parentNode) &&
35
- node.parentNode !== root
36
- ? node.parentNode
37
- : null;
38
- }
31
+ edgeNode = node;
32
+
33
+ if (node[key]) {
34
+ node = node[key] as Nullable<Node>;
35
+ } else {
36
+ node =
37
+ node.parentNode &&
38
+ !Dom.isBlock(node.parentNode) &&
39
+ node.parentNode !== root
40
+ ? node.parentNode
41
+ : null;
42
+ }
39
43
 
40
- if (Dom.isBlock(node)) {
41
- break;
44
+ if (Dom.isBlock(node)) {
45
+ break;
46
+ }
42
47
  }
43
- }
44
48
 
45
- return edgeNode;
46
- };
49
+ return edgeNode;
50
+ };
47
51
 
48
52
  const start: Node = edge(elm),
49
53
  end: Node = edge(elm, 'nextSibling');
@@ -53,13 +57,11 @@ export function wrapUnwrappedText(
53
57
  range.setEndAfter(end);
54
58
  const fragment = range.extractContents();
55
59
 
56
- let wrapper = ci.element(style.element);
60
+ const wrapper = ci.element(style.element);
57
61
  wrapper.appendChild(fragment);
58
62
  range.insertNode(wrapper);
59
63
 
60
64
  if (style.elementIsBlock) {
61
- wrapper = postProcessListElement(style, wrapper, ci);
62
-
63
65
  if (
64
66
  Dom.isEmpty(wrapper) &&
65
67
  !Dom.isTag(wrapper.firstElementChild, 'br')