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 CHANGED
@@ -34,8 +34,10 @@ __export(index_exports, {
34
34
  BlockRenderer: () => BlockRenderer,
35
35
  DocumentHeader: () => DocumentHeader,
36
36
  blocksToHtml: () => blocksToHtml,
37
+ blocksToMarkdown: () => blocksToMarkdown,
37
38
  escHtml: () => escHtml,
38
39
  getEditorTools: () => getEditorTools,
40
+ markdownToBlocks: () => markdownToBlocks,
39
41
  sanitizeInlineHtml: () => sanitizeInlineHtml,
40
42
  slugify: () => slugify,
41
43
  uploadFileToBucket: () => uploadFileToBucket,
@@ -44,7 +46,7 @@ __export(index_exports, {
44
46
  module.exports = __toCommonJS(index_exports);
45
47
 
46
48
  // src/components/BlockEditor.tsx
47
- var import_react4 = __toESM(require("react"), 1);
49
+ var import_react5 = __toESM(require("react"), 1);
48
50
  var import_editorjs2 = __toESM(require("@editorjs/editorjs"), 1);
49
51
  var import_editorjs_drag_drop = __toESM(require("editorjs-drag-drop"), 1);
50
52
  var import_editorjs_undo = __toESM(require("editorjs-undo"), 1);
@@ -54,7 +56,6 @@ var import_editorjs = __toESM(require("@editorjs/editorjs"), 1);
54
56
  var import_header = __toESM(require("@editorjs/header"), 1);
55
57
  var import_list = __toESM(require("@editorjs/list"), 1);
56
58
  var import_nested_list = __toESM(require("@editorjs/nested-list"), 1);
57
- var import_checklist = __toESM(require("@editorjs/checklist"), 1);
58
59
  var import_table = __toESM(require("@editorjs/table"), 1);
59
60
  var import_quote = __toESM(require("@editorjs/quote"), 1);
60
61
  var import_inline_code = __toESM(require("@editorjs/inline-code"), 1);
@@ -298,7 +299,7 @@ function sanitizeInlineHtml(value) {
298
299
  element.replaceWith(document.createTextNode(element.textContent || ""));
299
300
  return;
300
301
  }
301
- if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler")) {
302
+ if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler") && !element.classList.contains("ng-inline-color")) {
302
303
  element.replaceWith(document.createTextNode(element.textContent || ""));
303
304
  return;
304
305
  }
@@ -307,7 +308,10 @@ function sanitizeInlineHtml(value) {
307
308
  if (element.tagName === "A" && attribute.name === "class" && attribute.value === "editor-mention") {
308
309
  return;
309
310
  }
310
- if (element.tagName === "SPAN" && attribute.name === "class" && attribute.value === "editor-inline-spoiler") {
311
+ if (element.tagName === "SPAN" && attribute.name === "class" && (attribute.value === "editor-inline-spoiler" || attribute.value === "ng-inline-color")) {
312
+ return;
313
+ }
314
+ if (element.tagName === "SPAN" && element.classList.contains("ng-inline-color") && attribute.name === "style") {
311
315
  return;
312
316
  }
313
317
  if (["target", "rel"].includes(attribute.name) && element.tagName === "A") return;
@@ -591,9 +595,12 @@ function blocksToHtml(data) {
591
595
  }).join("") + "</div>";
592
596
  }
593
597
  if (block.type === "embed") {
594
- return d.embed ? `<iframe src="${escHtml(d.embed)}" title="${escHtml(
595
- d.caption
596
- )}" loading="lazy"></iframe>` : "";
598
+ if (!d.embed) return "";
599
+ const align = ["left", "center", "right"].includes(d.align) ? d.align : "center";
600
+ const size = ["small", "medium", "large", "full"].includes(d.size) ? d.size : "medium";
601
+ return `<div class="editor-embed-wrap" data-align="${align}" data-size="${size}"><iframe src="${escHtml(
602
+ d.embed
603
+ )}" title="${escHtml(d.caption)}" loading="lazy" allowfullscreen></iframe></div>`;
597
604
  }
598
605
  if (block.type === "attaches") {
599
606
  const attachmentUrl = d.file && d.file.url ? d.file.url : d.dataUrl || "";
@@ -643,6 +650,85 @@ function blocksToHtml(data) {
643
650
  d.text || ""
644
651
  )}</div></div>${overlay}</div>`;
645
652
  }
653
+ if (block.type === "mermaid") {
654
+ const code = String(d.code || "");
655
+ const caption = d.caption ? `<figcaption>${escHtml(d.caption)}</figcaption>` : "";
656
+ return `<figure class="editor-mermaid-block"><div class="editor-mermaid-diagram" data-mermaid="${escHtml(
657
+ code
658
+ )}"><pre class="editor-mermaid-fallback">${escHtml(code)}</pre></div>${caption}</figure>`;
659
+ }
660
+ if (block.type === "bookmark") {
661
+ const url = String(d.url || "#");
662
+ let host = url;
663
+ try {
664
+ host = new URL(url).hostname;
665
+ } catch {
666
+ }
667
+ return `<a class="editor-bookmark-card" href="${escHtml(
668
+ url
669
+ )}" target="_blank" rel="noopener noreferrer"><div class="editor-bookmark-body"><div class="editor-bookmark-title">${escHtml(
670
+ d.title || host
671
+ )}</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>`;
672
+ }
673
+ if (block.type === "steps") {
674
+ const items = Array.isArray(d.items) ? d.items : [];
675
+ return `<ol class="editor-steps-list">${items.map(
676
+ (item, idx) => `<li class="editor-step-item"><div class="editor-step-badge">${idx + 1}</div><div class="editor-step-content"><h4>${escHtml(
677
+ item.title || `Step ${idx + 1}`
678
+ )}</h4><p>${escHtml(item.body || "")}</p></div></li>`
679
+ ).join("")}</ol>`;
680
+ }
681
+ if (block.type === "diff") {
682
+ const before = String(d.before || "").split("\n");
683
+ const after = String(d.after || "").split("\n");
684
+ const max = Math.max(before.length, after.length);
685
+ const rows = [];
686
+ for (let i = 0; i < max; i += 1) {
687
+ if (before[i] === after[i]) {
688
+ if (before[i] !== void 0) {
689
+ rows.push(`<span class="editor-diff-line is-same"> ${escHtml(before[i])}</span>`);
690
+ }
691
+ } else {
692
+ if (before[i] !== void 0) {
693
+ rows.push(`<span class="editor-diff-line is-del">- ${escHtml(before[i])}</span>`);
694
+ }
695
+ if (after[i] !== void 0) {
696
+ rows.push(`<span class="editor-diff-line is-add">+ ${escHtml(after[i])}</span>`);
697
+ }
698
+ }
699
+ }
700
+ 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>`;
701
+ }
702
+ if (block.type === "video") {
703
+ if (!d.url) return "";
704
+ 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>`;
705
+ }
706
+ if (block.type === "changelog") {
707
+ const items = Array.isArray(d.items) ? d.items : [];
708
+ return `<section class="editor-changelog-block"><div class="editor-changelog-head"><span class="editor-changelog-version">${escHtml(
709
+ d.version || "v1.0.0"
710
+ )}</span><span class="editor-changelog-date">${escHtml(
711
+ d.date || ""
712
+ )}</span></div><ul class="editor-changelog-list">${items.map(
713
+ (i) => `<li><span class="editor-changelog-badge is-${escHtml(
714
+ i.kind || "added"
715
+ )}">${escHtml((i.kind || "added").toUpperCase())}</span><span>${escHtml(
716
+ i.text || ""
717
+ )}</span></li>`
718
+ ).join("")}</ul></section>`;
719
+ }
720
+ if (block.type === "today") {
721
+ return `<div class="editor-today-pill"><span class="editor-today-badge">\u{1F4C5} ${escHtml(
722
+ d.date || ""
723
+ )}</span></div>`;
724
+ }
725
+ if (block.type === "social") {
726
+ return `<blockquote class="editor-social-card"><div class="editor-social-head"><strong>${escHtml(
727
+ d.author || ""
728
+ )}</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(
729
+ d.url
730
+ )}" target="_blank" rel="noopener noreferrer">View original post \u2192</a>` : ""}</blockquote>`;
731
+ }
646
732
  if (block.type === "alert") {
647
733
  const variant = ["info", "tip", "warning", "danger"].includes(d.variant) ? d.variant : "info";
648
734
  const icons = {
@@ -1733,22 +1819,25 @@ function attachEmojiSidePicker(container) {
1733
1819
  const triggerRange = document.createRange();
1734
1820
  triggerRange.setStart(textNode, triggerStart);
1735
1821
  triggerRange.setEnd(textNode, offset);
1736
- const rect = triggerRange.getBoundingClientRect();
1822
+ const rawRect = triggerRange.getBoundingClientRect();
1823
+ const rect = rawRect.width > 0 || rawRect.height > 0 ? rawRect : target.getBoundingClientRect();
1737
1824
  openEmojiSideMenu({
1738
1825
  anchorRect: rect,
1739
1826
  onSelect: (emoji) => {
1740
- if (!textNode.isConnected) return;
1741
- const current = textNode.data;
1742
- const nextText = current.slice(0, triggerStart) + emoji + current.slice(offset);
1743
- textNode.data = nextText;
1744
- const nextCaret = triggerStart + emoji.length;
1745
- const newRange = document.createRange();
1746
- newRange.setStart(textNode, nextCaret);
1747
- newRange.setEnd(textNode, nextCaret);
1748
- const s = window.getSelection();
1749
- if (s) {
1750
- s.removeAllRanges();
1751
- s.addRange(newRange);
1827
+ if (textNode.isConnected) {
1828
+ const current = textNode.data;
1829
+ textNode.data = current.slice(0, triggerStart) + emoji + current.slice(offset);
1830
+ const nextCaret = triggerStart + emoji.length;
1831
+ const newRange = document.createRange();
1832
+ newRange.setStart(textNode, nextCaret);
1833
+ newRange.setEnd(textNode, nextCaret);
1834
+ const s = window.getSelection();
1835
+ if (s) {
1836
+ s.removeAllRanges();
1837
+ s.addRange(newRange);
1838
+ }
1839
+ } else if (target.isConnected) {
1840
+ target.innerHTML = target.innerHTML.replace(/\/emoji/i, emoji);
1752
1841
  }
1753
1842
  target.focus();
1754
1843
  target.dispatchEvent(new Event("input", { bubbles: true }));
@@ -3713,14 +3802,23 @@ function createActionTriggerTool(title, icon, eventName) {
3713
3802
  }
3714
3803
  render() {
3715
3804
  const el = document.createElement("div");
3716
- el.style.display = "none";
3805
+ el.style.height = "1px";
3806
+ el.style.opacity = "0";
3807
+ el.style.pointerEvents = "none";
3717
3808
  this.el = el;
3718
3809
  return el;
3719
3810
  }
3720
3811
  rendered() {
3721
3812
  if (this.fired || !this.el) return;
3722
3813
  this.fired = true;
3723
- this.el.dispatchEvent(new CustomEvent(eventName, { bubbles: true }));
3814
+ const contentEl = this.el.closest(".ce-block__content") || this.el.closest(".ce-block") || this.el;
3815
+ const blockRect = contentEl.getBoundingClientRect();
3816
+ this.el.dispatchEvent(
3817
+ new CustomEvent(eventName, {
3818
+ bubbles: true,
3819
+ detail: { rect: blockRect }
3820
+ })
3821
+ );
3724
3822
  window.setTimeout(() => {
3725
3823
  try {
3726
3824
  const idx = this.api.blocks.getCurrentBlockIndex();
@@ -4118,12 +4216,17 @@ var EmojiTool = class {
4118
4216
  anchorRect: rect,
4119
4217
  onSelect: (em) => {
4120
4218
  if (this.isNewInsert && this.api?.blocks) {
4121
- const idx = this.api.blocks.getCurrentBlockIndex();
4122
- this.api.blocks.delete(idx);
4123
- this.api.blocks.insert("paragraph", { text: `${em} ` }, {}, idx, true);
4124
- queueMicrotask(() => {
4125
- this.api?.caret?.setToBlock(idx, "end");
4126
- });
4219
+ const blockEl = this.anchorEl?.closest(".ce-block");
4220
+ const parent = blockEl?.parentElement;
4221
+ const domIdx = blockEl && parent ? Array.from(parent.children).indexOf(blockEl) : -1;
4222
+ const idx = domIdx >= 0 ? domIdx : this.api.blocks.getCurrentBlockIndex();
4223
+ if (idx >= 0) {
4224
+ this.api.blocks.insert("paragraph", { text: `${em} ` }, {}, idx + 1, true);
4225
+ this.api.blocks.delete(idx);
4226
+ window.requestAnimationFrame(() => {
4227
+ this.api?.caret?.setToBlock(idx, "end");
4228
+ });
4229
+ }
4127
4230
  return;
4128
4231
  }
4129
4232
  this.data.emoji = em;
@@ -4147,7 +4250,7 @@ var EmojiTool = class {
4147
4250
  }
4148
4251
  rendered() {
4149
4252
  if (this.isNewInsert) {
4150
- queueMicrotask(() => this.openPickerAtAnchor());
4253
+ window.requestAnimationFrame(() => this.openPickerAtAnchor());
4151
4254
  }
4152
4255
  }
4153
4256
  save() {
@@ -4158,83 +4261,11 @@ var EmojiTool = class {
4158
4261
  };
4159
4262
  }
4160
4263
  };
4161
- var ScratchTool = class {
4162
- data;
4163
- static get toolbox() {
4164
- return {
4165
- title: "Scratchpad",
4166
- 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>'
4167
- };
4168
- }
4169
- constructor({ data }) {
4170
- this.data = {
4171
- title: data?.title ?? "Scratchpad",
4172
- text: data?.text ?? ""
4173
- };
4174
- }
4175
- render() {
4176
- const wrap = document.createElement("div");
4177
- wrap.className = "editor-scratch-tool";
4178
- const head = document.createElement("div");
4179
- head.className = "editor-scratch-head";
4180
- const titleIn = document.createElement("input");
4181
- titleIn.type = "text";
4182
- titleIn.className = "cdx-input editor-scratch-title";
4183
- titleIn.placeholder = "Scratchpad title...";
4184
- titleIn.value = this.data.title ?? "Scratchpad";
4185
- titleIn.addEventListener("input", () => {
4186
- this.data.title = titleIn.value;
4187
- });
4188
- const stats = document.createElement("span");
4189
- stats.className = "editor-scratch-stats";
4190
- const updateStats = () => {
4191
- const len = this.data.text.length;
4192
- const words = this.data.text.trim() ? this.data.text.trim().split(/\s+/).length : 0;
4193
- stats.textContent = `${words}w \xB7 ${len}c`;
4194
- };
4195
- const copyBtn = document.createElement("button");
4196
- copyBtn.type = "button";
4197
- copyBtn.className = "b2";
4198
- copyBtn.textContent = "Copy";
4199
- copyBtn.addEventListener("click", () => {
4200
- if (!this.data.text) return;
4201
- void navigator.clipboard?.writeText(this.data.text);
4202
- copyBtn.textContent = "Copied";
4203
- window.setTimeout(() => {
4204
- copyBtn.textContent = "Copy";
4205
- }, 1200);
4206
- });
4207
- const clearBtn = document.createElement("button");
4208
- clearBtn.type = "button";
4209
- clearBtn.className = "b2";
4210
- clearBtn.textContent = "Clear";
4211
- head.append(titleIn, stats, copyBtn, clearBtn);
4212
- const textarea = document.createElement("textarea");
4213
- textarea.className = "cdx-input editor-scratch-textarea";
4214
- textarea.rows = 4;
4215
- textarea.placeholder = "Quick brain dump, rough notes, snippets...";
4216
- textarea.value = this.data.text || "";
4217
- textarea.addEventListener("input", () => {
4218
- this.data.text = textarea.value;
4219
- updateStats();
4220
- });
4221
- clearBtn.addEventListener("click", () => {
4222
- this.data.text = "";
4223
- textarea.value = "";
4224
- updateStats();
4225
- textarea.focus();
4226
- });
4227
- updateStats();
4228
- wrap.append(head, textarea);
4229
- return wrap;
4230
- }
4231
- save() {
4232
- return {
4233
- title: this.data.title?.trim() || "Scratchpad",
4234
- text: this.data.text
4235
- };
4236
- }
4237
- };
4264
+ var ScratchTool = createActionTriggerTool(
4265
+ "Scratchpad",
4266
+ '<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>',
4267
+ "nextgen-open-scratch"
4268
+ );
4238
4269
  var DialogueTool = class {
4239
4270
  data;
4240
4271
  static get toolbox() {
@@ -4944,178 +4975,1196 @@ var TagsTool = class {
4944
4975
  }
4945
4976
  };
4946
4977
 
4947
- // src/editorTools.ts
4948
- var CustomMediaTool = class {
4949
- data;
4950
- elements;
4951
- constructor(options) {
4952
- this.data = options.data || {};
4978
+ // src/blocks/mermaidBlock.ts
4979
+ var import_mermaid = __toESM(require("mermaid"), 1);
4980
+ var MERMAID_PRESETS = {
4981
+ Flowchart: `graph TD
4982
+ A[Start] --> B{Condition?}
4983
+ B -->|Yes| C[Proceed]
4984
+ B -->|No| D[Retry]`,
4985
+ Sequence: `sequenceDiagram
4986
+ User->>Editor: Type /mermaid
4987
+ Editor->>Mermaid: Render SVG
4988
+ Mermaid-->>User: Interactive Diagram`,
4989
+ Mindmap: `mindmap
4990
+ root((NextGen Editor))
4991
+ Blocks
4992
+ Mermaid
4993
+ Charts
4994
+ Code
4995
+ AI
4996
+ Rewrite
4997
+ Continue`
4998
+ };
4999
+ var mermaidInitialized = false;
5000
+ var mermaidCounter = 0;
5001
+ function ensureMermaidInit() {
5002
+ if (mermaidInitialized) return;
5003
+ mermaidInitialized = true;
5004
+ import_mermaid.default.initialize({
5005
+ startOnLoad: false,
5006
+ securityLevel: "strict",
5007
+ theme: "neutral"
5008
+ });
5009
+ }
5010
+ async function renderMermaidInto(container, code) {
5011
+ const trimmed = code.trim();
5012
+ if (!trimmed) {
5013
+ container.innerHTML = '<span class="editor-mermaid-empty">Enter Mermaid syntax to preview</span>';
5014
+ return;
5015
+ }
5016
+ ensureMermaidInit();
5017
+ const id = `ng-mermaid-${++mermaidCounter}`;
5018
+ try {
5019
+ const { svg } = await import_mermaid.default.render(id, trimmed);
5020
+ container.innerHTML = svg;
5021
+ } catch (err) {
5022
+ const message = err instanceof Error ? err.message : "Invalid Mermaid syntax";
5023
+ container.innerHTML = `<pre class="editor-mermaid-error">${message.replace(/</g, "&lt;")}</pre>`;
4953
5024
  }
5025
+ }
5026
+ var MermaidTool = class {
5027
+ data;
5028
+ renderSeq = 0;
4954
5029
  static get toolbox() {
4955
5030
  return {
4956
- title: "Image",
4957
- 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>'
5031
+ title: "Mermaid Diagram",
5032
+ 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>'
5033
+ };
5034
+ }
5035
+ constructor({ data }) {
5036
+ this.data = {
5037
+ code: data?.code ?? MERMAID_PRESETS.Flowchart,
5038
+ caption: data?.caption ?? ""
4958
5039
  };
4959
5040
  }
4960
5041
  render() {
4961
- const root = document.createElement("div");
4962
- root.className = "custom-media-fields";
4963
- const input = document.createElement("input");
4964
- input.type = "text";
4965
- input.placeholder = "Paste image URL";
4966
- input.value = this.data.url || "";
4967
- const file = document.createElement("input");
4968
- file.type = "file";
4969
- file.accept = "image/*";
4970
- const caption = document.createElement("input");
4971
- caption.type = "text";
4972
- caption.placeholder = "Caption";
4973
- caption.value = this.data.caption || "";
5042
+ const wrap = document.createElement("div");
5043
+ wrap.className = "editor-mermaid-tool";
5044
+ const head = document.createElement("div");
5045
+ head.className = "editor-mermaid-head";
5046
+ const title = document.createElement("span");
5047
+ title.className = "editor-mermaid-label";
5048
+ title.textContent = "Mermaid Diagram";
5049
+ const presets = document.createElement("div");
5050
+ presets.className = "editor-mermaid-presets";
5051
+ Object.entries(MERMAID_PRESETS).forEach(([label, snippet]) => {
5052
+ const btn = document.createElement("button");
5053
+ btn.type = "button";
5054
+ btn.className = "editor-mermaid-preset-btn";
5055
+ btn.textContent = label;
5056
+ btn.addEventListener("click", () => {
5057
+ this.data.code = snippet;
5058
+ textarea.value = snippet;
5059
+ void updatePreview();
5060
+ });
5061
+ presets.appendChild(btn);
5062
+ });
5063
+ head.append(title, presets);
5064
+ const textarea = document.createElement("textarea");
5065
+ textarea.className = "editor-mermaid-input";
5066
+ textarea.rows = 5;
5067
+ textarea.placeholder = "graph TD\n A --> B";
5068
+ textarea.value = this.data.code;
4974
5069
  const preview = document.createElement("div");
4975
- preview.className = "custom-media-preview";
4976
- const paint = (url) => {
4977
- preview.innerHTML = url ? `<img src="${escHtml(url)}" alt="">` : "";
4978
- };
4979
- paint(input.value);
4980
- input.oninput = () => paint(input.value);
4981
- file.onchange = async () => {
4982
- const selected = file.files?.[0];
4983
- if (!selected) return;
4984
- const bucketUrl = await uploadFileToBucket(selected, "writing");
4985
- if (bucketUrl) {
4986
- input.value = bucketUrl;
4987
- paint(bucketUrl);
4988
- return;
4989
- }
4990
- const reader = new FileReader();
4991
- reader.onload = () => {
4992
- const res = String(reader.result || "");
4993
- input.value = res;
4994
- paint(res);
4995
- };
4996
- reader.readAsDataURL(selected);
5070
+ preview.className = "editor-mermaid-preview";
5071
+ const captionInput = document.createElement("input");
5072
+ captionInput.type = "text";
5073
+ captionInput.className = "editor-mermaid-caption cdx-input";
5074
+ captionInput.placeholder = "Optional diagram caption";
5075
+ captionInput.value = this.data.caption || "";
5076
+ const updatePreview = async () => {
5077
+ const seq = ++this.renderSeq;
5078
+ await renderMermaidInto(preview, this.data.code);
5079
+ if (seq !== this.renderSeq) return;
4997
5080
  };
4998
- root.append(input, file, caption, preview);
4999
- this.elements = { root, input, caption };
5000
- return root;
5081
+ textarea.addEventListener("input", () => {
5082
+ this.data.code = textarea.value;
5083
+ void updatePreview();
5084
+ });
5085
+ captionInput.addEventListener("input", () => {
5086
+ this.data.caption = captionInput.value;
5087
+ });
5088
+ void updatePreview();
5089
+ wrap.append(head, textarea, preview, captionInput);
5090
+ return wrap;
5001
5091
  }
5002
5092
  save() {
5003
5093
  return {
5004
- url: this.elements?.input.value.trim() || "",
5005
- caption: this.elements?.caption.value.trim() || ""
5094
+ code: this.data.code,
5095
+ caption: this.data.caption?.trim() || void 0
5006
5096
  };
5007
5097
  }
5008
5098
  };
5009
- var GifTool = class {
5099
+
5100
+ // src/blocks/extraBlocks.ts
5101
+ function createInput(type, className, placeholder, value, onInput) {
5102
+ const input = document.createElement("input");
5103
+ input.type = type;
5104
+ input.className = className;
5105
+ input.placeholder = placeholder;
5106
+ input.value = value;
5107
+ input.addEventListener("input", () => onInput(input.value));
5108
+ return input;
5109
+ }
5110
+ function createTextarea(className, rows, placeholder, value, onInput) {
5111
+ const ta = document.createElement("textarea");
5112
+ ta.className = className;
5113
+ ta.rows = rows;
5114
+ ta.placeholder = placeholder;
5115
+ ta.value = value;
5116
+ ta.addEventListener("input", () => onInput(ta.value));
5117
+ return ta;
5118
+ }
5119
+ var BookmarkTool = class {
5010
5120
  data;
5011
- elements;
5012
- constructor(options) {
5013
- this.data = options.data || {};
5014
- }
5015
5121
  static get toolbox() {
5016
5122
  return {
5017
- title: "GIF",
5018
- 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>'
5123
+ title: "Bookmark",
5124
+ 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>'
5125
+ };
5126
+ }
5127
+ constructor({ data }) {
5128
+ this.data = {
5129
+ url: data?.url ?? "",
5130
+ title: data?.title ?? "",
5131
+ description: data?.description ?? "",
5132
+ image: data?.image ?? ""
5019
5133
  };
5020
5134
  }
5021
5135
  render() {
5022
- const root = document.createElement("div");
5023
- root.className = "custom-media-fields";
5024
- const searchRow = document.createElement("div");
5025
- searchRow.className = "gif-search-row";
5026
- const searchInput = document.createElement("input");
5027
- searchInput.type = "search";
5028
- searchInput.placeholder = "Search free GIFs (trending or keyword)...";
5029
- const searchBtn = document.createElement("button");
5030
- searchBtn.type = "button";
5031
- searchBtn.className = "b2";
5032
- searchBtn.textContent = "Search";
5033
- searchRow.append(searchInput, searchBtn);
5034
- const resultsGrid = document.createElement("div");
5035
- resultsGrid.className = "gif-picker-grid";
5036
- const url = document.createElement("input");
5037
- url.type = "url";
5038
- url.placeholder = "Or paste GIF / image URL";
5039
- url.value = this.data.url || "";
5040
- const caption = document.createElement("input");
5041
- caption.type = "text";
5042
- caption.placeholder = "Caption";
5043
- caption.value = this.data.caption || "";
5136
+ const wrap = document.createElement("div");
5137
+ wrap.className = "editor-extra-card";
5138
+ const head = document.createElement("div");
5139
+ head.className = "editor-extra-head";
5140
+ head.textContent = "URL Bookmark Card";
5044
5141
  const preview = document.createElement("div");
5045
- preview.className = "custom-media-preview";
5046
- const paint = () => {
5047
- preview.innerHTML = url.value ? `<img src="${escHtml(url.value)}" alt="${escHtml(caption.value || "GIF")}">` : "";
5048
- };
5049
- paint();
5050
- url.oninput = paint;
5051
- const runSearch = async (query) => {
5052
- resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
5053
- try {
5054
- const res = await fetch(
5055
- `/api/gifs?q=${encodeURIComponent(query)}&limit=12`
5056
- );
5057
- const json = await res.json();
5058
- const items = json.results || [];
5059
- if (!items.length) {
5060
- resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
5061
- return;
5142
+ preview.className = "editor-bookmark-preview";
5143
+ const refreshPreview = () => {
5144
+ const host = (() => {
5145
+ try {
5146
+ return this.data.url ? new URL(this.data.url).hostname : "example.com";
5147
+ } catch {
5148
+ return this.data.url || "example.com";
5062
5149
  }
5063
- resultsGrid.innerHTML = "";
5064
- items.forEach((item) => {
5065
- const btn = document.createElement("button");
5066
- btn.type = "button";
5067
- btn.className = "gif-picker-item";
5068
- btn.title = item.title;
5069
- btn.innerHTML = `<img src="${escHtml(item.previewUrl)}" alt="${escHtml(item.title)}" loading="lazy">`;
5070
- btn.onclick = () => {
5071
- url.value = item.url;
5072
- if (!caption.value) caption.value = item.title;
5073
- paint();
5074
- };
5075
- resultsGrid.appendChild(btn);
5076
- });
5077
- } catch {
5078
- resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
5079
- }
5150
+ })();
5151
+ preview.innerHTML = `
5152
+ <div class="editor-bookmark-card">
5153
+ <div class="editor-bookmark-body">
5154
+ <div class="editor-bookmark-title">${escHtml(this.data.title || host)}</div>
5155
+ ${this.data.description ? `<div class="editor-bookmark-desc">${escHtml(this.data.description)}</div>` : ""}
5156
+ <div class="editor-bookmark-url">${escHtml(host)}</div>
5157
+ </div>
5158
+ ${this.data.image ? `<img class="editor-bookmark-thumb" src="${escHtml(this.data.image)}" alt="" />` : ""}
5159
+ </div>`;
5080
5160
  };
5081
- searchBtn.onclick = () => void runSearch(searchInput.value);
5082
- searchInput.addEventListener("keydown", (e) => {
5083
- if (e.key === "Enter") {
5084
- e.preventDefault();
5085
- e.stopPropagation();
5086
- void runSearch(searchInput.value);
5087
- }
5088
- });
5089
- if (!this.data.url) {
5090
- void runSearch("");
5091
- }
5092
- root.append(searchRow, resultsGrid, url, caption, preview);
5093
- this.elements = { url, caption };
5094
- return root;
5161
+ const grid = document.createElement("div");
5162
+ grid.className = "editor-extra-grid";
5163
+ grid.append(
5164
+ createInput("url", "cdx-input", "https://example.com/article", this.data.url, (v) => {
5165
+ this.data.url = v;
5166
+ refreshPreview();
5167
+ }),
5168
+ createInput("text", "cdx-input", "Link title", this.data.title, (v) => {
5169
+ this.data.title = v;
5170
+ refreshPreview();
5171
+ }),
5172
+ createInput("text", "cdx-input", "Short description", this.data.description, (v) => {
5173
+ this.data.description = v;
5174
+ refreshPreview();
5175
+ }),
5176
+ createInput("url", "cdx-input", "Optional thumbnail URL", this.data.image || "", (v) => {
5177
+ this.data.image = v;
5178
+ refreshPreview();
5179
+ })
5180
+ );
5181
+ refreshPreview();
5182
+ wrap.append(head, grid, preview);
5183
+ return wrap;
5095
5184
  }
5096
5185
  save() {
5097
5186
  return {
5098
- url: this.elements?.url.value.trim() || "",
5099
- caption: this.elements?.caption.value.trim() || ""
5187
+ url: this.data.url.trim(),
5188
+ title: this.data.title.trim(),
5189
+ description: this.data.description.trim(),
5190
+ image: this.data.image?.trim() || void 0
5100
5191
  };
5101
5192
  }
5102
5193
  };
5103
- var AttachTool = class {
5194
+ var StepsTool = class {
5104
5195
  data;
5105
- elements;
5106
- constructor(options) {
5107
- this.data = options.data || {};
5108
- }
5109
5196
  static get toolbox() {
5110
5197
  return {
5111
- title: "Attachment",
5112
- 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>'
5198
+ title: "Steps",
5199
+ 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>'
5200
+ };
5201
+ }
5202
+ constructor({ data }) {
5203
+ this.data = {
5204
+ items: Array.isArray(data?.items) && data.items.length > 0 ? data.items.map((item) => ({ title: item.title || "", body: item.body || "" })) : [
5205
+ { title: "Install dependencies", body: "Run npm install to set up the package." },
5206
+ { title: "Configure & render", body: "Pass initialData and onChange to BlockEditor." }
5207
+ ]
5113
5208
  };
5114
5209
  }
5115
5210
  render() {
5116
- const root = document.createElement("div");
5117
- root.className = "custom-media-fields";
5118
- const file = document.createElement("input");
5211
+ const wrap = document.createElement("div");
5212
+ wrap.className = "editor-extra-card";
5213
+ const head = document.createElement("div");
5214
+ head.className = "editor-extra-head";
5215
+ head.textContent = "Step-by-Step Walkthrough";
5216
+ const list = document.createElement("div");
5217
+ list.className = "editor-steps-editor-list";
5218
+ const renderList = () => {
5219
+ list.innerHTML = "";
5220
+ this.data.items.forEach((item, idx) => {
5221
+ const row = document.createElement("div");
5222
+ row.className = "editor-step-editor-row";
5223
+ const badge = document.createElement("span");
5224
+ badge.className = "editor-step-badge";
5225
+ badge.textContent = String(idx + 1);
5226
+ const fields = document.createElement("div");
5227
+ fields.className = "editor-step-editor-fields";
5228
+ fields.append(
5229
+ createInput("text", "cdx-input", `Step ${idx + 1} title`, item.title, (v) => {
5230
+ item.title = v;
5231
+ }),
5232
+ createTextarea("cdx-input", 2, "Step details", item.body, (v) => {
5233
+ item.body = v;
5234
+ })
5235
+ );
5236
+ const removeBtn = document.createElement("button");
5237
+ removeBtn.type = "button";
5238
+ removeBtn.className = "excalidraw-btn";
5239
+ removeBtn.textContent = "\xD7";
5240
+ removeBtn.title = "Remove step";
5241
+ removeBtn.addEventListener("click", () => {
5242
+ if (this.data.items.length <= 1) return;
5243
+ this.data.items.splice(idx, 1);
5244
+ renderList();
5245
+ });
5246
+ row.append(badge, fields, removeBtn);
5247
+ list.appendChild(row);
5248
+ });
5249
+ };
5250
+ const addBtn = document.createElement("button");
5251
+ addBtn.type = "button";
5252
+ addBtn.className = "excalidraw-btn";
5253
+ addBtn.textContent = "+ Add Step";
5254
+ addBtn.addEventListener("click", () => {
5255
+ this.data.items.push({ title: "", body: "" });
5256
+ renderList();
5257
+ });
5258
+ renderList();
5259
+ wrap.append(head, list, addBtn);
5260
+ return wrap;
5261
+ }
5262
+ save() {
5263
+ return {
5264
+ items: this.data.items.filter((i) => i.title.trim() || i.body.trim())
5265
+ };
5266
+ }
5267
+ };
5268
+ function computeSimpleDiff(before, after) {
5269
+ const a = before.split("\n");
5270
+ const b = after.split("\n");
5271
+ const lines = [];
5272
+ const max = Math.max(a.length, b.length);
5273
+ for (let i = 0; i < max; i += 1) {
5274
+ const left = a[i];
5275
+ const right = b[i];
5276
+ if (left === right) {
5277
+ if (left !== void 0) lines.push({ kind: "same", text: left });
5278
+ } else {
5279
+ if (left !== void 0) lines.push({ kind: "del", text: left });
5280
+ if (right !== void 0) lines.push({ kind: "add", text: right });
5281
+ }
5282
+ }
5283
+ return lines;
5284
+ }
5285
+ var DiffTool = class {
5286
+ data;
5287
+ static get toolbox() {
5288
+ return {
5289
+ title: "Code Diff",
5290
+ 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>'
5291
+ };
5292
+ }
5293
+ constructor({ data }) {
5294
+ this.data = {
5295
+ filename: data?.filename ?? "example.ts",
5296
+ before: data?.before ?? 'const theme = "catppuccin";',
5297
+ after: data?.after ?? 'const theme = "dark";'
5298
+ };
5299
+ }
5300
+ render() {
5301
+ const wrap = document.createElement("div");
5302
+ wrap.className = "editor-extra-card";
5303
+ const head = document.createElement("div");
5304
+ head.className = "editor-extra-head";
5305
+ head.textContent = "Code Diff Viewer";
5306
+ const preview = document.createElement("pre");
5307
+ preview.className = "editor-diff-preview";
5308
+ const refreshPreview = () => {
5309
+ const diffLines = computeSimpleDiff(this.data.before, this.data.after);
5310
+ preview.innerHTML = diffLines.map((line) => {
5311
+ const prefix = line.kind === "del" ? "-" : line.kind === "add" ? "+" : " ";
5312
+ return `<span class="editor-diff-line is-${line.kind}">${prefix} ${escHtml(line.text)}</span>`;
5313
+ }).join("\n");
5314
+ };
5315
+ const cols = document.createElement("div");
5316
+ cols.className = "editor-diff-inputs";
5317
+ cols.append(
5318
+ createTextarea("editor-mermaid-input", 4, "Before code...", this.data.before, (v) => {
5319
+ this.data.before = v;
5320
+ refreshPreview();
5321
+ }),
5322
+ createTextarea("editor-mermaid-input", 4, "After code...", this.data.after, (v) => {
5323
+ this.data.after = v;
5324
+ refreshPreview();
5325
+ })
5326
+ );
5327
+ const fileInput = createInput("text", "cdx-input", "Filename (optional)", this.data.filename || "", (v) => {
5328
+ this.data.filename = v;
5329
+ });
5330
+ refreshPreview();
5331
+ wrap.append(head, fileInput, cols, preview);
5332
+ return wrap;
5333
+ }
5334
+ save() {
5335
+ return {
5336
+ filename: this.data.filename?.trim() || void 0,
5337
+ before: this.data.before,
5338
+ after: this.data.after
5339
+ };
5340
+ }
5341
+ };
5342
+ var VideoTool = class {
5343
+ data;
5344
+ static get toolbox() {
5345
+ return {
5346
+ title: "Video Player",
5347
+ 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>'
5348
+ };
5349
+ }
5350
+ constructor({ data }) {
5351
+ this.data = {
5352
+ url: data?.url ?? "",
5353
+ poster: data?.poster ?? "",
5354
+ caption: data?.caption ?? ""
5355
+ };
5356
+ }
5357
+ render() {
5358
+ const wrap = document.createElement("div");
5359
+ wrap.className = "editor-extra-card";
5360
+ const head = document.createElement("div");
5361
+ head.className = "editor-extra-head";
5362
+ head.textContent = "Video Player (MP4 / WebM)";
5363
+ const preview = document.createElement("div");
5364
+ preview.className = "editor-video-preview";
5365
+ const refreshPreview = () => {
5366
+ if (!this.data.url.trim()) {
5367
+ preview.innerHTML = '<div class="editor-mermaid-empty">Paste a video URL or upload a file</div>';
5368
+ return;
5369
+ }
5370
+ 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>`;
5371
+ };
5372
+ const urlInput = createInput("url", "cdx-input", "https://.../video.mp4", this.data.url, (v) => {
5373
+ this.data.url = v;
5374
+ refreshPreview();
5375
+ });
5376
+ const uploadInput = document.createElement("input");
5377
+ uploadInput.type = "file";
5378
+ uploadInput.accept = "video/mp4,video/webm,video/ogg";
5379
+ uploadInput.className = "cdx-input";
5380
+ uploadInput.addEventListener("change", async () => {
5381
+ const file = uploadInput.files?.[0];
5382
+ if (!file) return;
5383
+ const uploaded = await uploadFileToBucket(file, "videos");
5384
+ if (uploaded) {
5385
+ this.data.url = uploaded;
5386
+ urlInput.value = uploaded;
5387
+ refreshPreview();
5388
+ }
5389
+ });
5390
+ const posterInput = createInput("url", "cdx-input", "Optional poster image URL", this.data.poster || "", (v) => {
5391
+ this.data.poster = v;
5392
+ refreshPreview();
5393
+ });
5394
+ const captionInput = createInput("text", "cdx-input", "Optional video caption", this.data.caption || "", (v) => {
5395
+ this.data.caption = v;
5396
+ });
5397
+ refreshPreview();
5398
+ wrap.append(head, urlInput, uploadInput, posterInput, captionInput, preview);
5399
+ return wrap;
5400
+ }
5401
+ save() {
5402
+ return {
5403
+ url: this.data.url.trim(),
5404
+ poster: this.data.poster?.trim() || void 0,
5405
+ caption: this.data.caption?.trim() || void 0
5406
+ };
5407
+ }
5408
+ };
5409
+ var ChangelogTool = class {
5410
+ data;
5411
+ static get toolbox() {
5412
+ return {
5413
+ title: "Changelog",
5414
+ 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>'
5415
+ };
5416
+ }
5417
+ constructor({ data }) {
5418
+ this.data = {
5419
+ version: data?.version ?? "v1.0.0",
5420
+ date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
5421
+ 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" }]
5422
+ };
5423
+ }
5424
+ render() {
5425
+ const wrap = document.createElement("div");
5426
+ wrap.className = "editor-extra-card";
5427
+ const head = document.createElement("div");
5428
+ head.className = "editor-extra-head";
5429
+ head.textContent = "Release Changelog";
5430
+ const meta = document.createElement("div");
5431
+ meta.className = "editor-diff-inputs";
5432
+ meta.append(
5433
+ createInput("text", "cdx-input", "Version (e.g. v1.2.0)", this.data.version, (v) => {
5434
+ this.data.version = v;
5435
+ }),
5436
+ createInput("date", "cdx-input", "Release date", this.data.date, (v) => {
5437
+ this.data.date = v;
5438
+ })
5439
+ );
5440
+ const list = document.createElement("div");
5441
+ list.className = "editor-steps-editor-list";
5442
+ const renderItems = () => {
5443
+ list.innerHTML = "";
5444
+ this.data.items.forEach((item, idx) => {
5445
+ const row = document.createElement("div");
5446
+ row.className = "editor-changelog-row";
5447
+ const select = document.createElement("select");
5448
+ select.className = "cdx-input editor-form-select";
5449
+ ["added", "changed", "fixed"].forEach((k) => {
5450
+ const opt = document.createElement("option");
5451
+ opt.value = k;
5452
+ opt.textContent = k.toUpperCase();
5453
+ if (item.kind === k) opt.selected = true;
5454
+ select.appendChild(opt);
5455
+ });
5456
+ select.addEventListener("change", () => {
5457
+ item.kind = select.value;
5458
+ });
5459
+ const text = createInput("text", "cdx-input", "Change description", item.text, (v) => {
5460
+ item.text = v;
5461
+ });
5462
+ const del = document.createElement("button");
5463
+ del.type = "button";
5464
+ del.className = "excalidraw-btn";
5465
+ del.textContent = "\xD7";
5466
+ del.addEventListener("click", () => {
5467
+ if (this.data.items.length <= 1) return;
5468
+ this.data.items.splice(idx, 1);
5469
+ renderItems();
5470
+ });
5471
+ row.append(select, text, del);
5472
+ list.appendChild(row);
5473
+ });
5474
+ };
5475
+ const addBtn = document.createElement("button");
5476
+ addBtn.type = "button";
5477
+ addBtn.className = "excalidraw-btn";
5478
+ addBtn.textContent = "+ Add Entry";
5479
+ addBtn.addEventListener("click", () => {
5480
+ this.data.items.push({ kind: "added", text: "" });
5481
+ renderItems();
5482
+ });
5483
+ renderItems();
5484
+ wrap.append(head, meta, list, addBtn);
5485
+ return wrap;
5486
+ }
5487
+ save() {
5488
+ return {
5489
+ version: this.data.version.trim() || "v1.0.0",
5490
+ date: this.data.date,
5491
+ items: this.data.items.filter((i) => i.text.trim())
5492
+ };
5493
+ }
5494
+ };
5495
+ var SocialTool = class {
5496
+ data;
5497
+ static get toolbox() {
5498
+ return {
5499
+ title: "Social Post",
5500
+ 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>'
5501
+ };
5502
+ }
5503
+ constructor({ data }) {
5504
+ this.data = {
5505
+ author: data?.author ?? "Alex Rivera",
5506
+ handle: data?.handle ?? "@alexrivera",
5507
+ date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
5508
+ text: data?.text ?? "",
5509
+ url: data?.url ?? ""
5510
+ };
5511
+ }
5512
+ render() {
5513
+ const wrap = document.createElement("div");
5514
+ wrap.className = "editor-extra-card";
5515
+ const head = document.createElement("div");
5516
+ head.className = "editor-extra-head";
5517
+ head.textContent = "Social Post Quote Card";
5518
+ const meta = document.createElement("div");
5519
+ meta.className = "editor-diff-inputs";
5520
+ meta.append(
5521
+ createInput("text", "cdx-input", "Author name", this.data.author, (v) => {
5522
+ this.data.author = v;
5523
+ }),
5524
+ createInput("text", "cdx-input", "@handle", this.data.handle, (v) => {
5525
+ this.data.handle = v;
5526
+ })
5527
+ );
5528
+ const text = createTextarea("cdx-input", 3, "Quoted post content...", this.data.text, (v) => {
5529
+ this.data.text = v;
5530
+ });
5531
+ const extra = document.createElement("div");
5532
+ extra.className = "editor-diff-inputs";
5533
+ extra.append(
5534
+ createInput("text", "cdx-input", "Date (optional)", this.data.date || "", (v) => {
5535
+ this.data.date = v;
5536
+ }),
5537
+ createInput("url", "cdx-input", "Original post URL (optional)", this.data.url || "", (v) => {
5538
+ this.data.url = v;
5539
+ })
5540
+ );
5541
+ wrap.append(head, meta, text, extra);
5542
+ return wrap;
5543
+ }
5544
+ save() {
5545
+ return {
5546
+ author: this.data.author.trim(),
5547
+ handle: this.data.handle.trim(),
5548
+ date: this.data.date?.trim() || void 0,
5549
+ text: this.data.text.trim(),
5550
+ url: this.data.url?.trim() || void 0
5551
+ };
5552
+ }
5553
+ };
5554
+
5555
+ // src/utils/aiClient.ts
5556
+ var AI_PROVIDER_PRESETS = [
5557
+ {
5558
+ id: "openai",
5559
+ label: "OpenAI (ChatGPT)",
5560
+ defaultModel: "gpt-4o-mini",
5561
+ defaultEndpoint: "https://api.openai.com/v1/chat/completions"
5562
+ },
5563
+ {
5564
+ id: "codex",
5565
+ label: "OpenAI Codex",
5566
+ defaultModel: "codex-mini-latest",
5567
+ defaultEndpoint: "https://api.openai.com/v1/chat/completions"
5568
+ },
5569
+ {
5570
+ id: "openrouter",
5571
+ label: "OpenRouter",
5572
+ defaultModel: "openai/gpt-4o-mini",
5573
+ defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
5574
+ },
5575
+ {
5576
+ id: "opencode",
5577
+ label: "OpenCode",
5578
+ defaultModel: "opencode/default",
5579
+ defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
5580
+ },
5581
+ {
5582
+ id: "anthropic",
5583
+ label: "Anthropic (Claude)",
5584
+ defaultModel: "claude-3-5-sonnet-latest",
5585
+ defaultEndpoint: "https://api.anthropic.com/v1/messages"
5586
+ },
5587
+ {
5588
+ id: "gemini",
5589
+ label: "Google Gemini",
5590
+ defaultModel: "gemini-2.5-flash",
5591
+ defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
5592
+ },
5593
+ {
5594
+ id: "custom",
5595
+ label: "Custom OpenAI-Compatible",
5596
+ defaultModel: "gpt-4o-mini",
5597
+ defaultEndpoint: "http://localhost:11434/v1/chat/completions"
5598
+ }
5599
+ ];
5600
+ var AI_STORAGE_KEY = "nextgen-editor-ai-config";
5601
+ function loadAiConfig() {
5602
+ try {
5603
+ const raw = localStorage.getItem(AI_STORAGE_KEY);
5604
+ if (raw) {
5605
+ const parsed = JSON.parse(raw);
5606
+ if (parsed.provider) {
5607
+ return {
5608
+ provider: parsed.provider,
5609
+ model: parsed.model || "gpt-4o-mini",
5610
+ apiKey: parsed.apiKey || "",
5611
+ endpoint: parsed.endpoint || ""
5612
+ };
5613
+ }
5614
+ }
5615
+ } catch {
5616
+ }
5617
+ return {
5618
+ provider: "openai",
5619
+ model: "gpt-4o-mini",
5620
+ apiKey: "",
5621
+ endpoint: ""
5622
+ };
5623
+ }
5624
+ function saveAiConfig(cfg) {
5625
+ try {
5626
+ localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
5627
+ } catch {
5628
+ }
5629
+ }
5630
+ async function generateAiText(params) {
5631
+ const { config, mode, prompt, context } = params;
5632
+ const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
5633
+ const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
5634
+ const model = (config.model || preset.defaultModel).trim();
5635
+ const apiKey = config.apiKey.trim();
5636
+ if (!apiKey && config.provider !== "custom") {
5637
+ throw new Error("Please add an API key in Settings first.");
5638
+ }
5639
+ 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.";
5640
+ const userContent = mode === "continue" ? `Document context:
5641
+ ${context || "(Empty document)"}
5642
+
5643
+ Continue writing naturally:` : `Document context:
5644
+ ${context || "(Empty document)"}
5645
+
5646
+ User request: ${prompt}`;
5647
+ if (config.provider === "gemini") {
5648
+ const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
5649
+ model
5650
+ )}:generateContent?key=${encodeURIComponent(apiKey)}`;
5651
+ const res2 = await fetch(url, {
5652
+ method: "POST",
5653
+ headers: { "Content-Type": "application/json" },
5654
+ body: JSON.stringify({
5655
+ contents: [{ parts: [{ text: `${systemPrompt}
5656
+
5657
+ ${userContent}` }] }]
5658
+ })
5659
+ });
5660
+ if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
5661
+ const json2 = await res2.json();
5662
+ return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
5663
+ }
5664
+ if (config.provider === "anthropic") {
5665
+ const res2 = await fetch(endpoint, {
5666
+ method: "POST",
5667
+ headers: {
5668
+ "Content-Type": "application/json",
5669
+ "x-api-key": apiKey,
5670
+ "anthropic-version": "2023-06-01"
5671
+ },
5672
+ body: JSON.stringify({
5673
+ model,
5674
+ max_tokens: 1024,
5675
+ system: systemPrompt,
5676
+ messages: [{ role: "user", content: userContent }]
5677
+ })
5678
+ });
5679
+ if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
5680
+ const json2 = await res2.json();
5681
+ return json2.content?.[0]?.text?.trim() || "";
5682
+ }
5683
+ const headers = {
5684
+ "Content-Type": "application/json"
5685
+ };
5686
+ if (apiKey) {
5687
+ headers.Authorization = `Bearer ${apiKey}`;
5688
+ }
5689
+ const res = await fetch(endpoint, {
5690
+ method: "POST",
5691
+ headers,
5692
+ body: JSON.stringify({
5693
+ model,
5694
+ messages: [
5695
+ { role: "system", content: systemPrompt },
5696
+ { role: "user", content: userContent }
5697
+ ]
5698
+ })
5699
+ });
5700
+ if (!res.ok) throw new Error(`AI API error (${res.status})`);
5701
+ const json = await res.json();
5702
+ return json.choices?.[0]?.message?.content?.trim() || "";
5703
+ }
5704
+
5705
+ // src/blocks/inlineExtensions.ts
5706
+ var TEXT_COLOR_SWATCHES = [
5707
+ { label: "Default", value: "" },
5708
+ { label: "Gray", value: "#71717a" },
5709
+ { label: "Red", value: "#dc2626" },
5710
+ { label: "Amber", value: "#d97706" },
5711
+ { label: "Green", value: "#16a34a" },
5712
+ { label: "Blue", value: "#2563eb" },
5713
+ { label: "Purple", value: "#9333ea" }
5714
+ ];
5715
+ var HIGHLIGHT_SWATCHES = [
5716
+ { label: "None", value: "" },
5717
+ { label: "Yellow", value: "rgba(250, 204, 21, 0.35)" },
5718
+ { label: "Green", value: "rgba(74, 222, 128, 0.3)" },
5719
+ { label: "Blue", value: "rgba(96, 165, 250, 0.3)" },
5720
+ { label: "Pink", value: "rgba(244, 114, 182, 0.3)" },
5721
+ { label: "Gray", value: "rgba(161, 161, 170, 0.28)" }
5722
+ ];
5723
+ var REWRITE_ACTIONS = [
5724
+ {
5725
+ id: "improve",
5726
+ label: "Improve",
5727
+ prompt: "Rewrite the following text to be clearer, smoother, and more engaging. Return only the rewritten text."
5728
+ },
5729
+ {
5730
+ id: "shorten",
5731
+ label: "Shorten",
5732
+ prompt: "Make the following text more concise while preserving its core meaning. Return only the shortened text."
5733
+ },
5734
+ {
5735
+ id: "grammar",
5736
+ label: "Fix Grammar",
5737
+ prompt: "Fix any spelling, punctuation, or grammar mistakes in the following text. Return only the corrected text."
5738
+ },
5739
+ {
5740
+ id: "professional",
5741
+ label: "Professional",
5742
+ prompt: "Rewrite the following text in a polished, professional tone. Return only the rewritten text."
5743
+ },
5744
+ {
5745
+ id: "translate",
5746
+ label: "Translate (ES)",
5747
+ prompt: "Translate the following text into natural Spanish. Return only the translated text."
5748
+ }
5749
+ ];
5750
+ var AiRewriteInline = class {
5751
+ savedRange = null;
5752
+ actionsEl = null;
5753
+ static get isInline() {
5754
+ return true;
5755
+ }
5756
+ static get title() {
5757
+ return "AI Rewrite";
5758
+ }
5759
+ static get sanitize() {
5760
+ return {};
5761
+ }
5762
+ render() {
5763
+ const btn = document.createElement("button");
5764
+ btn.type = "button";
5765
+ btn.className = "ce-inline-tool";
5766
+ btn.title = "AI Rewrite selection";
5767
+ btn.innerHTML = '<span style="font-size:12px;font-weight:700;">\u2726 AI</span>';
5768
+ return btn;
5769
+ }
5770
+ surround(range) {
5771
+ this.savedRange = range.cloneRange();
5772
+ if (this.actionsEl) {
5773
+ this.actionsEl.hidden = false;
5774
+ }
5775
+ }
5776
+ renderActions() {
5777
+ const wrap = document.createElement("div");
5778
+ wrap.className = "ng-inline-ai-actions";
5779
+ wrap.hidden = true;
5780
+ const status = document.createElement("span");
5781
+ status.className = "ng-inline-ai-status";
5782
+ const row = document.createElement("div");
5783
+ row.className = "ng-inline-ai-row";
5784
+ REWRITE_ACTIONS.forEach((act) => {
5785
+ const b = document.createElement("button");
5786
+ b.type = "button";
5787
+ b.className = "ng-inline-action-btn";
5788
+ b.textContent = act.label;
5789
+ b.addEventListener("click", async () => {
5790
+ const range = this.savedRange;
5791
+ const selected = range?.toString().trim() || "";
5792
+ if (!range || !selected) {
5793
+ status.textContent = "Select text first.";
5794
+ return;
5795
+ }
5796
+ status.textContent = "Rewriting\u2026";
5797
+ try {
5798
+ const rewritten = await generateAiText({
5799
+ config: loadAiConfig(),
5800
+ mode: "ask",
5801
+ prompt: `${act.prompt}
5802
+
5803
+ Text:
5804
+ "${selected}"`,
5805
+ context: selected
5806
+ });
5807
+ if (rewritten) {
5808
+ range.deleteContents();
5809
+ range.insertNode(document.createTextNode(rewritten));
5810
+ status.textContent = "Done";
5811
+ } else {
5812
+ status.textContent = "Empty response";
5813
+ }
5814
+ } catch (err) {
5815
+ status.textContent = err instanceof Error ? err.message : "AI error";
5816
+ }
5817
+ });
5818
+ row.appendChild(b);
5819
+ });
5820
+ wrap.append(row, status);
5821
+ this.actionsEl = wrap;
5822
+ return wrap;
5823
+ }
5824
+ checkState() {
5825
+ const sel = window.getSelection();
5826
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
5827
+ this.savedRange = sel.getRangeAt(0).cloneRange();
5828
+ }
5829
+ return false;
5830
+ }
5831
+ };
5832
+ var ColorInline = class {
5833
+ savedRange = null;
5834
+ actionsEl = null;
5835
+ static get isInline() {
5836
+ return true;
5837
+ }
5838
+ static get title() {
5839
+ return "Color & Highlight";
5840
+ }
5841
+ static get sanitize() {
5842
+ return {
5843
+ span: {
5844
+ class: "ng-inline-color",
5845
+ style: true
5846
+ }
5847
+ };
5848
+ }
5849
+ render() {
5850
+ const btn = document.createElement("button");
5851
+ btn.type = "button";
5852
+ btn.className = "ce-inline-tool";
5853
+ btn.title = "Text & Highlight Color";
5854
+ btn.innerHTML = '<span style="font-weight:700;font-size:12px;border-bottom:2px solid currentColor;">A</span>';
5855
+ return btn;
5856
+ }
5857
+ surround(range) {
5858
+ this.savedRange = range.cloneRange();
5859
+ if (this.actionsEl) {
5860
+ this.actionsEl.hidden = false;
5861
+ }
5862
+ }
5863
+ applyStyle(prop, value) {
5864
+ const range = this.savedRange;
5865
+ if (!range || range.collapsed) return;
5866
+ if (!value) {
5867
+ const span2 = document.createElement("span");
5868
+ span2.appendChild(range.extractContents());
5869
+ span2.querySelectorAll(".ng-inline-color").forEach((el) => {
5870
+ el.style[prop] = "";
5871
+ });
5872
+ range.insertNode(span2);
5873
+ return;
5874
+ }
5875
+ const span = document.createElement("span");
5876
+ span.className = "ng-inline-color";
5877
+ span.style[prop] = value;
5878
+ try {
5879
+ range.surroundContents(span);
5880
+ } catch {
5881
+ const frag = range.extractContents();
5882
+ span.appendChild(frag);
5883
+ range.insertNode(span);
5884
+ }
5885
+ }
5886
+ renderActions() {
5887
+ const wrap = document.createElement("div");
5888
+ wrap.className = "ng-inline-color-actions";
5889
+ wrap.hidden = true;
5890
+ const makeRow = (title, swatches, prop) => {
5891
+ const row = document.createElement("div");
5892
+ row.className = "ng-inline-swatch-row";
5893
+ const lbl = document.createElement("span");
5894
+ lbl.className = "ng-inline-swatch-label";
5895
+ lbl.textContent = title;
5896
+ row.appendChild(lbl);
5897
+ swatches.forEach((sw) => {
5898
+ const dot = document.createElement("button");
5899
+ dot.type = "button";
5900
+ dot.className = "ng-inline-swatch";
5901
+ dot.title = sw.label;
5902
+ dot.style.background = sw.value || "transparent";
5903
+ if (!sw.value) dot.textContent = "\xD7";
5904
+ dot.addEventListener("click", () => this.applyStyle(prop, sw.value));
5905
+ row.appendChild(dot);
5906
+ });
5907
+ return row;
5908
+ };
5909
+ wrap.append(
5910
+ makeRow("Text", TEXT_COLOR_SWATCHES, "color"),
5911
+ makeRow("Bg", HIGHLIGHT_SWATCHES, "backgroundColor")
5912
+ );
5913
+ this.actionsEl = wrap;
5914
+ return wrap;
5915
+ }
5916
+ checkState() {
5917
+ const sel = window.getSelection();
5918
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
5919
+ this.savedRange = sel.getRangeAt(0).cloneRange();
5920
+ }
5921
+ return false;
5922
+ }
5923
+ };
5924
+ var TodayTool = class {
5925
+ data;
5926
+ static get toolbox() {
5927
+ return {
5928
+ title: "Today Date",
5929
+ 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>'
5930
+ };
5931
+ }
5932
+ constructor({ data }) {
5933
+ const now = /* @__PURE__ */ new Date();
5934
+ this.data = {
5935
+ date: data?.date ?? now.toLocaleDateString(void 0, {
5936
+ year: "numeric",
5937
+ month: "long",
5938
+ day: "numeric"
5939
+ }),
5940
+ label: data?.label ?? "Date"
5941
+ };
5942
+ }
5943
+ render() {
5944
+ const wrap = document.createElement("div");
5945
+ wrap.className = "editor-today-pill";
5946
+ const badge = document.createElement("span");
5947
+ badge.className = "editor-today-badge";
5948
+ badge.textContent = `\u{1F4C5} ${this.data.date}`;
5949
+ const toggle = document.createElement("button");
5950
+ toggle.type = "button";
5951
+ toggle.className = "editor-mermaid-preset-btn";
5952
+ toggle.textContent = "ISO";
5953
+ toggle.addEventListener("click", () => {
5954
+ const now = /* @__PURE__ */ new Date();
5955
+ const iso = now.toISOString().slice(0, 10);
5956
+ const long = now.toLocaleDateString(void 0, {
5957
+ year: "numeric",
5958
+ month: "long",
5959
+ day: "numeric"
5960
+ });
5961
+ this.data.date = this.data.date === iso ? long : iso;
5962
+ badge.textContent = `\u{1F4C5} ${this.data.date}`;
5963
+ toggle.textContent = this.data.date === iso ? "Long" : "ISO";
5964
+ });
5965
+ wrap.append(badge, toggle);
5966
+ return wrap;
5967
+ }
5968
+ save() {
5969
+ return {
5970
+ date: this.data.date,
5971
+ label: this.data.label
5972
+ };
5973
+ }
5974
+ };
5975
+ var ExportTriggerTool = class {
5976
+ static get toolbox() {
5977
+ return {
5978
+ title: "Export / Import",
5979
+ 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>'
5980
+ };
5981
+ }
5982
+ render() {
5983
+ const el = document.createElement("div");
5984
+ el.className = "editor-export-trigger";
5985
+ el.textContent = "Opening Export & Markdown modal\u2026";
5986
+ queueMicrotask(() => {
5987
+ el.dispatchEvent(new CustomEvent("nextgen-open-export", { bubbles: true }));
5988
+ });
5989
+ return el;
5990
+ }
5991
+ save() {
5992
+ return {};
5993
+ }
5994
+ };
5995
+
5996
+ // src/editorTools.ts
5997
+ var CustomMediaTool = class {
5998
+ data;
5999
+ elements;
6000
+ constructor(options) {
6001
+ this.data = options.data || {};
6002
+ }
6003
+ static get toolbox() {
6004
+ return {
6005
+ title: "Image",
6006
+ 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>'
6007
+ };
6008
+ }
6009
+ render() {
6010
+ const root = document.createElement("div");
6011
+ root.className = "custom-media-fields";
6012
+ const input = document.createElement("input");
6013
+ input.type = "text";
6014
+ input.placeholder = "Paste image URL";
6015
+ input.value = this.data.url || "";
6016
+ const file = document.createElement("input");
6017
+ file.type = "file";
6018
+ file.accept = "image/*";
6019
+ const caption = document.createElement("input");
6020
+ caption.type = "text";
6021
+ caption.placeholder = "Caption";
6022
+ caption.value = this.data.caption || "";
6023
+ const preview = document.createElement("div");
6024
+ preview.className = "custom-media-preview";
6025
+ const paint = (url) => {
6026
+ preview.innerHTML = url ? `<img src="${escHtml(url)}" alt="">` : "";
6027
+ };
6028
+ paint(input.value);
6029
+ input.oninput = () => paint(input.value);
6030
+ file.onchange = async () => {
6031
+ const selected = file.files?.[0];
6032
+ if (!selected) return;
6033
+ const bucketUrl = await uploadFileToBucket(selected, "writing");
6034
+ if (bucketUrl) {
6035
+ input.value = bucketUrl;
6036
+ paint(bucketUrl);
6037
+ return;
6038
+ }
6039
+ const reader = new FileReader();
6040
+ reader.onload = () => {
6041
+ const res = String(reader.result || "");
6042
+ input.value = res;
6043
+ paint(res);
6044
+ };
6045
+ reader.readAsDataURL(selected);
6046
+ };
6047
+ root.append(input, file, caption, preview);
6048
+ this.elements = { root, input, caption };
6049
+ return root;
6050
+ }
6051
+ save() {
6052
+ return {
6053
+ url: this.elements?.input.value.trim() || "",
6054
+ caption: this.elements?.caption.value.trim() || ""
6055
+ };
6056
+ }
6057
+ };
6058
+ var GifTool = class {
6059
+ data;
6060
+ elements;
6061
+ constructor(options) {
6062
+ this.data = options.data || {};
6063
+ }
6064
+ static get toolbox() {
6065
+ return {
6066
+ title: "GIF",
6067
+ 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>'
6068
+ };
6069
+ }
6070
+ render() {
6071
+ const root = document.createElement("div");
6072
+ root.className = "custom-media-fields";
6073
+ const searchRow = document.createElement("div");
6074
+ searchRow.className = "gif-search-row";
6075
+ const searchInput = document.createElement("input");
6076
+ searchInput.type = "search";
6077
+ searchInput.placeholder = "Search free GIFs (trending or keyword)...";
6078
+ const searchBtn = document.createElement("button");
6079
+ searchBtn.type = "button";
6080
+ searchBtn.className = "b2";
6081
+ searchBtn.textContent = "Search";
6082
+ searchRow.append(searchInput, searchBtn);
6083
+ const resultsGrid = document.createElement("div");
6084
+ resultsGrid.className = "gif-picker-grid";
6085
+ const url = document.createElement("input");
6086
+ url.type = "url";
6087
+ url.placeholder = "Or paste GIF / image URL";
6088
+ url.value = this.data.url || "";
6089
+ const caption = document.createElement("input");
6090
+ caption.type = "text";
6091
+ caption.placeholder = "Caption";
6092
+ caption.value = this.data.caption || "";
6093
+ const preview = document.createElement("div");
6094
+ preview.className = "custom-media-preview";
6095
+ const paint = () => {
6096
+ preview.innerHTML = url.value ? `<img src="${escHtml(url.value)}" alt="${escHtml(caption.value || "GIF")}">` : "";
6097
+ };
6098
+ paint();
6099
+ url.oninput = paint;
6100
+ const runSearch = async (query) => {
6101
+ resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
6102
+ try {
6103
+ const res = await fetch(
6104
+ `/api/gifs?q=${encodeURIComponent(query)}&limit=12`
6105
+ );
6106
+ const json = await res.json();
6107
+ const items = json.results || [];
6108
+ if (!items.length) {
6109
+ resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
6110
+ return;
6111
+ }
6112
+ resultsGrid.innerHTML = "";
6113
+ items.forEach((item) => {
6114
+ const btn = document.createElement("button");
6115
+ btn.type = "button";
6116
+ btn.className = "gif-picker-item";
6117
+ btn.title = item.title;
6118
+ btn.innerHTML = `<img src="${escHtml(item.previewUrl)}" alt="${escHtml(item.title)}" loading="lazy">`;
6119
+ btn.onclick = () => {
6120
+ url.value = item.url;
6121
+ if (!caption.value) caption.value = item.title;
6122
+ paint();
6123
+ };
6124
+ resultsGrid.appendChild(btn);
6125
+ });
6126
+ } catch {
6127
+ resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
6128
+ }
6129
+ };
6130
+ searchBtn.onclick = () => void runSearch(searchInput.value);
6131
+ searchInput.addEventListener("keydown", (e) => {
6132
+ if (e.key === "Enter") {
6133
+ e.preventDefault();
6134
+ e.stopPropagation();
6135
+ void runSearch(searchInput.value);
6136
+ }
6137
+ });
6138
+ if (!this.data.url) {
6139
+ void runSearch("");
6140
+ }
6141
+ root.append(searchRow, resultsGrid, url, caption, preview);
6142
+ this.elements = { url, caption };
6143
+ return root;
6144
+ }
6145
+ save() {
6146
+ return {
6147
+ url: this.elements?.url.value.trim() || "",
6148
+ caption: this.elements?.caption.value.trim() || ""
6149
+ };
6150
+ }
6151
+ };
6152
+ var AttachTool = class {
6153
+ data;
6154
+ elements;
6155
+ constructor(options) {
6156
+ this.data = options.data || {};
6157
+ }
6158
+ static get toolbox() {
6159
+ return {
6160
+ title: "Attachment",
6161
+ 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>'
6162
+ };
6163
+ }
6164
+ render() {
6165
+ const root = document.createElement("div");
6166
+ root.className = "custom-media-fields";
6167
+ const file = document.createElement("input");
5119
6168
  file.type = "file";
5120
6169
  const name = document.createElement("input");
5121
6170
  name.type = "text";
@@ -5357,7 +6406,11 @@ var CustomEmbedTool = class {
5357
6406
  data;
5358
6407
  elements;
5359
6408
  constructor(options) {
5360
- this.data = options.data || {};
6409
+ this.data = {
6410
+ align: "center",
6411
+ size: "medium",
6412
+ ...options.data || {}
6413
+ };
5361
6414
  }
5362
6415
  static get toolbox() {
5363
6416
  return {
@@ -5418,15 +6471,20 @@ var CustomEmbedTool = class {
5418
6471
  caption.value = this.data.caption || "";
5419
6472
  const preview = document.createElement("div");
5420
6473
  preview.className = "custom-embed-preview";
6474
+ preview.dataset.align = this.data.align || "center";
6475
+ preview.dataset.size = this.data.size || "medium";
5421
6476
  const elements = {
5422
6477
  url,
5423
6478
  caption,
6479
+ preview,
5424
6480
  embedUrl: this.data.embed || this.toEmbedUrl(url.value)
5425
6481
  };
5426
6482
  this.elements = elements;
5427
6483
  const paint = () => {
5428
6484
  const embedUrl = this.toEmbedUrl(url.value);
5429
6485
  elements.embedUrl = embedUrl;
6486
+ preview.dataset.align = this.data.align || "center";
6487
+ preview.dataset.size = this.data.size || "medium";
5430
6488
  preview.innerHTML = embedUrl ? `<iframe src="${escHtml(embedUrl)}" title="${escHtml(
5431
6489
  caption.value || "Embedded content"
5432
6490
  )}" loading="lazy" allowfullscreen></iframe>` : "";
@@ -5440,13 +6498,96 @@ var CustomEmbedTool = class {
5440
6498
  root.append(url, caption, preview);
5441
6499
  return root;
5442
6500
  }
6501
+ renderSettings() {
6502
+ const tunes = [
6503
+ {
6504
+ name: "align-left",
6505
+ label: "Align Left",
6506
+ 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>',
6507
+ isActive: (this.data.align || "center") === "left",
6508
+ onActivate: () => {
6509
+ this.data.align = "left";
6510
+ if (this.elements?.preview) this.elements.preview.dataset.align = "left";
6511
+ }
6512
+ },
6513
+ {
6514
+ name: "align-center",
6515
+ label: "Align Center",
6516
+ 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>',
6517
+ isActive: (this.data.align || "center") === "center",
6518
+ onActivate: () => {
6519
+ this.data.align = "center";
6520
+ if (this.elements?.preview) this.elements.preview.dataset.align = "center";
6521
+ }
6522
+ },
6523
+ {
6524
+ name: "align-right",
6525
+ label: "Align Right",
6526
+ 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>',
6527
+ isActive: (this.data.align || "center") === "right",
6528
+ onActivate: () => {
6529
+ this.data.align = "right";
6530
+ if (this.elements?.preview) this.elements.preview.dataset.align = "right";
6531
+ }
6532
+ },
6533
+ {
6534
+ name: "size-small",
6535
+ label: "Small",
6536
+ icon: '<span style="font-size:11px;font-weight:700;">S</span>',
6537
+ isActive: (this.data.size || "medium") === "small",
6538
+ onActivate: () => {
6539
+ this.data.size = "small";
6540
+ if (this.elements?.preview) this.elements.preview.dataset.size = "small";
6541
+ }
6542
+ },
6543
+ {
6544
+ name: "size-medium",
6545
+ label: "Medium",
6546
+ icon: '<span style="font-size:11px;font-weight:700;">M</span>',
6547
+ isActive: (this.data.size || "medium") === "medium",
6548
+ onActivate: () => {
6549
+ this.data.size = "medium";
6550
+ if (this.elements?.preview) this.elements.preview.dataset.size = "medium";
6551
+ }
6552
+ },
6553
+ {
6554
+ name: "size-large",
6555
+ label: "Large",
6556
+ icon: '<span style="font-size:11px;font-weight:700;">L</span>',
6557
+ isActive: (this.data.size || "medium") === "large",
6558
+ onActivate: () => {
6559
+ this.data.size = "large";
6560
+ if (this.elements?.preview) this.elements.preview.dataset.size = "large";
6561
+ }
6562
+ },
6563
+ {
6564
+ name: "size-full",
6565
+ label: "Full Page",
6566
+ 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>',
6567
+ isActive: (this.data.size || "medium") === "full",
6568
+ onActivate: () => {
6569
+ this.data.size = "full";
6570
+ if (this.elements?.preview) this.elements.preview.dataset.size = "full";
6571
+ }
6572
+ }
6573
+ ];
6574
+ return tunes.map((t) => ({
6575
+ icon: t.icon,
6576
+ label: t.label,
6577
+ isActive: t.isActive,
6578
+ closeOnActivate: true,
6579
+ onActivate: t.onActivate
6580
+ }));
6581
+ }
5443
6582
  save() {
5444
6583
  const source = this.elements?.url.value.trim() || "";
5445
6584
  const embed = this.toEmbedUrl(source);
5446
6585
  return {
5447
6586
  source,
5448
6587
  embed,
5449
- caption: this.elements?.caption.value.trim() || ""
6588
+ caption: this.elements?.caption.value.trim() || "",
6589
+ align: this.data.align || "center",
6590
+ size: this.data.size || "medium"
5450
6591
  };
5451
6592
  }
5452
6593
  };
@@ -5896,6 +7037,8 @@ var SpoilerInline = class {
5896
7037
  }
5897
7038
  };
5898
7039
  var MentionInline = class {
7040
+ savedRange = null;
7041
+ actionsEl = null;
5899
7042
  static get isInline() {
5900
7043
  return true;
5901
7044
  }
@@ -5911,23 +7054,59 @@ var MentionInline = class {
5911
7054
  return button;
5912
7055
  }
5913
7056
  surround(range) {
5914
- const selectedText = range.toString().trim();
5915
- const url = window.prompt("Enter profile or mention URL (https://...)");
5916
- if (!url) return;
5917
- const anchor = document.createElement("a");
5918
- anchor.className = "editor-mention";
5919
- anchor.href = url.trim();
5920
- anchor.target = "_blank";
5921
- anchor.rel = "noopener noreferrer";
5922
- try {
5923
- range.surroundContents(anchor);
5924
- if (selectedText && !selectedText.startsWith("@")) {
5925
- anchor.textContent = `@${selectedText}`;
5926
- }
5927
- } catch {
7057
+ this.savedRange = range.cloneRange();
7058
+ if (this.actionsEl) {
7059
+ this.actionsEl.hidden = false;
7060
+ const input = this.actionsEl.querySelector("input");
7061
+ input?.focus();
5928
7062
  }
5929
7063
  }
7064
+ renderActions() {
7065
+ const wrap = document.createElement("div");
7066
+ wrap.className = "ng-mention-popover";
7067
+ wrap.hidden = true;
7068
+ const input = document.createElement("input");
7069
+ input.type = "url";
7070
+ input.className = "cdx-input";
7071
+ input.placeholder = "https://github.com/username";
7072
+ const applyBtn = document.createElement("button");
7073
+ applyBtn.type = "button";
7074
+ applyBtn.className = "ng-inline-action-btn";
7075
+ applyBtn.textContent = "Apply";
7076
+ const applyMention = (url) => {
7077
+ const range = this.savedRange;
7078
+ if (!range || !url.trim()) return;
7079
+ const selectedText = range.toString().trim();
7080
+ const anchor = document.createElement("a");
7081
+ anchor.className = "editor-mention";
7082
+ anchor.href = url.trim();
7083
+ anchor.target = "_blank";
7084
+ anchor.rel = "noopener noreferrer";
7085
+ try {
7086
+ range.surroundContents(anchor);
7087
+ if (selectedText && !selectedText.startsWith("@")) {
7088
+ anchor.textContent = `@${selectedText}`;
7089
+ }
7090
+ } catch {
7091
+ }
7092
+ wrap.hidden = true;
7093
+ };
7094
+ applyBtn.addEventListener("click", () => applyMention(input.value));
7095
+ input.addEventListener("keydown", (e) => {
7096
+ if (e.key === "Enter") {
7097
+ e.preventDefault();
7098
+ applyMention(input.value);
7099
+ }
7100
+ });
7101
+ wrap.append(input, applyBtn);
7102
+ this.actionsEl = wrap;
7103
+ return wrap;
7104
+ }
5930
7105
  checkState() {
7106
+ const sel = window.getSelection();
7107
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
7108
+ this.savedRange = sel.getRangeAt(0).cloneRange();
7109
+ }
5931
7110
  return false;
5932
7111
  }
5933
7112
  };
@@ -6026,7 +7205,6 @@ function getEditorTools(includeLayout = true, enabledTools) {
6026
7205
  }
6027
7206
  },
6028
7207
  delimiter: DelimiterTool,
6029
- checklist: import_checklist.default,
6030
7208
  table: import_table.default,
6031
7209
  callout: CalloutTool,
6032
7210
  hotkey: HotkeyTool,
@@ -6035,225 +7213,90 @@ function getEditorTools(includeLayout = true, enabledTools) {
6035
7213
  alert: AlertTool,
6036
7214
  // 2. Common rich media & layout
6037
7215
  upload: UploadTool,
6038
- audio: AudioPlayerTool,
6039
- musicCarousel: MusicCarouselTool,
6040
- embed: CustomEmbedTool,
6041
- gallery: LightboxGalleryTool,
6042
- masonry: MasonryTool,
6043
- carousel: CarouselTool,
6044
- bento: BentoTool,
6045
- ...includeLayout ? { layout: LayoutTool } : {},
6046
- tabs: TabsTool,
6047
- accordion: AccordionTool,
6048
- toggleh1: ToggleH1Tool,
6049
- toggleh2: ToggleH2Tool,
6050
- toggleh3: ToggleH3Tool,
6051
- // 3. Structured & editorial blocks
6052
- flashcards: FlashcardTool,
6053
- chart: ChartTool,
6054
- footnotes: FootnotesTool,
6055
- quiz: QuizTool,
6056
- kanban: KanbanTool,
6057
- timer: FocusTimerTool,
6058
- poll: PollTool,
6059
- faq: FaqTool,
6060
- todo: TaskChecklistTool,
6061
- eisenhower: EisenhowerMatrixTool,
6062
- form: FormBuilderTool,
6063
- latex: LatexTool,
6064
- excalidraw: ExcalidrawTool,
6065
- pullquote: PullQuoteTool,
6066
- timeline: TimelineTool,
6067
- stats: StatsTool,
6068
- proscons: ProsConsTool,
6069
- cards: CardsTool,
6070
- badges: BadgesTool,
6071
- tags: TagsTool,
6072
- button: ButtonTool,
6073
- dialogue: DialogueTool,
6074
- // 4. Specialized / least frequent blocks
6075
- gif: GifTool,
6076
- compare: CompareTool,
6077
- slides: SlidesTool,
6078
- spoiler: SpoilerTool,
6079
- collapsible: CollapsibleTool,
6080
- attaches: AttachTool,
6081
- nestedlist: import_nested_list.default,
6082
- simpleImage: import_simple_image.default,
6083
- comment: CommentTool,
6084
- continueWriting: ContinueWritingTool,
6085
- askAi: AskAiTool,
6086
- settings: SettingsTriggerTool,
6087
- // Inline toolbar tools
6088
- inlineCode: import_inline_code.default,
6089
- marker: MarkerInline,
6090
- spoilerInline: SpoilerInline,
6091
- underline: import_underline.default,
6092
- strikethrough: import_strikethrough.default,
6093
- hyperlink: HyperlinkInline,
6094
- mention: MentionInline
6095
- };
6096
- if (enabledTools && enabledTools.length > 0) {
6097
- const allowed = new Set(enabledTools);
6098
- return Object.fromEntries(
6099
- Object.entries(tools).filter(([key]) => allowed.has(key))
6100
- );
6101
- }
6102
- return tools;
6103
- }
6104
-
6105
- // src/utils/aiClient.ts
6106
- var AI_PROVIDER_PRESETS = [
6107
- {
6108
- id: "openai",
6109
- label: "OpenAI (ChatGPT)",
6110
- defaultModel: "gpt-4o-mini",
6111
- defaultEndpoint: "https://api.openai.com/v1/chat/completions"
6112
- },
6113
- {
6114
- id: "codex",
6115
- label: "OpenAI Codex",
6116
- defaultModel: "codex-mini-latest",
6117
- defaultEndpoint: "https://api.openai.com/v1/chat/completions"
6118
- },
6119
- {
6120
- id: "openrouter",
6121
- label: "OpenRouter",
6122
- defaultModel: "openai/gpt-4o-mini",
6123
- defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
6124
- },
6125
- {
6126
- id: "opencode",
6127
- label: "OpenCode",
6128
- defaultModel: "opencode/default",
6129
- defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
6130
- },
6131
- {
6132
- id: "anthropic",
6133
- label: "Anthropic (Claude)",
6134
- defaultModel: "claude-3-5-sonnet-latest",
6135
- defaultEndpoint: "https://api.anthropic.com/v1/messages"
6136
- },
6137
- {
6138
- id: "gemini",
6139
- label: "Google Gemini",
6140
- defaultModel: "gemini-2.5-flash",
6141
- defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
6142
- },
6143
- {
6144
- id: "custom",
6145
- label: "Custom OpenAI-Compatible",
6146
- defaultModel: "gpt-4o-mini",
6147
- defaultEndpoint: "http://localhost:11434/v1/chat/completions"
6148
- }
6149
- ];
6150
- var AI_STORAGE_KEY = "nextgen-editor-ai-config";
6151
- function loadAiConfig() {
6152
- try {
6153
- const raw = localStorage.getItem(AI_STORAGE_KEY);
6154
- if (raw) {
6155
- const parsed = JSON.parse(raw);
6156
- if (parsed.provider) {
6157
- return {
6158
- provider: parsed.provider,
6159
- model: parsed.model || "gpt-4o-mini",
6160
- apiKey: parsed.apiKey || "",
6161
- endpoint: parsed.endpoint || ""
6162
- };
6163
- }
6164
- }
6165
- } catch {
6166
- }
6167
- return {
6168
- provider: "openai",
6169
- model: "gpt-4o-mini",
6170
- apiKey: "",
6171
- endpoint: ""
6172
- };
6173
- }
6174
- function saveAiConfig(cfg) {
6175
- try {
6176
- localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
6177
- } catch {
6178
- }
6179
- }
6180
- async function generateAiText(params) {
6181
- const { config, mode, prompt, context } = params;
6182
- const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
6183
- const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
6184
- const model = (config.model || preset.defaultModel).trim();
6185
- const apiKey = config.apiKey.trim();
6186
- if (!apiKey && config.provider !== "custom") {
6187
- throw new Error("Please add an API key in Settings first.");
6188
- }
6189
- 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.";
6190
- const userContent = mode === "continue" ? `Document context:
6191
- ${context || "(Empty document)"}
6192
-
6193
- Continue writing naturally:` : `Document context:
6194
- ${context || "(Empty document)"}
6195
-
6196
- User request: ${prompt}`;
6197
- if (config.provider === "gemini") {
6198
- const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
6199
- model
6200
- )}:generateContent?key=${encodeURIComponent(apiKey)}`;
6201
- const res2 = await fetch(url, {
6202
- method: "POST",
6203
- headers: { "Content-Type": "application/json" },
6204
- body: JSON.stringify({
6205
- contents: [{ parts: [{ text: `${systemPrompt}
6206
-
6207
- ${userContent}` }] }]
6208
- })
6209
- });
6210
- if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
6211
- const json2 = await res2.json();
6212
- return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
6213
- }
6214
- if (config.provider === "anthropic") {
6215
- const res2 = await fetch(endpoint, {
6216
- method: "POST",
6217
- headers: {
6218
- "Content-Type": "application/json",
6219
- "x-api-key": apiKey,
6220
- "anthropic-version": "2023-06-01"
6221
- },
6222
- body: JSON.stringify({
6223
- model,
6224
- max_tokens: 1024,
6225
- system: systemPrompt,
6226
- messages: [{ role: "user", content: userContent }]
6227
- })
6228
- });
6229
- if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
6230
- const json2 = await res2.json();
6231
- return json2.content?.[0]?.text?.trim() || "";
6232
- }
6233
- const headers = {
6234
- "Content-Type": "application/json"
7216
+ audio: AudioPlayerTool,
7217
+ musicCarousel: MusicCarouselTool,
7218
+ embed: CustomEmbedTool,
7219
+ gallery: LightboxGalleryTool,
7220
+ masonry: MasonryTool,
7221
+ carousel: CarouselTool,
7222
+ bento: BentoTool,
7223
+ ...includeLayout ? { layout: LayoutTool } : {},
7224
+ tabs: TabsTool,
7225
+ accordion: AccordionTool,
7226
+ toggleh1: ToggleH1Tool,
7227
+ toggleh2: ToggleH2Tool,
7228
+ toggleh3: ToggleH3Tool,
7229
+ // 3. Structured & editorial blocks
7230
+ flashcards: FlashcardTool,
7231
+ chart: ChartTool,
7232
+ footnotes: FootnotesTool,
7233
+ quiz: QuizTool,
7234
+ kanban: KanbanTool,
7235
+ timer: FocusTimerTool,
7236
+ poll: PollTool,
7237
+ faq: FaqTool,
7238
+ todo: TaskChecklistTool,
7239
+ eisenhower: EisenhowerMatrixTool,
7240
+ form: FormBuilderTool,
7241
+ latex: LatexTool,
7242
+ mermaid: MermaidTool,
7243
+ bookmark: BookmarkTool,
7244
+ steps: StepsTool,
7245
+ diff: DiffTool,
7246
+ video: VideoTool,
7247
+ changelog: ChangelogTool,
7248
+ social: SocialTool,
7249
+ excalidraw: ExcalidrawTool,
7250
+ pullquote: PullQuoteTool,
7251
+ timeline: TimelineTool,
7252
+ stats: StatsTool,
7253
+ proscons: ProsConsTool,
7254
+ cards: CardsTool,
7255
+ badges: BadgesTool,
7256
+ tags: TagsTool,
7257
+ button: ButtonTool,
7258
+ dialogue: DialogueTool,
7259
+ // 4. Specialized / least frequent blocks
7260
+ gif: GifTool,
7261
+ compare: CompareTool,
7262
+ slides: SlidesTool,
7263
+ spoiler: SpoilerTool,
7264
+ collapsible: CollapsibleTool,
7265
+ attaches: AttachTool,
7266
+ nestedlist: import_nested_list.default,
7267
+ simpleImage: import_simple_image.default,
7268
+ comment: CommentTool,
7269
+ continueWriting: ContinueWritingTool,
7270
+ askAi: AskAiTool,
7271
+ today: TodayTool,
7272
+ export: ExportTriggerTool,
7273
+ settings: SettingsTriggerTool,
7274
+ // Inline toolbar tools
7275
+ inlineCode: import_inline_code.default,
7276
+ marker: MarkerInline,
7277
+ textColor: ColorInline,
7278
+ aiRewrite: AiRewriteInline,
7279
+ spoilerInline: SpoilerInline,
7280
+ underline: import_underline.default,
7281
+ strikethrough: import_strikethrough.default,
7282
+ hyperlink: HyperlinkInline,
7283
+ mention: MentionInline
6235
7284
  };
6236
- if (apiKey) {
6237
- headers.Authorization = `Bearer ${apiKey}`;
7285
+ if (enabledTools && enabledTools.length > 0) {
7286
+ const allowed = new Set(enabledTools);
7287
+ return Object.fromEntries(
7288
+ Object.entries(tools).filter(([key]) => allowed.has(key))
7289
+ );
6238
7290
  }
6239
- const res = await fetch(endpoint, {
6240
- method: "POST",
6241
- headers,
6242
- body: JSON.stringify({
6243
- model,
6244
- messages: [
6245
- { role: "system", content: systemPrompt },
6246
- { role: "user", content: userContent }
6247
- ]
6248
- })
6249
- });
6250
- if (!res.ok) throw new Error(`AI API error (${res.status})`);
6251
- const json = await res.json();
6252
- return json.choices?.[0]?.message?.content?.trim() || "";
7291
+ return tools;
6253
7292
  }
6254
7293
 
6255
7294
  // src/utils/popoverCategories.ts
6256
7295
  var TOOL_CATEGORIES = [
7296
+ {
7297
+ label: "AI",
7298
+ tools: ["continueWriting", "askAi"]
7299
+ },
6257
7300
  {
6258
7301
  label: "Text & Style",
6259
7302
  tools: [
@@ -6263,13 +7306,13 @@ var TOOL_CATEGORIES = [
6263
7306
  "paragraph",
6264
7307
  "list",
6265
7308
  "nestedlist",
6266
- "checklist",
6267
7309
  "quote",
6268
7310
  "pullquote",
6269
7311
  "delimiter",
6270
7312
  "callout",
6271
7313
  "hotkey",
6272
7314
  "emoji",
7315
+ "today",
6273
7316
  "scratch",
6274
7317
  "alert",
6275
7318
  "badges",
@@ -6309,6 +7352,8 @@ var TOOL_CATEGORIES = [
6309
7352
  "audio",
6310
7353
  "musicCarousel",
6311
7354
  "embed",
7355
+ "bookmark",
7356
+ "video",
6312
7357
  "attaches",
6313
7358
  "excalidraw"
6314
7359
  ]
@@ -6318,6 +7363,11 @@ var TOOL_CATEGORIES = [
6318
7363
  tools: [
6319
7364
  "code",
6320
7365
  "latex",
7366
+ "mermaid",
7367
+ "diff",
7368
+ "steps",
7369
+ "changelog",
7370
+ "social",
6321
7371
  "chart",
6322
7372
  "table",
6323
7373
  "stats",
@@ -6336,13 +7386,9 @@ var TOOL_CATEGORIES = [
6336
7386
  "slides"
6337
7387
  ]
6338
7388
  },
6339
- {
6340
- label: "AI",
6341
- tools: ["continueWriting", "askAi"]
6342
- },
6343
7389
  {
6344
7390
  label: "Settings",
6345
- tools: ["settings"]
7391
+ tools: ["export", "settings"]
6346
7392
  }
6347
7393
  ];
6348
7394
  var SIMPLE_MODE_TOOLS = [
@@ -6367,9 +7413,8 @@ var TOOL_LABELS = {
6367
7413
  h2: "Heading 2",
6368
7414
  h3: "Heading 3",
6369
7415
  paragraph: "Paragraph",
6370
- list: "List",
7416
+ list: "List (Ordered / Unordered / Checklist)",
6371
7417
  nestedlist: "Nested List",
6372
- checklist: "Checklist",
6373
7418
  quote: "Quote",
6374
7419
  pullquote: "Pull Quote",
6375
7420
  delimiter: "Delimiter",
@@ -6409,6 +7454,14 @@ var TOOL_LABELS = {
6409
7454
  excalidraw: "Excalidraw",
6410
7455
  code: "Code Block",
6411
7456
  latex: "LaTeX Math",
7457
+ mermaid: "Mermaid Diagram",
7458
+ bookmark: "Bookmark Card",
7459
+ steps: "Steps Walkthrough",
7460
+ diff: "Code Diff",
7461
+ video: "Video Player",
7462
+ changelog: "Changelog",
7463
+ social: "Social Quote",
7464
+ today: "Today Date",
6412
7465
  chart: "Data Chart",
6413
7466
  table: "Table",
6414
7467
  stats: "Stats",
@@ -6427,6 +7480,7 @@ var TOOL_LABELS = {
6427
7480
  slides: "Slides",
6428
7481
  continueWriting: "Continue Writing",
6429
7482
  askAi: "Ask AI",
7483
+ export: "Export / Import",
6430
7484
  settings: "Settings"
6431
7485
  };
6432
7486
  function attachPopoverCategoryHeaders(container) {
@@ -6454,18 +7508,25 @@ function attachPopoverCategoryHeaders(container) {
6454
7508
  titleEl.textContent = "Paragraph";
6455
7509
  }
6456
7510
  }
6457
- if (name) byName.set(name, el);
6458
- else uncategorized.push(el);
7511
+ if (name) {
7512
+ const arr = byName.get(name) || [];
7513
+ arr.push(el);
7514
+ byName.set(name, arr);
7515
+ } else {
7516
+ uncategorized.push(el);
7517
+ }
6459
7518
  });
6460
7519
  const frag = document.createDocumentFragment();
6461
7520
  const placed = /* @__PURE__ */ new Set();
6462
7521
  for (const group of TOOL_CATEGORIES) {
6463
7522
  const matched = [];
6464
7523
  for (const toolName of group.tools) {
6465
- const el = byName.get(toolName);
6466
- if (el && !placed.has(el)) {
6467
- matched.push(el);
6468
- placed.add(el);
7524
+ const els = byName.get(toolName) || [];
7525
+ for (const el of els) {
7526
+ if (!placed.has(el)) {
7527
+ matched.push(el);
7528
+ placed.add(el);
7529
+ }
6469
7530
  }
6470
7531
  }
6471
7532
  if (matched.length > 0) {
@@ -6642,6 +7703,28 @@ var ClassicToolbar = ({
6642
7703
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-s", onMouseDown: keepSelection, onClick: () => exec("strikeThrough"), title: "Strikethrough", children: "S" }),
6643
7704
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => toggleInlineTag("code"), title: "Inline Code", children: "<>" }),
6644
7705
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-highlight", onMouseDown: keepSelection, onClick: () => toggleInlineTag("mark"), title: "Highlight", children: "A" }),
7706
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
7707
+ "input",
7708
+ {
7709
+ type: "color",
7710
+ className: "ng-ct-color",
7711
+ title: "Text Color",
7712
+ "aria-label": "Text Color",
7713
+ defaultValue: "#18181b",
7714
+ onChange: (e) => exec("foreColor", e.target.value)
7715
+ }
7716
+ ),
7717
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
7718
+ "input",
7719
+ {
7720
+ type: "color",
7721
+ className: "ng-ct-color",
7722
+ title: "Highlight Color",
7723
+ "aria-label": "Highlight Color",
7724
+ defaultValue: "#fef08a",
7725
+ onChange: (e) => exec("hiliteColor", e.target.value)
7726
+ }
7727
+ ),
6645
7728
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6646
7729
  "button",
6647
7730
  {
@@ -6679,7 +7762,7 @@ var ClassicToolbar = ({
6679
7762
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 10h2" }),
6680
7763
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" })
6681
7764
  ] }) }),
6682
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("checklist", { items: [] }), title: "Checklist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
7765
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("list", { style: "checklist", items: [] }), title: "Checklist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6683
7766
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "5", width: "6", height: "6", rx: "1" }),
6684
7767
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3 17 2 2 4-4" }),
6685
7768
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 6h8" }),
@@ -6738,311 +7821,691 @@ var ClassicToolbar = ({
6738
7821
  setAlignOpen(false);
6739
7822
  }, children: "Justify" })
6740
7823
  ] })
6741
- ] }),
6742
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
6743
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-ct-dropdown-wrap", children: [
6744
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6745
- "button",
6746
- {
6747
- type: "button",
6748
- className: "ng-ct-insert-btn",
6749
- onClick: () => {
6750
- setInsertOpen((v) => !v);
6751
- setAlignOpen(false);
6752
- },
6753
- children: [
6754
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "+ Insert" }),
6755
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-caret", children: "\u25BE" })
6756
- ]
6757
- }
6758
- ),
6759
- insertOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ng-ct-menu ng-ct-insert-menu", children: visibleInsertItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6760
- "button",
6761
- {
6762
- type: "button",
6763
- onClick: () => insertBlock(item.tool),
6764
- children: [
6765
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: item.label }),
6766
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-cat", children: item.category })
6767
- ]
6768
- },
6769
- item.tool
6770
- )) })
7824
+ ] }),
7825
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
7826
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-ct-dropdown-wrap", children: [
7827
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
7828
+ "button",
7829
+ {
7830
+ type: "button",
7831
+ className: "ng-ct-insert-btn",
7832
+ onClick: () => {
7833
+ setInsertOpen((v) => !v);
7834
+ setAlignOpen(false);
7835
+ },
7836
+ children: [
7837
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "+ Insert" }),
7838
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-caret", children: "\u25BE" })
7839
+ ]
7840
+ }
7841
+ ),
7842
+ insertOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ng-ct-menu ng-ct-insert-menu", children: visibleInsertItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
7843
+ "button",
7844
+ {
7845
+ type: "button",
7846
+ onClick: () => insertBlock(item.tool),
7847
+ children: [
7848
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: item.label }),
7849
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-cat", children: item.category })
7850
+ ]
7851
+ },
7852
+ item.tool
7853
+ )) })
7854
+ ] })
7855
+ ] });
7856
+ };
7857
+
7858
+ // src/components/SettingsModal.tsx
7859
+ var import_react3 = require("react");
7860
+ var import_jsx_runtime2 = require("react/jsx-runtime");
7861
+ var SettingsModal = ({
7862
+ open,
7863
+ theme,
7864
+ docWidth,
7865
+ mode,
7866
+ showStats,
7867
+ aiConfig,
7868
+ selectedTools,
7869
+ allowedTools,
7870
+ canConfigureTools,
7871
+ developerRestricted,
7872
+ accessNoticeText,
7873
+ onChangeTheme,
7874
+ onChangeDocWidth,
7875
+ onChangeMode,
7876
+ onChangeShowStats,
7877
+ onChangeAiConfig,
7878
+ onChangeSelectedTools,
7879
+ onClose
7880
+ }) => {
7881
+ const [showKey, setShowKey] = (0, import_react3.useState)(false);
7882
+ const [toolFilter, setToolFilter] = (0, import_react3.useState)("");
7883
+ const [activeTab, setActiveTab] = (0, import_react3.useState)("appearance");
7884
+ if (!open) return null;
7885
+ const selectedSet = new Set(selectedTools);
7886
+ const toggleTool = (tool) => {
7887
+ const next = new Set(selectedTools);
7888
+ if (next.has(tool)) next.delete(tool);
7889
+ else next.add(tool);
7890
+ next.add("settings");
7891
+ onChangeSelectedTools(Array.from(next));
7892
+ };
7893
+ const handleProviderChange = (providerId) => {
7894
+ const preset = AI_PROVIDER_PRESETS.find((p) => p.id === providerId);
7895
+ onChangeAiConfig({
7896
+ ...aiConfig,
7897
+ provider: providerId,
7898
+ model: preset?.defaultModel || aiConfig.model,
7899
+ endpoint: preset?.defaultEndpoint || ""
7900
+ });
7901
+ };
7902
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal ng-modal-wide", children: [
7903
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-head", children: [
7904
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
7905
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: "Editor Settings" }),
7906
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Configure appearance, AI provider, and registered components." })
7907
+ ] }),
7908
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
7909
+ ] }),
7910
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-layout", children: [
7911
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("aside", { className: "ng-modal-sidebar", role: "tablist", "aria-label": "Settings sections", children: [
7912
+ { id: "appearance", label: "Appearance" },
7913
+ { id: "ai", label: "AI Provider" },
7914
+ { id: "components", label: `Components (${selectedSet.size})` }
7915
+ ].map((t) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7916
+ "button",
7917
+ {
7918
+ type: "button",
7919
+ role: "tab",
7920
+ "aria-selected": activeTab === t.id,
7921
+ className: `ng-modal-tab${activeTab === t.id ? " is-active" : ""}`,
7922
+ onClick: () => setActiveTab(t.id),
7923
+ children: t.label
7924
+ },
7925
+ t.id
7926
+ )) }),
7927
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-main", children: [
7928
+ activeTab === "appearance" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-panel", children: [
7929
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
7930
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Appearance" }),
7931
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
7932
+ "select",
7933
+ {
7934
+ className: "cdx-input editor-form-select",
7935
+ value: theme,
7936
+ onChange: (e) => onChangeTheme(e.target.value),
7937
+ children: [
7938
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
7939
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "light", children: "Light (White)" }),
7940
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "dark", children: "Dark (Black)" })
7941
+ ]
7942
+ }
7943
+ )
7944
+ ] }),
7945
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
7946
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Document Width" }),
7947
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-segmented", children: [
7948
+ { id: "narrow", label: "Narrow" },
7949
+ { id: "standard", label: "Standard" },
7950
+ { id: "full", label: "Full-Width" }
7951
+ ].map((w) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7952
+ "button",
7953
+ {
7954
+ type: "button",
7955
+ className: `excalidraw-btn${docWidth === w.id ? " is-active" : ""}`,
7956
+ onClick: () => onChangeDocWidth(w.id),
7957
+ children: w.label
7958
+ },
7959
+ w.id
7960
+ )) })
7961
+ ] }),
7962
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
7963
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Editor Mode" }),
7964
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-segmented", children: [
7965
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7966
+ "button",
7967
+ {
7968
+ type: "button",
7969
+ className: `excalidraw-btn${mode === "block" ? " is-active" : ""}`,
7970
+ onClick: () => onChangeMode("block"),
7971
+ children: "Block Editor (Full)"
7972
+ }
7973
+ ),
7974
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7975
+ "button",
7976
+ {
7977
+ type: "button",
7978
+ className: `excalidraw-btn${mode === "simple" ? " is-active" : ""}`,
7979
+ onClick: () => onChangeMode("simple"),
7980
+ children: "Simple Mode"
7981
+ }
7982
+ )
7983
+ ] })
7984
+ ] }),
7985
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field ng-field-inline", children: [
7986
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
7987
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7988
+ "input",
7989
+ {
7990
+ id: "ng-stats-toggle",
7991
+ type: "checkbox",
7992
+ checked: showStats,
7993
+ onChange: (e) => onChangeShowStats(e.target.checked)
7994
+ }
7995
+ )
7996
+ ] })
7997
+ ] }),
7998
+ activeTab === "ai" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-panel", children: [
7999
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
8000
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "AI Provider" }),
8001
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8002
+ "select",
8003
+ {
8004
+ className: "cdx-input editor-form-select",
8005
+ value: aiConfig.provider,
8006
+ onChange: (e) => handleProviderChange(e.target.value),
8007
+ children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: p.id, children: p.label }, p.id))
8008
+ }
8009
+ )
8010
+ ] }),
8011
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
8012
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Model" }),
8013
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8014
+ "input",
8015
+ {
8016
+ type: "text",
8017
+ className: "cdx-input editor-form-input",
8018
+ value: aiConfig.model,
8019
+ placeholder: "e.g. gpt-4o-mini",
8020
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
8021
+ }
8022
+ )
8023
+ ] }),
8024
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
8025
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "API Key" }),
8026
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-key-row", children: [
8027
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8028
+ "input",
8029
+ {
8030
+ type: showKey ? "text" : "password",
8031
+ className: "cdx-input editor-form-input",
8032
+ value: aiConfig.apiKey,
8033
+ placeholder: "sk-...",
8034
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
8035
+ }
8036
+ ),
8037
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8038
+ "button",
8039
+ {
8040
+ type: "button",
8041
+ className: "excalidraw-btn",
8042
+ onClick: () => setShowKey((s) => !s),
8043
+ children: showKey ? "Hide" : "Show"
8044
+ }
8045
+ )
8046
+ ] })
8047
+ ] }),
8048
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
8049
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Endpoint URL (optional)" }),
8050
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8051
+ "input",
8052
+ {
8053
+ type: "url",
8054
+ className: "cdx-input editor-form-input",
8055
+ value: aiConfig.endpoint || "",
8056
+ placeholder: "Default provider endpoint",
8057
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
8058
+ }
8059
+ )
8060
+ ] })
8061
+ ] }),
8062
+ activeTab === "components" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-manager", children: [
8063
+ (developerRestricted || !canConfigureTools) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-dev-access-bar", role: "status", children: [
8064
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: "Access Managed by Developer:" }),
8065
+ " ",
8066
+ accessNoticeText || "Some commands are not enabled for this workspace and are hidden."
8067
+ ] }),
8068
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-header", children: [
8069
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
8070
+ "Registered Components (",
8071
+ selectedSet.size,
8072
+ "/",
8073
+ developerRestricted && allowedTools ? allowedTools.length : ALL_TOOL_NAMES.length,
8074
+ ")"
8075
+ ] }) }),
8076
+ canConfigureTools && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-actions", children: [
8077
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8078
+ "button",
8079
+ {
8080
+ type: "button",
8081
+ className: "excalidraw-btn",
8082
+ onClick: () => onChangeSelectedTools(
8083
+ developerRestricted && allowedTools ? [...allowedTools] : [...ALL_TOOL_NAMES]
8084
+ ),
8085
+ children: "All"
8086
+ }
8087
+ ),
8088
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8089
+ "button",
8090
+ {
8091
+ type: "button",
8092
+ className: "excalidraw-btn",
8093
+ onClick: () => {
8094
+ const base = new Set(SIMPLE_MODE_TOOLS);
8095
+ const minimal = developerRestricted && allowedTools ? allowedTools.filter((t) => base.has(t)) : [...SIMPLE_MODE_TOOLS];
8096
+ onChangeSelectedTools(minimal);
8097
+ },
8098
+ children: "Minimal"
8099
+ }
8100
+ )
8101
+ ] })
8102
+ ] }),
8103
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8104
+ "input",
8105
+ {
8106
+ type: "search",
8107
+ className: "cdx-input editor-form-input",
8108
+ placeholder: "Filter components (e.g. bento, chart, spoiler...)",
8109
+ value: toolFilter,
8110
+ onChange: (e) => setToolFilter(e.target.value)
8111
+ }
8112
+ ),
8113
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
8114
+ const q = toolFilter.trim().toLowerCase();
8115
+ const allowedSet = developerRestricted && allowedTools ? new Set(allowedTools) : null;
8116
+ const visible = group.tools.filter((t) => {
8117
+ if (allowedSet && !allowedSet.has(t)) return false;
8118
+ const label = (TOOL_LABELS[t] || t).toLowerCase();
8119
+ return !q || label.includes(q) || t.toLowerCase().includes(q);
8120
+ });
8121
+ if (!visible.length) return null;
8122
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-group", children: [
8123
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-group-title", children: group.label }),
8124
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-grid", children: visible.map((tool) => {
8125
+ const checked = selectedSet.has(tool);
8126
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
8127
+ "label",
8128
+ {
8129
+ className: `ng-tool-chip${checked ? " is-checked" : ""}${!canConfigureTools ? " is-locked" : ""}`,
8130
+ children: [
8131
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8132
+ "input",
8133
+ {
8134
+ type: "checkbox",
8135
+ checked,
8136
+ disabled: !canConfigureTools,
8137
+ onChange: () => {
8138
+ if (canConfigureTools) toggleTool(tool);
8139
+ }
8140
+ }
8141
+ ),
8142
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: TOOL_LABELS[tool] || tool })
8143
+ ]
8144
+ },
8145
+ tool
8146
+ );
8147
+ }) })
8148
+ ] }, group.label);
8149
+ }) })
8150
+ ] })
8151
+ ] })
6771
8152
  ] })
6772
- ] });
8153
+ ] }) });
6773
8154
  };
6774
8155
 
6775
- // src/components/SettingsModal.tsx
6776
- var import_react3 = require("react");
6777
- var import_jsx_runtime2 = require("react/jsx-runtime");
6778
- var SettingsModal = ({
8156
+ // src/components/ExportModal.tsx
8157
+ var import_react4 = require("react");
8158
+
8159
+ // src/utils/markdown.ts
8160
+ function stripHtmlTags(html) {
8161
+ return String(html == null ? "" : html).replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|li)>/gi, "\n").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").trim();
8162
+ }
8163
+ function blocksToMarkdown(data) {
8164
+ if (!data || !Array.isArray(data.blocks)) return "";
8165
+ const parts = [];
8166
+ for (const block of data.blocks) {
8167
+ const d = block.data || {};
8168
+ switch (block.type) {
8169
+ case "header":
8170
+ case "h1":
8171
+ case "h2":
8172
+ case "h3": {
8173
+ const lvl = block.type === "h1" ? 1 : block.type === "h2" ? 2 : block.type === "h3" ? 3 : Number(d.level) || 2;
8174
+ parts.push(`${"#".repeat(Math.min(6, Math.max(1, lvl)))} ${stripHtmlTags(d.text)}`);
8175
+ break;
8176
+ }
8177
+ case "paragraph":
8178
+ parts.push(stripHtmlTags(d.text));
8179
+ break;
8180
+ case "quote":
8181
+ case "pullquote": {
8182
+ const quote = stripHtmlTags(d.text).split("\n").map((l) => `> ${l}`).join("\n");
8183
+ const cap = d.caption ? `
8184
+ > \u2014 ${stripHtmlTags(d.caption)}` : "";
8185
+ parts.push(`${quote}${cap}`);
8186
+ break;
8187
+ }
8188
+ case "list":
8189
+ case "nestedlist": {
8190
+ const ordered = d.style === "ordered";
8191
+ const items = Array.isArray(d.items) ? d.items : [];
8192
+ const lines = items.map((item, idx) => {
8193
+ const txt = typeof item === "string" ? item : item?.content || item?.text || "";
8194
+ return `${ordered ? `${idx + 1}.` : "-"} ${stripHtmlTags(txt)}`;
8195
+ });
8196
+ parts.push(lines.join("\n"));
8197
+ break;
8198
+ }
8199
+ case "checklist":
8200
+ case "todo": {
8201
+ const items = Array.isArray(d.items) ? d.items : [];
8202
+ parts.push(
8203
+ items.map((item) => `- [${item.checked || item.done ? "x" : " "}] ${stripHtmlTags(item.text || item.title)}`).join("\n")
8204
+ );
8205
+ break;
8206
+ }
8207
+ case "code":
8208
+ parts.push(`\`\`\`${d.language || ""}
8209
+ ${d.code || ""}
8210
+ \`\`\``);
8211
+ break;
8212
+ case "mermaid":
8213
+ parts.push(`\`\`\`mermaid
8214
+ ${d.code || ""}
8215
+ \`\`\``);
8216
+ break;
8217
+ case "latex":
8218
+ parts.push(`$$
8219
+ ${d.tex || ""}
8220
+ $$`);
8221
+ break;
8222
+ case "delimiter":
8223
+ parts.push("---");
8224
+ break;
8225
+ case "image":
8226
+ case "simpleImage": {
8227
+ const url = d.file?.url || d.url || "";
8228
+ if (url) parts.push(`![${stripHtmlTags(d.caption || "")}](${url})`);
8229
+ break;
8230
+ }
8231
+ case "bookmark":
8232
+ parts.push(`[${d.title || d.url || "Link"}](${d.url || "#"})`);
8233
+ break;
8234
+ case "steps": {
8235
+ const items = Array.isArray(d.items) ? d.items : [];
8236
+ parts.push(
8237
+ items.map((s, i) => `${i + 1}. **${s.title || ""}** \u2014 ${s.body || ""}`).join("\n")
8238
+ );
8239
+ break;
8240
+ }
8241
+ case "diff":
8242
+ parts.push(`\`\`\`diff
8243
+ - ${String(d.before || "").replace(/\n/g, "\n- ")}
8244
+ + ${String(d.after || "").replace(/\n/g, "\n+ ")}
8245
+ \`\`\``);
8246
+ break;
8247
+ case "changelog": {
8248
+ const items = Array.isArray(d.items) ? d.items : [];
8249
+ parts.push(
8250
+ `### ${d.version || "Release"} (${d.date || ""})
8251
+ ` + items.map((i) => `- **${(i.kind || "added").toUpperCase()}**: ${i.text || ""}`).join("\n")
8252
+ );
8253
+ break;
8254
+ }
8255
+ case "social":
8256
+ parts.push(`> ${d.text || ""}
8257
+ > \u2014 ${d.author || ""} (${d.handle || ""})`);
8258
+ break;
8259
+ case "today":
8260
+ parts.push(`\u{1F4C5} ${d.date || ""}`);
8261
+ break;
8262
+ default:
8263
+ if (d.text) parts.push(stripHtmlTags(d.text));
8264
+ break;
8265
+ }
8266
+ }
8267
+ return parts.filter(Boolean).join("\n\n");
8268
+ }
8269
+ function markdownToBlocks(markdown) {
8270
+ const lines = markdown.replace(/\r\n/g, "\n").split("\n");
8271
+ const blocks = [];
8272
+ let i = 0;
8273
+ while (i < lines.length) {
8274
+ const line = lines[i];
8275
+ const trimmed = line.trim();
8276
+ if (!trimmed) {
8277
+ i += 1;
8278
+ continue;
8279
+ }
8280
+ if (trimmed.startsWith("```")) {
8281
+ const lang = trimmed.slice(3).trim();
8282
+ const codeLines = [];
8283
+ i += 1;
8284
+ while (i < lines.length && !lines[i].trim().startsWith("```")) {
8285
+ codeLines.push(lines[i]);
8286
+ i += 1;
8287
+ }
8288
+ i += 1;
8289
+ if (lang === "mermaid") {
8290
+ blocks.push({ type: "mermaid", data: { code: codeLines.join("\n") } });
8291
+ } else {
8292
+ blocks.push({ type: "code", data: { code: codeLines.join("\n"), language: lang || void 0 } });
8293
+ }
8294
+ continue;
8295
+ }
8296
+ const headingMatch = trimmed.match(/^(#{1,3})\s+(.+)$/);
8297
+ if (headingMatch) {
8298
+ const level = headingMatch[1].length;
8299
+ const type = level === 1 ? "h1" : level === 2 ? "h2" : "h3";
8300
+ blocks.push({ type, data: { text: headingMatch[2], level } });
8301
+ i += 1;
8302
+ continue;
8303
+ }
8304
+ if (/^[-*_]{3,}$/.test(trimmed)) {
8305
+ blocks.push({ type: "delimiter", data: {} });
8306
+ i += 1;
8307
+ continue;
8308
+ }
8309
+ if (trimmed.startsWith("> ")) {
8310
+ const quoteLines = [];
8311
+ while (i < lines.length && lines[i].trim().startsWith("> ")) {
8312
+ quoteLines.push(lines[i].trim().slice(2));
8313
+ i += 1;
8314
+ }
8315
+ blocks.push({ type: "quote", data: { text: quoteLines.join("\n"), caption: "" } });
8316
+ continue;
8317
+ }
8318
+ if (/^[-*]\s+/.test(trimmed) || /^\d+\.\s+/.test(trimmed)) {
8319
+ const ordered = /^\d+\.\s+/.test(trimmed);
8320
+ const items = [];
8321
+ while (i < lines.length && (ordered ? /^\d+\.\s+/.test(lines[i].trim()) : /^[-*]\s+/.test(lines[i].trim()))) {
8322
+ items.push(lines[i].trim().replace(ordered ? /^\d+\.\s+/ : /^[-*]\s+/, ""));
8323
+ i += 1;
8324
+ }
8325
+ blocks.push({ type: "list", data: { style: ordered ? "ordered" : "unordered", items } });
8326
+ continue;
8327
+ }
8328
+ blocks.push({ type: "paragraph", data: { text: trimmed } });
8329
+ i += 1;
8330
+ }
8331
+ return blocks;
8332
+ }
8333
+
8334
+ // src/components/ExportModal.tsx
8335
+ var import_jsx_runtime3 = require("react/jsx-runtime");
8336
+ var ExportModal = ({
6779
8337
  open,
6780
- theme,
6781
- mode,
6782
- showStats,
6783
- aiConfig,
6784
- selectedTools,
6785
- onChangeTheme,
6786
- onChangeMode,
6787
- onChangeShowStats,
6788
- onChangeAiConfig,
6789
- onChangeSelectedTools,
8338
+ data,
8339
+ onImportBlocks,
6790
8340
  onClose
6791
8341
  }) => {
6792
- const [showKey, setShowKey] = (0, import_react3.useState)(false);
6793
- const [toolFilter, setToolFilter] = (0, import_react3.useState)("");
8342
+ const [importText, setImportText] = (0, import_react4.useState)("");
8343
+ const [copiedKind, setCopiedKind] = (0, import_react4.useState)(null);
8344
+ const markdown = (0, import_react4.useMemo)(() => open ? blocksToMarkdown(data) : "", [open, data]);
8345
+ const html = (0, import_react4.useMemo)(() => open ? blocksToHtml(data) : "", [open, data]);
6794
8346
  if (!open) return null;
6795
- const selectedSet = new Set(selectedTools);
6796
- const toggleTool = (tool) => {
6797
- const next = new Set(selectedTools);
6798
- if (next.has(tool)) next.delete(tool);
6799
- else next.add(tool);
6800
- next.add("settings");
6801
- onChangeSelectedTools(Array.from(next));
8347
+ const copyText = async (text, kind) => {
8348
+ try {
8349
+ await navigator.clipboard.writeText(text);
8350
+ setCopiedKind(kind);
8351
+ window.setTimeout(() => setCopiedKind(null), 1500);
8352
+ } catch {
8353
+ }
6802
8354
  };
6803
- const handleProviderChange = (providerId) => {
6804
- const preset = AI_PROVIDER_PRESETS.find((p) => p.id === providerId);
6805
- onChangeAiConfig({
6806
- ...aiConfig,
6807
- provider: providerId,
6808
- model: preset?.defaultModel || aiConfig.model,
6809
- endpoint: preset?.defaultEndpoint || ""
6810
- });
8355
+ const downloadFile = (content, filename, mime) => {
8356
+ const blob = new Blob([content], { type: mime });
8357
+ const url = URL.createObjectURL(blob);
8358
+ const a = document.createElement("a");
8359
+ a.href = url;
8360
+ a.download = filename;
8361
+ a.click();
8362
+ URL.revokeObjectURL(url);
6811
8363
  };
6812
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal", children: [
6813
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-head", children: [
6814
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
6815
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: "Editor Settings" }),
6816
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Configure appearance, editor mode, and AI provider." })
8364
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Export & Import", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-modal", children: [
8365
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-modal-head", children: [
8366
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
8367
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { children: "Export & Markdown" }),
8368
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: "Export to Markdown, HTML, PDF, or import Markdown into blocks." })
6817
8369
  ] }),
6818
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
8370
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
6819
8371
  ] }),
6820
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-body", children: [
6821
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6822
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Theme" }),
6823
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6824
- "select",
6825
- {
6826
- className: "cdx-input editor-form-select",
6827
- value: theme,
6828
- onChange: (e) => onChangeTheme(e.target.value),
6829
- children: [
6830
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
6831
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "light", children: "shadcn Light" }),
6832
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "dark", children: "shadcn Dark" }),
6833
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6834
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6835
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6836
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
6837
- ]
6838
- }
6839
- )
6840
- ] }),
6841
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6842
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Editor Mode" }),
6843
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-segmented", children: [
6844
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8372
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-modal-panel", children: [
8373
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-field", children: [
8374
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { children: "Quick Export" }),
8375
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-inline-ai-row", children: [
8376
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6845
8377
  "button",
6846
8378
  {
6847
8379
  type: "button",
6848
- className: `excalidraw-btn${mode === "block" ? " is-active" : ""}`,
6849
- onClick: () => onChangeMode("block"),
6850
- children: "Block Editor (Full)"
8380
+ className: "excalidraw-btn",
8381
+ onClick: () => void copyText(markdown, "md"),
8382
+ children: copiedKind === "md" ? "Copied MD!" : "Copy Markdown"
6851
8383
  }
6852
8384
  ),
6853
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8385
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6854
8386
  "button",
6855
8387
  {
6856
8388
  type: "button",
6857
- className: `excalidraw-btn${mode === "simple" ? " is-active" : ""}`,
6858
- onClick: () => onChangeMode("simple"),
6859
- children: "Simple Mode"
8389
+ className: "excalidraw-btn",
8390
+ onClick: () => downloadFile(markdown, "document.md", "text/markdown"),
8391
+ children: "Download .md"
6860
8392
  }
6861
- )
6862
- ] })
6863
- ] }),
6864
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field ng-field-inline", children: [
6865
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
6866
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6867
- "input",
6868
- {
6869
- id: "ng-stats-toggle",
6870
- type: "checkbox",
6871
- checked: showStats,
6872
- onChange: (e) => onChangeShowStats(e.target.checked)
6873
- }
6874
- )
6875
- ] }),
6876
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "ng-divider" }),
6877
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6878
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "AI Provider" }),
6879
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6880
- "select",
6881
- {
6882
- className: "cdx-input editor-form-select",
6883
- value: aiConfig.provider,
6884
- onChange: (e) => handleProviderChange(e.target.value),
6885
- children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: p.id, children: p.label }, p.id))
6886
- }
6887
- )
6888
- ] }),
6889
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6890
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Model" }),
6891
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6892
- "input",
6893
- {
6894
- type: "text",
6895
- className: "cdx-input editor-form-input",
6896
- value: aiConfig.model,
6897
- placeholder: "e.g. gpt-4o-mini",
6898
- onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
6899
- }
6900
- )
6901
- ] }),
6902
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6903
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "API Key" }),
6904
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-key-row", children: [
6905
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6906
- "input",
8393
+ ),
8394
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8395
+ "button",
6907
8396
  {
6908
- type: showKey ? "text" : "password",
6909
- className: "cdx-input editor-form-input",
6910
- value: aiConfig.apiKey,
6911
- placeholder: "sk-...",
6912
- onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
8397
+ type: "button",
8398
+ className: "excalidraw-btn",
8399
+ onClick: () => void copyText(html, "html"),
8400
+ children: copiedKind === "html" ? "Copied HTML!" : "Copy HTML"
6913
8401
  }
6914
8402
  ),
6915
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8403
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8404
+ "button",
8405
+ {
8406
+ type: "button",
8407
+ className: "excalidraw-btn",
8408
+ onClick: () => downloadFile(
8409
+ `<!doctype html><html><head><meta charset="utf-8"><title>Document</title></head><body>${html}</body></html>`,
8410
+ "document.html",
8411
+ "text/html"
8412
+ ),
8413
+ children: "Download .html"
8414
+ }
8415
+ ),
8416
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6916
8417
  "button",
6917
8418
  {
6918
8419
  type: "button",
6919
8420
  className: "excalidraw-btn",
6920
- onClick: () => setShowKey((s) => !s),
6921
- children: showKey ? "Hide" : "Show"
8421
+ onClick: () => window.print(),
8422
+ children: "Print / PDF"
6922
8423
  }
6923
8424
  )
6924
8425
  ] })
6925
8426
  ] }),
6926
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6927
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Endpoint URL (optional)" }),
6928
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6929
- "input",
8427
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-field", children: [
8428
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { children: "Import Markdown" }),
8429
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8430
+ "textarea",
6930
8431
  {
6931
- type: "url",
6932
- className: "cdx-input editor-form-input",
6933
- value: aiConfig.endpoint || "",
6934
- placeholder: "Default provider endpoint",
6935
- onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
8432
+ className: "editor-mermaid-input",
8433
+ rows: 5,
8434
+ placeholder: "Paste Markdown here (# Heading, - list, ```mermaid ...```)...",
8435
+ value: importText,
8436
+ onChange: (e) => setImportText(e.target.value)
6936
8437
  }
6937
- )
6938
- ] }),
6939
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "ng-divider" }),
6940
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-manager", children: [
6941
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-header", children: [
6942
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
6943
- "Registered Components (",
6944
- selectedSet.size,
6945
- "/",
6946
- ALL_TOOL_NAMES.length,
6947
- ")"
6948
- ] }) }),
6949
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-actions", children: [
6950
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6951
- "button",
6952
- {
6953
- type: "button",
6954
- className: "excalidraw-btn",
6955
- onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
6956
- children: "All"
6957
- }
6958
- ),
6959
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6960
- "button",
6961
- {
6962
- type: "button",
6963
- className: "excalidraw-btn",
6964
- onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
6965
- children: "Minimal"
6966
- }
6967
- )
6968
- ] })
6969
- ] }),
6970
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6971
- "input",
8438
+ ),
8439
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8440
+ "button",
6972
8441
  {
6973
- type: "search",
6974
- className: "cdx-input editor-form-input",
6975
- placeholder: "Filter components (e.g. bento, chart, spoiler...)",
6976
- value: toolFilter,
6977
- onChange: (e) => setToolFilter(e.target.value)
8442
+ type: "button",
8443
+ className: "excalidraw-btn is-active",
8444
+ disabled: !importText.trim(),
8445
+ onClick: () => {
8446
+ const blocks = markdownToBlocks(importText);
8447
+ if (blocks.length > 0) {
8448
+ onImportBlocks(blocks);
8449
+ setImportText("");
8450
+ onClose();
8451
+ }
8452
+ },
8453
+ children: "Append Markdown as Blocks"
6978
8454
  }
6979
- ),
6980
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
6981
- const q = toolFilter.trim().toLowerCase();
6982
- const visible = group.tools.filter((t) => {
6983
- const label = (TOOL_LABELS[t] || t).toLowerCase();
6984
- return !q || label.includes(q) || t.toLowerCase().includes(q);
6985
- });
6986
- if (!visible.length) return null;
6987
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-group", children: [
6988
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-group-title", children: group.label }),
6989
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-grid", children: visible.map((tool) => {
6990
- const checked = selectedSet.has(tool);
6991
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6992
- "label",
6993
- {
6994
- className: `ng-tool-chip${checked ? " is-checked" : ""}`,
6995
- children: [
6996
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6997
- "input",
6998
- {
6999
- type: "checkbox",
7000
- checked,
7001
- onChange: () => toggleTool(tool)
7002
- }
7003
- ),
7004
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: TOOL_LABELS[tool] || tool })
7005
- ]
7006
- },
7007
- tool
7008
- );
7009
- }) })
7010
- ] }, group.label);
7011
- }) })
8455
+ ) })
7012
8456
  ] })
7013
8457
  ] })
7014
8458
  ] }) });
7015
8459
  };
7016
8460
 
7017
8461
  // src/components/BlockEditor.tsx
7018
- var import_jsx_runtime3 = require("react/jsx-runtime");
7019
- var BlockEditor = import_react4.default.forwardRef(
8462
+ var import_jsx_runtime4 = require("react/jsx-runtime");
8463
+ var BlockEditor = import_react5.default.forwardRef(
7020
8464
  ({
7021
8465
  initialData,
7022
8466
  placeholder,
7023
8467
  enabledTools,
8468
+ allowToolConfiguration,
8469
+ accessNoticeText,
7024
8470
  showStats = true,
7025
8471
  showAiBar = false,
7026
8472
  onAiRequest,
7027
8473
  className,
7028
8474
  onReady,
7029
- onChange
8475
+ onChange,
8476
+ onThemeChange
7030
8477
  }, ref) => {
7031
- const shellRef = (0, import_react4.useRef)(null);
7032
- const holderRef = (0, import_react4.useRef)(null);
7033
- const editorRef = (0, import_react4.useRef)(null);
7034
- const undoRef = (0, import_react4.useRef)(null);
7035
- const lifecycleRef = (0, import_react4.useRef)(Promise.resolve());
7036
- const latestDocRef = (0, import_react4.useRef)(initialData || { blocks: [] });
7037
- const onChangeRef = (0, import_react4.useRef)(onChange);
7038
- const onReadyRef = (0, import_react4.useRef)(onReady);
7039
- const runAiRef = (0, import_react4.useRef)(async () => {
7040
- });
7041
- const [settingsOpen, setSettingsOpen] = (0, import_react4.useState)(false);
7042
- const [theme, setTheme] = (0, import_react4.useState)("inherit");
7043
- const [editorMode, setEditorMode] = (0, import_react4.useState)("block");
7044
- const [simpleFont, setSimpleFont] = (0, import_react4.useState)("sans");
7045
- const [selectedTools, setSelectedTools] = (0, import_react4.useState)(() => {
8478
+ const shellRef = (0, import_react5.useRef)(null);
8479
+ const holderRef = (0, import_react5.useRef)(null);
8480
+ const editorRef = (0, import_react5.useRef)(null);
8481
+ const undoRef = (0, import_react5.useRef)(null);
8482
+ const lifecycleRef = (0, import_react5.useRef)(Promise.resolve());
8483
+ const latestDocRef = (0, import_react5.useRef)(initialData || { blocks: [] });
8484
+ const onChangeRef = (0, import_react5.useRef)(onChange);
8485
+ const onReadyRef = (0, import_react5.useRef)(onReady);
8486
+ const runAiRef = (0, import_react5.useRef)(async () => {
8487
+ });
8488
+ const [settingsOpen, setSettingsOpen] = (0, import_react5.useState)(false);
8489
+ const [exportOpen, setExportOpen] = (0, import_react5.useState)(false);
8490
+ const [theme, setTheme] = (0, import_react5.useState)(() => {
8491
+ try {
8492
+ const saved = localStorage.getItem("ng-editor-theme");
8493
+ if (saved === "light" || saved === "dark" || saved === "inherit") return saved;
8494
+ } catch {
8495
+ }
8496
+ return "inherit";
8497
+ });
8498
+ const [docWidth, setDocWidth] = (0, import_react5.useState)(() => {
8499
+ try {
8500
+ const saved = localStorage.getItem("ng-editor-width");
8501
+ if (saved === "narrow" || saved === "standard" || saved === "full") return saved;
8502
+ } catch {
8503
+ }
8504
+ return "full";
8505
+ });
8506
+ const [editorMode, setEditorMode] = (0, import_react5.useState)("block");
8507
+ const [simpleFont, setSimpleFont] = (0, import_react5.useState)("sans");
8508
+ const [selectedTools, setSelectedTools] = (0, import_react5.useState)(() => {
7046
8509
  if (enabledTools && enabledTools.length > 0) return enabledTools;
7047
8510
  try {
7048
8511
  const raw = localStorage.getItem("ng-enabled-tools");
@@ -7054,13 +8517,28 @@ var BlockEditor = import_react4.default.forwardRef(
7054
8517
  }
7055
8518
  return ALL_TOOL_NAMES;
7056
8519
  });
7057
- const [statsVisible, setStatsVisible] = (0, import_react4.useState)(showStats);
7058
- const [aiConfig, setAiConfig] = (0, import_react4.useState)(loadAiConfig);
7059
- const [askOpen, setAskOpen] = (0, import_react4.useState)(false);
7060
- const [askPrompt, setAskPrompt] = (0, import_react4.useState)("");
7061
- const [aiBusy, setAiBusy] = (0, import_react4.useState)(false);
7062
- const [aiError, setAiError] = (0, import_react4.useState)(null);
7063
- const [stats, setStats] = (0, import_react4.useState)(() => {
8520
+ const [statsVisible, setStatsVisible] = (0, import_react5.useState)(showStats);
8521
+ const developerRestricted = Boolean(
8522
+ enabledTools && enabledTools.length > 0 && allowToolConfiguration !== true
8523
+ );
8524
+ const canConfigureTools = allowToolConfiguration ?? !developerRestricted;
8525
+ const effectiveSelectedTools = developerRestricted && enabledTools ? enabledTools : selectedTools;
8526
+ const [aiConfig, setAiConfig] = (0, import_react5.useState)(loadAiConfig);
8527
+ const [aiPopover, setAiPopover] = (0, import_react5.useState)(null);
8528
+ const [askPrompt, setAskPrompt] = (0, import_react5.useState)("");
8529
+ const [aiBusy, setAiBusy] = (0, import_react5.useState)(false);
8530
+ const [aiError, setAiError] = (0, import_react5.useState)(null);
8531
+ const [scratchOpen, setScratchOpen] = (0, import_react5.useState)(false);
8532
+ const [scratchText, setScratchText] = (0, import_react5.useState)(() => {
8533
+ try {
8534
+ return localStorage.getItem("ng-scratchpad-note") || "";
8535
+ } catch {
8536
+ return "";
8537
+ }
8538
+ });
8539
+ const [scratchCopied, setScratchCopied] = (0, import_react5.useState)(false);
8540
+ const [scratchOffset, setScratchOffset] = (0, import_react5.useState)({ x: 0, y: 0 });
8541
+ const [stats, setStats] = (0, import_react5.useState)(() => {
7064
8542
  const blocks = initialData?.blocks || [];
7065
8543
  const text = blocks.map((b) => JSON.stringify(b.data || {})).join(" ");
7066
8544
  const words = text.trim() ? text.trim().split(/\s+/).length : 0;
@@ -7068,38 +8546,87 @@ var BlockEditor = import_react4.default.forwardRef(
7068
8546
  });
7069
8547
  onChangeRef.current = onChange;
7070
8548
  onReadyRef.current = onReady;
7071
- (0, import_react4.useEffect)(() => {
8549
+ (0, import_react5.useEffect)(() => {
7072
8550
  setStatsVisible(showStats);
7073
8551
  }, [showStats]);
7074
- (0, import_react4.useEffect)(() => {
8552
+ (0, import_react5.useEffect)(() => {
8553
+ try {
8554
+ localStorage.setItem("ng-editor-theme", theme);
8555
+ } catch {
8556
+ }
8557
+ if (theme === "inherit") {
8558
+ document.documentElement.removeAttribute("data-ng-theme");
8559
+ } else {
8560
+ document.documentElement.setAttribute("data-ng-theme", theme);
8561
+ }
8562
+ onThemeChange?.(theme);
8563
+ }, [theme, onThemeChange]);
8564
+ (0, import_react5.useEffect)(() => {
7075
8565
  const shell = shellRef.current;
7076
8566
  if (!shell) return;
8567
+ const openAiNearRect = (mode, e) => {
8568
+ const rect = e.detail?.rect;
8569
+ const shellRect = shell.getBoundingClientRect();
8570
+ const popW = 320;
8571
+ const rawLeft = rect ? rect.left - shellRect.left : 60;
8572
+ const rawTop = rect ? rect.top - shellRect.top + 4 : 60;
8573
+ const maxLeft = Math.max(12, shellRect.width - popW - 12);
8574
+ const left = Math.max(12, Math.min(rawLeft, maxLeft));
8575
+ const top = Math.max(12, rawTop);
8576
+ setAiError(null);
8577
+ setAskPrompt("");
8578
+ setAiPopover({ mode, top, left });
8579
+ };
7077
8580
  const onOpenSettings = () => setSettingsOpen(true);
7078
- const onAiContinue = () => void runAiRef.current?.("continue");
7079
- const onAiAsk = () => setAskOpen(true);
8581
+ const onOpenExport = () => setExportOpen(true);
8582
+ const onAiContinue = (e) => openAiNearRect("continue", e);
8583
+ const onAiAsk = (e) => openAiNearRect("ask", e);
8584
+ const onOpenScratch = () => setScratchOpen(true);
8585
+ const onKeyDown = async (e) => {
8586
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "d") {
8587
+ e.preventDefault();
8588
+ const ed = editorRef.current;
8589
+ if (!ed) return;
8590
+ try {
8591
+ const idx = ed.blocks.getCurrentBlockIndex();
8592
+ const saved = await ed.save();
8593
+ const blk = saved.blocks?.[idx];
8594
+ if (blk) {
8595
+ ed.blocks.insert(blk.type, blk.data, {}, idx + 1, true);
8596
+ }
8597
+ } catch {
8598
+ }
8599
+ }
8600
+ };
7080
8601
  shell.addEventListener("nextgen-open-settings", onOpenSettings);
8602
+ shell.addEventListener("nextgen-open-export", onOpenExport);
7081
8603
  shell.addEventListener("nextgen-ai-continue", onAiContinue);
7082
8604
  shell.addEventListener("nextgen-ai-ask", onAiAsk);
8605
+ shell.addEventListener("nextgen-open-scratch", onOpenScratch);
8606
+ shell.addEventListener("keydown", onKeyDown);
7083
8607
  return () => {
7084
8608
  shell.removeEventListener("nextgen-open-settings", onOpenSettings);
8609
+ shell.removeEventListener("nextgen-open-export", onOpenExport);
7085
8610
  shell.removeEventListener("nextgen-ai-continue", onAiContinue);
7086
8611
  shell.removeEventListener("nextgen-ai-ask", onAiAsk);
8612
+ shell.removeEventListener("nextgen-open-scratch", onOpenScratch);
8613
+ shell.removeEventListener("keydown", onKeyDown);
7087
8614
  };
7088
8615
  }, []);
7089
- (0, import_react4.useEffect)(() => {
8616
+ (0, import_react5.useEffect)(() => {
7090
8617
  const holder = holderRef.current;
7091
8618
  if (!holder) return;
7092
8619
  let cancelled = false;
7093
8620
  const detachCategories = attachPopoverCategoryHeaders(holder);
7094
8621
  const detachEmoji = attachEmojiSidePicker(holder);
7095
- const effectiveTools = Array.from(/* @__PURE__ */ new Set([...selectedTools, "settings"]));
8622
+ const effectiveTools = Array.from(/* @__PURE__ */ new Set([...effectiveSelectedTools, "settings"]));
7096
8623
  const mount = async () => {
7097
8624
  await lifecycleRef.current;
7098
8625
  if (cancelled) return;
7099
8626
  const sanitizedInitial = {
7100
8627
  ...latestDocRef.current || { blocks: [] },
7101
8628
  blocks: (latestDocRef.current?.blocks || []).filter(
7102
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
8629
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7103
8630
  )
7104
8631
  };
7105
8632
  latestDocRef.current = sanitizedInitial;
@@ -7113,7 +8640,7 @@ var BlockEditor = import_react4.default.forwardRef(
7113
8640
  try {
7114
8641
  const saved = await instance.save();
7115
8642
  const filteredBlocks = (saved.blocks || []).filter(
7116
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
8643
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7117
8644
  );
7118
8645
  const typed = { ...saved, blocks: filteredBlocks };
7119
8646
  latestDocRef.current = typed;
@@ -7158,14 +8685,14 @@ var BlockEditor = import_react4.default.forwardRef(
7158
8685
  });
7159
8686
  }
7160
8687
  };
7161
- }, [editorMode, selectedTools]);
7162
- (0, import_react4.useImperativeHandle)(ref, () => ({
8688
+ }, [editorMode, effectiveSelectedTools]);
8689
+ (0, import_react5.useImperativeHandle)(ref, () => ({
7163
8690
  save: async () => {
7164
8691
  if (!editorRef.current) return null;
7165
8692
  await editorRef.current.isReady;
7166
8693
  const saved = await editorRef.current.save();
7167
8694
  const filteredBlocks = (saved.blocks || []).filter(
7168
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
8695
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7169
8696
  );
7170
8697
  const typed = { ...saved, blocks: filteredBlocks };
7171
8698
  latestDocRef.current = typed;
@@ -7212,7 +8739,7 @@ var BlockEditor = import_react4.default.forwardRef(
7212
8739
  }
7213
8740
  if (mode === "ask") {
7214
8741
  setAskPrompt("");
7215
- setAskOpen(false);
8742
+ setAiPopover(null);
7216
8743
  }
7217
8744
  } catch (err) {
7218
8745
  setAiError(err instanceof Error ? err.message : "AI request failed.");
@@ -7234,17 +8761,18 @@ var BlockEditor = import_react4.default.forwardRef(
7234
8761
  setEditorMode(nextMode);
7235
8762
  };
7236
8763
  const readMins = Math.max(1, Math.ceil(stats.words / 200));
7237
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
8764
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
7238
8765
  "div",
7239
8766
  {
7240
8767
  ref: shellRef,
7241
8768
  "data-ng-theme": theme === "inherit" ? void 0 : theme,
8769
+ "data-ng-width": docWidth,
7242
8770
  "data-ng-font": editorMode === "simple" ? simpleFont : void 0,
7243
8771
  className: className ? `nextgen-editor-shell ${className}` : "nextgen-editor-shell",
7244
8772
  children: [
7245
- showAiBar && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-bar", children: [
7246
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-actions", children: [
7247
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8773
+ showAiBar && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "ng-ai-bar", children: [
8774
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "ng-ai-actions", children: [
8775
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7248
8776
  "button",
7249
8777
  {
7250
8778
  type: "button",
@@ -7254,18 +8782,20 @@ var BlockEditor = import_react4.default.forwardRef(
7254
8782
  children: aiBusy ? "Thinking\u2026" : "\u2726 Continue Writing"
7255
8783
  }
7256
8784
  ),
7257
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8785
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7258
8786
  "button",
7259
8787
  {
7260
8788
  type: "button",
7261
- className: `excalidraw-btn${askOpen ? " is-active" : ""}`,
8789
+ className: `excalidraw-btn${aiPopover?.mode === "ask" ? " is-active" : ""}`,
7262
8790
  disabled: aiBusy,
7263
- onClick: () => setAskOpen((o) => !o),
8791
+ onClick: () => setAiPopover(
8792
+ (p) => p ? null : { mode: "ask", top: 120, left: 120 }
8793
+ ),
7264
8794
  children: "Ask AI"
7265
8795
  }
7266
8796
  )
7267
8797
  ] }),
7268
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8798
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7269
8799
  "button",
7270
8800
  {
7271
8801
  type: "button",
@@ -7276,31 +8806,7 @@ var BlockEditor = import_react4.default.forwardRef(
7276
8806
  }
7277
8807
  )
7278
8808
  ] }),
7279
- askOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
7280
- "form",
7281
- {
7282
- className: "ng-ask-form",
7283
- onSubmit: (e) => {
7284
- e.preventDefault();
7285
- if (askPrompt.trim()) void runAi("ask", askPrompt.trim());
7286
- },
7287
- children: [
7288
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7289
- "input",
7290
- {
7291
- type: "text",
7292
- className: "cdx-input editor-form-input",
7293
- placeholder: "Ask AI to draft, summarize, or expand...",
7294
- value: askPrompt,
7295
- onChange: (e) => setAskPrompt(e.target.value)
7296
- }
7297
- ),
7298
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "editor-form-submit", disabled: aiBusy, children: aiBusy ? "Running\u2026" : "Generate" })
7299
- ]
7300
- }
7301
- ),
7302
- aiError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ng-ai-error", children: aiError }),
7303
- editorMode === "simple" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8809
+ editorMode === "simple" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7304
8810
  ClassicToolbar,
7305
8811
  {
7306
8812
  editorRef,
@@ -7308,38 +8814,50 @@ var BlockEditor = import_react4.default.forwardRef(
7308
8814
  onRedo: () => undoRef.current?.redo?.(),
7309
8815
  fontFamily: simpleFont,
7310
8816
  onChangeFontFamily: setSimpleFont,
7311
- enabledTools: selectedTools,
8817
+ enabledTools: effectiveSelectedTools,
7312
8818
  onOpenSettings: () => setSettingsOpen(true)
7313
8819
  }
7314
8820
  ),
7315
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { id: "editorjs", ref: holderRef }),
7316
- statsVisible && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "nextgen-editor-stats", children: [
7317
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
7318
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u2022" }),
7319
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
8821
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: "editorjs", ref: holderRef }),
8822
+ statsVisible && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "nextgen-editor-stats", children: [
8823
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
8824
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: "\u2022" }),
8825
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
7320
8826
  stats.blocks,
7321
8827
  " blocks"
7322
8828
  ] }),
7323
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
8829
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
7324
8830
  stats.words,
7325
8831
  " words"
7326
8832
  ] }),
7327
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
8833
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { children: [
7328
8834
  "~",
7329
8835
  readMins,
7330
8836
  " min read"
7331
8837
  ] })
7332
8838
  ] }),
7333
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8839
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7334
8840
  SettingsModal,
7335
8841
  {
7336
8842
  open: settingsOpen,
7337
8843
  theme,
8844
+ docWidth,
7338
8845
  mode: editorMode,
7339
8846
  showStats: statsVisible,
7340
8847
  aiConfig,
7341
- selectedTools,
8848
+ selectedTools: effectiveSelectedTools,
8849
+ allowedTools: enabledTools,
8850
+ canConfigureTools,
8851
+ developerRestricted,
8852
+ accessNoticeText,
7342
8853
  onChangeTheme: setTheme,
8854
+ onChangeDocWidth: (w) => {
8855
+ setDocWidth(w);
8856
+ try {
8857
+ localStorage.setItem("ng-editor-width", w);
8858
+ } catch {
8859
+ }
8860
+ },
7343
8861
  onChangeMode: (m) => void handleModeSwitch(m),
7344
8862
  onChangeShowStats: setStatsVisible,
7345
8863
  onChangeAiConfig: (cfg) => {
@@ -7356,6 +8874,176 @@ var BlockEditor = import_react4.default.forwardRef(
7356
8874
  },
7357
8875
  onClose: () => setSettingsOpen(false)
7358
8876
  }
8877
+ ),
8878
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8879
+ ExportModal,
8880
+ {
8881
+ open: exportOpen,
8882
+ data: latestDocRef.current,
8883
+ onImportBlocks: (blocks) => {
8884
+ const ed = editorRef.current;
8885
+ if (!ed) return;
8886
+ blocks.forEach((b) => {
8887
+ ed.blocks.insert(b.type, b.data);
8888
+ });
8889
+ },
8890
+ onClose: () => setExportOpen(false)
8891
+ }
8892
+ ),
8893
+ aiPopover && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
8894
+ "form",
8895
+ {
8896
+ className: "ng-ai-inline-popover",
8897
+ style: { top: `${aiPopover.top}px`, left: `${aiPopover.left}px` },
8898
+ onSubmit: (e) => {
8899
+ e.preventDefault();
8900
+ if (aiPopover.mode === "continue") {
8901
+ void runAi("continue", askPrompt.trim());
8902
+ } else if (askPrompt.trim()) {
8903
+ void runAi("ask", askPrompt.trim());
8904
+ }
8905
+ },
8906
+ children: [
8907
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "ng-ai-inline-head", children: [
8908
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: aiPopover.mode === "continue" ? "\u2726 Continue Writing" : "Ask AI" }),
8909
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8910
+ "button",
8911
+ {
8912
+ type: "button",
8913
+ className: "b2",
8914
+ "aria-label": "Close AI prompt",
8915
+ onClick: () => setAiPopover(null),
8916
+ children: "\xD7"
8917
+ }
8918
+ )
8919
+ ] }),
8920
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "ng-ai-inline-row", children: [
8921
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8922
+ "input",
8923
+ {
8924
+ type: "text",
8925
+ autoFocus: true,
8926
+ className: "cdx-input editor-form-input",
8927
+ placeholder: aiPopover.mode === "continue" ? "How should AI continue? (optional)" : "What do you want AI to write?",
8928
+ value: askPrompt,
8929
+ onChange: (e) => setAskPrompt(e.target.value),
8930
+ onKeyDown: (e) => {
8931
+ if (e.key === "Escape") setAiPopover(null);
8932
+ }
8933
+ }
8934
+ ),
8935
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8936
+ "button",
8937
+ {
8938
+ type: "submit",
8939
+ className: "editor-form-submit",
8940
+ disabled: aiBusy || aiPopover.mode === "ask" && !askPrompt.trim(),
8941
+ children: aiBusy ? "Running\u2026" : aiPopover.mode === "continue" ? "Continue" : "Generate"
8942
+ }
8943
+ )
8944
+ ] }),
8945
+ aiError && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "ng-ai-error", children: aiError })
8946
+ ]
8947
+ }
8948
+ ),
8949
+ scratchOpen && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
8950
+ "div",
8951
+ {
8952
+ className: "ng-scratch-sticky",
8953
+ role: "dialog",
8954
+ "aria-label": "Scratchpad sticky note",
8955
+ style: {
8956
+ transform: `translate(${scratchOffset.x}px, ${scratchOffset.y}px)`
8957
+ },
8958
+ children: [
8959
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
8960
+ "div",
8961
+ {
8962
+ className: "ng-scratch-sticky-head",
8963
+ onMouseDown: (e) => {
8964
+ if (e.target.closest("button")) return;
8965
+ const startX = e.clientX - scratchOffset.x;
8966
+ const startY = e.clientY - scratchOffset.y;
8967
+ const onMove = (ev) => {
8968
+ setScratchOffset({ x: ev.clientX - startX, y: ev.clientY - startY });
8969
+ };
8970
+ const onUp = () => {
8971
+ window.removeEventListener("mousemove", onMove);
8972
+ window.removeEventListener("mouseup", onUp);
8973
+ };
8974
+ window.addEventListener("mousemove", onMove);
8975
+ window.addEventListener("mouseup", onUp);
8976
+ },
8977
+ children: [
8978
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "ng-scratch-sticky-title", children: "\u{1F4DD} Scratchpad" }),
8979
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "ng-scratch-sticky-count", children: [
8980
+ scratchText.trim() ? scratchText.trim().split(/\s+/).length : 0,
8981
+ "w \xB7 ",
8982
+ scratchText.length,
8983
+ "c"
8984
+ ] }),
8985
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "ng-scratch-sticky-actions", children: [
8986
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8987
+ "button",
8988
+ {
8989
+ type: "button",
8990
+ className: "ng-scratch-sticky-btn",
8991
+ onClick: () => {
8992
+ if (!scratchText) return;
8993
+ void navigator.clipboard?.writeText(scratchText);
8994
+ setScratchCopied(true);
8995
+ window.setTimeout(() => setScratchCopied(false), 1200);
8996
+ },
8997
+ children: scratchCopied ? "Copied" : "Copy"
8998
+ }
8999
+ ),
9000
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9001
+ "button",
9002
+ {
9003
+ type: "button",
9004
+ className: "ng-scratch-sticky-btn",
9005
+ onClick: () => {
9006
+ setScratchText("");
9007
+ try {
9008
+ localStorage.setItem("ng-scratchpad-note", "");
9009
+ } catch {
9010
+ }
9011
+ },
9012
+ children: "Clear"
9013
+ }
9014
+ ),
9015
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9016
+ "button",
9017
+ {
9018
+ type: "button",
9019
+ className: "ng-scratch-sticky-btn",
9020
+ "aria-label": "Close scratchpad",
9021
+ onClick: () => setScratchOpen(false),
9022
+ children: "\xD7"
9023
+ }
9024
+ )
9025
+ ] })
9026
+ ]
9027
+ }
9028
+ ),
9029
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9030
+ "textarea",
9031
+ {
9032
+ className: "ng-scratch-sticky-body",
9033
+ placeholder: "Quick sticky note, rough ideas, snippets...",
9034
+ value: scratchText,
9035
+ onChange: (e) => {
9036
+ const val = e.target.value;
9037
+ setScratchText(val);
9038
+ try {
9039
+ localStorage.setItem("ng-scratchpad-note", val);
9040
+ } catch {
9041
+ }
9042
+ }
9043
+ }
9044
+ )
9045
+ ]
9046
+ }
7359
9047
  )
7360
9048
  ]
7361
9049
  }
@@ -7365,13 +9053,13 @@ var BlockEditor = import_react4.default.forwardRef(
7365
9053
  BlockEditor.displayName = "BlockEditor";
7366
9054
 
7367
9055
  // src/components/BlockRenderer.tsx
7368
- var import_react6 = require("react");
9056
+ var import_react7 = require("react");
7369
9057
 
7370
9058
  // src/hooks/useInteractiveArticle.ts
7371
9059
  var import_auto2 = __toESM(require("chart.js/auto"), 1);
7372
- var import_react5 = require("react");
9060
+ var import_react6 = require("react");
7373
9061
  function useInteractiveArticle(containerRef, depKey) {
7374
- (0, import_react5.useEffect)(() => {
9062
+ (0, import_react6.useEffect)(() => {
7375
9063
  const root = containerRef.current;
7376
9064
  if (!root) return;
7377
9065
  const cleanups = [];
@@ -8054,6 +9742,12 @@ function useInteractiveArticle(containerRef, depKey) {
8054
9742
  btn.addEventListener("click", onOpen);
8055
9743
  cleanups.push(() => btn.removeEventListener("click", onOpen));
8056
9744
  });
9745
+ root.querySelectorAll("[data-mermaid]").forEach((el) => {
9746
+ const code = el.getAttribute("data-mermaid") || "";
9747
+ if (code.trim()) {
9748
+ void renderMermaidInto(el, code);
9749
+ }
9750
+ });
8057
9751
  return () => {
8058
9752
  cleanups.forEach((fn) => fn());
8059
9753
  };
@@ -8061,26 +9755,60 @@ function useInteractiveArticle(containerRef, depKey) {
8061
9755
  }
8062
9756
 
8063
9757
  // src/components/BlockRenderer.tsx
8064
- var import_jsx_runtime4 = require("react/jsx-runtime");
9758
+ var import_jsx_runtime5 = require("react/jsx-runtime");
8065
9759
  var BlockRenderer = ({
8066
9760
  data,
9761
+ theme,
8067
9762
  className
8068
9763
  }) => {
8069
- const bodyRef = (0, import_react6.useRef)(null);
8070
- const html = (0, import_react6.useMemo)(() => blocksToHtml(data), [data]);
9764
+ const bodyRef = (0, import_react7.useRef)(null);
9765
+ const [progress, setProgress] = (0, import_react7.useState)(0);
9766
+ const html = (0, import_react7.useMemo)(() => blocksToHtml(data), [data]);
8071
9767
  useInteractiveArticle(bodyRef, html);
8072
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
9768
+ (0, import_react7.useEffect)(() => {
9769
+ const updateProgress = () => {
9770
+ const el = bodyRef.current;
9771
+ if (!el) return;
9772
+ const rect = el.getBoundingClientRect();
9773
+ const total = Math.max(1, el.scrollHeight - window.innerHeight);
9774
+ const scrolled = Math.min(total, Math.max(0, -rect.top));
9775
+ setProgress(Math.round(scrolled / total * 100));
9776
+ };
9777
+ updateProgress();
9778
+ window.addEventListener("scroll", updateProgress, { passive: true });
9779
+ window.addEventListener("resize", updateProgress);
9780
+ return () => {
9781
+ window.removeEventListener("scroll", updateProgress);
9782
+ window.removeEventListener("resize", updateProgress);
9783
+ };
9784
+ }, [html]);
9785
+ let resolvedTheme = theme;
9786
+ if (!resolvedTheme && typeof window !== "undefined") {
9787
+ resolvedTheme = document.documentElement.getAttribute("data-ng-theme") || (() => {
9788
+ try {
9789
+ return localStorage.getItem("ng-editor-theme") || void 0;
9790
+ } catch {
9791
+ return void 0;
9792
+ }
9793
+ })();
9794
+ }
9795
+ const attrTheme = resolvedTheme === "light" || resolvedTheme === "dark" ? resolvedTheme : void 0;
9796
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
8073
9797
  "div",
8074
9798
  {
8075
9799
  ref: bodyRef,
9800
+ "data-ng-theme": attrTheme,
8076
9801
  className: className ? `article nextgen-editor-article ${className}` : "article nextgen-editor-article",
8077
- dangerouslySetInnerHTML: { __html: html }
9802
+ children: [
9803
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "ng-reading-progress", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "ng-reading-progress-fill", style: { width: `${progress}%` } }) }),
9804
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { dangerouslySetInnerHTML: { __html: html } })
9805
+ ]
8078
9806
  }
8079
9807
  );
8080
9808
  };
8081
9809
 
8082
9810
  // src/components/DocumentHeader.tsx
8083
- var import_jsx_runtime5 = require("react/jsx-runtime");
9811
+ var import_jsx_runtime6 = require("react/jsx-runtime");
8084
9812
  var DocumentHeader = ({
8085
9813
  coverUrl,
8086
9814
  gradient = "linear-gradient(135deg, #27272a 0%, #52525b 100%)",
@@ -8090,12 +9818,12 @@ var DocumentHeader = ({
8090
9818
  className
8091
9819
  }) => {
8092
9820
  const bannerStyle = coverUrl ? { backgroundImage: `url("${coverUrl}")`, backgroundSize: "cover", backgroundPosition: "center" } : { background: gradient };
8093
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
8094
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "editor-cover-banner", style: bannerStyle }),
8095
- icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "editor-cover-icon", children: icon }) : null,
8096
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "editor-cover-meta", children: [
8097
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { className: "editor-cover-title", children: title }),
8098
- subtitle ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "editor-cover-subtitle", children: subtitle }) : null
9821
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
9822
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "editor-cover-banner", style: bannerStyle }),
9823
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "editor-cover-icon", children: icon }) : null,
9824
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "editor-cover-meta", children: [
9825
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h1", { className: "editor-cover-title", children: title }),
9826
+ subtitle ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "editor-cover-subtitle", children: subtitle }) : null
8099
9827
  ] })
8100
9828
  ] });
8101
9829
  };
@@ -8105,8 +9833,10 @@ var DocumentHeader = ({
8105
9833
  BlockRenderer,
8106
9834
  DocumentHeader,
8107
9835
  blocksToHtml,
9836
+ blocksToMarkdown,
8108
9837
  escHtml,
8109
9838
  getEditorTools,
9839
+ markdownToBlocks,
8110
9840
  sanitizeInlineHtml,
8111
9841
  slugify,
8112
9842
  uploadFileToBucket,