@ckeditor/ckeditor5-image 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 (260) hide show
  1. package/CHANGELOG.md +25 -25
  2. package/LICENSE.md +1 -1
  3. package/build/image.js +3 -3
  4. package/build/translations/ar.js +1 -1
  5. package/build/translations/ast.js +1 -1
  6. package/build/translations/az.js +1 -1
  7. package/build/translations/bg.js +1 -1
  8. package/build/translations/bn.js +1 -1
  9. package/build/translations/bs.js +1 -1
  10. package/build/translations/ca.js +1 -1
  11. package/build/translations/cs.js +1 -1
  12. package/build/translations/da.js +1 -1
  13. package/build/translations/de-ch.js +1 -1
  14. package/build/translations/de.js +1 -1
  15. package/build/translations/el.js +1 -1
  16. package/build/translations/en-au.js +1 -1
  17. package/build/translations/en-gb.js +1 -1
  18. package/build/translations/eo.js +1 -1
  19. package/build/translations/es.js +1 -1
  20. package/build/translations/et.js +1 -1
  21. package/build/translations/eu.js +1 -1
  22. package/build/translations/fa.js +1 -1
  23. package/build/translations/fi.js +1 -1
  24. package/build/translations/fr.js +1 -1
  25. package/build/translations/gl.js +1 -1
  26. package/build/translations/he.js +1 -1
  27. package/build/translations/hi.js +1 -1
  28. package/build/translations/hr.js +1 -1
  29. package/build/translations/hu.js +1 -1
  30. package/build/translations/id.js +1 -1
  31. package/build/translations/it.js +1 -1
  32. package/build/translations/ja.js +1 -1
  33. package/build/translations/jv.js +1 -1
  34. package/build/translations/km.js +1 -1
  35. package/build/translations/kn.js +1 -1
  36. package/build/translations/ko.js +1 -1
  37. package/build/translations/ku.js +1 -1
  38. package/build/translations/lt.js +1 -1
  39. package/build/translations/lv.js +1 -1
  40. package/build/translations/ms.js +1 -1
  41. package/build/translations/nb.js +1 -1
  42. package/build/translations/ne.js +1 -1
  43. package/build/translations/nl.js +1 -1
  44. package/build/translations/no.js +1 -1
  45. package/build/translations/pl.js +1 -1
  46. package/build/translations/pt-br.js +1 -1
  47. package/build/translations/pt.js +1 -1
  48. package/build/translations/ro.js +1 -1
  49. package/build/translations/ru.js +1 -1
  50. package/build/translations/si.js +1 -1
  51. package/build/translations/sk.js +1 -1
  52. package/build/translations/sq.js +1 -1
  53. package/build/translations/sr-latn.js +1 -1
  54. package/build/translations/sr.js +1 -1
  55. package/build/translations/sv.js +1 -1
  56. package/build/translations/th.js +1 -1
  57. package/build/translations/tk.js +1 -1
  58. package/build/translations/tr.js +1 -1
  59. package/build/translations/tt.js +1 -1
  60. package/build/translations/ug.js +1 -1
  61. package/build/translations/uk.js +1 -1
  62. package/build/translations/ur.js +1 -1
  63. package/build/translations/uz.js +1 -1
  64. package/build/translations/vi.js +1 -1
  65. package/build/translations/zh-cn.js +1 -1
  66. package/build/translations/zh.js +1 -1
  67. package/ckeditor5-metadata.json +3 -3
  68. package/lang/contexts.json +5 -0
  69. package/lang/translations/ar.po +21 -1
  70. package/lang/translations/ast.po +21 -1
  71. package/lang/translations/az.po +21 -1
  72. package/lang/translations/bg.po +21 -1
  73. package/lang/translations/bn.po +21 -1
  74. package/lang/translations/bs.po +21 -1
  75. package/lang/translations/ca.po +21 -1
  76. package/lang/translations/cs.po +21 -1
  77. package/lang/translations/da.po +21 -1
  78. package/lang/translations/de-ch.po +21 -1
  79. package/lang/translations/de.po +21 -1
  80. package/lang/translations/el.po +21 -1
  81. package/lang/translations/en-au.po +21 -1
  82. package/lang/translations/en-gb.po +21 -1
  83. package/lang/translations/en.po +21 -1
  84. package/lang/translations/eo.po +21 -1
  85. package/lang/translations/es.po +21 -1
  86. package/lang/translations/et.po +21 -1
  87. package/lang/translations/eu.po +21 -1
  88. package/lang/translations/fa.po +21 -1
  89. package/lang/translations/fi.po +21 -1
  90. package/lang/translations/fr.po +21 -1
  91. package/lang/translations/gl.po +21 -1
  92. package/lang/translations/he.po +21 -1
  93. package/lang/translations/hi.po +21 -1
  94. package/lang/translations/hr.po +21 -1
  95. package/lang/translations/hu.po +21 -1
  96. package/lang/translations/id.po +21 -1
  97. package/lang/translations/it.po +21 -1
  98. package/lang/translations/ja.po +21 -1
  99. package/lang/translations/jv.po +21 -1
  100. package/lang/translations/km.po +21 -1
  101. package/lang/translations/kn.po +21 -1
  102. package/lang/translations/ko.po +21 -1
  103. package/lang/translations/ku.po +21 -1
  104. package/lang/translations/lt.po +21 -1
  105. package/lang/translations/lv.po +21 -1
  106. package/lang/translations/ms.po +21 -1
  107. package/lang/translations/nb.po +21 -1
  108. package/lang/translations/ne.po +21 -1
  109. package/lang/translations/nl.po +21 -1
  110. package/lang/translations/no.po +21 -1
  111. package/lang/translations/pl.po +21 -1
  112. package/lang/translations/pt-br.po +21 -1
  113. package/lang/translations/pt.po +21 -1
  114. package/lang/translations/ro.po +21 -1
  115. package/lang/translations/ru.po +21 -1
  116. package/lang/translations/si.po +21 -1
  117. package/lang/translations/sk.po +21 -1
  118. package/lang/translations/sq.po +21 -1
  119. package/lang/translations/sr-latn.po +21 -1
  120. package/lang/translations/sr.po +21 -1
  121. package/lang/translations/sv.po +21 -1
  122. package/lang/translations/th.po +21 -1
  123. package/lang/translations/tk.po +21 -1
  124. package/lang/translations/tr.po +21 -1
  125. package/lang/translations/tt.po +21 -1
  126. package/lang/translations/ug.po +22 -2
  127. package/lang/translations/uk.po +21 -1
  128. package/lang/translations/ur.po +21 -1
  129. package/lang/translations/uz.po +21 -1
  130. package/lang/translations/vi.po +21 -1
  131. package/lang/translations/zh-cn.po +21 -1
  132. package/lang/translations/zh.po +21 -1
  133. package/package.json +4 -3
  134. package/src/augmentation.d.ts +1 -1
  135. package/src/augmentation.js +1 -1
  136. package/src/autoimage.d.ts +6 -6
  137. package/src/autoimage.js +8 -8
  138. package/src/image/converters.d.ts +3 -3
  139. package/src/image/converters.js +2 -2
  140. package/src/image/imageblockediting.d.ts +7 -7
  141. package/src/image/imageblockediting.js +11 -11
  142. package/src/image/imageediting.d.ts +3 -3
  143. package/src/image/imageediting.js +6 -6
  144. package/src/image/imageinlineediting.d.ts +7 -7
  145. package/src/image/imageinlineediting.js +11 -11
  146. package/src/image/imageloadobserver.d.ts +2 -2
  147. package/src/image/imageloadobserver.js +2 -2
  148. package/src/image/imageplaceholder.d.ts +3 -3
  149. package/src/image/imageplaceholder.js +4 -4
  150. package/src/image/imagetypecommand.d.ts +3 -3
  151. package/src/image/imagetypecommand.js +2 -2
  152. package/src/image/insertimagecommand.d.ts +3 -3
  153. package/src/image/insertimagecommand.js +3 -3
  154. package/src/image/replaceimagesourcecommand.d.ts +3 -3
  155. package/src/image/replaceimagesourcecommand.js +2 -2
  156. package/src/image/ui/utils.d.ts +3 -3
  157. package/src/image/ui/utils.js +2 -2
  158. package/src/image/utils.d.ts +3 -3
  159. package/src/image/utils.js +2 -2
  160. package/src/image.d.ts +4 -4
  161. package/src/image.js +4 -4
  162. package/src/imageblock.d.ts +7 -6
  163. package/src/imageblock.js +7 -6
  164. package/src/imagecaption/imagecaptionediting.d.ts +5 -5
  165. package/src/imagecaption/imagecaptionediting.js +7 -7
  166. package/src/imagecaption/imagecaptionui.d.ts +3 -3
  167. package/src/imagecaption/imagecaptionui.js +4 -4
  168. package/src/imagecaption/imagecaptionutils.d.ts +4 -4
  169. package/src/imagecaption/imagecaptionutils.js +3 -3
  170. package/src/imagecaption/toggleimagecaptioncommand.d.ts +2 -2
  171. package/src/imagecaption/toggleimagecaptioncommand.js +3 -3
  172. package/src/imagecaption.d.ts +4 -4
  173. package/src/imagecaption.js +4 -4
  174. package/src/imageconfig.d.ts +10 -14
  175. package/src/imageconfig.js +1 -1
  176. package/src/imageinline.d.ts +7 -6
  177. package/src/imageinline.js +7 -6
  178. package/src/imageinsert/imageinsertui.d.ts +39 -11
  179. package/src/imageinsert/imageinsertui.js +127 -94
  180. package/src/imageinsert/imageinsertviaurlui.d.ts +44 -0
  181. package/src/imageinsert/imageinsertviaurlui.js +122 -0
  182. package/src/imageinsert/ui/imageinsertformview.d.ts +56 -0
  183. package/src/imageinsert/ui/imageinsertformview.js +112 -0
  184. package/src/imageinsert/ui/imageinserturlview.d.ts +107 -0
  185. package/src/imageinsert/ui/imageinserturlview.js +156 -0
  186. package/src/imageinsert.d.ts +5 -5
  187. package/src/imageinsert.js +5 -5
  188. package/src/imageinsertviaurl.d.ts +5 -4
  189. package/src/imageinsertviaurl.js +5 -4
  190. package/src/imageresize/imageresizebuttons.d.ts +3 -3
  191. package/src/imageresize/imageresizebuttons.js +6 -6
  192. package/src/imageresize/imageresizeediting.d.ts +3 -3
  193. package/src/imageresize/imageresizeediting.js +5 -5
  194. package/src/imageresize/imageresizehandles.d.ts +4 -4
  195. package/src/imageresize/imageresizehandles.js +5 -5
  196. package/src/imageresize/resizeimagecommand.d.ts +2 -2
  197. package/src/imageresize/resizeimagecommand.js +2 -2
  198. package/src/imageresize.d.ts +5 -5
  199. package/src/imageresize.js +5 -5
  200. package/src/imagesizeattributes.d.ts +3 -3
  201. package/src/imagesizeattributes.js +4 -4
  202. package/src/imagestyle/converters.d.ts +4 -4
  203. package/src/imagestyle/converters.js +2 -2
  204. package/src/imagestyle/imagestylecommand.d.ts +4 -4
  205. package/src/imagestyle/imagestylecommand.js +2 -2
  206. package/src/imagestyle/imagestyleediting.d.ts +4 -4
  207. package/src/imagestyle/imagestyleediting.js +6 -6
  208. package/src/imagestyle/imagestyleui.d.ts +3 -3
  209. package/src/imagestyle/imagestyleui.js +5 -5
  210. package/src/imagestyle/utils.d.ts +3 -3
  211. package/src/imagestyle/utils.js +3 -3
  212. package/src/imagestyle.d.ts +4 -4
  213. package/src/imagestyle.js +4 -4
  214. package/src/imagetextalternative/imagetextalternativecommand.d.ts +2 -2
  215. package/src/imagetextalternative/imagetextalternativecommand.js +2 -2
  216. package/src/imagetextalternative/imagetextalternativeediting.d.ts +3 -3
  217. package/src/imagetextalternative/imagetextalternativeediting.js +4 -4
  218. package/src/imagetextalternative/imagetextalternativeui.d.ts +3 -3
  219. package/src/imagetextalternative/imagetextalternativeui.js +5 -5
  220. package/src/imagetextalternative/ui/textalternativeformview.d.ts +22 -4
  221. package/src/imagetextalternative/ui/textalternativeformview.js +4 -4
  222. package/src/imagetextalternative.d.ts +4 -4
  223. package/src/imagetextalternative.js +4 -4
  224. package/src/imagetoolbar.d.ts +4 -4
  225. package/src/imagetoolbar.js +4 -4
  226. package/src/imageupload/imageuploadediting.d.ts +7 -7
  227. package/src/imageupload/imageuploadediting.js +11 -11
  228. package/src/imageupload/imageuploadprogress.d.ts +2 -2
  229. package/src/imageupload/imageuploadprogress.js +3 -3
  230. package/src/imageupload/imageuploadui.d.ts +2 -2
  231. package/src/imageupload/imageuploadui.js +34 -10
  232. package/src/imageupload/uploadimagecommand.d.ts +3 -3
  233. package/src/imageupload/uploadimagecommand.js +4 -4
  234. package/src/imageupload/utils.d.ts +3 -3
  235. package/src/imageupload/utils.js +2 -2
  236. package/src/imageupload.d.ts +5 -5
  237. package/src/imageupload.js +5 -5
  238. package/src/imageutils.d.ts +3 -3
  239. package/src/imageutils.js +5 -5
  240. package/src/index.d.ts +42 -42
  241. package/src/index.js +33 -33
  242. package/src/pictureediting.d.ts +4 -4
  243. package/src/pictureediting.js +5 -5
  244. package/theme/image.css +1 -1
  245. package/theme/imagecaption.css +1 -1
  246. package/theme/imageinsert.css +6 -18
  247. package/theme/imageplaceholder.css +1 -1
  248. package/theme/imageresize.css +1 -1
  249. package/theme/imagestyle.css +1 -1
  250. package/theme/imageuploadicon.css +1 -1
  251. package/theme/imageuploadloader.css +1 -1
  252. package/theme/imageuploadprogress.css +1 -1
  253. package/theme/textalternativeform.css +1 -1
  254. package/src/imageinsert/ui/imageinsertformrowview.d.ts +0 -61
  255. package/src/imageinsert/ui/imageinsertformrowview.js +0 -54
  256. package/src/imageinsert/ui/imageinsertpanelview.d.ts +0 -106
  257. package/src/imageinsert/ui/imageinsertpanelview.js +0 -161
  258. package/src/imageinsert/utils.d.ts +0 -25
  259. package/src/imageinsert/utils.js +0 -58
  260. package/theme/imageinsertformrowview.css +0 -36
@@ -1,14 +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 image/imageinsert/imageinsertui
7
7
  */
8
- import { Plugin, icons } from 'ckeditor5/src/core';
9
- import { SplitButtonView, createDropdown } from 'ckeditor5/src/ui';
10
- import ImageInsertPanelView from './ui/imageinsertpanelview';
11
- import { prepareIntegrations } from './utils';
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import { logWarning } from 'ckeditor5/src/utils.js';
10
+ import { createDropdown, SplitButtonView } from 'ckeditor5/src/ui.js';
11
+ import ImageInsertFormView from './ui/imageinsertformview.js';
12
+ import ImageUtils from '../imageutils.js';
12
13
  /**
13
14
  * The image insert dropdown plugin.
14
15
  *
@@ -25,117 +26,149 @@ export default class ImageInsertUI extends Plugin {
25
26
  static get pluginName() {
26
27
  return 'ImageInsertUI';
27
28
  }
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get requires() {
33
+ return [ImageUtils];
34
+ }
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ constructor(editor) {
39
+ super(editor);
40
+ /**
41
+ * Registered integrations map.
42
+ */
43
+ this._integrations = new Map();
44
+ editor.config.define('image.insert.integrations', [
45
+ 'upload',
46
+ 'assetManager',
47
+ 'url'
48
+ ]);
49
+ }
28
50
  /**
29
51
  * @inheritDoc
30
52
  */
31
53
  init() {
32
54
  const editor = this.editor;
33
- const componentCreator = (locale) => {
34
- return this._createDropdownView(locale);
35
- };
55
+ const selection = editor.model.document.selection;
56
+ const imageUtils = editor.plugins.get('ImageUtils');
57
+ this.set('isImageSelected', false);
58
+ this.listenTo(editor.model.document, 'change', () => {
59
+ this.isImageSelected = imageUtils.isImage(selection.getSelectedElement());
60
+ });
61
+ const componentCreator = (locale) => this._createToolbarComponent(locale);
36
62
  // Register `insertImage` dropdown and add `imageInsert` dropdown as an alias for backward compatibility.
37
63
  editor.ui.componentFactory.add('insertImage', componentCreator);
38
64
  editor.ui.componentFactory.add('imageInsert', componentCreator);
39
65
  }
40
66
  /**
41
- * Creates the dropdown view.
42
- *
43
- * @param locale The localization services instance.
67
+ * Registers the insert image dropdown integration.
68
+ */
69
+ registerIntegration({ name, observable, buttonViewCreator, formViewCreator, requiresForm }) {
70
+ if (this._integrations.has(name)) {
71
+ /**
72
+ * There are two insert-image integrations registered with the same name.
73
+ *
74
+ * Make sure that you do not load multiple asset manager plugins.
75
+ *
76
+ * @error image-insert-integration-exists
77
+ */
78
+ logWarning('image-insert-integration-exists', { name });
79
+ }
80
+ this._integrations.set(name, {
81
+ observable,
82
+ buttonViewCreator,
83
+ formViewCreator,
84
+ requiresForm: !!requiresForm
85
+ });
86
+ }
87
+ /**
88
+ * Creates the toolbar component.
44
89
  */
45
- _createDropdownView(locale) {
90
+ _createToolbarComponent(locale) {
46
91
  const editor = this.editor;
47
92
  const t = locale.t;
48
- const uploadImageCommand = editor.commands.get('uploadImage');
49
- const insertImageCommand = editor.commands.get('insertImage');
50
- this.dropdownView = createDropdown(locale, uploadImageCommand ? SplitButtonView : undefined);
51
- const buttonView = this.dropdownView.buttonView;
52
- const panelView = this.dropdownView.panelView;
53
- buttonView.set({
54
- label: t('Insert image'),
55
- icon: icons.image,
56
- tooltip: true
57
- });
58
- panelView.extendTemplate({
59
- attributes: {
60
- class: 'ck-image-insert__panel'
93
+ const integrations = this._prepareIntegrations();
94
+ if (!integrations.length) {
95
+ return null;
96
+ }
97
+ let dropdownButton;
98
+ const firstIntegration = integrations[0];
99
+ if (integrations.length == 1) {
100
+ // Do not use dropdown for a single integration button (integration that does not require form view).
101
+ if (!firstIntegration.requiresForm) {
102
+ return firstIntegration.buttonViewCreator(true);
61
103
  }
62
- });
63
- if (uploadImageCommand) {
64
- const splitButtonView = this.dropdownView.buttonView;
65
- // We are injecting custom button replacement to readonly field.
66
- splitButtonView.actionView = editor.ui.componentFactory.create('uploadImage');
67
- // After we replaced action button with `uploadImage` component,
68
- // we have lost a proper styling and some minor visual quirks have appeared.
69
- // Brining back original split button classes helps fix the button styling
70
- // See https://github.com/ckeditor/ckeditor5/issues/7986.
71
- splitButtonView.actionView.extendTemplate({
72
- attributes: {
73
- class: 'ck ck-button ck-splitbutton__action'
74
- }
75
- });
104
+ dropdownButton = firstIntegration.buttonViewCreator(true);
76
105
  }
77
- return this._setUpDropdown(uploadImageCommand || insertImageCommand);
106
+ else {
107
+ const actionButton = firstIntegration.buttonViewCreator(false);
108
+ dropdownButton = new SplitButtonView(locale, actionButton);
109
+ dropdownButton.tooltip = true;
110
+ dropdownButton.bind('label').to(this, 'isImageSelected', isImageSelected => isImageSelected ?
111
+ t('Replace image') :
112
+ t('Insert image'));
113
+ }
114
+ const dropdownView = this.dropdownView = createDropdown(locale, dropdownButton);
115
+ const observables = integrations.map(({ observable }) => observable);
116
+ dropdownView.bind('isEnabled').toMany(observables, 'isEnabled', (...isEnabled) => (isEnabled.some(isEnabled => isEnabled)));
117
+ dropdownView.once('change:isOpen', () => {
118
+ const integrationViews = integrations.map(({ formViewCreator }) => formViewCreator(integrations.length == 1));
119
+ const imageInsertFormView = new ImageInsertFormView(editor.locale, integrationViews);
120
+ dropdownView.panelView.children.add(imageInsertFormView);
121
+ });
122
+ return dropdownView;
78
123
  }
79
124
  /**
80
- * Sets up the dropdown view.
81
- *
82
- * @param command An uploadImage or insertImage command.
125
+ * Validates the integrations list.
83
126
  */
84
- _setUpDropdown(command) {
127
+ _prepareIntegrations() {
85
128
  const editor = this.editor;
86
- const t = editor.t;
87
- const dropdownView = this.dropdownView;
88
- const panelView = dropdownView.panelView;
89
- const imageUtils = this.editor.plugins.get('ImageUtils');
90
- const replaceImageSourceCommand = editor.commands.get('replaceImageSource');
91
- let imageInsertView;
92
- dropdownView.bind('isEnabled').to(command);
93
- dropdownView.once('change:isOpen', () => {
94
- imageInsertView = new ImageInsertPanelView(editor.locale, prepareIntegrations(editor));
95
- imageInsertView.delegate('submit', 'cancel').to(dropdownView);
96
- panelView.children.add(imageInsertView);
97
- });
98
- dropdownView.on('change:isOpen', () => {
99
- const selectedElement = editor.model.document.selection.getSelectedElement();
100
- const insertButtonView = imageInsertView.insertButtonView;
101
- const insertImageViaUrlForm = imageInsertView.getIntegration('insertImageViaUrl');
102
- if (dropdownView.isOpen) {
103
- if (imageUtils.isImage(selectedElement)) {
104
- imageInsertView.imageURLInputValue = replaceImageSourceCommand.value;
105
- insertButtonView.label = t('Update');
106
- insertImageViaUrlForm.label = t('Update image URL');
107
- }
108
- else {
109
- imageInsertView.imageURLInputValue = '';
110
- insertButtonView.label = t('Insert');
111
- insertImageViaUrlForm.label = t('Insert image via URL');
129
+ const items = editor.config.get('image.insert.integrations');
130
+ const result = [];
131
+ if (!items.length) {
132
+ /**
133
+ * The insert image feature requires a list of integrations to be provided in the editor configuration.
134
+ *
135
+ * The default list of integrations is `upload`, `assetManager`, `url`. Those integrations are included
136
+ * in the insert image dropdown if the given feature plugin is loaded. You should omit the `integrations`
137
+ * configuration key to use the default set or provide a selected list of integrations that should be used.
138
+ *
139
+ * @error image-insert-integrations-not-specified
140
+ */
141
+ logWarning('image-insert-integrations-not-specified');
142
+ return result;
143
+ }
144
+ for (const item of items) {
145
+ if (!this._integrations.has(item)) {
146
+ if (!['upload', 'assetManager', 'url'].includes(item)) {
147
+ /**
148
+ * The specified insert image integration name is unknown or the providing plugin is not loaded in the editor.
149
+ *
150
+ * @error image-insert-unknown-integration
151
+ */
152
+ logWarning('image-insert-unknown-integration', { item });
112
153
  }
154
+ continue;
113
155
  }
114
- // Note: Use the low priority to make sure the following listener starts working after the
115
- // default action of the drop-down is executed (i.e. the panel showed up). Otherwise, the
116
- // invisible form/input cannot be focused/selected.
117
- }, { priority: 'low' });
118
- this.delegate('cancel').to(dropdownView);
119
- dropdownView.on('submit', () => {
120
- closePanel();
121
- onSubmit();
122
- });
123
- dropdownView.on('cancel', () => {
124
- closePanel();
125
- });
126
- function onSubmit() {
127
- const selectedElement = editor.model.document.selection.getSelectedElement();
128
- if (imageUtils.isImage(selectedElement)) {
129
- editor.execute('replaceImageSource', { source: imageInsertView.imageURLInputValue });
130
- }
131
- else {
132
- editor.execute('insertImage', { source: imageInsertView.imageURLInputValue });
133
- }
156
+ result.push(this._integrations.get(item));
134
157
  }
135
- function closePanel() {
136
- editor.editing.view.focus();
137
- dropdownView.isOpen = false;
158
+ if (!result.length) {
159
+ /**
160
+ * The image insert feature requires integrations to be registered by separate features.
161
+ *
162
+ * The `insertImage` toolbar button requires integrations to be registered by other features.
163
+ * For example {@link module:image/imageupload~ImageUpload ImageUpload},
164
+ * {@link module:image/imageinsert~ImageInsert ImageInsert},
165
+ * {@link module:image/imageinsertviaurl~ImageInsertViaUrl ImageInsertViaUrl},
166
+ * {@link module:ckbox/ckbox~CKBox CKBox}
167
+ *
168
+ * @error image-insert-integrations-not-registered
169
+ */
170
+ logWarning('image-insert-integrations-not-registered');
138
171
  }
139
- return dropdownView;
172
+ return result;
140
173
  }
141
174
  }
@@ -0,0 +1,44 @@
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 image/imageinsert/imageinsertviaurlui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core.js';
9
+ import ImageInsertUI from './imageinsertui.js';
10
+ /**
11
+ * The image insert via URL plugin (UI part).
12
+ *
13
+ * For a detailed overview, check the {@glink features/images/images-inserting
14
+ * Insert images via source URL} documentation.
15
+ *
16
+ * This plugin registers the {@link module:image/imageinsert/imageinsertui~ImageInsertUI} integration for `url`.
17
+ */
18
+ export default class ImageInsertViaUrlUI extends Plugin {
19
+ private _imageInsertUI;
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ static get pluginName(): "ImageInsertViaUrlUI";
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get requires(): readonly [typeof ImageInsertUI];
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init(): void;
32
+ /**
33
+ * Creates the view displayed in the dropdown.
34
+ */
35
+ private _createInsertUrlView;
36
+ /**
37
+ * Creates the toolbar button.
38
+ */
39
+ private _createInsertUrlButton;
40
+ /**
41
+ * Closes the dropdown.
42
+ */
43
+ private _closePanel;
44
+ }
@@ -0,0 +1,122 @@
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 image/imageinsert/imageinsertviaurlui
7
+ */
8
+ import { icons, Plugin } from 'ckeditor5/src/core.js';
9
+ import { ButtonView, CollapsibleView, DropdownButtonView } from 'ckeditor5/src/ui.js';
10
+ import ImageInsertUI from './imageinsertui.js';
11
+ import ImageInsertUrlView from './ui/imageinserturlview.js';
12
+ /**
13
+ * The image insert via URL plugin (UI part).
14
+ *
15
+ * For a detailed overview, check the {@glink features/images/images-inserting
16
+ * Insert images via source URL} documentation.
17
+ *
18
+ * This plugin registers the {@link module:image/imageinsert/imageinsertui~ImageInsertUI} integration for `url`.
19
+ */
20
+ export default class ImageInsertViaUrlUI extends Plugin {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName() {
25
+ return 'ImageInsertViaUrlUI';
26
+ }
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ static get requires() {
31
+ return [ImageInsertUI];
32
+ }
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ init() {
37
+ this._imageInsertUI = this.editor.plugins.get('ImageInsertUI');
38
+ const insertImageCommand = this.editor.commands.get('insertImage');
39
+ this._imageInsertUI.registerIntegration({
40
+ name: 'url',
41
+ observable: insertImageCommand,
42
+ requiresForm: true,
43
+ buttonViewCreator: isOnlyOne => this._createInsertUrlButton(isOnlyOne),
44
+ formViewCreator: isOnlyOne => this._createInsertUrlView(isOnlyOne)
45
+ });
46
+ }
47
+ /**
48
+ * Creates the view displayed in the dropdown.
49
+ */
50
+ _createInsertUrlView(isOnlyOne) {
51
+ const editor = this.editor;
52
+ const locale = editor.locale;
53
+ const t = locale.t;
54
+ const replaceImageSourceCommand = editor.commands.get('replaceImageSource');
55
+ const insertImageCommand = editor.commands.get('insertImage');
56
+ const imageInsertUrlView = new ImageInsertUrlView(locale);
57
+ const collapsibleView = isOnlyOne ? null : new CollapsibleView(locale, [imageInsertUrlView]);
58
+ imageInsertUrlView.bind('isImageSelected').to(this._imageInsertUI);
59
+ imageInsertUrlView.bind('isEnabled').toMany([insertImageCommand, replaceImageSourceCommand], 'isEnabled', (...isEnabled) => (isEnabled.some(isCommandEnabled => isCommandEnabled)));
60
+ // Set initial value because integrations are created on first dropdown open.
61
+ imageInsertUrlView.imageURLInputValue = replaceImageSourceCommand.value || '';
62
+ this._imageInsertUI.dropdownView.on('change:isOpen', () => {
63
+ if (this._imageInsertUI.dropdownView.isOpen) {
64
+ // Make sure that each time the panel shows up, the URL field remains in sync with the value of
65
+ // the command. If the user typed in the input, then canceled and re-opened it without changing
66
+ // the value of the media command (e.g. because they didn't change the selection), they would see
67
+ // the old value instead of the actual value of the command.
68
+ imageInsertUrlView.imageURLInputValue = replaceImageSourceCommand.value || '';
69
+ if (collapsibleView) {
70
+ collapsibleView.isCollapsed = true;
71
+ }
72
+ }
73
+ // Note: Use the low priority to make sure the following listener starts working after the
74
+ // default action of the drop-down is executed (i.e. the panel showed up). Otherwise, the
75
+ // invisible form/input cannot be focused/selected.
76
+ }, { priority: 'low' });
77
+ imageInsertUrlView.on('submit', () => {
78
+ if (replaceImageSourceCommand.isEnabled) {
79
+ editor.execute('replaceImageSource', { source: imageInsertUrlView.imageURLInputValue });
80
+ }
81
+ else {
82
+ editor.execute('insertImage', { source: imageInsertUrlView.imageURLInputValue });
83
+ }
84
+ this._closePanel();
85
+ });
86
+ imageInsertUrlView.on('cancel', () => this._closePanel());
87
+ if (collapsibleView) {
88
+ collapsibleView.set({
89
+ isCollapsed: true
90
+ });
91
+ collapsibleView.bind('label').to(this._imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ?
92
+ t('Update image URL') :
93
+ t('Insert image via URL'));
94
+ return collapsibleView;
95
+ }
96
+ return imageInsertUrlView;
97
+ }
98
+ /**
99
+ * Creates the toolbar button.
100
+ */
101
+ _createInsertUrlButton(isOnlyOne) {
102
+ const ButtonClass = isOnlyOne ? DropdownButtonView : ButtonView;
103
+ const editor = this.editor;
104
+ const button = new ButtonClass(editor.locale);
105
+ const t = editor.locale.t;
106
+ button.set({
107
+ icon: icons.imageUrl,
108
+ tooltip: true
109
+ });
110
+ button.bind('label').to(this._imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ?
111
+ t('Update image URL') :
112
+ t('Insert image via URL'));
113
+ return button;
114
+ }
115
+ /**
116
+ * Closes the dropdown.
117
+ */
118
+ _closePanel() {
119
+ this.editor.editing.view.focus();
120
+ this._imageInsertUI.dropdownView.isOpen = false;
121
+ }
122
+ }
@@ -0,0 +1,56 @@
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 image/imageinsert/ui/imageinsertformview
7
+ */
8
+ import { View, ViewCollection, FocusCycler, type FocusableView } from 'ckeditor5/src/ui.js';
9
+ import { FocusTracker, KeystrokeHandler, type Locale } from 'ckeditor5/src/utils.js';
10
+ import '../../../theme/imageinsert.css';
11
+ /**
12
+ * The view displayed in the insert image dropdown.
13
+ *
14
+ * See {@link module:image/imageinsert/imageinsertui~ImageInsertUI}.
15
+ */
16
+ export default class ImageInsertFormView extends View {
17
+ /**
18
+ * Tracks information about DOM focus in the form.
19
+ */
20
+ readonly focusTracker: FocusTracker;
21
+ /**
22
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
23
+ */
24
+ readonly keystrokes: KeystrokeHandler;
25
+ /**
26
+ * A collection of views that can be focused in the form.
27
+ */
28
+ protected readonly _focusables: ViewCollection<FocusableView>;
29
+ /**
30
+ * Helps cycling over {@link #_focusables} in the form.
31
+ */
32
+ protected readonly _focusCycler: FocusCycler;
33
+ /**
34
+ * A collection of the defined integrations for inserting the images.
35
+ */
36
+ private readonly children;
37
+ /**
38
+ * Creates a view for the dropdown panel of {@link module:image/imageinsert/imageinsertui~ImageInsertUI}.
39
+ *
40
+ * @param locale The localization services instance.
41
+ * @param integrations An integrations object that contains components (or tokens for components) to be shown in the panel view.
42
+ */
43
+ constructor(locale: Locale, integrations?: Array<FocusableView>);
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ render(): void;
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ destroy(): void;
52
+ /**
53
+ * Focuses the first {@link #_focusables focusable} in the form.
54
+ */
55
+ focus(): void;
56
+ }
@@ -0,0 +1,112 @@
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 image/imageinsert/ui/imageinsertformview
7
+ */
8
+ import { View, ViewCollection, submitHandler, FocusCycler, CollapsibleView } from 'ckeditor5/src/ui.js';
9
+ import { FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils.js';
10
+ import '../../../theme/imageinsert.css';
11
+ /**
12
+ * The view displayed in the insert image dropdown.
13
+ *
14
+ * See {@link module:image/imageinsert/imageinsertui~ImageInsertUI}.
15
+ */
16
+ export default class ImageInsertFormView extends View {
17
+ /**
18
+ * Creates a view for the dropdown panel of {@link module:image/imageinsert/imageinsertui~ImageInsertUI}.
19
+ *
20
+ * @param locale The localization services instance.
21
+ * @param integrations An integrations object that contains components (or tokens for components) to be shown in the panel view.
22
+ */
23
+ constructor(locale, integrations = []) {
24
+ super(locale);
25
+ this.focusTracker = new FocusTracker();
26
+ this.keystrokes = new KeystrokeHandler();
27
+ this._focusables = new ViewCollection();
28
+ this.children = this.createCollection();
29
+ this._focusCycler = new FocusCycler({
30
+ focusables: this._focusables,
31
+ focusTracker: this.focusTracker,
32
+ keystrokeHandler: this.keystrokes,
33
+ actions: {
34
+ // Navigate form fields backwards using the Shift + Tab keystroke.
35
+ focusPrevious: 'shift + tab',
36
+ // Navigate form fields forwards using the Tab key.
37
+ focusNext: 'tab'
38
+ }
39
+ });
40
+ for (const view of integrations) {
41
+ this.children.add(view);
42
+ this._focusables.add(view);
43
+ if (view instanceof CollapsibleView) {
44
+ this._focusables.addMany(view.children);
45
+ }
46
+ }
47
+ if (this._focusables.length > 1) {
48
+ for (const view of this._focusables) {
49
+ if (isViewWithFocusCycler(view)) {
50
+ view.focusCycler.on('forwardCycle', evt => {
51
+ this._focusCycler.focusNext();
52
+ evt.stop();
53
+ });
54
+ view.focusCycler.on('backwardCycle', evt => {
55
+ this._focusCycler.focusPrevious();
56
+ evt.stop();
57
+ });
58
+ }
59
+ }
60
+ }
61
+ this.setTemplate({
62
+ tag: 'form',
63
+ attributes: {
64
+ class: [
65
+ 'ck',
66
+ 'ck-image-insert-form'
67
+ ],
68
+ tabindex: -1
69
+ },
70
+ children: this.children
71
+ });
72
+ }
73
+ /**
74
+ * @inheritDoc
75
+ */
76
+ render() {
77
+ super.render();
78
+ submitHandler({
79
+ view: this
80
+ });
81
+ for (const view of this._focusables) {
82
+ this.focusTracker.add(view.element);
83
+ }
84
+ // Start listening for the keystrokes coming from #element.
85
+ this.keystrokes.listenTo(this.element);
86
+ const stopPropagation = (data) => data.stopPropagation();
87
+ // Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
88
+ // keystroke handler would take over the key management in the URL input. We need to prevent
89
+ // this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
90
+ this.keystrokes.set('arrowright', stopPropagation);
91
+ this.keystrokes.set('arrowleft', stopPropagation);
92
+ this.keystrokes.set('arrowup', stopPropagation);
93
+ this.keystrokes.set('arrowdown', stopPropagation);
94
+ }
95
+ /**
96
+ * @inheritDoc
97
+ */
98
+ destroy() {
99
+ super.destroy();
100
+ this.focusTracker.destroy();
101
+ this.keystrokes.destroy();
102
+ }
103
+ /**
104
+ * Focuses the first {@link #_focusables focusable} in the form.
105
+ */
106
+ focus() {
107
+ this._focusCycler.focusFirst();
108
+ }
109
+ }
110
+ function isViewWithFocusCycler(view) {
111
+ return 'focusCycler' in view;
112
+ }