@ckeditor/ckeditor5-font 41.3.1 → 41.4.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/dist/index-content.css +16 -0
- package/dist/index-editor.css +4 -0
- package/dist/index.css +27 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +1428 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/bs.d.ts +8 -0
- package/dist/translations/bs.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en-gb.d.ts +8 -0
- package/dist/translations/en-gb.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es-co.d.ts +8 -0
- package/dist/translations/es-co.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/jv.d.ts +8 -0
- package/dist/translations/jv.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nb.d.ts +8 -0
- package/dist/translations/nb.js +5 -0
- package/dist/translations/ne.d.ts +8 -0
- package/dist/translations/ne.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sl.d.ts +8 -0
- package/dist/translations/sl.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/ug.d.ts +8 -0
- package/dist/translations/ug.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +62 -0
- package/dist/types/font.d.ts +37 -0
- package/dist/types/fontbackgroundcolor/fontbackgroundcolorcommand.d.ts +30 -0
- package/dist/types/fontbackgroundcolor/fontbackgroundcolorediting.d.ts +30 -0
- package/dist/types/fontbackgroundcolor/fontbackgroundcolorui.d.ts +26 -0
- package/dist/types/fontbackgroundcolor.d.ts +34 -0
- package/dist/types/fontcolor/fontcolorcommand.d.ts +29 -0
- package/dist/types/fontcolor/fontcolorediting.d.ts +30 -0
- package/dist/types/fontcolor/fontcolorui.d.ts +26 -0
- package/dist/types/fontcolor.d.ts +33 -0
- package/dist/types/fontcommand.d.ts +52 -0
- package/dist/types/fontconfig.d.ts +377 -0
- package/dist/types/fontfamily/fontfamilycommand.d.ts +29 -0
- package/dist/types/fontfamily/fontfamilyediting.d.ts +43 -0
- package/dist/types/fontfamily/fontfamilyui.d.ts +34 -0
- package/dist/types/fontfamily/utils.d.ts +19 -0
- package/dist/types/fontfamily.d.ts +33 -0
- package/dist/types/fontsize/fontsizecommand.d.ts +29 -0
- package/dist/types/fontsize/fontsizeediting.d.ts +48 -0
- package/dist/types/fontsize/fontsizeui.d.ts +35 -0
- package/dist/types/fontsize/utils.d.ts +16 -0
- package/dist/types/fontsize.d.ts +41 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/ui/colorui.d.ts +67 -0
- package/dist/types/utils.d.ts +84 -0
- package/package.json +3 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,1428 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2024, 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 { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
|
|
6
|
+
import { ColorSelectorView, createDropdown, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ViewModel, normalizeColorOptions, getLocalizedColorOptions, focusChildOnDropdownOpen } from '@ckeditor/ckeditor5-ui/dist/index.js';
|
|
7
|
+
import { Collection, CKEditorError } from '@ckeditor/ckeditor5-utils/dist/index.js';
|
|
8
|
+
import { isLength, isPercentage, addBackgroundRules } from '@ckeditor/ckeditor5-engine/dist/index.js';
|
|
9
|
+
|
|
10
|
+
class FontCommand extends Command {
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/ refresh() {
|
|
14
|
+
const model = this.editor.model;
|
|
15
|
+
const doc = model.document;
|
|
16
|
+
this.value = doc.selection.getAttribute(this.attributeKey);
|
|
17
|
+
this.isEnabled = model.schema.checkAttributeInSelection(doc.selection, this.attributeKey);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Executes the command. Applies the `value` of the {@link #attributeKey} to the selection.
|
|
21
|
+
* If no `value` is passed, it removes the attribute from the selection.
|
|
22
|
+
*
|
|
23
|
+
* @param options Options for the executed command.
|
|
24
|
+
* @param options.value The value to apply.
|
|
25
|
+
* @fires execute
|
|
26
|
+
*/ execute(options = {}) {
|
|
27
|
+
const model = this.editor.model;
|
|
28
|
+
const document = model.document;
|
|
29
|
+
const selection = document.selection;
|
|
30
|
+
const value = options.value;
|
|
31
|
+
const batch = options.batch;
|
|
32
|
+
const updateAttribute = (writer)=>{
|
|
33
|
+
if (selection.isCollapsed) {
|
|
34
|
+
if (value) {
|
|
35
|
+
writer.setSelectionAttribute(this.attributeKey, value);
|
|
36
|
+
} else {
|
|
37
|
+
writer.removeSelectionAttribute(this.attributeKey);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
const ranges = model.schema.getValidRanges(selection.getRanges(), this.attributeKey);
|
|
41
|
+
for (const range of ranges){
|
|
42
|
+
if (value) {
|
|
43
|
+
writer.setAttribute(this.attributeKey, value, range);
|
|
44
|
+
} else {
|
|
45
|
+
writer.removeAttribute(this.attributeKey, range);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
// In some scenarios, you may want to use a single undo step for multiple changes (e.g. in color picker).
|
|
51
|
+
if (batch) {
|
|
52
|
+
model.enqueueChange(batch, (writer)=>{
|
|
53
|
+
updateAttribute(writer);
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
model.change((writer)=>{
|
|
57
|
+
updateAttribute(writer);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates an instance of the command.
|
|
63
|
+
*
|
|
64
|
+
* @param editor Editor instance.
|
|
65
|
+
* @param attributeKey The name of a model attribute on which this command operates.
|
|
66
|
+
*/ constructor(editor, attributeKey){
|
|
67
|
+
super(editor);
|
|
68
|
+
this.attributeKey = attributeKey;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The name of the font size plugin.
|
|
74
|
+
*/ const FONT_SIZE = 'fontSize';
|
|
75
|
+
/**
|
|
76
|
+
* The name of the font family plugin.
|
|
77
|
+
*/ const FONT_FAMILY = 'fontFamily';
|
|
78
|
+
/**
|
|
79
|
+
* The name of the font color plugin.
|
|
80
|
+
*/ const FONT_COLOR = 'fontColor';
|
|
81
|
+
/**
|
|
82
|
+
* The name of the font background color plugin.
|
|
83
|
+
*/ const FONT_BACKGROUND_COLOR = 'fontBackgroundColor';
|
|
84
|
+
/**
|
|
85
|
+
* Builds a proper converter definition out of input data.
|
|
86
|
+
*/ function buildDefinition(modelAttributeKey, options) {
|
|
87
|
+
const definition = {
|
|
88
|
+
model: {
|
|
89
|
+
key: modelAttributeKey,
|
|
90
|
+
values: []
|
|
91
|
+
},
|
|
92
|
+
view: {},
|
|
93
|
+
upcastAlso: {}
|
|
94
|
+
};
|
|
95
|
+
for (const option of options){
|
|
96
|
+
definition.model.values.push(option.model);
|
|
97
|
+
definition.view[option.model] = option.view;
|
|
98
|
+
if (option.upcastAlso) {
|
|
99
|
+
definition.upcastAlso[option.model] = option.upcastAlso;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return definition;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
106
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
107
|
+
* responsible for upcasting data to the model.
|
|
108
|
+
*
|
|
109
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
110
|
+
*/ function renderUpcastAttribute(styleAttr) {
|
|
111
|
+
return (viewElement)=>normalizeColorCode(viewElement.getStyle(styleAttr));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* A {@link module:font/fontcolor~FontColor font color} and
|
|
115
|
+
* {@link module:font/fontbackgroundcolor~FontBackgroundColor font background color} helper
|
|
116
|
+
* responsible for downcasting a color attribute to a `<span>` element.
|
|
117
|
+
*
|
|
118
|
+
* **Note**: The `styleAttr` parameter should be either `'color'` or `'background-color'`.
|
|
119
|
+
*/ function renderDowncastElement(styleAttr) {
|
|
120
|
+
return (modelAttributeValue, { writer })=>writer.createAttributeElement('span', {
|
|
121
|
+
style: `${styleAttr}:${modelAttributeValue}`
|
|
122
|
+
}, {
|
|
123
|
+
priority: 7
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A helper that adds {@link module:ui/colorselector/colorselectorview~ColorSelectorView} to the color dropdown with proper initial values.
|
|
128
|
+
*
|
|
129
|
+
* @param config.dropdownView The dropdown view to which a {@link module:ui/colorselector/colorselectorview~ColorSelectorView}
|
|
130
|
+
* will be added.
|
|
131
|
+
* @param config.colors An array with definitions representing colors to be displayed in the color selector.
|
|
132
|
+
* @param config.removeButtonLabel The label for the button responsible for removing the color.
|
|
133
|
+
* @param config.documentColorsLabel The label for the section with document colors.
|
|
134
|
+
* @param config.documentColorsCount The number of document colors inside the dropdown.
|
|
135
|
+
* @param config.colorPickerViewConfig Configuration of the color picker view.
|
|
136
|
+
* @returns The new color selector view.
|
|
137
|
+
*/ function addColorSelectorToDropdown({ dropdownView, colors, columns, removeButtonLabel, colorPickerLabel, documentColorsLabel, documentColorsCount, colorPickerViewConfig }) {
|
|
138
|
+
const locale = dropdownView.locale;
|
|
139
|
+
const colorSelectorView = new ColorSelectorView(locale, {
|
|
140
|
+
colors,
|
|
141
|
+
columns,
|
|
142
|
+
removeButtonLabel,
|
|
143
|
+
colorPickerLabel,
|
|
144
|
+
documentColorsLabel,
|
|
145
|
+
documentColorsCount,
|
|
146
|
+
colorPickerViewConfig
|
|
147
|
+
});
|
|
148
|
+
dropdownView.colorSelectorView = colorSelectorView;
|
|
149
|
+
dropdownView.panelView.children.add(colorSelectorView);
|
|
150
|
+
return colorSelectorView;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fixes the color value string.
|
|
154
|
+
*/ function normalizeColorCode(value) {
|
|
155
|
+
return value.replace(/\s/g, '');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
class FontFamilyCommand extends FontCommand {
|
|
159
|
+
/**
|
|
160
|
+
* @inheritDoc
|
|
161
|
+
*/ constructor(editor){
|
|
162
|
+
super(editor, FONT_FAMILY);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
|
|
168
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
169
|
+
*/ /**
|
|
170
|
+
* @module font/fontfamily/utils
|
|
171
|
+
*/ /**
|
|
172
|
+
* Normalizes the {@link module:font/fontconfig~FontFamilyConfig#options configuration options}
|
|
173
|
+
* to the {@link module:font/fontconfig~FontFamilyOption} format.
|
|
174
|
+
*
|
|
175
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
176
|
+
*/ function normalizeOptions$1(configuredOptions) {
|
|
177
|
+
// Convert options to objects.
|
|
178
|
+
return configuredOptions.map(getOptionDefinition$1)// Filter out undefined values that `getOptionDefinition` might return.
|
|
179
|
+
.filter((option)=>option !== undefined);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns an option definition either created from string shortcut.
|
|
183
|
+
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
184
|
+
*
|
|
185
|
+
*/ function getOptionDefinition$1(option) {
|
|
186
|
+
// Treat any object as full item definition provided by user in configuration.
|
|
187
|
+
if (typeof option === 'object') {
|
|
188
|
+
return option;
|
|
189
|
+
}
|
|
190
|
+
// Handle 'default' string as a special case. It will be used to remove the fontFamily attribute.
|
|
191
|
+
if (option === 'default') {
|
|
192
|
+
return {
|
|
193
|
+
title: 'Default',
|
|
194
|
+
model: undefined
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// Ignore values that we cannot parse to a definition.
|
|
198
|
+
if (typeof option !== 'string') {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
// Return font family definition from font string.
|
|
202
|
+
return generateFontPreset(option);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Creates a predefined preset for pixel size. It deconstructs font-family like string into full configuration option.
|
|
206
|
+
* A font definition is passed as coma delimited set of font family names. Font names might be quoted.
|
|
207
|
+
*
|
|
208
|
+
* @param fontDefinition A font definition form configuration.
|
|
209
|
+
*/ function generateFontPreset(fontDefinition) {
|
|
210
|
+
// Remove quotes from font names. They will be normalized later.
|
|
211
|
+
const fontNames = fontDefinition.replace(/"|'/g, '').split(',');
|
|
212
|
+
// The first matched font name will be used as dropdown list item title and as model value.
|
|
213
|
+
const firstFontName = fontNames[0];
|
|
214
|
+
// CSS-compatible font names.
|
|
215
|
+
const cssFontNames = fontNames.map(normalizeFontNameForCSS).join(', ');
|
|
216
|
+
return {
|
|
217
|
+
title: firstFontName,
|
|
218
|
+
model: cssFontNames,
|
|
219
|
+
view: {
|
|
220
|
+
name: 'span',
|
|
221
|
+
styles: {
|
|
222
|
+
'font-family': cssFontNames
|
|
223
|
+
},
|
|
224
|
+
priority: 7
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Normalizes font name for the style attribute. It adds braces (') if font name contains spaces.
|
|
230
|
+
*/ function normalizeFontNameForCSS(fontName) {
|
|
231
|
+
fontName = fontName.trim();
|
|
232
|
+
// Compound font names should be quoted.
|
|
233
|
+
if (fontName.indexOf(' ') > 0) {
|
|
234
|
+
fontName = `'${fontName}'`;
|
|
235
|
+
}
|
|
236
|
+
return fontName;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
class FontFamilyEditing extends Plugin {
|
|
240
|
+
/**
|
|
241
|
+
* @inheritDoc
|
|
242
|
+
*/ static get pluginName() {
|
|
243
|
+
return 'FontFamilyEditing';
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @inheritDoc
|
|
247
|
+
*/ init() {
|
|
248
|
+
const editor = this.editor;
|
|
249
|
+
// Allow fontFamily attribute on text nodes.
|
|
250
|
+
editor.model.schema.extend('$text', {
|
|
251
|
+
allowAttributes: FONT_FAMILY
|
|
252
|
+
});
|
|
253
|
+
editor.model.schema.setAttributeProperties(FONT_FAMILY, {
|
|
254
|
+
isFormatting: true,
|
|
255
|
+
copyOnEnter: true
|
|
256
|
+
});
|
|
257
|
+
// Get configured font family options without "default" option.
|
|
258
|
+
const options = normalizeOptions$1(editor.config.get('fontFamily.options')).filter((item)=>item.model);
|
|
259
|
+
const definition = buildDefinition(FONT_FAMILY, options);
|
|
260
|
+
// Set-up the two-way conversion.
|
|
261
|
+
if (editor.config.get('fontFamily.supportAllValues')) {
|
|
262
|
+
this._prepareAnyValueConverters();
|
|
263
|
+
this._prepareCompatibilityConverter();
|
|
264
|
+
} else {
|
|
265
|
+
editor.conversion.attributeToElement(definition);
|
|
266
|
+
}
|
|
267
|
+
editor.commands.add(FONT_FAMILY, new FontFamilyCommand(editor));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* These converters enable keeping any value found as `style="font-family: *"` as a value of an attribute on a text even
|
|
271
|
+
* if it is not defined in the plugin configuration.
|
|
272
|
+
*/ _prepareAnyValueConverters() {
|
|
273
|
+
const editor = this.editor;
|
|
274
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
275
|
+
model: FONT_FAMILY,
|
|
276
|
+
view: (attributeValue, { writer })=>{
|
|
277
|
+
return writer.createAttributeElement('span', {
|
|
278
|
+
style: 'font-family:' + attributeValue
|
|
279
|
+
}, {
|
|
280
|
+
priority: 7
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
285
|
+
model: {
|
|
286
|
+
key: FONT_FAMILY,
|
|
287
|
+
value: (viewElement)=>viewElement.getStyle('font-family')
|
|
288
|
+
},
|
|
289
|
+
view: {
|
|
290
|
+
name: 'span',
|
|
291
|
+
styles: {
|
|
292
|
+
'font-family': /.*/
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Adds support for legacy `<font face="..">` formatting.
|
|
299
|
+
*/ _prepareCompatibilityConverter() {
|
|
300
|
+
const editor = this.editor;
|
|
301
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
302
|
+
view: {
|
|
303
|
+
name: 'font',
|
|
304
|
+
attributes: {
|
|
305
|
+
'face': /.*/
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
model: {
|
|
309
|
+
key: FONT_FAMILY,
|
|
310
|
+
value: (viewElement)=>viewElement.getAttribute('face')
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* @inheritDoc
|
|
316
|
+
*/ constructor(editor){
|
|
317
|
+
super(editor);
|
|
318
|
+
// Define default configuration using font families shortcuts.
|
|
319
|
+
editor.config.define(FONT_FAMILY, {
|
|
320
|
+
options: [
|
|
321
|
+
'default',
|
|
322
|
+
'Arial, Helvetica, sans-serif',
|
|
323
|
+
'Courier New, Courier, monospace',
|
|
324
|
+
'Georgia, serif',
|
|
325
|
+
'Lucida Sans Unicode, Lucida Grande, sans-serif',
|
|
326
|
+
'Tahoma, Geneva, sans-serif',
|
|
327
|
+
'Times New Roman, Times, serif',
|
|
328
|
+
'Trebuchet MS, Helvetica, sans-serif',
|
|
329
|
+
'Verdana, Geneva, sans-serif'
|
|
330
|
+
],
|
|
331
|
+
supportAllValues: false
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
var fontFamilyIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.03 3h6.149a.75.75 0 1 1 0 1.5h-5.514L11.03 3zm1.27 3h4.879a.75.75 0 1 1 0 1.5h-4.244L12.3 6zm1.27 3h3.609a.75.75 0 1 1 0 1.5h-2.973L13.57 9zm-2.754 2.5L8.038 4.785 5.261 11.5h5.555zm.62 1.5H4.641l-1.666 4.028H1.312l5.789-14h1.875l5.789 14h-1.663L11.436 13z\"/></svg>";
|
|
337
|
+
|
|
338
|
+
class FontFamilyUI extends Plugin {
|
|
339
|
+
/**
|
|
340
|
+
* @inheritDoc
|
|
341
|
+
*/ static get pluginName() {
|
|
342
|
+
return 'FontFamilyUI';
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* @inheritDoc
|
|
346
|
+
*/ init() {
|
|
347
|
+
const editor = this.editor;
|
|
348
|
+
const t = editor.t;
|
|
349
|
+
const options = this._getLocalizedOptions();
|
|
350
|
+
const command = editor.commands.get(FONT_FAMILY);
|
|
351
|
+
const accessibleLabel = t('Font Family');
|
|
352
|
+
const listOptions = _prepareListOptions$1(options, command);
|
|
353
|
+
// Register UI component.
|
|
354
|
+
editor.ui.componentFactory.add(FONT_FAMILY, (locale)=>{
|
|
355
|
+
const dropdownView = createDropdown(locale);
|
|
356
|
+
addListToDropdown(dropdownView, listOptions, {
|
|
357
|
+
role: 'menu',
|
|
358
|
+
ariaLabel: accessibleLabel
|
|
359
|
+
});
|
|
360
|
+
dropdownView.buttonView.set({
|
|
361
|
+
label: accessibleLabel,
|
|
362
|
+
icon: fontFamilyIcon,
|
|
363
|
+
tooltip: true
|
|
364
|
+
});
|
|
365
|
+
dropdownView.extendTemplate({
|
|
366
|
+
attributes: {
|
|
367
|
+
class: 'ck-font-family-dropdown'
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
dropdownView.bind('isEnabled').to(command);
|
|
371
|
+
// Execute command when an item from the dropdown is selected.
|
|
372
|
+
this.listenTo(dropdownView, 'execute', (evt)=>{
|
|
373
|
+
editor.execute(evt.source.commandName, {
|
|
374
|
+
value: evt.source.commandParam
|
|
375
|
+
});
|
|
376
|
+
editor.editing.view.focus();
|
|
377
|
+
});
|
|
378
|
+
return dropdownView;
|
|
379
|
+
});
|
|
380
|
+
editor.ui.componentFactory.add(`menuBar:${FONT_FAMILY}`, (locale)=>{
|
|
381
|
+
const menuView = new MenuBarMenuView(locale);
|
|
382
|
+
menuView.buttonView.set({
|
|
383
|
+
label: accessibleLabel,
|
|
384
|
+
icon: fontFamilyIcon
|
|
385
|
+
});
|
|
386
|
+
menuView.bind('isEnabled').to(command);
|
|
387
|
+
const listView = new MenuBarMenuListView(locale);
|
|
388
|
+
for (const definition of listOptions){
|
|
389
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
390
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
391
|
+
buttonView.bind(...Object.keys(definition.model)).to(definition.model);
|
|
392
|
+
buttonView.bind('ariaChecked').to(buttonView, 'isOn');
|
|
393
|
+
buttonView.delegate('execute').to(menuView);
|
|
394
|
+
buttonView.on('execute', ()=>{
|
|
395
|
+
editor.execute(definition.model.commandName, {
|
|
396
|
+
value: definition.model.commandParam
|
|
397
|
+
});
|
|
398
|
+
editor.editing.view.focus();
|
|
399
|
+
});
|
|
400
|
+
listItemView.children.add(buttonView);
|
|
401
|
+
listView.items.add(listItemView);
|
|
402
|
+
}
|
|
403
|
+
menuView.panelView.children.add(listView);
|
|
404
|
+
return menuView;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Returns options as defined in `config.fontFamily.options` but processed to account for
|
|
409
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontFamilyOption}
|
|
410
|
+
* in the correct language.
|
|
411
|
+
*
|
|
412
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
413
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
414
|
+
*/ _getLocalizedOptions() {
|
|
415
|
+
const editor = this.editor;
|
|
416
|
+
const t = editor.t;
|
|
417
|
+
const options = normalizeOptions$1(editor.config.get(FONT_FAMILY).options);
|
|
418
|
+
return options.map((option)=>{
|
|
419
|
+
// The only title to localize is "Default" others are font names.
|
|
420
|
+
if (option.title === 'Default') {
|
|
421
|
+
option.title = t('Default');
|
|
422
|
+
}
|
|
423
|
+
return option;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Prepares FontFamily dropdown items.
|
|
429
|
+
*/ function _prepareListOptions$1(options, command) {
|
|
430
|
+
const itemDefinitions = new Collection();
|
|
431
|
+
// Create dropdown items.
|
|
432
|
+
for (const option of options){
|
|
433
|
+
const def = {
|
|
434
|
+
type: 'button',
|
|
435
|
+
model: new ViewModel({
|
|
436
|
+
commandName: FONT_FAMILY,
|
|
437
|
+
commandParam: option.model,
|
|
438
|
+
label: option.title,
|
|
439
|
+
role: 'menuitemradio',
|
|
440
|
+
withText: true
|
|
441
|
+
})
|
|
442
|
+
};
|
|
443
|
+
def.model.bind('isOn').to(command, 'value', (value)=>{
|
|
444
|
+
// "Default" or check in strict font-family converters mode.
|
|
445
|
+
if (value === option.model) {
|
|
446
|
+
return true;
|
|
447
|
+
}
|
|
448
|
+
if (!value || !option.model) {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
return value.split(',')[0].replace(/'/g, '').toLowerCase() === option.model.toLowerCase();
|
|
452
|
+
});
|
|
453
|
+
// Try to set a dropdown list item style.
|
|
454
|
+
if (option.view && typeof option.view !== 'string' && option.view.styles) {
|
|
455
|
+
def.model.set('labelStyle', `font-family: ${option.view.styles['font-family']}`);
|
|
456
|
+
}
|
|
457
|
+
itemDefinitions.add(def);
|
|
458
|
+
}
|
|
459
|
+
return itemDefinitions;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
class FontFamily extends Plugin {
|
|
463
|
+
/**
|
|
464
|
+
* @inheritDoc
|
|
465
|
+
*/ static get requires() {
|
|
466
|
+
return [
|
|
467
|
+
FontFamilyEditing,
|
|
468
|
+
FontFamilyUI
|
|
469
|
+
];
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* @inheritDoc
|
|
473
|
+
*/ static get pluginName() {
|
|
474
|
+
return 'FontFamily';
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
class FontSizeCommand extends FontCommand {
|
|
479
|
+
/**
|
|
480
|
+
* @inheritDoc
|
|
481
|
+
*/ constructor(editor){
|
|
482
|
+
super(editor, FONT_SIZE);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Normalizes and translates the {@link module:font/fontconfig~FontSizeConfig#options configuration options}
|
|
488
|
+
* to the {@link module:font/fontconfig~FontSizeOption} format.
|
|
489
|
+
*
|
|
490
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
491
|
+
*/ function normalizeOptions(configuredOptions) {
|
|
492
|
+
// Convert options to objects.
|
|
493
|
+
return configuredOptions.map((item)=>getOptionDefinition(item))// Filter out undefined values that `getOptionDefinition` might return.
|
|
494
|
+
.filter((option)=>option !== undefined);
|
|
495
|
+
}
|
|
496
|
+
// Default named presets map. Always create a new instance of the preset object in order to avoid modifying references.
|
|
497
|
+
const namedPresets = {
|
|
498
|
+
get tiny () {
|
|
499
|
+
return {
|
|
500
|
+
title: 'Tiny',
|
|
501
|
+
model: 'tiny',
|
|
502
|
+
view: {
|
|
503
|
+
name: 'span',
|
|
504
|
+
classes: 'text-tiny',
|
|
505
|
+
priority: 7
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
get small () {
|
|
510
|
+
return {
|
|
511
|
+
title: 'Small',
|
|
512
|
+
model: 'small',
|
|
513
|
+
view: {
|
|
514
|
+
name: 'span',
|
|
515
|
+
classes: 'text-small',
|
|
516
|
+
priority: 7
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
},
|
|
520
|
+
get big () {
|
|
521
|
+
return {
|
|
522
|
+
title: 'Big',
|
|
523
|
+
model: 'big',
|
|
524
|
+
view: {
|
|
525
|
+
name: 'span',
|
|
526
|
+
classes: 'text-big',
|
|
527
|
+
priority: 7
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
},
|
|
531
|
+
get huge () {
|
|
532
|
+
return {
|
|
533
|
+
title: 'Huge',
|
|
534
|
+
model: 'huge',
|
|
535
|
+
view: {
|
|
536
|
+
name: 'span',
|
|
537
|
+
classes: 'text-huge',
|
|
538
|
+
priority: 7
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
/**
|
|
544
|
+
* Returns an option definition either from preset or creates one from number shortcut.
|
|
545
|
+
* If object is passed then this method will return it without alternating it. Returns undefined for item than cannot be parsed.
|
|
546
|
+
*/ function getOptionDefinition(option) {
|
|
547
|
+
if (typeof option === 'number') {
|
|
548
|
+
option = String(option);
|
|
549
|
+
}
|
|
550
|
+
// Check whether passed option is a full item definition provided by user in configuration.
|
|
551
|
+
if (typeof option === 'object' && isFullItemDefinition(option)) {
|
|
552
|
+
return attachPriority(option);
|
|
553
|
+
}
|
|
554
|
+
const preset = findPreset(option);
|
|
555
|
+
// Item is a named preset.
|
|
556
|
+
if (preset) {
|
|
557
|
+
return attachPriority(preset);
|
|
558
|
+
}
|
|
559
|
+
// 'Default' font size. It will be used to remove the fontSize attribute.
|
|
560
|
+
if (option === 'default') {
|
|
561
|
+
return {
|
|
562
|
+
model: undefined,
|
|
563
|
+
title: 'Default'
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
// At this stage we probably have numerical value to generate a preset so parse it's value.
|
|
567
|
+
// Discard any faulty values.
|
|
568
|
+
if (isNumericalDefinition(option)) {
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
|
571
|
+
// Return font size definition from size value.
|
|
572
|
+
return generatePixelPreset(option);
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Creates a predefined preset for pixel size.
|
|
576
|
+
* @param definition Font size in pixels.
|
|
577
|
+
* @returns
|
|
578
|
+
*/ function generatePixelPreset(definition) {
|
|
579
|
+
// Extend a short (numeric value) definition.
|
|
580
|
+
if (typeof definition === 'string') {
|
|
581
|
+
definition = {
|
|
582
|
+
title: definition,
|
|
583
|
+
model: `${parseFloat(definition)}px`
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
definition.view = {
|
|
587
|
+
name: 'span',
|
|
588
|
+
styles: {
|
|
589
|
+
'font-size': definition.model
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
return attachPriority(definition);
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Adds the priority to the view element definition if missing. It's required due to ckeditor/ckeditor5#2291
|
|
596
|
+
*/ function attachPriority(definition) {
|
|
597
|
+
if (definition.view && typeof definition.view !== 'string' && !definition.view.priority) {
|
|
598
|
+
definition.view.priority = 7;
|
|
599
|
+
}
|
|
600
|
+
return definition;
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Returns a prepared preset definition. If passed an object, a name of preset should be defined as `model` value.
|
|
604
|
+
*
|
|
605
|
+
* @param definition.model A preset name.
|
|
606
|
+
*/ function findPreset(definition) {
|
|
607
|
+
return typeof definition === 'string' ? namedPresets[definition] : namedPresets[definition.model];
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* We treat `definition` as completed if it is an object that contains `title`, `model` and `view` values.
|
|
611
|
+
*/ function isFullItemDefinition(definition) {
|
|
612
|
+
return definition.title && definition.model && definition.view;
|
|
613
|
+
}
|
|
614
|
+
function isNumericalDefinition(definition) {
|
|
615
|
+
let numberValue;
|
|
616
|
+
if (typeof definition === 'object') {
|
|
617
|
+
if (!definition.model) {
|
|
618
|
+
/**
|
|
619
|
+
* Provided value as an option for {@link module:font/fontsize~FontSize} seems to invalid.
|
|
620
|
+
*
|
|
621
|
+
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
622
|
+
*
|
|
623
|
+
* @error font-size-invalid-definition
|
|
624
|
+
*/ throw new CKEditorError('font-size-invalid-definition', null, definition);
|
|
625
|
+
} else {
|
|
626
|
+
numberValue = parseFloat(definition.model);
|
|
627
|
+
}
|
|
628
|
+
} else {
|
|
629
|
+
numberValue = parseFloat(definition);
|
|
630
|
+
}
|
|
631
|
+
return isNaN(numberValue);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// Mapping of `<font size="..">` styling to CSS's `font-size` values.
|
|
635
|
+
const styleFontSize = [
|
|
636
|
+
'x-small',
|
|
637
|
+
'x-small',
|
|
638
|
+
'small',
|
|
639
|
+
'medium',
|
|
640
|
+
'large',
|
|
641
|
+
'x-large',
|
|
642
|
+
'xx-large',
|
|
643
|
+
'xxx-large'
|
|
644
|
+
];
|
|
645
|
+
class FontSizeEditing extends Plugin {
|
|
646
|
+
/**
|
|
647
|
+
* @inheritDoc
|
|
648
|
+
*/ static get pluginName() {
|
|
649
|
+
return 'FontSizeEditing';
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* @inheritDoc
|
|
653
|
+
*/ init() {
|
|
654
|
+
const editor = this.editor;
|
|
655
|
+
// Allow fontSize attribute on text nodes.
|
|
656
|
+
editor.model.schema.extend('$text', {
|
|
657
|
+
allowAttributes: FONT_SIZE
|
|
658
|
+
});
|
|
659
|
+
editor.model.schema.setAttributeProperties(FONT_SIZE, {
|
|
660
|
+
isFormatting: true,
|
|
661
|
+
copyOnEnter: true
|
|
662
|
+
});
|
|
663
|
+
const supportAllValues = editor.config.get('fontSize.supportAllValues');
|
|
664
|
+
// Define view to model conversion.
|
|
665
|
+
const options = normalizeOptions(this.editor.config.get('fontSize.options')).filter((item)=>item.model);
|
|
666
|
+
const definition = buildDefinition(FONT_SIZE, options);
|
|
667
|
+
// Set-up the two-way conversion.
|
|
668
|
+
if (supportAllValues) {
|
|
669
|
+
this._prepareAnyValueConverters(definition);
|
|
670
|
+
this._prepareCompatibilityConverter();
|
|
671
|
+
} else {
|
|
672
|
+
editor.conversion.attributeToElement(definition);
|
|
673
|
+
}
|
|
674
|
+
// Add FontSize command.
|
|
675
|
+
editor.commands.add(FONT_SIZE, new FontSizeCommand(editor));
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* These converters enable keeping any value found as `style="font-size: *"` as a value of an attribute on a text even
|
|
679
|
+
* if it is not defined in the plugin configuration.
|
|
680
|
+
*
|
|
681
|
+
* @param definition Converter definition out of input data.
|
|
682
|
+
*/ _prepareAnyValueConverters(definition) {
|
|
683
|
+
const editor = this.editor;
|
|
684
|
+
// If `fontSize.supportAllValues=true`, we do not allow to use named presets in the plugin's configuration.
|
|
685
|
+
const presets = definition.model.values.filter((value)=>{
|
|
686
|
+
return !isLength(String(value)) && !isPercentage(String(value));
|
|
687
|
+
});
|
|
688
|
+
if (presets.length) {
|
|
689
|
+
/**
|
|
690
|
+
* If {@link module:font/fontconfig~FontSizeConfig#supportAllValues `config.fontSize.supportAllValues`} is `true`,
|
|
691
|
+
* you need to use numerical values as font size options.
|
|
692
|
+
*
|
|
693
|
+
* See valid examples described in the {@link module:font/fontconfig~FontSizeConfig#options plugin configuration}.
|
|
694
|
+
*
|
|
695
|
+
* @error font-size-invalid-use-of-named-presets
|
|
696
|
+
* @param {Array.<String>} presets Invalid values.
|
|
697
|
+
*/ throw new CKEditorError('font-size-invalid-use-of-named-presets', null, {
|
|
698
|
+
presets
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
702
|
+
model: FONT_SIZE,
|
|
703
|
+
view: (attributeValue, { writer })=>{
|
|
704
|
+
if (!attributeValue) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
return writer.createAttributeElement('span', {
|
|
708
|
+
style: 'font-size:' + attributeValue
|
|
709
|
+
}, {
|
|
710
|
+
priority: 7
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
715
|
+
model: {
|
|
716
|
+
key: FONT_SIZE,
|
|
717
|
+
value: (viewElement)=>viewElement.getStyle('font-size')
|
|
718
|
+
},
|
|
719
|
+
view: {
|
|
720
|
+
name: 'span',
|
|
721
|
+
styles: {
|
|
722
|
+
'font-size': /.*/
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Adds support for legacy `<font size="..">` formatting.
|
|
729
|
+
*/ _prepareCompatibilityConverter() {
|
|
730
|
+
const editor = this.editor;
|
|
731
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
732
|
+
view: {
|
|
733
|
+
name: 'font',
|
|
734
|
+
attributes: {
|
|
735
|
+
// Documentation mentions sizes from 1 to 7. To handle old content we support all values
|
|
736
|
+
// up to 999 but clamp it to the valid range. Why 999? It should cover accidental values
|
|
737
|
+
// similar to percentage, e.g. 100%, 200% which could be the usual mistake for font size.
|
|
738
|
+
'size': /^[+-]?\d{1,3}$/
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
model: {
|
|
742
|
+
key: FONT_SIZE,
|
|
743
|
+
value: (viewElement)=>{
|
|
744
|
+
const value = viewElement.getAttribute('size');
|
|
745
|
+
const isRelative = value[0] === '-' || value[0] === '+';
|
|
746
|
+
let size = parseInt(value, 10);
|
|
747
|
+
if (isRelative) {
|
|
748
|
+
// Add relative size (which can be negative) to the default size = 3.
|
|
749
|
+
size = 3 + size;
|
|
750
|
+
}
|
|
751
|
+
const maxSize = styleFontSize.length - 1;
|
|
752
|
+
const clampedSize = Math.min(Math.max(size, 0), maxSize);
|
|
753
|
+
return styleFontSize[clampedSize];
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* @inheritDoc
|
|
760
|
+
*/ constructor(editor){
|
|
761
|
+
super(editor);
|
|
762
|
+
// Define default configuration using named presets.
|
|
763
|
+
editor.config.define(FONT_SIZE, {
|
|
764
|
+
options: [
|
|
765
|
+
'tiny',
|
|
766
|
+
'small',
|
|
767
|
+
'default',
|
|
768
|
+
'big',
|
|
769
|
+
'huge'
|
|
770
|
+
],
|
|
771
|
+
supportAllValues: false
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
var fontSizeIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M9.816 11.5 7.038 4.785 4.261 11.5h5.555zm.62 1.5H3.641l-1.666 4.028H.312l5.789-14h1.875l5.789 14h-1.663L10.436 13zm7.55 2.279.779-.779.707.707-2.265 2.265-2.193-2.265.707-.707.765.765V4.825c0-.042 0-.083.002-.123l-.77.77-.707-.707L17.207 2.5l2.265 2.265-.707.707-.782-.782c.002.043.003.089.003.135v10.454z\"/></svg>";
|
|
777
|
+
|
|
778
|
+
class FontSizeUI extends Plugin {
|
|
779
|
+
/**
|
|
780
|
+
* @inheritDoc
|
|
781
|
+
*/ static get pluginName() {
|
|
782
|
+
return 'FontSizeUI';
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* @inheritDoc
|
|
786
|
+
*/ init() {
|
|
787
|
+
const editor = this.editor;
|
|
788
|
+
const t = editor.t;
|
|
789
|
+
const options = this._getLocalizedOptions();
|
|
790
|
+
const command = editor.commands.get(FONT_SIZE);
|
|
791
|
+
const accessibleLabel = t('Font Size');
|
|
792
|
+
const listOptions = _prepareListOptions(options, command);
|
|
793
|
+
// Register UI component.
|
|
794
|
+
editor.ui.componentFactory.add(FONT_SIZE, (locale)=>{
|
|
795
|
+
const dropdownView = createDropdown(locale);
|
|
796
|
+
addListToDropdown(dropdownView, listOptions, {
|
|
797
|
+
role: 'menu',
|
|
798
|
+
ariaLabel: accessibleLabel
|
|
799
|
+
});
|
|
800
|
+
// Create dropdown model.
|
|
801
|
+
dropdownView.buttonView.set({
|
|
802
|
+
label: accessibleLabel,
|
|
803
|
+
icon: fontSizeIcon,
|
|
804
|
+
tooltip: true
|
|
805
|
+
});
|
|
806
|
+
dropdownView.extendTemplate({
|
|
807
|
+
attributes: {
|
|
808
|
+
class: [
|
|
809
|
+
'ck-font-size-dropdown'
|
|
810
|
+
]
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
dropdownView.bind('isEnabled').to(command);
|
|
814
|
+
// Execute command when an item from the dropdown is selected.
|
|
815
|
+
this.listenTo(dropdownView, 'execute', (evt)=>{
|
|
816
|
+
editor.execute(evt.source.commandName, {
|
|
817
|
+
value: evt.source.commandParam
|
|
818
|
+
});
|
|
819
|
+
editor.editing.view.focus();
|
|
820
|
+
});
|
|
821
|
+
return dropdownView;
|
|
822
|
+
});
|
|
823
|
+
editor.ui.componentFactory.add(`menuBar:${FONT_SIZE}`, (locale)=>{
|
|
824
|
+
const menuView = new MenuBarMenuView(locale);
|
|
825
|
+
menuView.buttonView.set({
|
|
826
|
+
label: accessibleLabel,
|
|
827
|
+
icon: fontSizeIcon
|
|
828
|
+
});
|
|
829
|
+
menuView.bind('isEnabled').to(command);
|
|
830
|
+
const listView = new MenuBarMenuListView(locale);
|
|
831
|
+
for (const definition of listOptions){
|
|
832
|
+
const listItemView = new MenuBarMenuListItemView(locale, menuView);
|
|
833
|
+
const buttonView = new MenuBarMenuListItemButtonView(locale);
|
|
834
|
+
buttonView.bind(...Object.keys(definition.model)).to(definition.model);
|
|
835
|
+
buttonView.bind('ariaChecked').to(buttonView, 'isOn');
|
|
836
|
+
buttonView.delegate('execute').to(menuView);
|
|
837
|
+
buttonView.on('execute', ()=>{
|
|
838
|
+
editor.execute(definition.model.commandName, {
|
|
839
|
+
value: definition.model.commandParam
|
|
840
|
+
});
|
|
841
|
+
editor.editing.view.focus();
|
|
842
|
+
});
|
|
843
|
+
listItemView.children.add(buttonView);
|
|
844
|
+
listView.items.add(listItemView);
|
|
845
|
+
}
|
|
846
|
+
menuView.panelView.children.add(listView);
|
|
847
|
+
return menuView;
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Returns options as defined in `config.fontSize.options` but processed to account for
|
|
852
|
+
* editor localization, i.e. to display {@link module:font/fontconfig~FontSizeOption}
|
|
853
|
+
* in the correct language.
|
|
854
|
+
*
|
|
855
|
+
* Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
|
|
856
|
+
* when the user configuration is defined because the editor does not exist yet.
|
|
857
|
+
*/ _getLocalizedOptions() {
|
|
858
|
+
const editor = this.editor;
|
|
859
|
+
const t = editor.t;
|
|
860
|
+
const localizedTitles = {
|
|
861
|
+
Default: t('Default'),
|
|
862
|
+
Tiny: t('Tiny'),
|
|
863
|
+
Small: t('Small'),
|
|
864
|
+
Big: t('Big'),
|
|
865
|
+
Huge: t('Huge')
|
|
866
|
+
};
|
|
867
|
+
const options = normalizeOptions(editor.config.get(FONT_SIZE).options);
|
|
868
|
+
return options.map((option)=>{
|
|
869
|
+
const title = localizedTitles[option.title];
|
|
870
|
+
if (title && title != option.title) {
|
|
871
|
+
// Clone the option to avoid altering the original `namedPresets` from `./utils.js`.
|
|
872
|
+
option = Object.assign({}, option, {
|
|
873
|
+
title
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
return option;
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Prepares FontSize dropdown items.
|
|
882
|
+
*/ function _prepareListOptions(options, command) {
|
|
883
|
+
const itemDefinitions = new Collection();
|
|
884
|
+
for (const option of options){
|
|
885
|
+
const def = {
|
|
886
|
+
type: 'button',
|
|
887
|
+
model: new ViewModel({
|
|
888
|
+
commandName: FONT_SIZE,
|
|
889
|
+
commandParam: option.model,
|
|
890
|
+
label: option.title,
|
|
891
|
+
class: 'ck-fontsize-option',
|
|
892
|
+
role: 'menuitemradio',
|
|
893
|
+
withText: true
|
|
894
|
+
})
|
|
895
|
+
};
|
|
896
|
+
if (option.view && typeof option.view !== 'string') {
|
|
897
|
+
if (option.view.styles) {
|
|
898
|
+
def.model.set('labelStyle', `font-size:${option.view.styles['font-size']}`);
|
|
899
|
+
}
|
|
900
|
+
if (option.view.classes) {
|
|
901
|
+
def.model.set('class', `${def.model.class} ${option.view.classes}`);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
def.model.bind('isOn').to(command, 'value', (value)=>value === option.model);
|
|
905
|
+
// Add the option to the collection.
|
|
906
|
+
itemDefinitions.add(def);
|
|
907
|
+
}
|
|
908
|
+
return itemDefinitions;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
class FontSize extends Plugin {
|
|
912
|
+
/**
|
|
913
|
+
* @inheritDoc
|
|
914
|
+
*/ static get requires() {
|
|
915
|
+
return [
|
|
916
|
+
FontSizeEditing,
|
|
917
|
+
FontSizeUI
|
|
918
|
+
];
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* @inheritDoc
|
|
922
|
+
*/ static get pluginName() {
|
|
923
|
+
return 'FontSize';
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Normalizes and translates the {@link module:font/fontconfig~FontSizeConfig#options configuration options}
|
|
927
|
+
* to the {@link module:font/fontconfig~FontSizeOption} format.
|
|
928
|
+
*
|
|
929
|
+
* @param configuredOptions An array of options taken from the configuration.
|
|
930
|
+
*/ normalizeSizeOptions(options) {
|
|
931
|
+
return normalizeOptions(options);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
class FontColorCommand extends FontCommand {
|
|
936
|
+
/**
|
|
937
|
+
* @inheritDoc
|
|
938
|
+
*/ constructor(editor){
|
|
939
|
+
super(editor, FONT_COLOR);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
class FontColorEditing extends Plugin {
|
|
944
|
+
/**
|
|
945
|
+
* @inheritDoc
|
|
946
|
+
*/ static get pluginName() {
|
|
947
|
+
return 'FontColorEditing';
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* @inheritDoc
|
|
951
|
+
*/ constructor(editor){
|
|
952
|
+
super(editor);
|
|
953
|
+
editor.config.define(FONT_COLOR, {
|
|
954
|
+
colors: [
|
|
955
|
+
{
|
|
956
|
+
color: 'hsl(0, 0%, 0%)',
|
|
957
|
+
label: 'Black'
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
color: 'hsl(0, 0%, 30%)',
|
|
961
|
+
label: 'Dim grey'
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
color: 'hsl(0, 0%, 60%)',
|
|
965
|
+
label: 'Grey'
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
color: 'hsl(0, 0%, 90%)',
|
|
969
|
+
label: 'Light grey'
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
color: 'hsl(0, 0%, 100%)',
|
|
973
|
+
label: 'White',
|
|
974
|
+
hasBorder: true
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
color: 'hsl(0, 75%, 60%)',
|
|
978
|
+
label: 'Red'
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
color: 'hsl(30, 75%, 60%)',
|
|
982
|
+
label: 'Orange'
|
|
983
|
+
},
|
|
984
|
+
{
|
|
985
|
+
color: 'hsl(60, 75%, 60%)',
|
|
986
|
+
label: 'Yellow'
|
|
987
|
+
},
|
|
988
|
+
{
|
|
989
|
+
color: 'hsl(90, 75%, 60%)',
|
|
990
|
+
label: 'Light green'
|
|
991
|
+
},
|
|
992
|
+
{
|
|
993
|
+
color: 'hsl(120, 75%, 60%)',
|
|
994
|
+
label: 'Green'
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
color: 'hsl(150, 75%, 60%)',
|
|
998
|
+
label: 'Aquamarine'
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
color: 'hsl(180, 75%, 60%)',
|
|
1002
|
+
label: 'Turquoise'
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
color: 'hsl(210, 75%, 60%)',
|
|
1006
|
+
label: 'Light blue'
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
color: 'hsl(240, 75%, 60%)',
|
|
1010
|
+
label: 'Blue'
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
color: 'hsl(270, 75%, 60%)',
|
|
1014
|
+
label: 'Purple'
|
|
1015
|
+
}
|
|
1016
|
+
],
|
|
1017
|
+
columns: 5
|
|
1018
|
+
});
|
|
1019
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
1020
|
+
view: {
|
|
1021
|
+
name: 'span',
|
|
1022
|
+
styles: {
|
|
1023
|
+
'color': /[\s\S]+/
|
|
1024
|
+
}
|
|
1025
|
+
},
|
|
1026
|
+
model: {
|
|
1027
|
+
key: FONT_COLOR,
|
|
1028
|
+
value: renderUpcastAttribute('color')
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
// Support legacy `<font color="..">` formatting.
|
|
1032
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
1033
|
+
view: {
|
|
1034
|
+
name: 'font',
|
|
1035
|
+
attributes: {
|
|
1036
|
+
'color': /^#?\w+$/
|
|
1037
|
+
}
|
|
1038
|
+
},
|
|
1039
|
+
model: {
|
|
1040
|
+
key: FONT_COLOR,
|
|
1041
|
+
value: (viewElement)=>viewElement.getAttribute('color')
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
1045
|
+
model: FONT_COLOR,
|
|
1046
|
+
view: renderDowncastElement('color')
|
|
1047
|
+
});
|
|
1048
|
+
editor.commands.add(FONT_COLOR, new FontColorCommand(editor));
|
|
1049
|
+
// Allow the font color attribute on text nodes.
|
|
1050
|
+
editor.model.schema.extend('$text', {
|
|
1051
|
+
allowAttributes: FONT_COLOR
|
|
1052
|
+
});
|
|
1053
|
+
editor.model.schema.setAttributeProperties(FONT_COLOR, {
|
|
1054
|
+
isFormatting: true,
|
|
1055
|
+
copyOnEnter: true
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
class ColorUI extends Plugin {
|
|
1061
|
+
/**
|
|
1062
|
+
* @inheritDoc
|
|
1063
|
+
*/ init() {
|
|
1064
|
+
const editor = this.editor;
|
|
1065
|
+
const locale = editor.locale;
|
|
1066
|
+
const t = locale.t;
|
|
1067
|
+
const command = editor.commands.get(this.commandName);
|
|
1068
|
+
const componentConfig = editor.config.get(this.componentName);
|
|
1069
|
+
const colorsConfig = normalizeColorOptions(componentConfig.colors);
|
|
1070
|
+
const localizedColors = getLocalizedColorOptions(locale, colorsConfig);
|
|
1071
|
+
const documentColorsCount = componentConfig.documentColors;
|
|
1072
|
+
const hasColorPicker = componentConfig.colorPicker !== false;
|
|
1073
|
+
// Register the UI component.
|
|
1074
|
+
editor.ui.componentFactory.add(this.componentName, (locale)=>{
|
|
1075
|
+
const dropdownView = createDropdown(locale);
|
|
1076
|
+
// Font color dropdown rendering is deferred once it gets open to improve performance (#6192).
|
|
1077
|
+
let dropdownContentRendered = false;
|
|
1078
|
+
const colorSelectorView = addColorSelectorToDropdown({
|
|
1079
|
+
dropdownView,
|
|
1080
|
+
colors: localizedColors.map((option)=>({
|
|
1081
|
+
label: option.label,
|
|
1082
|
+
color: option.model,
|
|
1083
|
+
options: {
|
|
1084
|
+
hasBorder: option.hasBorder
|
|
1085
|
+
}
|
|
1086
|
+
})),
|
|
1087
|
+
columns: this.columns,
|
|
1088
|
+
removeButtonLabel: t('Remove color'),
|
|
1089
|
+
colorPickerLabel: t('Color picker'),
|
|
1090
|
+
documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
|
|
1091
|
+
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount,
|
|
1092
|
+
colorPickerViewConfig: hasColorPicker ? componentConfig.colorPicker || {} : false
|
|
1093
|
+
});
|
|
1094
|
+
colorSelectorView.bind('selectedColor').to(command, 'value');
|
|
1095
|
+
dropdownView.buttonView.set({
|
|
1096
|
+
label: this.dropdownLabel,
|
|
1097
|
+
icon: this.icon,
|
|
1098
|
+
tooltip: true
|
|
1099
|
+
});
|
|
1100
|
+
dropdownView.extendTemplate({
|
|
1101
|
+
attributes: {
|
|
1102
|
+
class: 'ck-color-ui-dropdown'
|
|
1103
|
+
}
|
|
1104
|
+
});
|
|
1105
|
+
dropdownView.bind('isEnabled').to(command);
|
|
1106
|
+
colorSelectorView.on('execute', (evt, data)=>{
|
|
1107
|
+
if (dropdownView.isOpen) {
|
|
1108
|
+
editor.execute(this.commandName, {
|
|
1109
|
+
value: data.value,
|
|
1110
|
+
batch: this._undoStepBatch
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
if (data.source !== 'colorPicker') {
|
|
1114
|
+
editor.editing.view.focus();
|
|
1115
|
+
}
|
|
1116
|
+
if (data.source === 'colorPickerSaveButton') {
|
|
1117
|
+
dropdownView.isOpen = false;
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
colorSelectorView.on('colorPicker:show', ()=>{
|
|
1121
|
+
this._undoStepBatch = editor.model.createBatch();
|
|
1122
|
+
});
|
|
1123
|
+
colorSelectorView.on('colorPicker:cancel', ()=>{
|
|
1124
|
+
if (this._undoStepBatch.operations.length) {
|
|
1125
|
+
// We need to close the dropdown before the undo batch.
|
|
1126
|
+
// Otherwise, ColorUI treats undo as a selected color change,
|
|
1127
|
+
// propagating the update to the whole selection.
|
|
1128
|
+
// That's an issue if spans with various colors were selected.
|
|
1129
|
+
dropdownView.isOpen = false;
|
|
1130
|
+
editor.execute('undo', this._undoStepBatch);
|
|
1131
|
+
}
|
|
1132
|
+
editor.editing.view.focus();
|
|
1133
|
+
});
|
|
1134
|
+
dropdownView.on('change:isOpen', (evt, name, isVisible)=>{
|
|
1135
|
+
if (!dropdownContentRendered) {
|
|
1136
|
+
dropdownContentRendered = true;
|
|
1137
|
+
dropdownView.colorSelectorView.appendUI();
|
|
1138
|
+
}
|
|
1139
|
+
if (isVisible) {
|
|
1140
|
+
if (documentColorsCount !== 0) {
|
|
1141
|
+
colorSelectorView.updateDocumentColors(editor.model, this.componentName);
|
|
1142
|
+
}
|
|
1143
|
+
colorSelectorView.updateSelectedColors();
|
|
1144
|
+
colorSelectorView.showColorGridsFragment();
|
|
1145
|
+
}
|
|
1146
|
+
});
|
|
1147
|
+
// Accessibility: focus the first active color when opening the dropdown.
|
|
1148
|
+
focusChildOnDropdownOpen(dropdownView, ()=>dropdownView.colorSelectorView.colorGridsFragmentView.staticColorsGrid.items.find((item)=>item.isOn));
|
|
1149
|
+
return dropdownView;
|
|
1150
|
+
});
|
|
1151
|
+
// Register menu bar button..
|
|
1152
|
+
editor.ui.componentFactory.add(`menuBar:${this.componentName}`, (locale)=>{
|
|
1153
|
+
const menuView = new MenuBarMenuView(locale);
|
|
1154
|
+
menuView.buttonView.set({
|
|
1155
|
+
label: this.dropdownLabel,
|
|
1156
|
+
icon: this.icon
|
|
1157
|
+
});
|
|
1158
|
+
menuView.bind('isEnabled').to(command);
|
|
1159
|
+
// Font color sub-menu rendering is deferred once it gets open to improve performance (#6192).
|
|
1160
|
+
let contentRendered = false;
|
|
1161
|
+
const colorSelectorView = new ColorSelectorView(locale, {
|
|
1162
|
+
colors: localizedColors.map((option)=>({
|
|
1163
|
+
label: option.label,
|
|
1164
|
+
color: option.model,
|
|
1165
|
+
options: {
|
|
1166
|
+
hasBorder: option.hasBorder
|
|
1167
|
+
}
|
|
1168
|
+
})),
|
|
1169
|
+
columns: this.columns,
|
|
1170
|
+
removeButtonLabel: t('Remove color'),
|
|
1171
|
+
colorPickerLabel: t('Color picker'),
|
|
1172
|
+
documentColorsLabel: documentColorsCount !== 0 ? t('Document colors') : '',
|
|
1173
|
+
documentColorsCount: documentColorsCount === undefined ? this.columns : documentColorsCount,
|
|
1174
|
+
colorPickerViewConfig: false
|
|
1175
|
+
});
|
|
1176
|
+
colorSelectorView.bind('selectedColor').to(command, 'value');
|
|
1177
|
+
colorSelectorView.delegate('execute').to(menuView);
|
|
1178
|
+
colorSelectorView.on('execute', (evt, data)=>{
|
|
1179
|
+
editor.execute(this.commandName, {
|
|
1180
|
+
value: data.value,
|
|
1181
|
+
batch: this._undoStepBatch
|
|
1182
|
+
});
|
|
1183
|
+
editor.editing.view.focus();
|
|
1184
|
+
});
|
|
1185
|
+
menuView.on('change:isOpen', (evt, name, isVisible)=>{
|
|
1186
|
+
if (!contentRendered) {
|
|
1187
|
+
contentRendered = true;
|
|
1188
|
+
colorSelectorView.appendUI();
|
|
1189
|
+
}
|
|
1190
|
+
if (isVisible) {
|
|
1191
|
+
if (documentColorsCount !== 0) {
|
|
1192
|
+
colorSelectorView.updateDocumentColors(editor.model, this.componentName);
|
|
1193
|
+
}
|
|
1194
|
+
colorSelectorView.updateSelectedColors();
|
|
1195
|
+
colorSelectorView.showColorGridsFragment();
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
menuView.panelView.children.add(colorSelectorView);
|
|
1199
|
+
return menuView;
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Creates a plugin which introduces a dropdown with a pre–configured
|
|
1204
|
+
* {@link module:ui/colorselector/colorselectorview~ColorSelectorView}.
|
|
1205
|
+
*
|
|
1206
|
+
* @param config The configuration object.
|
|
1207
|
+
* @param config.commandName The name of the command which will be executed when a color tile is clicked.
|
|
1208
|
+
* @param config.componentName The name of the dropdown in the {@link module:ui/componentfactory~ComponentFactory}
|
|
1209
|
+
* and the configuration scope name in `editor.config`.
|
|
1210
|
+
* @param config.icon The SVG icon used by the dropdown.
|
|
1211
|
+
* @param config.dropdownLabel The label used by the dropdown.
|
|
1212
|
+
*/ constructor(editor, { commandName, componentName, icon, dropdownLabel }){
|
|
1213
|
+
super(editor);
|
|
1214
|
+
this.commandName = commandName;
|
|
1215
|
+
this.componentName = componentName;
|
|
1216
|
+
this.icon = icon;
|
|
1217
|
+
this.dropdownLabel = dropdownLabel;
|
|
1218
|
+
this.columns = editor.config.get(`${this.componentName}.columns`);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
var fontColorIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12.4 10.3 10 4.5l-2.4 5.8h4.8zm.5 1.2H7.1L5.7 15H4.2l5-12h1.6l5 12h-1.5L13 11.5zm3.1 7H4a1 1 0 0 1 0-2h12a1 1 0 0 1 0 2z\"/></svg>";
|
|
1223
|
+
|
|
1224
|
+
class FontColorUI extends ColorUI {
|
|
1225
|
+
/**
|
|
1226
|
+
* @inheritDoc
|
|
1227
|
+
*/ static get pluginName() {
|
|
1228
|
+
return 'FontColorUI';
|
|
1229
|
+
}
|
|
1230
|
+
/**
|
|
1231
|
+
* @inheritDoc
|
|
1232
|
+
*/ constructor(editor){
|
|
1233
|
+
const t = editor.locale.t;
|
|
1234
|
+
super(editor, {
|
|
1235
|
+
commandName: FONT_COLOR,
|
|
1236
|
+
componentName: FONT_COLOR,
|
|
1237
|
+
icon: fontColorIcon,
|
|
1238
|
+
dropdownLabel: t('Font Color')
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
class FontColor extends Plugin {
|
|
1244
|
+
/**
|
|
1245
|
+
* @inheritDoc
|
|
1246
|
+
*/ static get requires() {
|
|
1247
|
+
return [
|
|
1248
|
+
FontColorEditing,
|
|
1249
|
+
FontColorUI
|
|
1250
|
+
];
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* @inheritDoc
|
|
1254
|
+
*/ static get pluginName() {
|
|
1255
|
+
return 'FontColor';
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
class FontBackgroundColorCommand extends FontCommand {
|
|
1260
|
+
/**
|
|
1261
|
+
* @inheritDoc
|
|
1262
|
+
*/ constructor(editor){
|
|
1263
|
+
super(editor, FONT_BACKGROUND_COLOR);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
class FontBackgroundColorEditing extends Plugin {
|
|
1268
|
+
/**
|
|
1269
|
+
* @inheritDoc
|
|
1270
|
+
*/ static get pluginName() {
|
|
1271
|
+
return 'FontBackgroundColorEditing';
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* @inheritDoc
|
|
1275
|
+
*/ constructor(editor){
|
|
1276
|
+
super(editor);
|
|
1277
|
+
editor.config.define(FONT_BACKGROUND_COLOR, {
|
|
1278
|
+
colors: [
|
|
1279
|
+
{
|
|
1280
|
+
color: 'hsl(0, 0%, 0%)',
|
|
1281
|
+
label: 'Black'
|
|
1282
|
+
},
|
|
1283
|
+
{
|
|
1284
|
+
color: 'hsl(0, 0%, 30%)',
|
|
1285
|
+
label: 'Dim grey'
|
|
1286
|
+
},
|
|
1287
|
+
{
|
|
1288
|
+
color: 'hsl(0, 0%, 60%)',
|
|
1289
|
+
label: 'Grey'
|
|
1290
|
+
},
|
|
1291
|
+
{
|
|
1292
|
+
color: 'hsl(0, 0%, 90%)',
|
|
1293
|
+
label: 'Light grey'
|
|
1294
|
+
},
|
|
1295
|
+
{
|
|
1296
|
+
color: 'hsl(0, 0%, 100%)',
|
|
1297
|
+
label: 'White',
|
|
1298
|
+
hasBorder: true
|
|
1299
|
+
},
|
|
1300
|
+
{
|
|
1301
|
+
color: 'hsl(0, 75%, 60%)',
|
|
1302
|
+
label: 'Red'
|
|
1303
|
+
},
|
|
1304
|
+
{
|
|
1305
|
+
color: 'hsl(30, 75%, 60%)',
|
|
1306
|
+
label: 'Orange'
|
|
1307
|
+
},
|
|
1308
|
+
{
|
|
1309
|
+
color: 'hsl(60, 75%, 60%)',
|
|
1310
|
+
label: 'Yellow'
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
color: 'hsl(90, 75%, 60%)',
|
|
1314
|
+
label: 'Light green'
|
|
1315
|
+
},
|
|
1316
|
+
{
|
|
1317
|
+
color: 'hsl(120, 75%, 60%)',
|
|
1318
|
+
label: 'Green'
|
|
1319
|
+
},
|
|
1320
|
+
{
|
|
1321
|
+
color: 'hsl(150, 75%, 60%)',
|
|
1322
|
+
label: 'Aquamarine'
|
|
1323
|
+
},
|
|
1324
|
+
{
|
|
1325
|
+
color: 'hsl(180, 75%, 60%)',
|
|
1326
|
+
label: 'Turquoise'
|
|
1327
|
+
},
|
|
1328
|
+
{
|
|
1329
|
+
color: 'hsl(210, 75%, 60%)',
|
|
1330
|
+
label: 'Light blue'
|
|
1331
|
+
},
|
|
1332
|
+
{
|
|
1333
|
+
color: 'hsl(240, 75%, 60%)',
|
|
1334
|
+
label: 'Blue'
|
|
1335
|
+
},
|
|
1336
|
+
{
|
|
1337
|
+
color: 'hsl(270, 75%, 60%)',
|
|
1338
|
+
label: 'Purple'
|
|
1339
|
+
}
|
|
1340
|
+
],
|
|
1341
|
+
columns: 5
|
|
1342
|
+
});
|
|
1343
|
+
editor.data.addStyleProcessorRules(addBackgroundRules);
|
|
1344
|
+
editor.conversion.for('upcast').elementToAttribute({
|
|
1345
|
+
view: {
|
|
1346
|
+
name: 'span',
|
|
1347
|
+
styles: {
|
|
1348
|
+
'background-color': /[\s\S]+/
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
model: {
|
|
1352
|
+
key: FONT_BACKGROUND_COLOR,
|
|
1353
|
+
value: renderUpcastAttribute('background-color')
|
|
1354
|
+
}
|
|
1355
|
+
});
|
|
1356
|
+
editor.conversion.for('downcast').attributeToElement({
|
|
1357
|
+
model: FONT_BACKGROUND_COLOR,
|
|
1358
|
+
view: renderDowncastElement('background-color')
|
|
1359
|
+
});
|
|
1360
|
+
editor.commands.add(FONT_BACKGROUND_COLOR, new FontBackgroundColorCommand(editor));
|
|
1361
|
+
// Allow the font backgroundColor attribute on text nodes.
|
|
1362
|
+
editor.model.schema.extend('$text', {
|
|
1363
|
+
allowAttributes: FONT_BACKGROUND_COLOR
|
|
1364
|
+
});
|
|
1365
|
+
editor.model.schema.setAttributeProperties(FONT_BACKGROUND_COLOR, {
|
|
1366
|
+
isFormatting: true,
|
|
1367
|
+
copyOnEnter: true
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
var fontBackgroundColorIcon = "<svg viewBox=\"0 0 20 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4 2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm8.38 9.262H7.62L10 5.506l2.38 5.756zm.532 1.285L14.34 16h1.426L10.804 4H9.196L4.234 16H5.66l1.428-3.453h5.824z\"/></svg>";
|
|
1373
|
+
|
|
1374
|
+
class FontBackgroundColorUI extends ColorUI {
|
|
1375
|
+
/**
|
|
1376
|
+
* @inheritDoc
|
|
1377
|
+
*/ static get pluginName() {
|
|
1378
|
+
return 'FontBackgroundColorUI';
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* @inheritDoc
|
|
1382
|
+
*/ constructor(editor){
|
|
1383
|
+
const t = editor.locale.t;
|
|
1384
|
+
super(editor, {
|
|
1385
|
+
commandName: FONT_BACKGROUND_COLOR,
|
|
1386
|
+
componentName: FONT_BACKGROUND_COLOR,
|
|
1387
|
+
icon: fontBackgroundColorIcon,
|
|
1388
|
+
dropdownLabel: t('Font Background Color')
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
class FontBackgroundColor extends Plugin {
|
|
1394
|
+
/**
|
|
1395
|
+
* @inheritDoc
|
|
1396
|
+
*/ static get requires() {
|
|
1397
|
+
return [
|
|
1398
|
+
FontBackgroundColorEditing,
|
|
1399
|
+
FontBackgroundColorUI
|
|
1400
|
+
];
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* @inheritDoc
|
|
1404
|
+
*/ static get pluginName() {
|
|
1405
|
+
return 'FontBackgroundColor';
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
class Font extends Plugin {
|
|
1410
|
+
/**
|
|
1411
|
+
* @inheritDoc
|
|
1412
|
+
*/ static get requires() {
|
|
1413
|
+
return [
|
|
1414
|
+
FontFamily,
|
|
1415
|
+
FontSize,
|
|
1416
|
+
FontColor,
|
|
1417
|
+
FontBackgroundColor
|
|
1418
|
+
];
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* @inheritDoc
|
|
1422
|
+
*/ static get pluginName() {
|
|
1423
|
+
return 'Font';
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
export { Font, FontBackgroundColor, FontBackgroundColorEditing, FontBackgroundColorUI, FontColor, FontColorEditing, FontColorUI, FontFamily, FontFamilyEditing, FontFamilyUI, FontSize, FontSizeEditing, FontSizeUI };
|
|
1428
|
+
//# sourceMappingURL=index.js.map
|