@ckeditor/ckeditor5-font 39.0.2 → 40.0.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.map +1 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +58 -58
- package/src/augmentation.js +5 -5
- package/src/font.d.ts +33 -33
- package/src/font.js +37 -37
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +26 -26
- package/src/fontbackgroundcolor/fontbackgroundcolorcommand.js +25 -25
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +26 -26
- package/src/fontbackgroundcolor/fontbackgroundcolorediting.js +123 -123
- package/src/fontbackgroundcolor/fontbackgroundcolorui.d.ts +22 -22
- package/src/fontbackgroundcolor/fontbackgroundcolorui.js +33 -33
- package/src/fontbackgroundcolor.d.ts +30 -30
- package/src/fontbackgroundcolor.js +34 -34
- package/src/fontcolor/fontcolorcommand.d.ts +25 -25
- package/src/fontcolor/fontcolorcommand.js +24 -24
- package/src/fontcolor/fontcolorediting.d.ts +26 -26
- package/src/fontcolor/fontcolorediting.js +134 -134
- package/src/fontcolor/fontcolorui.d.ts +22 -22
- package/src/fontcolor/fontcolorui.js +33 -33
- package/src/fontcolor.d.ts +29 -29
- package/src/fontcolor.js +33 -33
- package/src/fontcommand.d.ts +48 -48
- package/src/fontcommand.js +79 -79
- package/src/fontconfig.d.ts +373 -373
- package/src/fontconfig.js +5 -5
- package/src/fontfamily/fontfamilycommand.d.ts +25 -25
- package/src/fontfamily/fontfamilycommand.js +24 -24
- package/src/fontfamily/fontfamilyediting.d.ts +39 -39
- package/src/fontfamily/fontfamilyediting.js +115 -115
- package/src/fontfamily/fontfamilyui.d.ts +30 -30
- package/src/fontfamily/fontfamilyui.js +114 -114
- package/src/fontfamily/utils.d.ts +15 -15
- package/src/fontfamily/utils.js +80 -80
- package/src/fontfamily.d.ts +29 -29
- package/src/fontfamily.js +33 -33
- package/src/fontsize/fontsizecommand.d.ts +25 -25
- package/src/fontsize/fontsizecommand.js +24 -24
- package/src/fontsize/fontsizeediting.d.ts +44 -44
- package/src/fontsize/fontsizeediting.js +165 -165
- package/src/fontsize/fontsizeui.d.ts +31 -31
- package/src/fontsize/fontsizeui.js +122 -122
- package/src/fontsize/utils.d.ts +12 -12
- package/src/fontsize/utils.js +166 -166
- package/src/fontsize.d.ts +37 -37
- package/src/fontsize.js +43 -43
- package/src/index.d.ts +27 -27
- package/src/index.js +21 -21
- package/src/ui/colorui.d.ts +68 -68
- package/src/ui/colorui.js +130 -130
- package/src/utils.d.ts +80 -80
- package/src/utils.js +97 -97
package/src/ui/colorui.js
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
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 } from 'ckeditor5/src/core';
|
|
9
|
-
import { createDropdown, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
|
|
10
|
-
import { addColorSelectorToDropdown } from '../utils';
|
|
11
|
-
/**
|
|
12
|
-
* The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
|
|
13
|
-
*
|
|
14
|
-
* It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
|
|
15
|
-
* a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
|
|
16
|
-
*/
|
|
17
|
-
export default class ColorUI extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* Creates a plugin which introduces a dropdown with a pre–configured
|
|
20
|
-
* {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
|
|
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.colorSelectorView = 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 componentConfig = editor.config.get(this.componentName);
|
|
47
|
-
const colorsConfig = normalizeColorOptions(componentConfig.colors);
|
|
48
|
-
const localizedColors = getLocalizedColorOptions(locale, colorsConfig);
|
|
49
|
-
const documentColorsCount = componentConfig.documentColors;
|
|
50
|
-
const hasColorPicker = componentConfig.colorPicker !== false;
|
|
51
|
-
// Register the UI component.
|
|
52
|
-
editor.ui.componentFactory.add(this.componentName, locale => {
|
|
53
|
-
const dropdownView = createDropdown(locale);
|
|
54
|
-
// Font color dropdown rendering is deferred once it gets open to improve performance (#6192).
|
|
55
|
-
let dropdownContentRendered = false;
|
|
56
|
-
this.colorSelectorView = addColorSelectorToDropdown({
|
|
57
|
-
dropdownView,
|
|
58
|
-
colors: localizedColors.map(option => ({
|
|
59
|
-
label: option.label,
|
|
60
|
-
color: option.model,
|
|
61
|
-
options: {
|
|
62
|
-
hasBorder: option.hasBorder
|
|
63
|
-
}
|
|
64
|
-
})),
|
|
65
|
-
columns: this.columns,
|
|
66
|
-
removeButtonLabel: t('Remove color'),
|
|
67
|
-
colorPickerLabel: t('Color picker'),
|
|
68
|
-
documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
|
|
69
|
-
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount,
|
|
70
|
-
colorPickerViewConfig: hasColorPicker ? (componentConfig.colorPicker || {}) : false
|
|
71
|
-
});
|
|
72
|
-
this.colorSelectorView.bind('selectedColor').to(command, 'value');
|
|
73
|
-
dropdownView.buttonView.set({
|
|
74
|
-
label: this.dropdownLabel,
|
|
75
|
-
icon: this.icon,
|
|
76
|
-
tooltip: true
|
|
77
|
-
});
|
|
78
|
-
dropdownView.extendTemplate({
|
|
79
|
-
attributes: {
|
|
80
|
-
class: 'ck-color-ui-dropdown'
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
dropdownView.bind('isEnabled').to(command);
|
|
84
|
-
this.colorSelectorView.on('execute', (evt, data) => {
|
|
85
|
-
if (dropdownView.isOpen) {
|
|
86
|
-
editor.execute(this.commandName, {
|
|
87
|
-
value: data.value,
|
|
88
|
-
batch: this._undoStepBatch
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (data.source !== 'colorPicker') {
|
|
92
|
-
editor.editing.view.focus();
|
|
93
|
-
}
|
|
94
|
-
if (data.source === 'colorPickerSaveButton') {
|
|
95
|
-
dropdownView.isOpen = false;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this.colorSelectorView.on('colorPicker:show', () => {
|
|
99
|
-
this._undoStepBatch = editor.model.createBatch();
|
|
100
|
-
});
|
|
101
|
-
this.colorSelectorView.on('colorPicker:cancel', () => {
|
|
102
|
-
if (this._undoStepBatch.operations.length) {
|
|
103
|
-
// We need to close the dropdown before the undo batch.
|
|
104
|
-
// Otherwise, ColorUI treats undo as a selected color change,
|
|
105
|
-
// propagating the update to the whole selection.
|
|
106
|
-
// That's an issue if spans with various colors were selected.
|
|
107
|
-
dropdownView.isOpen = false;
|
|
108
|
-
editor.execute('undo', this._undoStepBatch);
|
|
109
|
-
}
|
|
110
|
-
editor.editing.view.focus();
|
|
111
|
-
});
|
|
112
|
-
dropdownView.on('change:isOpen', (evt, name, isVisible) => {
|
|
113
|
-
if (!dropdownContentRendered) {
|
|
114
|
-
dropdownContentRendered = true;
|
|
115
|
-
dropdownView.colorSelectorView.appendUI();
|
|
116
|
-
}
|
|
117
|
-
if (isVisible) {
|
|
118
|
-
if (documentColorsCount !== 0) {
|
|
119
|
-
this.colorSelectorView.updateDocumentColors(editor.model, this.componentName);
|
|
120
|
-
}
|
|
121
|
-
this.colorSelectorView.updateSelectedColors();
|
|
122
|
-
this.colorSelectorView.showColorGridsFragment();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
// Accessibility: focus the first active color when opening the dropdown.
|
|
126
|
-
focusChildOnDropdownOpen(dropdownView, () => dropdownView.colorSelectorView.colorGridsFragmentView.staticColorsGrid.items.find((item) => item.isOn));
|
|
127
|
-
return dropdownView;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
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 } from 'ckeditor5/src/core';
|
|
9
|
+
import { createDropdown, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from 'ckeditor5/src/ui';
|
|
10
|
+
import { addColorSelectorToDropdown } from '../utils';
|
|
11
|
+
/**
|
|
12
|
+
* The color UI plugin which isolates the common logic responsible for displaying dropdowns with color grids.
|
|
13
|
+
*
|
|
14
|
+
* It is used to create the `'fontBackgroundColor'` and `'fontColor'` dropdowns, each hosting
|
|
15
|
+
* a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
|
|
16
|
+
*/
|
|
17
|
+
export default class ColorUI extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* Creates a plugin which introduces a dropdown with a pre–configured
|
|
20
|
+
* {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
|
|
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.colorSelectorView = 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 componentConfig = editor.config.get(this.componentName);
|
|
47
|
+
const colorsConfig = normalizeColorOptions(componentConfig.colors);
|
|
48
|
+
const localizedColors = getLocalizedColorOptions(locale, colorsConfig);
|
|
49
|
+
const documentColorsCount = componentConfig.documentColors;
|
|
50
|
+
const hasColorPicker = componentConfig.colorPicker !== false;
|
|
51
|
+
// Register the UI component.
|
|
52
|
+
editor.ui.componentFactory.add(this.componentName, locale => {
|
|
53
|
+
const dropdownView = createDropdown(locale);
|
|
54
|
+
// Font color dropdown rendering is deferred once it gets open to improve performance (#6192).
|
|
55
|
+
let dropdownContentRendered = false;
|
|
56
|
+
this.colorSelectorView = addColorSelectorToDropdown({
|
|
57
|
+
dropdownView,
|
|
58
|
+
colors: localizedColors.map(option => ({
|
|
59
|
+
label: option.label,
|
|
60
|
+
color: option.model,
|
|
61
|
+
options: {
|
|
62
|
+
hasBorder: option.hasBorder
|
|
63
|
+
}
|
|
64
|
+
})),
|
|
65
|
+
columns: this.columns,
|
|
66
|
+
removeButtonLabel: t('Remove color'),
|
|
67
|
+
colorPickerLabel: t('Color picker'),
|
|
68
|
+
documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
|
|
69
|
+
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount,
|
|
70
|
+
colorPickerViewConfig: hasColorPicker ? (componentConfig.colorPicker || {}) : false
|
|
71
|
+
});
|
|
72
|
+
this.colorSelectorView.bind('selectedColor').to(command, 'value');
|
|
73
|
+
dropdownView.buttonView.set({
|
|
74
|
+
label: this.dropdownLabel,
|
|
75
|
+
icon: this.icon,
|
|
76
|
+
tooltip: true
|
|
77
|
+
});
|
|
78
|
+
dropdownView.extendTemplate({
|
|
79
|
+
attributes: {
|
|
80
|
+
class: 'ck-color-ui-dropdown'
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
dropdownView.bind('isEnabled').to(command);
|
|
84
|
+
this.colorSelectorView.on('execute', (evt, data) => {
|
|
85
|
+
if (dropdownView.isOpen) {
|
|
86
|
+
editor.execute(this.commandName, {
|
|
87
|
+
value: data.value,
|
|
88
|
+
batch: this._undoStepBatch
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
if (data.source !== 'colorPicker') {
|
|
92
|
+
editor.editing.view.focus();
|
|
93
|
+
}
|
|
94
|
+
if (data.source === 'colorPickerSaveButton') {
|
|
95
|
+
dropdownView.isOpen = false;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.colorSelectorView.on('colorPicker:show', () => {
|
|
99
|
+
this._undoStepBatch = editor.model.createBatch();
|
|
100
|
+
});
|
|
101
|
+
this.colorSelectorView.on('colorPicker:cancel', () => {
|
|
102
|
+
if (this._undoStepBatch.operations.length) {
|
|
103
|
+
// We need to close the dropdown before the undo batch.
|
|
104
|
+
// Otherwise, ColorUI treats undo as a selected color change,
|
|
105
|
+
// propagating the update to the whole selection.
|
|
106
|
+
// That's an issue if spans with various colors were selected.
|
|
107
|
+
dropdownView.isOpen = false;
|
|
108
|
+
editor.execute('undo', this._undoStepBatch);
|
|
109
|
+
}
|
|
110
|
+
editor.editing.view.focus();
|
|
111
|
+
});
|
|
112
|
+
dropdownView.on('change:isOpen', (evt, name, isVisible) => {
|
|
113
|
+
if (!dropdownContentRendered) {
|
|
114
|
+
dropdownContentRendered = true;
|
|
115
|
+
dropdownView.colorSelectorView.appendUI();
|
|
116
|
+
}
|
|
117
|
+
if (isVisible) {
|
|
118
|
+
if (documentColorsCount !== 0) {
|
|
119
|
+
this.colorSelectorView.updateDocumentColors(editor.model, this.componentName);
|
|
120
|
+
}
|
|
121
|
+
this.colorSelectorView.updateSelectedColors();
|
|
122
|
+
this.colorSelectorView.showColorGridsFragment();
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
// Accessibility: focus the first active color when opening the dropdown.
|
|
126
|
+
focusChildOnDropdownOpen(dropdownView, () => dropdownView.colorSelectorView.colorGridsFragmentView.staticColorsGrid.items.find((item) => item.isOn));
|
|
127
|
+
return dropdownView;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/utils.d.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
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 type { FontFamilyOption, FontSizeOption } from './fontconfig';
|
|
9
|
-
import { ColorSelectorView, type ColorDefinition, type ColorPickerViewConfig, type DropdownView } from 'ckeditor5/src/ui';
|
|
10
|
-
import type { ArrayOrItem } from 'ckeditor5/src/utils';
|
|
11
|
-
import type { ViewAttributeElement, ViewElement, MatcherPattern, ViewElementDefinition, DowncastConversionApi } from 'ckeditor5/src/engine';
|
|
12
|
-
/**
|
|
13
|
-
* The name of the font size plugin.
|
|
14
|
-
*/
|
|
15
|
-
export declare const FONT_SIZE = "fontSize";
|
|
16
|
-
/**
|
|
17
|
-
* The name of the font family plugin.
|
|
18
|
-
*/
|
|
19
|
-
export declare const FONT_FAMILY = "fontFamily";
|
|
20
|
-
/**
|
|
21
|
-
* The name of the font color plugin.
|
|
22
|
-
*/
|
|
23
|
-
export declare const FONT_COLOR = "fontColor";
|
|
24
|
-
/**
|
|
25
|
-
* The name of the font background color plugin.
|
|
26
|
-
*/
|
|
27
|
-
export declare const FONT_BACKGROUND_COLOR = "fontBackgroundColor";
|
|
28
|
-
/**
|
|
29
|
-
* Builds a proper converter definition out of input data.
|
|
30
|
-
*/
|
|
31
|
-
export declare function buildDefinition(modelAttributeKey: string, options: Array<FontFamilyOption> | Array<FontSizeOption>): FontConverterDefinition;
|
|
32
|
-
export type FontConverterDefinition = {
|
|
33
|
-
model: {
|
|
34
|
-
key: string;
|
|
35
|
-
values: Array<string>;
|
|
36
|
-
};
|
|
37
|
-
view: Record<string, ViewElementDefinition>;
|
|
38
|
-
upcastAlso: Record<string, ArrayOrItem<MatcherPattern>>;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* A {@link module:font/fontcolor~FontColor font color} and
|
|
42
|
-
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
43
|
-
* responsible for upcasting data to the model.
|
|
44
|
-
*
|
|
45
|
-
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
46
|
-
*/
|
|
47
|
-
export declare function renderUpcastAttribute(styleAttr: string): (viewElement: ViewElement) => string;
|
|
48
|
-
/**
|
|
49
|
-
* A {@link module:font/fontcolor~FontColor font color} and
|
|
50
|
-
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
51
|
-
* responsible for downcasting a color attribute to a `<span>` element.
|
|
52
|
-
*
|
|
53
|
-
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
54
|
-
*/
|
|
55
|
-
export declare function renderDowncastElement(styleAttr: string): (modelAttributeValue: string, { writer }: DowncastConversionApi) => ViewAttributeElement;
|
|
56
|
-
/**
|
|
57
|
-
* A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
|
|
58
|
-
*
|
|
59
|
-
* @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
|
|
60
|
-
* will be added.
|
|
61
|
-
* @param config.colors An array with definitions representing colors to be displayed in the color selector.
|
|
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
|
-
* @param config.colorPickerViewConfig Configuration of the color picker view.
|
|
66
|
-
* @returns The new color selector view.
|
|
67
|
-
*/
|
|
68
|
-
export declare function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }: {
|
|
69
|
-
dropdownView: ColorSelectorDropdownView;
|
|
70
|
-
colors: Array<ColorDefinition>;
|
|
71
|
-
columns: number;
|
|
72
|
-
removeButtonLabel: string;
|
|
73
|
-
colorPickerLabel: string;
|
|
74
|
-
documentColorsLabel?: string;
|
|
75
|
-
documentColorsCount?: number;
|
|
76
|
-
colorPickerViewConfig: ColorPickerViewConfig | false;
|
|
77
|
-
}): ColorSelectorView;
|
|
78
|
-
export type ColorSelectorDropdownView = DropdownView & {
|
|
79
|
-
colorSelectorView?: ColorSelectorView;
|
|
80
|
-
};
|
|
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 type { FontFamilyOption, FontSizeOption } from './fontconfig';
|
|
9
|
+
import { ColorSelectorView, type ColorDefinition, type ColorPickerViewConfig, type DropdownView } from 'ckeditor5/src/ui';
|
|
10
|
+
import type { ArrayOrItem } from 'ckeditor5/src/utils';
|
|
11
|
+
import type { ViewAttributeElement, ViewElement, MatcherPattern, ViewElementDefinition, DowncastConversionApi } from 'ckeditor5/src/engine';
|
|
12
|
+
/**
|
|
13
|
+
* The name of the font size plugin.
|
|
14
|
+
*/
|
|
15
|
+
export declare const FONT_SIZE = "fontSize";
|
|
16
|
+
/**
|
|
17
|
+
* The name of the font family plugin.
|
|
18
|
+
*/
|
|
19
|
+
export declare const FONT_FAMILY = "fontFamily";
|
|
20
|
+
/**
|
|
21
|
+
* The name of the font color plugin.
|
|
22
|
+
*/
|
|
23
|
+
export declare const FONT_COLOR = "fontColor";
|
|
24
|
+
/**
|
|
25
|
+
* The name of the font background color plugin.
|
|
26
|
+
*/
|
|
27
|
+
export declare const FONT_BACKGROUND_COLOR = "fontBackgroundColor";
|
|
28
|
+
/**
|
|
29
|
+
* Builds a proper converter definition out of input data.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildDefinition(modelAttributeKey: string, options: Array<FontFamilyOption> | Array<FontSizeOption>): FontConverterDefinition;
|
|
32
|
+
export type FontConverterDefinition = {
|
|
33
|
+
model: {
|
|
34
|
+
key: string;
|
|
35
|
+
values: Array<string>;
|
|
36
|
+
};
|
|
37
|
+
view: Record<string, ViewElementDefinition>;
|
|
38
|
+
upcastAlso: Record<string, ArrayOrItem<MatcherPattern>>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
42
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
43
|
+
* responsible for upcasting data to the model.
|
|
44
|
+
*
|
|
45
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderUpcastAttribute(styleAttr: string): (viewElement: ViewElement) => string;
|
|
48
|
+
/**
|
|
49
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
50
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
51
|
+
* responsible for downcasting a color attribute to a `<span>` element.
|
|
52
|
+
*
|
|
53
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function renderDowncastElement(styleAttr: string): (modelAttributeValue: string, { writer }: DowncastConversionApi) => ViewAttributeElement;
|
|
56
|
+
/**
|
|
57
|
+
* A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
|
|
58
|
+
*
|
|
59
|
+
* @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
|
|
60
|
+
* will be added.
|
|
61
|
+
* @param config.colors An array with definitions representing colors to be displayed in the color selector.
|
|
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
|
+
* @param config.colorPickerViewConfig Configuration of the color picker view.
|
|
66
|
+
* @returns The new color selector view.
|
|
67
|
+
*/
|
|
68
|
+
export declare function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }: {
|
|
69
|
+
dropdownView: ColorSelectorDropdownView;
|
|
70
|
+
colors: Array<ColorDefinition>;
|
|
71
|
+
columns: number;
|
|
72
|
+
removeButtonLabel: string;
|
|
73
|
+
colorPickerLabel: string;
|
|
74
|
+
documentColorsLabel?: string;
|
|
75
|
+
documentColorsCount?: number;
|
|
76
|
+
colorPickerViewConfig: ColorPickerViewConfig | false;
|
|
77
|
+
}): ColorSelectorView;
|
|
78
|
+
export type ColorSelectorDropdownView = DropdownView & {
|
|
79
|
+
colorSelectorView?: ColorSelectorView;
|
|
80
|
+
};
|
package/src/utils.js
CHANGED
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { ColorSelectorView } from 'ckeditor5/src/ui';
|
|
6
|
-
/**
|
|
7
|
-
* The name of the font size plugin.
|
|
8
|
-
*/
|
|
9
|
-
export const FONT_SIZE = 'fontSize';
|
|
10
|
-
/**
|
|
11
|
-
* The name of the font family plugin.
|
|
12
|
-
*/
|
|
13
|
-
export const FONT_FAMILY = 'fontFamily';
|
|
14
|
-
/**
|
|
15
|
-
* The name of the font color plugin.
|
|
16
|
-
*/
|
|
17
|
-
export const FONT_COLOR = 'fontColor';
|
|
18
|
-
/**
|
|
19
|
-
* The name of the font background color plugin.
|
|
20
|
-
*/
|
|
21
|
-
export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
|
|
22
|
-
/**
|
|
23
|
-
* Builds a proper converter definition out of input data.
|
|
24
|
-
*/
|
|
25
|
-
export function buildDefinition(modelAttributeKey, options) {
|
|
26
|
-
const definition = {
|
|
27
|
-
model: {
|
|
28
|
-
key: modelAttributeKey,
|
|
29
|
-
values: []
|
|
30
|
-
},
|
|
31
|
-
view: {},
|
|
32
|
-
upcastAlso: {}
|
|
33
|
-
};
|
|
34
|
-
for (const option of options) {
|
|
35
|
-
definition.model.values.push(option.model);
|
|
36
|
-
definition.view[option.model] = option.view;
|
|
37
|
-
if (option.upcastAlso) {
|
|
38
|
-
definition.upcastAlso[option.model] = option.upcastAlso;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return definition;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* A {@link module:font/fontcolor~FontColor font color} and
|
|
45
|
-
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
46
|
-
* responsible for upcasting data to the model.
|
|
47
|
-
*
|
|
48
|
-
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
49
|
-
*/
|
|
50
|
-
export function renderUpcastAttribute(styleAttr) {
|
|
51
|
-
return (viewElement) => normalizeColorCode(viewElement.getStyle(styleAttr));
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* A {@link module:font/fontcolor~FontColor font color} and
|
|
55
|
-
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
56
|
-
* responsible for downcasting a color attribute to a `<span>` element.
|
|
57
|
-
*
|
|
58
|
-
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
59
|
-
*/
|
|
60
|
-
export function renderDowncastElement(styleAttr) {
|
|
61
|
-
return (modelAttributeValue, { writer }) => writer.createAttributeElement('span', {
|
|
62
|
-
style: `${styleAttr}:${modelAttributeValue}`
|
|
63
|
-
}, { priority: 7 });
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
|
|
67
|
-
*
|
|
68
|
-
* @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
|
|
69
|
-
* will be added.
|
|
70
|
-
* @param config.colors An array with definitions representing colors to be displayed in the color selector.
|
|
71
|
-
* @param config.removeButtonLabel The label for the button responsible for removing the color.
|
|
72
|
-
* @param config.documentColorsLabel The label for the section with document colors.
|
|
73
|
-
* @param config.documentColorsCount The number of document colors inside the dropdown.
|
|
74
|
-
* @param config.colorPickerViewConfig Configuration of the color picker view.
|
|
75
|
-
* @returns The new color selector view.
|
|
76
|
-
*/
|
|
77
|
-
export function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }) {
|
|
78
|
-
const locale = dropdownView.locale;
|
|
79
|
-
const colorSelectorView = new ColorSelectorView(locale, {
|
|
80
|
-
colors,
|
|
81
|
-
columns,
|
|
82
|
-
removeButtonLabel,
|
|
83
|
-
colorPickerLabel,
|
|
84
|
-
documentColorsLabel,
|
|
85
|
-
documentColorsCount,
|
|
86
|
-
colorPickerViewConfig
|
|
87
|
-
});
|
|
88
|
-
dropdownView.colorSelectorView = colorSelectorView;
|
|
89
|
-
dropdownView.panelView.children.add(colorSelectorView);
|
|
90
|
-
return colorSelectorView;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Fixes the color value string.
|
|
94
|
-
*/
|
|
95
|
-
function normalizeColorCode(value) {
|
|
96
|
-
return value.replace(/\s/g, '');
|
|
97
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { ColorSelectorView } from 'ckeditor5/src/ui';
|
|
6
|
+
/**
|
|
7
|
+
* The name of the font size plugin.
|
|
8
|
+
*/
|
|
9
|
+
export const FONT_SIZE = 'fontSize';
|
|
10
|
+
/**
|
|
11
|
+
* The name of the font family plugin.
|
|
12
|
+
*/
|
|
13
|
+
export const FONT_FAMILY = 'fontFamily';
|
|
14
|
+
/**
|
|
15
|
+
* The name of the font color plugin.
|
|
16
|
+
*/
|
|
17
|
+
export const FONT_COLOR = 'fontColor';
|
|
18
|
+
/**
|
|
19
|
+
* The name of the font background color plugin.
|
|
20
|
+
*/
|
|
21
|
+
export const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
|
|
22
|
+
/**
|
|
23
|
+
* Builds a proper converter definition out of input data.
|
|
24
|
+
*/
|
|
25
|
+
export function buildDefinition(modelAttributeKey, options) {
|
|
26
|
+
const definition = {
|
|
27
|
+
model: {
|
|
28
|
+
key: modelAttributeKey,
|
|
29
|
+
values: []
|
|
30
|
+
},
|
|
31
|
+
view: {},
|
|
32
|
+
upcastAlso: {}
|
|
33
|
+
};
|
|
34
|
+
for (const option of options) {
|
|
35
|
+
definition.model.values.push(option.model);
|
|
36
|
+
definition.view[option.model] = option.view;
|
|
37
|
+
if (option.upcastAlso) {
|
|
38
|
+
definition.upcastAlso[option.model] = option.upcastAlso;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return definition;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
45
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
46
|
+
* responsible for upcasting data to the model.
|
|
47
|
+
*
|
|
48
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
49
|
+
*/
|
|
50
|
+
export function renderUpcastAttribute(styleAttr) {
|
|
51
|
+
return (viewElement) => normalizeColorCode(viewElement.getStyle(styleAttr));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
55
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
56
|
+
* responsible for downcasting a color attribute to a `<span>` element.
|
|
57
|
+
*
|
|
58
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
59
|
+
*/
|
|
60
|
+
export function renderDowncastElement(styleAttr) {
|
|
61
|
+
return (modelAttributeValue, { writer }) => writer.createAttributeElement('span', {
|
|
62
|
+
style: `${styleAttr}:${modelAttributeValue}`
|
|
63
|
+
}, { priority: 7 });
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
|
|
67
|
+
*
|
|
68
|
+
* @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
|
|
69
|
+
* will be added.
|
|
70
|
+
* @param config.colors An array with definitions representing colors to be displayed in the color selector.
|
|
71
|
+
* @param config.removeButtonLabel The label for the button responsible for removing the color.
|
|
72
|
+
* @param config.documentColorsLabel The label for the section with document colors.
|
|
73
|
+
* @param config.documentColorsCount The number of document colors inside the dropdown.
|
|
74
|
+
* @param config.colorPickerViewConfig Configuration of the color picker view.
|
|
75
|
+
* @returns The new color selector view.
|
|
76
|
+
*/
|
|
77
|
+
export function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }) {
|
|
78
|
+
const locale = dropdownView.locale;
|
|
79
|
+
const colorSelectorView = new ColorSelectorView(locale, {
|
|
80
|
+
colors,
|
|
81
|
+
columns,
|
|
82
|
+
removeButtonLabel,
|
|
83
|
+
colorPickerLabel,
|
|
84
|
+
documentColorsLabel,
|
|
85
|
+
documentColorsCount,
|
|
86
|
+
colorPickerViewConfig
|
|
87
|
+
});
|
|
88
|
+
dropdownView.colorSelectorView = colorSelectorView;
|
|
89
|
+
dropdownView.panelView.children.add(colorSelectorView);
|
|
90
|
+
return colorSelectorView;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Fixes the color value string.
|
|
94
|
+
*/
|
|
95
|
+
function normalizeColorCode(value) {
|
|
96
|
+
return value.replace(/\s/g, '');
|
|
97
|
+
}
|