@ckeditor/ckeditor5-heading 48.8.1-alpha.3 → 49.0.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.
Files changed (165) hide show
  1. package/dist/augmentation.d.ts +28 -28
  2. package/dist/heading.d.ts +30 -31
  3. package/dist/headingbuttonsui.d.ts +46 -46
  4. package/dist/headingcommand.d.ts +43 -43
  5. package/dist/headingconfig.d.ts +112 -112
  6. package/dist/headingediting.d.ts +41 -41
  7. package/dist/headingui.d.ts +20 -21
  8. package/dist/index-content.css +3 -0
  9. package/dist/index-content.css.map +1 -0
  10. package/dist/index-editor.css +17 -13
  11. package/dist/index-editor.css.map +1 -0
  12. package/dist/index.css +7 -5
  13. package/dist/index.css.map +1 -1
  14. package/dist/index.d.ts +17 -15
  15. package/dist/index.js +875 -905
  16. package/dist/index.js.map +1 -1
  17. package/dist/title.d.ts +122 -115
  18. package/dist/translations/af.js +1 -1
  19. package/dist/translations/af.umd.js +5 -3
  20. package/dist/translations/ar.js +1 -1
  21. package/dist/translations/ar.umd.js +5 -3
  22. package/dist/translations/ast.js +1 -1
  23. package/dist/translations/ast.umd.js +5 -3
  24. package/dist/translations/az.js +1 -1
  25. package/dist/translations/az.umd.js +5 -3
  26. package/dist/translations/be.js +1 -1
  27. package/dist/translations/be.umd.js +5 -3
  28. package/dist/translations/bg.js +1 -1
  29. package/dist/translations/bg.umd.js +5 -3
  30. package/dist/translations/bn.js +1 -1
  31. package/dist/translations/bn.umd.js +5 -3
  32. package/dist/translations/bs.js +1 -1
  33. package/dist/translations/bs.umd.js +5 -3
  34. package/dist/translations/ca.js +1 -1
  35. package/dist/translations/ca.umd.js +5 -3
  36. package/dist/translations/cs.js +1 -1
  37. package/dist/translations/cs.umd.js +5 -3
  38. package/dist/translations/da.js +1 -1
  39. package/dist/translations/da.umd.js +5 -3
  40. package/dist/translations/de-ch.js +1 -1
  41. package/dist/translations/de-ch.umd.js +5 -3
  42. package/dist/translations/de.js +1 -1
  43. package/dist/translations/de.umd.js +5 -3
  44. package/dist/translations/el.js +1 -1
  45. package/dist/translations/el.umd.js +5 -3
  46. package/dist/translations/en-au.js +1 -1
  47. package/dist/translations/en-au.umd.js +5 -3
  48. package/dist/translations/en-gb.js +1 -1
  49. package/dist/translations/en-gb.umd.js +5 -3
  50. package/dist/translations/en.js +1 -1
  51. package/dist/translations/en.umd.js +5 -3
  52. package/dist/translations/eo.js +1 -1
  53. package/dist/translations/eo.umd.js +5 -3
  54. package/dist/translations/es-co.js +1 -1
  55. package/dist/translations/es-co.umd.js +5 -3
  56. package/dist/translations/es.js +1 -1
  57. package/dist/translations/es.umd.js +5 -3
  58. package/dist/translations/et.js +1 -1
  59. package/dist/translations/et.umd.js +5 -3
  60. package/dist/translations/eu.js +1 -1
  61. package/dist/translations/eu.umd.js +5 -3
  62. package/dist/translations/fa.js +1 -1
  63. package/dist/translations/fa.umd.js +5 -3
  64. package/dist/translations/fi.js +1 -1
  65. package/dist/translations/fi.umd.js +5 -3
  66. package/dist/translations/fr.js +1 -1
  67. package/dist/translations/fr.umd.js +5 -3
  68. package/dist/translations/gl.js +1 -1
  69. package/dist/translations/gl.umd.js +5 -3
  70. package/dist/translations/gu.js +1 -1
  71. package/dist/translations/gu.umd.js +5 -3
  72. package/dist/translations/he.js +1 -1
  73. package/dist/translations/he.umd.js +5 -3
  74. package/dist/translations/hi.js +1 -1
  75. package/dist/translations/hi.umd.js +5 -3
  76. package/dist/translations/hr.js +1 -1
  77. package/dist/translations/hr.umd.js +5 -3
  78. package/dist/translations/hu.js +1 -1
  79. package/dist/translations/hu.umd.js +5 -3
  80. package/dist/translations/hy.js +1 -1
  81. package/dist/translations/hy.umd.js +5 -3
  82. package/dist/translations/id.js +1 -1
  83. package/dist/translations/id.umd.js +5 -3
  84. package/dist/translations/it.js +1 -1
  85. package/dist/translations/it.umd.js +5 -3
  86. package/dist/translations/ja.js +1 -1
  87. package/dist/translations/ja.umd.js +5 -3
  88. package/dist/translations/jv.js +1 -1
  89. package/dist/translations/jv.umd.js +5 -3
  90. package/dist/translations/kk.js +1 -1
  91. package/dist/translations/kk.umd.js +5 -3
  92. package/dist/translations/km.js +1 -1
  93. package/dist/translations/km.umd.js +5 -3
  94. package/dist/translations/kn.js +1 -1
  95. package/dist/translations/kn.umd.js +5 -3
  96. package/dist/translations/ko.js +1 -1
  97. package/dist/translations/ko.umd.js +5 -3
  98. package/dist/translations/ku.js +1 -1
  99. package/dist/translations/ku.umd.js +5 -3
  100. package/dist/translations/lt.js +1 -1
  101. package/dist/translations/lt.umd.js +5 -3
  102. package/dist/translations/lv.js +1 -1
  103. package/dist/translations/lv.umd.js +5 -3
  104. package/dist/translations/ms.js +1 -1
  105. package/dist/translations/ms.umd.js +5 -3
  106. package/dist/translations/nb.js +1 -1
  107. package/dist/translations/nb.umd.js +5 -3
  108. package/dist/translations/ne.js +1 -1
  109. package/dist/translations/ne.umd.js +5 -3
  110. package/dist/translations/nl.js +1 -1
  111. package/dist/translations/nl.umd.js +5 -3
  112. package/dist/translations/no.js +1 -1
  113. package/dist/translations/no.umd.js +5 -3
  114. package/dist/translations/oc.js +1 -1
  115. package/dist/translations/oc.umd.js +5 -3
  116. package/dist/translations/pl.js +1 -1
  117. package/dist/translations/pl.umd.js +5 -3
  118. package/dist/translations/pt-br.js +1 -1
  119. package/dist/translations/pt-br.umd.js +5 -3
  120. package/dist/translations/pt.js +1 -1
  121. package/dist/translations/pt.umd.js +5 -3
  122. package/dist/translations/ro.js +1 -1
  123. package/dist/translations/ro.umd.js +5 -3
  124. package/dist/translations/ru.js +1 -1
  125. package/dist/translations/ru.umd.js +5 -3
  126. package/dist/translations/si.js +1 -1
  127. package/dist/translations/si.umd.js +5 -3
  128. package/dist/translations/sk.js +1 -1
  129. package/dist/translations/sk.umd.js +5 -3
  130. package/dist/translations/sl.js +1 -1
  131. package/dist/translations/sl.umd.js +5 -3
  132. package/dist/translations/sq.js +1 -1
  133. package/dist/translations/sq.umd.js +5 -3
  134. package/dist/translations/sr-latn.js +1 -1
  135. package/dist/translations/sr-latn.umd.js +5 -3
  136. package/dist/translations/sr.js +1 -1
  137. package/dist/translations/sr.umd.js +5 -3
  138. package/dist/translations/sv.js +1 -1
  139. package/dist/translations/sv.umd.js +5 -3
  140. package/dist/translations/th.js +1 -1
  141. package/dist/translations/th.umd.js +5 -3
  142. package/dist/translations/ti.js +1 -1
  143. package/dist/translations/ti.umd.js +5 -3
  144. package/dist/translations/tk.js +1 -1
  145. package/dist/translations/tk.umd.js +5 -3
  146. package/dist/translations/tr.js +1 -1
  147. package/dist/translations/tr.umd.js +5 -3
  148. package/dist/translations/tt.js +1 -1
  149. package/dist/translations/tt.umd.js +5 -3
  150. package/dist/translations/ug.js +1 -1
  151. package/dist/translations/ug.umd.js +5 -3
  152. package/dist/translations/uk.js +1 -1
  153. package/dist/translations/uk.umd.js +5 -3
  154. package/dist/translations/ur.js +1 -1
  155. package/dist/translations/ur.umd.js +5 -3
  156. package/dist/translations/uz.js +1 -1
  157. package/dist/translations/uz.umd.js +5 -3
  158. package/dist/translations/vi.js +1 -1
  159. package/dist/translations/vi.umd.js +5 -3
  160. package/dist/translations/zh-cn.js +1 -1
  161. package/dist/translations/zh-cn.umd.js +5 -3
  162. package/dist/translations/zh.js +1 -1
  163. package/dist/translations/zh.umd.js +5 -3
  164. package/dist/utils.d.ts +16 -16
  165. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -2,944 +2,914 @@
2
2
  * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { Paragraph } from '@ckeditor/ckeditor5-paragraph/dist/index.js';
7
- import { first, priorities, Collection } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
- import { UIModel, createDropdown, addListToDropdown, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
9
- import { IconHeading6, IconHeading5, IconHeading4, IconHeading3, IconHeading2, IconHeading1 } from '@ckeditor/ckeditor5-icons/dist/index.js';
10
- import { ViewDowncastWriter, enableViewPlaceholder, hideViewPlaceholder, needsViewPlaceholder, showViewPlaceholder } from '@ckeditor/ckeditor5-engine/dist/index.js';
5
+ import { Command, Plugin } from "@ckeditor/ckeditor5-core";
6
+ import { Paragraph } from "@ckeditor/ckeditor5-paragraph";
7
+ import { Collection, first, logWarning, priorities } from "@ckeditor/ckeditor5-utils";
8
+ import { ButtonView, MenuBarMenuListItemButtonView, MenuBarMenuListItemView, MenuBarMenuListView, MenuBarMenuView, UIModel, addListToDropdown, createDropdown } from "@ckeditor/ckeditor5-ui";
9
+ import { IconHeading1, IconHeading2, IconHeading3, IconHeading4, IconHeading5, IconHeading6 } from "@ckeditor/ckeditor5-icons";
10
+ import { ViewDowncastWriter, enableViewPlaceholder, hideViewPlaceholder, needsViewPlaceholder, showViewPlaceholder } from "@ckeditor/ckeditor5-engine";
11
11
 
12
12
  /**
13
- * The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
14
- */ class HeadingCommand extends Command {
15
- /**
16
- * Set of defined model's elements names that this command support.
17
- * See {@link module:heading/headingconfig~HeadingOption}.
18
- */ modelElements;
19
- /**
20
- * Creates an instance of the command.
21
- *
22
- * @param editor Editor instance.
23
- * @param modelElements Names of the element which this command can apply in the model.
24
- */ constructor(editor, modelElements){
25
- super(editor);
26
- this.modelElements = modelElements;
27
- }
28
- /**
29
- * @inheritDoc
30
- */ refresh() {
31
- const block = first(this.editor.model.document.selection.getSelectedBlocks());
32
- this.value = !!block && this.modelElements.includes(block.name) && block.name;
33
- this.isEnabled = !!block && this.modelElements.some((heading)=>checkCanBecomeHeading(block, heading, this.editor.model.schema));
34
- }
35
- /**
36
- * Executes the command. Applies the heading to the selected blocks or, if the first selected
37
- * block is a heading already, turns selected headings (of this level only) to paragraphs.
38
- *
39
- * @param options.value Name of the element which this command will apply in the model.
40
- * @fires execute
41
- */ execute(options) {
42
- const model = this.editor.model;
43
- const document = model.document;
44
- const modelElement = options.value;
45
- model.change((writer)=>{
46
- const blocks = Array.from(document.selection.getSelectedBlocks()).filter((block)=>{
47
- return checkCanBecomeHeading(block, modelElement, model.schema);
48
- });
49
- for (const block of blocks){
50
- if (!block.is('element', modelElement)) {
51
- writer.rename(block, modelElement);
52
- }
53
- }
54
- });
55
- }
56
- }
13
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
14
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
15
+ */
16
+ /**
17
+ * @module heading/headingcommand
18
+ */
19
+ /**
20
+ * The heading command. It is used by the {@link module:heading/heading~Heading heading feature} to apply headings.
21
+ */
22
+ var HeadingCommand = class extends Command {
23
+ /**
24
+ * Set of defined model's elements names that this command support.
25
+ * See {@link module:heading/headingconfig~HeadingOption}.
26
+ */
27
+ modelElements;
28
+ /**
29
+ * Creates an instance of the command.
30
+ *
31
+ * @param editor Editor instance.
32
+ * @param modelElements Names of the element which this command can apply in the model.
33
+ */
34
+ constructor(editor, modelElements) {
35
+ super(editor);
36
+ this.modelElements = modelElements;
37
+ }
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ refresh() {
42
+ const block = first(this.editor.model.document.selection.getSelectedBlocks());
43
+ this.value = !!block && this.modelElements.includes(block.name) && block.name;
44
+ this.isEnabled = !!block && this.modelElements.some((heading) => checkCanBecomeHeading(block, heading, this.editor.model.schema));
45
+ }
46
+ /**
47
+ * Executes the command. Applies the heading to the selected blocks or, if the first selected
48
+ * block is a heading already, turns selected headings (of this level only) to paragraphs.
49
+ *
50
+ * @param options.value Name of the element which this command will apply in the model.
51
+ * @fires execute
52
+ */
53
+ execute(options) {
54
+ const model = this.editor.model;
55
+ const document = model.document;
56
+ const modelElement = options.value;
57
+ model.change((writer) => {
58
+ const blocks = Array.from(document.selection.getSelectedBlocks()).filter((block) => {
59
+ return checkCanBecomeHeading(block, modelElement, model.schema);
60
+ });
61
+ for (const block of blocks) if (!block.is("element", modelElement)) writer.rename(block, modelElement);
62
+ });
63
+ }
64
+ };
57
65
  /**
58
- * Checks whether the given block can be replaced by a specific heading.
59
- *
60
- * @param block A block to be tested.
61
- * @param heading Command element name in the model.
62
- * @param schema The schema of the document.
63
- */ function checkCanBecomeHeading(block, heading, schema) {
64
- return schema.checkChild(block.parent, heading) && !schema.isObject(block);
66
+ * Checks whether the given block can be replaced by a specific heading.
67
+ *
68
+ * @param block A block to be tested.
69
+ * @param heading Command element name in the model.
70
+ * @param schema The schema of the document.
71
+ */
72
+ function checkCanBecomeHeading(block, heading, schema) {
73
+ return schema.checkChild(block.parent, heading) && !schema.isObject(block);
65
74
  }
66
75
 
67
- const defaultModelElement = 'paragraph';
68
76
  /**
69
- * The headings engine feature. It handles switching between block formats – headings and paragraph.
70
- * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
71
- * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
72
- */ class HeadingEditing extends Plugin {
73
- /**
74
- * @inheritDoc
75
- */ static get pluginName() {
76
- return 'HeadingEditing';
77
- }
78
- /**
79
- * @inheritDoc
80
- */ static get isOfficialPlugin() {
81
- return true;
82
- }
83
- /**
84
- * @inheritDoc
85
- */ constructor(editor){
86
- super(editor);
87
- editor.config.define('heading', {
88
- options: [
89
- {
90
- model: 'paragraph',
91
- title: 'Paragraph',
92
- class: 'ck-heading_paragraph'
93
- },
94
- {
95
- model: 'heading1',
96
- view: 'h2',
97
- title: 'Heading 1',
98
- class: 'ck-heading_heading1'
99
- },
100
- {
101
- model: 'heading2',
102
- view: 'h3',
103
- title: 'Heading 2',
104
- class: 'ck-heading_heading2'
105
- },
106
- {
107
- model: 'heading3',
108
- view: 'h4',
109
- title: 'Heading 3',
110
- class: 'ck-heading_heading3'
111
- }
112
- ]
113
- });
114
- }
115
- /**
116
- * @inheritDoc
117
- */ static get requires() {
118
- return [
119
- Paragraph
120
- ];
121
- }
122
- /**
123
- * @inheritDoc
124
- */ init() {
125
- const editor = this.editor;
126
- const options = editor.config.get('heading.options');
127
- const modelElements = [];
128
- for (const option of options){
129
- // Skip paragraph - it is defined in required Paragraph feature.
130
- if (option.model === 'paragraph') {
131
- continue;
132
- }
133
- // Schema.
134
- editor.model.schema.register(option.model, {
135
- inheritAllFrom: '$block'
136
- });
137
- editor.conversion.elementToElement(option);
138
- modelElements.push(option.model);
139
- }
140
- this._addDefaultH1Conversion(editor);
141
- // Register the heading command for this option.
142
- editor.commands.add('heading', new HeadingCommand(editor, modelElements));
143
- }
144
- /**
145
- * @inheritDoc
146
- */ afterInit() {
147
- // If the enter command is added to the editor, alter its behavior.
148
- // Enter at the end of a heading element should create a paragraph.
149
- const editor = this.editor;
150
- const enterCommand = editor.commands.get('enter');
151
- const options = editor.config.get('heading.options');
152
- if (enterCommand) {
153
- this.listenTo(enterCommand, 'afterExecute', (evt, data)=>{
154
- const positionParent = editor.model.document.selection.getFirstPosition().parent;
155
- const isHeading = options.some((option)=>positionParent.is('element', option.model));
156
- if (isHeading && !positionParent.is('element', defaultModelElement) && positionParent.childCount === 0) {
157
- data.writer.rename(positionParent, defaultModelElement);
158
- }
159
- });
160
- }
161
- }
162
- /**
163
- * Adds default conversion for `h1` -> `heading1` with a low priority.
164
- *
165
- * @param editor Editor instance on which to add the `h1` conversion.
166
- */ _addDefaultH1Conversion(editor) {
167
- editor.conversion.for('upcast').elementToElement({
168
- model: 'heading1',
169
- view: 'h1',
170
- // With a `low` priority, `paragraph` plugin autoparagraphing mechanism is executed. Make sure
171
- // this listener is called before it. If not, `h1` will be transformed into a paragraph.
172
- converterPriority: priorities.low + 1
173
- });
174
- }
175
- }
77
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
78
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
79
+ */
80
+ /**
81
+ * @module heading/headingediting
82
+ */
83
+ const defaultModelElement = "paragraph";
84
+ /**
85
+ * The headings engine feature. It handles switching between block formats – headings and paragraph.
86
+ * This class represents the engine part of the heading feature. See also {@link module:heading/heading~Heading}.
87
+ * It introduces `heading1`-`headingN` commands which allow to convert paragraphs into headings.
88
+ */
89
+ var HeadingEditing = class extends Plugin {
90
+ /**
91
+ * @inheritDoc
92
+ */
93
+ static get pluginName() {
94
+ return "HeadingEditing";
95
+ }
96
+ /**
97
+ * @inheritDoc
98
+ */
99
+ static get isOfficialPlugin() {
100
+ return true;
101
+ }
102
+ /**
103
+ * @inheritDoc
104
+ */
105
+ constructor(editor) {
106
+ super(editor);
107
+ editor.config.define("heading", { options: [
108
+ {
109
+ model: "paragraph",
110
+ title: "Paragraph",
111
+ class: "ck-heading_paragraph"
112
+ },
113
+ {
114
+ model: "heading1",
115
+ view: "h2",
116
+ title: "Heading 1",
117
+ class: "ck-heading_heading1"
118
+ },
119
+ {
120
+ model: "heading2",
121
+ view: "h3",
122
+ title: "Heading 2",
123
+ class: "ck-heading_heading2"
124
+ },
125
+ {
126
+ model: "heading3",
127
+ view: "h4",
128
+ title: "Heading 3",
129
+ class: "ck-heading_heading3"
130
+ }
131
+ ] });
132
+ }
133
+ /**
134
+ * @inheritDoc
135
+ */
136
+ static get requires() {
137
+ return [Paragraph];
138
+ }
139
+ /**
140
+ * @inheritDoc
141
+ */
142
+ init() {
143
+ const editor = this.editor;
144
+ const options = editor.config.get("heading.options");
145
+ const modelElements = [];
146
+ for (const option of options) {
147
+ if (option.model === "paragraph") continue;
148
+ editor.model.schema.register(option.model, { inheritAllFrom: "$block" });
149
+ editor.conversion.elementToElement(option);
150
+ modelElements.push(option.model);
151
+ }
152
+ this._addDefaultH1Conversion(editor);
153
+ editor.commands.add("heading", new HeadingCommand(editor, modelElements));
154
+ }
155
+ /**
156
+ * @inheritDoc
157
+ */
158
+ afterInit() {
159
+ const editor = this.editor;
160
+ const enterCommand = editor.commands.get("enter");
161
+ const options = editor.config.get("heading.options");
162
+ if (enterCommand) this.listenTo(enterCommand, "afterExecute", (evt, data) => {
163
+ const positionParent = editor.model.document.selection.getFirstPosition().parent;
164
+ if (options.some((option) => positionParent.is("element", option.model)) && !positionParent.is("element", defaultModelElement) && positionParent.childCount === 0) data.writer.rename(positionParent, defaultModelElement);
165
+ });
166
+ }
167
+ /**
168
+ * Adds default conversion for `h1` -> `heading1` with a low priority.
169
+ *
170
+ * @param editor Editor instance on which to add the `h1` conversion.
171
+ */
172
+ _addDefaultH1Conversion(editor) {
173
+ editor.conversion.for("upcast").elementToElement({
174
+ model: "heading1",
175
+ view: "h1",
176
+ converterPriority: priorities.low + 1
177
+ });
178
+ }
179
+ };
176
180
 
177
181
  /**
178
- * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
179
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
180
- */ /**
181
- * @module heading/utils
182
- */ /**
183
- * Returns heading options as defined in `config.heading.options` but processed to consider
184
- * the editor localization, i.e. to display {@link module:heading/headingconfig~HeadingOption}
185
- * in the correct language.
186
- *
187
- * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
188
- * when the user configuration is defined because the editor does not exist yet.
189
- *
190
- * @internal
191
- */ function getLocalizedOptions(editor) {
192
- const t = editor.t;
193
- const localizedTitles = {
194
- 'Paragraph': t('Paragraph'),
195
- 'Heading 1': t('Heading 1'),
196
- 'Heading 2': t('Heading 2'),
197
- 'Heading 3': t('Heading 3'),
198
- 'Heading 4': t('Heading 4'),
199
- 'Heading 5': t('Heading 5'),
200
- 'Heading 6': t('Heading 6')
201
- };
202
- return editor.config.get('heading.options').map((option)=>{
203
- const title = localizedTitles[option.title];
204
- if (title && title != option.title) {
205
- option.title = title;
206
- }
207
- return option;
208
- });
182
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
183
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
184
+ */
185
+ /**
186
+ * Returns heading options as defined in `config.heading.options` but processed to consider
187
+ * the editor localization, i.e. to display {@link module:heading/headingconfig~HeadingOption}
188
+ * in the correct language.
189
+ *
190
+ * Note: The reason behind this method is that there is no way to use {@link module:utils/locale~Locale#t}
191
+ * when the user configuration is defined because the editor does not exist yet.
192
+ *
193
+ * @internal
194
+ */
195
+ function getLocalizedOptions(editor) {
196
+ const t = editor.t;
197
+ const localizedTitles = {
198
+ "Paragraph": t("Paragraph"),
199
+ "Heading 1": t("Heading 1"),
200
+ "Heading 2": t("Heading 2"),
201
+ "Heading 3": t("Heading 3"),
202
+ "Heading 4": t("Heading 4"),
203
+ "Heading 5": t("Heading 5"),
204
+ "Heading 6": t("Heading 6")
205
+ };
206
+ return editor.config.get("heading.options").map((option) => {
207
+ const title = localizedTitles[option.title];
208
+ if (title && title != option.title) option.title = title;
209
+ return option;
210
+ });
209
211
  }
210
212
 
211
213
  /**
212
- * The headings UI feature. It introduces the `headings` dropdown.
213
- */ class HeadingUI extends Plugin {
214
- /**
215
- * @inheritDoc
216
- */ static get pluginName() {
217
- return 'HeadingUI';
218
- }
219
- /**
220
- * @inheritDoc
221
- */ static get isOfficialPlugin() {
222
- return true;
223
- }
224
- /**
225
- * @inheritDoc
226
- */ init() {
227
- const editor = this.editor;
228
- const t = editor.t;
229
- const options = getLocalizedOptions(editor);
230
- const defaultTitle = t('Choose heading');
231
- const accessibleLabel = t('Heading');
232
- // Register UI component.
233
- editor.ui.componentFactory.add('heading', (locale)=>{
234
- const titles = {};
235
- const itemDefinitions = new Collection();
236
- const headingCommand = editor.commands.get('heading');
237
- const paragraphCommand = editor.commands.get('paragraph');
238
- const commands = [
239
- headingCommand
240
- ];
241
- for (const option of options){
242
- const def = {
243
- type: 'button',
244
- model: new UIModel({
245
- label: option.title,
246
- class: option.class,
247
- role: 'menuitemradio',
248
- withText: true
249
- })
250
- };
251
- if (option.model === 'paragraph') {
252
- def.model.bind('isOn').to(paragraphCommand, 'value');
253
- def.model.set('commandName', 'paragraph');
254
- commands.push(paragraphCommand);
255
- } else {
256
- def.model.bind('isOn').to(headingCommand, 'value', (value)=>value === option.model);
257
- def.model.set({
258
- commandName: 'heading',
259
- commandValue: option.model
260
- });
261
- }
262
- // Add the option to the collection.
263
- itemDefinitions.add(def);
264
- titles[option.model] = option.title;
265
- }
266
- const dropdownView = createDropdown(locale);
267
- addListToDropdown(dropdownView, itemDefinitions, {
268
- ariaLabel: accessibleLabel,
269
- role: 'menu'
270
- });
271
- dropdownView.buttonView.set({
272
- ariaLabel: accessibleLabel,
273
- ariaLabelledBy: undefined,
274
- isOn: false,
275
- withText: true,
276
- tooltip: accessibleLabel
277
- });
278
- dropdownView.extendTemplate({
279
- attributes: {
280
- class: [
281
- 'ck-heading-dropdown'
282
- ]
283
- }
284
- });
285
- dropdownView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled)=>{
286
- return areEnabled.some((isEnabled)=>isEnabled);
287
- });
288
- dropdownView.buttonView.bind('label').to(headingCommand, 'value', paragraphCommand, 'value', (heading, paragraph)=>{
289
- const whichModel = paragraph ? 'paragraph' : heading;
290
- if (typeof whichModel === 'boolean') {
291
- return defaultTitle;
292
- }
293
- // If none of the commands is active, display default title.
294
- if (!titles[whichModel]) {
295
- return defaultTitle;
296
- }
297
- return titles[whichModel];
298
- });
299
- dropdownView.buttonView.bind('ariaLabel').to(headingCommand, 'value', paragraphCommand, 'value', (heading, paragraph)=>{
300
- const whichModel = paragraph ? 'paragraph' : heading;
301
- if (typeof whichModel === 'boolean') {
302
- return accessibleLabel;
303
- }
304
- // If none of the commands is active, display default title.
305
- if (!titles[whichModel]) {
306
- return accessibleLabel;
307
- }
308
- return `${titles[whichModel]}, ${accessibleLabel}`;
309
- });
310
- // Execute command when an item from the dropdown is selected.
311
- this.listenTo(dropdownView, 'execute', (evt)=>{
312
- const { commandName, commandValue } = evt.source;
313
- editor.execute(commandName, commandValue ? {
314
- value: commandValue
315
- } : undefined);
316
- editor.editing.view.focus();
317
- });
318
- return dropdownView;
319
- });
320
- editor.ui.componentFactory.add('menuBar:heading', (locale)=>{
321
- const menuView = new MenuBarMenuView(locale);
322
- const headingCommand = editor.commands.get('heading');
323
- const paragraphCommand = editor.commands.get('paragraph');
324
- const commands = [
325
- headingCommand
326
- ];
327
- const listView = new MenuBarMenuListView(locale);
328
- menuView.set({
329
- class: 'ck-heading-dropdown'
330
- });
331
- listView.set({
332
- ariaLabel: t('Heading'),
333
- role: 'menu'
334
- });
335
- menuView.buttonView.set({
336
- label: t('Heading')
337
- });
338
- menuView.panelView.children.add(listView);
339
- for (const option of options){
340
- const listItemView = new MenuBarMenuListItemView(locale, menuView);
341
- const buttonView = new MenuBarMenuListItemButtonView(locale);
342
- listItemView.children.add(buttonView);
343
- listView.items.add(listItemView);
344
- buttonView.set({
345
- isToggleable: true,
346
- label: option.title,
347
- role: 'menuitemradio',
348
- class: option.class
349
- });
350
- buttonView.delegate('execute').to(menuView);
351
- buttonView.on('execute', ()=>{
352
- const commandName = option.model === 'paragraph' ? 'paragraph' : 'heading';
353
- editor.execute(commandName, {
354
- value: option.model
355
- });
356
- editor.editing.view.focus();
357
- });
358
- if (option.model === 'paragraph') {
359
- buttonView.bind('isOn').to(paragraphCommand, 'value');
360
- commands.push(paragraphCommand);
361
- } else {
362
- buttonView.bind('isOn').to(headingCommand, 'value', (value)=>value === option.model);
363
- }
364
- }
365
- menuView.bind('isEnabled').toMany(commands, 'isEnabled', (...areEnabled)=>{
366
- return areEnabled.some((isEnabled)=>isEnabled);
367
- });
368
- return menuView;
369
- });
370
- }
371
- }
214
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
215
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
216
+ */
217
+ /**
218
+ * @module heading/headingui
219
+ */
220
+ /**
221
+ * The headings UI feature. It introduces the `headings` dropdown.
222
+ */
223
+ var HeadingUI = class extends Plugin {
224
+ /**
225
+ * @inheritDoc
226
+ */
227
+ static get pluginName() {
228
+ return "HeadingUI";
229
+ }
230
+ /**
231
+ * @inheritDoc
232
+ */
233
+ static get isOfficialPlugin() {
234
+ return true;
235
+ }
236
+ /**
237
+ * @inheritDoc
238
+ */
239
+ init() {
240
+ const editor = this.editor;
241
+ const t = editor.t;
242
+ const options = getLocalizedOptions(editor);
243
+ const defaultTitle = t("Choose heading");
244
+ const accessibleLabel = t("Heading");
245
+ editor.ui.componentFactory.add("heading", (locale) => {
246
+ const titles = {};
247
+ const itemDefinitions = new Collection();
248
+ const headingCommand = editor.commands.get("heading");
249
+ const paragraphCommand = editor.commands.get("paragraph");
250
+ const commands = [headingCommand];
251
+ for (const option of options) {
252
+ const def = {
253
+ type: "button",
254
+ model: new UIModel({
255
+ label: option.title,
256
+ class: option.class,
257
+ role: "menuitemradio",
258
+ withText: true
259
+ })
260
+ };
261
+ if (option.model === "paragraph") {
262
+ def.model.bind("isOn").to(paragraphCommand, "value");
263
+ def.model.set("commandName", "paragraph");
264
+ commands.push(paragraphCommand);
265
+ } else {
266
+ def.model.bind("isOn").to(headingCommand, "value", (value) => value === option.model);
267
+ def.model.set({
268
+ commandName: "heading",
269
+ commandValue: option.model
270
+ });
271
+ }
272
+ itemDefinitions.add(def);
273
+ titles[option.model] = option.title;
274
+ }
275
+ const dropdownView = createDropdown(locale);
276
+ addListToDropdown(dropdownView, itemDefinitions, {
277
+ ariaLabel: accessibleLabel,
278
+ role: "menu"
279
+ });
280
+ dropdownView.buttonView.set({
281
+ ariaLabel: accessibleLabel,
282
+ ariaLabelledBy: void 0,
283
+ isOn: false,
284
+ withText: true,
285
+ tooltip: accessibleLabel
286
+ });
287
+ dropdownView.extendTemplate({ attributes: { class: ["ck-heading-dropdown"] } });
288
+ dropdownView.bind("isEnabled").toMany(commands, "isEnabled", (...areEnabled) => {
289
+ return areEnabled.some((isEnabled) => isEnabled);
290
+ });
291
+ dropdownView.buttonView.bind("label").to(headingCommand, "value", paragraphCommand, "value", (heading, paragraph) => {
292
+ const whichModel = paragraph ? "paragraph" : heading;
293
+ if (typeof whichModel === "boolean") return defaultTitle;
294
+ if (!titles[whichModel]) return defaultTitle;
295
+ return titles[whichModel];
296
+ });
297
+ dropdownView.buttonView.bind("ariaLabel").to(headingCommand, "value", paragraphCommand, "value", (heading, paragraph) => {
298
+ const whichModel = paragraph ? "paragraph" : heading;
299
+ if (typeof whichModel === "boolean") return accessibleLabel;
300
+ if (!titles[whichModel]) return accessibleLabel;
301
+ return `${titles[whichModel]}, ${accessibleLabel}`;
302
+ });
303
+ this.listenTo(dropdownView, "execute", (evt) => {
304
+ const { commandName, commandValue } = evt.source;
305
+ editor.execute(commandName, commandValue ? { value: commandValue } : void 0);
306
+ editor.editing.view.focus();
307
+ });
308
+ return dropdownView;
309
+ });
310
+ editor.ui.componentFactory.add("menuBar:heading", (locale) => {
311
+ const menuView = new MenuBarMenuView(locale);
312
+ const headingCommand = editor.commands.get("heading");
313
+ const paragraphCommand = editor.commands.get("paragraph");
314
+ const commands = [headingCommand];
315
+ const listView = new MenuBarMenuListView(locale);
316
+ menuView.set({ class: "ck-heading-dropdown" });
317
+ listView.set({
318
+ ariaLabel: t("Heading"),
319
+ role: "menu"
320
+ });
321
+ menuView.buttonView.set({ label: t("Heading") });
322
+ menuView.panelView.children.add(listView);
323
+ for (const option of options) {
324
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
325
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
326
+ listItemView.children.add(buttonView);
327
+ listView.items.add(listItemView);
328
+ buttonView.set({
329
+ isToggleable: true,
330
+ label: option.title,
331
+ role: "menuitemradio",
332
+ class: option.class
333
+ });
334
+ buttonView.delegate("execute").to(menuView);
335
+ buttonView.on("execute", () => {
336
+ const commandName = option.model === "paragraph" ? "paragraph" : "heading";
337
+ editor.execute(commandName, { value: option.model });
338
+ editor.editing.view.focus();
339
+ });
340
+ if (option.model === "paragraph") {
341
+ buttonView.bind("isOn").to(paragraphCommand, "value");
342
+ commands.push(paragraphCommand);
343
+ } else buttonView.bind("isOn").to(headingCommand, "value", (value) => value === option.model);
344
+ }
345
+ menuView.bind("isEnabled").toMany(commands, "isEnabled", (...areEnabled) => {
346
+ return areEnabled.some((isEnabled) => isEnabled);
347
+ });
348
+ return menuView;
349
+ });
350
+ }
351
+ };
372
352
 
373
353
  /**
374
- * The headings feature.
375
- *
376
- * For a detailed overview, check the {@glink features/headings Headings feature} guide
377
- * and the {@glink api/heading package page}.
378
- *
379
- * This is a "glue" plugin which loads the {@link module:heading/headingediting~HeadingEditing heading editing feature}
380
- * and {@link module:heading/headingui~HeadingUI heading UI feature}.
381
- *
382
- * @extends module:core/plugin~Plugin
383
- */ class Heading extends Plugin {
384
- /**
385
- * @inheritDoc
386
- */ static get requires() {
387
- return [
388
- HeadingEditing,
389
- HeadingUI
390
- ];
391
- }
392
- /**
393
- * @inheritDoc
394
- */ static get pluginName() {
395
- return 'Heading';
396
- }
397
- /**
398
- * @inheritDoc
399
- */ static get isOfficialPlugin() {
400
- return true;
401
- }
402
- }
354
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
355
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
356
+ */
357
+ /**
358
+ * @module heading/heading
359
+ */
360
+ /**
361
+ * The headings feature.
362
+ *
363
+ * For a detailed overview, check the {@glink features/headings Headings feature} guide
364
+ * and the {@glink api/heading package page}.
365
+ *
366
+ * This is a "glue" plugin which loads the {@link module:heading/headingediting~HeadingEditing heading editing feature}
367
+ * and {@link module:heading/headingui~HeadingUI heading UI feature}.
368
+ *
369
+ * @extends module:core/plugin~Plugin
370
+ */
371
+ var Heading = class extends Plugin {
372
+ /**
373
+ * @inheritDoc
374
+ */
375
+ static get requires() {
376
+ return [HeadingEditing, HeadingUI];
377
+ }
378
+ /**
379
+ * @inheritDoc
380
+ */
381
+ static get pluginName() {
382
+ return "Heading";
383
+ }
384
+ /**
385
+ * @inheritDoc
386
+ */
387
+ static get isOfficialPlugin() {
388
+ return true;
389
+ }
390
+ };
403
391
 
404
- const defaultIcons = /* #__PURE__ */ (()=>({
405
- heading1: IconHeading1,
406
- heading2: IconHeading2,
407
- heading3: IconHeading3,
408
- heading4: IconHeading4,
409
- heading5: IconHeading5,
410
- heading6: IconHeading6
411
- }))();
412
392
  /**
413
- * The `HeadingButtonsUI` plugin defines a set of UI buttons that can be used instead of the
414
- * standard drop down component.
415
- *
416
- * This feature is not enabled by default by the {@link module:heading/heading~Heading} plugin and needs to be
417
- * installed manually to the editor configuration.
418
- *
419
- * Plugin introduces button UI elements, which names are same as `model` property from {@link module:heading/headingconfig~HeadingOption}.
420
- *
421
- * ```ts
422
- * ClassicEditor
423
- * .create( {
424
- * plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
425
- * heading: {
426
- * options: [
427
- * { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
428
- * { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
429
- * { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
430
- * { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
431
- * ]
432
- * },
433
- * toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
434
- * } )
435
- * .then( ... )
436
- * .catch( ... );
437
- * ```
438
- *
439
- * NOTE: The `'paragraph'` button is defined in by the {@link module:paragraph/paragraphbuttonui~ParagraphButtonUI} plugin
440
- * which needs to be loaded manually as well.
441
- *
442
- * It is possible to use custom icons by providing `icon` config option in {@link module:heading/headingconfig~HeadingOption}.
443
- * For the default configuration standard icons are used.
444
- */ class HeadingButtonsUI extends Plugin {
445
- /**
446
- * @inheritDoc
447
- */ init() {
448
- const options = getLocalizedOptions(this.editor);
449
- options.filter((item)=>item.model !== 'paragraph').map((item)=>this._createButton(item));
450
- }
451
- /**
452
- * Creates single button view from provided configuration option.
453
- */ _createButton(option) {
454
- const editor = this.editor;
455
- editor.ui.componentFactory.add(option.model, (locale)=>{
456
- const view = new ButtonView(locale);
457
- const command = editor.commands.get('heading');
458
- view.label = option.title;
459
- view.icon = option.icon || defaultIcons[option.model];
460
- view.tooltip = true;
461
- view.isToggleable = true;
462
- view.bind('isEnabled').to(command);
463
- view.bind('isOn').to(command, 'value', (value)=>value == option.model);
464
- view.on('execute', ()=>{
465
- editor.execute('heading', {
466
- value: option.model
467
- });
468
- editor.editing.view.focus();
469
- });
470
- return view;
471
- });
472
- }
473
- }
393
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
394
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
395
+ */
396
+ /**
397
+ * @module heading/headingbuttonsui
398
+ */
399
+ const defaultIcons = /* #__PURE__ */ (() => ({
400
+ heading1: IconHeading1,
401
+ heading2: IconHeading2,
402
+ heading3: IconHeading3,
403
+ heading4: IconHeading4,
404
+ heading5: IconHeading5,
405
+ heading6: IconHeading6
406
+ }))();
407
+ /**
408
+ * The `HeadingButtonsUI` plugin defines a set of UI buttons that can be used instead of the
409
+ * standard drop down component.
410
+ *
411
+ * This feature is not enabled by default by the {@link module:heading/heading~Heading} plugin and needs to be
412
+ * installed manually to the editor configuration.
413
+ *
414
+ * Plugin introduces button UI elements, which names are same as `model` property from {@link module:heading/headingconfig~HeadingOption}.
415
+ *
416
+ * ```ts
417
+ * ClassicEditor
418
+ * .create( {
419
+ * plugins: [ ..., Heading, Paragraph, HeadingButtonsUI, ParagraphButtonUI ]
420
+ * heading: {
421
+ * options: [
422
+ * { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
423
+ * { model: 'heading1', view: 'h2', title: 'Heading 1', class: 'ck-heading_heading1' },
424
+ * { model: 'heading2', view: 'h3', title: 'Heading 2', class: 'ck-heading_heading2' },
425
+ * { model: 'heading3', view: 'h4', title: 'Heading 3', class: 'ck-heading_heading3' }
426
+ * ]
427
+ * },
428
+ * toolbar: [ 'paragraph', 'heading1', 'heading2', 'heading3' ]
429
+ * } )
430
+ * .then( ... )
431
+ * .catch( ... );
432
+ * ```
433
+ *
434
+ * NOTE: The `'paragraph'` button is defined in by the {@link module:paragraph/paragraphbuttonui~ParagraphButtonUI} plugin
435
+ * which needs to be loaded manually as well.
436
+ *
437
+ * It is possible to use custom icons by providing `icon` config option in {@link module:heading/headingconfig~HeadingOption}.
438
+ * For the default configuration standard icons are used.
439
+ */
440
+ var HeadingButtonsUI = class extends Plugin {
441
+ /**
442
+ * @inheritDoc
443
+ */
444
+ init() {
445
+ getLocalizedOptions(this.editor).filter((item) => item.model !== "paragraph").map((item) => this._createButton(item));
446
+ }
447
+ /**
448
+ * Creates single button view from provided configuration option.
449
+ */
450
+ _createButton(option) {
451
+ const editor = this.editor;
452
+ editor.ui.componentFactory.add(option.model, (locale) => {
453
+ const view = new ButtonView(locale);
454
+ const command = editor.commands.get("heading");
455
+ view.label = option.title;
456
+ view.icon = option.icon || defaultIcons[option.model];
457
+ view.tooltip = true;
458
+ view.isToggleable = true;
459
+ view.bind("isEnabled").to(command);
460
+ view.bind("isOn").to(command, "value", (value) => value == option.model);
461
+ view.on("execute", () => {
462
+ editor.execute("heading", { value: option.model });
463
+ editor.editing.view.focus();
464
+ });
465
+ return view;
466
+ });
467
+ }
468
+ };
474
469
 
475
- // A list of element names that should be treated by the Title plugin as title-like.
476
- // This means that an element of a type from this list will be changed to a title element
477
- // when it is the first element in the root.
478
- const titleLikeElements = new Set([
479
- 'paragraph',
480
- 'heading1',
481
- 'heading2',
482
- 'heading3',
483
- 'heading4',
484
- 'heading5',
485
- 'heading6'
470
+ /**
471
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
472
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
473
+ */
474
+ /**
475
+ * @module heading/title
476
+ */
477
+ const titleLikeElements = /* @__PURE__ */ new Set([
478
+ "paragraph",
479
+ "heading1",
480
+ "heading2",
481
+ "heading3",
482
+ "heading4",
483
+ "heading5",
484
+ "heading6"
486
485
  ]);
487
486
  /**
488
- * The Title plugin.
489
- *
490
- * It splits the document into `Title` and `Body` sections.
491
- */ class Title extends Plugin {
492
- /**
493
- * A reference to an empty paragraph in the body
494
- * created when there is no element in the body for the placeholder purposes.
495
- */ _bodyPlaceholder = new Map();
496
- /**
497
- * @inheritDoc
498
- */ static get pluginName() {
499
- return 'Title';
500
- }
501
- /**
502
- * @inheritDoc
503
- */ static get isOfficialPlugin() {
504
- return true;
505
- }
506
- /**
507
- * @inheritDoc
508
- */ static get requires() {
509
- return [
510
- Paragraph
511
- ];
512
- }
513
- /**
514
- * @inheritDoc
515
- */ init() {
516
- const editor = this.editor;
517
- const model = editor.model;
518
- // To use the schema for disabling some features when the selection is inside the title element
519
- // it is needed to create the following structure:
520
- //
521
- // <title>
522
- // <title-content>The title text</title-content>
523
- // </title>
524
- //
525
- // See: https://github.com/ckeditor/ckeditor5/issues/2005.
526
- model.schema.register('title', {
527
- isBlock: true,
528
- allowIn: '$root'
529
- });
530
- model.schema.register('title-content', {
531
- isBlock: true,
532
- allowIn: 'title',
533
- allowAttributes: [
534
- 'alignment'
535
- ]
536
- });
537
- model.schema.extend('$text', {
538
- allowIn: 'title-content'
539
- });
540
- // Disallow all attributes in `title-content`.
541
- model.schema.addAttributeCheck((context)=>{
542
- if (context.endsWith('title-content $text')) {
543
- return false;
544
- }
545
- });
546
- // Because `title` is represented by two elements in the model
547
- // but only one in the view, it is needed to adjust Mapper.
548
- editor.editing.mapper.on('modelToViewPosition', mapModelPositionToView(editor.editing.view));
549
- editor.data.mapper.on('modelToViewPosition', mapModelPositionToView(editor.editing.view));
550
- // Conversion.
551
- editor.conversion.for('downcast').elementToElement({
552
- model: 'title-content',
553
- view: 'h1'
554
- });
555
- editor.conversion.for('downcast').add((dispatcher)=>dispatcher.on('insert:title', (evt, data, conversionApi)=>{
556
- conversionApi.consumable.consume(data.item, evt.name);
557
- }));
558
- // Custom converter is used for data v -> m conversion to avoid calling post-fixer when setting data.
559
- // See https://github.com/ckeditor/ckeditor5/issues/2036.
560
- editor.data.upcastDispatcher.on('element:h1', dataViewModelH1Insertion, {
561
- priority: 'high'
562
- });
563
- editor.data.upcastDispatcher.on('element:h2', dataViewModelH1Insertion, {
564
- priority: 'high'
565
- });
566
- editor.data.upcastDispatcher.on('element:h3', dataViewModelH1Insertion, {
567
- priority: 'high'
568
- });
569
- // Take care about correct `title` element structure.
570
- model.document.registerPostFixer((writer)=>this._fixTitleContent(writer));
571
- // Create and take care of correct position of a `title` element.
572
- model.document.registerPostFixer((writer)=>this._fixTitleElement(writer));
573
- // Create element for `Body` placeholder if it is missing.
574
- model.document.registerPostFixer((writer)=>this._fixBodyElement(writer));
575
- // Prevent from adding extra at the end of the document.
576
- model.document.registerPostFixer((writer)=>this._fixExtraParagraph(writer));
577
- // Attach `Title` and `Body` placeholders to the empty title and/or content.
578
- this._attachPlaceholders();
579
- // Attach Tab handling.
580
- this._attachTabPressHandling();
581
- }
582
- /**
583
- * Returns the title of the document. Note that because this plugin does not allow any formatting inside
584
- * the title element, the output of this method will be a plain text, with no HTML tags.
585
- *
586
- * It is not recommended to use this method together with features that insert markers to the
587
- * data output, like comments or track changes features. If such markers start in the title and end in the
588
- * body, the result of this method might be incorrect.
589
- *
590
- * @param options Additional configuration passed to the conversion process.
591
- * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
592
- * @returns The title of the document.
593
- */ getTitle(options = {}) {
594
- const rootName = options.rootName ? options.rootName : undefined;
595
- const titleElement = this._getTitleElement(rootName);
596
- const titleContentElement = titleElement.getChild(0);
597
- return this.editor.data.stringify(titleContentElement, options);
598
- }
599
- /**
600
- * Returns the body of the document.
601
- *
602
- * Note that it is not recommended to use this method together with features that insert markers to the
603
- * data output, like comments or track changes features. If such markers start in the title and end in the
604
- * body, the result of this method might be incorrect.
605
- *
606
- * @param options Additional configuration passed to the conversion process.
607
- * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
608
- * @returns The body of the document.
609
- */ getBody(options = {}) {
610
- const editor = this.editor;
611
- const data = editor.data;
612
- const model = editor.model;
613
- const rootName = options.rootName ? options.rootName : undefined;
614
- const root = editor.model.document.getRoot(rootName);
615
- const view = editor.editing.view;
616
- const viewWriter = new ViewDowncastWriter(view.document);
617
- const rootRange = model.createRangeIn(root);
618
- const viewDocumentFragment = viewWriter.createDocumentFragment();
619
- // Find all markers that intersects with body.
620
- const bodyStartPosition = model.createPositionAfter(root.getChild(0));
621
- const bodyRange = model.createRange(bodyStartPosition, model.createPositionAt(root, 'end'));
622
- const markers = new Map();
623
- for (const marker of model.markers){
624
- const intersection = bodyRange.getIntersection(marker.getRange());
625
- if (intersection) {
626
- markers.set(marker.name, intersection);
627
- }
628
- }
629
- // Convert the entire root to view.
630
- data.mapper.clearBindings();
631
- data.mapper.bindElements(root, viewDocumentFragment);
632
- data.downcastDispatcher.convert(rootRange, markers, viewWriter, options);
633
- // Remove title element from view.
634
- viewWriter.remove(viewWriter.createRangeOn(viewDocumentFragment.getChild(0)));
635
- // view -> data
636
- return editor.data.processor.toData(viewDocumentFragment);
637
- }
638
- /**
639
- * Returns the `title` element when it is in the document. Returns `undefined` otherwise.
640
- */ _getTitleElement(rootName) {
641
- const root = this.editor.model.document.getRoot(rootName);
642
- for (const child of root.getChildren()){
643
- if (isTitle(child)) {
644
- return child;
645
- }
646
- }
647
- }
648
- /**
649
- * Model post-fixer callback that ensures that `title` has only one `title-content` child.
650
- * All additional children should be moved after the `title` element and renamed to a paragraph.
651
- */ _fixTitleContent(writer) {
652
- let changed = false;
653
- for (const rootName of this.editor.model.document.getRootNames()){
654
- const title = this._getTitleElement(rootName);
655
- // If there is no title in the content it will be created by `_fixTitleElement` post-fixer.
656
- // If the title has just one element, then it is correct. No fixing.
657
- if (!title || title.maxOffset === 1) {
658
- continue;
659
- }
660
- const titleChildren = Array.from(title.getChildren());
661
- // Skip first child because it is an allowed element.
662
- titleChildren.shift();
663
- for (const titleChild of titleChildren){
664
- writer.move(writer.createRangeOn(titleChild), title, 'after');
665
- writer.rename(titleChild, 'paragraph');
666
- }
667
- changed = true;
668
- }
669
- return changed;
670
- }
671
- /**
672
- * Model post-fixer callback that creates a title element when it is missing,
673
- * takes care of the correct position of it and removes additional title elements.
674
- */ _fixTitleElement(writer) {
675
- let changed = false;
676
- const model = this.editor.model;
677
- for (const modelRoot of this.editor.model.document.getRoots()){
678
- const titleElements = Array.from(modelRoot.getChildren()).filter(isTitle);
679
- const firstTitleElement = titleElements[0];
680
- const firstRootChild = modelRoot.getChild(0);
681
- // When title element is at the beginning of the document then try to fix additional title elements (if there are any).
682
- if (firstRootChild.is('element', 'title')) {
683
- if (titleElements.length > 1) {
684
- fixAdditionalTitleElements(titleElements, writer, model);
685
- changed = true;
686
- }
687
- continue;
688
- }
689
- // When there is no title in the document and first element in the document cannot be changed
690
- // to the title then create an empty title element at the beginning of the document.
691
- if (!firstTitleElement && !titleLikeElements.has(firstRootChild.name)) {
692
- const title = writer.createElement('title');
693
- writer.insert(title, modelRoot);
694
- writer.insertElement('title-content', title);
695
- changed = true;
696
- continue;
697
- }
698
- if (titleLikeElements.has(firstRootChild.name)) {
699
- // Change the first element in the document to the title if it can be changed (is title-like).
700
- changeElementToTitle(firstRootChild, writer, model);
701
- } else {
702
- // Otherwise, move the first occurrence of the title element to the beginning of the document.
703
- writer.move(writer.createRangeOn(firstTitleElement), modelRoot, 0);
704
- }
705
- fixAdditionalTitleElements(titleElements, writer, model);
706
- changed = true;
707
- }
708
- return changed;
709
- }
710
- /**
711
- * Model post-fixer callback that adds an empty paragraph at the end of the document
712
- * when it is needed for the placeholder purposes.
713
- */ _fixBodyElement(writer) {
714
- let changed = false;
715
- for (const rootName of this.editor.model.document.getRootNames()){
716
- const modelRoot = this.editor.model.document.getRoot(rootName);
717
- if (modelRoot.childCount < 2) {
718
- const placeholder = writer.createElement('paragraph');
719
- writer.insert(placeholder, modelRoot, 1);
720
- this._bodyPlaceholder.set(rootName, placeholder);
721
- changed = true;
722
- }
723
- }
724
- return changed;
725
- }
726
- /**
727
- * Model post-fixer callback that removes a paragraph from the end of the document
728
- * if it was created for the placeholder purposes and is not needed anymore.
729
- */ _fixExtraParagraph(writer) {
730
- let changed = false;
731
- for (const rootName of this.editor.model.document.getRootNames()){
732
- const root = this.editor.model.document.getRoot(rootName);
733
- const placeholder = this._bodyPlaceholder.get(rootName);
734
- if (shouldRemoveLastParagraph(placeholder, root)) {
735
- this._bodyPlaceholder.delete(rootName);
736
- writer.remove(placeholder);
737
- changed = true;
738
- }
739
- }
740
- return changed;
741
- }
742
- /**
743
- * Attaches the `Title` and `Body` placeholders to the title and/or content.
744
- */ _attachPlaceholders() {
745
- const editor = this.editor;
746
- const t = editor.t;
747
- const view = editor.editing.view;
748
- const sourceElement = editor.sourceElement;
749
- const titlePlaceholder = editor.config.get('title.placeholder') || t('Type your title');
750
- // Attach placeholder to the view title element.
751
- editor.editing.downcastDispatcher.on('insert:title-content', (evt, data, conversionApi)=>{
752
- const element = conversionApi.mapper.toViewElement(data.item);
753
- element.placeholder = titlePlaceholder;
754
- enableViewPlaceholder({
755
- view,
756
- element,
757
- keepOnFocus: true
758
- });
759
- });
760
- // Attach placeholder to first element after a title element and remove it if it's not needed anymore.
761
- // First element after title can change, so we need to observe all changes keep placeholder in sync.
762
- const bodyViewElements = new Map();
763
- // This post-fixer runs after the model post-fixer, so we can assume that the second child in view root will always exist.
764
- view.document.registerPostFixer((writer)=>{
765
- let hasChanged = false;
766
- for (const viewRoot of view.document.roots){
767
- // `viewRoot` can be empty despite the model post-fixers if the model root was detached.
768
- if (viewRoot.isEmpty) {
769
- continue;
770
- }
771
- // If `viewRoot` is not empty, then we can expect at least two elements in it.
772
- const body = viewRoot.getChild(1);
773
- const oldBody = bodyViewElements.get(viewRoot.rootName);
774
- // If body element has changed we need to disable placeholder on the previous element and enable on the new one.
775
- if (body !== oldBody) {
776
- if (oldBody) {
777
- hideViewPlaceholder(writer, oldBody);
778
- writer.removeAttribute('data-placeholder', oldBody);
779
- }
780
- const bodyPlaceholder = editor.config.get('roots')[viewRoot.rootName]?.placeholder || isTextArea(sourceElement) && sourceElement.getAttribute('placeholder') || t('Type or paste your content here.');
781
- writer.setAttribute('data-placeholder', bodyPlaceholder, body);
782
- bodyViewElements.set(viewRoot.rootName, body);
783
- hasChanged = true;
784
- }
785
- // Then we need to display placeholder if it is needed.
786
- // See: https://github.com/ckeditor/ckeditor5/issues/8689.
787
- if (needsViewPlaceholder(body, true) && viewRoot.childCount === 2 && body.name === 'p') {
788
- hasChanged = showViewPlaceholder(writer, body) ? true : hasChanged;
789
- } else {
790
- // Or hide if it is not needed.
791
- hasChanged = hideViewPlaceholder(writer, body) ? true : hasChanged;
792
- }
793
- }
794
- return hasChanged;
795
- });
796
- }
797
- /**
798
- * Creates navigation between the title and body sections using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.
799
- */ _attachTabPressHandling() {
800
- const editor = this.editor;
801
- const model = editor.model;
802
- // Pressing <kbd>Tab</kbd> inside the title should move the caret to the body.
803
- editor.keystrokes.set('TAB', (data, cancel)=>{
804
- model.change((writer)=>{
805
- const selection = model.document.selection;
806
- const selectedElements = Array.from(selection.getSelectedBlocks());
807
- if (selectedElements.length === 1 && selectedElements[0].is('element', 'title-content')) {
808
- const root = selection.getFirstPosition().root;
809
- const firstBodyElement = root.getChild(1);
810
- writer.setSelection(firstBodyElement, 0);
811
- cancel();
812
- }
813
- });
814
- });
815
- // Pressing <kbd>Shift</kbd>+<kbd>Tab</kbd> at the beginning of the body should move the caret to the title.
816
- editor.keystrokes.set('SHIFT + TAB', (data, cancel)=>{
817
- model.change((writer)=>{
818
- const selection = model.document.selection;
819
- if (!selection.isCollapsed) {
820
- return;
821
- }
822
- const selectedElement = first(selection.getSelectedBlocks());
823
- const selectionPosition = selection.getFirstPosition();
824
- const root = editor.model.document.getRoot(selectionPosition.root.rootName);
825
- const title = root.getChild(0);
826
- const body = root.getChild(1);
827
- if (selectedElement === body && selectionPosition.isAtStart) {
828
- writer.setSelection(title.getChild(0), 0);
829
- cancel();
830
- }
831
- });
832
- });
833
- }
834
- }
487
+ * The Title plugin.
488
+ *
489
+ * It splits the document into `Title` and `Body` sections.
490
+ */
491
+ var Title = class extends Plugin {
492
+ /**
493
+ * A reference to an empty paragraph in the body
494
+ * created when there is no element in the body for the placeholder purposes.
495
+ */
496
+ _bodyPlaceholder = /* @__PURE__ */ new Map();
497
+ /**
498
+ * @inheritDoc
499
+ */
500
+ static get pluginName() {
501
+ return "Title";
502
+ }
503
+ /**
504
+ * @inheritDoc
505
+ */
506
+ static get isOfficialPlugin() {
507
+ return true;
508
+ }
509
+ /**
510
+ * @inheritDoc
511
+ */
512
+ static get requires() {
513
+ return [Paragraph];
514
+ }
515
+ /**
516
+ * @inheritDoc
517
+ */
518
+ init() {
519
+ const editor = this.editor;
520
+ const model = editor.model;
521
+ model.schema.register("title", {
522
+ isBlock: true,
523
+ allowIn: "$root"
524
+ });
525
+ model.schema.register("title-content", {
526
+ isBlock: true,
527
+ allowIn: "title",
528
+ allowAttributes: ["alignment"]
529
+ });
530
+ model.schema.extend("$text", { allowIn: "title-content" });
531
+ model.schema.addAttributeCheck((context) => {
532
+ if (context.endsWith("title-content $text")) return false;
533
+ });
534
+ editor.editing.mapper.on("modelToViewPosition", mapModelPositionToView(editor.editing.view));
535
+ editor.data.mapper.on("modelToViewPosition", mapModelPositionToView(editor.editing.view));
536
+ editor.conversion.for("downcast").elementToElement({
537
+ model: "title-content",
538
+ view: "h1"
539
+ });
540
+ editor.conversion.for("downcast").add((dispatcher) => dispatcher.on("insert:title", (evt, data, conversionApi) => {
541
+ conversionApi.consumable.consume(data.item, evt.name);
542
+ }));
543
+ editor.data.upcastDispatcher.on("element:h1", dataViewModelH1Insertion, { priority: "high" });
544
+ editor.data.upcastDispatcher.on("element:h2", dataViewModelH1Insertion, { priority: "high" });
545
+ editor.data.upcastDispatcher.on("element:h3", dataViewModelH1Insertion, { priority: "high" });
546
+ model.document.registerPostFixer((writer) => this._fixTitleContent(writer));
547
+ model.document.registerPostFixer((writer) => this._fixTitleElement(writer));
548
+ model.document.registerPostFixer((writer) => this._fixBodyElement(writer));
549
+ model.document.registerPostFixer((writer) => this._fixExtraParagraph(writer));
550
+ this._attachPlaceholders();
551
+ this._attachTabPressHandling();
552
+ this._warnIfNoSupportedRoot();
553
+ }
554
+ /**
555
+ * Logs a single warning when none of the editor's roots can host the title structure. The Title feature
556
+ * only operates on roots whose `modelElement` is the default `$root`; roots configured with a custom
557
+ * `modelElement` are silently skipped at runtime. If no root supports the structure, the plugin is
558
+ * effectively a no-op and the integrator likely wants to know.
559
+ */
560
+ _warnIfNoSupportedRoot() {
561
+ const model = this.editor.model;
562
+ for (const root of model.document.getRoots()) if (model.schema.checkChild(root, "title")) return;
563
+ /**
564
+ * The Title feature was loaded, but none of the editor's roots supports the `title` element. The feature
565
+ * only operates on roots whose `modelElement` is the default `$root`; roots configured with a custom
566
+ * `modelElement` (including `$inlineRoot`) are silently skipped, so `getTitle()` / `getBody()` fall back
567
+ * to the regular data getter and no title structure is ever inserted.
568
+ *
569
+ * To use the Title feature, ensure at least one root uses the default `$root` model element. Otherwise,
570
+ * remove the Title plugin from this editor's plugin list.
571
+ *
572
+ * @error title-no-supported-root
573
+ */
574
+ logWarning("title-no-supported-root");
575
+ }
576
+ /**
577
+ * Returns the title of the document. Note that because this plugin does not allow any formatting inside
578
+ * the title element, the output of this method will be a plain text, with no HTML tags.
579
+ *
580
+ * It is not recommended to use this method together with features that insert markers to the
581
+ * data output, like comments or track changes features. If such markers start in the title and end in the
582
+ * body, the result of this method might be incorrect.
583
+ *
584
+ * @param options Additional configuration passed to the conversion process.
585
+ * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
586
+ * @returns The title of the document.
587
+ */
588
+ getTitle(options = {}) {
589
+ const rootName = options.rootName ? options.rootName : void 0;
590
+ const titleElement = this._getTitleElement(rootName);
591
+ if (!titleElement) return "";
592
+ const titleContentElement = titleElement.getChild(0);
593
+ return this.editor.data.stringify(titleContentElement, options);
594
+ }
595
+ /**
596
+ * Returns the body of the document.
597
+ *
598
+ * Note that it is not recommended to use this method together with features that insert markers to the
599
+ * data output, like comments or track changes features. If such markers start in the title and end in the
600
+ * body, the result of this method might be incorrect.
601
+ *
602
+ * @param options Additional configuration passed to the conversion process.
603
+ * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
604
+ * @returns The body of the document.
605
+ */
606
+ getBody(options = {}) {
607
+ const editor = this.editor;
608
+ const data = editor.data;
609
+ const model = editor.model;
610
+ const rootName = options.rootName ? options.rootName : void 0;
611
+ const root = editor.model.document.getRoot(rootName);
612
+ if (!model.schema.checkChild(root, "title")) return data.get({
613
+ ...options,
614
+ rootName: root.rootName
615
+ });
616
+ const firstChild = root.getChild(0);
617
+ if (!firstChild || !firstChild.is("element", "title")) return "";
618
+ const view = editor.editing.view;
619
+ const viewWriter = new ViewDowncastWriter(view.document);
620
+ const rootRange = model.createRangeIn(root);
621
+ const viewDocumentFragment = viewWriter.createDocumentFragment();
622
+ const bodyStartPosition = model.createPositionAfter(firstChild);
623
+ const bodyRange = model.createRange(bodyStartPosition, model.createPositionAt(root, "end"));
624
+ const markers = /* @__PURE__ */ new Map();
625
+ for (const marker of model.markers) {
626
+ const intersection = bodyRange.getIntersection(marker.getRange());
627
+ if (intersection) markers.set(marker.name, intersection);
628
+ }
629
+ data.mapper.clearBindings();
630
+ data.mapper.bindElements(root, viewDocumentFragment);
631
+ data.downcastDispatcher.convert(rootRange, markers, viewWriter, options);
632
+ viewWriter.remove(viewWriter.createRangeOn(viewDocumentFragment.getChild(0)));
633
+ return editor.data.processor.toData(viewDocumentFragment);
634
+ }
635
+ /**
636
+ * Returns the `title` element when it is in the document. Returns `undefined` otherwise.
637
+ */
638
+ _getTitleElement(rootName) {
639
+ const model = this.editor.model;
640
+ const root = model.document.getRoot(rootName);
641
+ if (!model.schema.checkChild(root, "title")) return;
642
+ for (const child of root.getChildren()) if (isTitle(child)) return child;
643
+ }
644
+ /**
645
+ * Model post-fixer callback that ensures that `title` has only one `title-content` child.
646
+ * All additional children should be moved after the `title` element and renamed to a paragraph.
647
+ */
648
+ _fixTitleContent(writer) {
649
+ let changed = false;
650
+ for (const rootName of this.editor.model.document.getRootNames()) {
651
+ const title = this._getTitleElement(rootName);
652
+ if (!title || title.maxOffset === 1) continue;
653
+ const titleChildren = Array.from(title.getChildren());
654
+ titleChildren.shift();
655
+ for (const titleChild of titleChildren) {
656
+ writer.move(writer.createRangeOn(titleChild), title, "after");
657
+ writer.rename(titleChild, "paragraph");
658
+ }
659
+ changed = true;
660
+ }
661
+ return changed;
662
+ }
663
+ /**
664
+ * Model post-fixer callback that creates a title element when it is missing,
665
+ * takes care of the correct position of it and removes additional title elements.
666
+ */
667
+ _fixTitleElement(writer) {
668
+ let changed = false;
669
+ const model = this.editor.model;
670
+ for (const modelRoot of this.editor.model.document.getRoots()) {
671
+ if (!model.schema.checkChild(modelRoot, "title")) continue;
672
+ const titleElements = Array.from(modelRoot.getChildren()).filter(isTitle);
673
+ const firstTitleElement = titleElements[0];
674
+ const firstRootChild = modelRoot.getChild(0);
675
+ if (firstRootChild.is("element", "title")) {
676
+ if (titleElements.length > 1) {
677
+ fixAdditionalTitleElements(titleElements, writer, model);
678
+ changed = true;
679
+ }
680
+ continue;
681
+ }
682
+ if (!firstTitleElement && !titleLikeElements.has(firstRootChild.name)) {
683
+ const title = writer.createElement("title");
684
+ writer.insert(title, modelRoot);
685
+ writer.insertElement("title-content", title);
686
+ changed = true;
687
+ continue;
688
+ }
689
+ if (titleLikeElements.has(firstRootChild.name)) changeElementToTitle(firstRootChild, writer, model);
690
+ else writer.move(writer.createRangeOn(firstTitleElement), modelRoot, 0);
691
+ fixAdditionalTitleElements(titleElements, writer, model);
692
+ changed = true;
693
+ }
694
+ return changed;
695
+ }
696
+ /**
697
+ * Model post-fixer callback that adds an empty paragraph at the end of the document
698
+ * when it is needed for the placeholder purposes.
699
+ */
700
+ _fixBodyElement(writer) {
701
+ const schema = this.editor.model.schema;
702
+ let changed = false;
703
+ for (const rootName of this.editor.model.document.getRootNames()) {
704
+ const modelRoot = this.editor.model.document.getRoot(rootName);
705
+ if (modelRoot.childCount < 2 && schema.checkChild(modelRoot, "title")) {
706
+ const placeholder = writer.createElement("paragraph");
707
+ writer.insert(placeholder, modelRoot, 1);
708
+ this._bodyPlaceholder.set(rootName, placeholder);
709
+ changed = true;
710
+ }
711
+ }
712
+ return changed;
713
+ }
714
+ /**
715
+ * Model post-fixer callback that removes a paragraph from the end of the document
716
+ * if it was created for the placeholder purposes and is not needed anymore.
717
+ */
718
+ _fixExtraParagraph(writer) {
719
+ let changed = false;
720
+ for (const rootName of this.editor.model.document.getRootNames()) {
721
+ const root = this.editor.model.document.getRoot(rootName);
722
+ const placeholder = this._bodyPlaceholder.get(rootName);
723
+ if (!placeholder) continue;
724
+ if (shouldRemoveLastParagraph(placeholder, root)) {
725
+ this._bodyPlaceholder.delete(rootName);
726
+ writer.remove(placeholder);
727
+ changed = true;
728
+ }
729
+ }
730
+ return changed;
731
+ }
732
+ /**
733
+ * Attaches the `Title` and `Body` placeholders to the title and/or content.
734
+ */
735
+ _attachPlaceholders() {
736
+ const editor = this.editor;
737
+ const t = editor.t;
738
+ const view = editor.editing.view;
739
+ const sourceElement = editor.sourceElement;
740
+ const titlePlaceholder = editor.config.get("title.placeholder") || t("Type your title");
741
+ editor.editing.downcastDispatcher.on("insert:title-content", (evt, data, conversionApi) => {
742
+ const element = conversionApi.mapper.toViewElement(data.item);
743
+ element.placeholder = titlePlaceholder;
744
+ enableViewPlaceholder({
745
+ view,
746
+ element,
747
+ keepOnFocus: true
748
+ });
749
+ });
750
+ const bodyViewElements = /* @__PURE__ */ new Map();
751
+ view.document.registerPostFixer((writer) => {
752
+ let hasChanged = false;
753
+ for (const viewRoot of view.document.roots) {
754
+ if (viewRoot.isEmpty) continue;
755
+ const modelRoot = editor.editing.mapper.toModelElement(viewRoot);
756
+ if (!editor.model.schema.checkChild(modelRoot, "title")) continue;
757
+ const body = viewRoot.getChild(1);
758
+ const oldBody = bodyViewElements.get(viewRoot.rootName);
759
+ if (body !== oldBody) {
760
+ if (oldBody) {
761
+ hideViewPlaceholder(writer, oldBody);
762
+ writer.removeAttribute("data-placeholder", oldBody);
763
+ }
764
+ const bodyPlaceholder = editor.config.get("roots")[viewRoot.rootName]?.placeholder || isTextArea(sourceElement) && sourceElement.getAttribute("placeholder") || t("Type or paste your content here.");
765
+ writer.setAttribute("data-placeholder", bodyPlaceholder, body);
766
+ bodyViewElements.set(viewRoot.rootName, body);
767
+ hasChanged = true;
768
+ }
769
+ if (needsViewPlaceholder(body, true) && viewRoot.childCount === 2 && body.name === "p") hasChanged = showViewPlaceholder(writer, body) ? true : hasChanged;
770
+ else hasChanged = hideViewPlaceholder(writer, body) ? true : hasChanged;
771
+ }
772
+ return hasChanged;
773
+ });
774
+ }
775
+ /**
776
+ * Creates navigation between the title and body sections using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.
777
+ */
778
+ _attachTabPressHandling() {
779
+ const editor = this.editor;
780
+ const model = editor.model;
781
+ editor.keystrokes.set("TAB", (data, cancel) => {
782
+ model.change((writer) => {
783
+ const selection = model.document.selection;
784
+ const selectedElements = Array.from(selection.getSelectedBlocks());
785
+ if (selectedElements.length === 1 && selectedElements[0].is("element", "title-content")) {
786
+ const firstBodyElement = selection.getFirstPosition().root.getChild(1);
787
+ writer.setSelection(firstBodyElement, 0);
788
+ cancel();
789
+ }
790
+ });
791
+ });
792
+ editor.keystrokes.set("SHIFT + TAB", (data, cancel) => {
793
+ model.change((writer) => {
794
+ const selection = model.document.selection;
795
+ if (!selection.isCollapsed) return;
796
+ const selectedElement = first(selection.getSelectedBlocks());
797
+ const selectionPosition = selection.getFirstPosition();
798
+ const root = editor.model.document.getRoot(selectionPosition.root.rootName);
799
+ if (!model.schema.checkChild(root, "title")) return;
800
+ const title = root.getChild(0);
801
+ if (selectedElement === root.getChild(1) && selectionPosition.isAtStart) {
802
+ writer.setSelection(title.getChild(0), 0);
803
+ cancel();
804
+ }
805
+ });
806
+ });
807
+ }
808
+ };
835
809
  /**
836
- * A view-to-model converter for the h1 that appears at the beginning of the document (a title element).
837
- *
838
- * @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
839
- * @param evt An object containing information about the fired event.
840
- * @param data An object containing conversion input, a placeholder for conversion output and possibly other values.
841
- * @param conversionApi Conversion interface to be used by the callback.
842
- */ function dataViewModelH1Insertion(evt, data, conversionApi) {
843
- const modelCursor = data.modelCursor;
844
- const viewItem = data.viewItem;
845
- if (!modelCursor.isAtStart || !modelCursor.parent.is('element', '$root')) {
846
- return;
847
- }
848
- if (!conversionApi.consumable.consume(viewItem, {
849
- name: true
850
- })) {
851
- return;
852
- }
853
- const modelWriter = conversionApi.writer;
854
- const title = modelWriter.createElement('title');
855
- const titleContent = modelWriter.createElement('title-content');
856
- modelWriter.append(titleContent, title);
857
- modelWriter.insert(title, modelCursor);
858
- conversionApi.convertChildren(viewItem, titleContent);
859
- conversionApi.updateConversionResult(title, data);
810
+ * A view-to-model converter for the h1 that appears at the beginning of the document (a title element).
811
+ *
812
+ * Matches only the synthetic upcast parent named `$root` (the default generic root element). Title is not supported
813
+ * for roots whose `modelElement` is customized, so this converter intentionally does not fire on them.
814
+ *
815
+ * @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
816
+ * @param evt An object containing information about the fired event.
817
+ * @param data An object containing conversion input, a placeholder for conversion output and possibly other values.
818
+ * @param conversionApi Conversion interface to be used by the callback.
819
+ */
820
+ function dataViewModelH1Insertion(evt, data, conversionApi) {
821
+ const modelCursor = data.modelCursor;
822
+ const viewItem = data.viewItem;
823
+ if (!modelCursor.isAtStart || !modelCursor.parent.is("element", "$root")) return;
824
+ if (!conversionApi.consumable.consume(viewItem, { name: true })) return;
825
+ const modelWriter = conversionApi.writer;
826
+ const title = modelWriter.createElement("title");
827
+ const titleContent = modelWriter.createElement("title-content");
828
+ modelWriter.append(titleContent, title);
829
+ modelWriter.insert(title, modelCursor);
830
+ conversionApi.convertChildren(viewItem, titleContent);
831
+ conversionApi.updateConversionResult(title, data);
860
832
  }
861
833
  /**
862
- * Maps position from the beginning of the model `title` element to the beginning of the view `h1` element.
863
- *
864
- * ```html
865
- * <title>^<title-content>Foo</title-content></title> -> <h1>^Foo</h1>
866
- * ```
867
- */ function mapModelPositionToView(editingView) {
868
- return (evt, data)=>{
869
- const positionParent = data.modelPosition.parent;
870
- if (!positionParent.is('element', 'title')) {
871
- return;
872
- }
873
- const modelTitleElement = positionParent.parent;
874
- const viewElement = data.mapper.toViewElement(modelTitleElement);
875
- data.viewPosition = editingView.createPositionAt(viewElement, 0);
876
- evt.stop();
877
- };
834
+ * Maps position from the beginning of the model `title` element to the beginning of the view `h1` element.
835
+ *
836
+ * ```html
837
+ * <title>^<title-content>Foo</title-content></title> -> <h1>^Foo</h1>
838
+ * ```
839
+ */
840
+ function mapModelPositionToView(editingView) {
841
+ return (evt, data) => {
842
+ const positionParent = data.modelPosition.parent;
843
+ if (!positionParent.is("element", "title")) return;
844
+ const modelTitleElement = positionParent.parent;
845
+ const viewElement = data.mapper.toViewElement(modelTitleElement);
846
+ data.viewPosition = editingView.createPositionAt(viewElement, 0);
847
+ evt.stop();
848
+ };
878
849
  }
879
850
  /**
880
- * @returns Returns true when given element is a title. Returns false otherwise.
881
- */ function isTitle(element) {
882
- return element.is('element', 'title');
851
+ * @returns Returns true when given element is a title. Returns false otherwise.
852
+ */
853
+ function isTitle(element) {
854
+ return element.is("element", "title");
883
855
  }
884
856
  /**
885
- * Changes the given element to the title element.
886
- */ function changeElementToTitle(element, writer, model) {
887
- const title = writer.createElement('title');
888
- writer.insert(title, element, 'before');
889
- writer.insert(element, title, 0);
890
- writer.rename(element, 'title-content');
891
- model.schema.removeDisallowedAttributes([
892
- element
893
- ], writer);
857
+ * Changes the given element to the title element.
858
+ */
859
+ function changeElementToTitle(element, writer, model) {
860
+ const title = writer.createElement("title");
861
+ writer.insert(title, element, "before");
862
+ writer.insert(element, title, 0);
863
+ writer.rename(element, "title-content");
864
+ model.schema.removeDisallowedAttributes([element], writer);
894
865
  }
895
866
  /**
896
- * Loops over the list of title elements and fixes additional ones.
897
- *
898
- * @returns Returns true when there was any change. Returns false otherwise.
899
- */ function fixAdditionalTitleElements(titleElements, writer, model) {
900
- let hasChanged = false;
901
- for (const title of titleElements){
902
- if (title.index !== 0) {
903
- fixTitleElement(title, writer, model);
904
- hasChanged = true;
905
- }
906
- }
907
- return hasChanged;
867
+ * Loops over the list of title elements and fixes additional ones.
868
+ *
869
+ * @returns Returns true when there was any change. Returns false otherwise.
870
+ */
871
+ function fixAdditionalTitleElements(titleElements, writer, model) {
872
+ let hasChanged = false;
873
+ for (const title of titleElements) if (title.index !== 0) {
874
+ fixTitleElement(title, writer, model);
875
+ hasChanged = true;
876
+ }
877
+ return hasChanged;
908
878
  }
909
879
  /**
910
- * Changes given title element to a paragraph or removes it when it is empty.
911
- */ function fixTitleElement(title, writer, model) {
912
- const child = title.getChild(0);
913
- // Empty title should be removed.
914
- // It is created as a result of pasting to the title element.
915
- if (child.isEmpty) {
916
- writer.remove(title);
917
- return;
918
- }
919
- writer.move(writer.createRangeOn(child), title, 'before');
920
- writer.rename(child, 'paragraph');
921
- writer.remove(title);
922
- model.schema.removeDisallowedAttributes([
923
- child
924
- ], writer);
880
+ * Changes given title element to a paragraph or removes it when it is empty.
881
+ */
882
+ function fixTitleElement(title, writer, model) {
883
+ const child = title.getChild(0);
884
+ if (child.isEmpty) {
885
+ writer.remove(title);
886
+ return;
887
+ }
888
+ writer.move(writer.createRangeOn(child), title, "before");
889
+ writer.rename(child, "paragraph");
890
+ writer.remove(title);
891
+ model.schema.removeDisallowedAttributes([child], writer);
925
892
  }
926
893
  /**
927
- * Returns true when the last paragraph in the document was created only for the placeholder
928
- * purpose and it's not needed anymore. Returns false otherwise.
929
- */ function shouldRemoveLastParagraph(placeholder, root) {
930
- if (!placeholder || !placeholder.is('element', 'paragraph') || placeholder.childCount) {
931
- return false;
932
- }
933
- if (root.childCount <= 2 || root.getChild(root.childCount - 1) !== placeholder) {
934
- return false;
935
- }
936
- return true;
894
+ * Returns true when the last paragraph in the document was created only for the placeholder
895
+ * purpose and it's not needed anymore. Returns false otherwise.
896
+ */
897
+ function shouldRemoveLastParagraph(placeholder, root) {
898
+ if (!placeholder.is("element", "paragraph") || placeholder.childCount) return false;
899
+ if (root.childCount <= 2 || root.getChild(root.childCount - 1) !== placeholder) return false;
900
+ return true;
937
901
  }
938
902
  /**
939
- * Returns true when given element is a DOM textarea.
940
- */ function isTextArea(sourceElement) {
941
- return !!sourceElement && sourceElement.tagName.toLowerCase() === 'textarea';
903
+ * Returns true when given element is a DOM textarea.
904
+ */
905
+ function isTextArea(sourceElement) {
906
+ return !!sourceElement && sourceElement.tagName.toLowerCase() === "textarea";
942
907
  }
943
908
 
909
+ /**
910
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
911
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
912
+ */
913
+
944
914
  export { Heading, HeadingButtonsUI, HeadingCommand, HeadingEditing, HeadingUI, Title, getLocalizedOptions as _getLocalizedHeadingOptions };
945
- //# sourceMappingURL=index.js.map
915
+ //# sourceMappingURL=index.js.map