@ckeditor/ckeditor5-font 36.0.0 → 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/build/font.js +1 -1
- package/package.json +20 -15
- package/src/documentcolorcollection.d.ts +47 -0
- package/src/documentcolorcollection.js +34 -63
- package/src/font.d.ts +34 -0
- package/src/font.js +12 -19
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +32 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +9 -15
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +31 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +102 -115
- package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +27 -0
- package/src/fontbackgroundcolor/fontbackgroundcolorui.js +18 -25
- package/src/fontbackgroundcolor.d.ts +33 -0
- package/src/fontbackgroundcolor.js +12 -165
- package/src/fontcolor/fontcolorcommand.d.ts +31 -0
- package/src/fontcolor/fontcolorcommand.js +9 -15
- package/src/fontcolor/fontcolorediting.d.ts +31 -0
- package/src/fontcolor/fontcolorediting.js +115 -128
- package/src/fontcolor/fontcolorui.d.ts +27 -0
- package/src/fontcolor/fontcolorui.js +18 -25
- package/src/fontcolor.d.ts +29 -0
- package/src/fontcolor.js +12 -168
- package/src/fontcommand.d.ts +46 -0
- package/src/fontcommand.js +54 -78
- package/src/fontconfig.d.ts +399 -0
- package/src/fontconfig.js +5 -0
- package/src/fontfamily/fontfamilycommand.d.ts +31 -0
- package/src/fontfamily/fontfamilycommand.js +9 -15
- package/src/fontfamily/fontfamilyediting.d.ts +45 -0
- package/src/fontfamily/fontfamilyediting.js +96 -116
- package/src/fontfamily/fontfamilyui.d.ts +35 -0
- package/src/fontfamily/fontfamilyui.js +90 -122
- package/src/fontfamily/utils.d.ts +15 -0
- package/src/fontfamily/utils.js +66 -79
- package/src/fontfamily.d.ts +29 -0
- package/src/fontfamily.js +12 -112
- package/src/fontsize/fontsizecommand.d.ts +31 -0
- package/src/fontsize/fontsizecommand.js +9 -15
- package/src/fontsize/fontsizeediting.d.ts +50 -0
- package/src/fontsize/fontsizeediting.js +138 -169
- package/src/fontsize/fontsizeui.d.ts +36 -0
- package/src/fontsize/fontsizeui.js +98 -130
- package/src/fontsize/utils.d.ts +12 -0
- package/src/fontsize/utils.js +145 -174
- package/src/fontsize.d.ts +40 -0
- package/src/fontsize.js +21 -141
- package/src/index.d.ts +20 -0
- package/src/index.js +0 -2
- package/src/ui/colortableview.d.ts +167 -0
- package/src/ui/colortableview.js +240 -416
- package/src/ui/colorui.d.ts +64 -0
- package/src/ui/colorui.js +79 -132
- package/src/utils.d.ts +77 -0
- package/src/utils.js +42 -72
|
@@ -0,0 +1,64 @@
|
|
|
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 font/ui/colorui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import { type FONT_BACKGROUND_COLOR, type FONT_COLOR } from '../utils';
|
|
10
|
+
import type ColorTableView from './colortableview';
|
|
11
|
+
import '../fontconfig';
|
|
12
|
+
/**
|
|
13
|
+
* The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
|
|
14
|
+
*
|
|
15
|
+
* It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
|
|
16
|
+
* a {@link module:font/ui/colortableview~ColorTableView}.
|
|
17
|
+
*/
|
|
18
|
+
export default class ColorUI extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* The name of the command which will be executed when a color tile is clicked.
|
|
21
|
+
*/
|
|
22
|
+
commandName: typeof FONT_BACKGROUND_COLOR | typeof FONT_COLOR;
|
|
23
|
+
/**
|
|
24
|
+
* The name of this component in the {@link module:ui/componentfactory~ComponentFactory}.
|
|
25
|
+
* Also the configuration scope name in `editor.config`.
|
|
26
|
+
*/
|
|
27
|
+
componentName: typeof FONT_BACKGROUND_COLOR | typeof FONT_COLOR;
|
|
28
|
+
/**
|
|
29
|
+
* The SVG icon used by the dropdown.
|
|
30
|
+
*/
|
|
31
|
+
icon: string;
|
|
32
|
+
/**
|
|
33
|
+
* The label used by the dropdown.
|
|
34
|
+
*/
|
|
35
|
+
dropdownLabel: string;
|
|
36
|
+
/**
|
|
37
|
+
* The number of columns in the color grid.
|
|
38
|
+
*/
|
|
39
|
+
columns: number;
|
|
40
|
+
/**
|
|
41
|
+
* Keeps a reference to {@link module:font/ui/colortableview~ColorTableView}.
|
|
42
|
+
*/
|
|
43
|
+
colorTableView: ColorTableView | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a plugin which introduces a dropdown with a pre–configured {@link module:font/ui/colortableview~ColorTableView}.
|
|
46
|
+
*
|
|
47
|
+
* @param config The configuration object.
|
|
48
|
+
* @param config.commandName The name of the command which will be executed when a color tile is clicked.
|
|
49
|
+
* @param config.componentName The name of the dropdown in the {@link module:ui/componentfactory~ComponentFactory}
|
|
50
|
+
* and the configuration scope name in `editor.config`.
|
|
51
|
+
* @param config.icon The SVG icon used by the dropdown.
|
|
52
|
+
* @param config.dropdownLabel The label used by the dropdown.
|
|
53
|
+
*/
|
|
54
|
+
constructor(editor: Editor, { commandName, componentName, icon, dropdownLabel }: {
|
|
55
|
+
commandName: typeof FONT_BACKGROUND_COLOR | typeof FONT_COLOR;
|
|
56
|
+
componentName: typeof FONT_BACKGROUND_COLOR | typeof FONT_COLOR;
|
|
57
|
+
icon: string;
|
|
58
|
+
dropdownLabel: string;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
init(): void;
|
|
64
|
+
}
|
package/src/ui/colorui.js
CHANGED
|
@@ -2,149 +2,96 @@
|
|
|
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
5
|
/**
|
|
7
6
|
* @module font/ui/colorui
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import { createDropdown, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
|
|
12
|
-
|
|
13
10
|
import { addColorTableToDropdown } from '../utils';
|
|
14
|
-
|
|
11
|
+
import '../fontconfig';
|
|
15
12
|
/**
|
|
16
13
|
* The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
|
|
17
14
|
*
|
|
18
15
|
* It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
|
|
19
16
|
* a {@link module:font/ui/colortableview~ColorTableView}.
|
|
20
|
-
*
|
|
21
|
-
* @extends module:core/plugin~Plugin
|
|
22
17
|
*/
|
|
23
18
|
export default class ColorUI extends Plugin {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
hasBorder: option.hasBorder
|
|
103
|
-
}
|
|
104
|
-
} ) ),
|
|
105
|
-
columns: this.columns,
|
|
106
|
-
removeButtonLabel: t( 'Remove color' ),
|
|
107
|
-
documentColorsLabel: documentColorsCount !== 0 ? t( 'Document colors' ) : undefined,
|
|
108
|
-
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount
|
|
109
|
-
} );
|
|
110
|
-
|
|
111
|
-
this.colorTableView.bind( 'selectedColor' ).to( command, 'value' );
|
|
112
|
-
|
|
113
|
-
dropdownView.buttonView.set( {
|
|
114
|
-
label: this.dropdownLabel,
|
|
115
|
-
icon: this.icon,
|
|
116
|
-
tooltip: true
|
|
117
|
-
} );
|
|
118
|
-
|
|
119
|
-
dropdownView.extendTemplate( {
|
|
120
|
-
attributes: {
|
|
121
|
-
class: 'ck-color-ui-dropdown'
|
|
122
|
-
}
|
|
123
|
-
} );
|
|
124
|
-
|
|
125
|
-
dropdownView.bind( 'isEnabled' ).to( command );
|
|
126
|
-
|
|
127
|
-
dropdownView.on( 'execute', ( evt, data ) => {
|
|
128
|
-
editor.execute( this.commandName, data );
|
|
129
|
-
editor.editing.view.focus();
|
|
130
|
-
} );
|
|
131
|
-
|
|
132
|
-
dropdownView.on( 'change:isOpen', ( evt, name, isVisible ) => {
|
|
133
|
-
// Grids rendering is deferred (#6192).
|
|
134
|
-
dropdownView.colorTableView.appendGrids();
|
|
135
|
-
|
|
136
|
-
if ( isVisible ) {
|
|
137
|
-
if ( documentColorsCount !== 0 ) {
|
|
138
|
-
this.colorTableView.updateDocumentColors( editor.model, this.componentName );
|
|
139
|
-
}
|
|
140
|
-
this.colorTableView.updateSelectedColors();
|
|
141
|
-
}
|
|
142
|
-
} );
|
|
143
|
-
|
|
144
|
-
// Accessibility: focus the first active color when opening the dropdown.
|
|
145
|
-
focusChildOnDropdownOpen( dropdownView, () => dropdownView.colorTableView.staticColorsGrid.items.find( item => item.isOn ) );
|
|
146
|
-
|
|
147
|
-
return dropdownView;
|
|
148
|
-
} );
|
|
149
|
-
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a plugin which introduces a dropdown with a pre–configured {@link module:font/ui/colortableview~ColorTableView}.
|
|
21
|
+
*
|
|
22
|
+
* @param config The configuration object.
|
|
23
|
+
* @param config.commandName The name of the command which will be executed when a color tile is clicked.
|
|
24
|
+
* @param config.componentName The name of the dropdown in the {@link module:ui/componentfactory~ComponentFactory}
|
|
25
|
+
* and the configuration scope name in `editor.config`.
|
|
26
|
+
* @param config.icon The SVG icon used by the dropdown.
|
|
27
|
+
* @param config.dropdownLabel The label used by the dropdown.
|
|
28
|
+
*/
|
|
29
|
+
constructor(editor, { commandName, componentName, icon, dropdownLabel }) {
|
|
30
|
+
super(editor);
|
|
31
|
+
this.commandName = commandName;
|
|
32
|
+
this.componentName = componentName;
|
|
33
|
+
this.icon = icon;
|
|
34
|
+
this.dropdownLabel = dropdownLabel;
|
|
35
|
+
this.columns = editor.config.get(`${this.componentName}.columns`);
|
|
36
|
+
this.colorTableView = undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritDoc
|
|
40
|
+
*/
|
|
41
|
+
init() {
|
|
42
|
+
const editor = this.editor;
|
|
43
|
+
const locale = editor.locale;
|
|
44
|
+
const t = locale.t;
|
|
45
|
+
const command = editor.commands.get(this.commandName);
|
|
46
|
+
const colorsConfig = normalizeColorOptions((editor.config.get(this.componentName)).colors);
|
|
47
|
+
const localizedColors = getLocalizedColorOptions(locale, colorsConfig);
|
|
48
|
+
const documentColorsCount = editor.config.get(`${this.componentName}.documentColors`);
|
|
49
|
+
// Register the UI component.
|
|
50
|
+
editor.ui.componentFactory.add(this.componentName, locale => {
|
|
51
|
+
const dropdownView = createDropdown(locale);
|
|
52
|
+
this.colorTableView = addColorTableToDropdown({
|
|
53
|
+
dropdownView,
|
|
54
|
+
colors: localizedColors.map(option => ({
|
|
55
|
+
label: option.label,
|
|
56
|
+
color: option.model,
|
|
57
|
+
options: {
|
|
58
|
+
hasBorder: option.hasBorder
|
|
59
|
+
}
|
|
60
|
+
})),
|
|
61
|
+
columns: this.columns,
|
|
62
|
+
removeButtonLabel: t('Remove color'),
|
|
63
|
+
documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
|
|
64
|
+
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount
|
|
65
|
+
});
|
|
66
|
+
this.colorTableView.bind('selectedColor').to(command, 'value');
|
|
67
|
+
dropdownView.buttonView.set({
|
|
68
|
+
label: this.dropdownLabel,
|
|
69
|
+
icon: this.icon,
|
|
70
|
+
tooltip: true
|
|
71
|
+
});
|
|
72
|
+
dropdownView.extendTemplate({
|
|
73
|
+
attributes: {
|
|
74
|
+
class: 'ck-color-ui-dropdown'
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
dropdownView.bind('isEnabled').to(command);
|
|
78
|
+
dropdownView.on('execute', (evt, data) => {
|
|
79
|
+
editor.execute(this.commandName, data);
|
|
80
|
+
editor.editing.view.focus();
|
|
81
|
+
});
|
|
82
|
+
dropdownView.on('change:isOpen', (evt, name, isVisible) => {
|
|
83
|
+
// Grids rendering is deferred (#6192).
|
|
84
|
+
dropdownView.colorTableView.appendGrids();
|
|
85
|
+
if (isVisible) {
|
|
86
|
+
if (documentColorsCount !== 0) {
|
|
87
|
+
this.colorTableView.updateDocumentColors(editor.model, this.componentName);
|
|
88
|
+
}
|
|
89
|
+
this.colorTableView.updateSelectedColors();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// Accessibility: focus the first active color when opening the dropdown.
|
|
93
|
+
focusChildOnDropdownOpen(dropdownView, () => dropdownView.colorTableView.staticColorsGrid.items.find((item) => item.isOn));
|
|
94
|
+
return dropdownView;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
150
97
|
}
|
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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 font/utils
|
|
7
|
+
*/
|
|
8
|
+
import ColorTableView from './ui/colortableview';
|
|
9
|
+
import type { FontFamilyOption, FontSizeOption } from './fontconfig';
|
|
10
|
+
import type { ColorDefinition, DropdownView } from 'ckeditor5/src/ui';
|
|
11
|
+
import type { ArrayOrItem } from 'ckeditor5/src/utils';
|
|
12
|
+
import type { ViewAttributeElement, ViewElement, MatcherPattern, ViewElementDefinition, DowncastConversionApi } from 'ckeditor5/src/engine';
|
|
13
|
+
/**
|
|
14
|
+
* The name of the font size plugin.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FONT_SIZE = "fontSize";
|
|
17
|
+
/**
|
|
18
|
+
* The name of the font family plugin.
|
|
19
|
+
*/
|
|
20
|
+
export declare const FONT_FAMILY = "fontFamily";
|
|
21
|
+
/**
|
|
22
|
+
* The name of the font color plugin.
|
|
23
|
+
*/
|
|
24
|
+
export declare const FONT_COLOR = "fontColor";
|
|
25
|
+
/**
|
|
26
|
+
* The name of the font background color plugin.
|
|
27
|
+
*/
|
|
28
|
+
export declare const FONT_BACKGROUND_COLOR = "fontBackgroundColor";
|
|
29
|
+
/**
|
|
30
|
+
* Builds a proper converter definition out of input data.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildDefinition(modelAttributeKey: string, options: Array<FontFamilyOption> | Array<FontSizeOption>): FontConverterDefinition;
|
|
33
|
+
export type FontConverterDefinition = {
|
|
34
|
+
model: {
|
|
35
|
+
key: string;
|
|
36
|
+
values: Array<string>;
|
|
37
|
+
};
|
|
38
|
+
view: Record<string, ViewElementDefinition>;
|
|
39
|
+
upcastAlso: Record<string, ArrayOrItem<MatcherPattern>>;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
43
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
44
|
+
* responsible for upcasting data to the model.
|
|
45
|
+
*
|
|
46
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderUpcastAttribute(styleAttr: string): (viewElement: ViewElement) => string;
|
|
49
|
+
/**
|
|
50
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
51
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
52
|
+
* responsible for downcasting a color attribute to a `<span>` element.
|
|
53
|
+
*
|
|
54
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function renderDowncastElement(styleAttr: string): (modelAttributeValue: string, { writer }: DowncastConversionApi) => ViewAttributeElement;
|
|
57
|
+
/**
|
|
58
|
+
* A helper that adds {@link module:font/ui/colortableview~ColorTableView} to the color dropdown with proper initial values.
|
|
59
|
+
*
|
|
60
|
+
* @param config.dropdownView The dropdown view to which a {@link module:font/ui/colortableview~ColorTableView} will be added.
|
|
61
|
+
* @param config.colors An array with definitions representing colors to be displayed in the color table.
|
|
62
|
+
* @param config.removeButtonLabel The label for the button responsible for removing the color.
|
|
63
|
+
* @param config.documentColorsLabel The label for the section with document colors.
|
|
64
|
+
* @param config.documentColorsCount The number of document colors inside the dropdown.
|
|
65
|
+
* @returns The new color table view.
|
|
66
|
+
*/
|
|
67
|
+
export declare function addColorTableToDropdown({ dropdownView, colors, columns, removeButtonLabel, documentColorsLabel, documentColorsCount }: {
|
|
68
|
+
dropdownView: ColorTableDropdownView;
|
|
69
|
+
colors: Array<ColorDefinition>;
|
|
70
|
+
columns: number;
|
|
71
|
+
removeButtonLabel: string;
|
|
72
|
+
documentColorsLabel?: string;
|
|
73
|
+
documentColorsCount?: number;
|
|
74
|
+
}): ColorTableView;
|
|
75
|
+
export type ColorTableDropdownView = DropdownView & {
|
|
76
|
+
colorTableView?: ColorTableView;
|
|
77
|
+
};
|
package/src/utils.js
CHANGED
|
@@ -2,120 +2,90 @@
|
|
|
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
5
|
/**
|
|
7
6
|
* @module font/utils
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import ColorTableView from './ui/colortableview';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The name of the font size plugin.
|
|
14
11
|
*/
|
|
15
12
|
export const FONT_SIZE = 'fontSize';
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* The name of the font family plugin.
|
|
19
15
|
*/
|
|
20
16
|
export const FONT_FAMILY = 'fontFamily';
|
|
21
|
-
|
|
22
17
|
/**
|
|
23
18
|
* The name of the font color plugin.
|
|
24
19
|
*/
|
|
25
20
|
export const FONT_COLOR = 'fontColor';
|
|
26
|
-
|
|
27
21
|
/**
|
|
28
22
|
* The name of the font background color plugin.
|
|
29
23
|
*/
|
|
30
24
|
export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
|
|
31
|
-
|
|
32
25
|
/**
|
|
33
|
-
* Builds a proper
|
|
34
|
-
*
|
|
35
|
-
* @param {String} modelAttributeKey Key
|
|
36
|
-
* @param {Array.<module:font/fontfamily~FontFamilyOption>|Array.<module:font/fontsize~FontSizeOption>} options
|
|
37
|
-
* @returns {module:engine/conversion/conversion~ConverterDefinition}
|
|
26
|
+
* Builds a proper converter definition out of input data.
|
|
38
27
|
*/
|
|
39
|
-
export function buildDefinition(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return definition;
|
|
28
|
+
export function buildDefinition(modelAttributeKey, options) {
|
|
29
|
+
const definition = {
|
|
30
|
+
model: {
|
|
31
|
+
key: modelAttributeKey,
|
|
32
|
+
values: []
|
|
33
|
+
},
|
|
34
|
+
view: {},
|
|
35
|
+
upcastAlso: {}
|
|
36
|
+
};
|
|
37
|
+
for (const option of options) {
|
|
38
|
+
definition.model.values.push(option.model);
|
|
39
|
+
definition.view[option.model] = option.view;
|
|
40
|
+
if (option.upcastAlso) {
|
|
41
|
+
definition.upcastAlso[option.model] = option.upcastAlso;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return definition;
|
|
59
45
|
}
|
|
60
|
-
|
|
61
46
|
/**
|
|
62
47
|
* A {@link module:font/fontcolor~FontColor font color} and
|
|
63
48
|
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
64
49
|
* responsible for upcasting data to the model.
|
|
65
50
|
*
|
|
66
51
|
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
67
|
-
*
|
|
68
|
-
* @param {String} styleAttr
|
|
69
|
-
* @return {String}
|
|
70
52
|
*/
|
|
71
|
-
export function renderUpcastAttribute(
|
|
72
|
-
|
|
53
|
+
export function renderUpcastAttribute(styleAttr) {
|
|
54
|
+
return (viewElement) => normalizeColorCode(viewElement.getStyle(styleAttr));
|
|
73
55
|
}
|
|
74
|
-
|
|
75
56
|
/**
|
|
76
57
|
* A {@link module:font/fontcolor~FontColor font color} and
|
|
77
58
|
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
78
59
|
* responsible for downcasting a color attribute to a `<span>` element.
|
|
79
60
|
*
|
|
80
61
|
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
81
|
-
*
|
|
82
|
-
* @param {String} styleAttr
|
|
83
62
|
*/
|
|
84
|
-
export function renderDowncastElement(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
export function renderDowncastElement(styleAttr) {
|
|
64
|
+
return (modelAttributeValue, { writer }) => writer.createAttributeElement('span', {
|
|
65
|
+
style: `${styleAttr}:${modelAttributeValue}`
|
|
66
|
+
}, { priority: 7 });
|
|
88
67
|
}
|
|
89
|
-
|
|
90
68
|
/**
|
|
91
69
|
* A helper that adds {@link module:font/ui/colortableview~ColorTableView} to the color dropdown with proper initial values.
|
|
92
70
|
*
|
|
93
|
-
* @param {
|
|
94
|
-
* @param
|
|
95
|
-
*
|
|
96
|
-
* @param
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
99
|
-
* @param {String} config.documentColorsLabel The label for the section with document colors.
|
|
100
|
-
* @param {String} config.documentColorsCount The number of document colors inside the dropdown.
|
|
101
|
-
* @returns {module:font/ui/colortableview~ColorTableView} The new color table view.
|
|
71
|
+
* @param config.dropdownView The dropdown view to which a {@link module:font/ui/colortableview~ColorTableView} will be added.
|
|
72
|
+
* @param config.colors An array with definitions representing colors to be displayed in the color table.
|
|
73
|
+
* @param config.removeButtonLabel The label for the button responsible for removing the color.
|
|
74
|
+
* @param config.documentColorsLabel The label for the section with document colors.
|
|
75
|
+
* @param config.documentColorsCount The number of document colors inside the dropdown.
|
|
76
|
+
* @returns The new color table view.
|
|
102
77
|
*/
|
|
103
|
-
export function addColorTableToDropdown(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
colorTableView.delegate( 'execute' ).to( dropdownView, 'execute' );
|
|
111
|
-
|
|
112
|
-
return colorTableView;
|
|
78
|
+
export function addColorTableToDropdown({ dropdownView, colors, columns, removeButtonLabel, documentColorsLabel, documentColorsCount }) {
|
|
79
|
+
const locale = dropdownView.locale;
|
|
80
|
+
const colorTableView = new ColorTableView(locale, { colors, columns, removeButtonLabel, documentColorsLabel, documentColorsCount });
|
|
81
|
+
dropdownView.colorTableView = colorTableView;
|
|
82
|
+
dropdownView.panelView.children.add(colorTableView);
|
|
83
|
+
colorTableView.delegate('execute').to(dropdownView, 'execute');
|
|
84
|
+
return colorTableView;
|
|
113
85
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function normalizeColorCode( value ) {
|
|
120
|
-
return value.replace( /\s/g, '' );
|
|
86
|
+
/**
|
|
87
|
+
* Fixes the color value string.
|
|
88
|
+
*/
|
|
89
|
+
function normalizeColorCode(value) {
|
|
90
|
+
return value.replace(/\s/g, '');
|
|
121
91
|
}
|