@ckeditor/ckeditor5-mention 0.0.0-nightly-20240603.0 → 0.0.0-nightly-20240604.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.
- package/README.md +0 -6
- package/dist/index.js +189 -262
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,12 +15,6 @@ Check out the demo in the [mentions (autocomplete) feature guide](https://ckedit
|
|
|
15
15
|
|
|
16
16
|
See the [`@ckeditor/ckeditor5-mention` package](https://ckeditor.com/docs/ckeditor5/latest/api/mention.html) page in [CKEditor 5 documentation](https://ckeditor.com/docs/ckeditor5/latest/).
|
|
17
17
|
|
|
18
|
-
## Installation
|
|
19
|
-
|
|
20
|
-
```bash
|
|
21
|
-
npm install ckeditor5
|
|
22
|
-
```
|
|
23
|
-
|
|
24
18
|
## License
|
|
25
19
|
|
|
26
20
|
Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html). For full details about the license, please check the `LICENSE.md` file or [https://ckeditor.com/legal/ckeditor-oss-license](https://ckeditor.com/legal/ckeditor-oss-license).
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
|
|
6
|
-
import { CKEditorError, toMap, uid, Rect, keyCodes,
|
|
6
|
+
import { CKEditorError, toMap, uid, Rect, keyCodes, logWarning, Collection, env } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
|
7
7
|
import { ListView, View, ListItemView, ContextualBalloon, clickOutsideHandler, ButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
8
8
|
import { TextWatcher } from '@ckeditor/ckeditor5-typing/dist/index.js';
|
|
9
9
|
import { debounce } from 'lodash-es';
|
|
@@ -13,69 +13,27 @@ const BRACKET_PAIRS = {
|
|
|
13
13
|
'[': ']',
|
|
14
14
|
'{': '}'
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
* The mention command.
|
|
18
|
-
*
|
|
19
|
-
* The command is registered by {@link module:mention/mentionediting~MentionEditing} as `'mention'`.
|
|
20
|
-
*
|
|
21
|
-
* To insert a mention into a range, execute the command and specify a mention object with a range to replace:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* const focus = editor.model.document.selection.focus;
|
|
25
|
-
*
|
|
26
|
-
* // It will replace one character before the selection focus with the '#1234' text
|
|
27
|
-
* // with the mention attribute filled with passed attributes.
|
|
28
|
-
* editor.execute( 'mention', {
|
|
29
|
-
* marker: '#',
|
|
30
|
-
* mention: {
|
|
31
|
-
* id: '#1234',
|
|
32
|
-
* name: 'Foo',
|
|
33
|
-
* title: 'Big Foo'
|
|
34
|
-
* },
|
|
35
|
-
* range: editor.model.createRange( focus.getShiftedBy( -1 ), focus )
|
|
36
|
-
* } );
|
|
37
|
-
*
|
|
38
|
-
* // It will replace one character before the selection focus with the 'The "Big Foo"' text
|
|
39
|
-
* // with the mention attribute filled with passed attributes.
|
|
40
|
-
* editor.execute( 'mention', {
|
|
41
|
-
* marker: '#',
|
|
42
|
-
* mention: {
|
|
43
|
-
* id: '#1234',
|
|
44
|
-
* name: 'Foo',
|
|
45
|
-
* title: 'Big Foo'
|
|
46
|
-
* },
|
|
47
|
-
* text: 'The "Big Foo"',
|
|
48
|
-
* range: editor.model.createRange( focus.getShiftedBy( -1 ), focus )
|
|
49
|
-
* } );
|
|
50
|
-
* ```
|
|
51
|
-
*/ class MentionCommand extends Command {
|
|
16
|
+
class MentionCommand extends Command {
|
|
52
17
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
super(editor);
|
|
56
|
-
// Since this command may pass range in execution parameters, it should be checked directly in execute block.
|
|
57
|
-
this._isEnabledBasedOnSelection = false;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* @inheritDoc
|
|
61
|
-
*/ refresh() {
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/ refresh() {
|
|
62
20
|
const model = this.editor.model;
|
|
63
21
|
const doc = model.document;
|
|
64
22
|
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, 'mention');
|
|
65
23
|
}
|
|
66
24
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
25
|
+
* Executes the command.
|
|
26
|
+
*
|
|
27
|
+
* @param options Options for the executed command.
|
|
28
|
+
* @param options.mention The mention object to insert. When a string is passed, it will be used to create a plain
|
|
29
|
+
* object with the name attribute that equals the passed string.
|
|
30
|
+
* @param options.marker The marker character (e.g. `'@'`).
|
|
31
|
+
* @param options.text The text of the inserted mention. Defaults to the full mention string composed from `marker` and
|
|
32
|
+
* `mention` string or `mention.id` if an object is passed.
|
|
33
|
+
* @param options.range The range to replace.
|
|
34
|
+
* Note that the replaced range might be shorter than the inserted text with the mention attribute.
|
|
35
|
+
* @fires execute
|
|
36
|
+
*/ execute(options) {
|
|
79
37
|
const model = this.editor.model;
|
|
80
38
|
const document = model.document;
|
|
81
39
|
const selection = document.selection;
|
|
@@ -95,47 +53,47 @@ const BRACKET_PAIRS = {
|
|
|
95
53
|
}, mentionData);
|
|
96
54
|
if (options.marker.length != 1) {
|
|
97
55
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
56
|
+
* The marker must be a single character.
|
|
57
|
+
*
|
|
58
|
+
* Correct markers: `'@'`, `'#'`.
|
|
59
|
+
*
|
|
60
|
+
* Incorrect markers: `'@@'`, `'[@'`.
|
|
61
|
+
*
|
|
62
|
+
* See {@link module:mention/mentionconfig~MentionConfig}.
|
|
63
|
+
*
|
|
64
|
+
* @error mentioncommand-incorrect-marker
|
|
65
|
+
*/ throw new CKEditorError('mentioncommand-incorrect-marker', this);
|
|
108
66
|
}
|
|
109
67
|
if (mentionID.charAt(0) != options.marker) {
|
|
110
68
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
69
|
+
* The feed item ID must start with the marker character.
|
|
70
|
+
*
|
|
71
|
+
* Correct mention feed setting:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* mentions: [
|
|
75
|
+
* {
|
|
76
|
+
* marker: '@',
|
|
77
|
+
* feed: [ '@Ann', '@Barney', ... ]
|
|
78
|
+
* }
|
|
79
|
+
* ]
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* Incorrect mention feed setting:
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* mentions: [
|
|
86
|
+
* {
|
|
87
|
+
* marker: '@',
|
|
88
|
+
* feed: [ 'Ann', 'Barney', ... ]
|
|
89
|
+
* }
|
|
90
|
+
* ]
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* See {@link module:mention/mentionconfig~MentionConfig}.
|
|
94
|
+
*
|
|
95
|
+
* @error mentioncommand-incorrect-id
|
|
96
|
+
*/ throw new CKEditorError('mentioncommand-incorrect-id', this);
|
|
139
97
|
}
|
|
140
98
|
model.change((writer)=>{
|
|
141
99
|
const currentAttributes = toMap(selection.getAttributes());
|
|
@@ -162,23 +120,24 @@ const BRACKET_PAIRS = {
|
|
|
162
120
|
}
|
|
163
121
|
});
|
|
164
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* @inheritDoc
|
|
125
|
+
*/ constructor(editor){
|
|
126
|
+
super(editor);
|
|
127
|
+
// Since this command may pass range in execution parameters, it should be checked directly in execute block.
|
|
128
|
+
this._isEnabledBasedOnSelection = false;
|
|
129
|
+
}
|
|
165
130
|
}
|
|
166
131
|
|
|
167
|
-
|
|
168
|
-
* The mention editing feature.
|
|
169
|
-
*
|
|
170
|
-
* It introduces the {@link module:mention/mentioncommand~MentionCommand command} and the `mention`
|
|
171
|
-
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
|
|
172
|
-
* as a `<span class="mention" data-mention="@mention">`.
|
|
173
|
-
*/ class MentionEditing extends Plugin {
|
|
132
|
+
class MentionEditing extends Plugin {
|
|
174
133
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
134
|
+
* @inheritDoc
|
|
135
|
+
*/ static get pluginName() {
|
|
177
136
|
return 'MentionEditing';
|
|
178
137
|
}
|
|
179
138
|
/**
|
|
180
|
-
|
|
181
|
-
|
|
139
|
+
* @inheritDoc
|
|
140
|
+
*/ init() {
|
|
182
141
|
const editor = this.editor;
|
|
183
142
|
const model = editor.model;
|
|
184
143
|
const doc = model.document;
|
|
@@ -382,56 +341,39 @@ const BRACKET_PAIRS = {
|
|
|
382
341
|
return false;
|
|
383
342
|
}
|
|
384
343
|
|
|
385
|
-
|
|
386
|
-
* The mention ui view.
|
|
387
|
-
*/ class MentionsView extends ListView {
|
|
388
|
-
selected;
|
|
389
|
-
position;
|
|
344
|
+
class MentionsView extends ListView {
|
|
390
345
|
/**
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
super(locale);
|
|
394
|
-
this.extendTemplate({
|
|
395
|
-
attributes: {
|
|
396
|
-
class: [
|
|
397
|
-
'ck-mentions'
|
|
398
|
-
],
|
|
399
|
-
tabindex: '-1'
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* {@link #select Selects} the first item.
|
|
405
|
-
*/ selectFirst() {
|
|
346
|
+
* {@link #select Selects} the first item.
|
|
347
|
+
*/ selectFirst() {
|
|
406
348
|
this.select(0);
|
|
407
349
|
}
|
|
408
350
|
/**
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
351
|
+
* Selects next item to the currently {@link #select selected}.
|
|
352
|
+
*
|
|
353
|
+
* If the last item is already selected, it will select the first item.
|
|
354
|
+
*/ selectNext() {
|
|
413
355
|
const item = this.selected;
|
|
414
356
|
const index = this.items.getIndex(item);
|
|
415
357
|
this.select(index + 1);
|
|
416
358
|
}
|
|
417
359
|
/**
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
360
|
+
* Selects previous item to the currently {@link #select selected}.
|
|
361
|
+
*
|
|
362
|
+
* If the first item is already selected, it will select the last item.
|
|
363
|
+
*/ selectPrevious() {
|
|
422
364
|
const item = this.selected;
|
|
423
365
|
const index = this.items.getIndex(item);
|
|
424
366
|
this.select(index - 1);
|
|
425
367
|
}
|
|
426
368
|
/**
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
369
|
+
* Marks item at a given index as selected.
|
|
370
|
+
*
|
|
371
|
+
* Handles selection cycling when passed index is out of bounds:
|
|
372
|
+
* - if the index is lower than 0, it will select the last item,
|
|
373
|
+
* - if the index is higher than the last item index, it will select the first item.
|
|
374
|
+
*
|
|
375
|
+
* @param index Index of an item to be marked as selected.
|
|
376
|
+
*/ select(index) {
|
|
435
377
|
let indexToGet = 0;
|
|
436
378
|
if (index > 0 && index < this.items.length) {
|
|
437
379
|
indexToGet = index;
|
|
@@ -455,34 +397,51 @@ const BRACKET_PAIRS = {
|
|
|
455
397
|
}
|
|
456
398
|
}
|
|
457
399
|
/**
|
|
458
|
-
|
|
459
|
-
|
|
400
|
+
* Triggers the `execute` event on the {@link #select selected} item.
|
|
401
|
+
*/ executeSelected() {
|
|
460
402
|
this.selected.fire('execute');
|
|
461
403
|
}
|
|
462
404
|
/**
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
405
|
+
* Checks if an item is visible in the scrollable area.
|
|
406
|
+
*
|
|
407
|
+
* The item is considered visible when:
|
|
408
|
+
* - its top boundary is inside the scrollable rect
|
|
409
|
+
* - its bottom boundary is inside the scrollable rect (the whole item must be visible)
|
|
410
|
+
*/ _isItemVisibleInScrolledArea(item) {
|
|
469
411
|
return new Rect(this.element).contains(new Rect(item.element));
|
|
470
412
|
}
|
|
413
|
+
/**
|
|
414
|
+
* @inheritDoc
|
|
415
|
+
*/ constructor(locale){
|
|
416
|
+
super(locale);
|
|
417
|
+
this.extendTemplate({
|
|
418
|
+
attributes: {
|
|
419
|
+
class: [
|
|
420
|
+
'ck-mentions'
|
|
421
|
+
],
|
|
422
|
+
tabindex: '-1'
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}
|
|
471
426
|
}
|
|
472
427
|
|
|
473
|
-
|
|
474
|
-
* This class wraps DOM element as a CKEditor5 UI View.
|
|
475
|
-
*
|
|
476
|
-
* It allows to render any DOM element and use it in mentions list.
|
|
477
|
-
*/ class DomWrapperView extends View {
|
|
428
|
+
class DomWrapperView extends View {
|
|
478
429
|
/**
|
|
479
|
-
|
|
480
|
-
|
|
430
|
+
* @inheritDoc
|
|
431
|
+
*/ render() {
|
|
432
|
+
super.render();
|
|
433
|
+
this.element = this.domElement;
|
|
434
|
+
}
|
|
481
435
|
/**
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
436
|
+
* Focuses the DOM element.
|
|
437
|
+
*/ focus() {
|
|
438
|
+
this.domElement.focus();
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Creates an instance of {@link module:mention/ui/domwrapperview~DomWrapperView} class.
|
|
442
|
+
*
|
|
443
|
+
* Also see {@link #render}.
|
|
444
|
+
*/ constructor(locale, domElement){
|
|
486
445
|
super(locale);
|
|
487
446
|
// Disable template rendering on this view.
|
|
488
447
|
this.template = undefined;
|
|
@@ -505,22 +464,9 @@ const BRACKET_PAIRS = {
|
|
|
505
464
|
this.fire('execute');
|
|
506
465
|
});
|
|
507
466
|
}
|
|
508
|
-
/**
|
|
509
|
-
* @inheritDoc
|
|
510
|
-
*/ render() {
|
|
511
|
-
super.render();
|
|
512
|
-
this.element = this.domElement;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Focuses the DOM element.
|
|
516
|
-
*/ focus() {
|
|
517
|
-
this.domElement.focus();
|
|
518
|
-
}
|
|
519
467
|
}
|
|
520
468
|
|
|
521
469
|
class MentionListItemView extends ListItemView {
|
|
522
|
-
item;
|
|
523
|
-
marker;
|
|
524
470
|
highlight() {
|
|
525
471
|
const child = this.children.first;
|
|
526
472
|
child.isOn = true;
|
|
@@ -543,49 +489,22 @@ const defaultCommitKeyCodes = [
|
|
|
543
489
|
keyCodes.enter,
|
|
544
490
|
keyCodes.tab
|
|
545
491
|
];
|
|
546
|
-
|
|
547
|
-
* The mention UI feature.
|
|
548
|
-
*/ class MentionUI extends Plugin {
|
|
549
|
-
/**
|
|
550
|
-
* The mention view.
|
|
551
|
-
*/ _mentionsView;
|
|
552
|
-
/**
|
|
553
|
-
* Stores mention feeds configurations.
|
|
554
|
-
*/ _mentionsConfigurations;
|
|
555
|
-
/**
|
|
556
|
-
* The contextual balloon plugin instance.
|
|
557
|
-
*/ _balloon;
|
|
558
|
-
_items = new Collection();
|
|
559
|
-
_lastRequested;
|
|
560
|
-
/**
|
|
561
|
-
* Debounced feed requester. It uses `lodash#debounce` method to delay function call.
|
|
562
|
-
*/ _requestFeedDebounced;
|
|
492
|
+
class MentionUI extends Plugin {
|
|
563
493
|
/**
|
|
564
|
-
|
|
565
|
-
|
|
494
|
+
* @inheritDoc
|
|
495
|
+
*/ static get pluginName() {
|
|
566
496
|
return 'MentionUI';
|
|
567
497
|
}
|
|
568
498
|
/**
|
|
569
|
-
|
|
570
|
-
|
|
499
|
+
* @inheritDoc
|
|
500
|
+
*/ static get requires() {
|
|
571
501
|
return [
|
|
572
502
|
ContextualBalloon
|
|
573
503
|
];
|
|
574
504
|
}
|
|
575
505
|
/**
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
super(editor);
|
|
579
|
-
this._mentionsView = this._createMentionView();
|
|
580
|
-
this._mentionsConfigurations = new Map();
|
|
581
|
-
this._requestFeedDebounced = debounce(this._requestFeed, 100);
|
|
582
|
-
editor.config.define('mention', {
|
|
583
|
-
feeds: []
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* @inheritDoc
|
|
588
|
-
*/ init() {
|
|
506
|
+
* @inheritDoc
|
|
507
|
+
*/ init() {
|
|
589
508
|
const editor = this.editor;
|
|
590
509
|
const commitKeys = editor.config.get('mention.commitKeys') || defaultCommitKeyCodes;
|
|
591
510
|
const handledKeyCodes = defaultHandledKeyCodes.concat(commitKeys);
|
|
@@ -625,17 +544,17 @@ const defaultCommitKeyCodes = [
|
|
|
625
544
|
const { feed, marker, dropdownLimit } = mentionDescription;
|
|
626
545
|
if (!isValidMentionMarker(marker)) {
|
|
627
546
|
/**
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
547
|
+
* The marker must be a single character.
|
|
548
|
+
*
|
|
549
|
+
* Correct markers: `'@'`, `'#'`.
|
|
550
|
+
*
|
|
551
|
+
* Incorrect markers: `'$$'`, `'[@'`.
|
|
552
|
+
*
|
|
553
|
+
* See {@link module:mention/mentionconfig~MentionConfig}.
|
|
554
|
+
*
|
|
555
|
+
* @error mentionconfig-incorrect-marker
|
|
556
|
+
* @param marker Configured marker
|
|
557
|
+
*/ throw new CKEditorError('mentionconfig-incorrect-marker', null, {
|
|
639
558
|
marker
|
|
640
559
|
});
|
|
641
560
|
}
|
|
@@ -656,27 +575,27 @@ const defaultCommitKeyCodes = [
|
|
|
656
575
|
this.on('requestFeed:response', (evt, data)=>this._handleFeedResponse(data));
|
|
657
576
|
this.on('requestFeed:error', ()=>this._hideUIAndRemoveMarker());
|
|
658
577
|
/**
|
|
659
|
-
|
|
660
|
-
|
|
578
|
+
* Checks if a given key code is handled by the mention UI.
|
|
579
|
+
*/ function isHandledKey(keyCode) {
|
|
661
580
|
return handledKeyCodes.includes(keyCode);
|
|
662
581
|
}
|
|
663
582
|
}
|
|
664
583
|
/**
|
|
665
|
-
|
|
666
|
-
|
|
584
|
+
* @inheritDoc
|
|
585
|
+
*/ destroy() {
|
|
667
586
|
super.destroy();
|
|
668
587
|
// Destroy created UI components as they are not automatically destroyed (see ckeditor5#1341).
|
|
669
588
|
this._mentionsView.destroy();
|
|
670
589
|
}
|
|
671
590
|
/**
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
591
|
+
* Returns true when {@link #_mentionsView} is in the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon} and it is
|
|
592
|
+
* currently visible.
|
|
593
|
+
*/ get _isUIVisible() {
|
|
675
594
|
return this._balloon.visibleView === this._mentionsView;
|
|
676
595
|
}
|
|
677
596
|
/**
|
|
678
|
-
|
|
679
|
-
|
|
597
|
+
* Creates the {@link #_mentionsView}.
|
|
598
|
+
*/ _createMentionView() {
|
|
680
599
|
const locale = this.editor.locale;
|
|
681
600
|
const mentionsView = new MentionsView(locale);
|
|
682
601
|
mentionsView.items.bindTo(this._items).using((data)=>{
|
|
@@ -723,14 +642,14 @@ const defaultCommitKeyCodes = [
|
|
|
723
642
|
return mentionsView;
|
|
724
643
|
}
|
|
725
644
|
/**
|
|
726
|
-
|
|
727
|
-
|
|
645
|
+
* Returns item renderer for the marker.
|
|
646
|
+
*/ _getItemRenderer(marker) {
|
|
728
647
|
const { itemRenderer } = this._mentionsConfigurations.get(marker);
|
|
729
648
|
return itemRenderer;
|
|
730
649
|
}
|
|
731
650
|
/**
|
|
732
|
-
|
|
733
|
-
|
|
651
|
+
* Requests a feed from a configured callbacks.
|
|
652
|
+
*/ _requestFeed(marker, feedText) {
|
|
734
653
|
// @if CK_DEBUG_MENTION // console.log( '%c[Feed]%c Requesting for', 'color: blue', 'color: black', `"${ feedText }"` );
|
|
735
654
|
// Store the last requested feed - it is used to discard any out-of order requests.
|
|
736
655
|
this._lastRequested = feedText;
|
|
@@ -769,18 +688,18 @@ const defaultCommitKeyCodes = [
|
|
|
769
688
|
error
|
|
770
689
|
});
|
|
771
690
|
/**
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
691
|
+
* The callback used for obtaining mention autocomplete feed thrown and error and the mention UI was hidden or
|
|
692
|
+
* not displayed at all.
|
|
693
|
+
*
|
|
694
|
+
* @error mention-feed-callback-error
|
|
695
|
+
*/ logWarning('mention-feed-callback-error', {
|
|
777
696
|
marker
|
|
778
697
|
});
|
|
779
698
|
});
|
|
780
699
|
}
|
|
781
700
|
/**
|
|
782
|
-
|
|
783
|
-
|
|
701
|
+
* Registers a text watcher for the marker.
|
|
702
|
+
*/ _setupTextWatcher(feeds) {
|
|
784
703
|
const editor = this.editor;
|
|
785
704
|
const feedsWithPattern = feeds.map((feed)=>({
|
|
786
705
|
...feed,
|
|
@@ -837,8 +756,8 @@ const defaultCommitKeyCodes = [
|
|
|
837
756
|
return watcher;
|
|
838
757
|
}
|
|
839
758
|
/**
|
|
840
|
-
|
|
841
|
-
|
|
759
|
+
* Handles the feed response event data.
|
|
760
|
+
*/ _handleFeedResponse(data) {
|
|
842
761
|
const { feed, marker } = data;
|
|
843
762
|
// eslint-disable-next-line max-len
|
|
844
763
|
// @if CK_DEBUG_MENTION // console.log( `%c[Feed]%c Response for "${ data.feedText }" (${ feed.length })`, 'color: blue', 'color: black', feed );
|
|
@@ -867,8 +786,8 @@ const defaultCommitKeyCodes = [
|
|
|
867
786
|
}
|
|
868
787
|
}
|
|
869
788
|
/**
|
|
870
|
-
|
|
871
|
-
|
|
789
|
+
* Shows the mentions balloon. If the panel is already visible, it will reposition it.
|
|
790
|
+
*/ _showOrUpdateUI(markerMarker) {
|
|
872
791
|
if (this._isUIVisible) {
|
|
873
792
|
// @if CK_DEBUG_MENTION // console.log( '%c[UI]%c Updating position.', 'color: green', 'color: black' );
|
|
874
793
|
// Update balloon position as the mention list view may change its size.
|
|
@@ -885,8 +804,8 @@ const defaultCommitKeyCodes = [
|
|
|
885
804
|
this._mentionsView.selectFirst();
|
|
886
805
|
}
|
|
887
806
|
/**
|
|
888
|
-
|
|
889
|
-
|
|
807
|
+
* Hides the mentions balloon and removes the 'mention' marker from the markers collection.
|
|
808
|
+
*/ _hideUIAndRemoveMarker() {
|
|
890
809
|
// Remove the mention view from balloon before removing marker - it is used by balloon position target().
|
|
891
810
|
if (this._balloon.hasView(this._mentionsView)) {
|
|
892
811
|
// @if CK_DEBUG_MENTION // console.log( '%c[UI]%c Hiding the UI.', 'color: green', 'color: black' );
|
|
@@ -901,8 +820,8 @@ const defaultCommitKeyCodes = [
|
|
|
901
820
|
this._mentionsView.position = undefined;
|
|
902
821
|
}
|
|
903
822
|
/**
|
|
904
|
-
|
|
905
|
-
|
|
823
|
+
* Renders a single item in the autocomplete list.
|
|
824
|
+
*/ _renderItem(item, marker) {
|
|
906
825
|
const editor = this.editor;
|
|
907
826
|
let view;
|
|
908
827
|
let label = item.id;
|
|
@@ -924,11 +843,11 @@ const defaultCommitKeyCodes = [
|
|
|
924
843
|
return view;
|
|
925
844
|
}
|
|
926
845
|
/**
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
846
|
+
* Creates a position options object used to position the balloon panel.
|
|
847
|
+
*
|
|
848
|
+
* @param mentionMarker
|
|
849
|
+
* @param preferredPosition The name of the last matched position name.
|
|
850
|
+
*/ _getBalloonPanelPositionData(mentionMarker, preferredPosition) {
|
|
932
851
|
const editor = this.editor;
|
|
933
852
|
const editing = editor.editing;
|
|
934
853
|
const domConverter = editing.view.domConverter;
|
|
@@ -958,6 +877,18 @@ const defaultCommitKeyCodes = [
|
|
|
958
877
|
positions: getBalloonPanelPositions(preferredPosition, uiLanguageDirection)
|
|
959
878
|
};
|
|
960
879
|
}
|
|
880
|
+
/**
|
|
881
|
+
* @inheritDoc
|
|
882
|
+
*/ constructor(editor){
|
|
883
|
+
super(editor);
|
|
884
|
+
this._items = new Collection();
|
|
885
|
+
this._mentionsView = this._createMentionView();
|
|
886
|
+
this._mentionsConfigurations = new Map();
|
|
887
|
+
this._requestFeedDebounced = debounce(this._requestFeed, 100);
|
|
888
|
+
editor.config.define('mention', {
|
|
889
|
+
feeds: []
|
|
890
|
+
});
|
|
891
|
+
}
|
|
961
892
|
}
|
|
962
893
|
/**
|
|
963
894
|
* Returns the balloon positions data callbacks.
|
|
@@ -1154,22 +1085,18 @@ const defaultCommitKeyCodes = [
|
|
|
1154
1085
|
return editor.model.markers.has('mention');
|
|
1155
1086
|
}
|
|
1156
1087
|
|
|
1157
|
-
|
|
1158
|
-
* The mention plugin.
|
|
1159
|
-
*
|
|
1160
|
-
* For a detailed overview, check the {@glink features/mentions Mention feature} guide.
|
|
1161
|
-
*/ class Mention extends Plugin {
|
|
1088
|
+
class Mention extends Plugin {
|
|
1162
1089
|
toMentionAttribute(viewElement, data) {
|
|
1163
1090
|
return _toMentionAttribute(viewElement, data);
|
|
1164
1091
|
}
|
|
1165
1092
|
/**
|
|
1166
|
-
|
|
1167
|
-
|
|
1093
|
+
* @inheritDoc
|
|
1094
|
+
*/ static get pluginName() {
|
|
1168
1095
|
return 'Mention';
|
|
1169
1096
|
}
|
|
1170
1097
|
/**
|
|
1171
|
-
|
|
1172
|
-
|
|
1098
|
+
* @inheritDoc
|
|
1099
|
+
*/ static get requires() {
|
|
1173
1100
|
return [
|
|
1174
1101
|
MentionEditing,
|
|
1175
1102
|
MentionUI
|