@ckeditor/ckeditor5-widget 0.0.0-nightly-20241215.0 → 0.0.0-nightly-20241217.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.

Potentially problematic release.


This version of @ckeditor/ckeditor5-widget might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -21,12 +21,15 @@ import { throttle } from 'lodash-es';
21
21
  *
22
22
  * This way, highlight will be applied with the same rules it is applied on texts.
23
23
  */ class HighlightStack extends /* #__PURE__ */ EmitterMixin() {
24
- _stack = [];
24
+ constructor(){
25
+ super(...arguments);
26
+ this._stack = [];
27
+ }
25
28
  /**
26
- * Adds highlight descriptor to the stack.
27
- *
28
- * @fires change:top
29
- */ add(descriptor, writer) {
29
+ * Adds highlight descriptor to the stack.
30
+ *
31
+ * @fires change:top
32
+ */ add(descriptor, writer) {
30
33
  const stack = this._stack;
31
34
  // Save top descriptor and insert new one. If top is changed - fire event.
32
35
  const oldTop = stack[0];
@@ -42,11 +45,11 @@ import { throttle } from 'lodash-es';
42
45
  }
43
46
  }
44
47
  /**
45
- * Removes highlight descriptor from the stack.
46
- *
47
- * @fires change:top
48
- * @param id Id of the descriptor to remove.
49
- */ remove(id, writer) {
48
+ * Removes highlight descriptor from the stack.
49
+ *
50
+ * @fires change:top
51
+ * @param id Id of the descriptor to remove.
52
+ */ remove(id, writer) {
50
53
  const stack = this._stack;
51
54
  const oldTop = stack[0];
52
55
  this._removeDescriptor(id);
@@ -61,9 +64,9 @@ import { throttle } from 'lodash-es';
61
64
  }
62
65
  }
63
66
  /**
64
- * Inserts a given descriptor in correct place in the stack. It also takes care about updating information
65
- * when descriptor with same id is already present.
66
- */ _insertDescriptor(descriptor) {
67
+ * Inserts a given descriptor in correct place in the stack. It also takes care about updating information
68
+ * when descriptor with same id is already present.
69
+ */ _insertDescriptor(descriptor) {
67
70
  const stack = this._stack;
68
71
  const index = stack.findIndex((item)=>item.id === descriptor.id);
69
72
  // Inserting exact same descriptor - do nothing.
@@ -83,10 +86,10 @@ import { throttle } from 'lodash-es';
83
86
  stack.splice(i, 0, descriptor);
84
87
  }
85
88
  /**
86
- * Removes descriptor with given id from the stack.
87
- *
88
- * @param id Descriptor's id.
89
- */ _removeDescriptor(id) {
89
+ * Removes descriptor with given id from the stack.
90
+ *
91
+ * @param id Descriptor's id.
92
+ */ _removeDescriptor(id) {
90
93
  const stack = this._stack;
91
94
  const index = stack.findIndex((item)=>item.id === id);
92
95
  // If descriptor with same id is on the list - remove it.
@@ -184,12 +187,12 @@ var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/
184
187
  */ function toWidget(element, writer, options = {}) {
185
188
  if (!element.is('containerElement')) {
186
189
  /**
187
- * The element passed to `toWidget()` must be a {@link module:engine/view/containerelement~ContainerElement}
188
- * instance.
189
- *
190
- * @error widget-to-widget-wrong-element-type
191
- * @param element The view element passed to `toWidget()`.
192
- */ throw new CKEditorError('widget-to-widget-wrong-element-type', null, {
190
+ * The element passed to `toWidget()` must be a {@link module:engine/view/containerelement~ContainerElement}
191
+ * instance.
192
+ *
193
+ * @error widget-to-widget-wrong-element-type
194
+ * @param element The view element passed to `toWidget()`.
195
+ */ throw new CKEditorError('widget-to-widget-wrong-element-type', null, {
193
196
  element
194
197
  });
195
198
  }
@@ -555,32 +558,35 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
555
558
  * user if the widget is next to the "tight spot". Once clicked, a paragraph is created with the selection anchored
556
559
  * in it so that users can type (or insert content, paste, etc.) straight away.
557
560
  */ class WidgetTypeAround extends Plugin {
561
+ constructor(){
562
+ super(...arguments);
563
+ /**
564
+ * A reference to the model widget element that has the fake caret active
565
+ * on either side of it. It is later used to remove CSS classes associated with the fake caret
566
+ * when the widget no longer needs it.
567
+ */ this._currentFakeCaretModelElement = null;
568
+ }
558
569
  /**
559
- * A reference to the model widget element that has the fake caret active
560
- * on either side of it. It is later used to remove CSS classes associated with the fake caret
561
- * when the widget no longer needs it.
562
- */ _currentFakeCaretModelElement = null;
563
- /**
564
- * @inheritDoc
565
- */ static get pluginName() {
570
+ * @inheritDoc
571
+ */ static get pluginName() {
566
572
  return 'WidgetTypeAround';
567
573
  }
568
574
  /**
569
- * @inheritDoc
570
- */ static get isOfficialPlugin() {
575
+ * @inheritDoc
576
+ */ static get isOfficialPlugin() {
571
577
  return true;
572
578
  }
573
579
  /**
574
- * @inheritDoc
575
- */ static get requires() {
580
+ * @inheritDoc
581
+ */ static get requires() {
576
582
  return [
577
583
  Enter,
578
584
  Delete
579
585
  ];
580
586
  }
581
587
  /**
582
- * @inheritDoc
583
- */ init() {
588
+ * @inheritDoc
589
+ */ init() {
584
590
  const editor = this.editor;
585
591
  const editingView = editor.editing.view;
586
592
  // Set a CSS class on the view editing root when the plugin is disabled so all the buttons
@@ -612,20 +618,20 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
612
618
  this._enableDeleteContentIntegration();
613
619
  }
614
620
  /**
615
- * @inheritDoc
616
- */ destroy() {
621
+ * @inheritDoc
622
+ */ destroy() {
617
623
  super.destroy();
618
624
  this._currentFakeCaretModelElement = null;
619
625
  }
620
626
  /**
621
- * Inserts a new paragraph next to a widget element with the selection anchored in it.
622
- *
623
- * **Note**: This method is heavily user-oriented and will both focus the editing view and scroll
624
- * the viewport to the selection in the inserted paragraph.
625
- *
626
- * @param widgetModelElement The model widget element next to which a paragraph is inserted.
627
- * @param position The position where the paragraph is inserted. Either `'before'` or `'after'` the widget.
628
- */ _insertParagraph(widgetModelElement, position) {
627
+ * Inserts a new paragraph next to a widget element with the selection anchored in it.
628
+ *
629
+ * **Note**: This method is heavily user-oriented and will both focus the editing view and scroll
630
+ * the viewport to the selection in the inserted paragraph.
631
+ *
632
+ * @param widgetModelElement The model widget element next to which a paragraph is inserted.
633
+ * @param position The position where the paragraph is inserted. Either `'before'` or `'after'` the widget.
634
+ */ _insertParagraph(widgetModelElement, position) {
629
635
  const editor = this.editor;
630
636
  const editingView = editor.editing.view;
631
637
  const attributesToCopy = editor.model.schema.getAttributesWithProperty(widgetModelElement, 'copyOnReplace', true);
@@ -637,16 +643,16 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
637
643
  editingView.scrollToTheSelection();
638
644
  }
639
645
  /**
640
- * A wrapper for the {@link module:utils/emittermixin~Emitter#listenTo} method that executes the callbacks only
641
- * when the plugin {@link #isEnabled is enabled}.
642
- *
643
- * @param emitter The object that fires the event.
644
- * @param event The name of the event.
645
- * @param callback The function to be called on event.
646
- * @param options Additional options.
647
- * @param options.priority The priority of this event callback. The higher the priority value the sooner
648
- * the callback will be fired. Events having the same priority are called in the order they were added.
649
- */ _listenToIfEnabled(emitter, event, callback, options) {
646
+ * A wrapper for the {@link module:utils/emittermixin~Emitter#listenTo} method that executes the callbacks only
647
+ * when the plugin {@link #isEnabled is enabled}.
648
+ *
649
+ * @param emitter The object that fires the event.
650
+ * @param event The name of the event.
651
+ * @param callback The function to be called on event.
652
+ * @param options Additional options.
653
+ * @param options.priority The priority of this event callback. The higher the priority value the sooner
654
+ * the callback will be fired. Events having the same priority are called in the order they were added.
655
+ */ _listenToIfEnabled(emitter, event, callback, options) {
650
656
  this.listenTo(emitter, event, (...args)=>{
651
657
  // Do not respond if the plugin is disabled.
652
658
  if (this.isEnabled) {
@@ -655,16 +661,16 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
655
661
  }, options);
656
662
  }
657
663
  /**
658
- * Similar to {@link #_insertParagraph}, this method inserts a paragraph except that it
659
- * does not expect a position. Instead, it performs the insertion next to a selected widget
660
- * according to the `widget-type-around` model selection attribute value (fake caret position).
661
- *
662
- * Because this method requires the `widget-type-around` attribute to be set,
663
- * the insertion can only happen when the widget's fake caret is active (e.g. activated
664
- * using the keyboard).
665
- *
666
- * @returns Returns `true` when the paragraph was inserted (the attribute was present) and `false` otherwise.
667
- */ _insertParagraphAccordingToFakeCaretPosition() {
664
+ * Similar to {@link #_insertParagraph}, this method inserts a paragraph except that it
665
+ * does not expect a position. Instead, it performs the insertion next to a selected widget
666
+ * according to the `widget-type-around` model selection attribute value (fake caret position).
667
+ *
668
+ * Because this method requires the `widget-type-around` attribute to be set,
669
+ * the insertion can only happen when the widget's fake caret is active (e.g. activated
670
+ * using the keyboard).
671
+ *
672
+ * @returns Returns `true` when the paragraph was inserted (the attribute was present) and `false` otherwise.
673
+ */ _insertParagraphAccordingToFakeCaretPosition() {
668
674
  const editor = this.editor;
669
675
  const model = editor.model;
670
676
  const modelSelection = model.document.selection;
@@ -682,12 +688,12 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
682
688
  return true;
683
689
  }
684
690
  /**
685
- * Creates a listener in the editing conversion pipeline that injects the widget type around
686
- * UI into every single widget instance created in the editor.
687
- *
688
- * The UI is delivered as a {@link module:engine/view/uielement~UIElement}
689
- * wrapper which renders DOM buttons that users can use to insert paragraphs.
690
- */ _enableTypeAroundUIInjection() {
691
+ * Creates a listener in the editing conversion pipeline that injects the widget type around
692
+ * UI into every single widget instance created in the editor.
693
+ *
694
+ * The UI is delivered as a {@link module:engine/view/uielement~UIElement}
695
+ * wrapper which renders DOM buttons that users can use to insert paragraphs.
696
+ */ _enableTypeAroundUIInjection() {
691
697
  const editor = this.editor;
692
698
  const schema = editor.model.schema;
693
699
  const t = editor.locale.t;
@@ -713,30 +719,30 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
713
719
  });
714
720
  }
715
721
  /**
716
- * Brings support for the fake caret that appears when either:
717
- *
718
- * * the selection moves to a widget from a position next to it using arrow keys,
719
- * * the arrow key is pressed when the widget is already selected.
720
- *
721
- * The fake caret lets the user know that they can start typing or just press
722
- * <kbd>Enter</kbd> to insert a paragraph at the position next to a widget as suggested by the fake caret.
723
- *
724
- * The fake caret disappears when the user changes the selection or the editor
725
- * gets blurred.
726
- *
727
- * The whole idea is as follows:
728
- *
729
- * 1. A user does one of the 2 scenarios described at the beginning.
730
- * 2. The "keydown" listener is executed and the decision is made whether to show or hide the fake caret.
731
- * 3. If it should show up, the `widget-type-around` model selection attribute is set indicating
732
- * on which side of the widget it should appear.
733
- * 4. The selection dispatcher reacts to the selection attribute and sets CSS classes responsible for the
734
- * fake caret on the view widget.
735
- * 5. If the fake caret should disappear, the selection attribute is removed and the dispatcher
736
- * does the CSS class clean-up in the view.
737
- * 6. Additionally, `change:range` and `FocusTracker#isFocused` listeners also remove the selection
738
- * attribute (the former also removes widget CSS classes).
739
- */ _enableTypeAroundFakeCaretActivationUsingKeyboardArrows() {
722
+ * Brings support for the fake caret that appears when either:
723
+ *
724
+ * * the selection moves to a widget from a position next to it using arrow keys,
725
+ * * the arrow key is pressed when the widget is already selected.
726
+ *
727
+ * The fake caret lets the user know that they can start typing or just press
728
+ * <kbd>Enter</kbd> to insert a paragraph at the position next to a widget as suggested by the fake caret.
729
+ *
730
+ * The fake caret disappears when the user changes the selection or the editor
731
+ * gets blurred.
732
+ *
733
+ * The whole idea is as follows:
734
+ *
735
+ * 1. A user does one of the 2 scenarios described at the beginning.
736
+ * 2. The "keydown" listener is executed and the decision is made whether to show or hide the fake caret.
737
+ * 3. If it should show up, the `widget-type-around` model selection attribute is set indicating
738
+ * on which side of the widget it should appear.
739
+ * 4. The selection dispatcher reacts to the selection attribute and sets CSS classes responsible for the
740
+ * fake caret on the view widget.
741
+ * 5. If the fake caret should disappear, the selection attribute is removed and the dispatcher
742
+ * does the CSS class clean-up in the view.
743
+ * 6. Additionally, `change:range` and `FocusTracker#isFocused` listeners also remove the selection
744
+ * attribute (the former also removes widget CSS classes).
745
+ */ _enableTypeAroundFakeCaretActivationUsingKeyboardArrows() {
740
746
  const editor = this.editor;
741
747
  const model = editor.model;
742
748
  const modelSelection = model.document.selection;
@@ -824,17 +830,17 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
824
830
  }
825
831
  }
826
832
  /**
827
- * A listener executed on each "keydown" in the view document, a part of
828
- * {@link #_enableTypeAroundFakeCaretActivationUsingKeyboardArrows}.
829
- *
830
- * It decides whether the arrow keypress should activate the fake caret or not (also whether it should
831
- * be deactivated).
832
- *
833
- * The fake caret activation is done by setting the `widget-type-around` model selection attribute
834
- * in this listener, and stopping and preventing the event that would normally be handled by the widget
835
- * plugin that is responsible for the regular keyboard navigation near/across all widgets (that
836
- * includes inline widgets, which are ignored by the widget type around plugin).
837
- */ _handleArrowKeyPress(evt, domEventData) {
833
+ * A listener executed on each "keydown" in the view document, a part of
834
+ * {@link #_enableTypeAroundFakeCaretActivationUsingKeyboardArrows}.
835
+ *
836
+ * It decides whether the arrow keypress should activate the fake caret or not (also whether it should
837
+ * be deactivated).
838
+ *
839
+ * The fake caret activation is done by setting the `widget-type-around` model selection attribute
840
+ * in this listener, and stopping and preventing the event that would normally be handled by the widget
841
+ * plugin that is responsible for the regular keyboard navigation near/across all widgets (that
842
+ * includes inline widgets, which are ignored by the widget type around plugin).
843
+ */ _handleArrowKeyPress(evt, domEventData) {
838
844
  const editor = this.editor;
839
845
  const model = editor.model;
840
846
  const modelSelection = model.document.selection;
@@ -859,15 +865,15 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
859
865
  }
860
866
  }
861
867
  /**
862
- * Handles the keyboard navigation on "keydown" when a widget is currently selected and activates or deactivates
863
- * the fake caret for that widget, depending on the current value of the `widget-type-around` model
864
- * selection attribute and the direction of the pressed arrow key.
865
- *
866
- * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
867
- * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
868
- * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
869
- * process the event any further. Returns `false` otherwise.
870
- */ _handleArrowKeyPressOnSelectedWidget(isForward) {
868
+ * Handles the keyboard navigation on "keydown" when a widget is currently selected and activates or deactivates
869
+ * the fake caret for that widget, depending on the current value of the `widget-type-around` model
870
+ * selection attribute and the direction of the pressed arrow key.
871
+ *
872
+ * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
873
+ * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
874
+ * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
875
+ * process the event any further. Returns `false` otherwise.
876
+ */ _handleArrowKeyPressOnSelectedWidget(isForward) {
871
877
  const editor = this.editor;
872
878
  const model = editor.model;
873
879
  const modelSelection = model.document.selection;
@@ -896,19 +902,19 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
896
902
  });
897
903
  }
898
904
  /**
899
- * Handles the keyboard navigation on "keydown" when **no** widget is selected but the selection is **directly** next
900
- * to one and upon the fake caret should become active for this widget upon arrow keypress
901
- * (AKA entering/selecting the widget).
902
- *
903
- * **Note**: This code mirrors the implementation from the widget plugin but also adds the selection attribute.
904
- * Unfortunately, there is no safe way to let the widget plugin do the selection part first and then just set the
905
- * selection attribute here in the widget type around plugin. This is why this code must duplicate some from the widget plugin.
906
- *
907
- * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
908
- * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
909
- * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
910
- * process the event any further. Returns `false` otherwise.
911
- */ _handleArrowKeyPressWhenSelectionNextToAWidget(isForward) {
905
+ * Handles the keyboard navigation on "keydown" when **no** widget is selected but the selection is **directly** next
906
+ * to one and upon the fake caret should become active for this widget upon arrow keypress
907
+ * (AKA entering/selecting the widget).
908
+ *
909
+ * **Note**: This code mirrors the implementation from the widget plugin but also adds the selection attribute.
910
+ * Unfortunately, there is no safe way to let the widget plugin do the selection part first and then just set the
911
+ * selection attribute here in the widget type around plugin. This is why this code must duplicate some from the widget plugin.
912
+ *
913
+ * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
914
+ * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
915
+ * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
916
+ * process the event any further. Returns `false` otherwise.
917
+ */ _handleArrowKeyPressWhenSelectionNextToAWidget(isForward) {
912
918
  const editor = this.editor;
913
919
  const model = editor.model;
914
920
  const schema = model.schema;
@@ -928,14 +934,14 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
928
934
  return false;
929
935
  }
930
936
  /**
931
- * Handles the keyboard navigation on "keydown" when a widget is currently selected (together with some other content)
932
- * and the widget is the first or last element in the selection. It activates or deactivates the fake caret for that widget.
933
- *
934
- * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
935
- * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
936
- * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
937
- * process the event any further. Returns `false` otherwise.
938
- */ _handleArrowKeyPressWhenNonCollapsedSelection(isForward) {
937
+ * Handles the keyboard navigation on "keydown" when a widget is currently selected (together with some other content)
938
+ * and the widget is the first or last element in the selection. It activates or deactivates the fake caret for that widget.
939
+ *
940
+ * @param isForward `true` when the pressed arrow key was responsible for the forward model selection movement
941
+ * as in {@link module:utils/keyboard~isForwardArrowKeyCode}.
942
+ * @returns Returns `true` when the keypress was handled and no other keydown listener of the editor should
943
+ * process the event any further. Returns `false` otherwise.
944
+ */ _handleArrowKeyPressWhenNonCollapsedSelection(isForward) {
939
945
  const editor = this.editor;
940
946
  const model = editor.model;
941
947
  const schema = model.schema;
@@ -954,10 +960,10 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
954
960
  return false;
955
961
  }
956
962
  /**
957
- * Registers a `mousedown` listener for the view document which intercepts events
958
- * coming from the widget type around UI, which happens when a user clicks one of the buttons
959
- * that insert a paragraph next to a widget.
960
- */ _enableInsertingParagraphsOnButtonClick() {
963
+ * Registers a `mousedown` listener for the view document which intercepts events
964
+ * coming from the widget type around UI, which happens when a user clicks one of the buttons
965
+ * that insert a paragraph next to a widget.
966
+ */ _enableInsertingParagraphsOnButtonClick() {
961
967
  const editor = this.editor;
962
968
  const editingView = editor.editing.view;
963
969
  this._listenToIfEnabled(editingView.document, 'mousedown', (evt, domEventData)=>{
@@ -974,18 +980,18 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
974
980
  });
975
981
  }
976
982
  /**
977
- * Creates the <kbd>Enter</kbd> key listener on the view document that allows the user to insert a paragraph
978
- * near the widget when either:
979
- *
980
- * * The fake caret was first activated using the arrow keys,
981
- * * The entire widget is selected in the model.
982
- *
983
- * In the first case, the new paragraph is inserted according to the `widget-type-around` selection
984
- * attribute (see {@link #_handleArrowKeyPress}).
985
- *
986
- * In the second case, the new paragraph is inserted based on whether a soft (<kbd>Shift</kbd>+<kbd>Enter</kbd>) keystroke
987
- * was pressed or not.
988
- */ _enableInsertingParagraphsOnEnterKeypress() {
983
+ * Creates the <kbd>Enter</kbd> key listener on the view document that allows the user to insert a paragraph
984
+ * near the widget when either:
985
+ *
986
+ * * The fake caret was first activated using the arrow keys,
987
+ * * The entire widget is selected in the model.
988
+ *
989
+ * In the first case, the new paragraph is inserted according to the `widget-type-around` selection
990
+ * attribute (see {@link #_handleArrowKeyPress}).
991
+ *
992
+ * In the second case, the new paragraph is inserted based on whether a soft (<kbd>Shift</kbd>+<kbd>Enter</kbd>) keystroke
993
+ * was pressed or not.
994
+ */ _enableInsertingParagraphsOnEnterKeypress() {
989
995
  const editor = this.editor;
990
996
  const selection = editor.model.document.selection;
991
997
  const editingView = editor.editing.view;
@@ -1016,18 +1022,18 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
1016
1022
  });
1017
1023
  }
1018
1024
  /**
1019
- * Similar to the {@link #_enableInsertingParagraphsOnEnterKeypress}, it allows the user
1020
- * to insert a paragraph next to a widget when the fake caret was activated using arrow
1021
- * keys but it responds to typing instead of <kbd>Enter</kbd>.
1022
- *
1023
- * Listener enabled by this method will insert a new paragraph according to the `widget-type-around`
1024
- * model selection attribute as the user simply starts typing, which creates the impression that the fake caret
1025
- * behaves like a real one rendered by the browser (AKA your text appears where the caret was).
1026
- *
1027
- * **Note**: At the moment this listener creates 2 undo steps: one for the `insertParagraph` command
1028
- * and another one for actual typing. It is not a disaster but this may need to be fixed
1029
- * sooner or later.
1030
- */ _enableInsertingParagraphsOnTypingKeystroke() {
1025
+ * Similar to the {@link #_enableInsertingParagraphsOnEnterKeypress}, it allows the user
1026
+ * to insert a paragraph next to a widget when the fake caret was activated using arrow
1027
+ * keys but it responds to typing instead of <kbd>Enter</kbd>.
1028
+ *
1029
+ * Listener enabled by this method will insert a new paragraph according to the `widget-type-around`
1030
+ * model selection attribute as the user simply starts typing, which creates the impression that the fake caret
1031
+ * behaves like a real one rendered by the browser (AKA your text appears where the caret was).
1032
+ *
1033
+ * **Note**: At the moment this listener creates 2 undo steps: one for the `insertParagraph` command
1034
+ * and another one for actual typing. It is not a disaster but this may need to be fixed
1035
+ * sooner or later.
1036
+ */ _enableInsertingParagraphsOnTypingKeystroke() {
1031
1037
  const editor = this.editor;
1032
1038
  const viewDocument = editor.editing.view.document;
1033
1039
  // Note: The priority must precede the default Input plugin insertText handler.
@@ -1061,13 +1067,13 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
1061
1067
  }
1062
1068
  }
1063
1069
  /**
1064
- * It creates a "delete" event listener on the view document to handle cases when the <kbd>Delete</kbd> or <kbd>Backspace</kbd>
1065
- * is pressed and the fake caret is currently active.
1066
- *
1067
- * The fake caret should create an illusion of a real browser caret so that when it appears before or after
1068
- * a widget, pressing <kbd>Delete</kbd> or <kbd>Backspace</kbd> should remove a widget or delete the content
1069
- * before or after a widget (depending on the content surrounding the widget).
1070
- */ _enableDeleteIntegration() {
1070
+ * It creates a "delete" event listener on the view document to handle cases when the <kbd>Delete</kbd> or <kbd>Backspace</kbd>
1071
+ * is pressed and the fake caret is currently active.
1072
+ *
1073
+ * The fake caret should create an illusion of a real browser caret so that when it appears before or after
1074
+ * a widget, pressing <kbd>Delete</kbd> or <kbd>Backspace</kbd> should remove a widget or delete the content
1075
+ * before or after a widget (depending on the content surrounding the widget).
1076
+ */ _enableDeleteIntegration() {
1071
1077
  const editor = this.editor;
1072
1078
  const editingView = editor.editing.view;
1073
1079
  const model = editor.model;
@@ -1132,11 +1138,11 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
1132
1138
  });
1133
1139
  }
1134
1140
  /**
1135
- * Attaches the {@link module:engine/model/model~Model#event:insertContent} event listener that, for instance, allows the user to paste
1136
- * content near a widget when the fake caret is first activated using the arrow keys.
1137
- *
1138
- * The content is inserted according to the `widget-type-around` selection attribute (see {@link #_handleArrowKeyPress}).
1139
- */ _enableInsertContentIntegration() {
1141
+ * Attaches the {@link module:engine/model/model~Model#event:insertContent} event listener that, for instance, allows the user to paste
1142
+ * content near a widget when the fake caret is first activated using the arrow keys.
1143
+ *
1144
+ * The content is inserted according to the `widget-type-around` selection attribute (see {@link #_handleArrowKeyPress}).
1145
+ */ _enableInsertContentIntegration() {
1140
1146
  const editor = this.editor;
1141
1147
  const model = this.editor.model;
1142
1148
  const documentSelection = model.document.selection;
@@ -1162,12 +1168,12 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
1162
1168
  });
1163
1169
  }
1164
1170
  /**
1165
- * Attaches the {@link module:engine/model/model~Model#event:insertObject} event listener that modifies the
1166
- * `options.findOptimalPosition`parameter to position of fake caret in relation to selected element
1167
- * to reflect user's intent of desired insertion position.
1168
- *
1169
- * The object is inserted according to the `widget-type-around` selection attribute (see {@link #_handleArrowKeyPress}).
1170
- */ _enableInsertObjectIntegration() {
1171
+ * Attaches the {@link module:engine/model/model~Model#event:insertObject} event listener that modifies the
1172
+ * `options.findOptimalPosition`parameter to position of fake caret in relation to selected element
1173
+ * to reflect user's intent of desired insertion position.
1174
+ *
1175
+ * The object is inserted according to the `widget-type-around` selection attribute (see {@link #_handleArrowKeyPress}).
1176
+ */ _enableInsertObjectIntegration() {
1171
1177
  const editor = this.editor;
1172
1178
  const model = this.editor.model;
1173
1179
  const documentSelection = model.document.selection;
@@ -1187,13 +1193,13 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
1187
1193
  });
1188
1194
  }
1189
1195
  /**
1190
- * Attaches the {@link module:engine/model/model~Model#event:deleteContent} event listener to block the event when the fake
1191
- * caret is active.
1192
- *
1193
- * This is required for cases that trigger {@link module:engine/model/model~Model#deleteContent `model.deleteContent()`}
1194
- * before calling {@link module:engine/model/model~Model#insertContent `model.insertContent()`} like, for instance,
1195
- * plain text pasting.
1196
- */ _enableDeleteContentIntegration() {
1196
+ * Attaches the {@link module:engine/model/model~Model#event:deleteContent} event listener to block the event when the fake
1197
+ * caret is active.
1198
+ *
1199
+ * This is required for cases that trigger {@link module:engine/model/model~Model#deleteContent `model.deleteContent()`}
1200
+ * before calling {@link module:engine/model/model~Model#insertContent `model.insertContent()`} like, for instance,
1201
+ * plain text pasting.
1202
+ */ _enableDeleteContentIntegration() {
1197
1203
  const editor = this.editor;
1198
1204
  const model = this.editor.model;
1199
1205
  const documentSelection = model.document.selection;
@@ -1481,30 +1487,33 @@ function selectionWillShrink(selection, isForward) {
1481
1487
  * is added to indicate that widget has been selected.
1482
1488
  * * The mouse and keyboard events handling on and around widget elements.
1483
1489
  */ class Widget extends Plugin {
1490
+ constructor(){
1491
+ super(...arguments);
1492
+ /**
1493
+ * Holds previously selected widgets.
1494
+ */ this._previouslySelected = new Set();
1495
+ }
1484
1496
  /**
1485
- * Holds previously selected widgets.
1486
- */ _previouslySelected = new Set();
1487
- /**
1488
- * @inheritDoc
1489
- */ static get pluginName() {
1497
+ * @inheritDoc
1498
+ */ static get pluginName() {
1490
1499
  return 'Widget';
1491
1500
  }
1492
1501
  /**
1493
- * @inheritDoc
1494
- */ static get isOfficialPlugin() {
1502
+ * @inheritDoc
1503
+ */ static get isOfficialPlugin() {
1495
1504
  return true;
1496
1505
  }
1497
1506
  /**
1498
- * @inheritDoc
1499
- */ static get requires() {
1507
+ * @inheritDoc
1508
+ */ static get requires() {
1500
1509
  return [
1501
1510
  WidgetTypeAround,
1502
1511
  Delete
1503
1512
  ];
1504
1513
  }
1505
1514
  /**
1506
- * @inheritDoc
1507
- */ init() {
1515
+ * @inheritDoc
1516
+ */ init() {
1508
1517
  const editor = this.editor;
1509
1518
  const view = editor.editing.view;
1510
1519
  const viewDocument = view.document;
@@ -1699,8 +1708,8 @@ function selectionWillShrink(selection, isForward) {
1699
1708
  });
1700
1709
  }
1701
1710
  /**
1702
- * Handles {@link module:engine/view/document~Document#event:mousedown mousedown} events on widget elements.
1703
- */ _onMousedown(eventInfo, domEventData) {
1711
+ * Handles {@link module:engine/view/document~Document#event:mousedown mousedown} events on widget elements.
1712
+ */ _onMousedown(eventInfo, domEventData) {
1704
1713
  const editor = this.editor;
1705
1714
  const view = editor.editing.view;
1706
1715
  const viewDocument = view.document;
@@ -1748,8 +1757,8 @@ function selectionWillShrink(selection, isForward) {
1748
1757
  this._setSelectionOverElement(modelElement);
1749
1758
  }
1750
1759
  /**
1751
- * Selects entire block content, e.g. on triple click it selects entire paragraph.
1752
- */ _selectBlockContent(element) {
1760
+ * Selects entire block content, e.g. on triple click it selects entire paragraph.
1761
+ */ _selectBlockContent(element) {
1753
1762
  const editor = this.editor;
1754
1763
  const model = editor.model;
1755
1764
  const mapper = editor.editing.mapper;
@@ -1768,14 +1777,14 @@ function selectionWillShrink(selection, isForward) {
1768
1777
  return true;
1769
1778
  }
1770
1779
  /**
1771
- * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and changes
1772
- * the model selection when:
1773
- *
1774
- * * arrow key is pressed when the widget is selected,
1775
- * * the selection is next to a widget and the widget should become selected upon the arrow key press.
1776
- *
1777
- * See {@link #_preventDefaultOnArrowKeyPress}.
1778
- */ _handleSelectionChangeOnArrowKeyPress(eventInfo, domEventData) {
1780
+ * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and changes
1781
+ * the model selection when:
1782
+ *
1783
+ * * arrow key is pressed when the widget is selected,
1784
+ * * the selection is next to a widget and the widget should become selected upon the arrow key press.
1785
+ *
1786
+ * See {@link #_preventDefaultOnArrowKeyPress}.
1787
+ */ _handleSelectionChangeOnArrowKeyPress(eventInfo, domEventData) {
1779
1788
  const keyCode = domEventData.keyCode;
1780
1789
  const model = this.editor.model;
1781
1790
  const schema = model.schema;
@@ -1830,12 +1839,12 @@ function selectionWillShrink(selection, isForward) {
1830
1839
  }
1831
1840
  }
1832
1841
  /**
1833
- * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and prevents
1834
- * the default browser behavior to make sure the fake selection is not being moved from a fake selection
1835
- * container.
1836
- *
1837
- * See {@link #_handleSelectionChangeOnArrowKeyPress}.
1838
- */ _preventDefaultOnArrowKeyPress(eventInfo, domEventData) {
1842
+ * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and prevents
1843
+ * the default browser behavior to make sure the fake selection is not being moved from a fake selection
1844
+ * container.
1845
+ *
1846
+ * See {@link #_handleSelectionChangeOnArrowKeyPress}.
1847
+ */ _preventDefaultOnArrowKeyPress(eventInfo, domEventData) {
1839
1848
  const model = this.editor.model;
1840
1849
  const schema = model.schema;
1841
1850
  const objectElement = model.document.selection.getSelectedElement();
@@ -1846,11 +1855,11 @@ function selectionWillShrink(selection, isForward) {
1846
1855
  }
1847
1856
  }
1848
1857
  /**
1849
- * Handles delete keys: backspace and delete.
1850
- *
1851
- * @param isForward Set to true if delete was performed in forward direction.
1852
- * @returns Returns `true` if keys were handled correctly.
1853
- */ _handleDelete(isForward) {
1858
+ * Handles delete keys: backspace and delete.
1859
+ *
1860
+ * @param isForward Set to true if delete was performed in forward direction.
1861
+ * @returns Returns `true` if keys were handled correctly.
1862
+ */ _handleDelete(isForward) {
1854
1863
  const modelDocument = this.editor.model.document;
1855
1864
  const modelSelection = modelDocument.selection;
1856
1865
  // Do nothing when the read only mode is enabled.
@@ -1877,22 +1886,22 @@ function selectionWillShrink(selection, isForward) {
1877
1886
  }
1878
1887
  }
1879
1888
  /**
1880
- * Sets {@link module:engine/model/selection~Selection document's selection} over given element.
1881
- *
1882
- * @internal
1883
- */ _setSelectionOverElement(element) {
1889
+ * Sets {@link module:engine/model/selection~Selection document's selection} over given element.
1890
+ *
1891
+ * @internal
1892
+ */ _setSelectionOverElement(element) {
1884
1893
  this.editor.model.change((writer)=>{
1885
1894
  writer.setSelection(writer.createRangeOn(element));
1886
1895
  });
1887
1896
  }
1888
1897
  /**
1889
- * Checks if {@link module:engine/model/element~Element element} placed next to the current
1890
- * {@link module:engine/model/selection~Selection model selection} exists and is marked in
1891
- * {@link module:engine/model/schema~Schema schema} as `object`.
1892
- *
1893
- * @internal
1894
- * @param forward Direction of checking.
1895
- */ _getObjectElementNextToSelection(forward) {
1898
+ * Checks if {@link module:engine/model/element~Element element} placed next to the current
1899
+ * {@link module:engine/model/selection~Selection model selection} exists and is marked in
1900
+ * {@link module:engine/model/schema~Schema schema} as `object`.
1901
+ *
1902
+ * @internal
1903
+ * @param forward Direction of checking.
1904
+ */ _getObjectElementNextToSelection(forward) {
1896
1905
  const model = this.editor.model;
1897
1906
  const schema = model.schema;
1898
1907
  const modelSelection = model.document.selection;
@@ -1913,16 +1922,16 @@ function selectionWillShrink(selection, isForward) {
1913
1922
  return null;
1914
1923
  }
1915
1924
  /**
1916
- * Removes CSS class from previously selected widgets.
1917
- */ _clearPreviouslySelectedWidgets(writer) {
1925
+ * Removes CSS class from previously selected widgets.
1926
+ */ _clearPreviouslySelectedWidgets(writer) {
1918
1927
  for (const widget of this._previouslySelected){
1919
1928
  writer.removeClass(WIDGET_SELECTED_CLASS_NAME, widget);
1920
1929
  }
1921
1930
  this._previouslySelected.clear();
1922
1931
  }
1923
1932
  /**
1924
- * Moves the document selection into the first nested editable.
1925
- */ _selectFirstNestedEditable() {
1933
+ * Moves the document selection into the first nested editable.
1934
+ */ _selectFirstNestedEditable() {
1926
1935
  const editor = this.editor;
1927
1936
  const view = this.editor.editing.view;
1928
1937
  const viewDocument = view.document;
@@ -1943,8 +1952,8 @@ function selectionWillShrink(selection, isForward) {
1943
1952
  return false;
1944
1953
  }
1945
1954
  /**
1946
- * Updates the document selection so that it selects first ancestor widget.
1947
- */ _selectAncestorWidget() {
1955
+ * Updates the document selection so that it selects first ancestor widget.
1956
+ */ _selectAncestorWidget() {
1948
1957
  const editor = this.editor;
1949
1958
  const mapper = editor.editing.mapper;
1950
1959
  const selection = editor.editing.view.document.selection;
@@ -2091,30 +2100,32 @@ function selectionWillShrink(selection, isForward) {
2091
2100
  * }
2092
2101
  * ```
2093
2102
  */ class WidgetToolbarRepository extends Plugin {
2103
+ constructor(){
2104
+ super(...arguments);
2105
+ /**
2106
+ * A map of toolbar definitions.
2107
+ */ this._toolbarDefinitions = new Map();
2108
+ }
2094
2109
  /**
2095
- * A map of toolbar definitions.
2096
- */ _toolbarDefinitions = new Map();
2097
- _balloon;
2098
- /**
2099
- * @inheritDoc
2100
- */ static get requires() {
2110
+ * @inheritDoc
2111
+ */ static get requires() {
2101
2112
  return [
2102
2113
  ContextualBalloon
2103
2114
  ];
2104
2115
  }
2105
2116
  /**
2106
- * @inheritDoc
2107
- */ static get pluginName() {
2117
+ * @inheritDoc
2118
+ */ static get pluginName() {
2108
2119
  return 'WidgetToolbarRepository';
2109
2120
  }
2110
2121
  /**
2111
- * @inheritDoc
2112
- */ static get isOfficialPlugin() {
2122
+ * @inheritDoc
2123
+ */ static get isOfficialPlugin() {
2113
2124
  return true;
2114
2125
  }
2115
2126
  /**
2116
- * @inheritDoc
2117
- */ init() {
2127
+ * @inheritDoc
2128
+ */ init() {
2118
2129
  const editor = this.editor;
2119
2130
  // Disables the default balloon toolbar for all widgets.
2120
2131
  if (editor.plugins.has('BalloonToolbar')) {
@@ -2148,35 +2159,35 @@ function selectionWillShrink(selection, isForward) {
2148
2159
  }
2149
2160
  }
2150
2161
  /**
2151
- * Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
2152
- * `getRelatedElement` function. Toolbar items are gathered from `items` array.
2153
- * The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
2154
- *
2155
- * Note: This method should be called in the {@link module:core/plugin~PluginInterface#afterInit `Plugin#afterInit()`}
2156
- * callback (or later) to make sure that the given toolbar items were already registered by other plugins.
2157
- *
2158
- * @param toolbarId An id for the toolbar. Used to
2159
- * @param options.ariaLabel Label used by assistive technologies to describe this toolbar element.
2160
- * @param options.items Array of toolbar items.
2161
- * @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
2162
- * @param options.balloonClassName CSS class for the widget balloon.
2163
- */ register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container' }) {
2162
+ * Registers toolbar in the WidgetToolbarRepository. It renders it in the `ContextualBalloon` based on the value of the invoked
2163
+ * `getRelatedElement` function. Toolbar items are gathered from `items` array.
2164
+ * The balloon's CSS class is by default `ck-toolbar-container` and may be override with the `balloonClassName` option.
2165
+ *
2166
+ * Note: This method should be called in the {@link module:core/plugin~PluginInterface#afterInit `Plugin#afterInit()`}
2167
+ * callback (or later) to make sure that the given toolbar items were already registered by other plugins.
2168
+ *
2169
+ * @param toolbarId An id for the toolbar. Used to
2170
+ * @param options.ariaLabel Label used by assistive technologies to describe this toolbar element.
2171
+ * @param options.items Array of toolbar items.
2172
+ * @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
2173
+ * @param options.balloonClassName CSS class for the widget balloon.
2174
+ */ register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container' }) {
2164
2175
  // Trying to register a toolbar without any item.
2165
2176
  if (!items.length) {
2166
2177
  /**
2167
- * When {@link module:widget/widgettoolbarrepository~WidgetToolbarRepository#register registering} a new widget toolbar, you
2168
- * need to provide a non-empty array with the items that will be inserted into the toolbar.
2169
- *
2170
- * If you see this error when integrating the editor, you likely forgot to configure one of the widget toolbars.
2171
- *
2172
- * See for instance:
2173
- *
2174
- * * {@link module:table/tableconfig~TableConfig#contentToolbar `config.table.contentToolbar`}
2175
- * * {@link module:image/imageconfig~ImageConfig#toolbar `config.image.toolbar`}
2176
- *
2177
- * @error widget-toolbar-no-items
2178
- * @param toolbarId The id of the toolbar that has not been configured correctly.
2179
- */ logWarning('widget-toolbar-no-items', {
2178
+ * When {@link module:widget/widgettoolbarrepository~WidgetToolbarRepository#register registering} a new widget toolbar, you
2179
+ * need to provide a non-empty array with the items that will be inserted into the toolbar.
2180
+ *
2181
+ * If you see this error when integrating the editor, you likely forgot to configure one of the widget toolbars.
2182
+ *
2183
+ * See for instance:
2184
+ *
2185
+ * * {@link module:table/tableconfig~TableConfig#contentToolbar `config.table.contentToolbar`}
2186
+ * * {@link module:image/imageconfig~ImageConfig#toolbar `config.image.toolbar`}
2187
+ *
2188
+ * @error widget-toolbar-no-items
2189
+ * @param toolbarId The id of the toolbar that has not been configured correctly.
2190
+ */ logWarning('widget-toolbar-no-items', {
2180
2191
  toolbarId
2181
2192
  });
2182
2193
  return;
@@ -2187,11 +2198,11 @@ function selectionWillShrink(selection, isForward) {
2187
2198
  toolbarView.ariaLabel = ariaLabel || t('Widget toolbar');
2188
2199
  if (this._toolbarDefinitions.has(toolbarId)) {
2189
2200
  /**
2190
- * Toolbar with the given id was already added.
2191
- *
2192
- * @error widget-toolbar-duplicated
2193
- * @param toolbarId Toolbar id.
2194
- */ throw new CKEditorError('widget-toolbar-duplicated', this, {
2201
+ * Toolbar with the given id was already added.
2202
+ *
2203
+ * @error widget-toolbar-duplicated
2204
+ * @param toolbarId Toolbar id.
2205
+ */ throw new CKEditorError('widget-toolbar-duplicated', this, {
2195
2206
  toolbarId
2196
2207
  });
2197
2208
  }
@@ -2218,8 +2229,8 @@ function selectionWillShrink(selection, isForward) {
2218
2229
  this._toolbarDefinitions.set(toolbarId, toolbarDefinition);
2219
2230
  }
2220
2231
  /**
2221
- * Iterates over stored toolbars and makes them visible or hidden.
2222
- */ _updateToolbarsVisibility() {
2232
+ * Iterates over stored toolbars and makes them visible or hidden.
2233
+ */ _updateToolbarsVisibility() {
2223
2234
  let maxRelatedElementDepth = 0;
2224
2235
  let deepestRelatedElement = null;
2225
2236
  let deepestToolbarDefinition = null;
@@ -2251,18 +2262,18 @@ function selectionWillShrink(selection, isForward) {
2251
2262
  }
2252
2263
  }
2253
2264
  /**
2254
- * Hides the given toolbar.
2255
- */ _hideToolbar(toolbarDefinition) {
2265
+ * Hides the given toolbar.
2266
+ */ _hideToolbar(toolbarDefinition) {
2256
2267
  this._balloon.remove(toolbarDefinition.view);
2257
2268
  this.stopListening(this._balloon, 'change:visibleView');
2258
2269
  }
2259
2270
  /**
2260
- * Shows up the toolbar if the toolbar is not visible.
2261
- * Otherwise, repositions the toolbar's balloon when toolbar's view is the most top view in balloon stack.
2262
- *
2263
- * It might happen here that the toolbar's view is under another view. Then do nothing as the other toolbar view
2264
- * should be still visible after the {@link module:ui/editorui/editorui~EditorUI#event:update}.
2265
- */ _showToolbar(toolbarDefinition, relatedElement) {
2271
+ * Shows up the toolbar if the toolbar is not visible.
2272
+ * Otherwise, repositions the toolbar's balloon when toolbar's view is the most top view in balloon stack.
2273
+ *
2274
+ * It might happen here that the toolbar's view is under another view. Then do nothing as the other toolbar view
2275
+ * should be still visible after the {@link module:ui/editorui/editorui~EditorUI#event:update}.
2276
+ */ _showToolbar(toolbarDefinition, relatedElement) {
2266
2277
  if (this._isToolbarVisible(toolbarDefinition)) {
2267
2278
  repositionContextualBalloon(this.editor, relatedElement);
2268
2279
  } else if (!this._isToolbarInBalloon(toolbarDefinition)) {
@@ -2326,38 +2337,8 @@ function isWidgetSelected(selection) {
2326
2337
  * Stores the internal state of a single resizable object.
2327
2338
  */ class ResizeState extends /* #__PURE__ */ ObservableMixin() {
2328
2339
  /**
2329
- * The reference point of the resizer where the dragging started. It is used to measure the distance the user cursor
2330
- * traveled, so how much the image should be enlarged.
2331
- * This information is only known after the DOM was rendered, so it will be updated later.
2332
- *
2333
- * @internal
2334
- */ _referenceCoordinates;
2335
- /**
2336
- * Resizer options.
2337
- */ _options;
2338
- /**
2339
- * The original width (pixels) of the resized object when the resize process was started.
2340
- *
2341
- * @readonly
2342
- */ _originalWidth;
2343
- /**
2344
- * The original height (pixels) of the resized object when the resize process was started.
2345
- *
2346
- * @readonly
2347
- */ _originalHeight;
2348
- /**
2349
- * The original width (percents) of the resized object when the resize process was started.
2350
- *
2351
- * @readonly
2352
- */ _originalWidthPercents;
2353
- /**
2354
- * A width to height ratio of the resized image.
2355
- *
2356
- * @readonly
2357
- */ _aspectRatio;
2358
- /**
2359
- * @param options Resizer options.
2360
- */ constructor(options){
2340
+ * @param options Resizer options.
2341
+ */ constructor(options){
2361
2342
  super();
2362
2343
  this.set('activeHandlePosition', null);
2363
2344
  this.set('proposedWidthPercents', null);
@@ -2369,29 +2350,29 @@ function isWidgetSelected(selection) {
2369
2350
  this._referenceCoordinates = null;
2370
2351
  }
2371
2352
  /**
2372
- * The original width (pixels) of the resized object when the resize process was started.
2373
- */ get originalWidth() {
2353
+ * The original width (pixels) of the resized object when the resize process was started.
2354
+ */ get originalWidth() {
2374
2355
  return this._originalWidth;
2375
2356
  }
2376
2357
  /**
2377
- * The original height (pixels) of the resized object when the resize process was started.
2378
- */ get originalHeight() {
2358
+ * The original height (pixels) of the resized object when the resize process was started.
2359
+ */ get originalHeight() {
2379
2360
  return this._originalHeight;
2380
2361
  }
2381
2362
  /**
2382
- * The original width (percents) of the resized object when the resize process was started.
2383
- */ get originalWidthPercents() {
2363
+ * The original width (percents) of the resized object when the resize process was started.
2364
+ */ get originalWidthPercents() {
2384
2365
  return this._originalWidthPercents;
2385
2366
  }
2386
2367
  /**
2387
- * A width to height ratio of the resized image.
2388
- */ get aspectRatio() {
2368
+ * A width to height ratio of the resized image.
2369
+ */ get aspectRatio() {
2389
2370
  return this._aspectRatio;
2390
2371
  }
2391
2372
  /**
2392
- *
2393
- * @param domResizeHandle The handle used to calculate the reference point.
2394
- */ begin(domResizeHandle, domHandleHost, domResizeHost) {
2373
+ *
2374
+ * @param domResizeHandle The handle used to calculate the reference point.
2375
+ */ begin(domResizeHandle, domHandleHost, domResizeHost) {
2395
2376
  const clientRect = new Rect(domHandleHost);
2396
2377
  this.activeHandlePosition = getHandlePosition(domResizeHandle);
2397
2378
  this._referenceCoordinates = getAbsoluteBoundaryPoint(domHandleHost, getOppositePosition(this.activeHandlePosition));
@@ -2492,12 +2473,12 @@ function isWidgetSelected(selection) {
2492
2473
  });
2493
2474
  }
2494
2475
  /**
2495
- * A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
2496
- *
2497
- * @internal
2498
- * @param options An object defining the resizer options, used for setting the proper size label.
2499
- * @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
2500
- */ _bindToState(options, resizeState) {
2476
+ * A method used for binding the `SizeView` instance properties to the `ResizeState` instance observable properties.
2477
+ *
2478
+ * @internal
2479
+ * @param options An object defining the resizer options, used for setting the proper size label.
2480
+ * @param resizeState The `ResizeState` class instance, used for keeping the `SizeView` state up to date.
2481
+ */ _bindToState(options, resizeState) {
2501
2482
  this.bind('_isVisible').to(resizeState, 'proposedWidth', resizeState, 'proposedHeight', (width, height)=>width !== null && height !== null);
2502
2483
  this.bind('_label').to(resizeState, 'proposedHandleHostWidth', resizeState, 'proposedHandleHostHeight', resizeState, 'proposedWidthPercents', (width, height, widthPercents)=>{
2503
2484
  if (options.unit === 'px') {
@@ -2510,10 +2491,10 @@ function isWidgetSelected(selection) {
2510
2491
  (position, width, height)=>width < 50 || height < 50 ? 'above-center' : position);
2511
2492
  }
2512
2493
  /**
2513
- * A method used for cleaning up. It removes the bindings and hides the view.
2514
- *
2515
- * @internal
2516
- */ _dismiss() {
2494
+ * A method used for cleaning up. It removes the bindings and hides the view.
2495
+ *
2496
+ * @internal
2497
+ */ _dismiss() {
2517
2498
  this.unbind();
2518
2499
  this._isVisible = false;
2519
2500
  }
@@ -2523,26 +2504,12 @@ function isWidgetSelected(selection) {
2523
2504
  * Represents a resizer for a single resizable object.
2524
2505
  */ class Resizer extends /* #__PURE__ */ ObservableMixin() {
2525
2506
  /**
2526
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
2527
- *
2528
- * Note that a new state is created for each resize transaction.
2529
- */ _state;
2530
- /**
2531
- * A view displaying the proposed new element size during the resizing.
2532
- */ _sizeView;
2533
- /**
2534
- * Options passed to the {@link #constructor}.
2535
- */ _options;
2536
- /**
2537
- * A wrapper that is controlled by the resizer. This is usually a widget element.
2538
- */ _viewResizerWrapper = null;
2539
- /**
2540
- * The width of the resized {@link module:widget/widgetresize~ResizerOptions#viewElement viewElement} before the resizing started.
2541
- */ _initialViewWidth;
2542
- /**
2543
- * @param options Resizer options.
2544
- */ constructor(options){
2507
+ * @param options Resizer options.
2508
+ */ constructor(options){
2545
2509
  super();
2510
+ /**
2511
+ * A wrapper that is controlled by the resizer. This is usually a widget element.
2512
+ */ this._viewResizerWrapper = null;
2546
2513
  this._options = options;
2547
2514
  this.set('isEnabled', true);
2548
2515
  this.set('isSelected', false);
@@ -2563,31 +2530,31 @@ function isWidgetSelected(selection) {
2563
2530
  });
2564
2531
  }
2565
2532
  /**
2566
- * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
2567
- *
2568
- * Note that a new state is created for each resize transaction.
2569
- */ get state() {
2533
+ * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
2534
+ *
2535
+ * Note that a new state is created for each resize transaction.
2536
+ */ get state() {
2570
2537
  return this._state;
2571
2538
  }
2572
2539
  /**
2573
- * Makes resizer visible in the UI.
2574
- */ show() {
2540
+ * Makes resizer visible in the UI.
2541
+ */ show() {
2575
2542
  const editingView = this._options.editor.editing.view;
2576
2543
  editingView.change((writer)=>{
2577
2544
  writer.removeClass('ck-hidden', this._viewResizerWrapper);
2578
2545
  });
2579
2546
  }
2580
2547
  /**
2581
- * Hides resizer in the UI.
2582
- */ hide() {
2548
+ * Hides resizer in the UI.
2549
+ */ hide() {
2583
2550
  const editingView = this._options.editor.editing.view;
2584
2551
  editingView.change((writer)=>{
2585
2552
  writer.addClass('ck-hidden', this._viewResizerWrapper);
2586
2553
  });
2587
2554
  }
2588
2555
  /**
2589
- * Attaches the resizer to the DOM.
2590
- */ attach() {
2556
+ * Attaches the resizer to the DOM.
2557
+ */ attach() {
2591
2558
  // eslint-disable-next-line @typescript-eslint/no-this-alias
2592
2559
  const that = this;
2593
2560
  const widgetElement = this._options.viewElement;
@@ -2619,23 +2586,23 @@ function isWidgetSelected(selection) {
2619
2586
  });
2620
2587
  }
2621
2588
  /**
2622
- * Starts the resizing process.
2623
- *
2624
- * Creates a new {@link #state} for the current process.
2625
- *
2626
- * @fires begin
2627
- * @param domResizeHandle Clicked handle.
2628
- */ begin(domResizeHandle) {
2589
+ * Starts the resizing process.
2590
+ *
2591
+ * Creates a new {@link #state} for the current process.
2592
+ *
2593
+ * @fires begin
2594
+ * @param domResizeHandle Clicked handle.
2595
+ */ begin(domResizeHandle) {
2629
2596
  this._state = new ResizeState(this._options);
2630
2597
  this._sizeView._bindToState(this._options, this.state);
2631
2598
  this._initialViewWidth = this._options.viewElement.getStyle('width');
2632
2599
  this.state.begin(domResizeHandle, this._getHandleHost(), this._getResizeHost());
2633
2600
  }
2634
2601
  /**
2635
- * Updates the proposed size based on `domEventData`.
2636
- *
2637
- * @fires updateSize
2638
- */ updateSize(domEventData) {
2602
+ * Updates the proposed size based on `domEventData`.
2603
+ *
2604
+ * @fires updateSize
2605
+ */ updateSize(domEventData) {
2639
2606
  const newSize = this._proposeNewSize(domEventData);
2640
2607
  const editingView = this._options.editor.editing.view;
2641
2608
  editingView.change((writer)=>{
@@ -2662,10 +2629,10 @@ function isWidgetSelected(selection) {
2662
2629
  });
2663
2630
  }
2664
2631
  /**
2665
- * Applies the geometry proposed with the resizer.
2666
- *
2667
- * @fires commit
2668
- */ commit() {
2632
+ * Applies the geometry proposed with the resizer.
2633
+ *
2634
+ * @fires commit
2635
+ */ commit() {
2669
2636
  const unit = this._options.unit || '%';
2670
2637
  const newValue = (unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth) + unit;
2671
2638
  // Both cleanup and onCommit callback are very likely to make view changes. Ensure that it is made in a single step.
@@ -2675,22 +2642,22 @@ function isWidgetSelected(selection) {
2675
2642
  });
2676
2643
  }
2677
2644
  /**
2678
- * Cancels and rejects the proposed resize dimensions, hiding the UI.
2679
- *
2680
- * @fires cancel
2681
- */ cancel() {
2645
+ * Cancels and rejects the proposed resize dimensions, hiding the UI.
2646
+ *
2647
+ * @fires cancel
2648
+ */ cancel() {
2682
2649
  this._cleanup();
2683
2650
  }
2684
2651
  /**
2685
- * Destroys the resizer.
2686
- */ destroy() {
2652
+ * Destroys the resizer.
2653
+ */ destroy() {
2687
2654
  this.cancel();
2688
2655
  }
2689
2656
  /**
2690
- * Redraws the resizer.
2691
- *
2692
- * @param handleHostRect Handle host rectangle might be given to improve performance.
2693
- */ redraw(handleHostRect) {
2657
+ * Redraws the resizer.
2658
+ *
2659
+ * @param handleHostRect Handle host rectangle might be given to improve performance.
2660
+ */ redraw(handleHostRect) {
2694
2661
  const domWrapper = this._domResizerWrapper;
2695
2662
  // Refresh only if resizer exists in the DOM.
2696
2663
  if (!existsInDom(domWrapper)) {
@@ -2745,8 +2712,8 @@ function isWidgetSelected(selection) {
2745
2712
  return domElement.classList.contains('ck-widget__resizer__handle');
2746
2713
  }
2747
2714
  /**
2748
- * Cleans up the context state.
2749
- */ _cleanup() {
2715
+ * Cleans up the context state.
2716
+ */ _cleanup() {
2750
2717
  this._sizeView._dismiss();
2751
2718
  const editingView = this._options.editor.editing.view;
2752
2719
  editingView.change((writer)=>{
@@ -2754,10 +2721,10 @@ function isWidgetSelected(selection) {
2754
2721
  });
2755
2722
  }
2756
2723
  /**
2757
- * Calculates the proposed size as the resize handles are dragged.
2758
- *
2759
- * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
2760
- */ _proposeNewSize(domEventData) {
2724
+ * Calculates the proposed size as the resize handles are dragged.
2725
+ *
2726
+ * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
2727
+ */ _proposeNewSize(domEventData) {
2761
2728
  const state = this.state;
2762
2729
  const currentCoordinates = extractCoordinates(domEventData);
2763
2730
  const isCentered = this._options.isCentered ? this._options.isCentered(this) : true;
@@ -2803,37 +2770,37 @@ function isWidgetSelected(selection) {
2803
2770
  };
2804
2771
  }
2805
2772
  /**
2806
- * Obtains the resize host.
2807
- *
2808
- * Resize host is an object that receives dimensions which are the result of resizing.
2809
- */ _getResizeHost() {
2773
+ * Obtains the resize host.
2774
+ *
2775
+ * Resize host is an object that receives dimensions which are the result of resizing.
2776
+ */ _getResizeHost() {
2810
2777
  const widgetWrapper = this._domResizerWrapper.parentElement;
2811
2778
  return this._options.getResizeHost(widgetWrapper);
2812
2779
  }
2813
2780
  /**
2814
- * Obtains the handle host.
2815
- *
2816
- * Handle host is an object that the handles are aligned to.
2817
- *
2818
- * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
2819
- * contains an image and a caption. Only the image should be surrounded with handles.
2820
- */ _getHandleHost() {
2781
+ * Obtains the handle host.
2782
+ *
2783
+ * Handle host is an object that the handles are aligned to.
2784
+ *
2785
+ * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
2786
+ * contains an image and a caption. Only the image should be surrounded with handles.
2787
+ */ _getHandleHost() {
2821
2788
  const widgetWrapper = this._domResizerWrapper.parentElement;
2822
2789
  return this._options.getHandleHost(widgetWrapper);
2823
2790
  }
2824
2791
  /**
2825
- * DOM container of the entire resize UI.
2826
- *
2827
- * Note that this property will have a value only after the element bound with the resizer is rendered
2828
- * (otherwise `null`).
2829
- */ get _domResizerWrapper() {
2792
+ * DOM container of the entire resize UI.
2793
+ *
2794
+ * Note that this property will have a value only after the element bound with the resizer is rendered
2795
+ * (otherwise `null`).
2796
+ */ get _domResizerWrapper() {
2830
2797
  return this._options.editor.editing.view.domConverter.mapViewToDom(this._viewResizerWrapper);
2831
2798
  }
2832
2799
  /**
2833
- * Renders the resize handles in the DOM.
2834
- *
2835
- * @param domElement The resizer wrapper.
2836
- */ _appendHandles(domElement) {
2800
+ * Renders the resize handles in the DOM.
2801
+ *
2802
+ * @param domElement The resizer wrapper.
2803
+ */ _appendHandles(domElement) {
2837
2804
  const resizerPositions = [
2838
2805
  'top-left',
2839
2806
  'top-right',
@@ -2850,8 +2817,8 @@ function isWidgetSelected(selection) {
2850
2817
  }
2851
2818
  }
2852
2819
  /**
2853
- * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
2854
- */ _appendSizeUI(domElement) {
2820
+ * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
2821
+ */ _appendSizeUI(domElement) {
2855
2822
  this._sizeView = new SizeView();
2856
2823
  // Make sure icon#element is rendered before passing to appendChild().
2857
2824
  this._sizeView.render();
@@ -2879,24 +2846,25 @@ function existsInDom(element) {
2879
2846
  *
2880
2847
  * Use the {@link module:widget/widgetresize~WidgetResize#attachTo} method to create a resizer for the specified widget.
2881
2848
  */ class WidgetResize extends Plugin {
2849
+ constructor(){
2850
+ super(...arguments);
2851
+ /**
2852
+ * A map of resizers created using this plugin instance.
2853
+ */ this._resizers = new Map();
2854
+ }
2882
2855
  /**
2883
- * A map of resizers created using this plugin instance.
2884
- */ _resizers = new Map();
2885
- _observer;
2886
- _redrawSelectedResizerThrottled;
2887
- /**
2888
- * @inheritDoc
2889
- */ static get pluginName() {
2856
+ * @inheritDoc
2857
+ */ static get pluginName() {
2890
2858
  return 'WidgetResize';
2891
2859
  }
2892
2860
  /**
2893
- * @inheritDoc
2894
- */ static get isOfficialPlugin() {
2861
+ * @inheritDoc
2862
+ */ static get isOfficialPlugin() {
2895
2863
  return true;
2896
2864
  }
2897
2865
  /**
2898
- * @inheritDoc
2899
- */ init() {
2866
+ * @inheritDoc
2867
+ */ init() {
2900
2868
  const editing = this.editor.editing;
2901
2869
  const domDocument = global.window.document;
2902
2870
  this.set('selectedResizer', null);
@@ -2938,15 +2906,15 @@ function existsInDom(element) {
2938
2906
  });
2939
2907
  }
2940
2908
  /**
2941
- * Redraws the selected resizer if there is any selected resizer and if it is visible.
2942
- */ redrawSelectedResizer() {
2909
+ * Redraws the selected resizer if there is any selected resizer and if it is visible.
2910
+ */ redrawSelectedResizer() {
2943
2911
  if (this.selectedResizer && this.selectedResizer.isVisible) {
2944
2912
  this.selectedResizer.redraw();
2945
2913
  }
2946
2914
  }
2947
2915
  /**
2948
- * @inheritDoc
2949
- */ destroy() {
2916
+ * @inheritDoc
2917
+ */ destroy() {
2950
2918
  super.destroy();
2951
2919
  this._observer.stopListening();
2952
2920
  for (const resizer of this._resizers.values()){
@@ -2955,23 +2923,23 @@ function existsInDom(element) {
2955
2923
  this._redrawSelectedResizerThrottled.cancel();
2956
2924
  }
2957
2925
  /**
2958
- * Marks resizer as selected.
2959
- */ select(resizer) {
2926
+ * Marks resizer as selected.
2927
+ */ select(resizer) {
2960
2928
  this.deselect();
2961
2929
  this.selectedResizer = resizer;
2962
2930
  this.selectedResizer.isSelected = true;
2963
2931
  }
2964
2932
  /**
2965
- * Deselects currently set resizer.
2966
- */ deselect() {
2933
+ * Deselects currently set resizer.
2934
+ */ deselect() {
2967
2935
  if (this.selectedResizer) {
2968
2936
  this.selectedResizer.isSelected = false;
2969
2937
  }
2970
2938
  this.selectedResizer = null;
2971
2939
  }
2972
2940
  /**
2973
- * @param options Resizer options.
2974
- */ attachTo(options) {
2941
+ * @param options Resizer options.
2942
+ */ attachTo(options) {
2975
2943
  const resizer = new Resizer(options);
2976
2944
  const plugins = this.editor.plugins;
2977
2945
  resizer.attach();
@@ -3005,15 +2973,15 @@ function existsInDom(element) {
3005
2973
  return resizer;
3006
2974
  }
3007
2975
  /**
3008
- * Returns a resizer created for a given view element (widget element).
3009
- *
3010
- * @param viewElement View element associated with the resizer.
3011
- */ getResizerByViewElement(viewElement) {
2976
+ * Returns a resizer created for a given view element (widget element).
2977
+ *
2978
+ * @param viewElement View element associated with the resizer.
2979
+ */ getResizerByViewElement(viewElement) {
3012
2980
  return this._resizers.get(viewElement);
3013
2981
  }
3014
2982
  /**
3015
- * Returns a resizer that contains a given resize handle.
3016
- */ _getResizerByHandle(domResizeHandle) {
2983
+ * Returns a resizer that contains a given resize handle.
2984
+ */ _getResizerByHandle(domResizeHandle) {
3017
2985
  for (const resizer of this._resizers.values()){
3018
2986
  if (resizer.containsHandle(domResizeHandle)) {
3019
2987
  return resizer;
@@ -3021,8 +2989,8 @@ function existsInDom(element) {
3021
2989
  }
3022
2990
  }
3023
2991
  /**
3024
- * @param domEventData Native DOM event.
3025
- */ _mouseDownListener(event, domEventData) {
2992
+ * @param domEventData Native DOM event.
2993
+ */ _mouseDownListener(event, domEventData) {
3026
2994
  const resizeHandle = domEventData.domTarget;
3027
2995
  if (!Resizer.isResizeHandle(resizeHandle)) {
3028
2996
  return;
@@ -3036,8 +3004,8 @@ function existsInDom(element) {
3036
3004
  }
3037
3005
  }
3038
3006
  /**
3039
- * @param domEventData Native DOM event.
3040
- */ _mouseMoveListener(event, domEventData) {
3007
+ * @param domEventData Native DOM event.
3008
+ */ _mouseMoveListener(event, domEventData) {
3041
3009
  if (this._activeResizer) {
3042
3010
  this._activeResizer.updateSize(domEventData);
3043
3011
  }