This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
fontsizeediting.js
71 lines (61 loc) · 1.97 KB
/
fontsizeediting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
/**
* @module font/fontsize/fontsizeediting
*/
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import FontSizeCommand from './fontsizecommand';
import { normalizeOptions } from './utils';
import { buildDefinition, FONT_SIZE } from '../utils';
/**
* The font size editing feature.
*
* It introduces the {@link module:font/fontsize/fontsizecommand~FontSizeCommand command} and the `fontSize`
* attribute in the {@link module:engine/model/model~Model model} which renders in the {@link module:engine/view/view view}
* as a `<span>` element with either:
* * a style attribute (`<span style="font-size:12px">...</span>`),
* * or a class attribute (`<span class="text-small">...</span>`)
*
* depending on the {@link module:font/fontsize~FontSizeConfig configuration}.
*
* @extends module:core/plugin~Plugin
*/
export default class FontSizeEditing extends Plugin {
/**
* @inheritDoc
*/
constructor( editor ) {
super( editor );
// Define default configuration using named presets.
editor.config.define( FONT_SIZE, {
options: [
'tiny',
'small',
'default',
'big',
'huge'
]
} );
// Define view to model conversion.
const options = normalizeOptions( this.editor.config.get( 'fontSize.options' ) ).filter( item => item.model );
const definition = buildDefinition( FONT_SIZE, options );
// Set-up the two-way conversion.
editor.conversion.attributeToElement( definition );
// Add FontSize command.
editor.commands.add( FONT_SIZE, new FontSizeCommand( editor ) );
}
/**
* @inheritDoc
*/
init() {
const editor = this.editor;
// Allow fontSize attribute on text nodes.
editor.model.schema.extend( '$text', { allowAttributes: FONT_SIZE } );
editor.model.schema.setAttributeProperties( FONT_SIZE, {
isFormatting: true,
copyOnEnter: true
} );
}
}