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

Introduced Title plugin #130

Merged
merged 34 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
82fd357
Introduced Title plugin.
oskarwrobel Aug 28, 2019
c04659f
Added missing dev deps.
oskarwrobel Aug 28, 2019
b3bf397
Added missing dev deps.
oskarwrobel Aug 28, 2019
ee9467e
Fixed invalid import path.
oskarwrobel Aug 28, 2019
8e2639f
Disallow attributes in title.
oskarwrobel Aug 29, 2019
4a19242
Docs: title feature guide and snippet.
Aug 29, 2019
4520804
Remove broken links.
Aug 30, 2019
5cc7883
Small fixed in docs.
Aug 30, 2019
6e5ce6b
Changed model structure of title element to make it possible to contr…
oskarwrobel Sep 2, 2019
4a85217
Added missing dev dependency.
oskarwrobel Sep 2, 2019
21d1ec4
Added integration with EditorConfig#placeholder.
oskarwrobel Sep 2, 2019
8099525
Removed Enter from Title requienments.
oskarwrobel Sep 2, 2019
bf6a252
Minor improvements.
oskarwrobel Sep 2, 2019
9d70d35
Added missing headings to the list title-like elements. Changed the l…
oskarwrobel Sep 2, 2019
475c8f6
Simplified schema rules.
oskarwrobel Sep 2, 2019
d03c323
Minor improvements.
oskarwrobel Sep 2, 2019
93f629a
Used translation service for placeholders.
oskarwrobel Sep 2, 2019
65c2ffd
Docs.
oskarwrobel Sep 2, 2019
3865496
Improved code readability.
oskarwrobel Sep 2, 2019
32b7540
Added comment.
oskarwrobel Sep 2, 2019
14fee6d
Minor manual test improvements.
oskarwrobel Sep 2, 2019
5b0fec7
Enabled alignment feature.
oskarwrobel Sep 3, 2019
c03ba99
Add missing dev dependency.
oskarwrobel Sep 3, 2019
b015f2b
Handle multiple non title-like elements pasted before the title.
oskarwrobel Sep 3, 2019
00176c3
Filter out disallowed attributes from title-content element.
oskarwrobel Sep 3, 2019
0514a88
Tests improvements.
oskarwrobel Sep 3, 2019
3d61f01
Title.titleLikeElements docs.
jodator Sep 4, 2019
25d2e3b
Add explanatory comments.
jodator Sep 4, 2019
8ab1e9e
Added test case for existing title with title-like elements in the data.
jodator Sep 4, 2019
d587b39
Simplified post-fixers.
oskarwrobel Sep 4, 2019
454325d
Used first() util to get first selected block.
oskarwrobel Sep 4, 2019
0df59cd
Minor giude improvement.
oskarwrobel Sep 4, 2019
d12b0cd
Fix post-fixer that fixes extra paragraphs name.
jodator Sep 5, 2019
fbba254
Docs wording fixup.
jodator Sep 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/_snippets/features/title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div id="snippet-title">
</div>

<h3>Console</h3>

<pre><code class="title-console title-console__title">''</code></pre>
<pre><code class="title-console title-console__body">''</code></pre>
<pre><code class="title-console title-console__data">''</code></pre>

<style>
#title-console {
max-height: 300px;
overflow: auto;
white-space: normal;
background: #2b2c26;
margin-top: 20px;
transition: background-color 500ms;
}

#title-console.updated {
background: green;
}

.title-console__title,
.title-console__body {
margin-bottom: 10px;
}

.title-console__title::before,
.title-console__body::before,
.title-console__data::before {
display: inline-block;
margin-right: 5px;
opacity: 0.5;
}

.title-console__title::before {
content: 'Title:'
}

.title-console__body::before {
content: 'Body:'
}

.title-console__data::before {
content: 'Data:';
}
</style>
64 changes: 64 additions & 0 deletions docs/_snippets/features/title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals console, window, document, setTimeout */

import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
import Title from '@ckeditor/ckeditor5-heading/src/title';

import { CS_CONFIG } from '@ckeditor/ckeditor5-cloud-services/tests/_utils/cloud-services-config';

ClassicEditor.builtinPlugins.push( Title );

ClassicEditor
.create( document.querySelector( '#snippet-title' ), {
cloudServices: CS_CONFIG
} )
.then( editor => {
window.editor = editor;

const titlePlugin = editor.plugins.get( 'Title' );
const titleConsole = new Console( document.querySelector( '.title-console__title' ) );
const bodyConsole = new Console( document.querySelector( '.title-console__body' ) );
const dataConsole = new Console( document.querySelector( '.title-console__data' ) );

editor.model.document.on( 'change:data', () => {
titleConsole.update( titlePlugin.getTitle() );
bodyConsole.update( titlePlugin.getBody() );
dataConsole.update( editor.getData() );
} );
} )
.catch( err => {
console.error( err.stack );
} );

class Console {
constructor( element ) {
this.element = element;
this.consoleUpdates = 0;
this.previousData = '';
}

update( data ) {
if ( this.previousData == data ) {
return;
}

this.previousData = data;

const element = this.element;

this.consoleUpdates++;

element.classList.add( 'updated' );
element.textContent = `'${ data }'`;

setTimeout( () => {
if ( --this.consoleUpdates == 0 ) {
element.classList.remove( 'updated' );
}
}, 500 );
}
}
45 changes: 45 additions & 0 deletions docs/features/title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
category: features
---

# Title

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.

## Demo

{@snippet features/title}

## Keyboard navigation

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.

## Placeholder integration

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.
jodator marked this conversation as resolved.
Show resolved Hide resolved

## Installation

To add this feature to your editor, install the [`@ckeditor/ckeditor5-heading`](https://www.npmjs.com/package/@ckeditor/ckeditor5-heading) package:

```bash
npm install --save @ckeditor/ckeditor5-heading
```

Then add the `Title` plugin to your plugin list:

```js
import Title from '@ckeditor/ckeditor5-heading/src/title';

ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ Title, ... ]
} )
.then( ... )
.catch( ... );
```

<info-box info>
Read more about {@link builds/guides/integration/installing-plugins installing plugins}.
</info-box>

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
"@ckeditor/ckeditor5-utils": "^14.0.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-alignment": "^11.2.0",
"@ckeditor/ckeditor5-basic-styles": "^11.1.4",
"@ckeditor/ckeditor5-block-quote": "^11.1.3",
"@ckeditor/ckeditor5-clipboard": "^12.0.2",
"@ckeditor/ckeditor5-editor-classic": "^12.1.4",
"@ckeditor/ckeditor5-engine": "^14.0.0",
"@ckeditor/ckeditor5-enter": "^11.1.0",
"@ckeditor/ckeditor5-image": "^14.0.0",
"@ckeditor/ckeditor5-typing": "^12.2.0",
"@ckeditor/ckeditor5-undo": "^11.0.5",
"@ckeditor/ckeditor5-upload": "^12.0.0",
"eslint": "^5.5.0",
"eslint-config-ckeditor5": "^2.0.0",
"husky": "^1.3.1",
Expand Down
Loading