@ckeditor/ckeditor5-heading 39.0.2 → 40.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/build/heading.js.map +1 -0
- package/build/translations/hy.js +1 -0
- package/lang/translations/hy.po +62 -0
- package/package.json +2 -2
- package/src/augmentation.d.ts +30 -30
- package/src/augmentation.js +5 -5
- package/src/heading.d.ts +32 -32
- package/src/heading.js +36 -36
- package/src/headingbuttonsui.d.ts +51 -51
- package/src/headingbuttonsui.js +89 -89
- package/src/headingcommand.d.ts +48 -48
- package/src/headingcommand.js +65 -65
- package/src/headingconfig.d.ts +110 -110
- package/src/headingconfig.js +5 -5
- package/src/headingediting.d.ts +42 -42
- package/src/headingediting.js +101 -101
- package/src/headingui.d.ts +22 -22
- package/src/headingui.js +107 -107
- package/src/index.d.ts +16 -16
- package/src/index.js +13 -13
- package/src/title.d.ts +115 -115
- package/src/title.js +460 -460
- package/src/utils.d.ts +18 -18
- package/src/utils.js +31 -31
package/src/headingbuttonsui.js
CHANGED
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module heading/headingbuttonsui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { ButtonView } from 'ckeditor5/src/ui';
|
|
10
|
-
import { getLocalizedOptions } from './utils';
|
|
11
|
-
import iconHeading1 from '../theme/icons/heading1.svg';
|
|
12
|
-
import iconHeading2 from '../theme/icons/heading2.svg';
|
|
13
|
-
import iconHeading3 from '../theme/icons/heading3.svg';
|
|
14
|
-
import iconHeading4 from '../theme/icons/heading4.svg';
|
|
15
|
-
import iconHeading5 from '../theme/icons/heading5.svg';
|
|
16
|
-
import iconHeading6 from '../theme/icons/heading6.svg';
|
|
17
|
-
const defaultIcons = {
|
|
18
|
-
heading1: iconHeading1,
|
|
19
|
-
heading2: iconHeading2,
|
|
20
|
-
heading3: iconHeading3,
|
|
21
|
-
heading4: iconHeading4,
|
|
22
|
-
heading5: iconHeading5,
|
|
23
|
-
heading6: iconHeading6
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The `HeadingButtonsUI` plugin defines a set of UI buttons that can be used instead of the
|
|
27
|
-
* standard drop down component.
|
|
28
|
-
*
|
|
29
|
-
* This feature is not enabled by default by the {@link module:heading/heading~Heading} plugin and needs to be
|
|
30
|
-
* installed manually to the editor configuration.
|
|
31
|
-
*
|
|
32
|
-
* Plugin introduces button UI elements, which names are same as `model` property from {@link module:heading/headingconfig~HeadingOption}.
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* ClassicEditor
|
|
36
|
-
* .create( {
|
|
37
|
-
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
38
|
-
* heading: {
|
|
39
|
-
* options: [
|
|
40
|
-
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
41
|
-
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
42
|
-
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
43
|
-
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
44
|
-
* ]
|
|
45
|
-
* },
|
|
46
|
-
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
47
|
-
* } )
|
|
48
|
-
* .then( ... )
|
|
49
|
-
* .catch( ... );
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* NOTE: The `'paragraph'` button is defined in by the {@link module:paragraph/paragraphbuttonui~ParagraphButtonUI} plugin
|
|
53
|
-
* which needs to be loaded manually as well.
|
|
54
|
-
*
|
|
55
|
-
* It is possible to use custom icons by providing `icon` config option in {@link module:heading/headingconfig~HeadingOption}.
|
|
56
|
-
* For the default configuration standard icons are used.
|
|
57
|
-
*/
|
|
58
|
-
export default class HeadingButtonsUI extends Plugin {
|
|
59
|
-
/**
|
|
60
|
-
* @inheritDoc
|
|
61
|
-
*/
|
|
62
|
-
init() {
|
|
63
|
-
const options = getLocalizedOptions(this.editor);
|
|
64
|
-
options
|
|
65
|
-
.filter(item => item.model !== 'paragraph')
|
|
66
|
-
.map(item => this._createButton(item));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Creates single button view from provided configuration option.
|
|
70
|
-
*/
|
|
71
|
-
_createButton(option) {
|
|
72
|
-
const editor = this.editor;
|
|
73
|
-
editor.ui.componentFactory.add(option.model, locale => {
|
|
74
|
-
const view = new ButtonView(locale);
|
|
75
|
-
const command = editor.commands.get('heading');
|
|
76
|
-
view.label = option.title;
|
|
77
|
-
view.icon = option.icon || defaultIcons[option.model];
|
|
78
|
-
view.tooltip = true;
|
|
79
|
-
view.isToggleable = true;
|
|
80
|
-
view.bind('isEnabled').to(command);
|
|
81
|
-
view.bind('isOn').to(command, 'value', value => value == option.model);
|
|
82
|
-
view.on('execute', () => {
|
|
83
|
-
editor.execute('heading', { value: option.model });
|
|
84
|
-
editor.editing.view.focus();
|
|
85
|
-
});
|
|
86
|
-
return view;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module heading/headingbuttonsui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { ButtonView } from 'ckeditor5/src/ui';
|
|
10
|
+
import { getLocalizedOptions } from './utils';
|
|
11
|
+
import iconHeading1 from '../theme/icons/heading1.svg';
|
|
12
|
+
import iconHeading2 from '../theme/icons/heading2.svg';
|
|
13
|
+
import iconHeading3 from '../theme/icons/heading3.svg';
|
|
14
|
+
import iconHeading4 from '../theme/icons/heading4.svg';
|
|
15
|
+
import iconHeading5 from '../theme/icons/heading5.svg';
|
|
16
|
+
import iconHeading6 from '../theme/icons/heading6.svg';
|
|
17
|
+
const defaultIcons = {
|
|
18
|
+
heading1: iconHeading1,
|
|
19
|
+
heading2: iconHeading2,
|
|
20
|
+
heading3: iconHeading3,
|
|
21
|
+
heading4: iconHeading4,
|
|
22
|
+
heading5: iconHeading5,
|
|
23
|
+
heading6: iconHeading6
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The `HeadingButtonsUI` plugin defines a set of UI buttons that can be used instead of the
|
|
27
|
+
* standard drop down component.
|
|
28
|
+
*
|
|
29
|
+
* This feature is not enabled by default by the {@link module:heading/heading~Heading} plugin and needs to be
|
|
30
|
+
* installed manually to the editor configuration.
|
|
31
|
+
*
|
|
32
|
+
* Plugin introduces button UI elements, which names are same as `model` property from {@link module:heading/headingconfig~HeadingOption}.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* ClassicEditor
|
|
36
|
+
* .create( {
|
|
37
|
+
* plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
|
|
38
|
+
* heading: {
|
|
39
|
+
* options: [
|
|
40
|
+
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
41
|
+
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
42
|
+
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
43
|
+
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
44
|
+
* ]
|
|
45
|
+
* },
|
|
46
|
+
* toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
|
|
47
|
+
* } )
|
|
48
|
+
* .then( ... )
|
|
49
|
+
* .catch( ... );
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* NOTE: The `'paragraph'` button is defined in by the {@link module:paragraph/paragraphbuttonui~ParagraphButtonUI} plugin
|
|
53
|
+
* which needs to be loaded manually as well.
|
|
54
|
+
*
|
|
55
|
+
* It is possible to use custom icons by providing `icon` config option in {@link module:heading/headingconfig~HeadingOption}.
|
|
56
|
+
* For the default configuration standard icons are used.
|
|
57
|
+
*/
|
|
58
|
+
export default class HeadingButtonsUI extends Plugin {
|
|
59
|
+
/**
|
|
60
|
+
* @inheritDoc
|
|
61
|
+
*/
|
|
62
|
+
init() {
|
|
63
|
+
const options = getLocalizedOptions(this.editor);
|
|
64
|
+
options
|
|
65
|
+
.filter(item => item.model !== 'paragraph')
|
|
66
|
+
.map(item => this._createButton(item));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates single button view from provided configuration option.
|
|
70
|
+
*/
|
|
71
|
+
_createButton(option) {
|
|
72
|
+
const editor = this.editor;
|
|
73
|
+
editor.ui.componentFactory.add(option.model, locale => {
|
|
74
|
+
const view = new ButtonView(locale);
|
|
75
|
+
const command = editor.commands.get('heading');
|
|
76
|
+
view.label = option.title;
|
|
77
|
+
view.icon = option.icon || defaultIcons[option.model];
|
|
78
|
+
view.tooltip = true;
|
|
79
|
+
view.isToggleable = true;
|
|
80
|
+
view.bind('isEnabled').to(command);
|
|
81
|
+
view.bind('isOn').to(command, 'value', value => value == option.model);
|
|
82
|
+
view.on('execute', () => {
|
|
83
|
+
editor.execute('heading', { value: option.model });
|
|
84
|
+
editor.editing.view.focus();
|
|
85
|
+
});
|
|
86
|
+
return view;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/headingcommand.d.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module heading/headingcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command, type Editor } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
|
|
11
|
-
*/
|
|
12
|
-
export default class HeadingCommand extends Command {
|
|
13
|
-
/**
|
|
14
|
-
* If the selection starts in a heading (which {@link #modelElements is supported by this command})
|
|
15
|
-
* the value is set to the name of that heading model element.
|
|
16
|
-
* It is set to `false` otherwise.
|
|
17
|
-
*
|
|
18
|
-
* @observable
|
|
19
|
-
* @readonly
|
|
20
|
-
*/
|
|
21
|
-
value: false | string;
|
|
22
|
-
/**
|
|
23
|
-
* Set of defined model's elements names that this command support.
|
|
24
|
-
* See {@link module:heading/headingconfig~HeadingOption}.
|
|
25
|
-
*/
|
|
26
|
-
readonly modelElements: Array<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Creates an instance of the command.
|
|
29
|
-
*
|
|
30
|
-
* @param editor Editor instance.
|
|
31
|
-
* @param modelElements Names of the element which this command can apply in the model.
|
|
32
|
-
*/
|
|
33
|
-
constructor(editor: Editor, modelElements: Array<string>);
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
refresh(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Executes the command. Applies the heading to the selected blocks or, if the first selected
|
|
40
|
-
* block is a heading already, turns selected headings (of this level only) to paragraphs.
|
|
41
|
-
*
|
|
42
|
-
* @param options.value Name of the element which this command will apply in the model.
|
|
43
|
-
* @fires execute
|
|
44
|
-
*/
|
|
45
|
-
execute(options: {
|
|
46
|
-
value: string;
|
|
47
|
-
}): void;
|
|
48
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module heading/headingcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command, type Editor } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
|
|
11
|
+
*/
|
|
12
|
+
export default class HeadingCommand extends Command {
|
|
13
|
+
/**
|
|
14
|
+
* If the selection starts in a heading (which {@link #modelElements is supported by this command})
|
|
15
|
+
* the value is set to the name of that heading model element.
|
|
16
|
+
* It is set to `false` otherwise.
|
|
17
|
+
*
|
|
18
|
+
* @observable
|
|
19
|
+
* @readonly
|
|
20
|
+
*/
|
|
21
|
+
value: false | string;
|
|
22
|
+
/**
|
|
23
|
+
* Set of defined model's elements names that this command support.
|
|
24
|
+
* See {@link module:heading/headingconfig~HeadingOption}.
|
|
25
|
+
*/
|
|
26
|
+
readonly modelElements: Array<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of the command.
|
|
29
|
+
*
|
|
30
|
+
* @param editor Editor instance.
|
|
31
|
+
* @param modelElements Names of the element which this command can apply in the model.
|
|
32
|
+
*/
|
|
33
|
+
constructor(editor: Editor, modelElements: Array<string>);
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
refresh(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Executes the command. Applies the heading to the selected blocks or, if the first selected
|
|
40
|
+
* block is a heading already, turns selected headings (of this level only) to paragraphs.
|
|
41
|
+
*
|
|
42
|
+
* @param options.value Name of the element which this command will apply in the model.
|
|
43
|
+
* @fires execute
|
|
44
|
+
*/
|
|
45
|
+
execute(options: {
|
|
46
|
+
value: string;
|
|
47
|
+
}): void;
|
|
48
|
+
}
|
package/src/headingcommand.js
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module heading/headingcommand
|
|
7
|
-
*/
|
|
8
|
-
import { Command } from 'ckeditor5/src/core';
|
|
9
|
-
import { first } from 'ckeditor5/src/utils';
|
|
10
|
-
/**
|
|
11
|
-
* The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
|
|
12
|
-
*/
|
|
13
|
-
export default class HeadingCommand extends Command {
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of the command.
|
|
16
|
-
*
|
|
17
|
-
* @param editor Editor instance.
|
|
18
|
-
* @param modelElements Names of the element which this command can apply in the model.
|
|
19
|
-
*/
|
|
20
|
-
constructor(editor, modelElements) {
|
|
21
|
-
super(editor);
|
|
22
|
-
this.modelElements = modelElements;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
refresh() {
|
|
28
|
-
const block = first(this.editor.model.document.selection.getSelectedBlocks());
|
|
29
|
-
this.value = !!block && this.modelElements.includes(block.name) && block.name;
|
|
30
|
-
this.isEnabled = !!block && this.modelElements.some(heading => checkCanBecomeHeading(block, heading, this.editor.model.schema));
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Executes the command. Applies the heading to the selected blocks or, if the first selected
|
|
34
|
-
* block is a heading already, turns selected headings (of this level only) to paragraphs.
|
|
35
|
-
*
|
|
36
|
-
* @param options.value Name of the element which this command will apply in the model.
|
|
37
|
-
* @fires execute
|
|
38
|
-
*/
|
|
39
|
-
execute(options) {
|
|
40
|
-
const model = this.editor.model;
|
|
41
|
-
const document = model.document;
|
|
42
|
-
const modelElement = options.value;
|
|
43
|
-
model.change(writer => {
|
|
44
|
-
const blocks = Array.from(document.selection.getSelectedBlocks())
|
|
45
|
-
.filter(block => {
|
|
46
|
-
return checkCanBecomeHeading(block, modelElement, model.schema);
|
|
47
|
-
});
|
|
48
|
-
for (const block of blocks) {
|
|
49
|
-
if (!block.is('element', modelElement)) {
|
|
50
|
-
writer.rename(block, modelElement);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Checks whether the given block can be replaced by a specific heading.
|
|
58
|
-
*
|
|
59
|
-
* @param block A block to be tested.
|
|
60
|
-
* @param heading Command element name in the model.
|
|
61
|
-
* @param schema The schema of the document.
|
|
62
|
-
*/
|
|
63
|
-
function checkCanBecomeHeading(block, heading, schema) {
|
|
64
|
-
return schema.checkChild(block.parent, heading) && !schema.isObject(block);
|
|
65
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module heading/headingcommand
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'ckeditor5/src/core';
|
|
9
|
+
import { first } from 'ckeditor5/src/utils';
|
|
10
|
+
/**
|
|
11
|
+
* The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
|
|
12
|
+
*/
|
|
13
|
+
export default class HeadingCommand extends Command {
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of the command.
|
|
16
|
+
*
|
|
17
|
+
* @param editor Editor instance.
|
|
18
|
+
* @param modelElements Names of the element which this command can apply in the model.
|
|
19
|
+
*/
|
|
20
|
+
constructor(editor, modelElements) {
|
|
21
|
+
super(editor);
|
|
22
|
+
this.modelElements = modelElements;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
refresh() {
|
|
28
|
+
const block = first(this.editor.model.document.selection.getSelectedBlocks());
|
|
29
|
+
this.value = !!block && this.modelElements.includes(block.name) && block.name;
|
|
30
|
+
this.isEnabled = !!block && this.modelElements.some(heading => checkCanBecomeHeading(block, heading, this.editor.model.schema));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the command. Applies the heading to the selected blocks or, if the first selected
|
|
34
|
+
* block is a heading already, turns selected headings (of this level only) to paragraphs.
|
|
35
|
+
*
|
|
36
|
+
* @param options.value Name of the element which this command will apply in the model.
|
|
37
|
+
* @fires execute
|
|
38
|
+
*/
|
|
39
|
+
execute(options) {
|
|
40
|
+
const model = this.editor.model;
|
|
41
|
+
const document = model.document;
|
|
42
|
+
const modelElement = options.value;
|
|
43
|
+
model.change(writer => {
|
|
44
|
+
const blocks = Array.from(document.selection.getSelectedBlocks())
|
|
45
|
+
.filter(block => {
|
|
46
|
+
return checkCanBecomeHeading(block, modelElement, model.schema);
|
|
47
|
+
});
|
|
48
|
+
for (const block of blocks) {
|
|
49
|
+
if (!block.is('element', modelElement)) {
|
|
50
|
+
writer.rename(block, modelElement);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks whether the given block can be replaced by a specific heading.
|
|
58
|
+
*
|
|
59
|
+
* @param block A block to be tested.
|
|
60
|
+
* @param heading Command element name in the model.
|
|
61
|
+
* @param schema The schema of the document.
|
|
62
|
+
*/
|
|
63
|
+
function checkCanBecomeHeading(block, heading, schema) {
|
|
64
|
+
return schema.checkChild(block.parent, heading) && !schema.isObject(block);
|
|
65
|
+
}
|
package/src/headingconfig.d.ts
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module heading/headingconfig
|
|
7
|
-
*/
|
|
8
|
-
import type { ViewElementDefinition } from 'ckeditor5/src/engine';
|
|
9
|
-
/**
|
|
10
|
-
* The configuration of the heading feature.
|
|
11
|
-
* The option is used by the {@link module:heading/headingediting~HeadingEditing} feature.
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* ClassicEditor
|
|
15
|
-
* .create( {
|
|
16
|
-
* heading: ... // Heading feature config.
|
|
17
|
-
* } )
|
|
18
|
-
* .then( ... )
|
|
19
|
-
* .catch( ... );
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
23
|
-
*/
|
|
24
|
-
export interface HeadingConfig {
|
|
25
|
-
/**
|
|
26
|
-
* The available heading options.
|
|
27
|
-
*
|
|
28
|
-
* The default value is:
|
|
29
|
-
* ```ts
|
|
30
|
-
* const headingConfig = {
|
|
31
|
-
* options: [
|
|
32
|
-
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
-
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
-
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
-
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
-
* ]
|
|
37
|
-
* };
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* It defines 3 levels of headings. In the editor model they will use `heading1`, `heading2`, and `heading3` elements.
|
|
41
|
-
* Their respective view elements (so the elements output by the editor) will be: `h2`, `h3`, and `h4`. This means that
|
|
42
|
-
* if you choose "Heading 1" in the headings dropdown the editor will turn the current block to `<heading1>` in the model
|
|
43
|
-
* which will result in rendering (and outputting to data) the `<h2>` element.
|
|
44
|
-
*
|
|
45
|
-
* The `title` and `class` properties will be used by the `headings` dropdown to render available options.
|
|
46
|
-
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
|
|
47
|
-
* However, you don't need to define its view representation because it's handled by
|
|
48
|
-
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
|
|
49
|
-
* the {@link module:heading/headingediting~HeadingEditing} feature).
|
|
50
|
-
*
|
|
51
|
-
* You can **read more** about configuring heading levels and **see more examples** in
|
|
52
|
-
* the {@glink features/headings Headings} guide.
|
|
53
|
-
*
|
|
54
|
-
* Note: In the model you should always start from `heading1`, regardless of how the headings are represented in the view.
|
|
55
|
-
* That's assumption is used by features like {@link module:autoformat/autoformat~Autoformat} to know which element
|
|
56
|
-
* they should use when applying the first level heading.
|
|
57
|
-
*
|
|
58
|
-
* The defined headings are also available as values passed to the `'heading'` command under their model names.
|
|
59
|
-
* For example, the below code will apply `<heading1>` to the current selection:
|
|
60
|
-
*
|
|
61
|
-
* ```ts
|
|
62
|
-
* editor.execute( 'heading', { value: 'heading1' } );
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
options?: Array<HeadingOption>;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Heading option descriptor.
|
|
69
|
-
*/
|
|
70
|
-
export type HeadingOption = HeadingElementOption | HeadingParagraphOption;
|
|
71
|
-
export interface HeadingElementOption {
|
|
72
|
-
/**
|
|
73
|
-
* Name of the model element to convert.
|
|
74
|
-
*/
|
|
75
|
-
model: 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
|
|
76
|
-
/**
|
|
77
|
-
* Definition of a view element to convert from/to.
|
|
78
|
-
*/
|
|
79
|
-
view: ViewElementDefinition;
|
|
80
|
-
/**
|
|
81
|
-
* The user-readable title of the option.
|
|
82
|
-
*/
|
|
83
|
-
title: string;
|
|
84
|
-
/**
|
|
85
|
-
* The class which will be added to the dropdown item representing this option.
|
|
86
|
-
*/
|
|
87
|
-
class: string;
|
|
88
|
-
/**
|
|
89
|
-
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
90
|
-
*/
|
|
91
|
-
icon?: string;
|
|
92
|
-
}
|
|
93
|
-
export interface HeadingParagraphOption {
|
|
94
|
-
/**
|
|
95
|
-
* Name of the model element to convert.
|
|
96
|
-
*/
|
|
97
|
-
model: 'paragraph';
|
|
98
|
-
/**
|
|
99
|
-
* The user-readable title of the option.
|
|
100
|
-
*/
|
|
101
|
-
title: string;
|
|
102
|
-
/**
|
|
103
|
-
* The class which will be added to the dropdown item representing this option.
|
|
104
|
-
* */
|
|
105
|
-
class: string;
|
|
106
|
-
/**
|
|
107
|
-
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
108
|
-
*/
|
|
109
|
-
icon?: string;
|
|
110
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module heading/headingconfig
|
|
7
|
+
*/
|
|
8
|
+
import type { ViewElementDefinition } from 'ckeditor5/src/engine';
|
|
9
|
+
/**
|
|
10
|
+
* The configuration of the heading feature.
|
|
11
|
+
* The option is used by the {@link module:heading/headingediting~HeadingEditing} feature.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* ClassicEditor
|
|
15
|
+
* .create( {
|
|
16
|
+
* heading: ... // Heading feature config.
|
|
17
|
+
* } )
|
|
18
|
+
* .then( ... )
|
|
19
|
+
* .catch( ... );
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
23
|
+
*/
|
|
24
|
+
export interface HeadingConfig {
|
|
25
|
+
/**
|
|
26
|
+
* The available heading options.
|
|
27
|
+
*
|
|
28
|
+
* The default value is:
|
|
29
|
+
* ```ts
|
|
30
|
+
* const headingConfig = {
|
|
31
|
+
* options: [
|
|
32
|
+
* { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
|
33
|
+
* { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
|
|
34
|
+
* { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
|
|
35
|
+
* { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
|
|
36
|
+
* ]
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* It defines 3 levels of headings. In the editor model they will use `heading1`, `heading2`, and `heading3` elements.
|
|
41
|
+
* Their respective view elements (so the elements output by the editor) will be: `h2`, `h3`, and `h4`. This means that
|
|
42
|
+
* if you choose "Heading 1" in the headings dropdown the editor will turn the current block to `<heading1>` in the model
|
|
43
|
+
* which will result in rendering (and outputting to data) the `<h2>` element.
|
|
44
|
+
*
|
|
45
|
+
* The `title` and `class` properties will be used by the `headings` dropdown to render available options.
|
|
46
|
+
* Usually, the first option in the headings dropdown is the "Paragraph" option, hence it's also defined on the list.
|
|
47
|
+
* However, you don't need to define its view representation because it's handled by
|
|
48
|
+
* the {@link module:paragraph/paragraph~Paragraph} feature (which is required by
|
|
49
|
+
* the {@link module:heading/headingediting~HeadingEditing} feature).
|
|
50
|
+
*
|
|
51
|
+
* You can **read more** about configuring heading levels and **see more examples** in
|
|
52
|
+
* the {@glink features/headings Headings} guide.
|
|
53
|
+
*
|
|
54
|
+
* Note: In the model you should always start from `heading1`, regardless of how the headings are represented in the view.
|
|
55
|
+
* That's assumption is used by features like {@link module:autoformat/autoformat~Autoformat} to know which element
|
|
56
|
+
* they should use when applying the first level heading.
|
|
57
|
+
*
|
|
58
|
+
* The defined headings are also available as values passed to the `'heading'` command under their model names.
|
|
59
|
+
* For example, the below code will apply `<heading1>` to the current selection:
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* editor.execute( 'heading', { value: 'heading1' } );
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
options?: Array<HeadingOption>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Heading option descriptor.
|
|
69
|
+
*/
|
|
70
|
+
export type HeadingOption = HeadingElementOption | HeadingParagraphOption;
|
|
71
|
+
export interface HeadingElementOption {
|
|
72
|
+
/**
|
|
73
|
+
* Name of the model element to convert.
|
|
74
|
+
*/
|
|
75
|
+
model: 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
|
|
76
|
+
/**
|
|
77
|
+
* Definition of a view element to convert from/to.
|
|
78
|
+
*/
|
|
79
|
+
view: ViewElementDefinition;
|
|
80
|
+
/**
|
|
81
|
+
* The user-readable title of the option.
|
|
82
|
+
*/
|
|
83
|
+
title: string;
|
|
84
|
+
/**
|
|
85
|
+
* The class which will be added to the dropdown item representing this option.
|
|
86
|
+
*/
|
|
87
|
+
class: string;
|
|
88
|
+
/**
|
|
89
|
+
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
90
|
+
*/
|
|
91
|
+
icon?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface HeadingParagraphOption {
|
|
94
|
+
/**
|
|
95
|
+
* Name of the model element to convert.
|
|
96
|
+
*/
|
|
97
|
+
model: 'paragraph';
|
|
98
|
+
/**
|
|
99
|
+
* The user-readable title of the option.
|
|
100
|
+
*/
|
|
101
|
+
title: string;
|
|
102
|
+
/**
|
|
103
|
+
* The class which will be added to the dropdown item representing this option.
|
|
104
|
+
* */
|
|
105
|
+
class: string;
|
|
106
|
+
/**
|
|
107
|
+
* Icon used by {@link module:heading/headingbuttonsui~HeadingButtonsUI}. It can be omitted when using the default configuration.
|
|
108
|
+
*/
|
|
109
|
+
icon?: string;
|
|
110
|
+
}
|
package/src/headingconfig.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
export {};
|