ckeditor5-elements-quick-insert 0.0.0-stage → 49.0.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.
- package/LICENSE +21 -0
- package/README.md +29 -2
- package/dist/augmentation.d.ts +18 -0
- package/dist/augmentation.d.ts.map +1 -0
- package/dist/augmentation.js +2 -0
- package/dist/augmentation.js.map +1 -0
- package/dist/icons.d.ts +16 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +21 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/quickInsert.d.ts +56 -0
- package/dist/quickInsert.d.ts.map +1 -0
- package/dist/quickInsert.js +106 -0
- package/dist/quickInsert.js.map +1 -0
- package/dist/quickInsertCommand.d.ts +39 -0
- package/dist/quickInsertCommand.d.ts.map +1 -0
- package/dist/quickInsertCommand.js +88 -0
- package/dist/quickInsertCommand.js.map +1 -0
- package/dist/quickInsertListView.d.ts +29 -0
- package/dist/quickInsertListView.d.ts.map +1 -0
- package/dist/quickInsertListView.js +44 -0
- package/dist/quickInsertListView.js.map +1 -0
- package/dist/quickInsertPositionCommand.d.ts +28 -0
- package/dist/quickInsertPositionCommand.d.ts.map +1 -0
- package/dist/quickInsertPositionCommand.js +54 -0
- package/dist/quickInsertPositionCommand.js.map +1 -0
- package/dist/quickInsertView.d.ts +20 -0
- package/dist/quickInsertView.d.ts.map +1 -0
- package/dist/quickInsertView.js +52 -0
- package/dist/quickInsertView.js.map +1 -0
- package/package.json +49 -3
- package/src/augmentation.ts +20 -0
- package/src/icons.ts +26 -0
- package/src/index.ts +21 -0
- package/src/quickInsert.ts +148 -0
- package/src/quickInsertCommand.ts +103 -0
- package/src/quickInsertListView.ts +71 -0
- package/src/quickInsertPositionCommand.ts +72 -0
- package/src/quickInsertView.ts +64 -0
- package/theme/quickInsert.css +12 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SearchTextView, type FilteredViewExecuteEvent, type Locale } from 'ckeditor5';
|
|
2
|
+
import QuickInsertListView, { type QuickInsertItem } from './quickInsertListView.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A search field with a filtered list of insertable elements.
|
|
6
|
+
*
|
|
7
|
+
* In the search field, Enter chooses the first matching item and the down arrow moves the focus to the list.
|
|
8
|
+
* Fires `execute` with `{ value: name }` when an item is chosen.
|
|
9
|
+
*/
|
|
10
|
+
export default class QuickInsertView extends SearchTextView {
|
|
11
|
+
/**
|
|
12
|
+
* The list of elements.
|
|
13
|
+
*/
|
|
14
|
+
public readonly listView: QuickInsertListView;
|
|
15
|
+
|
|
16
|
+
constructor(locale: Locale, items: readonly QuickInsertItem[]) {
|
|
17
|
+
const listView = new QuickInsertListView(locale, items);
|
|
18
|
+
const t = locale.t;
|
|
19
|
+
|
|
20
|
+
super(locale, {
|
|
21
|
+
queryView: { label: t('Insert element') },
|
|
22
|
+
filteredView: listView,
|
|
23
|
+
infoView: {
|
|
24
|
+
text: {
|
|
25
|
+
notFound: { primary: t('No matching elements') },
|
|
26
|
+
noSearchableItems: { primary: t('No elements can be inserted here') }
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
class: 'ck-elements-quick-insert'
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
this.listView = listView;
|
|
33
|
+
listView.delegate('execute').to(this);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Renders the view and sets up Enter (choose the first match) and the down arrow (go to the list) in the search field.
|
|
38
|
+
*/
|
|
39
|
+
public override render(): void {
|
|
40
|
+
super.render();
|
|
41
|
+
|
|
42
|
+
const isInQueryField = (): boolean => this.focusTracker.focusedElement === this.queryView.element;
|
|
43
|
+
|
|
44
|
+
this.keystrokes.set('enter', (data, cancel) => {
|
|
45
|
+
const item = isInQueryField() ? this.listView.getFirstVisibleItem() : null;
|
|
46
|
+
|
|
47
|
+
if (item) {
|
|
48
|
+
this.fire<FilteredViewExecuteEvent>('execute', { value: item.name });
|
|
49
|
+
cancel();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.keystrokes.set(
|
|
54
|
+
'arrowdown',
|
|
55
|
+
(data, cancel) => {
|
|
56
|
+
if (isInQueryField()) {
|
|
57
|
+
this.listView.focusFirst();
|
|
58
|
+
cancel();
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{ priority: 'high' }
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|