@ckeditor/ckeditor5-media-embed 40.0.0 → 40.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Software License Agreement
2
2
  ==========================
3
3
 
4
4
  **CKEditor&nbsp;5 media embed feature** – https://github.com/ckeditor/ckeditor5-media-embed <br>
5
- Copyright (c) 2003-2023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
5
+ Copyright (c) 20032023, [CKSource Holding sp. z o.o.](https://cksource.com) All rights reserved.
6
6
 
7
7
  Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).
8
8
 
@@ -14,4 +14,4 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
14
14
  Trademarks
15
15
  ----------
16
16
 
17
- **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.
17
+ **CKEditor** is a trademark of [CKSource Holding sp. z o.o.](https://cksource.com) All other brand and product names are trademarks, registered trademarks, or service marks of their respective holders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-media-embed",
3
- "version": "40.0.0",
3
+ "version": "40.1.0",
4
4
  "description": "Media embed feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,8 +12,8 @@
12
12
  ],
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-ui": "40.0.0",
16
- "ckeditor5": "40.0.0"
15
+ "@ckeditor/ckeditor5-ui": "40.1.0",
16
+ "ckeditor5": "40.1.0"
17
17
  },
18
18
  "author": "CKSource (http://cksource.com/)",
19
19
  "license": "GPL-2.0-or-later",
@@ -1,25 +1,25 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- import type { MediaEmbedConfig, AutoMediaEmbed, MediaEmbed, MediaEmbedEditing, MediaEmbedToolbar, MediaEmbedUI, MediaEmbedCommand } from './index';
6
- declare module '@ckeditor/ckeditor5-core' {
7
- interface EditorConfig {
8
- /**
9
- * The configuration of the {@link module:media-embed/mediaembed~MediaEmbed} feature.
10
- *
11
- * Read more in {@link module:media-embed/mediaembedconfig~MediaEmbedConfig}.
12
- */
13
- mediaEmbed?: MediaEmbedConfig;
14
- }
15
- interface PluginsMap {
16
- [AutoMediaEmbed.pluginName]: AutoMediaEmbed;
17
- [MediaEmbed.pluginName]: MediaEmbed;
18
- [MediaEmbedEditing.pluginName]: MediaEmbedEditing;
19
- [MediaEmbedToolbar.pluginName]: MediaEmbedToolbar;
20
- [MediaEmbedUI.pluginName]: MediaEmbedUI;
21
- }
22
- interface CommandsMap {
23
- mediaEmbed: MediaEmbedCommand;
24
- }
25
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ import type { MediaEmbedConfig, AutoMediaEmbed, MediaEmbed, MediaEmbedEditing, MediaEmbedToolbar, MediaEmbedUI, MediaEmbedCommand } from './index';
6
+ declare module '@ckeditor/ckeditor5-core' {
7
+ interface EditorConfig {
8
+ /**
9
+ * The configuration of the {@link module:media-embed/mediaembed~MediaEmbed} feature.
10
+ *
11
+ * Read more in {@link module:media-embed/mediaembedconfig~MediaEmbedConfig}.
12
+ */
13
+ mediaEmbed?: MediaEmbedConfig;
14
+ }
15
+ interface PluginsMap {
16
+ [AutoMediaEmbed.pluginName]: AutoMediaEmbed;
17
+ [MediaEmbed.pluginName]: MediaEmbed;
18
+ [MediaEmbedEditing.pluginName]: MediaEmbedEditing;
19
+ [MediaEmbedToolbar.pluginName]: MediaEmbedToolbar;
20
+ [MediaEmbedUI.pluginName]: MediaEmbedUI;
21
+ }
22
+ interface CommandsMap {
23
+ mediaEmbed: MediaEmbedCommand;
24
+ }
25
+ }
@@ -1,5 +1,5 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ export {};
@@ -1,51 +1,51 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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 media-embed/automediaembed
7
- */
8
- import { type Editor, Plugin } from 'ckeditor5/src/core';
9
- import { Clipboard } from 'ckeditor5/src/clipboard';
10
- import { Delete } from 'ckeditor5/src/typing';
11
- import { Undo } from 'ckeditor5/src/undo';
12
- /**
13
- * The auto-media embed plugin. It recognizes media links in the pasted content and embeds
14
- * them shortly after they are injected into the document.
15
- */
16
- export default class AutoMediaEmbed extends Plugin {
17
- /**
18
- * @inheritDoc
19
- */
20
- static get requires(): readonly [typeof Clipboard, typeof Delete, typeof Undo];
21
- /**
22
- * @inheritDoc
23
- */
24
- static get pluginName(): "AutoMediaEmbed";
25
- /**
26
- * The paste–to–embed `setTimeout` ID. Stored as a property to allow
27
- * cleaning of the timeout.
28
- */
29
- private _timeoutId;
30
- /**
31
- * The position where the `<media>` element will be inserted after the timeout,
32
- * determined each time the new content is pasted into the document.
33
- */
34
- private _positionToInsert;
35
- /**
36
- * @inheritDoc
37
- */
38
- constructor(editor: Editor);
39
- /**
40
- * @inheritDoc
41
- */
42
- init(): void;
43
- /**
44
- * Analyzes the part of the document between provided positions in search for a URL representing media.
45
- * When the URL is found, it is automatically converted into media.
46
- *
47
- * @param leftPosition Left position of the selection.
48
- * @param rightPosition Right position of the selection.
49
- */
50
- private _embedMediaBetweenPositions;
51
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 media-embed/automediaembed
7
+ */
8
+ import { type Editor, Plugin } from 'ckeditor5/src/core';
9
+ import { Clipboard } from 'ckeditor5/src/clipboard';
10
+ import { Delete } from 'ckeditor5/src/typing';
11
+ import { Undo } from 'ckeditor5/src/undo';
12
+ /**
13
+ * The auto-media embed plugin. It recognizes media links in the pasted content and embeds
14
+ * them shortly after they are injected into the document.
15
+ */
16
+ export default class AutoMediaEmbed extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get requires(): readonly [typeof Clipboard, typeof Delete, typeof Undo];
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName(): "AutoMediaEmbed";
25
+ /**
26
+ * The paste–to–embed `setTimeout` ID. Stored as a property to allow
27
+ * cleaning of the timeout.
28
+ */
29
+ private _timeoutId;
30
+ /**
31
+ * The position where the `<media>` element will be inserted after the timeout,
32
+ * determined each time the new content is pasted into the document.
33
+ */
34
+ private _positionToInsert;
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ constructor(editor: Editor);
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ init(): void;
43
+ /**
44
+ * Analyzes the part of the document between provided positions in search for a URL representing media.
45
+ * When the URL is found, it is automatically converted into media.
46
+ *
47
+ * @param leftPosition Left position of the selection.
48
+ * @param rightPosition Right position of the selection.
49
+ */
50
+ private _embedMediaBetweenPositions;
51
+ }
@@ -1,131 +1,131 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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 media-embed/automediaembed
7
- */
8
- import { Plugin } from 'ckeditor5/src/core';
9
- import { LiveRange, LivePosition } from 'ckeditor5/src/engine';
10
- import { Clipboard } from 'ckeditor5/src/clipboard';
11
- import { Delete } from 'ckeditor5/src/typing';
12
- import { Undo } from 'ckeditor5/src/undo';
13
- import { global } from 'ckeditor5/src/utils';
14
- import MediaEmbedEditing from './mediaembedediting';
15
- import { insertMedia } from './utils';
16
- const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
17
- /**
18
- * The auto-media embed plugin. It recognizes media links in the pasted content and embeds
19
- * them shortly after they are injected into the document.
20
- */
21
- export default class AutoMediaEmbed extends Plugin {
22
- /**
23
- * @inheritDoc
24
- */
25
- static get requires() {
26
- return [Clipboard, Delete, Undo];
27
- }
28
- /**
29
- * @inheritDoc
30
- */
31
- static get pluginName() {
32
- return 'AutoMediaEmbed';
33
- }
34
- /**
35
- * @inheritDoc
36
- */
37
- constructor(editor) {
38
- super(editor);
39
- this._timeoutId = null;
40
- this._positionToInsert = null;
41
- }
42
- /**
43
- * @inheritDoc
44
- */
45
- init() {
46
- const editor = this.editor;
47
- const modelDocument = editor.model.document;
48
- // We need to listen on `Clipboard#inputTransformation` because we need to save positions of selection.
49
- // After pasting, the content between those positions will be checked for a URL that could be transformed
50
- // into media.
51
- const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
52
- this.listenTo(clipboardPipeline, 'inputTransformation', () => {
53
- const firstRange = modelDocument.selection.getFirstRange();
54
- const leftLivePosition = LivePosition.fromPosition(firstRange.start);
55
- leftLivePosition.stickiness = 'toPrevious';
56
- const rightLivePosition = LivePosition.fromPosition(firstRange.end);
57
- rightLivePosition.stickiness = 'toNext';
58
- modelDocument.once('change:data', () => {
59
- this._embedMediaBetweenPositions(leftLivePosition, rightLivePosition);
60
- leftLivePosition.detach();
61
- rightLivePosition.detach();
62
- }, { priority: 'high' });
63
- });
64
- const undoCommand = editor.commands.get('undo');
65
- undoCommand.on('execute', () => {
66
- if (this._timeoutId) {
67
- global.window.clearTimeout(this._timeoutId);
68
- this._positionToInsert.detach();
69
- this._timeoutId = null;
70
- this._positionToInsert = null;
71
- }
72
- }, { priority: 'high' });
73
- }
74
- /**
75
- * Analyzes the part of the document between provided positions in search for a URL representing media.
76
- * When the URL is found, it is automatically converted into media.
77
- *
78
- * @param leftPosition Left position of the selection.
79
- * @param rightPosition Right position of the selection.
80
- */
81
- _embedMediaBetweenPositions(leftPosition, rightPosition) {
82
- const editor = this.editor;
83
- const mediaRegistry = editor.plugins.get(MediaEmbedEditing).registry;
84
- // TODO: Use marker instead of LiveRange & LivePositions.
85
- const urlRange = new LiveRange(leftPosition, rightPosition);
86
- const walker = urlRange.getWalker({ ignoreElementEnd: true });
87
- let url = '';
88
- for (const node of walker) {
89
- if (node.item.is('$textProxy')) {
90
- url += node.item.data;
91
- }
92
- }
93
- url = url.trim();
94
- // If the URL does not match to universal URL regexp, let's skip that.
95
- if (!url.match(URL_REGEXP)) {
96
- urlRange.detach();
97
- return;
98
- }
99
- // If the URL represents a media, let's use it.
100
- if (!mediaRegistry.hasMedia(url)) {
101
- urlRange.detach();
102
- return;
103
- }
104
- const mediaEmbedCommand = editor.commands.get('mediaEmbed');
105
- // Do not anything if media element cannot be inserted at the current position (#47).
106
- if (!mediaEmbedCommand.isEnabled) {
107
- urlRange.detach();
108
- return;
109
- }
110
- // Position won't be available in the `setTimeout` function so let's clone it.
111
- this._positionToInsert = LivePosition.fromPosition(leftPosition);
112
- // This action mustn't be executed if undo was called between pasting and auto-embedding.
113
- this._timeoutId = global.window.setTimeout(() => {
114
- editor.model.change(writer => {
115
- this._timeoutId = null;
116
- writer.remove(urlRange);
117
- urlRange.detach();
118
- let insertionPosition = null;
119
- // Check if position where the media element should be inserted is still valid.
120
- // Otherwise leave it as undefined to use document.selection - default behavior of model.insertContent().
121
- if (this._positionToInsert.root.rootName !== '$graveyard') {
122
- insertionPosition = this._positionToInsert;
123
- }
124
- insertMedia(editor.model, url, insertionPosition, false);
125
- this._positionToInsert.detach();
126
- this._positionToInsert = null;
127
- });
128
- editor.plugins.get(Delete).requestUndoOnBackspace();
129
- }, 100);
130
- }
131
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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 media-embed/automediaembed
7
+ */
8
+ import { Plugin } from 'ckeditor5/src/core';
9
+ import { LiveRange, LivePosition } from 'ckeditor5/src/engine';
10
+ import { Clipboard } from 'ckeditor5/src/clipboard';
11
+ import { Delete } from 'ckeditor5/src/typing';
12
+ import { Undo } from 'ckeditor5/src/undo';
13
+ import { global } from 'ckeditor5/src/utils';
14
+ import MediaEmbedEditing from './mediaembedediting';
15
+ import { insertMedia } from './utils';
16
+ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
17
+ /**
18
+ * The auto-media embed plugin. It recognizes media links in the pasted content and embeds
19
+ * them shortly after they are injected into the document.
20
+ */
21
+ export default class AutoMediaEmbed extends Plugin {
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ static get requires() {
26
+ return [Clipboard, Delete, Undo];
27
+ }
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ static get pluginName() {
32
+ return 'AutoMediaEmbed';
33
+ }
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ constructor(editor) {
38
+ super(editor);
39
+ this._timeoutId = null;
40
+ this._positionToInsert = null;
41
+ }
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ init() {
46
+ const editor = this.editor;
47
+ const modelDocument = editor.model.document;
48
+ // We need to listen on `Clipboard#inputTransformation` because we need to save positions of selection.
49
+ // After pasting, the content between those positions will be checked for a URL that could be transformed
50
+ // into media.
51
+ const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
52
+ this.listenTo(clipboardPipeline, 'inputTransformation', () => {
53
+ const firstRange = modelDocument.selection.getFirstRange();
54
+ const leftLivePosition = LivePosition.fromPosition(firstRange.start);
55
+ leftLivePosition.stickiness = 'toPrevious';
56
+ const rightLivePosition = LivePosition.fromPosition(firstRange.end);
57
+ rightLivePosition.stickiness = 'toNext';
58
+ modelDocument.once('change:data', () => {
59
+ this._embedMediaBetweenPositions(leftLivePosition, rightLivePosition);
60
+ leftLivePosition.detach();
61
+ rightLivePosition.detach();
62
+ }, { priority: 'high' });
63
+ });
64
+ const undoCommand = editor.commands.get('undo');
65
+ undoCommand.on('execute', () => {
66
+ if (this._timeoutId) {
67
+ global.window.clearTimeout(this._timeoutId);
68
+ this._positionToInsert.detach();
69
+ this._timeoutId = null;
70
+ this._positionToInsert = null;
71
+ }
72
+ }, { priority: 'high' });
73
+ }
74
+ /**
75
+ * Analyzes the part of the document between provided positions in search for a URL representing media.
76
+ * When the URL is found, it is automatically converted into media.
77
+ *
78
+ * @param leftPosition Left position of the selection.
79
+ * @param rightPosition Right position of the selection.
80
+ */
81
+ _embedMediaBetweenPositions(leftPosition, rightPosition) {
82
+ const editor = this.editor;
83
+ const mediaRegistry = editor.plugins.get(MediaEmbedEditing).registry;
84
+ // TODO: Use marker instead of LiveRange & LivePositions.
85
+ const urlRange = new LiveRange(leftPosition, rightPosition);
86
+ const walker = urlRange.getWalker({ ignoreElementEnd: true });
87
+ let url = '';
88
+ for (const node of walker) {
89
+ if (node.item.is('$textProxy')) {
90
+ url += node.item.data;
91
+ }
92
+ }
93
+ url = url.trim();
94
+ // If the URL does not match to universal URL regexp, let's skip that.
95
+ if (!url.match(URL_REGEXP)) {
96
+ urlRange.detach();
97
+ return;
98
+ }
99
+ // If the URL represents a media, let's use it.
100
+ if (!mediaRegistry.hasMedia(url)) {
101
+ urlRange.detach();
102
+ return;
103
+ }
104
+ const mediaEmbedCommand = editor.commands.get('mediaEmbed');
105
+ // Do not anything if media element cannot be inserted at the current position (#47).
106
+ if (!mediaEmbedCommand.isEnabled) {
107
+ urlRange.detach();
108
+ return;
109
+ }
110
+ // Position won't be available in the `setTimeout` function so let's clone it.
111
+ this._positionToInsert = LivePosition.fromPosition(leftPosition);
112
+ // This action mustn't be executed if undo was called between pasting and auto-embedding.
113
+ this._timeoutId = global.window.setTimeout(() => {
114
+ editor.model.change(writer => {
115
+ this._timeoutId = null;
116
+ writer.remove(urlRange);
117
+ urlRange.detach();
118
+ let insertionPosition = null;
119
+ // Check if position where the media element should be inserted is still valid.
120
+ // Otherwise leave it as undefined to use document.selection - default behavior of model.insertContent().
121
+ if (this._positionToInsert.root.rootName !== '$graveyard') {
122
+ insertionPosition = this._positionToInsert;
123
+ }
124
+ insertMedia(editor.model, url, insertionPosition, false);
125
+ this._positionToInsert.detach();
126
+ this._positionToInsert = null;
127
+ });
128
+ editor.plugins.get(Delete).requestUndoOnBackspace();
129
+ }, 100);
130
+ }
131
+ }
@@ -1,38 +1,38 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- import type { DowncastDispatcher } from 'ckeditor5/src/engine';
6
- import type MediaRegistry from './mediaregistry';
7
- import type { MediaOptions } from './utils';
8
- /**
9
- * Returns a function that converts the model "url" attribute to the view representation.
10
- *
11
- * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
12
- *
13
- * ```html
14
- * <figure class="media">
15
- * <oembed url="foo"></oembed>
16
- * </figure>
17
- * ```
18
- *
19
- * or "non-semantic" (for the editing view pipeline):
20
- *
21
- * ```html
22
- * <figure class="media">
23
- * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
24
- * </figure>
25
- * ```
26
- *
27
- * **Note:** Changing the model "url" attribute replaces the entire content of the
28
- * `<figure>` in the view.
29
- *
30
- * @param registry The registry providing
31
- * the media and their content.
32
- * @param options options object with following properties:
33
- * - elementName When set, overrides the default element name for semantic media embeds.
34
- * - renderMediaPreview When `true`, the converter will create the view in the non-semantic form.
35
- * - renderForEditingView When `true`, the converter will create a view specific for the
36
- * editing pipeline (e.g. including CSS classes, content placeholders).
37
- */
38
- export declare function modelToViewUrlAttributeConverter(registry: MediaRegistry, options: MediaOptions): (dispatcher: DowncastDispatcher) => void;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ import type { DowncastDispatcher } from 'ckeditor5/src/engine';
6
+ import type MediaRegistry from './mediaregistry';
7
+ import type { MediaOptions } from './utils';
8
+ /**
9
+ * Returns a function that converts the model "url" attribute to the view representation.
10
+ *
11
+ * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
12
+ *
13
+ * ```html
14
+ * <figure class="media">
15
+ * <oembed url="foo"></oembed>
16
+ * </figure>
17
+ * ```
18
+ *
19
+ * or "non-semantic" (for the editing view pipeline):
20
+ *
21
+ * ```html
22
+ * <figure class="media">
23
+ * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
24
+ * </figure>
25
+ * ```
26
+ *
27
+ * **Note:** Changing the model "url" attribute replaces the entire content of the
28
+ * `<figure>` in the view.
29
+ *
30
+ * @param registry The registry providing
31
+ * the media and their content.
32
+ * @param options options object with following properties:
33
+ * - elementName When set, overrides the default element name for semantic media embeds.
34
+ * - renderMediaPreview When `true`, the converter will create the view in the non-semantic form.
35
+ * - renderForEditingView When `true`, the converter will create a view specific for the
36
+ * editing pipeline (e.g. including CSS classes, content placeholders).
37
+ */
38
+ export declare function modelToViewUrlAttributeConverter(registry: MediaRegistry, options: MediaOptions): (dispatcher: DowncastDispatcher) => void;
package/src/converters.js CHANGED
@@ -1,53 +1,53 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * Returns a function that converts the model "url" attribute to the view representation.
7
- *
8
- * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
9
- *
10
- * ```html
11
- * <figure class="media">
12
- * <oembed url="foo"></oembed>
13
- * </figure>
14
- * ```
15
- *
16
- * or "non-semantic" (for the editing view pipeline):
17
- *
18
- * ```html
19
- * <figure class="media">
20
- * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
21
- * </figure>
22
- * ```
23
- *
24
- * **Note:** Changing the model "url" attribute replaces the entire content of the
25
- * `<figure>` in the view.
26
- *
27
- * @param registry The registry providing
28
- * the media and their content.
29
- * @param options options object with following properties:
30
- * - elementName When set, overrides the default element name for semantic media embeds.
31
- * - renderMediaPreview When `true`, the converter will create the view in the non-semantic form.
32
- * - renderForEditingView When `true`, the converter will create a view specific for the
33
- * editing pipeline (e.g. including CSS classes, content placeholders).
34
- */
35
- export function modelToViewUrlAttributeConverter(registry, options) {
36
- const converter = (evt, data, conversionApi) => {
37
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
38
- return;
39
- }
40
- const url = data.attributeNewValue;
41
- const viewWriter = conversionApi.writer;
42
- const figure = conversionApi.mapper.toViewElement(data.item);
43
- const mediaContentElement = [...figure.getChildren()]
44
- .find(child => child.getCustomProperty('media-content'));
45
- // TODO: removing the wrapper and creating it from scratch is a hack. We can do better than that.
46
- viewWriter.remove(mediaContentElement);
47
- const mediaViewElement = registry.getMediaViewElement(viewWriter, url, options);
48
- viewWriter.insert(viewWriter.createPositionAt(figure, 0), mediaViewElement);
49
- };
50
- return dispatcher => {
51
- dispatcher.on('attribute:url:media', converter);
52
- };
53
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * Returns a function that converts the model "url" attribute to the view representation.
7
+ *
8
+ * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
9
+ *
10
+ * ```html
11
+ * <figure class="media">
12
+ * <oembed url="foo"></oembed>
13
+ * </figure>
14
+ * ```
15
+ *
16
+ * or "non-semantic" (for the editing view pipeline):
17
+ *
18
+ * ```html
19
+ * <figure class="media">
20
+ * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
21
+ * </figure>
22
+ * ```
23
+ *
24
+ * **Note:** Changing the model "url" attribute replaces the entire content of the
25
+ * `<figure>` in the view.
26
+ *
27
+ * @param registry The registry providing
28
+ * the media and their content.
29
+ * @param options options object with following properties:
30
+ * - elementName When set, overrides the default element name for semantic media embeds.
31
+ * - renderMediaPreview When `true`, the converter will create the view in the non-semantic form.
32
+ * - renderForEditingView When `true`, the converter will create a view specific for the
33
+ * editing pipeline (e.g. including CSS classes, content placeholders).
34
+ */
35
+ export function modelToViewUrlAttributeConverter(registry, options) {
36
+ const converter = (evt, data, conversionApi) => {
37
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
38
+ return;
39
+ }
40
+ const url = data.attributeNewValue;
41
+ const viewWriter = conversionApi.writer;
42
+ const figure = conversionApi.mapper.toViewElement(data.item);
43
+ const mediaContentElement = [...figure.getChildren()]
44
+ .find(child => child.getCustomProperty('media-content'));
45
+ // TODO: removing the wrapper and creating it from scratch is a hack. We can do better than that.
46
+ viewWriter.remove(mediaContentElement);
47
+ const mediaViewElement = registry.getMediaViewElement(viewWriter, url, options);
48
+ viewWriter.insert(viewWriter.createPositionAt(figure, 0), mediaViewElement);
49
+ };
50
+ return dispatcher => {
51
+ dispatcher.on('attribute:url:media', converter);
52
+ };
53
+ }