@ckeditor/ckeditor5-mention 35.3.2 → 36.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,78 +1,51 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module mention/ui/domwrapperview
8
7
  */
9
-
10
8
  import { View } from 'ckeditor5/src/ui';
11
-
12
9
  /**
13
10
  * This class wraps DOM element as a CKEditor5 UI View.
14
11
  *
15
12
  * It allows to render any DOM element and use it in mentions list.
16
- *
17
- * @extends {module:ui/view~View}
18
13
  */
19
14
  export default class DomWrapperView extends View {
20
- /**
21
- * Creates an instance of {@link module:mention/ui/domwrapperview~DomWrapperView} class.
22
- *
23
- * Also see {@link #render}.
24
- *
25
- * @param {module:utils/locale~Locale} [locale] The localization services instance.
26
- * @param {Element} domElement
27
- */
28
- constructor( locale, domElement ) {
29
- super( locale );
30
-
31
- // Disable template rendering on this view.
32
- this.template = false;
33
-
34
- /**
35
- * The DOM element for which wrapper was created.
36
- *
37
- * @type {Element}
38
- */
39
- this.domElement = domElement;
40
-
41
- // Render dom wrapper as a button.
42
- this.domElement.classList.add( 'ck-button' );
43
-
44
- /**
45
- * Controls whether the dom wrapper view is "on". This is in line with {@link module:ui/button/button~Button#isOn} property.
46
- *
47
- * @observable
48
- * @default true
49
- * @member {Boolean} #isOn
50
- */
51
- this.set( 'isOn', false );
52
-
53
- // Handle isOn state as in buttons.
54
- this.on( 'change:isOn', ( evt, name, isOn ) => {
55
- if ( isOn ) {
56
- this.domElement.classList.add( 'ck-on' );
57
- this.domElement.classList.remove( 'ck-off' );
58
- } else {
59
- this.domElement.classList.add( 'ck-off' );
60
- this.domElement.classList.remove( 'ck-on' );
61
- }
62
- } );
63
-
64
- // Pass click event as execute event.
65
- this.listenTo( this.domElement, 'click', () => {
66
- this.fire( 'execute' );
67
- } );
68
- }
69
-
70
- /**
71
- * @inheritDoc
72
- */
73
- render() {
74
- super.render();
75
-
76
- this.element = this.domElement;
77
- }
15
+ /**
16
+ * Creates an instance of {@link module:mention/ui/domwrapperview~DomWrapperView} class.
17
+ *
18
+ * Also see {@link #render}.
19
+ */
20
+ constructor(locale, domElement) {
21
+ super(locale);
22
+ // Disable template rendering on this view.
23
+ this.template = false;
24
+ this.domElement = domElement;
25
+ // Render dom wrapper as a button.
26
+ this.domElement.classList.add('ck-button');
27
+ this.set('isOn', false);
28
+ // Handle isOn state as in buttons.
29
+ this.on('change:isOn', (evt, name, isOn) => {
30
+ if (isOn) {
31
+ this.domElement.classList.add('ck-on');
32
+ this.domElement.classList.remove('ck-off');
33
+ }
34
+ else {
35
+ this.domElement.classList.add('ck-off');
36
+ this.domElement.classList.remove('ck-on');
37
+ }
38
+ });
39
+ // Pass click event as execute event.
40
+ this.listenTo(this.domElement, 'click', () => {
41
+ this.fire('execute');
42
+ });
43
+ }
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ render() {
48
+ super.render();
49
+ this.element = this.domElement;
50
+ }
78
51
  }
@@ -1,24 +1,18 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module mention/ui/mentionlistitemview
8
7
  */
9
-
10
8
  import { ListItemView } from 'ckeditor5/src/ui';
11
-
12
9
  export default class MentionListItemView extends ListItemView {
13
- highlight() {
14
- const child = this.children.first;
15
-
16
- child.isOn = true;
17
- }
18
-
19
- removeHighlight() {
20
- const child = this.children.first;
21
-
22
- child.isOn = false;
23
- }
10
+ highlight() {
11
+ const child = this.children.first;
12
+ child.isOn = true;
13
+ }
14
+ removeHighlight() {
15
+ const child = this.children.first;
16
+ child.isOn = false;
17
+ }
24
18
  }
@@ -1,123 +1,104 @@
1
1
  /**
2
- * @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module mention/ui/mentionsview
8
7
  */
9
-
10
8
  import { ListView } from 'ckeditor5/src/ui';
11
9
  import { Rect } from 'ckeditor5/src/utils';
12
-
13
10
  import '../../theme/mentionui.css';
14
-
15
11
  /**
16
12
  * The mention ui view.
17
- *
18
- * @extends module:ui/list/listview~ListView
19
13
  */
20
14
  export default class MentionsView extends ListView {
21
- /**
22
- * @inheritDoc
23
- */
24
- constructor( locale ) {
25
- super( locale );
26
-
27
- this.extendTemplate( {
28
- attributes: {
29
- class: [
30
- 'ck-mentions'
31
- ],
32
-
33
- tabindex: '-1'
34
- }
35
- } );
36
- }
37
-
38
- /**
39
- * {@link #select Selects} the first item.
40
- */
41
- selectFirst() {
42
- this.select( 0 );
43
- }
44
-
45
- /**
46
- * Selects next item to the currently {@link #select selected}.
47
- *
48
- * If the last item is already selected, it will select the first item.
49
- */
50
- selectNext() {
51
- const item = this.selected;
52
- const index = this.items.getIndex( item );
53
-
54
- this.select( index + 1 );
55
- }
56
-
57
- /**
58
- * Selects previous item to the currently {@link #select selected}.
59
- *
60
- * If the first item is already selected, it will select the last item.
61
- */
62
- selectPrevious() {
63
- const item = this.selected;
64
- const index = this.items.getIndex( item );
65
-
66
- this.select( index - 1 );
67
- }
68
-
69
- /**
70
- * Marks item at a given index as selected.
71
- *
72
- * Handles selection cycling when passed index is out of bounds:
73
- * - if the index is lower than 0, it will select the last item,
74
- * - if the index is higher than the last item index, it will select the first item.
75
- *
76
- * @param {Number} index Index of an item to be marked as selected.
77
- */
78
- select( index ) {
79
- let indexToGet = 0;
80
-
81
- if ( index > 0 && index < this.items.length ) {
82
- indexToGet = index;
83
- } else if ( index < 0 ) {
84
- indexToGet = this.items.length - 1;
85
- }
86
-
87
- const item = this.items.get( indexToGet );
88
-
89
- // Return early if item is already selected.
90
- if ( this.selected === item ) {
91
- return;
92
- }
93
-
94
- // Remove highlight of previously selected item.
95
- if ( this.selected ) {
96
- this.selected.removeHighlight();
97
- }
98
-
99
- item.highlight();
100
- this.selected = item;
101
-
102
- // Scroll the mentions view to the selected element.
103
- if ( !this._isItemVisibleInScrolledArea( item ) ) {
104
- this.element.scrollTop = item.element.offsetTop;
105
- }
106
- }
107
-
108
- /**
109
- * Triggers the `execute` event on the {@link #select selected} item.
110
- */
111
- executeSelected() {
112
- this.selected.fire( 'execute' );
113
- }
114
-
115
- // Checks if an item is visible in the scrollable area.
116
- //
117
- // The item is considered visible when:
118
- // - its top boundary is inside the scrollable rect
119
- // - its bottom boundary is inside the scrollable rect (the whole item must be visible)
120
- _isItemVisibleInScrolledArea( item ) {
121
- return new Rect( this.element ).contains( new Rect( item.element ) );
122
- }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ constructor(locale) {
19
+ super(locale);
20
+ this.extendTemplate({
21
+ attributes: {
22
+ class: [
23
+ 'ck-mentions'
24
+ ],
25
+ tabindex: '-1'
26
+ }
27
+ });
28
+ }
29
+ /**
30
+ * {@link #select Selects} the first item.
31
+ */
32
+ selectFirst() {
33
+ this.select(0);
34
+ }
35
+ /**
36
+ * Selects next item to the currently {@link #select selected}.
37
+ *
38
+ * If the last item is already selected, it will select the first item.
39
+ */
40
+ selectNext() {
41
+ const item = this.selected;
42
+ const index = this.items.getIndex(item);
43
+ this.select(index + 1);
44
+ }
45
+ /**
46
+ * Selects previous item to the currently {@link #select selected}.
47
+ *
48
+ * If the first item is already selected, it will select the last item.
49
+ */
50
+ selectPrevious() {
51
+ const item = this.selected;
52
+ const index = this.items.getIndex(item);
53
+ this.select(index - 1);
54
+ }
55
+ /**
56
+ * Marks item at a given index as selected.
57
+ *
58
+ * Handles selection cycling when passed index is out of bounds:
59
+ * - if the index is lower than 0, it will select the last item,
60
+ * - if the index is higher than the last item index, it will select the first item.
61
+ *
62
+ * @param index Index of an item to be marked as selected.
63
+ */
64
+ select(index) {
65
+ let indexToGet = 0;
66
+ if (index > 0 && index < this.items.length) {
67
+ indexToGet = index;
68
+ }
69
+ else if (index < 0) {
70
+ indexToGet = this.items.length - 1;
71
+ }
72
+ const item = this.items.get(indexToGet);
73
+ // Return early if item is already selected.
74
+ if (this.selected === item) {
75
+ return;
76
+ }
77
+ // Remove highlight of previously selected item.
78
+ if (this.selected) {
79
+ this.selected.removeHighlight();
80
+ }
81
+ item.highlight();
82
+ this.selected = item;
83
+ // Scroll the mentions view to the selected element.
84
+ if (!this._isItemVisibleInScrolledArea(item)) {
85
+ this.element.scrollTop = item.element.offsetTop;
86
+ }
87
+ }
88
+ /**
89
+ * Triggers the `execute` event on the {@link #select selected} item.
90
+ */
91
+ executeSelected() {
92
+ this.selected.fire('execute');
93
+ }
94
+ /**
95
+ * Checks if an item is visible in the scrollable area.
96
+ *
97
+ * The item is considered visible when:
98
+ * - its top boundary is inside the scrollable rect
99
+ * - its bottom boundary is inside the scrollable rect (the whole item must be visible)
100
+ */
101
+ _isItemVisibleInScrolledArea(item) {
102
+ return new Rect(this.element).contains(new Rect(item.element));
103
+ }
123
104
  }
package/theme/mention.css CHANGED
@@ -1,4 +1,4 @@
1
1
  /*
2
- * Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
2
+ * Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5