@ohos-ports/ckeditor5-html-embed 48.5.0-beta.1

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