magic-editor-x 1.6.0 → 2.0.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 (97) hide show
  1. package/CHANGELOG.md +268 -0
  2. package/LICENSE +1 -7
  3. package/README.md +324 -981
  4. package/dist/admin/ConfigurationPage-B1uCIE3J.js +767 -0
  5. package/dist/admin/ConfigurationPage-DvAifELO.mjs +767 -0
  6. package/dist/admin/CustomBlocksPage-6-OQwpXQ.mjs +1741 -0
  7. package/dist/admin/CustomBlocksPage-6eWCOreU.js +1743 -0
  8. package/dist/admin/EditorField-DocyD2Q3.js +5506 -0
  9. package/dist/admin/EditorField-ThSoOCPm.mjs +5471 -0
  10. package/dist/admin/api-B-RsxJCs.js +34 -0
  11. package/dist/admin/api-C4XsDZxd.mjs +35 -0
  12. package/dist/admin/de-B8XFFhHh.js +95 -0
  13. package/dist/admin/de-BMxADn2Z.mjs +231 -0
  14. package/dist/admin/de-DBR893G4.js +13 -0
  15. package/dist/admin/de-DcDPRzV4.js +155 -0
  16. package/dist/admin/de-Dx7vUW0Z.js +231 -0
  17. package/dist/admin/de-RAxzvrwm.mjs +95 -0
  18. package/dist/admin/de-fBFh09Wl.mjs +13 -0
  19. package/dist/admin/de-n5V6c5RT.mjs +155 -0
  20. package/dist/admin/en-BQ5Pxe2o.mjs +231 -0
  21. package/dist/admin/en-BqNm3nMQ.mjs +155 -0
  22. package/dist/admin/en-BzfyifEU.mjs +95 -0
  23. package/dist/admin/en-D-DGftl0.js +155 -0
  24. package/dist/admin/en-D9Nfccux.mjs +13 -0
  25. package/dist/admin/en-DcWUTE2J.js +95 -0
  26. package/dist/admin/en-gueRT44P.js +13 -0
  27. package/dist/admin/en-sNn4z9lA.js +231 -0
  28. package/dist/admin/es-B0Zy8DVg.mjs +13 -0
  29. package/dist/admin/es-B6NYq0VH.mjs +231 -0
  30. package/dist/admin/es-BOtVc9qv.js +95 -0
  31. package/dist/admin/es-C2OJVYkV.mjs +95 -0
  32. package/dist/admin/es-DRGs7meF.js +13 -0
  33. package/dist/admin/es-DVsXnS0N.js +231 -0
  34. package/dist/admin/es-Di0pyQCh.js +155 -0
  35. package/dist/admin/es-SzeTV4q8.mjs +155 -0
  36. package/dist/admin/fr-B8rdLAIL.js +13 -0
  37. package/dist/admin/fr-Bpo5Uq1f.mjs +95 -0
  38. package/dist/admin/fr-D6F--jIB.js +155 -0
  39. package/dist/admin/fr-DfxKaOc_.js +95 -0
  40. package/dist/admin/fr-DhgPYHIH.mjs +155 -0
  41. package/dist/admin/fr-DmG3_Cn-.mjs +231 -0
  42. package/dist/admin/fr-Fwxcj4SM.js +231 -0
  43. package/dist/admin/fr-oiUb2bb_.mjs +13 -0
  44. package/dist/admin/index-CwfaB5-e.js +155 -0
  45. package/dist/admin/index-D1Q5Rlt6.mjs +156 -0
  46. package/dist/admin/index.js +1 -1
  47. package/dist/admin/index.mjs +2 -2
  48. package/dist/admin/pt-B3Jce6uT.mjs +13 -0
  49. package/dist/admin/pt-BPo0ex21.js +155 -0
  50. package/dist/admin/pt-BbdwHlWF.mjs +231 -0
  51. package/dist/admin/pt-BiWuSBcH.js +13 -0
  52. package/dist/admin/pt-BvSl1btT.mjs +155 -0
  53. package/dist/admin/pt-C6nr71Yw.js +231 -0
  54. package/dist/admin/pt-DqCXuI4S.mjs +95 -0
  55. package/dist/admin/pt-LCvjwk0y.js +95 -0
  56. package/dist/admin/sanitize-9UVcXFfc.js +552 -0
  57. package/dist/admin/sanitize-D4kfZ_ly.mjs +551 -0
  58. package/dist/admin/useT-B5M49wGH.js +130 -0
  59. package/dist/admin/useT-CjX6fL2m.mjs +131 -0
  60. package/dist/server/index.js +4150 -64739
  61. package/dist/server/index.mjs +4150 -64748
  62. package/package.json +90 -66
  63. package/strapi-admin.js +3 -0
  64. package/strapi-server.js +3 -0
  65. package/COPYRIGHT_NOTICE.txt +0 -20
  66. package/dist/admin/App-BwMEZnS-.mjs +0 -2144
  67. package/dist/admin/App-HNr2tizR.js +0 -2147
  68. package/dist/admin/CustomBlocksPage-BjcA7MGz.js +0 -1519
  69. package/dist/admin/CustomBlocksPage-COPOZ2-_.mjs +0 -1517
  70. package/dist/admin/LicensePage-D0DMTF41.mjs +0 -392
  71. package/dist/admin/LicensePage-D0_9yPkw.js +0 -394
  72. package/dist/admin/LiveCollaborationPanel-CZAbgAVr.js +0 -223
  73. package/dist/admin/LiveCollaborationPanel-D8z72afw.mjs +0 -221
  74. package/dist/admin/Settings-DRenvRcG.js +0 -441
  75. package/dist/admin/Settings-DjyNURlS.mjs +0 -439
  76. package/dist/admin/de-C_0Mj-Zo.mjs +0 -296
  77. package/dist/admin/de-DVNVpAt9.js +0 -296
  78. package/dist/admin/en-B7AAf1ie.mjs +0 -296
  79. package/dist/admin/en-C2hv5GsA.js +0 -296
  80. package/dist/admin/es-BzJqcIST.js +0 -274
  81. package/dist/admin/es-zdP8sd-f.mjs +0 -274
  82. package/dist/admin/fr-CtAgOgH1.mjs +0 -274
  83. package/dist/admin/fr-D3GwqAAJ.js +0 -274
  84. package/dist/admin/getTranslation-2OiEgVGt.mjs +0 -49459
  85. package/dist/admin/getTranslation-DQ_WJ-7M.js +0 -49475
  86. package/dist/admin/index-Bn2tfJrC.js +0 -2186
  87. package/dist/admin/index-DAtClhqy.js +0 -6956
  88. package/dist/admin/index-FVEbTfqO.mjs +0 -2187
  89. package/dist/admin/index-gjWl-6E2.mjs +0 -6934
  90. package/dist/admin/magic-editor-x.css +0 -1103
  91. package/dist/admin/pt-BmUw6YMP.mjs +0 -274
  92. package/dist/admin/pt-CFo0nTbj.js +0 -274
  93. package/dist/admin/tools-CzHTZaY_.mjs +0 -2268
  94. package/dist/admin/tools-DALFhvPO.js +0 -2299
  95. package/pics/collab-magiceditorX.png +0 -0
  96. package/pics/editorX.png +0 -0
  97. package/pics/liveCollabwidget1.png +0 -0
@@ -1,2268 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import Header from "@editorjs/header";
5
- import Paragraph from "@editorjs/paragraph";
6
- import NestedList from "@editorjs/nested-list";
7
- import Checklist from "@editorjs/checklist";
8
- import Quote from "@editorjs/quote";
9
- import Warning from "@editorjs/warning";
10
- import Code from "@editorjs/code";
11
- import Delimiter from "@editorjs/delimiter";
12
- import Table from "@editorjs/table";
13
- import Embed from "@editorjs/embed";
14
- import Raw from "@editorjs/raw";
15
- import Image from "@editorjs/image";
16
- import SimpleImage from "@editorjs/simple-image";
17
- import LinkTool from "@editorjs/link";
18
- import Attaches from "@editorjs/attaches";
19
- import Personality from "@editorjs/personality";
20
- import Alert from "editorjs-alert";
21
- import ToggleBlock from "editorjs-toggle-block";
22
- import CodeFlask from "@calumk/editorjs-codeflask";
23
- import s__default, { useState, useRef, useEffect } from "react";
24
- import { createRoot } from "react-dom/client";
25
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
26
- import styled, { keyframes } from "styled-components";
27
- import Marker from "@editorjs/marker";
28
- import InlineCode from "@editorjs/inline-code";
29
- import Underline from "@editorjs/underline";
30
- import Strikethrough from "@sotaproject/strikethrough";
31
- import Tooltip from "editorjs-tooltip";
32
- import TextVariantTune from "@editorjs/text-variant-tune";
33
- import AlignmentTune from "editorjs-text-alignment-blocktune";
34
- import IndentTune from "editorjs-indent-tune";
35
- import Undo from "editorjs-undo";
36
- import DragDrop from "editorjs-drag-drop";
37
- class ButtonTool {
38
- /**
39
- * Enable paragraph-like behavior
40
- */
41
- static get pasteConfig() {
42
- return { tags: ["BUTTON", "A"] };
43
- }
44
- /**
45
- * Tool icon in the toolbox
46
- */
47
- static get toolbox() {
48
- return {
49
- title: "Button",
50
- icon: '<svg width="17" height="15" viewBox="0 0 17 15" xmlns="http://www.w3.org/2000/svg"><path d="M1 2.5C1 1.67157 1.67157 1 2.5 1H14.5C15.3284 1 16 1.67157 16 2.5V12.5C16 13.3284 15.3284 14 14.5 14H2.5C1.67157 14 1 13.3284 1 12.5V2.5ZM3.5 5C3.22386 5 3 5.22386 3 5.5V9.5C3 9.77614 3.22386 10 3.5 10H13.5C13.7761 10 14 9.77614 14 9.5V5.5C14 5.22386 13.7761 5 13.5 5H3.5Z" fill="currentColor"/></svg>'
51
- };
52
- }
53
- /**
54
- * Creates an instance of ButtonTool
55
- * @param {object} params - Constructor params
56
- * @param {object} params.data - Previously saved data
57
- * @param {object} params.config - Tool configuration
58
- * @param {object} params.api - Editor.js API
59
- */
60
- constructor({ data, config, api }) {
61
- this.api = api;
62
- this.config = config || {};
63
- this.data = {
64
- text: data.text || "",
65
- link: data.link || "",
66
- style: data.style || "primary",
67
- openInNewTab: data.openInNewTab !== false
68
- };
69
- this.wrapper = null;
70
- this.styles = this._getDefaultStyles();
71
- }
72
- /**
73
- * Returns default button styles
74
- * @returns {object} Style configuration
75
- */
76
- _getDefaultStyles() {
77
- return {
78
- primary: {
79
- background: "#3b82f6",
80
- color: "#ffffff",
81
- border: "none",
82
- hoverBackground: "#2563eb"
83
- },
84
- secondary: {
85
- background: "#64748b",
86
- color: "#ffffff",
87
- border: "none",
88
- hoverBackground: "#475569"
89
- },
90
- outline: {
91
- background: "transparent",
92
- color: "#3b82f6",
93
- border: "2px solid #3b82f6",
94
- hoverBackground: "#eff6ff"
95
- },
96
- success: {
97
- background: "#22c55e",
98
- color: "#ffffff",
99
- border: "none",
100
- hoverBackground: "#16a34a"
101
- },
102
- danger: {
103
- background: "#ef4444",
104
- color: "#ffffff",
105
- border: "none",
106
- hoverBackground: "#dc2626"
107
- }
108
- };
109
- }
110
- /**
111
- * Renders the tool UI
112
- * @returns {HTMLElement} The tool wrapper element
113
- */
114
- render() {
115
- this.wrapper = document.createElement("div");
116
- this.wrapper.classList.add("cdx-button-tool");
117
- this.wrapper.style.cssText = `
118
- padding: 12px;
119
- background: #f8fafc;
120
- border-radius: 8px;
121
- margin: 8px 0;
122
- `;
123
- const preview = document.createElement("div");
124
- preview.style.cssText = "text-align: center; margin-bottom: 12px;";
125
- const button = this._createButton();
126
- preview.appendChild(button);
127
- const form = document.createElement("div");
128
- form.style.cssText = "display: flex; flex-direction: column; gap: 8px;";
129
- const textInput = this._createInput("Button Text", this.data.text, (value) => {
130
- this.data.text = value;
131
- button.textContent = value || "Click Me";
132
- });
133
- const linkInput = this._createInput("Link URL", this.data.link, (value) => {
134
- this.data.link = value;
135
- });
136
- const styleSelect = this._createStyleSelect((value) => {
137
- this.data.style = value;
138
- this._updateButtonStyle(button, value);
139
- });
140
- const newTabCheckbox = this._createCheckbox("Open in new tab", this.data.openInNewTab, (checked) => {
141
- this.data.openInNewTab = checked;
142
- });
143
- form.appendChild(textInput);
144
- form.appendChild(linkInput);
145
- form.appendChild(styleSelect);
146
- form.appendChild(newTabCheckbox);
147
- this.wrapper.appendChild(preview);
148
- this.wrapper.appendChild(form);
149
- return this.wrapper;
150
- }
151
- /**
152
- * Creates the button element
153
- * @returns {HTMLElement} Button element
154
- */
155
- _createButton() {
156
- const button = document.createElement("button");
157
- button.type = "button";
158
- button.textContent = this.data.text || "Click Me";
159
- button.style.cssText = `
160
- padding: 10px 24px;
161
- font-size: 14px;
162
- font-weight: 600;
163
- border-radius: 6px;
164
- cursor: pointer;
165
- transition: all 0.2s ease;
166
- outline: none;
167
- `;
168
- this._updateButtonStyle(button, this.data.style);
169
- button.addEventListener("click", (e) => {
170
- e.preventDefault();
171
- e.stopPropagation();
172
- });
173
- return button;
174
- }
175
- /**
176
- * Updates button styling
177
- * @param {HTMLElement} button - Button element
178
- * @param {string} style - Style name
179
- */
180
- _updateButtonStyle(button, style) {
181
- const styleConfig = this.styles[style] || this.styles.primary;
182
- button.style.backgroundColor = styleConfig.background;
183
- button.style.color = styleConfig.color;
184
- button.style.border = styleConfig.border;
185
- }
186
- /**
187
- * Creates an input field with label
188
- * @param {string} label - Input label
189
- * @param {string} value - Initial value
190
- * @param {Function} onChange - Change handler
191
- * @returns {HTMLElement} Input container
192
- */
193
- _createInput(label, value, onChange) {
194
- const container = document.createElement("div");
195
- container.style.cssText = "display: flex; flex-direction: column; gap: 4px;";
196
- const labelEl = document.createElement("label");
197
- labelEl.textContent = label;
198
- labelEl.style.cssText = "font-size: 12px; color: #64748b; font-weight: 500;";
199
- const input = document.createElement("input");
200
- input.type = "text";
201
- input.value = value;
202
- input.placeholder = label;
203
- input.style.cssText = `
204
- padding: 8px 12px;
205
- border: 1px solid #e2e8f0;
206
- border-radius: 6px;
207
- font-size: 14px;
208
- outline: none;
209
- transition: border-color 0.2s;
210
- `;
211
- input.addEventListener("focus", () => {
212
- input.style.borderColor = "#3b82f6";
213
- });
214
- input.addEventListener("blur", () => {
215
- input.style.borderColor = "#e2e8f0";
216
- });
217
- input.addEventListener("input", (e) => {
218
- onChange(e.target.value);
219
- });
220
- container.appendChild(labelEl);
221
- container.appendChild(input);
222
- return container;
223
- }
224
- /**
225
- * Creates style select dropdown
226
- * @param {Function} onChange - Change handler
227
- * @returns {HTMLElement} Select container
228
- */
229
- _createStyleSelect(onChange) {
230
- const container = document.createElement("div");
231
- container.style.cssText = "display: flex; flex-direction: column; gap: 4px;";
232
- const label = document.createElement("label");
233
- label.textContent = "Button Style";
234
- label.style.cssText = "font-size: 12px; color: #64748b; font-weight: 500;";
235
- const select = document.createElement("select");
236
- select.style.cssText = `
237
- padding: 8px 12px;
238
- border: 1px solid #e2e8f0;
239
- border-radius: 6px;
240
- font-size: 14px;
241
- outline: none;
242
- cursor: pointer;
243
- background: white;
244
- `;
245
- const options = [
246
- { value: "primary", label: "Primary (Blue)" },
247
- { value: "secondary", label: "Secondary (Gray)" },
248
- { value: "outline", label: "Outline" },
249
- { value: "success", label: "Success (Green)" },
250
- { value: "danger", label: "Danger (Red)" }
251
- ];
252
- options.forEach((opt) => {
253
- const option = document.createElement("option");
254
- option.value = opt.value;
255
- option.textContent = opt.label;
256
- option.selected = this.data.style === opt.value;
257
- select.appendChild(option);
258
- });
259
- select.addEventListener("change", (e) => {
260
- onChange(e.target.value);
261
- });
262
- container.appendChild(label);
263
- container.appendChild(select);
264
- return container;
265
- }
266
- /**
267
- * Creates checkbox with label
268
- * @param {string} label - Checkbox label
269
- * @param {boolean} checked - Initial state
270
- * @param {Function} onChange - Change handler
271
- * @returns {HTMLElement} Checkbox container
272
- */
273
- _createCheckbox(label, checked, onChange) {
274
- const container = document.createElement("div");
275
- container.style.cssText = "display: flex; align-items: center; gap: 8px; margin-top: 4px;";
276
- const checkbox = document.createElement("input");
277
- checkbox.type = "checkbox";
278
- checkbox.checked = checked;
279
- checkbox.style.cssText = "width: 16px; height: 16px; cursor: pointer;";
280
- checkbox.addEventListener("change", (e) => {
281
- onChange(e.target.checked);
282
- });
283
- const labelEl = document.createElement("label");
284
- labelEl.textContent = label;
285
- labelEl.style.cssText = "font-size: 14px; color: #334155; cursor: pointer;";
286
- labelEl.addEventListener("click", () => {
287
- checkbox.checked = !checkbox.checked;
288
- onChange(checkbox.checked);
289
- });
290
- container.appendChild(checkbox);
291
- container.appendChild(labelEl);
292
- return container;
293
- }
294
- /**
295
- * Extracts data from the tool
296
- * @returns {object} Saved data
297
- */
298
- save() {
299
- return {
300
- text: this.data.text,
301
- link: this.data.link,
302
- style: this.data.style,
303
- openInNewTab: this.data.openInNewTab
304
- };
305
- }
306
- /**
307
- * Validates block data
308
- * @param {object} savedData - Saved data to validate
309
- * @returns {boolean} True if valid
310
- */
311
- validate(savedData) {
312
- return savedData.text && savedData.text.trim().length > 0;
313
- }
314
- }
315
- class HyperlinkTool {
316
- /**
317
- * Creates an instance of HyperlinkTool
318
- * @param {object} params - Constructor params
319
- * @param {object} params.api - Editor.js API
320
- * @param {object} params.config - Tool configuration
321
- */
322
- constructor({ api, config }) {
323
- /**
324
- * Handles clicks outside the popup
325
- * @param {Event} e - Click event
326
- */
327
- __publicField(this, "_handleOutsideClick", (e) => {
328
- if (this.popup && !this.popup.contains(e.target) && !this.button.contains(e.target)) {
329
- this._closePopup();
330
- }
331
- });
332
- this.api = api;
333
- this.config = config || {};
334
- this.defaultTarget = this.config.target || "_blank";
335
- this.defaultRel = this.config.rel || "noopener noreferrer";
336
- this.availableTargets = this.config.availableTargets || ["_blank", "_self", "_parent", "_top"];
337
- this.availableRels = this.config.availableRels || ["nofollow", "noreferrer", "noopener", "sponsored", "ugc"];
338
- this.button = null;
339
- this.popup = null;
340
- this.state = false;
341
- this.selectedRange = null;
342
- this.existingLink = null;
343
- }
344
- /**
345
- * Specifies this is an inline tool
346
- */
347
- static get isInline() {
348
- return true;
349
- }
350
- /**
351
- * CSS class for the tool icon
352
- */
353
- static get CSS() {
354
- return "ce-inline-tool--hyperlink";
355
- }
356
- /**
357
- * Sanitize config for Editor.js
358
- */
359
- static get sanitize() {
360
- return {
361
- a: {
362
- href: true,
363
- target: true,
364
- rel: true
365
- }
366
- };
367
- }
368
- /**
369
- * Renders the toolbar button
370
- * @returns {HTMLElement} Button element
371
- */
372
- render() {
373
- this.button = document.createElement("button");
374
- this.button.type = "button";
375
- this.button.classList.add(this.api.styles.inlineToolButton);
376
- this.button.classList.add(HyperlinkTool.CSS);
377
- this.button.innerHTML = this._getIcon();
378
- return this.button;
379
- }
380
- /**
381
- * Returns the link icon SVG
382
- * @returns {string} SVG icon
383
- */
384
- _getIcon() {
385
- return `<svg width="14" height="10" viewBox="0 0 14 10" xmlns="http://www.w3.org/2000/svg">
386
- <path d="M6 1.25H2.75C1.64543 1.25 0.75 2.14543 0.75 3.25V6.75C0.75 7.85457 1.64543 8.75 2.75 8.75H6" stroke="currentColor" stroke-width="1.5" fill="none"/>
387
- <path d="M8 8.75H11.25C12.3546 8.75 13.25 7.85457 13.25 6.75V3.25C13.25 2.14543 12.3546 1.25 11.25 1.25H8" stroke="currentColor" stroke-width="1.5" fill="none"/>
388
- <path d="M4 5H10" stroke="currentColor" stroke-width="1.5"/>
389
- </svg>`;
390
- }
391
- /**
392
- * Handles click/activation of the tool
393
- * @param {Range} range - Current selection range
394
- */
395
- surround(range) {
396
- if (this.state) {
397
- this._unwrap(range);
398
- } else {
399
- this._showPopup(range);
400
- }
401
- }
402
- /**
403
- * Shows the link input popup
404
- * @param {Range} range - Current selection range
405
- */
406
- _showPopup(range) {
407
- this.selectedRange = range;
408
- const parentAnchor = this.api.selection.findParentTag("A");
409
- this.existingLink = parentAnchor;
410
- this.popup = document.createElement("div");
411
- this.popup.classList.add("ce-inline-tool-hyperlink-popup");
412
- this.popup.style.cssText = `
413
- position: fixed;
414
- background: white;
415
- border: 1px solid #e2e8f0;
416
- border-radius: 12px;
417
- box-shadow: 0 8px 32px rgba(0,0,0,0.15);
418
- padding: 16px;
419
- z-index: 999999;
420
- min-width: 360px;
421
- max-width: 420px;
422
- `;
423
- const urlContainer = this._createInputContainer("URL", "url", parentAnchor?.href || "");
424
- const targetContainer = this._createSelectContainer(
425
- "Target",
426
- "target",
427
- this.availableTargets.map((t) => ({ value: t, label: t })),
428
- parentAnchor?.target || this.defaultTarget
429
- );
430
- const relContainer = this._createRelContainer(parentAnchor?.rel || this.defaultRel);
431
- const buttonsContainer = document.createElement("div");
432
- buttonsContainer.style.cssText = "display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end;";
433
- const cancelBtn = document.createElement("button");
434
- cancelBtn.type = "button";
435
- cancelBtn.textContent = "Cancel";
436
- cancelBtn.style.cssText = `
437
- padding: 6px 12px;
438
- border: 1px solid #e2e8f0;
439
- border-radius: 6px;
440
- background: white;
441
- cursor: pointer;
442
- font-size: 13px;
443
- `;
444
- cancelBtn.addEventListener("click", () => this._closePopup());
445
- const saveBtn = document.createElement("button");
446
- saveBtn.type = "button";
447
- saveBtn.textContent = parentAnchor ? "Update" : "Add Link";
448
- saveBtn.style.cssText = `
449
- padding: 6px 12px;
450
- border: none;
451
- border-radius: 6px;
452
- background: #3b82f6;
453
- color: white;
454
- cursor: pointer;
455
- font-size: 13px;
456
- font-weight: 500;
457
- `;
458
- saveBtn.addEventListener("click", () => this._saveLink());
459
- if (parentAnchor) {
460
- const removeBtn = document.createElement("button");
461
- removeBtn.type = "button";
462
- removeBtn.textContent = "Remove";
463
- removeBtn.style.cssText = `
464
- padding: 6px 12px;
465
- border: 1px solid #ef4444;
466
- border-radius: 6px;
467
- background: white;
468
- color: #ef4444;
469
- cursor: pointer;
470
- font-size: 13px;
471
- `;
472
- removeBtn.addEventListener("click", () => {
473
- this._unwrap(range);
474
- this._closePopup();
475
- });
476
- buttonsContainer.appendChild(removeBtn);
477
- }
478
- buttonsContainer.appendChild(cancelBtn);
479
- buttonsContainer.appendChild(saveBtn);
480
- this.popup.appendChild(urlContainer);
481
- this.popup.appendChild(targetContainer);
482
- this.popup.appendChild(relContainer);
483
- this.popup.appendChild(buttonsContainer);
484
- document.body.appendChild(this.popup);
485
- this._positionPopup();
486
- setTimeout(() => {
487
- const urlInput = this.popup.querySelector('input[name="url"]');
488
- if (urlInput) urlInput.focus();
489
- }, 50);
490
- setTimeout(() => {
491
- document.addEventListener("click", this._handleOutsideClick);
492
- }, 100);
493
- }
494
- /**
495
- * Creates an input container
496
- * @param {string} label - Input label
497
- * @param {string} name - Input name
498
- * @param {string} value - Initial value
499
- * @returns {HTMLElement} Input container
500
- */
501
- _createInputContainer(label, name, value) {
502
- const container = document.createElement("div");
503
- container.style.cssText = "margin-bottom: 10px;";
504
- const labelEl = document.createElement("label");
505
- labelEl.textContent = label;
506
- labelEl.style.cssText = "display: block; font-size: 12px; color: #64748b; margin-bottom: 4px; font-weight: 500;";
507
- const input = document.createElement("input");
508
- input.type = "text";
509
- input.name = name;
510
- input.value = value;
511
- input.placeholder = "https://example.com";
512
- input.style.cssText = `
513
- width: 100%;
514
- padding: 8px 10px;
515
- border: 1px solid #e2e8f0;
516
- border-radius: 6px;
517
- font-size: 14px;
518
- outline: none;
519
- box-sizing: border-box;
520
- `;
521
- input.addEventListener("focus", () => {
522
- input.style.borderColor = "#3b82f6";
523
- });
524
- input.addEventListener("blur", () => {
525
- input.style.borderColor = "#e2e8f0";
526
- });
527
- container.appendChild(labelEl);
528
- container.appendChild(input);
529
- return container;
530
- }
531
- /**
532
- * Creates a select container
533
- * @param {string} label - Select label
534
- * @param {string} name - Select name
535
- * @param {Array} options - Select options
536
- * @param {string} value - Initial value
537
- * @returns {HTMLElement} Select container
538
- */
539
- _createSelectContainer(label, name, options, value) {
540
- const container = document.createElement("div");
541
- container.style.cssText = "margin-bottom: 10px;";
542
- const labelEl = document.createElement("label");
543
- labelEl.textContent = label;
544
- labelEl.style.cssText = "display: block; font-size: 12px; color: #64748b; margin-bottom: 4px; font-weight: 500;";
545
- const select = document.createElement("select");
546
- select.name = name;
547
- select.style.cssText = `
548
- width: 100%;
549
- padding: 8px 10px;
550
- border: 1px solid #e2e8f0;
551
- border-radius: 6px;
552
- font-size: 14px;
553
- outline: none;
554
- background: white;
555
- cursor: pointer;
556
- box-sizing: border-box;
557
- `;
558
- options.forEach((opt) => {
559
- const option = document.createElement("option");
560
- option.value = opt.value;
561
- option.textContent = opt.label;
562
- option.selected = value === opt.value;
563
- select.appendChild(option);
564
- });
565
- container.appendChild(labelEl);
566
- container.appendChild(select);
567
- return container;
568
- }
569
- /**
570
- * Creates rel attribute checkboxes
571
- * @param {string} currentRel - Current rel value
572
- * @returns {HTMLElement} Rel container
573
- */
574
- _createRelContainer(currentRel) {
575
- const container = document.createElement("div");
576
- container.style.cssText = "margin-bottom: 8px;";
577
- const label = document.createElement("label");
578
- label.textContent = "Rel Attributes";
579
- label.style.cssText = "display: block; font-size: 12px; color: #64748b; margin-bottom: 6px; font-weight: 500;";
580
- container.appendChild(label);
581
- const checkboxContainer = document.createElement("div");
582
- checkboxContainer.style.cssText = "display: flex; flex-wrap: wrap; gap: 12px;";
583
- const currentRels = currentRel ? currentRel.split(" ") : [];
584
- this.availableRels.forEach((rel) => {
585
- const wrapper = document.createElement("label");
586
- wrapper.style.cssText = "display: flex; align-items: center; gap: 4px; cursor: pointer; font-size: 13px;";
587
- const checkbox = document.createElement("input");
588
- checkbox.type = "checkbox";
589
- checkbox.name = "rel";
590
- checkbox.value = rel;
591
- checkbox.checked = currentRels.includes(rel);
592
- checkbox.style.cssText = "cursor: pointer;";
593
- wrapper.appendChild(checkbox);
594
- wrapper.appendChild(document.createTextNode(rel));
595
- checkboxContainer.appendChild(wrapper);
596
- });
597
- container.appendChild(checkboxContainer);
598
- return container;
599
- }
600
- /**
601
- * Positions the popup centered on screen
602
- */
603
- _positionPopup() {
604
- if (!this.popup) return;
605
- const popupRect = this.popup.getBoundingClientRect();
606
- const left = (window.innerWidth - popupRect.width) / 2;
607
- const top = (window.innerHeight - popupRect.height) / 2;
608
- this.popup.style.left = `${Math.max(10, left)}px`;
609
- this.popup.style.top = `${Math.max(10, top)}px`;
610
- }
611
- /**
612
- * Saves the link with user-entered values
613
- */
614
- _saveLink() {
615
- if (!this.popup) return;
616
- const urlInput = this.popup.querySelector('input[name="url"]');
617
- const targetSelect = this.popup.querySelector('select[name="target"]');
618
- const relCheckboxes = this.popup.querySelectorAll('input[name="rel"]:checked');
619
- const url = urlInput?.value?.trim();
620
- if (!url) {
621
- urlInput.style.borderColor = "#ef4444";
622
- return;
623
- }
624
- const target = targetSelect?.value || this.defaultTarget;
625
- const rel = Array.from(relCheckboxes).map((cb) => cb.value).join(" ") || this.defaultRel;
626
- this._closePopup();
627
- if (this.selectedRange) {
628
- const selection = window.getSelection();
629
- selection.removeAllRanges();
630
- selection.addRange(this.selectedRange);
631
- }
632
- if (this.existingLink) {
633
- this.existingLink.href = url;
634
- this.existingLink.target = target;
635
- this.existingLink.rel = rel;
636
- } else {
637
- this._wrap(url, target, rel);
638
- }
639
- }
640
- /**
641
- * Wraps selection in anchor tag
642
- * @param {string} href - Link URL
643
- * @param {string} target - Link target
644
- * @param {string} rel - Link rel
645
- */
646
- _wrap(href, target, rel) {
647
- const selection = window.getSelection();
648
- if (!selection.rangeCount) return;
649
- const range = selection.getRangeAt(0);
650
- const selectedText = range.extractContents();
651
- const anchor = document.createElement("a");
652
- anchor.href = href;
653
- anchor.target = target;
654
- anchor.rel = rel;
655
- anchor.appendChild(selectedText);
656
- range.insertNode(anchor);
657
- selection.removeAllRanges();
658
- const newRange = document.createRange();
659
- newRange.selectNode(anchor);
660
- selection.addRange(newRange);
661
- }
662
- /**
663
- * Unwraps anchor tag from selection
664
- * @param {Range} range - Selection range
665
- */
666
- _unwrap(range) {
667
- const anchor = this.api.selection.findParentTag("A");
668
- if (!anchor) return;
669
- const text = anchor.textContent;
670
- const textNode = document.createTextNode(text);
671
- anchor.parentNode.replaceChild(textNode, anchor);
672
- const selection = window.getSelection();
673
- selection.removeAllRanges();
674
- const newRange = document.createRange();
675
- newRange.selectNode(textNode);
676
- selection.addRange(newRange);
677
- }
678
- /**
679
- * Closes the popup
680
- */
681
- _closePopup() {
682
- if (this.popup) {
683
- this.popup.remove();
684
- this.popup = null;
685
- }
686
- document.removeEventListener("click", this._handleOutsideClick);
687
- }
688
- /**
689
- * Checks if current selection is inside a link
690
- * @param {Selection} selection - Current selection
691
- * @returns {boolean} True if inside link
692
- */
693
- checkState(selection) {
694
- const anchor = this.api.selection.findParentTag("A");
695
- this.state = !!anchor;
696
- this.button.classList.toggle(this.api.styles.inlineToolButtonActive, this.state);
697
- return this.state;
698
- }
699
- /**
700
- * Shortcut key
701
- */
702
- get shortcut() {
703
- return this.config.shortcut || "CMD+K";
704
- }
705
- /**
706
- * Clean up on destroy
707
- */
708
- destroy() {
709
- this._closePopup();
710
- }
711
- }
712
- const API_BASE_URL = "https://magicapi.fitlex.me/api/magic-editor";
713
- class MagicEditorAPI {
714
- constructor(licenseKey) {
715
- this.licenseKey = licenseKey;
716
- this.baseUrl = API_BASE_URL;
717
- }
718
- async request(endpoint, options = {}) {
719
- if (!this.licenseKey) {
720
- throw new Error("No license key available");
721
- }
722
- let url = `${this.baseUrl}${endpoint}`;
723
- if (!options.method || options.method === "GET") {
724
- const separator = url.includes("?") ? "&" : "?";
725
- url = `${url}${separator}licenseKey=${encodeURIComponent(this.licenseKey)}`;
726
- }
727
- const response = await fetch(url, {
728
- ...options,
729
- headers: {
730
- "Content-Type": "application/json",
731
- ...options.headers
732
- }
733
- });
734
- const data = await response.json();
735
- if (!response.ok) {
736
- const error = new Error(data.error?.message || "API request failed");
737
- error.code = data.error?.code;
738
- error.status = response.status;
739
- error.upgrade = data.upgrade;
740
- throw error;
741
- }
742
- return data;
743
- }
744
- /**
745
- * Perform text correction/transformation
746
- * All AI actions go through this endpoint with different types
747
- * @param {string} text - Text to process
748
- * @param {string} type - Type: 'grammar' | 'style' | 'rewrite' | 'expand' | 'summarize' | 'continue' | 'translate'
749
- * @param {object} options - Additional options (tone, language, etc.)
750
- * @returns {Promise<object>} Result with corrected text
751
- */
752
- async correct(text, type = "grammar", options = {}) {
753
- return this.request("/correct", {
754
- method: "POST",
755
- body: JSON.stringify({ text, type, options, licenseKey: this.licenseKey })
756
- });
757
- }
758
- async getUsage() {
759
- return this.request("/usage");
760
- }
761
- async getCredits() {
762
- return this.request("/credits");
763
- }
764
- async getModels() {
765
- return this.request("/models");
766
- }
767
- async getLimits() {
768
- return this.request("/limits");
769
- }
770
- }
771
- const ToolbarContainer = styled.div`
772
- position: fixed;
773
- background: white;
774
- border: 1px solid #e2e8f0;
775
- border-radius: 8px;
776
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.05);
777
- padding: 4px;
778
- display: flex;
779
- gap: 2px;
780
- z-index: 9999;
781
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
782
- animation: slideUp 0.2s ease-out;
783
-
784
- @keyframes slideUp {
785
- from {
786
- opacity: 0;
787
- transform: translateY(4px);
788
- }
789
- to {
790
- opacity: 1;
791
- transform: translateY(0);
792
- }
793
- }
794
-
795
- &::before {
796
- content: '';
797
- position: absolute;
798
- top: -6px;
799
- left: 50%;
800
- transform: translateX(-50%);
801
- width: 12px;
802
- height: 12px;
803
- background: white;
804
- border-left: 1px solid #e2e8f0;
805
- border-top: 1px solid #e2e8f0;
806
- transform: translateX(-50%) rotate(45deg);
807
- }
808
- `;
809
- const ActionButton = styled.button`
810
- padding: 6px 12px;
811
- display: flex;
812
- align-items: center;
813
- gap: 6px;
814
- font-size: 13px;
815
- font-weight: 500;
816
- border: none;
817
- border-radius: 6px;
818
- background: transparent;
819
- color: #334155;
820
- cursor: pointer;
821
- transition: all 0.15s ease;
822
- white-space: nowrap;
823
- position: relative;
824
-
825
- &:hover:not(:disabled) {
826
- background: #f8fafc;
827
- color: #7C3AED;
828
- }
829
-
830
- &:active:not(:disabled) {
831
- transform: scale(0.98);
832
- }
833
-
834
- &:disabled {
835
- opacity: 0.5;
836
- cursor: not-allowed;
837
- }
838
-
839
- svg {
840
- width: 16px;
841
- height: 16px;
842
- flex-shrink: 0;
843
- }
844
- `;
845
- const Divider = styled.div`
846
- width: 1px;
847
- height: 24px;
848
- background: #e2e8f0;
849
- margin: 0 4px;
850
- align-self: center;
851
- `;
852
- const Submenu = styled.div`
853
- position: absolute;
854
- top: 100%;
855
- left: 0;
856
- margin-top: 4px;
857
- background: white;
858
- border: 1px solid #e2e8f0;
859
- border-radius: 8px;
860
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
861
- padding: 4px;
862
- min-width: 160px;
863
- z-index: 10000;
864
- animation: slideDown 0.15s ease-out;
865
-
866
- @keyframes slideDown {
867
- from {
868
- opacity: 0;
869
- transform: translateY(-4px);
870
- }
871
- to {
872
- opacity: 1;
873
- transform: translateY(0);
874
- }
875
- }
876
- `;
877
- const SubmenuItem = styled.button`
878
- width: 100%;
879
- padding: 8px 12px;
880
- display: flex;
881
- align-items: center;
882
- gap: 8px;
883
- font-size: 13px;
884
- border: none;
885
- border-radius: 4px;
886
- background: transparent;
887
- color: #334155;
888
- cursor: pointer;
889
- text-align: left;
890
- transition: all 0.1s ease;
891
-
892
- &:hover {
893
- background: #f8fafc;
894
- color: #7C3AED;
895
- }
896
-
897
- svg {
898
- width: 14px;
899
- height: 14px;
900
- }
901
- `;
902
- const LoadingSpinner = styled.div`
903
- width: 14px;
904
- height: 14px;
905
- border: 2px solid #e2e8f0;
906
- border-top-color: #7C3AED;
907
- border-radius: 50%;
908
- animation: spin 0.8s linear infinite;
909
-
910
- @keyframes spin {
911
- to { transform: rotate(360deg); }
912
- }
913
- `;
914
- const AIInlineToolbar = ({
915
- position,
916
- onAction,
917
- loading = false,
918
- disabled = false,
919
- onClose
920
- }) => {
921
- const [activeSubmenu, setActiveSubmenu] = useState(null);
922
- const toolbarRef = useRef(null);
923
- useEffect(() => {
924
- const handleClickOutside = (e) => {
925
- if (toolbarRef.current && !toolbarRef.current.contains(e.target)) {
926
- onClose?.();
927
- }
928
- };
929
- const handleEscape = (e) => {
930
- if (e.key === "Escape") {
931
- onClose?.();
932
- }
933
- };
934
- document.addEventListener("mousedown", handleClickOutside);
935
- document.addEventListener("keydown", handleEscape);
936
- return () => {
937
- document.removeEventListener("mousedown", handleClickOutside);
938
- document.removeEventListener("keydown", handleEscape);
939
- };
940
- }, [onClose]);
941
- const handleAction = (action, options = {}) => {
942
- setActiveSubmenu(null);
943
- onAction?.(action, options);
944
- };
945
- const toggleSubmenu = (menu) => {
946
- setActiveSubmenu(activeSubmenu === menu ? null : menu);
947
- };
948
- return /* @__PURE__ */ jsxs(
949
- ToolbarContainer,
950
- {
951
- ref: toolbarRef,
952
- style: {
953
- left: `${position.left}px`,
954
- top: `${position.top}px`
955
- },
956
- children: [
957
- /* @__PURE__ */ jsxs(
958
- ActionButton,
959
- {
960
- onClick: () => handleAction("fix"),
961
- disabled: disabled || loading,
962
- title: "Fix grammar and spelling",
963
- children: [
964
- loading ? /* @__PURE__ */ jsx(LoadingSpinner, {}) : /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("polyline", { points: "20 6 9 17 4 12" }) }),
965
- /* @__PURE__ */ jsx("span", { children: "Fix" })
966
- ]
967
- }
968
- ),
969
- /* @__PURE__ */ jsxs(
970
- ActionButton,
971
- {
972
- onClick: () => toggleSubmenu("rewrite"),
973
- disabled: disabled || loading,
974
- title: "Rewrite text with different style",
975
- style: { position: "relative" },
976
- children: [
977
- /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { d: "M12 3l1.912 5.813a2 2 0 001.275 1.275L21 12l-5.813 1.912a2 2 0 00-1.275 1.275L12 21l-1.912-5.813a2 2 0 00-1.275-1.275L3 12l5.813-1.912a2 2 0 001.275-1.275L12 3z" }) }),
978
- /* @__PURE__ */ jsx("span", { children: "Rewrite" }),
979
- /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { width: "12px", height: "12px" }, children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" }) }),
980
- activeSubmenu === "rewrite" && /* @__PURE__ */ jsxs(Submenu, { children: [
981
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("rewrite", { tone: "professional" }), children: [
982
- /* @__PURE__ */ jsx("span", { children: "💼" }),
983
- /* @__PURE__ */ jsx("span", { children: "Professional" })
984
- ] }),
985
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("rewrite", { tone: "casual" }), children: [
986
- /* @__PURE__ */ jsx("span", { children: "😊" }),
987
- /* @__PURE__ */ jsx("span", { children: "Casual" })
988
- ] }),
989
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("rewrite", { tone: "friendly" }), children: [
990
- /* @__PURE__ */ jsx("span", { children: "👋" }),
991
- /* @__PURE__ */ jsx("span", { children: "Friendly" })
992
- ] })
993
- ] })
994
- ]
995
- }
996
- ),
997
- /* @__PURE__ */ jsx(Divider, {}),
998
- /* @__PURE__ */ jsxs(
999
- ActionButton,
1000
- {
1001
- onClick: () => handleAction("expand"),
1002
- disabled: disabled || loading,
1003
- title: "Make text longer and more detailed",
1004
- children: [
1005
- /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1006
- /* @__PURE__ */ jsx("polyline", { points: "7 13 12 18 17 13" }),
1007
- /* @__PURE__ */ jsx("polyline", { points: "7 6 12 11 17 6" })
1008
- ] }),
1009
- /* @__PURE__ */ jsx("span", { children: "Expand" })
1010
- ]
1011
- }
1012
- ),
1013
- /* @__PURE__ */ jsxs(
1014
- ActionButton,
1015
- {
1016
- onClick: () => handleAction("summarize"),
1017
- disabled: disabled || loading,
1018
- title: "Make text shorter and concise",
1019
- children: [
1020
- /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1021
- /* @__PURE__ */ jsx("polyline", { points: "17 11 12 6 7 11" }),
1022
- /* @__PURE__ */ jsx("polyline", { points: "17 18 12 13 7 18" })
1023
- ] }),
1024
- /* @__PURE__ */ jsx("span", { children: "Shorten" })
1025
- ]
1026
- }
1027
- ),
1028
- /* @__PURE__ */ jsx(Divider, {}),
1029
- /* @__PURE__ */ jsxs(
1030
- ActionButton,
1031
- {
1032
- onClick: () => handleAction("continue"),
1033
- disabled: disabled || loading,
1034
- title: "Continue writing from here",
1035
- children: [
1036
- /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M5 12l7 7 7-7" }) }),
1037
- /* @__PURE__ */ jsx("span", { children: "Continue" })
1038
- ]
1039
- }
1040
- ),
1041
- /* @__PURE__ */ jsxs(
1042
- ActionButton,
1043
- {
1044
- onClick: () => toggleSubmenu("translate"),
1045
- disabled: disabled || loading,
1046
- title: "Translate to another language",
1047
- style: { position: "relative" },
1048
- children: [
1049
- /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { d: "M5 8l6 6M4 14l6-6 2-3M2 5h12M7 2h1M22 22l-5-10-5 10M14.5 17h6" }) }),
1050
- /* @__PURE__ */ jsx("span", { children: "Translate" }),
1051
- /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", style: { width: "12px", height: "12px" }, children: /* @__PURE__ */ jsx("polyline", { points: "6 9 12 15 18 9" }) }),
1052
- activeSubmenu === "translate" && /* @__PURE__ */ jsxs(Submenu, { children: [
1053
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("translate", { language: "en" }), children: [
1054
- /* @__PURE__ */ jsx("span", { children: "🇬🇧" }),
1055
- /* @__PURE__ */ jsx("span", { children: "English" })
1056
- ] }),
1057
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("translate", { language: "de" }), children: [
1058
- /* @__PURE__ */ jsx("span", { children: "🇩🇪" }),
1059
- /* @__PURE__ */ jsx("span", { children: "German" })
1060
- ] }),
1061
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("translate", { language: "fr" }), children: [
1062
- /* @__PURE__ */ jsx("span", { children: "🇫🇷" }),
1063
- /* @__PURE__ */ jsx("span", { children: "French" })
1064
- ] }),
1065
- /* @__PURE__ */ jsxs(SubmenuItem, { onClick: () => handleAction("translate", { language: "es" }), children: [
1066
- /* @__PURE__ */ jsx("span", { children: "🇪🇸" }),
1067
- /* @__PURE__ */ jsx("span", { children: "Spanish" })
1068
- ] })
1069
- ] })
1070
- ]
1071
- }
1072
- )
1073
- ]
1074
- }
1075
- );
1076
- };
1077
- const slideIn = keyframes`
1078
- from {
1079
- opacity: 0;
1080
- transform: translateY(-20px);
1081
- }
1082
- to {
1083
- opacity: 1;
1084
- transform: translateY(0);
1085
- }
1086
- `;
1087
- const slideOut = keyframes`
1088
- from {
1089
- opacity: 1;
1090
- transform: translateY(0);
1091
- }
1092
- to {
1093
- opacity: 0;
1094
- transform: translateY(-20px);
1095
- }
1096
- `;
1097
- const ToastContainer = styled.div`
1098
- position: fixed;
1099
- top: 20px;
1100
- right: 20px;
1101
- z-index: 99999;
1102
- display: flex;
1103
- flex-direction: column;
1104
- gap: 10px;
1105
- pointer-events: none;
1106
- `;
1107
- const ToastItem = styled.div`
1108
- display: flex;
1109
- align-items: center;
1110
- gap: 12px;
1111
- padding: 12px 16px;
1112
- background: white;
1113
- border: 1px solid #e2e8f0;
1114
- border-radius: 8px;
1115
- box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
1116
- font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
1117
- font-size: 14px;
1118
- color: #334155;
1119
- min-width: 280px;
1120
- max-width: 400px;
1121
- pointer-events: auto;
1122
- animation: ${(props) => props.$closing ? slideOut : slideIn} 0.3s ease-out;
1123
-
1124
- &.success {
1125
- border-left: 3px solid #10b981;
1126
- }
1127
-
1128
- &.error {
1129
- border-left: 3px solid #ef4444;
1130
- }
1131
-
1132
- &.info {
1133
- border-left: 3px solid #3b82f6;
1134
- }
1135
-
1136
- &.warning {
1137
- border-left: 3px solid #f59e0b;
1138
- }
1139
- `;
1140
- const Icon = styled.div`
1141
- flex-shrink: 0;
1142
- width: 20px;
1143
- height: 20px;
1144
- display: flex;
1145
- align-items: center;
1146
- justify-content: center;
1147
- font-size: 16px;
1148
- `;
1149
- const Message = styled.div`
1150
- flex: 1;
1151
- line-height: 1.4;
1152
-
1153
- strong {
1154
- font-weight: 600;
1155
- display: block;
1156
- margin-bottom: 2px;
1157
- }
1158
-
1159
- span {
1160
- font-size: 13px;
1161
- color: #64748b;
1162
- }
1163
- `;
1164
- const CloseButton = styled.button`
1165
- flex-shrink: 0;
1166
- width: 20px;
1167
- height: 20px;
1168
- display: flex;
1169
- align-items: center;
1170
- justify-content: center;
1171
- border: none;
1172
- background: transparent;
1173
- color: #94a3b8;
1174
- cursor: pointer;
1175
- border-radius: 4px;
1176
- transition: all 0.15s ease;
1177
-
1178
- &:hover {
1179
- background: #f1f5f9;
1180
- color: #334155;
1181
- }
1182
-
1183
- svg {
1184
- width: 14px;
1185
- height: 14px;
1186
- }
1187
- `;
1188
- const UndoButton = styled.button`
1189
- flex-shrink: 0;
1190
- padding: 4px 10px;
1191
- font-size: 12px;
1192
- font-weight: 500;
1193
- border: 1px solid #e2e8f0;
1194
- background: white;
1195
- color: #7C3AED;
1196
- border-radius: 4px;
1197
- cursor: pointer;
1198
- transition: all 0.15s ease;
1199
-
1200
- &:hover {
1201
- background: #f5f3ff;
1202
- border-color: #7C3AED;
1203
- }
1204
-
1205
- &:active {
1206
- transform: scale(0.98);
1207
- }
1208
- `;
1209
- class ToastManager {
1210
- constructor() {
1211
- this.toasts = [];
1212
- this.listeners = [];
1213
- }
1214
- subscribe(listener) {
1215
- this.listeners.push(listener);
1216
- return () => {
1217
- this.listeners = this.listeners.filter((l) => l !== listener);
1218
- };
1219
- }
1220
- notify() {
1221
- this.listeners.forEach((listener) => listener(this.toasts));
1222
- }
1223
- show(options) {
1224
- const id = Date.now() + Math.random();
1225
- const toast = {
1226
- id,
1227
- type: options.type || "info",
1228
- icon: options.icon,
1229
- message: options.message,
1230
- description: options.description,
1231
- duration: options.duration || 3e3,
1232
- onUndo: options.onUndo,
1233
- closeable: options.closeable !== false
1234
- };
1235
- this.toasts.push(toast);
1236
- this.notify();
1237
- if (toast.duration > 0) {
1238
- setTimeout(() => {
1239
- this.remove(id);
1240
- }, toast.duration);
1241
- }
1242
- return id;
1243
- }
1244
- remove(id) {
1245
- this.toasts = this.toasts.filter((t) => t.id !== id);
1246
- this.notify();
1247
- }
1248
- success(message, options = {}) {
1249
- return this.show({
1250
- type: "success",
1251
- icon: "✓",
1252
- message,
1253
- ...options
1254
- });
1255
- }
1256
- error(message, options = {}) {
1257
- return this.show({
1258
- type: "error",
1259
- icon: "✕",
1260
- message,
1261
- ...options
1262
- });
1263
- }
1264
- info(message, options = {}) {
1265
- return this.show({
1266
- type: "info",
1267
- icon: "ℹ",
1268
- message,
1269
- ...options
1270
- });
1271
- }
1272
- warning(message, options = {}) {
1273
- return this.show({
1274
- type: "warning",
1275
- icon: "⚠",
1276
- message,
1277
- ...options
1278
- });
1279
- }
1280
- }
1281
- const toastManager = new ToastManager();
1282
- const Toast = ({ toast, onClose }) => {
1283
- const [closing, setClosing] = useState(false);
1284
- const handleClose = () => {
1285
- setClosing(true);
1286
- setTimeout(() => {
1287
- onClose();
1288
- }, 300);
1289
- };
1290
- const handleUndo = () => {
1291
- toast.onUndo?.();
1292
- handleClose();
1293
- };
1294
- return /* @__PURE__ */ jsxs(ToastItem, { className: toast.type, $closing: closing, children: [
1295
- toast.icon && /* @__PURE__ */ jsx(Icon, { children: toast.icon }),
1296
- /* @__PURE__ */ jsx(Message, { children: typeof toast.message === "string" ? toast.message : /* @__PURE__ */ jsxs(Fragment, { children: [
1297
- /* @__PURE__ */ jsx("strong", { children: toast.message }),
1298
- toast.description && /* @__PURE__ */ jsx("span", { children: toast.description })
1299
- ] }) }),
1300
- toast.onUndo && /* @__PURE__ */ jsx(UndoButton, { onClick: handleUndo, children: "Undo" }),
1301
- toast.closeable && /* @__PURE__ */ jsx(CloseButton, { onClick: handleClose, children: /* @__PURE__ */ jsxs("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
1302
- /* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1303
- /* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1304
- ] }) })
1305
- ] });
1306
- };
1307
- const AIToast = () => {
1308
- const [toasts, setToasts] = useState([]);
1309
- useEffect(() => {
1310
- const unsubscribe = toastManager.subscribe(setToasts);
1311
- return unsubscribe;
1312
- }, []);
1313
- if (toasts.length === 0) {
1314
- return null;
1315
- }
1316
- return /* @__PURE__ */ jsx(ToastContainer, { children: toasts.map((toast) => /* @__PURE__ */ jsx(
1317
- Toast,
1318
- {
1319
- toast,
1320
- onClose: () => toastManager.remove(toast.id)
1321
- },
1322
- toast.id
1323
- )) });
1324
- };
1325
- class AIAssistantTool {
1326
- static get isInline() {
1327
- return true;
1328
- }
1329
- static get CSS() {
1330
- return "ce-inline-tool--ai-assistant";
1331
- }
1332
- static get sanitize() {
1333
- return {
1334
- span: {
1335
- class: "ai-suggestion",
1336
- "data-original": true,
1337
- "data-corrected": true,
1338
- "data-type": true
1339
- }
1340
- };
1341
- }
1342
- static get title() {
1343
- return "KI-Assistent";
1344
- }
1345
- constructor({ api, config }) {
1346
- this.api = api;
1347
- this.config = config || {};
1348
- this.getLicenseKey = this.config.getLicenseKey || (() => window.__MAGIC_EDITOR_LICENSE_KEY__);
1349
- this.button = null;
1350
- this.toolbar = null;
1351
- this.toolbarRoot = null;
1352
- this.state = false;
1353
- this.selectedRange = null;
1354
- this.selectedText = "";
1355
- this.currentBlockIndex = null;
1356
- this.apiClient = null;
1357
- this.isLoading = false;
1358
- this.lastAction = null;
1359
- }
1360
- _initAPIClient() {
1361
- const licenseKey = this.getLicenseKey();
1362
- if (licenseKey && !this.apiClient) {
1363
- this.apiClient = new MagicEditorAPI(licenseKey);
1364
- }
1365
- return this.apiClient;
1366
- }
1367
- render() {
1368
- this.button = document.createElement("button");
1369
- this.button.type = "button";
1370
- this.button.classList.add(this.api.styles.inlineToolButton);
1371
- this.button.classList.add(AIAssistantTool.CSS);
1372
- this.button.innerHTML = this._getIcon();
1373
- this.button.title = "KI-Assistent (⌘+Shift+G)";
1374
- return this.button;
1375
- }
1376
- _getIcon() {
1377
- return `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1378
- <path d="M12 3l1.912 5.813a2 2 0 001.275 1.275L21 12l-5.813 1.912a2 2 0 00-1.275 1.275L12 21l-1.912-5.813a2 2 0 00-1.275-1.275L3 12l5.813-1.912a2 2 0 001.275-1.275L12 3z"/>
1379
- <path d="M5 3v4"/>
1380
- <path d="M3 5h4"/>
1381
- <path d="M19 17v4"/>
1382
- <path d="M17 19h4"/>
1383
- </svg>`;
1384
- }
1385
- surround(range) {
1386
- const selection = window.getSelection();
1387
- let text = "";
1388
- if (selection.rangeCount > 0) {
1389
- this.selectedRange = selection.getRangeAt(0).cloneRange();
1390
- text = selection.toString().trim();
1391
- }
1392
- if (!text) {
1393
- const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
1394
- const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
1395
- if (currentBlock) {
1396
- this.currentBlockIndex = currentBlockIndex;
1397
- const blockElement = currentBlock.holder?.querySelector("[contenteditable]") || currentBlock.holder?.querySelector(".ce-paragraph") || currentBlock.holder?.querySelector(".ce-header");
1398
- if (blockElement) {
1399
- text = blockElement.textContent?.trim() || "";
1400
- if (text) {
1401
- const range2 = document.createRange();
1402
- range2.selectNodeContents(blockElement);
1403
- selection.removeAllRanges();
1404
- selection.addRange(range2);
1405
- this.selectedRange = range2.cloneRange();
1406
- }
1407
- }
1408
- }
1409
- }
1410
- this.selectedText = text;
1411
- if (!text) {
1412
- toastManager.warning("Bitte Text auswählen");
1413
- return;
1414
- }
1415
- this._showInlineToolbar();
1416
- }
1417
- async _showInlineToolbar() {
1418
- if (!this._initAPIClient()) {
1419
- toastManager.error("Keine Lizenz verfügbar");
1420
- return;
1421
- }
1422
- if (this.api.inlineToolbar) {
1423
- this.api.inlineToolbar.close();
1424
- }
1425
- const selection = window.getSelection();
1426
- if (!selection.rangeCount) return;
1427
- const rect = selection.getRangeAt(0).getBoundingClientRect();
1428
- const position = {
1429
- left: rect.left + rect.width / 2 - 200,
1430
- // Center toolbar (approximate width)
1431
- top: rect.bottom + 8
1432
- };
1433
- if (position.left < 10) position.left = 10;
1434
- if (position.left + 400 > window.innerWidth - 10) {
1435
- position.left = window.innerWidth - 410;
1436
- }
1437
- this.toolbar = document.createElement("div");
1438
- this.toolbar.classList.add("ai-inline-toolbar-container");
1439
- document.body.appendChild(this.toolbar);
1440
- this.toolbarRoot = createRoot(this.toolbar);
1441
- this.toolbarRoot.render(
1442
- s__default.createElement(AIInlineToolbar, {
1443
- position,
1444
- onAction: this._handleAction.bind(this),
1445
- loading: this.isLoading,
1446
- onClose: this._closeToolbar.bind(this)
1447
- })
1448
- );
1449
- }
1450
- async _handleAction(action, options = {}) {
1451
- if (!this.apiClient || !this.selectedText) return;
1452
- this.isLoading = true;
1453
- this._updateToolbar();
1454
- try {
1455
- let result;
1456
- let originalText = this.selectedText;
1457
- switch (action) {
1458
- case "fix":
1459
- result = await this.apiClient.correct(this.selectedText, "grammar");
1460
- if (result.data.hasChanges) {
1461
- this._replaceText(result.data.corrected);
1462
- toastManager.success(`✓ ${result.data.changes.length} Korrekturen angewendet`, {
1463
- description: `${result.usage?.remaining || 0} Credits übrig`,
1464
- onUndo: () => this._replaceText(originalText),
1465
- duration: 5e3
1466
- });
1467
- } else {
1468
- toastManager.info("Text ist bereits korrekt");
1469
- }
1470
- break;
1471
- case "rewrite":
1472
- result = await this.apiClient.rewrite(this.selectedText, options);
1473
- if (result.data.rewritten) {
1474
- this._replaceText(result.data.rewritten);
1475
- toastManager.success(`✨ Text umgeschrieben (${options.tone || "standard"})`, {
1476
- onUndo: () => this._replaceText(originalText),
1477
- duration: 5e3
1478
- });
1479
- }
1480
- break;
1481
- case "expand":
1482
- result = await this.apiClient.expand(this.selectedText);
1483
- if (result.data.expanded) {
1484
- this._replaceText(result.data.expanded);
1485
- toastManager.success("📈 Text erweitert", {
1486
- onUndo: () => this._replaceText(originalText),
1487
- duration: 5e3
1488
- });
1489
- }
1490
- break;
1491
- case "summarize":
1492
- result = await this.apiClient.summarize(this.selectedText);
1493
- if (result.data.summary) {
1494
- this._replaceText(result.data.summary);
1495
- toastManager.success("📉 Text zusammengefasst", {
1496
- onUndo: () => this._replaceText(originalText),
1497
- duration: 5e3
1498
- });
1499
- }
1500
- break;
1501
- case "continue":
1502
- result = await this.apiClient.continueWriting(this.selectedText);
1503
- if (result.data.continuation) {
1504
- this._appendText(" " + result.data.continuation);
1505
- toastManager.success("✍️ Text fortgesetzt", {
1506
- onUndo: () => this._replaceText(originalText),
1507
- duration: 5e3
1508
- });
1509
- }
1510
- break;
1511
- case "translate":
1512
- const langNames = { en: "Englisch", de: "Deutsch", fr: "Französisch", es: "Spanisch" };
1513
- result = await this.apiClient.translate(this.selectedText, options.language);
1514
- if (result.data.translated) {
1515
- this._replaceText(result.data.translated);
1516
- toastManager.success(`🌍 Übersetzt zu ${langNames[options.language] || options.language}`, {
1517
- onUndo: () => this._replaceText(originalText),
1518
- duration: 5e3
1519
- });
1520
- }
1521
- break;
1522
- default:
1523
- console.warn("Unknown action:", action);
1524
- }
1525
- this._closeToolbar();
1526
- } catch (err) {
1527
- console.error("[AI Assistant] Action failed:", err);
1528
- const isLimitError = err.code === "DAILY_LIMIT_EXCEEDED" || err.code === "MONTHLY_LIMIT_EXCEEDED";
1529
- if (isLimitError) {
1530
- toastManager.warning("Limit erreicht", {
1531
- description: err.message,
1532
- duration: 5e3
1533
- });
1534
- } else {
1535
- toastManager.error("Fehler", {
1536
- description: err.message || "Aktion fehlgeschlagen",
1537
- duration: 4e3
1538
- });
1539
- }
1540
- } finally {
1541
- this.isLoading = false;
1542
- this._updateToolbar();
1543
- }
1544
- }
1545
- _replaceText(newText) {
1546
- if (!this.selectedRange) return;
1547
- try {
1548
- const selection = window.getSelection();
1549
- selection.removeAllRanges();
1550
- selection.addRange(this.selectedRange);
1551
- document.execCommand("insertText", false, newText);
1552
- this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex())?.dispatchChange?.();
1553
- } catch (err) {
1554
- console.error("[AI Assistant] Failed to replace text:", err);
1555
- }
1556
- }
1557
- _appendText(additionalText) {
1558
- if (!this.selectedRange) return;
1559
- try {
1560
- const selection = window.getSelection();
1561
- const range = this.selectedRange.cloneRange();
1562
- range.collapse(false);
1563
- selection.removeAllRanges();
1564
- selection.addRange(range);
1565
- document.execCommand("insertText", false, additionalText);
1566
- this.api.blocks.getBlockByIndex(this.api.blocks.getCurrentBlockIndex())?.dispatchChange?.();
1567
- } catch (err) {
1568
- console.error("[AI Assistant] Failed to append text:", err);
1569
- }
1570
- }
1571
- _updateToolbar() {
1572
- if (this.toolbarRoot && this.toolbar) {
1573
- const selection = window.getSelection();
1574
- const rect = selection.rangeCount > 0 ? selection.getRangeAt(0).getBoundingClientRect() : { left: 0, bottom: 0, width: 0 };
1575
- const position = {
1576
- left: rect.left + rect.width / 2 - 200,
1577
- top: rect.bottom + 8
1578
- };
1579
- this.toolbarRoot.render(
1580
- s__default.createElement(AIInlineToolbar, {
1581
- position,
1582
- onAction: this._handleAction.bind(this),
1583
- loading: this.isLoading,
1584
- onClose: this._closeToolbar.bind(this)
1585
- })
1586
- );
1587
- }
1588
- }
1589
- _closeToolbar() {
1590
- if (this.toolbarRoot) {
1591
- this.toolbarRoot.unmount();
1592
- this.toolbarRoot = null;
1593
- }
1594
- if (this.toolbar) {
1595
- this.toolbar.remove();
1596
- this.toolbar = null;
1597
- }
1598
- this.isLoading = false;
1599
- this.selectedRange = null;
1600
- this.selectedText = "";
1601
- this.currentBlockIndex = null;
1602
- }
1603
- checkState(selection) {
1604
- this.state = selection && !selection.isCollapsed;
1605
- return this.state;
1606
- }
1607
- get shortcut() {
1608
- return "CMD+SHIFT+G";
1609
- }
1610
- destroy() {
1611
- this._closeToolbar();
1612
- }
1613
- }
1614
- class MediaLibAdapter {
1615
- /**
1616
- * Toolbox configuration
1617
- */
1618
- static get toolbox() {
1619
- return {
1620
- title: "Image (Media Library)",
1621
- icon: `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="15" viewBox="0 0 336 276">
1622
- <path d="M291 150.242V79c0-18.778-15.222-34-34-34H79c-18.778 0-34 15.222-34 34v42.264l67.179-44.192 80.398 71.614 56.686-29.14L291 150.242zm-.345 51.622l-42.3-30.246-56.3 29.884-80.773-66.925L45 174.187V197c0 18.778 15.222 34 34 34h178c17.126 0 31.295-12.663 33.655-29.136zM79 0h178c43.63 0 79 35.37 79 79v118c0 43.63-35.37 79-79 79H79c-43.63 0-79-35.37-79-79V79C0 35.37 35.37 0 79 0z"/>
1623
- </svg>`
1624
- };
1625
- }
1626
- /**
1627
- * Tool is not inline
1628
- */
1629
- static get isInline() {
1630
- return false;
1631
- }
1632
- /**
1633
- * Constructor
1634
- * @param {object} params - Tool parameters
1635
- * @param {object} params.api - EditorJS API
1636
- * @param {object} params.config - Tool config
1637
- * @param {object} params.data - Block data (when restoring from saved state)
1638
- */
1639
- constructor({ api, config, data }) {
1640
- this.api = api;
1641
- this.config = config || {};
1642
- this.data = data || {};
1643
- this._isRestore = !!(data && data.type === "mediaLibraryStrapi");
1644
- }
1645
- /**
1646
- * Render tool
1647
- * Opens Media Library dialog only when user clicks the toolbox
1648
- */
1649
- render() {
1650
- const wrapper = document.createElement("div");
1651
- wrapper.classList.add("media-lib-placeholder");
1652
- if (!this._isRestore) {
1653
- const currentIndex = this.api.blocks.getCurrentBlockIndex();
1654
- if (this.config.mediaLibToggleFunc) {
1655
- setTimeout(() => {
1656
- this.config.mediaLibToggleFunc(currentIndex);
1657
- }, 50);
1658
- }
1659
- wrapper.innerHTML = '<p style="color: #7C3AED; text-align: center; padding: 20px; font-size: 14px;">📷 Media Library wird geöffnet...</p>';
1660
- } else {
1661
- wrapper.innerHTML = '<p style="color: #999; text-align: center; padding: 10px; font-size: 12px;">⚠️ Ungültiger Block wird entfernt...</p>';
1662
- setTimeout(() => {
1663
- try {
1664
- const currentIndex = this.api.blocks.getCurrentBlockIndex();
1665
- this.api.blocks.delete(currentIndex);
1666
- } catch (e) {
1667
- console.warn("[Magic Editor X] Could not auto-delete mediaLib block:", e);
1668
- }
1669
- }, 100);
1670
- }
1671
- return wrapper;
1672
- }
1673
- /**
1674
- * Save data
1675
- * Returns undefined to prevent saving this placeholder block
1676
- */
1677
- save() {
1678
- return void 0;
1679
- }
1680
- /**
1681
- * Validate saved data
1682
- * Always return false so this block type is never persisted
1683
- */
1684
- validate(savedData) {
1685
- return false;
1686
- }
1687
- /**
1688
- * Sanitizer config
1689
- */
1690
- static get sanitize() {
1691
- return {
1692
- type: false
1693
- };
1694
- }
1695
- }
1696
- // Track if we're currently opening from user action vs restore
1697
- __publicField(MediaLibAdapter, "_isUserAction", false);
1698
- class BoldInlineTool {
1699
- static get isInline() {
1700
- return true;
1701
- }
1702
- static get title() {
1703
- return "Bold";
1704
- }
1705
- static get sanitize() {
1706
- return {
1707
- b: {},
1708
- strong: {}
1709
- };
1710
- }
1711
- constructor({ api }) {
1712
- this.api = api;
1713
- this.button = null;
1714
- this._state = false;
1715
- }
1716
- render() {
1717
- this.button = document.createElement("button");
1718
- this.button.type = "button";
1719
- this.button.innerHTML = '<svg width="12" height="14" xmlns="http://www.w3.org/2000/svg"><path d="M5.997 14H1.72c-.618 0-1.058-.138-1.323-.415C.132 13.308 0 12.924 0 12.435V1.565C0 1.076.132.692.397.415.662.138 1.102 0 1.72 0h4.418c.862 0 1.592.175 2.189.526.597.35 1.047.818 1.35 1.403.302.585.454 1.236.454 1.952 0 .603-.13 1.144-.388 1.624-.26.48-.617.871-1.072 1.174.659.225 1.182.608 1.57 1.147.388.54.583 1.173.583 1.9 0 .792-.19 1.496-.57 2.111-.38.616-.91 1.1-1.592 1.451-.682.352-1.465.527-2.35.527H6zm-.02-8.393h2.341c.444 0 .804-.13 1.08-.39.278-.26.416-.618.416-1.072 0-.467-.152-.838-.457-1.114-.305-.276-.677-.414-1.115-.414H5.977v2.99zm0 6.182h2.593c.478 0 .862-.152 1.152-.456.29-.305.436-.69.436-1.155 0-.467-.152-.858-.456-1.172-.304-.315-.709-.472-1.214-.472H5.977v3.255z" fill="currentColor"/></svg>';
1720
- this.button.classList.add("ce-inline-tool");
1721
- return this.button;
1722
- }
1723
- surround(range) {
1724
- document.execCommand("bold");
1725
- }
1726
- checkState() {
1727
- const isActive = document.queryCommandState("bold");
1728
- this.button.classList.toggle("ce-inline-tool--active", isActive);
1729
- return isActive;
1730
- }
1731
- get shortcut() {
1732
- return "CMD+B";
1733
- }
1734
- }
1735
- class ItalicInlineTool {
1736
- static get isInline() {
1737
- return true;
1738
- }
1739
- static get title() {
1740
- return "Italic";
1741
- }
1742
- static get sanitize() {
1743
- return {
1744
- i: {},
1745
- em: {}
1746
- };
1747
- }
1748
- constructor({ api }) {
1749
- this.api = api;
1750
- this.button = null;
1751
- this._state = false;
1752
- }
1753
- render() {
1754
- this.button = document.createElement("button");
1755
- this.button.type = "button";
1756
- this.button.innerHTML = '<svg width="6" height="14" xmlns="http://www.w3.org/2000/svg"><path d="M3.289 14L4.867 3.286H3.267L3.496 1.59h4.555L8 0H1.49l-.498 1.59h1.594L.844 12.304H.265L0 14h3.289z" fill="currentColor"/></svg>';
1757
- this.button.classList.add("ce-inline-tool");
1758
- return this.button;
1759
- }
1760
- surround(range) {
1761
- document.execCommand("italic");
1762
- }
1763
- checkState() {
1764
- const isActive = document.queryCommandState("italic");
1765
- this.button.classList.toggle("ce-inline-tool--active", isActive);
1766
- return isActive;
1767
- }
1768
- get shortcut() {
1769
- return "CMD+I";
1770
- }
1771
- }
1772
- Personality.isReadOnlySupported = true;
1773
- MediaLibAdapter.isReadOnlySupported = true;
1774
- ButtonTool.isReadOnlySupported = true;
1775
- const getAuthToken = () => {
1776
- try {
1777
- const token = sessionStorage.getItem("jwtToken");
1778
- if (token) {
1779
- return JSON.parse(token);
1780
- }
1781
- const localToken = localStorage.getItem("jwtToken");
1782
- if (localToken) {
1783
- return JSON.parse(localToken);
1784
- }
1785
- return null;
1786
- } catch (e) {
1787
- console.warn("[Magic Editor X] Could not get auth token:", e);
1788
- return null;
1789
- }
1790
- };
1791
- const getTools = ({ mediaLibToggleFunc, pluginId, openLinkPicker, customBlocks = [] }) => {
1792
- const token = getAuthToken();
1793
- const authHeader = token ? `Bearer ${token}` : "";
1794
- const tools = {
1795
- // ============================================
1796
- // OFFICIAL BLOCK TOOLS (16 Tools)
1797
- // ============================================
1798
- /**
1799
- * Header Tool
1800
- * @see https://github.com/editor-js/header
1801
- */
1802
- header: {
1803
- class: Header,
1804
- inlineToolbar: ["bold", "italic", "marker", "inlineCode", "underline", "strikethrough"],
1805
- tunes: ["alignmentTune"],
1806
- config: {
1807
- placeholder: "Enter a heading",
1808
- levels: [1, 2, 3, 4, 5, 6],
1809
- defaultLevel: 2
1810
- },
1811
- shortcut: "CMD+SHIFT+H"
1812
- },
1813
- /**
1814
- * Paragraph Tool (default)
1815
- * @see https://github.com/editor-js/paragraph
1816
- */
1817
- paragraph: {
1818
- class: Paragraph,
1819
- inlineToolbar: ["bold", "italic", "marker", "inlineCode", "underline", "strikethrough", "hyperlink"],
1820
- tunes: ["alignmentTune", "indentTune"],
1821
- config: {
1822
- placeholder: "Start writing or press Tab to add a block...",
1823
- preserveBlank: true
1824
- }
1825
- },
1826
- /**
1827
- * Nested List Tool
1828
- * @see https://github.com/editor-js/nested-list
1829
- */
1830
- list: {
1831
- class: NestedList,
1832
- inlineToolbar: ["bold", "italic", "marker", "inlineCode", "underline", "strikethrough"],
1833
- tunes: ["indentTune"],
1834
- config: {
1835
- defaultStyle: "unordered"
1836
- },
1837
- shortcut: "CMD+SHIFT+L"
1838
- },
1839
- /**
1840
- * Checklist Tool
1841
- * @see https://github.com/editor-js/checklist
1842
- */
1843
- checklist: {
1844
- class: Checklist,
1845
- inlineToolbar: true,
1846
- shortcut: "CMD+SHIFT+C"
1847
- },
1848
- /**
1849
- * Quote Tool
1850
- * @see https://github.com/editor-js/quote
1851
- */
1852
- quote: {
1853
- class: Quote,
1854
- inlineToolbar: true,
1855
- tunes: ["alignmentTune"],
1856
- config: {
1857
- quotePlaceholder: "Enter a quote",
1858
- captionPlaceholder: "Quote author"
1859
- },
1860
- shortcut: "CMD+SHIFT+Q"
1861
- },
1862
- /**
1863
- * Warning Tool
1864
- * @see https://github.com/editor-js/warning
1865
- */
1866
- warning: {
1867
- class: Warning,
1868
- inlineToolbar: true,
1869
- config: {
1870
- titlePlaceholder: "Warning title",
1871
- messagePlaceholder: "Warning message"
1872
- },
1873
- shortcut: "CMD+SHIFT+W"
1874
- },
1875
- /**
1876
- * Code Tool (basic)
1877
- * @see https://github.com/editor-js/code
1878
- */
1879
- code: {
1880
- class: Code,
1881
- config: {
1882
- placeholder: "Enter code here..."
1883
- },
1884
- shortcut: "CMD+SHIFT+P"
1885
- },
1886
- /**
1887
- * Delimiter Tool
1888
- * @see https://github.com/editor-js/delimiter
1889
- */
1890
- delimiter: {
1891
- class: Delimiter,
1892
- shortcut: "CMD+SHIFT+D"
1893
- },
1894
- /**
1895
- * Table Tool
1896
- * @see https://github.com/editor-js/table
1897
- */
1898
- table: {
1899
- class: Table,
1900
- inlineToolbar: true,
1901
- config: {
1902
- rows: 2,
1903
- cols: 3,
1904
- withHeadings: true
1905
- },
1906
- shortcut: "CMD+SHIFT+T"
1907
- },
1908
- /**
1909
- * Embed Tool
1910
- * @see https://github.com/editor-js/embed
1911
- */
1912
- embed: {
1913
- class: Embed,
1914
- config: {
1915
- services: {
1916
- youtube: true,
1917
- vimeo: true,
1918
- twitter: true,
1919
- instagram: true,
1920
- codepen: true,
1921
- codesandbox: true,
1922
- github: true,
1923
- gfycat: true,
1924
- imgur: true,
1925
- pinterest: true,
1926
- twitch: true,
1927
- miro: true,
1928
- figma: true,
1929
- aparat: true,
1930
- facebook: true
1931
- }
1932
- }
1933
- },
1934
- /**
1935
- * Raw HTML Tool
1936
- * @see https://github.com/editor-js/raw
1937
- */
1938
- raw: {
1939
- class: Raw,
1940
- config: {
1941
- placeholder: "Enter raw HTML..."
1942
- }
1943
- },
1944
- /**
1945
- * Link Tool
1946
- * @see https://github.com/editor-js/link
1947
- */
1948
- linkTool: {
1949
- class: LinkTool,
1950
- config: {
1951
- endpoint: `/${pluginId}/link`,
1952
- headers: {
1953
- Authorization: authHeader
1954
- }
1955
- }
1956
- },
1957
- /**
1958
- * Image Tool (with Upload)
1959
- * @see https://github.com/editor-js/image
1960
- */
1961
- image: {
1962
- class: Image,
1963
- config: {
1964
- field: "files.image",
1965
- additionalRequestData: {
1966
- data: JSON.stringify({})
1967
- },
1968
- additionalRequestHeaders: {
1969
- Authorization: authHeader
1970
- },
1971
- endpoints: {
1972
- byUrl: `/${pluginId}/image/byUrl`
1973
- },
1974
- uploader: {
1975
- async uploadByFile(file) {
1976
- const formData = new FormData();
1977
- formData.append("data", JSON.stringify({}));
1978
- formData.append("files.image", file);
1979
- try {
1980
- const response = await fetch(`/${pluginId}/image/byFile`, {
1981
- method: "POST",
1982
- headers: {
1983
- Authorization: authHeader
1984
- },
1985
- body: formData
1986
- });
1987
- return await response.json();
1988
- } catch (error) {
1989
- console.error("[Magic Editor X] Upload error:", error);
1990
- return { success: 0, message: error.message };
1991
- }
1992
- }
1993
- },
1994
- captionPlaceholder: "Image caption",
1995
- buttonContent: "Select image"
1996
- }
1997
- },
1998
- /**
1999
- * Simple Image Tool (URL only)
2000
- * @see https://github.com/editor-js/simple-image
2001
- */
2002
- simpleImage: {
2003
- class: SimpleImage
2004
- },
2005
- /**
2006
- * Attaches Tool
2007
- * @see https://github.com/editor-js/attaches
2008
- */
2009
- attaches: {
2010
- class: Attaches,
2011
- config: {
2012
- endpoint: `/${pluginId}/file/upload`,
2013
- field: "file",
2014
- types: "application/pdf,text/plain,text/csv,application/json,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/zip,audio/mpeg,audio/wav,audio/ogg,video/mp4,video/webm,image/jpeg,image/png,image/gif,image/webp",
2015
- buttonText: "Select file to upload",
2016
- errorMessage: "File upload failed",
2017
- additionalRequestHeaders: {
2018
- Authorization: authHeader
2019
- }
2020
- }
2021
- },
2022
- /**
2023
- * Personality Tool
2024
- * @see https://github.com/editor-js/personality
2025
- */
2026
- personality: {
2027
- class: Personality,
2028
- config: {
2029
- endpoint: `/${pluginId}/image/byFile`,
2030
- field: "files.image",
2031
- additionalRequestHeaders: {
2032
- Authorization: authHeader
2033
- },
2034
- namePlaceholder: "Name",
2035
- descriptionPlaceholder: "Description / Title",
2036
- linkPlaceholder: "Link (optional)"
2037
- }
2038
- },
2039
- /**
2040
- * Media Library Tool (Custom)
2041
- * Strapi Media Library integration
2042
- */
2043
- mediaLib: {
2044
- class: MediaLibAdapter,
2045
- config: {
2046
- mediaLibToggleFunc
2047
- }
2048
- },
2049
- // ============================================
2050
- // COMMUNITY BLOCK TOOLS (4 Tools)
2051
- // ============================================
2052
- /**
2053
- * Alert Tool
2054
- * @see https://github.com/vishaltelangre/editorjs-alert
2055
- * Colorful alert boxes (info, success, warning, danger)
2056
- */
2057
- alert: {
2058
- class: Alert,
2059
- inlineToolbar: true,
2060
- config: {
2061
- defaultType: "info",
2062
- messagePlaceholder: "Enter your message..."
2063
- },
2064
- shortcut: "CMD+SHIFT+A"
2065
- },
2066
- /**
2067
- * Toggle Block Tool
2068
- * @see https://github.com/kommitters/editorjs-toggle-block
2069
- * Collapsible/expandable content blocks (FAQ, Accordions)
2070
- */
2071
- toggle: {
2072
- class: ToggleBlock,
2073
- inlineToolbar: true,
2074
- config: {
2075
- placeholder: "Toggle title",
2076
- defaultContent: "Toggle content..."
2077
- }
2078
- },
2079
- /**
2080
- * CodeFlask Tool (with Syntax Highlighting)
2081
- * @see https://github.com/calumk/editorjs-codeflask
2082
- * Code blocks with syntax highlighting
2083
- */
2084
- codeFlask: {
2085
- class: CodeFlask,
2086
- config: {
2087
- language: "javascript"
2088
- }
2089
- },
2090
- /**
2091
- * Button Tool (Custom Implementation)
2092
- * CTA buttons with customizable text, link, and style
2093
- * Secure implementation without eval()
2094
- */
2095
- button: {
2096
- class: ButtonTool,
2097
- inlineToolbar: false
2098
- },
2099
- // ============================================
2100
- // CORE INLINE TOOLS (Bold & Italic)
2101
- // These are essential for basic text formatting
2102
- // ============================================
2103
- /**
2104
- * Bold Tool (Custom Implementation)
2105
- * Essential inline formatting tool
2106
- */
2107
- bold: {
2108
- class: BoldInlineTool,
2109
- shortcut: "CMD+B"
2110
- },
2111
- /**
2112
- * Italic Tool (Custom Implementation)
2113
- * Essential inline formatting tool
2114
- */
2115
- italic: {
2116
- class: ItalicInlineTool,
2117
- shortcut: "CMD+I"
2118
- },
2119
- // ============================================
2120
- // OFFICIAL INLINE TOOLS (3 Tools)
2121
- // ============================================
2122
- /**
2123
- * Marker (Highlight) Tool
2124
- * @see https://github.com/editor-js/marker
2125
- */
2126
- marker: {
2127
- class: Marker,
2128
- shortcut: "CMD+SHIFT+M"
2129
- },
2130
- /**
2131
- * Inline Code Tool
2132
- * @see https://github.com/editor-js/inline-code
2133
- */
2134
- inlineCode: {
2135
- class: InlineCode,
2136
- shortcut: "CMD+SHIFT+I"
2137
- },
2138
- /**
2139
- * Underline Tool
2140
- * @see https://github.com/editor-js/underline
2141
- */
2142
- underline: {
2143
- class: Underline,
2144
- shortcut: "CMD+U"
2145
- },
2146
- // ============================================
2147
- // COMMUNITY INLINE TOOLS (3 Tools)
2148
- // ============================================
2149
- /**
2150
- * Strikethrough Tool
2151
- * @see https://github.com/nicosrm/strikethrough
2152
- */
2153
- strikethrough: {
2154
- class: Strikethrough,
2155
- shortcut: "CMD+SHIFT+S"
2156
- },
2157
- /**
2158
- * Tooltip Tool
2159
- * @see https://github.com/kommitters/editorjs-tooltip
2160
- * Add tooltips to text
2161
- */
2162
- tooltip: {
2163
- class: Tooltip,
2164
- config: {
2165
- location: "top",
2166
- highlightColor: "#FFEFD5",
2167
- underline: true,
2168
- backgroundColor: "#1e293b",
2169
- textColor: "#ffffff"
2170
- }
2171
- },
2172
- /**
2173
- * Hyperlink Tool (Custom Implementation)
2174
- * Links with target and rel attributes
2175
- * Secure implementation without eval()
2176
- */
2177
- hyperlink: {
2178
- class: HyperlinkTool,
2179
- config: {
2180
- shortcut: "CMD+K",
2181
- target: "_blank",
2182
- rel: "noopener noreferrer",
2183
- availableTargets: ["_blank", "_self", "_parent", "_top"],
2184
- availableRels: ["nofollow", "noreferrer", "noopener", "sponsored", "ugc"]
2185
- }
2186
- },
2187
- /**
2188
- * AI Assistant Tool (Custom Implementation)
2189
- * AI-powered text corrections (grammar, style, rewrite)
2190
- */
2191
- aiAssistant: {
2192
- class: AIAssistantTool,
2193
- config: {
2194
- apiBaseUrl: "https://magicapi.fitlex.me/api/magic-editor",
2195
- getLicenseKey: () => window.__MAGIC_EDITOR_LICENSE_KEY__
2196
- },
2197
- shortcut: "CMD+SHIFT+G"
2198
- },
2199
- // Note: Webtools Link integration is handled via toolbar button in EditorJS component
2200
- // The inline tool was removed as redundant - toolbar button works better
2201
- // ============================================
2202
- // TUNES (3 Tunes)
2203
- // ============================================
2204
- /**
2205
- * Text Variant Tune
2206
- * @see https://github.com/editor-js/text-variant-tune
2207
- */
2208
- textVariant: TextVariantTune,
2209
- /**
2210
- * Alignment Tune
2211
- * @see https://github.com/kaaaaaaaaaaai/editorjs-alignment-blocktune
2212
- * Text alignment (left, center, right, justify)
2213
- */
2214
- alignmentTune: {
2215
- class: AlignmentTune,
2216
- config: {
2217
- default: "left",
2218
- blocks: {
2219
- header: "center"
2220
- }
2221
- }
2222
- },
2223
- /**
2224
- * Indent Tune
2225
- * @see https://github.com/kommitters/editorjs-indent-tune
2226
- * Block indentation
2227
- */
2228
- indentTune: {
2229
- class: IndentTune,
2230
- config: {
2231
- maxIndent: 5,
2232
- indentSize: 30,
2233
- multiblock: true,
2234
- tuneName: "indentTune"
2235
- }
2236
- }
2237
- };
2238
- if (customBlocks && customBlocks.length > 0) {
2239
- customBlocks.forEach((block) => {
2240
- if (block && block.name && block.class) {
2241
- tools[block.name] = {
2242
- class: block.class,
2243
- config: block.config || {},
2244
- inlineToolbar: block.inlineToolbar !== void 0 ? block.inlineToolbar : true,
2245
- tunes: block.tunes || [],
2246
- shortcut: block.shortcut || null
2247
- };
2248
- console.log(`[Magic Editor X] Registered custom block: ${block.name}`);
2249
- }
2250
- });
2251
- }
2252
- return tools;
2253
- };
2254
- const initUndoRedo = (editor) => {
2255
- return new Undo({ editor });
2256
- };
2257
- const initDragDrop = (editor) => {
2258
- return new DragDrop(editor);
2259
- };
2260
- export {
2261
- AIToast as A,
2262
- MagicEditorAPI as M,
2263
- initDragDrop as a,
2264
- AIInlineToolbar as b,
2265
- getTools as g,
2266
- initUndoRedo as i,
2267
- toastManager as t
2268
- };