Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit a65c0ac

Browse files
authored
Merge pull request #130 from ckeditor/t/ckeditor5/2003
Feature: Introduced Title plugin. Closes ckeditor/ckeditor5#2003. Closes ckeditor/ckeditor5#2005.
2 parents b895460 + fbba254 commit a65c0ac

File tree

9 files changed

+1527
-0
lines changed

9 files changed

+1527
-0
lines changed

docs/_snippets/features/title.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<div id="snippet-title">
2+
</div>
3+
4+
<h3>Console</h3>
5+
6+
<pre><code class="title-console title-console__title">''</code></pre>
7+
<pre><code class="title-console title-console__body">''</code></pre>
8+
<pre><code class="title-console title-console__data">''</code></pre>
9+
10+
<style>
11+
#title-console {
12+
max-height: 300px;
13+
overflow: auto;
14+
white-space: normal;
15+
background: #2b2c26;
16+
margin-top: 20px;
17+
transition: background-color 500ms;
18+
}
19+
20+
#title-console.updated {
21+
background: green;
22+
}
23+
24+
.title-console__title,
25+
.title-console__body {
26+
margin-bottom: 10px;
27+
}
28+
29+
.title-console__title::before,
30+
.title-console__body::before,
31+
.title-console__data::before {
32+
display: inline-block;
33+
margin-right: 5px;
34+
opacity: 0.5;
35+
}
36+
37+
.title-console__title::before {
38+
content: 'Title:'
39+
}
40+
41+
.title-console__body::before {
42+
content: 'Body:'
43+
}
44+
45+
.title-console__data::before {
46+
content: 'Data:';
47+
}
48+
</style>

docs/_snippets/features/title.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4+
*/
5+
6+
/* globals console, window, document, setTimeout */
7+
8+
import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
9+
import Title from '@ckeditor/ckeditor5-heading/src/title';
10+
11+
import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';
12+
13+
ClassicEditor.builtinPlugins.push( Title );
14+
15+
ClassicEditor
16+
.create( document.querySelector( '#snippet-title' ), {
17+
cloudServices: CS_CONFIG
18+
} )
19+
.then( editor => {
20+
window.editor = editor;
21+
22+
const titlePlugin = editor.plugins.get( 'Title' );
23+
const titleConsole = new Console( document.querySelector( '.title-console__title' ) );
24+
const bodyConsole = new Console( document.querySelector( '.title-console__body' ) );
25+
const dataConsole = new Console( document.querySelector( '.title-console__data' ) );
26+
27+
editor.model.document.on( 'change:data', () => {
28+
titleConsole.update( titlePlugin.getTitle() );
29+
bodyConsole.update( titlePlugin.getBody() );
30+
dataConsole.update( editor.getData() );
31+
} );
32+
} )
33+
.catch( err => {
34+
console.error( err.stack );
35+
} );
36+
37+
class Console {
38+
constructor( element ) {
39+
this.element = element;
40+
this.consoleUpdates = 0;
41+
this.previousData = '';
42+
}
43+
44+
update( data ) {
45+
if ( this.previousData == data ) {
46+
return;
47+
}
48+
49+
this.previousData = data;
50+
51+
const element = this.element;
52+
53+
this.consoleUpdates++;
54+
55+
element.classList.add( 'updated' );
56+
element.textContent = `'${ data }'`;
57+
58+
setTimeout( () => {
59+
if ( --this.consoleUpdates == 0 ) {
60+
element.classList.remove( 'updated' );
61+
}
62+
}, 500 );
63+
}
64+
}

docs/features/title.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
category: features
3+
---
4+
5+
# Title
6+
7+
The {@link module:heading/title~Title title} feature adds support for the title field to your document. It makes sure that there will be always a single title field at the beginning of your document.
8+
9+
## Demo
10+
11+
{@snippet features/title}
12+
13+
## Keyboard navigation
14+
15+
Title plugin lets you navigate between title and body elements using <kbd>Tab</kbd> key and back, using <kbd>Shift</kbd> + <kbd>Tab</kbd> (when the selection is at the beginning of the first body element), providing form-like experience. You can also use <kbd>Enter</kbd> and <kbd>Backspace</kbd> keys to move caret between title and body.
16+
17+
## Placeholder integration
18+
19+
Title plugin is integrated with the {@link features/editor-placeholder placeholder} configuration. If you define it, it will be used as the placeholder for the body element.
20+
21+
## Installation
22+
23+
To add this feature to your editor, install the [`@ckeditor/ckeditor5-heading`](https://www.npmjs.com/package/@ckeditor/ckeditor5-heading) package:
24+
25+
```bash
26+
npm install --save @ckeditor/ckeditor5-heading
27+
```
28+
29+
Then add the `Title` plugin to your plugin list:
30+
31+
```js
32+
import Title from '@ckeditor/ckeditor5-heading/src/title';
33+
34+
ClassicEditor
35+
.create( document.querySelector( '#editor' ), {
36+
plugins: [ Title, ... ]
37+
} )
38+
.then( ... )
39+
.catch( ... );
40+
```
41+
42+
<info-box info>
43+
Read more about {@link builds/guides/integration/installing-plugins installing plugins}.
44+
</info-box>
45+

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
"@ckeditor/ckeditor5-utils": "^14.0.0"
1717
},
1818
"devDependencies": {
19+
"@ckeditor/ckeditor5-alignment": "^11.2.0",
20+
"@ckeditor/ckeditor5-basic-styles": "^11.1.4",
21+
"@ckeditor/ckeditor5-block-quote": "^11.1.3",
22+
"@ckeditor/ckeditor5-clipboard": "^12.0.2",
1923
"@ckeditor/ckeditor5-editor-classic": "^12.1.4",
2024
"@ckeditor/ckeditor5-engine": "^14.0.0",
2125
"@ckeditor/ckeditor5-enter": "^11.1.0",
2226
"@ckeditor/ckeditor5-image": "^14.0.0",
2327
"@ckeditor/ckeditor5-typing": "^12.2.0",
2428
"@ckeditor/ckeditor5-undo": "^11.0.5",
29+
"@ckeditor/ckeditor5-upload": "^12.0.0",
2530
"eslint": "^5.5.0",
2631
"eslint-config-ckeditor5": "^2.0.0",
2732
"husky": "^1.3.1",

0 commit comments

Comments
 (0)