@ckeditor/ckeditor5-font 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/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
package/src/fontcommand.js
CHANGED
|
@@ -2,90 +2,66 @@
|
|
|
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/fontcommand
|
|
8
7
|
*/
|
|
9
|
-
|
|
10
8
|
import { Command } from 'ckeditor5/src/core';
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* The base font command.
|
|
14
|
-
*
|
|
15
|
-
* @extends module:core/command~Command
|
|
16
11
|
*/
|
|
17
12
|
export default class FontCommand extends Command {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
if ( selection.isCollapsed ) {
|
|
73
|
-
if ( value ) {
|
|
74
|
-
writer.setSelectionAttribute( this.attributeKey, value );
|
|
75
|
-
} else {
|
|
76
|
-
writer.removeSelectionAttribute( this.attributeKey );
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
const ranges = model.schema.getValidRanges( selection.getRanges(), this.attributeKey );
|
|
80
|
-
|
|
81
|
-
for ( const range of ranges ) {
|
|
82
|
-
if ( value ) {
|
|
83
|
-
writer.setAttribute( this.attributeKey, value, range );
|
|
84
|
-
} else {
|
|
85
|
-
writer.removeAttribute( this.attributeKey, range );
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
} );
|
|
90
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of the command.
|
|
15
|
+
*
|
|
16
|
+
* @param editor Editor instance.
|
|
17
|
+
* @param attributeKey The name of a model attribute on which this command operates.
|
|
18
|
+
*/
|
|
19
|
+
constructor(editor, attributeKey) {
|
|
20
|
+
super(editor);
|
|
21
|
+
this.attributeKey = attributeKey;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
refresh() {
|
|
27
|
+
const model = this.editor.model;
|
|
28
|
+
const doc = model.document;
|
|
29
|
+
this.value = doc.selection.getAttribute(this.attributeKey);
|
|
30
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, this.attributeKey);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the command. Applies the `value` of the {@link #attributeKey} to the selection.
|
|
34
|
+
* If no `value` is passed, it removes the attribute from the selection.
|
|
35
|
+
*
|
|
36
|
+
* @param options Options for the executed command.
|
|
37
|
+
* @param options.value The value to apply.
|
|
38
|
+
* @fires execute
|
|
39
|
+
*/
|
|
40
|
+
execute(options = {}) {
|
|
41
|
+
const model = this.editor.model;
|
|
42
|
+
const document = model.document;
|
|
43
|
+
const selection = document.selection;
|
|
44
|
+
const value = options.value;
|
|
45
|
+
model.change(writer => {
|
|
46
|
+
if (selection.isCollapsed) {
|
|
47
|
+
if (value) {
|
|
48
|
+
writer.setSelectionAttribute(this.attributeKey, value);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
writer.removeSelectionAttribute(this.attributeKey);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const ranges = model.schema.getValidRanges(selection.getRanges(), this.attributeKey);
|
|
56
|
+
for (const range of ranges) {
|
|
57
|
+
if (value) {
|
|
58
|
+
writer.setAttribute(this.attributeKey, value, range);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
writer.removeAttribute(this.attributeKey, range);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
91
67
|
}
|
|
@@ -0,0 +1,399 @@
|
|
|
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/fontconfig
|
|
7
|
+
*/
|
|
8
|
+
import type { ColorOption } from 'ckeditor5/src/ui';
|
|
9
|
+
import type { MatcherPattern, ViewElementDefinition } from 'ckeditor5/src/engine';
|
|
10
|
+
/**
|
|
11
|
+
* The configuration of the font color and font background color features.
|
|
12
|
+
* This option is used by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} and
|
|
13
|
+
* {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} features.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* ClassicEditor
|
|
17
|
+
* .create( {
|
|
18
|
+
* fontColor: ... // Font color feature configuration.
|
|
19
|
+
* fontBackgroundColor: ... // Font background color feature configuration.
|
|
20
|
+
* } )
|
|
21
|
+
* .then( ... )
|
|
22
|
+
* .catch( ... );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
26
|
+
*/
|
|
27
|
+
export interface FontColorConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Available font colors defined as an array of strings or objects.
|
|
30
|
+
*
|
|
31
|
+
* The default value registers the following colors:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const fontColorConfig = {
|
|
35
|
+
* colors: [
|
|
36
|
+
* {
|
|
37
|
+
* color: 'hsl(0, 0%, 0%)',
|
|
38
|
+
* label: 'Black'
|
|
39
|
+
* },
|
|
40
|
+
* {
|
|
41
|
+
* color: 'hsl(0, 0%, 30%)',
|
|
42
|
+
* label: 'Dim grey'
|
|
43
|
+
* },
|
|
44
|
+
* {
|
|
45
|
+
* color: 'hsl(0, 0%, 60%)',
|
|
46
|
+
* label: 'Grey'
|
|
47
|
+
* },
|
|
48
|
+
* {
|
|
49
|
+
* color: 'hsl(0, 0%, 90%)',
|
|
50
|
+
* label: 'Light grey'
|
|
51
|
+
* },
|
|
52
|
+
* {
|
|
53
|
+
* color: 'hsl(0, 0%, 100%)',
|
|
54
|
+
* label: 'White',
|
|
55
|
+
* hasBorder: true
|
|
56
|
+
* },
|
|
57
|
+
* {
|
|
58
|
+
* color: 'hsl(0, 75%, 60%)',
|
|
59
|
+
* label: 'Red'
|
|
60
|
+
* },
|
|
61
|
+
* {
|
|
62
|
+
* color: 'hsl(30, 75%, 60%)',
|
|
63
|
+
* label: 'Orange'
|
|
64
|
+
* },
|
|
65
|
+
* {
|
|
66
|
+
* color: 'hsl(60, 75%, 60%)',
|
|
67
|
+
* label: 'Yellow'
|
|
68
|
+
* },
|
|
69
|
+
* {
|
|
70
|
+
* color: 'hsl(90, 75%, 60%)',
|
|
71
|
+
* label: 'Light green'
|
|
72
|
+
* },
|
|
73
|
+
* {
|
|
74
|
+
* color: 'hsl(120, 75%, 60%)',
|
|
75
|
+
* label: 'Green'
|
|
76
|
+
* },
|
|
77
|
+
* {
|
|
78
|
+
* color: 'hsl(150, 75%, 60%)',
|
|
79
|
+
* label: 'Aquamarine'
|
|
80
|
+
* },
|
|
81
|
+
* {
|
|
82
|
+
* color: 'hsl(180, 75%, 60%)',
|
|
83
|
+
* label: 'Turquoise'
|
|
84
|
+
* },
|
|
85
|
+
* {
|
|
86
|
+
* color: 'hsl(210, 75%, 60%)',
|
|
87
|
+
* label: 'Light blue'
|
|
88
|
+
* },
|
|
89
|
+
* {
|
|
90
|
+
* color: 'hsl(240, 75%, 60%)',
|
|
91
|
+
* label: 'Blue'
|
|
92
|
+
* },
|
|
93
|
+
* {
|
|
94
|
+
* color: 'hsl(270, 75%, 60%)',
|
|
95
|
+
* label: 'Purple'
|
|
96
|
+
* }
|
|
97
|
+
* ]
|
|
98
|
+
* };
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* **Note**: The colors are displayed in the `'fontColor'` dropdown.
|
|
102
|
+
*/
|
|
103
|
+
colors?: Array<string | ColorOption>;
|
|
104
|
+
/**
|
|
105
|
+
* Determines the maximum number of available document colors.
|
|
106
|
+
* Setting it to `0` will disable the document colors feature.
|
|
107
|
+
*
|
|
108
|
+
* By default it equals to the {@link module:font/fontconfig~FontColorConfig#columns} value.
|
|
109
|
+
*
|
|
110
|
+
* Examples:
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* // 1) Neither document colors nor columns are defined in the configuration.
|
|
114
|
+
* // Document colors will equal 5,
|
|
115
|
+
* // because the value will be inherited from columns,
|
|
116
|
+
* // which has a predefined value of 5.
|
|
117
|
+
* const fontColorConfig = {}
|
|
118
|
+
*
|
|
119
|
+
* // 2) Document colors will equal 8, because the value will be inherited from columns.
|
|
120
|
+
* const fontColorConfig = {
|
|
121
|
+
* columns: 8
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* // 3) Document colors will equal 24, because it has its own value defined.
|
|
125
|
+
* const fontColorConfig = {
|
|
126
|
+
* columns: 8,
|
|
127
|
+
* documentColors: 24
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* // 4) The document colors feature will be disabled.
|
|
131
|
+
* const fontColorConfig = {
|
|
132
|
+
* columns: 8,
|
|
133
|
+
* documentColors: 0
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
documentColors?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Represents the number of columns in the font color dropdown.
|
|
140
|
+
*
|
|
141
|
+
* The default value is:
|
|
142
|
+
*
|
|
143
|
+
* ```ts
|
|
144
|
+
* const fontColorConfig = {
|
|
145
|
+
* columns: 5
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
columns?: number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The configuration of the font family feature.
|
|
153
|
+
* This option is used by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} feature.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* ClassicEditor
|
|
157
|
+
* .create( {
|
|
158
|
+
* fontFamily: ... // Font family feature configuration.
|
|
159
|
+
* } )
|
|
160
|
+
* .then( ... )
|
|
161
|
+
* .catch( ... );
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
165
|
+
*/
|
|
166
|
+
export interface FontFamilyConfig {
|
|
167
|
+
/**
|
|
168
|
+
* Available font family options defined as an array of strings. The default value is:
|
|
169
|
+
*
|
|
170
|
+
* ```ts
|
|
171
|
+
* const fontFamilyConfig = {
|
|
172
|
+
* options: [
|
|
173
|
+
* 'default',
|
|
174
|
+
* 'Arial, Helvetica, sans-serif',
|
|
175
|
+
* 'Courier New, Courier, monospace',
|
|
176
|
+
* 'Georgia, serif',
|
|
177
|
+
* 'Lucida Sans Unicode, Lucida Grande, sans-serif',
|
|
178
|
+
* 'Tahoma, Geneva, sans-serif',
|
|
179
|
+
* 'Times New Roman, Times, serif',
|
|
180
|
+
* 'Trebuchet MS, Helvetica, sans-serif',
|
|
181
|
+
* 'Verdana, Geneva, sans-serif'
|
|
182
|
+
* ]
|
|
183
|
+
* };
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* which configures 8 font family options. Each option consists of one or more comma–separated font family names. The first font name is
|
|
187
|
+
* used as the dropdown item description in the UI.
|
|
188
|
+
*
|
|
189
|
+
* **Note:** The family names that consist of spaces should not have quotes (as opposed to the CSS standard). The necessary quotes
|
|
190
|
+
* will be added automatically in the view. For example, the `"Lucida Sans Unicode"` will render as follows:
|
|
191
|
+
*
|
|
192
|
+
* ```html
|
|
193
|
+
* <span style="font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif">...</span>
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* The "default" option removes the `fontFamily` attribute from the selection. In such case, the text will
|
|
197
|
+
* be rendered in the view using the default font family defined in the styles of the web page.
|
|
198
|
+
*
|
|
199
|
+
* Font family can be applied using the command API. To do that, use the `fontFamily` command and pass the desired family as a `value`.
|
|
200
|
+
* For example, the following code will apply the `fontFamily` attribute with the `'Arial'` `value` to the current selection:
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* editor.execute( 'fontFamily', { value: 'Arial' } );
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* Executing the `'fontFamily'` command without any value will remove the `fontFamily` attribute from the current selection.
|
|
207
|
+
*/
|
|
208
|
+
options?: Array<string | FontFamilyOption>;
|
|
209
|
+
/**
|
|
210
|
+
* By default the plugin removes any `font-family` value that does not match the plugin's configuration.
|
|
211
|
+
* It means that if you paste content with font families that the editor does not understand, the `font-family` attribute
|
|
212
|
+
* will be removed and the content will be displayed with the default font.
|
|
213
|
+
*
|
|
214
|
+
* You can preserve pasted font family values by switching the `supportAllValues` option to `true`:
|
|
215
|
+
*
|
|
216
|
+
* ```ts
|
|
217
|
+
* const fontFamilyConfig = {
|
|
218
|
+
* supportAllValues: true
|
|
219
|
+
* };
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* With this configuration font families not specified in the editor configuration will not be removed when pasting the content.
|
|
223
|
+
*/
|
|
224
|
+
supportAllValues?: boolean;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The font family option descriptor.
|
|
228
|
+
*/
|
|
229
|
+
export interface FontFamilyOption {
|
|
230
|
+
/**
|
|
231
|
+
* The user-readable title of the option.
|
|
232
|
+
*/
|
|
233
|
+
title: string;
|
|
234
|
+
/**
|
|
235
|
+
* The attribute's unique value in the model.
|
|
236
|
+
*/
|
|
237
|
+
model?: string;
|
|
238
|
+
/**
|
|
239
|
+
* View element configuration.
|
|
240
|
+
*/
|
|
241
|
+
view?: ViewElementDefinition;
|
|
242
|
+
/**
|
|
243
|
+
* An array with all matched elements that the view-to-model conversion should also accept.
|
|
244
|
+
*/
|
|
245
|
+
upcastAlso?: Array<MatcherPattern>;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The configuration of the font size feature.
|
|
249
|
+
* This option is used by the {@link module:font/fontsize/fontsizeediting~FontSizeEditing} feature.
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* ClassicEditor
|
|
253
|
+
* .create( {
|
|
254
|
+
* fontSize: ... // Font size feature configuration.
|
|
255
|
+
* } )
|
|
256
|
+
* .then( ... )
|
|
257
|
+
* .catch( ... );
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
261
|
+
*/
|
|
262
|
+
export interface FontSizeConfig {
|
|
263
|
+
/**
|
|
264
|
+
* Available font size options. Expressed as predefined presets, numerical "pixel" values
|
|
265
|
+
* or the {@link module:font/fontconfig~FontSizeOption}.
|
|
266
|
+
*
|
|
267
|
+
* The default value is:
|
|
268
|
+
*
|
|
269
|
+
* ```ts
|
|
270
|
+
* const fontSizeConfig = {
|
|
271
|
+
* options: [
|
|
272
|
+
* 'tiny',
|
|
273
|
+
* 'small',
|
|
274
|
+
* 'default',
|
|
275
|
+
* 'big',
|
|
276
|
+
* 'huge'
|
|
277
|
+
* ]
|
|
278
|
+
* };
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* It defines 4 sizes: **tiny**, **small**, **big**, and **huge**. These values will be rendered as `<span>` elements in the view.
|
|
282
|
+
* The **default** defines a text without the `fontSize` attribute.
|
|
283
|
+
*
|
|
284
|
+
* Each `<span>` has the the `class` attribute set to the corresponding size name. For instance, this is what the **small** size looks
|
|
285
|
+
* like in the view:
|
|
286
|
+
*
|
|
287
|
+
* ```html
|
|
288
|
+
* <span class="text-small">...</span>
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* As an alternative, the font size might be defined using numerical values (either as a `Number` or as a `String`):
|
|
292
|
+
*
|
|
293
|
+
* ```ts
|
|
294
|
+
* const fontSizeConfig = {
|
|
295
|
+
* options: [ 9, 10, 11, 12, 13, 14, 15 ]
|
|
296
|
+
* };
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* Also, you can define a label in the dropdown for numerical values:
|
|
300
|
+
*
|
|
301
|
+
* ```ts
|
|
302
|
+
* const fontSizeConfig = {
|
|
303
|
+
* options: [
|
|
304
|
+
* {
|
|
305
|
+
* title: 'Small',
|
|
306
|
+
* model: '8px'
|
|
307
|
+
* },
|
|
308
|
+
* 'default',
|
|
309
|
+
* {
|
|
310
|
+
* title: 'Big',
|
|
311
|
+
* model: '14px'
|
|
312
|
+
* }
|
|
313
|
+
* ]
|
|
314
|
+
* };
|
|
315
|
+
* ```
|
|
316
|
+
*
|
|
317
|
+
* Font size can be applied using the command API. To do that, use the `'fontSize'` command and pass the desired font size as a `value`.
|
|
318
|
+
* For example, the following code will apply the `fontSize` attribute with the **tiny** value to the current selection:
|
|
319
|
+
*
|
|
320
|
+
* ```ts
|
|
321
|
+
* editor.execute( 'fontSize', { value: 'tiny' } );
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* Executing the `fontSize` command without value will remove the `fontSize` attribute from the current selection.
|
|
325
|
+
*/
|
|
326
|
+
options?: Array<string | number | FontSizeOption>;
|
|
327
|
+
/**
|
|
328
|
+
* By default the plugin removes any `font-size` value that does not match the plugin's configuration.
|
|
329
|
+
* It means that if you paste content with font sizes that the editor does not understand, the `font-size` attribute
|
|
330
|
+
* will be removed and the content will be displayed with the default size.
|
|
331
|
+
*
|
|
332
|
+
* You can preserve pasted font size values by switching the `supportAllValues` option to `true`:
|
|
333
|
+
*
|
|
334
|
+
* ```ts
|
|
335
|
+
* const fontSizeConfig = {
|
|
336
|
+
* options: [ 9, 10, 11, 12, 'default', 14, 15 ],
|
|
337
|
+
* supportAllValues: true
|
|
338
|
+
* };
|
|
339
|
+
* ```
|
|
340
|
+
*
|
|
341
|
+
* **Note:** This option can only be used with numerical values as font size options.
|
|
342
|
+
*
|
|
343
|
+
* With this configuration font sizes not specified in the editor configuration will not be removed when pasting the content.
|
|
344
|
+
*/
|
|
345
|
+
supportAllValues?: boolean;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The font size option descriptor.
|
|
349
|
+
*/
|
|
350
|
+
export interface FontSizeOption {
|
|
351
|
+
/**
|
|
352
|
+
* The user-readable title of the option.
|
|
353
|
+
*/
|
|
354
|
+
title: string;
|
|
355
|
+
/**
|
|
356
|
+
* The attribute's unique value in the model.
|
|
357
|
+
*/
|
|
358
|
+
model?: string;
|
|
359
|
+
/**
|
|
360
|
+
* View element configuration.
|
|
361
|
+
*/
|
|
362
|
+
view?: ViewElementDefinition;
|
|
363
|
+
/**
|
|
364
|
+
* An array with all matched elements that the view-to-model conversion should also accept.
|
|
365
|
+
*/
|
|
366
|
+
upcastAlso?: Array<MatcherPattern>;
|
|
367
|
+
}
|
|
368
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
369
|
+
interface EditorConfig {
|
|
370
|
+
/**
|
|
371
|
+
* The configuration of the font background color feature.
|
|
372
|
+
* It is introduced by the {@link module:font/fontbackgroundcolor/fontbackgroundcolorediting~FontBackgroundColorEditing} feature.
|
|
373
|
+
*
|
|
374
|
+
* Read more in {@link module:font/fontconfig~FontColorConfig}.
|
|
375
|
+
*/
|
|
376
|
+
fontBackgroundColor?: FontColorConfig;
|
|
377
|
+
/**
|
|
378
|
+
* The configuration of the font color feature.
|
|
379
|
+
* It is introduced by the {@link module:font/fontcolor/fontcolorediting~FontColorEditing} feature.
|
|
380
|
+
*
|
|
381
|
+
* Read more in {@link module:font/fontconfig~FontColorConfig}.
|
|
382
|
+
*/
|
|
383
|
+
fontColor?: FontColorConfig;
|
|
384
|
+
/**
|
|
385
|
+
* The configuration of the font family feature.
|
|
386
|
+
* It is introduced by the {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing} feature.
|
|
387
|
+
*
|
|
388
|
+
* Read more in {@link module:font/fontconfig~FontFamilyConfig}.
|
|
389
|
+
*/
|
|
390
|
+
fontFamily?: FontFamilyConfig;
|
|
391
|
+
/**
|
|
392
|
+
* The configuration of the font size feature.
|
|
393
|
+
* It is introduced by the {@link module:font/fontsize/fontsizeediting~FontSizeEditing} feature.
|
|
394
|
+
*
|
|
395
|
+
* Read more in {@link module:font/fontconfig~FontSizeConfig}.
|
|
396
|
+
*/
|
|
397
|
+
fontSize?: FontSizeConfig;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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/fontfamily/fontfamilycommand
|
|
7
|
+
*/
|
|
8
|
+
import type { Editor } from 'ckeditor5/src/core';
|
|
9
|
+
import FontCommand from '../fontcommand';
|
|
10
|
+
import { FONT_FAMILY } from '../utils';
|
|
11
|
+
/**
|
|
12
|
+
* The font family command. It is used by {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing}
|
|
13
|
+
* to apply the font family.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* editor.execute( 'fontFamily', { value: 'Arial' } );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
20
|
+
*/
|
|
21
|
+
export default class FontFamilyCommand extends FontCommand {
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
constructor(editor: Editor);
|
|
26
|
+
}
|
|
27
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
28
|
+
interface CommandsMap {
|
|
29
|
+
[FONT_FAMILY]: FontFamilyCommand;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -2,29 +2,23 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* @module font/fontfamily/fontfamilycommand
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
import FontCommand from '../fontcommand';
|
|
11
6
|
import { FONT_FAMILY } from '../utils';
|
|
12
|
-
|
|
13
7
|
/**
|
|
14
8
|
* The font family command. It is used by {@link module:font/fontfamily/fontfamilyediting~FontFamilyEditing}
|
|
15
9
|
* to apply the font family.
|
|
16
10
|
*
|
|
17
|
-
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* editor.execute( 'fontFamily', { value: 'Arial' } );
|
|
13
|
+
* ```
|
|
18
14
|
*
|
|
19
15
|
* **Note**: Executing the command without the value removes the attribute from the model.
|
|
20
|
-
*
|
|
21
|
-
* @extends module:font/fontcommand~FontCommand
|
|
22
16
|
*/
|
|
23
17
|
export default class FontFamilyCommand extends FontCommand {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
constructor(editor) {
|
|
22
|
+
super(editor, FONT_FAMILY);
|
|
23
|
+
}
|
|
30
24
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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/fontfamily/fontfamilyediting
|
|
7
|
+
*/
|
|
8
|
+
import { type Editor, Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import '../fontconfig';
|
|
10
|
+
/**
|
|
11
|
+
* The font family editing feature.
|
|
12
|
+
*
|
|
13
|
+
* It introduces the {@link module:font/fontfamily/fontfamilycommand~FontFamilyCommand command} and
|
|
14
|
+
* the `fontFamily` attribute in the {@link module:engine/model/model~Model model} which renders
|
|
15
|
+
* in the {@link module:engine/view/view view} as an inline `<span>` element (`<span style="font-family: Arial">`),
|
|
16
|
+
* depending on the {@link module:font/fontconfig~FontFamilyConfig configuration}.
|
|
17
|
+
*/
|
|
18
|
+
export default class FontFamilyEditing extends Plugin {
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
static get pluginName(): 'FontFamilyEditing';
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
constructor(editor: Editor);
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
init(): void;
|
|
31
|
+
/**
|
|
32
|
+
* These converters enable keeping any value found as `style="font-family: *"` as a value of an attribute on a text even
|
|
33
|
+
* if it is not defined in the plugin configuration.
|
|
34
|
+
*/
|
|
35
|
+
private _prepareAnyValueConverters;
|
|
36
|
+
/**
|
|
37
|
+
* Adds support for legacy `<font face="..">` formatting.
|
|
38
|
+
*/
|
|
39
|
+
private _prepareCompatibilityConverter;
|
|
40
|
+
}
|
|
41
|
+
declare module '@ckeditor/ckeditor5-core' {
|
|
42
|
+
interface PluginsMap {
|
|
43
|
+
[FontFamilyEditing.pluginName]: FontFamilyEditing;
|
|
44
|
+
}
|
|
45
|
+
}
|