UNPKG

5.05 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4 */
5/**
6 * @module link/linkediting
7 */
8import { Plugin, type Editor } from 'ckeditor5/src/core';
9import { Input, TwoStepCaretMovement } from 'ckeditor5/src/typing';
10import { ClipboardPipeline } from 'ckeditor5/src/clipboard';
11import '../theme/link.css';
12/**
13 * The link engine feature.
14 *
15 * It introduces the `linkHref="url"` attribute in the model which renders to the view as a `<a href="url">` element
16 * as well as `'link'` and `'unlink'` commands.
17 */
18export default class LinkEditing extends Plugin {
19 /**
20 * @inheritDoc
21 */
22 static get pluginName(): "LinkEditing";
23 /**
24 * @inheritDoc
25 */
26 static get requires(): readonly [typeof TwoStepCaretMovement, typeof Input, typeof ClipboardPipeline];
27 /**
28 * @inheritDoc
29 */
30 constructor(editor: Editor);
31 /**
32 * @inheritDoc
33 */
34 init(): void;
35 /**
36 * Processes an array of configured {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators}
37 * and registers a {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher downcast dispatcher}
38 * for each one of them. Downcast dispatchers are obtained using the
39 * {@link module:link/utils/automaticdecorators~AutomaticDecorators#getDispatcher} method.
40 *
41 * **Note**: This method also activates the automatic external link decorator if enabled with
42 * {@link module:link/linkconfig~LinkConfig#addTargetToExternalLinks `config.link.addTargetToExternalLinks`}.
43 */
44 private _enableAutomaticDecorators;
45 /**
46 * Processes an array of configured {@link module:link/linkconfig~LinkDecoratorManualDefinition manual decorators},
47 * transforms them into {@link module:link/utils/manualdecorator~ManualDecorator} instances and stores them in the
48 * {@link module:link/linkcommand~LinkCommand#manualDecorators} collection (a model for manual decorators state).
49 *
50 * Also registers an {@link module:engine/conversion/downcasthelpers~DowncastHelpers#attributeToElement attribute-to-element}
51 * converter for each manual decorator and extends the {@link module:engine/model/schema~Schema model's schema}
52 * with adequate model attributes.
53 */
54 private _enableManualDecorators;
55 /**
56 * Attaches handlers for {@link module:engine/view/document~Document#event:enter} and
57 * {@link module:engine/view/document~Document#event:click} to enable link following.
58 */
59 private _enableLinkOpen;
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.
63 *
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.
100 */
101 private _handleDeleteContentAfterLink;
102 /**
103 * Enables URL fixing on pasting.
104 */
105 private _enableClipboardIntegration;
106}