@ckeditor/ckeditor5-mention 44.1.0-alpha.5 → 44.2.0-alpha.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.
@@ -1,269 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/mentionconfig
11
- */
12
- /**
13
- * The configuration of the mention feature.
14
- *
15
- * Read more about {@glink features/mentions#configuration configuring the mention feature}.
16
- *
17
- * ```ts
18
- * ClassicEditor
19
- * .create( editorElement, {
20
- * mention: ... // Mention feature options.
21
- * } )
22
- * .then( ... )
23
- * .catch( ... );
24
- * ```
25
- *
26
- * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
27
- */
28
- export interface MentionConfig {
29
- /**
30
- * The list of mention feeds supported by the editor.
31
- *
32
- * ```ts
33
- * ClassicEditor
34
- * .create( editorElement, {
35
- * plugins: [ Mention, ... ],
36
- * mention: {
37
- * feeds: [
38
- * {
39
- * marker: '@',
40
- * feed: [ '@Barney', '@Lily', '@Marshall', '@Robin', '@Ted' ]
41
- * },
42
- * ...
43
- * ]
44
- * }
45
- * } )
46
- * .then( ... )
47
- * .catch( ... );
48
- * ```
49
- *
50
- * You can provide many mention feeds but they must use different `marker`s.
51
- * For example, you can use `'@'` to autocomplete people and `'#'` to autocomplete tags.
52
- */
53
- feeds: Array<MentionFeed>;
54
- /**
55
- * The configuration of the custom commit keys supported by the editor.
56
- *
57
- * ```ts
58
- * ClassicEditor
59
- * .create( editorElement, {
60
- * plugins: [ Mention, ... ],
61
- * mention: {
62
- * // [ Enter, Space ]
63
- * commitKeys: [ 13, 32 ]
64
- * feeds: [
65
- * { ... }
66
- * ...
67
- * ]
68
- * }
69
- * } )
70
- * .then( ... )
71
- * .catch( ... );
72
- * ```
73
- *
74
- * Custom commit keys configuration allows you to customize how users will confirm the selection of mentions from the dropdown list.
75
- * You can add as many mention commit keys as you need. For instance, in the snippet above new mentions will be committed by pressing
76
- * either <kbd>Enter</kbd> or <kbd>Space</kbd> (13 and 32 key codes respectively).
77
- *
78
- * @default [ 13, 9 ] // [ Enter, Tab ]
79
- */
80
- commitKeys?: Array<number>;
81
- /**
82
- * The configuration of the custom number of visible mentions.
83
- *
84
- * Customizing the number of visible mentions allows you to specify how many available elements will the users be able to see
85
- * in the dropdown list. You can specify any number you see fit. For example, in the snippets below you will find the
86
- * dropdownLimit set to `20` and `Infinity` (the latter will result in showing all available mentions).
87
- *
88
- * ```ts
89
- * ClassicEditor
90
- * .create( editorElement, {
91
- * plugins: [ Mention, ... ],
92
- * mention: {
93
- * dropdownLimit: 20,
94
- * feeds: [
95
- * { ... }
96
- * ...
97
- * ]
98
- * }
99
- * } )
100
- * .then( ... )
101
- * .catch( ... );
102
- *
103
- * ClassicEditor
104
- * .create( editorElement, {
105
- * plugins: [ Mention, ... ],
106
- * mention: {
107
- * dropdownLimit: Infinity,
108
- * feeds: [
109
- * { ... }
110
- * ...
111
- * ]
112
- * }
113
- * } )
114
- * .then( ... )
115
- * .catch( ... );
116
- * ```
117
- *
118
- * @default 10
119
- */
120
- dropdownLimit?: number;
121
- }
122
- /**
123
- * The mention feed descriptor. Used in {@link module:mention/mentionconfig~MentionConfig `config.mention`}.
124
- *
125
- * See {@link module:mention/mentionconfig~MentionConfig} to learn more.
126
- *
127
- * ```ts
128
- * // Static configuration.
129
- * const mentionFeedPeople = {
130
- * marker: '@',
131
- * feed: [ '@Alice', '@Bob', ... ],
132
- * minimumCharacters: 2
133
- * };
134
- *
135
- * // Simple synchronous callback.
136
- * const mentionFeedTags = {
137
- * marker: '#',
138
- * feed: ( searchString: string ) => {
139
- * return tags
140
- * // Filter the tags list.
141
- * .filter( tag => {
142
- * return tag.toLowerCase().includes( queryText.toLowerCase() );
143
- * } )
144
- * }
145
- * };
146
- *
147
- * const tags = [ 'wysiwyg', 'rte', 'rich-text-edior', 'collaboration', 'real-time', ... ];
148
- *
149
- * // Asynchronous callback.
150
- * const mentionFeedPlaceholders = {
151
- * marker: '$',
152
- * feed: ( searchString: string ) => {
153
- * return getMatchingPlaceholders( searchString );
154
- * }
155
- * };
156
- *
157
- * function getMatchingPlaceholders( searchString: string ) {
158
- * return new Promise<Array<MentionFeedItem>>( resolve => {
159
- * doSomeXHRQuery( result => {
160
- * // console.log( result );
161
- * // -> [ '$name', '$surname', '$postal', ... ]
162
- *
163
- * resolve( result );
164
- * } );
165
- * } );
166
- * }
167
- * ```
168
- */
169
- export interface MentionFeed {
170
- /**
171
- * The character which triggers autocompletion for mention. It must be a single character.
172
- */
173
- marker: string;
174
- /**
175
- * Autocomplete items. Provide an array for
176
- * a static configuration (the mention feature will show matching items automatically) or a function which returns an array of
177
- * matching items (directly, or via a promise). If a function is passed, it is executed in the context of the editor instance.
178
- */
179
- feed: Array<MentionFeedItem> | FeedCallback;
180
- /**
181
- * Specifies after how many characters the autocomplete panel should be shown.
182
- *
183
- * @default 0
184
- */
185
- minimumCharacters?: number;
186
- /**
187
- * A function that renders a {@link module:mention/mentionconfig~MentionFeedItem}
188
- * to the autocomplete panel.
189
- */
190
- itemRenderer?: ItemRenderer;
191
- /**
192
- * Specify how many available elements per feeds will the users be able to see in the dropdown list.
193
- * If it not set, limit is inherited from {@link module:mention/mentionconfig~MentionConfig#dropdownLimit MentionConfig}.
194
- */
195
- dropdownLimit?: number;
196
- }
197
- /**
198
- * Function that renders an array of {@link module:mention/mentionconfig~MentionFeedItem} based on string input.
199
- */
200
- export type FeedCallback = (searchString: string) => Array<MentionFeedItem> | Promise<Array<MentionFeedItem>>;
201
- /**
202
- * Function that takes renders a {@link module:mention/mentionconfig~MentionFeedObjectItem} as HTMLElement.
203
- */
204
- export type ItemRenderer = (item: MentionFeedObjectItem) => HTMLElement | string;
205
- /**
206
- * The mention feed item. It may be defined as a string or a plain object.
207
- *
208
- * When defining a feed item as a plain object, the `id` property is obligatory. Additional properties
209
- * can be used when customizing the mention feature bahavior
210
- * (see {@glink features/mentions#customizing-the-autocomplete-list "Customizing the autocomplete list"}
211
- * and {@glink features/mentions#customizing-the-output "Customizing the output"} sections).
212
- *
213
- * ```ts
214
- * ClassicEditor
215
- * .create( editorElement, {
216
- * plugins: [ Mention, ... ],
217
- * mention: {
218
- * feeds: [
219
- * // Feed items as objects.
220
- * {
221
- * marker: '@',
222
- * feed: [
223
- * {
224
- * id: '@Barney',
225
- * fullName: 'Barney Bloom'
226
- * },
227
- * {
228
- * id: '@Lily',
229
- * fullName: 'Lily Smith'
230
- * },
231
- * {
232
- * id: '@Marshall',
233
- * fullName: 'Marshall McDonald'
234
- * },
235
- * {
236
- * id: '@Robin',
237
- * fullName: 'Robin Hood'
238
- * },
239
- * {
240
- * id: '@Ted',
241
- * fullName: 'Ted Cruze'
242
- * },
243
- * // ...
244
- * ]
245
- * },
246
- *
247
- * // Feed items as plain strings.
248
- * {
249
- * marker: '#',
250
- * feed: [ 'wysiwyg', 'rte', 'rich-text-edior', 'collaboration', 'real-time', ... ]
251
- * },
252
- * ]
253
- * }
254
- * } )
255
- * .then( ... )
256
- * .catch( ... );
257
- * ```
258
- */
259
- export type MentionFeedItem = string | MentionFeedObjectItem;
260
- export type MentionFeedObjectItem = {
261
- /**
262
- * A unique ID of the mention. It must start with the marker character.
263
- */
264
- id: string;
265
- /**
266
- * Text inserted into the editor when creating a mention.
267
- */
268
- text?: string;
269
- };
@@ -1,51 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/mentionediting
11
- */
12
- import { Plugin } from 'ckeditor5/src/core.js';
13
- import type { Element } from 'ckeditor5/src/engine.js';
14
- import type { MentionAttribute } from './mention.js';
15
- /**
16
- * The mention editing feature.
17
- *
18
- * It introduces the {@link module:mention/mentioncommand~MentionCommand command} and the `mention`
19
- * attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
20
- * as a `<span class="mention" data-mention="@mention">`.
21
- */
22
- export default class MentionEditing extends Plugin {
23
- /**
24
- * @inheritDoc
25
- */
26
- static get pluginName(): "MentionEditing";
27
- /**
28
- * @inheritDoc
29
- */
30
- static get isOfficialPlugin(): true;
31
- /**
32
- * @inheritDoc
33
- */
34
- init(): void;
35
- }
36
- /**
37
- * @internal
38
- */
39
- export declare function _addMentionAttributes(baseMentionData: {
40
- id: string;
41
- _text: string;
42
- }, data?: Record<string, unknown>): MentionAttribute;
43
- /**
44
- * Creates a mention attribute value from the provided view element and optional data.
45
- *
46
- * This function is exposed as
47
- * {@link module:mention/mention~Mention#toMentionAttribute `editor.plugins.get( 'Mention' ).toMentionAttribute()`}.
48
- *
49
- * @internal
50
- */
51
- export declare function _toMentionAttribute(viewElementOrMention: Element, data?: Record<string, unknown>): MentionAttribute | undefined;
@@ -1,110 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/mentionui
11
- */
12
- import { Plugin, type Editor } from 'ckeditor5/src/core.js';
13
- import { ContextualBalloon } from 'ckeditor5/src/ui.js';
14
- /**
15
- * The mention UI feature.
16
- */
17
- export default class MentionUI extends Plugin {
18
- /**
19
- * The mention view.
20
- */
21
- private readonly _mentionsView;
22
- /**
23
- * Stores mention feeds configurations.
24
- */
25
- private _mentionsConfigurations;
26
- /**
27
- * The contextual balloon plugin instance.
28
- */
29
- private _balloon;
30
- private _items;
31
- private _lastRequested?;
32
- /**
33
- * Debounced feed requester. It uses `lodash#debounce` method to delay function call.
34
- */
35
- private _requestFeedDebounced;
36
- /**
37
- * @inheritDoc
38
- */
39
- static get pluginName(): "MentionUI";
40
- /**
41
- * @inheritDoc
42
- */
43
- static get isOfficialPlugin(): true;
44
- /**
45
- * @inheritDoc
46
- */
47
- static get requires(): readonly [typeof ContextualBalloon];
48
- /**
49
- * @inheritDoc
50
- */
51
- constructor(editor: Editor);
52
- /**
53
- * @inheritDoc
54
- */
55
- init(): void;
56
- /**
57
- * @inheritDoc
58
- */
59
- destroy(): void;
60
- /**
61
- * Returns true when {@link #_mentionsView} is in the {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon} and it is
62
- * currently visible.
63
- */
64
- private get _isUIVisible();
65
- /**
66
- * Creates the {@link #_mentionsView}.
67
- */
68
- private _createMentionView;
69
- /**
70
- * Returns item renderer for the marker.
71
- */
72
- private _getItemRenderer;
73
- /**
74
- * Requests a feed from a configured callbacks.
75
- */
76
- private _requestFeed;
77
- /**
78
- * Registers a text watcher for the marker.
79
- */
80
- private _setupTextWatcher;
81
- /**
82
- * Handles the feed response event data.
83
- */
84
- private _handleFeedResponse;
85
- /**
86
- * Shows the mentions balloon. If the panel is already visible, it will reposition it.
87
- */
88
- private _showOrUpdateUI;
89
- /**
90
- * Hides the mentions balloon and removes the 'mention' marker from the markers collection.
91
- */
92
- private _hideUIAndRemoveMarker;
93
- /**
94
- * Renders a single item in the autocomplete list.
95
- */
96
- private _renderItem;
97
- /**
98
- * Creates a position options object used to position the balloon panel.
99
- *
100
- * @param mentionMarker
101
- * @param preferredPosition The name of the last matched position name.
102
- */
103
- private _getBalloonPanelPositionData;
104
- }
105
- /**
106
- * Creates a RegExp pattern for the marker.
107
- *
108
- * Function has to be exported to achieve 100% code coverage.
109
- */
110
- export declare function createRegExp(marker: string, minimumCharacters: number): RegExp;
@@ -1,45 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/ui/domwrapperview
11
- */
12
- import { View } from 'ckeditor5/src/ui.js';
13
- import type { Locale } from 'ckeditor5/src/utils.js';
14
- /**
15
- * This class wraps DOM element as a CKEditor5 UI View.
16
- *
17
- * It allows to render any DOM element and use it in mentions list.
18
- */
19
- export default class DomWrapperView extends View {
20
- /**
21
- * The DOM element for which wrapper was created.
22
- */
23
- domElement: HTMLElement;
24
- /**
25
- * Controls whether the dom wrapper view is "on". This is in line with {@link module:ui/button/button~Button#isOn} property.
26
- *
27
- * @observable
28
- * @default true
29
- */
30
- isOn: boolean;
31
- /**
32
- * Creates an instance of {@link module:mention/ui/domwrapperview~DomWrapperView} class.
33
- *
34
- * Also see {@link #render}.
35
- */
36
- constructor(locale: Locale, domElement: HTMLElement);
37
- /**
38
- * @inheritDoc
39
- */
40
- render(): void;
41
- /**
42
- * Focuses the DOM element.
43
- */
44
- focus(): void;
45
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/ui/mentionlistitemview
11
- */
12
- import { ListItemView } from 'ckeditor5/src/ui.js';
13
- import type { MentionFeedItem } from '../mentionconfig.js';
14
- export default class MentionListItemView extends ListItemView {
15
- item: MentionFeedItem;
16
- marker: string;
17
- highlight(): void;
18
- removeHighlight(): void;
19
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
8
- */
9
- /**
10
- * @module mention/ui/mentionsview
11
- */
12
- import { ListView } from 'ckeditor5/src/ui.js';
13
- import { type Locale } from 'ckeditor5/src/utils.js';
14
- import type MentionListItemView from './mentionlistitemview.js';
15
- import '../../theme/mentionui.css';
16
- /**
17
- * The mention ui view.
18
- */
19
- export default class MentionsView extends ListView {
20
- selected: MentionListItemView | undefined;
21
- position: string | undefined;
22
- /**
23
- * @inheritDoc
24
- */
25
- constructor(locale: Locale);
26
- /**
27
- * {@link #select Selects} the first item.
28
- */
29
- selectFirst(): void;
30
- /**
31
- * Selects next item to the currently {@link #select selected}.
32
- *
33
- * If the last item is already selected, it will select the first item.
34
- */
35
- selectNext(): void;
36
- /**
37
- * Selects previous item to the currently {@link #select selected}.
38
- *
39
- * If the first item is already selected, it will select the last item.
40
- */
41
- selectPrevious(): void;
42
- /**
43
- * Marks item at a given index as selected.
44
- *
45
- * Handles selection cycling when passed index is out of bounds:
46
- * - if the index is lower than 0, it will select the last item,
47
- * - if the index is higher than the last item index, it will select the first item.
48
- *
49
- * @param index Index of an item to be marked as selected.
50
- */
51
- select(index: number): void;
52
- /**
53
- * Triggers the `execute` event on the {@link #select selected} item.
54
- */
55
- executeSelected(): void;
56
- /**
57
- * Checks if an item is visible in the scrollable area.
58
- *
59
- * The item is considered visible when:
60
- * - its top boundary is inside the scrollable rect
61
- * - its bottom boundary is inside the scrollable rect (the whole item must be visible)
62
- */
63
- private _isItemVisibleInScrolledArea;
64
- }