@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.
@@ -1,42 +1,42 @@
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/headingediting
7
- */
8
- import { Plugin, type Editor } from 'ckeditor5/src/core';
9
- import { Paragraph } from 'ckeditor5/src/paragraph';
10
- /**
11
- * The headings engine feature. It handles switching between block formats – headings and paragraph.
12
- * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
13
- * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
14
- */
15
- export default class HeadingEditing extends Plugin {
16
- /**
17
- * @inheritDoc
18
- */
19
- static get pluginName(): "HeadingEditing";
20
- /**
21
- * @inheritDoc
22
- */
23
- constructor(editor: Editor);
24
- /**
25
- * @inheritDoc
26
- */
27
- static get requires(): readonly [typeof Paragraph];
28
- /**
29
- * @inheritDoc
30
- */
31
- init(): void;
32
- /**
33
- * @inheritDoc
34
- */
35
- afterInit(): void;
36
- /**
37
- * Adds default conversion for `h1` -> `heading1` with a low priority.
38
- *
39
- * @param editor Editor instance on which to add the `h1` conversion.
40
- */
41
- private _addDefaultH1Conversion;
42
- }
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/headingediting
7
+ */
8
+ import { Plugin, type Editor } from 'ckeditor5/src/core';
9
+ import { Paragraph } from 'ckeditor5/src/paragraph';
10
+ /**
11
+ * The headings engine feature. It handles switching between block formats – headings and paragraph.
12
+ * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
13
+ * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
14
+ */
15
+ export default class HeadingEditing extends Plugin {
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static get pluginName(): "HeadingEditing";
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ constructor(editor: Editor);
24
+ /**
25
+ * @inheritDoc
26
+ */
27
+ static get requires(): readonly [typeof Paragraph];
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ init(): void;
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ afterInit(): void;
36
+ /**
37
+ * Adds default conversion for `h1` -> `heading1` with a low priority.
38
+ *
39
+ * @param editor Editor instance on which to add the `h1` conversion.
40
+ */
41
+ private _addDefaultH1Conversion;
42
+ }
@@ -1,101 +1,101 @@
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/headingediting
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Paragraph } from 'ckeditor5/src/paragraph';
10
- import { priorities } from 'ckeditor5/src/utils';
11
- import HeadingCommand from './headingcommand';
12
- const defaultModelElement = 'paragraph';
13
- /**
14
- * The headings engine feature. It handles switching between block formats – headings and paragraph.
15
- * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
16
- * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
17
- */
18
- export default class HeadingEditing extends Plugin {
19
- /**
20
- * @inheritDoc
21
- */
22
- static get pluginName() {
23
- return 'HeadingEditing';
24
- }
25
- /**
26
- * @inheritDoc
27
- */
28
- constructor(editor) {
29
- super(editor);
30
- editor.config.define('heading', {
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
- * @inheritDoc
41
- */
42
- static get requires() {
43
- return [Paragraph];
44
- }
45
- /**
46
- * @inheritDoc
47
- */
48
- init() {
49
- const editor = this.editor;
50
- const options = editor.config.get('heading.options');
51
- const modelElements = [];
52
- for (const option of options) {
53
- // Skip paragraph - it is defined in required Paragraph feature.
54
- if (option.model === 'paragraph') {
55
- continue;
56
- }
57
- // Schema.
58
- editor.model.schema.register(option.model, {
59
- inheritAllFrom: '$block'
60
- });
61
- editor.conversion.elementToElement(option);
62
- modelElements.push(option.model);
63
- }
64
- this._addDefaultH1Conversion(editor);
65
- // Register the heading command for this option.
66
- editor.commands.add('heading', new HeadingCommand(editor, modelElements));
67
- }
68
- /**
69
- * @inheritDoc
70
- */
71
- afterInit() {
72
- // If the enter command is added to the editor, alter its behavior.
73
- // Enter at the end of a heading element should create a paragraph.
74
- const editor = this.editor;
75
- const enterCommand = editor.commands.get('enter');
76
- const options = editor.config.get('heading.options');
77
- if (enterCommand) {
78
- this.listenTo(enterCommand, 'afterExecute', (evt, data) => {
79
- const positionParent = editor.model.document.selection.getFirstPosition().parent;
80
- const isHeading = options.some(option => positionParent.is('element', option.model));
81
- if (isHeading && !positionParent.is('element', defaultModelElement) && positionParent.childCount === 0) {
82
- data.writer.rename(positionParent, defaultModelElement);
83
- }
84
- });
85
- }
86
- }
87
- /**
88
- * Adds default conversion for `h1` -> `heading1` with a low priority.
89
- *
90
- * @param editor Editor instance on which to add the `h1` conversion.
91
- */
92
- _addDefaultH1Conversion(editor) {
93
- editor.conversion.for('upcast').elementToElement({
94
- model: 'heading1',
95
- view: 'h1',
96
- // With a `low` priority, `paragraph` plugin autoparagraphing mechanism is executed. Make sure
97
- // this listener is called before it. If not, `h1` will be transformed into a paragraph.
98
- converterPriority: priorities.low + 1
99
- });
100
- }
101
- }
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/headingediting
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { Paragraph } from 'ckeditor5/src/paragraph';
10
+ import { priorities } from 'ckeditor5/src/utils';
11
+ import HeadingCommand from './headingcommand';
12
+ const defaultModelElement = 'paragraph';
13
+ /**
14
+ * The headings engine feature. It handles switching between block formats – headings and paragraph.
15
+ * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
16
+ * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
17
+ */
18
+ export default class HeadingEditing extends Plugin {
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ static get pluginName() {
23
+ return 'HeadingEditing';
24
+ }
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ constructor(editor) {
29
+ super(editor);
30
+ editor.config.define('heading', {
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
+ * @inheritDoc
41
+ */
42
+ static get requires() {
43
+ return [Paragraph];
44
+ }
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ init() {
49
+ const editor = this.editor;
50
+ const options = editor.config.get('heading.options');
51
+ const modelElements = [];
52
+ for (const option of options) {
53
+ // Skip paragraph - it is defined in required Paragraph feature.
54
+ if (option.model === 'paragraph') {
55
+ continue;
56
+ }
57
+ // Schema.
58
+ editor.model.schema.register(option.model, {
59
+ inheritAllFrom: '$block'
60
+ });
61
+ editor.conversion.elementToElement(option);
62
+ modelElements.push(option.model);
63
+ }
64
+ this._addDefaultH1Conversion(editor);
65
+ // Register the heading command for this option.
66
+ editor.commands.add('heading', new HeadingCommand(editor, modelElements));
67
+ }
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ afterInit() {
72
+ // If the enter command is added to the editor, alter its behavior.
73
+ // Enter at the end of a heading element should create a paragraph.
74
+ const editor = this.editor;
75
+ const enterCommand = editor.commands.get('enter');
76
+ const options = editor.config.get('heading.options');
77
+ if (enterCommand) {
78
+ this.listenTo(enterCommand, 'afterExecute', (evt, data) => {
79
+ const positionParent = editor.model.document.selection.getFirstPosition().parent;
80
+ const isHeading = options.some(option => positionParent.is('element', option.model));
81
+ if (isHeading && !positionParent.is('element', defaultModelElement) && positionParent.childCount === 0) {
82
+ data.writer.rename(positionParent, defaultModelElement);
83
+ }
84
+ });
85
+ }
86
+ }
87
+ /**
88
+ * Adds default conversion for `h1` -> `heading1` with a low priority.
89
+ *
90
+ * @param editor Editor instance on which to add the `h1` conversion.
91
+ */
92
+ _addDefaultH1Conversion(editor) {
93
+ editor.conversion.for('upcast').elementToElement({
94
+ model: 'heading1',
95
+ view: 'h1',
96
+ // With a `low` priority, `paragraph` plugin autoparagraphing mechanism is executed. Make sure
97
+ // this listener is called before it. If not, `h1` will be transformed into a paragraph.
98
+ converterPriority: priorities.low + 1
99
+ });
100
+ }
101
+ }
@@ -1,22 +1,22 @@
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/headingui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import '../theme/heading.css';
10
- /**
11
- * The headings UI feature. It introduces the `headings` dropdown.
12
- */
13
- export default class HeadingUI extends Plugin {
14
- /**
15
- * @inheritDoc
16
- */
17
- static get pluginName(): "HeadingUI";
18
- /**
19
- * @inheritDoc
20
- */
21
- init(): void;
22
- }
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/headingui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import '../theme/heading.css';
10
+ /**
11
+ * The headings UI feature. It introduces the `headings` dropdown.
12
+ */
13
+ export default class HeadingUI extends Plugin {
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ static get pluginName(): "HeadingUI";
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ init(): void;
22
+ }
package/src/headingui.js CHANGED
@@ -1,107 +1,107 @@
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/headingui
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
10
- import { Collection } from 'ckeditor5/src/utils';
11
- import { getLocalizedOptions } from './utils';
12
- import '../theme/heading.css';
13
- /**
14
- * The headings UI feature. It introduces the `headings` dropdown.
15
- */
16
- export default class HeadingUI extends Plugin {
17
- /**
18
- * @inheritDoc
19
- */
20
- static get pluginName() {
21
- return 'HeadingUI';
22
- }
23
- /**
24
- * @inheritDoc
25
- */
26
- init() {
27
- const editor = this.editor;
28
- const t = editor.t;
29
- const options = getLocalizedOptions(editor);
30
- const defaultTitle = t('Choose heading');
31
- const accessibleLabel = t('Heading');
32
- // Register UI component.
33
- editor.ui.componentFactory.add('heading', locale => {
34
- const titles = {};
35
- const itemDefinitions = new Collection();
36
- const headingCommand = editor.commands.get('heading');
37
- const paragraphCommand = editor.commands.get('paragraph');
38
- const commands = [headingCommand];
39
- for (const option of options) {
40
- const def = {
41
- type: 'button',
42
- model: new Model({
43
- label: option.title,
44
- class: option.class,
45
- role: 'menuitemradio',
46
- withText: true
47
- })
48
- };
49
- if (option.model === 'paragraph') {
50
- def.model.bind('isOn').to(paragraphCommand, 'value');
51
- def.model.set('commandName', 'paragraph');
52
- commands.push(paragraphCommand);
53
- }
54
- else {
55
- def.model.bind('isOn').to(headingCommand, 'value', value => value === option.model);
56
- def.model.set({
57
- commandName: 'heading',
58
- commandValue: option.model
59
- });
60
- }
61
- // Add the option to the collection.
62
- itemDefinitions.add(def);
63
- titles[option.model] = option.title;
64
- }
65
- const dropdownView = createDropdown(locale);
66
- addListToDropdown(dropdownView, itemDefinitions, {
67
- ariaLabel: accessibleLabel,
68
- role: 'menu'
69
- });
70
- dropdownView.buttonView.set({
71
- ariaLabel: accessibleLabel,
72
- ariaLabelledBy: undefined,
73
- isOn: false,
74
- withText: true,
75
- tooltip: accessibleLabel
76
- });
77
- dropdownView.extendTemplate({
78
- attributes: {
79
- class: [
80
- 'ck-heading-dropdown'
81
- ]
82
- }
83
- });
84
- dropdownView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled) => {
85
- return areEnabled.some(isEnabled => isEnabled);
86
- });
87
- dropdownView.buttonView.bind('label').to(headingCommand, 'value', paragraphCommand, 'value', (value, para) => {
88
- const whichModel = value || para && 'paragraph';
89
- if (typeof whichModel === 'boolean') {
90
- return defaultTitle;
91
- }
92
- // If none of the commands is active, display default title.
93
- if (!titles[whichModel]) {
94
- return defaultTitle;
95
- }
96
- return titles[whichModel];
97
- });
98
- // Execute command when an item from the dropdown is selected.
99
- this.listenTo(dropdownView, 'execute', evt => {
100
- const { commandName, commandValue } = evt.source;
101
- editor.execute(commandName, commandValue ? { value: commandValue } : undefined);
102
- editor.editing.view.focus();
103
- });
104
- return dropdownView;
105
- });
106
- }
107
- }
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/headingui
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
10
+ import { Collection } from 'ckeditor5/src/utils';
11
+ import { getLocalizedOptions } from './utils';
12
+ import '../theme/heading.css';
13
+ /**
14
+ * The headings UI feature. It introduces the `headings` dropdown.
15
+ */
16
+ export default class HeadingUI extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName() {
21
+ return 'HeadingUI';
22
+ }
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ init() {
27
+ const editor = this.editor;
28
+ const t = editor.t;
29
+ const options = getLocalizedOptions(editor);
30
+ const defaultTitle = t('Choose heading');
31
+ const accessibleLabel = t('Heading');
32
+ // Register UI component.
33
+ editor.ui.componentFactory.add('heading', locale => {
34
+ const titles = {};
35
+ const itemDefinitions = new Collection();
36
+ const headingCommand = editor.commands.get('heading');
37
+ const paragraphCommand = editor.commands.get('paragraph');
38
+ const commands = [headingCommand];
39
+ for (const option of options) {
40
+ const def = {
41
+ type: 'button',
42
+ model: new Model({
43
+ label: option.title,
44
+ class: option.class,
45
+ role: 'menuitemradio',
46
+ withText: true
47
+ })
48
+ };
49
+ if (option.model === 'paragraph') {
50
+ def.model.bind('isOn').to(paragraphCommand, 'value');
51
+ def.model.set('commandName', 'paragraph');
52
+ commands.push(paragraphCommand);
53
+ }
54
+ else {
55
+ def.model.bind('isOn').to(headingCommand, 'value', value => value === option.model);
56
+ def.model.set({
57
+ commandName: 'heading',
58
+ commandValue: option.model
59
+ });
60
+ }
61
+ // Add the option to the collection.
62
+ itemDefinitions.add(def);
63
+ titles[option.model] = option.title;
64
+ }
65
+ const dropdownView = createDropdown(locale);
66
+ addListToDropdown(dropdownView, itemDefinitions, {
67
+ ariaLabel: accessibleLabel,
68
+ role: 'menu'
69
+ });
70
+ dropdownView.buttonView.set({
71
+ ariaLabel: accessibleLabel,
72
+ ariaLabelledBy: undefined,
73
+ isOn: false,
74
+ withText: true,
75
+ tooltip: accessibleLabel
76
+ });
77
+ dropdownView.extendTemplate({
78
+ attributes: {
79
+ class: [
80
+ 'ck-heading-dropdown'
81
+ ]
82
+ }
83
+ });
84
+ dropdownView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled) => {
85
+ return areEnabled.some(isEnabled => isEnabled);
86
+ });
87
+ dropdownView.buttonView.bind('label').to(headingCommand, 'value', paragraphCommand, 'value', (value, para) => {
88
+ const whichModel = value || para && 'paragraph';
89
+ if (typeof whichModel === 'boolean') {
90
+ return defaultTitle;
91
+ }
92
+ // If none of the commands is active, display default title.
93
+ if (!titles[whichModel]) {
94
+ return defaultTitle;
95
+ }
96
+ return titles[whichModel];
97
+ });
98
+ // Execute command when an item from the dropdown is selected.
99
+ this.listenTo(dropdownView, 'execute', evt => {
100
+ const { commandName, commandValue } = evt.source;
101
+ editor.execute(commandName, commandValue ? { value: commandValue } : undefined);
102
+ editor.editing.view.focus();
103
+ });
104
+ return dropdownView;
105
+ });
106
+ }
107
+ }
package/src/index.d.ts CHANGED
@@ -1,16 +1,16 @@
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
7
- */
8
- export { default as Heading } from './heading';
9
- export type { HeadingOption } from './headingconfig';
10
- export { default as HeadingEditing } from './headingediting';
11
- export { default as HeadingUI } from './headingui';
12
- export { default as HeadingButtonsUI } from './headingbuttonsui';
13
- export { default as Title, type TitleConfig } from './title';
14
- export type { HeadingConfig } from './headingconfig';
15
- export type { default as HeadingCommand } from './headingcommand';
16
- import './augmentation';
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
7
+ */
8
+ export { default as Heading } from './heading';
9
+ export type { HeadingOption } from './headingconfig';
10
+ export { default as HeadingEditing } from './headingediting';
11
+ export { default as HeadingUI } from './headingui';
12
+ export { default as HeadingButtonsUI } from './headingbuttonsui';
13
+ export { default as Title, type TitleConfig } from './title';
14
+ export type { HeadingConfig } from './headingconfig';
15
+ export type { default as HeadingCommand } from './headingcommand';
16
+ import './augmentation';
package/src/index.js CHANGED
@@ -1,13 +1,13 @@
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
7
- */
8
- export { default as Heading } from './heading';
9
- export { default as HeadingEditing } from './headingediting';
10
- export { default as HeadingUI } from './headingui';
11
- export { default as HeadingButtonsUI } from './headingbuttonsui';
12
- export { default as Title } from './title';
13
- import './augmentation';
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
7
+ */
8
+ export { default as Heading } from './heading';
9
+ export { default as HeadingEditing } from './headingediting';
10
+ export { default as HeadingUI } from './headingui';
11
+ export { default as HeadingButtonsUI } from './headingbuttonsui';
12
+ export { default as Title } from './title';
13
+ import './augmentation';