1 | /**
|
2 | * @license Copyright (c) 2003-2024, 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/title
|
7 | */
|
8 | import { Plugin } from 'ckeditor5/src/core.js';
|
9 | /**
|
10 | * The Title plugin.
|
11 | *
|
12 | * It splits the document into `Title` and `Body` sections.
|
13 | */
|
14 | export default class Title extends Plugin {
|
15 | /**
|
16 | * A reference to an empty paragraph in the body
|
17 | * created when there is no element in the body for the placeholder purposes.
|
18 | */
|
19 | private _bodyPlaceholder;
|
20 | /**
|
21 | * @inheritDoc
|
22 | */
|
23 | static get pluginName(): "Title";
|
24 | /**
|
25 | * @inheritDoc
|
26 | */
|
27 | static get isOfficialPlugin(): true;
|
28 | /**
|
29 | * @inheritDoc
|
30 | */
|
31 | static get requires(): readonly ["Paragraph"];
|
32 | /**
|
33 | * @inheritDoc
|
34 | */
|
35 | init(): void;
|
36 | /**
|
37 | * Returns the title of the document. Note that because this plugin does not allow any formatting inside
|
38 | * the title element, the output of this method will be a plain text, with no HTML tags.
|
39 | *
|
40 | * It is not recommended to use this method together with features that insert markers to the
|
41 | * data output, like comments or track changes features. If such markers start in the title and end in the
|
42 | * body, the result of this method might be incorrect.
|
43 | *
|
44 | * @param options Additional configuration passed to the conversion process.
|
45 | * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
|
46 | * @returns The title of the document.
|
47 | */
|
48 | getTitle(options?: Record<string, unknown>): string;
|
49 | /**
|
50 | * Returns the body of the document.
|
51 | *
|
52 | * Note that it is not recommended to use this method together with features that insert markers to the
|
53 | * data output, like comments or track changes features. If such markers start in the title and end in the
|
54 | * body, the result of this method might be incorrect.
|
55 | *
|
56 | * @param options Additional configuration passed to the conversion process.
|
57 | * See {@link module:engine/controller/datacontroller~DataController#get `DataController#get`}.
|
58 | * @returns The body of the document.
|
59 | */
|
60 | getBody(options?: Record<string, unknown>): string;
|
61 | /**
|
62 | * Returns the `title` element when it is in the document. Returns `undefined` otherwise.
|
63 | */
|
64 | private _getTitleElement;
|
65 | /**
|
66 | * Model post-fixer callback that ensures that `title` has only one `title-content` child.
|
67 | * All additional children should be moved after the `title` element and renamed to a paragraph.
|
68 | */
|
69 | private _fixTitleContent;
|
70 | /**
|
71 | * Model post-fixer callback that creates a title element when it is missing,
|
72 | * takes care of the correct position of it and removes additional title elements.
|
73 | */
|
74 | private _fixTitleElement;
|
75 | /**
|
76 | * Model post-fixer callback that adds an empty paragraph at the end of the document
|
77 | * when it is needed for the placeholder purposes.
|
78 | */
|
79 | private _fixBodyElement;
|
80 | /**
|
81 | * Model post-fixer callback that removes a paragraph from the end of the document
|
82 | * if it was created for the placeholder purposes and is not needed anymore.
|
83 | */
|
84 | private _fixExtraParagraph;
|
85 | /**
|
86 | * Attaches the `Title` and `Body` placeholders to the title and/or content.
|
87 | */
|
88 | private _attachPlaceholders;
|
89 | /**
|
90 | * Creates navigation between the title and body sections using <kbd>Tab</kbd> and <kbd>Shift</kbd>+<kbd>Tab</kbd> keys.
|
91 | */
|
92 | private _attachTabPressHandling;
|
93 | }
|
94 | /**
|
95 | * The configuration of the {@link module:heading/title~Title title feature}.
|
96 | *
|
97 | * ```ts
|
98 | * ClassicEditor
|
99 | * .create( document.querySelector( '#editor' ), {
|
100 | * plugins: [ Title, ... ],
|
101 | * title: {
|
102 | * placeholder: 'My custom placeholder for the title'
|
103 | * },
|
104 | * placeholder: 'My custom placeholder for the body'
|
105 | * } )
|
106 | * .then( ... )
|
107 | * .catch( ... );
|
108 | * ```
|
109 | *
|
110 | * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
|
111 | */
|
112 | export interface TitleConfig {
|
113 | /**
|
114 | * Defines a custom value of the placeholder for the title field.
|
115 | *
|
116 | * Read more in {@link module:heading/title~TitleConfig}.
|
117 | */
|
118 | placeholder?: string;
|
119 | }
|