jodit 4.20.1 → 4.20.3

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 (85) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/es2015/jodit.css +68 -9
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +10 -10
  5. package/es2015/jodit.js +309 -72
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +7 -7
  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 +10 -10
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +7 -7
  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 +68 -9
  21. package/es2021/jodit.fat.min.css +1 -1
  22. package/es2021/jodit.fat.min.js +11 -11
  23. package/es2021/jodit.js +302 -72
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +7 -7
  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 +68 -9
  33. package/es2021.en/jodit.fat.min.css +1 -1
  34. package/es2021.en/jodit.fat.min.js +19 -19
  35. package/es2021.en/jodit.js +302 -72
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +19 -19
  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 +45 -2
  45. package/es5/jodit.fat.min.css +1 -1
  46. package/es5/jodit.fat.min.js +2 -2
  47. package/es5/jodit.js +358 -74
  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/core/constants.js +1 -1
  60. package/esm/modules/file-browser/builders/context-menu.js +6 -2
  61. package/esm/modules/toolbar/button/button.d.ts +10 -0
  62. package/esm/modules/toolbar/button/button.js +17 -2
  63. package/esm/modules/toolbar/button/select/select.d.ts +6 -0
  64. package/esm/modules/toolbar/button/select/select.js +18 -0
  65. package/esm/modules/toolbar/factory.js +3 -1
  66. package/esm/modules/widget/color-picker/color-picker.js +76 -18
  67. package/esm/plugins/anchor/anchor.d.ts +11 -0
  68. package/esm/plugins/anchor/anchor.js +84 -8
  69. package/esm/plugins/backspace/cases/check-not-collapsed.js +1 -1
  70. package/esm/plugins/delete/delete.d.ts +12 -0
  71. package/esm/plugins/delete/delete.js +66 -4
  72. package/esm/plugins/delete/interface.d.ts +4 -2
  73. package/esm/plugins/dtd/after-insert/remove-extra-br.js +7 -1
  74. package/esm/plugins/fullsize/config.js +2 -0
  75. package/esm/plugins/hr/hr.js +0 -1
  76. package/esm/plugins/line-height/config.js +0 -1
  77. package/esm/plugins/placeholder/placeholder.js +3 -1
  78. package/esm/types/toolbar.d.ts +2 -0
  79. package/package.json +1 -1
  80. package/types/modules/toolbar/button/button.d.ts +10 -0
  81. package/types/modules/toolbar/button/select/select.d.ts +6 -0
  82. package/types/plugins/anchor/anchor.d.ts +11 -0
  83. package/types/plugins/delete/delete.d.ts +12 -0
  84. package/types/plugins/delete/interface.d.ts +4 -2
  85. package/types/types/toolbar.d.ts +2 -0
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
package/es5/polyfills.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.1
4
+ * Version: v4.20.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -3,7 +3,7 @@
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
- export const APP_VERSION = "4.20.1";
6
+ export const APP_VERSION = "4.20.3";
7
7
  // prettier-ignore
8
8
  export const ES = "es2020";
9
9
  export const IS_ES_MODERN = true;
@@ -81,12 +81,13 @@ export default (self) => {
81
81
  }), temp_content = self.c.div(CLASS_PREVIEW, '<div class="jodit-icon_loader"></div>'), preview_box = self.c.div(CLASS_PREVIEW + '__box'), next = self.c.fromHTML(preview_tpl_next()), prev = self.c.fromHTML(preview_tpl_next('prev', 'left')), addLoadHandler = (src) => {
82
82
  const image = self.c.element('img');
83
83
  attr(image, 'src', src);
84
+ attr(image, 'alt', ga('data-name'));
84
85
  const onload = () => {
85
86
  var _a;
86
87
  if (self.isInDestruct) {
87
88
  return;
88
89
  }
89
- self.e.off(image, 'load');
90
+ self.e.off(image, 'load error');
90
91
  Dom.detach(temp_content);
91
92
  if (opt.showPreviewNavigation) {
92
93
  if (Dom.prevWithClass(item, self.files.getFullElName('item'))) {
@@ -101,7 +102,10 @@ export default (self) => {
101
102
  preview.setPosition();
102
103
  (_a = self === null || self === void 0 ? void 0 : self.events) === null || _a === void 0 ? void 0 : _a.fire('previewOpenedAndLoaded');
103
104
  };
104
- self.e.on(image, 'load', onload);
105
+ // An image that can't load is shown too,
106
+ // broken with the file's name, rather
107
+ // than the loader for good
108
+ self.e.on(image, 'load error', onload);
105
109
  if (image.complete) {
106
110
  onload();
107
111
  }
@@ -47,6 +47,16 @@ export declare class ToolbarButton<T extends IViewBased = IViewBased> extends UI
47
47
  * Calculates whether an element is blocked for the user
48
48
  */
49
49
  private __calculateDisabledStatus;
50
+ /**
51
+ * A button that its control can show as on is a toggle, and says whether
52
+ * it's pressed
53
+ */
54
+ protected get isToggle(): boolean;
55
+ /**
56
+ * The pressed look comes from the mod, as any button looks pressed while
57
+ * its list is open, and the container is a `listitem`, which can't have
58
+ * `aria-pressed`
59
+ */
50
60
  protected onChangeActivated(): void;
51
61
  protected onChangeText(): void;
52
62
  protected onChangeTabIndex(): void;
@@ -117,9 +117,22 @@ let ToolbarButton = ToolbarButton_1 = class ToolbarButton extends UIButton {
117
117
  }
118
118
  return Boolean(tc && tc.shouldBeDisabled(this));
119
119
  }
120
+ /**
121
+ * A button that its control can show as on is a toggle, and says whether
122
+ * it's pressed
123
+ */
124
+ get isToggle() {
125
+ const { isActive, tags, css } = this.control;
126
+ return Boolean(isActive || tags || css);
127
+ }
128
+ /**
129
+ * The pressed look comes from the mod, as any button looks pressed while
130
+ * its list is open, and the container is a `listitem`, which can't have
131
+ * `aria-pressed`
132
+ */
120
133
  onChangeActivated() {
121
- attr(this.button, 'aria-pressed', this.state.activated);
122
- super.onChangeActivated();
134
+ attr(this.button, 'aria-pressed', this.isToggle ? this.state.activated : null);
135
+ this.setMod('activated', this.state.activated || null);
123
136
  }
124
137
  onChangeText() {
125
138
  if (isFunction(this.control.template)) {
@@ -225,6 +238,8 @@ let ToolbarButton = ToolbarButton_1 = class ToolbarButton extends UIButton {
225
238
  : ctr.tooltip;
226
239
  }
227
240
  state.hasTrigger = Boolean(ctr.list || (ctr.popup && ctr.exec));
241
+ // UIButton's template makes every button a toggle
242
+ this.onChangeActivated();
228
243
  }
229
244
  __initIconFromControl() {
230
245
  var _a;
@@ -10,5 +10,11 @@ import type { IViewBased } from "../../../../types/index";
10
10
  import { ToolbarButton } from "../button";
11
11
  export declare class ToolbarSelect<T extends IViewBased = IViewBased> extends ToolbarButton<T> {
12
12
  className(): string;
13
+ protected get isToggle(): boolean;
13
14
  update(): void;
15
+ /**
16
+ * The button shows only the value, so its name says which control it
17
+ * is too: "Font size, 16px"
18
+ */
19
+ protected updateAriaLabel(): void;
14
20
  }
@@ -16,11 +16,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
16
16
  import { component } from "../../../../core/decorators/index.js";
17
17
  import { isPlainObject } from "../../../../core/helpers/checker/is-plain-object.js";
18
18
  import { isString } from "../../../../core/helpers/checker/is-string.js";
19
+ import { attr } from "../../../../core/helpers/utils/attr.js";
19
20
  import { ToolbarButton } from "../button.js";
20
21
  let ToolbarSelect = class ToolbarSelect extends ToolbarButton {
21
22
  className() {
22
23
  return 'ToolbarSelect';
23
24
  }
25
+ // It shows its value, rather than being on or off
26
+ get isToggle() {
27
+ return false;
28
+ }
24
29
  update() {
25
30
  var _a, _b, _c;
26
31
  super.update();
@@ -40,6 +45,19 @@ let ToolbarSelect = class ToolbarSelect extends ToolbarButton {
40
45
  (_c = (_b = (_a = this.control).textTemplate) === null || _b === void 0 ? void 0 : _b.call(_a, this.jodit, text)) !== null && _c !== void 0 ? _c : text;
41
46
  }
42
47
  }
48
+ /**
49
+ * The button shows only the value, so its name says which control it
50
+ * is too: "Font size, 16px"
51
+ */
52
+ updateAriaLabel() {
53
+ var _a;
54
+ super.updateAriaLabel();
55
+ const { tooltip } = this.state;
56
+ const value = (_a = this.text.textContent) === null || _a === void 0 ? void 0 : _a.trim();
57
+ if (tooltip && value) {
58
+ attr(this.button, 'aria-label', `${this.jodit.i18n(tooltip)}, ${value}`);
59
+ }
60
+ }
43
61
  };
44
62
  ToolbarSelect = __decorate([
45
63
  component
@@ -41,5 +41,7 @@ export function makeButton(jodit, control, target = null) {
41
41
  }
42
42
  export function makeSelect(view, control, target = null) {
43
43
  const ToolbarSelect = getComponentClass('ToolbarSelect');
44
- return new ToolbarSelect(view, control, target);
44
+ const select = new ToolbarSelect(view, control, target);
45
+ select.state.tabIndex = view.o.allowTabNavigation ? 0 : -1;
46
+ return select;
45
47
  }
@@ -3,8 +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 { KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_UP } from "../../../core/constants.js";
6
7
  import { Dom } from "../../../core/dom/index.js";
7
- import { attr, hasBrowserColorPicker, isArray, isFunction, isPlainObject, normalizeColor, refs } from "../../../core/helpers/index.js";
8
+ import { attr, css, hasBrowserColorPicker, isArray, isFunction, isPlainObject, normalizeColor, refs, toArray } from "../../../core/helpers/index.js";
8
9
  import { Icon } from "../../../core/ui/index.js";
9
10
  import paletteIcon from "./palette.svg.js";
10
11
  Icon.set('palette', paletteIcon);
@@ -26,6 +27,7 @@ Icon.set('palette', paletteIcon);
26
27
  * ```
27
28
  */
28
29
  export const ColorPickerWidget = (editor, callback, coldColor) => {
30
+ var _a;
29
31
  const cn = 'jodit-color-picker', valueHex = normalizeColor(coldColor), form = editor.c.div(cn), iconPalette = editor.o.textIcons
30
32
  ? `<span>${editor.i18n('palette')}</span>`
31
33
  : Icon.get('palette'), eachColor = (colors) => {
@@ -39,9 +41,8 @@ export const ColorPickerWidget = (editor, callback, coldColor) => {
39
41
  }
40
42
  else if (isArray(colors)) {
41
43
  colors.forEach(color => {
42
- stack.push(`<span class='${cn}__color-item ${valueHex === color
43
- ? cn + '__color-item_active_true'
44
- : ''}' title="${color}" style="background-color:${color}" data-color="${color}"></span>`);
44
+ const active = valueHex === color;
45
+ stack.push(`<button type="button" class='${cn}__color-item ${active ? cn + '__color-item_active_true' : ''}' title="${color}" aria-pressed="${active}" tabindex="-1" style="background-color:${color}" data-color="${color}"></button>`);
45
46
  });
46
47
  }
47
48
  return stack.join('');
@@ -52,6 +53,33 @@ export const ColorPickerWidget = (editor, callback, coldColor) => {
52
53
  ? `<div class="${cn}__group">${eachColor(editor.o.colors)}</div>`
53
54
  : eachColor(editor.o.colors);
54
55
  Dom.append(form, editor.c.fromHTML(`<div class="${cn}__groups">${groups}</div>`));
56
+ const items = toArray(form.querySelectorAll(`.${cn}__color-item`));
57
+ // Tab stops at one color, the current one or the first, and the arrow
58
+ // keys move from it
59
+ const tabStop = (_a = items.find(item => attr(item, 'aria-pressed') === 'true')) !== null && _a !== void 0 ? _a : items[0];
60
+ if (tabStop) {
61
+ attr(tabStop, 'tabindex', 0);
62
+ }
63
+ // Along a row, or to the nearest color in the row above or below, as the
64
+ // palette is laid out
65
+ const nextItem = (item, key) => {
66
+ const index = items.indexOf(item);
67
+ if (key === KEY_LEFT || key === KEY_RIGHT) {
68
+ const step = key === KEY_LEFT ? -1 : 1;
69
+ const rtl = css(item, 'direction') === 'rtl';
70
+ return items[index + (rtl ? -step : step)];
71
+ }
72
+ const down = key === KEY_DOWN, rows = items.filter(other => down
73
+ ? other.offsetTop > item.offsetTop
74
+ : other.offsetTop < item.offsetTop);
75
+ if (!rows.length) {
76
+ return;
77
+ }
78
+ const top = (down ? Math.min : Math.max)(...rows.map(other => other.offsetTop)), distance = (other) => Math.abs(other.offsetLeft - item.offsetLeft);
79
+ return rows
80
+ .filter(other => other.offsetTop === top)
81
+ .reduce((nearest, other) => distance(other) < distance(nearest) ? other : nearest);
82
+ };
55
83
  Dom.append(form, editor.c.fromHTML(`<div data-ref="extra" class="${cn}__extra"></div>`));
56
84
  const { extra } = refs(form);
57
85
  Dom.append(extra, editor.c.fromHTML(`<div class="${cn}__hex"><input data-ref="hexInput" type="text" spellcheck="false" aria-label="HEX" placeholder="#FF0000" value="${valueHex || ''}"/></div>`));
@@ -88,7 +116,7 @@ export const ColorPickerWidget = (editor, callback, coldColor) => {
88
116
  e.stopPropagation();
89
117
  applyHexInput();
90
118
  });
91
- Dom.append(extra, editor.c.fromHTML(`<span class="${cn}__remove" data-color="" title="${editor.i18n('Remove')}">${editor.o.textIcons ? editor.i18n('Remove') : Icon.get('eraser')}</span>`));
119
+ Dom.append(extra, editor.c.fromHTML(`<button type="button" class="${cn}__remove" data-color="" title="${editor.i18n('Remove')}">${editor.o.textIcons ? editor.i18n('Remove') : Icon.get('eraser')}</button>`));
92
120
  if (editor.o.showBrowserColorPicker && hasBrowserColorPicker()) {
93
121
  Dom.append(extra, editor.c.fromHTML(`<div class="${cn}__native">${iconPalette}<input type="color" value="#ffffff"/></div>`));
94
122
  editor.e.on(form, 'change', (e) => {
@@ -107,6 +135,22 @@ export const ColorPickerWidget = (editor, callback, coldColor) => {
107
135
  e.preventDefault();
108
136
  });
109
137
  }
138
+ // The color of a swatch, or '' for Remove, from an event on it or its icon
139
+ const colorOf = (node) => {
140
+ const button = Dom.closest(node, elm => Dom.isHTMLElement(elm) &&
141
+ (elm.classList.contains(cn + '__color-item') ||
142
+ elm.classList.contains(cn + '__remove')), form);
143
+ return button ? attr(button, '-color') || '' : undefined;
144
+ };
145
+ const apply = (color) => {
146
+ if (callback && isFunction(callback)) {
147
+ callback(color);
148
+ }
149
+ };
150
+ // A pointer applies the color on `mousedown`, which keeps the selection.
151
+ // The keyboard and screen readers press the button, which sends only
152
+ // `click`, so a click after the pointer's `mousedown` is skipped
153
+ let pointerPressed = false;
110
154
  editor.e.on(form, 'mousedown touchend', (e) => {
111
155
  // let the hex/native inputs receive focus and clicks
112
156
  if (Dom.isTag(e.target, 'input')) {
@@ -115,22 +159,36 @@ export const ColorPickerWidget = (editor, callback, coldColor) => {
115
159
  }
116
160
  e.stopPropagation();
117
161
  e.preventDefault();
118
- let target = e.target;
119
- if ((!target ||
120
- !target.tagName ||
121
- Dom.isTag(target, 'svg') ||
122
- Dom.isTag(target, 'path')) &&
123
- target.parentNode) {
124
- target = Dom.closest(target.parentNode, 'span', editor.editor);
162
+ const color = colorOf(e.target);
163
+ if (color !== undefined) {
164
+ pointerPressed = e.type === 'mousedown';
165
+ apply(color);
125
166
  }
126
- if (!Dom.isTag(target, 'span') ||
127
- (!target.classList.contains(cn + '__color-item') &&
128
- !target.classList.contains(cn + '__remove'))) {
167
+ });
168
+ editor.e
169
+ .on(form, 'click', (e) => {
170
+ const color = colorOf(e.target);
171
+ if (color !== undefined && !pointerPressed) {
172
+ apply(color);
173
+ }
174
+ pointerPressed = false;
175
+ })
176
+ .on(form, 'keydown', (e) => {
177
+ var _a;
178
+ pointerPressed = false;
179
+ const item = e.target;
180
+ if (!items.includes(item) ||
181
+ ![KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN].includes(e.key)) {
129
182
  return;
130
183
  }
131
- const color = attr(target, '-color') || '';
132
- if (callback && isFunction(callback)) {
133
- callback(color);
184
+ // The toolbar's dropdown would walk every color one by one
185
+ e.preventDefault();
186
+ e.stopPropagation();
187
+ (_a = nextItem(item, e.key)) === null || _a === void 0 ? void 0 : _a.focus();
188
+ })
189
+ .on(form, 'focusin', (e) => {
190
+ if (items.includes(e.target)) {
191
+ items.forEach(item => attr(item, 'tabindex', item === e.target ? 0 : -1));
134
192
  }
135
193
  });
136
194
  editor.e.fire('afterGenerateColorPicker', form, extra, callback, valueHex);
@@ -35,6 +35,11 @@ export declare class anchor extends Plugin {
35
35
  protected onAfterGetValueFromEditor(data: {
36
36
  value: string;
37
37
  }): void;
38
+ /**
39
+ * A pasted or dropped copy of an anchor the document already has gets the
40
+ * next free name, as `fees-2`, and the links that came with it follow it
41
+ */
42
+ protected onBeforePasteInsert(html: unknown): string | void;
38
43
  /**
39
44
  * The form that names a new anchor, or renames or removes `target`
40
45
  */
@@ -62,6 +67,12 @@ export declare class anchor extends Plugin {
62
67
  * something else by the old one, as they do after a copy is pasted
63
68
  */
64
69
  private __rename;
70
+ /**
71
+ * Gives each anchor in `root` whose name the document already has the
72
+ * next free one, avoiding the names in `root` too, and points the links
73
+ * in `root` to it at the new name. Whether any was renamed
74
+ */
75
+ private __renameCopies;
65
76
  /** @override */
66
77
  protected beforeDestruct(jodit: IJodit): void;
67
78
  }
@@ -17,19 +17,27 @@ import * as consts from "../../core/constants.js";
17
17
  import { autobind, debounce, watch } from "../../core/decorators/index.js";
18
18
  import { Dom } from "../../core/dom/dom.js";
19
19
  import { getContainer, pluginSystem } from "../../core/global.js";
20
- import { attr, camelCase, getAnchorName, getAnchors, isAnchor, position, toArray } from "../../core/helpers/index.js";
20
+ import { attr, camelCase, getAnchorName, getAnchors, isAnchor, isString, position, toArray } from "../../core/helpers/index.js";
21
21
  import { Plugin } from "../../core/plugin/index.js";
22
22
  import { UIButton } from "../../core/ui/button/index.js";
23
23
  import { UIBlock, UIForm, UIInput } from "../../core/ui/form/index.js";
24
+ import { Icon } from "../../core/ui/icon.js";
24
25
  import "./config.js";
25
- const ICON = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e88e5' stroke-width='2.5' stroke-linejoin='round'%3E%3Cpath d='M6 3h12v18l-6-4-6 4z'/%3E%3C/svg%3E\")";
26
- const MARKER = ['id', 'name']
27
- .map(key => `.jodit-wysiwyg a[${key}]:not([href]):empty::before`)
28
- .join(',');
29
26
  /**
30
- * Each anchor's marker, in the editing area only
27
+ * The editing area of an editor with the plugin, when it shares its document
28
+ * with the page and so with any other editor on it
31
29
  */
32
- const MARKER_STYLE = `${MARKER}{display:inline-block;width:.75em;height:1em;margin:0 .1em;vertical-align:-.15em;background:${ICON} center/contain no-repeat;cursor:pointer;content:''}`;
30
+ const WITH_ANCHORS = 'jodit-wysiwyg_anchors';
31
+ /**
32
+ * Each anchor's marker, in the editing areas `scope` picks out
33
+ */
34
+ function markerStyle(scope) {
35
+ const marker = ['id', 'name']
36
+ .map(key => `.jodit-wysiwyg${scope} a[${key}]:not([href]):empty::before`)
37
+ .join(',');
38
+ const icon = `url("data:image/svg+xml,${encodeURIComponent(Icon.get('anchor'))}") center/contain no-repeat`;
39
+ return `${marker}{display:inline-block;width:.75em;height:1em;margin:0 .1em;vertical-align:-.15em;background-color:var(--jd-color-icon,#4c4c4c);-webkit-mask:${icon};mask:${icon};cursor:pointer;content:''}`;
40
+ }
33
41
  /**
34
42
  * The attribute `markAnchor` gives an anchor: an empty `<a>` with no `href`
35
43
  */
@@ -57,8 +65,14 @@ export class anchor extends Plugin {
57
65
  }
58
66
  /** @override */
59
67
  afterInit(jodit) {
68
+ // An iframe's document is the editor's alone, and its body is part of
69
+ // the value with `editHTMLDocumentMode`, so it gets no class
70
+ const shared = jodit.ed === jodit.od;
71
+ if (shared) {
72
+ jodit.editor.classList.add(WITH_ANCHORS);
73
+ }
60
74
  // It goes in the editing document, so iframe mode has it whatever `iframeStyle` holds
61
- getContainer(jodit, 'anchor', 'style', true).textContent = MARKER_STYLE;
75
+ getContainer(jodit, 'anchor', 'style', true).textContent = markerStyle(shared ? '.' + WITH_ANCHORS : '');
62
76
  jodit.e
63
77
  .on('generateAnchorForm.anchor', this.__generateForm)
64
78
  .on('clickA touchstartA', this.__onClickA, { top: true });
@@ -94,6 +108,25 @@ export class anchor extends Plugin {
94
108
  onAfterGetValueFromEditor(data) {
95
109
  data.value = unmarkAnchors(data.value);
96
110
  }
111
+ /**
112
+ * A pasted or dropped copy of an anchor the document already has gets the
113
+ * next free name, as `fees-2`, and the links that came with it follow it
114
+ */
115
+ onBeforePasteInsert(html) {
116
+ if (Dom.isElement(html) || Dom.isFragment(html)) {
117
+ this.__renameCopies(html);
118
+ return;
119
+ }
120
+ if (!isString(html) || !/<a\s/i.test(html)) {
121
+ return;
122
+ }
123
+ // Inert, so nothing in it loads
124
+ const template = this.j.createInside.element('template');
125
+ template.innerHTML = html;
126
+ if (this.__renameCopies(template.content)) {
127
+ return template.innerHTML;
128
+ }
129
+ }
97
130
  /**
98
131
  * The form that names a new anchor, or renames or removes `target`
99
132
  */
@@ -238,9 +271,49 @@ export class anchor extends Plugin {
238
271
  }
239
272
  });
240
273
  }
274
+ /**
275
+ * Gives each anchor in `root` whose name the document already has the
276
+ * next free one, avoiding the names in `root` too, and points the links
277
+ * in `root` to it at the new name. Whether any was renamed
278
+ */
279
+ __renameCopies(root) {
280
+ const inRoot = new Set(toArray(root.querySelectorAll('[id], a[name]')).map(elm => elm.id || attr(elm, 'name')));
281
+ const renamed = new Map();
282
+ const anchors = isAnchor(root) ? [root] : getAnchors(root);
283
+ anchors.forEach(anchor => {
284
+ const name = getAnchorName(anchor);
285
+ if (!this.__isTaken(name, null)) {
286
+ return;
287
+ }
288
+ let copy = name;
289
+ for (let n = 2; inRoot.has(copy) || this.__isTaken(copy, null); n += 1) {
290
+ copy = `${name}-${n}`;
291
+ }
292
+ ['id', 'name'].forEach(key => {
293
+ if (anchor.hasAttribute(key)) {
294
+ attr(anchor, key, copy);
295
+ }
296
+ });
297
+ inRoot.add(copy);
298
+ renamed.set(name, copy);
299
+ });
300
+ if (!renamed.size) {
301
+ return false;
302
+ }
303
+ toArray(root.querySelectorAll('a[href]')).forEach(link => {
304
+ var _a;
305
+ const href = (_a = attr(link, 'href')) !== null && _a !== void 0 ? _a : '';
306
+ const copy = href[0] === '#' && renamed.get(href.slice(1));
307
+ if (copy) {
308
+ attr(link, 'href', '#' + copy);
309
+ }
310
+ });
311
+ return true;
312
+ }
241
313
  /** @override */
242
314
  beforeDestruct(jodit) {
243
315
  this.__dropForm();
316
+ jodit.editor.classList.remove(WITH_ANCHORS);
244
317
  jodit.e
245
318
  .off('generateAnchorForm.anchor', this.__generateForm)
246
319
  .off('clickA touchstartA', this.__onClickA);
@@ -256,6 +329,9 @@ __decorate([
256
329
  __decorate([
257
330
  watch(':afterGetValueFromEditor')
258
331
  ], anchor.prototype, "onAfterGetValueFromEditor", null);
332
+ __decorate([
333
+ watch(':beforePasteInsert')
334
+ ], anchor.prototype, "onBeforePasteInsert", null);
259
335
  __decorate([
260
336
  autobind
261
337
  ], anchor.prototype, "__generateForm", null);
@@ -18,7 +18,7 @@
18
18
  */
19
19
  export function checkNotCollapsed(jodit) {
20
20
  if (!jodit.s.isCollapsed()) {
21
- jodit.execCommand('Delete');
21
+ jodit.execCommand('delete', false, true);
22
22
  return true;
23
23
  }
24
24
  return false;
@@ -27,6 +27,18 @@ export declare class deleteCommand extends Plugin {
27
27
  * Firefox's own delete
28
28
  */
29
29
  private __moveEdgesIntoCells;
30
+ /**
31
+ * The formatting elements the deletion takes whole from its start,
32
+ * outermost first: `<strong>` and `<em>` for all of the text in
33
+ * `<strong><em>cd</em></strong>`
34
+ */
35
+ private __formatTakenWhole;
36
+ /**
37
+ * As the browsers do, the next letter typed keeps the formatting that was
38
+ * deleted whole: empty copies go where it was, round an invisible space,
39
+ * as Bold does at a collapsed caret, and the caret goes inside (#1784)
40
+ */
41
+ private __keepFormat;
30
42
  /**
31
43
  * A selection that starts or ends in a table cell clears the selected part
32
44
  * of each cell it covers and keeps the cells, as the browsers do.