@ckeditor/ckeditor5-ckbox 0.0.0-internal-20241017.0 → 0.0.0-internal-20241206.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.
- package/LICENSE.md +7 -2
- package/README.md +22 -7
- package/build/ckbox.js +1 -1
- package/build/translations/af.js +1 -0
- package/build/translations/ast.js +1 -0
- package/build/translations/bs.js +1 -0
- package/build/translations/de-ch.js +1 -0
- package/build/translations/en-gb.js +1 -0
- package/build/translations/eo.js +1 -0
- package/build/translations/eu.js +1 -0
- package/build/translations/gu.js +1 -0
- package/build/translations/hy.js +1 -0
- package/build/translations/jv.js +1 -0
- package/build/translations/kk.js +1 -0
- package/build/translations/km.js +1 -0
- package/build/translations/kn.js +1 -0
- package/build/translations/ku.js +1 -0
- package/build/translations/nb.js +1 -0
- package/build/translations/ne.js +1 -0
- package/build/translations/oc.js +1 -0
- package/build/translations/si.js +1 -0
- package/build/translations/sl.js +1 -0
- package/build/translations/ti.js +1 -0
- package/build/translations/tk.js +1 -0
- package/build/translations/tt.js +1 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.js +270 -295
- package/dist/index.js.map +1 -1
- package/dist/translations/af.d.ts +8 -0
- package/dist/translations/af.js +5 -0
- package/dist/translations/af.umd.js +11 -0
- package/dist/translations/ar.js +1 -1
- package/dist/translations/ar.umd.js +1 -1
- package/dist/translations/ast.d.ts +8 -0
- package/dist/translations/ast.js +5 -0
- package/dist/translations/ast.umd.js +11 -0
- package/dist/translations/bs.d.ts +8 -0
- package/dist/translations/bs.js +5 -0
- package/dist/translations/bs.umd.js +11 -0
- package/dist/translations/cs.js +1 -1
- package/dist/translations/cs.umd.js +1 -1
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de-ch.umd.js +11 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en-gb.umd.js +11 -0
- package/dist/translations/en.js +1 -1
- package/dist/translations/en.umd.js +1 -1
- package/dist/translations/eo.d.ts +8 -0
- package/dist/translations/eo.js +5 -0
- package/dist/translations/eo.umd.js +11 -0
- package/dist/translations/es-co.js +1 -1
- package/dist/translations/es-co.umd.js +1 -1
- package/dist/translations/es.js +1 -1
- package/dist/translations/es.umd.js +1 -1
- package/dist/translations/eu.d.ts +8 -0
- package/dist/translations/eu.js +5 -0
- package/dist/translations/eu.umd.js +11 -0
- package/dist/translations/fa.js +1 -1
- package/dist/translations/fa.umd.js +1 -1
- package/dist/translations/fr.js +1 -1
- package/dist/translations/fr.umd.js +1 -1
- package/dist/translations/gu.d.ts +8 -0
- package/dist/translations/gu.js +5 -0
- package/dist/translations/gu.umd.js +11 -0
- package/dist/translations/he.js +1 -1
- package/dist/translations/he.umd.js +1 -1
- package/dist/translations/hr.js +1 -1
- package/dist/translations/hr.umd.js +1 -1
- package/dist/translations/hy.d.ts +8 -0
- package/dist/translations/hy.js +5 -0
- package/dist/translations/hy.umd.js +11 -0
- package/dist/translations/it.js +1 -1
- package/dist/translations/it.umd.js +1 -1
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/jv.umd.js +11 -0
- package/dist/translations/kk.d.ts +8 -0
- package/dist/translations/kk.js +5 -0
- package/dist/translations/kk.umd.js +11 -0
- package/dist/translations/km.d.ts +8 -0
- package/dist/translations/km.js +5 -0
- package/dist/translations/km.umd.js +11 -0
- package/dist/translations/kn.d.ts +8 -0
- package/dist/translations/kn.js +5 -0
- package/dist/translations/kn.umd.js +11 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/ku.umd.js +11 -0
- package/dist/translations/lt.js +1 -1
- package/dist/translations/lt.umd.js +1 -1
- package/dist/translations/lv.js +1 -1
- package/dist/translations/lv.umd.js +1 -1
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/nb.umd.js +11 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/ne.umd.js +11 -0
- package/dist/translations/oc.d.ts +8 -0
- package/dist/translations/oc.js +5 -0
- package/dist/translations/oc.umd.js +11 -0
- package/dist/translations/pl.js +1 -1
- package/dist/translations/pl.umd.js +1 -1
- package/dist/translations/pt-br.js +1 -1
- package/dist/translations/pt-br.umd.js +1 -1
- package/dist/translations/pt.js +1 -1
- package/dist/translations/pt.umd.js +1 -1
- package/dist/translations/ro.js +1 -1
- package/dist/translations/ro.umd.js +1 -1
- package/dist/translations/ru.js +1 -1
- package/dist/translations/ru.umd.js +1 -1
- package/dist/translations/si.d.ts +8 -0
- package/dist/translations/si.js +5 -0
- package/dist/translations/si.umd.js +11 -0
- package/dist/translations/sk.js +1 -1
- package/dist/translations/sk.umd.js +1 -1
- package/dist/translations/sl.d.ts +8 -0
- package/dist/translations/sl.js +5 -0
- package/dist/translations/sl.umd.js +11 -0
- package/dist/translations/sr-latn.js +1 -1
- package/dist/translations/sr-latn.umd.js +1 -1
- package/dist/translations/sr.js +1 -1
- package/dist/translations/sr.umd.js +1 -1
- package/dist/translations/ti.d.ts +8 -0
- package/dist/translations/ti.js +5 -0
- package/dist/translations/ti.umd.js +11 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tk.umd.js +11 -0
- package/dist/translations/tt.d.ts +8 -0
- package/dist/translations/tt.js +5 -0
- package/dist/translations/tt.umd.js +11 -0
- package/dist/translations/ug.js +1 -1
- package/dist/translations/ug.umd.js +1 -1
- package/dist/translations/uk.js +1 -1
- package/dist/translations/uk.umd.js +1 -1
- package/dist/translations/uz.js +1 -1
- package/dist/translations/uz.umd.js +1 -1
- package/lang/translations/af.po +44 -0
- package/lang/translations/ar.po +4 -10
- package/lang/translations/ast.po +44 -0
- package/lang/translations/az.po +3 -9
- package/lang/translations/bg.po +3 -9
- package/lang/translations/bn.po +3 -9
- package/lang/translations/bs.po +44 -0
- package/lang/translations/ca.po +3 -9
- package/lang/translations/cs.po +4 -10
- package/lang/translations/da.po +3 -9
- package/lang/translations/de-ch.po +44 -0
- package/lang/translations/de.po +3 -9
- package/lang/translations/el.po +3 -9
- package/lang/translations/en-au.po +3 -9
- package/lang/translations/en-gb.po +44 -0
- package/lang/translations/en.po +5 -11
- package/lang/translations/eo.po +44 -0
- package/lang/translations/es-co.po +4 -10
- package/lang/translations/es.po +4 -10
- package/lang/translations/et.po +3 -9
- package/lang/translations/eu.po +44 -0
- package/lang/translations/fa.po +4 -10
- package/lang/translations/fi.po +3 -9
- package/lang/translations/fr.po +4 -10
- package/lang/translations/gl.po +3 -9
- package/lang/translations/gu.po +44 -0
- package/lang/translations/he.po +4 -10
- package/lang/translations/hi.po +3 -9
- package/lang/translations/hr.po +4 -10
- package/lang/translations/hu.po +3 -9
- package/lang/translations/hy.po +44 -0
- package/lang/translations/id.po +3 -9
- package/lang/translations/it.po +4 -10
- package/lang/translations/ja.po +3 -9
- package/lang/translations/jv.po +44 -0
- package/lang/translations/kk.po +44 -0
- package/lang/translations/km.po +44 -0
- package/lang/translations/kn.po +44 -0
- package/lang/translations/ko.po +3 -9
- package/lang/translations/ku.po +44 -0
- package/lang/translations/lt.po +4 -10
- package/lang/translations/lv.po +4 -10
- package/lang/translations/ms.po +3 -9
- package/lang/translations/nb.po +44 -0
- package/lang/translations/ne.po +44 -0
- package/lang/translations/nl.po +3 -9
- package/lang/translations/no.po +3 -9
- package/lang/translations/oc.po +44 -0
- package/lang/translations/pl.po +4 -10
- package/lang/translations/pt-br.po +4 -10
- package/lang/translations/pt.po +4 -10
- package/lang/translations/ro.po +4 -10
- package/lang/translations/ru.po +4 -10
- package/lang/translations/si.po +44 -0
- package/lang/translations/sk.po +4 -10
- package/lang/translations/sl.po +44 -0
- package/lang/translations/sq.po +3 -9
- package/lang/translations/sr-latn.po +4 -10
- package/lang/translations/sr.po +4 -10
- package/lang/translations/sv.po +3 -9
- package/lang/translations/th.po +3 -9
- package/lang/translations/ti.po +44 -0
- package/lang/translations/tk.po +44 -0
- package/lang/translations/tr.po +3 -9
- package/lang/translations/tt.po +44 -0
- package/lang/translations/ug.po +4 -10
- package/lang/translations/uk.po +4 -10
- package/lang/translations/ur.po +3 -9
- package/lang/translations/uz.po +4 -10
- package/lang/translations/vi.po +3 -9
- package/lang/translations/zh-cn.po +3 -9
- package/lang/translations/zh.po +3 -9
- package/package.json +28 -9
- package/src/augmentation.d.ts +1 -1
- package/src/augmentation.js +1 -1
- package/src/ckbox.d.ts +1 -1
- package/src/ckbox.js +1 -1
- package/src/ckboxcommand.d.ts +1 -1
- package/src/ckboxcommand.js +1 -1
- package/src/ckboxconfig.d.ts +1 -1
- package/src/ckboxconfig.js +1 -1
- package/src/ckboxediting.d.ts +1 -1
- package/src/ckboxediting.js +1 -1
- package/src/ckboximageedit/ckboximageeditcommand.d.ts +1 -1
- package/src/ckboximageedit/ckboximageeditcommand.js +1 -1
- package/src/ckboximageedit/ckboximageeditediting.d.ts +1 -1
- package/src/ckboximageedit/ckboximageeditediting.js +1 -1
- package/src/ckboximageedit/ckboximageeditui.d.ts +1 -1
- package/src/ckboximageedit/ckboximageeditui.js +1 -1
- package/src/ckboximageedit/utils.d.ts +1 -1
- package/src/ckboximageedit/utils.js +1 -1
- package/src/ckboximageedit.d.ts +1 -1
- package/src/ckboximageedit.js +1 -1
- package/src/ckboxui.d.ts +1 -1
- package/src/ckboxui.js +4 -2
- package/src/ckboxuploadadapter.d.ts +1 -1
- package/src/ckboxuploadadapter.js +1 -1
- package/src/ckboxutils.d.ts +1 -1
- package/src/ckboxutils.js +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/utils.d.ts +1 -1
- package/src/utils.js +1 -1
- package/theme/ckboximageedit.css +1 -1
- package/dist/augmentation.d.ts +0 -36
- package/dist/ckbox.d.ts +0 -41
- package/dist/ckboxcommand.d.ts +0 -130
- package/dist/ckboxconfig.d.ts +0 -434
- package/dist/ckboxediting.d.ts +0 -65
- package/dist/ckboximageedit/ckboximageeditcommand.d.ts +0 -109
- package/dist/ckboximageedit/ckboximageeditediting.d.ts +0 -36
- package/dist/ckboximageedit/ckboximageeditui.d.ts +0 -32
- package/dist/ckboximageedit/utils.d.ts +0 -14
- package/dist/ckboximageedit.d.ts +0 -32
- package/dist/ckboxui.d.ts +0 -60
- package/dist/ckboxuploadadapter.d.ts +0 -41
- package/dist/ckboxutils.d.ts +0 -58
- package/dist/index.d.ts +0 -21
- package/dist/utils.d.ts +0 -67
package/dist/index.js
CHANGED
|
@@ -21,18 +21,18 @@ import { isEqual } from 'lodash-es';
|
|
|
21
21
|
* It also integrates with the `insertImage` toolbar component and `menuBar:insertImage` menu component.
|
|
22
22
|
*/ class CKBoxUI extends Plugin {
|
|
23
23
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/ static get pluginName() {
|
|
26
26
|
return 'CKBoxUI';
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/ static get isOfficialPlugin() {
|
|
31
31
|
return true;
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/ afterInit() {
|
|
36
36
|
const editor = this.editor;
|
|
37
37
|
// Do not register the `ckbox` button if the command does not exist.
|
|
38
38
|
// This might happen when CKBox library is not loaded on the page.
|
|
@@ -52,8 +52,8 @@ import { isEqual } from 'lodash-es';
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
* Creates the base for various kinds of the button component provided by this feature.
|
|
56
|
+
*/ _createButton(ButtonClass) {
|
|
57
57
|
const editor = this.editor;
|
|
58
58
|
const locale = editor.locale;
|
|
59
59
|
const view = new ButtonClass(locale);
|
|
@@ -65,8 +65,8 @@ import { isEqual } from 'lodash-es';
|
|
|
65
65
|
return view;
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
* Creates a simple toolbar button for files management, with an icon and a tooltip.
|
|
69
|
+
*/ _createFileToolbarButton() {
|
|
70
70
|
const t = this.editor.locale.t;
|
|
71
71
|
const button = this._createButton(ButtonView);
|
|
72
72
|
button.icon = icons.browseFiles;
|
|
@@ -75,8 +75,8 @@ import { isEqual } from 'lodash-es';
|
|
|
75
75
|
return button;
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
* Creates a simple toolbar button for images management, with an icon and a tooltip.
|
|
79
|
+
*/ _createImageToolbarButton() {
|
|
80
80
|
const t = this.editor.locale.t;
|
|
81
81
|
const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
|
|
82
82
|
const button = this._createButton(ButtonView);
|
|
@@ -86,8 +86,8 @@ import { isEqual } from 'lodash-es';
|
|
|
86
86
|
return button;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
* Creates a button for images management for the dropdown view, with an icon, text and no tooltip.
|
|
90
|
+
*/ _createImageDropdownButton() {
|
|
91
91
|
const t = this.editor.locale.t;
|
|
92
92
|
const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
|
|
93
93
|
const button = this._createButton(ButtonView);
|
|
@@ -100,8 +100,8 @@ import { isEqual } from 'lodash-es';
|
|
|
100
100
|
return button;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
* Creates a button for files management for the menu bar.
|
|
104
|
+
*/ _createFileMenuBarButton() {
|
|
105
105
|
const t = this.editor.locale.t;
|
|
106
106
|
const button = this._createButton(MenuBarMenuListItemButtonView);
|
|
107
107
|
button.icon = icons.browseFiles;
|
|
@@ -110,15 +110,17 @@ import { isEqual } from 'lodash-es';
|
|
|
110
110
|
return button;
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
* Creates a button for images management for the menu bar.
|
|
114
|
+
*/ _createImageMenuBarButton(type) {
|
|
115
|
+
// Use t() stored in a variable with a different name to reuse existing translations from another package.
|
|
116
|
+
const translateVariableKey = this.editor.locale.t;
|
|
115
117
|
const t = this.editor.locale.t;
|
|
116
118
|
const button = this._createButton(MenuBarMenuListItemButtonView);
|
|
117
119
|
button.icon = icons.imageAssetManager;
|
|
118
120
|
button.withText = true;
|
|
119
121
|
switch(type){
|
|
120
122
|
case 'insertOnly':
|
|
121
|
-
button.label =
|
|
123
|
+
button.label = translateVariableKey('Image');
|
|
122
124
|
break;
|
|
123
125
|
case 'insertNested':
|
|
124
126
|
button.label = t('With file manager');
|
|
@@ -310,53 +312,53 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
310
312
|
* {@link module:link/link~Link Link feature}.
|
|
311
313
|
*/ class CKBoxCommand extends Command {
|
|
312
314
|
/**
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
* This association map is then used to set the ID on the model element.
|
|
316
|
-
*
|
|
317
|
-
* All chosen assets are automatically removed after the timeout, because (theoretically) it may happen that they will never be
|
|
318
|
-
* inserted into the model, even if the {@link module:link/linkcommand~LinkCommand `'link'`} command or the
|
|
319
|
-
* {@link module:image/image/insertimagecommand~InsertImageCommand `'insertImage'`} command is enabled. Such a case may arise when
|
|
320
|
-
* another plugin blocks the command execution. Then, in order not to keep the chosen (but not inserted) assets forever, we delete
|
|
321
|
-
* them automatically to prevent memory leakage. The 1 second timeout is enough to insert the asset into the model and extract the
|
|
322
|
-
* ID from the chosen asset.
|
|
323
|
-
*
|
|
324
|
-
* The assets are stored only if
|
|
325
|
-
* the {@link module:ckbox/ckboxconfig~CKBoxConfig#ignoreDataId `config.ckbox.ignoreDataId`} option is set to `false` (by default).
|
|
326
|
-
*
|
|
327
|
-
* @internal
|
|
328
|
-
*/ _chosenAssets = new Set();
|
|
329
|
-
/**
|
|
330
|
-
* The DOM element that acts as a mounting point for the CKBox dialog.
|
|
331
|
-
*/ _wrapper = null;
|
|
332
|
-
/**
|
|
333
|
-
* @inheritDoc
|
|
334
|
-
*/ constructor(editor){
|
|
315
|
+
* @inheritDoc
|
|
316
|
+
*/ constructor(editor){
|
|
335
317
|
super(editor);
|
|
318
|
+
/**
|
|
319
|
+
* A set of all chosen assets. They are stored temporarily and they are automatically removed 1 second after being chosen.
|
|
320
|
+
* Chosen assets have to be "remembered" for a while to be able to map the given asset with the element inserted into the model.
|
|
321
|
+
* This association map is then used to set the ID on the model element.
|
|
322
|
+
*
|
|
323
|
+
* All chosen assets are automatically removed after the timeout, because (theoretically) it may happen that they will never be
|
|
324
|
+
* inserted into the model, even if the {@link module:link/linkcommand~LinkCommand `'link'`} command or the
|
|
325
|
+
* {@link module:image/image/insertimagecommand~InsertImageCommand `'insertImage'`} command is enabled. Such a case may arise when
|
|
326
|
+
* another plugin blocks the command execution. Then, in order not to keep the chosen (but not inserted) assets forever, we delete
|
|
327
|
+
* them automatically to prevent memory leakage. The 1 second timeout is enough to insert the asset into the model and extract the
|
|
328
|
+
* ID from the chosen asset.
|
|
329
|
+
*
|
|
330
|
+
* The assets are stored only if
|
|
331
|
+
* the {@link module:ckbox/ckboxconfig~CKBoxConfig#ignoreDataId `config.ckbox.ignoreDataId`} option is set to `false` (by default).
|
|
332
|
+
*
|
|
333
|
+
* @internal
|
|
334
|
+
*/ this._chosenAssets = new Set();
|
|
335
|
+
/**
|
|
336
|
+
* The DOM element that acts as a mounting point for the CKBox dialog.
|
|
337
|
+
*/ this._wrapper = null;
|
|
336
338
|
this._initListeners();
|
|
337
339
|
}
|
|
338
340
|
/**
|
|
339
|
-
|
|
340
|
-
|
|
341
|
+
* @inheritDoc
|
|
342
|
+
*/ refresh() {
|
|
341
343
|
this.value = this._getValue();
|
|
342
344
|
this.isEnabled = this._checkEnabled();
|
|
343
345
|
}
|
|
344
346
|
/**
|
|
345
|
-
|
|
346
|
-
|
|
347
|
+
* @inheritDoc
|
|
348
|
+
*/ execute() {
|
|
347
349
|
this.fire('ckbox:open');
|
|
348
350
|
}
|
|
349
351
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
* Indicates if the CKBox dialog is already opened.
|
|
353
|
+
*
|
|
354
|
+
* @protected
|
|
355
|
+
* @returns {Boolean}
|
|
356
|
+
*/ _getValue() {
|
|
355
357
|
return this._wrapper !== null;
|
|
356
358
|
}
|
|
357
359
|
/**
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
* Checks whether the command can be enabled in the current context.
|
|
361
|
+
*/ _checkEnabled() {
|
|
360
362
|
const imageCommand = this.editor.commands.get('insertImage');
|
|
361
363
|
const linkCommand = this.editor.commands.get('link');
|
|
362
364
|
if (!imageCommand.isEnabled && !linkCommand.isEnabled) {
|
|
@@ -365,29 +367,29 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
365
367
|
return true;
|
|
366
368
|
}
|
|
367
369
|
/**
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
370
|
+
* Creates the options object for the CKBox dialog.
|
|
371
|
+
*
|
|
372
|
+
* @returns The object with properties:
|
|
373
|
+
* - theme The theme for CKBox dialog.
|
|
374
|
+
* - language The language for CKBox dialog.
|
|
375
|
+
* - tokenUrl The token endpoint URL.
|
|
376
|
+
* - serviceOrigin The base URL of the API service.
|
|
377
|
+
* - forceDemoLabel Whether to force "Powered by CKBox" link.
|
|
378
|
+
* - assets.onChoose The callback function invoked after choosing the assets.
|
|
379
|
+
* - dialog.onClose The callback function invoked after closing the CKBox dialog.
|
|
380
|
+
* - dialog.width The dialog width in pixels.
|
|
381
|
+
* - dialog.height The dialog height in pixels.
|
|
382
|
+
* - categories.icons Allows setting custom icons for categories.
|
|
383
|
+
* - view.openLastView Sets if the last view visited by the user will be reopened
|
|
384
|
+
* on the next startup.
|
|
385
|
+
* - view.startupFolderId Sets the ID of the folder that will be opened on startup.
|
|
386
|
+
* - view.startupCategoryId Sets the ID of the category that will be opened on startup.
|
|
387
|
+
* - view.hideMaximizeButton Sets whether to hide the ‘Maximize’ button.
|
|
388
|
+
* - view.componentsHideTimeout Sets timeout after which upload components are hidden
|
|
389
|
+
* after completed upload.
|
|
390
|
+
* - view.dialogMinimizeTimeout Sets timeout after which upload dialog is minimized
|
|
391
|
+
* after completed upload.
|
|
392
|
+
*/ _prepareOptions() {
|
|
391
393
|
const editor = this.editor;
|
|
392
394
|
const ckboxConfig = editor.config.get('ckbox');
|
|
393
395
|
const dialog = ckboxConfig.dialog;
|
|
@@ -425,8 +427,8 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
425
427
|
};
|
|
426
428
|
}
|
|
427
429
|
/**
|
|
428
|
-
|
|
429
|
-
|
|
430
|
+
* Initializes various event listeners for the `ckbox:*` events, because all functionality of the `ckbox` command is event-based.
|
|
431
|
+
*/ _initListeners() {
|
|
430
432
|
const editor = this.editor;
|
|
431
433
|
const model = editor.model;
|
|
432
434
|
const shouldInsertDataId = !editor.config.get('ckbox.ignoreDataId');
|
|
@@ -495,13 +497,13 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
495
497
|
});
|
|
496
498
|
}
|
|
497
499
|
/**
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
500
|
+
* Inserts the asset into the model.
|
|
501
|
+
*
|
|
502
|
+
* @param asset The asset to be inserted.
|
|
503
|
+
* @param isLastAsset Indicates if the current asset is the last one from the chosen set.
|
|
504
|
+
* @param writer An instance of the model writer.
|
|
505
|
+
* @param isSingleAsset It's true when only one asset is processed.
|
|
506
|
+
*/ _insertAsset(asset, isLastAsset, writer, isSingleAsset) {
|
|
505
507
|
const editor = this.editor;
|
|
506
508
|
const model = editor.model;
|
|
507
509
|
const selection = model.document.selection;
|
|
@@ -519,10 +521,10 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
519
521
|
}
|
|
520
522
|
}
|
|
521
523
|
/**
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
* Inserts the image by calling the `insertImage` command.
|
|
525
|
+
*
|
|
526
|
+
* @param asset The asset to be inserted.
|
|
527
|
+
*/ _insertImage(asset) {
|
|
526
528
|
const editor = this.editor;
|
|
527
529
|
const { imageFallbackUrl, imageSources, imageTextAlternative, imageWidth, imageHeight, imagePlaceholder } = asset.attributes;
|
|
528
530
|
editor.execute('insertImage', {
|
|
@@ -539,12 +541,12 @@ const ASSET_INSERTION_WAIT_TIMEOUT = 1000;
|
|
|
539
541
|
});
|
|
540
542
|
}
|
|
541
543
|
/**
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
544
|
+
* Inserts the link to the asset by calling the `link` command.
|
|
545
|
+
*
|
|
546
|
+
* @param asset The asset to be inserted.
|
|
547
|
+
* @param writer An instance of the model writer.
|
|
548
|
+
* @param isSingleAsset It's true when only one asset is processed.
|
|
549
|
+
*/ _insertLink(asset, writer, isSingleAsset) {
|
|
548
550
|
const editor = this.editor;
|
|
549
551
|
const model = editor.model;
|
|
550
552
|
const selection = model.document.selection;
|
|
@@ -639,28 +641,25 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
639
641
|
* The CKBox utilities plugin.
|
|
640
642
|
*/ class CKBoxUtils extends Plugin {
|
|
641
643
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* @inheritDoc
|
|
646
|
-
*/ static get pluginName() {
|
|
644
|
+
* @inheritDoc
|
|
645
|
+
*/ static get pluginName() {
|
|
647
646
|
return 'CKBoxUtils';
|
|
648
647
|
}
|
|
649
648
|
/**
|
|
650
|
-
|
|
651
|
-
|
|
649
|
+
* @inheritDoc
|
|
650
|
+
*/ static get isOfficialPlugin() {
|
|
652
651
|
return true;
|
|
653
652
|
}
|
|
654
653
|
/**
|
|
655
|
-
|
|
656
|
-
|
|
654
|
+
* @inheritDoc
|
|
655
|
+
*/ static get requires() {
|
|
657
656
|
return [
|
|
658
657
|
'CloudServices'
|
|
659
658
|
];
|
|
660
659
|
}
|
|
661
660
|
/**
|
|
662
|
-
|
|
663
|
-
|
|
661
|
+
* @inheritDoc
|
|
662
|
+
*/ init() {
|
|
664
663
|
const editor = this.editor;
|
|
665
664
|
const hasConfiguration = !!editor.config.get('ckbox');
|
|
666
665
|
const isLibraryLoaded = !!window.CKBox;
|
|
@@ -682,22 +681,22 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
682
681
|
const ckboxTokenUrl = editor.config.get('ckbox.tokenUrl');
|
|
683
682
|
if (!ckboxTokenUrl) {
|
|
684
683
|
/**
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
684
|
+
* The {@link module:ckbox/ckboxconfig~CKBoxConfig#tokenUrl `config.ckbox.tokenUrl`} or the
|
|
685
|
+
* {@link module:cloud-services/cloudservicesconfig~CloudServicesConfig#tokenUrl `config.cloudServices.tokenUrl`}
|
|
686
|
+
* configuration is required for the CKBox plugin.
|
|
687
|
+
*
|
|
688
|
+
* ```ts
|
|
689
|
+
* ClassicEditor.create( document.createElement( 'div' ), {
|
|
690
|
+
* ckbox: {
|
|
691
|
+
* tokenUrl: "YOUR_TOKEN_URL"
|
|
692
|
+
* // ...
|
|
693
|
+
* }
|
|
694
|
+
* // ...
|
|
695
|
+
* } );
|
|
696
|
+
* ```
|
|
697
|
+
*
|
|
698
|
+
* @error ckbox-plugin-missing-token-url
|
|
699
|
+
*/ throw new CKEditorError('ckbox-plugin-missing-token-url', this);
|
|
701
700
|
}
|
|
702
701
|
if (ckboxTokenUrl == cloudServicesTokenUrl) {
|
|
703
702
|
this._token = Promise.resolve(cloudServices.token);
|
|
@@ -706,30 +705,30 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
706
705
|
}
|
|
707
706
|
}
|
|
708
707
|
/**
|
|
709
|
-
|
|
710
|
-
|
|
708
|
+
* Returns a token used by the CKBox plugin for communication with the CKBox service.
|
|
709
|
+
*/ getToken() {
|
|
711
710
|
return this._token;
|
|
712
711
|
}
|
|
713
712
|
/**
|
|
714
|
-
|
|
715
|
-
|
|
713
|
+
* The ID of workspace to use when uploading an image.
|
|
714
|
+
*/ async getWorkspaceId() {
|
|
716
715
|
const t = this.editor.t;
|
|
717
716
|
const cannotAccessDefaultWorkspaceError = t('Cannot access default workspace.');
|
|
718
717
|
const defaultWorkspaceId = this.editor.config.get('ckbox.defaultUploadWorkspaceId');
|
|
719
718
|
const workspaceId = getWorkspaceId(await this._token, defaultWorkspaceId);
|
|
720
719
|
if (workspaceId == null) {
|
|
721
720
|
/**
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
721
|
+
* The user is not authorized to access the workspace defined in the`ckbox.defaultUploadWorkspaceId` configuration.
|
|
722
|
+
*
|
|
723
|
+
* @error ckbox-access-default-workspace-error
|
|
724
|
+
*/ logError('ckbox-access-default-workspace-error');
|
|
726
725
|
throw cannotAccessDefaultWorkspaceError;
|
|
727
726
|
}
|
|
728
727
|
return workspaceId;
|
|
729
728
|
}
|
|
730
729
|
/**
|
|
731
|
-
|
|
732
|
-
|
|
730
|
+
* Resolves a promise with an object containing a category with which the uploaded file is associated or an error code.
|
|
731
|
+
*/ async getCategoryIdForFile(fileOrUrl, options) {
|
|
733
732
|
const t = this.editor.t;
|
|
734
733
|
const cannotFindCategoryError = t('Cannot determine a category for the uploaded file.');
|
|
735
734
|
const defaultCategories = this.editor.config.get('ckbox.defaultUploadCategories');
|
|
@@ -762,10 +761,10 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
762
761
|
return category.id;
|
|
763
762
|
}
|
|
764
763
|
/**
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
764
|
+
* Resolves a promise with an array containing available categories with which the uploaded file can be associated.
|
|
765
|
+
*
|
|
766
|
+
* If the API returns limited results, the method will collect all items.
|
|
767
|
+
*/ async _getAvailableCategories(options) {
|
|
769
768
|
const ITEMS_PER_REQUEST = 50;
|
|
770
769
|
const editor = this.editor;
|
|
771
770
|
const token = this._token;
|
|
@@ -786,10 +785,10 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
786
785
|
} catch {
|
|
787
786
|
signal.throwIfAborted();
|
|
788
787
|
/**
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
788
|
+
* Fetching a list of available categories with which an uploaded file can be associated failed.
|
|
789
|
+
*
|
|
790
|
+
* @error ckbox-fetch-category-http-error
|
|
791
|
+
*/ logError('ckbox-fetch-category-http-error');
|
|
793
792
|
return undefined;
|
|
794
793
|
}
|
|
795
794
|
async function fetchCategories(offset) {
|
|
@@ -816,8 +815,8 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
816
815
|
* other ways to upload images into CKEditor 5.
|
|
817
816
|
*/ class CKBoxUploadAdapter extends Plugin {
|
|
818
817
|
/**
|
|
819
|
-
|
|
820
|
-
|
|
818
|
+
* @inheritDoc
|
|
819
|
+
*/ static get requires() {
|
|
821
820
|
return [
|
|
822
821
|
'ImageUploadEditing',
|
|
823
822
|
'ImageUploadProgress',
|
|
@@ -826,18 +825,18 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
826
825
|
];
|
|
827
826
|
}
|
|
828
827
|
/**
|
|
829
|
-
|
|
830
|
-
|
|
828
|
+
* @inheritDoc
|
|
829
|
+
*/ static get pluginName() {
|
|
831
830
|
return 'CKBoxUploadAdapter';
|
|
832
831
|
}
|
|
833
832
|
/**
|
|
834
|
-
|
|
835
|
-
|
|
833
|
+
* @inheritDoc
|
|
834
|
+
*/ static get isOfficialPlugin() {
|
|
836
835
|
return true;
|
|
837
836
|
}
|
|
838
837
|
/**
|
|
839
|
-
|
|
840
|
-
|
|
838
|
+
* @inheritDoc
|
|
839
|
+
*/ async afterInit() {
|
|
841
840
|
const editor = this.editor;
|
|
842
841
|
const hasConfiguration = !!editor.config.get('ckbox');
|
|
843
842
|
const isLibraryLoaded = !!window.CKBox;
|
|
@@ -866,26 +865,8 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
866
865
|
* Upload adapter for CKBox.
|
|
867
866
|
*/ class Adapter {
|
|
868
867
|
/**
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* CKEditor Cloud Services access token.
|
|
873
|
-
*/ token;
|
|
874
|
-
/**
|
|
875
|
-
* The editor instance.
|
|
876
|
-
*/ editor;
|
|
877
|
-
/**
|
|
878
|
-
* The abort controller for aborting asynchronous processes.
|
|
879
|
-
*/ controller;
|
|
880
|
-
/**
|
|
881
|
-
* The base URL where all requests should be sent.
|
|
882
|
-
*/ serviceOrigin;
|
|
883
|
-
/**
|
|
884
|
-
* The reference to CKBoxUtils plugin.
|
|
885
|
-
*/ ckboxUtils;
|
|
886
|
-
/**
|
|
887
|
-
* Creates a new adapter instance.
|
|
888
|
-
*/ constructor(loader, editor, ckboxUtils){
|
|
868
|
+
* Creates a new adapter instance.
|
|
869
|
+
*/ constructor(loader, editor, ckboxUtils){
|
|
889
870
|
this.loader = loader;
|
|
890
871
|
this.token = ckboxUtils.getToken();
|
|
891
872
|
this.ckboxUtils = ckboxUtils;
|
|
@@ -894,10 +875,10 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
894
875
|
this.serviceOrigin = editor.config.get('ckbox.serviceOrigin');
|
|
895
876
|
}
|
|
896
877
|
/**
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
878
|
+
* Starts the upload process.
|
|
879
|
+
*
|
|
880
|
+
* @see module:upload/filerepository~UploadAdapter#upload
|
|
881
|
+
*/ async upload() {
|
|
901
882
|
const ckboxUtils = this.ckboxUtils;
|
|
902
883
|
const t = this.editor.t;
|
|
903
884
|
const file = await this.loader.file;
|
|
@@ -935,10 +916,10 @@ const DEFAULT_CKBOX_THEME_NAME = 'lark';
|
|
|
935
916
|
});
|
|
936
917
|
}
|
|
937
918
|
/**
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
919
|
+
* Aborts the upload process.
|
|
920
|
+
*
|
|
921
|
+
* @see module:upload/filerepository~UploadAdapter#abort
|
|
922
|
+
*/ abort() {
|
|
942
923
|
this.controller.abort();
|
|
943
924
|
}
|
|
944
925
|
}
|
|
@@ -949,18 +930,18 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
949
930
|
* {@link module:ckbox/ckboxuploadadapter~CKBoxUploadAdapter CKBox upload adapter}.
|
|
950
931
|
*/ class CKBoxEditing extends Plugin {
|
|
951
932
|
/**
|
|
952
|
-
|
|
953
|
-
|
|
933
|
+
* @inheritDoc
|
|
934
|
+
*/ static get pluginName() {
|
|
954
935
|
return 'CKBoxEditing';
|
|
955
936
|
}
|
|
956
937
|
/**
|
|
957
|
-
|
|
958
|
-
|
|
938
|
+
* @inheritDoc
|
|
939
|
+
*/ static get isOfficialPlugin() {
|
|
959
940
|
return true;
|
|
960
941
|
}
|
|
961
942
|
/**
|
|
962
|
-
|
|
963
|
-
|
|
943
|
+
* @inheritDoc
|
|
944
|
+
*/ static get requires() {
|
|
964
945
|
return [
|
|
965
946
|
'LinkEditing',
|
|
966
947
|
'PictureEditing',
|
|
@@ -969,8 +950,8 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
969
950
|
];
|
|
970
951
|
}
|
|
971
952
|
/**
|
|
972
|
-
|
|
973
|
-
|
|
953
|
+
* @inheritDoc
|
|
954
|
+
*/ init() {
|
|
974
955
|
const editor = this.editor;
|
|
975
956
|
if (!this._shouldBeInitialised()) {
|
|
976
957
|
return;
|
|
@@ -988,8 +969,8 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
988
969
|
});
|
|
989
970
|
}
|
|
990
971
|
/**
|
|
991
|
-
|
|
992
|
-
|
|
972
|
+
* @inheritDoc
|
|
973
|
+
*/ afterInit() {
|
|
993
974
|
const editor = this.editor;
|
|
994
975
|
if (!this._shouldBeInitialised()) {
|
|
995
976
|
return;
|
|
@@ -1003,16 +984,16 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
1003
984
|
}
|
|
1004
985
|
}
|
|
1005
986
|
/**
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
987
|
+
* Returns true only when the integrator intentionally wants to use the plugin, i.e. when the `config.ckbox` exists or
|
|
988
|
+
* the CKBox JavaScript library is loaded.
|
|
989
|
+
*/ _shouldBeInitialised() {
|
|
1009
990
|
const editor = this.editor;
|
|
1010
991
|
const hasConfiguration = !!editor.config.get('ckbox');
|
|
1011
992
|
return hasConfiguration || isLibraryLoaded();
|
|
1012
993
|
}
|
|
1013
994
|
/**
|
|
1014
|
-
|
|
1015
|
-
|
|
995
|
+
* Blocks `uploadImage` and `ckboxImageEdit` commands.
|
|
996
|
+
*/ _blockImageCommands() {
|
|
1016
997
|
const editor = this.editor;
|
|
1017
998
|
const uploadImageCommand = editor.commands.get('uploadImage');
|
|
1018
999
|
const imageEditingCommand = editor.commands.get('ckboxImageEdit');
|
|
@@ -1025,27 +1006,27 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
1025
1006
|
}
|
|
1026
1007
|
}
|
|
1027
1008
|
/**
|
|
1028
|
-
|
|
1029
|
-
|
|
1009
|
+
* Checks if at least one image plugin is loaded.
|
|
1010
|
+
*/ _checkImagePlugins() {
|
|
1030
1011
|
const editor = this.editor;
|
|
1031
1012
|
if (!editor.plugins.has('ImageBlockEditing') && !editor.plugins.has('ImageInlineEditing')) {
|
|
1032
1013
|
/**
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1014
|
+
* The CKBox feature requires one of the following plugins to be loaded to work correctly:
|
|
1015
|
+
*
|
|
1016
|
+
* * {@link module:image/imageblock~ImageBlock},
|
|
1017
|
+
* * {@link module:image/imageinline~ImageInline},
|
|
1018
|
+
* * {@link module:image/image~Image} (loads both `ImageBlock` and `ImageInline`)
|
|
1019
|
+
*
|
|
1020
|
+
* Please make sure your editor configuration is correct.
|
|
1021
|
+
*
|
|
1022
|
+
* @error ckbox-plugin-image-feature-missing
|
|
1023
|
+
* @param {module:core/editor/editor~Editor} editor
|
|
1024
|
+
*/ logError('ckbox-plugin-image-feature-missing', editor);
|
|
1044
1025
|
}
|
|
1045
1026
|
}
|
|
1046
1027
|
/**
|
|
1047
|
-
|
|
1048
|
-
|
|
1028
|
+
* Extends the schema to allow the `ckboxImageId` and `ckboxLinkId` attributes for links and images.
|
|
1029
|
+
*/ _initSchema() {
|
|
1049
1030
|
const editor = this.editor;
|
|
1050
1031
|
const schema = editor.model.schema;
|
|
1051
1032
|
schema.extend('$text', {
|
|
@@ -1075,8 +1056,8 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
1075
1056
|
}, 'ckboxLinkId');
|
|
1076
1057
|
}
|
|
1077
1058
|
/**
|
|
1078
|
-
|
|
1079
|
-
|
|
1059
|
+
* Configures the upcast and downcast conversions for the `ckboxImageId` and `ckboxLinkId` attributes.
|
|
1060
|
+
*/ _initConversion() {
|
|
1080
1061
|
const editor = this.editor;
|
|
1081
1062
|
// Convert `ckboxLinkId` => `data-ckbox-resource-id`.
|
|
1082
1063
|
editor.conversion.for('downcast').add((dispatcher)=>{
|
|
@@ -1197,8 +1178,8 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
1197
1178
|
}
|
|
1198
1179
|
}
|
|
1199
1180
|
/**
|
|
1200
|
-
|
|
1201
|
-
|
|
1181
|
+
* Registers post-fixers that add or remove the `ckboxLinkId` and `ckboxImageId` attributes.
|
|
1182
|
+
*/ _initFixers() {
|
|
1202
1183
|
const editor = this.editor;
|
|
1203
1184
|
const model = editor.model;
|
|
1204
1185
|
const selection = model.document.selection;
|
|
@@ -1339,18 +1320,18 @@ const COMMAND_FORCE_DISABLE_ID = 'NoPermission';
|
|
|
1339
1320
|
* images into CKEditor 5.
|
|
1340
1321
|
*/ class CKBox extends Plugin {
|
|
1341
1322
|
/**
|
|
1342
|
-
|
|
1343
|
-
|
|
1323
|
+
* @inheritDoc
|
|
1324
|
+
*/ static get pluginName() {
|
|
1344
1325
|
return 'CKBox';
|
|
1345
1326
|
}
|
|
1346
1327
|
/**
|
|
1347
|
-
|
|
1348
|
-
|
|
1328
|
+
* @inheritDoc
|
|
1329
|
+
*/ static get isOfficialPlugin() {
|
|
1349
1330
|
return true;
|
|
1350
1331
|
}
|
|
1351
1332
|
/**
|
|
1352
|
-
|
|
1353
|
-
|
|
1333
|
+
* @inheritDoc
|
|
1334
|
+
*/ static get requires() {
|
|
1354
1335
|
return [
|
|
1355
1336
|
CKBoxEditing,
|
|
1356
1337
|
CKBoxUI
|
|
@@ -1400,44 +1381,38 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1400
1381
|
* Opens the CKBox dialog for editing the image.
|
|
1401
1382
|
*/ class CKBoxImageEditCommand extends Command {
|
|
1402
1383
|
/**
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* The states of image processing in progress.
|
|
1407
|
-
*/ _processInProgress = new Set();
|
|
1408
|
-
/**
|
|
1409
|
-
* Determines if the element can be edited.
|
|
1410
|
-
*/ _canEdit;
|
|
1411
|
-
/**
|
|
1412
|
-
* A wrapper function to prepare mount options. Ensures that at most one preparation is in-flight.
|
|
1413
|
-
*/ _prepareOptions;
|
|
1414
|
-
/**
|
|
1415
|
-
* CKBox's onClose function runs before the final cleanup, potentially causing
|
|
1416
|
-
* page layout changes after it finishes. To address this, we use a setTimeout hack
|
|
1417
|
-
* to ensure that floating elements on the page maintain their correct position.
|
|
1418
|
-
*
|
|
1419
|
-
* See: https://github.com/ckeditor/ckeditor5/issues/16153.
|
|
1420
|
-
*/ _updateUiDelayed = delay(()=>this.editor.ui.update(), 0);
|
|
1421
|
-
/**
|
|
1422
|
-
* @inheritDoc
|
|
1423
|
-
*/ constructor(editor){
|
|
1384
|
+
* @inheritDoc
|
|
1385
|
+
*/ constructor(editor){
|
|
1424
1386
|
super(editor);
|
|
1387
|
+
/**
|
|
1388
|
+
* The DOM element that acts as a mounting point for the CKBox Edit Image dialog.
|
|
1389
|
+
*/ this._wrapper = null;
|
|
1390
|
+
/**
|
|
1391
|
+
* The states of image processing in progress.
|
|
1392
|
+
*/ this._processInProgress = new Set();
|
|
1393
|
+
/**
|
|
1394
|
+
* CKBox's onClose function runs before the final cleanup, potentially causing
|
|
1395
|
+
* page layout changes after it finishes. To address this, we use a setTimeout hack
|
|
1396
|
+
* to ensure that floating elements on the page maintain their correct position.
|
|
1397
|
+
*
|
|
1398
|
+
* See: https://github.com/ckeditor/ckeditor5/issues/16153.
|
|
1399
|
+
*/ this._updateUiDelayed = delay(()=>this.editor.ui.update(), 0);
|
|
1425
1400
|
this.value = false;
|
|
1426
1401
|
this._canEdit = createEditabilityChecker(editor.config.get('ckbox.allowExternalImagesEditing'));
|
|
1427
1402
|
this._prepareOptions = abortableDebounce((signal, state)=>this._prepareOptionsAbortable(signal, state));
|
|
1428
1403
|
this._prepareListeners();
|
|
1429
1404
|
}
|
|
1430
1405
|
/**
|
|
1431
|
-
|
|
1432
|
-
|
|
1406
|
+
* @inheritDoc
|
|
1407
|
+
*/ refresh() {
|
|
1433
1408
|
const editor = this.editor;
|
|
1434
1409
|
this.value = this._getValue();
|
|
1435
1410
|
const selectedElement = editor.model.document.selection.getSelectedElement();
|
|
1436
1411
|
this.isEnabled = !!selectedElement && this._canEdit(selectedElement) && !this._checkIfElementIsBeingProcessed(selectedElement);
|
|
1437
1412
|
}
|
|
1438
1413
|
/**
|
|
1439
|
-
|
|
1440
|
-
|
|
1414
|
+
* Opens the CKBox Image Editor dialog for editing the image.
|
|
1415
|
+
*/ execute() {
|
|
1441
1416
|
if (this._getValue()) {
|
|
1442
1417
|
return;
|
|
1443
1418
|
}
|
|
@@ -1464,8 +1439,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1464
1439
|
});
|
|
1465
1440
|
}
|
|
1466
1441
|
/**
|
|
1467
|
-
|
|
1468
|
-
|
|
1442
|
+
* @inheritDoc
|
|
1443
|
+
*/ destroy() {
|
|
1469
1444
|
this._handleImageEditorClose();
|
|
1470
1445
|
this._prepareOptions.abort();
|
|
1471
1446
|
this._updateUiDelayed.cancel();
|
|
@@ -1475,13 +1450,13 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1475
1450
|
super.destroy();
|
|
1476
1451
|
}
|
|
1477
1452
|
/**
|
|
1478
|
-
|
|
1479
|
-
|
|
1453
|
+
* Indicates if the CKBox Image Editor dialog is already opened.
|
|
1454
|
+
*/ _getValue() {
|
|
1480
1455
|
return this._wrapper !== null;
|
|
1481
1456
|
}
|
|
1482
1457
|
/**
|
|
1483
|
-
|
|
1484
|
-
|
|
1458
|
+
* Creates the options object for the CKBox Image Editor dialog.
|
|
1459
|
+
*/ async _prepareOptionsAbortable(signal, state) {
|
|
1485
1460
|
const editor = this.editor;
|
|
1486
1461
|
const ckboxConfig = editor.config.get('ckbox');
|
|
1487
1462
|
const ckboxUtils = editor.plugins.get(CKBoxUtils);
|
|
@@ -1516,8 +1491,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1516
1491
|
};
|
|
1517
1492
|
}
|
|
1518
1493
|
/**
|
|
1519
|
-
|
|
1520
|
-
|
|
1494
|
+
* Initializes event lister for an event of removing an image.
|
|
1495
|
+
*/ _prepareListeners() {
|
|
1521
1496
|
// Abort editing processing when the image has been removed.
|
|
1522
1497
|
this.listenTo(this.editor.model.document, 'change:data', ()=>{
|
|
1523
1498
|
const processingStates = this._getProcessingStatesOfDeletedImages();
|
|
@@ -1527,8 +1502,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1527
1502
|
});
|
|
1528
1503
|
}
|
|
1529
1504
|
/**
|
|
1530
|
-
|
|
1531
|
-
|
|
1505
|
+
* Gets processing states of images that have been deleted in the mean time.
|
|
1506
|
+
*/ _getProcessingStatesOfDeletedImages() {
|
|
1532
1507
|
const states = [];
|
|
1533
1508
|
for (const state of this._processInProgress.values()){
|
|
1534
1509
|
if (state.element.root.rootName == '$graveyard') {
|
|
@@ -1546,8 +1521,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1546
1521
|
return false;
|
|
1547
1522
|
}
|
|
1548
1523
|
/**
|
|
1549
|
-
|
|
1550
|
-
|
|
1524
|
+
* Closes the CKBox Image Editor dialog.
|
|
1525
|
+
*/ _handleImageEditorClose() {
|
|
1551
1526
|
if (!this._wrapper) {
|
|
1552
1527
|
return;
|
|
1553
1528
|
}
|
|
@@ -1558,9 +1533,9 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1558
1533
|
this.refresh();
|
|
1559
1534
|
}
|
|
1560
1535
|
/**
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1536
|
+
* Save edited image. In case server respond with "success" replace with edited image,
|
|
1537
|
+
* otherwise show notification error.
|
|
1538
|
+
*/ _handleImageEditorSave(state, asset) {
|
|
1564
1539
|
const t = this.editor.locale.t;
|
|
1565
1540
|
const notification = this.editor.plugins.get(Notification);
|
|
1566
1541
|
const pendingActions = this.editor.plugins.get(PendingActions);
|
|
@@ -1590,9 +1565,9 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1590
1565
|
});
|
|
1591
1566
|
}
|
|
1592
1567
|
/**
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1568
|
+
* Get asset's status on server. If server responds with "success" status then
|
|
1569
|
+
* image is already proceeded and ready for saving.
|
|
1570
|
+
*/ async _getAssetStatusFromServer(id, signal) {
|
|
1596
1571
|
const ckboxUtils = this.editor.plugins.get(CKBoxUtils);
|
|
1597
1572
|
const url = new URL('assets/' + id, this.editor.config.get('ckbox.serviceOrigin'));
|
|
1598
1573
|
const response = await sendHttpRequest({
|
|
@@ -1603,10 +1578,10 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1603
1578
|
const status = response.metadata.metadataProcessingStatus;
|
|
1604
1579
|
if (!status || status == 'queued') {
|
|
1605
1580
|
/**
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1581
|
+
* Image has not been processed yet.
|
|
1582
|
+
*
|
|
1583
|
+
* @error ckbox-image-not-processed
|
|
1584
|
+
*/ throw new CKEditorError('ckbox-image-not-processed');
|
|
1610
1585
|
}
|
|
1611
1586
|
return {
|
|
1612
1587
|
data: {
|
|
@@ -1615,27 +1590,27 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1615
1590
|
};
|
|
1616
1591
|
}
|
|
1617
1592
|
/**
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1593
|
+
* Waits for an asset to be processed.
|
|
1594
|
+
* It retries retrieving asset status from the server in case of failure.
|
|
1595
|
+
*/ async _waitForAssetProcessed(id, signal) {
|
|
1621
1596
|
const result = await retry(()=>this._getAssetStatusFromServer(id, signal), {
|
|
1622
1597
|
signal,
|
|
1623
1598
|
maxAttempts: 5
|
|
1624
1599
|
});
|
|
1625
1600
|
if (result.data.metadata.metadataProcessingStatus != 'success') {
|
|
1626
1601
|
/**
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1602
|
+
* The image processing failed.
|
|
1603
|
+
*
|
|
1604
|
+
* @error ckbox-image-processing-failed
|
|
1605
|
+
*/ throw new CKEditorError('ckbox-image-processing-failed');
|
|
1631
1606
|
}
|
|
1632
1607
|
return result;
|
|
1633
1608
|
}
|
|
1634
1609
|
/**
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1610
|
+
* Shows processing indicator while image is processing.
|
|
1611
|
+
*
|
|
1612
|
+
* @param asset Data about certain asset.
|
|
1613
|
+
*/ _showImageProcessingIndicator(element, asset) {
|
|
1639
1614
|
const editor = this.editor;
|
|
1640
1615
|
editor.editing.view.change((writer)=>{
|
|
1641
1616
|
const imageElementView = editor.editing.mapper.toViewElement(element);
|
|
@@ -1650,8 +1625,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1650
1625
|
});
|
|
1651
1626
|
}
|
|
1652
1627
|
/**
|
|
1653
|
-
|
|
1654
|
-
|
|
1628
|
+
* Replace the edited image with the new one.
|
|
1629
|
+
*/ _replaceImage(element, asset) {
|
|
1655
1630
|
const editor = this.editor;
|
|
1656
1631
|
const { imageFallbackUrl, imageSources, imageWidth, imageHeight, imagePlaceholder } = prepareImageAssetAttributes(asset);
|
|
1657
1632
|
const previousSelectionRanges = Array.from(editor.model.document.selection.getRanges());
|
|
@@ -1687,18 +1662,18 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1687
1662
|
* The CKBox image edit editing plugin.
|
|
1688
1663
|
*/ class CKBoxImageEditEditing extends Plugin {
|
|
1689
1664
|
/**
|
|
1690
|
-
|
|
1691
|
-
|
|
1665
|
+
* @inheritDoc
|
|
1666
|
+
*/ static get pluginName() {
|
|
1692
1667
|
return 'CKBoxImageEditEditing';
|
|
1693
1668
|
}
|
|
1694
1669
|
/**
|
|
1695
|
-
|
|
1696
|
-
|
|
1670
|
+
* @inheritDoc
|
|
1671
|
+
*/ static get isOfficialPlugin() {
|
|
1697
1672
|
return true;
|
|
1698
1673
|
}
|
|
1699
1674
|
/**
|
|
1700
|
-
|
|
1701
|
-
|
|
1675
|
+
* @inheritDoc
|
|
1676
|
+
*/ static get requires() {
|
|
1702
1677
|
return [
|
|
1703
1678
|
CKBoxEditing,
|
|
1704
1679
|
CKBoxUtils,
|
|
@@ -1709,8 +1684,8 @@ function createUrlChecker(allowExternalImagesEditing) {
|
|
|
1709
1684
|
];
|
|
1710
1685
|
}
|
|
1711
1686
|
/**
|
|
1712
|
-
|
|
1713
|
-
|
|
1687
|
+
* @inheritDoc
|
|
1688
|
+
*/ init() {
|
|
1714
1689
|
const { editor } = this;
|
|
1715
1690
|
editor.commands.add('ckboxImageEdit', new CKBoxImageEditCommand(editor));
|
|
1716
1691
|
}
|
|
@@ -1725,18 +1700,18 @@ var ckboxImageEditIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2
|
|
|
1725
1700
|
* that allows you to open the CKBox dialog and edit the image.
|
|
1726
1701
|
*/ class CKBoxImageEditUI extends Plugin {
|
|
1727
1702
|
/**
|
|
1728
|
-
|
|
1729
|
-
|
|
1703
|
+
* @inheritDoc
|
|
1704
|
+
*/ static get pluginName() {
|
|
1730
1705
|
return 'CKBoxImageEditUI';
|
|
1731
1706
|
}
|
|
1732
1707
|
/**
|
|
1733
|
-
|
|
1734
|
-
|
|
1708
|
+
* @inheritDoc
|
|
1709
|
+
*/ static get isOfficialPlugin() {
|
|
1735
1710
|
return true;
|
|
1736
1711
|
}
|
|
1737
1712
|
/**
|
|
1738
|
-
|
|
1739
|
-
|
|
1713
|
+
* @inheritDoc
|
|
1714
|
+
*/ init() {
|
|
1740
1715
|
const editor = this.editor;
|
|
1741
1716
|
editor.ui.componentFactory.add('ckboxImageEdit', (locale)=>{
|
|
1742
1717
|
const command = editor.commands.get('ckboxImageEdit');
|
|
@@ -1764,18 +1739,18 @@ var ckboxImageEditIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2
|
|
|
1764
1739
|
* The CKBox image edit feature.
|
|
1765
1740
|
*/ class CKBoxImageEdit extends Plugin {
|
|
1766
1741
|
/**
|
|
1767
|
-
|
|
1768
|
-
|
|
1742
|
+
* @inheritDoc
|
|
1743
|
+
*/ static get pluginName() {
|
|
1769
1744
|
return 'CKBoxImageEdit';
|
|
1770
1745
|
}
|
|
1771
1746
|
/**
|
|
1772
|
-
|
|
1773
|
-
|
|
1747
|
+
* @inheritDoc
|
|
1748
|
+
*/ static get isOfficialPlugin() {
|
|
1774
1749
|
return true;
|
|
1775
1750
|
}
|
|
1776
1751
|
/**
|
|
1777
|
-
|
|
1778
|
-
|
|
1752
|
+
* @inheritDoc
|
|
1753
|
+
*/ static get requires() {
|
|
1779
1754
|
return [
|
|
1780
1755
|
CKBoxImageEditEditing,
|
|
1781
1756
|
CKBoxImageEditUI
|