@ckeditor/ckeditor5-basic-styles 30.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -0
- package/README.md +20 -0
- package/build/basic-styles.js +5 -0
- package/build/translations/af.js +1 -0
- package/build/translations/ar.js +1 -0
- package/build/translations/ast.js +1 -0
- package/build/translations/az.js +1 -0
- package/build/translations/bg.js +1 -0
- package/build/translations/ca.js +1 -0
- package/build/translations/cs.js +1 -0
- package/build/translations/da.js +1 -0
- package/build/translations/de-ch.js +1 -0
- package/build/translations/de.js +1 -0
- package/build/translations/el.js +1 -0
- package/build/translations/en-au.js +1 -0
- package/build/translations/en-gb.js +1 -0
- package/build/translations/eo.js +1 -0
- package/build/translations/es.js +1 -0
- package/build/translations/et.js +1 -0
- package/build/translations/eu.js +1 -0
- package/build/translations/fa.js +1 -0
- package/build/translations/fi.js +1 -0
- package/build/translations/fr.js +1 -0
- package/build/translations/gl.js +1 -0
- package/build/translations/gu.js +1 -0
- package/build/translations/he.js +1 -0
- package/build/translations/hi.js +1 -0
- package/build/translations/hr.js +1 -0
- package/build/translations/hu.js +1 -0
- package/build/translations/id.js +1 -0
- package/build/translations/it.js +1 -0
- package/build/translations/ja.js +1 -0
- package/build/translations/km.js +1 -0
- package/build/translations/kn.js +1 -0
- package/build/translations/ko.js +1 -0
- package/build/translations/ku.js +1 -0
- package/build/translations/lt.js +1 -0
- package/build/translations/lv.js +1 -0
- package/build/translations/nb.js +1 -0
- package/build/translations/ne.js +1 -0
- package/build/translations/nl.js +1 -0
- package/build/translations/no.js +1 -0
- package/build/translations/oc.js +1 -0
- package/build/translations/pl.js +1 -0
- package/build/translations/pt-br.js +1 -0
- package/build/translations/pt.js +1 -0
- package/build/translations/ro.js +1 -0
- package/build/translations/ru.js +1 -0
- package/build/translations/si.js +1 -0
- package/build/translations/sk.js +1 -0
- package/build/translations/sl.js +1 -0
- package/build/translations/sq.js +1 -0
- package/build/translations/sr-latn.js +1 -0
- package/build/translations/sr.js +1 -0
- package/build/translations/sv.js +1 -0
- package/build/translations/tk.js +1 -0
- package/build/translations/tr.js +1 -0
- package/build/translations/tt.js +1 -0
- package/build/translations/ug.js +1 -0
- package/build/translations/uk.js +1 -0
- package/build/translations/vi.js +1 -0
- package/build/translations/zh-cn.js +1 -0
- package/build/translations/zh.js +1 -0
- package/ckeditor5-metadata.json +137 -0
- package/lang/contexts.json +9 -0
- package/lang/translations/af.po +45 -0
- package/lang/translations/ar.po +45 -0
- package/lang/translations/ast.po +45 -0
- package/lang/translations/az.po +45 -0
- package/lang/translations/bg.po +45 -0
- package/lang/translations/ca.po +45 -0
- package/lang/translations/cs.po +45 -0
- package/lang/translations/da.po +45 -0
- package/lang/translations/de-ch.po +45 -0
- package/lang/translations/de.po +45 -0
- package/lang/translations/el.po +45 -0
- package/lang/translations/en-au.po +45 -0
- package/lang/translations/en-gb.po +45 -0
- package/lang/translations/en.po +45 -0
- package/lang/translations/eo.po +45 -0
- package/lang/translations/es.po +45 -0
- package/lang/translations/et.po +45 -0
- package/lang/translations/eu.po +45 -0
- package/lang/translations/fa.po +45 -0
- package/lang/translations/fi.po +45 -0
- package/lang/translations/fr.po +45 -0
- package/lang/translations/gl.po +45 -0
- package/lang/translations/gu.po +45 -0
- package/lang/translations/he.po +45 -0
- package/lang/translations/hi.po +45 -0
- package/lang/translations/hr.po +45 -0
- package/lang/translations/hu.po +45 -0
- package/lang/translations/id.po +45 -0
- package/lang/translations/it.po +45 -0
- package/lang/translations/ja.po +45 -0
- package/lang/translations/km.po +45 -0
- package/lang/translations/kn.po +45 -0
- package/lang/translations/ko.po +45 -0
- package/lang/translations/ku.po +45 -0
- package/lang/translations/lt.po +45 -0
- package/lang/translations/lv.po +45 -0
- package/lang/translations/nb.po +45 -0
- package/lang/translations/ne.po +45 -0
- package/lang/translations/nl.po +45 -0
- package/lang/translations/no.po +45 -0
- package/lang/translations/oc.po +45 -0
- package/lang/translations/pl.po +45 -0
- package/lang/translations/pt-br.po +45 -0
- package/lang/translations/pt.po +45 -0
- package/lang/translations/ro.po +45 -0
- package/lang/translations/ru.po +45 -0
- package/lang/translations/si.po +45 -0
- package/lang/translations/sk.po +45 -0
- package/lang/translations/sl.po +45 -0
- package/lang/translations/sq.po +45 -0
- package/lang/translations/sr-latn.po +45 -0
- package/lang/translations/sr.po +45 -0
- package/lang/translations/sv.po +45 -0
- package/lang/translations/tk.po +45 -0
- package/lang/translations/tr.po +45 -0
- package/lang/translations/tt.po +45 -0
- package/lang/translations/ug.po +45 -0
- package/lang/translations/uk.po +45 -0
- package/lang/translations/vi.po +45 -0
- package/lang/translations/zh-cn.po +45 -0
- package/lang/translations/zh.po +45 -0
- package/package.json +53 -0
- package/src/attributecommand.js +138 -0
- package/src/bold/boldediting.js +73 -0
- package/src/bold/boldui.js +61 -0
- package/src/bold.js +39 -0
- package/src/code/codeediting.js +73 -0
- package/src/code/codeui.js +62 -0
- package/src/code.js +41 -0
- package/src/index.js +30 -0
- package/src/italic/italicediting.js +63 -0
- package/src/italic/italicui.js +61 -0
- package/src/italic.js +39 -0
- package/src/strikethrough/strikethroughediting.js +65 -0
- package/src/strikethrough/strikethroughui.js +61 -0
- package/src/strikethrough.js +39 -0
- package/src/subscript/subscriptediting.js +60 -0
- package/src/subscript/subscriptui.js +60 -0
- package/src/subscript.js +36 -0
- package/src/superscript/superscriptediting.js +60 -0
- package/src/superscript/superscriptui.js +60 -0
- package/src/superscript.js +36 -0
- package/src/underline/underlineediting.js +60 -0
- package/src/underline/underlineui.js +61 -0
- package/src/underline.js +39 -0
- package/theme/code.css +14 -0
- package/theme/icons/bold.svg +1 -0
- package/theme/icons/code.svg +1 -0
- package/theme/icons/italic.svg +1 -0
- package/theme/icons/strikethrough.svg +1 -0
- package/theme/icons/subscript.svg +1 -0
- package/theme/icons/superscript.svg +1 -0
- package/theme/icons/underline.svg +1 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# !!! IMPORTANT !!!
|
|
4
|
+
#
|
|
5
|
+
# Before you edit this file, please keep in mind that contributing to the project
|
|
6
|
+
# translations is possible ONLY via the Transifex online service.
|
|
7
|
+
#
|
|
8
|
+
# To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
|
|
9
|
+
#
|
|
10
|
+
# To learn more, check out the official contributor's guide:
|
|
11
|
+
# https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
|
|
12
|
+
#
|
|
13
|
+
msgid ""
|
|
14
|
+
msgstr ""
|
|
15
|
+
"Language-Team: Chinese (China) (https://www.transifex.com/ckeditor/teams/11143/zh_CN/)\n"
|
|
16
|
+
"Language: zh_CN\n"
|
|
17
|
+
"Plural-Forms: nplurals=1; plural=0;\n"
|
|
18
|
+
|
|
19
|
+
msgctxt "Toolbar button tooltip for the Bold feature."
|
|
20
|
+
msgid "Bold"
|
|
21
|
+
msgstr "加粗"
|
|
22
|
+
|
|
23
|
+
msgctxt "Toolbar button tooltip for the Italic feature."
|
|
24
|
+
msgid "Italic"
|
|
25
|
+
msgstr "倾斜"
|
|
26
|
+
|
|
27
|
+
msgctxt "Toolbar button tooltip for the Underline feature."
|
|
28
|
+
msgid "Underline"
|
|
29
|
+
msgstr "下划线"
|
|
30
|
+
|
|
31
|
+
msgctxt "Toolbar button tooltip for the Code feature."
|
|
32
|
+
msgid "Code"
|
|
33
|
+
msgstr "代码"
|
|
34
|
+
|
|
35
|
+
msgctxt "Toolbar button tooltip for the Strikethrough feature."
|
|
36
|
+
msgid "Strikethrough"
|
|
37
|
+
msgstr "删除线"
|
|
38
|
+
|
|
39
|
+
msgctxt "Toolbar button tooltip for the Subscript feature."
|
|
40
|
+
msgid "Subscript"
|
|
41
|
+
msgstr "下标"
|
|
42
|
+
|
|
43
|
+
msgctxt "Toolbar button tooltip for the Superscript feature."
|
|
44
|
+
msgid "Superscript"
|
|
45
|
+
msgstr "上标"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
2
|
+
#
|
|
3
|
+
# !!! IMPORTANT !!!
|
|
4
|
+
#
|
|
5
|
+
# Before you edit this file, please keep in mind that contributing to the project
|
|
6
|
+
# translations is possible ONLY via the Transifex online service.
|
|
7
|
+
#
|
|
8
|
+
# To submit your translations, visit https://www.transifex.com/ckeditor/ckeditor5.
|
|
9
|
+
#
|
|
10
|
+
# To learn more, check out the official contributor's guide:
|
|
11
|
+
# https://ckeditor.com/docs/ckeditor5/latest/framework/guides/contributing/contributing.html
|
|
12
|
+
#
|
|
13
|
+
msgid ""
|
|
14
|
+
msgstr ""
|
|
15
|
+
"Language-Team: Chinese (Taiwan) (https://www.transifex.com/ckeditor/teams/11143/zh_TW/)\n"
|
|
16
|
+
"Language: zh_TW\n"
|
|
17
|
+
"Plural-Forms: nplurals=1; plural=0;\n"
|
|
18
|
+
|
|
19
|
+
msgctxt "Toolbar button tooltip for the Bold feature."
|
|
20
|
+
msgid "Bold"
|
|
21
|
+
msgstr "粗體"
|
|
22
|
+
|
|
23
|
+
msgctxt "Toolbar button tooltip for the Italic feature."
|
|
24
|
+
msgid "Italic"
|
|
25
|
+
msgstr "斜體"
|
|
26
|
+
|
|
27
|
+
msgctxt "Toolbar button tooltip for the Underline feature."
|
|
28
|
+
msgid "Underline"
|
|
29
|
+
msgstr "底線"
|
|
30
|
+
|
|
31
|
+
msgctxt "Toolbar button tooltip for the Code feature."
|
|
32
|
+
msgid "Code"
|
|
33
|
+
msgstr "代碼"
|
|
34
|
+
|
|
35
|
+
msgctxt "Toolbar button tooltip for the Strikethrough feature."
|
|
36
|
+
msgid "Strikethrough"
|
|
37
|
+
msgstr "刪除線"
|
|
38
|
+
|
|
39
|
+
msgctxt "Toolbar button tooltip for the Subscript feature."
|
|
40
|
+
msgid "Subscript"
|
|
41
|
+
msgstr "下標"
|
|
42
|
+
|
|
43
|
+
msgctxt "Toolbar button tooltip for the Superscript feature."
|
|
44
|
+
msgid "Superscript"
|
|
45
|
+
msgstr "上標"
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ckeditor/ckeditor5-basic-styles",
|
|
3
|
+
"version": "30.0.0",
|
|
4
|
+
"description": "Basic styles feature for CKEditor 5.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ckeditor",
|
|
7
|
+
"ckeditor5",
|
|
8
|
+
"ckeditor 5",
|
|
9
|
+
"ckeditor5-feature",
|
|
10
|
+
"ckeditor5-plugin",
|
|
11
|
+
"ckeditor5-dll"
|
|
12
|
+
],
|
|
13
|
+
"main": "src/index.js",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"ckeditor5": "^30.0.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@ckeditor/ckeditor5-core": "^30.0.0",
|
|
19
|
+
"@ckeditor/ckeditor5-dev-utils": "^25.4.0",
|
|
20
|
+
"@ckeditor/ckeditor5-editor-classic": "^30.0.0",
|
|
21
|
+
"@ckeditor/ckeditor5-engine": "^30.0.0",
|
|
22
|
+
"@ckeditor/ckeditor5-essentials": "^30.0.0",
|
|
23
|
+
"@ckeditor/ckeditor5-paragraph": "^30.0.0",
|
|
24
|
+
"@ckeditor/ckeditor5-theme-lark": "^30.0.0",
|
|
25
|
+
"@ckeditor/ckeditor5-ui": "^30.0.0",
|
|
26
|
+
"@ckeditor/ckeditor5-utils": "^30.0.0",
|
|
27
|
+
"webpack": "^4.43.0",
|
|
28
|
+
"webpack-cli": "^3.3.11"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=12.0.0",
|
|
32
|
+
"npm": ">=5.7.1"
|
|
33
|
+
},
|
|
34
|
+
"author": "CKSource (http://cksource.com/)",
|
|
35
|
+
"license": "GPL-2.0-or-later",
|
|
36
|
+
"homepage": "https://ckeditor.com/ckeditor-5",
|
|
37
|
+
"bugs": "https://github.com/ckeditor/ckeditor5/issues",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/ckeditor/ckeditor5.git",
|
|
41
|
+
"directory": "packages/ckeditor5-basic-styles"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"lang",
|
|
45
|
+
"src",
|
|
46
|
+
"theme",
|
|
47
|
+
"build",
|
|
48
|
+
"ckeditor5-metadata.json"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"dll:build": "webpack"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/attributecommand
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Command } from 'ckeditor5/src/core';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An extension of the base {@link module:core/command~Command} class, which provides utilities for a command
|
|
14
|
+
* that toggles a single attribute on a text or an element.
|
|
15
|
+
*
|
|
16
|
+
* `AttributeCommand` uses {@link module:engine/model/document~Document#selection}
|
|
17
|
+
* to decide which nodes (if any) should be changed, and applies or removes the attribute from them.
|
|
18
|
+
*
|
|
19
|
+
* The command checks the {@link module:engine/model/model~Model#schema} to decide if it can be enabled
|
|
20
|
+
* for the current selection and to which nodes the attribute can be applied.
|
|
21
|
+
*
|
|
22
|
+
* @extends module:core/command~Command
|
|
23
|
+
*/
|
|
24
|
+
export default class AttributeCommand extends Command {
|
|
25
|
+
/**
|
|
26
|
+
* @param {module:core/editor/editor~Editor} editor
|
|
27
|
+
* @param {String} attributeKey Attribute that will be set by the command.
|
|
28
|
+
*/
|
|
29
|
+
constructor( editor, attributeKey ) {
|
|
30
|
+
super( editor );
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The attribute that will be set by the command.
|
|
34
|
+
*
|
|
35
|
+
* @readonly
|
|
36
|
+
* @member {String}
|
|
37
|
+
*/
|
|
38
|
+
this.attributeKey = attributeKey;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Flag indicating whether the command is active. The command is active when the
|
|
42
|
+
* {@link module:engine/model/selection~Selection#hasAttribute selection has the attribute} which means that:
|
|
43
|
+
*
|
|
44
|
+
* * If the selection is not empty – That the attribute is set on the first node in the selection that allows this attribute.
|
|
45
|
+
* * If the selection is empty – That the selection has the attribute itself (which means that newly typed
|
|
46
|
+
* text will have this attribute, too).
|
|
47
|
+
*
|
|
48
|
+
* @observable
|
|
49
|
+
* @readonly
|
|
50
|
+
* @member {Boolean} #value
|
|
51
|
+
*/
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Updates the command's {@link #value} and {@link #isEnabled} based on the current selection.
|
|
56
|
+
*/
|
|
57
|
+
refresh() {
|
|
58
|
+
const model = this.editor.model;
|
|
59
|
+
const doc = model.document;
|
|
60
|
+
|
|
61
|
+
this.value = this._getValueFromFirstAllowedNode();
|
|
62
|
+
this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, this.attributeKey );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Executes the command — applies the attribute to the selection or removes it from the selection.
|
|
67
|
+
*
|
|
68
|
+
* If the command is active (`value == true`), it will remove attributes. Otherwise, it will set attributes.
|
|
69
|
+
*
|
|
70
|
+
* The execution result differs, depending on the {@link module:engine/model/document~Document#selection}:
|
|
71
|
+
*
|
|
72
|
+
* * If the selection is on a range, the command applies the attribute to all nodes in that range
|
|
73
|
+
* (if they are allowed to have this attribute by the {@link module:engine/model/schema~Schema schema}).
|
|
74
|
+
* * If the selection is collapsed in a non-empty node, the command applies the attribute to the
|
|
75
|
+
* {@link module:engine/model/document~Document#selection} itself (note that typed characters copy attributes from the selection).
|
|
76
|
+
* * If the selection is collapsed in an empty node, the command applies the attribute to the parent node of the selection (note
|
|
77
|
+
* that the selection inherits all attributes from a node if it is in an empty node).
|
|
78
|
+
*
|
|
79
|
+
* @fires execute
|
|
80
|
+
* @param {Object} [options] Command options.
|
|
81
|
+
* @param {Boolean} [options.forceValue] If set, it will force the command behavior. If `true`, the command will apply the attribute,
|
|
82
|
+
* otherwise the command will remove the attribute.
|
|
83
|
+
* If not set, the command will look for its current value to decide what it should do.
|
|
84
|
+
*/
|
|
85
|
+
execute( options = {} ) {
|
|
86
|
+
const model = this.editor.model;
|
|
87
|
+
const doc = model.document;
|
|
88
|
+
const selection = doc.selection;
|
|
89
|
+
const value = ( options.forceValue === undefined ) ? !this.value : options.forceValue;
|
|
90
|
+
|
|
91
|
+
model.change( writer => {
|
|
92
|
+
if ( selection.isCollapsed ) {
|
|
93
|
+
if ( value ) {
|
|
94
|
+
writer.setSelectionAttribute( this.attributeKey, true );
|
|
95
|
+
} else {
|
|
96
|
+
writer.removeSelectionAttribute( this.attributeKey );
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
const ranges = model.schema.getValidRanges( selection.getRanges(), this.attributeKey );
|
|
100
|
+
|
|
101
|
+
for ( const range of ranges ) {
|
|
102
|
+
if ( value ) {
|
|
103
|
+
writer.setAttribute( this.attributeKey, value, range );
|
|
104
|
+
} else {
|
|
105
|
+
writer.removeAttribute( this.attributeKey, range );
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} );
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Checks the attribute value of the first node in the selection that allows the attribute.
|
|
114
|
+
* For the collapsed selection returns the selection attribute.
|
|
115
|
+
*
|
|
116
|
+
* @private
|
|
117
|
+
* @returns {Boolean} The attribute value.
|
|
118
|
+
*/
|
|
119
|
+
_getValueFromFirstAllowedNode() {
|
|
120
|
+
const model = this.editor.model;
|
|
121
|
+
const schema = model.schema;
|
|
122
|
+
const selection = model.document.selection;
|
|
123
|
+
|
|
124
|
+
if ( selection.isCollapsed ) {
|
|
125
|
+
return selection.hasAttribute( this.attributeKey );
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for ( const range of selection.getRanges() ) {
|
|
129
|
+
for ( const item of range.getItems() ) {
|
|
130
|
+
if ( schema.checkAttribute( item, this.attributeKey ) ) {
|
|
131
|
+
return item.hasAttribute( this.attributeKey );
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/bold/boldediting
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import AttributeCommand from '../attributecommand';
|
|
12
|
+
|
|
13
|
+
const BOLD = 'bold';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The bold editing feature.
|
|
17
|
+
*
|
|
18
|
+
* It registers the `'bold'` command and introduces the `bold` attribute in the model which renders to the view
|
|
19
|
+
* as a `<strong>` element.
|
|
20
|
+
*
|
|
21
|
+
* @extends module:core/plugin~Plugin
|
|
22
|
+
*/
|
|
23
|
+
export default class BoldEditing extends Plugin {
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
static get pluginName() {
|
|
28
|
+
return 'BoldEditing';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @inheritDoc
|
|
33
|
+
*/
|
|
34
|
+
init() {
|
|
35
|
+
const editor = this.editor;
|
|
36
|
+
// Allow bold attribute on text nodes.
|
|
37
|
+
editor.model.schema.extend( '$text', { allowAttributes: BOLD } );
|
|
38
|
+
editor.model.schema.setAttributeProperties( BOLD, {
|
|
39
|
+
isFormatting: true,
|
|
40
|
+
copyOnEnter: true
|
|
41
|
+
} );
|
|
42
|
+
|
|
43
|
+
// Build converter from model to view for data and editing pipelines.
|
|
44
|
+
editor.conversion.attributeToElement( {
|
|
45
|
+
model: BOLD,
|
|
46
|
+
view: 'strong',
|
|
47
|
+
upcastAlso: [
|
|
48
|
+
'b',
|
|
49
|
+
viewElement => {
|
|
50
|
+
const fontWeight = viewElement.getStyle( 'font-weight' );
|
|
51
|
+
|
|
52
|
+
if ( !fontWeight ) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Value of the `font-weight` attribute can be defined as a string or a number.
|
|
57
|
+
if ( fontWeight == 'bold' || Number( fontWeight ) >= 600 ) {
|
|
58
|
+
return {
|
|
59
|
+
name: true,
|
|
60
|
+
styles: [ 'font-weight' ]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
} );
|
|
66
|
+
|
|
67
|
+
// Create bold command.
|
|
68
|
+
editor.commands.add( BOLD, new AttributeCommand( editor, BOLD ) );
|
|
69
|
+
|
|
70
|
+
// Set the Ctrl+B keystroke.
|
|
71
|
+
editor.keystrokes.set( 'CTRL+B', BOLD );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/bold/boldui
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import { ButtonView } from 'ckeditor5/src/ui';
|
|
12
|
+
|
|
13
|
+
import boldIcon from '../../theme/icons/bold.svg';
|
|
14
|
+
|
|
15
|
+
const BOLD = 'bold';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The bold UI feature. It introduces the Bold button.
|
|
19
|
+
*
|
|
20
|
+
* @extends module:core/plugin~Plugin
|
|
21
|
+
*/
|
|
22
|
+
export default class BoldUI extends Plugin {
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
static get pluginName() {
|
|
27
|
+
return 'BoldUI';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
init() {
|
|
34
|
+
const editor = this.editor;
|
|
35
|
+
const t = editor.t;
|
|
36
|
+
|
|
37
|
+
// Add bold button to feature components.
|
|
38
|
+
editor.ui.componentFactory.add( BOLD, locale => {
|
|
39
|
+
const command = editor.commands.get( BOLD );
|
|
40
|
+
const view = new ButtonView( locale );
|
|
41
|
+
|
|
42
|
+
view.set( {
|
|
43
|
+
label: t( 'Bold' ),
|
|
44
|
+
icon: boldIcon,
|
|
45
|
+
keystroke: 'CTRL+B',
|
|
46
|
+
tooltip: true,
|
|
47
|
+
isToggleable: true
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
|
|
51
|
+
|
|
52
|
+
// Execute command.
|
|
53
|
+
this.listenTo( view, 'execute', () => {
|
|
54
|
+
editor.execute( BOLD );
|
|
55
|
+
editor.editing.view.focus();
|
|
56
|
+
} );
|
|
57
|
+
|
|
58
|
+
return view;
|
|
59
|
+
} );
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/bold.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/bold
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import BoldEditing from './bold/boldediting';
|
|
12
|
+
import BoldUI from './bold/boldui';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The bold feature.
|
|
16
|
+
*
|
|
17
|
+
* For a detailed overview check the {@glink features/basic-styles Basic styles feature documentation}
|
|
18
|
+
* and the {@glink api/basic-styles package page}.
|
|
19
|
+
*
|
|
20
|
+
* This is a "glue" plugin which loads the {@link module:basic-styles/bold/boldediting~BoldEditing bold editing feature}
|
|
21
|
+
* and {@link module:basic-styles/bold/boldui~BoldUI bold UI feature}.
|
|
22
|
+
*
|
|
23
|
+
* @extends module:core/plugin~Plugin
|
|
24
|
+
*/
|
|
25
|
+
export default class Bold extends Plugin {
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get requires() {
|
|
30
|
+
return [ BoldEditing, BoldUI ];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
static get pluginName() {
|
|
37
|
+
return 'Bold';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/code/codeediting
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import { TwoStepCaretMovement, inlineHighlight } from 'ckeditor5/src/typing';
|
|
12
|
+
|
|
13
|
+
import AttributeCommand from '../attributecommand';
|
|
14
|
+
|
|
15
|
+
const CODE = 'code';
|
|
16
|
+
const HIGHLIGHT_CLASS = 'ck-code_selected';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The code editing feature.
|
|
20
|
+
*
|
|
21
|
+
* It registers the `'code'` command and introduces the `code` attribute in the model which renders to the view
|
|
22
|
+
* as a `<code>` element.
|
|
23
|
+
*
|
|
24
|
+
* @extends module:core/plugin~Plugin
|
|
25
|
+
*/
|
|
26
|
+
export default class CodeEditing extends Plugin {
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
static get pluginName() {
|
|
31
|
+
return 'CodeEditing';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
static get requires() {
|
|
38
|
+
return [ TwoStepCaretMovement ];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @inheritDoc
|
|
43
|
+
*/
|
|
44
|
+
init() {
|
|
45
|
+
const editor = this.editor;
|
|
46
|
+
|
|
47
|
+
// Allow code attribute on text nodes.
|
|
48
|
+
editor.model.schema.extend( '$text', { allowAttributes: CODE } );
|
|
49
|
+
editor.model.schema.setAttributeProperties( CODE, {
|
|
50
|
+
isFormatting: true,
|
|
51
|
+
copyOnEnter: false
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
editor.conversion.attributeToElement( {
|
|
55
|
+
model: CODE,
|
|
56
|
+
view: 'code',
|
|
57
|
+
upcastAlso: {
|
|
58
|
+
styles: {
|
|
59
|
+
'word-wrap': 'break-word'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} );
|
|
63
|
+
|
|
64
|
+
// Create code command.
|
|
65
|
+
editor.commands.add( CODE, new AttributeCommand( editor, CODE ) );
|
|
66
|
+
|
|
67
|
+
// Enable two-step caret movement for `code` attribute.
|
|
68
|
+
editor.plugins.get( TwoStepCaretMovement ).registerAttribute( CODE );
|
|
69
|
+
|
|
70
|
+
// Setup highlight over selected element.
|
|
71
|
+
inlineHighlight( editor, CODE, 'code', HIGHLIGHT_CLASS );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/code/codeui
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import { ButtonView } from 'ckeditor5/src/ui';
|
|
12
|
+
|
|
13
|
+
import codeIcon from '../../theme/icons/code.svg';
|
|
14
|
+
|
|
15
|
+
import '../../theme/code.css';
|
|
16
|
+
|
|
17
|
+
const CODE = 'code';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The code UI feature. It introduces the Code button.
|
|
21
|
+
*
|
|
22
|
+
* @extends module:core/plugin~Plugin
|
|
23
|
+
*/
|
|
24
|
+
export default class CodeUI extends Plugin {
|
|
25
|
+
/**
|
|
26
|
+
* @inheritDoc
|
|
27
|
+
*/
|
|
28
|
+
static get pluginName() {
|
|
29
|
+
return 'CodeUI';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
init() {
|
|
36
|
+
const editor = this.editor;
|
|
37
|
+
const t = editor.t;
|
|
38
|
+
|
|
39
|
+
// Add code button to feature components.
|
|
40
|
+
editor.ui.componentFactory.add( CODE, locale => {
|
|
41
|
+
const command = editor.commands.get( CODE );
|
|
42
|
+
const view = new ButtonView( locale );
|
|
43
|
+
|
|
44
|
+
view.set( {
|
|
45
|
+
label: t( 'Code' ),
|
|
46
|
+
icon: codeIcon,
|
|
47
|
+
tooltip: true,
|
|
48
|
+
isToggleable: true
|
|
49
|
+
} );
|
|
50
|
+
|
|
51
|
+
view.bind( 'isOn', 'isEnabled' ).to( command, 'value', 'isEnabled' );
|
|
52
|
+
|
|
53
|
+
// Execute command.
|
|
54
|
+
this.listenTo( view, 'execute', () => {
|
|
55
|
+
editor.execute( CODE );
|
|
56
|
+
editor.editing.view.focus();
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
return view;
|
|
60
|
+
} );
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/code.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles/code
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
11
|
+
import CodeEditing from './code/codeediting';
|
|
12
|
+
import CodeUI from './code/codeui';
|
|
13
|
+
|
|
14
|
+
import '../theme/code.css';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The code feature.
|
|
18
|
+
*
|
|
19
|
+
* For a detailed overview check the {@glink features/basic-styles Basic styles feature documentation}
|
|
20
|
+
* and the {@glink api/basic-styles package page}.
|
|
21
|
+
*
|
|
22
|
+
* This is a "glue" plugin which loads the {@link module:basic-styles/code/codeediting~CodeEditing code editing feature}
|
|
23
|
+
* and {@link module:basic-styles/code/codeui~CodeUI code UI feature}.
|
|
24
|
+
*
|
|
25
|
+
* @extends module:core/plugin~Plugin
|
|
26
|
+
*/
|
|
27
|
+
export default class Code extends Plugin {
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
static get requires() {
|
|
32
|
+
return [ CodeEditing, CodeUI ];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @inheritDoc
|
|
37
|
+
*/
|
|
38
|
+
static get pluginName() {
|
|
39
|
+
return 'Code';
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @module basic-styles
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export { default as Bold } from './bold';
|
|
11
|
+
export { default as BoldEditing } from './bold/boldediting';
|
|
12
|
+
export { default as BoldUI } from './bold/boldui';
|
|
13
|
+
export { default as Code } from './code';
|
|
14
|
+
export { default as CodeEditing } from './code/codeediting';
|
|
15
|
+
export { default as CodeUI } from './code/codeui';
|
|
16
|
+
export { default as Italic } from './italic';
|
|
17
|
+
export { default as ItalicEditing } from './italic/italicediting';
|
|
18
|
+
export { default as ItalicUI } from './italic/italicui';
|
|
19
|
+
export { default as Strikethrough } from './strikethrough';
|
|
20
|
+
export { default as StrikethroughEditing } from './strikethrough/strikethroughediting';
|
|
21
|
+
export { default as StrikethroughUI } from './strikethrough/strikethroughui';
|
|
22
|
+
export { default as Subscript } from './subscript';
|
|
23
|
+
export { default as SubscriptEditing } from './subscript/subscriptediting';
|
|
24
|
+
export { default as SubscriptUI } from './subscript/subscriptui';
|
|
25
|
+
export { default as Superscript } from './superscript';
|
|
26
|
+
export { default as SuperscriptEditing } from './superscript/superscriptediting';
|
|
27
|
+
export { default as SuperscriptUI } from './superscript/superscriptui';
|
|
28
|
+
export { default as Underline } from './underline';
|
|
29
|
+
export { default as UnderlineEditing } from './underline/underlineediting';
|
|
30
|
+
export { default as UnderlineUI } from './underline/underlineui';
|