@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.
Files changed (136) hide show
  1. package/LICENSE.md +3 -3
  2. package/lang/contexts.json +5 -1
  3. package/lang/translations/ar.po +16 -0
  4. package/lang/translations/ast.po +16 -0
  5. package/lang/translations/az.po +16 -0
  6. package/lang/translations/bg.po +16 -0
  7. package/lang/translations/bn.po +16 -0
  8. package/lang/translations/ca.po +16 -0
  9. package/lang/translations/cs.po +16 -0
  10. package/lang/translations/da.po +16 -0
  11. package/lang/translations/de-ch.po +16 -0
  12. package/lang/translations/de.po +16 -0
  13. package/lang/translations/el.po +16 -0
  14. package/lang/translations/en-au.po +16 -0
  15. package/lang/translations/en-gb.po +16 -0
  16. package/lang/translations/en.po +16 -0
  17. package/lang/translations/eo.po +16 -0
  18. package/lang/translations/es.po +16 -0
  19. package/lang/translations/et.po +16 -0
  20. package/lang/translations/eu.po +16 -0
  21. package/lang/translations/fa.po +16 -0
  22. package/lang/translations/fi.po +16 -0
  23. package/lang/translations/fr.po +16 -0
  24. package/lang/translations/gl.po +16 -0
  25. package/lang/translations/he.po +16 -0
  26. package/lang/translations/hi.po +16 -0
  27. package/lang/translations/hr.po +16 -0
  28. package/lang/translations/hu.po +16 -0
  29. package/lang/translations/id.po +16 -0
  30. package/lang/translations/it.po +16 -0
  31. package/lang/translations/ja.po +16 -0
  32. package/lang/translations/km.po +16 -0
  33. package/lang/translations/kn.po +16 -0
  34. package/lang/translations/ko.po +16 -0
  35. package/lang/translations/ku.po +16 -0
  36. package/lang/translations/lt.po +16 -0
  37. package/lang/translations/lv.po +16 -0
  38. package/lang/translations/ms.po +16 -0
  39. package/lang/translations/nb.po +16 -0
  40. package/lang/translations/ne.po +16 -0
  41. package/lang/translations/nl.po +16 -0
  42. package/lang/translations/no.po +16 -0
  43. package/lang/translations/pl.po +16 -0
  44. package/lang/translations/pt-br.po +17 -1
  45. package/lang/translations/pt.po +16 -0
  46. package/lang/translations/ro.po +16 -0
  47. package/lang/translations/ru.po +16 -0
  48. package/lang/translations/sk.po +16 -0
  49. package/lang/translations/sl.po +16 -0
  50. package/lang/translations/sq.po +16 -0
  51. package/lang/translations/sr-latn.po +16 -0
  52. package/lang/translations/sr.po +16 -0
  53. package/lang/translations/sv.po +16 -0
  54. package/lang/translations/th.po +16 -0
  55. package/lang/translations/tk.po +16 -0
  56. package/lang/translations/tr.po +16 -0
  57. package/lang/translations/tt.po +16 -0
  58. package/lang/translations/ug.po +38 -22
  59. package/lang/translations/uk.po +16 -0
  60. package/lang/translations/ur.po +16 -0
  61. package/lang/translations/uz.po +16 -0
  62. package/lang/translations/vi.po +16 -0
  63. package/lang/translations/zh-cn.po +16 -0
  64. package/lang/translations/zh.po +16 -0
  65. package/package.json +3 -3
  66. package/src/arialiveannouncer.d.ts +94 -0
  67. package/src/arialiveannouncer.js +113 -0
  68. package/src/autocomplete/autocompleteview.d.ts +81 -0
  69. package/src/autocomplete/autocompleteview.js +153 -0
  70. package/src/button/button.d.ts +0 -6
  71. package/src/button/buttonlabel.d.ts +34 -0
  72. package/src/button/buttonlabel.js +5 -0
  73. package/src/button/buttonlabelview.d.ts +31 -0
  74. package/src/button/buttonlabelview.js +42 -0
  75. package/src/button/buttonview.d.ts +14 -10
  76. package/src/button/buttonview.js +11 -25
  77. package/src/dropdown/dropdownview.js +5 -4
  78. package/src/dropdown/utils.d.ts +15 -1
  79. package/src/dropdown/utils.js +47 -21
  80. package/src/editorui/editorui.d.ts +6 -0
  81. package/src/editorui/editorui.js +2 -0
  82. package/src/editorui/poweredby.js +14 -37
  83. package/src/focuscycler.d.ts +45 -2
  84. package/src/focuscycler.js +34 -9
  85. package/src/formheader/formheaderview.d.ts +6 -0
  86. package/src/formheader/formheaderview.js +6 -0
  87. package/src/highlightedtext/highlightedtextview.d.ts +38 -0
  88. package/src/highlightedtext/highlightedtextview.js +102 -0
  89. package/src/icon/iconview.d.ts +7 -0
  90. package/src/icon/iconview.js +2 -0
  91. package/src/index.d.ts +12 -2
  92. package/src/index.js +8 -0
  93. package/src/input/inputbase.d.ts +107 -0
  94. package/src/input/inputbase.js +110 -0
  95. package/src/input/inputview.d.ts +4 -89
  96. package/src/input/inputview.js +5 -87
  97. package/src/labeledfield/labeledfieldview.d.ts +7 -2
  98. package/src/labeledfield/labeledfieldview.js +2 -2
  99. package/src/labeledfield/utils.d.ts +34 -4
  100. package/src/labeledfield/utils.js +51 -6
  101. package/src/list/listitemgroupview.d.ts +59 -0
  102. package/src/list/listitemgroupview.js +63 -0
  103. package/src/list/listitemview.d.ts +2 -1
  104. package/src/list/listitemview.js +3 -1
  105. package/src/list/listview.d.ts +59 -2
  106. package/src/list/listview.js +105 -8
  107. package/src/panel/balloon/balloonpanelview.js +26 -4
  108. package/src/panel/sticky/stickypanelview.d.ts +1 -3
  109. package/src/panel/sticky/stickypanelview.js +53 -50
  110. package/src/search/filteredview.d.ts +31 -0
  111. package/src/search/filteredview.js +5 -0
  112. package/src/search/searchinfoview.d.ts +45 -0
  113. package/src/search/searchinfoview.js +59 -0
  114. package/src/search/searchresultsview.d.ts +54 -0
  115. package/src/search/searchresultsview.js +65 -0
  116. package/src/search/text/searchtextqueryview.d.ts +76 -0
  117. package/src/search/text/searchtextqueryview.js +75 -0
  118. package/src/search/text/searchtextview.d.ts +219 -0
  119. package/src/search/text/searchtextview.js +201 -0
  120. package/src/spinner/spinnerview.d.ts +25 -0
  121. package/src/spinner/spinnerview.js +38 -0
  122. package/src/textarea/textareaview.d.ts +88 -0
  123. package/src/textarea/textareaview.js +142 -0
  124. package/src/toolbar/block/blocktoolbar.js +30 -26
  125. package/src/toolbar/normalizetoolbarconfig.d.ts +1 -0
  126. package/src/toolbar/normalizetoolbarconfig.js +9 -8
  127. package/src/toolbar/toolbarview.d.ts +1 -0
  128. package/src/toolbar/toolbarview.js +4 -2
  129. package/theme/components/arialiveannouncer/arialiveannouncer.css +10 -0
  130. package/theme/components/autocomplete/autocomplete.css +22 -0
  131. package/theme/components/button/button.css +9 -1
  132. package/theme/components/formheader/formheader.css +4 -0
  133. package/theme/components/highlightedtext/highlightedtext.css +12 -0
  134. package/theme/components/search/search.css +43 -0
  135. package/theme/components/spinner/spinner.css +23 -0
  136. package/theme/components/textarea/textarea.css +10 -0
@@ -0,0 +1,102 @@
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/highlightedtext/highlightedtextview
7
+ */
8
+ import View from '../view';
9
+ import { escape } from 'lodash-es';
10
+ import '../../theme/components/highlightedtext/highlightedtext.css';
11
+ /**
12
+ * A class representing a view that displays a text which subset can be highlighted using the
13
+ * {@link #highlightText} method.
14
+ */
15
+ export default class HighlightedTextView extends View {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ constructor() {
20
+ super();
21
+ this.set('text', undefined);
22
+ this.setTemplate({
23
+ tag: 'span',
24
+ attributes: {
25
+ class: ['ck', 'ck-highlighted-text']
26
+ }
27
+ });
28
+ this.on('render', () => {
29
+ // Classic setTemplate binding for #text will not work because highlightText() replaces the
30
+ // pre-rendered DOM text node new a new one (and <mark> elements).
31
+ this.on('change:text', () => {
32
+ this._updateInnerHTML(this.text);
33
+ });
34
+ this._updateInnerHTML(this.text);
35
+ });
36
+ }
37
+ /**
38
+ * Highlights view's {@link #text} according to the specified `RegExp`. If the passed RegExp is `null`, the
39
+ * highlighting is removed
40
+ *
41
+ * @param regExp
42
+ */
43
+ highlightText(regExp) {
44
+ this._updateInnerHTML(markText(this.text || '', regExp));
45
+ }
46
+ /**
47
+ * Updates element's `innerHTML` with the passed content.
48
+ */
49
+ _updateInnerHTML(newInnerHTML) {
50
+ this.element.innerHTML = newInnerHTML || '';
51
+ }
52
+ }
53
+ /**
54
+ * Replaces `regExp` occurrences with `<mark>` tags in a text.
55
+ *
56
+ * @param text A text to get marked.
57
+ * @param regExp An optional `RegExp`. If not passed, this is a pass-through function.
58
+ * @returns A text with `RegExp` occurrences marked by `<mark>`.
59
+ */
60
+ function markText(text, regExp) {
61
+ if (!regExp) {
62
+ return escape(text);
63
+ }
64
+ const textParts = [];
65
+ let lastMatchEnd = 0;
66
+ let matchInfo = regExp.exec(text);
67
+ // Iterate over all matches and create an array of text parts. The idea is to mark which parts are query matches
68
+ // so that later on they can be highlighted.
69
+ while (matchInfo !== null) {
70
+ const curMatchStart = matchInfo.index;
71
+ // Detect if there was something between last match and this one.
72
+ if (curMatchStart !== lastMatchEnd) {
73
+ textParts.push({
74
+ text: text.substring(lastMatchEnd, curMatchStart),
75
+ isMatch: false
76
+ });
77
+ }
78
+ textParts.push({
79
+ text: matchInfo[0],
80
+ isMatch: true
81
+ });
82
+ lastMatchEnd = regExp.lastIndex;
83
+ matchInfo = regExp.exec(text);
84
+ }
85
+ // Your match might not be the last part of a string. Be sure to add any plain text following the last match.
86
+ if (lastMatchEnd !== text.length) {
87
+ textParts.push({
88
+ text: text.substring(lastMatchEnd),
89
+ isMatch: false
90
+ });
91
+ }
92
+ const outputHtml = textParts
93
+ // The entire text should be escaped.
94
+ .map(part => {
95
+ part.text = escape(part.text);
96
+ return part;
97
+ })
98
+ // Only matched text should be wrapped with HTML mark element.
99
+ .map(part => part.isMatch ? `<mark>${part.text}</mark>` : part.text)
100
+ .join('');
101
+ return outputHtml;
102
+ }
@@ -52,6 +52,13 @@ export default class IconView extends View {
52
52
  * @default true
53
53
  */
54
54
  isColorInherited: boolean;
55
+ /**
56
+ * Controls whether the icon is visible.
57
+ *
58
+ * @observable
59
+ * @default true
60
+ */
61
+ isVisible: boolean;
55
62
  /**
56
63
  * A list of presentational attributes that can be set on the `<svg>` element and should be preserved
57
64
  * when the icon {@link module:ui/icon/iconview~IconView#content content} is loaded.
@@ -22,6 +22,7 @@ export default class IconView extends View {
22
22
  this.set('viewBox', '0 0 20 20');
23
23
  this.set('fillColor', '');
24
24
  this.set('isColorInherited', true);
25
+ this.set('isVisible', true);
25
26
  this.setTemplate({
26
27
  tag: 'svg',
27
28
  ns: 'http://www.w3.org/2000/svg',
@@ -29,6 +30,7 @@ export default class IconView extends View {
29
30
  class: [
30
31
  'ck',
31
32
  'ck-icon',
33
+ bind.if('isVisible', 'ck-hidden', value => !value),
32
34
  // Exclude icon internals from the CSS reset to allow rich (non-monochromatic) icons
33
35
  // (https://github.com/ckeditor/ckeditor5/issues/12599).
34
36
  'ck-reset_all-excluded',
package/src/index.d.ts CHANGED
@@ -12,7 +12,9 @@ export { default as submitHandler } from './bindings/submithandler';
12
12
  export { default as addKeyboardHandlingForGrid } from './bindings/addkeyboardhandlingforgrid';
13
13
  export { default as BodyCollection } from './editorui/bodycollection';
14
14
  export { type ButtonExecuteEvent } from './button/button';
15
+ export { type default as ButtonLabel } from './button/buttonlabel';
15
16
  export { default as ButtonView } from './button/buttonview';
17
+ export { default as ButtonLabelView } from './button/buttonlabelview';
16
18
  export { default as SwitchButtonView } from './button/switchbuttonview';
17
19
  export * from './colorgrid/utils';
18
20
  export { default as ColorGridView, type ColorDefinition } from './colorgrid/colorgridview';
@@ -31,15 +33,17 @@ export { default as EditorUIView } from './editorui/editoruiview';
31
33
  export { default as BoxedEditorUIView } from './editorui/boxed/boxededitoruiview';
32
34
  export { default as InlineEditableUIView } from './editableui/inline/inlineeditableuiview';
33
35
  export { default as FormHeaderView } from './formheader/formheaderview';
34
- export { default as FocusCycler, type FocusableView } from './focuscycler';
36
+ export { default as FocusCycler, type FocusableView, type FocusCyclerForwardCycleEvent, type FocusCyclerBackwardCycleEvent } from './focuscycler';
35
37
  export { default as IconView } from './icon/iconview';
36
38
  export { default as InputView } from './input/inputview';
37
39
  export { default as InputTextView } from './inputtext/inputtextview';
38
40
  export { default as InputNumberView } from './inputnumber/inputnumberview';
41
+ export { default as TextareaView, type TextareaViewUpdateEvent } from './textarea/textareaview';
39
42
  export { default as IframeView } from './iframe/iframeview';
40
43
  export { default as LabelView } from './label/labelview';
41
- export { default as LabeledFieldView } from './labeledfield/labeledfieldview';
44
+ export { type LabeledFieldViewCreator, default as LabeledFieldView } from './labeledfield/labeledfieldview';
42
45
  export * from './labeledfield/utils';
46
+ export { default as ListItemGroupView } from './list/listitemgroupview';
43
47
  export { default as ListItemView } from './list/listitemview';
44
48
  export { default as ListView } from './list/listview';
45
49
  export { default as Notification } from './notification/notification';
@@ -47,8 +51,14 @@ export { default as Model } from './model';
47
51
  export { default as BalloonPanelView } from './panel/balloon/balloonpanelview';
48
52
  export { default as ContextualBalloon } from './panel/balloon/contextualballoon';
49
53
  export { default as StickyPanelView } from './panel/sticky/stickypanelview';
54
+ export { default as AutocompleteView, type AutocompleteViewConfig, type AutocompleteResultsView } from './autocomplete/autocompleteview';
55
+ export { default as SearchTextView, type SearchTextViewSearchEvent, type SearchTextViewConfig } from './search/text/searchtextview';
56
+ export { default as SearchInfoView } from './search/searchinfoview';
57
+ export { default as FilteredView, type FilteredViewExecuteEvent } from './search/filteredview';
58
+ export { default as HighlightedTextView } from './highlightedtext/highlightedtextview';
50
59
  export { default as TooltipManager } from './tooltipmanager';
51
60
  export { default as Template, type TemplateDefinition } from './template';
61
+ export { default as SpinnerView } from './spinner/spinnerview';
52
62
  export { default as ToolbarView } from './toolbar/toolbarview';
53
63
  export { default as ToolbarLineBreakView } from './toolbar/toolbarlinebreakview';
54
64
  export { default as ToolbarSeparatorView } from './toolbar/toolbarseparatorview';
package/src/index.js CHANGED
@@ -12,6 +12,7 @@ export { default as submitHandler } from './bindings/submithandler';
12
12
  export { default as addKeyboardHandlingForGrid } from './bindings/addkeyboardhandlingforgrid';
13
13
  export { default as BodyCollection } from './editorui/bodycollection';
14
14
  export { default as ButtonView } from './button/buttonview';
15
+ export { default as ButtonLabelView } from './button/buttonlabelview';
15
16
  export { default as SwitchButtonView } from './button/switchbuttonview';
16
17
  export * from './colorgrid/utils';
17
18
  export { default as ColorGridView } from './colorgrid/colorgridview';
@@ -34,10 +35,12 @@ export { default as IconView } from './icon/iconview';
34
35
  export { default as InputView } from './input/inputview';
35
36
  export { default as InputTextView } from './inputtext/inputtextview';
36
37
  export { default as InputNumberView } from './inputnumber/inputnumberview';
38
+ export { default as TextareaView } from './textarea/textareaview';
37
39
  export { default as IframeView } from './iframe/iframeview';
38
40
  export { default as LabelView } from './label/labelview';
39
41
  export { default as LabeledFieldView } from './labeledfield/labeledfieldview';
40
42
  export * from './labeledfield/utils';
43
+ export { default as ListItemGroupView } from './list/listitemgroupview';
41
44
  export { default as ListItemView } from './list/listitemview';
42
45
  export { default as ListView } from './list/listview';
43
46
  export { default as Notification } from './notification/notification';
@@ -45,8 +48,13 @@ export { default as Model } from './model';
45
48
  export { default as BalloonPanelView } from './panel/balloon/balloonpanelview';
46
49
  export { default as ContextualBalloon } from './panel/balloon/contextualballoon';
47
50
  export { default as StickyPanelView } from './panel/sticky/stickypanelview';
51
+ export { default as AutocompleteView } from './autocomplete/autocompleteview';
52
+ export { default as SearchTextView } from './search/text/searchtextview';
53
+ export { default as SearchInfoView } from './search/searchinfoview';
54
+ export { default as HighlightedTextView } from './highlightedtext/highlightedtextview';
48
55
  export { default as TooltipManager } from './tooltipmanager';
49
56
  export { default as Template } from './template';
57
+ export { default as SpinnerView } from './spinner/spinnerview';
50
58
  export { default as ToolbarView } from './toolbar/toolbarview';
51
59
  export { default as ToolbarLineBreakView } from './toolbar/toolbarlinebreakview';
52
60
  export { default as ToolbarSeparatorView } from './toolbar/toolbarseparatorview';
@@ -0,0 +1,107 @@
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/input/inputbase
7
+ */
8
+ import View from '../view';
9
+ import { FocusTracker, type Locale } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * The base input view class.
12
+ */
13
+ export default abstract class InputBase<TElement extends HTMLInputElement | HTMLTextAreaElement = HTMLInputElement> extends View<TElement> {
14
+ /**
15
+ * Stores information about the editor UI focus and propagates it so various plugins and components
16
+ * are unified as a focus group.
17
+ */
18
+ readonly focusTracker: FocusTracker;
19
+ /**
20
+ * The value of the input.
21
+ *
22
+ * @observable
23
+ */
24
+ value: string | undefined;
25
+ /**
26
+ * The `id` attribute of the input (i.e. to pair with a `<label>` element).
27
+ *
28
+ * @observable
29
+ */
30
+ id: string | undefined;
31
+ /**
32
+ * The `placeholder` attribute of the input.
33
+ *
34
+ * @observable
35
+ */
36
+ placeholder: string | undefined;
37
+ /**
38
+ * Controls whether the input view is in read-only mode.
39
+ *
40
+ * @observable
41
+ */
42
+ isReadOnly: boolean;
43
+ /**
44
+ * Set to `true` when the field has some error. Usually controlled via
45
+ * {@link module:ui/labeledinput/labeledinputview~LabeledInputView#errorText}.
46
+ *
47
+ * @observable
48
+ */
49
+ hasError: boolean;
50
+ /**
51
+ * The `id` of the element describing this field, e.g. when it has
52
+ * some error; it helps screen readers read the error text.
53
+ *
54
+ * @observable
55
+ */
56
+ ariaDescribedById: string | undefined;
57
+ /**
58
+ * An observable flag set to `true` when the input is currently focused by the user.
59
+ * Set to `false` otherwise.
60
+ *
61
+ * @readonly
62
+ * @observable
63
+ * @default false
64
+ */
65
+ isFocused: boolean;
66
+ /**
67
+ * An observable flag set to `true` when the input contains no text, i.e.
68
+ * when {@link #value} is `''`, `null`, or `false`.
69
+ *
70
+ * @readonly
71
+ * @observable
72
+ * @default true
73
+ */
74
+ isEmpty: boolean;
75
+ /**
76
+ * @inheritDoc
77
+ */
78
+ constructor(locale?: Locale);
79
+ /**
80
+ * @inheritDoc
81
+ */
82
+ render(): void;
83
+ /**
84
+ * @inheritDoc
85
+ */
86
+ destroy(): void;
87
+ /**
88
+ * Moves the focus to the input and selects the value.
89
+ */
90
+ select(): void;
91
+ /**
92
+ * Focuses the input.
93
+ */
94
+ focus(): void;
95
+ /**
96
+ * Resets the value of the input
97
+ */
98
+ reset(): void;
99
+ /**
100
+ * Updates the {@link #isEmpty} property value on demand.
101
+ */
102
+ protected _updateIsEmpty(): void;
103
+ /**
104
+ * Sets the `value` property of the {@link #element DOM element} on demand.
105
+ */
106
+ private _setDomElementValue;
107
+ }
@@ -0,0 +1,110 @@
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/input/inputbase
7
+ */
8
+ import View from '../view';
9
+ import { FocusTracker } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * The base input view class.
12
+ */
13
+ export default class InputBase extends View {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ constructor(locale) {
18
+ super(locale);
19
+ this.set('value', undefined);
20
+ this.set('id', undefined);
21
+ this.set('placeholder', undefined);
22
+ this.set('isReadOnly', false);
23
+ this.set('hasError', false);
24
+ this.set('ariaDescribedById', undefined);
25
+ this.focusTracker = new FocusTracker();
26
+ this.bind('isFocused').to(this.focusTracker);
27
+ this.set('isEmpty', true);
28
+ const bind = this.bindTemplate;
29
+ this.setTemplate({
30
+ tag: 'input',
31
+ attributes: {
32
+ class: [
33
+ 'ck',
34
+ 'ck-input',
35
+ bind.if('isFocused', 'ck-input_focused'),
36
+ bind.if('isEmpty', 'ck-input-text_empty'),
37
+ bind.if('hasError', 'ck-error')
38
+ ],
39
+ id: bind.to('id'),
40
+ placeholder: bind.to('placeholder'),
41
+ readonly: bind.to('isReadOnly'),
42
+ 'aria-invalid': bind.if('hasError', true),
43
+ 'aria-describedby': bind.to('ariaDescribedById')
44
+ },
45
+ on: {
46
+ input: bind.to((...args) => {
47
+ this.fire('input', ...args);
48
+ this._updateIsEmpty();
49
+ }),
50
+ change: bind.to(this._updateIsEmpty.bind(this))
51
+ }
52
+ });
53
+ }
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ render() {
58
+ super.render();
59
+ this.focusTracker.add(this.element);
60
+ this._setDomElementValue(this.value);
61
+ this._updateIsEmpty();
62
+ // Bind `this.value` to the DOM element's value.
63
+ // We cannot use `value` DOM attribute because removing it on Edge does not clear the DOM element's value property.
64
+ this.on('change:value', (evt, name, value) => {
65
+ this._setDomElementValue(value);
66
+ this._updateIsEmpty();
67
+ });
68
+ }
69
+ /**
70
+ * @inheritDoc
71
+ */
72
+ destroy() {
73
+ super.destroy();
74
+ this.focusTracker.destroy();
75
+ }
76
+ /**
77
+ * Moves the focus to the input and selects the value.
78
+ */
79
+ select() {
80
+ this.element.select();
81
+ }
82
+ /**
83
+ * Focuses the input.
84
+ */
85
+ focus() {
86
+ this.element.focus();
87
+ }
88
+ /**
89
+ * Resets the value of the input
90
+ */
91
+ reset() {
92
+ this.value = this.element.value = '';
93
+ this._updateIsEmpty();
94
+ }
95
+ /**
96
+ * Updates the {@link #isEmpty} property value on demand.
97
+ */
98
+ _updateIsEmpty() {
99
+ this.isEmpty = isInputElementEmpty(this.element);
100
+ }
101
+ /**
102
+ * Sets the `value` property of the {@link #element DOM element} on demand.
103
+ */
104
+ _setDomElementValue(value) {
105
+ this.element.value = (!value && value !== 0) ? '' : value;
106
+ }
107
+ }
108
+ function isInputElementEmpty(domElement) {
109
+ return !domElement.value;
110
+ }
@@ -5,74 +5,13 @@
5
5
  /**
6
6
  * @module ui/input/inputview
7
7
  */
8
- import View from '../view';
9
- import { FocusTracker, type Locale } from '@ckeditor/ckeditor5-utils';
8
+ import { type Locale } from '@ckeditor/ckeditor5-utils';
9
+ import InputBase from './inputbase';
10
10
  import '../../theme/components/input/input.css';
11
11
  /**
12
- * The base input view class.
12
+ * The input view class.
13
13
  */
14
- export default class InputView extends View<HTMLInputElement> {
15
- /**
16
- * Stores information about the editor UI focus and propagates it so various plugins and components
17
- * are unified as a focus group.
18
- */
19
- readonly focusTracker: FocusTracker;
20
- /**
21
- * The value of the input.
22
- *
23
- * @observable
24
- */
25
- value: string | undefined;
26
- /**
27
- * The `id` attribute of the input (i.e. to pair with a `<label>` element).
28
- *
29
- * @observable
30
- */
31
- id: string | undefined;
32
- /**
33
- * The `placeholder` attribute of the input.
34
- *
35
- * @observable
36
- */
37
- placeholder: string | undefined;
38
- /**
39
- * Controls whether the input view is in read-only mode.
40
- *
41
- * @observable
42
- */
43
- isReadOnly: boolean;
44
- /**
45
- * Set to `true` when the field has some error. Usually controlled via
46
- * {@link module:ui/labeledinput/labeledinputview~LabeledInputView#errorText}.
47
- *
48
- * @observable
49
- */
50
- hasError: boolean;
51
- /**
52
- * The `id` of the element describing this field, e.g. when it has
53
- * some error; it helps screen readers read the error text.
54
- *
55
- * @observable
56
- */
57
- ariaDescribedById: string | undefined;
58
- /**
59
- * An observable flag set to `true` when the input is currently focused by the user.
60
- * Set to `false` otherwise.
61
- *
62
- * @readonly
63
- * @observable
64
- * @default false
65
- */
66
- isFocused: boolean;
67
- /**
68
- * An observable flag set to `true` when the input contains no text, i.e.
69
- * when {@link #value} is `''`, `null`, or `false`.
70
- *
71
- * @readonly
72
- * @observable
73
- * @default true
74
- */
75
- isEmpty: boolean;
14
+ export default class InputView extends InputBase {
76
15
  /**
77
16
  * Corresponds to the `inputmode` DOM attribute. Can be `text`, `numeric`, `decimal`, etc.
78
17
  *
@@ -84,30 +23,6 @@ export default class InputView extends View<HTMLInputElement> {
84
23
  * @inheritDoc
85
24
  */
86
25
  constructor(locale?: Locale);
87
- /**
88
- * @inheritDoc
89
- */
90
- render(): void;
91
- /**
92
- * @inheritDoc
93
- */
94
- destroy(): void;
95
- /**
96
- * Moves the focus to the input and selects the value.
97
- */
98
- select(): void;
99
- /**
100
- * Focuses the input.
101
- */
102
- focus(): void;
103
- /**
104
- * Updates the {@link #isEmpty} property value on demand.
105
- */
106
- private _updateIsEmpty;
107
- /**
108
- * Sets the `value` property of the {@link #element DOM element} on demand.
109
- */
110
- private _setDomElementValue;
111
26
  }
112
27
  /**
113
28
  * Fired when the user types in the input. Corresponds to the native
@@ -2,105 +2,23 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
- /**
6
- * @module ui/input/inputview
7
- */
8
- import View from '../view';
9
- import { FocusTracker } from '@ckeditor/ckeditor5-utils';
5
+ import InputBase from './inputbase';
10
6
  import '../../theme/components/input/input.css';
11
7
  /**
12
- * The base input view class.
8
+ * The input view class.
13
9
  */
14
- export default class InputView extends View {
10
+ export default class InputView extends InputBase {
15
11
  /**
16
12
  * @inheritDoc
17
13
  */
18
14
  constructor(locale) {
19
15
  super(locale);
20
- this.set('value', undefined);
21
- this.set('id', undefined);
22
- this.set('placeholder', undefined);
23
- this.set('isReadOnly', false);
24
- this.set('hasError', false);
25
- this.set('ariaDescribedById', undefined);
26
- this.focusTracker = new FocusTracker();
27
- this.bind('isFocused').to(this.focusTracker);
28
- this.set('isEmpty', true);
29
16
  this.set('inputMode', 'text');
30
17
  const bind = this.bindTemplate;
31
- this.setTemplate({
32
- tag: 'input',
18
+ this.extendTemplate({
33
19
  attributes: {
34
- class: [
35
- 'ck',
36
- 'ck-input',
37
- bind.if('isFocused', 'ck-input_focused'),
38
- bind.if('isEmpty', 'ck-input-text_empty'),
39
- bind.if('hasError', 'ck-error')
40
- ],
41
- id: bind.to('id'),
42
- placeholder: bind.to('placeholder'),
43
- readonly: bind.to('isReadOnly'),
44
- inputmode: bind.to('inputMode'),
45
- 'aria-invalid': bind.if('hasError', true),
46
- 'aria-describedby': bind.to('ariaDescribedById')
47
- },
48
- on: {
49
- input: bind.to((...args) => {
50
- this.fire('input', ...args);
51
- this._updateIsEmpty();
52
- }),
53
- change: bind.to(this._updateIsEmpty.bind(this))
20
+ inputmode: bind.to('inputMode')
54
21
  }
55
22
  });
56
23
  }
57
- /**
58
- * @inheritDoc
59
- */
60
- render() {
61
- super.render();
62
- this.focusTracker.add(this.element);
63
- this._setDomElementValue(this.value);
64
- this._updateIsEmpty();
65
- // Bind `this.value` to the DOM element's value.
66
- // We cannot use `value` DOM attribute because removing it on Edge does not clear the DOM element's value property.
67
- this.on('change:value', (evt, name, value) => {
68
- this._setDomElementValue(value);
69
- this._updateIsEmpty();
70
- });
71
- }
72
- /**
73
- * @inheritDoc
74
- */
75
- destroy() {
76
- super.destroy();
77
- this.focusTracker.destroy();
78
- }
79
- /**
80
- * Moves the focus to the input and selects the value.
81
- */
82
- select() {
83
- this.element.select();
84
- }
85
- /**
86
- * Focuses the input.
87
- */
88
- focus() {
89
- this.element.focus();
90
- }
91
- /**
92
- * Updates the {@link #isEmpty} property value on demand.
93
- */
94
- _updateIsEmpty() {
95
- this.isEmpty = isInputElementEmpty(this.element);
96
- }
97
- /**
98
- * Sets the `value` property of the {@link #element DOM element} on demand.
99
- */
100
- _setDomElementValue(value) {
101
- this.element.value = (!value && value !== 0) ? '' : value;
102
- }
103
- }
104
- function isInputElementEmpty(domElement) {
105
- return !domElement.value;
106
24
  }
@@ -160,7 +160,7 @@ export default class LabeledFieldView<TFieldView extends FocusableView = Focusab
160
160
  * * an UID string that connects the {@link #labelView label} and the labeled field view in DOM,
161
161
  * * an UID string that connects the {@link #statusView status} and the labeled field view in DOM.
162
162
  */
163
- constructor(locale: Locale | undefined, viewCreator: (labeledFieldView: LabeledFieldView, viewUid: string, statusUid: string) => TFieldView);
163
+ constructor(locale: Locale | undefined, viewCreator: LabeledFieldViewCreator<TFieldView>);
164
164
  /**
165
165
  * Creates label view class instance and bind with view.
166
166
  *
@@ -178,5 +178,10 @@ export default class LabeledFieldView<TFieldView extends FocusableView = Focusab
178
178
  /**
179
179
  * Focuses the {@link #fieldView}.
180
180
  */
181
- focus(): void;
181
+ focus(direction?: 1 | -1): void;
182
182
  }
183
+ /**
184
+ * A creator function that returns a focusable view to be labeled by a {@link module:ui/labeledfield/labeledfieldview~LabeledFieldView}
185
+ * instance.
186
+ */
187
+ export type LabeledFieldViewCreator<TFieldView extends FocusableView> = (labeledFieldView: LabeledFieldView, viewUid: string, statusUid: string) => TFieldView;
@@ -151,7 +151,7 @@ export default class LabeledFieldView extends View {
151
151
  /**
152
152
  * Focuses the {@link #fieldView}.
153
153
  */
154
- focus() {
155
- this.fieldView.focus();
154
+ focus(direction) {
155
+ this.fieldView.focus(direction);
156
156
  }
157
157
  }