@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
|
@@ -2,31 +2,27 @@
|
|
|
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/fontsize/fontsizeediting
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import { CKEditorError } from 'ckeditor5/src/utils';
|
|
12
10
|
import { isLength, isPercentage } from 'ckeditor5/src/engine';
|
|
13
|
-
|
|
14
11
|
import FontSizeCommand from './fontsizecommand';
|
|
15
12
|
import { normalizeOptions } from './utils';
|
|
16
13
|
import { buildDefinition, FONT_SIZE } from '../utils';
|
|
17
|
-
|
|
14
|
+
import '../fontconfig';
|
|
18
15
|
// Mapping of `<font size="..">` styling to CSS's `font-size` values.
|
|
19
16
|
const styleFontSize = [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
'x-small',
|
|
18
|
+
'x-small',
|
|
19
|
+
'small',
|
|
20
|
+
'medium',
|
|
21
|
+
'large',
|
|
22
|
+
'x-large',
|
|
23
|
+
'xx-large',
|
|
24
|
+
'xxx-large'
|
|
28
25
|
];
|
|
29
|
-
|
|
30
26
|
/**
|
|
31
27
|
* The font size editing feature.
|
|
32
28
|
*
|
|
@@ -36,162 +32,135 @@ const styleFontSize = [
|
|
|
36
32
|
* * a style attribute (`<span style="font-size:12px">...</span>`),
|
|
37
33
|
* * or a class attribute (`<span class="text-small">...</span>`)
|
|
38
34
|
*
|
|
39
|
-
* depending on the {@link module:font/
|
|
40
|
-
*
|
|
41
|
-
* @extends module:core/plugin~Plugin
|
|
35
|
+
* depending on the {@link module:font/fontconfig~FontSizeConfig configuration}.
|
|
42
36
|
*/
|
|
43
37
|
export default class FontSizeEditing extends Plugin {
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
173
|
-
'size': /^[+-]?\d{1,3}$/
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
model: {
|
|
177
|
-
key: FONT_SIZE,
|
|
178
|
-
value: viewElement => {
|
|
179
|
-
const value = viewElement.getAttribute( 'size' );
|
|
180
|
-
const isRelative = value[ 0 ] === '-' || value[ 0 ] === '+';
|
|
181
|
-
|
|
182
|
-
let size = parseInt( value, 10 );
|
|
183
|
-
|
|
184
|
-
if ( isRelative ) {
|
|
185
|
-
// Add relative size (which can be negative) to the default size = 3.
|
|
186
|
-
size = 3 + size;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const maxSize = styleFontSize.length - 1;
|
|
190
|
-
const clampedSize = Math.min( Math.max( size, 0 ), maxSize );
|
|
191
|
-
|
|
192
|
-
return styleFontSize[ clampedSize ];
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
} );
|
|
196
|
-
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritDoc
|
|
40
|
+
*/
|
|
41
|
+
static get pluginName() {
|
|
42
|
+
return 'FontSizeEditing';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
47
|
+
constructor(editor) {
|
|
48
|
+
super(editor);
|
|
49
|
+
// Define default configuration using named presets.
|
|
50
|
+
editor.config.define(FONT_SIZE, {
|
|
51
|
+
options: [
|
|
52
|
+
'tiny',
|
|
53
|
+
'small',
|
|
54
|
+
'default',
|
|
55
|
+
'big',
|
|
56
|
+
'huge'
|
|
57
|
+
],
|
|
58
|
+
supportAllValues: false
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @inheritDoc
|
|
63
|
+
*/
|
|
64
|
+
init() {
|
|
65
|
+
const editor = this.editor;
|
|
66
|
+
// Allow fontSize attribute on text nodes.
|
|
67
|
+
editor.model.schema.extend('$text', { allowAttributes: FONT_SIZE });
|
|
68
|
+
editor.model.schema.setAttributeProperties(FONT_SIZE, {
|
|
69
|
+
isFormatting: true,
|
|
70
|
+
copyOnEnter: true
|
|
71
|
+
});
|
|
72
|
+
const supportAllValues = editor.config.get('fontSize.supportAllValues');
|
|
73
|
+
// Define view to model conversion.
|
|
74
|
+
const options = normalizeOptions(this.editor.config.get('fontSize.options'))
|
|
75
|
+
.filter(item => item.model);
|
|
76
|
+
const definition = buildDefinition(FONT_SIZE, options);
|
|
77
|
+
// Set-up the two-way conversion.
|
|
78
|
+
if (supportAllValues) {
|
|
79
|
+
this._prepareAnyValueConverters(definition);
|
|
80
|
+
this._prepareCompatibilityConverter();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
editor.conversion.attributeToElement(definition);
|
|
84
|
+
}
|
|
85
|
+
// Add FontSize command.
|
|
86
|
+
editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
90
|
+
* if it is not defined in the plugin configuration.
|
|
91
|
+
*
|
|
92
|
+
* @param definition Converter definition out of input data.
|
|
93
|
+
*/
|
|
94
|
+
_prepareAnyValueConverters(definition) {
|
|
95
|
+
const editor = this.editor;
|
|
96
|
+
// If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
|
|
97
|
+
const presets = definition.model.values.filter((value) => {
|
|
98
|
+
return !isLength(String(value)) && !isPercentage(String(value));
|
|
99
|
+
});
|
|
100
|
+
if (presets.length) {
|
|
101
|
+
/**
|
|
102
|
+
* If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
|
|
103
|
+
* you need to use numerical values as font size options.
|
|
104
|
+
*
|
|
105
|
+
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
106
|
+
*
|
|
107
|
+
* @error font-size-invalid-use-of-named-presets
|
|
108
|
+
* @param {Array.<String>} presets Invalid values.
|
|
109
|
+
*/
|
|
110
|
+
throw new CKEditorError('font-size-invalid-use-of-named-presets', null, { presets });
|
|
111
|
+
}
|
|
112
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
113
|
+
model: FONT_SIZE,
|
|
114
|
+
view: (attributeValue, { writer }) => {
|
|
115
|
+
if (!attributeValue) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
return writer.createAttributeElement('span', { style: 'font-size:' + attributeValue }, { priority: 7 });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
122
|
+
model: {
|
|
123
|
+
key: FONT_SIZE,
|
|
124
|
+
value: (viewElement) => viewElement.getStyle('font-size')
|
|
125
|
+
},
|
|
126
|
+
view: {
|
|
127
|
+
name: 'span',
|
|
128
|
+
styles: {
|
|
129
|
+
'font-size': /.*/
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Adds support for legacy `<font size="..">` formatting.
|
|
136
|
+
*/
|
|
137
|
+
_prepareCompatibilityConverter() {
|
|
138
|
+
const editor = this.editor;
|
|
139
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
140
|
+
view: {
|
|
141
|
+
name: 'font',
|
|
142
|
+
attributes: {
|
|
143
|
+
// Documentation mentions sizes from 1 to 7. To handle old content we support all values
|
|
144
|
+
// up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
|
|
145
|
+
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
146
|
+
'size': /^[+-]?\d{1,3}$/
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
model: {
|
|
150
|
+
key: FONT_SIZE,
|
|
151
|
+
value: (viewElement) => {
|
|
152
|
+
const value = viewElement.getAttribute('size');
|
|
153
|
+
const isRelative = value[0] === '-' || value[0] === '+';
|
|
154
|
+
let size = parseInt(value, 10);
|
|
155
|
+
if (isRelative) {
|
|
156
|
+
// Add relative size (which can be negative) to the default size = 3.
|
|
157
|
+
size = 3 + size;
|
|
158
|
+
}
|
|
159
|
+
const maxSize = styleFontSize.length - 1;
|
|
160
|
+
const clampedSize = Math.min(Math.max(size, 0), maxSize);
|
|
161
|
+
return styleFontSize[clampedSize];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
197
166
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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/fontsize/fontsizeui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import '../../theme/fontsize.css';
|
|
10
|
+
/**
|
|
11
|
+
* The font size UI plugin. It introduces the `'fontSize'` dropdown.
|
|
12
|
+
*/
|
|
13
|
+
export default class FontSizeUI extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName(): 'FontSizeUI';
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
init(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
24
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
25
|
+
* in the correct language.
|
|
26
|
+
*
|
|
27
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
28
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
29
|
+
*/
|
|
30
|
+
private _getLocalizedOptions;
|
|
31
|
+
}
|
|
32
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
33
|
+
interface PluginsMap {
|
|
34
|
+
[FontSizeUI.pluginName]: FontSizeUI;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -2,148 +2,116 @@
|
|
|
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/fontsize/fontsizeui
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Plugin } from 'ckeditor5/src/core';
|
|
11
9
|
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
12
10
|
import { Collection } from 'ckeditor5/src/utils';
|
|
13
|
-
|
|
14
11
|
import { normalizeOptions } from './utils';
|
|
15
12
|
import { FONT_SIZE } from '../utils';
|
|
16
|
-
|
|
17
|
-
import fontSizeIcon from '../../theme/icons/font-size.svg';
|
|
18
13
|
import '../../theme/fontsize.css';
|
|
19
|
-
|
|
14
|
+
import fontSizeIcon from '../../theme/icons/font-size.svg';
|
|
20
15
|
/**
|
|
21
16
|
* The font size UI plugin. It introduces the `'fontSize'` dropdown.
|
|
22
|
-
*
|
|
23
|
-
* @extends module:core/plugin~Plugin
|
|
24
17
|
*/
|
|
25
18
|
export default class FontSizeUI extends Plugin {
|
|
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
|
-
Tiny: t( 'Tiny' ),
|
|
95
|
-
Small: t( 'Small' ),
|
|
96
|
-
Big: t( 'Big' ),
|
|
97
|
-
Huge: t( 'Huge' )
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const options = normalizeOptions( editor.config.get( FONT_SIZE ).options );
|
|
101
|
-
|
|
102
|
-
return options.map( option => {
|
|
103
|
-
const title = localizedTitles[ option.title ];
|
|
104
|
-
|
|
105
|
-
if ( title && title != option.title ) {
|
|
106
|
-
// Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
|
|
107
|
-
option = Object.assign( {}, option, { title } );
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return option;
|
|
111
|
-
} );
|
|
112
|
-
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName() {
|
|
23
|
+
return 'FontSizeUI';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
init() {
|
|
29
|
+
const editor = this.editor;
|
|
30
|
+
const t = editor.t;
|
|
31
|
+
const options = this._getLocalizedOptions();
|
|
32
|
+
const command = editor.commands.get(FONT_SIZE);
|
|
33
|
+
// Register UI component.
|
|
34
|
+
editor.ui.componentFactory.add(FONT_SIZE, locale => {
|
|
35
|
+
const dropdownView = createDropdown(locale);
|
|
36
|
+
addListToDropdown(dropdownView, () => _prepareListOptions(options, command));
|
|
37
|
+
// Create dropdown model.
|
|
38
|
+
dropdownView.buttonView.set({
|
|
39
|
+
label: t('Font Size'),
|
|
40
|
+
icon: fontSizeIcon,
|
|
41
|
+
tooltip: true
|
|
42
|
+
});
|
|
43
|
+
dropdownView.extendTemplate({
|
|
44
|
+
attributes: {
|
|
45
|
+
class: [
|
|
46
|
+
'ck-font-size-dropdown'
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
dropdownView.bind('isEnabled').to(command);
|
|
51
|
+
// Execute command when an item from the dropdown is selected.
|
|
52
|
+
this.listenTo(dropdownView, 'execute', evt => {
|
|
53
|
+
editor.execute(evt.source.commandName, { value: evt.source.commandParam });
|
|
54
|
+
editor.editing.view.focus();
|
|
55
|
+
});
|
|
56
|
+
return dropdownView;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
61
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
62
|
+
* in the correct language.
|
|
63
|
+
*
|
|
64
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
65
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
66
|
+
*/
|
|
67
|
+
_getLocalizedOptions() {
|
|
68
|
+
const editor = this.editor;
|
|
69
|
+
const t = editor.t;
|
|
70
|
+
const localizedTitles = {
|
|
71
|
+
Default: t('Default'),
|
|
72
|
+
Tiny: t('Tiny'),
|
|
73
|
+
Small: t('Small'),
|
|
74
|
+
Big: t('Big'),
|
|
75
|
+
Huge: t('Huge')
|
|
76
|
+
};
|
|
77
|
+
const options = normalizeOptions((editor.config.get(FONT_SIZE)).options);
|
|
78
|
+
return options.map(option => {
|
|
79
|
+
const title = localizedTitles[option.title];
|
|
80
|
+
if (title && title != option.title) {
|
|
81
|
+
// Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
|
|
82
|
+
option = Object.assign({}, option, { title });
|
|
83
|
+
}
|
|
84
|
+
return option;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
113
87
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// Add the option to the collection.
|
|
145
|
-
itemDefinitions.add( def );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return itemDefinitions;
|
|
88
|
+
/**
|
|
89
|
+
* Prepares FontSize dropdown items.
|
|
90
|
+
*/
|
|
91
|
+
function _prepareListOptions(options, command) {
|
|
92
|
+
const itemDefinitions = new Collection();
|
|
93
|
+
for (const option of options) {
|
|
94
|
+
const def = {
|
|
95
|
+
type: 'button',
|
|
96
|
+
model: new Model({
|
|
97
|
+
commandName: FONT_SIZE,
|
|
98
|
+
commandParam: option.model,
|
|
99
|
+
label: option.title,
|
|
100
|
+
class: 'ck-fontsize-option',
|
|
101
|
+
withText: true
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
if (option.view && typeof option.view !== 'string') {
|
|
105
|
+
if (option.view.styles) {
|
|
106
|
+
def.model.set('labelStyle', `font-size:${option.view.styles['font-size']}`);
|
|
107
|
+
}
|
|
108
|
+
if (option.view.classes) {
|
|
109
|
+
def.model.set('class', `${def.model.class} ${option.view.classes}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
def.model.bind('isOn').to(command, 'value', value => value === option.model);
|
|
113
|
+
// Add the option to the collection.
|
|
114
|
+
itemDefinitions.add(def);
|
|
115
|
+
}
|
|
116
|
+
return itemDefinitions;
|
|
149
117
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { type FontSizeOption } from '../fontconfig';
|
|
6
|
+
/**
|
|
7
|
+
* Normalizes and translates the {@link module:font/fontconfig~FontSizeConfig#options configuration options}
|
|
8
|
+
* to the {@link module:font/fontconfig~FontSizeOption} format.
|
|
9
|
+
*
|
|
10
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeOptions(configuredOptions: Array<string | number | FontSizeOption>): Array<FontSizeOption>;
|