@ckeditor/ckeditor5-link 47.6.1 → 48.0.0-alpha.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 (203) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +6 -6
  3. package/{src → dist}/autolink.d.ts +2 -2
  4. package/dist/index-editor.css +181 -105
  5. package/dist/index.css +169 -151
  6. package/dist/index.css.map +1 -1
  7. package/{src → dist}/index.d.ts +1 -1
  8. package/dist/index.js +8 -8
  9. package/dist/index.js.map +1 -1
  10. package/{src → dist}/link.d.ts +1 -1
  11. package/{src → dist}/linkcommand.d.ts +2 -2
  12. package/{src → dist}/linkconfig.d.ts +1 -1
  13. package/{src → dist}/linkediting.d.ts +3 -3
  14. package/{src → dist}/linkimage.d.ts +1 -1
  15. package/{src → dist}/linkimageediting.d.ts +3 -2
  16. package/{src → dist}/linkimageui.d.ts +3 -2
  17. package/{src → dist}/linkui.d.ts +2 -2
  18. package/{src → dist}/ui/linkbuttonview.d.ts +2 -2
  19. package/{src → dist}/ui/linkformview.d.ts +2 -4
  20. package/{src → dist}/ui/linkpreviewbuttonview.d.ts +2 -2
  21. package/{src → dist}/ui/linkpropertiesview.d.ts +2 -2
  22. package/{src → dist}/ui/linkprovideritemsview.d.ts +2 -2
  23. package/{src → dist}/unlinkcommand.d.ts +1 -1
  24. package/{src → dist}/utils/automaticdecorators.d.ts +2 -2
  25. package/{src → dist}/utils/manualdecorator.d.ts +4 -4
  26. package/{src → dist}/utils.d.ts +2 -2
  27. package/package.json +29 -52
  28. package/build/link.js +0 -5
  29. package/build/translations/af.js +0 -1
  30. package/build/translations/ar.js +0 -1
  31. package/build/translations/ast.js +0 -1
  32. package/build/translations/az.js +0 -1
  33. package/build/translations/be.js +0 -1
  34. package/build/translations/bg.js +0 -1
  35. package/build/translations/bn.js +0 -1
  36. package/build/translations/bs.js +0 -1
  37. package/build/translations/ca.js +0 -1
  38. package/build/translations/cs.js +0 -1
  39. package/build/translations/da.js +0 -1
  40. package/build/translations/de-ch.js +0 -1
  41. package/build/translations/de.js +0 -1
  42. package/build/translations/el.js +0 -1
  43. package/build/translations/en-au.js +0 -1
  44. package/build/translations/en-gb.js +0 -1
  45. package/build/translations/eo.js +0 -1
  46. package/build/translations/es-co.js +0 -1
  47. package/build/translations/es.js +0 -1
  48. package/build/translations/et.js +0 -1
  49. package/build/translations/eu.js +0 -1
  50. package/build/translations/fa.js +0 -1
  51. package/build/translations/fi.js +0 -1
  52. package/build/translations/fr.js +0 -1
  53. package/build/translations/gl.js +0 -1
  54. package/build/translations/gu.js +0 -1
  55. package/build/translations/he.js +0 -1
  56. package/build/translations/hi.js +0 -1
  57. package/build/translations/hr.js +0 -1
  58. package/build/translations/hu.js +0 -1
  59. package/build/translations/hy.js +0 -1
  60. package/build/translations/id.js +0 -1
  61. package/build/translations/it.js +0 -1
  62. package/build/translations/ja.js +0 -1
  63. package/build/translations/jv.js +0 -1
  64. package/build/translations/kk.js +0 -1
  65. package/build/translations/km.js +0 -1
  66. package/build/translations/kn.js +0 -1
  67. package/build/translations/ko.js +0 -1
  68. package/build/translations/ku.js +0 -1
  69. package/build/translations/lt.js +0 -1
  70. package/build/translations/lv.js +0 -1
  71. package/build/translations/ms.js +0 -1
  72. package/build/translations/nb.js +0 -1
  73. package/build/translations/ne.js +0 -1
  74. package/build/translations/nl.js +0 -1
  75. package/build/translations/no.js +0 -1
  76. package/build/translations/oc.js +0 -1
  77. package/build/translations/pl.js +0 -1
  78. package/build/translations/pt-br.js +0 -1
  79. package/build/translations/pt.js +0 -1
  80. package/build/translations/ro.js +0 -1
  81. package/build/translations/ru.js +0 -1
  82. package/build/translations/si.js +0 -1
  83. package/build/translations/sk.js +0 -1
  84. package/build/translations/sl.js +0 -1
  85. package/build/translations/sq.js +0 -1
  86. package/build/translations/sr-latn.js +0 -1
  87. package/build/translations/sr.js +0 -1
  88. package/build/translations/sv.js +0 -1
  89. package/build/translations/th.js +0 -1
  90. package/build/translations/ti.js +0 -1
  91. package/build/translations/tk.js +0 -1
  92. package/build/translations/tr.js +0 -1
  93. package/build/translations/tt.js +0 -1
  94. package/build/translations/ug.js +0 -1
  95. package/build/translations/uk.js +0 -1
  96. package/build/translations/ur.js +0 -1
  97. package/build/translations/uz.js +0 -1
  98. package/build/translations/vi.js +0 -1
  99. package/build/translations/zh-cn.js +0 -1
  100. package/build/translations/zh.js +0 -1
  101. package/lang/contexts.json +0 -16
  102. package/lang/translations/af.po +0 -68
  103. package/lang/translations/ar.po +0 -68
  104. package/lang/translations/ast.po +0 -68
  105. package/lang/translations/az.po +0 -68
  106. package/lang/translations/be.po +0 -68
  107. package/lang/translations/bg.po +0 -68
  108. package/lang/translations/bn.po +0 -70
  109. package/lang/translations/bs.po +0 -68
  110. package/lang/translations/ca.po +0 -68
  111. package/lang/translations/cs.po +0 -68
  112. package/lang/translations/da.po +0 -68
  113. package/lang/translations/de-ch.po +0 -68
  114. package/lang/translations/de.po +0 -68
  115. package/lang/translations/el.po +0 -68
  116. package/lang/translations/en-au.po +0 -68
  117. package/lang/translations/en-gb.po +0 -68
  118. package/lang/translations/en.po +0 -68
  119. package/lang/translations/eo.po +0 -68
  120. package/lang/translations/es-co.po +0 -68
  121. package/lang/translations/es.po +0 -68
  122. package/lang/translations/et.po +0 -68
  123. package/lang/translations/eu.po +0 -68
  124. package/lang/translations/fa.po +0 -68
  125. package/lang/translations/fi.po +0 -68
  126. package/lang/translations/fr.po +0 -68
  127. package/lang/translations/gl.po +0 -68
  128. package/lang/translations/gu.po +0 -68
  129. package/lang/translations/he.po +0 -68
  130. package/lang/translations/hi.po +0 -68
  131. package/lang/translations/hr.po +0 -68
  132. package/lang/translations/hu.po +0 -68
  133. package/lang/translations/hy.po +0 -68
  134. package/lang/translations/id.po +0 -68
  135. package/lang/translations/it.po +0 -68
  136. package/lang/translations/ja.po +0 -68
  137. package/lang/translations/jv.po +0 -68
  138. package/lang/translations/kk.po +0 -68
  139. package/lang/translations/km.po +0 -68
  140. package/lang/translations/kn.po +0 -68
  141. package/lang/translations/ko.po +0 -68
  142. package/lang/translations/ku.po +0 -68
  143. package/lang/translations/lt.po +0 -68
  144. package/lang/translations/lv.po +0 -68
  145. package/lang/translations/ms.po +0 -68
  146. package/lang/translations/nb.po +0 -68
  147. package/lang/translations/ne.po +0 -68
  148. package/lang/translations/nl.po +0 -68
  149. package/lang/translations/no.po +0 -68
  150. package/lang/translations/oc.po +0 -68
  151. package/lang/translations/pl.po +0 -68
  152. package/lang/translations/pt-br.po +0 -68
  153. package/lang/translations/pt.po +0 -68
  154. package/lang/translations/ro.po +0 -68
  155. package/lang/translations/ru.po +0 -68
  156. package/lang/translations/si.po +0 -68
  157. package/lang/translations/sk.po +0 -68
  158. package/lang/translations/sl.po +0 -68
  159. package/lang/translations/sq.po +0 -68
  160. package/lang/translations/sr-latn.po +0 -68
  161. package/lang/translations/sr.po +0 -68
  162. package/lang/translations/sv.po +0 -68
  163. package/lang/translations/th.po +0 -68
  164. package/lang/translations/ti.po +0 -68
  165. package/lang/translations/tk.po +0 -68
  166. package/lang/translations/tr.po +0 -68
  167. package/lang/translations/tt.po +0 -68
  168. package/lang/translations/ug.po +0 -68
  169. package/lang/translations/uk.po +0 -68
  170. package/lang/translations/ur.po +0 -68
  171. package/lang/translations/uz.po +0 -68
  172. package/lang/translations/vi.po +0 -68
  173. package/lang/translations/zh-cn.po +0 -68
  174. package/lang/translations/zh.po +0 -68
  175. package/src/augmentation.js +0 -5
  176. package/src/autolink.js +0 -307
  177. package/src/index.js +0 -25
  178. package/src/link.js +0 -37
  179. package/src/linkcommand.js +0 -431
  180. package/src/linkconfig.js +0 -5
  181. package/src/linkediting.js +0 -402
  182. package/src/linkimage.js +0 -37
  183. package/src/linkimageediting.js +0 -264
  184. package/src/linkimageui.js +0 -102
  185. package/src/linkui.js +0 -1072
  186. package/src/ui/linkbuttonview.js +0 -54
  187. package/src/ui/linkformview.js +0 -302
  188. package/src/ui/linkpreviewbuttonview.js +0 -43
  189. package/src/ui/linkpropertiesview.js +0 -170
  190. package/src/ui/linkprovideritemsview.js +0 -207
  191. package/src/unlinkcommand.js +0 -66
  192. package/src/utils/automaticdecorators.js +0 -181
  193. package/src/utils/conflictingdecorators.js +0 -80
  194. package/src/utils/manualdecorator.js +0 -69
  195. package/src/utils.js +0 -157
  196. package/theme/link.css +0 -10
  197. package/theme/linkform.css +0 -24
  198. package/theme/linkimage.css +0 -16
  199. package/theme/linkproperties.css +0 -4
  200. package/theme/linkprovideritems.css +0 -18
  201. package/theme/linktoolbar.css +0 -12
  202. /package/{src → dist}/augmentation.d.ts +0 -0
  203. /package/{src → dist}/utils/conflictingdecorators.d.ts +0 -0
@@ -1,264 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module link/linkimageediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { Matcher } from 'ckeditor5/src/engine.js';
10
- import { priorities, toMap } from 'ckeditor5/src/utils.js';
11
- import { LinkEditing } from './linkediting.js';
12
- /**
13
- * The link image engine feature.
14
- *
15
- * It accepts the `linkHref="url"` attribute in the model for the {@link module:image/image~Image `<imageBlock>`} element
16
- * which allows linking images.
17
- */
18
- export class LinkImageEditing extends Plugin {
19
- /**
20
- * @inheritDoc
21
- */
22
- static get requires() {
23
- return ['ImageEditing', 'ImageUtils', LinkEditing];
24
- }
25
- /**
26
- * @inheritDoc
27
- */
28
- static get pluginName() {
29
- return 'LinkImageEditing';
30
- }
31
- /**
32
- * @inheritDoc
33
- */
34
- static get isOfficialPlugin() {
35
- return true;
36
- }
37
- /**
38
- * @inheritDoc
39
- */
40
- afterInit() {
41
- const editor = this.editor;
42
- const schema = editor.model.schema;
43
- if (editor.plugins.has('ImageBlockEditing')) {
44
- schema.extend('imageBlock', { allowAttributes: ['linkHref'] });
45
- }
46
- editor.conversion.for('upcast').add(upcastLink(editor));
47
- editor.conversion.for('downcast').add(downcastImageLink(editor));
48
- // Definitions for decorators are provided by the `link` command and the `LinkEditing` plugin.
49
- this._enableAutomaticDecorators();
50
- this._enableManualDecorators();
51
- }
52
- /**
53
- * Processes {@link module:link/linkconfig~LinkDecoratorAutomaticDefinition automatic decorators} definitions and
54
- * attaches proper converters that will work when linking an image.`
55
- */
56
- _enableAutomaticDecorators() {
57
- const editor = this.editor;
58
- const command = editor.commands.get('link');
59
- const automaticDecorators = command.automaticDecorators;
60
- if (automaticDecorators.length) {
61
- editor.conversion.for('downcast').add(automaticDecorators.getDispatcherForLinkedImage());
62
- }
63
- }
64
- /**
65
- * Processes transformed {@link module:link/utils/manualdecorator~LinkManualDecorator} instances and attaches proper converters
66
- * that will work when linking an image.
67
- */
68
- _enableManualDecorators() {
69
- const editor = this.editor;
70
- const command = editor.commands.get('link');
71
- for (const decorator of command.manualDecorators) {
72
- if (editor.plugins.has('ImageBlockEditing')) {
73
- editor.model.schema.extend('imageBlock', { allowAttributes: decorator.id });
74
- }
75
- if (editor.plugins.has('ImageInlineEditing')) {
76
- editor.model.schema.extend('imageInline', { allowAttributes: decorator.id });
77
- }
78
- editor.conversion.for('downcast').add(downcastImageLinkManualDecorator(decorator));
79
- editor.conversion.for('upcast').add(upcastImageLinkManualDecorator(editor, decorator));
80
- }
81
- }
82
- }
83
- /**
84
- * Returns a converter for linked block images that consumes the "href" attribute
85
- * if a link contains an image.
86
- *
87
- * @param editor The editor instance.
88
- */
89
- function upcastLink(editor) {
90
- const isImageInlinePluginLoaded = editor.plugins.has('ImageInlineEditing');
91
- const imageUtils = editor.plugins.get('ImageUtils');
92
- return dispatcher => {
93
- dispatcher.on('element:a', (evt, data, conversionApi) => {
94
- const viewLink = data.viewItem;
95
- const imageInLink = imageUtils.findViewImgElement(viewLink);
96
- if (!imageInLink) {
97
- return;
98
- }
99
- const blockImageView = imageInLink.findAncestor(element => imageUtils.isBlockImageView(element));
100
- // There are four possible cases to consider here
101
- //
102
- // 1. A "root > ... > figure.image > a > img" structure.
103
- // 2. A "root > ... > figure.image > a > picture > img" structure.
104
- // 3. A "root > ... > block > a > img" structure.
105
- // 4. A "root > ... > block > a > picture > img" structure.
106
- //
107
- // but the last 2 cases should only be considered by this converter when the inline image plugin
108
- // is NOT loaded in the editor (because otherwise, that would be a plain, linked inline image).
109
- if (isImageInlinePluginLoaded && !blockImageView) {
110
- return;
111
- }
112
- // There's an image inside an <a> element - we consume it so it won't be picked up by the Link plugin.
113
- const consumableAttributes = { attributes: ['href'] };
114
- // Consume the `href` attribute so the default one will not convert it to $text attribute.
115
- if (!conversionApi.consumable.test(viewLink, consumableAttributes)) {
116
- // Might be consumed by something else - i.e. other converter with priority=highest - a standard check.
117
- return;
118
- }
119
- const linkHref = viewLink.getAttribute('href');
120
- // A full definition of the image feature.
121
- // figure > a > img: parent of the view link element is an image element (figure).
122
- const modelElement = data.modelCursor.parent;
123
- if (modelElement.is('element', 'imageBlock')) {
124
- // Set the linkHref attribute from link element on model image element.
125
- conversionApi.writer.setAttribute('linkHref', linkHref, modelElement);
126
- conversionApi.consumable.consume(viewLink, consumableAttributes);
127
- }
128
- }, { priority: 'high' });
129
- // Using the same priority that `upcastImageLinkManualDecorator()` converter guarantees
130
- // that manual decorators will decorate the proper element.
131
- };
132
- }
133
- /**
134
- * Creates a converter that adds `<a>` to linked block image view elements.
135
- */
136
- function downcastImageLink(editor) {
137
- const imageUtils = editor.plugins.get('ImageUtils');
138
- return dispatcher => {
139
- dispatcher.on('attribute:linkHref:imageBlock', (evt, data, conversionApi) => {
140
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
141
- return;
142
- }
143
- // The image will be already converted - so it will be present in the view.
144
- const viewFigure = conversionApi.mapper.toViewElement(data.item);
145
- const writer = conversionApi.writer;
146
- // But we need to check whether the link element exists.
147
- const linkInImage = Array.from(viewFigure.getChildren())
148
- .find((child) => child.is('element', 'a'));
149
- const viewImage = imageUtils.findViewImgElement(viewFigure);
150
- // <picture>...<img/></picture> or <img/>
151
- const viewImgOrPicture = viewImage.parent.is('element', 'picture') ? viewImage.parent : viewImage;
152
- // If so, update the attribute if it's defined or remove the entire link if the attribute is empty.
153
- if (linkInImage) {
154
- if (data.attributeNewValue) {
155
- writer.setAttribute('href', data.attributeNewValue, linkInImage);
156
- }
157
- else {
158
- writer.move(writer.createRangeOn(viewImgOrPicture), writer.createPositionAt(viewFigure, 0));
159
- writer.remove(linkInImage);
160
- }
161
- }
162
- else {
163
- // But if it does not exist. Let's wrap already converted image by newly created link element.
164
- // 1. Create an empty link element.
165
- const linkElement = writer.createContainerElement('a', { href: data.attributeNewValue });
166
- // 2. Insert link inside the associated image.
167
- writer.insert(writer.createPositionAt(viewFigure, 0), linkElement);
168
- // 3. Move the image to the link.
169
- writer.move(writer.createRangeOn(viewImgOrPicture), writer.createPositionAt(linkElement, 0));
170
- }
171
- }, { priority: 'high' });
172
- };
173
- }
174
- /**
175
- * Returns a converter that decorates the `<a>` element when the image is the link label.
176
- */
177
- function downcastImageLinkManualDecorator(decorator) {
178
- return dispatcher => {
179
- const createConverter = (isApplyingConverter) => {
180
- return (evt, data, conversionApi) => {
181
- const viewFigure = conversionApi.mapper.toViewElement(data.item);
182
- const linkInImage = Array.from(viewFigure.getChildren())
183
- .find((child) => child.is('element', 'a'));
184
- // The <a> element was removed by the time this converter is executed.
185
- // It may happen when the base `linkHref` and decorator attributes are removed
186
- // at the same time (see #8401).
187
- if (!linkInImage) {
188
- return;
189
- }
190
- // Handle deactivated manual decorator.
191
- if (!isApplyingConverter && data.attributeOldValue) {
192
- for (const [key, val] of toMap(decorator.attributes)) {
193
- conversionApi.writer.removeAttribute(key, val, linkInImage);
194
- }
195
- if (decorator.classes) {
196
- conversionApi.writer.removeClass(decorator.classes, linkInImage);
197
- }
198
- for (const key in decorator.styles) {
199
- conversionApi.writer.removeStyle(key, linkInImage);
200
- }
201
- }
202
- // Handle activated manual decorator.
203
- if (isApplyingConverter && data.attributeNewValue) {
204
- for (const [key, val] of toMap(decorator.attributes)) {
205
- conversionApi.writer.setAttribute(key, val, false, linkInImage);
206
- }
207
- if (decorator.classes) {
208
- conversionApi.writer.addClass(decorator.classes, linkInImage);
209
- }
210
- for (const key in decorator.styles) {
211
- conversionApi.writer.setStyle(key, decorator.styles[key], linkInImage);
212
- }
213
- }
214
- };
215
- };
216
- dispatcher.on(`attribute:${decorator.id}:imageBlock`, createConverter(false), {
217
- priority: priorities.high - 1
218
- });
219
- // Apply decorators after all automatic and manual decorators are removed so removing one decorator
220
- // won't strip part of the other decorator's attributes, classes or styles.
221
- dispatcher.on(`attribute:${decorator.id}:imageBlock`, createConverter(true), {
222
- priority: priorities.high - 2
223
- });
224
- };
225
- }
226
- /**
227
- * Returns a converter that checks whether manual decorators should be applied to the link.
228
- */
229
- function upcastImageLinkManualDecorator(editor, decorator) {
230
- const isImageInlinePluginLoaded = editor.plugins.has('ImageInlineEditing');
231
- const imageUtils = editor.plugins.get('ImageUtils');
232
- return dispatcher => {
233
- dispatcher.on('element:a', (evt, data, conversionApi) => {
234
- const viewLink = data.viewItem;
235
- const imageInLink = imageUtils.findViewImgElement(viewLink);
236
- // We need to check whether an image is inside a link because the converter handles
237
- // only manual decorators for linked images. See #7975.
238
- if (!imageInLink) {
239
- return;
240
- }
241
- const blockImageView = imageInLink.findAncestor(element => imageUtils.isBlockImageView(element));
242
- if (isImageInlinePluginLoaded && !blockImageView) {
243
- return;
244
- }
245
- const matcher = new Matcher(decorator._createPattern());
246
- const result = matcher.match(viewLink);
247
- // The link element does not have required attributes or/and proper values.
248
- if (!result) {
249
- return;
250
- }
251
- // Check whether we can consume those attributes.
252
- if (!conversionApi.consumable.test(viewLink, result.match)) {
253
- return;
254
- }
255
- // At this stage we can assume that we have the `<imageBlock>` elements in model cursor or range.
256
- const modelElement = data.modelCursor.parent;
257
- if (modelElement?.is('element', 'imageBlock')) {
258
- conversionApi.writer.setAttribute(decorator.id, true, modelElement);
259
- conversionApi.consumable.consume(viewLink, result.match);
260
- }
261
- }, { priority: 'high' });
262
- // Using the same priority that `upcastLink()` converter guarantees that the linked image was properly converted.
263
- };
264
- }
@@ -1,102 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
- */
5
- /**
6
- * @module link/linkimageui
7
- */
8
- import { ButtonView } from 'ckeditor5/src/ui.js';
9
- import { Plugin } from 'ckeditor5/src/core.js';
10
- import { IconLink } from 'ckeditor5/src/icons.js';
11
- import { LinkUI } from './linkui.js';
12
- import { LinkEditing } from './linkediting.js';
13
- import { LINK_KEYSTROKE } from './utils.js';
14
- /**
15
- * The link image UI plugin.
16
- *
17
- * This plugin provides the `'linkImage'` button that can be displayed in the {@link module:image/imagetoolbar~ImageToolbar}.
18
- * It can be used to wrap images in links.
19
- */
20
- export class LinkImageUI extends Plugin {
21
- /**
22
- * @inheritDoc
23
- */
24
- static get requires() {
25
- return [LinkEditing, LinkUI, 'ImageBlockEditing'];
26
- }
27
- /**
28
- * @inheritDoc
29
- */
30
- static get pluginName() {
31
- return 'LinkImageUI';
32
- }
33
- /**
34
- * @inheritDoc
35
- */
36
- static get isOfficialPlugin() {
37
- return true;
38
- }
39
- /**
40
- * @inheritDoc
41
- */
42
- init() {
43
- const editor = this.editor;
44
- const viewDocument = editor.editing.view.document;
45
- this.listenTo(viewDocument, 'click', (evt, data) => {
46
- if (this._isSelectedLinkedImage(editor.model.document.selection)) {
47
- // Prevent browser navigation when clicking a linked image.
48
- data.preventDefault();
49
- // Block the `LinkUI` plugin when an image was clicked.
50
- // In such a case, we'd like to display the image toolbar.
51
- evt.stop();
52
- }
53
- }, { priority: 'high' });
54
- this._createToolbarLinkImageButton();
55
- }
56
- /**
57
- * Creates a `LinkImageUI` button view.
58
- *
59
- * Clicking this button shows a {@link module:link/linkui~LinkUI#_balloon} attached to the selection.
60
- * When an image is already linked, the view shows {@link module:link/linkui~LinkUI#toolbarView} or
61
- * {@link module:link/linkui~LinkUI#formView} if it is not.
62
- */
63
- _createToolbarLinkImageButton() {
64
- const editor = this.editor;
65
- const t = editor.t;
66
- editor.ui.componentFactory.add('linkImage', locale => {
67
- const button = new ButtonView(locale);
68
- const plugin = editor.plugins.get('LinkUI');
69
- const linkCommand = editor.commands.get('link');
70
- button.set({
71
- isEnabled: true,
72
- label: t('Link image'),
73
- icon: IconLink,
74
- keystroke: LINK_KEYSTROKE,
75
- tooltip: true,
76
- isToggleable: true
77
- });
78
- // Bind button to the command.
79
- button.bind('isEnabled').to(linkCommand, 'isEnabled');
80
- button.bind('isOn').to(linkCommand, 'value', value => !!value);
81
- // Show the actionsView or formView (both from LinkUI) on button click depending on whether the image is linked already.
82
- this.listenTo(button, 'execute', () => {
83
- if (this._isSelectedLinkedImage(editor.model.document.selection)) {
84
- plugin._addToolbarView();
85
- }
86
- else {
87
- plugin._showUI(true);
88
- }
89
- });
90
- return button;
91
- });
92
- }
93
- /**
94
- * Returns true if a linked image (either block or inline) is the only selected element
95
- * in the model document.
96
- */
97
- _isSelectedLinkedImage(selection) {
98
- const selectedModelElement = selection.getSelectedElement();
99
- const imageUtils = this.editor.plugins.get('ImageUtils');
100
- return imageUtils.isImage(selectedModelElement) && selectedModelElement.hasAttribute('linkHref');
101
- }
102
- }