@ckeditor/ckeditor5-media-embed 41.3.0-alpha.1 → 41.3.0-alpha.3

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.
Files changed (125) hide show
  1. package/dist/editor-index.css +12 -0
  2. package/dist/index.css +40 -0
  3. package/dist/index.css.map +1 -1
  4. package/dist/translations/ar.d.ts +8 -0
  5. package/dist/translations/ar.js +5 -0
  6. package/dist/translations/az.d.ts +8 -0
  7. package/dist/translations/az.js +5 -0
  8. package/dist/translations/bg.d.ts +8 -0
  9. package/dist/translations/bg.js +5 -0
  10. package/dist/translations/bn.d.ts +8 -0
  11. package/dist/translations/bn.js +5 -0
  12. package/dist/translations/ca.d.ts +8 -0
  13. package/dist/translations/ca.js +5 -0
  14. package/dist/translations/cs.d.ts +8 -0
  15. package/dist/translations/cs.js +5 -0
  16. package/dist/translations/da.d.ts +8 -0
  17. package/dist/translations/da.js +5 -0
  18. package/dist/translations/de-ch.d.ts +8 -0
  19. package/dist/translations/de-ch.js +5 -0
  20. package/dist/translations/de.d.ts +8 -0
  21. package/dist/translations/de.js +5 -0
  22. package/dist/translations/el.d.ts +8 -0
  23. package/dist/translations/el.js +5 -0
  24. package/dist/translations/en-au.d.ts +8 -0
  25. package/dist/translations/en-au.js +5 -0
  26. package/dist/translations/en-gb.d.ts +8 -0
  27. package/dist/translations/en-gb.js +5 -0
  28. package/dist/translations/en.d.ts +8 -0
  29. package/dist/translations/en.js +5 -0
  30. package/dist/translations/es.d.ts +8 -0
  31. package/dist/translations/es.js +5 -0
  32. package/dist/translations/et.d.ts +8 -0
  33. package/dist/translations/et.js +5 -0
  34. package/dist/translations/fa.d.ts +8 -0
  35. package/dist/translations/fa.js +5 -0
  36. package/dist/translations/fi.d.ts +8 -0
  37. package/dist/translations/fi.js +5 -0
  38. package/dist/translations/fr.d.ts +8 -0
  39. package/dist/translations/fr.js +5 -0
  40. package/dist/translations/gl.d.ts +8 -0
  41. package/dist/translations/gl.js +5 -0
  42. package/dist/translations/he.d.ts +8 -0
  43. package/dist/translations/he.js +5 -0
  44. package/dist/translations/hi.d.ts +8 -0
  45. package/dist/translations/hi.js +5 -0
  46. package/dist/translations/hr.d.ts +8 -0
  47. package/dist/translations/hr.js +5 -0
  48. package/dist/translations/hu.d.ts +8 -0
  49. package/dist/translations/hu.js +5 -0
  50. package/dist/translations/id.d.ts +8 -0
  51. package/dist/translations/id.js +5 -0
  52. package/dist/translations/it.d.ts +8 -0
  53. package/dist/translations/it.js +5 -0
  54. package/dist/translations/ja.d.ts +8 -0
  55. package/dist/translations/ja.js +5 -0
  56. package/dist/translations/ko.d.ts +8 -0
  57. package/dist/translations/ko.js +5 -0
  58. package/dist/translations/ku.d.ts +8 -0
  59. package/dist/translations/ku.js +5 -0
  60. package/dist/translations/lt.d.ts +8 -0
  61. package/dist/translations/lt.js +5 -0
  62. package/dist/translations/lv.d.ts +8 -0
  63. package/dist/translations/lv.js +5 -0
  64. package/dist/translations/ms.d.ts +8 -0
  65. package/dist/translations/ms.js +5 -0
  66. package/dist/translations/ne.d.ts +8 -0
  67. package/dist/translations/ne.js +5 -0
  68. package/dist/translations/nl.d.ts +8 -0
  69. package/dist/translations/nl.js +5 -0
  70. package/dist/translations/no.d.ts +8 -0
  71. package/dist/translations/no.js +5 -0
  72. package/dist/translations/pl.d.ts +8 -0
  73. package/dist/translations/pl.js +5 -0
  74. package/dist/translations/pt-br.d.ts +8 -0
  75. package/dist/translations/pt-br.js +5 -0
  76. package/dist/translations/pt.d.ts +8 -0
  77. package/dist/translations/pt.js +5 -0
  78. package/dist/translations/ro.d.ts +8 -0
  79. package/dist/translations/ro.js +5 -0
  80. package/dist/translations/ru.d.ts +8 -0
  81. package/dist/translations/ru.js +5 -0
  82. package/dist/translations/sk.d.ts +8 -0
  83. package/dist/translations/sk.js +5 -0
  84. package/dist/translations/sq.d.ts +8 -0
  85. package/dist/translations/sq.js +5 -0
  86. package/dist/translations/sr-latn.d.ts +8 -0
  87. package/dist/translations/sr-latn.js +5 -0
  88. package/dist/translations/sr.d.ts +8 -0
  89. package/dist/translations/sr.js +5 -0
  90. package/dist/translations/sv.d.ts +8 -0
  91. package/dist/translations/sv.js +5 -0
  92. package/dist/translations/th.d.ts +8 -0
  93. package/dist/translations/th.js +5 -0
  94. package/dist/translations/tk.d.ts +8 -0
  95. package/dist/translations/tk.js +5 -0
  96. package/dist/translations/tr.d.ts +8 -0
  97. package/dist/translations/tr.js +5 -0
  98. package/dist/translations/uk.d.ts +8 -0
  99. package/dist/translations/uk.js +5 -0
  100. package/dist/translations/ur.d.ts +8 -0
  101. package/dist/translations/ur.js +5 -0
  102. package/dist/translations/uz.d.ts +8 -0
  103. package/dist/translations/uz.js +5 -0
  104. package/dist/translations/vi.d.ts +8 -0
  105. package/dist/translations/vi.js +5 -0
  106. package/dist/translations/zh-cn.d.ts +8 -0
  107. package/dist/translations/zh-cn.js +5 -0
  108. package/dist/translations/zh.d.ts +8 -0
  109. package/dist/translations/zh.js +5 -0
  110. package/dist/types/augmentation.d.ts +4 -0
  111. package/dist/types/automediaembed.d.ts +4 -0
  112. package/dist/types/converters.d.ts +4 -0
  113. package/dist/types/index.d.ts +4 -0
  114. package/dist/types/mediaembed.d.ts +4 -0
  115. package/dist/types/mediaembedcommand.d.ts +4 -0
  116. package/dist/types/mediaembedconfig.d.ts +4 -0
  117. package/dist/types/mediaembedediting.d.ts +4 -0
  118. package/dist/types/mediaembedtoolbar.d.ts +4 -0
  119. package/dist/types/mediaembedui.d.ts +4 -0
  120. package/dist/types/mediaregistry.d.ts +4 -0
  121. package/dist/types/ui/mediaformview.d.ts +4 -0
  122. package/dist/types/utils.d.ts +4 -0
  123. package/package.json +3 -3
  124. package/dist/index.js +0 -1167
  125. package/dist/index.js.map +0 -1
package/dist/index.js DELETED
@@ -1,1167 +0,0 @@
1
- /**
2
- * @license Copyright (c) 2003-2024, 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 { Command, Plugin, icons } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { toWidget, isWidget, findOptimalInsertionRange, Widget, WidgetToolbarRepository } from '@ckeditor/ckeditor5-widget/dist/index.js';
7
- import { logWarning, toArray, first, global, FocusTracker, KeystrokeHandler } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
- import { IconView, Template, View, ViewCollection, FocusCycler, submitHandler, LabeledFieldView, createLabeledInputText, ButtonView, createDropdown, CssTransitionDisablerMixin } from '@ckeditor/ckeditor5-ui/dist/index.js';
9
- import { LivePosition, LiveRange } from '@ckeditor/ckeditor5-engine/dist/index.js';
10
- import { Clipboard } from '@ckeditor/ckeditor5-clipboard/dist/index.js';
11
- import { Delete } from '@ckeditor/ckeditor5-typing/dist/index.js';
12
- import { Undo } from '@ckeditor/ckeditor5-undo/dist/index.js';
13
- import '@ckeditor/ckeditor5-ui/dist/index.js';
14
-
15
- /**
16
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
17
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
18
- */
19
- /**
20
- * Returns a function that converts the model "url" attribute to the view representation.
21
- *
22
- * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
23
- *
24
- * ```html
25
- * <figure class="media">
26
- * <oembed url="foo"></oembed>
27
- * </figure>
28
- * ```
29
- *
30
- * or "non-semantic" (for the editing view pipeline):
31
- *
32
- * ```html
33
- * <figure class="media">
34
- * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
35
- * </figure>
36
- * ```
37
- *
38
- * **Note:** Changing the model "url" attribute replaces the entire content of the
39
- * `<figure>` in the view.
40
- *
41
- * @param registry The registry providing
42
- * the media and their content.
43
- * @param options options object with following properties:
44
- * - elementName When set, overrides the default element name for semantic media embeds.
45
- * - renderMediaPreview When `true`, the converter will create the view in the non-semantic form.
46
- * - renderForEditingView When `true`, the converter will create a view specific for the
47
- * editing pipeline (e.g. including CSS classes, content placeholders).
48
- */
49
- function modelToViewUrlAttributeConverter(registry, options) {
50
- const converter = (evt, data, conversionApi) => {
51
- if (!conversionApi.consumable.consume(data.item, evt.name)) {
52
- return;
53
- }
54
- const url = data.attributeNewValue;
55
- const viewWriter = conversionApi.writer;
56
- const figure = conversionApi.mapper.toViewElement(data.item);
57
- const mediaContentElement = [...figure.getChildren()]
58
- .find(child => child.getCustomProperty('media-content'));
59
- // TODO: removing the wrapper and creating it from scratch is a hack. We can do better than that.
60
- viewWriter.remove(mediaContentElement);
61
- const mediaViewElement = registry.getMediaViewElement(viewWriter, url, options);
62
- viewWriter.insert(viewWriter.createPositionAt(figure, 0), mediaViewElement);
63
- };
64
- return dispatcher => {
65
- dispatcher.on('attribute:url:media', converter);
66
- };
67
- }
68
-
69
- /**
70
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
71
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
72
- */
73
- /**
74
- * Converts a given {@link module:engine/view/element~Element} to a media embed widget:
75
- * * Adds a {@link module:engine/view/element~Element#_setCustomProperty custom property} allowing to recognize the media widget element.
76
- * * Calls the {@link module:widget/utils~toWidget} function with the proper element's label creator.
77
- *
78
- * @param writer An instance of the view writer.
79
- * @param label The element's label.
80
- */
81
- function toMediaWidget(viewElement, writer, label) {
82
- writer.setCustomProperty('media', true, viewElement);
83
- return toWidget(viewElement, writer, { label });
84
- }
85
- /**
86
- * Returns a media widget editing view element if one is selected.
87
- */
88
- function getSelectedMediaViewWidget(selection) {
89
- const viewElement = selection.getSelectedElement();
90
- if (viewElement && isMediaWidget(viewElement)) {
91
- return viewElement;
92
- }
93
- return null;
94
- }
95
- /**
96
- * Checks if a given view element is a media widget.
97
- */
98
- function isMediaWidget(viewElement) {
99
- return !!viewElement.getCustomProperty('media') && isWidget(viewElement);
100
- }
101
- /**
102
- * Creates a view element representing the media. Either a "semantic" one for the data pipeline:
103
- *
104
- * ```html
105
- * <figure class="media">
106
- * <oembed url="foo"></oembed>
107
- * </figure>
108
- * ```
109
- *
110
- * or a "non-semantic" (for the editing view pipeline):
111
- *
112
- * ```html
113
- * <figure class="media">
114
- * <div data-oembed-url="foo">[ non-semantic media preview for "foo" ]</div>
115
- * </figure>
116
- * ```
117
- */
118
- function createMediaFigureElement(writer, registry, url, options) {
119
- return writer.createContainerElement('figure', { class: 'media' }, [
120
- registry.getMediaViewElement(writer, url, options),
121
- writer.createSlot()
122
- ]);
123
- }
124
- /**
125
- * Returns a selected media element in the model, if any.
126
- */
127
- function getSelectedMediaModelWidget(selection) {
128
- const selectedElement = selection.getSelectedElement();
129
- if (selectedElement && selectedElement.is('element', 'media')) {
130
- return selectedElement;
131
- }
132
- return null;
133
- }
134
- /**
135
- * Creates a media element and inserts it into the model.
136
- *
137
- * **Note**: This method will use {@link module:engine/model/model~Model#insertContent `model.insertContent()`} logic of inserting content
138
- * if no `insertPosition` is passed.
139
- *
140
- * @param url An URL of an embeddable media.
141
- * @param findOptimalPosition If true it will try to find optimal position to insert media without breaking content
142
- * in which a selection is.
143
- */
144
- function insertMedia(model, url, selectable, findOptimalPosition) {
145
- model.change(writer => {
146
- const mediaElement = writer.createElement('media', { url });
147
- model.insertObject(mediaElement, selectable, null, {
148
- setSelection: 'on',
149
- findOptimalPosition: findOptimalPosition ? 'auto' : undefined
150
- });
151
- });
152
- }
153
-
154
- /**
155
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
156
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
157
- */
158
- /**
159
- * The insert media command.
160
- *
161
- * The command is registered by the {@link module:media-embed/mediaembedediting~MediaEmbedEditing} as `'mediaEmbed'`.
162
- *
163
- * To insert media at the current selection, execute the command and specify the URL:
164
- *
165
- * ```ts
166
- * editor.execute( 'mediaEmbed', 'http://url.to.the/media' );
167
- * ```
168
- */
169
- class MediaEmbedCommand extends Command {
170
- /**
171
- * @inheritDoc
172
- */
173
- refresh() {
174
- const model = this.editor.model;
175
- const selection = model.document.selection;
176
- const selectedMedia = getSelectedMediaModelWidget(selection);
177
- this.value = selectedMedia ? selectedMedia.getAttribute('url') : undefined;
178
- this.isEnabled = isMediaSelected(selection) || isAllowedInParent(selection, model);
179
- }
180
- /**
181
- * Executes the command, which either:
182
- *
183
- * * updates the URL of the selected media,
184
- * * inserts the new media into the editor and puts the selection around it.
185
- *
186
- * @fires execute
187
- * @param url The URL of the media.
188
- */
189
- execute(url) {
190
- const model = this.editor.model;
191
- const selection = model.document.selection;
192
- const selectedMedia = getSelectedMediaModelWidget(selection);
193
- if (selectedMedia) {
194
- model.change(writer => {
195
- writer.setAttribute('url', url, selectedMedia);
196
- });
197
- }
198
- else {
199
- insertMedia(model, url, selection, true);
200
- }
201
- }
202
- }
203
- /**
204
- * Checks if the media embed is allowed in the parent.
205
- */
206
- function isAllowedInParent(selection, model) {
207
- const insertionRange = findOptimalInsertionRange(selection, model);
208
- let parent = insertionRange.start.parent;
209
- // The model.insertContent() will remove empty parent (unless it is a $root or a limit).
210
- if (parent.isEmpty && !model.schema.isLimit(parent)) {
211
- parent = parent.parent;
212
- }
213
- return model.schema.checkChild(parent, 'media');
214
- }
215
- /**
216
- * Checks if the media object is selected.
217
- */
218
- function isMediaSelected(selection) {
219
- const element = selection.getSelectedElement();
220
- return !!element && element.name === 'media';
221
- }
222
-
223
- var mediaPlaceholderIcon = "<svg viewBox=\"0 0 64 42\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M47.426 17V3.713L63.102 0v19.389h-.001l.001.272c0 1.595-2.032 3.43-4.538 4.098-2.506.668-4.538-.083-4.538-1.678 0-1.594 2.032-3.43 4.538-4.098.914-.244 2.032-.565 2.888-.603V4.516L49.076 7.447v9.556A1.014 1.014 0 0 0 49 17h-1.574zM29.5 17h-8.343a7.073 7.073 0 1 0-4.657 4.06v3.781H3.3a2.803 2.803 0 0 1-2.8-2.804V8.63a2.803 2.803 0 0 1 2.8-2.805h4.082L8.58 2.768A1.994 1.994 0 0 1 10.435 1.5h8.985c.773 0 1.477.448 1.805 1.149l1.488 3.177H26.7c1.546 0 2.8 1.256 2.8 2.805V17zm-11.637 0H17.5a1 1 0 0 0-1 1v.05A4.244 4.244 0 1 1 17.863 17zm29.684 2c.97 0 .953-.048.953.889v20.743c0 .953.016.905-.953.905H19.453c-.97 0-.953.048-.953-.905V19.89c0-.937-.016-.889.97-.889h28.077zm-4.701 19.338V22.183H24.154v16.155h18.692zM20.6 21.375v1.616h1.616v-1.616H20.6zm0 3.231v1.616h1.616v-1.616H20.6zm0 3.231v1.616h1.616v-1.616H20.6zm0 3.231v1.616h1.616v-1.616H20.6zm0 3.231v1.616h1.616v-1.616H20.6zm0 3.231v1.616h1.616V37.53H20.6zm24.233-16.155v1.616h1.615v-1.616h-1.615zm0 3.231v1.616h1.615v-1.616h-1.615zm0 3.231v1.616h1.615v-1.616h-1.615zm0 3.231v1.616h1.615v-1.616h-1.615zm0 3.231v1.616h1.615v-1.616h-1.615zm0 3.231v1.616h1.615V37.53h-1.615zM29.485 25.283a.4.4 0 0 1 .593-.35l9.05 4.977a.4.4 0 0 1 0 .701l-9.05 4.978a.4.4 0 0 1-.593-.35v-9.956z\"/></svg>";
224
-
225
- /**
226
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
227
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
228
- */
229
- const mediaPlaceholderIconViewBox = '0 0 64 42';
230
- /**
231
- * A bridge between the raw media content provider definitions and the editor view content.
232
- *
233
- * It helps translating media URLs to corresponding {@link module:engine/view/element~Element view elements}.
234
- *
235
- * Mostly used by the {@link module:media-embed/mediaembedediting~MediaEmbedEditing} plugin.
236
- */
237
- class MediaRegistry {
238
- /**
239
- * Creates an instance of the {@link module:media-embed/mediaregistry~MediaRegistry} class.
240
- *
241
- * @param locale The localization services instance.
242
- * @param config The configuration of the media embed feature.
243
- */
244
- constructor(locale, config) {
245
- const providers = config.providers;
246
- const extraProviders = config.extraProviders || [];
247
- const removedProviders = new Set(config.removeProviders);
248
- const providerDefinitions = providers
249
- .concat(extraProviders)
250
- .filter(provider => {
251
- const name = provider.name;
252
- if (!name) {
253
- /**
254
- * One of the providers (or extra providers) specified in the media embed configuration
255
- * has no name and will not be used by the editor. In order to get this media
256
- * provider working, double check your editor configuration.
257
- *
258
- * @error media-embed-no-provider-name
259
- */
260
- logWarning('media-embed-no-provider-name', { provider });
261
- return false;
262
- }
263
- return !removedProviders.has(name);
264
- });
265
- this.locale = locale;
266
- this.providerDefinitions = providerDefinitions;
267
- }
268
- /**
269
- * Checks whether the passed URL is representing a certain media type allowed in the editor.
270
- *
271
- * @param url The URL to be checked
272
- */
273
- hasMedia(url) {
274
- return !!this._getMedia(url);
275
- }
276
- /**
277
- * For the given media URL string and options, it returns the {@link module:engine/view/element~Element view element}
278
- * representing that media.
279
- *
280
- * **Note:** If no URL is specified, an empty view element is returned.
281
- *
282
- * @param writer The view writer used to produce a view element.
283
- * @param url The URL to be translated into a view element.
284
- */
285
- getMediaViewElement(writer, url, options) {
286
- return this._getMedia(url).getViewElement(writer, options);
287
- }
288
- /**
289
- * Returns a `Media` instance for the given URL.
290
- *
291
- * @param url The URL of the media.
292
- * @returns The `Media` instance or `null` when there is none.
293
- */
294
- _getMedia(url) {
295
- if (!url) {
296
- return new Media(this.locale);
297
- }
298
- url = url.trim();
299
- for (const definition of this.providerDefinitions) {
300
- const previewRenderer = definition.html;
301
- const pattern = toArray(definition.url);
302
- for (const subPattern of pattern) {
303
- const match = this._getUrlMatches(url, subPattern);
304
- if (match) {
305
- return new Media(this.locale, url, match, previewRenderer);
306
- }
307
- }
308
- }
309
- return null;
310
- }
311
- /**
312
- * Tries to match `url` to `pattern`.
313
- *
314
- * @param url The URL of the media.
315
- * @param pattern The pattern that should accept the media URL.
316
- */
317
- _getUrlMatches(url, pattern) {
318
- // 1. Try to match without stripping the protocol and "www" subdomain.
319
- let match = url.match(pattern);
320
- if (match) {
321
- return match;
322
- }
323
- // 2. Try to match after stripping the protocol.
324
- let rawUrl = url.replace(/^https?:\/\//, '');
325
- match = rawUrl.match(pattern);
326
- if (match) {
327
- return match;
328
- }
329
- // 3. Try to match after stripping the "www" subdomain.
330
- rawUrl = rawUrl.replace(/^www\./, '');
331
- match = rawUrl.match(pattern);
332
- if (match) {
333
- return match;
334
- }
335
- return null;
336
- }
337
- }
338
- /**
339
- * Represents media defined by the provider configuration.
340
- *
341
- * It can be rendered to the {@link module:engine/view/element~Element view element} and used in the editing or data pipeline.
342
- */
343
- class Media {
344
- constructor(locale, url, match, previewRenderer) {
345
- this.url = this._getValidUrl(url);
346
- this._locale = locale;
347
- this._match = match;
348
- this._previewRenderer = previewRenderer;
349
- }
350
- /**
351
- * Returns the view element representation of the media.
352
- *
353
- * @param writer The view writer used to produce a view element.
354
- */
355
- getViewElement(writer, options) {
356
- const attributes = {};
357
- let viewElement;
358
- if (options.renderForEditingView || (options.renderMediaPreview && this.url && this._previewRenderer)) {
359
- if (this.url) {
360
- attributes['data-oembed-url'] = this.url;
361
- }
362
- if (options.renderForEditingView) {
363
- attributes.class = 'ck-media__wrapper';
364
- }
365
- const mediaHtml = this._getPreviewHtml(options);
366
- viewElement = writer.createRawElement('div', attributes, (domElement, domConverter) => {
367
- domConverter.setContentOf(domElement, mediaHtml);
368
- });
369
- }
370
- else {
371
- if (this.url) {
372
- attributes.url = this.url;
373
- }
374
- viewElement = writer.createEmptyElement(options.elementName, attributes);
375
- }
376
- writer.setCustomProperty('media-content', true, viewElement);
377
- return viewElement;
378
- }
379
- /**
380
- * Returns the HTML string of the media content preview.
381
- */
382
- _getPreviewHtml(options) {
383
- if (this._previewRenderer) {
384
- return this._previewRenderer(this._match);
385
- }
386
- else {
387
- // The placeholder only makes sense for editing view and media which have URLs.
388
- // Placeholder is never displayed in data and URL-less media have no content.
389
- if (this.url && options.renderForEditingView) {
390
- return this._getPlaceholderHtml();
391
- }
392
- return '';
393
- }
394
- }
395
- /**
396
- * Returns the placeholder HTML when the media has no content preview.
397
- */
398
- _getPlaceholderHtml() {
399
- const icon = new IconView();
400
- const t = this._locale.t;
401
- icon.content = mediaPlaceholderIcon;
402
- icon.viewBox = mediaPlaceholderIconViewBox;
403
- const placeholder = new Template({
404
- tag: 'div',
405
- attributes: {
406
- class: 'ck ck-reset_all ck-media__placeholder'
407
- },
408
- children: [
409
- {
410
- tag: 'div',
411
- attributes: {
412
- class: 'ck-media__placeholder__icon'
413
- },
414
- children: [icon]
415
- },
416
- {
417
- tag: 'a',
418
- attributes: {
419
- class: 'ck-media__placeholder__url',
420
- target: '_blank',
421
- rel: 'noopener noreferrer',
422
- href: this.url,
423
- 'data-cke-tooltip-text': t('Open media in new tab')
424
- },
425
- children: [
426
- {
427
- tag: 'span',
428
- attributes: {
429
- class: 'ck-media__placeholder__url__text'
430
- },
431
- children: [this.url]
432
- }
433
- ]
434
- }
435
- ]
436
- }).render();
437
- return placeholder.outerHTML;
438
- }
439
- /**
440
- * Returns the full URL to the specified media.
441
- *
442
- * @param url The URL of the media.
443
- */
444
- _getValidUrl(url) {
445
- if (!url) {
446
- return null;
447
- }
448
- if (url.match(/^https?/)) {
449
- return url;
450
- }
451
- return 'https://' + url;
452
- }
453
- }
454
-
455
- /**
456
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
457
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
458
- */
459
- /**
460
- * @module media-embed/mediaembedediting
461
- */
462
- /**
463
- * The media embed editing feature.
464
- */
465
- class MediaEmbedEditing extends Plugin {
466
- /**
467
- * @inheritDoc
468
- */
469
- static get pluginName() {
470
- return 'MediaEmbedEditing';
471
- }
472
- /**
473
- * @inheritDoc
474
- */
475
- constructor(editor) {
476
- super(editor);
477
- editor.config.define('mediaEmbed', {
478
- elementName: 'oembed',
479
- providers: [
480
- {
481
- name: 'dailymotion',
482
- url: [
483
- /^dailymotion\.com\/video\/(\w+)/,
484
- /^dai.ly\/(\w+)/
485
- ],
486
- html: match => {
487
- const id = match[1];
488
- return ('<div style="position: relative; padding-bottom: 100%; height: 0; ">' +
489
- `<iframe src="https://www.dailymotion.com/embed/video/${id}" ` +
490
- 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' +
491
- 'frameborder="0" width="480" height="270" allowfullscreen allow="autoplay">' +
492
- '</iframe>' +
493
- '</div>');
494
- }
495
- },
496
- {
497
- name: 'spotify',
498
- url: [
499
- /^open\.spotify\.com\/(artist\/\w+)/,
500
- /^open\.spotify\.com\/(album\/\w+)/,
501
- /^open\.spotify\.com\/(track\/\w+)/
502
- ],
503
- html: match => {
504
- const id = match[1];
505
- return ('<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 126%;">' +
506
- `<iframe src="https://open.spotify.com/embed/${id}" ` +
507
- 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' +
508
- 'frameborder="0" allowtransparency="true" allow="encrypted-media">' +
509
- '</iframe>' +
510
- '</div>');
511
- }
512
- },
513
- {
514
- name: 'youtube',
515
- url: [
516
- /^(?:m\.)?youtube\.com\/watch\?v=([\w-]+)(?:&t=(\d+))?/,
517
- /^(?:m\.)?youtube\.com\/v\/([\w-]+)(?:\?t=(\d+))?/,
518
- /^youtube\.com\/embed\/([\w-]+)(?:\?start=(\d+))?/,
519
- /^youtu\.be\/([\w-]+)(?:\?t=(\d+))?/
520
- ],
521
- html: match => {
522
- const id = match[1];
523
- const time = match[2];
524
- return ('<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 56.2493%;">' +
525
- `<iframe src="https://www.youtube.com/embed/${id}${time ? `?start=${time}` : ''}" ` +
526
- 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' +
527
- 'frameborder="0" allow="autoplay; encrypted-media" allowfullscreen>' +
528
- '</iframe>' +
529
- '</div>');
530
- }
531
- },
532
- {
533
- name: 'vimeo',
534
- url: [
535
- /^vimeo\.com\/(\d+)/,
536
- /^vimeo\.com\/[^/]+\/[^/]+\/video\/(\d+)/,
537
- /^vimeo\.com\/album\/[^/]+\/video\/(\d+)/,
538
- /^vimeo\.com\/channels\/[^/]+\/(\d+)/,
539
- /^vimeo\.com\/groups\/[^/]+\/videos\/(\d+)/,
540
- /^vimeo\.com\/ondemand\/[^/]+\/(\d+)/,
541
- /^player\.vimeo\.com\/video\/(\d+)/
542
- ],
543
- html: match => {
544
- const id = match[1];
545
- return ('<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 56.2493%;">' +
546
- `<iframe src="https://player.vimeo.com/video/${id}" ` +
547
- 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' +
548
- 'frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>' +
549
- '</iframe>' +
550
- '</div>');
551
- }
552
- },
553
- {
554
- name: 'instagram',
555
- url: /^instagram\.com\/p\/(\w+)/
556
- },
557
- {
558
- name: 'twitter',
559
- url: /^twitter\.com/
560
- },
561
- {
562
- name: 'googleMaps',
563
- url: [
564
- /^google\.com\/maps/,
565
- /^goo\.gl\/maps/,
566
- /^maps\.google\.com/,
567
- /^maps\.app\.goo\.gl/
568
- ]
569
- },
570
- {
571
- name: 'flickr',
572
- url: /^flickr\.com/
573
- },
574
- {
575
- name: 'facebook',
576
- url: /^facebook\.com/
577
- }
578
- ]
579
- });
580
- this.registry = new MediaRegistry(editor.locale, editor.config.get('mediaEmbed'));
581
- }
582
- /**
583
- * @inheritDoc
584
- */
585
- init() {
586
- const editor = this.editor;
587
- const schema = editor.model.schema;
588
- const t = editor.t;
589
- const conversion = editor.conversion;
590
- const renderMediaPreview = editor.config.get('mediaEmbed.previewsInData');
591
- const elementName = editor.config.get('mediaEmbed.elementName');
592
- const registry = this.registry;
593
- editor.commands.add('mediaEmbed', new MediaEmbedCommand(editor));
594
- // Configure the schema.
595
- schema.register('media', {
596
- inheritAllFrom: '$blockObject',
597
- allowAttributes: ['url']
598
- });
599
- // Model -> Data
600
- conversion.for('dataDowncast').elementToStructure({
601
- model: 'media',
602
- view: (modelElement, { writer }) => {
603
- const url = modelElement.getAttribute('url');
604
- return createMediaFigureElement(writer, registry, url, {
605
- elementName,
606
- renderMediaPreview: !!url && renderMediaPreview
607
- });
608
- }
609
- });
610
- // Model -> Data (url -> data-oembed-url)
611
- conversion.for('dataDowncast').add(modelToViewUrlAttributeConverter(registry, {
612
- elementName,
613
- renderMediaPreview
614
- }));
615
- // Model -> View (element)
616
- conversion.for('editingDowncast').elementToStructure({
617
- model: 'media',
618
- view: (modelElement, { writer }) => {
619
- const url = modelElement.getAttribute('url');
620
- const figure = createMediaFigureElement(writer, registry, url, {
621
- elementName,
622
- renderForEditingView: true
623
- });
624
- return toMediaWidget(figure, writer, t('media widget'));
625
- }
626
- });
627
- // Model -> View (url -> data-oembed-url)
628
- conversion.for('editingDowncast').add(modelToViewUrlAttributeConverter(registry, {
629
- elementName,
630
- renderForEditingView: true
631
- }));
632
- // View -> Model (data-oembed-url -> url)
633
- conversion.for('upcast')
634
- // Upcast semantic media.
635
- .elementToElement({
636
- view: element => ['oembed', elementName].includes(element.name) && element.getAttribute('url') ?
637
- { name: true } :
638
- null,
639
- model: (viewMedia, { writer }) => {
640
- const url = viewMedia.getAttribute('url');
641
- if (registry.hasMedia(url)) {
642
- return writer.createElement('media', { url });
643
- }
644
- return null;
645
- }
646
- })
647
- // Upcast non-semantic media.
648
- .elementToElement({
649
- view: {
650
- name: 'div',
651
- attributes: {
652
- 'data-oembed-url': true
653
- }
654
- },
655
- model: (viewMedia, { writer }) => {
656
- const url = viewMedia.getAttribute('data-oembed-url');
657
- if (registry.hasMedia(url)) {
658
- return writer.createElement('media', { url });
659
- }
660
- return null;
661
- }
662
- })
663
- // Consume `<figure class="media">` elements, that were left after upcast.
664
- .add(dispatcher => {
665
- const converter = (evt, data, conversionApi) => {
666
- if (!conversionApi.consumable.consume(data.viewItem, { name: true, classes: 'media' })) {
667
- return;
668
- }
669
- const { modelRange, modelCursor } = conversionApi.convertChildren(data.viewItem, data.modelCursor);
670
- data.modelRange = modelRange;
671
- data.modelCursor = modelCursor;
672
- const modelElement = first(modelRange.getItems());
673
- if (!modelElement) {
674
- // Revert consumed figure so other features can convert it.
675
- conversionApi.consumable.revert(data.viewItem, { name: true, classes: 'media' });
676
- }
677
- };
678
- dispatcher.on('element:figure', converter);
679
- });
680
- }
681
- }
682
-
683
- /**
684
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
685
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
686
- */
687
- /**
688
- * @module media-embed/automediaembed
689
- */
690
- const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
691
- /**
692
- * The auto-media embed plugin. It recognizes media links in the pasted content and embeds
693
- * them shortly after they are injected into the document.
694
- */
695
- class AutoMediaEmbed extends Plugin {
696
- /**
697
- * @inheritDoc
698
- */
699
- static get requires() {
700
- return [Clipboard, Delete, Undo];
701
- }
702
- /**
703
- * @inheritDoc
704
- */
705
- static get pluginName() {
706
- return 'AutoMediaEmbed';
707
- }
708
- /**
709
- * @inheritDoc
710
- */
711
- constructor(editor) {
712
- super(editor);
713
- this._timeoutId = null;
714
- this._positionToInsert = null;
715
- }
716
- /**
717
- * @inheritDoc
718
- */
719
- init() {
720
- const editor = this.editor;
721
- const modelDocument = editor.model.document;
722
- // We need to listen on `Clipboard#inputTransformation` because we need to save positions of selection.
723
- // After pasting, the content between those positions will be checked for a URL that could be transformed
724
- // into media.
725
- const clipboardPipeline = editor.plugins.get('ClipboardPipeline');
726
- this.listenTo(clipboardPipeline, 'inputTransformation', () => {
727
- const firstRange = modelDocument.selection.getFirstRange();
728
- const leftLivePosition = LivePosition.fromPosition(firstRange.start);
729
- leftLivePosition.stickiness = 'toPrevious';
730
- const rightLivePosition = LivePosition.fromPosition(firstRange.end);
731
- rightLivePosition.stickiness = 'toNext';
732
- modelDocument.once('change:data', () => {
733
- this._embedMediaBetweenPositions(leftLivePosition, rightLivePosition);
734
- leftLivePosition.detach();
735
- rightLivePosition.detach();
736
- }, { priority: 'high' });
737
- });
738
- const undoCommand = editor.commands.get('undo');
739
- undoCommand.on('execute', () => {
740
- if (this._timeoutId) {
741
- global.window.clearTimeout(this._timeoutId);
742
- this._positionToInsert.detach();
743
- this._timeoutId = null;
744
- this._positionToInsert = null;
745
- }
746
- }, { priority: 'high' });
747
- }
748
- /**
749
- * Analyzes the part of the document between provided positions in search for a URL representing media.
750
- * When the URL is found, it is automatically converted into media.
751
- *
752
- * @param leftPosition Left position of the selection.
753
- * @param rightPosition Right position of the selection.
754
- */
755
- _embedMediaBetweenPositions(leftPosition, rightPosition) {
756
- const editor = this.editor;
757
- const mediaRegistry = editor.plugins.get(MediaEmbedEditing).registry;
758
- // TODO: Use marker instead of LiveRange & LivePositions.
759
- const urlRange = new LiveRange(leftPosition, rightPosition);
760
- const walker = urlRange.getWalker({ ignoreElementEnd: true });
761
- let url = '';
762
- for (const node of walker) {
763
- if (node.item.is('$textProxy')) {
764
- url += node.item.data;
765
- }
766
- }
767
- url = url.trim();
768
- // If the URL does not match to universal URL regexp, let's skip that.
769
- if (!url.match(URL_REGEXP)) {
770
- urlRange.detach();
771
- return;
772
- }
773
- // If the URL represents a media, let's use it.
774
- if (!mediaRegistry.hasMedia(url)) {
775
- urlRange.detach();
776
- return;
777
- }
778
- const mediaEmbedCommand = editor.commands.get('mediaEmbed');
779
- // Do not anything if media element cannot be inserted at the current position (#47).
780
- if (!mediaEmbedCommand.isEnabled) {
781
- urlRange.detach();
782
- return;
783
- }
784
- // Position won't be available in the `setTimeout` function so let's clone it.
785
- this._positionToInsert = LivePosition.fromPosition(leftPosition);
786
- // This action mustn't be executed if undo was called between pasting and auto-embedding.
787
- this._timeoutId = global.window.setTimeout(() => {
788
- editor.model.change(writer => {
789
- this._timeoutId = null;
790
- writer.remove(urlRange);
791
- urlRange.detach();
792
- let insertionPosition = null;
793
- // Check if position where the media element should be inserted is still valid.
794
- // Otherwise leave it as undefined to use document.selection - default behavior of model.insertContent().
795
- if (this._positionToInsert.root.rootName !== '$graveyard') {
796
- insertionPosition = this._positionToInsert;
797
- }
798
- insertMedia(editor.model, url, insertionPosition, false);
799
- this._positionToInsert.detach();
800
- this._positionToInsert = null;
801
- });
802
- editor.plugins.get(Delete).requestUndoOnBackspace();
803
- }, 100);
804
- }
805
- }
806
-
807
- /**
808
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
809
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
810
- */
811
- /**
812
- * @module media-embed/ui/mediaformview
813
- */
814
- /**
815
- * The media form view controller class.
816
- *
817
- * See {@link module:media-embed/ui/mediaformview~MediaFormView}.
818
- */
819
- class MediaFormView extends View {
820
- /**
821
- * @param validators Form validators used by {@link #isValid}.
822
- * @param locale The localization services instance.
823
- */
824
- constructor(validators, locale) {
825
- super(locale);
826
- const t = locale.t;
827
- this.focusTracker = new FocusTracker();
828
- this.keystrokes = new KeystrokeHandler();
829
- this.set('mediaURLInputValue', '');
830
- this.urlInputView = this._createUrlInput();
831
- this.saveButtonView = this._createButton(t('Save'), icons.check, 'ck-button-save');
832
- this.saveButtonView.type = 'submit';
833
- this.saveButtonView.bind('isEnabled').to(this, 'mediaURLInputValue', value => !!value);
834
- this.cancelButtonView = this._createButton(t('Cancel'), icons.cancel, 'ck-button-cancel', 'cancel');
835
- this._focusables = new ViewCollection();
836
- this._focusCycler = new FocusCycler({
837
- focusables: this._focusables,
838
- focusTracker: this.focusTracker,
839
- keystrokeHandler: this.keystrokes,
840
- actions: {
841
- // Navigate form fields backwards using the <kbd>Shift</kbd> + <kbd>Tab</kbd> keystroke.
842
- focusPrevious: 'shift + tab',
843
- // Navigate form fields forwards using the <kbd>Tab</kbd> key.
844
- focusNext: 'tab'
845
- }
846
- });
847
- this._validators = validators;
848
- this.setTemplate({
849
- tag: 'form',
850
- attributes: {
851
- class: [
852
- 'ck',
853
- 'ck-media-form',
854
- 'ck-responsive-form'
855
- ],
856
- tabindex: '-1'
857
- },
858
- children: [
859
- this.urlInputView,
860
- this.saveButtonView,
861
- this.cancelButtonView
862
- ]
863
- });
864
- }
865
- /**
866
- * @inheritDoc
867
- */
868
- render() {
869
- super.render();
870
- submitHandler({
871
- view: this
872
- });
873
- const childViews = [
874
- this.urlInputView,
875
- this.saveButtonView,
876
- this.cancelButtonView
877
- ];
878
- childViews.forEach(v => {
879
- // Register the view as focusable.
880
- this._focusables.add(v);
881
- // Register the view in the focus tracker.
882
- this.focusTracker.add(v.element);
883
- });
884
- // Start listening for the keystrokes coming from #element.
885
- this.keystrokes.listenTo(this.element);
886
- const stopPropagation = (data) => data.stopPropagation();
887
- // Since the form is in the dropdown panel which is a child of the toolbar, the toolbar's
888
- // keystroke handler would take over the key management in the URL input. We need to prevent
889
- // this ASAP. Otherwise, the basic caret movement using the arrow keys will be impossible.
890
- this.keystrokes.set('arrowright', stopPropagation);
891
- this.keystrokes.set('arrowleft', stopPropagation);
892
- this.keystrokes.set('arrowup', stopPropagation);
893
- this.keystrokes.set('arrowdown', stopPropagation);
894
- }
895
- /**
896
- * @inheritDoc
897
- */
898
- destroy() {
899
- super.destroy();
900
- this.focusTracker.destroy();
901
- this.keystrokes.destroy();
902
- }
903
- /**
904
- * Focuses the fist {@link #_focusables} in the form.
905
- */
906
- focus() {
907
- this._focusCycler.focusFirst();
908
- }
909
- /**
910
- * The native DOM `value` of the {@link #urlInputView} element.
911
- *
912
- * **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
913
- * which works one way only and may not represent the actual state of the component in the DOM.
914
- */
915
- get url() {
916
- return this.urlInputView.fieldView.element.value.trim();
917
- }
918
- set url(url) {
919
- this.urlInputView.fieldView.element.value = url.trim();
920
- }
921
- /**
922
- * Validates the form and returns `false` when some fields are invalid.
923
- */
924
- isValid() {
925
- this.resetFormStatus();
926
- for (const validator of this._validators) {
927
- const errorText = validator(this);
928
- // One error per field is enough.
929
- if (errorText) {
930
- // Apply updated error.
931
- this.urlInputView.errorText = errorText;
932
- return false;
933
- }
934
- }
935
- return true;
936
- }
937
- /**
938
- * Cleans up the supplementary error and information text of the {@link #urlInputView}
939
- * bringing them back to the state when the form has been displayed for the first time.
940
- *
941
- * See {@link #isValid}.
942
- */
943
- resetFormStatus() {
944
- this.urlInputView.errorText = null;
945
- this.urlInputView.infoText = this._urlInputViewInfoDefault;
946
- }
947
- /**
948
- * Creates a labeled input view.
949
- *
950
- * @returns Labeled input view instance.
951
- */
952
- _createUrlInput() {
953
- const t = this.locale.t;
954
- const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
955
- const inputField = labeledInput.fieldView;
956
- this._urlInputViewInfoDefault = t('Paste the media URL in the input.');
957
- this._urlInputViewInfoTip = t('Tip: Paste the URL into the content to embed faster.');
958
- labeledInput.label = t('Media URL');
959
- labeledInput.infoText = this._urlInputViewInfoDefault;
960
- inputField.on('input', () => {
961
- // Display the tip text only when there is some value. Otherwise fall back to the default info text.
962
- labeledInput.infoText = inputField.element.value ? this._urlInputViewInfoTip : this._urlInputViewInfoDefault;
963
- this.mediaURLInputValue = inputField.element.value.trim();
964
- });
965
- return labeledInput;
966
- }
967
- /**
968
- * Creates a button view.
969
- *
970
- * @param label The button label.
971
- * @param icon The button icon.
972
- * @param className The additional button CSS class name.
973
- * @param eventName An event name that the `ButtonView#execute` event will be delegated to.
974
- * @returns The button view instance.
975
- */
976
- _createButton(label, icon, className, eventName) {
977
- const button = new ButtonView(this.locale);
978
- button.set({
979
- label,
980
- icon,
981
- tooltip: true
982
- });
983
- button.extendTemplate({
984
- attributes: {
985
- class: className
986
- }
987
- });
988
- if (eventName) {
989
- button.delegate('execute').to(this, eventName);
990
- }
991
- return button;
992
- }
993
- }
994
-
995
- var mediaIcon = "<svg viewBox=\"0 0 22 20\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M1.587 1.5c-.612 0-.601-.029-.601.551v14.84c0 .59-.01.559.591.559h18.846c.602 0 .591.03.591-.56V2.052c0-.58.01-.55-.591-.55H1.587Zm.701.971h1.003v1H2.288v-1Zm16.448 0h1.003v1h-1.003v-1Zm-14.24 1h13.008v12H4.467l.029-12Zm-2.208 1h1.003v1H2.288v-1Zm16.448 0h1.003v1h-1.003v-1Zm-16.448 2h1.003v1H2.288v-1Zm16.448 0h1.003v1h-1.003v-1Zm-16.448 2h1.003v1H2.288v-1Zm16.448 0h1.003v1h-1.003v-1Zm-16.448 2h1.003v1H2.288v-1Zm16.448 0h1.003v1h-1.003v-1Zm-16.448 2h1.003l-.029 1h-.974v-1Zm16.448 0h1.003v1h-1.003v-1Zm-16.448 2h.974v1h-.974v-1Zm16.448 0h1.003v1h-1.003v-1Z\"/><path d=\"M8.374 6.648a.399.399 0 0 1 .395-.4.402.402 0 0 1 .2.049l5.148 2.824a.4.4 0 0 1 0 .7l-5.148 2.824a.403.403 0 0 1-.595-.35V6.648Z\"/></svg>";
996
-
997
- /**
998
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
999
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
1000
- */
1001
- /**
1002
- * @module media-embed/mediaembedui
1003
- */
1004
- /**
1005
- * The media embed UI plugin.
1006
- */
1007
- class MediaEmbedUI extends Plugin {
1008
- /**
1009
- * @inheritDoc
1010
- */
1011
- static get requires() {
1012
- return [MediaEmbedEditing];
1013
- }
1014
- /**
1015
- * @inheritDoc
1016
- */
1017
- static get pluginName() {
1018
- return 'MediaEmbedUI';
1019
- }
1020
- /**
1021
- * @inheritDoc
1022
- */
1023
- init() {
1024
- const editor = this.editor;
1025
- const command = editor.commands.get('mediaEmbed');
1026
- editor.ui.componentFactory.add('mediaEmbed', locale => {
1027
- const dropdown = createDropdown(locale);
1028
- this._setUpDropdown(dropdown, command);
1029
- return dropdown;
1030
- });
1031
- }
1032
- _setUpDropdown(dropdown, command) {
1033
- const editor = this.editor;
1034
- const t = editor.t;
1035
- const button = dropdown.buttonView;
1036
- const registry = editor.plugins.get(MediaEmbedEditing).registry;
1037
- dropdown.once('change:isOpen', () => {
1038
- const form = new (CssTransitionDisablerMixin(MediaFormView))(getFormValidators(editor.t, registry), editor.locale);
1039
- dropdown.panelView.children.add(form);
1040
- // Note: Use the low priority to make sure the following listener starts working after the
1041
- // default action of the drop-down is executed (i.e. the panel showed up). Otherwise, the
1042
- // invisible form/input cannot be focused/selected.
1043
- button.on('open', () => {
1044
- form.disableCssTransitions();
1045
- // Make sure that each time the panel shows up, the URL field remains in sync with the value of
1046
- // the command. If the user typed in the input, then canceled (`urlInputView#fieldView#value` stays
1047
- // unaltered) and re-opened it without changing the value of the media command (e.g. because they
1048
- // didn't change the selection), they would see the old value instead of the actual value of the
1049
- // command.
1050
- form.url = command.value || '';
1051
- form.urlInputView.fieldView.select();
1052
- form.enableCssTransitions();
1053
- }, { priority: 'low' });
1054
- dropdown.on('submit', () => {
1055
- if (form.isValid()) {
1056
- editor.execute('mediaEmbed', form.url);
1057
- editor.editing.view.focus();
1058
- }
1059
- });
1060
- dropdown.on('change:isOpen', () => form.resetFormStatus());
1061
- dropdown.on('cancel', () => {
1062
- editor.editing.view.focus();
1063
- });
1064
- form.delegate('submit', 'cancel').to(dropdown);
1065
- form.urlInputView.fieldView.bind('value').to(command, 'value');
1066
- // Form elements should be read-only when corresponding commands are disabled.
1067
- form.urlInputView.bind('isEnabled').to(command, 'isEnabled');
1068
- });
1069
- dropdown.bind('isEnabled').to(command);
1070
- button.set({
1071
- label: t('Insert media'),
1072
- icon: mediaIcon,
1073
- tooltip: true
1074
- });
1075
- }
1076
- }
1077
- function getFormValidators(t, registry) {
1078
- return [
1079
- form => {
1080
- if (!form.url.length) {
1081
- return t('The URL must not be empty.');
1082
- }
1083
- },
1084
- form => {
1085
- if (!registry.hasMedia(form.url)) {
1086
- return t('This media URL is not supported.');
1087
- }
1088
- }
1089
- ];
1090
- }
1091
-
1092
- /**
1093
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
1094
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
1095
- */
1096
- /**
1097
- * @module media-embed/mediaembed
1098
- */
1099
- /**
1100
- * The media embed plugin.
1101
- *
1102
- * For a detailed overview, check the {@glink features/media-embed Media Embed feature documentation}.
1103
- *
1104
- * This is a "glue" plugin which loads the following plugins:
1105
- *
1106
- * * The {@link module:media-embed/mediaembedediting~MediaEmbedEditing media embed editing feature},
1107
- * * The {@link module:media-embed/mediaembedui~MediaEmbedUI media embed UI feature} and
1108
- * * The {@link module:media-embed/automediaembed~AutoMediaEmbed auto-media embed feature}.
1109
- */
1110
- class MediaEmbed extends Plugin {
1111
- /**
1112
- * @inheritDoc
1113
- */
1114
- static get requires() {
1115
- return [MediaEmbedEditing, MediaEmbedUI, AutoMediaEmbed, Widget];
1116
- }
1117
- /**
1118
- * @inheritDoc
1119
- */
1120
- static get pluginName() {
1121
- return 'MediaEmbed';
1122
- }
1123
- }
1124
-
1125
- /**
1126
- * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
1127
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
1128
- */
1129
- /**
1130
- * @module media-embed/mediaembedtoolbar
1131
- */
1132
- /**
1133
- * The media embed toolbar plugin. It creates a toolbar for media embed that shows up when the media element is selected.
1134
- *
1135
- * Instances of toolbar components (e.g. buttons) are created based on the
1136
- * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#toolbar `media.toolbar` configuration option}.
1137
- */
1138
- class MediaEmbedToolbar extends Plugin {
1139
- /**
1140
- * @inheritDoc
1141
- */
1142
- static get requires() {
1143
- return [WidgetToolbarRepository];
1144
- }
1145
- /**
1146
- * @inheritDoc
1147
- */
1148
- static get pluginName() {
1149
- return 'MediaEmbedToolbar';
1150
- }
1151
- /**
1152
- * @inheritDoc
1153
- */
1154
- afterInit() {
1155
- const editor = this.editor;
1156
- const t = editor.t;
1157
- const widgetToolbarRepository = editor.plugins.get(WidgetToolbarRepository);
1158
- widgetToolbarRepository.register('mediaEmbed', {
1159
- ariaLabel: t('Media toolbar'),
1160
- items: editor.config.get('mediaEmbed.toolbar') || [],
1161
- getRelatedElement: getSelectedMediaViewWidget
1162
- });
1163
- }
1164
- }
1165
-
1166
- export { AutoMediaEmbed, MediaEmbed, MediaEmbedEditing, MediaEmbedToolbar, MediaEmbedUI };
1167
- //# sourceMappingURL=index.js.map