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