@ckeditor/ckeditor5-media-embed 48.1.1 → 48.2.0-alpha.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.
Files changed (170) hide show
  1. package/ckeditor5-metadata.json +108 -12
  2. package/dist/augmentation.d.ts +9 -1
  3. package/dist/index-content.css +45 -1
  4. package/dist/index-editor.css +8 -5
  5. package/dist/index.css +49 -6
  6. package/dist/index.css.map +1 -1
  7. package/dist/index.d.ts +9 -1
  8. package/dist/index.js +918 -11
  9. package/dist/index.js.map +1 -1
  10. package/dist/mediaembed.d.ts +1 -1
  11. package/dist/mediaembedconfig.d.ts +233 -10
  12. package/dist/mediaembedresize/constants.d.ts +17 -0
  13. package/dist/mediaembedresize/mediaembedresizeediting.d.ts +47 -0
  14. package/dist/mediaembedresize/mediaembedresizehandles.d.ts +42 -0
  15. package/dist/mediaembedresize/resizemediaembedcommand.d.ts +40 -0
  16. package/dist/mediaembedresize.d.ts +30 -0
  17. package/dist/mediaembedstyle/constants.d.ts +29 -0
  18. package/dist/mediaembedstyle/mediaembedstylecommand.d.ts +72 -0
  19. package/dist/mediaembedstyle/mediaembedstyleediting.d.ts +43 -0
  20. package/dist/mediaembedstyle/mediaembedstyleui.d.ts +81 -0
  21. package/dist/mediaembedstyle/utils.d.ts +23 -0
  22. package/dist/mediaembedstyle.d.ts +34 -0
  23. package/dist/mediaembedtoolbar.d.ts +0 -1
  24. package/dist/translations/af.js +1 -1
  25. package/dist/translations/af.umd.js +1 -1
  26. package/dist/translations/ar.js +1 -1
  27. package/dist/translations/ar.umd.js +1 -1
  28. package/dist/translations/ast.js +1 -1
  29. package/dist/translations/ast.umd.js +1 -1
  30. package/dist/translations/az.js +1 -1
  31. package/dist/translations/az.umd.js +1 -1
  32. package/dist/translations/be.js +1 -1
  33. package/dist/translations/be.umd.js +1 -1
  34. package/dist/translations/bg.js +1 -1
  35. package/dist/translations/bg.umd.js +1 -1
  36. package/dist/translations/bn.js +1 -1
  37. package/dist/translations/bn.umd.js +1 -1
  38. package/dist/translations/bs.js +1 -1
  39. package/dist/translations/bs.umd.js +1 -1
  40. package/dist/translations/ca.js +1 -1
  41. package/dist/translations/ca.umd.js +1 -1
  42. package/dist/translations/cs.js +1 -1
  43. package/dist/translations/cs.umd.js +1 -1
  44. package/dist/translations/da.js +1 -1
  45. package/dist/translations/da.umd.js +1 -1
  46. package/dist/translations/de-ch.js +1 -1
  47. package/dist/translations/de-ch.umd.js +1 -1
  48. package/dist/translations/de.js +1 -1
  49. package/dist/translations/de.umd.js +1 -1
  50. package/dist/translations/el.js +1 -1
  51. package/dist/translations/el.umd.js +1 -1
  52. package/dist/translations/en-au.js +1 -1
  53. package/dist/translations/en-au.umd.js +1 -1
  54. package/dist/translations/en-gb.js +1 -1
  55. package/dist/translations/en-gb.umd.js +1 -1
  56. package/dist/translations/en.js +1 -1
  57. package/dist/translations/en.umd.js +1 -1
  58. package/dist/translations/eo.js +1 -1
  59. package/dist/translations/eo.umd.js +1 -1
  60. package/dist/translations/es-co.js +1 -1
  61. package/dist/translations/es-co.umd.js +1 -1
  62. package/dist/translations/es.js +1 -1
  63. package/dist/translations/es.umd.js +1 -1
  64. package/dist/translations/et.js +1 -1
  65. package/dist/translations/et.umd.js +1 -1
  66. package/dist/translations/eu.js +1 -1
  67. package/dist/translations/eu.umd.js +1 -1
  68. package/dist/translations/fa.js +1 -1
  69. package/dist/translations/fa.umd.js +1 -1
  70. package/dist/translations/fi.js +1 -1
  71. package/dist/translations/fi.umd.js +1 -1
  72. package/dist/translations/fr.js +1 -1
  73. package/dist/translations/fr.umd.js +1 -1
  74. package/dist/translations/gl.js +1 -1
  75. package/dist/translations/gl.umd.js +1 -1
  76. package/dist/translations/gu.js +1 -1
  77. package/dist/translations/gu.umd.js +1 -1
  78. package/dist/translations/he.js +1 -1
  79. package/dist/translations/he.umd.js +1 -1
  80. package/dist/translations/hi.js +1 -1
  81. package/dist/translations/hi.umd.js +1 -1
  82. package/dist/translations/hr.js +1 -1
  83. package/dist/translations/hr.umd.js +1 -1
  84. package/dist/translations/hu.js +1 -1
  85. package/dist/translations/hu.umd.js +1 -1
  86. package/dist/translations/hy.js +1 -1
  87. package/dist/translations/hy.umd.js +1 -1
  88. package/dist/translations/id.js +1 -1
  89. package/dist/translations/id.umd.js +1 -1
  90. package/dist/translations/it.js +1 -1
  91. package/dist/translations/it.umd.js +1 -1
  92. package/dist/translations/ja.js +1 -1
  93. package/dist/translations/ja.umd.js +1 -1
  94. package/dist/translations/jv.js +1 -1
  95. package/dist/translations/jv.umd.js +1 -1
  96. package/dist/translations/kk.js +1 -1
  97. package/dist/translations/kk.umd.js +1 -1
  98. package/dist/translations/km.js +1 -1
  99. package/dist/translations/km.umd.js +1 -1
  100. package/dist/translations/kn.js +1 -1
  101. package/dist/translations/kn.umd.js +1 -1
  102. package/dist/translations/ko.js +1 -1
  103. package/dist/translations/ko.umd.js +1 -1
  104. package/dist/translations/ku.js +1 -1
  105. package/dist/translations/ku.umd.js +1 -1
  106. package/dist/translations/lt.js +1 -1
  107. package/dist/translations/lt.umd.js +1 -1
  108. package/dist/translations/lv.js +1 -1
  109. package/dist/translations/lv.umd.js +1 -1
  110. package/dist/translations/ms.js +1 -1
  111. package/dist/translations/ms.umd.js +1 -1
  112. package/dist/translations/nb.js +1 -1
  113. package/dist/translations/nb.umd.js +1 -1
  114. package/dist/translations/ne.js +1 -1
  115. package/dist/translations/ne.umd.js +1 -1
  116. package/dist/translations/nl.js +1 -1
  117. package/dist/translations/nl.umd.js +1 -1
  118. package/dist/translations/no.js +1 -1
  119. package/dist/translations/no.umd.js +1 -1
  120. package/dist/translations/oc.js +1 -1
  121. package/dist/translations/oc.umd.js +1 -1
  122. package/dist/translations/pl.js +1 -1
  123. package/dist/translations/pl.umd.js +1 -1
  124. package/dist/translations/pt-br.js +1 -1
  125. package/dist/translations/pt-br.umd.js +1 -1
  126. package/dist/translations/pt.js +1 -1
  127. package/dist/translations/pt.umd.js +1 -1
  128. package/dist/translations/ro.js +1 -1
  129. package/dist/translations/ro.umd.js +1 -1
  130. package/dist/translations/ru.js +1 -1
  131. package/dist/translations/ru.umd.js +1 -1
  132. package/dist/translations/si.js +1 -1
  133. package/dist/translations/si.umd.js +1 -1
  134. package/dist/translations/sk.js +1 -1
  135. package/dist/translations/sk.umd.js +1 -1
  136. package/dist/translations/sl.js +1 -1
  137. package/dist/translations/sl.umd.js +1 -1
  138. package/dist/translations/sq.js +1 -1
  139. package/dist/translations/sq.umd.js +1 -1
  140. package/dist/translations/sr-latn.js +1 -1
  141. package/dist/translations/sr-latn.umd.js +1 -1
  142. package/dist/translations/sr.js +1 -1
  143. package/dist/translations/sr.umd.js +1 -1
  144. package/dist/translations/sv.js +1 -1
  145. package/dist/translations/sv.umd.js +1 -1
  146. package/dist/translations/th.js +1 -1
  147. package/dist/translations/th.umd.js +1 -1
  148. package/dist/translations/ti.js +1 -1
  149. package/dist/translations/ti.umd.js +1 -1
  150. package/dist/translations/tk.js +1 -1
  151. package/dist/translations/tk.umd.js +1 -1
  152. package/dist/translations/tr.js +1 -1
  153. package/dist/translations/tr.umd.js +1 -1
  154. package/dist/translations/tt.js +1 -1
  155. package/dist/translations/tt.umd.js +1 -1
  156. package/dist/translations/ug.js +1 -1
  157. package/dist/translations/ug.umd.js +1 -1
  158. package/dist/translations/uk.js +1 -1
  159. package/dist/translations/uk.umd.js +1 -1
  160. package/dist/translations/ur.js +1 -1
  161. package/dist/translations/ur.umd.js +1 -1
  162. package/dist/translations/uz.js +1 -1
  163. package/dist/translations/uz.umd.js +1 -1
  164. package/dist/translations/vi.js +1 -1
  165. package/dist/translations/vi.umd.js +1 -1
  166. package/dist/translations/zh-cn.js +1 -1
  167. package/dist/translations/zh-cn.umd.js +1 -1
  168. package/dist/translations/zh.js +1 -1
  169. package/dist/translations/zh.umd.js +1 -1
  170. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -3,10 +3,10 @@
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
5
  import { Command, Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
- import { isWidget, toWidget, findOptimalInsertionRange, Widget, WidgetToolbarRepository } from '@ckeditor/ckeditor5-widget/dist/index.js';
6
+ import { isWidget, toWidget, findOptimalInsertionRange, Widget, WidgetToolbarRepository, WidgetResize } from '@ckeditor/ckeditor5-widget/dist/index.js';
7
7
  import { logWarning, toArray, first, global, FocusTracker, KeystrokeHandler } from '@ckeditor/ckeditor5-utils/dist/index.js';
8
- import { IconView, Template, View, submitHandler, LabeledFieldView, createLabeledInputText, Dialog, ButtonView, MenuBarMenuListItemButtonView, CssTransitionDisablerMixin } from '@ckeditor/ckeditor5-ui/dist/index.js';
9
- import { IconMediaPlaceholder, IconMedia } from '@ckeditor/ckeditor5-icons/dist/index.js';
8
+ import { IconView, Template, View, submitHandler, LabeledFieldView, createLabeledInputText, Dialog, ButtonView, MenuBarMenuListItemButtonView, CssTransitionDisablerMixin, createDropdown, SplitButtonView, addToolbarToDropdown } from '@ckeditor/ckeditor5-ui/dist/index.js';
9
+ import { IconMediaPlaceholder, IconMedia, IconObjectInlineRight, IconObjectRight, IconObjectCenter, IconObjectLeft, IconObjectInlineLeft } from '@ckeditor/ckeditor5-icons/dist/index.js';
10
10
  import { ModelLivePosition, ModelLiveRange } from '@ckeditor/ckeditor5-engine/dist/index.js';
11
11
  import { Clipboard } from '@ckeditor/ckeditor5-clipboard/dist/index.js';
12
12
  import { Delete } from '@ckeditor/ckeditor5-typing/dist/index.js';
@@ -488,7 +488,7 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
488
488
  ],
489
489
  html: (match)=>{
490
490
  const id = match[1];
491
- return '<div style="position: relative; padding-bottom: 100%; height: 0; ">' + `<iframe src="https://www.dailymotion.com/embed/video/${id}" ` + 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' + 'frameborder="0" width="480" height="270" allowfullscreen allow="autoplay">' + '</iframe>' + '</div>';
491
+ return '<div>' + `<iframe src="https://www.dailymotion.com/embed/video/${id}" ` + 'width="1280" height="720" ' + 'style="width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0; display: block;" ' + 'frameborder="0" allowfullscreen allow="autoplay">' + '</iframe>' + '</div>';
492
492
  }
493
493
  },
494
494
  {
@@ -500,7 +500,7 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
500
500
  ],
501
501
  html: (match)=>{
502
502
  const id = match[1];
503
- return '<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 126%;">' + `<iframe src="https://open.spotify.com/embed/${id}" ` + 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' + 'frameborder="0" allowtransparency="true" allow="encrypted-media">' + '</iframe>' + '</div>';
503
+ return '<div>' + `<iframe src="https://open.spotify.com/embed/${id}" ` + 'width="300" height="378" ' + 'style="width: 100%; height: auto; aspect-ratio: 100 / 126; border: 0; display: block;" ' + 'frameborder="0" allowtransparency="true" allow="encrypted-media">' + '</iframe>' + '</div>';
504
504
  }
505
505
  },
506
506
  {
@@ -515,7 +515,7 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
515
515
  html: (match)=>{
516
516
  const id = match[1];
517
517
  const time = match[2];
518
- return '<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 56.2493%;">' + `<iframe src="https://www.youtube.com/embed/${id}${time ? `?start=${time}` : ''}" ` + 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' + 'frameborder="0" allow="autoplay; encrypted-media" referrerpolicy="strict-origin-when-cross-origin" ' + 'allowfullscreen>' + '</iframe>' + '</div>';
518
+ return '<div>' + `<iframe src="https://www.youtube.com/embed/${id}${time ? `?start=${time}` : ''}" ` + 'width="1280" height="720" ' + 'style="width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0; display: block;" ' + 'frameborder="0" allow="autoplay; encrypted-media" referrerpolicy="strict-origin-when-cross-origin" ' + 'allowfullscreen>' + '</iframe>' + '</div>';
519
519
  }
520
520
  },
521
521
  {
@@ -531,7 +531,7 @@ const mediaPlaceholderIconViewBox = '0 0 64 42';
531
531
  ],
532
532
  html: (match)=>{
533
533
  const id = match[1];
534
- return '<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 56.2493%;">' + `<iframe src="https://player.vimeo.com/video/${id}" ` + 'style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" ' + 'frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>' + '</iframe>' + '</div>';
534
+ return '<div>' + `<iframe src="https://player.vimeo.com/video/${id}" ` + 'width="1280" height="720" ' + 'style="width: 100%; height: auto; aspect-ratio: 16 / 9; border: 0; display: block;" ' + 'frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>' + '</iframe>' + '</div>';
535
535
  }
536
536
  },
537
537
  {
@@ -787,7 +787,8 @@ const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w-]+\.[\w-.~:/?#[\]@!$&'()*+,;=%]+$/;
787
787
  return;
788
788
  }
789
789
  const mediaEmbedCommand = editor.commands.get('mediaEmbed');
790
- // Do not anything if media element cannot be inserted at the current position (#47).
790
+ // Do not anything if media element cannot be inserted at the current position.
791
+ // See https://github.com/ckeditor/ckeditor5-media-embed/issues/47.
791
792
  if (!mediaEmbedCommand.isEnabled) {
792
793
  urlRange.detach();
793
794
  return;
@@ -1067,7 +1068,7 @@ function getFormValidators(t, registry) {
1067
1068
  /**
1068
1069
  * The media embed plugin.
1069
1070
  *
1070
- * For a detailed overview, check the {@glink features/media-embed Media Embed feature documentation}.
1071
+ * For a detailed overview, check the {@glink features/media-embed/media-embed Media Embed feature documentation}.
1071
1072
  *
1072
1073
  * This is a "glue" plugin which loads the following plugins:
1073
1074
  *
@@ -1097,6 +1098,165 @@ function getFormValidators(t, registry) {
1097
1098
  }
1098
1099
  }
1099
1100
 
1101
+ /**
1102
+ * Built-in style options provided by the plugin. Integrators can refer to these by
1103
+ * name in {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles`}
1104
+ * to opt out, override individual fields, or coexist with custom styles.
1105
+ *
1106
+ * @internal
1107
+ */ const DEFAULT_OPTIONS = {
1108
+ alignLeft: {
1109
+ name: 'alignLeft',
1110
+ title: 'Left aligned media',
1111
+ icon: IconObjectInlineLeft,
1112
+ className: 'media-style-align-left'
1113
+ },
1114
+ alignBlockLeft: {
1115
+ name: 'alignBlockLeft',
1116
+ title: 'Left aligned media',
1117
+ icon: IconObjectLeft,
1118
+ className: 'media-style-block-align-left'
1119
+ },
1120
+ alignCenter: {
1121
+ name: 'alignCenter',
1122
+ title: 'Centered media',
1123
+ icon: IconObjectCenter,
1124
+ isDefault: true
1125
+ },
1126
+ alignBlockRight: {
1127
+ name: 'alignBlockRight',
1128
+ title: 'Right aligned media',
1129
+ icon: IconObjectRight,
1130
+ className: 'media-style-block-align-right'
1131
+ },
1132
+ alignRight: {
1133
+ name: 'alignRight',
1134
+ title: 'Right aligned media',
1135
+ icon: IconObjectInlineRight,
1136
+ className: 'media-style-align-right'
1137
+ }
1138
+ };
1139
+ /**
1140
+ * Short icon-name aliases that can be used as the `icon` value in a media style
1141
+ * option definition. Matches the alias set exposed by the image styles feature so
1142
+ * the two APIs feel symmetrical.
1143
+ *
1144
+ * @internal
1145
+ */ const DEFAULT_ICONS = {
1146
+ inlineLeft: IconObjectInlineLeft,
1147
+ left: IconObjectLeft,
1148
+ center: IconObjectCenter,
1149
+ right: IconObjectRight,
1150
+ inlineRight: IconObjectInlineRight
1151
+ };
1152
+ /**
1153
+ * Built-in dropdown groupings. Each entry references built-in style component names. If any
1154
+ * items are filtered out by configuration, the dropdown is rebuilt from the remaining names
1155
+ * (or skipped entirely if fewer than two remain).
1156
+ *
1157
+ * @internal
1158
+ */ const DEFAULT_DROPDOWN_DEFINITIONS = [
1159
+ {
1160
+ name: 'mediaEmbed:wrapText',
1161
+ title: 'Wrap text',
1162
+ items: [
1163
+ 'mediaEmbed:alignLeft',
1164
+ 'mediaEmbed:alignRight'
1165
+ ],
1166
+ defaultItem: 'mediaEmbed:alignLeft'
1167
+ },
1168
+ {
1169
+ name: 'mediaEmbed:breakText',
1170
+ title: 'Break text',
1171
+ items: [
1172
+ 'mediaEmbed:alignBlockLeft',
1173
+ 'mediaEmbed:alignCenter',
1174
+ 'mediaEmbed:alignBlockRight'
1175
+ ],
1176
+ defaultItem: 'mediaEmbed:alignCenter'
1177
+ }
1178
+ ];
1179
+
1180
+ /**
1181
+ * Normalizes the {@link module:media-embed/mediaembedconfig~MediaStyleConfig#options style options}
1182
+ * provided by the integrator. Each entry is resolved into a full
1183
+ * {@link module:media-embed/mediaembedconfig~MediaStyleOptionDefinition} and invalid entries
1184
+ * are filtered out with a console warning.
1185
+ *
1186
+ * @internal
1187
+ */ function normalizeStyles(configuredStyles) {
1188
+ const configured = configuredStyles.options || [];
1189
+ return configured.map((entry)=>normalizeDefinition(entry)).filter((entry)=>isValidOption(entry));
1190
+ }
1191
+ /**
1192
+ * Resolves a single config entry into a style option definition. A string entry is first
1193
+ * promoted to its object form (`{ name }`) and then shallow-merged on top of the matching
1194
+ * built-in default — entries without a matching built-in pass through unchanged and are
1195
+ * rejected by {@link ~isValidOption} if they lack required fields.
1196
+ *
1197
+ * Also resolves icon-name aliases (`'left'`, `'inlineLeft'`, etc.) to the corresponding
1198
+ * SVG sources from {@link module:media-embed/mediaembedstyle/constants~DEFAULT_ICONS}.
1199
+ */ function normalizeDefinition(entry) {
1200
+ // Spread of `undefined` is a no-op, so unknown-name overrides produce a clean passthrough.
1201
+ const override = typeof entry === 'string' ? {
1202
+ name: entry
1203
+ } : entry;
1204
+ const definition = {
1205
+ ...DEFAULT_OPTIONS[override.name],
1206
+ ...override
1207
+ };
1208
+ if (typeof definition.icon === 'string' && DEFAULT_ICONS[definition.icon]) {
1209
+ definition.icon = DEFAULT_ICONS[definition.icon];
1210
+ }
1211
+ return definition;
1212
+ }
1213
+ /**
1214
+ * Validates a normalized style option. `name`, `title`, and `icon` are always required.
1215
+ * `className` is required unless the entry is the default style (defaults encode as
1216
+ * attribute-absence and intentionally have no class). Emits a console warning and returns
1217
+ * `false` when any of these checks fails.
1218
+ */ function isValidOption(option) {
1219
+ if (!option.name || !option.title || !option.icon || !option.isDefault && !option.className) {
1220
+ warnInvalidStyle({
1221
+ style: option
1222
+ });
1223
+ return false;
1224
+ }
1225
+ return true;
1226
+ }
1227
+ function warnInvalidStyle(info) {
1228
+ /**
1229
+ * The media style configuration provided in the editor config is invalid. The warning is
1230
+ * emitted in two situations:
1231
+ *
1232
+ * * An entry in {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles.options`}
1233
+ * does not reference a built-in style by name (`'alignLeft'`, `'alignBlockLeft'`,
1234
+ * `'alignCenter'`, `'alignBlockRight'`, `'alignRight'`) and does not follow the
1235
+ * {@link module:media-embed/mediaembedconfig~MediaStyleOptionDefinition} shape —
1236
+ * `name`, `title`, `icon`, and (unless `isDefault: true`) `className` are required.
1237
+ * The offending entry is reported under the `style` parameter.
1238
+ * * A dropdown entry placed inline in
1239
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#toolbar `config.mediaEmbed.toolbar`}
1240
+ * does not follow the {@link module:media-embed/mediaembedconfig~MediaStyleDropdownDefinition} shape
1241
+ * (`name` and every `items[]` entry must use the full `mediaEmbed:` prefix, `defaultItem` must
1242
+ * be one of the `items`, `title` must be a non-empty string), or its `items[]` reference styles
1243
+ * that are not in the resolved
1244
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles`} list.
1245
+ * The offending entry is reported under the `dropdown` parameter.
1246
+ *
1247
+ * @error media-style-configuration-definition-invalid
1248
+ */ logWarning('media-style-configuration-definition-invalid', info);
1249
+ }
1250
+ /**
1251
+ * Type guard for toolbar config entries shaped like a media style dropdown definition. The
1252
+ * discriminator is `defaultItem` — generic toolbar groupings use `items` + `label` and never
1253
+ * carry a `defaultItem` field.
1254
+ *
1255
+ * @internal
1256
+ */ function isMediaStyleDropdown(item) {
1257
+ return typeof item === 'object' && item !== null && typeof item.defaultItem === 'string';
1258
+ }
1259
+
1100
1260
  /**
1101
1261
  * The media embed toolbar plugin. It creates a toolbar for media embed that shows up when the media element is selected.
1102
1262
  *
@@ -1128,11 +1288,758 @@ function getFormValidators(t, registry) {
1128
1288
  const widgetToolbarRepository = editor.plugins.get(WidgetToolbarRepository);
1129
1289
  widgetToolbarRepository.register('mediaEmbed', {
1130
1290
  ariaLabel: t('Media toolbar'),
1131
- items: editor.config.get('mediaEmbed.toolbar') || [],
1291
+ items: normalizeDeclarativeConfig(editor.ui.componentFactory, editor.config.get('mediaEmbed.toolbar') || []),
1132
1292
  getRelatedElement: getSelectedMediaViewWidget
1133
1293
  });
1134
1294
  }
1135
1295
  }
1296
+ /**
1297
+ * Flattens dropdown definitions to their factory names, dropping any `mediaEmbed:`-prefixed
1298
+ * name the style UI did not register — otherwise the toolbar crashes with `componentfactory-item-missing`.
1299
+ * Non-string entries (e.g. generic `{ label, items }` toolbar groupings) pass through unchanged.
1300
+ */ function normalizeDeclarativeConfig(factory, config) {
1301
+ return config.map((item)=>isMediaStyleDropdown(item) ? item.name : item).filter((item)=>typeof item !== 'string' || !item.startsWith('mediaEmbed:') || factory.has(item));
1302
+ }
1303
+
1304
+ /**
1305
+ * The resize media embed command.
1306
+ */ class ResizeMediaEmbedCommand extends Command {
1307
+ /**
1308
+ * @inheritDoc
1309
+ */ refresh() {
1310
+ const element = getSelectedMediaModelWidget(this.editor.model.document.selection);
1311
+ this.isEnabled = !!element;
1312
+ if (!element || !element.hasAttribute('resizedWidth')) {
1313
+ this.value = null;
1314
+ } else {
1315
+ this.value = element.getAttribute('resizedWidth');
1316
+ }
1317
+ }
1318
+ /**
1319
+ * Executes the command.
1320
+ *
1321
+ * ```ts
1322
+ * // Sets the width as a percentage of the parent width:
1323
+ * editor.execute( 'resizeMediaEmbed', { width: '50%' } );
1324
+ *
1325
+ * // Removes the resize and restores the default width:
1326
+ * editor.execute( 'resizeMediaEmbed', { width: null } );
1327
+ * ```
1328
+ *
1329
+ * @param options
1330
+ * @param options.width The new width of the media embed as a CSS `width` value
1331
+ * (e.g. `'50%'`), or `null` to remove the resize.
1332
+ * @fires execute
1333
+ */ execute(options) {
1334
+ const model = this.editor.model;
1335
+ const mediaElement = getSelectedMediaModelWidget(model.document.selection);
1336
+ if (mediaElement) {
1337
+ model.change((writer)=>{
1338
+ writer.setAttribute('resizedWidth', options.width, mediaElement);
1339
+ });
1340
+ }
1341
+ }
1342
+ }
1343
+
1344
+ /**
1345
+ * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved.
1346
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
1347
+ */ /**
1348
+ * @module media-embed/mediaembedresize/constants
1349
+ */ /**
1350
+ * The view class applied to a resized media embed figure.
1351
+ *
1352
+ * Shared between the editing plugin (which toggles it via downcast of `resizedWidth` and consumes
1353
+ * it on upcast) and the handles plugin (which adds it during drag and strips it on commit), so
1354
+ * both layers agree on the exact class name.
1355
+ *
1356
+ * @internal
1357
+ */ const RESIZED_MEDIA_CLASS = 'media_resized';
1358
+
1359
+ /**
1360
+ * The media embed resize editing feature.
1361
+ *
1362
+ * It adds the ability to resize each media embed using handles.
1363
+ */ class MediaEmbedResizeEditing extends Plugin {
1364
+ /**
1365
+ * @inheritDoc
1366
+ */ static get requires() {
1367
+ return [
1368
+ MediaEmbedEditing
1369
+ ];
1370
+ }
1371
+ /**
1372
+ * @inheritDoc
1373
+ */ static get pluginName() {
1374
+ return 'MediaEmbedResizeEditing';
1375
+ }
1376
+ /**
1377
+ * @inheritDoc
1378
+ * @internal
1379
+ */ static get licenseFeatureCode() {
1380
+ return 'MER';
1381
+ }
1382
+ /**
1383
+ * @inheritDoc
1384
+ */ static get isOfficialPlugin() {
1385
+ return true;
1386
+ }
1387
+ /**
1388
+ * @inheritDoc
1389
+ */ static get isPremiumPlugin() {
1390
+ return true;
1391
+ }
1392
+ /**
1393
+ * @inheritDoc
1394
+ */ init() {
1395
+ const editor = this.editor;
1396
+ editor.commands.add('resizeMediaEmbed', new ResizeMediaEmbedCommand(editor));
1397
+ this._registerConverters();
1398
+ }
1399
+ /**
1400
+ * @inheritDoc
1401
+ */ afterInit() {
1402
+ this._registerSchema();
1403
+ }
1404
+ _registerSchema() {
1405
+ const schema = this.editor.model.schema;
1406
+ schema.extend('media', {
1407
+ allowAttributes: [
1408
+ 'resizedWidth'
1409
+ ]
1410
+ });
1411
+ schema.setAttributeProperties('resizedWidth', {
1412
+ isFormatting: true
1413
+ });
1414
+ }
1415
+ /**
1416
+ * Registers media embed resize converters.
1417
+ */ _registerConverters() {
1418
+ const editor = this.editor;
1419
+ // Downcast (model → view): resizedWidth → style.width + class on <figure>.
1420
+ editor.conversion.for('downcast').add((dispatcher)=>dispatcher.on('attribute:resizedWidth:media', (evt, data, conversionApi)=>{
1421
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
1422
+ return;
1423
+ }
1424
+ const viewWriter = conversionApi.writer;
1425
+ const figure = conversionApi.mapper.toViewElement(data.item);
1426
+ if (data.attributeNewValue !== null) {
1427
+ viewWriter.setStyle('width', data.attributeNewValue, figure);
1428
+ viewWriter.addClass(RESIZED_MEDIA_CLASS, figure);
1429
+ } else {
1430
+ viewWriter.removeStyle('width', figure);
1431
+ viewWriter.removeClass(RESIZED_MEDIA_CLASS, figure);
1432
+ }
1433
+ }));
1434
+ // Upcast: style.width on <figure class="media"> → resizedWidth.
1435
+ //
1436
+ // The `hasClass` guard lives in the value callback (not the matcher) because the `media`
1437
+ // class is already consumed upstream by MediaEmbedEditing. Without the guard, any figure
1438
+ // with a width style would match and could race image resize's upcast on image figures.
1439
+ editor.conversion.for('upcast').attributeToAttribute({
1440
+ view: {
1441
+ name: 'figure',
1442
+ styles: {
1443
+ width: /.+/
1444
+ }
1445
+ },
1446
+ model: {
1447
+ key: 'resizedWidth',
1448
+ value: (viewElement)=>{
1449
+ if (!viewElement.hasClass('media')) {
1450
+ return null;
1451
+ }
1452
+ return viewElement.getStyle('width');
1453
+ }
1454
+ }
1455
+ });
1456
+ // Consume the media_resized class during upcast so it does not cause conversion issues.
1457
+ editor.conversion.for('upcast').add((dispatcher)=>{
1458
+ dispatcher.on('element:figure', (evt, data, conversionApi)=>{
1459
+ conversionApi.consumable.consume(data.viewItem, {
1460
+ classes: [
1461
+ RESIZED_MEDIA_CLASS
1462
+ ]
1463
+ });
1464
+ });
1465
+ });
1466
+ }
1467
+ }
1468
+
1469
+ /**
1470
+ * The media embed resize by handles feature.
1471
+ *
1472
+ * It adds the ability to resize each media embed using handles.
1473
+ */ class MediaEmbedResizeHandles extends Plugin {
1474
+ /**
1475
+ * @inheritDoc
1476
+ */ static get requires() {
1477
+ return [
1478
+ WidgetResize
1479
+ ];
1480
+ }
1481
+ /**
1482
+ * @inheritDoc
1483
+ */ static get pluginName() {
1484
+ return 'MediaEmbedResizeHandles';
1485
+ }
1486
+ /**
1487
+ * @inheritDoc
1488
+ */ static get isOfficialPlugin() {
1489
+ return true;
1490
+ }
1491
+ /**
1492
+ * @inheritDoc
1493
+ */ init() {
1494
+ const command = this.editor.commands.get('resizeMediaEmbed');
1495
+ this.bind('isEnabled').to(command);
1496
+ this._setupResizerCreator();
1497
+ }
1498
+ /**
1499
+ * Attaches a resizer to every newly inserted media widget. Walks only the ranges
1500
+ * reported by the differ — never the whole document — so unrelated inserts (e.g.
1501
+ * pressing Enter to create a paragraph) cost only the differ check.
1502
+ *
1503
+ * Each resizer's `isEnabled` is bound to the plugin in {@link #_attachResizer},
1504
+ * so it auto-tracks the resize command's state.
1505
+ */ _setupResizerCreator() {
1506
+ const editor = this.editor;
1507
+ const model = editor.model;
1508
+ const widgetResize = editor.plugins.get(WidgetResize);
1509
+ // Low priority ensures downcast has run before we look up view elements.
1510
+ this.listenTo(model.document, 'change:data', ()=>{
1511
+ for (const change of model.document.differ.getChanges()){
1512
+ if (change.type !== 'insert' || change.name === '$text') {
1513
+ continue;
1514
+ }
1515
+ const insertedRange = model.createRange(change.position, change.position.getShiftedBy(change.length));
1516
+ for (const item of insertedRange.getItems()){
1517
+ if (!item.is('element', 'media')) {
1518
+ continue;
1519
+ }
1520
+ const viewElement = editor.editing.mapper.toViewElement(item);
1521
+ /* istanbul ignore if: paranoid check — conversion has run at this point -- @preserve */ if (!viewElement) {
1522
+ continue;
1523
+ }
1524
+ if (!widgetResize.getResizerByViewElement(viewElement)) {
1525
+ this._attachResizer(item, viewElement);
1526
+ }
1527
+ }
1528
+ }
1529
+ }, {
1530
+ priority: 'low'
1531
+ });
1532
+ }
1533
+ /**
1534
+ * Attaches a resizer to a single media widget.
1535
+ */ _attachResizer(modelElement, widgetView) {
1536
+ const editor = this.editor;
1537
+ const editingView = editor.editing.view;
1538
+ const resizer = editor.plugins.get(WidgetResize).attachTo({
1539
+ unit: '%',
1540
+ modelElement,
1541
+ viewElement: widgetView,
1542
+ editor,
1543
+ getHandleHost: (domWidgetElement)=>domWidgetElement.querySelector('.ck-media__wrapper'),
1544
+ getResizeHost: (domWidgetElement)=>domWidgetElement,
1545
+ onCommit: (newValue)=>{
1546
+ editingView.change((writer)=>writer.removeClass(RESIZED_MEDIA_CLASS, widgetView));
1547
+ editor.execute('resizeMediaEmbed', {
1548
+ width: newValue
1549
+ });
1550
+ }
1551
+ });
1552
+ resizer.bind('isEnabled').to(this);
1553
+ resizer.on('updateSize', ()=>{
1554
+ if (!widgetView.hasClass(RESIZED_MEDIA_CLASS)) {
1555
+ editingView.change((writer)=>writer.addClass(RESIZED_MEDIA_CLASS, widgetView));
1556
+ }
1557
+ });
1558
+ // Redraw once the view has flushed to DOM — otherwise the freshly inserted resizer
1559
+ // UIElement has no inline styles and handles cluster at the top-left corner (visible
1560
+ // after drag-and-drop until another event eventually triggers a redraw).
1561
+ editingView.once('render', ()=>resizer.redraw());
1562
+ }
1563
+ }
1564
+
1565
+ /**
1566
+ * The media embed resize plugin.
1567
+ *
1568
+ * It adds a possibility to resize each media embed using handles.
1569
+ */ class MediaEmbedResize extends Plugin {
1570
+ /**
1571
+ * @inheritDoc
1572
+ */ static get requires() {
1573
+ return [
1574
+ MediaEmbedResizeEditing,
1575
+ MediaEmbedResizeHandles
1576
+ ];
1577
+ }
1578
+ /**
1579
+ * @inheritDoc
1580
+ */ static get pluginName() {
1581
+ return 'MediaEmbedResize';
1582
+ }
1583
+ /**
1584
+ * @inheritDoc
1585
+ */ static get isOfficialPlugin() {
1586
+ return true;
1587
+ }
1588
+ }
1589
+
1590
+ /**
1591
+ * The media embed style command. It is used to apply a style option (e.g. an alignment) to a
1592
+ * selected media embed.
1593
+ *
1594
+ * The set of accepted style values comes from the resolved
1595
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles`}
1596
+ * options. Values not in that set are silently rejected by {@link #execute}.
1597
+ */ class MediaEmbedStyleCommand extends Command {
1598
+ /**
1599
+ * Resolved styles indexed by `name`. Used to look up the `isDefault` flag at execute time
1600
+ * (any default-marked style clears the attribute) and to validate that a requested style
1601
+ * is part of the resolved options list.
1602
+ */ _styles;
1603
+ /**
1604
+ * The `name` of the first style with `isDefault: true` in the resolved options, or `null`
1605
+ * when the integrator did not designate a default. Exposed via {@link #value} when the
1606
+ * selected media has no `mediaStyle` attribute, so the default-state UI button can light up.
1607
+ * Does not gate the "clear attribute" branch in {@link #execute} — that uses the per-style
1608
+ * `isDefault` flag so multi-default configs behave consistently with the downcast.
1609
+ */ _defaultStyleName;
1610
+ /**
1611
+ * Creates an instance of the media embed style command.
1612
+ *
1613
+ * @param editor The editor instance.
1614
+ * @param styles The resolved list of style options that this command will accept.
1615
+ */ constructor(editor, styles){
1616
+ super(editor);
1617
+ this._styles = new Map(styles.map((style)=>[
1618
+ style.name,
1619
+ style
1620
+ ]));
1621
+ const defaultStyle = styles.find((style)=>style.isDefault);
1622
+ this._defaultStyleName = defaultStyle ? defaultStyle.name : null;
1623
+ }
1624
+ /**
1625
+ * @inheritDoc
1626
+ */ refresh() {
1627
+ const element = getSelectedMediaModelWidget(this.editor.model.document.selection);
1628
+ this.isEnabled = !!element;
1629
+ if (!element) {
1630
+ this.value = false;
1631
+ } else if (element.hasAttribute('mediaStyle')) {
1632
+ const styleName = element.getAttribute('mediaStyle');
1633
+ // A previously-applied style may have been dropped from the resolved options list
1634
+ // (e.g. by a config change). Fall back to the effective default so the UI stays
1635
+ // consistent with what the downcast actually renders (no class for unknown names).
1636
+ this.value = this._styles.has(styleName) ? styleName : this._defaultStyleName ?? false;
1637
+ } else {
1638
+ this.value = this._defaultStyleName ?? false;
1639
+ }
1640
+ }
1641
+ /**
1642
+ * Executes the command and applies the chosen style to the currently selected media embed.
1643
+ *
1644
+ * ```ts
1645
+ * editor.execute( 'mediaStyle', { value: 'alignLeft' } );
1646
+ * editor.execute( 'mediaStyle', { value: 'alignCenter' } ); // removes the attribute — alignCenter is the built-in default
1647
+ * editor.execute( 'mediaStyle', { value: null } ); // removes the attribute
1648
+ * ```
1649
+ *
1650
+ * The default style is encoded on the model as the absence of the `mediaStyle` attribute.
1651
+ * Passing any `isDefault: true` style name (or `null`) therefore clears the attribute. Values
1652
+ * that are neither falsy, an `isDefault` style, nor present in the resolved options list are
1653
+ * silently rejected.
1654
+ *
1655
+ * @param options
1656
+ * @param options.value The name of the style to apply, or `null` to clear the alignment.
1657
+ * @fires execute
1658
+ */ execute(options) {
1659
+ const model = this.editor.model;
1660
+ const element = getSelectedMediaModelWidget(model.document.selection);
1661
+ const requestedStyle = options.value;
1662
+ // Falsy value or any `isDefault: true` style clears the attribute. Default styles encode
1663
+ // as attribute-absence on the model. The downcast emits no class for them.
1664
+ if (!requestedStyle || this._styles.get(requestedStyle)?.isDefault) {
1665
+ model.change((writer)=>{
1666
+ writer.removeAttribute('mediaStyle', element);
1667
+ });
1668
+ return;
1669
+ }
1670
+ // Reject names that are not part of the resolved options list.
1671
+ if (!this._styles.has(requestedStyle)) {
1672
+ return;
1673
+ }
1674
+ model.change((writer)=>{
1675
+ writer.setAttribute('mediaStyle', requestedStyle, element);
1676
+ });
1677
+ }
1678
+ }
1679
+
1680
+ /**
1681
+ * The media embed style engine plugin. It extends the schema with the `mediaStyle` attribute,
1682
+ * registers the {@link module:media-embed/mediaembedstyle/mediaembedstylecommand~MediaEmbedStyleCommand} command,
1683
+ * and adds the converters that apply alignment CSS classes to the figure.
1684
+ */ class MediaEmbedStyleEditing extends Plugin {
1685
+ /**
1686
+ * The resolved list of media style options. Built once from
1687
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles`}
1688
+ * during {@link #init} and consumed by both the command and the UI plugin (single source of truth).
1689
+ *
1690
+ * @internal
1691
+ * @readonly
1692
+ */ normalizedStyles;
1693
+ /**
1694
+ * @inheritDoc
1695
+ */ static get requires() {
1696
+ return [
1697
+ MediaEmbedEditing
1698
+ ];
1699
+ }
1700
+ /**
1701
+ * @inheritDoc
1702
+ */ static get pluginName() {
1703
+ return 'MediaEmbedStyleEditing';
1704
+ }
1705
+ /**
1706
+ * @inheritDoc
1707
+ */ static get isOfficialPlugin() {
1708
+ return true;
1709
+ }
1710
+ /**
1711
+ * @inheritDoc
1712
+ */ init() {
1713
+ const editor = this.editor;
1714
+ const schema = editor.model.schema;
1715
+ editor.config.define('mediaEmbed.styles', {
1716
+ options: Object.keys(DEFAULT_OPTIONS)
1717
+ });
1718
+ this.normalizedStyles = normalizeStyles(editor.config.get('mediaEmbed.styles'));
1719
+ schema.extend('media', {
1720
+ allowAttributes: [
1721
+ 'mediaStyle'
1722
+ ]
1723
+ });
1724
+ schema.setAttributeProperties('mediaStyle', {
1725
+ isFormatting: true
1726
+ });
1727
+ editor.commands.add('mediaStyle', new MediaEmbedStyleCommand(editor, this.normalizedStyles));
1728
+ this._registerConverters();
1729
+ }
1730
+ /**
1731
+ * Registers the downcast and upcast converters for the `mediaStyle` attribute.
1732
+ */ _registerConverters() {
1733
+ const editor = this.editor;
1734
+ // Runtime lookup of style `name` → CSS `className`. Excludes the default style, which is
1735
+ // encoded as the absence of the attribute (no class). Iteration order follows the configured
1736
+ // options order — the upcast relies on this so the last matching class wins on a figure
1737
+ // that has multiple alignment classes.
1738
+ const styleClassMap = new Map(this.normalizedStyles.filter((style)=>!style.isDefault && style.className).map((style)=>[
1739
+ style.name,
1740
+ style.className
1741
+ ]));
1742
+ // Downcast: `mediaStyle` → CSS class on the <figure>. Covers both editing and data pipelines.
1743
+ editor.conversion.for('downcast').add((dispatcher)=>dispatcher.on('attribute:mediaStyle:media', (evt, data, conversionApi)=>{
1744
+ if (!conversionApi.consumable.consume(data.item, evt.name)) {
1745
+ return;
1746
+ }
1747
+ const figure = conversionApi.mapper.toViewElement(data.item);
1748
+ const viewWriter = conversionApi.writer;
1749
+ const oldClass = styleClassMap.get(data.attributeOldValue);
1750
+ const newClass = styleClassMap.get(data.attributeNewValue);
1751
+ if (oldClass) {
1752
+ viewWriter.removeClass(oldClass, figure);
1753
+ }
1754
+ if (newClass) {
1755
+ viewWriter.addClass(newClass, figure);
1756
+ }
1757
+ }));
1758
+ // Upcast: alignment class on a media <figure> → `mediaStyle` attribute. Runs at `low`
1759
+ // priority so the main media upcast creates the `media` model element first.
1760
+ editor.conversion.for('upcast').add((dispatcher)=>{
1761
+ dispatcher.on('element:figure', (_evt, data, conversionApi)=>{
1762
+ if (!data.modelRange) {
1763
+ return;
1764
+ }
1765
+ const modelElement = first(data.modelRange.getItems());
1766
+ if (!modelElement || !modelElement.is('element', 'media')) {
1767
+ return;
1768
+ }
1769
+ // Iterate in insertion order — last consumed class wins when multiple
1770
+ // alignment classes are present on the same figure.
1771
+ for (const [styleName, className] of styleClassMap){
1772
+ if (conversionApi.consumable.consume(data.viewItem, {
1773
+ classes: className
1774
+ })) {
1775
+ conversionApi.writer.setAttribute('mediaStyle', styleName, modelElement);
1776
+ }
1777
+ }
1778
+ }, {
1779
+ priority: 'low'
1780
+ });
1781
+ });
1782
+ }
1783
+ }
1784
+
1785
+ /**
1786
+ * The media embed style UI plugin.
1787
+ *
1788
+ * It registers a button for every style in the resolved
1789
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#styles `config.mediaEmbed.styles`}
1790
+ * list, and the default split-button dropdowns (`mediaEmbed:wrapText`, `mediaEmbed:breakText`)
1791
+ * — filtered to the styles that survived configuration. The resulting components can be placed
1792
+ * in the {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#toolbar media embed toolbar}.
1793
+ */ class MediaEmbedStyleUI extends Plugin {
1794
+ /**
1795
+ * @inheritDoc
1796
+ */ static get requires() {
1797
+ return [
1798
+ MediaEmbedStyleEditing
1799
+ ];
1800
+ }
1801
+ /**
1802
+ * @inheritDoc
1803
+ */ static get pluginName() {
1804
+ return 'MediaEmbedStyleUI';
1805
+ }
1806
+ /**
1807
+ * @inheritDoc
1808
+ */ static get isOfficialPlugin() {
1809
+ return true;
1810
+ }
1811
+ /**
1812
+ * @inheritDoc
1813
+ */ init() {
1814
+ const titles = this._getLocalizedTitles();
1815
+ for (const button of this._getButtonDefinitions(titles)){
1816
+ this._createButton(button);
1817
+ }
1818
+ for (const dropdown of this._getDropdownDefinitions(titles)){
1819
+ this._createDropdown(dropdown);
1820
+ }
1821
+ }
1822
+ /**
1823
+ * Returns the alignment button definitions sourced from the resolved options list.
1824
+ */ _getButtonDefinitions(titles) {
1825
+ const editing = this.editor.plugins.get(MediaEmbedStyleEditing);
1826
+ return editing.normalizedStyles.map((option)=>({
1827
+ name: option.name,
1828
+ label: titles[option.title] || option.title,
1829
+ icon: option.icon
1830
+ }));
1831
+ }
1832
+ /**
1833
+ * Returns the localized titles of the built-in styles and dropdowns.
1834
+ */ _getLocalizedTitles() {
1835
+ const t = this.editor.t;
1836
+ return {
1837
+ 'Left aligned media': t('Left aligned media'),
1838
+ 'Centered media': t('Centered media'),
1839
+ 'Right aligned media': t('Right aligned media'),
1840
+ 'Wrap text': t('Wrap text'),
1841
+ 'Break text': t('Break text')
1842
+ };
1843
+ }
1844
+ /**
1845
+ * Returns the split-button dropdown definitions, filtered to the styles present in the
1846
+ * resolved options list. Combines the {@link module:media-embed/mediaembedstyle/constants~DEFAULT_DROPDOWN_DEFINITIONS
1847
+ * built-in dropdowns} with custom dropdowns declared inline in
1848
+ * {@link module:media-embed/mediaembedconfig~MediaEmbedConfig#toolbar `config.mediaEmbed.toolbar`}.
1849
+ *
1850
+ * A dropdown with fewer than two items is skipped — a single-item dropdown carries no value
1851
+ * over the flat button. If the configured `defaultItem` was filtered out, the first surviving
1852
+ * item becomes the default.
1853
+ *
1854
+ * When a *custom* dropdown's items reference styles that are not in the resolved options list,
1855
+ * a console warning is emitted (the integrator's config was not fully honored). Built-in
1856
+ * dropdowns auto-skip silently — they are added by the plugin, not the integrator.
1857
+ */ _getDropdownDefinitions(titles) {
1858
+ const editor = this.editor;
1859
+ const editing = editor.plugins.get(MediaEmbedStyleEditing);
1860
+ const availableComponentNames = new Set(editing.normalizedStyles.map(({ name })=>`mediaEmbed:${name}`));
1861
+ const dropdowns = [];
1862
+ const resolveDropdown = (definition, warnOnFilter)=>{
1863
+ const items = definition.items.filter((itemName)=>availableComponentNames.has(itemName));
1864
+ if (warnOnFilter && items.length !== definition.items.length) {
1865
+ warnInvalidDropdown({
1866
+ dropdown: definition
1867
+ });
1868
+ }
1869
+ if (items.length < 2) {
1870
+ return;
1871
+ }
1872
+ const defaultItem = availableComponentNames.has(definition.defaultItem) ? definition.defaultItem : items[0];
1873
+ dropdowns.push({
1874
+ name: definition.name,
1875
+ title: titles[definition.title] || definition.title,
1876
+ items,
1877
+ defaultItem
1878
+ });
1879
+ };
1880
+ for (const definition of DEFAULT_DROPDOWN_DEFINITIONS){
1881
+ resolveDropdown(definition, false);
1882
+ }
1883
+ for (const definition of this._collectCustomDropdowns()){
1884
+ resolveDropdown(definition, true);
1885
+ }
1886
+ return dropdowns;
1887
+ }
1888
+ /**
1889
+ * Scans `config.mediaEmbed.toolbar` for entries shaped like a dropdown definition
1890
+ * (objects with both `items` and `defaultItem`) and returns the valid ones. `defaultItem`
1891
+ * is the discriminator between our split-button dropdowns and generic toolbar groupings
1892
+ * (which use `items` + `label` and have no `defaultItem`).
1893
+ *
1894
+ * Invalid entries (wrong name prefix, `defaultItem` missing from `items`) are warned and
1895
+ * dropped here. Items that reference filtered-out styles are filtered later by
1896
+ * {@link #_getDropdownDefinitions}, alongside the same logic that applies to built-in
1897
+ * dropdowns.
1898
+ */ _collectCustomDropdowns() {
1899
+ const toolbarConfig = this.editor.config.get('mediaEmbed.toolbar') || [];
1900
+ return toolbarConfig.filter((item)=>isMediaStyleDropdown(item) && isValidCustomDropdown(item));
1901
+ }
1902
+ /**
1903
+ * Registers a single alignment toggle button in the component factory.
1904
+ */ _createButton(definition) {
1905
+ const editor = this.editor;
1906
+ const componentName = `mediaEmbed:${definition.name}`;
1907
+ editor.ui.componentFactory.add(componentName, (locale)=>{
1908
+ const command = editor.commands.get('mediaStyle');
1909
+ const view = new ButtonView(locale);
1910
+ view.set({
1911
+ label: definition.label,
1912
+ icon: definition.icon,
1913
+ tooltip: true,
1914
+ isToggleable: true
1915
+ });
1916
+ view.bind('isEnabled').to(command, 'isEnabled');
1917
+ view.bind('isOn').to(command, 'value', (value)=>value === definition.name);
1918
+ view.on('execute', ()=>{
1919
+ editor.execute('mediaStyle', {
1920
+ value: definition.name
1921
+ });
1922
+ editor.editing.view.focus();
1923
+ });
1924
+ return view;
1925
+ });
1926
+ }
1927
+ /**
1928
+ * Registers a split-button dropdown grouping a set of alignment buttons. The action button
1929
+ * reflects whichever child option is currently `isOn`, falling back to the dropdown's
1930
+ * `defaultItem` when nothing is active.
1931
+ */ _createDropdown(definition) {
1932
+ const editor = this.editor;
1933
+ const factory = editor.ui.componentFactory;
1934
+ factory.add(definition.name, (locale)=>{
1935
+ // Build child buttons via the factory; pick the default by name.
1936
+ const buttonViews = definition.items.map((itemName)=>factory.create(itemName));
1937
+ const defaultButton = buttonViews[definition.items.indexOf(definition.defaultItem)];
1938
+ // Resolve the currently-active child or fall back to the default. Used by the
1939
+ // reactive `icon` and `label` bindings on the split button.
1940
+ const activeOrDefault = (...areOn)=>{
1941
+ const index = areOn.findIndex(Boolean);
1942
+ return index < 0 ? defaultButton : buttonViews[index];
1943
+ };
1944
+ // Build the dropdown shell.
1945
+ const dropdownView = createDropdown(locale, SplitButtonView);
1946
+ const splitButtonView = dropdownView.buttonView;
1947
+ addToolbarToDropdown(dropdownView, buttonViews, {
1948
+ enableActiveItemFocusOnDropdownOpen: true
1949
+ });
1950
+ splitButtonView.set({
1951
+ label: getDropdownButtonTitle(definition.title, defaultButton.label),
1952
+ class: null,
1953
+ tooltip: true
1954
+ });
1955
+ splitButtonView.arrowView.unbind('label');
1956
+ splitButtonView.arrowView.set({
1957
+ label: definition.title
1958
+ });
1959
+ // Reactive: action button mirrors the active child's icon and label.
1960
+ splitButtonView.bind('icon').toMany(buttonViews, 'isOn', (...areOn)=>activeOrDefault(...areOn).icon);
1961
+ splitButtonView.bind('label').toMany(buttonViews, 'isOn', (...areOn)=>getDropdownButtonTitle(definition.title, activeOrDefault(...areOn).label));
1962
+ // Reactive: split button shows the "active" state when any child is on.
1963
+ splitButtonView.bind('isOn').toMany(buttonViews, 'isOn', (...areOn)=>areOn.some(Boolean));
1964
+ splitButtonView.bind('class').toMany(buttonViews, 'isOn', (...areOn)=>areOn.some(Boolean) ? 'ck-splitbutton_flatten' : undefined);
1965
+ // Action click: re-fire the default child when nothing is active; otherwise toggle the dropdown.
1966
+ this.listenTo(splitButtonView, 'execute', ()=>{
1967
+ if (buttonViews.some(({ isOn })=>isOn)) {
1968
+ dropdownView.isOpen = !dropdownView.isOpen;
1969
+ } else {
1970
+ defaultButton.fire('execute');
1971
+ }
1972
+ });
1973
+ // Reactive: dropdown is enabled when any child is enabled.
1974
+ dropdownView.bind('isEnabled').toMany(buttonViews, 'isEnabled', (...areEnabled)=>areEnabled.some(Boolean));
1975
+ // Refocus the editing view so the dropdown action doesn't steal caret position.
1976
+ this.listenTo(dropdownView, 'execute', ()=>{
1977
+ editor.editing.view.focus();
1978
+ });
1979
+ return dropdownView;
1980
+ });
1981
+ }
1982
+ }
1983
+ /**
1984
+ * Combines the dropdown title and the default action item label for the split-button label.
1985
+ */ function getDropdownButtonTitle(dropdownTitle, buttonTitle) {
1986
+ return `${dropdownTitle}: ${buttonTitle}`;
1987
+ }
1988
+ /**
1989
+ * Validates a user-supplied dropdown definition. Emits a console warning under
1990
+ * `media-style-configuration-definition-invalid` and returns `false` when any of these rules is
1991
+ * broken: `name` must start with `mediaEmbed:`, `title` must be a non-empty string, `items` must
1992
+ * be non-empty and every entry must be a `mediaEmbed:`-prefixed string, and `defaultItem` must be
1993
+ * one of the `items`.
1994
+ *
1995
+ * Item-membership against the resolved styles is checked separately, downstream, alongside the
1996
+ * same logic that applies to built-in dropdowns.
1997
+ */ function isValidCustomDropdown(definition) {
1998
+ const valid = definition.name.startsWith('mediaEmbed:') && typeof definition.title === 'string' && definition.title.length > 0 && definition.items.length > 0 && definition.items.every((name)=>typeof name === 'string' && name.startsWith('mediaEmbed:')) && definition.items.includes(definition.defaultItem);
1999
+ if (!valid) {
2000
+ warnInvalidDropdown({
2001
+ dropdown: definition
2002
+ });
2003
+ }
2004
+ return valid;
2005
+ }
2006
+ /**
2007
+ * Emits a console warning under `media-style-configuration-definition-invalid` for an invalid
2008
+ * or partially-honored dropdown definition. Called from {@link ~isValidCustomDropdown} for
2009
+ * structural problems and from {@link MediaEmbedStyleUI#_getDropdownDefinitions} when items
2010
+ * reference styles that are not in the resolved options list.
2011
+ */ function warnInvalidDropdown(info) {
2012
+ logWarning('media-style-configuration-definition-invalid', info);
2013
+ }
2014
+
2015
+ /**
2016
+ * The media embed style plugin.
2017
+ *
2018
+ * This is a "glue" plugin which loads the following plugins:
2019
+ * * {@link module:media-embed/mediaembedstyle/mediaembedstyleediting~MediaEmbedStyleEditing},
2020
+ * * {@link module:media-embed/mediaembedstyle/mediaembedstyleui~MediaEmbedStyleUI}
2021
+ *
2022
+ * For a detailed overview, check the {@glink features/media-embed/media-embed-styles Media embed styles feature documentation}.
2023
+ */ class MediaEmbedStyle extends Plugin {
2024
+ /**
2025
+ * @inheritDoc
2026
+ */ static get requires() {
2027
+ return [
2028
+ MediaEmbedStyleEditing,
2029
+ MediaEmbedStyleUI
2030
+ ];
2031
+ }
2032
+ /**
2033
+ * @inheritDoc
2034
+ */ static get pluginName() {
2035
+ return 'MediaEmbedStyle';
2036
+ }
2037
+ /**
2038
+ * @inheritDoc
2039
+ */ static get isOfficialPlugin() {
2040
+ return true;
2041
+ }
2042
+ }
1136
2043
 
1137
- export { AutoMediaEmbed, MediaEmbed, MediaEmbedCommand, MediaEmbedEditing, MediaEmbedToolbar, MediaEmbedUI, MediaRegistry, MediaFormView as _MediaFormView, createMediaFigureElement as _createMediaFigureElement, getSelectedMediaModelWidget as _getSelectedMediaModelWidget, getSelectedMediaViewWidget as _getSelectedMediaViewWidget, insertMedia as _insertMedia, isMediaWidget as _isMediaWidget, modelToViewUrlAttributeConverter as _modelToViewUrlAttributeMediaConverter, toMediaWidget as _toMediaWidget };
2044
+ export { AutoMediaEmbed, MediaEmbed, MediaEmbedCommand, MediaEmbedEditing, MediaEmbedResize, MediaEmbedResizeEditing, MediaEmbedResizeHandles, MediaEmbedStyle, MediaEmbedStyleCommand, MediaEmbedStyleEditing, MediaEmbedStyleUI, MediaEmbedToolbar, MediaEmbedUI, MediaRegistry, ResizeMediaEmbedCommand, MediaFormView as _MediaFormView, createMediaFigureElement as _createMediaFigureElement, getSelectedMediaModelWidget as _getSelectedMediaModelWidget, getSelectedMediaViewWidget as _getSelectedMediaViewWidget, insertMedia as _insertMedia, isMediaWidget as _isMediaWidget, modelToViewUrlAttributeConverter as _modelToViewUrlAttributeMediaConverter, toMediaWidget as _toMediaWidget };
1138
2045
  //# sourceMappingURL=index.js.map