nextgen-block-editor 0.3.0 → 0.4.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.
- package/dist/index.cjs +2549 -819
- package/dist/index.d.cts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +2536 -808
- package/dist/styles.css +895 -178
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/components/BlockEditor.tsx
|
|
2
|
-
import
|
|
2
|
+
import React5, { useEffect as useEffect2, useImperativeHandle, useRef as useRef2, useState as useState4 } from "react";
|
|
3
3
|
import EditorJS2 from "@editorjs/editorjs";
|
|
4
4
|
import DragDrop from "editorjs-drag-drop";
|
|
5
5
|
import Undo from "editorjs-undo";
|
|
@@ -9,7 +9,6 @@ import EditorJS from "@editorjs/editorjs";
|
|
|
9
9
|
import Header from "@editorjs/header";
|
|
10
10
|
import List from "@editorjs/list";
|
|
11
11
|
import NestedList from "@editorjs/nested-list";
|
|
12
|
-
import Checklist from "@editorjs/checklist";
|
|
13
12
|
import Table from "@editorjs/table";
|
|
14
13
|
import Quote from "@editorjs/quote";
|
|
15
14
|
import InlineCode from "@editorjs/inline-code";
|
|
@@ -253,7 +252,7 @@ function sanitizeInlineHtml(value) {
|
|
|
253
252
|
element.replaceWith(document.createTextNode(element.textContent || ""));
|
|
254
253
|
return;
|
|
255
254
|
}
|
|
256
|
-
if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler")) {
|
|
255
|
+
if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler") && !element.classList.contains("ng-inline-color")) {
|
|
257
256
|
element.replaceWith(document.createTextNode(element.textContent || ""));
|
|
258
257
|
return;
|
|
259
258
|
}
|
|
@@ -262,7 +261,10 @@ function sanitizeInlineHtml(value) {
|
|
|
262
261
|
if (element.tagName === "A" && attribute.name === "class" && attribute.value === "editor-mention") {
|
|
263
262
|
return;
|
|
264
263
|
}
|
|
265
|
-
if (element.tagName === "SPAN" && attribute.name === "class" && attribute.value === "editor-inline-spoiler") {
|
|
264
|
+
if (element.tagName === "SPAN" && attribute.name === "class" && (attribute.value === "editor-inline-spoiler" || attribute.value === "ng-inline-color")) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (element.tagName === "SPAN" && element.classList.contains("ng-inline-color") && attribute.name === "style") {
|
|
266
268
|
return;
|
|
267
269
|
}
|
|
268
270
|
if (["target", "rel"].includes(attribute.name) && element.tagName === "A") return;
|
|
@@ -546,9 +548,12 @@ function blocksToHtml(data) {
|
|
|
546
548
|
}).join("") + "</div>";
|
|
547
549
|
}
|
|
548
550
|
if (block.type === "embed") {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
551
|
+
if (!d.embed) return "";
|
|
552
|
+
const align = ["left", "center", "right"].includes(d.align) ? d.align : "center";
|
|
553
|
+
const size = ["small", "medium", "large", "full"].includes(d.size) ? d.size : "medium";
|
|
554
|
+
return `<div class="editor-embed-wrap" data-align="${align}" data-size="${size}"><iframe src="${escHtml(
|
|
555
|
+
d.embed
|
|
556
|
+
)}" title="${escHtml(d.caption)}" loading="lazy" allowfullscreen></iframe></div>`;
|
|
552
557
|
}
|
|
553
558
|
if (block.type === "attaches") {
|
|
554
559
|
const attachmentUrl = d.file && d.file.url ? d.file.url : d.dataUrl || "";
|
|
@@ -598,6 +603,85 @@ function blocksToHtml(data) {
|
|
|
598
603
|
d.text || ""
|
|
599
604
|
)}</div></div>${overlay}</div>`;
|
|
600
605
|
}
|
|
606
|
+
if (block.type === "mermaid") {
|
|
607
|
+
const code = String(d.code || "");
|
|
608
|
+
const caption = d.caption ? `<figcaption>${escHtml(d.caption)}</figcaption>` : "";
|
|
609
|
+
return `<figure class="editor-mermaid-block"><div class="editor-mermaid-diagram" data-mermaid="${escHtml(
|
|
610
|
+
code
|
|
611
|
+
)}"><pre class="editor-mermaid-fallback">${escHtml(code)}</pre></div>${caption}</figure>`;
|
|
612
|
+
}
|
|
613
|
+
if (block.type === "bookmark") {
|
|
614
|
+
const url = String(d.url || "#");
|
|
615
|
+
let host = url;
|
|
616
|
+
try {
|
|
617
|
+
host = new URL(url).hostname;
|
|
618
|
+
} catch {
|
|
619
|
+
}
|
|
620
|
+
return `<a class="editor-bookmark-card" href="${escHtml(
|
|
621
|
+
url
|
|
622
|
+
)}" target="_blank" rel="noopener noreferrer"><div class="editor-bookmark-body"><div class="editor-bookmark-title">${escHtml(
|
|
623
|
+
d.title || host
|
|
624
|
+
)}</div>${d.description ? `<div class="editor-bookmark-desc">${escHtml(d.description)}</div>` : ""}<div class="editor-bookmark-url">${escHtml(host)}</div></div>${d.image ? `<img class="editor-bookmark-thumb" src="${escHtml(d.image)}" alt="" loading="lazy">` : ""}</a>`;
|
|
625
|
+
}
|
|
626
|
+
if (block.type === "steps") {
|
|
627
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
628
|
+
return `<ol class="editor-steps-list">${items.map(
|
|
629
|
+
(item, idx) => `<li class="editor-step-item"><div class="editor-step-badge">${idx + 1}</div><div class="editor-step-content"><h4>${escHtml(
|
|
630
|
+
item.title || `Step ${idx + 1}`
|
|
631
|
+
)}</h4><p>${escHtml(item.body || "")}</p></div></li>`
|
|
632
|
+
).join("")}</ol>`;
|
|
633
|
+
}
|
|
634
|
+
if (block.type === "diff") {
|
|
635
|
+
const before = String(d.before || "").split("\n");
|
|
636
|
+
const after = String(d.after || "").split("\n");
|
|
637
|
+
const max = Math.max(before.length, after.length);
|
|
638
|
+
const rows = [];
|
|
639
|
+
for (let i = 0; i < max; i += 1) {
|
|
640
|
+
if (before[i] === after[i]) {
|
|
641
|
+
if (before[i] !== void 0) {
|
|
642
|
+
rows.push(`<span class="editor-diff-line is-same"> ${escHtml(before[i])}</span>`);
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
if (before[i] !== void 0) {
|
|
646
|
+
rows.push(`<span class="editor-diff-line is-del">- ${escHtml(before[i])}</span>`);
|
|
647
|
+
}
|
|
648
|
+
if (after[i] !== void 0) {
|
|
649
|
+
rows.push(`<span class="editor-diff-line is-add">+ ${escHtml(after[i])}</span>`);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return `<div class="editor-diff-block">${d.filename ? `<div class="editor-diff-filename">${escHtml(d.filename)}</div>` : ""}<pre class="editor-diff-preview">${rows.join("\n")}</pre></div>`;
|
|
654
|
+
}
|
|
655
|
+
if (block.type === "video") {
|
|
656
|
+
if (!d.url) return "";
|
|
657
|
+
return `<figure class="editor-video-block"><video controls preload="metadata" class="editor-video-el"${d.poster ? ` poster="${escHtml(d.poster)}"` : ""}><source src="${escHtml(d.url)}"></video>${d.caption ? `<figcaption>${escHtml(d.caption)}</figcaption>` : ""}</figure>`;
|
|
658
|
+
}
|
|
659
|
+
if (block.type === "changelog") {
|
|
660
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
661
|
+
return `<section class="editor-changelog-block"><div class="editor-changelog-head"><span class="editor-changelog-version">${escHtml(
|
|
662
|
+
d.version || "v1.0.0"
|
|
663
|
+
)}</span><span class="editor-changelog-date">${escHtml(
|
|
664
|
+
d.date || ""
|
|
665
|
+
)}</span></div><ul class="editor-changelog-list">${items.map(
|
|
666
|
+
(i) => `<li><span class="editor-changelog-badge is-${escHtml(
|
|
667
|
+
i.kind || "added"
|
|
668
|
+
)}">${escHtml((i.kind || "added").toUpperCase())}</span><span>${escHtml(
|
|
669
|
+
i.text || ""
|
|
670
|
+
)}</span></li>`
|
|
671
|
+
).join("")}</ul></section>`;
|
|
672
|
+
}
|
|
673
|
+
if (block.type === "today") {
|
|
674
|
+
return `<div class="editor-today-pill"><span class="editor-today-badge">\u{1F4C5} ${escHtml(
|
|
675
|
+
d.date || ""
|
|
676
|
+
)}</span></div>`;
|
|
677
|
+
}
|
|
678
|
+
if (block.type === "social") {
|
|
679
|
+
return `<blockquote class="editor-social-card"><div class="editor-social-head"><strong>${escHtml(
|
|
680
|
+
d.author || ""
|
|
681
|
+
)}</strong><span>${escHtml(d.handle || "")}</span>${d.date ? `<span>\xB7 ${escHtml(d.date)}</span>` : ""}</div><p class="editor-social-text">${escHtml(d.text || "")}</p>${d.url ? `<a class="editor-social-link" href="${escHtml(
|
|
682
|
+
d.url
|
|
683
|
+
)}" target="_blank" rel="noopener noreferrer">View original post \u2192</a>` : ""}</blockquote>`;
|
|
684
|
+
}
|
|
601
685
|
if (block.type === "alert") {
|
|
602
686
|
const variant = ["info", "tip", "warning", "danger"].includes(d.variant) ? d.variant : "info";
|
|
603
687
|
const icons = {
|
|
@@ -1688,22 +1772,25 @@ function attachEmojiSidePicker(container) {
|
|
|
1688
1772
|
const triggerRange = document.createRange();
|
|
1689
1773
|
triggerRange.setStart(textNode, triggerStart);
|
|
1690
1774
|
triggerRange.setEnd(textNode, offset);
|
|
1691
|
-
const
|
|
1775
|
+
const rawRect = triggerRange.getBoundingClientRect();
|
|
1776
|
+
const rect = rawRect.width > 0 || rawRect.height > 0 ? rawRect : target.getBoundingClientRect();
|
|
1692
1777
|
openEmojiSideMenu({
|
|
1693
1778
|
anchorRect: rect,
|
|
1694
1779
|
onSelect: (emoji) => {
|
|
1695
|
-
if (
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1780
|
+
if (textNode.isConnected) {
|
|
1781
|
+
const current = textNode.data;
|
|
1782
|
+
textNode.data = current.slice(0, triggerStart) + emoji + current.slice(offset);
|
|
1783
|
+
const nextCaret = triggerStart + emoji.length;
|
|
1784
|
+
const newRange = document.createRange();
|
|
1785
|
+
newRange.setStart(textNode, nextCaret);
|
|
1786
|
+
newRange.setEnd(textNode, nextCaret);
|
|
1787
|
+
const s = window.getSelection();
|
|
1788
|
+
if (s) {
|
|
1789
|
+
s.removeAllRanges();
|
|
1790
|
+
s.addRange(newRange);
|
|
1791
|
+
}
|
|
1792
|
+
} else if (target.isConnected) {
|
|
1793
|
+
target.innerHTML = target.innerHTML.replace(/\/emoji/i, emoji);
|
|
1707
1794
|
}
|
|
1708
1795
|
target.focus();
|
|
1709
1796
|
target.dispatchEvent(new Event("input", { bubbles: true }));
|
|
@@ -3668,14 +3755,23 @@ function createActionTriggerTool(title, icon, eventName) {
|
|
|
3668
3755
|
}
|
|
3669
3756
|
render() {
|
|
3670
3757
|
const el = document.createElement("div");
|
|
3671
|
-
el.style.
|
|
3758
|
+
el.style.height = "1px";
|
|
3759
|
+
el.style.opacity = "0";
|
|
3760
|
+
el.style.pointerEvents = "none";
|
|
3672
3761
|
this.el = el;
|
|
3673
3762
|
return el;
|
|
3674
3763
|
}
|
|
3675
3764
|
rendered() {
|
|
3676
3765
|
if (this.fired || !this.el) return;
|
|
3677
3766
|
this.fired = true;
|
|
3678
|
-
this.el.
|
|
3767
|
+
const contentEl = this.el.closest(".ce-block__content") || this.el.closest(".ce-block") || this.el;
|
|
3768
|
+
const blockRect = contentEl.getBoundingClientRect();
|
|
3769
|
+
this.el.dispatchEvent(
|
|
3770
|
+
new CustomEvent(eventName, {
|
|
3771
|
+
bubbles: true,
|
|
3772
|
+
detail: { rect: blockRect }
|
|
3773
|
+
})
|
|
3774
|
+
);
|
|
3679
3775
|
window.setTimeout(() => {
|
|
3680
3776
|
try {
|
|
3681
3777
|
const idx = this.api.blocks.getCurrentBlockIndex();
|
|
@@ -4073,12 +4169,17 @@ var EmojiTool = class {
|
|
|
4073
4169
|
anchorRect: rect,
|
|
4074
4170
|
onSelect: (em) => {
|
|
4075
4171
|
if (this.isNewInsert && this.api?.blocks) {
|
|
4076
|
-
const
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4172
|
+
const blockEl = this.anchorEl?.closest(".ce-block");
|
|
4173
|
+
const parent = blockEl?.parentElement;
|
|
4174
|
+
const domIdx = blockEl && parent ? Array.from(parent.children).indexOf(blockEl) : -1;
|
|
4175
|
+
const idx = domIdx >= 0 ? domIdx : this.api.blocks.getCurrentBlockIndex();
|
|
4176
|
+
if (idx >= 0) {
|
|
4177
|
+
this.api.blocks.insert("paragraph", { text: `${em} ` }, {}, idx + 1, true);
|
|
4178
|
+
this.api.blocks.delete(idx);
|
|
4179
|
+
window.requestAnimationFrame(() => {
|
|
4180
|
+
this.api?.caret?.setToBlock(idx, "end");
|
|
4181
|
+
});
|
|
4182
|
+
}
|
|
4082
4183
|
return;
|
|
4083
4184
|
}
|
|
4084
4185
|
this.data.emoji = em;
|
|
@@ -4102,7 +4203,7 @@ var EmojiTool = class {
|
|
|
4102
4203
|
}
|
|
4103
4204
|
rendered() {
|
|
4104
4205
|
if (this.isNewInsert) {
|
|
4105
|
-
|
|
4206
|
+
window.requestAnimationFrame(() => this.openPickerAtAnchor());
|
|
4106
4207
|
}
|
|
4107
4208
|
}
|
|
4108
4209
|
save() {
|
|
@@ -4113,83 +4214,11 @@ var EmojiTool = class {
|
|
|
4113
4214
|
};
|
|
4114
4215
|
}
|
|
4115
4216
|
};
|
|
4116
|
-
var ScratchTool =
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"/></svg>'
|
|
4122
|
-
};
|
|
4123
|
-
}
|
|
4124
|
-
constructor({ data }) {
|
|
4125
|
-
this.data = {
|
|
4126
|
-
title: data?.title ?? "Scratchpad",
|
|
4127
|
-
text: data?.text ?? ""
|
|
4128
|
-
};
|
|
4129
|
-
}
|
|
4130
|
-
render() {
|
|
4131
|
-
const wrap = document.createElement("div");
|
|
4132
|
-
wrap.className = "editor-scratch-tool";
|
|
4133
|
-
const head = document.createElement("div");
|
|
4134
|
-
head.className = "editor-scratch-head";
|
|
4135
|
-
const titleIn = document.createElement("input");
|
|
4136
|
-
titleIn.type = "text";
|
|
4137
|
-
titleIn.className = "cdx-input editor-scratch-title";
|
|
4138
|
-
titleIn.placeholder = "Scratchpad title...";
|
|
4139
|
-
titleIn.value = this.data.title ?? "Scratchpad";
|
|
4140
|
-
titleIn.addEventListener("input", () => {
|
|
4141
|
-
this.data.title = titleIn.value;
|
|
4142
|
-
});
|
|
4143
|
-
const stats = document.createElement("span");
|
|
4144
|
-
stats.className = "editor-scratch-stats";
|
|
4145
|
-
const updateStats = () => {
|
|
4146
|
-
const len = this.data.text.length;
|
|
4147
|
-
const words = this.data.text.trim() ? this.data.text.trim().split(/\s+/).length : 0;
|
|
4148
|
-
stats.textContent = `${words}w \xB7 ${len}c`;
|
|
4149
|
-
};
|
|
4150
|
-
const copyBtn = document.createElement("button");
|
|
4151
|
-
copyBtn.type = "button";
|
|
4152
|
-
copyBtn.className = "b2";
|
|
4153
|
-
copyBtn.textContent = "Copy";
|
|
4154
|
-
copyBtn.addEventListener("click", () => {
|
|
4155
|
-
if (!this.data.text) return;
|
|
4156
|
-
void navigator.clipboard?.writeText(this.data.text);
|
|
4157
|
-
copyBtn.textContent = "Copied";
|
|
4158
|
-
window.setTimeout(() => {
|
|
4159
|
-
copyBtn.textContent = "Copy";
|
|
4160
|
-
}, 1200);
|
|
4161
|
-
});
|
|
4162
|
-
const clearBtn = document.createElement("button");
|
|
4163
|
-
clearBtn.type = "button";
|
|
4164
|
-
clearBtn.className = "b2";
|
|
4165
|
-
clearBtn.textContent = "Clear";
|
|
4166
|
-
head.append(titleIn, stats, copyBtn, clearBtn);
|
|
4167
|
-
const textarea = document.createElement("textarea");
|
|
4168
|
-
textarea.className = "cdx-input editor-scratch-textarea";
|
|
4169
|
-
textarea.rows = 4;
|
|
4170
|
-
textarea.placeholder = "Quick brain dump, rough notes, snippets...";
|
|
4171
|
-
textarea.value = this.data.text || "";
|
|
4172
|
-
textarea.addEventListener("input", () => {
|
|
4173
|
-
this.data.text = textarea.value;
|
|
4174
|
-
updateStats();
|
|
4175
|
-
});
|
|
4176
|
-
clearBtn.addEventListener("click", () => {
|
|
4177
|
-
this.data.text = "";
|
|
4178
|
-
textarea.value = "";
|
|
4179
|
-
updateStats();
|
|
4180
|
-
textarea.focus();
|
|
4181
|
-
});
|
|
4182
|
-
updateStats();
|
|
4183
|
-
wrap.append(head, textarea);
|
|
4184
|
-
return wrap;
|
|
4185
|
-
}
|
|
4186
|
-
save() {
|
|
4187
|
-
return {
|
|
4188
|
-
title: this.data.title?.trim() || "Scratchpad",
|
|
4189
|
-
text: this.data.text
|
|
4190
|
-
};
|
|
4191
|
-
}
|
|
4192
|
-
};
|
|
4217
|
+
var ScratchTool = createActionTriggerTool(
|
|
4218
|
+
"Scratchpad",
|
|
4219
|
+
'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"/></svg>',
|
|
4220
|
+
"nextgen-open-scratch"
|
|
4221
|
+
);
|
|
4193
4222
|
var DialogueTool = class {
|
|
4194
4223
|
data;
|
|
4195
4224
|
static get toolbox() {
|
|
@@ -4899,178 +4928,1196 @@ var TagsTool = class {
|
|
|
4899
4928
|
}
|
|
4900
4929
|
};
|
|
4901
4930
|
|
|
4902
|
-
// src/
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4931
|
+
// src/blocks/mermaidBlock.ts
|
|
4932
|
+
import mermaid from "mermaid";
|
|
4933
|
+
var MERMAID_PRESETS = {
|
|
4934
|
+
Flowchart: `graph TD
|
|
4935
|
+
A[Start] --> B{Condition?}
|
|
4936
|
+
B -->|Yes| C[Proceed]
|
|
4937
|
+
B -->|No| D[Retry]`,
|
|
4938
|
+
Sequence: `sequenceDiagram
|
|
4939
|
+
User->>Editor: Type /mermaid
|
|
4940
|
+
Editor->>Mermaid: Render SVG
|
|
4941
|
+
Mermaid-->>User: Interactive Diagram`,
|
|
4942
|
+
Mindmap: `mindmap
|
|
4943
|
+
root((NextGen Editor))
|
|
4944
|
+
Blocks
|
|
4945
|
+
Mermaid
|
|
4946
|
+
Charts
|
|
4947
|
+
Code
|
|
4948
|
+
AI
|
|
4949
|
+
Rewrite
|
|
4950
|
+
Continue`
|
|
4951
|
+
};
|
|
4952
|
+
var mermaidInitialized = false;
|
|
4953
|
+
var mermaidCounter = 0;
|
|
4954
|
+
function ensureMermaidInit() {
|
|
4955
|
+
if (mermaidInitialized) return;
|
|
4956
|
+
mermaidInitialized = true;
|
|
4957
|
+
mermaid.initialize({
|
|
4958
|
+
startOnLoad: false,
|
|
4959
|
+
securityLevel: "strict",
|
|
4960
|
+
theme: "neutral"
|
|
4961
|
+
});
|
|
4962
|
+
}
|
|
4963
|
+
async function renderMermaidInto(container, code) {
|
|
4964
|
+
const trimmed = code.trim();
|
|
4965
|
+
if (!trimmed) {
|
|
4966
|
+
container.innerHTML = '<span class="editor-mermaid-empty">Enter Mermaid syntax to preview</span>';
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4969
|
+
ensureMermaidInit();
|
|
4970
|
+
const id = `ng-mermaid-${++mermaidCounter}`;
|
|
4971
|
+
try {
|
|
4972
|
+
const { svg } = await mermaid.render(id, trimmed);
|
|
4973
|
+
container.innerHTML = svg;
|
|
4974
|
+
} catch (err) {
|
|
4975
|
+
const message = err instanceof Error ? err.message : "Invalid Mermaid syntax";
|
|
4976
|
+
container.innerHTML = `<pre class="editor-mermaid-error">${message.replace(/</g, "<")}</pre>`;
|
|
4908
4977
|
}
|
|
4978
|
+
}
|
|
4979
|
+
var MermaidTool = class {
|
|
4980
|
+
data;
|
|
4981
|
+
renderSeq = 0;
|
|
4909
4982
|
static get toolbox() {
|
|
4910
4983
|
return {
|
|
4911
|
-
title: "
|
|
4912
|
-
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="
|
|
4984
|
+
title: "Mermaid Diagram",
|
|
4985
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="6" height="6" rx="1"/><rect x="15" y="3" width="6" height="6" rx="1"/><rect x="9" y="15" width="6" height="6" rx="1"/><path d="M6 9v3a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V9"/><path d="M12 12v3"/></svg>'
|
|
4986
|
+
};
|
|
4987
|
+
}
|
|
4988
|
+
constructor({ data }) {
|
|
4989
|
+
this.data = {
|
|
4990
|
+
code: data?.code ?? MERMAID_PRESETS.Flowchart,
|
|
4991
|
+
caption: data?.caption ?? ""
|
|
4913
4992
|
};
|
|
4914
4993
|
}
|
|
4915
4994
|
render() {
|
|
4916
|
-
const
|
|
4917
|
-
|
|
4918
|
-
const
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4995
|
+
const wrap = document.createElement("div");
|
|
4996
|
+
wrap.className = "editor-mermaid-tool";
|
|
4997
|
+
const head = document.createElement("div");
|
|
4998
|
+
head.className = "editor-mermaid-head";
|
|
4999
|
+
const title = document.createElement("span");
|
|
5000
|
+
title.className = "editor-mermaid-label";
|
|
5001
|
+
title.textContent = "Mermaid Diagram";
|
|
5002
|
+
const presets = document.createElement("div");
|
|
5003
|
+
presets.className = "editor-mermaid-presets";
|
|
5004
|
+
Object.entries(MERMAID_PRESETS).forEach(([label, snippet]) => {
|
|
5005
|
+
const btn = document.createElement("button");
|
|
5006
|
+
btn.type = "button";
|
|
5007
|
+
btn.className = "editor-mermaid-preset-btn";
|
|
5008
|
+
btn.textContent = label;
|
|
5009
|
+
btn.addEventListener("click", () => {
|
|
5010
|
+
this.data.code = snippet;
|
|
5011
|
+
textarea.value = snippet;
|
|
5012
|
+
void updatePreview();
|
|
5013
|
+
});
|
|
5014
|
+
presets.appendChild(btn);
|
|
5015
|
+
});
|
|
5016
|
+
head.append(title, presets);
|
|
5017
|
+
const textarea = document.createElement("textarea");
|
|
5018
|
+
textarea.className = "editor-mermaid-input";
|
|
5019
|
+
textarea.rows = 5;
|
|
5020
|
+
textarea.placeholder = "graph TD\n A --> B";
|
|
5021
|
+
textarea.value = this.data.code;
|
|
4929
5022
|
const preview = document.createElement("div");
|
|
4930
|
-
preview.className = "
|
|
4931
|
-
const
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
const
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
if (bucketUrl) {
|
|
4941
|
-
input.value = bucketUrl;
|
|
4942
|
-
paint(bucketUrl);
|
|
4943
|
-
return;
|
|
4944
|
-
}
|
|
4945
|
-
const reader = new FileReader();
|
|
4946
|
-
reader.onload = () => {
|
|
4947
|
-
const res = String(reader.result || "");
|
|
4948
|
-
input.value = res;
|
|
4949
|
-
paint(res);
|
|
4950
|
-
};
|
|
4951
|
-
reader.readAsDataURL(selected);
|
|
5023
|
+
preview.className = "editor-mermaid-preview";
|
|
5024
|
+
const captionInput = document.createElement("input");
|
|
5025
|
+
captionInput.type = "text";
|
|
5026
|
+
captionInput.className = "editor-mermaid-caption cdx-input";
|
|
5027
|
+
captionInput.placeholder = "Optional diagram caption";
|
|
5028
|
+
captionInput.value = this.data.caption || "";
|
|
5029
|
+
const updatePreview = async () => {
|
|
5030
|
+
const seq = ++this.renderSeq;
|
|
5031
|
+
await renderMermaidInto(preview, this.data.code);
|
|
5032
|
+
if (seq !== this.renderSeq) return;
|
|
4952
5033
|
};
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
5034
|
+
textarea.addEventListener("input", () => {
|
|
5035
|
+
this.data.code = textarea.value;
|
|
5036
|
+
void updatePreview();
|
|
5037
|
+
});
|
|
5038
|
+
captionInput.addEventListener("input", () => {
|
|
5039
|
+
this.data.caption = captionInput.value;
|
|
5040
|
+
});
|
|
5041
|
+
void updatePreview();
|
|
5042
|
+
wrap.append(head, textarea, preview, captionInput);
|
|
5043
|
+
return wrap;
|
|
4956
5044
|
}
|
|
4957
5045
|
save() {
|
|
4958
5046
|
return {
|
|
4959
|
-
|
|
4960
|
-
caption: this.
|
|
5047
|
+
code: this.data.code,
|
|
5048
|
+
caption: this.data.caption?.trim() || void 0
|
|
4961
5049
|
};
|
|
4962
5050
|
}
|
|
4963
5051
|
};
|
|
4964
|
-
|
|
5052
|
+
|
|
5053
|
+
// src/blocks/extraBlocks.ts
|
|
5054
|
+
function createInput(type, className, placeholder, value, onInput) {
|
|
5055
|
+
const input = document.createElement("input");
|
|
5056
|
+
input.type = type;
|
|
5057
|
+
input.className = className;
|
|
5058
|
+
input.placeholder = placeholder;
|
|
5059
|
+
input.value = value;
|
|
5060
|
+
input.addEventListener("input", () => onInput(input.value));
|
|
5061
|
+
return input;
|
|
5062
|
+
}
|
|
5063
|
+
function createTextarea(className, rows, placeholder, value, onInput) {
|
|
5064
|
+
const ta = document.createElement("textarea");
|
|
5065
|
+
ta.className = className;
|
|
5066
|
+
ta.rows = rows;
|
|
5067
|
+
ta.placeholder = placeholder;
|
|
5068
|
+
ta.value = value;
|
|
5069
|
+
ta.addEventListener("input", () => onInput(ta.value));
|
|
5070
|
+
return ta;
|
|
5071
|
+
}
|
|
5072
|
+
var BookmarkTool = class {
|
|
4965
5073
|
data;
|
|
4966
|
-
elements;
|
|
4967
|
-
constructor(options) {
|
|
4968
|
-
this.data = options.data || {};
|
|
4969
|
-
}
|
|
4970
5074
|
static get toolbox() {
|
|
4971
5075
|
return {
|
|
4972
|
-
title: "
|
|
4973
|
-
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><
|
|
5076
|
+
title: "Bookmark",
|
|
5077
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/></svg>'
|
|
5078
|
+
};
|
|
5079
|
+
}
|
|
5080
|
+
constructor({ data }) {
|
|
5081
|
+
this.data = {
|
|
5082
|
+
url: data?.url ?? "",
|
|
5083
|
+
title: data?.title ?? "",
|
|
5084
|
+
description: data?.description ?? "",
|
|
5085
|
+
image: data?.image ?? ""
|
|
4974
5086
|
};
|
|
4975
5087
|
}
|
|
4976
5088
|
render() {
|
|
4977
|
-
const
|
|
4978
|
-
|
|
4979
|
-
const
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
searchInput.type = "search";
|
|
4983
|
-
searchInput.placeholder = "Search free GIFs (trending or keyword)...";
|
|
4984
|
-
const searchBtn = document.createElement("button");
|
|
4985
|
-
searchBtn.type = "button";
|
|
4986
|
-
searchBtn.className = "b2";
|
|
4987
|
-
searchBtn.textContent = "Search";
|
|
4988
|
-
searchRow.append(searchInput, searchBtn);
|
|
4989
|
-
const resultsGrid = document.createElement("div");
|
|
4990
|
-
resultsGrid.className = "gif-picker-grid";
|
|
4991
|
-
const url = document.createElement("input");
|
|
4992
|
-
url.type = "url";
|
|
4993
|
-
url.placeholder = "Or paste GIF / image URL";
|
|
4994
|
-
url.value = this.data.url || "";
|
|
4995
|
-
const caption = document.createElement("input");
|
|
4996
|
-
caption.type = "text";
|
|
4997
|
-
caption.placeholder = "Caption";
|
|
4998
|
-
caption.value = this.data.caption || "";
|
|
5089
|
+
const wrap = document.createElement("div");
|
|
5090
|
+
wrap.className = "editor-extra-card";
|
|
5091
|
+
const head = document.createElement("div");
|
|
5092
|
+
head.className = "editor-extra-head";
|
|
5093
|
+
head.textContent = "URL Bookmark Card";
|
|
4999
5094
|
const preview = document.createElement("div");
|
|
5000
|
-
preview.className = "
|
|
5001
|
-
const
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
|
|
5008
|
-
try {
|
|
5009
|
-
const res = await fetch(
|
|
5010
|
-
`/api/gifs?q=${encodeURIComponent(query)}&limit=12`
|
|
5011
|
-
);
|
|
5012
|
-
const json = await res.json();
|
|
5013
|
-
const items = json.results || [];
|
|
5014
|
-
if (!items.length) {
|
|
5015
|
-
resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
|
|
5016
|
-
return;
|
|
5095
|
+
preview.className = "editor-bookmark-preview";
|
|
5096
|
+
const refreshPreview = () => {
|
|
5097
|
+
const host = (() => {
|
|
5098
|
+
try {
|
|
5099
|
+
return this.data.url ? new URL(this.data.url).hostname : "example.com";
|
|
5100
|
+
} catch {
|
|
5101
|
+
return this.data.url || "example.com";
|
|
5017
5102
|
}
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
paint();
|
|
5029
|
-
};
|
|
5030
|
-
resultsGrid.appendChild(btn);
|
|
5031
|
-
});
|
|
5032
|
-
} catch {
|
|
5033
|
-
resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
|
|
5034
|
-
}
|
|
5103
|
+
})();
|
|
5104
|
+
preview.innerHTML = `
|
|
5105
|
+
<div class="editor-bookmark-card">
|
|
5106
|
+
<div class="editor-bookmark-body">
|
|
5107
|
+
<div class="editor-bookmark-title">${escHtml(this.data.title || host)}</div>
|
|
5108
|
+
${this.data.description ? `<div class="editor-bookmark-desc">${escHtml(this.data.description)}</div>` : ""}
|
|
5109
|
+
<div class="editor-bookmark-url">${escHtml(host)}</div>
|
|
5110
|
+
</div>
|
|
5111
|
+
${this.data.image ? `<img class="editor-bookmark-thumb" src="${escHtml(this.data.image)}" alt="" />` : ""}
|
|
5112
|
+
</div>`;
|
|
5035
5113
|
};
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
}
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5114
|
+
const grid = document.createElement("div");
|
|
5115
|
+
grid.className = "editor-extra-grid";
|
|
5116
|
+
grid.append(
|
|
5117
|
+
createInput("url", "cdx-input", "https://example.com/article", this.data.url, (v) => {
|
|
5118
|
+
this.data.url = v;
|
|
5119
|
+
refreshPreview();
|
|
5120
|
+
}),
|
|
5121
|
+
createInput("text", "cdx-input", "Link title", this.data.title, (v) => {
|
|
5122
|
+
this.data.title = v;
|
|
5123
|
+
refreshPreview();
|
|
5124
|
+
}),
|
|
5125
|
+
createInput("text", "cdx-input", "Short description", this.data.description, (v) => {
|
|
5126
|
+
this.data.description = v;
|
|
5127
|
+
refreshPreview();
|
|
5128
|
+
}),
|
|
5129
|
+
createInput("url", "cdx-input", "Optional thumbnail URL", this.data.image || "", (v) => {
|
|
5130
|
+
this.data.image = v;
|
|
5131
|
+
refreshPreview();
|
|
5132
|
+
})
|
|
5133
|
+
);
|
|
5134
|
+
refreshPreview();
|
|
5135
|
+
wrap.append(head, grid, preview);
|
|
5136
|
+
return wrap;
|
|
5050
5137
|
}
|
|
5051
5138
|
save() {
|
|
5052
5139
|
return {
|
|
5053
|
-
url: this.
|
|
5054
|
-
|
|
5140
|
+
url: this.data.url.trim(),
|
|
5141
|
+
title: this.data.title.trim(),
|
|
5142
|
+
description: this.data.description.trim(),
|
|
5143
|
+
image: this.data.image?.trim() || void 0
|
|
5055
5144
|
};
|
|
5056
5145
|
}
|
|
5057
5146
|
};
|
|
5058
|
-
var
|
|
5147
|
+
var StepsTool = class {
|
|
5059
5148
|
data;
|
|
5060
|
-
elements;
|
|
5061
|
-
constructor(options) {
|
|
5062
|
-
this.data = options.data || {};
|
|
5063
|
-
}
|
|
5064
5149
|
static get toolbox() {
|
|
5065
5150
|
return {
|
|
5066
|
-
title: "
|
|
5067
|
-
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><
|
|
5151
|
+
title: "Steps",
|
|
5152
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>'
|
|
5153
|
+
};
|
|
5154
|
+
}
|
|
5155
|
+
constructor({ data }) {
|
|
5156
|
+
this.data = {
|
|
5157
|
+
items: Array.isArray(data?.items) && data.items.length > 0 ? data.items.map((item) => ({ title: item.title || "", body: item.body || "" })) : [
|
|
5158
|
+
{ title: "Install dependencies", body: "Run npm install to set up the package." },
|
|
5159
|
+
{ title: "Configure & render", body: "Pass initialData and onChange to BlockEditor." }
|
|
5160
|
+
]
|
|
5068
5161
|
};
|
|
5069
5162
|
}
|
|
5070
5163
|
render() {
|
|
5071
|
-
const
|
|
5072
|
-
|
|
5073
|
-
const
|
|
5164
|
+
const wrap = document.createElement("div");
|
|
5165
|
+
wrap.className = "editor-extra-card";
|
|
5166
|
+
const head = document.createElement("div");
|
|
5167
|
+
head.className = "editor-extra-head";
|
|
5168
|
+
head.textContent = "Step-by-Step Walkthrough";
|
|
5169
|
+
const list = document.createElement("div");
|
|
5170
|
+
list.className = "editor-steps-editor-list";
|
|
5171
|
+
const renderList = () => {
|
|
5172
|
+
list.innerHTML = "";
|
|
5173
|
+
this.data.items.forEach((item, idx) => {
|
|
5174
|
+
const row = document.createElement("div");
|
|
5175
|
+
row.className = "editor-step-editor-row";
|
|
5176
|
+
const badge = document.createElement("span");
|
|
5177
|
+
badge.className = "editor-step-badge";
|
|
5178
|
+
badge.textContent = String(idx + 1);
|
|
5179
|
+
const fields = document.createElement("div");
|
|
5180
|
+
fields.className = "editor-step-editor-fields";
|
|
5181
|
+
fields.append(
|
|
5182
|
+
createInput("text", "cdx-input", `Step ${idx + 1} title`, item.title, (v) => {
|
|
5183
|
+
item.title = v;
|
|
5184
|
+
}),
|
|
5185
|
+
createTextarea("cdx-input", 2, "Step details", item.body, (v) => {
|
|
5186
|
+
item.body = v;
|
|
5187
|
+
})
|
|
5188
|
+
);
|
|
5189
|
+
const removeBtn = document.createElement("button");
|
|
5190
|
+
removeBtn.type = "button";
|
|
5191
|
+
removeBtn.className = "excalidraw-btn";
|
|
5192
|
+
removeBtn.textContent = "\xD7";
|
|
5193
|
+
removeBtn.title = "Remove step";
|
|
5194
|
+
removeBtn.addEventListener("click", () => {
|
|
5195
|
+
if (this.data.items.length <= 1) return;
|
|
5196
|
+
this.data.items.splice(idx, 1);
|
|
5197
|
+
renderList();
|
|
5198
|
+
});
|
|
5199
|
+
row.append(badge, fields, removeBtn);
|
|
5200
|
+
list.appendChild(row);
|
|
5201
|
+
});
|
|
5202
|
+
};
|
|
5203
|
+
const addBtn = document.createElement("button");
|
|
5204
|
+
addBtn.type = "button";
|
|
5205
|
+
addBtn.className = "excalidraw-btn";
|
|
5206
|
+
addBtn.textContent = "+ Add Step";
|
|
5207
|
+
addBtn.addEventListener("click", () => {
|
|
5208
|
+
this.data.items.push({ title: "", body: "" });
|
|
5209
|
+
renderList();
|
|
5210
|
+
});
|
|
5211
|
+
renderList();
|
|
5212
|
+
wrap.append(head, list, addBtn);
|
|
5213
|
+
return wrap;
|
|
5214
|
+
}
|
|
5215
|
+
save() {
|
|
5216
|
+
return {
|
|
5217
|
+
items: this.data.items.filter((i) => i.title.trim() || i.body.trim())
|
|
5218
|
+
};
|
|
5219
|
+
}
|
|
5220
|
+
};
|
|
5221
|
+
function computeSimpleDiff(before, after) {
|
|
5222
|
+
const a = before.split("\n");
|
|
5223
|
+
const b = after.split("\n");
|
|
5224
|
+
const lines = [];
|
|
5225
|
+
const max = Math.max(a.length, b.length);
|
|
5226
|
+
for (let i = 0; i < max; i += 1) {
|
|
5227
|
+
const left = a[i];
|
|
5228
|
+
const right = b[i];
|
|
5229
|
+
if (left === right) {
|
|
5230
|
+
if (left !== void 0) lines.push({ kind: "same", text: left });
|
|
5231
|
+
} else {
|
|
5232
|
+
if (left !== void 0) lines.push({ kind: "del", text: left });
|
|
5233
|
+
if (right !== void 0) lines.push({ kind: "add", text: right });
|
|
5234
|
+
}
|
|
5235
|
+
}
|
|
5236
|
+
return lines;
|
|
5237
|
+
}
|
|
5238
|
+
var DiffTool = class {
|
|
5239
|
+
data;
|
|
5240
|
+
static get toolbox() {
|
|
5241
|
+
return {
|
|
5242
|
+
title: "Code Diff",
|
|
5243
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v14"/><path d="M5 10h14"/><path d="M5 21h14"/></svg>'
|
|
5244
|
+
};
|
|
5245
|
+
}
|
|
5246
|
+
constructor({ data }) {
|
|
5247
|
+
this.data = {
|
|
5248
|
+
filename: data?.filename ?? "example.ts",
|
|
5249
|
+
before: data?.before ?? 'const theme = "catppuccin";',
|
|
5250
|
+
after: data?.after ?? 'const theme = "dark";'
|
|
5251
|
+
};
|
|
5252
|
+
}
|
|
5253
|
+
render() {
|
|
5254
|
+
const wrap = document.createElement("div");
|
|
5255
|
+
wrap.className = "editor-extra-card";
|
|
5256
|
+
const head = document.createElement("div");
|
|
5257
|
+
head.className = "editor-extra-head";
|
|
5258
|
+
head.textContent = "Code Diff Viewer";
|
|
5259
|
+
const preview = document.createElement("pre");
|
|
5260
|
+
preview.className = "editor-diff-preview";
|
|
5261
|
+
const refreshPreview = () => {
|
|
5262
|
+
const diffLines = computeSimpleDiff(this.data.before, this.data.after);
|
|
5263
|
+
preview.innerHTML = diffLines.map((line) => {
|
|
5264
|
+
const prefix = line.kind === "del" ? "-" : line.kind === "add" ? "+" : " ";
|
|
5265
|
+
return `<span class="editor-diff-line is-${line.kind}">${prefix} ${escHtml(line.text)}</span>`;
|
|
5266
|
+
}).join("\n");
|
|
5267
|
+
};
|
|
5268
|
+
const cols = document.createElement("div");
|
|
5269
|
+
cols.className = "editor-diff-inputs";
|
|
5270
|
+
cols.append(
|
|
5271
|
+
createTextarea("editor-mermaid-input", 4, "Before code...", this.data.before, (v) => {
|
|
5272
|
+
this.data.before = v;
|
|
5273
|
+
refreshPreview();
|
|
5274
|
+
}),
|
|
5275
|
+
createTextarea("editor-mermaid-input", 4, "After code...", this.data.after, (v) => {
|
|
5276
|
+
this.data.after = v;
|
|
5277
|
+
refreshPreview();
|
|
5278
|
+
})
|
|
5279
|
+
);
|
|
5280
|
+
const fileInput = createInput("text", "cdx-input", "Filename (optional)", this.data.filename || "", (v) => {
|
|
5281
|
+
this.data.filename = v;
|
|
5282
|
+
});
|
|
5283
|
+
refreshPreview();
|
|
5284
|
+
wrap.append(head, fileInput, cols, preview);
|
|
5285
|
+
return wrap;
|
|
5286
|
+
}
|
|
5287
|
+
save() {
|
|
5288
|
+
return {
|
|
5289
|
+
filename: this.data.filename?.trim() || void 0,
|
|
5290
|
+
before: this.data.before,
|
|
5291
|
+
after: this.data.after
|
|
5292
|
+
};
|
|
5293
|
+
}
|
|
5294
|
+
};
|
|
5295
|
+
var VideoTool = class {
|
|
5296
|
+
data;
|
|
5297
|
+
static get toolbox() {
|
|
5298
|
+
return {
|
|
5299
|
+
title: "Video Player",
|
|
5300
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="6 3 20 12 6 21 6 3"/></svg>'
|
|
5301
|
+
};
|
|
5302
|
+
}
|
|
5303
|
+
constructor({ data }) {
|
|
5304
|
+
this.data = {
|
|
5305
|
+
url: data?.url ?? "",
|
|
5306
|
+
poster: data?.poster ?? "",
|
|
5307
|
+
caption: data?.caption ?? ""
|
|
5308
|
+
};
|
|
5309
|
+
}
|
|
5310
|
+
render() {
|
|
5311
|
+
const wrap = document.createElement("div");
|
|
5312
|
+
wrap.className = "editor-extra-card";
|
|
5313
|
+
const head = document.createElement("div");
|
|
5314
|
+
head.className = "editor-extra-head";
|
|
5315
|
+
head.textContent = "Video Player (MP4 / WebM)";
|
|
5316
|
+
const preview = document.createElement("div");
|
|
5317
|
+
preview.className = "editor-video-preview";
|
|
5318
|
+
const refreshPreview = () => {
|
|
5319
|
+
if (!this.data.url.trim()) {
|
|
5320
|
+
preview.innerHTML = '<div class="editor-mermaid-empty">Paste a video URL or upload a file</div>';
|
|
5321
|
+
return;
|
|
5322
|
+
}
|
|
5323
|
+
preview.innerHTML = `<video controls preload="metadata" class="editor-video-el"${this.data.poster ? ` poster="${escHtml(this.data.poster)}"` : ""}><source src="${escHtml(this.data.url)}" /></video>`;
|
|
5324
|
+
};
|
|
5325
|
+
const urlInput = createInput("url", "cdx-input", "https://.../video.mp4", this.data.url, (v) => {
|
|
5326
|
+
this.data.url = v;
|
|
5327
|
+
refreshPreview();
|
|
5328
|
+
});
|
|
5329
|
+
const uploadInput = document.createElement("input");
|
|
5330
|
+
uploadInput.type = "file";
|
|
5331
|
+
uploadInput.accept = "video/mp4,video/webm,video/ogg";
|
|
5332
|
+
uploadInput.className = "cdx-input";
|
|
5333
|
+
uploadInput.addEventListener("change", async () => {
|
|
5334
|
+
const file = uploadInput.files?.[0];
|
|
5335
|
+
if (!file) return;
|
|
5336
|
+
const uploaded = await uploadFileToBucket(file, "videos");
|
|
5337
|
+
if (uploaded) {
|
|
5338
|
+
this.data.url = uploaded;
|
|
5339
|
+
urlInput.value = uploaded;
|
|
5340
|
+
refreshPreview();
|
|
5341
|
+
}
|
|
5342
|
+
});
|
|
5343
|
+
const posterInput = createInput("url", "cdx-input", "Optional poster image URL", this.data.poster || "", (v) => {
|
|
5344
|
+
this.data.poster = v;
|
|
5345
|
+
refreshPreview();
|
|
5346
|
+
});
|
|
5347
|
+
const captionInput = createInput("text", "cdx-input", "Optional video caption", this.data.caption || "", (v) => {
|
|
5348
|
+
this.data.caption = v;
|
|
5349
|
+
});
|
|
5350
|
+
refreshPreview();
|
|
5351
|
+
wrap.append(head, urlInput, uploadInput, posterInput, captionInput, preview);
|
|
5352
|
+
return wrap;
|
|
5353
|
+
}
|
|
5354
|
+
save() {
|
|
5355
|
+
return {
|
|
5356
|
+
url: this.data.url.trim(),
|
|
5357
|
+
poster: this.data.poster?.trim() || void 0,
|
|
5358
|
+
caption: this.data.caption?.trim() || void 0
|
|
5359
|
+
};
|
|
5360
|
+
}
|
|
5361
|
+
};
|
|
5362
|
+
var ChangelogTool = class {
|
|
5363
|
+
data;
|
|
5364
|
+
static get toolbox() {
|
|
5365
|
+
return {
|
|
5366
|
+
title: "Changelog",
|
|
5367
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>'
|
|
5368
|
+
};
|
|
5369
|
+
}
|
|
5370
|
+
constructor({ data }) {
|
|
5371
|
+
this.data = {
|
|
5372
|
+
version: data?.version ?? "v1.0.0",
|
|
5373
|
+
date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
5374
|
+
items: Array.isArray(data?.items) && data.items.length > 0 ? data.items.map((i) => ({ kind: i.kind || "added", text: i.text || "" })) : [{ kind: "added", text: "Initial release notes" }]
|
|
5375
|
+
};
|
|
5376
|
+
}
|
|
5377
|
+
render() {
|
|
5378
|
+
const wrap = document.createElement("div");
|
|
5379
|
+
wrap.className = "editor-extra-card";
|
|
5380
|
+
const head = document.createElement("div");
|
|
5381
|
+
head.className = "editor-extra-head";
|
|
5382
|
+
head.textContent = "Release Changelog";
|
|
5383
|
+
const meta = document.createElement("div");
|
|
5384
|
+
meta.className = "editor-diff-inputs";
|
|
5385
|
+
meta.append(
|
|
5386
|
+
createInput("text", "cdx-input", "Version (e.g. v1.2.0)", this.data.version, (v) => {
|
|
5387
|
+
this.data.version = v;
|
|
5388
|
+
}),
|
|
5389
|
+
createInput("date", "cdx-input", "Release date", this.data.date, (v) => {
|
|
5390
|
+
this.data.date = v;
|
|
5391
|
+
})
|
|
5392
|
+
);
|
|
5393
|
+
const list = document.createElement("div");
|
|
5394
|
+
list.className = "editor-steps-editor-list";
|
|
5395
|
+
const renderItems = () => {
|
|
5396
|
+
list.innerHTML = "";
|
|
5397
|
+
this.data.items.forEach((item, idx) => {
|
|
5398
|
+
const row = document.createElement("div");
|
|
5399
|
+
row.className = "editor-changelog-row";
|
|
5400
|
+
const select = document.createElement("select");
|
|
5401
|
+
select.className = "cdx-input editor-form-select";
|
|
5402
|
+
["added", "changed", "fixed"].forEach((k) => {
|
|
5403
|
+
const opt = document.createElement("option");
|
|
5404
|
+
opt.value = k;
|
|
5405
|
+
opt.textContent = k.toUpperCase();
|
|
5406
|
+
if (item.kind === k) opt.selected = true;
|
|
5407
|
+
select.appendChild(opt);
|
|
5408
|
+
});
|
|
5409
|
+
select.addEventListener("change", () => {
|
|
5410
|
+
item.kind = select.value;
|
|
5411
|
+
});
|
|
5412
|
+
const text = createInput("text", "cdx-input", "Change description", item.text, (v) => {
|
|
5413
|
+
item.text = v;
|
|
5414
|
+
});
|
|
5415
|
+
const del = document.createElement("button");
|
|
5416
|
+
del.type = "button";
|
|
5417
|
+
del.className = "excalidraw-btn";
|
|
5418
|
+
del.textContent = "\xD7";
|
|
5419
|
+
del.addEventListener("click", () => {
|
|
5420
|
+
if (this.data.items.length <= 1) return;
|
|
5421
|
+
this.data.items.splice(idx, 1);
|
|
5422
|
+
renderItems();
|
|
5423
|
+
});
|
|
5424
|
+
row.append(select, text, del);
|
|
5425
|
+
list.appendChild(row);
|
|
5426
|
+
});
|
|
5427
|
+
};
|
|
5428
|
+
const addBtn = document.createElement("button");
|
|
5429
|
+
addBtn.type = "button";
|
|
5430
|
+
addBtn.className = "excalidraw-btn";
|
|
5431
|
+
addBtn.textContent = "+ Add Entry";
|
|
5432
|
+
addBtn.addEventListener("click", () => {
|
|
5433
|
+
this.data.items.push({ kind: "added", text: "" });
|
|
5434
|
+
renderItems();
|
|
5435
|
+
});
|
|
5436
|
+
renderItems();
|
|
5437
|
+
wrap.append(head, meta, list, addBtn);
|
|
5438
|
+
return wrap;
|
|
5439
|
+
}
|
|
5440
|
+
save() {
|
|
5441
|
+
return {
|
|
5442
|
+
version: this.data.version.trim() || "v1.0.0",
|
|
5443
|
+
date: this.data.date,
|
|
5444
|
+
items: this.data.items.filter((i) => i.text.trim())
|
|
5445
|
+
};
|
|
5446
|
+
}
|
|
5447
|
+
};
|
|
5448
|
+
var SocialTool = class {
|
|
5449
|
+
data;
|
|
5450
|
+
static get toolbox() {
|
|
5451
|
+
return {
|
|
5452
|
+
title: "Social Post",
|
|
5453
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>'
|
|
5454
|
+
};
|
|
5455
|
+
}
|
|
5456
|
+
constructor({ data }) {
|
|
5457
|
+
this.data = {
|
|
5458
|
+
author: data?.author ?? "Alex Rivera",
|
|
5459
|
+
handle: data?.handle ?? "@alexrivera",
|
|
5460
|
+
date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
|
|
5461
|
+
text: data?.text ?? "",
|
|
5462
|
+
url: data?.url ?? ""
|
|
5463
|
+
};
|
|
5464
|
+
}
|
|
5465
|
+
render() {
|
|
5466
|
+
const wrap = document.createElement("div");
|
|
5467
|
+
wrap.className = "editor-extra-card";
|
|
5468
|
+
const head = document.createElement("div");
|
|
5469
|
+
head.className = "editor-extra-head";
|
|
5470
|
+
head.textContent = "Social Post Quote Card";
|
|
5471
|
+
const meta = document.createElement("div");
|
|
5472
|
+
meta.className = "editor-diff-inputs";
|
|
5473
|
+
meta.append(
|
|
5474
|
+
createInput("text", "cdx-input", "Author name", this.data.author, (v) => {
|
|
5475
|
+
this.data.author = v;
|
|
5476
|
+
}),
|
|
5477
|
+
createInput("text", "cdx-input", "@handle", this.data.handle, (v) => {
|
|
5478
|
+
this.data.handle = v;
|
|
5479
|
+
})
|
|
5480
|
+
);
|
|
5481
|
+
const text = createTextarea("cdx-input", 3, "Quoted post content...", this.data.text, (v) => {
|
|
5482
|
+
this.data.text = v;
|
|
5483
|
+
});
|
|
5484
|
+
const extra = document.createElement("div");
|
|
5485
|
+
extra.className = "editor-diff-inputs";
|
|
5486
|
+
extra.append(
|
|
5487
|
+
createInput("text", "cdx-input", "Date (optional)", this.data.date || "", (v) => {
|
|
5488
|
+
this.data.date = v;
|
|
5489
|
+
}),
|
|
5490
|
+
createInput("url", "cdx-input", "Original post URL (optional)", this.data.url || "", (v) => {
|
|
5491
|
+
this.data.url = v;
|
|
5492
|
+
})
|
|
5493
|
+
);
|
|
5494
|
+
wrap.append(head, meta, text, extra);
|
|
5495
|
+
return wrap;
|
|
5496
|
+
}
|
|
5497
|
+
save() {
|
|
5498
|
+
return {
|
|
5499
|
+
author: this.data.author.trim(),
|
|
5500
|
+
handle: this.data.handle.trim(),
|
|
5501
|
+
date: this.data.date?.trim() || void 0,
|
|
5502
|
+
text: this.data.text.trim(),
|
|
5503
|
+
url: this.data.url?.trim() || void 0
|
|
5504
|
+
};
|
|
5505
|
+
}
|
|
5506
|
+
};
|
|
5507
|
+
|
|
5508
|
+
// src/utils/aiClient.ts
|
|
5509
|
+
var AI_PROVIDER_PRESETS = [
|
|
5510
|
+
{
|
|
5511
|
+
id: "openai",
|
|
5512
|
+
label: "OpenAI (ChatGPT)",
|
|
5513
|
+
defaultModel: "gpt-4o-mini",
|
|
5514
|
+
defaultEndpoint: "https://api.openai.com/v1/chat/completions"
|
|
5515
|
+
},
|
|
5516
|
+
{
|
|
5517
|
+
id: "codex",
|
|
5518
|
+
label: "OpenAI Codex",
|
|
5519
|
+
defaultModel: "codex-mini-latest",
|
|
5520
|
+
defaultEndpoint: "https://api.openai.com/v1/chat/completions"
|
|
5521
|
+
},
|
|
5522
|
+
{
|
|
5523
|
+
id: "openrouter",
|
|
5524
|
+
label: "OpenRouter",
|
|
5525
|
+
defaultModel: "openai/gpt-4o-mini",
|
|
5526
|
+
defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
|
|
5527
|
+
},
|
|
5528
|
+
{
|
|
5529
|
+
id: "opencode",
|
|
5530
|
+
label: "OpenCode",
|
|
5531
|
+
defaultModel: "opencode/default",
|
|
5532
|
+
defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
|
|
5533
|
+
},
|
|
5534
|
+
{
|
|
5535
|
+
id: "anthropic",
|
|
5536
|
+
label: "Anthropic (Claude)",
|
|
5537
|
+
defaultModel: "claude-3-5-sonnet-latest",
|
|
5538
|
+
defaultEndpoint: "https://api.anthropic.com/v1/messages"
|
|
5539
|
+
},
|
|
5540
|
+
{
|
|
5541
|
+
id: "gemini",
|
|
5542
|
+
label: "Google Gemini",
|
|
5543
|
+
defaultModel: "gemini-2.5-flash",
|
|
5544
|
+
defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
|
|
5545
|
+
},
|
|
5546
|
+
{
|
|
5547
|
+
id: "custom",
|
|
5548
|
+
label: "Custom OpenAI-Compatible",
|
|
5549
|
+
defaultModel: "gpt-4o-mini",
|
|
5550
|
+
defaultEndpoint: "http://localhost:11434/v1/chat/completions"
|
|
5551
|
+
}
|
|
5552
|
+
];
|
|
5553
|
+
var AI_STORAGE_KEY = "nextgen-editor-ai-config";
|
|
5554
|
+
function loadAiConfig() {
|
|
5555
|
+
try {
|
|
5556
|
+
const raw = localStorage.getItem(AI_STORAGE_KEY);
|
|
5557
|
+
if (raw) {
|
|
5558
|
+
const parsed = JSON.parse(raw);
|
|
5559
|
+
if (parsed.provider) {
|
|
5560
|
+
return {
|
|
5561
|
+
provider: parsed.provider,
|
|
5562
|
+
model: parsed.model || "gpt-4o-mini",
|
|
5563
|
+
apiKey: parsed.apiKey || "",
|
|
5564
|
+
endpoint: parsed.endpoint || ""
|
|
5565
|
+
};
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5568
|
+
} catch {
|
|
5569
|
+
}
|
|
5570
|
+
return {
|
|
5571
|
+
provider: "openai",
|
|
5572
|
+
model: "gpt-4o-mini",
|
|
5573
|
+
apiKey: "",
|
|
5574
|
+
endpoint: ""
|
|
5575
|
+
};
|
|
5576
|
+
}
|
|
5577
|
+
function saveAiConfig(cfg) {
|
|
5578
|
+
try {
|
|
5579
|
+
localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
|
|
5580
|
+
} catch {
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5583
|
+
async function generateAiText(params) {
|
|
5584
|
+
const { config, mode, prompt, context } = params;
|
|
5585
|
+
const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
|
|
5586
|
+
const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
|
|
5587
|
+
const model = (config.model || preset.defaultModel).trim();
|
|
5588
|
+
const apiKey = config.apiKey.trim();
|
|
5589
|
+
if (!apiKey && config.provider !== "custom") {
|
|
5590
|
+
throw new Error("Please add an API key in Settings first.");
|
|
5591
|
+
}
|
|
5592
|
+
const systemPrompt = mode === "continue" ? "You are a concise writing assistant inside a block editor. Continue the document naturally from the provided context in 1-3 clear paragraphs. Return only the continuation text." : "You are a helpful writing and editing assistant inside a block editor. Fulfill the user request concisely using the provided document context.";
|
|
5593
|
+
const userContent = mode === "continue" ? `Document context:
|
|
5594
|
+
${context || "(Empty document)"}
|
|
5595
|
+
|
|
5596
|
+
Continue writing naturally:` : `Document context:
|
|
5597
|
+
${context || "(Empty document)"}
|
|
5598
|
+
|
|
5599
|
+
User request: ${prompt}`;
|
|
5600
|
+
if (config.provider === "gemini") {
|
|
5601
|
+
const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
|
|
5602
|
+
model
|
|
5603
|
+
)}:generateContent?key=${encodeURIComponent(apiKey)}`;
|
|
5604
|
+
const res2 = await fetch(url, {
|
|
5605
|
+
method: "POST",
|
|
5606
|
+
headers: { "Content-Type": "application/json" },
|
|
5607
|
+
body: JSON.stringify({
|
|
5608
|
+
contents: [{ parts: [{ text: `${systemPrompt}
|
|
5609
|
+
|
|
5610
|
+
${userContent}` }] }]
|
|
5611
|
+
})
|
|
5612
|
+
});
|
|
5613
|
+
if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
|
|
5614
|
+
const json2 = await res2.json();
|
|
5615
|
+
return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
|
|
5616
|
+
}
|
|
5617
|
+
if (config.provider === "anthropic") {
|
|
5618
|
+
const res2 = await fetch(endpoint, {
|
|
5619
|
+
method: "POST",
|
|
5620
|
+
headers: {
|
|
5621
|
+
"Content-Type": "application/json",
|
|
5622
|
+
"x-api-key": apiKey,
|
|
5623
|
+
"anthropic-version": "2023-06-01"
|
|
5624
|
+
},
|
|
5625
|
+
body: JSON.stringify({
|
|
5626
|
+
model,
|
|
5627
|
+
max_tokens: 1024,
|
|
5628
|
+
system: systemPrompt,
|
|
5629
|
+
messages: [{ role: "user", content: userContent }]
|
|
5630
|
+
})
|
|
5631
|
+
});
|
|
5632
|
+
if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
|
|
5633
|
+
const json2 = await res2.json();
|
|
5634
|
+
return json2.content?.[0]?.text?.trim() || "";
|
|
5635
|
+
}
|
|
5636
|
+
const headers = {
|
|
5637
|
+
"Content-Type": "application/json"
|
|
5638
|
+
};
|
|
5639
|
+
if (apiKey) {
|
|
5640
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
5641
|
+
}
|
|
5642
|
+
const res = await fetch(endpoint, {
|
|
5643
|
+
method: "POST",
|
|
5644
|
+
headers,
|
|
5645
|
+
body: JSON.stringify({
|
|
5646
|
+
model,
|
|
5647
|
+
messages: [
|
|
5648
|
+
{ role: "system", content: systemPrompt },
|
|
5649
|
+
{ role: "user", content: userContent }
|
|
5650
|
+
]
|
|
5651
|
+
})
|
|
5652
|
+
});
|
|
5653
|
+
if (!res.ok) throw new Error(`AI API error (${res.status})`);
|
|
5654
|
+
const json = await res.json();
|
|
5655
|
+
return json.choices?.[0]?.message?.content?.trim() || "";
|
|
5656
|
+
}
|
|
5657
|
+
|
|
5658
|
+
// src/blocks/inlineExtensions.ts
|
|
5659
|
+
var TEXT_COLOR_SWATCHES = [
|
|
5660
|
+
{ label: "Default", value: "" },
|
|
5661
|
+
{ label: "Gray", value: "#71717a" },
|
|
5662
|
+
{ label: "Red", value: "#dc2626" },
|
|
5663
|
+
{ label: "Amber", value: "#d97706" },
|
|
5664
|
+
{ label: "Green", value: "#16a34a" },
|
|
5665
|
+
{ label: "Blue", value: "#2563eb" },
|
|
5666
|
+
{ label: "Purple", value: "#9333ea" }
|
|
5667
|
+
];
|
|
5668
|
+
var HIGHLIGHT_SWATCHES = [
|
|
5669
|
+
{ label: "None", value: "" },
|
|
5670
|
+
{ label: "Yellow", value: "rgba(250, 204, 21, 0.35)" },
|
|
5671
|
+
{ label: "Green", value: "rgba(74, 222, 128, 0.3)" },
|
|
5672
|
+
{ label: "Blue", value: "rgba(96, 165, 250, 0.3)" },
|
|
5673
|
+
{ label: "Pink", value: "rgba(244, 114, 182, 0.3)" },
|
|
5674
|
+
{ label: "Gray", value: "rgba(161, 161, 170, 0.28)" }
|
|
5675
|
+
];
|
|
5676
|
+
var REWRITE_ACTIONS = [
|
|
5677
|
+
{
|
|
5678
|
+
id: "improve",
|
|
5679
|
+
label: "Improve",
|
|
5680
|
+
prompt: "Rewrite the following text to be clearer, smoother, and more engaging. Return only the rewritten text."
|
|
5681
|
+
},
|
|
5682
|
+
{
|
|
5683
|
+
id: "shorten",
|
|
5684
|
+
label: "Shorten",
|
|
5685
|
+
prompt: "Make the following text more concise while preserving its core meaning. Return only the shortened text."
|
|
5686
|
+
},
|
|
5687
|
+
{
|
|
5688
|
+
id: "grammar",
|
|
5689
|
+
label: "Fix Grammar",
|
|
5690
|
+
prompt: "Fix any spelling, punctuation, or grammar mistakes in the following text. Return only the corrected text."
|
|
5691
|
+
},
|
|
5692
|
+
{
|
|
5693
|
+
id: "professional",
|
|
5694
|
+
label: "Professional",
|
|
5695
|
+
prompt: "Rewrite the following text in a polished, professional tone. Return only the rewritten text."
|
|
5696
|
+
},
|
|
5697
|
+
{
|
|
5698
|
+
id: "translate",
|
|
5699
|
+
label: "Translate (ES)",
|
|
5700
|
+
prompt: "Translate the following text into natural Spanish. Return only the translated text."
|
|
5701
|
+
}
|
|
5702
|
+
];
|
|
5703
|
+
var AiRewriteInline = class {
|
|
5704
|
+
savedRange = null;
|
|
5705
|
+
actionsEl = null;
|
|
5706
|
+
static get isInline() {
|
|
5707
|
+
return true;
|
|
5708
|
+
}
|
|
5709
|
+
static get title() {
|
|
5710
|
+
return "AI Rewrite";
|
|
5711
|
+
}
|
|
5712
|
+
static get sanitize() {
|
|
5713
|
+
return {};
|
|
5714
|
+
}
|
|
5715
|
+
render() {
|
|
5716
|
+
const btn = document.createElement("button");
|
|
5717
|
+
btn.type = "button";
|
|
5718
|
+
btn.className = "ce-inline-tool";
|
|
5719
|
+
btn.title = "AI Rewrite selection";
|
|
5720
|
+
btn.innerHTML = '<span style="font-size:12px;font-weight:700;">\u2726 AI</span>';
|
|
5721
|
+
return btn;
|
|
5722
|
+
}
|
|
5723
|
+
surround(range) {
|
|
5724
|
+
this.savedRange = range.cloneRange();
|
|
5725
|
+
if (this.actionsEl) {
|
|
5726
|
+
this.actionsEl.hidden = false;
|
|
5727
|
+
}
|
|
5728
|
+
}
|
|
5729
|
+
renderActions() {
|
|
5730
|
+
const wrap = document.createElement("div");
|
|
5731
|
+
wrap.className = "ng-inline-ai-actions";
|
|
5732
|
+
wrap.hidden = true;
|
|
5733
|
+
const status = document.createElement("span");
|
|
5734
|
+
status.className = "ng-inline-ai-status";
|
|
5735
|
+
const row = document.createElement("div");
|
|
5736
|
+
row.className = "ng-inline-ai-row";
|
|
5737
|
+
REWRITE_ACTIONS.forEach((act) => {
|
|
5738
|
+
const b = document.createElement("button");
|
|
5739
|
+
b.type = "button";
|
|
5740
|
+
b.className = "ng-inline-action-btn";
|
|
5741
|
+
b.textContent = act.label;
|
|
5742
|
+
b.addEventListener("click", async () => {
|
|
5743
|
+
const range = this.savedRange;
|
|
5744
|
+
const selected = range?.toString().trim() || "";
|
|
5745
|
+
if (!range || !selected) {
|
|
5746
|
+
status.textContent = "Select text first.";
|
|
5747
|
+
return;
|
|
5748
|
+
}
|
|
5749
|
+
status.textContent = "Rewriting\u2026";
|
|
5750
|
+
try {
|
|
5751
|
+
const rewritten = await generateAiText({
|
|
5752
|
+
config: loadAiConfig(),
|
|
5753
|
+
mode: "ask",
|
|
5754
|
+
prompt: `${act.prompt}
|
|
5755
|
+
|
|
5756
|
+
Text:
|
|
5757
|
+
"${selected}"`,
|
|
5758
|
+
context: selected
|
|
5759
|
+
});
|
|
5760
|
+
if (rewritten) {
|
|
5761
|
+
range.deleteContents();
|
|
5762
|
+
range.insertNode(document.createTextNode(rewritten));
|
|
5763
|
+
status.textContent = "Done";
|
|
5764
|
+
} else {
|
|
5765
|
+
status.textContent = "Empty response";
|
|
5766
|
+
}
|
|
5767
|
+
} catch (err) {
|
|
5768
|
+
status.textContent = err instanceof Error ? err.message : "AI error";
|
|
5769
|
+
}
|
|
5770
|
+
});
|
|
5771
|
+
row.appendChild(b);
|
|
5772
|
+
});
|
|
5773
|
+
wrap.append(row, status);
|
|
5774
|
+
this.actionsEl = wrap;
|
|
5775
|
+
return wrap;
|
|
5776
|
+
}
|
|
5777
|
+
checkState() {
|
|
5778
|
+
const sel = window.getSelection();
|
|
5779
|
+
if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
|
|
5780
|
+
this.savedRange = sel.getRangeAt(0).cloneRange();
|
|
5781
|
+
}
|
|
5782
|
+
return false;
|
|
5783
|
+
}
|
|
5784
|
+
};
|
|
5785
|
+
var ColorInline = class {
|
|
5786
|
+
savedRange = null;
|
|
5787
|
+
actionsEl = null;
|
|
5788
|
+
static get isInline() {
|
|
5789
|
+
return true;
|
|
5790
|
+
}
|
|
5791
|
+
static get title() {
|
|
5792
|
+
return "Color & Highlight";
|
|
5793
|
+
}
|
|
5794
|
+
static get sanitize() {
|
|
5795
|
+
return {
|
|
5796
|
+
span: {
|
|
5797
|
+
class: "ng-inline-color",
|
|
5798
|
+
style: true
|
|
5799
|
+
}
|
|
5800
|
+
};
|
|
5801
|
+
}
|
|
5802
|
+
render() {
|
|
5803
|
+
const btn = document.createElement("button");
|
|
5804
|
+
btn.type = "button";
|
|
5805
|
+
btn.className = "ce-inline-tool";
|
|
5806
|
+
btn.title = "Text & Highlight Color";
|
|
5807
|
+
btn.innerHTML = '<span style="font-weight:700;font-size:12px;border-bottom:2px solid currentColor;">A</span>';
|
|
5808
|
+
return btn;
|
|
5809
|
+
}
|
|
5810
|
+
surround(range) {
|
|
5811
|
+
this.savedRange = range.cloneRange();
|
|
5812
|
+
if (this.actionsEl) {
|
|
5813
|
+
this.actionsEl.hidden = false;
|
|
5814
|
+
}
|
|
5815
|
+
}
|
|
5816
|
+
applyStyle(prop, value) {
|
|
5817
|
+
const range = this.savedRange;
|
|
5818
|
+
if (!range || range.collapsed) return;
|
|
5819
|
+
if (!value) {
|
|
5820
|
+
const span2 = document.createElement("span");
|
|
5821
|
+
span2.appendChild(range.extractContents());
|
|
5822
|
+
span2.querySelectorAll(".ng-inline-color").forEach((el) => {
|
|
5823
|
+
el.style[prop] = "";
|
|
5824
|
+
});
|
|
5825
|
+
range.insertNode(span2);
|
|
5826
|
+
return;
|
|
5827
|
+
}
|
|
5828
|
+
const span = document.createElement("span");
|
|
5829
|
+
span.className = "ng-inline-color";
|
|
5830
|
+
span.style[prop] = value;
|
|
5831
|
+
try {
|
|
5832
|
+
range.surroundContents(span);
|
|
5833
|
+
} catch {
|
|
5834
|
+
const frag = range.extractContents();
|
|
5835
|
+
span.appendChild(frag);
|
|
5836
|
+
range.insertNode(span);
|
|
5837
|
+
}
|
|
5838
|
+
}
|
|
5839
|
+
renderActions() {
|
|
5840
|
+
const wrap = document.createElement("div");
|
|
5841
|
+
wrap.className = "ng-inline-color-actions";
|
|
5842
|
+
wrap.hidden = true;
|
|
5843
|
+
const makeRow = (title, swatches, prop) => {
|
|
5844
|
+
const row = document.createElement("div");
|
|
5845
|
+
row.className = "ng-inline-swatch-row";
|
|
5846
|
+
const lbl = document.createElement("span");
|
|
5847
|
+
lbl.className = "ng-inline-swatch-label";
|
|
5848
|
+
lbl.textContent = title;
|
|
5849
|
+
row.appendChild(lbl);
|
|
5850
|
+
swatches.forEach((sw) => {
|
|
5851
|
+
const dot = document.createElement("button");
|
|
5852
|
+
dot.type = "button";
|
|
5853
|
+
dot.className = "ng-inline-swatch";
|
|
5854
|
+
dot.title = sw.label;
|
|
5855
|
+
dot.style.background = sw.value || "transparent";
|
|
5856
|
+
if (!sw.value) dot.textContent = "\xD7";
|
|
5857
|
+
dot.addEventListener("click", () => this.applyStyle(prop, sw.value));
|
|
5858
|
+
row.appendChild(dot);
|
|
5859
|
+
});
|
|
5860
|
+
return row;
|
|
5861
|
+
};
|
|
5862
|
+
wrap.append(
|
|
5863
|
+
makeRow("Text", TEXT_COLOR_SWATCHES, "color"),
|
|
5864
|
+
makeRow("Bg", HIGHLIGHT_SWATCHES, "backgroundColor")
|
|
5865
|
+
);
|
|
5866
|
+
this.actionsEl = wrap;
|
|
5867
|
+
return wrap;
|
|
5868
|
+
}
|
|
5869
|
+
checkState() {
|
|
5870
|
+
const sel = window.getSelection();
|
|
5871
|
+
if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
|
|
5872
|
+
this.savedRange = sel.getRangeAt(0).cloneRange();
|
|
5873
|
+
}
|
|
5874
|
+
return false;
|
|
5875
|
+
}
|
|
5876
|
+
};
|
|
5877
|
+
var TodayTool = class {
|
|
5878
|
+
data;
|
|
5879
|
+
static get toolbox() {
|
|
5880
|
+
return {
|
|
5881
|
+
title: "Today Date",
|
|
5882
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>'
|
|
5883
|
+
};
|
|
5884
|
+
}
|
|
5885
|
+
constructor({ data }) {
|
|
5886
|
+
const now = /* @__PURE__ */ new Date();
|
|
5887
|
+
this.data = {
|
|
5888
|
+
date: data?.date ?? now.toLocaleDateString(void 0, {
|
|
5889
|
+
year: "numeric",
|
|
5890
|
+
month: "long",
|
|
5891
|
+
day: "numeric"
|
|
5892
|
+
}),
|
|
5893
|
+
label: data?.label ?? "Date"
|
|
5894
|
+
};
|
|
5895
|
+
}
|
|
5896
|
+
render() {
|
|
5897
|
+
const wrap = document.createElement("div");
|
|
5898
|
+
wrap.className = "editor-today-pill";
|
|
5899
|
+
const badge = document.createElement("span");
|
|
5900
|
+
badge.className = "editor-today-badge";
|
|
5901
|
+
badge.textContent = `\u{1F4C5} ${this.data.date}`;
|
|
5902
|
+
const toggle = document.createElement("button");
|
|
5903
|
+
toggle.type = "button";
|
|
5904
|
+
toggle.className = "editor-mermaid-preset-btn";
|
|
5905
|
+
toggle.textContent = "ISO";
|
|
5906
|
+
toggle.addEventListener("click", () => {
|
|
5907
|
+
const now = /* @__PURE__ */ new Date();
|
|
5908
|
+
const iso = now.toISOString().slice(0, 10);
|
|
5909
|
+
const long = now.toLocaleDateString(void 0, {
|
|
5910
|
+
year: "numeric",
|
|
5911
|
+
month: "long",
|
|
5912
|
+
day: "numeric"
|
|
5913
|
+
});
|
|
5914
|
+
this.data.date = this.data.date === iso ? long : iso;
|
|
5915
|
+
badge.textContent = `\u{1F4C5} ${this.data.date}`;
|
|
5916
|
+
toggle.textContent = this.data.date === iso ? "Long" : "ISO";
|
|
5917
|
+
});
|
|
5918
|
+
wrap.append(badge, toggle);
|
|
5919
|
+
return wrap;
|
|
5920
|
+
}
|
|
5921
|
+
save() {
|
|
5922
|
+
return {
|
|
5923
|
+
date: this.data.date,
|
|
5924
|
+
label: this.data.label
|
|
5925
|
+
};
|
|
5926
|
+
}
|
|
5927
|
+
};
|
|
5928
|
+
var ExportTriggerTool = class {
|
|
5929
|
+
static get toolbox() {
|
|
5930
|
+
return {
|
|
5931
|
+
title: "Export / Import",
|
|
5932
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>'
|
|
5933
|
+
};
|
|
5934
|
+
}
|
|
5935
|
+
render() {
|
|
5936
|
+
const el = document.createElement("div");
|
|
5937
|
+
el.className = "editor-export-trigger";
|
|
5938
|
+
el.textContent = "Opening Export & Markdown modal\u2026";
|
|
5939
|
+
queueMicrotask(() => {
|
|
5940
|
+
el.dispatchEvent(new CustomEvent("nextgen-open-export", { bubbles: true }));
|
|
5941
|
+
});
|
|
5942
|
+
return el;
|
|
5943
|
+
}
|
|
5944
|
+
save() {
|
|
5945
|
+
return {};
|
|
5946
|
+
}
|
|
5947
|
+
};
|
|
5948
|
+
|
|
5949
|
+
// src/editorTools.ts
|
|
5950
|
+
var CustomMediaTool = class {
|
|
5951
|
+
data;
|
|
5952
|
+
elements;
|
|
5953
|
+
constructor(options) {
|
|
5954
|
+
this.data = options.data || {};
|
|
5955
|
+
}
|
|
5956
|
+
static get toolbox() {
|
|
5957
|
+
return {
|
|
5958
|
+
title: "Image",
|
|
5959
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/></svg>'
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
render() {
|
|
5963
|
+
const root = document.createElement("div");
|
|
5964
|
+
root.className = "custom-media-fields";
|
|
5965
|
+
const input = document.createElement("input");
|
|
5966
|
+
input.type = "text";
|
|
5967
|
+
input.placeholder = "Paste image URL";
|
|
5968
|
+
input.value = this.data.url || "";
|
|
5969
|
+
const file = document.createElement("input");
|
|
5970
|
+
file.type = "file";
|
|
5971
|
+
file.accept = "image/*";
|
|
5972
|
+
const caption = document.createElement("input");
|
|
5973
|
+
caption.type = "text";
|
|
5974
|
+
caption.placeholder = "Caption";
|
|
5975
|
+
caption.value = this.data.caption || "";
|
|
5976
|
+
const preview = document.createElement("div");
|
|
5977
|
+
preview.className = "custom-media-preview";
|
|
5978
|
+
const paint = (url) => {
|
|
5979
|
+
preview.innerHTML = url ? `<img src="${escHtml(url)}" alt="">` : "";
|
|
5980
|
+
};
|
|
5981
|
+
paint(input.value);
|
|
5982
|
+
input.oninput = () => paint(input.value);
|
|
5983
|
+
file.onchange = async () => {
|
|
5984
|
+
const selected = file.files?.[0];
|
|
5985
|
+
if (!selected) return;
|
|
5986
|
+
const bucketUrl = await uploadFileToBucket(selected, "writing");
|
|
5987
|
+
if (bucketUrl) {
|
|
5988
|
+
input.value = bucketUrl;
|
|
5989
|
+
paint(bucketUrl);
|
|
5990
|
+
return;
|
|
5991
|
+
}
|
|
5992
|
+
const reader = new FileReader();
|
|
5993
|
+
reader.onload = () => {
|
|
5994
|
+
const res = String(reader.result || "");
|
|
5995
|
+
input.value = res;
|
|
5996
|
+
paint(res);
|
|
5997
|
+
};
|
|
5998
|
+
reader.readAsDataURL(selected);
|
|
5999
|
+
};
|
|
6000
|
+
root.append(input, file, caption, preview);
|
|
6001
|
+
this.elements = { root, input, caption };
|
|
6002
|
+
return root;
|
|
6003
|
+
}
|
|
6004
|
+
save() {
|
|
6005
|
+
return {
|
|
6006
|
+
url: this.elements?.input.value.trim() || "",
|
|
6007
|
+
caption: this.elements?.caption.value.trim() || ""
|
|
6008
|
+
};
|
|
6009
|
+
}
|
|
6010
|
+
};
|
|
6011
|
+
var GifTool = class {
|
|
6012
|
+
data;
|
|
6013
|
+
elements;
|
|
6014
|
+
constructor(options) {
|
|
6015
|
+
this.data = options.data || {};
|
|
6016
|
+
}
|
|
6017
|
+
static get toolbox() {
|
|
6018
|
+
return {
|
|
6019
|
+
title: "GIF",
|
|
6020
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M10 9H7a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h2v-3H8"/><path d="M13 9v6"/><path d="M16 15V9h3"/><path d="M16 12h2"/></svg>'
|
|
6021
|
+
};
|
|
6022
|
+
}
|
|
6023
|
+
render() {
|
|
6024
|
+
const root = document.createElement("div");
|
|
6025
|
+
root.className = "custom-media-fields";
|
|
6026
|
+
const searchRow = document.createElement("div");
|
|
6027
|
+
searchRow.className = "gif-search-row";
|
|
6028
|
+
const searchInput = document.createElement("input");
|
|
6029
|
+
searchInput.type = "search";
|
|
6030
|
+
searchInput.placeholder = "Search free GIFs (trending or keyword)...";
|
|
6031
|
+
const searchBtn = document.createElement("button");
|
|
6032
|
+
searchBtn.type = "button";
|
|
6033
|
+
searchBtn.className = "b2";
|
|
6034
|
+
searchBtn.textContent = "Search";
|
|
6035
|
+
searchRow.append(searchInput, searchBtn);
|
|
6036
|
+
const resultsGrid = document.createElement("div");
|
|
6037
|
+
resultsGrid.className = "gif-picker-grid";
|
|
6038
|
+
const url = document.createElement("input");
|
|
6039
|
+
url.type = "url";
|
|
6040
|
+
url.placeholder = "Or paste GIF / image URL";
|
|
6041
|
+
url.value = this.data.url || "";
|
|
6042
|
+
const caption = document.createElement("input");
|
|
6043
|
+
caption.type = "text";
|
|
6044
|
+
caption.placeholder = "Caption";
|
|
6045
|
+
caption.value = this.data.caption || "";
|
|
6046
|
+
const preview = document.createElement("div");
|
|
6047
|
+
preview.className = "custom-media-preview";
|
|
6048
|
+
const paint = () => {
|
|
6049
|
+
preview.innerHTML = url.value ? `<img src="${escHtml(url.value)}" alt="${escHtml(caption.value || "GIF")}">` : "";
|
|
6050
|
+
};
|
|
6051
|
+
paint();
|
|
6052
|
+
url.oninput = paint;
|
|
6053
|
+
const runSearch = async (query) => {
|
|
6054
|
+
resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
|
|
6055
|
+
try {
|
|
6056
|
+
const res = await fetch(
|
|
6057
|
+
`/api/gifs?q=${encodeURIComponent(query)}&limit=12`
|
|
6058
|
+
);
|
|
6059
|
+
const json = await res.json();
|
|
6060
|
+
const items = json.results || [];
|
|
6061
|
+
if (!items.length) {
|
|
6062
|
+
resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
|
|
6063
|
+
return;
|
|
6064
|
+
}
|
|
6065
|
+
resultsGrid.innerHTML = "";
|
|
6066
|
+
items.forEach((item) => {
|
|
6067
|
+
const btn = document.createElement("button");
|
|
6068
|
+
btn.type = "button";
|
|
6069
|
+
btn.className = "gif-picker-item";
|
|
6070
|
+
btn.title = item.title;
|
|
6071
|
+
btn.innerHTML = `<img src="${escHtml(item.previewUrl)}" alt="${escHtml(item.title)}" loading="lazy">`;
|
|
6072
|
+
btn.onclick = () => {
|
|
6073
|
+
url.value = item.url;
|
|
6074
|
+
if (!caption.value) caption.value = item.title;
|
|
6075
|
+
paint();
|
|
6076
|
+
};
|
|
6077
|
+
resultsGrid.appendChild(btn);
|
|
6078
|
+
});
|
|
6079
|
+
} catch {
|
|
6080
|
+
resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
|
|
6081
|
+
}
|
|
6082
|
+
};
|
|
6083
|
+
searchBtn.onclick = () => void runSearch(searchInput.value);
|
|
6084
|
+
searchInput.addEventListener("keydown", (e) => {
|
|
6085
|
+
if (e.key === "Enter") {
|
|
6086
|
+
e.preventDefault();
|
|
6087
|
+
e.stopPropagation();
|
|
6088
|
+
void runSearch(searchInput.value);
|
|
6089
|
+
}
|
|
6090
|
+
});
|
|
6091
|
+
if (!this.data.url) {
|
|
6092
|
+
void runSearch("");
|
|
6093
|
+
}
|
|
6094
|
+
root.append(searchRow, resultsGrid, url, caption, preview);
|
|
6095
|
+
this.elements = { url, caption };
|
|
6096
|
+
return root;
|
|
6097
|
+
}
|
|
6098
|
+
save() {
|
|
6099
|
+
return {
|
|
6100
|
+
url: this.elements?.url.value.trim() || "",
|
|
6101
|
+
caption: this.elements?.caption.value.trim() || ""
|
|
6102
|
+
};
|
|
6103
|
+
}
|
|
6104
|
+
};
|
|
6105
|
+
var AttachTool = class {
|
|
6106
|
+
data;
|
|
6107
|
+
elements;
|
|
6108
|
+
constructor(options) {
|
|
6109
|
+
this.data = options.data || {};
|
|
6110
|
+
}
|
|
6111
|
+
static get toolbox() {
|
|
6112
|
+
return {
|
|
6113
|
+
title: "Attachment",
|
|
6114
|
+
icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>'
|
|
6115
|
+
};
|
|
6116
|
+
}
|
|
6117
|
+
render() {
|
|
6118
|
+
const root = document.createElement("div");
|
|
6119
|
+
root.className = "custom-media-fields";
|
|
6120
|
+
const file = document.createElement("input");
|
|
5074
6121
|
file.type = "file";
|
|
5075
6122
|
const name = document.createElement("input");
|
|
5076
6123
|
name.type = "text";
|
|
@@ -5312,7 +6359,11 @@ var CustomEmbedTool = class {
|
|
|
5312
6359
|
data;
|
|
5313
6360
|
elements;
|
|
5314
6361
|
constructor(options) {
|
|
5315
|
-
this.data =
|
|
6362
|
+
this.data = {
|
|
6363
|
+
align: "center",
|
|
6364
|
+
size: "medium",
|
|
6365
|
+
...options.data || {}
|
|
6366
|
+
};
|
|
5316
6367
|
}
|
|
5317
6368
|
static get toolbox() {
|
|
5318
6369
|
return {
|
|
@@ -5373,15 +6424,20 @@ var CustomEmbedTool = class {
|
|
|
5373
6424
|
caption.value = this.data.caption || "";
|
|
5374
6425
|
const preview = document.createElement("div");
|
|
5375
6426
|
preview.className = "custom-embed-preview";
|
|
6427
|
+
preview.dataset.align = this.data.align || "center";
|
|
6428
|
+
preview.dataset.size = this.data.size || "medium";
|
|
5376
6429
|
const elements = {
|
|
5377
6430
|
url,
|
|
5378
6431
|
caption,
|
|
6432
|
+
preview,
|
|
5379
6433
|
embedUrl: this.data.embed || this.toEmbedUrl(url.value)
|
|
5380
6434
|
};
|
|
5381
6435
|
this.elements = elements;
|
|
5382
6436
|
const paint = () => {
|
|
5383
6437
|
const embedUrl = this.toEmbedUrl(url.value);
|
|
5384
6438
|
elements.embedUrl = embedUrl;
|
|
6439
|
+
preview.dataset.align = this.data.align || "center";
|
|
6440
|
+
preview.dataset.size = this.data.size || "medium";
|
|
5385
6441
|
preview.innerHTML = embedUrl ? `<iframe src="${escHtml(embedUrl)}" title="${escHtml(
|
|
5386
6442
|
caption.value || "Embedded content"
|
|
5387
6443
|
)}" loading="lazy" allowfullscreen></iframe>` : "";
|
|
@@ -5395,13 +6451,96 @@ var CustomEmbedTool = class {
|
|
|
5395
6451
|
root.append(url, caption, preview);
|
|
5396
6452
|
return root;
|
|
5397
6453
|
}
|
|
6454
|
+
renderSettings() {
|
|
6455
|
+
const tunes = [
|
|
6456
|
+
{
|
|
6457
|
+
name: "align-left",
|
|
6458
|
+
label: "Align Left",
|
|
6459
|
+
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>',
|
|
6460
|
+
isActive: (this.data.align || "center") === "left",
|
|
6461
|
+
onActivate: () => {
|
|
6462
|
+
this.data.align = "left";
|
|
6463
|
+
if (this.elements?.preview) this.elements.preview.dataset.align = "left";
|
|
6464
|
+
}
|
|
6465
|
+
},
|
|
6466
|
+
{
|
|
6467
|
+
name: "align-center",
|
|
6468
|
+
label: "Align Center",
|
|
6469
|
+
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>',
|
|
6470
|
+
isActive: (this.data.align || "center") === "center",
|
|
6471
|
+
onActivate: () => {
|
|
6472
|
+
this.data.align = "center";
|
|
6473
|
+
if (this.elements?.preview) this.elements.preview.dataset.align = "center";
|
|
6474
|
+
}
|
|
6475
|
+
},
|
|
6476
|
+
{
|
|
6477
|
+
name: "align-right",
|
|
6478
|
+
label: "Align Right",
|
|
6479
|
+
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>',
|
|
6480
|
+
isActive: (this.data.align || "center") === "right",
|
|
6481
|
+
onActivate: () => {
|
|
6482
|
+
this.data.align = "right";
|
|
6483
|
+
if (this.elements?.preview) this.elements.preview.dataset.align = "right";
|
|
6484
|
+
}
|
|
6485
|
+
},
|
|
6486
|
+
{
|
|
6487
|
+
name: "size-small",
|
|
6488
|
+
label: "Small",
|
|
6489
|
+
icon: '<span style="font-size:11px;font-weight:700;">S</span>',
|
|
6490
|
+
isActive: (this.data.size || "medium") === "small",
|
|
6491
|
+
onActivate: () => {
|
|
6492
|
+
this.data.size = "small";
|
|
6493
|
+
if (this.elements?.preview) this.elements.preview.dataset.size = "small";
|
|
6494
|
+
}
|
|
6495
|
+
},
|
|
6496
|
+
{
|
|
6497
|
+
name: "size-medium",
|
|
6498
|
+
label: "Medium",
|
|
6499
|
+
icon: '<span style="font-size:11px;font-weight:700;">M</span>',
|
|
6500
|
+
isActive: (this.data.size || "medium") === "medium",
|
|
6501
|
+
onActivate: () => {
|
|
6502
|
+
this.data.size = "medium";
|
|
6503
|
+
if (this.elements?.preview) this.elements.preview.dataset.size = "medium";
|
|
6504
|
+
}
|
|
6505
|
+
},
|
|
6506
|
+
{
|
|
6507
|
+
name: "size-large",
|
|
6508
|
+
label: "Large",
|
|
6509
|
+
icon: '<span style="font-size:11px;font-weight:700;">L</span>',
|
|
6510
|
+
isActive: (this.data.size || "medium") === "large",
|
|
6511
|
+
onActivate: () => {
|
|
6512
|
+
this.data.size = "large";
|
|
6513
|
+
if (this.elements?.preview) this.elements.preview.dataset.size = "large";
|
|
6514
|
+
}
|
|
6515
|
+
},
|
|
6516
|
+
{
|
|
6517
|
+
name: "size-full",
|
|
6518
|
+
label: "Full Page",
|
|
6519
|
+
icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',
|
|
6520
|
+
isActive: (this.data.size || "medium") === "full",
|
|
6521
|
+
onActivate: () => {
|
|
6522
|
+
this.data.size = "full";
|
|
6523
|
+
if (this.elements?.preview) this.elements.preview.dataset.size = "full";
|
|
6524
|
+
}
|
|
6525
|
+
}
|
|
6526
|
+
];
|
|
6527
|
+
return tunes.map((t) => ({
|
|
6528
|
+
icon: t.icon,
|
|
6529
|
+
label: t.label,
|
|
6530
|
+
isActive: t.isActive,
|
|
6531
|
+
closeOnActivate: true,
|
|
6532
|
+
onActivate: t.onActivate
|
|
6533
|
+
}));
|
|
6534
|
+
}
|
|
5398
6535
|
save() {
|
|
5399
6536
|
const source = this.elements?.url.value.trim() || "";
|
|
5400
6537
|
const embed = this.toEmbedUrl(source);
|
|
5401
6538
|
return {
|
|
5402
6539
|
source,
|
|
5403
6540
|
embed,
|
|
5404
|
-
caption: this.elements?.caption.value.trim() || ""
|
|
6541
|
+
caption: this.elements?.caption.value.trim() || "",
|
|
6542
|
+
align: this.data.align || "center",
|
|
6543
|
+
size: this.data.size || "medium"
|
|
5405
6544
|
};
|
|
5406
6545
|
}
|
|
5407
6546
|
};
|
|
@@ -5851,6 +6990,8 @@ var SpoilerInline = class {
|
|
|
5851
6990
|
}
|
|
5852
6991
|
};
|
|
5853
6992
|
var MentionInline = class {
|
|
6993
|
+
savedRange = null;
|
|
6994
|
+
actionsEl = null;
|
|
5854
6995
|
static get isInline() {
|
|
5855
6996
|
return true;
|
|
5856
6997
|
}
|
|
@@ -5866,23 +7007,59 @@ var MentionInline = class {
|
|
|
5866
7007
|
return button;
|
|
5867
7008
|
}
|
|
5868
7009
|
surround(range) {
|
|
5869
|
-
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
anchor.href = url.trim();
|
|
5875
|
-
anchor.target = "_blank";
|
|
5876
|
-
anchor.rel = "noopener noreferrer";
|
|
5877
|
-
try {
|
|
5878
|
-
range.surroundContents(anchor);
|
|
5879
|
-
if (selectedText && !selectedText.startsWith("@")) {
|
|
5880
|
-
anchor.textContent = `@${selectedText}`;
|
|
5881
|
-
}
|
|
5882
|
-
} catch {
|
|
7010
|
+
this.savedRange = range.cloneRange();
|
|
7011
|
+
if (this.actionsEl) {
|
|
7012
|
+
this.actionsEl.hidden = false;
|
|
7013
|
+
const input = this.actionsEl.querySelector("input");
|
|
7014
|
+
input?.focus();
|
|
5883
7015
|
}
|
|
5884
7016
|
}
|
|
7017
|
+
renderActions() {
|
|
7018
|
+
const wrap = document.createElement("div");
|
|
7019
|
+
wrap.className = "ng-mention-popover";
|
|
7020
|
+
wrap.hidden = true;
|
|
7021
|
+
const input = document.createElement("input");
|
|
7022
|
+
input.type = "url";
|
|
7023
|
+
input.className = "cdx-input";
|
|
7024
|
+
input.placeholder = "https://github.com/username";
|
|
7025
|
+
const applyBtn = document.createElement("button");
|
|
7026
|
+
applyBtn.type = "button";
|
|
7027
|
+
applyBtn.className = "ng-inline-action-btn";
|
|
7028
|
+
applyBtn.textContent = "Apply";
|
|
7029
|
+
const applyMention = (url) => {
|
|
7030
|
+
const range = this.savedRange;
|
|
7031
|
+
if (!range || !url.trim()) return;
|
|
7032
|
+
const selectedText = range.toString().trim();
|
|
7033
|
+
const anchor = document.createElement("a");
|
|
7034
|
+
anchor.className = "editor-mention";
|
|
7035
|
+
anchor.href = url.trim();
|
|
7036
|
+
anchor.target = "_blank";
|
|
7037
|
+
anchor.rel = "noopener noreferrer";
|
|
7038
|
+
try {
|
|
7039
|
+
range.surroundContents(anchor);
|
|
7040
|
+
if (selectedText && !selectedText.startsWith("@")) {
|
|
7041
|
+
anchor.textContent = `@${selectedText}`;
|
|
7042
|
+
}
|
|
7043
|
+
} catch {
|
|
7044
|
+
}
|
|
7045
|
+
wrap.hidden = true;
|
|
7046
|
+
};
|
|
7047
|
+
applyBtn.addEventListener("click", () => applyMention(input.value));
|
|
7048
|
+
input.addEventListener("keydown", (e) => {
|
|
7049
|
+
if (e.key === "Enter") {
|
|
7050
|
+
e.preventDefault();
|
|
7051
|
+
applyMention(input.value);
|
|
7052
|
+
}
|
|
7053
|
+
});
|
|
7054
|
+
wrap.append(input, applyBtn);
|
|
7055
|
+
this.actionsEl = wrap;
|
|
7056
|
+
return wrap;
|
|
7057
|
+
}
|
|
5885
7058
|
checkState() {
|
|
7059
|
+
const sel = window.getSelection();
|
|
7060
|
+
if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
|
|
7061
|
+
this.savedRange = sel.getRangeAt(0).cloneRange();
|
|
7062
|
+
}
|
|
5886
7063
|
return false;
|
|
5887
7064
|
}
|
|
5888
7065
|
};
|
|
@@ -5981,234 +7158,98 @@ function getEditorTools(includeLayout = true, enabledTools) {
|
|
|
5981
7158
|
}
|
|
5982
7159
|
},
|
|
5983
7160
|
delimiter: DelimiterTool,
|
|
5984
|
-
checklist: Checklist,
|
|
5985
7161
|
table: Table,
|
|
5986
7162
|
callout: CalloutTool,
|
|
5987
|
-
hotkey: HotkeyTool,
|
|
5988
|
-
emoji: EmojiTool,
|
|
5989
|
-
scratch: ScratchTool,
|
|
5990
|
-
alert: AlertTool,
|
|
5991
|
-
// 2. Common rich media & layout
|
|
5992
|
-
upload: UploadTool,
|
|
5993
|
-
audio: AudioPlayerTool,
|
|
5994
|
-
musicCarousel: MusicCarouselTool,
|
|
5995
|
-
embed: CustomEmbedTool,
|
|
5996
|
-
gallery: LightboxGalleryTool,
|
|
5997
|
-
masonry: MasonryTool,
|
|
5998
|
-
carousel: CarouselTool,
|
|
5999
|
-
bento: BentoTool,
|
|
6000
|
-
...includeLayout ? { layout: LayoutTool } : {},
|
|
6001
|
-
tabs: TabsTool,
|
|
6002
|
-
accordion: AccordionTool,
|
|
6003
|
-
toggleh1: ToggleH1Tool,
|
|
6004
|
-
toggleh2: ToggleH2Tool,
|
|
6005
|
-
toggleh3: ToggleH3Tool,
|
|
6006
|
-
// 3. Structured & editorial blocks
|
|
6007
|
-
flashcards: FlashcardTool,
|
|
6008
|
-
chart: ChartTool,
|
|
6009
|
-
footnotes: FootnotesTool,
|
|
6010
|
-
quiz: QuizTool,
|
|
6011
|
-
kanban: KanbanTool,
|
|
6012
|
-
timer: FocusTimerTool,
|
|
6013
|
-
poll: PollTool,
|
|
6014
|
-
faq: FaqTool,
|
|
6015
|
-
todo: TaskChecklistTool,
|
|
6016
|
-
eisenhower: EisenhowerMatrixTool,
|
|
6017
|
-
form: FormBuilderTool,
|
|
6018
|
-
latex: LatexTool,
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
var AI_PROVIDER_PRESETS = [
|
|
6062
|
-
{
|
|
6063
|
-
id: "openai",
|
|
6064
|
-
label: "OpenAI (ChatGPT)",
|
|
6065
|
-
defaultModel: "gpt-4o-mini",
|
|
6066
|
-
defaultEndpoint: "https://api.openai.com/v1/chat/completions"
|
|
6067
|
-
},
|
|
6068
|
-
{
|
|
6069
|
-
id: "codex",
|
|
6070
|
-
label: "OpenAI Codex",
|
|
6071
|
-
defaultModel: "codex-mini-latest",
|
|
6072
|
-
defaultEndpoint: "https://api.openai.com/v1/chat/completions"
|
|
6073
|
-
},
|
|
6074
|
-
{
|
|
6075
|
-
id: "openrouter",
|
|
6076
|
-
label: "OpenRouter",
|
|
6077
|
-
defaultModel: "openai/gpt-4o-mini",
|
|
6078
|
-
defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
|
|
6079
|
-
},
|
|
6080
|
-
{
|
|
6081
|
-
id: "opencode",
|
|
6082
|
-
label: "OpenCode",
|
|
6083
|
-
defaultModel: "opencode/default",
|
|
6084
|
-
defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
|
|
6085
|
-
},
|
|
6086
|
-
{
|
|
6087
|
-
id: "anthropic",
|
|
6088
|
-
label: "Anthropic (Claude)",
|
|
6089
|
-
defaultModel: "claude-3-5-sonnet-latest",
|
|
6090
|
-
defaultEndpoint: "https://api.anthropic.com/v1/messages"
|
|
6091
|
-
},
|
|
6092
|
-
{
|
|
6093
|
-
id: "gemini",
|
|
6094
|
-
label: "Google Gemini",
|
|
6095
|
-
defaultModel: "gemini-2.5-flash",
|
|
6096
|
-
defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
|
|
6097
|
-
},
|
|
6098
|
-
{
|
|
6099
|
-
id: "custom",
|
|
6100
|
-
label: "Custom OpenAI-Compatible",
|
|
6101
|
-
defaultModel: "gpt-4o-mini",
|
|
6102
|
-
defaultEndpoint: "http://localhost:11434/v1/chat/completions"
|
|
6103
|
-
}
|
|
6104
|
-
];
|
|
6105
|
-
var AI_STORAGE_KEY = "nextgen-editor-ai-config";
|
|
6106
|
-
function loadAiConfig() {
|
|
6107
|
-
try {
|
|
6108
|
-
const raw = localStorage.getItem(AI_STORAGE_KEY);
|
|
6109
|
-
if (raw) {
|
|
6110
|
-
const parsed = JSON.parse(raw);
|
|
6111
|
-
if (parsed.provider) {
|
|
6112
|
-
return {
|
|
6113
|
-
provider: parsed.provider,
|
|
6114
|
-
model: parsed.model || "gpt-4o-mini",
|
|
6115
|
-
apiKey: parsed.apiKey || "",
|
|
6116
|
-
endpoint: parsed.endpoint || ""
|
|
6117
|
-
};
|
|
6118
|
-
}
|
|
6119
|
-
}
|
|
6120
|
-
} catch {
|
|
6121
|
-
}
|
|
6122
|
-
return {
|
|
6123
|
-
provider: "openai",
|
|
6124
|
-
model: "gpt-4o-mini",
|
|
6125
|
-
apiKey: "",
|
|
6126
|
-
endpoint: ""
|
|
6127
|
-
};
|
|
6128
|
-
}
|
|
6129
|
-
function saveAiConfig(cfg) {
|
|
6130
|
-
try {
|
|
6131
|
-
localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
|
|
6132
|
-
} catch {
|
|
6133
|
-
}
|
|
6134
|
-
}
|
|
6135
|
-
async function generateAiText(params) {
|
|
6136
|
-
const { config, mode, prompt, context } = params;
|
|
6137
|
-
const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
|
|
6138
|
-
const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
|
|
6139
|
-
const model = (config.model || preset.defaultModel).trim();
|
|
6140
|
-
const apiKey = config.apiKey.trim();
|
|
6141
|
-
if (!apiKey && config.provider !== "custom") {
|
|
6142
|
-
throw new Error("Please add an API key in Settings first.");
|
|
6143
|
-
}
|
|
6144
|
-
const systemPrompt = mode === "continue" ? "You are a concise writing assistant inside a block editor. Continue the document naturally from the provided context in 1-3 clear paragraphs. Return only the continuation text." : "You are a helpful writing and editing assistant inside a block editor. Fulfill the user request concisely using the provided document context.";
|
|
6145
|
-
const userContent = mode === "continue" ? `Document context:
|
|
6146
|
-
${context || "(Empty document)"}
|
|
6147
|
-
|
|
6148
|
-
Continue writing naturally:` : `Document context:
|
|
6149
|
-
${context || "(Empty document)"}
|
|
6150
|
-
|
|
6151
|
-
User request: ${prompt}`;
|
|
6152
|
-
if (config.provider === "gemini") {
|
|
6153
|
-
const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
|
|
6154
|
-
model
|
|
6155
|
-
)}:generateContent?key=${encodeURIComponent(apiKey)}`;
|
|
6156
|
-
const res2 = await fetch(url, {
|
|
6157
|
-
method: "POST",
|
|
6158
|
-
headers: { "Content-Type": "application/json" },
|
|
6159
|
-
body: JSON.stringify({
|
|
6160
|
-
contents: [{ parts: [{ text: `${systemPrompt}
|
|
6161
|
-
|
|
6162
|
-
${userContent}` }] }]
|
|
6163
|
-
})
|
|
6164
|
-
});
|
|
6165
|
-
if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
|
|
6166
|
-
const json2 = await res2.json();
|
|
6167
|
-
return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
|
|
6168
|
-
}
|
|
6169
|
-
if (config.provider === "anthropic") {
|
|
6170
|
-
const res2 = await fetch(endpoint, {
|
|
6171
|
-
method: "POST",
|
|
6172
|
-
headers: {
|
|
6173
|
-
"Content-Type": "application/json",
|
|
6174
|
-
"x-api-key": apiKey,
|
|
6175
|
-
"anthropic-version": "2023-06-01"
|
|
6176
|
-
},
|
|
6177
|
-
body: JSON.stringify({
|
|
6178
|
-
model,
|
|
6179
|
-
max_tokens: 1024,
|
|
6180
|
-
system: systemPrompt,
|
|
6181
|
-
messages: [{ role: "user", content: userContent }]
|
|
6182
|
-
})
|
|
6183
|
-
});
|
|
6184
|
-
if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
|
|
6185
|
-
const json2 = await res2.json();
|
|
6186
|
-
return json2.content?.[0]?.text?.trim() || "";
|
|
6187
|
-
}
|
|
6188
|
-
const headers = {
|
|
6189
|
-
"Content-Type": "application/json"
|
|
7163
|
+
hotkey: HotkeyTool,
|
|
7164
|
+
emoji: EmojiTool,
|
|
7165
|
+
scratch: ScratchTool,
|
|
7166
|
+
alert: AlertTool,
|
|
7167
|
+
// 2. Common rich media & layout
|
|
7168
|
+
upload: UploadTool,
|
|
7169
|
+
audio: AudioPlayerTool,
|
|
7170
|
+
musicCarousel: MusicCarouselTool,
|
|
7171
|
+
embed: CustomEmbedTool,
|
|
7172
|
+
gallery: LightboxGalleryTool,
|
|
7173
|
+
masonry: MasonryTool,
|
|
7174
|
+
carousel: CarouselTool,
|
|
7175
|
+
bento: BentoTool,
|
|
7176
|
+
...includeLayout ? { layout: LayoutTool } : {},
|
|
7177
|
+
tabs: TabsTool,
|
|
7178
|
+
accordion: AccordionTool,
|
|
7179
|
+
toggleh1: ToggleH1Tool,
|
|
7180
|
+
toggleh2: ToggleH2Tool,
|
|
7181
|
+
toggleh3: ToggleH3Tool,
|
|
7182
|
+
// 3. Structured & editorial blocks
|
|
7183
|
+
flashcards: FlashcardTool,
|
|
7184
|
+
chart: ChartTool,
|
|
7185
|
+
footnotes: FootnotesTool,
|
|
7186
|
+
quiz: QuizTool,
|
|
7187
|
+
kanban: KanbanTool,
|
|
7188
|
+
timer: FocusTimerTool,
|
|
7189
|
+
poll: PollTool,
|
|
7190
|
+
faq: FaqTool,
|
|
7191
|
+
todo: TaskChecklistTool,
|
|
7192
|
+
eisenhower: EisenhowerMatrixTool,
|
|
7193
|
+
form: FormBuilderTool,
|
|
7194
|
+
latex: LatexTool,
|
|
7195
|
+
mermaid: MermaidTool,
|
|
7196
|
+
bookmark: BookmarkTool,
|
|
7197
|
+
steps: StepsTool,
|
|
7198
|
+
diff: DiffTool,
|
|
7199
|
+
video: VideoTool,
|
|
7200
|
+
changelog: ChangelogTool,
|
|
7201
|
+
social: SocialTool,
|
|
7202
|
+
excalidraw: ExcalidrawTool,
|
|
7203
|
+
pullquote: PullQuoteTool,
|
|
7204
|
+
timeline: TimelineTool,
|
|
7205
|
+
stats: StatsTool,
|
|
7206
|
+
proscons: ProsConsTool,
|
|
7207
|
+
cards: CardsTool,
|
|
7208
|
+
badges: BadgesTool,
|
|
7209
|
+
tags: TagsTool,
|
|
7210
|
+
button: ButtonTool,
|
|
7211
|
+
dialogue: DialogueTool,
|
|
7212
|
+
// 4. Specialized / least frequent blocks
|
|
7213
|
+
gif: GifTool,
|
|
7214
|
+
compare: CompareTool,
|
|
7215
|
+
slides: SlidesTool,
|
|
7216
|
+
spoiler: SpoilerTool,
|
|
7217
|
+
collapsible: CollapsibleTool,
|
|
7218
|
+
attaches: AttachTool,
|
|
7219
|
+
nestedlist: NestedList,
|
|
7220
|
+
simpleImage: SimpleImage,
|
|
7221
|
+
comment: CommentTool,
|
|
7222
|
+
continueWriting: ContinueWritingTool,
|
|
7223
|
+
askAi: AskAiTool,
|
|
7224
|
+
today: TodayTool,
|
|
7225
|
+
export: ExportTriggerTool,
|
|
7226
|
+
settings: SettingsTriggerTool,
|
|
7227
|
+
// Inline toolbar tools
|
|
7228
|
+
inlineCode: InlineCode,
|
|
7229
|
+
marker: MarkerInline,
|
|
7230
|
+
textColor: ColorInline,
|
|
7231
|
+
aiRewrite: AiRewriteInline,
|
|
7232
|
+
spoilerInline: SpoilerInline,
|
|
7233
|
+
underline: Underline,
|
|
7234
|
+
strikethrough: Strikethrough,
|
|
7235
|
+
hyperlink: HyperlinkInline,
|
|
7236
|
+
mention: MentionInline
|
|
6190
7237
|
};
|
|
6191
|
-
if (
|
|
6192
|
-
|
|
7238
|
+
if (enabledTools && enabledTools.length > 0) {
|
|
7239
|
+
const allowed = new Set(enabledTools);
|
|
7240
|
+
return Object.fromEntries(
|
|
7241
|
+
Object.entries(tools).filter(([key]) => allowed.has(key))
|
|
7242
|
+
);
|
|
6193
7243
|
}
|
|
6194
|
-
|
|
6195
|
-
method: "POST",
|
|
6196
|
-
headers,
|
|
6197
|
-
body: JSON.stringify({
|
|
6198
|
-
model,
|
|
6199
|
-
messages: [
|
|
6200
|
-
{ role: "system", content: systemPrompt },
|
|
6201
|
-
{ role: "user", content: userContent }
|
|
6202
|
-
]
|
|
6203
|
-
})
|
|
6204
|
-
});
|
|
6205
|
-
if (!res.ok) throw new Error(`AI API error (${res.status})`);
|
|
6206
|
-
const json = await res.json();
|
|
6207
|
-
return json.choices?.[0]?.message?.content?.trim() || "";
|
|
7244
|
+
return tools;
|
|
6208
7245
|
}
|
|
6209
7246
|
|
|
6210
7247
|
// src/utils/popoverCategories.ts
|
|
6211
7248
|
var TOOL_CATEGORIES = [
|
|
7249
|
+
{
|
|
7250
|
+
label: "AI",
|
|
7251
|
+
tools: ["continueWriting", "askAi"]
|
|
7252
|
+
},
|
|
6212
7253
|
{
|
|
6213
7254
|
label: "Text & Style",
|
|
6214
7255
|
tools: [
|
|
@@ -6218,13 +7259,13 @@ var TOOL_CATEGORIES = [
|
|
|
6218
7259
|
"paragraph",
|
|
6219
7260
|
"list",
|
|
6220
7261
|
"nestedlist",
|
|
6221
|
-
"checklist",
|
|
6222
7262
|
"quote",
|
|
6223
7263
|
"pullquote",
|
|
6224
7264
|
"delimiter",
|
|
6225
7265
|
"callout",
|
|
6226
7266
|
"hotkey",
|
|
6227
7267
|
"emoji",
|
|
7268
|
+
"today",
|
|
6228
7269
|
"scratch",
|
|
6229
7270
|
"alert",
|
|
6230
7271
|
"badges",
|
|
@@ -6264,6 +7305,8 @@ var TOOL_CATEGORIES = [
|
|
|
6264
7305
|
"audio",
|
|
6265
7306
|
"musicCarousel",
|
|
6266
7307
|
"embed",
|
|
7308
|
+
"bookmark",
|
|
7309
|
+
"video",
|
|
6267
7310
|
"attaches",
|
|
6268
7311
|
"excalidraw"
|
|
6269
7312
|
]
|
|
@@ -6273,6 +7316,11 @@ var TOOL_CATEGORIES = [
|
|
|
6273
7316
|
tools: [
|
|
6274
7317
|
"code",
|
|
6275
7318
|
"latex",
|
|
7319
|
+
"mermaid",
|
|
7320
|
+
"diff",
|
|
7321
|
+
"steps",
|
|
7322
|
+
"changelog",
|
|
7323
|
+
"social",
|
|
6276
7324
|
"chart",
|
|
6277
7325
|
"table",
|
|
6278
7326
|
"stats",
|
|
@@ -6291,13 +7339,9 @@ var TOOL_CATEGORIES = [
|
|
|
6291
7339
|
"slides"
|
|
6292
7340
|
]
|
|
6293
7341
|
},
|
|
6294
|
-
{
|
|
6295
|
-
label: "AI",
|
|
6296
|
-
tools: ["continueWriting", "askAi"]
|
|
6297
|
-
},
|
|
6298
7342
|
{
|
|
6299
7343
|
label: "Settings",
|
|
6300
|
-
tools: ["settings"]
|
|
7344
|
+
tools: ["export", "settings"]
|
|
6301
7345
|
}
|
|
6302
7346
|
];
|
|
6303
7347
|
var SIMPLE_MODE_TOOLS = [
|
|
@@ -6322,9 +7366,8 @@ var TOOL_LABELS = {
|
|
|
6322
7366
|
h2: "Heading 2",
|
|
6323
7367
|
h3: "Heading 3",
|
|
6324
7368
|
paragraph: "Paragraph",
|
|
6325
|
-
list: "List",
|
|
7369
|
+
list: "List (Ordered / Unordered / Checklist)",
|
|
6326
7370
|
nestedlist: "Nested List",
|
|
6327
|
-
checklist: "Checklist",
|
|
6328
7371
|
quote: "Quote",
|
|
6329
7372
|
pullquote: "Pull Quote",
|
|
6330
7373
|
delimiter: "Delimiter",
|
|
@@ -6364,6 +7407,14 @@ var TOOL_LABELS = {
|
|
|
6364
7407
|
excalidraw: "Excalidraw",
|
|
6365
7408
|
code: "Code Block",
|
|
6366
7409
|
latex: "LaTeX Math",
|
|
7410
|
+
mermaid: "Mermaid Diagram",
|
|
7411
|
+
bookmark: "Bookmark Card",
|
|
7412
|
+
steps: "Steps Walkthrough",
|
|
7413
|
+
diff: "Code Diff",
|
|
7414
|
+
video: "Video Player",
|
|
7415
|
+
changelog: "Changelog",
|
|
7416
|
+
social: "Social Quote",
|
|
7417
|
+
today: "Today Date",
|
|
6367
7418
|
chart: "Data Chart",
|
|
6368
7419
|
table: "Table",
|
|
6369
7420
|
stats: "Stats",
|
|
@@ -6382,6 +7433,7 @@ var TOOL_LABELS = {
|
|
|
6382
7433
|
slides: "Slides",
|
|
6383
7434
|
continueWriting: "Continue Writing",
|
|
6384
7435
|
askAi: "Ask AI",
|
|
7436
|
+
export: "Export / Import",
|
|
6385
7437
|
settings: "Settings"
|
|
6386
7438
|
};
|
|
6387
7439
|
function attachPopoverCategoryHeaders(container) {
|
|
@@ -6409,18 +7461,25 @@ function attachPopoverCategoryHeaders(container) {
|
|
|
6409
7461
|
titleEl.textContent = "Paragraph";
|
|
6410
7462
|
}
|
|
6411
7463
|
}
|
|
6412
|
-
if (name)
|
|
6413
|
-
|
|
7464
|
+
if (name) {
|
|
7465
|
+
const arr = byName.get(name) || [];
|
|
7466
|
+
arr.push(el);
|
|
7467
|
+
byName.set(name, arr);
|
|
7468
|
+
} else {
|
|
7469
|
+
uncategorized.push(el);
|
|
7470
|
+
}
|
|
6414
7471
|
});
|
|
6415
7472
|
const frag = document.createDocumentFragment();
|
|
6416
7473
|
const placed = /* @__PURE__ */ new Set();
|
|
6417
7474
|
for (const group of TOOL_CATEGORIES) {
|
|
6418
7475
|
const matched = [];
|
|
6419
7476
|
for (const toolName of group.tools) {
|
|
6420
|
-
const
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
7477
|
+
const els = byName.get(toolName) || [];
|
|
7478
|
+
for (const el of els) {
|
|
7479
|
+
if (!placed.has(el)) {
|
|
7480
|
+
matched.push(el);
|
|
7481
|
+
placed.add(el);
|
|
7482
|
+
}
|
|
6424
7483
|
}
|
|
6425
7484
|
}
|
|
6426
7485
|
if (matched.length > 0) {
|
|
@@ -6597,6 +7656,28 @@ var ClassicToolbar = ({
|
|
|
6597
7656
|
/* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn ng-ct-s", onMouseDown: keepSelection, onClick: () => exec("strikeThrough"), title: "Strikethrough", children: "S" }),
|
|
6598
7657
|
/* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => toggleInlineTag("code"), title: "Inline Code", children: "<>" }),
|
|
6599
7658
|
/* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn ng-ct-highlight", onMouseDown: keepSelection, onClick: () => toggleInlineTag("mark"), title: "Highlight", children: "A" }),
|
|
7659
|
+
/* @__PURE__ */ jsx(
|
|
7660
|
+
"input",
|
|
7661
|
+
{
|
|
7662
|
+
type: "color",
|
|
7663
|
+
className: "ng-ct-color",
|
|
7664
|
+
title: "Text Color",
|
|
7665
|
+
"aria-label": "Text Color",
|
|
7666
|
+
defaultValue: "#18181b",
|
|
7667
|
+
onChange: (e) => exec("foreColor", e.target.value)
|
|
7668
|
+
}
|
|
7669
|
+
),
|
|
7670
|
+
/* @__PURE__ */ jsx(
|
|
7671
|
+
"input",
|
|
7672
|
+
{
|
|
7673
|
+
type: "color",
|
|
7674
|
+
className: "ng-ct-color",
|
|
7675
|
+
title: "Highlight Color",
|
|
7676
|
+
"aria-label": "Highlight Color",
|
|
7677
|
+
defaultValue: "#fef08a",
|
|
7678
|
+
onChange: (e) => exec("hiliteColor", e.target.value)
|
|
7679
|
+
}
|
|
7680
|
+
),
|
|
6600
7681
|
/* @__PURE__ */ jsx(
|
|
6601
7682
|
"button",
|
|
6602
7683
|
{
|
|
@@ -6634,7 +7715,7 @@ var ClassicToolbar = ({
|
|
|
6634
7715
|
/* @__PURE__ */ jsx("path", { d: "M4 10h2" }),
|
|
6635
7716
|
/* @__PURE__ */ jsx("path", { d: "M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" })
|
|
6636
7717
|
] }) }),
|
|
6637
|
-
/* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("
|
|
7718
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("list", { style: "checklist", items: [] }), title: "Checklist", children: /* @__PURE__ */ jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
6638
7719
|
/* @__PURE__ */ jsx("rect", { x: "3", y: "5", width: "6", height: "6", rx: "1" }),
|
|
6639
7720
|
/* @__PURE__ */ jsx("path", { d: "m3 17 2 2 4-4" }),
|
|
6640
7721
|
/* @__PURE__ */ jsx("path", { d: "M13 6h8" }),
|
|
@@ -6693,295 +7774,659 @@ var ClassicToolbar = ({
|
|
|
6693
7774
|
setAlignOpen(false);
|
|
6694
7775
|
}, children: "Justify" })
|
|
6695
7776
|
] })
|
|
6696
|
-
] }),
|
|
6697
|
-
/* @__PURE__ */ jsx("span", { className: "ng-ct-sep" }),
|
|
6698
|
-
/* @__PURE__ */ jsxs("div", { className: "ng-ct-dropdown-wrap", children: [
|
|
6699
|
-
/* @__PURE__ */ jsxs(
|
|
6700
|
-
"button",
|
|
6701
|
-
{
|
|
6702
|
-
type: "button",
|
|
6703
|
-
className: "ng-ct-insert-btn",
|
|
6704
|
-
onClick: () => {
|
|
6705
|
-
setInsertOpen((v) => !v);
|
|
6706
|
-
setAlignOpen(false);
|
|
6707
|
-
},
|
|
6708
|
-
children: [
|
|
6709
|
-
/* @__PURE__ */ jsx("span", { children: "+ Insert" }),
|
|
6710
|
-
/* @__PURE__ */ jsx("span", { className: "ng-ct-caret", children: "\u25BE" })
|
|
6711
|
-
]
|
|
6712
|
-
}
|
|
6713
|
-
),
|
|
6714
|
-
insertOpen && /* @__PURE__ */ jsx("div", { className: "ng-ct-menu ng-ct-insert-menu", children: visibleInsertItems.map((item) => /* @__PURE__ */ jsxs(
|
|
6715
|
-
"button",
|
|
6716
|
-
{
|
|
6717
|
-
type: "button",
|
|
6718
|
-
onClick: () => insertBlock(item.tool),
|
|
6719
|
-
children: [
|
|
6720
|
-
/* @__PURE__ */ jsx("span", { children: item.label }),
|
|
6721
|
-
/* @__PURE__ */ jsx("span", { className: "ng-ct-cat", children: item.category })
|
|
6722
|
-
]
|
|
6723
|
-
},
|
|
6724
|
-
item.tool
|
|
6725
|
-
)) })
|
|
7777
|
+
] }),
|
|
7778
|
+
/* @__PURE__ */ jsx("span", { className: "ng-ct-sep" }),
|
|
7779
|
+
/* @__PURE__ */ jsxs("div", { className: "ng-ct-dropdown-wrap", children: [
|
|
7780
|
+
/* @__PURE__ */ jsxs(
|
|
7781
|
+
"button",
|
|
7782
|
+
{
|
|
7783
|
+
type: "button",
|
|
7784
|
+
className: "ng-ct-insert-btn",
|
|
7785
|
+
onClick: () => {
|
|
7786
|
+
setInsertOpen((v) => !v);
|
|
7787
|
+
setAlignOpen(false);
|
|
7788
|
+
},
|
|
7789
|
+
children: [
|
|
7790
|
+
/* @__PURE__ */ jsx("span", { children: "+ Insert" }),
|
|
7791
|
+
/* @__PURE__ */ jsx("span", { className: "ng-ct-caret", children: "\u25BE" })
|
|
7792
|
+
]
|
|
7793
|
+
}
|
|
7794
|
+
),
|
|
7795
|
+
insertOpen && /* @__PURE__ */ jsx("div", { className: "ng-ct-menu ng-ct-insert-menu", children: visibleInsertItems.map((item) => /* @__PURE__ */ jsxs(
|
|
7796
|
+
"button",
|
|
7797
|
+
{
|
|
7798
|
+
type: "button",
|
|
7799
|
+
onClick: () => insertBlock(item.tool),
|
|
7800
|
+
children: [
|
|
7801
|
+
/* @__PURE__ */ jsx("span", { children: item.label }),
|
|
7802
|
+
/* @__PURE__ */ jsx("span", { className: "ng-ct-cat", children: item.category })
|
|
7803
|
+
]
|
|
7804
|
+
},
|
|
7805
|
+
item.tool
|
|
7806
|
+
)) })
|
|
7807
|
+
] })
|
|
7808
|
+
] });
|
|
7809
|
+
};
|
|
7810
|
+
|
|
7811
|
+
// src/components/SettingsModal.tsx
|
|
7812
|
+
import { useState as useState2 } from "react";
|
|
7813
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
7814
|
+
var SettingsModal = ({
|
|
7815
|
+
open,
|
|
7816
|
+
theme,
|
|
7817
|
+
docWidth,
|
|
7818
|
+
mode,
|
|
7819
|
+
showStats,
|
|
7820
|
+
aiConfig,
|
|
7821
|
+
selectedTools,
|
|
7822
|
+
allowedTools,
|
|
7823
|
+
canConfigureTools,
|
|
7824
|
+
developerRestricted,
|
|
7825
|
+
accessNoticeText,
|
|
7826
|
+
onChangeTheme,
|
|
7827
|
+
onChangeDocWidth,
|
|
7828
|
+
onChangeMode,
|
|
7829
|
+
onChangeShowStats,
|
|
7830
|
+
onChangeAiConfig,
|
|
7831
|
+
onChangeSelectedTools,
|
|
7832
|
+
onClose
|
|
7833
|
+
}) => {
|
|
7834
|
+
const [showKey, setShowKey] = useState2(false);
|
|
7835
|
+
const [toolFilter, setToolFilter] = useState2("");
|
|
7836
|
+
const [activeTab, setActiveTab] = useState2("appearance");
|
|
7837
|
+
if (!open) return null;
|
|
7838
|
+
const selectedSet = new Set(selectedTools);
|
|
7839
|
+
const toggleTool = (tool) => {
|
|
7840
|
+
const next = new Set(selectedTools);
|
|
7841
|
+
if (next.has(tool)) next.delete(tool);
|
|
7842
|
+
else next.add(tool);
|
|
7843
|
+
next.add("settings");
|
|
7844
|
+
onChangeSelectedTools(Array.from(next));
|
|
7845
|
+
};
|
|
7846
|
+
const handleProviderChange = (providerId) => {
|
|
7847
|
+
const preset = AI_PROVIDER_PRESETS.find((p) => p.id === providerId);
|
|
7848
|
+
onChangeAiConfig({
|
|
7849
|
+
...aiConfig,
|
|
7850
|
+
provider: providerId,
|
|
7851
|
+
model: preset?.defaultModel || aiConfig.model,
|
|
7852
|
+
endpoint: preset?.defaultEndpoint || ""
|
|
7853
|
+
});
|
|
7854
|
+
};
|
|
7855
|
+
return /* @__PURE__ */ jsx2("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ jsxs2("div", { className: "ng-modal ng-modal-wide", children: [
|
|
7856
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-modal-head", children: [
|
|
7857
|
+
/* @__PURE__ */ jsxs2("div", { children: [
|
|
7858
|
+
/* @__PURE__ */ jsx2("h3", { children: "Editor Settings" }),
|
|
7859
|
+
/* @__PURE__ */ jsx2("p", { children: "Configure appearance, AI provider, and registered components." })
|
|
7860
|
+
] }),
|
|
7861
|
+
/* @__PURE__ */ jsx2("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
|
|
7862
|
+
] }),
|
|
7863
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-modal-layout", children: [
|
|
7864
|
+
/* @__PURE__ */ jsx2("aside", { className: "ng-modal-sidebar", role: "tablist", "aria-label": "Settings sections", children: [
|
|
7865
|
+
{ id: "appearance", label: "Appearance" },
|
|
7866
|
+
{ id: "ai", label: "AI Provider" },
|
|
7867
|
+
{ id: "components", label: `Components (${selectedSet.size})` }
|
|
7868
|
+
].map((t) => /* @__PURE__ */ jsx2(
|
|
7869
|
+
"button",
|
|
7870
|
+
{
|
|
7871
|
+
type: "button",
|
|
7872
|
+
role: "tab",
|
|
7873
|
+
"aria-selected": activeTab === t.id,
|
|
7874
|
+
className: `ng-modal-tab${activeTab === t.id ? " is-active" : ""}`,
|
|
7875
|
+
onClick: () => setActiveTab(t.id),
|
|
7876
|
+
children: t.label
|
|
7877
|
+
},
|
|
7878
|
+
t.id
|
|
7879
|
+
)) }),
|
|
7880
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-modal-main", children: [
|
|
7881
|
+
activeTab === "appearance" && /* @__PURE__ */ jsxs2("div", { className: "ng-modal-panel", children: [
|
|
7882
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7883
|
+
/* @__PURE__ */ jsx2("label", { children: "Appearance" }),
|
|
7884
|
+
/* @__PURE__ */ jsxs2(
|
|
7885
|
+
"select",
|
|
7886
|
+
{
|
|
7887
|
+
className: "cdx-input editor-form-select",
|
|
7888
|
+
value: theme,
|
|
7889
|
+
onChange: (e) => onChangeTheme(e.target.value),
|
|
7890
|
+
children: [
|
|
7891
|
+
/* @__PURE__ */ jsx2("option", { value: "inherit", children: "Inherit from Host App" }),
|
|
7892
|
+
/* @__PURE__ */ jsx2("option", { value: "light", children: "Light (White)" }),
|
|
7893
|
+
/* @__PURE__ */ jsx2("option", { value: "dark", children: "Dark (Black)" })
|
|
7894
|
+
]
|
|
7895
|
+
}
|
|
7896
|
+
)
|
|
7897
|
+
] }),
|
|
7898
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7899
|
+
/* @__PURE__ */ jsx2("label", { children: "Document Width" }),
|
|
7900
|
+
/* @__PURE__ */ jsx2("div", { className: "ng-segmented", children: [
|
|
7901
|
+
{ id: "narrow", label: "Narrow" },
|
|
7902
|
+
{ id: "standard", label: "Standard" },
|
|
7903
|
+
{ id: "full", label: "Full-Width" }
|
|
7904
|
+
].map((w) => /* @__PURE__ */ jsx2(
|
|
7905
|
+
"button",
|
|
7906
|
+
{
|
|
7907
|
+
type: "button",
|
|
7908
|
+
className: `excalidraw-btn${docWidth === w.id ? " is-active" : ""}`,
|
|
7909
|
+
onClick: () => onChangeDocWidth(w.id),
|
|
7910
|
+
children: w.label
|
|
7911
|
+
},
|
|
7912
|
+
w.id
|
|
7913
|
+
)) })
|
|
7914
|
+
] }),
|
|
7915
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7916
|
+
/* @__PURE__ */ jsx2("label", { children: "Editor Mode" }),
|
|
7917
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-segmented", children: [
|
|
7918
|
+
/* @__PURE__ */ jsx2(
|
|
7919
|
+
"button",
|
|
7920
|
+
{
|
|
7921
|
+
type: "button",
|
|
7922
|
+
className: `excalidraw-btn${mode === "block" ? " is-active" : ""}`,
|
|
7923
|
+
onClick: () => onChangeMode("block"),
|
|
7924
|
+
children: "Block Editor (Full)"
|
|
7925
|
+
}
|
|
7926
|
+
),
|
|
7927
|
+
/* @__PURE__ */ jsx2(
|
|
7928
|
+
"button",
|
|
7929
|
+
{
|
|
7930
|
+
type: "button",
|
|
7931
|
+
className: `excalidraw-btn${mode === "simple" ? " is-active" : ""}`,
|
|
7932
|
+
onClick: () => onChangeMode("simple"),
|
|
7933
|
+
children: "Simple Mode"
|
|
7934
|
+
}
|
|
7935
|
+
)
|
|
7936
|
+
] })
|
|
7937
|
+
] }),
|
|
7938
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field ng-field-inline", children: [
|
|
7939
|
+
/* @__PURE__ */ jsx2("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
|
|
7940
|
+
/* @__PURE__ */ jsx2(
|
|
7941
|
+
"input",
|
|
7942
|
+
{
|
|
7943
|
+
id: "ng-stats-toggle",
|
|
7944
|
+
type: "checkbox",
|
|
7945
|
+
checked: showStats,
|
|
7946
|
+
onChange: (e) => onChangeShowStats(e.target.checked)
|
|
7947
|
+
}
|
|
7948
|
+
)
|
|
7949
|
+
] })
|
|
7950
|
+
] }),
|
|
7951
|
+
activeTab === "ai" && /* @__PURE__ */ jsxs2("div", { className: "ng-modal-panel", children: [
|
|
7952
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7953
|
+
/* @__PURE__ */ jsx2("label", { children: "AI Provider" }),
|
|
7954
|
+
/* @__PURE__ */ jsx2(
|
|
7955
|
+
"select",
|
|
7956
|
+
{
|
|
7957
|
+
className: "cdx-input editor-form-select",
|
|
7958
|
+
value: aiConfig.provider,
|
|
7959
|
+
onChange: (e) => handleProviderChange(e.target.value),
|
|
7960
|
+
children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ jsx2("option", { value: p.id, children: p.label }, p.id))
|
|
7961
|
+
}
|
|
7962
|
+
)
|
|
7963
|
+
] }),
|
|
7964
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7965
|
+
/* @__PURE__ */ jsx2("label", { children: "Model" }),
|
|
7966
|
+
/* @__PURE__ */ jsx2(
|
|
7967
|
+
"input",
|
|
7968
|
+
{
|
|
7969
|
+
type: "text",
|
|
7970
|
+
className: "cdx-input editor-form-input",
|
|
7971
|
+
value: aiConfig.model,
|
|
7972
|
+
placeholder: "e.g. gpt-4o-mini",
|
|
7973
|
+
onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
|
|
7974
|
+
}
|
|
7975
|
+
)
|
|
7976
|
+
] }),
|
|
7977
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
7978
|
+
/* @__PURE__ */ jsx2("label", { children: "API Key" }),
|
|
7979
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-key-row", children: [
|
|
7980
|
+
/* @__PURE__ */ jsx2(
|
|
7981
|
+
"input",
|
|
7982
|
+
{
|
|
7983
|
+
type: showKey ? "text" : "password",
|
|
7984
|
+
className: "cdx-input editor-form-input",
|
|
7985
|
+
value: aiConfig.apiKey,
|
|
7986
|
+
placeholder: "sk-...",
|
|
7987
|
+
onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
|
|
7988
|
+
}
|
|
7989
|
+
),
|
|
7990
|
+
/* @__PURE__ */ jsx2(
|
|
7991
|
+
"button",
|
|
7992
|
+
{
|
|
7993
|
+
type: "button",
|
|
7994
|
+
className: "excalidraw-btn",
|
|
7995
|
+
onClick: () => setShowKey((s) => !s),
|
|
7996
|
+
children: showKey ? "Hide" : "Show"
|
|
7997
|
+
}
|
|
7998
|
+
)
|
|
7999
|
+
] })
|
|
8000
|
+
] }),
|
|
8001
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
8002
|
+
/* @__PURE__ */ jsx2("label", { children: "Endpoint URL (optional)" }),
|
|
8003
|
+
/* @__PURE__ */ jsx2(
|
|
8004
|
+
"input",
|
|
8005
|
+
{
|
|
8006
|
+
type: "url",
|
|
8007
|
+
className: "cdx-input editor-form-input",
|
|
8008
|
+
value: aiConfig.endpoint || "",
|
|
8009
|
+
placeholder: "Default provider endpoint",
|
|
8010
|
+
onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
|
|
8011
|
+
}
|
|
8012
|
+
)
|
|
8013
|
+
] })
|
|
8014
|
+
] }),
|
|
8015
|
+
activeTab === "components" && /* @__PURE__ */ jsxs2("div", { className: "ng-tools-manager", children: [
|
|
8016
|
+
(developerRestricted || !canConfigureTools) && /* @__PURE__ */ jsxs2("div", { className: "ng-dev-access-bar", role: "status", children: [
|
|
8017
|
+
/* @__PURE__ */ jsx2("strong", { children: "Access Managed by Developer:" }),
|
|
8018
|
+
" ",
|
|
8019
|
+
accessNoticeText || "Some commands are not enabled for this workspace and are hidden."
|
|
8020
|
+
] }),
|
|
8021
|
+
/* @__PURE__ */ jsxs2("div", { className: "ng-tools-header", children: [
|
|
8022
|
+
/* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsxs2("label", { children: [
|
|
8023
|
+
"Registered Components (",
|
|
8024
|
+
selectedSet.size,
|
|
8025
|
+
"/",
|
|
8026
|
+
developerRestricted && allowedTools ? allowedTools.length : ALL_TOOL_NAMES.length,
|
|
8027
|
+
")"
|
|
8028
|
+
] }) }),
|
|
8029
|
+
canConfigureTools && /* @__PURE__ */ jsxs2("div", { className: "ng-tools-actions", children: [
|
|
8030
|
+
/* @__PURE__ */ jsx2(
|
|
8031
|
+
"button",
|
|
8032
|
+
{
|
|
8033
|
+
type: "button",
|
|
8034
|
+
className: "excalidraw-btn",
|
|
8035
|
+
onClick: () => onChangeSelectedTools(
|
|
8036
|
+
developerRestricted && allowedTools ? [...allowedTools] : [...ALL_TOOL_NAMES]
|
|
8037
|
+
),
|
|
8038
|
+
children: "All"
|
|
8039
|
+
}
|
|
8040
|
+
),
|
|
8041
|
+
/* @__PURE__ */ jsx2(
|
|
8042
|
+
"button",
|
|
8043
|
+
{
|
|
8044
|
+
type: "button",
|
|
8045
|
+
className: "excalidraw-btn",
|
|
8046
|
+
onClick: () => {
|
|
8047
|
+
const base = new Set(SIMPLE_MODE_TOOLS);
|
|
8048
|
+
const minimal = developerRestricted && allowedTools ? allowedTools.filter((t) => base.has(t)) : [...SIMPLE_MODE_TOOLS];
|
|
8049
|
+
onChangeSelectedTools(minimal);
|
|
8050
|
+
},
|
|
8051
|
+
children: "Minimal"
|
|
8052
|
+
}
|
|
8053
|
+
)
|
|
8054
|
+
] })
|
|
8055
|
+
] }),
|
|
8056
|
+
/* @__PURE__ */ jsx2(
|
|
8057
|
+
"input",
|
|
8058
|
+
{
|
|
8059
|
+
type: "search",
|
|
8060
|
+
className: "cdx-input editor-form-input",
|
|
8061
|
+
placeholder: "Filter components (e.g. bento, chart, spoiler...)",
|
|
8062
|
+
value: toolFilter,
|
|
8063
|
+
onChange: (e) => setToolFilter(e.target.value)
|
|
8064
|
+
}
|
|
8065
|
+
),
|
|
8066
|
+
/* @__PURE__ */ jsx2("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
|
|
8067
|
+
const q = toolFilter.trim().toLowerCase();
|
|
8068
|
+
const allowedSet = developerRestricted && allowedTools ? new Set(allowedTools) : null;
|
|
8069
|
+
const visible = group.tools.filter((t) => {
|
|
8070
|
+
if (allowedSet && !allowedSet.has(t)) return false;
|
|
8071
|
+
const label = (TOOL_LABELS[t] || t).toLowerCase();
|
|
8072
|
+
return !q || label.includes(q) || t.toLowerCase().includes(q);
|
|
8073
|
+
});
|
|
8074
|
+
if (!visible.length) return null;
|
|
8075
|
+
return /* @__PURE__ */ jsxs2("div", { className: "ng-tools-group", children: [
|
|
8076
|
+
/* @__PURE__ */ jsx2("div", { className: "ng-tools-group-title", children: group.label }),
|
|
8077
|
+
/* @__PURE__ */ jsx2("div", { className: "ng-tools-grid", children: visible.map((tool) => {
|
|
8078
|
+
const checked = selectedSet.has(tool);
|
|
8079
|
+
return /* @__PURE__ */ jsxs2(
|
|
8080
|
+
"label",
|
|
8081
|
+
{
|
|
8082
|
+
className: `ng-tool-chip${checked ? " is-checked" : ""}${!canConfigureTools ? " is-locked" : ""}`,
|
|
8083
|
+
children: [
|
|
8084
|
+
/* @__PURE__ */ jsx2(
|
|
8085
|
+
"input",
|
|
8086
|
+
{
|
|
8087
|
+
type: "checkbox",
|
|
8088
|
+
checked,
|
|
8089
|
+
disabled: !canConfigureTools,
|
|
8090
|
+
onChange: () => {
|
|
8091
|
+
if (canConfigureTools) toggleTool(tool);
|
|
8092
|
+
}
|
|
8093
|
+
}
|
|
8094
|
+
),
|
|
8095
|
+
/* @__PURE__ */ jsx2("span", { children: TOOL_LABELS[tool] || tool })
|
|
8096
|
+
]
|
|
8097
|
+
},
|
|
8098
|
+
tool
|
|
8099
|
+
);
|
|
8100
|
+
}) })
|
|
8101
|
+
] }, group.label);
|
|
8102
|
+
}) })
|
|
8103
|
+
] })
|
|
8104
|
+
] })
|
|
6726
8105
|
] })
|
|
6727
|
-
] });
|
|
8106
|
+
] }) });
|
|
6728
8107
|
};
|
|
6729
8108
|
|
|
6730
|
-
// src/components/
|
|
6731
|
-
import { useState as
|
|
6732
|
-
|
|
6733
|
-
|
|
8109
|
+
// src/components/ExportModal.tsx
|
|
8110
|
+
import { useMemo, useState as useState3 } from "react";
|
|
8111
|
+
|
|
8112
|
+
// src/utils/markdown.ts
|
|
8113
|
+
function stripHtmlTags(html) {
|
|
8114
|
+
return String(html == null ? "" : html).replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|li)>/gi, "\n").replace(/<[^>]+>/g, "").replace(/ /g, " ").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/'/g, "'").trim();
|
|
8115
|
+
}
|
|
8116
|
+
function blocksToMarkdown(data) {
|
|
8117
|
+
if (!data || !Array.isArray(data.blocks)) return "";
|
|
8118
|
+
const parts = [];
|
|
8119
|
+
for (const block of data.blocks) {
|
|
8120
|
+
const d = block.data || {};
|
|
8121
|
+
switch (block.type) {
|
|
8122
|
+
case "header":
|
|
8123
|
+
case "h1":
|
|
8124
|
+
case "h2":
|
|
8125
|
+
case "h3": {
|
|
8126
|
+
const lvl = block.type === "h1" ? 1 : block.type === "h2" ? 2 : block.type === "h3" ? 3 : Number(d.level) || 2;
|
|
8127
|
+
parts.push(`${"#".repeat(Math.min(6, Math.max(1, lvl)))} ${stripHtmlTags(d.text)}`);
|
|
8128
|
+
break;
|
|
8129
|
+
}
|
|
8130
|
+
case "paragraph":
|
|
8131
|
+
parts.push(stripHtmlTags(d.text));
|
|
8132
|
+
break;
|
|
8133
|
+
case "quote":
|
|
8134
|
+
case "pullquote": {
|
|
8135
|
+
const quote = stripHtmlTags(d.text).split("\n").map((l) => `> ${l}`).join("\n");
|
|
8136
|
+
const cap = d.caption ? `
|
|
8137
|
+
> \u2014 ${stripHtmlTags(d.caption)}` : "";
|
|
8138
|
+
parts.push(`${quote}${cap}`);
|
|
8139
|
+
break;
|
|
8140
|
+
}
|
|
8141
|
+
case "list":
|
|
8142
|
+
case "nestedlist": {
|
|
8143
|
+
const ordered = d.style === "ordered";
|
|
8144
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
8145
|
+
const lines = items.map((item, idx) => {
|
|
8146
|
+
const txt = typeof item === "string" ? item : item?.content || item?.text || "";
|
|
8147
|
+
return `${ordered ? `${idx + 1}.` : "-"} ${stripHtmlTags(txt)}`;
|
|
8148
|
+
});
|
|
8149
|
+
parts.push(lines.join("\n"));
|
|
8150
|
+
break;
|
|
8151
|
+
}
|
|
8152
|
+
case "checklist":
|
|
8153
|
+
case "todo": {
|
|
8154
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
8155
|
+
parts.push(
|
|
8156
|
+
items.map((item) => `- [${item.checked || item.done ? "x" : " "}] ${stripHtmlTags(item.text || item.title)}`).join("\n")
|
|
8157
|
+
);
|
|
8158
|
+
break;
|
|
8159
|
+
}
|
|
8160
|
+
case "code":
|
|
8161
|
+
parts.push(`\`\`\`${d.language || ""}
|
|
8162
|
+
${d.code || ""}
|
|
8163
|
+
\`\`\``);
|
|
8164
|
+
break;
|
|
8165
|
+
case "mermaid":
|
|
8166
|
+
parts.push(`\`\`\`mermaid
|
|
8167
|
+
${d.code || ""}
|
|
8168
|
+
\`\`\``);
|
|
8169
|
+
break;
|
|
8170
|
+
case "latex":
|
|
8171
|
+
parts.push(`$$
|
|
8172
|
+
${d.tex || ""}
|
|
8173
|
+
$$`);
|
|
8174
|
+
break;
|
|
8175
|
+
case "delimiter":
|
|
8176
|
+
parts.push("---");
|
|
8177
|
+
break;
|
|
8178
|
+
case "image":
|
|
8179
|
+
case "simpleImage": {
|
|
8180
|
+
const url = d.file?.url || d.url || "";
|
|
8181
|
+
if (url) parts.push(``);
|
|
8182
|
+
break;
|
|
8183
|
+
}
|
|
8184
|
+
case "bookmark":
|
|
8185
|
+
parts.push(`[${d.title || d.url || "Link"}](${d.url || "#"})`);
|
|
8186
|
+
break;
|
|
8187
|
+
case "steps": {
|
|
8188
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
8189
|
+
parts.push(
|
|
8190
|
+
items.map((s, i) => `${i + 1}. **${s.title || ""}** \u2014 ${s.body || ""}`).join("\n")
|
|
8191
|
+
);
|
|
8192
|
+
break;
|
|
8193
|
+
}
|
|
8194
|
+
case "diff":
|
|
8195
|
+
parts.push(`\`\`\`diff
|
|
8196
|
+
- ${String(d.before || "").replace(/\n/g, "\n- ")}
|
|
8197
|
+
+ ${String(d.after || "").replace(/\n/g, "\n+ ")}
|
|
8198
|
+
\`\`\``);
|
|
8199
|
+
break;
|
|
8200
|
+
case "changelog": {
|
|
8201
|
+
const items = Array.isArray(d.items) ? d.items : [];
|
|
8202
|
+
parts.push(
|
|
8203
|
+
`### ${d.version || "Release"} (${d.date || ""})
|
|
8204
|
+
` + items.map((i) => `- **${(i.kind || "added").toUpperCase()}**: ${i.text || ""}`).join("\n")
|
|
8205
|
+
);
|
|
8206
|
+
break;
|
|
8207
|
+
}
|
|
8208
|
+
case "social":
|
|
8209
|
+
parts.push(`> ${d.text || ""}
|
|
8210
|
+
> \u2014 ${d.author || ""} (${d.handle || ""})`);
|
|
8211
|
+
break;
|
|
8212
|
+
case "today":
|
|
8213
|
+
parts.push(`\u{1F4C5} ${d.date || ""}`);
|
|
8214
|
+
break;
|
|
8215
|
+
default:
|
|
8216
|
+
if (d.text) parts.push(stripHtmlTags(d.text));
|
|
8217
|
+
break;
|
|
8218
|
+
}
|
|
8219
|
+
}
|
|
8220
|
+
return parts.filter(Boolean).join("\n\n");
|
|
8221
|
+
}
|
|
8222
|
+
function markdownToBlocks(markdown) {
|
|
8223
|
+
const lines = markdown.replace(/\r\n/g, "\n").split("\n");
|
|
8224
|
+
const blocks = [];
|
|
8225
|
+
let i = 0;
|
|
8226
|
+
while (i < lines.length) {
|
|
8227
|
+
const line = lines[i];
|
|
8228
|
+
const trimmed = line.trim();
|
|
8229
|
+
if (!trimmed) {
|
|
8230
|
+
i += 1;
|
|
8231
|
+
continue;
|
|
8232
|
+
}
|
|
8233
|
+
if (trimmed.startsWith("```")) {
|
|
8234
|
+
const lang = trimmed.slice(3).trim();
|
|
8235
|
+
const codeLines = [];
|
|
8236
|
+
i += 1;
|
|
8237
|
+
while (i < lines.length && !lines[i].trim().startsWith("```")) {
|
|
8238
|
+
codeLines.push(lines[i]);
|
|
8239
|
+
i += 1;
|
|
8240
|
+
}
|
|
8241
|
+
i += 1;
|
|
8242
|
+
if (lang === "mermaid") {
|
|
8243
|
+
blocks.push({ type: "mermaid", data: { code: codeLines.join("\n") } });
|
|
8244
|
+
} else {
|
|
8245
|
+
blocks.push({ type: "code", data: { code: codeLines.join("\n"), language: lang || void 0 } });
|
|
8246
|
+
}
|
|
8247
|
+
continue;
|
|
8248
|
+
}
|
|
8249
|
+
const headingMatch = trimmed.match(/^(#{1,3})\s+(.+)$/);
|
|
8250
|
+
if (headingMatch) {
|
|
8251
|
+
const level = headingMatch[1].length;
|
|
8252
|
+
const type = level === 1 ? "h1" : level === 2 ? "h2" : "h3";
|
|
8253
|
+
blocks.push({ type, data: { text: headingMatch[2], level } });
|
|
8254
|
+
i += 1;
|
|
8255
|
+
continue;
|
|
8256
|
+
}
|
|
8257
|
+
if (/^[-*_]{3,}$/.test(trimmed)) {
|
|
8258
|
+
blocks.push({ type: "delimiter", data: {} });
|
|
8259
|
+
i += 1;
|
|
8260
|
+
continue;
|
|
8261
|
+
}
|
|
8262
|
+
if (trimmed.startsWith("> ")) {
|
|
8263
|
+
const quoteLines = [];
|
|
8264
|
+
while (i < lines.length && lines[i].trim().startsWith("> ")) {
|
|
8265
|
+
quoteLines.push(lines[i].trim().slice(2));
|
|
8266
|
+
i += 1;
|
|
8267
|
+
}
|
|
8268
|
+
blocks.push({ type: "quote", data: { text: quoteLines.join("\n"), caption: "" } });
|
|
8269
|
+
continue;
|
|
8270
|
+
}
|
|
8271
|
+
if (/^[-*]\s+/.test(trimmed) || /^\d+\.\s+/.test(trimmed)) {
|
|
8272
|
+
const ordered = /^\d+\.\s+/.test(trimmed);
|
|
8273
|
+
const items = [];
|
|
8274
|
+
while (i < lines.length && (ordered ? /^\d+\.\s+/.test(lines[i].trim()) : /^[-*]\s+/.test(lines[i].trim()))) {
|
|
8275
|
+
items.push(lines[i].trim().replace(ordered ? /^\d+\.\s+/ : /^[-*]\s+/, ""));
|
|
8276
|
+
i += 1;
|
|
8277
|
+
}
|
|
8278
|
+
blocks.push({ type: "list", data: { style: ordered ? "ordered" : "unordered", items } });
|
|
8279
|
+
continue;
|
|
8280
|
+
}
|
|
8281
|
+
blocks.push({ type: "paragraph", data: { text: trimmed } });
|
|
8282
|
+
i += 1;
|
|
8283
|
+
}
|
|
8284
|
+
return blocks;
|
|
8285
|
+
}
|
|
8286
|
+
|
|
8287
|
+
// src/components/ExportModal.tsx
|
|
8288
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
8289
|
+
var ExportModal = ({
|
|
6734
8290
|
open,
|
|
6735
|
-
|
|
6736
|
-
|
|
6737
|
-
showStats,
|
|
6738
|
-
aiConfig,
|
|
6739
|
-
selectedTools,
|
|
6740
|
-
onChangeTheme,
|
|
6741
|
-
onChangeMode,
|
|
6742
|
-
onChangeShowStats,
|
|
6743
|
-
onChangeAiConfig,
|
|
6744
|
-
onChangeSelectedTools,
|
|
8291
|
+
data,
|
|
8292
|
+
onImportBlocks,
|
|
6745
8293
|
onClose
|
|
6746
8294
|
}) => {
|
|
6747
|
-
const [
|
|
6748
|
-
const [
|
|
8295
|
+
const [importText, setImportText] = useState3("");
|
|
8296
|
+
const [copiedKind, setCopiedKind] = useState3(null);
|
|
8297
|
+
const markdown = useMemo(() => open ? blocksToMarkdown(data) : "", [open, data]);
|
|
8298
|
+
const html = useMemo(() => open ? blocksToHtml(data) : "", [open, data]);
|
|
6749
8299
|
if (!open) return null;
|
|
6750
|
-
const
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
6755
|
-
|
|
6756
|
-
|
|
8300
|
+
const copyText = async (text, kind) => {
|
|
8301
|
+
try {
|
|
8302
|
+
await navigator.clipboard.writeText(text);
|
|
8303
|
+
setCopiedKind(kind);
|
|
8304
|
+
window.setTimeout(() => setCopiedKind(null), 1500);
|
|
8305
|
+
} catch {
|
|
8306
|
+
}
|
|
6757
8307
|
};
|
|
6758
|
-
const
|
|
6759
|
-
const
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
8308
|
+
const downloadFile = (content, filename, mime) => {
|
|
8309
|
+
const blob = new Blob([content], { type: mime });
|
|
8310
|
+
const url = URL.createObjectURL(blob);
|
|
8311
|
+
const a = document.createElement("a");
|
|
8312
|
+
a.href = url;
|
|
8313
|
+
a.download = filename;
|
|
8314
|
+
a.click();
|
|
8315
|
+
URL.revokeObjectURL(url);
|
|
6766
8316
|
};
|
|
6767
|
-
return /* @__PURE__ */
|
|
6768
|
-
/* @__PURE__ */
|
|
6769
|
-
/* @__PURE__ */
|
|
6770
|
-
/* @__PURE__ */
|
|
6771
|
-
/* @__PURE__ */
|
|
8317
|
+
return /* @__PURE__ */ jsx3("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Export & Import", children: /* @__PURE__ */ jsxs3("div", { className: "ng-modal", children: [
|
|
8318
|
+
/* @__PURE__ */ jsxs3("div", { className: "ng-modal-head", children: [
|
|
8319
|
+
/* @__PURE__ */ jsxs3("div", { children: [
|
|
8320
|
+
/* @__PURE__ */ jsx3("h3", { children: "Export & Markdown" }),
|
|
8321
|
+
/* @__PURE__ */ jsx3("p", { children: "Export to Markdown, HTML, PDF, or import Markdown into blocks." })
|
|
6772
8322
|
] }),
|
|
6773
|
-
/* @__PURE__ */
|
|
8323
|
+
/* @__PURE__ */ jsx3("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
|
|
6774
8324
|
] }),
|
|
6775
|
-
/* @__PURE__ */
|
|
6776
|
-
/* @__PURE__ */
|
|
6777
|
-
/* @__PURE__ */
|
|
6778
|
-
/* @__PURE__ */
|
|
6779
|
-
|
|
6780
|
-
{
|
|
6781
|
-
className: "cdx-input editor-form-select",
|
|
6782
|
-
value: theme,
|
|
6783
|
-
onChange: (e) => onChangeTheme(e.target.value),
|
|
6784
|
-
children: [
|
|
6785
|
-
/* @__PURE__ */ jsx2("option", { value: "inherit", children: "Inherit from Host App" }),
|
|
6786
|
-
/* @__PURE__ */ jsx2("option", { value: "light", children: "shadcn Light" }),
|
|
6787
|
-
/* @__PURE__ */ jsx2("option", { value: "dark", children: "shadcn Dark" }),
|
|
6788
|
-
/* @__PURE__ */ jsx2("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
|
|
6789
|
-
/* @__PURE__ */ jsx2("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
|
|
6790
|
-
/* @__PURE__ */ jsx2("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
|
|
6791
|
-
/* @__PURE__ */ jsx2("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
|
|
6792
|
-
]
|
|
6793
|
-
}
|
|
6794
|
-
)
|
|
6795
|
-
] }),
|
|
6796
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
6797
|
-
/* @__PURE__ */ jsx2("label", { children: "Editor Mode" }),
|
|
6798
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-segmented", children: [
|
|
6799
|
-
/* @__PURE__ */ jsx2(
|
|
8325
|
+
/* @__PURE__ */ jsxs3("div", { className: "ng-modal-panel", children: [
|
|
8326
|
+
/* @__PURE__ */ jsxs3("div", { className: "ng-field", children: [
|
|
8327
|
+
/* @__PURE__ */ jsx3("label", { children: "Quick Export" }),
|
|
8328
|
+
/* @__PURE__ */ jsxs3("div", { className: "ng-inline-ai-row", children: [
|
|
8329
|
+
/* @__PURE__ */ jsx3(
|
|
6800
8330
|
"button",
|
|
6801
8331
|
{
|
|
6802
8332
|
type: "button",
|
|
6803
|
-
className:
|
|
6804
|
-
onClick: () =>
|
|
6805
|
-
children: "
|
|
8333
|
+
className: "excalidraw-btn",
|
|
8334
|
+
onClick: () => void copyText(markdown, "md"),
|
|
8335
|
+
children: copiedKind === "md" ? "Copied MD!" : "Copy Markdown"
|
|
6806
8336
|
}
|
|
6807
8337
|
),
|
|
6808
|
-
/* @__PURE__ */
|
|
8338
|
+
/* @__PURE__ */ jsx3(
|
|
6809
8339
|
"button",
|
|
6810
8340
|
{
|
|
6811
8341
|
type: "button",
|
|
6812
|
-
className:
|
|
6813
|
-
onClick: () =>
|
|
6814
|
-
children: "
|
|
8342
|
+
className: "excalidraw-btn",
|
|
8343
|
+
onClick: () => downloadFile(markdown, "document.md", "text/markdown"),
|
|
8344
|
+
children: "Download .md"
|
|
6815
8345
|
}
|
|
6816
|
-
)
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-field ng-field-inline", children: [
|
|
6820
|
-
/* @__PURE__ */ jsx2("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
|
|
6821
|
-
/* @__PURE__ */ jsx2(
|
|
6822
|
-
"input",
|
|
6823
|
-
{
|
|
6824
|
-
id: "ng-stats-toggle",
|
|
6825
|
-
type: "checkbox",
|
|
6826
|
-
checked: showStats,
|
|
6827
|
-
onChange: (e) => onChangeShowStats(e.target.checked)
|
|
6828
|
-
}
|
|
6829
|
-
)
|
|
6830
|
-
] }),
|
|
6831
|
-
/* @__PURE__ */ jsx2("hr", { className: "ng-divider" }),
|
|
6832
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
6833
|
-
/* @__PURE__ */ jsx2("label", { children: "AI Provider" }),
|
|
6834
|
-
/* @__PURE__ */ jsx2(
|
|
6835
|
-
"select",
|
|
6836
|
-
{
|
|
6837
|
-
className: "cdx-input editor-form-select",
|
|
6838
|
-
value: aiConfig.provider,
|
|
6839
|
-
onChange: (e) => handleProviderChange(e.target.value),
|
|
6840
|
-
children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ jsx2("option", { value: p.id, children: p.label }, p.id))
|
|
6841
|
-
}
|
|
6842
|
-
)
|
|
6843
|
-
] }),
|
|
6844
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
6845
|
-
/* @__PURE__ */ jsx2("label", { children: "Model" }),
|
|
6846
|
-
/* @__PURE__ */ jsx2(
|
|
6847
|
-
"input",
|
|
6848
|
-
{
|
|
6849
|
-
type: "text",
|
|
6850
|
-
className: "cdx-input editor-form-input",
|
|
6851
|
-
value: aiConfig.model,
|
|
6852
|
-
placeholder: "e.g. gpt-4o-mini",
|
|
6853
|
-
onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
|
|
6854
|
-
}
|
|
6855
|
-
)
|
|
6856
|
-
] }),
|
|
6857
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
|
|
6858
|
-
/* @__PURE__ */ jsx2("label", { children: "API Key" }),
|
|
6859
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-key-row", children: [
|
|
6860
|
-
/* @__PURE__ */ jsx2(
|
|
6861
|
-
"input",
|
|
8346
|
+
),
|
|
8347
|
+
/* @__PURE__ */ jsx3(
|
|
8348
|
+
"button",
|
|
6862
8349
|
{
|
|
6863
|
-
type:
|
|
6864
|
-
className: "
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
|
|
8350
|
+
type: "button",
|
|
8351
|
+
className: "excalidraw-btn",
|
|
8352
|
+
onClick: () => void copyText(html, "html"),
|
|
8353
|
+
children: copiedKind === "html" ? "Copied HTML!" : "Copy HTML"
|
|
6868
8354
|
}
|
|
6869
8355
|
),
|
|
6870
|
-
/* @__PURE__ */
|
|
8356
|
+
/* @__PURE__ */ jsx3(
|
|
8357
|
+
"button",
|
|
8358
|
+
{
|
|
8359
|
+
type: "button",
|
|
8360
|
+
className: "excalidraw-btn",
|
|
8361
|
+
onClick: () => downloadFile(
|
|
8362
|
+
`<!doctype html><html><head><meta charset="utf-8"><title>Document</title></head><body>${html}</body></html>`,
|
|
8363
|
+
"document.html",
|
|
8364
|
+
"text/html"
|
|
8365
|
+
),
|
|
8366
|
+
children: "Download .html"
|
|
8367
|
+
}
|
|
8368
|
+
),
|
|
8369
|
+
/* @__PURE__ */ jsx3(
|
|
6871
8370
|
"button",
|
|
6872
8371
|
{
|
|
6873
8372
|
type: "button",
|
|
6874
8373
|
className: "excalidraw-btn",
|
|
6875
|
-
onClick: () =>
|
|
6876
|
-
children:
|
|
8374
|
+
onClick: () => window.print(),
|
|
8375
|
+
children: "Print / PDF"
|
|
6877
8376
|
}
|
|
6878
8377
|
)
|
|
6879
8378
|
] })
|
|
6880
8379
|
] }),
|
|
6881
|
-
/* @__PURE__ */
|
|
6882
|
-
/* @__PURE__ */
|
|
6883
|
-
/* @__PURE__ */
|
|
6884
|
-
"
|
|
8380
|
+
/* @__PURE__ */ jsxs3("div", { className: "ng-field", children: [
|
|
8381
|
+
/* @__PURE__ */ jsx3("label", { children: "Import Markdown" }),
|
|
8382
|
+
/* @__PURE__ */ jsx3(
|
|
8383
|
+
"textarea",
|
|
6885
8384
|
{
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
onChange: (e) =>
|
|
8385
|
+
className: "editor-mermaid-input",
|
|
8386
|
+
rows: 5,
|
|
8387
|
+
placeholder: "Paste Markdown here (# Heading, - list, ```mermaid ...```)...",
|
|
8388
|
+
value: importText,
|
|
8389
|
+
onChange: (e) => setImportText(e.target.value)
|
|
6891
8390
|
}
|
|
6892
|
-
)
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-tools-manager", children: [
|
|
6896
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-tools-header", children: [
|
|
6897
|
-
/* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsxs2("label", { children: [
|
|
6898
|
-
"Registered Components (",
|
|
6899
|
-
selectedSet.size,
|
|
6900
|
-
"/",
|
|
6901
|
-
ALL_TOOL_NAMES.length,
|
|
6902
|
-
")"
|
|
6903
|
-
] }) }),
|
|
6904
|
-
/* @__PURE__ */ jsxs2("div", { className: "ng-tools-actions", children: [
|
|
6905
|
-
/* @__PURE__ */ jsx2(
|
|
6906
|
-
"button",
|
|
6907
|
-
{
|
|
6908
|
-
type: "button",
|
|
6909
|
-
className: "excalidraw-btn",
|
|
6910
|
-
onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
|
|
6911
|
-
children: "All"
|
|
6912
|
-
}
|
|
6913
|
-
),
|
|
6914
|
-
/* @__PURE__ */ jsx2(
|
|
6915
|
-
"button",
|
|
6916
|
-
{
|
|
6917
|
-
type: "button",
|
|
6918
|
-
className: "excalidraw-btn",
|
|
6919
|
-
onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
|
|
6920
|
-
children: "Minimal"
|
|
6921
|
-
}
|
|
6922
|
-
)
|
|
6923
|
-
] })
|
|
6924
|
-
] }),
|
|
6925
|
-
/* @__PURE__ */ jsx2(
|
|
6926
|
-
"input",
|
|
8391
|
+
),
|
|
8392
|
+
/* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3(
|
|
8393
|
+
"button",
|
|
6927
8394
|
{
|
|
6928
|
-
type: "
|
|
6929
|
-
className: "
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
8395
|
+
type: "button",
|
|
8396
|
+
className: "excalidraw-btn is-active",
|
|
8397
|
+
disabled: !importText.trim(),
|
|
8398
|
+
onClick: () => {
|
|
8399
|
+
const blocks = markdownToBlocks(importText);
|
|
8400
|
+
if (blocks.length > 0) {
|
|
8401
|
+
onImportBlocks(blocks);
|
|
8402
|
+
setImportText("");
|
|
8403
|
+
onClose();
|
|
8404
|
+
}
|
|
8405
|
+
},
|
|
8406
|
+
children: "Append Markdown as Blocks"
|
|
6933
8407
|
}
|
|
6934
|
-
)
|
|
6935
|
-
/* @__PURE__ */ jsx2("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
|
|
6936
|
-
const q = toolFilter.trim().toLowerCase();
|
|
6937
|
-
const visible = group.tools.filter((t) => {
|
|
6938
|
-
const label = (TOOL_LABELS[t] || t).toLowerCase();
|
|
6939
|
-
return !q || label.includes(q) || t.toLowerCase().includes(q);
|
|
6940
|
-
});
|
|
6941
|
-
if (!visible.length) return null;
|
|
6942
|
-
return /* @__PURE__ */ jsxs2("div", { className: "ng-tools-group", children: [
|
|
6943
|
-
/* @__PURE__ */ jsx2("div", { className: "ng-tools-group-title", children: group.label }),
|
|
6944
|
-
/* @__PURE__ */ jsx2("div", { className: "ng-tools-grid", children: visible.map((tool) => {
|
|
6945
|
-
const checked = selectedSet.has(tool);
|
|
6946
|
-
return /* @__PURE__ */ jsxs2(
|
|
6947
|
-
"label",
|
|
6948
|
-
{
|
|
6949
|
-
className: `ng-tool-chip${checked ? " is-checked" : ""}`,
|
|
6950
|
-
children: [
|
|
6951
|
-
/* @__PURE__ */ jsx2(
|
|
6952
|
-
"input",
|
|
6953
|
-
{
|
|
6954
|
-
type: "checkbox",
|
|
6955
|
-
checked,
|
|
6956
|
-
onChange: () => toggleTool(tool)
|
|
6957
|
-
}
|
|
6958
|
-
),
|
|
6959
|
-
/* @__PURE__ */ jsx2("span", { children: TOOL_LABELS[tool] || tool })
|
|
6960
|
-
]
|
|
6961
|
-
},
|
|
6962
|
-
tool
|
|
6963
|
-
);
|
|
6964
|
-
}) })
|
|
6965
|
-
] }, group.label);
|
|
6966
|
-
}) })
|
|
8408
|
+
) })
|
|
6967
8409
|
] })
|
|
6968
8410
|
] })
|
|
6969
8411
|
] }) });
|
|
6970
8412
|
};
|
|
6971
8413
|
|
|
6972
8414
|
// src/components/BlockEditor.tsx
|
|
6973
|
-
import { jsx as
|
|
6974
|
-
var BlockEditor =
|
|
8415
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
8416
|
+
var BlockEditor = React5.forwardRef(
|
|
6975
8417
|
({
|
|
6976
8418
|
initialData,
|
|
6977
8419
|
placeholder,
|
|
6978
8420
|
enabledTools,
|
|
8421
|
+
allowToolConfiguration,
|
|
8422
|
+
accessNoticeText,
|
|
6979
8423
|
showStats = true,
|
|
6980
8424
|
showAiBar = false,
|
|
6981
8425
|
onAiRequest,
|
|
6982
8426
|
className,
|
|
6983
8427
|
onReady,
|
|
6984
|
-
onChange
|
|
8428
|
+
onChange,
|
|
8429
|
+
onThemeChange
|
|
6985
8430
|
}, ref) => {
|
|
6986
8431
|
const shellRef = useRef2(null);
|
|
6987
8432
|
const holderRef = useRef2(null);
|
|
@@ -6993,11 +8438,27 @@ var BlockEditor = React4.forwardRef(
|
|
|
6993
8438
|
const onReadyRef = useRef2(onReady);
|
|
6994
8439
|
const runAiRef = useRef2(async () => {
|
|
6995
8440
|
});
|
|
6996
|
-
const [settingsOpen, setSettingsOpen] =
|
|
6997
|
-
const [
|
|
6998
|
-
const [
|
|
6999
|
-
|
|
7000
|
-
|
|
8441
|
+
const [settingsOpen, setSettingsOpen] = useState4(false);
|
|
8442
|
+
const [exportOpen, setExportOpen] = useState4(false);
|
|
8443
|
+
const [theme, setTheme] = useState4(() => {
|
|
8444
|
+
try {
|
|
8445
|
+
const saved = localStorage.getItem("ng-editor-theme");
|
|
8446
|
+
if (saved === "light" || saved === "dark" || saved === "inherit") return saved;
|
|
8447
|
+
} catch {
|
|
8448
|
+
}
|
|
8449
|
+
return "inherit";
|
|
8450
|
+
});
|
|
8451
|
+
const [docWidth, setDocWidth] = useState4(() => {
|
|
8452
|
+
try {
|
|
8453
|
+
const saved = localStorage.getItem("ng-editor-width");
|
|
8454
|
+
if (saved === "narrow" || saved === "standard" || saved === "full") return saved;
|
|
8455
|
+
} catch {
|
|
8456
|
+
}
|
|
8457
|
+
return "full";
|
|
8458
|
+
});
|
|
8459
|
+
const [editorMode, setEditorMode] = useState4("block");
|
|
8460
|
+
const [simpleFont, setSimpleFont] = useState4("sans");
|
|
8461
|
+
const [selectedTools, setSelectedTools] = useState4(() => {
|
|
7001
8462
|
if (enabledTools && enabledTools.length > 0) return enabledTools;
|
|
7002
8463
|
try {
|
|
7003
8464
|
const raw = localStorage.getItem("ng-enabled-tools");
|
|
@@ -7009,13 +8470,28 @@ var BlockEditor = React4.forwardRef(
|
|
|
7009
8470
|
}
|
|
7010
8471
|
return ALL_TOOL_NAMES;
|
|
7011
8472
|
});
|
|
7012
|
-
const [statsVisible, setStatsVisible] =
|
|
7013
|
-
const
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
const
|
|
7017
|
-
const
|
|
7018
|
-
const [
|
|
8473
|
+
const [statsVisible, setStatsVisible] = useState4(showStats);
|
|
8474
|
+
const developerRestricted = Boolean(
|
|
8475
|
+
enabledTools && enabledTools.length > 0 && allowToolConfiguration !== true
|
|
8476
|
+
);
|
|
8477
|
+
const canConfigureTools = allowToolConfiguration ?? !developerRestricted;
|
|
8478
|
+
const effectiveSelectedTools = developerRestricted && enabledTools ? enabledTools : selectedTools;
|
|
8479
|
+
const [aiConfig, setAiConfig] = useState4(loadAiConfig);
|
|
8480
|
+
const [aiPopover, setAiPopover] = useState4(null);
|
|
8481
|
+
const [askPrompt, setAskPrompt] = useState4("");
|
|
8482
|
+
const [aiBusy, setAiBusy] = useState4(false);
|
|
8483
|
+
const [aiError, setAiError] = useState4(null);
|
|
8484
|
+
const [scratchOpen, setScratchOpen] = useState4(false);
|
|
8485
|
+
const [scratchText, setScratchText] = useState4(() => {
|
|
8486
|
+
try {
|
|
8487
|
+
return localStorage.getItem("ng-scratchpad-note") || "";
|
|
8488
|
+
} catch {
|
|
8489
|
+
return "";
|
|
8490
|
+
}
|
|
8491
|
+
});
|
|
8492
|
+
const [scratchCopied, setScratchCopied] = useState4(false);
|
|
8493
|
+
const [scratchOffset, setScratchOffset] = useState4({ x: 0, y: 0 });
|
|
8494
|
+
const [stats, setStats] = useState4(() => {
|
|
7019
8495
|
const blocks = initialData?.blocks || [];
|
|
7020
8496
|
const text = blocks.map((b) => JSON.stringify(b.data || {})).join(" ");
|
|
7021
8497
|
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
|
|
@@ -7026,19 +8502,68 @@ var BlockEditor = React4.forwardRef(
|
|
|
7026
8502
|
useEffect2(() => {
|
|
7027
8503
|
setStatsVisible(showStats);
|
|
7028
8504
|
}, [showStats]);
|
|
8505
|
+
useEffect2(() => {
|
|
8506
|
+
try {
|
|
8507
|
+
localStorage.setItem("ng-editor-theme", theme);
|
|
8508
|
+
} catch {
|
|
8509
|
+
}
|
|
8510
|
+
if (theme === "inherit") {
|
|
8511
|
+
document.documentElement.removeAttribute("data-ng-theme");
|
|
8512
|
+
} else {
|
|
8513
|
+
document.documentElement.setAttribute("data-ng-theme", theme);
|
|
8514
|
+
}
|
|
8515
|
+
onThemeChange?.(theme);
|
|
8516
|
+
}, [theme, onThemeChange]);
|
|
7029
8517
|
useEffect2(() => {
|
|
7030
8518
|
const shell = shellRef.current;
|
|
7031
8519
|
if (!shell) return;
|
|
8520
|
+
const openAiNearRect = (mode, e) => {
|
|
8521
|
+
const rect = e.detail?.rect;
|
|
8522
|
+
const shellRect = shell.getBoundingClientRect();
|
|
8523
|
+
const popW = 320;
|
|
8524
|
+
const rawLeft = rect ? rect.left - shellRect.left : 60;
|
|
8525
|
+
const rawTop = rect ? rect.top - shellRect.top + 4 : 60;
|
|
8526
|
+
const maxLeft = Math.max(12, shellRect.width - popW - 12);
|
|
8527
|
+
const left = Math.max(12, Math.min(rawLeft, maxLeft));
|
|
8528
|
+
const top = Math.max(12, rawTop);
|
|
8529
|
+
setAiError(null);
|
|
8530
|
+
setAskPrompt("");
|
|
8531
|
+
setAiPopover({ mode, top, left });
|
|
8532
|
+
};
|
|
7032
8533
|
const onOpenSettings = () => setSettingsOpen(true);
|
|
7033
|
-
const
|
|
7034
|
-
const
|
|
8534
|
+
const onOpenExport = () => setExportOpen(true);
|
|
8535
|
+
const onAiContinue = (e) => openAiNearRect("continue", e);
|
|
8536
|
+
const onAiAsk = (e) => openAiNearRect("ask", e);
|
|
8537
|
+
const onOpenScratch = () => setScratchOpen(true);
|
|
8538
|
+
const onKeyDown = async (e) => {
|
|
8539
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "d") {
|
|
8540
|
+
e.preventDefault();
|
|
8541
|
+
const ed = editorRef.current;
|
|
8542
|
+
if (!ed) return;
|
|
8543
|
+
try {
|
|
8544
|
+
const idx = ed.blocks.getCurrentBlockIndex();
|
|
8545
|
+
const saved = await ed.save();
|
|
8546
|
+
const blk = saved.blocks?.[idx];
|
|
8547
|
+
if (blk) {
|
|
8548
|
+
ed.blocks.insert(blk.type, blk.data, {}, idx + 1, true);
|
|
8549
|
+
}
|
|
8550
|
+
} catch {
|
|
8551
|
+
}
|
|
8552
|
+
}
|
|
8553
|
+
};
|
|
7035
8554
|
shell.addEventListener("nextgen-open-settings", onOpenSettings);
|
|
8555
|
+
shell.addEventListener("nextgen-open-export", onOpenExport);
|
|
7036
8556
|
shell.addEventListener("nextgen-ai-continue", onAiContinue);
|
|
7037
8557
|
shell.addEventListener("nextgen-ai-ask", onAiAsk);
|
|
8558
|
+
shell.addEventListener("nextgen-open-scratch", onOpenScratch);
|
|
8559
|
+
shell.addEventListener("keydown", onKeyDown);
|
|
7038
8560
|
return () => {
|
|
7039
8561
|
shell.removeEventListener("nextgen-open-settings", onOpenSettings);
|
|
8562
|
+
shell.removeEventListener("nextgen-open-export", onOpenExport);
|
|
7040
8563
|
shell.removeEventListener("nextgen-ai-continue", onAiContinue);
|
|
7041
8564
|
shell.removeEventListener("nextgen-ai-ask", onAiAsk);
|
|
8565
|
+
shell.removeEventListener("nextgen-open-scratch", onOpenScratch);
|
|
8566
|
+
shell.removeEventListener("keydown", onKeyDown);
|
|
7042
8567
|
};
|
|
7043
8568
|
}, []);
|
|
7044
8569
|
useEffect2(() => {
|
|
@@ -7047,14 +8572,14 @@ var BlockEditor = React4.forwardRef(
|
|
|
7047
8572
|
let cancelled = false;
|
|
7048
8573
|
const detachCategories = attachPopoverCategoryHeaders(holder);
|
|
7049
8574
|
const detachEmoji = attachEmojiSidePicker(holder);
|
|
7050
|
-
const effectiveTools = Array.from(/* @__PURE__ */ new Set([...
|
|
8575
|
+
const effectiveTools = Array.from(/* @__PURE__ */ new Set([...effectiveSelectedTools, "settings"]));
|
|
7051
8576
|
const mount = async () => {
|
|
7052
8577
|
await lifecycleRef.current;
|
|
7053
8578
|
if (cancelled) return;
|
|
7054
8579
|
const sanitizedInitial = {
|
|
7055
8580
|
...latestDocRef.current || { blocks: [] },
|
|
7056
8581
|
blocks: (latestDocRef.current?.blocks || []).filter(
|
|
7057
|
-
(b) => !["settings", "continueWriting", "askAi"].includes(b.type)
|
|
8582
|
+
(b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
|
|
7058
8583
|
)
|
|
7059
8584
|
};
|
|
7060
8585
|
latestDocRef.current = sanitizedInitial;
|
|
@@ -7068,7 +8593,7 @@ var BlockEditor = React4.forwardRef(
|
|
|
7068
8593
|
try {
|
|
7069
8594
|
const saved = await instance.save();
|
|
7070
8595
|
const filteredBlocks = (saved.blocks || []).filter(
|
|
7071
|
-
(b) => !["settings", "continueWriting", "askAi"].includes(b.type)
|
|
8596
|
+
(b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
|
|
7072
8597
|
);
|
|
7073
8598
|
const typed = { ...saved, blocks: filteredBlocks };
|
|
7074
8599
|
latestDocRef.current = typed;
|
|
@@ -7113,14 +8638,14 @@ var BlockEditor = React4.forwardRef(
|
|
|
7113
8638
|
});
|
|
7114
8639
|
}
|
|
7115
8640
|
};
|
|
7116
|
-
}, [editorMode,
|
|
8641
|
+
}, [editorMode, effectiveSelectedTools]);
|
|
7117
8642
|
useImperativeHandle(ref, () => ({
|
|
7118
8643
|
save: async () => {
|
|
7119
8644
|
if (!editorRef.current) return null;
|
|
7120
8645
|
await editorRef.current.isReady;
|
|
7121
8646
|
const saved = await editorRef.current.save();
|
|
7122
8647
|
const filteredBlocks = (saved.blocks || []).filter(
|
|
7123
|
-
(b) => !["settings", "continueWriting", "askAi"].includes(b.type)
|
|
8648
|
+
(b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
|
|
7124
8649
|
);
|
|
7125
8650
|
const typed = { ...saved, blocks: filteredBlocks };
|
|
7126
8651
|
latestDocRef.current = typed;
|
|
@@ -7167,7 +8692,7 @@ var BlockEditor = React4.forwardRef(
|
|
|
7167
8692
|
}
|
|
7168
8693
|
if (mode === "ask") {
|
|
7169
8694
|
setAskPrompt("");
|
|
7170
|
-
|
|
8695
|
+
setAiPopover(null);
|
|
7171
8696
|
}
|
|
7172
8697
|
} catch (err) {
|
|
7173
8698
|
setAiError(err instanceof Error ? err.message : "AI request failed.");
|
|
@@ -7189,17 +8714,18 @@ var BlockEditor = React4.forwardRef(
|
|
|
7189
8714
|
setEditorMode(nextMode);
|
|
7190
8715
|
};
|
|
7191
8716
|
const readMins = Math.max(1, Math.ceil(stats.words / 200));
|
|
7192
|
-
return /* @__PURE__ */
|
|
8717
|
+
return /* @__PURE__ */ jsxs4(
|
|
7193
8718
|
"div",
|
|
7194
8719
|
{
|
|
7195
8720
|
ref: shellRef,
|
|
7196
8721
|
"data-ng-theme": theme === "inherit" ? void 0 : theme,
|
|
8722
|
+
"data-ng-width": docWidth,
|
|
7197
8723
|
"data-ng-font": editorMode === "simple" ? simpleFont : void 0,
|
|
7198
8724
|
className: className ? `nextgen-editor-shell ${className}` : "nextgen-editor-shell",
|
|
7199
8725
|
children: [
|
|
7200
|
-
showAiBar && /* @__PURE__ */
|
|
7201
|
-
/* @__PURE__ */
|
|
7202
|
-
/* @__PURE__ */
|
|
8726
|
+
showAiBar && /* @__PURE__ */ jsxs4("div", { className: "ng-ai-bar", children: [
|
|
8727
|
+
/* @__PURE__ */ jsxs4("div", { className: "ng-ai-actions", children: [
|
|
8728
|
+
/* @__PURE__ */ jsx4(
|
|
7203
8729
|
"button",
|
|
7204
8730
|
{
|
|
7205
8731
|
type: "button",
|
|
@@ -7209,18 +8735,20 @@ var BlockEditor = React4.forwardRef(
|
|
|
7209
8735
|
children: aiBusy ? "Thinking\u2026" : "\u2726 Continue Writing"
|
|
7210
8736
|
}
|
|
7211
8737
|
),
|
|
7212
|
-
/* @__PURE__ */
|
|
8738
|
+
/* @__PURE__ */ jsx4(
|
|
7213
8739
|
"button",
|
|
7214
8740
|
{
|
|
7215
8741
|
type: "button",
|
|
7216
|
-
className: `excalidraw-btn${
|
|
8742
|
+
className: `excalidraw-btn${aiPopover?.mode === "ask" ? " is-active" : ""}`,
|
|
7217
8743
|
disabled: aiBusy,
|
|
7218
|
-
onClick: () =>
|
|
8744
|
+
onClick: () => setAiPopover(
|
|
8745
|
+
(p) => p ? null : { mode: "ask", top: 120, left: 120 }
|
|
8746
|
+
),
|
|
7219
8747
|
children: "Ask AI"
|
|
7220
8748
|
}
|
|
7221
8749
|
)
|
|
7222
8750
|
] }),
|
|
7223
|
-
/* @__PURE__ */
|
|
8751
|
+
/* @__PURE__ */ jsx4(
|
|
7224
8752
|
"button",
|
|
7225
8753
|
{
|
|
7226
8754
|
type: "button",
|
|
@@ -7231,31 +8759,7 @@ var BlockEditor = React4.forwardRef(
|
|
|
7231
8759
|
}
|
|
7232
8760
|
)
|
|
7233
8761
|
] }),
|
|
7234
|
-
|
|
7235
|
-
"form",
|
|
7236
|
-
{
|
|
7237
|
-
className: "ng-ask-form",
|
|
7238
|
-
onSubmit: (e) => {
|
|
7239
|
-
e.preventDefault();
|
|
7240
|
-
if (askPrompt.trim()) void runAi("ask", askPrompt.trim());
|
|
7241
|
-
},
|
|
7242
|
-
children: [
|
|
7243
|
-
/* @__PURE__ */ jsx3(
|
|
7244
|
-
"input",
|
|
7245
|
-
{
|
|
7246
|
-
type: "text",
|
|
7247
|
-
className: "cdx-input editor-form-input",
|
|
7248
|
-
placeholder: "Ask AI to draft, summarize, or expand...",
|
|
7249
|
-
value: askPrompt,
|
|
7250
|
-
onChange: (e) => setAskPrompt(e.target.value)
|
|
7251
|
-
}
|
|
7252
|
-
),
|
|
7253
|
-
/* @__PURE__ */ jsx3("button", { type: "submit", className: "editor-form-submit", disabled: aiBusy, children: aiBusy ? "Running\u2026" : "Generate" })
|
|
7254
|
-
]
|
|
7255
|
-
}
|
|
7256
|
-
),
|
|
7257
|
-
aiError && /* @__PURE__ */ jsx3("div", { className: "ng-ai-error", children: aiError }),
|
|
7258
|
-
editorMode === "simple" && /* @__PURE__ */ jsx3(
|
|
8762
|
+
editorMode === "simple" && /* @__PURE__ */ jsx4(
|
|
7259
8763
|
ClassicToolbar,
|
|
7260
8764
|
{
|
|
7261
8765
|
editorRef,
|
|
@@ -7263,38 +8767,50 @@ var BlockEditor = React4.forwardRef(
|
|
|
7263
8767
|
onRedo: () => undoRef.current?.redo?.(),
|
|
7264
8768
|
fontFamily: simpleFont,
|
|
7265
8769
|
onChangeFontFamily: setSimpleFont,
|
|
7266
|
-
enabledTools:
|
|
8770
|
+
enabledTools: effectiveSelectedTools,
|
|
7267
8771
|
onOpenSettings: () => setSettingsOpen(true)
|
|
7268
8772
|
}
|
|
7269
8773
|
),
|
|
7270
|
-
/* @__PURE__ */
|
|
7271
|
-
statsVisible && /* @__PURE__ */
|
|
7272
|
-
/* @__PURE__ */
|
|
7273
|
-
/* @__PURE__ */
|
|
7274
|
-
/* @__PURE__ */
|
|
8774
|
+
/* @__PURE__ */ jsx4("div", { id: "editorjs", ref: holderRef }),
|
|
8775
|
+
statsVisible && /* @__PURE__ */ jsxs4("div", { className: "nextgen-editor-stats", children: [
|
|
8776
|
+
/* @__PURE__ */ jsx4("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
|
|
8777
|
+
/* @__PURE__ */ jsx4("span", { children: "\u2022" }),
|
|
8778
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
7275
8779
|
stats.blocks,
|
|
7276
8780
|
" blocks"
|
|
7277
8781
|
] }),
|
|
7278
|
-
/* @__PURE__ */
|
|
8782
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
7279
8783
|
stats.words,
|
|
7280
8784
|
" words"
|
|
7281
8785
|
] }),
|
|
7282
|
-
/* @__PURE__ */
|
|
8786
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
7283
8787
|
"~",
|
|
7284
8788
|
readMins,
|
|
7285
8789
|
" min read"
|
|
7286
8790
|
] })
|
|
7287
8791
|
] }),
|
|
7288
|
-
/* @__PURE__ */
|
|
8792
|
+
/* @__PURE__ */ jsx4(
|
|
7289
8793
|
SettingsModal,
|
|
7290
8794
|
{
|
|
7291
8795
|
open: settingsOpen,
|
|
7292
8796
|
theme,
|
|
8797
|
+
docWidth,
|
|
7293
8798
|
mode: editorMode,
|
|
7294
8799
|
showStats: statsVisible,
|
|
7295
8800
|
aiConfig,
|
|
7296
|
-
selectedTools,
|
|
8801
|
+
selectedTools: effectiveSelectedTools,
|
|
8802
|
+
allowedTools: enabledTools,
|
|
8803
|
+
canConfigureTools,
|
|
8804
|
+
developerRestricted,
|
|
8805
|
+
accessNoticeText,
|
|
7297
8806
|
onChangeTheme: setTheme,
|
|
8807
|
+
onChangeDocWidth: (w) => {
|
|
8808
|
+
setDocWidth(w);
|
|
8809
|
+
try {
|
|
8810
|
+
localStorage.setItem("ng-editor-width", w);
|
|
8811
|
+
} catch {
|
|
8812
|
+
}
|
|
8813
|
+
},
|
|
7298
8814
|
onChangeMode: (m) => void handleModeSwitch(m),
|
|
7299
8815
|
onChangeShowStats: setStatsVisible,
|
|
7300
8816
|
onChangeAiConfig: (cfg) => {
|
|
@@ -7311,6 +8827,176 @@ var BlockEditor = React4.forwardRef(
|
|
|
7311
8827
|
},
|
|
7312
8828
|
onClose: () => setSettingsOpen(false)
|
|
7313
8829
|
}
|
|
8830
|
+
),
|
|
8831
|
+
/* @__PURE__ */ jsx4(
|
|
8832
|
+
ExportModal,
|
|
8833
|
+
{
|
|
8834
|
+
open: exportOpen,
|
|
8835
|
+
data: latestDocRef.current,
|
|
8836
|
+
onImportBlocks: (blocks) => {
|
|
8837
|
+
const ed = editorRef.current;
|
|
8838
|
+
if (!ed) return;
|
|
8839
|
+
blocks.forEach((b) => {
|
|
8840
|
+
ed.blocks.insert(b.type, b.data);
|
|
8841
|
+
});
|
|
8842
|
+
},
|
|
8843
|
+
onClose: () => setExportOpen(false)
|
|
8844
|
+
}
|
|
8845
|
+
),
|
|
8846
|
+
aiPopover && /* @__PURE__ */ jsxs4(
|
|
8847
|
+
"form",
|
|
8848
|
+
{
|
|
8849
|
+
className: "ng-ai-inline-popover",
|
|
8850
|
+
style: { top: `${aiPopover.top}px`, left: `${aiPopover.left}px` },
|
|
8851
|
+
onSubmit: (e) => {
|
|
8852
|
+
e.preventDefault();
|
|
8853
|
+
if (aiPopover.mode === "continue") {
|
|
8854
|
+
void runAi("continue", askPrompt.trim());
|
|
8855
|
+
} else if (askPrompt.trim()) {
|
|
8856
|
+
void runAi("ask", askPrompt.trim());
|
|
8857
|
+
}
|
|
8858
|
+
},
|
|
8859
|
+
children: [
|
|
8860
|
+
/* @__PURE__ */ jsxs4("div", { className: "ng-ai-inline-head", children: [
|
|
8861
|
+
/* @__PURE__ */ jsx4("span", { children: aiPopover.mode === "continue" ? "\u2726 Continue Writing" : "Ask AI" }),
|
|
8862
|
+
/* @__PURE__ */ jsx4(
|
|
8863
|
+
"button",
|
|
8864
|
+
{
|
|
8865
|
+
type: "button",
|
|
8866
|
+
className: "b2",
|
|
8867
|
+
"aria-label": "Close AI prompt",
|
|
8868
|
+
onClick: () => setAiPopover(null),
|
|
8869
|
+
children: "\xD7"
|
|
8870
|
+
}
|
|
8871
|
+
)
|
|
8872
|
+
] }),
|
|
8873
|
+
/* @__PURE__ */ jsxs4("div", { className: "ng-ai-inline-row", children: [
|
|
8874
|
+
/* @__PURE__ */ jsx4(
|
|
8875
|
+
"input",
|
|
8876
|
+
{
|
|
8877
|
+
type: "text",
|
|
8878
|
+
autoFocus: true,
|
|
8879
|
+
className: "cdx-input editor-form-input",
|
|
8880
|
+
placeholder: aiPopover.mode === "continue" ? "How should AI continue? (optional)" : "What do you want AI to write?",
|
|
8881
|
+
value: askPrompt,
|
|
8882
|
+
onChange: (e) => setAskPrompt(e.target.value),
|
|
8883
|
+
onKeyDown: (e) => {
|
|
8884
|
+
if (e.key === "Escape") setAiPopover(null);
|
|
8885
|
+
}
|
|
8886
|
+
}
|
|
8887
|
+
),
|
|
8888
|
+
/* @__PURE__ */ jsx4(
|
|
8889
|
+
"button",
|
|
8890
|
+
{
|
|
8891
|
+
type: "submit",
|
|
8892
|
+
className: "editor-form-submit",
|
|
8893
|
+
disabled: aiBusy || aiPopover.mode === "ask" && !askPrompt.trim(),
|
|
8894
|
+
children: aiBusy ? "Running\u2026" : aiPopover.mode === "continue" ? "Continue" : "Generate"
|
|
8895
|
+
}
|
|
8896
|
+
)
|
|
8897
|
+
] }),
|
|
8898
|
+
aiError && /* @__PURE__ */ jsx4("div", { className: "ng-ai-error", children: aiError })
|
|
8899
|
+
]
|
|
8900
|
+
}
|
|
8901
|
+
),
|
|
8902
|
+
scratchOpen && /* @__PURE__ */ jsxs4(
|
|
8903
|
+
"div",
|
|
8904
|
+
{
|
|
8905
|
+
className: "ng-scratch-sticky",
|
|
8906
|
+
role: "dialog",
|
|
8907
|
+
"aria-label": "Scratchpad sticky note",
|
|
8908
|
+
style: {
|
|
8909
|
+
transform: `translate(${scratchOffset.x}px, ${scratchOffset.y}px)`
|
|
8910
|
+
},
|
|
8911
|
+
children: [
|
|
8912
|
+
/* @__PURE__ */ jsxs4(
|
|
8913
|
+
"div",
|
|
8914
|
+
{
|
|
8915
|
+
className: "ng-scratch-sticky-head",
|
|
8916
|
+
onMouseDown: (e) => {
|
|
8917
|
+
if (e.target.closest("button")) return;
|
|
8918
|
+
const startX = e.clientX - scratchOffset.x;
|
|
8919
|
+
const startY = e.clientY - scratchOffset.y;
|
|
8920
|
+
const onMove = (ev) => {
|
|
8921
|
+
setScratchOffset({ x: ev.clientX - startX, y: ev.clientY - startY });
|
|
8922
|
+
};
|
|
8923
|
+
const onUp = () => {
|
|
8924
|
+
window.removeEventListener("mousemove", onMove);
|
|
8925
|
+
window.removeEventListener("mouseup", onUp);
|
|
8926
|
+
};
|
|
8927
|
+
window.addEventListener("mousemove", onMove);
|
|
8928
|
+
window.addEventListener("mouseup", onUp);
|
|
8929
|
+
},
|
|
8930
|
+
children: [
|
|
8931
|
+
/* @__PURE__ */ jsx4("span", { className: "ng-scratch-sticky-title", children: "\u{1F4DD} Scratchpad" }),
|
|
8932
|
+
/* @__PURE__ */ jsxs4("span", { className: "ng-scratch-sticky-count", children: [
|
|
8933
|
+
scratchText.trim() ? scratchText.trim().split(/\s+/).length : 0,
|
|
8934
|
+
"w \xB7 ",
|
|
8935
|
+
scratchText.length,
|
|
8936
|
+
"c"
|
|
8937
|
+
] }),
|
|
8938
|
+
/* @__PURE__ */ jsxs4("div", { className: "ng-scratch-sticky-actions", children: [
|
|
8939
|
+
/* @__PURE__ */ jsx4(
|
|
8940
|
+
"button",
|
|
8941
|
+
{
|
|
8942
|
+
type: "button",
|
|
8943
|
+
className: "ng-scratch-sticky-btn",
|
|
8944
|
+
onClick: () => {
|
|
8945
|
+
if (!scratchText) return;
|
|
8946
|
+
void navigator.clipboard?.writeText(scratchText);
|
|
8947
|
+
setScratchCopied(true);
|
|
8948
|
+
window.setTimeout(() => setScratchCopied(false), 1200);
|
|
8949
|
+
},
|
|
8950
|
+
children: scratchCopied ? "Copied" : "Copy"
|
|
8951
|
+
}
|
|
8952
|
+
),
|
|
8953
|
+
/* @__PURE__ */ jsx4(
|
|
8954
|
+
"button",
|
|
8955
|
+
{
|
|
8956
|
+
type: "button",
|
|
8957
|
+
className: "ng-scratch-sticky-btn",
|
|
8958
|
+
onClick: () => {
|
|
8959
|
+
setScratchText("");
|
|
8960
|
+
try {
|
|
8961
|
+
localStorage.setItem("ng-scratchpad-note", "");
|
|
8962
|
+
} catch {
|
|
8963
|
+
}
|
|
8964
|
+
},
|
|
8965
|
+
children: "Clear"
|
|
8966
|
+
}
|
|
8967
|
+
),
|
|
8968
|
+
/* @__PURE__ */ jsx4(
|
|
8969
|
+
"button",
|
|
8970
|
+
{
|
|
8971
|
+
type: "button",
|
|
8972
|
+
className: "ng-scratch-sticky-btn",
|
|
8973
|
+
"aria-label": "Close scratchpad",
|
|
8974
|
+
onClick: () => setScratchOpen(false),
|
|
8975
|
+
children: "\xD7"
|
|
8976
|
+
}
|
|
8977
|
+
)
|
|
8978
|
+
] })
|
|
8979
|
+
]
|
|
8980
|
+
}
|
|
8981
|
+
),
|
|
8982
|
+
/* @__PURE__ */ jsx4(
|
|
8983
|
+
"textarea",
|
|
8984
|
+
{
|
|
8985
|
+
className: "ng-scratch-sticky-body",
|
|
8986
|
+
placeholder: "Quick sticky note, rough ideas, snippets...",
|
|
8987
|
+
value: scratchText,
|
|
8988
|
+
onChange: (e) => {
|
|
8989
|
+
const val = e.target.value;
|
|
8990
|
+
setScratchText(val);
|
|
8991
|
+
try {
|
|
8992
|
+
localStorage.setItem("ng-scratchpad-note", val);
|
|
8993
|
+
} catch {
|
|
8994
|
+
}
|
|
8995
|
+
}
|
|
8996
|
+
}
|
|
8997
|
+
)
|
|
8998
|
+
]
|
|
8999
|
+
}
|
|
7314
9000
|
)
|
|
7315
9001
|
]
|
|
7316
9002
|
}
|
|
@@ -7320,7 +9006,7 @@ var BlockEditor = React4.forwardRef(
|
|
|
7320
9006
|
BlockEditor.displayName = "BlockEditor";
|
|
7321
9007
|
|
|
7322
9008
|
// src/components/BlockRenderer.tsx
|
|
7323
|
-
import { useMemo, useRef as useRef3 } from "react";
|
|
9009
|
+
import { useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState5 } from "react";
|
|
7324
9010
|
|
|
7325
9011
|
// src/hooks/useInteractiveArticle.ts
|
|
7326
9012
|
import Chart2 from "chart.js/auto";
|
|
@@ -8009,6 +9695,12 @@ function useInteractiveArticle(containerRef, depKey) {
|
|
|
8009
9695
|
btn.addEventListener("click", onOpen);
|
|
8010
9696
|
cleanups.push(() => btn.removeEventListener("click", onOpen));
|
|
8011
9697
|
});
|
|
9698
|
+
root.querySelectorAll("[data-mermaid]").forEach((el) => {
|
|
9699
|
+
const code = el.getAttribute("data-mermaid") || "";
|
|
9700
|
+
if (code.trim()) {
|
|
9701
|
+
void renderMermaidInto(el, code);
|
|
9702
|
+
}
|
|
9703
|
+
});
|
|
8012
9704
|
return () => {
|
|
8013
9705
|
cleanups.forEach((fn) => fn());
|
|
8014
9706
|
};
|
|
@@ -8016,26 +9708,60 @@ function useInteractiveArticle(containerRef, depKey) {
|
|
|
8016
9708
|
}
|
|
8017
9709
|
|
|
8018
9710
|
// src/components/BlockRenderer.tsx
|
|
8019
|
-
import { jsx as
|
|
9711
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
8020
9712
|
var BlockRenderer = ({
|
|
8021
9713
|
data,
|
|
9714
|
+
theme,
|
|
8022
9715
|
className
|
|
8023
9716
|
}) => {
|
|
8024
9717
|
const bodyRef = useRef3(null);
|
|
8025
|
-
const
|
|
9718
|
+
const [progress, setProgress] = useState5(0);
|
|
9719
|
+
const html = useMemo2(() => blocksToHtml(data), [data]);
|
|
8026
9720
|
useInteractiveArticle(bodyRef, html);
|
|
8027
|
-
|
|
9721
|
+
useEffect4(() => {
|
|
9722
|
+
const updateProgress = () => {
|
|
9723
|
+
const el = bodyRef.current;
|
|
9724
|
+
if (!el) return;
|
|
9725
|
+
const rect = el.getBoundingClientRect();
|
|
9726
|
+
const total = Math.max(1, el.scrollHeight - window.innerHeight);
|
|
9727
|
+
const scrolled = Math.min(total, Math.max(0, -rect.top));
|
|
9728
|
+
setProgress(Math.round(scrolled / total * 100));
|
|
9729
|
+
};
|
|
9730
|
+
updateProgress();
|
|
9731
|
+
window.addEventListener("scroll", updateProgress, { passive: true });
|
|
9732
|
+
window.addEventListener("resize", updateProgress);
|
|
9733
|
+
return () => {
|
|
9734
|
+
window.removeEventListener("scroll", updateProgress);
|
|
9735
|
+
window.removeEventListener("resize", updateProgress);
|
|
9736
|
+
};
|
|
9737
|
+
}, [html]);
|
|
9738
|
+
let resolvedTheme = theme;
|
|
9739
|
+
if (!resolvedTheme && typeof window !== "undefined") {
|
|
9740
|
+
resolvedTheme = document.documentElement.getAttribute("data-ng-theme") || (() => {
|
|
9741
|
+
try {
|
|
9742
|
+
return localStorage.getItem("ng-editor-theme") || void 0;
|
|
9743
|
+
} catch {
|
|
9744
|
+
return void 0;
|
|
9745
|
+
}
|
|
9746
|
+
})();
|
|
9747
|
+
}
|
|
9748
|
+
const attrTheme = resolvedTheme === "light" || resolvedTheme === "dark" ? resolvedTheme : void 0;
|
|
9749
|
+
return /* @__PURE__ */ jsxs5(
|
|
8028
9750
|
"div",
|
|
8029
9751
|
{
|
|
8030
9752
|
ref: bodyRef,
|
|
9753
|
+
"data-ng-theme": attrTheme,
|
|
8031
9754
|
className: className ? `article nextgen-editor-article ${className}` : "article nextgen-editor-article",
|
|
8032
|
-
|
|
9755
|
+
children: [
|
|
9756
|
+
/* @__PURE__ */ jsx5("div", { className: "ng-reading-progress", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("div", { className: "ng-reading-progress-fill", style: { width: `${progress}%` } }) }),
|
|
9757
|
+
/* @__PURE__ */ jsx5("div", { dangerouslySetInnerHTML: { __html: html } })
|
|
9758
|
+
]
|
|
8033
9759
|
}
|
|
8034
9760
|
);
|
|
8035
9761
|
};
|
|
8036
9762
|
|
|
8037
9763
|
// src/components/DocumentHeader.tsx
|
|
8038
|
-
import { jsx as
|
|
9764
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
8039
9765
|
var DocumentHeader = ({
|
|
8040
9766
|
coverUrl,
|
|
8041
9767
|
gradient = "linear-gradient(135deg, #27272a 0%, #52525b 100%)",
|
|
@@ -8045,12 +9771,12 @@ var DocumentHeader = ({
|
|
|
8045
9771
|
className
|
|
8046
9772
|
}) => {
|
|
8047
9773
|
const bannerStyle = coverUrl ? { backgroundImage: `url("${coverUrl}")`, backgroundSize: "cover", backgroundPosition: "center" } : { background: gradient };
|
|
8048
|
-
return /* @__PURE__ */
|
|
8049
|
-
/* @__PURE__ */
|
|
8050
|
-
icon ? /* @__PURE__ */
|
|
8051
|
-
/* @__PURE__ */
|
|
8052
|
-
/* @__PURE__ */
|
|
8053
|
-
subtitle ? /* @__PURE__ */
|
|
9774
|
+
return /* @__PURE__ */ jsxs6("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
|
|
9775
|
+
/* @__PURE__ */ jsx6("div", { className: "editor-cover-banner", style: bannerStyle }),
|
|
9776
|
+
icon ? /* @__PURE__ */ jsx6("div", { className: "editor-cover-icon", children: icon }) : null,
|
|
9777
|
+
/* @__PURE__ */ jsxs6("div", { className: "editor-cover-meta", children: [
|
|
9778
|
+
/* @__PURE__ */ jsx6("h1", { className: "editor-cover-title", children: title }),
|
|
9779
|
+
subtitle ? /* @__PURE__ */ jsx6("p", { className: "editor-cover-subtitle", children: subtitle }) : null
|
|
8054
9780
|
] })
|
|
8055
9781
|
] });
|
|
8056
9782
|
};
|
|
@@ -8059,8 +9785,10 @@ export {
|
|
|
8059
9785
|
BlockRenderer,
|
|
8060
9786
|
DocumentHeader,
|
|
8061
9787
|
blocksToHtml,
|
|
9788
|
+
blocksToMarkdown,
|
|
8062
9789
|
escHtml,
|
|
8063
9790
|
getEditorTools,
|
|
9791
|
+
markdownToBlocks,
|
|
8064
9792
|
sanitizeInlineHtml,
|
|
8065
9793
|
slugify,
|
|
8066
9794
|
uploadFileToBucket,
|