@ckeditor/ckeditor5-ckbox 41.4.2 → 42.0.0-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,6 +36,14 @@ export default class CKBoxImageEditCommand extends Command {
36
36
  * A wrapper function to prepare mount options. Ensures that at most one preparation is in-flight.
37
37
  */
38
38
  private _prepareOptions;
39
+ /**
40
+ * CKBox's onClose function runs before the final cleanup, potentially causing
41
+ * page layout changes after it finishes. To address this, we use a setTimeout hack
42
+ * to ensure that floating elements on the page maintain their correct position.
43
+ *
44
+ * See: https://github.com/ckeditor/ckeditor5/issues/16153.
45
+ */
46
+ private _updateUiDelayed;
39
47
  /**
40
48
  * @inheritDoc
41
49
  */
@@ -11,7 +11,14 @@
11
11
  */
12
12
  import { Plugin } from 'ckeditor5/src/core.js';
13
13
  /**
14
- * The CKBoxUI plugin. It introduces the `'ckbox'` toolbar button.
14
+ * Introduces UI components for the `CKBox` plugin.
15
+ *
16
+ * The plugin introduces two UI components to the {@link module:ui/componentfactory~ComponentFactory UI component factory}:
17
+ *
18
+ * * the `'ckbox'` toolbar button,
19
+ * * the `'menuBar:ckbox'` menu bar component, which is by default added to the `'Insert'` menu.
20
+ *
21
+ * It also integrates with the `insertImage` toolbar component and `menuBar:insertImage` menu component.
15
22
  */
16
23
  export default class CKBoxUI extends Plugin {
17
24
  /**
@@ -23,7 +30,27 @@ export default class CKBoxUI extends Plugin {
23
30
  */
24
31
  afterInit(): void;
25
32
  /**
26
- * Creates a button for CKBox command to use either in toolbar or in menu bar.
33
+ * Creates the base for various kinds of the button component provided by this feature.
27
34
  */
28
35
  private _createButton;
36
+ /**
37
+ * Creates a simple toolbar button for files management, with an icon and a tooltip.
38
+ */
39
+ private _createFileToolbarButton;
40
+ /**
41
+ * Creates a simple toolbar button for images management, with an icon and a tooltip.
42
+ */
43
+ private _createImageToolbarButton;
44
+ /**
45
+ * Creates a button for images management for the dropdown view, with an icon, text and no tooltip.
46
+ */
47
+ private _createImageDropdownButton;
48
+ /**
49
+ * Creates a button for files management for the menu bar.
50
+ */
51
+ private _createFileMenuBarButton;
52
+ /**
53
+ * Creates a button for images management for the menu bar.
54
+ */
55
+ private _createImageMenuBarButton;
29
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-ckbox",
3
- "version": "41.4.2",
3
+ "version": "42.0.0-alpha.0",
4
4
  "description": "CKBox integration for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,7 +13,7 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "ckeditor5": "41.4.2",
16
+ "ckeditor5": "42.0.0-alpha.0",
17
17
  "blurhash": "2.0.5",
18
18
  "lodash-es": "4.17.21"
19
19
  },
@@ -32,6 +32,14 @@ export default class CKBoxImageEditCommand extends Command {
32
32
  * A wrapper function to prepare mount options. Ensures that at most one preparation is in-flight.
33
33
  */
34
34
  private _prepareOptions;
35
+ /**
36
+ * CKBox's onClose function runs before the final cleanup, potentially causing
37
+ * page layout changes after it finishes. To address this, we use a setTimeout hack
38
+ * to ensure that floating elements on the page maintain their correct position.
39
+ *
40
+ * See: https://github.com/ckeditor/ckeditor5/issues/16153.
41
+ */
42
+ private _updateUiDelayed;
35
43
  /**
36
44
  * @inheritDoc
37
45
  */
@@ -7,7 +7,7 @@
7
7
  * @module ckbox/ckboximageedit/ckboximageeditcommand
8
8
  */
9
9
  import { Command, PendingActions } from 'ckeditor5/src/core.js';
10
- import { CKEditorError, abortableDebounce, createElement, retry } from 'ckeditor5/src/utils.js';
10
+ import { CKEditorError, abortableDebounce, createElement, retry, delay } from 'ckeditor5/src/utils.js';
11
11
  import { Notification } from 'ckeditor5/src/ui.js';
12
12
  import { isEqual } from 'lodash-es';
13
13
  import { sendHttpRequest } from '../utils.js';
@@ -33,6 +33,14 @@ export default class CKBoxImageEditCommand extends Command {
33
33
  * The states of image processing in progress.
34
34
  */
35
35
  this._processInProgress = new Set();
36
+ /**
37
+ * CKBox's onClose function runs before the final cleanup, potentially causing
38
+ * page layout changes after it finishes. To address this, we use a setTimeout hack
39
+ * to ensure that floating elements on the page maintain their correct position.
40
+ *
41
+ * See: https://github.com/ckeditor/ckeditor5/issues/16153.
42
+ */
43
+ this._updateUiDelayed = delay(() => this.editor.ui.update(), 0);
36
44
  this.value = false;
37
45
  this._canEdit = createEditabilityChecker(editor.config.get('ckbox.allowExternalImagesEditing'));
38
46
  this._prepareOptions = abortableDebounce((signal, state) => this._prepareOptionsAbortable(signal, state));
@@ -83,6 +91,7 @@ export default class CKBoxImageEditCommand extends Command {
83
91
  destroy() {
84
92
  this._handleImageEditorClose();
85
93
  this._prepareOptions.abort();
94
+ this._updateUiDelayed.cancel();
86
95
  for (const state of this._processInProgress.values()) {
87
96
  state.controller.abort();
88
97
  }
@@ -170,6 +179,7 @@ export default class CKBoxImageEditCommand extends Command {
170
179
  this._wrapper.remove();
171
180
  this._wrapper = null;
172
181
  this.editor.editing.view.focus();
182
+ this._updateUiDelayed();
173
183
  this.refresh();
174
184
  }
175
185
  /**
package/src/ckboxui.d.ts CHANGED
@@ -7,7 +7,14 @@
7
7
  */
8
8
  import { Plugin } from 'ckeditor5/src/core.js';
9
9
  /**
10
- * The CKBoxUI plugin. It introduces the `'ckbox'` toolbar button.
10
+ * Introduces UI components for the `CKBox` plugin.
11
+ *
12
+ * The plugin introduces two UI components to the {@link module:ui/componentfactory~ComponentFactory UI component factory}:
13
+ *
14
+ * * the `'ckbox'` toolbar button,
15
+ * * the `'menuBar:ckbox'` menu bar component, which is by default added to the `'Insert'` menu.
16
+ *
17
+ * It also integrates with the `insertImage` toolbar component and `menuBar:insertImage` menu component.
11
18
  */
12
19
  export default class CKBoxUI extends Plugin {
13
20
  /**
@@ -19,7 +26,27 @@ export default class CKBoxUI extends Plugin {
19
26
  */
20
27
  afterInit(): void;
21
28
  /**
22
- * Creates a button for CKBox command to use either in toolbar or in menu bar.
29
+ * Creates the base for various kinds of the button component provided by this feature.
23
30
  */
24
31
  private _createButton;
32
+ /**
33
+ * Creates a simple toolbar button for files management, with an icon and a tooltip.
34
+ */
35
+ private _createFileToolbarButton;
36
+ /**
37
+ * Creates a simple toolbar button for images management, with an icon and a tooltip.
38
+ */
39
+ private _createImageToolbarButton;
40
+ /**
41
+ * Creates a button for images management for the dropdown view, with an icon, text and no tooltip.
42
+ */
43
+ private _createImageDropdownButton;
44
+ /**
45
+ * Creates a button for files management for the menu bar.
46
+ */
47
+ private _createFileMenuBarButton;
48
+ /**
49
+ * Creates a button for images management for the menu bar.
50
+ */
51
+ private _createImageMenuBarButton;
25
52
  }
package/src/ckboxui.js CHANGED
@@ -8,7 +8,14 @@
8
8
  import { icons, Plugin } from 'ckeditor5/src/core.js';
9
9
  import { ButtonView, MenuBarMenuListItemButtonView } from 'ckeditor5/src/ui.js';
10
10
  /**
11
- * The CKBoxUI plugin. It introduces the `'ckbox'` toolbar button.
11
+ * Introduces UI components for the `CKBox` plugin.
12
+ *
13
+ * The plugin introduces two UI components to the {@link module:ui/componentfactory~ComponentFactory UI component factory}:
14
+ *
15
+ * * the `'ckbox'` toolbar button,
16
+ * * the `'menuBar:ckbox'` menu bar component, which is by default added to the `'Insert'` menu.
17
+ *
18
+ * It also integrates with the `insertImage` toolbar component and `menuBar:insertImage` menu component.
12
19
  */
13
20
  export default class CKBoxUI extends Plugin {
14
21
  /**
@@ -27,44 +34,20 @@ export default class CKBoxUI extends Plugin {
27
34
  if (!editor.commands.get('ckbox')) {
28
35
  return;
29
36
  }
30
- const t = editor.t;
31
- const componentFactory = editor.ui.componentFactory;
32
- componentFactory.add('ckbox', () => {
33
- const button = this._createButton(ButtonView);
34
- button.tooltip = true;
35
- return button;
36
- });
37
- componentFactory.add('menuBar:ckbox', () => this._createButton(MenuBarMenuListItemButtonView));
37
+ editor.ui.componentFactory.add('ckbox', () => this._createFileToolbarButton());
38
+ editor.ui.componentFactory.add('menuBar:ckbox', () => this._createFileMenuBarButton());
38
39
  if (editor.plugins.has('ImageInsertUI')) {
39
- const imageInsertUI = editor.plugins.get('ImageInsertUI');
40
- imageInsertUI.registerIntegration({
40
+ editor.plugins.get('ImageInsertUI').registerIntegration({
41
41
  name: 'assetManager',
42
42
  observable: () => editor.commands.get('ckbox'),
43
- buttonViewCreator: () => {
44
- const button = this.editor.ui.componentFactory.create('ckbox');
45
- button.icon = icons.imageAssetManager;
46
- button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ?
47
- t('Replace image with file manager') :
48
- t('Insert image with file manager'));
49
- return button;
50
- },
51
- formViewCreator: () => {
52
- const button = this.editor.ui.componentFactory.create('ckbox');
53
- button.icon = icons.imageAssetManager;
54
- button.withText = true;
55
- button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ?
56
- t('Replace with file manager') :
57
- t('Insert with file manager'));
58
- button.on('execute', () => {
59
- imageInsertUI.dropdownView.isOpen = false;
60
- });
61
- return button;
62
- }
43
+ buttonViewCreator: () => this._createImageToolbarButton(),
44
+ formViewCreator: () => this._createImageDropdownButton(),
45
+ menuBarButtonViewCreator: isOnly => this._createImageMenuBarButton(isOnly ? 'insertOnly' : 'insertNested')
63
46
  });
64
47
  }
65
48
  }
66
49
  /**
67
- * Creates a button for CKBox command to use either in toolbar or in menu bar.
50
+ * Creates the base for various kinds of the button component provided by this feature.
68
51
  */
69
52
  _createButton(ButtonClass) {
70
53
  const editor = this.editor;
@@ -72,14 +55,77 @@ export default class CKBoxUI extends Plugin {
72
55
  const view = new ButtonClass(locale);
73
56
  const command = editor.commands.get('ckbox');
74
57
  const t = locale.t;
75
- view.set({
76
- label: t('Open file manager'),
77
- icon: icons.browseFiles
78
- });
79
58
  view.bind('isOn', 'isEnabled').to(command, 'value', 'isEnabled');
80
59
  view.on('execute', () => {
81
60
  editor.execute('ckbox');
82
61
  });
83
62
  return view;
84
63
  }
64
+ /**
65
+ * Creates a simple toolbar button for files management, with an icon and a tooltip.
66
+ */
67
+ _createFileToolbarButton() {
68
+ const t = this.editor.locale.t;
69
+ const button = this._createButton(ButtonView);
70
+ button.icon = icons.browseFiles;
71
+ button.label = t('Open file manager');
72
+ button.tooltip = true;
73
+ return button;
74
+ }
75
+ /**
76
+ * Creates a simple toolbar button for images management, with an icon and a tooltip.
77
+ */
78
+ _createImageToolbarButton() {
79
+ const t = this.editor.locale.t;
80
+ const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
81
+ const button = this._createButton(ButtonView);
82
+ button.icon = icons.imageAssetManager;
83
+ button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ? t('Replace image with file manager') : t('Insert image with file manager'));
84
+ button.tooltip = true;
85
+ return button;
86
+ }
87
+ /**
88
+ * Creates a button for images management for the dropdown view, with an icon, text and no tooltip.
89
+ */
90
+ _createImageDropdownButton() {
91
+ const t = this.editor.locale.t;
92
+ const imageInsertUI = this.editor.plugins.get('ImageInsertUI');
93
+ const button = this._createButton(ButtonView);
94
+ button.icon = icons.imageAssetManager;
95
+ button.withText = true;
96
+ button.bind('label').to(imageInsertUI, 'isImageSelected', isImageSelected => isImageSelected ? t('Replace with file manager') : t('Insert with file manager'));
97
+ button.on('execute', () => {
98
+ imageInsertUI.dropdownView.isOpen = false;
99
+ });
100
+ return button;
101
+ }
102
+ /**
103
+ * Creates a button for files management for the menu bar.
104
+ */
105
+ _createFileMenuBarButton() {
106
+ const t = this.editor.locale.t;
107
+ const button = this._createButton(MenuBarMenuListItemButtonView);
108
+ button.icon = icons.browseFiles;
109
+ button.withText = true;
110
+ button.label = t('File');
111
+ return button;
112
+ }
113
+ /**
114
+ * Creates a button for images management for the menu bar.
115
+ */
116
+ _createImageMenuBarButton(type) {
117
+ const t = this.editor.locale.t;
118
+ const button = this._createButton(MenuBarMenuListItemButtonView);
119
+ button.icon = icons.imageAssetManager;
120
+ button.withText = true;
121
+ switch (type) {
122
+ case 'insertOnly':
123
+ button.label = t('Image');
124
+ break;
125
+ case 'insertNested':
126
+ button.label = t('With file manager');
127
+ break;
128
+ }
129
+ return button;
130
+ }
85
131
  }