@ckeditor/ckeditor5-mention 35.4.0 → 36.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +1 -1
- package/build/mention.js +2 -2
- package/package.json +26 -22
- package/src/index.js +1 -3
- package/src/mention.js +30 -280
- package/src/mentioncommand.js +112 -129
- package/src/mentionediting.js +196 -256
- package/src/mentionui.js +581 -814
- package/src/ui/domwrapperview.js +37 -64
- package/src/ui/mentionlistitemview.js +9 -15
- package/src/ui/mentionsview.js +90 -109
- package/theme/mention.css +1 -1
- package/theme/mentionui.css +1 -1
package/src/ui/domwrapperview.js
CHANGED
@@ -1,78 +1,51 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
}
|
package/src/ui/mentionsview.js
CHANGED
@@ -1,123 +1,104 @@
|
|
1
1
|
/**
|
2
|
-
* @license Copyright (c) 2003-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
package/theme/mentionui.css
CHANGED