@ckeditor/ckeditor5-ui 39.0.2 → 40.1.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.md +3 -3
- package/lang/contexts.json +5 -1
- package/lang/translations/ar.po +16 -0
- package/lang/translations/ast.po +16 -0
- package/lang/translations/az.po +16 -0
- package/lang/translations/bg.po +16 -0
- package/lang/translations/bn.po +16 -0
- package/lang/translations/ca.po +16 -0
- package/lang/translations/cs.po +16 -0
- package/lang/translations/da.po +16 -0
- package/lang/translations/de-ch.po +16 -0
- package/lang/translations/de.po +16 -0
- package/lang/translations/el.po +16 -0
- package/lang/translations/en-au.po +16 -0
- package/lang/translations/en-gb.po +16 -0
- package/lang/translations/en.po +16 -0
- package/lang/translations/eo.po +16 -0
- package/lang/translations/es.po +16 -0
- package/lang/translations/et.po +16 -0
- package/lang/translations/eu.po +16 -0
- package/lang/translations/fa.po +16 -0
- package/lang/translations/fi.po +16 -0
- package/lang/translations/fr.po +16 -0
- package/lang/translations/gl.po +16 -0
- package/lang/translations/he.po +16 -0
- package/lang/translations/hi.po +16 -0
- package/lang/translations/hr.po +16 -0
- package/lang/translations/hu.po +16 -0
- package/lang/translations/id.po +16 -0
- package/lang/translations/it.po +16 -0
- package/lang/translations/ja.po +16 -0
- package/lang/translations/km.po +16 -0
- package/lang/translations/kn.po +16 -0
- package/lang/translations/ko.po +16 -0
- package/lang/translations/ku.po +16 -0
- package/lang/translations/lt.po +16 -0
- package/lang/translations/lv.po +16 -0
- package/lang/translations/ms.po +16 -0
- package/lang/translations/nb.po +16 -0
- package/lang/translations/ne.po +16 -0
- package/lang/translations/nl.po +16 -0
- package/lang/translations/no.po +16 -0
- package/lang/translations/pl.po +16 -0
- package/lang/translations/pt-br.po +17 -1
- package/lang/translations/pt.po +16 -0
- package/lang/translations/ro.po +16 -0
- package/lang/translations/ru.po +16 -0
- package/lang/translations/sk.po +16 -0
- package/lang/translations/sl.po +16 -0
- package/lang/translations/sq.po +16 -0
- package/lang/translations/sr-latn.po +16 -0
- package/lang/translations/sr.po +16 -0
- package/lang/translations/sv.po +16 -0
- package/lang/translations/th.po +16 -0
- package/lang/translations/tk.po +16 -0
- package/lang/translations/tr.po +16 -0
- package/lang/translations/tt.po +16 -0
- package/lang/translations/ug.po +38 -22
- package/lang/translations/uk.po +16 -0
- package/lang/translations/ur.po +16 -0
- package/lang/translations/uz.po +16 -0
- package/lang/translations/vi.po +16 -0
- package/lang/translations/zh-cn.po +16 -0
- package/lang/translations/zh.po +16 -0
- package/package.json +3 -3
- package/src/arialiveannouncer.d.ts +94 -0
- package/src/arialiveannouncer.js +113 -0
- package/src/autocomplete/autocompleteview.d.ts +81 -0
- package/src/autocomplete/autocompleteview.js +153 -0
- package/src/button/button.d.ts +0 -6
- package/src/button/buttonlabel.d.ts +34 -0
- package/src/button/buttonlabel.js +5 -0
- package/src/button/buttonlabelview.d.ts +31 -0
- package/src/button/buttonlabelview.js +42 -0
- package/src/button/buttonview.d.ts +14 -10
- package/src/button/buttonview.js +11 -25
- package/src/dropdown/dropdownview.js +5 -4
- package/src/dropdown/utils.d.ts +15 -1
- package/src/dropdown/utils.js +47 -21
- package/src/editorui/editorui.d.ts +6 -0
- package/src/editorui/editorui.js +2 -0
- package/src/editorui/poweredby.js +14 -37
- package/src/focuscycler.d.ts +45 -2
- package/src/focuscycler.js +34 -9
- package/src/formheader/formheaderview.d.ts +6 -0
- package/src/formheader/formheaderview.js +6 -0
- package/src/highlightedtext/highlightedtextview.d.ts +38 -0
- package/src/highlightedtext/highlightedtextview.js +102 -0
- package/src/icon/iconview.d.ts +7 -0
- package/src/icon/iconview.js +2 -0
- package/src/index.d.ts +12 -2
- package/src/index.js +8 -0
- package/src/input/inputbase.d.ts +107 -0
- package/src/input/inputbase.js +110 -0
- package/src/input/inputview.d.ts +4 -89
- package/src/input/inputview.js +5 -87
- package/src/labeledfield/labeledfieldview.d.ts +7 -2
- package/src/labeledfield/labeledfieldview.js +2 -2
- package/src/labeledfield/utils.d.ts +34 -4
- package/src/labeledfield/utils.js +51 -6
- package/src/list/listitemgroupview.d.ts +59 -0
- package/src/list/listitemgroupview.js +63 -0
- package/src/list/listitemview.d.ts +2 -1
- package/src/list/listitemview.js +3 -1
- package/src/list/listview.d.ts +59 -2
- package/src/list/listview.js +105 -8
- package/src/panel/balloon/balloonpanelview.js +26 -4
- package/src/panel/sticky/stickypanelview.d.ts +1 -3
- package/src/panel/sticky/stickypanelview.js +53 -50
- package/src/search/filteredview.d.ts +31 -0
- package/src/search/filteredview.js +5 -0
- package/src/search/searchinfoview.d.ts +45 -0
- package/src/search/searchinfoview.js +59 -0
- package/src/search/searchresultsview.d.ts +54 -0
- package/src/search/searchresultsview.js +65 -0
- package/src/search/text/searchtextqueryview.d.ts +76 -0
- package/src/search/text/searchtextqueryview.js +75 -0
- package/src/search/text/searchtextview.d.ts +219 -0
- package/src/search/text/searchtextview.js +201 -0
- package/src/spinner/spinnerview.d.ts +25 -0
- package/src/spinner/spinnerview.js +38 -0
- package/src/textarea/textareaview.d.ts +88 -0
- package/src/textarea/textareaview.js +142 -0
- package/src/toolbar/block/blocktoolbar.js +30 -26
- package/src/toolbar/normalizetoolbarconfig.d.ts +1 -0
- package/src/toolbar/normalizetoolbarconfig.js +9 -8
- package/src/toolbar/toolbarview.d.ts +1 -0
- package/src/toolbar/toolbarview.js +4 -2
- package/theme/components/arialiveannouncer/arialiveannouncer.css +10 -0
- package/theme/components/autocomplete/autocomplete.css +22 -0
- package/theme/components/button/button.css +9 -1
- package/theme/components/formheader/formheader.css +4 -0
- package/theme/components/highlightedtext/highlightedtext.css +12 -0
- package/theme/components/search/search.css +43 -0
- package/theme/components/spinner/spinner.css +23 -0
- package/theme/components/textarea/textarea.css +10 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/arialiveannouncer
|
|
7
|
+
*/
|
|
8
|
+
import type { Editor } from '@ckeditor/ckeditor5-core';
|
|
9
|
+
import type { Locale } from '@ckeditor/ckeditor5-utils';
|
|
10
|
+
import type ViewCollection from './viewcollection';
|
|
11
|
+
import View from './view';
|
|
12
|
+
import '../theme/components/arialiveannouncer/arialiveannouncer.css';
|
|
13
|
+
/**
|
|
14
|
+
* The politeness level of an `aria-live` announcement.
|
|
15
|
+
*
|
|
16
|
+
* See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions#Politeness_levels
|
|
17
|
+
*/
|
|
18
|
+
export declare enum AriaLiveAnnouncerPoliteness {
|
|
19
|
+
POLITE = "polite",
|
|
20
|
+
ASSERTIVE = "assertive"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* An accessibility helper that manages all ARIA live regions associated with an editor instance. ARIA live regions announce changes
|
|
24
|
+
* to the state of the editor features.
|
|
25
|
+
*
|
|
26
|
+
* These announcements are consumed and propagated by screen readers and give users a better understanding of the current
|
|
27
|
+
* state of the editor.
|
|
28
|
+
*
|
|
29
|
+
* To announce a state change to an editor feature named `'Some feature'`, use the {@link #announce} method:
|
|
30
|
+
* ```ts
|
|
31
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'Some feature', 'Text of an announcement.' );
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export default class AriaLiveAnnouncer {
|
|
35
|
+
/**
|
|
36
|
+
* The editor instance.
|
|
37
|
+
*/
|
|
38
|
+
readonly editor: Editor;
|
|
39
|
+
/**
|
|
40
|
+
* The view that aggregates all `aria-live` regions.
|
|
41
|
+
*/
|
|
42
|
+
view?: AriaLiveAnnouncerView;
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
constructor(editor: Editor);
|
|
47
|
+
/**
|
|
48
|
+
* Sets an announcement text to an aria region associated with a specific editor feature. The text is then
|
|
49
|
+
* announced by a screen reader to the user.
|
|
50
|
+
*
|
|
51
|
+
* If the aria region of a given name does not exist, it will be created and can be re-used later. The name of the region
|
|
52
|
+
* groups announcements originating from a specific editor feature and does not get announced by a screen reader.
|
|
53
|
+
*
|
|
54
|
+
* Using multiple regions allows for many announcements to be emitted in a short period of time. Changes to ARIA-live announcements
|
|
55
|
+
* are captured by a screen reader and read out in the order they were emitted.
|
|
56
|
+
*
|
|
57
|
+
* The default announcement politeness level is `'polite'`.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* // Most screen readers will queue announcements from multiple aria-live regions and read them out in the order they were emitted.
|
|
61
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'image', 'Image uploaded.' );
|
|
62
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'network', 'Connection lost. Reconnecting.' );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
announce(regionName: string, announcementText: string, politeness?: AriaLiveAnnouncerPoliteness): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The view that aggregates all `aria-live` regions.
|
|
69
|
+
*/
|
|
70
|
+
export declare class AriaLiveAnnouncerView extends View {
|
|
71
|
+
/**
|
|
72
|
+
* A collection of all views that represent individual `aria-live` regions.
|
|
73
|
+
*/
|
|
74
|
+
readonly regionViews: ViewCollection<AriaLiveAnnouncerRegionView>;
|
|
75
|
+
constructor(locale: Locale);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The view that represents a single `aria-live` region (e.g. for a specific editor feature) and its text.
|
|
79
|
+
*/
|
|
80
|
+
export declare class AriaLiveAnnouncerRegionView extends View {
|
|
81
|
+
/**
|
|
82
|
+
* Current text of the region.
|
|
83
|
+
*/
|
|
84
|
+
text: string;
|
|
85
|
+
/**
|
|
86
|
+
* Current politeness level of the region.
|
|
87
|
+
*/
|
|
88
|
+
politeness: AriaLiveAnnouncerPoliteness;
|
|
89
|
+
/**
|
|
90
|
+
* A unique name of the region, usually associated with a specific editor feature or system.
|
|
91
|
+
*/
|
|
92
|
+
regionName: string;
|
|
93
|
+
constructor(locale: Locale);
|
|
94
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
import View from './view';
|
|
6
|
+
import '../theme/components/arialiveannouncer/arialiveannouncer.css';
|
|
7
|
+
/**
|
|
8
|
+
* The politeness level of an `aria-live` announcement.
|
|
9
|
+
*
|
|
10
|
+
* See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions#Politeness_levels
|
|
11
|
+
*/
|
|
12
|
+
export var AriaLiveAnnouncerPoliteness;
|
|
13
|
+
(function (AriaLiveAnnouncerPoliteness) {
|
|
14
|
+
AriaLiveAnnouncerPoliteness["POLITE"] = "polite";
|
|
15
|
+
AriaLiveAnnouncerPoliteness["ASSERTIVE"] = "assertive";
|
|
16
|
+
})(AriaLiveAnnouncerPoliteness || (AriaLiveAnnouncerPoliteness = {}));
|
|
17
|
+
/**
|
|
18
|
+
* An accessibility helper that manages all ARIA live regions associated with an editor instance. ARIA live regions announce changes
|
|
19
|
+
* to the state of the editor features.
|
|
20
|
+
*
|
|
21
|
+
* These announcements are consumed and propagated by screen readers and give users a better understanding of the current
|
|
22
|
+
* state of the editor.
|
|
23
|
+
*
|
|
24
|
+
* To announce a state change to an editor feature named `'Some feature'`, use the {@link #announce} method:
|
|
25
|
+
* ```ts
|
|
26
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'Some feature', 'Text of an announcement.' );
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export default class AriaLiveAnnouncer {
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
constructor(editor) {
|
|
34
|
+
this.editor = editor;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sets an announcement text to an aria region associated with a specific editor feature. The text is then
|
|
38
|
+
* announced by a screen reader to the user.
|
|
39
|
+
*
|
|
40
|
+
* If the aria region of a given name does not exist, it will be created and can be re-used later. The name of the region
|
|
41
|
+
* groups announcements originating from a specific editor feature and does not get announced by a screen reader.
|
|
42
|
+
*
|
|
43
|
+
* Using multiple regions allows for many announcements to be emitted in a short period of time. Changes to ARIA-live announcements
|
|
44
|
+
* are captured by a screen reader and read out in the order they were emitted.
|
|
45
|
+
*
|
|
46
|
+
* The default announcement politeness level is `'polite'`.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Most screen readers will queue announcements from multiple aria-live regions and read them out in the order they were emitted.
|
|
50
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'image', 'Image uploaded.' );
|
|
51
|
+
* editor.ui.ariaLiveAnnouncer.announce( 'network', 'Connection lost. Reconnecting.' );
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
announce(regionName, announcementText, politeness = AriaLiveAnnouncerPoliteness.POLITE) {
|
|
55
|
+
const editor = this.editor;
|
|
56
|
+
if (!this.view) {
|
|
57
|
+
this.view = new AriaLiveAnnouncerView(editor.locale);
|
|
58
|
+
editor.ui.view.body.add(this.view);
|
|
59
|
+
}
|
|
60
|
+
let regionView = this.view.regionViews.find(view => view.regionName === regionName);
|
|
61
|
+
if (!regionView) {
|
|
62
|
+
regionView = new AriaLiveAnnouncerRegionView(this.view.locale);
|
|
63
|
+
this.view.regionViews.add(regionView);
|
|
64
|
+
}
|
|
65
|
+
regionView.set({
|
|
66
|
+
regionName,
|
|
67
|
+
text: announcementText,
|
|
68
|
+
politeness
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The view that aggregates all `aria-live` regions.
|
|
74
|
+
*/
|
|
75
|
+
export class AriaLiveAnnouncerView extends View {
|
|
76
|
+
constructor(locale) {
|
|
77
|
+
super(locale);
|
|
78
|
+
this.regionViews = this.createCollection();
|
|
79
|
+
this.setTemplate({
|
|
80
|
+
tag: 'div',
|
|
81
|
+
attributes: {
|
|
82
|
+
class: [
|
|
83
|
+
'ck',
|
|
84
|
+
'ck-aria-live-announcer'
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
children: this.regionViews
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The view that represents a single `aria-live` region (e.g. for a specific editor feature) and its text.
|
|
93
|
+
*/
|
|
94
|
+
export class AriaLiveAnnouncerRegionView extends View {
|
|
95
|
+
constructor(locale) {
|
|
96
|
+
super(locale);
|
|
97
|
+
const bind = this.bindTemplate;
|
|
98
|
+
this.set('regionName', '');
|
|
99
|
+
this.set('text', '');
|
|
100
|
+
this.set('politeness', AriaLiveAnnouncerPoliteness.POLITE);
|
|
101
|
+
this.setTemplate({
|
|
102
|
+
tag: 'div',
|
|
103
|
+
attributes: {
|
|
104
|
+
role: 'region',
|
|
105
|
+
'data-region': bind.to('regionName'),
|
|
106
|
+
'aria-live': bind.to('politeness')
|
|
107
|
+
},
|
|
108
|
+
children: [
|
|
109
|
+
{ text: bind.to('text') }
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/autocomplete/autocompleteview
|
|
7
|
+
*/
|
|
8
|
+
import { type PositioningFunction, type Locale } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
import SearchTextView, { type SearchTextViewConfig } from '../search/text/searchtextview';
|
|
10
|
+
import type SearchResultsView from '../search/searchresultsview';
|
|
11
|
+
import type InputBase from '../input/inputbase';
|
|
12
|
+
import '../../theme/components/autocomplete/autocomplete.css';
|
|
13
|
+
/**
|
|
14
|
+
* The autocomplete component's view class. It extends the {@link module:ui/search/text/searchtextview~SearchTextView} class
|
|
15
|
+
* with a floating {@link #resultsView} that shows up when the user starts typing and hides when they blur
|
|
16
|
+
* the component.
|
|
17
|
+
*/
|
|
18
|
+
export default class AutocompleteView<TQueryFieldView extends InputBase<HTMLInputElement | HTMLTextAreaElement>> extends SearchTextView<TQueryFieldView> {
|
|
19
|
+
/**
|
|
20
|
+
* The configuration of the autocomplete view.
|
|
21
|
+
*/
|
|
22
|
+
protected _config: AutocompleteViewConfig<TQueryFieldView>;
|
|
23
|
+
resultsView: AutocompleteResultsView;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
constructor(locale: Locale, config: AutocompleteViewConfig<TQueryFieldView>);
|
|
28
|
+
/**
|
|
29
|
+
* Updates the position of the results view on demand.
|
|
30
|
+
*/
|
|
31
|
+
private _updateResultsViewWidthAndPosition;
|
|
32
|
+
/**
|
|
33
|
+
* Updates the visibility of the results view on demand.
|
|
34
|
+
*/
|
|
35
|
+
private _updateResultsVisibility;
|
|
36
|
+
/**
|
|
37
|
+
* Positions for the autocomplete results view. Two positions are defined by default:
|
|
38
|
+
* * `s` - below the search field,
|
|
39
|
+
* * `n` - above the search field.
|
|
40
|
+
*/
|
|
41
|
+
static defaultResultsPositions: Array<PositioningFunction>;
|
|
42
|
+
/**
|
|
43
|
+
* A function used to calculate the optimal position for the dropdown panel.
|
|
44
|
+
*/
|
|
45
|
+
private static _getOptimalPosition;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An interface describing additional properties of the floating search results view used by the autocomplete plugin.
|
|
49
|
+
*/
|
|
50
|
+
export interface AutocompleteResultsView extends SearchResultsView {
|
|
51
|
+
/**
|
|
52
|
+
* Controls the visibility of the results view.
|
|
53
|
+
*
|
|
54
|
+
* @observable
|
|
55
|
+
*/
|
|
56
|
+
isVisible: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Controls the position (CSS class suffix) of the results view.
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
_position?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The observable property determining the CSS width of the results view.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
_width: number;
|
|
69
|
+
}
|
|
70
|
+
export interface AutocompleteViewConfig<TConfigInputCreator extends InputBase<HTMLInputElement | HTMLTextAreaElement>> extends SearchTextViewConfig<TConfigInputCreator> {
|
|
71
|
+
/**
|
|
72
|
+
* When set `true`, the query view will be reset when the autocomplete view loses focus.
|
|
73
|
+
*/
|
|
74
|
+
resetOnBlur?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Minimum number of characters that need to be typed before the search is performed.
|
|
77
|
+
*
|
|
78
|
+
* @default 0
|
|
79
|
+
*/
|
|
80
|
+
queryMinChars?: number;
|
|
81
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/autocomplete/autocompleteview
|
|
7
|
+
*/
|
|
8
|
+
import { getOptimalPosition, global, toUnit, Rect } from '@ckeditor/ckeditor5-utils';
|
|
9
|
+
import SearchTextView from '../search/text/searchtextview';
|
|
10
|
+
import '../../theme/components/autocomplete/autocomplete.css';
|
|
11
|
+
/**
|
|
12
|
+
* The autocomplete component's view class. It extends the {@link module:ui/search/text/searchtextview~SearchTextView} class
|
|
13
|
+
* with a floating {@link #resultsView} that shows up when the user starts typing and hides when they blur
|
|
14
|
+
* the component.
|
|
15
|
+
*/
|
|
16
|
+
export default class AutocompleteView extends SearchTextView {
|
|
17
|
+
/**
|
|
18
|
+
* @inheritDoc
|
|
19
|
+
*/
|
|
20
|
+
constructor(locale, config) {
|
|
21
|
+
super(locale, config);
|
|
22
|
+
this._config = config;
|
|
23
|
+
const toPx = toUnit('px');
|
|
24
|
+
this.extendTemplate({
|
|
25
|
+
attributes: {
|
|
26
|
+
class: ['ck-autocomplete']
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const bindResultsView = this.resultsView.bindTemplate;
|
|
30
|
+
this.resultsView.set('isVisible', false);
|
|
31
|
+
this.resultsView.set('_position', 's');
|
|
32
|
+
this.resultsView.set('_width', 0);
|
|
33
|
+
this.resultsView.extendTemplate({
|
|
34
|
+
attributes: {
|
|
35
|
+
class: [
|
|
36
|
+
bindResultsView.if('isVisible', 'ck-hidden', value => !value),
|
|
37
|
+
bindResultsView.to('_position', value => `ck-search__results_${value}`)
|
|
38
|
+
],
|
|
39
|
+
style: {
|
|
40
|
+
width: bindResultsView.to('_width', toPx)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
// Update the visibility of the results view when the user focuses or blurs the component.
|
|
45
|
+
// This is also integration for the `resetOnBlur` configuration.
|
|
46
|
+
this.focusTracker.on('change:isFocused', (evt, name, isFocused) => {
|
|
47
|
+
this._updateResultsVisibility();
|
|
48
|
+
if (isFocused) {
|
|
49
|
+
// Reset the scroll position of the results view whenever the autocomplete reopens.
|
|
50
|
+
this.resultsView.element.scrollTop = 0;
|
|
51
|
+
}
|
|
52
|
+
else if (config.resetOnBlur) {
|
|
53
|
+
this.queryView.reset();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
// Update the visibility of the results view when the user types in the query field.
|
|
57
|
+
// This is an integration for `queryMinChars` configuration.
|
|
58
|
+
// This is an integration for search results changing length and the #resultsView requiring to be repositioned.
|
|
59
|
+
this.on('search', () => {
|
|
60
|
+
this._updateResultsVisibility();
|
|
61
|
+
this._updateResultsViewWidthAndPosition();
|
|
62
|
+
});
|
|
63
|
+
// Hide the results view when the user presses the ESC key.
|
|
64
|
+
this.keystrokes.set('esc', (evt, cancel) => {
|
|
65
|
+
// Let the DOM event pass through if the focus is in the query view.
|
|
66
|
+
if (!this.resultsView.isVisible) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Focus the query view first and only then close the results view. Otherwise, if the focus
|
|
70
|
+
// was in the results view, it will get lost.
|
|
71
|
+
this.queryView.focus();
|
|
72
|
+
this.resultsView.isVisible = false;
|
|
73
|
+
cancel();
|
|
74
|
+
});
|
|
75
|
+
// Update the position of the results view when the user scrolls the page.
|
|
76
|
+
// TODO: This needs to be debounced down the road.
|
|
77
|
+
this.listenTo(global.document, 'scroll', () => {
|
|
78
|
+
this._updateResultsViewWidthAndPosition();
|
|
79
|
+
});
|
|
80
|
+
// Hide the results when the component becomes disabled.
|
|
81
|
+
this.on('change:isEnabled', () => {
|
|
82
|
+
this._updateResultsVisibility();
|
|
83
|
+
});
|
|
84
|
+
// Update the value of the query field when the user selects a result.
|
|
85
|
+
this.filteredView.on('execute', (evt, { value }) => {
|
|
86
|
+
// Focus the query view first to avoid losing the focus.
|
|
87
|
+
this.focus();
|
|
88
|
+
// Resetting the view will ensure that the #queryView will update its empty state correctly.
|
|
89
|
+
// This prevents bugs related to dynamic labels or auto-grow when re-setting the same value
|
|
90
|
+
// to #queryView.fieldView.value (which does not trigger empty state change) to an
|
|
91
|
+
// #queryView.fieldView.element that has been changed by the user.
|
|
92
|
+
this.reset();
|
|
93
|
+
// Update the value of the query field.
|
|
94
|
+
this.queryView.fieldView.value = this.queryView.fieldView.element.value = value;
|
|
95
|
+
// Finally, hide the results view. The focus has been moved earlier so this is safe.
|
|
96
|
+
this.resultsView.isVisible = false;
|
|
97
|
+
});
|
|
98
|
+
// Update the position and width of the results view when it becomes visible.
|
|
99
|
+
this.resultsView.on('change:isVisible', () => {
|
|
100
|
+
this._updateResultsViewWidthAndPosition();
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Updates the position of the results view on demand.
|
|
105
|
+
*/
|
|
106
|
+
_updateResultsViewWidthAndPosition() {
|
|
107
|
+
if (!this.resultsView.isVisible) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
this.resultsView._width = new Rect(this.queryView.fieldView.element).width;
|
|
111
|
+
const optimalResultsPosition = AutocompleteView._getOptimalPosition({
|
|
112
|
+
element: this.resultsView.element,
|
|
113
|
+
target: this.queryView.element,
|
|
114
|
+
fitInViewport: true,
|
|
115
|
+
positions: AutocompleteView.defaultResultsPositions
|
|
116
|
+
});
|
|
117
|
+
// _getOptimalPosition will return null if there is no optimal position found (e.g. target is off the viewport).
|
|
118
|
+
this.resultsView._position = optimalResultsPosition ? optimalResultsPosition.name : 's';
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Updates the visibility of the results view on demand.
|
|
122
|
+
*/
|
|
123
|
+
_updateResultsVisibility() {
|
|
124
|
+
const queryMinChars = typeof this._config.queryMinChars === 'undefined' ? 0 : this._config.queryMinChars;
|
|
125
|
+
const queryLength = this.queryView.fieldView.element.value.length;
|
|
126
|
+
this.resultsView.isVisible = this.focusTracker.isFocused && this.isEnabled && queryLength >= queryMinChars;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Positions for the autocomplete results view. Two positions are defined by default:
|
|
131
|
+
* * `s` - below the search field,
|
|
132
|
+
* * `n` - above the search field.
|
|
133
|
+
*/
|
|
134
|
+
AutocompleteView.defaultResultsPositions = [
|
|
135
|
+
(fieldRect => {
|
|
136
|
+
return {
|
|
137
|
+
top: fieldRect.bottom,
|
|
138
|
+
left: fieldRect.left,
|
|
139
|
+
name: 's'
|
|
140
|
+
};
|
|
141
|
+
}),
|
|
142
|
+
((fieldRect, resultsRect) => {
|
|
143
|
+
return {
|
|
144
|
+
top: fieldRect.top - resultsRect.height,
|
|
145
|
+
left: fieldRect.left,
|
|
146
|
+
name: 'n'
|
|
147
|
+
};
|
|
148
|
+
})
|
|
149
|
+
];
|
|
150
|
+
/**
|
|
151
|
+
* A function used to calculate the optimal position for the dropdown panel.
|
|
152
|
+
*/
|
|
153
|
+
AutocompleteView._getOptimalPosition = getOptimalPosition;
|
package/src/button/button.d.ts
CHANGED
|
@@ -135,12 +135,6 @@ export default interface Button {
|
|
|
135
135
|
* @observable
|
|
136
136
|
*/
|
|
137
137
|
class: string | undefined;
|
|
138
|
-
/**
|
|
139
|
-
* (Optional) The ARIA property reflected by the `aria-checked` DOM attribute used by assistive technologies.
|
|
140
|
-
*
|
|
141
|
-
* @observable
|
|
142
|
-
*/
|
|
143
|
-
ariaChecked?: boolean | undefined;
|
|
144
138
|
/**
|
|
145
139
|
* (Optional) The ARIA property reflected by the `aria-label` DOM attribute used by assistive technologies.
|
|
146
140
|
*
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/button/buttonlabel
|
|
7
|
+
*/
|
|
8
|
+
import type View from '../view';
|
|
9
|
+
/**
|
|
10
|
+
* The button label interface. Implemented by the {@link module:ui/button/buttonlabelview~ButtonLabelView}
|
|
11
|
+
* and any label view that can be used with the {@link module:ui/button/buttonview~ButtonView}.
|
|
12
|
+
*/
|
|
13
|
+
export default interface ButtonLabel extends View {
|
|
14
|
+
/**
|
|
15
|
+
* The `id` attribute of the button label. It is used for accessibility purposes
|
|
16
|
+
* to describe the button.
|
|
17
|
+
*
|
|
18
|
+
* @observable
|
|
19
|
+
*/
|
|
20
|
+
id: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The `style` attribute of the button label. It allows customizing the presentation
|
|
23
|
+
* of the label.
|
|
24
|
+
*
|
|
25
|
+
* @observable
|
|
26
|
+
*/
|
|
27
|
+
style: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* The human-readable text of the label.
|
|
30
|
+
*
|
|
31
|
+
* @observable
|
|
32
|
+
*/
|
|
33
|
+
text: string | undefined;
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/button/buttonlabelview
|
|
7
|
+
*/
|
|
8
|
+
import View from '../view';
|
|
9
|
+
import type ButtonLabel from './buttonlabel';
|
|
10
|
+
/**
|
|
11
|
+
* A default implementation of the button view's label. It comes with a dynamic text support
|
|
12
|
+
* via {@link module:ui/button/buttonlabelview~ButtonLabelView#text} property.
|
|
13
|
+
*/
|
|
14
|
+
export default class ButtonLabelView extends View implements ButtonLabel {
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
id: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
style: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
text: string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
constructor();
|
|
31
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ui/button/buttonlabelview
|
|
7
|
+
*/
|
|
8
|
+
import View from '../view';
|
|
9
|
+
/**
|
|
10
|
+
* A default implementation of the button view's label. It comes with a dynamic text support
|
|
11
|
+
* via {@link module:ui/button/buttonlabelview~ButtonLabelView#text} property.
|
|
12
|
+
*/
|
|
13
|
+
export default class ButtonLabelView extends View {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.set({
|
|
20
|
+
style: undefined,
|
|
21
|
+
text: undefined,
|
|
22
|
+
id: undefined
|
|
23
|
+
});
|
|
24
|
+
const bind = this.bindTemplate;
|
|
25
|
+
this.setTemplate({
|
|
26
|
+
tag: 'span',
|
|
27
|
+
attributes: {
|
|
28
|
+
class: [
|
|
29
|
+
'ck',
|
|
30
|
+
'ck-button__label'
|
|
31
|
+
],
|
|
32
|
+
style: bind.to('style'),
|
|
33
|
+
id: bind.to('id')
|
|
34
|
+
},
|
|
35
|
+
children: [
|
|
36
|
+
{
|
|
37
|
+
text: bind.to('text')
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -9,6 +9,7 @@ import View from '../view';
|
|
|
9
9
|
import IconView from '../icon/iconview';
|
|
10
10
|
import type ViewCollection from '../viewcollection';
|
|
11
11
|
import type { default as Button } from './button';
|
|
12
|
+
import type ButtonLabel from './buttonlabel';
|
|
12
13
|
import { type Locale } from '@ckeditor/ckeditor5-utils';
|
|
13
14
|
import '../../theme/components/button/button.css';
|
|
14
15
|
/**
|
|
@@ -35,9 +36,12 @@ export default class ButtonView extends View<HTMLButtonElement> implements Butto
|
|
|
35
36
|
*/
|
|
36
37
|
readonly children: ViewCollection;
|
|
37
38
|
/**
|
|
38
|
-
* Label of the button view.
|
|
39
|
+
* Label of the button view. Its text is configurable using the {@link #label label attribute}.
|
|
40
|
+
*
|
|
41
|
+
* If not configured otherwise in the `constructor()`, by default the label is an instance
|
|
42
|
+
* of {@link module:ui/button/buttonlabelview~ButtonLabelView}.
|
|
39
43
|
*/
|
|
40
|
-
readonly labelView:
|
|
44
|
+
readonly labelView: ButtonLabel;
|
|
41
45
|
/**
|
|
42
46
|
* The icon view of the button. Will be added to {@link #children} when the
|
|
43
47
|
* {@link #icon icon attribute} is defined.
|
|
@@ -113,10 +117,6 @@ export default class ButtonView extends View<HTMLButtonElement> implements Butto
|
|
|
113
117
|
* @inheritDoc
|
|
114
118
|
*/
|
|
115
119
|
role: string | undefined;
|
|
116
|
-
/**
|
|
117
|
-
* @inheritDoc
|
|
118
|
-
*/
|
|
119
|
-
ariaChecked: boolean | undefined;
|
|
120
120
|
/**
|
|
121
121
|
* @inheritDoc
|
|
122
122
|
*/
|
|
@@ -139,9 +139,13 @@ export default class ButtonView extends View<HTMLButtonElement> implements Butto
|
|
|
139
139
|
*/
|
|
140
140
|
private _focusDelayed;
|
|
141
141
|
/**
|
|
142
|
-
*
|
|
142
|
+
* Creates an instance of the button view class.
|
|
143
|
+
*
|
|
144
|
+
* @param locale The {@link module:core/editor/editor~Editor#locale} instance.
|
|
145
|
+
* @param labelView The instance of the button's label. If not provided, an instance of
|
|
146
|
+
* {@link module:ui/button/buttonlabelview~ButtonLabelView} is used.
|
|
143
147
|
*/
|
|
144
|
-
constructor(locale?: Locale);
|
|
148
|
+
constructor(locale?: Locale, labelView?: ButtonLabel);
|
|
145
149
|
/**
|
|
146
150
|
* @inheritDoc
|
|
147
151
|
*/
|
|
@@ -155,9 +159,9 @@ export default class ButtonView extends View<HTMLButtonElement> implements Butto
|
|
|
155
159
|
*/
|
|
156
160
|
destroy(): void;
|
|
157
161
|
/**
|
|
158
|
-
*
|
|
162
|
+
* Binds the label view instance it with button attributes.
|
|
159
163
|
*/
|
|
160
|
-
private
|
|
164
|
+
private _setupLabelView;
|
|
161
165
|
/**
|
|
162
166
|
* Creates a view that displays a keystroke next to a {@link #labelView label }
|
|
163
167
|
* and binds it with button attributes.
|