This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
T/1: The basic media embed feature #2
Merged
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 1b22e29
Tests: Added MediaEmbed and InsertMediaCommand tests.
oleq b677475
Tests: Added MediaEmbedUI tests.
oleq f9cd2c2
Tests: Added tests for the MediaFormView.
oleq b93f5b0
Tests: Extended MediaEmbedEditing tests.
oleq d7c62a5
Tests: Added tests for the default config.mediaEmbed.media.
oleq 6fd1dbe
Updated dependencies in package.json.
oleq 77f3cae
Fixed broken import paths in the MediaFormView class file.
oleq 5e1f5d9
Fixed broken import paths in the MediaFormView class file.
oleq ca2731b
Tests: Normalized the HTML in test cases to let tests pass in differe…
oleq b2bf14f
Updated travis.yml.
oleq 3b552d5
Extended media embed to support non-previewable providers.
oleq c9b86f1
Added a couple more generic providers.
oleq 2ad77af
Added 'any' default provider.
oleq 8c074aa
Code refactoring.
oleq 50f0790
Code refactoring.
oleq e17328e
Used the <oembed> element in data for embeds without preview or when …
oleq d57a5b1
Code refactoring.
oleq 196e762
Removed the .ck-media__wrapper__aspect class; replaced with inline st…
oleq 5233678
Fix: The generic media should have semantic representation in data.
oleq 70c93e5
Docs: Extended docs and refactored the code.
oleq b89298d
Docs: Fixed broken links.
oleq ed8538d
Simplified media config.
oleq a92b7dd
Tests: Added missing upcast tests.
oleq 6d35cb9
Removed a huge chunk of code because it looks like it's no longer nee…
oleq 49db076
Docs: Fixed wrong path to the converters module.
oleq b3aa2ce
Docs: Implemented a basic guide in the 'Features' section.
oleq 66cf092
Docs: Extended the guide.
oleq 6da2ece
Docs: Cleaned–up the feature guide.
oleq 7902b29
Docs: Introduced configuration docs.
oleq 9fb472c
Tests: Aligned tests to the latest engine dev utils API.
oleq c215866
Renamed the command the UI component 'insertMedia'->'mediaEmbed'.
oleq 0a76c71
Renamed InsertMediaCommand->MediaEmbedCommand.
oleq 0388d39
Configured the content styles so media use all the available horizont…
oleq 6165e96
Introduced new configuration options: 'providers', 'extraProviders' a…
oleq 949eb94
Removed obsolete code from the MediaRegistry class.
oleq 7b34a34
Added pkgs main API docs page.
Reinmar 657ca3f
Docs: Extended the media-embed guide.
oleq e3eab68
Aligned travis.yml configuration syntax to the rest of the project.
oleq 865211d
Some docs improvements.
Reinmar c3204ef
Added media placeholder tooltip. Code refactoring in media embed styles.
oleq f3b4faf
Tests: Used non-semantic data HTML in the non-semantic manual test.
oleq 688bb36
Tests: Provided test scenario descriptions for manual tests.
oleq b2cfdb6
Docs.
Reinmar c50903f
Fixed gmaps provider name.
Reinmar eb5eb5d
Reverted a mistakenly commited line.
Reinmar e0dd71e
Fixed a link.
Reinmar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
sudo: required | ||
dist: trusty | ||
addons: | ||
firefox: latest | ||
firefox: "latest" | ||
apt: | ||
sources: | ||
- google-chrome | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 whattravis encrypt
does too).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And almost every repo uses
""
. I'm confused, should I use it or not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhm.
There was a problem hiding this comment.
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.