@ckeditor/ckeditor5-link 40.1.0 → 41.0.0

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 (105) hide show
  1. package/CHANGELOG.md +29 -29
  2. package/LICENSE.md +1 -1
  3. package/build/link.js +2 -2
  4. package/build/translations/ug.js +1 -1
  5. package/lang/translations/ar.po +1 -1
  6. package/lang/translations/ast.po +1 -1
  7. package/lang/translations/az.po +1 -1
  8. package/lang/translations/bg.po +1 -1
  9. package/lang/translations/bn.po +1 -1
  10. package/lang/translations/ca.po +1 -1
  11. package/lang/translations/cs.po +1 -1
  12. package/lang/translations/da.po +1 -1
  13. package/lang/translations/de-ch.po +1 -1
  14. package/lang/translations/de.po +1 -1
  15. package/lang/translations/el.po +1 -1
  16. package/lang/translations/en-au.po +1 -1
  17. package/lang/translations/en-gb.po +1 -1
  18. package/lang/translations/en.po +1 -1
  19. package/lang/translations/eo.po +1 -1
  20. package/lang/translations/es.po +1 -1
  21. package/lang/translations/et.po +1 -1
  22. package/lang/translations/eu.po +1 -1
  23. package/lang/translations/fa.po +1 -1
  24. package/lang/translations/fi.po +1 -1
  25. package/lang/translations/fr.po +1 -1
  26. package/lang/translations/gl.po +1 -1
  27. package/lang/translations/he.po +1 -1
  28. package/lang/translations/hi.po +1 -1
  29. package/lang/translations/hr.po +1 -1
  30. package/lang/translations/hu.po +1 -1
  31. package/lang/translations/hy.po +1 -1
  32. package/lang/translations/id.po +1 -1
  33. package/lang/translations/it.po +1 -1
  34. package/lang/translations/ja.po +1 -1
  35. package/lang/translations/km.po +1 -1
  36. package/lang/translations/kn.po +1 -1
  37. package/lang/translations/ko.po +1 -1
  38. package/lang/translations/ku.po +1 -1
  39. package/lang/translations/lt.po +1 -1
  40. package/lang/translations/lv.po +1 -1
  41. package/lang/translations/ms.po +1 -1
  42. package/lang/translations/nb.po +1 -1
  43. package/lang/translations/ne.po +1 -1
  44. package/lang/translations/nl.po +1 -1
  45. package/lang/translations/no.po +1 -1
  46. package/lang/translations/pl.po +1 -1
  47. package/lang/translations/pt-br.po +1 -1
  48. package/lang/translations/pt.po +1 -1
  49. package/lang/translations/ro.po +1 -1
  50. package/lang/translations/ru.po +1 -1
  51. package/lang/translations/sk.po +1 -1
  52. package/lang/translations/sq.po +1 -1
  53. package/lang/translations/sr-latn.po +1 -1
  54. package/lang/translations/sr.po +1 -1
  55. package/lang/translations/sv.po +1 -1
  56. package/lang/translations/th.po +1 -1
  57. package/lang/translations/tk.po +1 -1
  58. package/lang/translations/tr.po +1 -1
  59. package/lang/translations/tt.po +1 -1
  60. package/lang/translations/ug.po +7 -7
  61. package/lang/translations/uk.po +1 -1
  62. package/lang/translations/ur.po +1 -1
  63. package/lang/translations/uz.po +1 -1
  64. package/lang/translations/vi.po +1 -1
  65. package/lang/translations/zh-cn.po +1 -1
  66. package/lang/translations/zh.po +1 -1
  67. package/package.json +4 -3
  68. package/src/augmentation.d.ts +2 -2
  69. package/src/augmentation.js +1 -1
  70. package/src/autolink.d.ts +19 -4
  71. package/src/autolink.js +73 -5
  72. package/src/index.d.ts +12 -12
  73. package/src/index.js +11 -11
  74. package/src/link.d.ts +5 -5
  75. package/src/link.js +5 -5
  76. package/src/linkcommand.d.ts +5 -5
  77. package/src/linkcommand.js +6 -6
  78. package/src/linkconfig.d.ts +21 -2
  79. package/src/linkconfig.js +1 -1
  80. package/src/linkediting.d.ts +7 -43
  81. package/src/linkediting.js +17 -285
  82. package/src/linkimage.d.ts +4 -4
  83. package/src/linkimage.js +4 -4
  84. package/src/linkimageediting.d.ts +4 -4
  85. package/src/linkimageediting.js +6 -6
  86. package/src/linkimageui.d.ts +4 -4
  87. package/src/linkimageui.js +6 -6
  88. package/src/linkui.d.ts +5 -5
  89. package/src/linkui.js +19 -15
  90. package/src/ui/linkactionsview.d.ts +4 -4
  91. package/src/ui/linkactionsview.js +5 -5
  92. package/src/ui/linkformview.d.ts +4 -4
  93. package/src/ui/linkformview.js +4 -4
  94. package/src/unlinkcommand.d.ts +2 -2
  95. package/src/unlinkcommand.js +4 -4
  96. package/src/utils/automaticdecorators.d.ts +4 -4
  97. package/src/utils/automaticdecorators.js +2 -2
  98. package/src/utils/manualdecorator.d.ts +6 -6
  99. package/src/utils/manualdecorator.js +2 -2
  100. package/src/utils.d.ts +4 -4
  101. package/src/utils.js +1 -1
  102. package/theme/link.css +1 -1
  103. package/theme/linkactions.css +1 -1
  104. package/theme/linkform.css +1 -1
  105. package/theme/linkimage.css +1 -1
package/src/link.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/link
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import LinkEditing from './linkediting';
10
- import LinkUI from './linkui';
11
- import AutoLink from './autolink';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import LinkEditing from './linkediting.js';
10
+ import LinkUI from './linkui.js';
11
+ import AutoLink from './autolink.js';
12
12
  /**
13
13
  * The link plugin.
14
14
  *
@@ -1,14 +1,14 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkcommand
7
7
  */
8
- import { Command } from 'ckeditor5/src/core';
9
- import { Collection } from 'ckeditor5/src/utils';
10
- import AutomaticDecorators from './utils/automaticdecorators';
11
- import type ManualDecorator from './utils/manualdecorator';
8
+ import { Command } from 'ckeditor5/src/core.js';
9
+ import { Collection } from 'ckeditor5/src/utils.js';
10
+ import AutomaticDecorators from './utils/automaticdecorators.js';
11
+ import type ManualDecorator from './utils/manualdecorator.js';
12
12
  /**
13
13
  * The link command. It is used by the {@link module:link/link~Link link feature}.
14
14
  */
@@ -1,15 +1,15 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkcommand
7
7
  */
8
- import { Command } from 'ckeditor5/src/core';
9
- import { findAttributeRange } from 'ckeditor5/src/typing';
10
- import { Collection, first, toMap } from 'ckeditor5/src/utils';
11
- import AutomaticDecorators from './utils/automaticdecorators';
12
- import { isLinkableElement } from './utils';
8
+ import { Command } from 'ckeditor5/src/core.js';
9
+ import { findAttributeRange } from 'ckeditor5/src/typing.js';
10
+ import { Collection, first, toMap } from 'ckeditor5/src/utils.js';
11
+ import AutomaticDecorators from './utils/automaticdecorators.js';
12
+ import { isLinkableElement } from './utils.js';
13
13
  /**
14
14
  * The link command. It is used by the {@link module:link/link~Link link feature}.
15
15
  */
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkconfig
7
7
  */
8
- import type { ArrayOrItem } from 'ckeditor5/src/utils';
8
+ import type { ArrayOrItem } from 'ckeditor5/src/utils.js';
9
9
  /**
10
10
  * The configuration of the {@link module:link/link~Link link feature}.
11
11
  *
@@ -43,6 +43,25 @@ export interface LinkConfig {
43
43
  * **NOTE:** If no configuration is provided, the editor will not auto-fix the links.
44
44
  */
45
45
  defaultProtocol?: string;
46
+ /**
47
+ * When set to `true`, the form will accept an empty value in the URL field, creating a link with an empty `href` (`<a href="">`).
48
+ *
49
+ * ```ts
50
+ * ClassicEditor
51
+ * .create( editorElement, {
52
+ * link: {
53
+ * allowCreatingEmptyLinks: true
54
+ * }
55
+ * } )
56
+ * .then( ... )
57
+ * .catch( ... );
58
+ * ```
59
+ *
60
+ * **NOTE:** This option only adds form validation. If a link with an empty `href` is loaded into the editor, it will be left as-is.
61
+ *
62
+ * @default false
63
+ */
64
+ allowCreatingEmptyLinks?: boolean;
46
65
  /**
47
66
  * When set to `true`, the `target="blank"` and `rel="noopener noreferrer"` attributes are automatically added to all external links
48
67
  * in the editor. "External links" are all links in the editor content starting with `http`, `https`, or `//`.
package/src/linkconfig.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  export {};
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkediting
7
7
  */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- import { Input, TwoStepCaretMovement } from 'ckeditor5/src/typing';
10
- import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
9
+ import { Input, TwoStepCaretMovement } from 'ckeditor5/src/typing.js';
10
+ import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
11
11
  import '../theme/link.css';
12
12
  /**
13
13
  * The link engine feature.
@@ -58,47 +58,11 @@ export default class LinkEditing extends Plugin {
58
58
  */
59
59
  private _enableLinkOpen;
60
60
  /**
61
- * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
62
- * selection attributes if the selection is at the end of a link after inserting the content.
61
+ * Watches the DocumentSelection attribute changes and removes link decorator attributes when the linkHref attribute is removed.
63
62
  *
64
- * The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
65
- * `linkHref` attribute of the selection and they can type a "clean" (`linkHref`–less) text right away.
66
- *
67
- * See https://github.com/ckeditor/ckeditor5/issues/6053.
68
- */
69
- private _enableInsertContentSelectionAttributesFixer;
70
- /**
71
- * Starts listening to {@link module:engine/view/document~Document#event:mousedown} and
72
- * {@link module:engine/view/document~Document#event:selectionChange} and puts the selection before/after a link node
73
- * if clicked at the beginning/ending of the link.
74
- *
75
- * The purpose of this action is to allow typing around the link node directly after a click.
76
- *
77
- * See https://github.com/ckeditor/ckeditor5/issues/1016.
78
- */
79
- private _enableClickingAfterLink;
80
- /**
81
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and {@link module:engine/model/model~Model#insertContent}
82
- * and checks whether typing over the link. If so, attributes of removed text are preserved and applied to the inserted text.
83
- *
84
- * The purpose of this action is to allow modifying a text without loosing the `linkHref` attribute (and other).
85
- *
86
- * See https://github.com/ckeditor/ckeditor5/issues/4762.
87
- */
88
- private _enableTypingOverLink;
89
- /**
90
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
91
- * removing a content right after the "linkHref" attribute.
92
- *
93
- * If so, the selection should not preserve the `linkHref` attribute. However, if
94
- * the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
95
- * the selection has the "linkHref" attribute due to overriden gravity (at the end), the `linkHref` attribute should stay untouched.
96
- *
97
- * The purpose of this action is to allow removing the link text and keep the selection outside the link.
98
- *
99
- * See https://github.com/ckeditor/ckeditor5/issues/7521.
63
+ * This is to ensure that there is no left-over link decorator attributes on the document selection that is no longer in a link.
100
64
  */
101
- private _handleDeleteContentAfterLink;
65
+ private _enableSelectionAttributesFixer;
102
66
  /**
103
67
  * Enables URL fixing on pasting.
104
68
  */
@@ -1,19 +1,18 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkediting
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { MouseObserver } from 'ckeditor5/src/engine';
10
- import { Input, TwoStepCaretMovement, inlineHighlight, findAttributeRange } from 'ckeditor5/src/typing';
11
- import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
12
- import { keyCodes, env } from 'ckeditor5/src/utils';
13
- import LinkCommand from './linkcommand';
14
- import UnlinkCommand from './unlinkcommand';
15
- import ManualDecorator from './utils/manualdecorator';
16
- import { createLinkElement, ensureSafeUrl, getLocalizedDecorators, normalizeDecorators, openLink, addLinkProtocolIfApplicable } from './utils';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { Input, TwoStepCaretMovement, inlineHighlight } from 'ckeditor5/src/typing.js';
10
+ import { ClipboardPipeline } from 'ckeditor5/src/clipboard.js';
11
+ import { keyCodes, env } from 'ckeditor5/src/utils.js';
12
+ import LinkCommand from './linkcommand.js';
13
+ import UnlinkCommand from './unlinkcommand.js';
14
+ import ManualDecorator from './utils/manualdecorator.js';
15
+ import { createLinkElement, ensureSafeUrl, getLocalizedDecorators, normalizeDecorators, openLink, addLinkProtocolIfApplicable } from './utils.js';
17
16
  import '../theme/link.css';
18
17
  const HIGHLIGHT_CLASS = 'ck-link_selected';
19
18
  const DECORATOR_AUTOMATIC = 'automatic';
@@ -45,6 +44,7 @@ export default class LinkEditing extends Plugin {
45
44
  constructor(editor) {
46
45
  super(editor);
47
46
  editor.config.define('link', {
47
+ allowCreatingEmptyLinks: false,
48
48
  addTargetToExternalLinks: false
49
49
  });
50
50
  }
@@ -89,14 +89,8 @@ export default class LinkEditing extends Plugin {
89
89
  inlineHighlight(editor, 'linkHref', 'a', HIGHLIGHT_CLASS);
90
90
  // Handle link following by CTRL+click or ALT+ENTER
91
91
  this._enableLinkOpen();
92
- // Change the attributes of the selection in certain situations after the link was inserted into the document.
93
- this._enableInsertContentSelectionAttributesFixer();
94
- // Handle a click at the beginning/end of a link element.
95
- this._enableClickingAfterLink();
96
- // Handle typing over the link.
97
- this._enableTypingOverLink();
98
- // Handle removing the content after the link element.
99
- this._handleDeleteContentAfterLink();
92
+ // Clears the DocumentSelection decorator attributes if the selection is no longer in a link (for example while using 2-SCM).
93
+ this._enableSelectionAttributesFixer();
100
94
  // Handle adding default protocol to pasted links.
101
95
  this._enableClipboardIntegration();
102
96
  }
@@ -225,244 +219,22 @@ export default class LinkEditing extends Plugin {
225
219
  });
226
220
  }
227
221
  /**
228
- * Starts listening to {@link module:engine/model/model~Model#event:insertContent} and corrects the model
229
- * selection attributes if the selection is at the end of a link after inserting the content.
222
+ * Watches the DocumentSelection attribute changes and removes link decorator attributes when the linkHref attribute is removed.
230
223
  *
231
- * The purpose of this action is to improve the overall UX because the user is no longer "trapped" by the
232
- * `linkHref` attribute of the selection and they can type a "clean" (`linkHref`–less) text right away.
233
- *
234
- * See https://github.com/ckeditor/ckeditor5/issues/6053.
224
+ * This is to ensure that there is no left-over link decorator attributes on the document selection that is no longer in a link.
235
225
  */
236
- _enableInsertContentSelectionAttributesFixer() {
226
+ _enableSelectionAttributesFixer() {
237
227
  const editor = this.editor;
238
228
  const model = editor.model;
239
229
  const selection = model.document.selection;
240
- this.listenTo(model, 'insertContent', () => {
241
- const nodeBefore = selection.anchor.nodeBefore;
242
- const nodeAfter = selection.anchor.nodeAfter;
243
- // NOTE: ↰ and ↱ represent the gravity of the selection.
244
- // The only truly valid case is:
245
- //
246
- // ↰
247
- // ...<$text linkHref="foo">INSERTED[]</$text>
248
- //
249
- // If the selection is not "trapped" by the `linkHref` attribute after inserting, there's nothing
250
- // to fix there.
251
- if (!selection.hasAttribute('linkHref')) {
252
- return;
253
- }
254
- // Filter out the following case where a link with the same href (e.g. <a href="foo">INSERTED</a>) is inserted
255
- // in the middle of an existing link:
256
- //
257
- // Before insertion:
258
- // ↰
259
- // <$text linkHref="foo">l[]ink</$text>
260
- //
261
- // Expected after insertion:
262
- // ↰
263
- // <$text linkHref="foo">lINSERTED[]ink</$text>
264
- //
265
- if (!nodeBefore) {
266
- return;
267
- }
268
- // Filter out the following case where the selection has the "linkHref" attribute because the
269
- // gravity is overridden and some text with another attribute (e.g. <b>INSERTED</b>) is inserted:
270
- //
271
- // Before insertion:
272
- //
273
- // ↱
274
- // <$text linkHref="foo">[]link</$text>
275
- //
276
- // Expected after insertion:
277
- //
278
- // ↱
279
- // <$text bold="true">INSERTED</$text><$text linkHref="foo">[]link</$text>
280
- //
281
- if (!nodeBefore.hasAttribute('linkHref')) {
282
- return;
283
- }
284
- // Filter out the following case where a link is a inserted in the middle (or before) another link
285
- // (different URLs, so they will not merge). In this (let's say weird) case, we can leave the selection
286
- // attributes as they are because the user will end up writing in one link or another anyway.
287
- //
288
- // Before insertion:
289
- //
290
- // ↰
291
- // <$text linkHref="foo">l[]ink</$text>
292
- //
293
- // Expected after insertion:
294
- //
295
- // ↰
296
- // <$text linkHref="foo">l</$text><$text linkHref="bar">INSERTED[]</$text><$text linkHref="foo">ink</$text>
297
- //
298
- if (nodeAfter && nodeAfter.hasAttribute('linkHref')) {
230
+ this.listenTo(selection, 'change:attribute', (evt, { attributeKeys }) => {
231
+ if (!attributeKeys.includes('linkHref') || selection.hasAttribute('linkHref')) {
299
232
  return;
300
233
  }
301
234
  model.change(writer => {
302
235
  removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
303
236
  });
304
- }, { priority: 'low' });
305
- }
306
- /**
307
- * Starts listening to {@link module:engine/view/document~Document#event:mousedown} and
308
- * {@link module:engine/view/document~Document#event:selectionChange} and puts the selection before/after a link node
309
- * if clicked at the beginning/ending of the link.
310
- *
311
- * The purpose of this action is to allow typing around the link node directly after a click.
312
- *
313
- * See https://github.com/ckeditor/ckeditor5/issues/1016.
314
- */
315
- _enableClickingAfterLink() {
316
- const editor = this.editor;
317
- const model = editor.model;
318
- editor.editing.view.addObserver(MouseObserver);
319
- let clicked = false;
320
- // Detect the click.
321
- this.listenTo(editor.editing.view.document, 'mousedown', () => {
322
- clicked = true;
323
237
  });
324
- // When the selection has changed...
325
- this.listenTo(editor.editing.view.document, 'selectionChange', () => {
326
- if (!clicked) {
327
- return;
328
- }
329
- // ...and it was caused by the click...
330
- clicked = false;
331
- const selection = model.document.selection;
332
- // ...and no text is selected...
333
- if (!selection.isCollapsed) {
334
- return;
335
- }
336
- // ...and clicked text is the link...
337
- if (!selection.hasAttribute('linkHref')) {
338
- return;
339
- }
340
- const position = selection.getFirstPosition();
341
- const linkRange = findAttributeRange(position, 'linkHref', selection.getAttribute('linkHref'), model);
342
- // ...check whether clicked start/end boundary of the link.
343
- // If so, remove the `linkHref` attribute.
344
- if (position.isTouching(linkRange.start) || position.isTouching(linkRange.end)) {
345
- model.change(writer => {
346
- removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
347
- });
348
- }
349
- });
350
- }
351
- /**
352
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and {@link module:engine/model/model~Model#insertContent}
353
- * and checks whether typing over the link. If so, attributes of removed text are preserved and applied to the inserted text.
354
- *
355
- * The purpose of this action is to allow modifying a text without loosing the `linkHref` attribute (and other).
356
- *
357
- * See https://github.com/ckeditor/ckeditor5/issues/4762.
358
- */
359
- _enableTypingOverLink() {
360
- const editor = this.editor;
361
- const view = editor.editing.view;
362
- // Selection attributes when started typing over the link.
363
- let selectionAttributes = null;
364
- // Whether pressed `Backspace` or `Delete`. If so, attributes should not be preserved.
365
- let deletedContent = false;
366
- // Detect pressing `Backspace` / `Delete`.
367
- this.listenTo(view.document, 'delete', () => {
368
- deletedContent = true;
369
- }, { priority: 'high' });
370
- // Listening to `model#deleteContent` allows detecting whether selected content was a link.
371
- // If so, before removing the element, we will copy its attributes.
372
- this.listenTo(editor.model, 'deleteContent', () => {
373
- const selection = editor.model.document.selection;
374
- // Copy attributes only if anything is selected.
375
- if (selection.isCollapsed) {
376
- return;
377
- }
378
- // When the content was deleted, do not preserve attributes.
379
- if (deletedContent) {
380
- deletedContent = false;
381
- return;
382
- }
383
- // Enabled only when typing.
384
- if (!isTyping(editor)) {
385
- return;
386
- }
387
- if (shouldCopyAttributes(editor.model)) {
388
- selectionAttributes = selection.getAttributes();
389
- }
390
- }, { priority: 'high' });
391
- // Listening to `model#insertContent` allows detecting the content insertion.
392
- // We want to apply attributes that were removed while typing over the link.
393
- this.listenTo(editor.model, 'insertContent', (evt, [element]) => {
394
- deletedContent = false;
395
- // Enabled only when typing.
396
- if (!isTyping(editor)) {
397
- return;
398
- }
399
- if (!selectionAttributes) {
400
- return;
401
- }
402
- editor.model.change(writer => {
403
- for (const [attribute, value] of selectionAttributes) {
404
- writer.setAttribute(attribute, value, element);
405
- }
406
- });
407
- selectionAttributes = null;
408
- }, { priority: 'high' });
409
- }
410
- /**
411
- * Starts listening to {@link module:engine/model/model~Model#deleteContent} and checks whether
412
- * removing a content right after the "linkHref" attribute.
413
- *
414
- * If so, the selection should not preserve the `linkHref` attribute. However, if
415
- * the {@link module:typing/twostepcaretmovement~TwoStepCaretMovement} plugin is active and
416
- * the selection has the "linkHref" attribute due to overriden gravity (at the end), the `linkHref` attribute should stay untouched.
417
- *
418
- * The purpose of this action is to allow removing the link text and keep the selection outside the link.
419
- *
420
- * See https://github.com/ckeditor/ckeditor5/issues/7521.
421
- */
422
- _handleDeleteContentAfterLink() {
423
- const editor = this.editor;
424
- const model = editor.model;
425
- const selection = model.document.selection;
426
- const view = editor.editing.view;
427
- // A flag whether attributes `linkHref` attribute should be preserved.
428
- let shouldPreserveAttributes = false;
429
- // A flag whether the `Backspace` key was pressed.
430
- let hasBackspacePressed = false;
431
- // Detect pressing `Backspace`.
432
- this.listenTo(view.document, 'delete', (evt, data) => {
433
- hasBackspacePressed = data.direction === 'backward';
434
- }, { priority: 'high' });
435
- // Before removing the content, check whether the selection is inside a link or at the end of link but with 2-SCM enabled.
436
- // If so, we want to preserve link attributes.
437
- this.listenTo(model, 'deleteContent', () => {
438
- // Reset the state.
439
- shouldPreserveAttributes = false;
440
- const position = selection.getFirstPosition();
441
- const linkHref = selection.getAttribute('linkHref');
442
- if (!linkHref) {
443
- return;
444
- }
445
- const linkRange = findAttributeRange(position, 'linkHref', linkHref, model);
446
- // Preserve `linkHref` attribute if the selection is in the middle of the link or
447
- // the selection is at the end of the link and 2-SCM is activated.
448
- shouldPreserveAttributes = linkRange.containsPosition(position) || linkRange.end.isEqual(position);
449
- }, { priority: 'high' });
450
- // After removing the content, check whether the current selection should preserve the `linkHref` attribute.
451
- this.listenTo(model, 'deleteContent', () => {
452
- // If didn't press `Backspace`.
453
- if (!hasBackspacePressed) {
454
- return;
455
- }
456
- hasBackspacePressed = false;
457
- // Disable the mechanism if inside a link (`<$text url="foo">F[]oo</$text>` or <$text url="foo">Foo[]</$text>`).
458
- if (shouldPreserveAttributes) {
459
- return;
460
- }
461
- // Use `model.enqueueChange()` in order to execute the callback at the end of the changes process.
462
- editor.model.enqueueChange(writer => {
463
- removeLinkAttributesFromSelection(writer, getLinkAttributesAllowedOnText(model.schema));
464
- });
465
- }, { priority: 'low' });
466
238
  }
467
239
  /**
468
240
  * Enables URL fixing on pasting.
@@ -498,46 +270,6 @@ function removeLinkAttributesFromSelection(writer, linkAttributes) {
498
270
  writer.removeSelectionAttribute(attribute);
499
271
  }
500
272
  }
501
- /**
502
- * Checks whether selection's attributes should be copied to the new inserted text.
503
- */
504
- function shouldCopyAttributes(model) {
505
- const selection = model.document.selection;
506
- const firstPosition = selection.getFirstPosition();
507
- const lastPosition = selection.getLastPosition();
508
- const nodeAtFirstPosition = firstPosition.nodeAfter;
509
- // The text link node does not exist...
510
- if (!nodeAtFirstPosition) {
511
- return false;
512
- }
513
- // ...or it isn't the text node...
514
- if (!nodeAtFirstPosition.is('$text')) {
515
- return false;
516
- }
517
- // ...or isn't the link.
518
- if (!nodeAtFirstPosition.hasAttribute('linkHref')) {
519
- return false;
520
- }
521
- // `textNode` = the position is inside the link element.
522
- // `nodeBefore` = the position is at the end of the link element.
523
- const nodeAtLastPosition = lastPosition.textNode || lastPosition.nodeBefore;
524
- // If both references the same node selection contains a single text node.
525
- if (nodeAtFirstPosition === nodeAtLastPosition) {
526
- return true;
527
- }
528
- // If nodes are not equal, maybe the link nodes has defined additional attributes inside.
529
- // First, we need to find the entire link range.
530
- const linkRange = findAttributeRange(firstPosition, 'linkHref', nodeAtFirstPosition.getAttribute('linkHref'), model);
531
- // Then we can check whether selected range is inside the found link range. If so, attributes should be preserved.
532
- return linkRange.containsRange(model.createRange(firstPosition, lastPosition), true);
533
- }
534
- /**
535
- * Checks whether provided changes were caused by typing.
536
- */
537
- function isTyping(editor) {
538
- const currentBatch = editor.model.change(writer => writer.batch);
539
- return currentBatch.isTyping;
540
- }
541
273
  /**
542
274
  * Returns an array containing names of the attributes allowed on `$text` that describes the link item.
543
275
  */
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkimage
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import LinkImageEditing from './linkimageediting';
10
- import LinkImageUI from './linkimageui';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import LinkImageEditing from './linkimageediting.js';
10
+ import LinkImageUI from './linkimageui.js';
11
11
  import '../theme/linkimage.css';
12
12
  /**
13
13
  * The `LinkImage` plugin.
package/src/linkimage.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkimage
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import LinkImageEditing from './linkimageediting';
10
- import LinkImageUI from './linkimageui';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import LinkImageEditing from './linkimageediting.js';
10
+ import LinkImageUI from './linkimageui.js';
11
11
  import '../theme/linkimage.css';
12
12
  /**
13
13
  * The `LinkImage` plugin.
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkimageediting
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import LinkEditing from './linkediting';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import LinkEditing from './linkediting.js';
10
10
  /**
11
11
  * The link image engine feature.
12
12
  *
@@ -25,7 +25,7 @@ export default class LinkImageEditing extends Plugin {
25
25
  /**
26
26
  * @inheritDoc
27
27
  */
28
- init(): void;
28
+ afterInit(): void;
29
29
  /**
30
30
  * Processes {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators} definitions and
31
31
  * attaches proper converters that will work when linking an image.`
@@ -1,14 +1,14 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
6
  * @module link/linkimageediting
7
7
  */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Matcher } from 'ckeditor5/src/engine';
10
- import { toMap } from 'ckeditor5/src/utils';
11
- import LinkEditing from './linkediting';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { Matcher } from 'ckeditor5/src/engine.js';
10
+ import { toMap } from 'ckeditor5/src/utils.js';
11
+ import LinkEditing from './linkediting.js';
12
12
  /**
13
13
  * The link image engine feature.
14
14
  *
@@ -31,7 +31,7 @@ export default class LinkImageEditing extends Plugin {
31
31
  /**
32
32
  * @inheritDoc
33
33
  */
34
- init() {
34
+ afterInit() {
35
35
  const editor = this.editor;
36
36
  const schema = editor.model.schema;
37
37
  if (editor.plugins.has('ImageBlockEditing')) {
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- import { Plugin } from 'ckeditor5/src/core';
6
- import LinkUI from './linkui';
7
- import LinkEditing from './linkediting';
5
+ import { Plugin } from 'ckeditor5/src/core.js';
6
+ import LinkUI from './linkui.js';
7
+ import LinkEditing from './linkediting.js';
8
8
  /**
9
9
  * The link image UI plugin.
10
10
  *