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

T/1: The basic media embed feature #2

Merged
merged 47 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2e5d3fd
The first implementation of the feature.
oleq Aug 1, 2018
1b22e29
Tests: Added MediaEmbed and InsertMediaCommand tests.
oleq Aug 6, 2018
b677475
Tests: Added MediaEmbedUI tests.
oleq Aug 6, 2018
f9cd2c2
Tests: Added tests for the MediaFormView.
oleq Aug 7, 2018
b93f5b0
Tests: Extended MediaEmbedEditing tests.
oleq Aug 7, 2018
d7c62a5
Tests: Added tests for the default config.mediaEmbed.media.
oleq Aug 7, 2018
6fd1dbe
Updated dependencies in package.json.
oleq Aug 7, 2018
77f3cae
Fixed broken import paths in the MediaFormView class file.
oleq Aug 7, 2018
5e1f5d9
Fixed broken import paths in the MediaFormView class file.
oleq Aug 7, 2018
ca2731b
Tests: Normalized the HTML in test cases to let tests pass in differe…
oleq Aug 7, 2018
b2bf14f
Updated travis.yml.
oleq Aug 7, 2018
3b552d5
Extended media embed to support non-previewable providers.
oleq Aug 8, 2018
c9b86f1
Added a couple more generic providers.
oleq Aug 8, 2018
2ad77af
Added 'any' default provider.
oleq Aug 9, 2018
8c074aa
Code refactoring.
oleq Aug 9, 2018
50f0790
Code refactoring.
oleq Aug 9, 2018
e17328e
Used the <oembed> element in data for embeds without preview or when …
oleq Aug 10, 2018
d57a5b1
Code refactoring.
oleq Aug 10, 2018
196e762
Removed the .ck-media__wrapper__aspect class; replaced with inline st…
oleq Aug 10, 2018
5233678
Fix: The generic media should have semantic representation in data.
oleq Aug 10, 2018
70c93e5
Docs: Extended docs and refactored the code.
oleq Aug 16, 2018
b89298d
Docs: Fixed broken links.
oleq Aug 16, 2018
ed8538d
Simplified media config.
oleq Aug 16, 2018
a92b7dd
Tests: Added missing upcast tests.
oleq Aug 16, 2018
6d35cb9
Removed a huge chunk of code because it looks like it's no longer nee…
oleq Aug 17, 2018
49db076
Docs: Fixed wrong path to the converters module.
oleq Aug 17, 2018
b3aa2ce
Docs: Implemented a basic guide in the 'Features' section.
oleq Aug 17, 2018
66cf092
Docs: Extended the guide.
oleq Aug 17, 2018
6da2ece
Docs: Cleaned–up the feature guide.
oleq Aug 20, 2018
7902b29
Docs: Introduced configuration docs.
oleq Aug 21, 2018
9fb472c
Tests: Aligned tests to the latest engine dev utils API.
oleq Aug 22, 2018
c215866
Renamed the command the UI component 'insertMedia'->'mediaEmbed'.
oleq Aug 22, 2018
0a76c71
Renamed InsertMediaCommand->MediaEmbedCommand.
oleq Aug 22, 2018
0388d39
Configured the content styles so media use all the available horizont…
oleq Aug 22, 2018
6165e96
Introduced new configuration options: 'providers', 'extraProviders' a…
oleq Aug 22, 2018
949eb94
Removed obsolete code from the MediaRegistry class.
oleq Aug 23, 2018
7b34a34
Added pkgs main API docs page.
Reinmar Aug 23, 2018
657ca3f
Docs: Extended the media-embed guide.
oleq Aug 23, 2018
e3eab68
Aligned travis.yml configuration syntax to the rest of the project.
oleq Aug 23, 2018
865211d
Some docs improvements.
Reinmar Aug 24, 2018
c3204ef
Added media placeholder tooltip. Code refactoring in media embed styles.
oleq Aug 24, 2018
f3b4faf
Tests: Used non-semantic data HTML in the non-semantic manual test.
oleq Aug 24, 2018
688bb36
Tests: Provided test scenario descriptions for manual tests.
oleq Aug 24, 2018
b2cfdb6
Docs.
Reinmar Aug 24, 2018
c50903f
Fixed gmaps provider name.
Reinmar Aug 24, 2018
eb5eb5d
Reverted a mistakenly commited line.
Reinmar Aug 24, 2018
e0dd71e
Fixed a link.
Reinmar Aug 24, 2018
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: required
dist: trusty
addons:
firefox: latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this. We unified the configs to not use " if not necessary (that's what travis encrypt does too).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We unified the configs to not use " if not necessary

And almost every repo uses "". I'm confused, should I use it or not?

(t/ckeditor5-media-embed/1 fcea342) oleq@MBP ~/ck/5/ckeditor5> mgit exec 'cat ./.travis.yml | grep firefox'
 #  @ckeditor/ckeditor5-adapter-ckfinder                                    1/38 (3%)
firefox: "latest"

 #  @ckeditor/ckeditor5-alignment                                           2/38 (5%)
firefox: "latest"

 #  @ckeditor/ckeditor5-autoformat                                          3/38 (8%)
firefox: "latest"

 #  @ckeditor/ckeditor5-autosave                                           4/38 (11%)
firefox: "latest"

 #  @ckeditor/ckeditor5-basic-styles                                       5/38 (13%)
firefox: "latest"

 #  @ckeditor/ckeditor5-block-quote                                        6/38 (16%)
firefox: "latest"

 #  @ckeditor/ckeditor5-cloud-services                                    11/38 (29%)
firefox: "latest"

 #  @ckeditor/ckeditor5-clipboard                                         12/38 (32%)
firefox: "latest"

 #  @ckeditor/ckeditor5-easy-image                                        13/38 (34%)
firefox: "latest"

 #  @ckeditor/ckeditor5-core                                              14/38 (37%)
firefox: "latest"

 #  @ckeditor/ckeditor5-editor-balloon                                    15/38 (39%)
firefox: "latest"

 #  @ckeditor/ckeditor5-editor-classic                                    16/38 (42%)
firefox: "latest"

 #  @ckeditor/ckeditor5-editor-inline                                     17/38 (45%)
firefox: "latest"

 #  @ckeditor/ckeditor5-editor-decoupled                                  18/38 (47%)
firefox: latest

 #  @ckeditor/ckeditor5-engine                                            19/38 (50%)
firefox: "latest"

 #  @ckeditor/ckeditor5-enter                                             20/38 (53%)
firefox: "latest"

 #  @ckeditor/ckeditor5-essentials                                        21/38 (55%)
firefox: "latest"

 #  @ckeditor/ckeditor5-font                                              22/38 (58%)
firefox: latest

 #  @ckeditor/ckeditor5-heading                                           23/38 (61%)
firefox: "latest"

 #  @ckeditor/ckeditor5-highlight                                         24/38 (63%)
firefox: latest

 #  @ckeditor/ckeditor5-image                                             25/38 (66%)
firefox: "latest"

 #  @ckeditor/ckeditor5-link                                              26/38 (68%)
firefox: "latest"

 #  @ckeditor/ckeditor5-list                                              27/38 (71%)
firefox: "latest"

 #  @ckeditor/ckeditor5-markdown-gfm                                      28/38 (74%)
firefox: "latest"

 #  @ckeditor/ckeditor5-paragraph                                         29/38 (76%)
firefox: "latest"

 #  @ckeditor/ckeditor5-media-embed                                       30/38 (79%)
firefox: "latest"

 #  @ckeditor/ckeditor5-table                                             31/38 (82%)
firefox: latest

 #  @ckeditor/ckeditor5-theme-lark                                        32/38 (84%)
firefox: "latest"

 #  @ckeditor/ckeditor5-typing                                            33/38 (87%)
firefox: "latest"

 #  @ckeditor/ckeditor5-ui                                                34/38 (89%)
firefox: "latest"

 #  @ckeditor/ckeditor5-undo                                              35/38 (92%)
firefox: "latest"

 #  @ckeditor/ckeditor5-upload                                            36/38 (95%)
firefox: "latest"

 #  @ckeditor/ckeditor5-utils                                             37/38 (97%)
firefox: "latest"

 #  @ckeditor/ckeditor5-widget                                           38/38 (100%)
firefox: "latest"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhm.

 #  @ckeditor/ckeditor5-alignment                                           1/37 (3%) 
firefox: latest

 #  @ckeditor/ckeditor5-adapter-ckfinder                                    2/37 (5%) 
firefox: latest

 #  @ckeditor/ckeditor5-autosave                                            3/37 (8%) 
firefox: latest

 #  @ckeditor/ckeditor5-autoformat                                         4/37 (11%) 
firefox: latest

 #  @ckeditor/ckeditor5-basic-styles                                       5/37 (14%) 
firefox: latest

 #  @ckeditor/ckeditor5-block-quote                                        6/37 (16%) 
firefox: latest

 #  @ckeditor/ckeditor5-build-balloon                                      7/37 (19%) 
cat: ./.travis.yml: No such file or directory

 #  @ckeditor/ckeditor5-build-classic                                      8/37 (22%) 
cat: ./.travis.yml: No such file or directory

 #  @ckeditor/ckeditor5-build-inline                                       9/37 (24%) 
cat: ./.travis.yml: No such file or directory

 #  @ckeditor/ckeditor5-build-decoupled-document                          10/37 (27%) 
cat: ./.travis.yml: No such file or directory

 #  @ckeditor/ckeditor5-clipboard                                         11/37 (30%) 
firefox: latest

 #  @ckeditor/ckeditor5-cloud-services                                    12/37 (32%) 
firefox: latest

 #  @ckeditor/ckeditor5-core                                              13/37 (35%) 
firefox: latest

 #  @ckeditor/ckeditor5-easy-image                                        14/37 (38%) 
firefox: latest

 #  @ckeditor/ckeditor5-editor-balloon                                    15/37 (41%) 
firefox: latest

 #  @ckeditor/ckeditor5-editor-classic                                    16/37 (43%) 
firefox: latest

 #  @ckeditor/ckeditor5-editor-decoupled                                  17/37 (46%) 
firefox: latest

 #  @ckeditor/ckeditor5-editor-inline                                     18/37 (49%) 
firefox: latest

 #  @ckeditor/ckeditor5-enter                                             19/37 (51%) 
firefox: latest

 #  @ckeditor/ckeditor5-engine                                            20/37 (54%) 
firefox: latest

 #  @ckeditor/ckeditor5-essentials                                        21/37 (57%) 
firefox: latest

 #  @ckeditor/ckeditor5-font                                              22/37 (59%) 
firefox: latest

 #  @ckeditor/ckeditor5-heading                                           23/37 (62%) 
firefox: latest

 #  @ckeditor/ckeditor5-highlight                                         24/37 (65%) 
firefox: latest

 #  @ckeditor/ckeditor5-link                                              25/37 (68%) 
firefox: latest

 #  @ckeditor/ckeditor5-image                                             26/37 (70%) 
firefox: latest

 #  @ckeditor/ckeditor5-markdown-gfm                                      27/37 (73%) 
firefox: latest

 #  @ckeditor/ckeditor5-list                                              28/37 (76%) 
firefox: latest

 #  @ckeditor/ckeditor5-paragraph                                         29/37 (78%) 
firefox: latest

 #  @ckeditor/ckeditor5-table                                             30/37 (81%) 
firefox: latest

 #  @ckeditor/ckeditor5-theme-lark                                        31/37 (84%) 
firefox: latest

 #  @ckeditor/ckeditor5-typing                                            32/37 (86%) 
firefox: latest

 #  @ckeditor/ckeditor5-ui                                                33/37 (89%) 
firefox: latest

 #  @ckeditor/ckeditor5-undo                                              34/37 (92%) 
firefox: latest

 #  @ckeditor/ckeditor5-upload                                            35/37 (95%) 
firefox: latest

 #  @ckeditor/ckeditor5-utils                                             36/37 (97%) 
firefox: latest

 #  @ckeditor/ckeditor5-widget                                           37/37 (100%) 
firefox: latest

Execution time: 2s489ms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We unified this recently, Olek.

firefox: "latest"
apt:
sources:
- google-chrome
Expand Down
Empty file.
13 changes: 13 additions & 0 deletions docs/_snippets/features/build-media-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals window */

import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed';

ClassicEditor.builtinPlugins.push( MediaEmbed );

window.ClassicEditor = ClassicEditor;
36 changes: 36 additions & 0 deletions docs/_snippets/features/media-embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div id="snippet-media-embed">
<h3>YouTube</h3>

<figure class="media">
<oembed url="https://www.youtube.com/watch?v=DgM5DfAPQTI"></oembed>
</figure>

<h3>Vimeo</h3>

<figure class="media">
<oembed url="https://vimeo.com/1084537"></oembed>
</figure>

<h3>Twitter</h3>

<figure>
<oembed url="https://twitter.com/ckeditor/status/1027571541989572612"></oembed>
</figure>

<h3>Google Maps</h3>

<figure class="media">
<oembed url="https://www.google.com/maps/place/Poland/@51.9537505,19.1343786,6z/data=!3m1!4b1!4m5!3m4!1s0x47009964a4640bbb:0x97573ca49cc55ea!8m2!3d51.919438!4d19.145136?hl=en"></oembed>
</figure>
</div>

<style>
.ck.ck-content .media iframe {
/* Override default Umberto guide styles. */
margin: 0;
}

input.example-input {
min-width: 600px;
}
</style>
28 changes: 28 additions & 0 deletions docs/_snippets/features/media-embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals ClassicEditor, console, window, document */

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

ClassicEditor
.create( document.querySelector( '#snippet-media-embed' ), {
cloudServices: CS_CONFIG,
toolbar: {
items: [
'mediaEmbed', '|', 'heading', '|', 'bold', 'italic', '|', 'undo', 'redo'
],
viewportTopOffset: 60
},
mediaEmbed: {
semanticDataOutput: true
}
} )
.then( editor => {
window.editor = editor;
} )
.catch( err => {
console.error( err.stack );
} );
86 changes: 86 additions & 0 deletions docs/features/media-embed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
category: features
---

{@snippet features/build-media-source}

# Media embed

The {@link module:media-embed/mediaembed~MediaEmbed} feature brings a basic support for embeddable, synchronous media in the editor content.

## Demo

### Example URLs

* <input class="example-input" type="text" value="https://www.youtube.com/watch?v=H08tGjXNHO4">
* <input class="example-input" type="text" value="https://open.spotify.com/album/2IXlgvecaDqOeF3viUZnPI?si=ogVw7KlcQAGZKK4Jz9QzvA">
* <input class="example-input" type="text" value="https://www.instagram.com/p/BmMZgokAGGQ/?taken-by=nasa">

{@snippet features/media-embed}

## Installation

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

```bash
npm install --save @ckeditor/ckeditor5-media-embed
```

Then add `'MediaEmbed'` to your plugin list and configure the media providers:

```js
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/table';

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

## Configuration

### Output type

To satisfy most of the use–cases, the feature can be configured using the {@link module:media-embed/mediaembed~MediaEmbedConfig#semanticDataOutput `semanticDataOutput`} option to output different kind data:

* **Non–semantic** (default) – outputs media in the same way it works in the editor, i.e. the media preview is saved to the database.

```html
<figure class="media">
<div data-oembed-url="https://url">
<iframe src="https://preview"></iframe>
</div>
</figure>
```

* **Semantic** – does not include the preview of the media, just just the `<oembed>` tag with the `url` attribute. Best when the application processes (expands) the media on the server–side or directly in the front–end, preserving the versatile database representation.

```html
<figure class="media">
<oembed url="https://url"></oembed>
</figure>
```

### Media providers

## Common API

The {@link module:media-embed/mediaembed~MediaEmbed} plugin registers:
* the `'mediaEmbed'` UI button component,
* the `'mediaEmbed'` command implemented by {@link module:media-embed/mediaembedcommand~MediaEmbedCommand}.

You can insert a new media or update the selected media URL by executing the following code:

```js
editor.execute( 'mediaEmbed', { url: 'http://url.to.the/media' } );
```

## Contribute

The source code of the feature is available on GitHub in https://github.com/ckeditor/ckeditor5-media-embed.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
"ckeditor5-feature"
],
"dependencies": {
"@ckeditor/ckeditor5-core": "^11.0.0",
"@ckeditor/ckeditor5-engine": "^10.2.0",
"@ckeditor/ckeditor5-ui": "^11.0.0",
"@ckeditor/ckeditor5-utils": "^10.2.0",
"@ckeditor/ckeditor5-widget": "^10.2.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-editor-classic": "^11.0.0",
"eslint": "^4.15.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
Expand Down
66 changes: 66 additions & 0 deletions src/converters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/**
* @module media-embed/converters
*/

import ViewRange from '@ckeditor/ckeditor5-engine/src/view/range';
import ViewPosition from '@ckeditor/ckeditor5-engine/src/view/position';

/**
* Returns a function that converts the model "url" attribute to the view representation.
*
* Depending on the configuration the view representation can be "sementaic" (for data pipeline):
*
* <figure class="media">
* <oembed url="foo"></div>
* </figure>
*
* or "non-semantic" (for editing view pipeline):
*
* <figure class="media">
* <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
* </figure>
*
* **Note:** Changing the model "url" attribute replaces the entire content of the
* `<figure>` in the view.
*
* @param {module:media-embed/mediaregistry~MediaRegistry} mediaRegistry The registry providing
* the media and their content.
* @param {Object} options
* @param {String} [options.semanticDataOutput] When `true`, the converter will create view in the semantic form.
* @param {String} [options.renderForEditingView] When `true`, the converter will create a view specific for the
* editing pipeline (e.g. including CSS classes, content placeholders).
* @returns {Function}
*/
export function modelToViewUrlAttributeConverter( mediaRegistry, options ) {
const mediaViewElementOptions = {
useSemanticWrapper: options.semanticDataOutput,
renderContent: !options.semanticDataOutput,
renderForEditingView: options.renderForEditingView
};

return dispatcher => {
dispatcher.on( 'attribute:url:media', converter );
};

function converter( evt, data, conversionApi ) {
if ( !conversionApi.consumable.consume( data.item, evt.name ) ) {
return;
}

const url = data.attributeNewValue;
const viewWriter = conversionApi.writer;
const figure = conversionApi.mapper.toViewElement( data.item );

// TODO: removing it and creating it from scratch is a hack. We can do better than that.
viewWriter.remove( ViewRange.createIn( figure ) );

const mediaViewElement = mediaRegistry.getMediaViewElement( viewWriter, url, mediaViewElementOptions );

viewWriter.insert( ViewPosition.createAt( figure ), mediaViewElement );
}
}
Loading