@ckeditor/ckeditor5-mention 30.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +17 -0
- package/README.md +20 -0
- package/build/mention.js +5 -0
- package/ckeditor5-metadata.json +18 -0
- package/package.json +63 -0
- package/src/index.js +12 -0
- package/src/mention.js +260 -0
- package/src/mentioncommand.js +150 -0
- package/src/mentionediting.js +291 -0
- package/src/mentionui.js +743 -0
- package/src/ui/domwrapperview.js +78 -0
- package/src/ui/mentionlistitemview.js +24 -0
- package/src/ui/mentionsview.js +123 -0
- package/theme/mention.css +4 -0
- package/theme/mentionui.css +27 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module mention/ui/domwrapperview
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { View } from 'ckeditor5/src/ui';
|
11
|
+
|
12
|
+
/**
|
13
|
+
* This class wraps DOM element as a CKEditor5 UI View.
|
14
|
+
*
|
15
|
+
* It allows to render any DOM element and use it in mentions list.
|
16
|
+
*
|
17
|
+
* @extends {module:ui/view~View}
|
18
|
+
*/
|
19
|
+
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
|
+
}
|
78
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module mention/ui/mentionlistitemview
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { ListItemView } from 'ckeditor5/src/ui';
|
11
|
+
|
12
|
+
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
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,123 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
/**
|
7
|
+
* @module mention/ui/mentionsview
|
8
|
+
*/
|
9
|
+
|
10
|
+
import { ListView } from 'ckeditor5/src/ui';
|
11
|
+
import { Rect } from 'ckeditor5/src/utils';
|
12
|
+
|
13
|
+
import '../../theme/mentionui.css';
|
14
|
+
|
15
|
+
/**
|
16
|
+
* The mention ui view.
|
17
|
+
*
|
18
|
+
* @extends module:ui/list/listview~ListView
|
19
|
+
*/
|
20
|
+
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
|
+
}
|
123
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
:root {
|
7
|
+
--ck-mention-list-max-height: 300px;
|
8
|
+
}
|
9
|
+
|
10
|
+
.ck.ck-mentions {
|
11
|
+
max-height: var(--ck-mention-list-max-height);
|
12
|
+
|
13
|
+
overflow-y: auto;
|
14
|
+
|
15
|
+
/* Prevent unnecessary horizontal scrollbar in Safari
|
16
|
+
https://github.com/ckeditor/ckeditor5-mention/issues/41 */
|
17
|
+
overflow-x: hidden;
|
18
|
+
|
19
|
+
overscroll-behavior: contain;
|
20
|
+
|
21
|
+
/* Prevent unnecessary vertical scrollbar in Safari
|
22
|
+
https://github.com/ckeditor/ckeditor5-mention/issues/41 */
|
23
|
+
& > .ck-list__item {
|
24
|
+
overflow: hidden;
|
25
|
+
flex-shrink: 0;
|
26
|
+
}
|
27
|
+
}
|