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