UNPKG

5.84 kBTypeScriptView Raw
1/**
2 * @license Copyright (c) 2003-2024, 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/linkui
7 */
8import { Plugin } from 'ckeditor5/src/core.js';
9import { ContextualBalloon, type ViewWithCssTransitionDisabler } from 'ckeditor5/src/ui.js';
10import LinkFormView from './ui/linkformview.js';
11import LinkActionsView from './ui/linkactionsview.js';
12/**
13 * The link UI plugin. It introduces the `'link'` and `'unlink'` buttons and support for the <kbd>Ctrl+K</kbd> keystroke.
14 *
15 * It uses the
16 * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon plugin}.
17 */
18export default class LinkUI extends Plugin {
19 /**
20 * The actions view displayed inside of the balloon.
21 */
22 actionsView: LinkActionsView | null;
23 /**
24 * The form view displayed inside the balloon.
25 */
26 formView: LinkFormView & ViewWithCssTransitionDisabler | null;
27 /**
28 * The contextual balloon plugin instance.
29 */
30 private _balloon;
31 /**
32 * @inheritDoc
33 */
34 static get requires(): readonly [typeof ContextualBalloon];
35 /**
36 * @inheritDoc
37 */
38 static get pluginName(): "LinkUI";
39 /**
40 * @inheritDoc
41 */
42 init(): void;
43 /**
44 * @inheritDoc
45 */
46 destroy(): void;
47 /**
48 * Creates views.
49 */
50 private _createViews;
51 /**
52 * Creates the {@link module:link/ui/linkactionsview~LinkActionsView} instance.
53 */
54 private _createActionsView;
55 /**
56 * Creates the {@link module:link/ui/linkformview~LinkFormView} instance.
57 */
58 private _createFormView;
59 /**
60 * Creates a toolbar Link button. Clicking this button will show
61 * a {@link #_balloon} attached to the selection.
62 */
63 private _createToolbarLinkButton;
64 /**
65 * Creates a button for link command to use either in toolbar or in menu bar.
66 */
67 private _createButton;
68 /**
69 * Attaches actions that control whether the balloon panel containing the
70 * {@link #formView} should be displayed.
71 */
72 private _enableBalloonActivators;
73 /**
74 * Attaches actions that control whether the balloon panel containing the
75 * {@link #formView} is visible or not.
76 */
77 private _enableUserBalloonInteractions;
78 /**
79 * Adds the {@link #actionsView} to the {@link #_balloon}.
80 *
81 * @internal
82 */
83 _addActionsView(): void;
84 /**
85 * Adds the {@link #formView} to the {@link #_balloon}.
86 */
87 private _addFormView;
88 /**
89 * Closes the form view. Decides whether the balloon should be hidden completely or if the action view should be shown. This is
90 * decided upon the link command value (which has a value if the document selection is in the link).
91 *
92 * Additionally, if any {@link module:link/linkconfig~LinkConfig#decorators} are defined in the editor configuration, the state of
93 * switch buttons responsible for manual decorator handling is restored.
94 */
95 private _closeFormView;
96 /**
97 * Removes the {@link #formView} from the {@link #_balloon}.
98 */
99 private _removeFormView;
100 /**
101 * Shows the correct UI type. It is either {@link #formView} or {@link #actionsView}.
102 *
103 * @internal
104 */
105 _showUI(forceVisible?: boolean): void;
106 /**
107 * Removes the {@link #formView} from the {@link #_balloon}.
108 *
109 * See {@link #_addFormView}, {@link #_addActionsView}.
110 */
111 private _hideUI;
112 /**
113 * Makes the UI react to the {@link module:ui/editorui/editorui~EditorUI#event:update} event to
114 * reposition itself when the editor UI should be refreshed.
115 *
116 * See: {@link #_hideUI} to learn when the UI stops reacting to the `update` event.
117 */
118 private _startUpdatingUI;
119 /**
120 * Returns `true` when {@link #formView} is in the {@link #_balloon}.
121 */
122 private get _isFormInPanel();
123 /**
124 * Returns `true` when {@link #actionsView} is in the {@link #_balloon}.
125 */
126 private get _areActionsInPanel();
127 /**
128 * Returns `true` when {@link #actionsView} is in the {@link #_balloon} and it is
129 * currently visible.
130 */
131 private get _areActionsVisible();
132 /**
133 * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon}.
134 */
135 private get _isUIInPanel();
136 /**
137 * Returns `true` when {@link #actionsView} or {@link #formView} is in the {@link #_balloon} and it is
138 * currently visible.
139 */
140 private get _isUIVisible();
141 /**
142 * Returns positioning options for the {@link #_balloon}. They control the way the balloon is attached
143 * to the target element or selection.
144 *
145 * If the selection is collapsed and inside a link element, the panel will be attached to the
146 * entire link element. Otherwise, it will be attached to the selection.
147 */
148 private _getBalloonPositionData;
149 /**
150 * Returns the link {@link module:engine/view/attributeelement~AttributeElement} under
151 * the {@link module:engine/view/document~Document editing view's} selection or `null`
152 * if there is none.
153 *
154 * **Note**: For a non–collapsed selection, the link element is returned when **fully**
155 * selected and the **only** element within the selection boundaries, or when
156 * a linked widget is selected.
157 */
158 private _getSelectedLinkElement;
159 /**
160 * Displays a fake visual selection when the contextual balloon is displayed.
161 *
162 * This adds a 'link-ui' marker into the document that is rendered as a highlight on selected text fragment.
163 */
164 private _showFakeVisualSelection;
165 /**
166 * Hides the fake visual selection created in {@link #_showFakeVisualSelection}.
167 */
168 private _hideFakeVisualSelection;
169}