@ckeditor/ckeditor5-media-embed 0.0.0-nightly-20241215.0 → 0.0.0-nightly-20241217.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.

Potentially problematic release.


This version of @ckeditor/ckeditor5-media-embed might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -15,8 +15,6 @@ import { Undo } from '@ckeditor/ckeditor5-undo/dist/index.js';
15
15
  * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
16
16
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
17
17
  */ /**
18
- * @module media-embed/converters
19
- */ /**
20
18
  * Returns a function that converts the model "url" attribute to the view representation.
21
19
  *
22
20
  * Depending on the configuration, the view representation can be "semantic" (for the data pipeline):
@@ -159,8 +157,8 @@ import { Undo } from '@ckeditor/ckeditor5-undo/dist/index.js';
159
157
  * ```
160
158
  */ class MediaEmbedCommand extends Command {
161
159
  /**
162
- * @inheritDoc
163
- */ refresh() {
160
+ * @inheritDoc
161
+ */ refresh() {
164
162
  const model = this.editor.model;
165
163
  const selection = model.document.selection;
166
164
  const selectedMedia = getSelectedMediaModelWidget(selection);
@@ -168,14 +166,14 @@ import { Undo } from '@ckeditor/ckeditor5-undo/dist/index.js';
168
166
  this.isEnabled = isMediaSelected(selection) || isAllowedInParent(selection, model);
169
167
  }
170
168
  /**
171
- * Executes the command, which either:
172
- *
173
- * * updates the URL of the selected media,
174
- * * inserts the new media into the editor and puts the selection around it.
175
- *
176
- * @fires execute
177
- * @param url The URL of the media.
178
- */ execute(url) {
169
+ * Executes the command, which either:
170
+ *
171
+ * * updates the URL of the selected media,
172
+ * * inserts the new media into the editor and puts the selection around it.
173
+ *
174
+ * @fires execute
175
+ * @param url The URL of the media.
176
+ */ execute(url) {
179
177
  const model = this.editor.model;
180
178
  const selection = model.document.selection;
181
179
  const selectedMedia = getSelectedMediaModelWidget(selection);
@@ -217,18 +215,11 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
217
215
  * Mostly used by the {@link module:media-embed/mediaembedediting~MediaEmbedEditing} plugin.
218
216
  */ class MediaRegistry {
219
217
  /**
220
- * The {@link module:utils/locale~Locale} instance.
221
- */ locale;
222
- /**
223
- * The media provider definitions available for the registry. Usually corresponding with the
224
- * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig media configuration}.
225
- */ providerDefinitions;
226
- /**
227
- * Creates an instance of the {@link module:media-embed/mediaregistry~MediaRegistry} class.
228
- *
229
- * @param locale The localization services instance.
230
- * @param config The configuration of the media embed feature.
231
- */ constructor(locale, config){
218
+ * Creates an instance of the {@link module:media-embed/mediaregistry~MediaRegistry} class.
219
+ *
220
+ * @param locale The localization services instance.
221
+ * @param config The configuration of the media embed feature.
222
+ */ constructor(locale, config){
232
223
  const providers = config.providers;
233
224
  const extraProviders = config.extraProviders || [];
234
225
  const removedProviders = new Set(config.removeProviders);
@@ -236,12 +227,12 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
236
227
  const name = provider.name;
237
228
  if (!name) {
238
229
  /**
239
- * One of the providers (or extra providers) specified in the media embed configuration
240
- * has no name and will not be used by the editor. In order to get this media
241
- * provider working, double check your editor configuration.
242
- *
243
- * @error media-embed-no-provider-name
244
- */ logWarning('media-embed-no-provider-name', {
230
+ * One of the providers (or extra providers) specified in the media embed configuration
231
+ * has no name and will not be used by the editor. In order to get this media
232
+ * provider working, double check your editor configuration.
233
+ *
234
+ * @error media-embed-no-provider-name
235
+ */ logWarning('media-embed-no-provider-name', {
245
236
  provider
246
237
  });
247
238
  return false;
@@ -252,29 +243,29 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
252
243
  this.providerDefinitions = providerDefinitions;
253
244
  }
254
245
  /**
255
- * Checks whether the passed URL is representing a certain media type allowed in the editor.
256
- *
257
- * @param url The URL to be checked
258
- */ hasMedia(url) {
246
+ * Checks whether the passed URL is representing a certain media type allowed in the editor.
247
+ *
248
+ * @param url The URL to be checked
249
+ */ hasMedia(url) {
259
250
  return !!this._getMedia(url);
260
251
  }
261
252
  /**
262
- * For the given media URL string and options, it returns the {@link module:engine/view/element~Element view element}
263
- * representing that media.
264
- *
265
- * **Note:** If no URL is specified, an empty view element is returned.
266
- *
267
- * @param writer The view writer used to produce a view element.
268
- * @param url The URL to be translated into a view element.
269
- */ getMediaViewElement(writer, url, options) {
253
+ * For the given media URL string and options, it returns the {@link module:engine/view/element~Element view element}
254
+ * representing that media.
255
+ *
256
+ * **Note:** If no URL is specified, an empty view element is returned.
257
+ *
258
+ * @param writer The view writer used to produce a view element.
259
+ * @param url The URL to be translated into a view element.
260
+ */ getMediaViewElement(writer, url, options) {
270
261
  return this._getMedia(url).getViewElement(writer, options);
271
262
  }
272
263
  /**
273
- * Returns a `Media` instance for the given URL.
274
- *
275
- * @param url The URL of the media.
276
- * @returns The `Media` instance or `null` when there is none.
277
- */ _getMedia(url) {
264
+ * Returns a `Media` instance for the given URL.
265
+ *
266
+ * @param url The URL of the media.
267
+ * @returns The `Media` instance or `null` when there is none.
268
+ */ _getMedia(url) {
278
269
  if (!url) {
279
270
  return new Media(this.locale);
280
271
  }
@@ -292,11 +283,11 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
292
283
  return null;
293
284
  }
294
285
  /**
295
- * Tries to match `url` to `pattern`.
296
- *
297
- * @param url The URL of the media.
298
- * @param pattern The pattern that should accept the media URL.
299
- */ _getUrlMatches(url, pattern) {
286
+ * Tries to match `url` to `pattern`.
287
+ *
288
+ * @param url The URL of the media.
289
+ * @param pattern The pattern that should accept the media URL.
290
+ */ _getUrlMatches(url, pattern) {
300
291
  // 1. Try to match without stripping the protocol and "www" subdomain.
301
292
  let match = url.match(pattern);
302
293
  if (match) {
@@ -322,20 +313,6 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
322
313
  *
323
314
  * It can be rendered to the {@link module:engine/view/element~Element view element} and used in the editing or data pipeline.
324
315
  */ class Media {
325
- /**
326
- * The URL this Media instance represents.
327
- */ url;
328
- /**
329
- * Shorthand for {@link module:utils/locale~Locale#t}.
330
- *
331
- * @see module:utils/locale~Locale#t
332
- */ _locale;
333
- /**
334
- * The output of the `RegExp.match` which validated the {@link #url} of this media.
335
- */ _match;
336
- /**
337
- * The function returning the HTML string preview of this media.
338
- */ _previewRenderer;
339
316
  constructor(locale, url, match, previewRenderer){
340
317
  this.url = this._getValidUrl(url);
341
318
  this._locale = locale;
@@ -343,10 +320,10 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
343
320
  this._previewRenderer = previewRenderer;
344
321
  }
345
322
  /**
346
- * Returns the view element representation of the media.
347
- *
348
- * @param writer The view writer used to produce a view element.
349
- */ getViewElement(writer, options) {
323
+ * Returns the view element representation of the media.
324
+ *
325
+ * @param writer The view writer used to produce a view element.
326
+ */ getViewElement(writer, options) {
350
327
  const attributes = {};
351
328
  let viewElement;
352
329
  if (options.renderForEditingView || options.renderMediaPreview && this.url && this._previewRenderer) {
@@ -370,8 +347,8 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
370
347
  return viewElement;
371
348
  }
372
349
  /**
373
- * Returns the HTML string of the media content preview.
374
- */ _getPreviewHtml(options) {
350
+ * Returns the HTML string of the media content preview.
351
+ */ _getPreviewHtml(options) {
375
352
  if (this._previewRenderer) {
376
353
  return this._previewRenderer(this._match);
377
354
  } else {
@@ -384,8 +361,8 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
384
361
  }
385
362
  }
386
363
  /**
387
- * Returns the placeholder HTML when the media has no content preview.
388
- */ _getPlaceholderHtml() {
364
+ * Returns the placeholder HTML when the media has no content preview.
365
+ */ _getPlaceholderHtml() {
389
366
  const icon = new IconView();
390
367
  const t = this._locale.t;
391
368
  icon.content = mediaPlaceholderIcon;
@@ -431,10 +408,10 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
431
408
  return placeholder.outerHTML;
432
409
  }
433
410
  /**
434
- * Returns the full URL to the specified media.
435
- *
436
- * @param url The URL of the media.
437
- */ _getValidUrl(url) {
411
+ * Returns the full URL to the specified media.
412
+ *
413
+ * @param url The URL of the media.
414
+ */ _getValidUrl(url) {
438
415
  if (!url) {
439
416
  return null;
440
417
  }
@@ -449,21 +426,18 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
449
426
  * The media embed editing feature.
450
427
  */ class MediaEmbedEditing extends Plugin {
451
428
  /**
452
- * @inheritDoc
453
- */ static get pluginName() {
429
+ * @inheritDoc
430
+ */ static get pluginName() {
454
431
  return 'MediaEmbedEditing';
455
432
  }
456
433
  /**
457
- * @inheritDoc
458
- */ static get isOfficialPlugin() {
434
+ * @inheritDoc
435
+ */ static get isOfficialPlugin() {
459
436
  return true;
460
437
  }
461
438
  /**
462
- * The media registry managing the media providers in the editor.
463
- */ registry;
464
- /**
465
- * @inheritDoc
466
- */ constructor(editor){
439
+ * @inheritDoc
440
+ */ constructor(editor){
467
441
  super(editor);
468
442
  editor.config.define('mediaEmbed', {
469
443
  elementName: 'oembed',
@@ -558,8 +532,8 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
558
532
  this.registry = new MediaRegistry(editor.locale, editor.config.get('mediaEmbed'));
559
533
  }
560
534
  /**
561
- * @inheritDoc
562
- */ init() {
535
+ * @inheritDoc
536
+ */ init() {
563
537
  const editor = this.editor;
564
538
  const schema = editor.model.schema;
565
539
  const t = editor.t;
@@ -675,8 +649,8 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
675
649
  * them shortly after they are injected into the document.
676
650
  */ class AutoMediaEmbed extends Plugin {
677
651
  /**
678
- * @inheritDoc
679
- */ static get requires() {
652
+ * @inheritDoc
653
+ */ static get requires() {
680
654
  return [
681
655
  Clipboard,
682
656
  Delete,
@@ -684,33 +658,25 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
684
658
  ];
685
659
  }
686
660
  /**
687
- * @inheritDoc
688
- */ static get pluginName() {
661
+ * @inheritDoc
662
+ */ static get pluginName() {
689
663
  return 'AutoMediaEmbed';
690
664
  }
691
665
  /**
692
- * @inheritDoc
693
- */ static get isOfficialPlugin() {
666
+ * @inheritDoc
667
+ */ static get isOfficialPlugin() {
694
668
  return true;
695
669
  }
696
670
  /**
697
- * The paste–to–embed `setTimeout` ID. Stored as a property to allow
698
- * cleaning of the timeout.
699
- */ _timeoutId;
700
- /**
701
- * The position where the `<media>` element will be inserted after the timeout,
702
- * determined each time the new content is pasted into the document.
703
- */ _positionToInsert;
704
- /**
705
- * @inheritDoc
706
- */ constructor(editor){
671
+ * @inheritDoc
672
+ */ constructor(editor){
707
673
  super(editor);
708
674
  this._timeoutId = null;
709
675
  this._positionToInsert = null;
710
676
  }
711
677
  /**
712
- * @inheritDoc
713
- */ init() {
678
+ * @inheritDoc
679
+ */ init() {
714
680
  const editor = this.editor;
715
681
  const modelDocument = editor.model.document;
716
682
  // We need to listen on `Clipboard#inputTransformation` because we need to save positions of selection.
@@ -744,12 +710,12 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
744
710
  });
745
711
  }
746
712
  /**
747
- * Analyzes the part of the document between provided positions in search for a URL representing media.
748
- * When the URL is found, it is automatically converted into media.
749
- *
750
- * @param leftPosition Left position of the selection.
751
- * @param rightPosition Right position of the selection.
752
- */ _embedMediaBetweenPositions(leftPosition, rightPosition) {
713
+ * Analyzes the part of the document between provided positions in search for a URL representing media.
714
+ * When the URL is found, it is automatically converted into media.
715
+ *
716
+ * @param leftPosition Left position of the selection.
717
+ * @param rightPosition Right position of the selection.
718
+ */ _embedMediaBetweenPositions(leftPosition, rightPosition) {
753
719
  const editor = this.editor;
754
720
  const mediaRegistry = editor.plugins.get(MediaEmbedEditing).registry;
755
721
  // TODO: Use marker instead of LiveRange & LivePositions.
@@ -809,28 +775,9 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
809
775
  * See {@link module:media-embed/ui/mediaformview~MediaFormView}.
810
776
  */ class MediaFormView extends View {
811
777
  /**
812
- * Tracks information about the DOM focus in the form.
813
- */ focusTracker;
814
- /**
815
- * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
816
- */ keystrokes;
817
- /**
818
- * The URL input view.
819
- */ urlInputView;
820
- /**
821
- * An array of form validators used by {@link #isValid}.
822
- */ _validators;
823
- /**
824
- * The default info text for the {@link #urlInputView}.
825
- */ _urlInputViewInfoDefault;
826
- /**
827
- * The info text with an additional tip for the {@link #urlInputView},
828
- * displayed when the input has some value.
829
- */ _urlInputViewInfoTip;
830
- /**
831
- * @param validators Form validators used by {@link #isValid}.
832
- * @param locale The localization services instance.
833
- */ constructor(validators, locale){
778
+ * @param validators Form validators used by {@link #isValid}.
779
+ * @param locale The localization services instance.
780
+ */ constructor(validators, locale){
834
781
  super(locale);
835
782
  this.focusTracker = new FocusTracker();
836
783
  this.keystrokes = new KeystrokeHandler();
@@ -853,8 +800,8 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
853
800
  });
854
801
  }
855
802
  /**
856
- * @inheritDoc
857
- */ render() {
803
+ * @inheritDoc
804
+ */ render() {
858
805
  super.render();
859
806
  submitHandler({
860
807
  view: this
@@ -865,31 +812,31 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
865
812
  this.keystrokes.listenTo(this.element);
866
813
  }
867
814
  /**
868
- * @inheritDoc
869
- */ destroy() {
815
+ * @inheritDoc
816
+ */ destroy() {
870
817
  super.destroy();
871
818
  this.focusTracker.destroy();
872
819
  this.keystrokes.destroy();
873
820
  }
874
821
  /**
875
- * Focuses the {@link #urlInputView}.
876
- */ focus() {
822
+ * Focuses the {@link #urlInputView}.
823
+ */ focus() {
877
824
  this.urlInputView.focus();
878
825
  }
879
826
  /**
880
- * The native DOM `value` of the {@link #urlInputView} element.
881
- *
882
- * **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
883
- * which works one way only and may not represent the actual state of the component in the DOM.
884
- */ get url() {
827
+ * The native DOM `value` of the {@link #urlInputView} element.
828
+ *
829
+ * **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
830
+ * which works one way only and may not represent the actual state of the component in the DOM.
831
+ */ get url() {
885
832
  return this.urlInputView.fieldView.element.value.trim();
886
833
  }
887
834
  set url(url) {
888
835
  this.urlInputView.fieldView.value = url.trim();
889
836
  }
890
837
  /**
891
- * Validates the form and returns `false` when some fields are invalid.
892
- */ isValid() {
838
+ * Validates the form and returns `false` when some fields are invalid.
839
+ */ isValid() {
893
840
  this.resetFormStatus();
894
841
  for (const validator of this._validators){
895
842
  const errorText = validator(this);
@@ -903,19 +850,19 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
903
850
  return true;
904
851
  }
905
852
  /**
906
- * Cleans up the supplementary error and information text of the {@link #urlInputView}
907
- * bringing them back to the state when the form has been displayed for the first time.
908
- *
909
- * See {@link #isValid}.
910
- */ resetFormStatus() {
853
+ * Cleans up the supplementary error and information text of the {@link #urlInputView}
854
+ * bringing them back to the state when the form has been displayed for the first time.
855
+ *
856
+ * See {@link #isValid}.
857
+ */ resetFormStatus() {
911
858
  this.urlInputView.errorText = null;
912
859
  this.urlInputView.infoText = this._urlInputViewInfoDefault;
913
860
  }
914
861
  /**
915
- * Creates a labeled input view.
916
- *
917
- * @returns Labeled input view instance.
918
- */ _createUrlInput() {
862
+ * Creates a labeled input view.
863
+ *
864
+ * @returns Labeled input view instance.
865
+ */ _createUrlInput() {
919
866
  const t = this.locale.t;
920
867
  const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);
921
868
  const inputField = labeledInput.fieldView;
@@ -939,27 +886,26 @@ var mediaIcon = "<svg viewBox=\"0 0 22 20\" xmlns=\"http://www.w3.org/2000/svg\"
939
886
  * The media embed UI plugin.
940
887
  */ class MediaEmbedUI extends Plugin {
941
888
  /**
942
- * @inheritDoc
943
- */ static get requires() {
889
+ * @inheritDoc
890
+ */ static get requires() {
944
891
  return [
945
892
  MediaEmbedEditing,
946
893
  Dialog
947
894
  ];
948
895
  }
949
896
  /**
950
- * @inheritDoc
951
- */ static get pluginName() {
897
+ * @inheritDoc
898
+ */ static get pluginName() {
952
899
  return 'MediaEmbedUI';
953
900
  }
954
901
  /**
955
- * @inheritDoc
956
- */ static get isOfficialPlugin() {
902
+ * @inheritDoc
903
+ */ static get isOfficialPlugin() {
957
904
  return true;
958
905
  }
959
- _formView;
960
906
  /**
961
- * @inheritDoc
962
- */ init() {
907
+ * @inheritDoc
908
+ */ init() {
963
909
  const editor = this.editor;
964
910
  editor.ui.componentFactory.add('mediaEmbed', ()=>{
965
911
  const t = this.editor.locale.t;
@@ -976,8 +922,8 @@ var mediaIcon = "<svg viewBox=\"0 0 22 20\" xmlns=\"http://www.w3.org/2000/svg\"
976
922
  });
977
923
  }
978
924
  /**
979
- * Creates a button for menu bar that will show media embed dialog.
980
- */ _createDialogButton(ButtonClass) {
925
+ * Creates a button for menu bar that will show media embed dialog.
926
+ */ _createDialogButton(ButtonClass) {
981
927
  const editor = this.editor;
982
928
  const buttonView = new ButtonClass(editor.locale);
983
929
  const command = editor.commands.get('mediaEmbed');
@@ -1065,8 +1011,8 @@ function getFormValidators(t, registry) {
1065
1011
  * * The {@link module:media-embed/automediaembed~AutoMediaEmbed auto-media embed feature}.
1066
1012
  */ class MediaEmbed extends Plugin {
1067
1013
  /**
1068
- * @inheritDoc
1069
- */ static get requires() {
1014
+ * @inheritDoc
1015
+ */ static get requires() {
1070
1016
  return [
1071
1017
  MediaEmbedEditing,
1072
1018
  MediaEmbedUI,
@@ -1075,13 +1021,13 @@ function getFormValidators(t, registry) {
1075
1021
  ];
1076
1022
  }
1077
1023
  /**
1078
- * @inheritDoc
1079
- */ static get pluginName() {
1024
+ * @inheritDoc
1025
+ */ static get pluginName() {
1080
1026
  return 'MediaEmbed';
1081
1027
  }
1082
1028
  /**
1083
- * @inheritDoc
1084
- */ static get isOfficialPlugin() {
1029
+ * @inheritDoc
1030
+ */ static get isOfficialPlugin() {
1085
1031
  return true;
1086
1032
  }
1087
1033
  }
@@ -1093,25 +1039,25 @@ function getFormValidators(t, registry) {
1093
1039
  * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#toolbar `media.toolbar` configuration option}.
1094
1040
  */ class MediaEmbedToolbar extends Plugin {
1095
1041
  /**
1096
- * @inheritDoc
1097
- */ static get requires() {
1042
+ * @inheritDoc
1043
+ */ static get requires() {
1098
1044
  return [
1099
1045
  WidgetToolbarRepository
1100
1046
  ];
1101
1047
  }
1102
1048
  /**
1103
- * @inheritDoc
1104
- */ static get pluginName() {
1049
+ * @inheritDoc
1050
+ */ static get pluginName() {
1105
1051
  return 'MediaEmbedToolbar';
1106
1052
  }
1107
1053
  /**
1108
- * @inheritDoc
1109
- */ static get isOfficialPlugin() {
1054
+ * @inheritDoc
1055
+ */ static get isOfficialPlugin() {
1110
1056
  return true;
1111
1057
  }
1112
1058
  /**
1113
- * @inheritDoc
1114
- */ afterInit() {
1059
+ * @inheritDoc
1060
+ */ afterInit() {
1115
1061
  const editor = this.editor;
1116
1062
  const t = editor.t;
1117
1063
  const widgetToolbarRepository = editor.plugins.get(WidgetToolbarRepository);