jodit 4.20.0 → 4.20.2

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 (80) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/es2015/jodit.css +68 -9
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +11 -11
  5. package/es2015/jodit.js +238 -54
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +8 -8
  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 +11 -11
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +8 -8
  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 +12 -12
  23. package/es2021/jodit.js +234 -54
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +8 -8
  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 +234 -54
  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 +285 -56
  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/core/ui/form/inputs/input/input.js +2 -0
  61. package/esm/modules/toolbar/button/button.d.ts +10 -0
  62. package/esm/modules/toolbar/button/button.js +19 -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/widget/color-picker/color-picker.js +76 -18
  66. package/esm/plugins/anchor/anchor.d.ts +11 -0
  67. package/esm/plugins/anchor/anchor.js +84 -8
  68. package/esm/plugins/fullsize/config.js +2 -0
  69. package/esm/plugins/hr/hr.js +0 -1
  70. package/esm/plugins/line-height/config.js +0 -1
  71. package/esm/plugins/link/template.js +3 -1
  72. package/esm/plugins/resizer/resizer.d.ts +6 -0
  73. package/esm/plugins/resizer/resizer.js +11 -0
  74. package/esm/types/toolbar.d.ts +2 -0
  75. package/package.json +1 -1
  76. package/types/modules/toolbar/button/button.d.ts +10 -0
  77. package/types/modules/toolbar/button/select/select.d.ts +6 -0
  78. package/types/plugins/anchor/anchor.d.ts +11 -0
  79. package/types/plugins/resizer/resizer.d.ts +6 -0
  80. 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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0
4
+ * Version: v4.20.2
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.0";
6
+ export const APP_VERSION = "4.20.2";
7
7
  // prettier-ignore
8
8
  export const ES = "es2020";
9
9
  export const IS_ES_MODERN = true;
@@ -59,6 +59,8 @@ let UIInput = UIInput_1 = class UIInput extends UIElement {
59
59
  if (label) {
60
60
  Dom.before(this.wrapper, this.label);
61
61
  this.label.innerText = this.j.i18n(label);
62
+ // The label is a span, so it names the input only this way
63
+ attr(input, 'aria-label', this.j.i18n(label));
62
64
  }
63
65
  else {
64
66
  Dom.safeRemove(this.label);
@@ -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,13 +117,28 @@ 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)) {
126
139
  this.text.innerHTML = this.control.template(this.j, this.control.name, this.j.i18n(this.state.text));
140
+ // The name given before the text came would otherwise stay
141
+ this.updateAriaLabel();
127
142
  }
128
143
  else {
129
144
  super.onChangeText();
@@ -223,6 +238,8 @@ let ToolbarButton = ToolbarButton_1 = class ToolbarButton extends UIButton {
223
238
  : ctr.tooltip;
224
239
  }
225
240
  state.hasTrigger = Boolean(ctr.list || (ctr.popup && ctr.exec));
241
+ // UIButton's template makes every button a toggle
242
+ this.onChangeActivated();
226
243
  }
227
244
  __initIconFromControl() {
228
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
@@ -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);
@@ -15,6 +15,8 @@ Config.prototype.controls.fullsize = {
15
15
  exec: (editor) => {
16
16
  editor.toggleFullSize();
17
17
  },
18
+ // Makes it a toggle. `update` sets the state, which holds while the editor doesn't have the focus
19
+ isActive: (editor) => editor.isFullSize,
18
20
  update(editor, button) {
19
21
  const mode = editor.isFullSize ? 'shrink' : 'fullsize';
20
22
  button.state.activated = editor.isFullSize;
@@ -11,7 +11,6 @@ import hrIcon from "./hr.svg.js";
11
11
  Icon.set('hr', hrIcon);
12
12
  Config.prototype.controls.hr = {
13
13
  command: 'insertHorizontalRule',
14
- tags: ['hr'],
15
14
  tooltip: 'Insert Horizontal Line'
16
15
  };
17
16
  export function hr(editor) {
@@ -11,7 +11,6 @@ Config.prototype.defaultLineHeight = null;
11
11
  Icon.set('line-height', lineHeightIcon);
12
12
  Config.prototype.controls.lineHeight = {
13
13
  command: 'applyLineHeight',
14
- tags: ['ol'],
15
14
  tooltip: 'Line height',
16
15
  list: [1, 1.1, 1.2, 1.3, 1.4, 1.5, 2],
17
16
  exec: (editor, event, { control }) => memorizeExec(editor, event, { control }, (value) => value)
@@ -11,7 +11,9 @@ export const formTemplate = (editor) => {
11
11
  new UIBlock(editor, [
12
12
  new UIInput(editor, {
13
13
  name: 'url',
14
- type: 'text',
14
+ // Touch keyboards leave a URL field as typed, with no capital or
15
+ // correction. The form is `novalidate`, so any address still goes in
16
+ type: 'url',
15
17
  ref: 'url_input',
16
18
  label: 'URL',
17
19
  placeholder: 'http://',
@@ -30,6 +30,12 @@ export declare class resizer extends Plugin {
30
30
  private sizeViewer;
31
31
  /** @override */
32
32
  protected afterInit(editor: IJodit): void;
33
+ /**
34
+ * A tap that selects an image sends no `click` (iPadOS), so `touchend`
35
+ * stands in for it. A tick later, after `onClickOutside` has had the same
36
+ * `touchend`, as `click` comes after `mouseup`
37
+ */
38
+ protected onEditorTouchEnd(e: TouchEvent): void;
33
39
  /**
34
40
  * Click in the editor area
35
41
  */
@@ -163,6 +163,14 @@ export class resizer extends Plugin {
163
163
  this.addEventListeners();
164
164
  this.__onChangeEditor();
165
165
  }
166
+ /**
167
+ * A tap that selects an image sends no `click` (iPadOS), so `touchend`
168
+ * stands in for it. A tick later, after `onClickOutside` has had the same
169
+ * `touchend`, as `click` comes after `mouseup`
170
+ */
171
+ onEditorTouchEnd(e) {
172
+ this.j.async.setTimeout(() => this.onEditorClick(e), 1);
173
+ }
166
174
  /**
167
175
  * Click in the editor area
168
176
  */
@@ -595,6 +603,9 @@ export class resizer extends Plugin {
595
603
  .off('keydown', this.onEditorKeyDown);
596
604
  }
597
605
  }
606
+ __decorate([
607
+ watch(':touchend')
608
+ ], resizer.prototype, "onEditorTouchEnd", null);
598
609
  __decorate([
599
610
  watch(':click')
600
611
  ], resizer.prototype, "onEditorClick", null);
@@ -25,6 +25,8 @@ interface IControlType<T extends IViewBased = IJodit | IViewBased | IFileBrowser
25
25
  /**
26
26
  * You can use it function for control - active/not active button
27
27
  *
28
+ * A button with `isActive`, `tags` or `css` is a toggle, with `aria-pressed`
29
+ *
28
30
  * @see copyformat plugin
29
31
  * @example
30
32
  * ```javascript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jodit",
3
- "version": "4.20.0",
3
+ "version": "4.20.2",
4
4
  "description": "Jodit is an awesome and useful wysiwyg editor with filebrowser",
5
5
  "main": "esm/index.js",
6
6
  "types": "types/index.d.ts",
@@ -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;