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