@ckeditor/ckeditor5-ui 36.0.1 → 37.0.0-alpha.1

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 (114) hide show
  1. package/package.json +24 -23
  2. package/src/augmentation.d.ts +86 -0
  3. package/src/augmentation.js +5 -0
  4. package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -0
  5. package/src/bindings/addkeyboardhandlingforgrid.js +42 -34
  6. package/src/bindings/clickoutsidehandler.d.ts +28 -0
  7. package/src/bindings/clickoutsidehandler.js +5 -6
  8. package/src/bindings/csstransitiondisablermixin.d.ts +40 -0
  9. package/src/bindings/csstransitiondisablermixin.js +55 -0
  10. package/src/bindings/injectcsstransitiondisabler.d.ts +59 -0
  11. package/src/bindings/injectcsstransitiondisabler.js +23 -20
  12. package/src/bindings/preventdefault.d.ts +33 -0
  13. package/src/bindings/preventdefault.js +13 -15
  14. package/src/bindings/submithandler.d.ts +57 -0
  15. package/src/bindings/submithandler.js +23 -24
  16. package/src/button/button.d.ts +154 -0
  17. package/src/button/buttonview.d.ts +155 -0
  18. package/src/button/buttonview.js +16 -60
  19. package/src/button/switchbuttonview.d.ts +45 -0
  20. package/src/button/switchbuttonview.js +9 -18
  21. package/src/colorgrid/colorgridview.d.ts +132 -0
  22. package/src/colorgrid/colorgridview.js +13 -44
  23. package/src/colorgrid/colortileview.d.ts +28 -0
  24. package/src/colorgrid/colortileview.js +2 -15
  25. package/src/colorgrid/utils.d.ts +47 -0
  26. package/src/colorgrid/utils.js +7 -13
  27. package/src/componentfactory.d.ts +81 -0
  28. package/src/componentfactory.js +22 -36
  29. package/src/dropdown/button/dropdownbutton.d.ts +25 -0
  30. package/src/dropdown/button/dropdownbuttonview.d.ts +48 -0
  31. package/src/dropdown/button/dropdownbuttonview.js +11 -21
  32. package/src/dropdown/button/splitbuttonview.d.ts +145 -0
  33. package/src/dropdown/button/splitbuttonview.js +11 -52
  34. package/src/dropdown/dropdownpanelfocusable.d.ts +21 -0
  35. package/src/dropdown/dropdownpanelview.d.ts +62 -0
  36. package/src/dropdown/dropdownpanelview.js +2 -30
  37. package/src/dropdown/dropdownview.d.ts +315 -0
  38. package/src/dropdown/dropdownview.js +121 -222
  39. package/src/dropdown/utils.d.ts +219 -0
  40. package/src/dropdown/utils.js +112 -106
  41. package/src/editableui/editableuiview.d.ts +72 -0
  42. package/src/editableui/editableuiview.js +16 -44
  43. package/src/editableui/inline/inlineeditableuiview.d.ts +40 -0
  44. package/src/editableui/inline/inlineeditableuiview.js +5 -15
  45. package/src/editorui/bodycollection.d.ts +51 -0
  46. package/src/editorui/bodycollection.js +2 -16
  47. package/src/editorui/boxed/boxededitoruiview.d.ts +40 -0
  48. package/src/editorui/boxed/boxededitoruiview.js +1 -27
  49. package/src/editorui/editorui.d.ts +263 -0
  50. package/src/editorui/editorui.js +27 -134
  51. package/src/editorui/editoruiview.d.ts +39 -0
  52. package/src/editorui/editoruiview.js +1 -10
  53. package/src/focuscycler.d.ts +183 -0
  54. package/src/focuscycler.js +34 -90
  55. package/src/formheader/formheaderview.d.ts +53 -0
  56. package/src/formheader/formheaderview.js +3 -24
  57. package/src/icon/iconview.d.ts +78 -0
  58. package/src/icon/iconview.js +0 -50
  59. package/src/iframe/iframeview.d.ts +50 -0
  60. package/src/iframe/iframeview.js +2 -2
  61. package/src/index.d.ts +55 -0
  62. package/src/index.js +2 -0
  63. package/src/input/inputview.d.ts +121 -0
  64. package/src/input/inputview.js +0 -82
  65. package/src/inputnumber/inputnumberview.d.ts +49 -0
  66. package/src/inputnumber/inputnumberview.js +5 -28
  67. package/src/inputtext/inputtextview.d.ts +18 -0
  68. package/src/inputtext/inputtextview.js +0 -2
  69. package/src/label/labelview.d.ts +36 -0
  70. package/src/label/labelview.js +0 -20
  71. package/src/labeledfield/labeledfieldview.d.ts +182 -0
  72. package/src/labeledfield/labeledfieldview.js +20 -126
  73. package/src/labeledfield/utils.d.ts +93 -0
  74. package/src/labeledfield/utils.js +24 -18
  75. package/src/labeledinput/labeledinputview.d.ts +125 -0
  76. package/src/labeledinput/labeledinputview.js +7 -90
  77. package/src/list/listitemview.d.ts +35 -0
  78. package/src/list/listitemview.js +0 -16
  79. package/src/list/listseparatorview.d.ts +18 -0
  80. package/src/list/listseparatorview.js +0 -2
  81. package/src/list/listview.d.ts +59 -0
  82. package/src/list/listview.js +0 -33
  83. package/src/model.d.ts +22 -0
  84. package/src/model.js +2 -4
  85. package/src/notification/notification.d.ts +211 -0
  86. package/src/notification/notification.js +64 -51
  87. package/src/panel/balloon/balloonpanelview.d.ts +685 -0
  88. package/src/panel/balloon/balloonpanelview.js +146 -168
  89. package/src/panel/balloon/contextualballoon.d.ts +299 -0
  90. package/src/panel/balloon/contextualballoon.js +42 -172
  91. package/src/panel/sticky/stickypanelview.d.ts +132 -0
  92. package/src/panel/sticky/stickypanelview.js +0 -115
  93. package/src/template.d.ts +942 -0
  94. package/src/template.js +397 -461
  95. package/src/toolbar/balloon/balloontoolbar.d.ts +118 -0
  96. package/src/toolbar/balloon/balloontoolbar.js +14 -81
  97. package/src/toolbar/block/blockbuttonview.d.ts +35 -0
  98. package/src/toolbar/block/blockbuttonview.js +1 -13
  99. package/src/toolbar/block/blocktoolbar.d.ts +153 -0
  100. package/src/toolbar/block/blocktoolbar.js +31 -69
  101. package/src/toolbar/normalizetoolbarconfig.d.ts +39 -0
  102. package/src/toolbar/normalizetoolbarconfig.js +12 -8
  103. package/src/toolbar/toolbarlinebreakview.d.ts +18 -0
  104. package/src/toolbar/toolbarlinebreakview.js +0 -2
  105. package/src/toolbar/toolbarseparatorview.d.ts +18 -0
  106. package/src/toolbar/toolbarseparatorview.js +0 -2
  107. package/src/toolbar/toolbarview.d.ts +265 -0
  108. package/src/toolbar/toolbarview.js +54 -305
  109. package/src/tooltipmanager.d.ts +180 -0
  110. package/src/tooltipmanager.js +48 -95
  111. package/src/view.d.ts +422 -0
  112. package/src/view.js +182 -251
  113. package/src/viewcollection.d.ts +139 -0
  114. package/src/viewcollection.js +62 -56
@@ -0,0 +1,132 @@
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/colorgrid/colorgridview
7
+ */
8
+ import View from '../view';
9
+ import ColorTileView from './colortileview';
10
+ import type DropdownPanelFocusable from '../dropdown/dropdownpanelfocusable';
11
+ import type ViewCollection from '../viewcollection';
12
+ import { FocusTracker, KeystrokeHandler, type Locale } from '@ckeditor/ckeditor5-utils';
13
+ import '../../theme/components/colorgrid/colorgrid.css';
14
+ /**
15
+ * A grid of {@link module:ui/colorgrid/colortileview~ColorTileView color tiles}.
16
+ */
17
+ export default class ColorGridView extends View implements DropdownPanelFocusable {
18
+ /**
19
+ * A number of columns for the tiles grid.
20
+ */
21
+ readonly columns: number;
22
+ /**
23
+ * Collection of the child tile views.
24
+ */
25
+ readonly items: ViewCollection<ColorTileView>;
26
+ /**
27
+ * Tracks information about DOM focus in the grid.
28
+ */
29
+ readonly focusTracker: FocusTracker;
30
+ /**
31
+ * Instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
32
+ */
33
+ readonly keystrokes: KeystrokeHandler;
34
+ /**
35
+ * The color of the currently selected color tile in {@link #items}.
36
+ *
37
+ * @observable
38
+ */
39
+ selectedColor: string | undefined | null;
40
+ /**
41
+ * Creates an instance of a color grid containing {@link module:ui/colorgrid/colortileview~ColorTileView tiles}.
42
+ *
43
+ * @fires execute
44
+ * @param locale The localization services instance.
45
+ * @param options Component configuration
46
+ * @param options.colorDefinitions Array with definitions
47
+ * required to create the {@link module:ui/colorgrid/colortileview~ColorTileView tiles}.
48
+ * @param options.columns A number of columns to display the tiles.
49
+ */
50
+ constructor(locale?: Locale, options?: {
51
+ colorDefinitions?: Array<ColorDefinition>;
52
+ columns?: number;
53
+ });
54
+ /**
55
+ * Focuses the first focusable in {@link #items}.
56
+ */
57
+ focus(): void;
58
+ /**
59
+ * Focuses the last focusable in {@link #items}.
60
+ */
61
+ focusLast(): void;
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ render(): void;
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ destroy(): void;
70
+ }
71
+ /**
72
+ * A color definition used to create a {@link module:ui/colorgrid/colortileview~ColorTileView}.
73
+ *
74
+ * ```json
75
+ * {
76
+ * color: 'hsl(0, 0%, 75%)',
77
+ * label: 'Light Grey',
78
+ * options: {
79
+ * hasBorder: true
80
+ * }
81
+ * }
82
+ * ```
83
+ */
84
+ export interface ColorDefinition {
85
+ /**
86
+ * String representing a color.
87
+ * It is used as value of background-color style in {@link module:ui/colorgrid/colortileview~ColorTileView}.
88
+ */
89
+ color: string;
90
+ /**
91
+ * String used as label for {@link module:ui/colorgrid/colortileview~ColorTileView}.
92
+ */
93
+ label: string;
94
+ /**
95
+ * Additional options passed to create a {@link module:ui/colorgrid/colortileview~ColorTileView}.
96
+ */
97
+ options: {
98
+ /**
99
+ * A flag that indicates if special a CSS class should be added
100
+ * to {@link module:ui/colorgrid/colortileview~ColorTileView}, which renders a border around it.
101
+ */
102
+ hasBorder: boolean;
103
+ };
104
+ }
105
+ /**
106
+ * Fired when the `ColorTileView` for the picked item is executed.
107
+ *
108
+ * @eventName ~ColorGridView#execute
109
+ * @param data Additional information about the event.
110
+ */
111
+ export type ColorGridViewExecuteEvent = {
112
+ name: 'execute';
113
+ args: [data: ColorGridViewExecuteEventData];
114
+ };
115
+ /**
116
+ * The data of {@link ~ColorGridViewExecuteEvent execute event}.
117
+ */
118
+ export interface ColorGridViewExecuteEventData {
119
+ /**
120
+ * The value of the selected color ({@link module:ui/colorgrid/colorgridview~ColorDefinition#color `color.color`}).
121
+ */
122
+ value: string;
123
+ /**
124
+ * The `hasBorder` property of the selected color
125
+ * ({@link module:ui/colorgrid/colorgridview~ColorDefinition#options `color.options.hasBorder`}).
126
+ */
127
+ hasBorder: boolean;
128
+ /**
129
+ * The label of the selected color ({@link module:ui/colorgrid/colorgridview~ColorDefinition#label `color.label`})
130
+ */
131
+ label: string;
132
+ }
@@ -3,69 +3,38 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
- * @module ui/colorgrid/colorgrid
6
+ * @module ui/colorgrid/colorgridview
7
7
  */
8
8
  import View from '../view';
9
9
  import ColorTileView from './colortileview';
10
- import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
11
10
  import addKeyboardHandlingForGrid from '../bindings/addkeyboardhandlingforgrid';
12
- import { FocusTracker } from '@ckeditor/ckeditor5-utils';
11
+ import { FocusTracker, KeystrokeHandler } from '@ckeditor/ckeditor5-utils';
13
12
  import '../../theme/components/colorgrid/colorgrid.css';
14
13
  /**
15
- * A grid of {@link module:ui/colorgrid/colortile~ColorTileView color tiles}.
16
- *
17
- * @extends module:ui/view~View
14
+ * A grid of {@link module:ui/colorgrid/colortileview~ColorTileView color tiles}.
18
15
  */
19
16
  export default class ColorGridView extends View {
20
17
  /**
21
- * Creates an instance of a color grid containing {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
18
+ * Creates an instance of a color grid containing {@link module:ui/colorgrid/colortileview~ColorTileView tiles}.
22
19
  *
23
- * @param {module:utils/locale~Locale} [locale] The localization services instance.
24
- * @param {Object} options Component configuration
25
- * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} [options.colorDefinitions] Array with definitions
26
- * required to create the {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
27
- * @param {Number} [options.columns=5] A number of columns to display the tiles.
20
+ * @fires execute
21
+ * @param locale The localization services instance.
22
+ * @param options Component configuration
23
+ * @param options.colorDefinitions Array with definitions
24
+ * required to create the {@link module:ui/colorgrid/colortileview~ColorTileView tiles}.
25
+ * @param options.columns A number of columns to display the tiles.
28
26
  */
29
27
  constructor(locale, options) {
28
+ var _a, _b;
30
29
  super(locale);
31
- const colorDefinitions = options && options.colorDefinitions || [];
32
- /**
33
- * A number of columns for the tiles grid.
34
- *
35
- * @readonly
36
- * @member {Number}
37
- */
38
- this.columns = options && options.columns ? options.columns : 5;
30
+ const colorDefinitions = (_a = options === null || options === void 0 ? void 0 : options.colorDefinitions) !== null && _a !== void 0 ? _a : [];
31
+ this.columns = (_b = options === null || options === void 0 ? void 0 : options.columns) !== null && _b !== void 0 ? _b : 5;
39
32
  const viewStyleAttribute = {
40
33
  gridTemplateColumns: `repeat( ${this.columns}, 1fr)`
41
34
  };
42
- /**
43
- * The color of the currently selected color tile in {@link #items}.
44
- *
45
- * @observable
46
- * @type {String}
47
- */
48
35
  this.set('selectedColor', undefined);
49
- /**
50
- * Collection of the child tile views.
51
- *
52
- * @readonly
53
- * @member {module:ui/viewcollection~ViewCollection}
54
- */
55
36
  this.items = this.createCollection();
56
- /**
57
- * Tracks information about DOM focus in the grid.
58
- *
59
- * @readonly
60
- * @member {module:utils/focustracker~FocusTracker}
61
- */
62
37
  this.focusTracker = new FocusTracker();
63
- /**
64
- * Instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
65
- *
66
- * @readonly
67
- * @member {module:utils/keystrokehandler~KeystrokeHandler}
68
- */
69
38
  this.keystrokes = new KeystrokeHandler();
70
39
  this.items.on('add', (evt, colorTile) => {
71
40
  colorTile.isOn = colorTile.color === this.selectedColor;
@@ -0,0 +1,28 @@
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/colorgrid/colortileview
7
+ */
8
+ import ButtonView from '../button/buttonview';
9
+ import type { Locale } from '@ckeditor/ckeditor5-utils';
10
+ /**
11
+ * This class represents a single color tile in the {@link module:ui/colorgrid/colorgridview~ColorGridView}.
12
+ */
13
+ export default class ColorTileView extends ButtonView {
14
+ /**
15
+ * String representing a color shown as tile's background.
16
+ */
17
+ color: string | undefined;
18
+ /**
19
+ * A flag that toggles a special CSS class responsible for displaying
20
+ * a border around the button.
21
+ */
22
+ hasBorder: boolean;
23
+ constructor(locale?: Locale);
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ render(): void;
28
+ }
@@ -3,31 +3,18 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
5
  /**
6
- * @module ui/colorgrid/colortile
6
+ * @module ui/colorgrid/colortileview
7
7
  */
8
8
  import ButtonView from '../button/buttonview';
9
9
  import checkIcon from '../../theme/icons/color-tile-check.svg';
10
10
  /**
11
- * This class represents a single color tile in the {@link module:ui/colorgrid/colorgrid~ColorGridView}.
12
- *
13
- * @extends module:ui/button/buttonview~ButtonView
11
+ * This class represents a single color tile in the {@link module:ui/colorgrid/colorgridview~ColorGridView}.
14
12
  */
15
13
  export default class ColorTileView extends ButtonView {
16
14
  constructor(locale) {
17
15
  super(locale);
18
16
  const bind = this.bindTemplate;
19
- /**
20
- * String representing a color shown as tile's background.
21
- *
22
- * @type {String}
23
- */
24
17
  this.set('color', undefined);
25
- /**
26
- * A flag that toggles a special CSS class responsible for displaying
27
- * a border around the button.
28
- *
29
- * @type {Boolean}
30
- */
31
18
  this.set('hasBorder', false);
32
19
  this.icon = checkIcon;
33
20
  this.extendTemplate({
@@ -0,0 +1,47 @@
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/colorgrid/utils
7
+ */
8
+ import type { Locale } from '@ckeditor/ckeditor5-utils';
9
+ export type ColorOption = string | {
10
+ color: string;
11
+ label?: string;
12
+ hasBorder?: boolean;
13
+ };
14
+ export interface NormalizedColorOption {
15
+ model: string;
16
+ label: string;
17
+ hasBorder: boolean;
18
+ view: {
19
+ name: string;
20
+ styles: {
21
+ color: string;
22
+ };
23
+ };
24
+ }
25
+ /**
26
+ * Returns color configuration options as defined in `editor.config.(fontColor|fontBackgroundColor).colors` or
27
+ * `editor.config.table.(tableProperties|tableCellProperties).(background|border).colors
28
+ * but processed to account for editor localization in the correct language.
29
+ *
30
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
31
+ * when the user configuration is defined because the editor does not exist yet.
32
+ *
33
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
34
+ */
35
+ export declare function getLocalizedColorOptions(locale: Locale, options: Array<NormalizedColorOption>): Array<NormalizedColorOption>;
36
+ /**
37
+ * Creates a unified color definition object from color configuration options.
38
+ * The object contains the information necessary to both render the UI and initialize the conversion.
39
+ */
40
+ export declare function normalizeColorOptions(options: Array<ColorOption>): Array<NormalizedColorOption>;
41
+ /**
42
+ * Creates a normalized color definition from the user-defined configuration.
43
+ * The "normalization" means it will create full
44
+ * {@link module:ui/colorgrid/colorgridview~ColorDefinition `ColorDefinition-like`}
45
+ * object for string values, and add a `view` property, for each definition.
46
+ */
47
+ export declare function normalizeSingleColorDefinition(color: ColorOption): NormalizedColorOption;
@@ -10,9 +10,7 @@
10
10
  * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
11
11
  * when the user configuration is defined because the editor does not exist yet.
12
12
  *
13
- * @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
14
- * @param {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>} options
15
- * @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}.
13
+ * @param locale The {@link module:core/editor/editor~Editor#locale} instance.
16
14
  */
17
15
  export function getLocalizedColorOptions(locale, options) {
18
16
  const t = locale.t;
@@ -44,22 +42,18 @@ export function getLocalizedColorOptions(locale, options) {
44
42
  /**
45
43
  * Creates a unified color definition object from color configuration options.
46
44
  * The object contains the information necessary to both render the UI and initialize the conversion.
47
- *
48
- * @param {module:ui/colorgrid/colorgrid~ColorDefinition} options
49
- * @returns {Array.<module:ui/colorgrid/colorgrid~ColorDefinition>}
50
45
  */
51
46
  export function normalizeColorOptions(options) {
52
47
  return options
53
48
  .map(normalizeSingleColorDefinition)
54
49
  .filter(option => !!option);
55
50
  }
56
- // Creates a normalized color definition from the user-defined configuration.
57
- // The "normalization" means it will create full
58
- // {@link module:ui/colorgrid/colorgrid~ColorDefinition `ColorDefinition-like`}
59
- // object for string values, and add a `view` property, for each definition.
60
- //
61
- // @param {String|module:ui/colorgrid/colorgrid~ColorDefinition}
62
- // @returns {module:ui/colorgrid/colorgrid~ColorDefinition}
51
+ /**
52
+ * Creates a normalized color definition from the user-defined configuration.
53
+ * The "normalization" means it will create full
54
+ * {@link module:ui/colorgrid/colorgridview~ColorDefinition `ColorDefinition-like`}
55
+ * object for string values, and add a `view` property, for each definition.
56
+ */
63
57
  export function normalizeSingleColorDefinition(color) {
64
58
  if (typeof color === 'string') {
65
59
  return {
@@ -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/componentfactory
7
+ */
8
+ import { type Locale } from '@ckeditor/ckeditor5-utils';
9
+ import type { Editor } from '@ckeditor/ckeditor5-core';
10
+ import type View from './view';
11
+ /**
12
+ * A helper class implementing the UI component ({@link module:ui/view~View view}) factory.
13
+ *
14
+ * It allows functions producing specific UI components to be registered under their unique names
15
+ * in the factory. A registered component can be then instantiated by providing its name.
16
+ * Note that the names are case insensitive.
17
+ *
18
+ * ```ts
19
+ * // The editor provides localization tools for the factory.
20
+ * const factory = new ComponentFactory( editor );
21
+ *
22
+ * factory.add( 'foo', locale => new FooView( locale ) );
23
+ * factory.add( 'bar', locale => new BarView( locale ) );
24
+ *
25
+ * // An instance of FooView.
26
+ * const fooInstance = factory.create( 'foo' );
27
+ *
28
+ * // Names are case insensitive so this is also allowed:
29
+ * const barInstance = factory.create( 'Bar' );
30
+ * ```
31
+ *
32
+ * The {@link module:core/editor/editor~Editor#locale editor locale} is passed to the factory
33
+ * function when {@link module:ui/componentfactory~ComponentFactory#create} is called.
34
+ */
35
+ export default class ComponentFactory {
36
+ /**
37
+ * The editor instance that the factory belongs to.
38
+ */
39
+ readonly editor: Editor;
40
+ /**
41
+ * Registered component factories.
42
+ */
43
+ private readonly _components;
44
+ /**
45
+ * Creates an instance of the factory.
46
+ *
47
+ * @param editor The editor instance.
48
+ */
49
+ constructor(editor: Editor);
50
+ /**
51
+ * Returns an iterator of registered component names. Names are returned in lower case.
52
+ */
53
+ names(): IterableIterator<string>;
54
+ /**
55
+ * Registers a component factory function that will be used by the
56
+ * {@link #create create} method and called with the
57
+ * {@link module:core/editor/editor~Editor#locale editor locale} as an argument,
58
+ * allowing localization of the {@link module:ui/view~View view}.
59
+ *
60
+ * @param name The name of the component.
61
+ * @param callback The callback that returns the component.
62
+ */
63
+ add(name: string, callback: (locale: Locale) => View): void;
64
+ /**
65
+ * Creates an instance of a component registered in the factory under a specific name.
66
+ *
67
+ * When called, the {@link module:core/editor/editor~Editor#locale editor locale} is passed to
68
+ * the previously {@link #add added} factory function, allowing localization of the
69
+ * {@link module:ui/view~View view}.
70
+ *
71
+ * @param name The name of the component.
72
+ * @returns The instantiated component view.
73
+ */
74
+ create(name: string): View;
75
+ /**
76
+ * Checks if a component of a given name is registered in the factory.
77
+ *
78
+ * @param name The name of the component.
79
+ */
80
+ has(name: string): boolean;
81
+ }
@@ -13,17 +13,19 @@ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
13
13
  * in the factory. A registered component can be then instantiated by providing its name.
14
14
  * Note that the names are case insensitive.
15
15
  *
16
- * // The editor provides localization tools for the factory.
17
- * const factory = new ComponentFactory( editor );
16
+ * ```ts
17
+ * // The editor provides localization tools for the factory.
18
+ * const factory = new ComponentFactory( editor );
18
19
  *
19
- * factory.add( 'foo', locale => new FooView( locale ) );
20
- * factory.add( 'bar', locale => new BarView( locale ) );
20
+ * factory.add( 'foo', locale => new FooView( locale ) );
21
+ * factory.add( 'bar', locale => new BarView( locale ) );
21
22
  *
22
- * // An instance of FooView.
23
- * const fooInstance = factory.create( 'foo' );
23
+ * // An instance of FooView.
24
+ * const fooInstance = factory.create( 'foo' );
24
25
  *
25
- * // Names are case insensitive so this is also allowed:
26
- * const barInstance = factory.create( 'Bar' );
26
+ * // Names are case insensitive so this is also allowed:
27
+ * const barInstance = factory.create( 'Bar' );
28
+ * ```
27
29
  *
28
30
  * The {@link module:core/editor/editor~Editor#locale editor locale} is passed to the factory
29
31
  * function when {@link module:ui/componentfactory~ComponentFactory#create} is called.
@@ -32,29 +34,17 @@ export default class ComponentFactory {
32
34
  /**
33
35
  * Creates an instance of the factory.
34
36
  *
35
- * @constructor
36
- * @param {module:core/editor/editor~Editor} editor The editor instance.
37
+ * @param editor The editor instance.
37
38
  */
38
39
  constructor(editor) {
39
- /**
40
- * The editor instance that the factory belongs to.
41
- *
42
- * @readonly
43
- * @member {module:core/editor/editor~Editor}
44
- */
45
- this.editor = editor;
46
40
  /**
47
41
  * Registered component factories.
48
- *
49
- * @private
50
- * @member {Map}
51
42
  */
52
43
  this._components = new Map();
44
+ this.editor = editor;
53
45
  }
54
46
  /**
55
47
  * Returns an iterator of registered component names. Names are returned in lower case.
56
- *
57
- * @returns {Iterable.<String>}
58
48
  */
59
49
  *names() {
60
50
  for (const value of this._components.values()) {
@@ -67,8 +57,8 @@ export default class ComponentFactory {
67
57
  * {@link module:core/editor/editor~Editor#locale editor locale} as an argument,
68
58
  * allowing localization of the {@link module:ui/view~View view}.
69
59
  *
70
- * @param {String} name The name of the component.
71
- * @param {Function} callback The callback that returns the component.
60
+ * @param name The name of the component.
61
+ * @param callback The callback that returns the component.
72
62
  */
73
63
  add(name, callback) {
74
64
  this._components.set(getNormalized(name), { callback, originalName: name });
@@ -80,18 +70,18 @@ export default class ComponentFactory {
80
70
  * the previously {@link #add added} factory function, allowing localization of the
81
71
  * {@link module:ui/view~View view}.
82
72
  *
83
- * @param {String} name The name of the component.
84
- * @returns {module:ui/view~View} The instantiated component view.
73
+ * @param name The name of the component.
74
+ * @returns The instantiated component view.
85
75
  */
86
76
  create(name) {
87
77
  if (!this.has(name)) {
88
78
  /**
89
79
  * The required component is not registered in the component factory. Please make sure
90
80
  * the provided name is correct and the component has been correctly
91
- * {@link #add added} to the factory.
81
+ * {@link module:ui/componentfactory~ComponentFactory#add added} to the factory.
92
82
  *
93
83
  * @error componentfactory-item-missing
94
- * @param {String} name The name of the missing component.
84
+ * @param name The name of the missing component.
95
85
  */
96
86
  throw new CKEditorError('componentfactory-item-missing', this, { name });
97
87
  }
@@ -100,19 +90,15 @@ export default class ComponentFactory {
100
90
  /**
101
91
  * Checks if a component of a given name is registered in the factory.
102
92
  *
103
- * @param {String} name The name of the component.
104
- * @returns {Boolean}
93
+ * @param name The name of the component.
105
94
  */
106
95
  has(name) {
107
96
  return this._components.has(getNormalized(name));
108
97
  }
109
98
  }
110
- //
111
- // Ensures that the component name used as the key in the internal map is in lower case.
112
- //
113
- // @private
114
- // @param {String} name
115
- // @returns {String}
99
+ /**
100
+ * Ensures that the component name used as the key in the internal map is in lower case.
101
+ */
116
102
  function getNormalized(name) {
117
103
  return String(name).toLowerCase();
118
104
  }
@@ -0,0 +1,25 @@
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/dropdown/button/dropdownbutton
7
+ */
8
+ import type Button from '../../button/button';
9
+ import type ViewCollection from '../../viewcollection';
10
+ /**
11
+ * The dropdown button interface.
12
+ */
13
+ export default interface DropdownButton extends Button {
14
+ children: ViewCollection;
15
+ }
16
+ /**
17
+ * Fired when the dropdown should be opened.
18
+ * It will not be fired when the button {@link module:ui/dropdown/button/dropdownbutton~DropdownButton#isEnabled is disabled}.
19
+ *
20
+ * @eventName ~DropdownButton#open
21
+ */
22
+ export type DropdownButtonOpenEvent = {
23
+ name: 'open';
24
+ args: [];
25
+ };
@@ -0,0 +1,48 @@
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/dropdown/button/dropdownbuttonview
7
+ */
8
+ import ButtonView from '../../button/buttonview';
9
+ import type DropdownButton from './dropdownbutton';
10
+ import IconView from '../../icon/iconview';
11
+ import type { Locale } from '@ckeditor/ckeditor5-utils';
12
+ /**
13
+ * The default dropdown button view class.
14
+ *
15
+ * ```ts
16
+ * const view = new DropdownButtonView();
17
+ *
18
+ * view.set( {
19
+ * label: 'A button',
20
+ * keystroke: 'Ctrl+B',
21
+ * tooltip: true
22
+ * } );
23
+ *
24
+ * view.render();
25
+ *
26
+ * document.body.append( view.element );
27
+ * ```
28
+ *
29
+ * Also see the {@link module:ui/dropdown/utils~createDropdown `createDropdown()` util}.
30
+ */
31
+ export default class DropdownButtonView extends ButtonView implements DropdownButton {
32
+ /**
33
+ * An icon that displays arrow to indicate a dropdown button.
34
+ */
35
+ readonly arrowView: IconView;
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ constructor(locale?: Locale);
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ render(): void;
44
+ /**
45
+ * Creates a {@link module:ui/icon/iconview~IconView} instance as {@link #arrowView}.
46
+ */
47
+ private _createArrowView;
48
+ }