@ckeditor/ckeditor5-ckbox 47.6.1-alpha.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 (186) hide show
  1. package/LICENSE.md +1 -1
  2. package/ckeditor5-metadata.json +4 -4
  3. package/{src → dist}/ckbox.d.ts +1 -1
  4. package/{src → dist}/ckboxcommand.d.ts +1 -1
  5. package/{src → dist}/ckboxconfig.d.ts +1 -1
  6. package/{src → dist}/ckboxediting.d.ts +4 -2
  7. package/{src → dist}/ckboximageedit/ckboximageeditcommand.d.ts +1 -1
  8. package/{src → dist}/ckboximageedit/ckboximageeditediting.d.ts +4 -3
  9. package/{src → dist}/ckboximageedit/ckboximageeditui.d.ts +1 -1
  10. package/{src → dist}/ckboximageedit/utils.d.ts +1 -1
  11. package/{src → dist}/ckboximageedit.d.ts +1 -1
  12. package/{src → dist}/ckboxui.d.ts +1 -1
  13. package/{src → dist}/ckboxuploadadapter.d.ts +4 -3
  14. package/{src → dist}/ckboxutils.d.ts +3 -3
  15. package/dist/index-editor.css +24 -28
  16. package/dist/index.css +25 -36
  17. package/dist/index.css.map +1 -1
  18. package/dist/index.js +14 -10
  19. package/dist/index.js.map +1 -1
  20. package/package.json +28 -51
  21. package/build/ckbox.js +0 -5
  22. package/build/translations/af.js +0 -1
  23. package/build/translations/ar.js +0 -1
  24. package/build/translations/ast.js +0 -1
  25. package/build/translations/az.js +0 -1
  26. package/build/translations/be.js +0 -1
  27. package/build/translations/bg.js +0 -1
  28. package/build/translations/bn.js +0 -1
  29. package/build/translations/bs.js +0 -1
  30. package/build/translations/ca.js +0 -1
  31. package/build/translations/cs.js +0 -1
  32. package/build/translations/da.js +0 -1
  33. package/build/translations/de-ch.js +0 -1
  34. package/build/translations/de.js +0 -1
  35. package/build/translations/el.js +0 -1
  36. package/build/translations/en-au.js +0 -1
  37. package/build/translations/en-gb.js +0 -1
  38. package/build/translations/eo.js +0 -1
  39. package/build/translations/es-co.js +0 -1
  40. package/build/translations/es.js +0 -1
  41. package/build/translations/et.js +0 -1
  42. package/build/translations/eu.js +0 -1
  43. package/build/translations/fa.js +0 -1
  44. package/build/translations/fi.js +0 -1
  45. package/build/translations/fr.js +0 -1
  46. package/build/translations/gl.js +0 -1
  47. package/build/translations/gu.js +0 -1
  48. package/build/translations/he.js +0 -1
  49. package/build/translations/hi.js +0 -1
  50. package/build/translations/hr.js +0 -1
  51. package/build/translations/hu.js +0 -1
  52. package/build/translations/hy.js +0 -1
  53. package/build/translations/id.js +0 -1
  54. package/build/translations/it.js +0 -1
  55. package/build/translations/ja.js +0 -1
  56. package/build/translations/jv.js +0 -1
  57. package/build/translations/kk.js +0 -1
  58. package/build/translations/km.js +0 -1
  59. package/build/translations/kn.js +0 -1
  60. package/build/translations/ko.js +0 -1
  61. package/build/translations/ku.js +0 -1
  62. package/build/translations/lt.js +0 -1
  63. package/build/translations/lv.js +0 -1
  64. package/build/translations/ms.js +0 -1
  65. package/build/translations/nb.js +0 -1
  66. package/build/translations/ne.js +0 -1
  67. package/build/translations/nl.js +0 -1
  68. package/build/translations/no.js +0 -1
  69. package/build/translations/oc.js +0 -1
  70. package/build/translations/pl.js +0 -1
  71. package/build/translations/pt-br.js +0 -1
  72. package/build/translations/pt.js +0 -1
  73. package/build/translations/ro.js +0 -1
  74. package/build/translations/ru.js +0 -1
  75. package/build/translations/si.js +0 -1
  76. package/build/translations/sk.js +0 -1
  77. package/build/translations/sl.js +0 -1
  78. package/build/translations/sq.js +0 -1
  79. package/build/translations/sr-latn.js +0 -1
  80. package/build/translations/sr.js +0 -1
  81. package/build/translations/sv.js +0 -1
  82. package/build/translations/th.js +0 -1
  83. package/build/translations/ti.js +0 -1
  84. package/build/translations/tk.js +0 -1
  85. package/build/translations/tr.js +0 -1
  86. package/build/translations/tt.js +0 -1
  87. package/build/translations/ug.js +0 -1
  88. package/build/translations/uk.js +0 -1
  89. package/build/translations/ur.js +0 -1
  90. package/build/translations/uz.js +0 -1
  91. package/build/translations/vi.js +0 -1
  92. package/build/translations/zh-cn.js +0 -1
  93. package/build/translations/zh.js +0 -1
  94. package/lang/contexts.json +0 -10
  95. package/lang/translations/af.po +0 -44
  96. package/lang/translations/ar.po +0 -44
  97. package/lang/translations/ast.po +0 -44
  98. package/lang/translations/az.po +0 -44
  99. package/lang/translations/be.po +0 -44
  100. package/lang/translations/bg.po +0 -44
  101. package/lang/translations/bn.po +0 -44
  102. package/lang/translations/bs.po +0 -44
  103. package/lang/translations/ca.po +0 -44
  104. package/lang/translations/cs.po +0 -44
  105. package/lang/translations/da.po +0 -44
  106. package/lang/translations/de-ch.po +0 -44
  107. package/lang/translations/de.po +0 -44
  108. package/lang/translations/el.po +0 -44
  109. package/lang/translations/en-au.po +0 -44
  110. package/lang/translations/en-gb.po +0 -44
  111. package/lang/translations/en.po +0 -44
  112. package/lang/translations/eo.po +0 -44
  113. package/lang/translations/es-co.po +0 -44
  114. package/lang/translations/es.po +0 -44
  115. package/lang/translations/et.po +0 -44
  116. package/lang/translations/eu.po +0 -44
  117. package/lang/translations/fa.po +0 -44
  118. package/lang/translations/fi.po +0 -44
  119. package/lang/translations/fr.po +0 -44
  120. package/lang/translations/gl.po +0 -44
  121. package/lang/translations/gu.po +0 -44
  122. package/lang/translations/he.po +0 -44
  123. package/lang/translations/hi.po +0 -44
  124. package/lang/translations/hr.po +0 -44
  125. package/lang/translations/hu.po +0 -44
  126. package/lang/translations/hy.po +0 -44
  127. package/lang/translations/id.po +0 -44
  128. package/lang/translations/it.po +0 -44
  129. package/lang/translations/ja.po +0 -44
  130. package/lang/translations/jv.po +0 -44
  131. package/lang/translations/kk.po +0 -44
  132. package/lang/translations/km.po +0 -44
  133. package/lang/translations/kn.po +0 -44
  134. package/lang/translations/ko.po +0 -44
  135. package/lang/translations/ku.po +0 -44
  136. package/lang/translations/lt.po +0 -44
  137. package/lang/translations/lv.po +0 -44
  138. package/lang/translations/ms.po +0 -44
  139. package/lang/translations/nb.po +0 -44
  140. package/lang/translations/ne.po +0 -44
  141. package/lang/translations/nl.po +0 -44
  142. package/lang/translations/no.po +0 -44
  143. package/lang/translations/oc.po +0 -44
  144. package/lang/translations/pl.po +0 -44
  145. package/lang/translations/pt-br.po +0 -44
  146. package/lang/translations/pt.po +0 -44
  147. package/lang/translations/ro.po +0 -44
  148. package/lang/translations/ru.po +0 -44
  149. package/lang/translations/si.po +0 -44
  150. package/lang/translations/sk.po +0 -44
  151. package/lang/translations/sl.po +0 -44
  152. package/lang/translations/sq.po +0 -44
  153. package/lang/translations/sr-latn.po +0 -44
  154. package/lang/translations/sr.po +0 -44
  155. package/lang/translations/sv.po +0 -44
  156. package/lang/translations/th.po +0 -44
  157. package/lang/translations/ti.po +0 -44
  158. package/lang/translations/tk.po +0 -44
  159. package/lang/translations/tr.po +0 -44
  160. package/lang/translations/tt.po +0 -44
  161. package/lang/translations/ug.po +0 -44
  162. package/lang/translations/uk.po +0 -44
  163. package/lang/translations/ur.po +0 -44
  164. package/lang/translations/uz.po +0 -44
  165. package/lang/translations/vi.po +0 -44
  166. package/lang/translations/zh-cn.po +0 -44
  167. package/lang/translations/zh.po +0 -44
  168. package/src/augmentation.js +0 -5
  169. package/src/ckbox.js +0 -43
  170. package/src/ckboxcommand.js +0 -382
  171. package/src/ckboxconfig.js +0 -5
  172. package/src/ckboxediting.js +0 -388
  173. package/src/ckboximageedit/ckboximageeditcommand.js +0 -318
  174. package/src/ckboximageedit/ckboximageeditediting.js +0 -42
  175. package/src/ckboximageedit/ckboximageeditui.js +0 -57
  176. package/src/ckboximageedit/utils.js +0 -48
  177. package/src/ckboximageedit.js +0 -34
  178. package/src/ckboxui.js +0 -139
  179. package/src/ckboxuploadadapter.js +0 -159
  180. package/src/ckboxutils.js +0 -215
  181. package/src/index.js +0 -21
  182. package/src/utils.js +0 -188
  183. package/theme/ckboximageedit.css +0 -53
  184. /package/{src → dist}/augmentation.d.ts +0 -0
  185. /package/{src → dist}/index.d.ts +0 -0
  186. /package/{src → dist}/utils.d.ts +0 -0
@@ -1,318 +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 ckbox/ckboximageedit/ckboximageeditcommand
7
- */
8
- import { Command, PendingActions } from 'ckeditor5/src/core.js';
9
- import { CKEditorError, abortableDebounce, createElement, retry, delay } from 'ckeditor5/src/utils.js';
10
- import { Notification } from 'ckeditor5/src/ui.js';
11
- import { isEqual } from 'es-toolkit/compat';
12
- import { sendHttpRequest } from '../utils.js';
13
- import { prepareImageAssetAttributes } from '../ckboxcommand.js';
14
- import { createEditabilityChecker } from './utils.js';
15
- import { CKBoxUtils } from '../ckboxutils.js';
16
- /**
17
- * The CKBox edit image command.
18
- *
19
- * Opens the CKBox dialog for editing the image.
20
- */
21
- export class CKBoxImageEditCommand extends Command {
22
- /**
23
- * The DOM element that acts as a mounting point for the CKBox Edit Image dialog.
24
- */
25
- _wrapper = null;
26
- /**
27
- * The states of image processing in progress.
28
- */
29
- _processInProgress = new Set();
30
- /**
31
- * Determines if the element can be edited.
32
- */
33
- _canEdit;
34
- /**
35
- * A wrapper function to prepare mount options. Ensures that at most one preparation is in-flight.
36
- */
37
- _prepareOptions;
38
- /**
39
- * CKBox's onClose function runs before the final cleanup, potentially causing
40
- * page layout changes after it finishes. To address this, we use a setTimeout hack
41
- * to ensure that floating elements on the page maintain their correct position.
42
- *
43
- * See: https://github.com/ckeditor/ckeditor5/issues/16153.
44
- */
45
- _updateUiDelayed = delay(() => this.editor.ui.update(), 0);
46
- /**
47
- * @inheritDoc
48
- */
49
- constructor(editor) {
50
- super(editor);
51
- this.value = false;
52
- this._canEdit = createEditabilityChecker(editor.config.get('ckbox.allowExternalImagesEditing'));
53
- this._prepareOptions = abortableDebounce((signal, state) => this._prepareOptionsAbortable(signal, state));
54
- this._prepareListeners();
55
- }
56
- /**
57
- * @inheritDoc
58
- */
59
- refresh() {
60
- const editor = this.editor;
61
- this.value = this._getValue();
62
- const selectedElement = editor.model.document.selection.getSelectedElement();
63
- this.isEnabled =
64
- !!selectedElement &&
65
- this._canEdit(selectedElement) &&
66
- !this._checkIfElementIsBeingProcessed(selectedElement);
67
- }
68
- /**
69
- * Opens the CKBox Image Editor dialog for editing the image.
70
- */
71
- execute() {
72
- if (this._getValue()) {
73
- return;
74
- }
75
- const wrapper = createElement(document, 'div', { class: 'ck ckbox-wrapper' });
76
- this._wrapper = wrapper;
77
- this.value = true;
78
- document.body.appendChild(this._wrapper);
79
- const imageElement = this.editor.model.document.selection.getSelectedElement();
80
- const processingState = {
81
- element: imageElement,
82
- controller: new AbortController()
83
- };
84
- this._prepareOptions(processingState).then(options => window.CKBox.mountImageEditor(wrapper, options), error => {
85
- const editor = this.editor;
86
- const t = editor.t;
87
- const notification = editor.plugins.get(Notification);
88
- notification.showWarning(t('Failed to determine category of edited image.'), {
89
- namespace: 'ckbox'
90
- });
91
- console.error(error);
92
- this._handleImageEditorClose();
93
- });
94
- }
95
- /**
96
- * @inheritDoc
97
- */
98
- destroy() {
99
- this._handleImageEditorClose();
100
- this._prepareOptions.abort();
101
- this._updateUiDelayed.cancel();
102
- for (const state of this._processInProgress.values()) {
103
- state.controller.abort();
104
- }
105
- super.destroy();
106
- }
107
- /**
108
- * Indicates if the CKBox Image Editor dialog is already opened.
109
- */
110
- _getValue() {
111
- return this._wrapper !== null;
112
- }
113
- /**
114
- * Creates the options object for the CKBox Image Editor dialog.
115
- */
116
- async _prepareOptionsAbortable(signal, state) {
117
- const editor = this.editor;
118
- const ckboxConfig = editor.config.get('ckbox');
119
- const ckboxUtils = editor.plugins.get(CKBoxUtils);
120
- const { element } = state;
121
- let imageMountOptions;
122
- const ckboxImageId = element.getAttribute('ckboxImageId');
123
- if (ckboxImageId) {
124
- imageMountOptions = {
125
- assetId: ckboxImageId
126
- };
127
- }
128
- else {
129
- const imageUrl = new URL(element.getAttribute('src'), document.baseURI).href;
130
- const uploadCategoryId = await ckboxUtils.getCategoryIdForFile(imageUrl, { signal });
131
- imageMountOptions = {
132
- imageUrl,
133
- uploadCategoryId
134
- };
135
- }
136
- return {
137
- ...imageMountOptions,
138
- imageEditing: {
139
- allowOverwrite: false
140
- },
141
- tokenUrl: ckboxConfig.tokenUrl,
142
- language: ckboxConfig.language,
143
- ...(ckboxConfig.serviceOrigin && { serviceOrigin: ckboxConfig.serviceOrigin }),
144
- onClose: () => this._handleImageEditorClose(),
145
- onSave: (asset) => this._handleImageEditorSave(state, asset)
146
- };
147
- }
148
- /**
149
- * Initializes event lister for an event of removing an image.
150
- */
151
- _prepareListeners() {
152
- // Abort editing processing when the image has been removed.
153
- this.listenTo(this.editor.model.document, 'change:data', () => {
154
- const processingStates = this._getProcessingStatesOfDeletedImages();
155
- processingStates.forEach(processingState => {
156
- processingState.controller.abort();
157
- });
158
- });
159
- }
160
- /**
161
- * Gets processing states of images that have been deleted in the mean time.
162
- */
163
- _getProcessingStatesOfDeletedImages() {
164
- const states = [];
165
- for (const state of this._processInProgress.values()) {
166
- if (state.element.root.rootName == '$graveyard') {
167
- states.push(state);
168
- }
169
- }
170
- return states;
171
- }
172
- _checkIfElementIsBeingProcessed(selectedElement) {
173
- for (const { element } of this._processInProgress) {
174
- if (isEqual(element, selectedElement)) {
175
- return true;
176
- }
177
- }
178
- return false;
179
- }
180
- /**
181
- * Closes the CKBox Image Editor dialog.
182
- */
183
- _handleImageEditorClose() {
184
- if (!this._wrapper) {
185
- return;
186
- }
187
- this._wrapper.remove();
188
- this._wrapper = null;
189
- this.editor.editing.view.focus();
190
- this._updateUiDelayed();
191
- this.refresh();
192
- }
193
- /**
194
- * Save edited image. In case server respond with "success" replace with edited image,
195
- * otherwise show notification error.
196
- */
197
- _handleImageEditorSave(state, asset) {
198
- const t = this.editor.locale.t;
199
- const notification = this.editor.plugins.get(Notification);
200
- const pendingActions = this.editor.plugins.get(PendingActions);
201
- const action = pendingActions.add(t('Processing the edited image.'));
202
- this._processInProgress.add(state);
203
- this._showImageProcessingIndicator(state.element, asset);
204
- this.refresh();
205
- this._waitForAssetProcessed(asset.data.id, state.controller.signal)
206
- .then(asset => {
207
- this._replaceImage(state.element, asset);
208
- }, error => {
209
- // Remove processing indicator. It was added only to ViewElement.
210
- this.editor.editing.reconvertItem(state.element);
211
- if (state.controller.signal.aborted) {
212
- return;
213
- }
214
- if (!error || error instanceof CKEditorError) {
215
- notification.showWarning(t('Server failed to process the image.'), {
216
- namespace: 'ckbox'
217
- });
218
- }
219
- else {
220
- console.error(error);
221
- }
222
- }).finally(() => {
223
- this._processInProgress.delete(state);
224
- pendingActions.remove(action);
225
- this.refresh();
226
- });
227
- }
228
- /**
229
- * Get asset's status on server. If server responds with "success" status then
230
- * image is already proceeded and ready for saving.
231
- */
232
- async _getAssetStatusFromServer(id, signal) {
233
- const ckboxUtils = this.editor.plugins.get(CKBoxUtils);
234
- const url = new URL('assets/' + id, this.editor.config.get('ckbox.serviceOrigin'));
235
- const response = await sendHttpRequest({
236
- url,
237
- signal,
238
- authorization: (await ckboxUtils.getToken()).value
239
- });
240
- const status = response.metadata.metadataProcessingStatus;
241
- if (!status || status == 'queued') {
242
- /**
243
- * Image has not been processed yet.
244
- *
245
- * @error ckbox-image-not-processed
246
- */
247
- throw new CKEditorError('ckbox-image-not-processed');
248
- }
249
- return { data: { ...response } };
250
- }
251
- /**
252
- * Waits for an asset to be processed.
253
- * It retries retrieving asset status from the server in case of failure.
254
- */
255
- async _waitForAssetProcessed(id, signal) {
256
- const result = await retry(() => this._getAssetStatusFromServer(id, signal), {
257
- signal,
258
- maxAttempts: 5
259
- });
260
- if (result.data.metadata.metadataProcessingStatus != 'success') {
261
- /**
262
- * The image processing failed.
263
- *
264
- * @error ckbox-image-processing-failed
265
- */
266
- throw new CKEditorError('ckbox-image-processing-failed');
267
- }
268
- return result;
269
- }
270
- /**
271
- * Shows processing indicator while image is processing.
272
- *
273
- * @param asset Data about certain asset.
274
- */
275
- _showImageProcessingIndicator(element, asset) {
276
- const editor = this.editor;
277
- editor.editing.view.change(writer => {
278
- const imageElementView = editor.editing.mapper.toViewElement(element);
279
- const imageUtils = this.editor.plugins.get('ImageUtils');
280
- const img = imageUtils.findViewImgElement(imageElementView);
281
- writer.removeStyle('aspect-ratio', img);
282
- writer.setAttribute('width', asset.data.metadata.width, img);
283
- writer.setAttribute('height', asset.data.metadata.height, img);
284
- writer.setStyle('width', `${asset.data.metadata.width}px`, img);
285
- writer.setStyle('height', `${asset.data.metadata.height}px`, img);
286
- writer.addClass('image-processing', imageElementView);
287
- });
288
- }
289
- /**
290
- * Replace the edited image with the new one.
291
- */
292
- _replaceImage(element, asset) {
293
- const editor = this.editor;
294
- const { imageFallbackUrl, imageSources, imageWidth, imageHeight, imagePlaceholder } = prepareImageAssetAttributes(asset);
295
- const previousSelectionRanges = Array.from(editor.model.document.selection.getRanges());
296
- editor.model.change(writer => {
297
- writer.setSelection(element, 'on');
298
- editor.execute('insertImage', {
299
- imageType: element.is('element', 'imageInline') ? 'imageInline' : null,
300
- source: {
301
- src: imageFallbackUrl,
302
- sources: imageSources,
303
- width: imageWidth,
304
- height: imageHeight,
305
- ...(imagePlaceholder ? { placeholder: imagePlaceholder } : null),
306
- ...(element.hasAttribute('alt') ? { alt: element.getAttribute('alt') } : null)
307
- }
308
- });
309
- const previousChildren = element.getChildren();
310
- element = editor.model.document.selection.getSelectedElement();
311
- for (const child of previousChildren) {
312
- writer.append(writer.cloneElement(child), element);
313
- }
314
- writer.setAttribute('ckboxImageId', asset.data.id, element);
315
- writer.setSelection(previousSelectionRanges);
316
- });
317
- }
318
- }
@@ -1,42 +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 ckbox/ckboximageedit/ckboximageeditediting
7
- */
8
- import { PendingActions, Plugin } from 'ckeditor5/src/core.js';
9
- import { Notification } from 'ckeditor5/src/ui.js';
10
- import { CKBoxImageEditCommand } from './ckboximageeditcommand.js';
11
- import { CKBoxEditing } from '../ckboxediting.js';
12
- import { CKBoxUtils } from '../ckboxutils.js';
13
- /**
14
- * The CKBox image edit editing plugin.
15
- */
16
- export class CKBoxImageEditEditing extends Plugin {
17
- /**
18
- * @inheritDoc
19
- */
20
- static get pluginName() {
21
- return 'CKBoxImageEditEditing';
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- static get isOfficialPlugin() {
27
- return true;
28
- }
29
- /**
30
- * @inheritDoc
31
- */
32
- static get requires() {
33
- return [CKBoxEditing, CKBoxUtils, PendingActions, Notification, 'ImageUtils', 'ImageEditing'];
34
- }
35
- /**
36
- * @inheritDoc
37
- */
38
- init() {
39
- const { editor } = this;
40
- editor.commands.add('ckboxImageEdit', new CKBoxImageEditCommand(editor));
41
- }
42
- }
@@ -1,57 +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 ckbox/ckboximageedit/ckboximageeditui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ButtonView } from 'ckeditor5/src/ui.js';
10
- import { IconCkboxImageEdit } from 'ckeditor5/src/icons.js';
11
- /**
12
- * The UI plugin of the CKBox image edit feature.
13
- *
14
- * It registers the `'ckboxImageEdit'` UI button in the editor's {@link module:ui/componentfactory~ComponentFactory component factory}
15
- * that allows you to open the CKBox dialog and edit the image.
16
- */
17
- export class CKBoxImageEditUI extends Plugin {
18
- /**
19
- * @inheritDoc
20
- */
21
- static get pluginName() {
22
- return 'CKBoxImageEditUI';
23
- }
24
- /**
25
- * @inheritDoc
26
- */
27
- static get isOfficialPlugin() {
28
- return true;
29
- }
30
- /**
31
- * @inheritDoc
32
- */
33
- init() {
34
- const editor = this.editor;
35
- editor.ui.componentFactory.add('ckboxImageEdit', locale => {
36
- const command = editor.commands.get('ckboxImageEdit');
37
- const uploadImageCommand = editor.commands.get('uploadImage');
38
- const view = new ButtonView(locale);
39
- const t = locale.t;
40
- view.set({
41
- icon: IconCkboxImageEdit,
42
- tooltip: true
43
- });
44
- view.bind('label').to(uploadImageCommand, 'isAccessAllowed', isAccessAllowed => isAccessAllowed ?
45
- t('Edit image') :
46
- t('You have no image editing permissions.'));
47
- view.bind('isOn').to(command, 'value', command, 'isEnabled', (value, isEnabled) => value && isEnabled);
48
- view.bind('isEnabled').to(command);
49
- // Execute the command.
50
- this.listenTo(view, 'execute', () => {
51
- editor.execute('ckboxImageEdit');
52
- editor.editing.view.focus();
53
- });
54
- return view;
55
- });
56
- }
57
- }
@@ -1,48 +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 ckbox/ckboximageedit/utils
7
- */
8
- import { global } from 'ckeditor5/src/utils.js';
9
- /**
10
- * @internal
11
- */
12
- export function createEditabilityChecker(allowExternalImagesEditing) {
13
- const checkUrl = createUrlChecker(allowExternalImagesEditing);
14
- return element => {
15
- const isImageElement = element.is('element', 'imageInline') ||
16
- element.is('element', 'imageBlock');
17
- if (!isImageElement) {
18
- return false;
19
- }
20
- if (element.hasAttribute('ckboxImageId')) {
21
- return true;
22
- }
23
- if (element.hasAttribute('src')) {
24
- return checkUrl(element.getAttribute('src'));
25
- }
26
- return false;
27
- };
28
- }
29
- function createUrlChecker(allowExternalImagesEditing) {
30
- if (Array.isArray(allowExternalImagesEditing)) {
31
- const urlMatchers = allowExternalImagesEditing.map(createUrlChecker);
32
- return src => urlMatchers.some(matcher => matcher(src));
33
- }
34
- if (allowExternalImagesEditing == 'origin') {
35
- const origin = global.window.location.origin;
36
- return src => new URL(src, global.document.baseURI).origin == origin;
37
- }
38
- if (typeof allowExternalImagesEditing == 'function') {
39
- return allowExternalImagesEditing;
40
- }
41
- if (allowExternalImagesEditing instanceof RegExp) {
42
- return src => !!(src.match(allowExternalImagesEditing) ||
43
- src.replace(/^https?:\/\//, '').match(allowExternalImagesEditing));
44
- }
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
- const shouldBeUndefned = allowExternalImagesEditing;
47
- return () => false;
48
- }
@@ -1,34 +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 ckbox/ckboximageedit
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { CKBoxImageEditEditing } from './ckboximageedit/ckboximageeditediting.js';
10
- import { CKBoxImageEditUI } from './ckboximageedit/ckboximageeditui.js';
11
- import '../theme/ckboximageedit.css';
12
- /**
13
- * The CKBox image edit feature.
14
- */
15
- export class CKBoxImageEdit extends Plugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName() {
20
- return 'CKBoxImageEdit';
21
- }
22
- /**
23
- * @inheritDoc
24
- */
25
- static get isOfficialPlugin() {
26
- return true;
27
- }
28
- /**
29
- * @inheritDoc
30
- */
31
- static get requires() {
32
- return [CKBoxImageEditEditing, CKBoxImageEditUI];
33
- }
34
- }
package/src/ckboxui.js DELETED
@@ -1,139 +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 ckbox/ckboxui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core.js';
9
- import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
10
- import { IconBrowseFiles, IconImageAssetManager } from 'ckeditor5/src/icons.js';
11
- /**
12
- * Introduces UI components for the `CKBox` plugin.
13
- *
14
- * The plugin introduces two UI components to the {@link module:ui/componentfactory~ComponentFactory UI component factory}:
15
- *
16
- * * the `'ckbox'` toolbar button,
17
- * * the `'menuBar:ckbox'` menu bar component, which is by default added to the `'Insert'` menu.
18
- *
19
- * It also integrates with the `insertImage` toolbar component and `menuBar:insertImage` menu component.
20
- */
21
- export class CKBoxUI extends Plugin {
22
- /**
23
- * @inheritDoc
24
- */
25
- static get pluginName() {
26
- return 'CKBoxUI';
27
- }
28
- /**
29
- * @inheritDoc
30
- */
31
- static get isOfficialPlugin() {
32
- return true;
33
- }
34
- /**
35
- * @inheritDoc
36
- */
37
- afterInit() {
38
- const editor = this.editor;
39
- // Do not register the `ckbox` button if the command does not exist.
40
- // This might happen when CKBox library is not loaded on the page.
41
- if (!editor.commands.get('ckbox')) {
42
- return;
43
- }
44
- editor.ui.componentFactory.add('ckbox', () => this._createFileToolbarButton());
45
- editor.ui.componentFactory.add('menuBar:ckbox', () => this._createFileMenuBarButton());
46
- if (editor.plugins.has('ImageInsertUI')) {
47
- editor.plugins.get('ImageInsertUI').registerIntegration({
48
- name: 'assetManager',
49
- observable: () => editor.commands.get('ckbox'),
50
- buttonViewCreator: () => this._createImageToolbarButton(),
51
- formViewCreator: () => this._createImageDropdownButton(),
52
- menuBarButtonViewCreator: isOnly => this._createImageMenuBarButton(isOnly ? 'insertOnly' : 'insertNested')
53
- });
54
- }
55
- }
56
- /**
57
- * Creates the base for various kinds of the button component provided by this feature.
58
- */
59
- _createButton(ButtonClass) {
60
- const editor = this.editor;
61
- const locale = editor.locale;
62
- const view = new ButtonClass(locale);
63
- const command = editor.commands.get('ckbox');
64
- view.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
65
- view.on('execute', () => {
66
- editor.execute('ckbox');
67
- });
68
- return view;
69
- }
70
- /**
71
- * Creates a simple toolbar button for files management, with an icon and a tooltip.
72
- */
73
- _createFileToolbarButton() {
74
- const t = this.editor.locale.t;
75
- const button = this._createButton(ButtonView);
76
- button.icon = IconBrowseFiles;
77
- button.label = t('Open file manager');
78
- button.tooltip = true;
79
- return button;
80
- }
81
- /**
82
- * Creates a simple toolbar button for images management, with an icon and a tooltip.
83
- */
84
- _createImageToolbarButton() {
85
- const t = this.editor.locale.t;
86
- const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
87
- const button = this._createButton(ButtonView);
88
- button.icon = IconImageAssetManager;
89
- button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ? t('Replace image with file manager') : t('Insert image with file manager'));
90
- button.tooltip = true;
91
- return button;
92
- }
93
- /**
94
- * Creates a button for images management for the dropdown view, with an icon, text and no tooltip.
95
- */
96
- _createImageDropdownButton() {
97
- const t = this.editor.locale.t;
98
- const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
99
- const button = this._createButton(ButtonView);
100
- button.icon = IconImageAssetManager;
101
- button.withText = true;
102
- button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ? t('Replace with file manager') : t('Insert with file manager'));
103
- button.on('execute', () => {
104
- imageInsertUI.dropdownView.isOpen = false;
105
- });
106
- return button;
107
- }
108
- /**
109
- * Creates a button for files management for the menu bar.
110
- */
111
- _createFileMenuBarButton() {
112
- const t = this.editor.locale.t;
113
- const button = this._createButton(MenuBarMenuListItemButtonView);
114
- button.icon = IconBrowseFiles;
115
- button.withText = true;
116
- button.label = t('File');
117
- return button;
118
- }
119
- /**
120
- * Creates a button for images management for the menu bar.
121
- */
122
- _createImageMenuBarButton(type) {
123
- // Use t() stored in a variable with a different name to reuse existing translations from another package.
124
- const translateVariableKey = this.editor.locale.t;
125
- const t = this.editor.locale.t;
126
- const button = this._createButton(MenuBarMenuListItemButtonView);
127
- button.icon = IconImageAssetManager;
128
- button.withText = true;
129
- switch (type) {
130
- case 'insertOnly':
131
- button.label = translateVariableKey('Image');
132
- break;
133
- case 'insertNested':
134
- button.label = t('With file manager');
135
- break;
136
- }
137
- return button;
138
- }
139
- }