@ckeditor/ckeditor5-html-embed 41.3.1 → 41.4.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 (165) hide show
  1. package/build/html-embed.js +1 -1
  2. package/dist/index-content.css +4 -0
  3. package/dist/index-editor.css +43 -0
  4. package/dist/index.css +68 -0
  5. package/dist/index.css.map +1 -0
  6. package/dist/index.js +483 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/translations/ar.d.ts +8 -0
  9. package/dist/translations/ar.js +5 -0
  10. package/dist/translations/ar.umd.js +11 -0
  11. package/dist/translations/bg.d.ts +8 -0
  12. package/dist/translations/bg.js +5 -0
  13. package/dist/translations/bg.umd.js +11 -0
  14. package/dist/translations/bn.d.ts +8 -0
  15. package/dist/translations/bn.js +5 -0
  16. package/dist/translations/bn.umd.js +11 -0
  17. package/dist/translations/bs.d.ts +8 -0
  18. package/dist/translations/bs.js +5 -0
  19. package/dist/translations/bs.umd.js +11 -0
  20. package/dist/translations/ca.d.ts +8 -0
  21. package/dist/translations/ca.js +5 -0
  22. package/dist/translations/ca.umd.js +11 -0
  23. package/dist/translations/cs.d.ts +8 -0
  24. package/dist/translations/cs.js +5 -0
  25. package/dist/translations/cs.umd.js +11 -0
  26. package/dist/translations/da.d.ts +8 -0
  27. package/dist/translations/da.js +5 -0
  28. package/dist/translations/da.umd.js +11 -0
  29. package/dist/translations/de-ch.d.ts +8 -0
  30. package/dist/translations/de-ch.js +5 -0
  31. package/dist/translations/de-ch.umd.js +11 -0
  32. package/dist/translations/de.d.ts +8 -0
  33. package/dist/translations/de.js +5 -0
  34. package/dist/translations/de.umd.js +11 -0
  35. package/dist/translations/el.d.ts +8 -0
  36. package/dist/translations/el.js +5 -0
  37. package/dist/translations/el.umd.js +11 -0
  38. package/dist/translations/en-au.d.ts +8 -0
  39. package/dist/translations/en-au.js +5 -0
  40. package/dist/translations/en-au.umd.js +11 -0
  41. package/dist/translations/en.d.ts +8 -0
  42. package/dist/translations/en.js +5 -0
  43. package/dist/translations/en.umd.js +11 -0
  44. package/dist/translations/es.d.ts +8 -0
  45. package/dist/translations/es.js +5 -0
  46. package/dist/translations/es.umd.js +11 -0
  47. package/dist/translations/et.d.ts +8 -0
  48. package/dist/translations/et.js +5 -0
  49. package/dist/translations/et.umd.js +11 -0
  50. package/dist/translations/fa.d.ts +8 -0
  51. package/dist/translations/fa.js +5 -0
  52. package/dist/translations/fa.umd.js +11 -0
  53. package/dist/translations/fi.d.ts +8 -0
  54. package/dist/translations/fi.js +5 -0
  55. package/dist/translations/fi.umd.js +11 -0
  56. package/dist/translations/fr.d.ts +8 -0
  57. package/dist/translations/fr.js +5 -0
  58. package/dist/translations/fr.umd.js +11 -0
  59. package/dist/translations/gl.d.ts +8 -0
  60. package/dist/translations/gl.js +5 -0
  61. package/dist/translations/gl.umd.js +11 -0
  62. package/dist/translations/he.d.ts +8 -0
  63. package/dist/translations/he.js +5 -0
  64. package/dist/translations/he.umd.js +11 -0
  65. package/dist/translations/hi.d.ts +8 -0
  66. package/dist/translations/hi.js +5 -0
  67. package/dist/translations/hi.umd.js +11 -0
  68. package/dist/translations/hr.d.ts +8 -0
  69. package/dist/translations/hr.js +5 -0
  70. package/dist/translations/hr.umd.js +11 -0
  71. package/dist/translations/hu.d.ts +8 -0
  72. package/dist/translations/hu.js +5 -0
  73. package/dist/translations/hu.umd.js +11 -0
  74. package/dist/translations/id.d.ts +8 -0
  75. package/dist/translations/id.js +5 -0
  76. package/dist/translations/id.umd.js +11 -0
  77. package/dist/translations/it.d.ts +8 -0
  78. package/dist/translations/it.js +5 -0
  79. package/dist/translations/it.umd.js +11 -0
  80. package/dist/translations/ja.d.ts +8 -0
  81. package/dist/translations/ja.js +5 -0
  82. package/dist/translations/ja.umd.js +11 -0
  83. package/dist/translations/jv.d.ts +8 -0
  84. package/dist/translations/jv.js +5 -0
  85. package/dist/translations/jv.umd.js +11 -0
  86. package/dist/translations/ko.d.ts +8 -0
  87. package/dist/translations/ko.js +5 -0
  88. package/dist/translations/ko.umd.js +11 -0
  89. package/dist/translations/lt.d.ts +8 -0
  90. package/dist/translations/lt.js +5 -0
  91. package/dist/translations/lt.umd.js +11 -0
  92. package/dist/translations/lv.d.ts +8 -0
  93. package/dist/translations/lv.js +5 -0
  94. package/dist/translations/lv.umd.js +11 -0
  95. package/dist/translations/ms.d.ts +8 -0
  96. package/dist/translations/ms.js +5 -0
  97. package/dist/translations/ms.umd.js +11 -0
  98. package/dist/translations/nl.d.ts +8 -0
  99. package/dist/translations/nl.js +5 -0
  100. package/dist/translations/nl.umd.js +11 -0
  101. package/dist/translations/no.d.ts +8 -0
  102. package/dist/translations/no.js +5 -0
  103. package/dist/translations/no.umd.js +11 -0
  104. package/dist/translations/pl.d.ts +8 -0
  105. package/dist/translations/pl.js +5 -0
  106. package/dist/translations/pl.umd.js +11 -0
  107. package/dist/translations/pt-br.d.ts +8 -0
  108. package/dist/translations/pt-br.js +5 -0
  109. package/dist/translations/pt-br.umd.js +11 -0
  110. package/dist/translations/pt.d.ts +8 -0
  111. package/dist/translations/pt.js +5 -0
  112. package/dist/translations/pt.umd.js +11 -0
  113. package/dist/translations/ro.d.ts +8 -0
  114. package/dist/translations/ro.js +5 -0
  115. package/dist/translations/ro.umd.js +11 -0
  116. package/dist/translations/ru.d.ts +8 -0
  117. package/dist/translations/ru.js +5 -0
  118. package/dist/translations/ru.umd.js +11 -0
  119. package/dist/translations/sk.d.ts +8 -0
  120. package/dist/translations/sk.js +5 -0
  121. package/dist/translations/sk.umd.js +11 -0
  122. package/dist/translations/sl.d.ts +8 -0
  123. package/dist/translations/sl.js +5 -0
  124. package/dist/translations/sl.umd.js +11 -0
  125. package/dist/translations/sr-latn.d.ts +8 -0
  126. package/dist/translations/sr-latn.js +5 -0
  127. package/dist/translations/sr-latn.umd.js +11 -0
  128. package/dist/translations/sr.d.ts +8 -0
  129. package/dist/translations/sr.js +5 -0
  130. package/dist/translations/sr.umd.js +11 -0
  131. package/dist/translations/sv.d.ts +8 -0
  132. package/dist/translations/sv.js +5 -0
  133. package/dist/translations/sv.umd.js +11 -0
  134. package/dist/translations/th.d.ts +8 -0
  135. package/dist/translations/th.js +5 -0
  136. package/dist/translations/th.umd.js +11 -0
  137. package/dist/translations/tr.d.ts +8 -0
  138. package/dist/translations/tr.js +5 -0
  139. package/dist/translations/tr.umd.js +11 -0
  140. package/dist/translations/uk.d.ts +8 -0
  141. package/dist/translations/uk.js +5 -0
  142. package/dist/translations/uk.umd.js +11 -0
  143. package/dist/translations/ur.d.ts +8 -0
  144. package/dist/translations/ur.js +5 -0
  145. package/dist/translations/ur.umd.js +11 -0
  146. package/dist/translations/uz.d.ts +8 -0
  147. package/dist/translations/uz.js +5 -0
  148. package/dist/translations/uz.umd.js +11 -0
  149. package/dist/translations/vi.d.ts +8 -0
  150. package/dist/translations/vi.js +5 -0
  151. package/dist/translations/vi.umd.js +11 -0
  152. package/dist/translations/zh-cn.d.ts +8 -0
  153. package/dist/translations/zh-cn.js +5 -0
  154. package/dist/translations/zh-cn.umd.js +11 -0
  155. package/dist/translations/zh.d.ts +8 -0
  156. package/dist/translations/zh.js +5 -0
  157. package/dist/translations/zh.umd.js +11 -0
  158. package/dist/types/augmentation.d.ts +28 -0
  159. package/dist/types/htmlembed.d.ts +32 -0
  160. package/dist/types/htmlembedcommand.d.ts +48 -0
  161. package/dist/types/htmlembedconfig.d.ts +90 -0
  162. package/dist/types/htmlembedediting.d.ts +44 -0
  163. package/dist/types/htmlembedui.d.ts +29 -0
  164. package/dist/types/index.d.ts +17 -0
  165. package/package.json +3 -2
package/dist/index.js ADDED
@@ -0,0 +1,483 @@
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 { findOptimalInsertionRange, toWidget, Widget } from '@ckeditor/ckeditor5-widget/dist/index.js';
7
+ import { ButtonView, MenuBarMenuListItemButtonView } from '@ckeditor/ckeditor5-ui/dist/index.js';
8
+ import { createElement, logWarning } from '@ckeditor/ckeditor5-utils/dist/index.js';
9
+
10
+ class HtmlEmbedCommand extends Command {
11
+ /**
12
+ * @inheritDoc
13
+ */ refresh() {
14
+ const model = this.editor.model;
15
+ const schema = model.schema;
16
+ const selection = model.document.selection;
17
+ const selectedRawHtmlElement = getSelectedRawHtmlModelWidget(selection);
18
+ this.isEnabled = isHtmlEmbedAllowedInParent(selection, schema, model);
19
+ this.value = selectedRawHtmlElement ? selectedRawHtmlElement.getAttribute('value') || '' : null;
20
+ }
21
+ /**
22
+ * Executes the command, which either:
23
+ *
24
+ * * creates and inserts a new HTML embed element if none was selected,
25
+ * * updates the content of the HTML embed if one was selected.
26
+ *
27
+ * @fires execute
28
+ * @param value When passed, the value (content) will be set on a new embed or a selected one.
29
+ */ execute(value) {
30
+ const model = this.editor.model;
31
+ const selection = model.document.selection;
32
+ model.change((writer)=>{
33
+ let htmlEmbedElement;
34
+ // If the command has a non-null value, there must be some HTML embed selected in the model.
35
+ if (this.value !== null) {
36
+ htmlEmbedElement = getSelectedRawHtmlModelWidget(selection);
37
+ } else {
38
+ htmlEmbedElement = writer.createElement('rawHtml');
39
+ model.insertObject(htmlEmbedElement, null, null, {
40
+ setSelection: 'on'
41
+ });
42
+ }
43
+ writer.setAttribute('value', value, htmlEmbedElement);
44
+ });
45
+ }
46
+ }
47
+ /**
48
+ * Checks if an HTML embed is allowed by the schema in the optimal insertion parent.
49
+ */ function isHtmlEmbedAllowedInParent(selection, schema, model) {
50
+ const parent = getInsertHtmlEmbedParent(selection, model);
51
+ return schema.checkChild(parent, 'rawHtml');
52
+ }
53
+ /**
54
+ * Returns a node that will be used to insert a html embed with `model.insertContent` to check if a html embed element can be placed there.
55
+ */ function getInsertHtmlEmbedParent(selection, model) {
56
+ const insertionRange = findOptimalInsertionRange(selection, model);
57
+ const parent = insertionRange.start.parent;
58
+ if (parent.isEmpty && !parent.is('rootElement')) {
59
+ return parent.parent;
60
+ }
61
+ return parent;
62
+ }
63
+ /**
64
+ * Returns the selected HTML embed element in the model, if any.
65
+ */ function getSelectedRawHtmlModelWidget(selection) {
66
+ const selectedElement = selection.getSelectedElement();
67
+ if (selectedElement && selectedElement.is('element', 'rawHtml')) {
68
+ return selectedElement;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ class HtmlEmbedEditing extends Plugin {
74
+ /**
75
+ * @inheritDoc
76
+ */ static get pluginName() {
77
+ return 'HtmlEmbedEditing';
78
+ }
79
+ /**
80
+ * @inheritDoc
81
+ */ init() {
82
+ const editor = this.editor;
83
+ const schema = editor.model.schema;
84
+ schema.register('rawHtml', {
85
+ inheritAllFrom: '$blockObject',
86
+ allowAttributes: [
87
+ 'value'
88
+ ]
89
+ });
90
+ editor.commands.add('htmlEmbed', new HtmlEmbedCommand(editor));
91
+ this._setupConversion();
92
+ }
93
+ /**
94
+ * Prepares converters for the feature.
95
+ */ _setupConversion() {
96
+ const editor = this.editor;
97
+ const t = editor.t;
98
+ const view = editor.editing.view;
99
+ const widgetButtonViewReferences = this._widgetButtonViewReferences;
100
+ const htmlEmbedConfig = editor.config.get('htmlEmbed');
101
+ // Destroy UI buttons created for widgets that have been removed from the view document (e.g. in the previous conversion).
102
+ // This prevents unexpected memory leaks from UI views.
103
+ this.editor.editing.view.on('render', ()=>{
104
+ for (const buttonView of widgetButtonViewReferences){
105
+ if (buttonView.element && buttonView.element.isConnected) {
106
+ return;
107
+ }
108
+ buttonView.destroy();
109
+ widgetButtonViewReferences.delete(buttonView);
110
+ }
111
+ }, {
112
+ priority: 'lowest'
113
+ });
114
+ // Register div.raw-html-embed as a raw content element so all of it's content will be provided
115
+ // as a view element's custom property while data upcasting.
116
+ editor.data.registerRawContentMatcher({
117
+ name: 'div',
118
+ classes: 'raw-html-embed'
119
+ });
120
+ editor.conversion.for('upcast').elementToElement({
121
+ view: {
122
+ name: 'div',
123
+ classes: 'raw-html-embed'
124
+ },
125
+ model: (viewElement, { writer })=>{
126
+ // The div.raw-html-embed is registered as a raw content element,
127
+ // so all it's content is available in a custom property.
128
+ return writer.createElement('rawHtml', {
129
+ value: viewElement.getCustomProperty('$rawContent')
130
+ });
131
+ }
132
+ });
133
+ editor.conversion.for('dataDowncast').elementToElement({
134
+ model: 'rawHtml',
135
+ view: (modelElement, { writer })=>{
136
+ return writer.createRawElement('div', {
137
+ class: 'raw-html-embed'
138
+ }, function(domElement) {
139
+ domElement.innerHTML = modelElement.getAttribute('value') || '';
140
+ });
141
+ }
142
+ });
143
+ editor.conversion.for('editingDowncast').elementToStructure({
144
+ model: {
145
+ name: 'rawHtml',
146
+ attributes: [
147
+ 'value'
148
+ ]
149
+ },
150
+ view: (modelElement, { writer })=>{
151
+ let domContentWrapper;
152
+ let state;
153
+ let props;
154
+ const viewContentWrapper = writer.createRawElement('div', {
155
+ class: 'raw-html-embed__content-wrapper'
156
+ }, function(domElement) {
157
+ domContentWrapper = domElement;
158
+ renderContent({
159
+ editor,
160
+ domElement,
161
+ state,
162
+ props
163
+ });
164
+ // Since there is a `data-cke-ignore-events` attribute set on the wrapper element in the editable mode,
165
+ // the explicit `mousedown` handler on the `capture` phase is needed to move the selection onto the whole
166
+ // HTML embed widget.
167
+ domContentWrapper.addEventListener('mousedown', ()=>{
168
+ if (state.isEditable) {
169
+ const model = editor.model;
170
+ const selectedElement = model.document.selection.getSelectedElement();
171
+ // Move the selection onto the whole HTML embed widget if it's currently not selected.
172
+ if (selectedElement !== modelElement) {
173
+ model.change((writer)=>writer.setSelection(modelElement, 'on'));
174
+ }
175
+ }
176
+ }, true);
177
+ });
178
+ // API exposed on each raw HTML embed widget so other features can control a particular widget.
179
+ const rawHtmlApi = {
180
+ makeEditable () {
181
+ state = Object.assign({}, state, {
182
+ isEditable: true
183
+ });
184
+ renderContent({
185
+ domElement: domContentWrapper,
186
+ editor,
187
+ state,
188
+ props
189
+ });
190
+ view.change((writer)=>{
191
+ writer.setAttribute('data-cke-ignore-events', 'true', viewContentWrapper);
192
+ });
193
+ // This could be potentially pulled to a separate method called focusTextarea().
194
+ domContentWrapper.querySelector('textarea').focus();
195
+ },
196
+ save (newValue) {
197
+ // If the value didn't change, we just cancel. If it changed,
198
+ // it's enough to update the model – the entire widget will be reconverted.
199
+ if (newValue !== state.getRawHtmlValue()) {
200
+ editor.execute('htmlEmbed', newValue);
201
+ editor.editing.view.focus();
202
+ } else {
203
+ this.cancel();
204
+ }
205
+ },
206
+ cancel () {
207
+ state = Object.assign({}, state, {
208
+ isEditable: false
209
+ });
210
+ renderContent({
211
+ domElement: domContentWrapper,
212
+ editor,
213
+ state,
214
+ props
215
+ });
216
+ editor.editing.view.focus();
217
+ view.change((writer)=>{
218
+ writer.removeAttribute('data-cke-ignore-events', viewContentWrapper);
219
+ });
220
+ }
221
+ };
222
+ state = {
223
+ showPreviews: htmlEmbedConfig.showPreviews,
224
+ isEditable: false,
225
+ getRawHtmlValue: ()=>modelElement.getAttribute('value') || ''
226
+ };
227
+ props = {
228
+ sanitizeHtml: htmlEmbedConfig.sanitizeHtml,
229
+ textareaPlaceholder: t('Paste raw HTML here...'),
230
+ onEditClick () {
231
+ rawHtmlApi.makeEditable();
232
+ },
233
+ onSaveClick (newValue) {
234
+ rawHtmlApi.save(newValue);
235
+ },
236
+ onCancelClick () {
237
+ rawHtmlApi.cancel();
238
+ }
239
+ };
240
+ const viewContainer = writer.createContainerElement('div', {
241
+ class: 'raw-html-embed',
242
+ 'data-html-embed-label': t('HTML snippet'),
243
+ dir: editor.locale.uiLanguageDirection
244
+ }, viewContentWrapper);
245
+ writer.setCustomProperty('rawHtmlApi', rawHtmlApi, viewContainer);
246
+ writer.setCustomProperty('rawHtml', true, viewContainer);
247
+ return toWidget(viewContainer, writer, {
248
+ label: t('HTML snippet'),
249
+ hasSelectionHandle: true
250
+ });
251
+ }
252
+ });
253
+ function renderContent({ editor, domElement, state, props }) {
254
+ // Remove all children;
255
+ domElement.textContent = '';
256
+ const domDocument = domElement.ownerDocument;
257
+ let domTextarea;
258
+ if (state.isEditable) {
259
+ const textareaProps = {
260
+ isDisabled: false,
261
+ placeholder: props.textareaPlaceholder
262
+ };
263
+ domTextarea = createDomTextarea({
264
+ domDocument,
265
+ state,
266
+ props: textareaProps
267
+ });
268
+ domElement.append(domTextarea);
269
+ } else if (state.showPreviews) {
270
+ const previewContainerProps = {
271
+ sanitizeHtml: props.sanitizeHtml
272
+ };
273
+ domElement.append(createPreviewContainer({
274
+ domDocument,
275
+ state,
276
+ props: previewContainerProps,
277
+ editor
278
+ }));
279
+ } else {
280
+ const textareaProps = {
281
+ isDisabled: true,
282
+ placeholder: props.textareaPlaceholder
283
+ };
284
+ domElement.append(createDomTextarea({
285
+ domDocument,
286
+ state,
287
+ props: textareaProps
288
+ }));
289
+ }
290
+ const buttonsWrapperProps = {
291
+ onEditClick: props.onEditClick,
292
+ onSaveClick: ()=>{
293
+ props.onSaveClick(domTextarea.value);
294
+ },
295
+ onCancelClick: props.onCancelClick
296
+ };
297
+ domElement.prepend(createDomButtonsWrapper({
298
+ editor,
299
+ domDocument,
300
+ state,
301
+ props: buttonsWrapperProps
302
+ }));
303
+ }
304
+ function createDomButtonsWrapper({ editor, domDocument, state, props }) {
305
+ const domButtonsWrapper = createElement(domDocument, 'div', {
306
+ class: 'raw-html-embed__buttons-wrapper'
307
+ });
308
+ if (state.isEditable) {
309
+ const saveButtonView = createUIButton(editor, 'save', props.onSaveClick);
310
+ const cancelButtonView = createUIButton(editor, 'cancel', props.onCancelClick);
311
+ domButtonsWrapper.append(saveButtonView.element, cancelButtonView.element);
312
+ widgetButtonViewReferences.add(saveButtonView).add(cancelButtonView);
313
+ } else {
314
+ const editButtonView = createUIButton(editor, 'edit', props.onEditClick);
315
+ domButtonsWrapper.append(editButtonView.element);
316
+ widgetButtonViewReferences.add(editButtonView);
317
+ }
318
+ return domButtonsWrapper;
319
+ }
320
+ function createDomTextarea({ domDocument, state, props }) {
321
+ const domTextarea = createElement(domDocument, 'textarea', {
322
+ placeholder: props.placeholder,
323
+ class: 'ck ck-reset ck-input ck-input-text raw-html-embed__source'
324
+ });
325
+ domTextarea.disabled = props.isDisabled;
326
+ domTextarea.value = state.getRawHtmlValue();
327
+ return domTextarea;
328
+ }
329
+ function createPreviewContainer({ editor, domDocument, state, props }) {
330
+ const sanitizedOutput = props.sanitizeHtml(state.getRawHtmlValue());
331
+ const placeholderText = state.getRawHtmlValue().length > 0 ? t('No preview available') : t('Empty snippet content');
332
+ const domPreviewPlaceholder = createElement(domDocument, 'div', {
333
+ class: 'ck ck-reset_all raw-html-embed__preview-placeholder'
334
+ }, placeholderText);
335
+ const domPreviewContent = createElement(domDocument, 'div', {
336
+ class: 'raw-html-embed__preview-content',
337
+ dir: editor.locale.contentLanguageDirection
338
+ });
339
+ // Creating a contextual document fragment allows executing scripts when inserting into the preview element.
340
+ // See: #8326.
341
+ const domRange = domDocument.createRange();
342
+ const domDocumentFragment = domRange.createContextualFragment(sanitizedOutput.html);
343
+ domPreviewContent.appendChild(domDocumentFragment);
344
+ const domPreviewContainer = createElement(domDocument, 'div', {
345
+ class: 'raw-html-embed__preview'
346
+ }, [
347
+ domPreviewPlaceholder,
348
+ domPreviewContent
349
+ ]);
350
+ return domPreviewContainer;
351
+ }
352
+ }
353
+ /**
354
+ * @inheritDoc
355
+ */ constructor(editor){
356
+ super(editor);
357
+ /**
358
+ * Keeps references to {@link module:ui/button/buttonview~ButtonView edit, save, and cancel} button instances created for
359
+ * each widget so they can be destroyed if they are no longer in DOM after the editing view was re-rendered.
360
+ */ this._widgetButtonViewReferences = new Set();
361
+ editor.config.define('htmlEmbed', {
362
+ showPreviews: false,
363
+ sanitizeHtml: (rawHtml)=>{
364
+ /**
365
+ * When using the HTML embed feature with the `htmlEmbed.showPreviews=true` option, it is strongly recommended to
366
+ * define a sanitize function that will clean up the input HTML in order to avoid XSS vulnerability.
367
+ *
368
+ * For a detailed overview, check the {@glink features/html/html-embed HTML embed feature} documentation.
369
+ *
370
+ * @error html-embed-provide-sanitize-function
371
+ */ logWarning('html-embed-provide-sanitize-function');
372
+ return {
373
+ html: rawHtml,
374
+ hasChanged: false
375
+ };
376
+ }
377
+ });
378
+ }
379
+ }
380
+ /**
381
+ * Returns a UI button view that can be used in conversion.
382
+ */ function createUIButton(editor, type, onClick) {
383
+ const { t } = editor.locale;
384
+ const buttonView = new ButtonView(editor.locale);
385
+ const command = editor.commands.get('htmlEmbed');
386
+ buttonView.set({
387
+ class: `raw-html-embed__${type}-button`,
388
+ icon: icons.pencil,
389
+ tooltip: true,
390
+ tooltipPosition: editor.locale.uiLanguageDirection === 'rtl' ? 'e' : 'w'
391
+ });
392
+ buttonView.render();
393
+ if (type === 'edit') {
394
+ buttonView.set({
395
+ icon: icons.pencil,
396
+ label: t('Edit source')
397
+ });
398
+ buttonView.bind('isEnabled').to(command);
399
+ } else if (type === 'save') {
400
+ buttonView.set({
401
+ icon: icons.check,
402
+ label: t('Save changes')
403
+ });
404
+ buttonView.bind('isEnabled').to(command);
405
+ } else {
406
+ buttonView.set({
407
+ icon: icons.cancel,
408
+ label: t('Cancel')
409
+ });
410
+ }
411
+ buttonView.on('execute', onClick);
412
+ return buttonView;
413
+ }
414
+
415
+ class HtmlEmbedUI extends Plugin {
416
+ /**
417
+ * @inheritDoc
418
+ */ static get pluginName() {
419
+ return 'HtmlEmbedUI';
420
+ }
421
+ /**
422
+ * @inheritDoc
423
+ */ init() {
424
+ const editor = this.editor;
425
+ const locale = editor.locale;
426
+ const t = locale.t;
427
+ // Add the `htmlEmbed` button to feature components.
428
+ editor.ui.componentFactory.add('htmlEmbed', ()=>{
429
+ const buttonView = this._createButton(ButtonView);
430
+ buttonView.set({
431
+ tooltip: true,
432
+ label: t('Insert HTML')
433
+ });
434
+ return buttonView;
435
+ });
436
+ editor.ui.componentFactory.add('menuBar:htmlEmbed', ()=>{
437
+ const buttonView = this._createButton(MenuBarMenuListItemButtonView);
438
+ buttonView.set({
439
+ label: t('HTML snippet')
440
+ });
441
+ return buttonView;
442
+ });
443
+ }
444
+ /**
445
+ * Creates a button for html embed command to use either in toolbar or in menu bar.
446
+ */ _createButton(ButtonClass) {
447
+ const editor = this.editor;
448
+ const command = editor.commands.get('htmlEmbed');
449
+ const view = new ButtonClass(editor.locale);
450
+ view.set({
451
+ icon: icons.html
452
+ });
453
+ view.bind('isEnabled').to(command, 'isEnabled');
454
+ // Execute the command.
455
+ this.listenTo(view, 'execute', ()=>{
456
+ editor.execute('htmlEmbed');
457
+ editor.editing.view.focus();
458
+ const rawHtmlApi = editor.editing.view.document.selection.getSelectedElement().getCustomProperty('rawHtmlApi');
459
+ rawHtmlApi.makeEditable();
460
+ });
461
+ return view;
462
+ }
463
+ }
464
+
465
+ class HtmlEmbed extends Plugin {
466
+ /**
467
+ * @inheritDoc
468
+ */ static get requires() {
469
+ return [
470
+ HtmlEmbedEditing,
471
+ HtmlEmbedUI,
472
+ Widget
473
+ ];
474
+ }
475
+ /**
476
+ * @inheritDoc
477
+ */ static get pluginName() {
478
+ return 'HtmlEmbed';
479
+ }
480
+ }
481
+
482
+ export { HtmlEmbed, HtmlEmbedEditing, HtmlEmbedUI };
483
+ //# sourceMappingURL=index.js.map