@ckeditor/ckeditor5-ui 36.0.1 → 37.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +23 -22
- package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -0
- package/src/bindings/addkeyboardhandlingforgrid.js +42 -34
- package/src/bindings/clickoutsidehandler.d.ts +28 -0
- package/src/bindings/clickoutsidehandler.js +5 -6
- package/src/bindings/csstransitiondisablermixin.d.ts +40 -0
- package/src/bindings/csstransitiondisablermixin.js +55 -0
- package/src/bindings/injectcsstransitiondisabler.d.ts +59 -0
- package/src/bindings/injectcsstransitiondisabler.js +23 -20
- package/src/bindings/preventdefault.d.ts +33 -0
- package/src/bindings/preventdefault.js +13 -15
- package/src/bindings/submithandler.d.ts +57 -0
- package/src/bindings/submithandler.js +22 -23
- package/src/button/button.d.ts +154 -0
- package/src/button/buttonview.d.ts +155 -0
- package/src/button/buttonview.js +16 -60
- package/src/button/switchbuttonview.d.ts +45 -0
- package/src/button/switchbuttonview.js +9 -18
- package/src/colorgrid/colorgridview.d.ts +132 -0
- package/src/colorgrid/colorgridview.js +8 -40
- package/src/colorgrid/colortileview.d.ts +28 -0
- package/src/colorgrid/colortileview.js +0 -13
- package/src/colorgrid/utils.d.ts +47 -0
- package/src/colorgrid/utils.js +7 -13
- package/src/componentfactory.d.ts +81 -0
- package/src/componentfactory.js +21 -35
- package/src/dropdown/button/dropdownbutton.d.ts +25 -0
- package/src/dropdown/button/dropdownbuttonview.d.ts +48 -0
- package/src/dropdown/button/dropdownbuttonview.js +11 -21
- package/src/dropdown/button/splitbuttonview.d.ts +145 -0
- package/src/dropdown/button/splitbuttonview.js +10 -51
- package/src/dropdown/dropdownpanelfocusable.d.ts +21 -0
- package/src/dropdown/dropdownpanelview.d.ts +62 -0
- package/src/dropdown/dropdownpanelview.js +2 -30
- package/src/dropdown/dropdownview.d.ts +315 -0
- package/src/dropdown/dropdownview.js +121 -222
- package/src/dropdown/utils.d.ts +219 -0
- package/src/dropdown/utils.js +112 -106
- package/src/editableui/editableuiview.d.ts +71 -0
- package/src/editableui/editableuiview.js +14 -43
- package/src/editableui/inline/inlineeditableuiview.d.ts +40 -0
- package/src/editableui/inline/inlineeditableuiview.js +5 -15
- package/src/editorui/bodycollection.d.ts +51 -0
- package/src/editorui/bodycollection.js +2 -16
- package/src/editorui/boxed/boxededitoruiview.d.ts +40 -0
- package/src/editorui/boxed/boxededitoruiview.js +1 -27
- package/src/editorui/editorui.d.ts +264 -0
- package/src/editorui/editorui.js +21 -128
- package/src/editorui/editoruiview.d.ts +39 -0
- package/src/editorui/editoruiview.js +1 -10
- package/src/focuscycler.d.ts +183 -0
- package/src/focuscycler.js +34 -90
- package/src/formheader/formheaderview.d.ts +53 -0
- package/src/formheader/formheaderview.js +3 -24
- package/src/icon/iconview.d.ts +78 -0
- package/src/icon/iconview.js +0 -50
- package/src/iframe/iframeview.d.ts +50 -0
- package/src/iframe/iframeview.js +2 -2
- package/src/index.d.ts +54 -0
- package/src/index.js +1 -0
- package/src/input/inputview.d.ts +121 -0
- package/src/input/inputview.js +0 -82
- package/src/inputnumber/inputnumberview.d.ts +49 -0
- package/src/inputnumber/inputnumberview.js +5 -28
- package/src/inputtext/inputtextview.d.ts +18 -0
- package/src/inputtext/inputtextview.js +0 -2
- package/src/label/labelview.d.ts +36 -0
- package/src/label/labelview.js +0 -20
- package/src/labeledfield/labeledfieldview.d.ts +182 -0
- package/src/labeledfield/labeledfieldview.js +20 -126
- package/src/labeledfield/utils.d.ts +93 -0
- package/src/labeledfield/utils.js +24 -18
- package/src/labeledinput/labeledinputview.d.ts +125 -0
- package/src/labeledinput/labeledinputview.js +7 -90
- package/src/list/listitemview.d.ts +35 -0
- package/src/list/listitemview.js +0 -16
- package/src/list/listseparatorview.d.ts +18 -0
- package/src/list/listseparatorview.js +0 -2
- package/src/list/listview.d.ts +59 -0
- package/src/list/listview.js +0 -33
- package/src/model.d.ts +22 -0
- package/src/model.js +2 -4
- package/src/notification/notification.d.ts +216 -0
- package/src/notification/notification.js +64 -51
- package/src/panel/balloon/balloonpanelview.d.ts +685 -0
- package/src/panel/balloon/balloonpanelview.js +146 -168
- package/src/panel/balloon/contextualballoon.d.ts +240 -0
- package/src/panel/balloon/contextualballoon.js +41 -171
- package/src/panel/sticky/stickypanelview.d.ts +132 -0
- package/src/panel/sticky/stickypanelview.js +0 -115
- package/src/template.d.ts +940 -0
- package/src/template.js +396 -460
- package/src/toolbar/balloon/balloontoolbar.d.ts +124 -0
- package/src/toolbar/balloon/balloontoolbar.js +15 -81
- package/src/toolbar/block/blockbuttonview.d.ts +35 -0
- package/src/toolbar/block/blockbuttonview.js +1 -13
- package/src/toolbar/block/blocktoolbar.d.ts +159 -0
- package/src/toolbar/block/blocktoolbar.js +32 -69
- package/src/toolbar/normalizetoolbarconfig.d.ts +39 -0
- package/src/toolbar/normalizetoolbarconfig.js +12 -8
- package/src/toolbar/toolbarlinebreakview.d.ts +18 -0
- package/src/toolbar/toolbarlinebreakview.js +0 -2
- package/src/toolbar/toolbarseparatorview.d.ts +18 -0
- package/src/toolbar/toolbarseparatorview.js +0 -2
- package/src/toolbar/toolbarview.d.ts +241 -0
- package/src/toolbar/toolbarview.js +54 -305
- package/src/tooltipmanager.d.ts +180 -0
- package/src/tooltipmanager.js +47 -94
- package/src/uiconfig.d.ts +82 -0
- package/src/uiconfig.js +5 -0
- package/src/view.d.ts +422 -0
- package/src/view.js +182 -251
- package/src/viewcollection.d.ts +139 -0
- 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/colorgrid
|
|
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/colortile~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/colortile~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/colortile~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/colortile~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/colortile~ColorTileView}.
|
|
88
|
+
*/
|
|
89
|
+
color: string;
|
|
90
|
+
/**
|
|
91
|
+
* String used as label for {@link module:ui/colorgrid/colortile~ColorTileView}.
|
|
92
|
+
*/
|
|
93
|
+
label: string;
|
|
94
|
+
/**
|
|
95
|
+
* Additional options passed to create a {@link module:ui/colorgrid/colortile~ColorTileView}.
|
|
96
|
+
*/
|
|
97
|
+
options: {
|
|
98
|
+
/**
|
|
99
|
+
* A flag that indicates if special a CSS class should be added
|
|
100
|
+
* to {@link module:ui/colorgrid/colortile~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 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/colorgrid~ColorDefinition#color `color.color`}).
|
|
121
|
+
*/
|
|
122
|
+
value: string;
|
|
123
|
+
/**
|
|
124
|
+
* The `hasBorder` property of the selected color
|
|
125
|
+
* ({@link module:ui/colorgrid/colorgrid~ColorDefinition#options `color.options.hasBorder`}).
|
|
126
|
+
*/
|
|
127
|
+
hasBorder: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* The label of the selected color ({@link module:ui/colorgrid/colorgrid~ColorDefinition#label `color.label`})
|
|
130
|
+
*/
|
|
131
|
+
label: string;
|
|
132
|
+
}
|
|
@@ -7,65 +7,33 @@
|
|
|
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
14
|
* A grid of {@link module:ui/colorgrid/colortile~ColorTileView color tiles}.
|
|
16
|
-
*
|
|
17
|
-
* @extends module:ui/view~View
|
|
18
15
|
*/
|
|
19
16
|
export default class ColorGridView extends View {
|
|
20
17
|
/**
|
|
21
18
|
* Creates an instance of a color grid containing {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
|
|
22
19
|
*
|
|
23
|
-
* @
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
20
|
+
* @fires execute
|
|
21
|
+
* @param locale The localization services instance.
|
|
22
|
+
* @param options Component configuration
|
|
23
|
+
* @param options.colorDefinitions Array with definitions
|
|
26
24
|
* required to create the {@link module:ui/colorgrid/colortile~ColorTileView tiles}.
|
|
27
|
-
* @param
|
|
25
|
+
* @param options.columns A number of columns to display the tiles.
|
|
28
26
|
*/
|
|
29
27
|
constructor(locale, options) {
|
|
30
28
|
super(locale);
|
|
31
|
-
const colorDefinitions = options
|
|
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;
|
|
29
|
+
const colorDefinitions = options?.colorDefinitions ?? [];
|
|
30
|
+
this.columns = options?.columns ?? 5;
|
|
39
31
|
const viewStyleAttribute = {
|
|
40
32
|
gridTemplateColumns: `repeat( ${this.columns}, 1fr)`
|
|
41
33
|
};
|
|
42
|
-
/**
|
|
43
|
-
* The color of the currently selected color tile in {@link #items}.
|
|
44
|
-
*
|
|
45
|
-
* @observable
|
|
46
|
-
* @type {String}
|
|
47
|
-
*/
|
|
48
34
|
this.set('selectedColor', undefined);
|
|
49
|
-
/**
|
|
50
|
-
* Collection of the child tile views.
|
|
51
|
-
*
|
|
52
|
-
* @readonly
|
|
53
|
-
* @member {module:ui/viewcollection~ViewCollection}
|
|
54
|
-
*/
|
|
55
35
|
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
36
|
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
37
|
this.keystrokes = new KeystrokeHandler();
|
|
70
38
|
this.items.on('add', (evt, colorTile) => {
|
|
71
39
|
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/colortile
|
|
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/colorgrid~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
|
+
}
|
|
@@ -9,25 +9,12 @@ import ButtonView from '../button/buttonview';
|
|
|
9
9
|
import checkIcon from '../../theme/icons/color-tile-check.svg';
|
|
10
10
|
/**
|
|
11
11
|
* This class represents a single color tile in the {@link module:ui/colorgrid/colorgrid~ColorGridView}.
|
|
12
|
-
*
|
|
13
|
-
* @extends module:ui/button/buttonview~ButtonView
|
|
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/colorgrid~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;
|
package/src/colorgrid/utils.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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/colorgrid~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
|
+
}
|
package/src/componentfactory.js
CHANGED
|
@@ -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
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* // The editor provides localization tools for the factory.
|
|
18
|
+
* const factory = new ComponentFactory( editor );
|
|
18
19
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* factory.add( 'foo', locale => new FooView( locale ) );
|
|
21
|
+
* factory.add( 'bar', locale => new BarView( locale ) );
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* // An instance of FooView.
|
|
24
|
+
* const fooInstance = factory.create( 'foo' );
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
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
|
-
* @
|
|
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
|
|
71
|
-
* @param
|
|
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,8 +70,8 @@ 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
|
|
84
|
-
* @returns
|
|
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)) {
|
|
@@ -91,7 +81,7 @@ export default class ComponentFactory {
|
|
|
91
81
|
* {@link #add added} to the factory.
|
|
92
82
|
*
|
|
93
83
|
* @error componentfactory-item-missing
|
|
94
|
-
* @param
|
|
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
|
|
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
|
-
|
|
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 #isEnabled is disabled}.
|
|
19
|
+
*
|
|
20
|
+
* @eventName 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
|
+
}
|
|
@@ -6,27 +6,26 @@
|
|
|
6
6
|
* @module ui/dropdown/button/dropdownbuttonview
|
|
7
7
|
*/
|
|
8
8
|
import ButtonView from '../../button/buttonview';
|
|
9
|
-
import dropdownArrowIcon from '../../../theme/icons/dropdown-arrow.svg';
|
|
10
9
|
import IconView from '../../icon/iconview';
|
|
10
|
+
import dropdownArrowIcon from '../../../theme/icons/dropdown-arrow.svg';
|
|
11
11
|
/**
|
|
12
12
|
* The default dropdown button view class.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* const view = new DropdownButtonView();
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* view.set( {
|
|
18
|
+
* label: 'A button',
|
|
19
|
+
* keystroke: 'Ctrl+B',
|
|
20
|
+
* tooltip: true
|
|
21
|
+
* } );
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
+
* view.render();
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
+
* document.body.append( view.element );
|
|
26
|
+
* ```
|
|
25
27
|
*
|
|
26
28
|
* Also see the {@link module:ui/dropdown/utils~createDropdown `createDropdown()` util}.
|
|
27
|
-
*
|
|
28
|
-
* @implements module:ui/dropdown/button/dropdownbutton~DropdownButton
|
|
29
|
-
* @extends module:ui/button/buttonview~ButtonView
|
|
30
29
|
*/
|
|
31
30
|
export default class DropdownButtonView extends ButtonView {
|
|
32
31
|
/**
|
|
@@ -34,12 +33,6 @@ export default class DropdownButtonView extends ButtonView {
|
|
|
34
33
|
*/
|
|
35
34
|
constructor(locale) {
|
|
36
35
|
super(locale);
|
|
37
|
-
/**
|
|
38
|
-
* An icon that displays arrow to indicate a dropdown button.
|
|
39
|
-
*
|
|
40
|
-
* @readonly
|
|
41
|
-
* @member {module:ui/icon/iconview~IconView}
|
|
42
|
-
*/
|
|
43
36
|
this.arrowView = this._createArrowView();
|
|
44
37
|
this.extendTemplate({
|
|
45
38
|
attributes: {
|
|
@@ -59,9 +52,6 @@ export default class DropdownButtonView extends ButtonView {
|
|
|
59
52
|
}
|
|
60
53
|
/**
|
|
61
54
|
* Creates a {@link module:ui/icon/iconview~IconView} instance as {@link #arrowView}.
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @returns {module:ui/icon/iconview~IconView}
|
|
65
55
|
*/
|
|
66
56
|
_createArrowView() {
|
|
67
57
|
const arrowView = new IconView();
|